[Rt-commit] rt branch, 4.2/smime-v2, updated. rt-4.0.4-520-g2b976ec

Ruslan Zakirov ruz at bestpractical.com
Wed Jul 11 12:12:13 EDT 2012


The branch, 4.2/smime-v2 has been updated
       via  2b976ece3bf0494f3e76e2a7a3ee77c84d6fbe27 (commit)
       via  23354135894f5ea03245116529f49ec6f75bddb3 (commit)
       via  af4f6faa3b973d47e3d76a9b6afcb3bf6d6c8fb9 (commit)
      from  3904b5d4460561641d8d3f942722d036d836b45b (commit)

Summary of changes:
 lib/RT/Crypt/SMIME.pm          |  27 ++++-----
 t/crypt/smime/bad-recipients.t |  66 +++++++++++++++++++++
 t/crypt/smime/cert-parser.t    | 127 +++++++++++++++++++++++++++++++++++++++++
 t/crypt/smime/status-string.t  |  26 +++++++++
 4 files changed, 233 insertions(+), 13 deletions(-)
 create mode 100644 t/crypt/smime/bad-recipients.t
 create mode 100644 t/crypt/smime/cert-parser.t
 create mode 100644 t/crypt/smime/status-string.t

- Log -----------------------------------------------------------------
commit af4f6faa3b973d47e3d76a9b6afcb3bf6d6c8fb9
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Wed Jul 11 18:56:13 2012 +0300

    format status string so multiple can be appended together

diff --git a/lib/RT/Crypt/SMIME.pm b/lib/RT/Crypt/SMIME.pm
index 711f07a..71104c2 100644
--- a/lib/RT/Crypt/SMIME.pm
+++ b/lib/RT/Crypt/SMIME.pm
@@ -509,10 +509,10 @@ sub FormatStatus {
 
     my $res = '';
     foreach ( @status ) {
-        $res .= "[SMIME:]\n" if $res;
         while ( my ($k, $v) = each %$_ ) {
             $res .= "[SMIME:]". $k .": ". $v ."\n";
         }
+        $res .= "[SMIME:]\n";
     }
 
     return $res;
diff --git a/t/crypt/smime/status-string.t b/t/crypt/smime/status-string.t
new file mode 100644
index 0000000..07e7989
--- /dev/null
+++ b/t/crypt/smime/status-string.t
@@ -0,0 +1,26 @@
+#!/usr/bin/perl
+use strict;
+use warnings;
+
+use RT::Test::SMIME tests => 3;
+
+note "simple round trip";
+{
+    my %data = (Foo => 'bar', Baz => 'zoo');
+    is_deeply(
+        [ RT::Crypt::SMIME->ParseStatus( RT::Crypt::SMIME->FormatStatus( \%data, \%data ) ) ],
+        [ \%data, \%data ],
+    );
+}
+
+note "status appendability";
+{
+    my %data = (Foo => 'bar', Baz => 'zoo');
+    is_deeply(
+        [ RT::Crypt::SMIME->ParseStatus(
+            RT::Crypt::SMIME->FormatStatus( \%data )
+            . RT::Crypt::SMIME->FormatStatus( \%data )
+        ) ],
+        [ \%data, \%data ],
+    );
+}

commit 23354135894f5ea03245116529f49ec6f75bddb3
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Wed Jul 11 19:03:07 2012 +0300

    fix detecting of bad recipients during SMIME encryption
    
    we have to use FormatStatus method rather than building
    string ourself.
    
    test things

diff --git a/lib/RT/Crypt/SMIME.pm b/lib/RT/Crypt/SMIME.pm
index 71104c2..0dda369 100644
--- a/lib/RT/Crypt/SMIME.pm
+++ b/lib/RT/Crypt/SMIME.pm
@@ -183,12 +183,13 @@ sub _SignEncrypt {
             unless ( defined $key_info{'info'} ) {
                 $res{'exit_code'} = 1;
                 my $reason = 'Key not found';
-                $res{'status'} .=
-                    "Operation: RecipientsCheck\nStatus: ERROR\n"
-                    ."Message: Recipient '$address' is unusable, the reason is '$reason'\n"
-                    ."Recipient: $address\n"
-                    ."Reason: $reason\n\n",
-                ;
+                $res{'status'} .= $self->FormatStatus({
+                    Operation => 'RecipientsCheck',
+                    Status => 'ERROR',
+                    Message => "Recipient '$address' is unusable, the reason is '$reason'",
+                    Recipient => $address,
+                    Reason => $reason,
+                } );
                 next;
             }
 
@@ -203,12 +204,12 @@ sub _SignEncrypt {
             elsif ( $key_info{'info'}[0]{'Expire'}->Diff( time ) < 0 ) {
                 $res{'exit_code'} = 1;
                 my $reason = 'Key expired';
-                $res{'status'} .=
-                    "Operation: RecipientsCheck\nStatus: ERROR\n"
-                    ."Message: Recipient '$address' is unusable, the reason is '$reason'\n"
-                    ."Recipient: $address\n"
-                    ."Reason: $reason\n\n",
-                ;
+                $res{'status'} .= $self->FormatStatus({
+                    Operation => 'RecipientsCheck', Status => 'ERROR',
+                    Message => "Recipient '$address' is unusable, the reason is '$reason'",
+                    Recipient => $address,
+                    Reason => $reason,
+                });
                 next;
             }
             push @keys, $key_info{'info'}[0]{'Content'};
diff --git a/t/crypt/smime/bad-recipients.t b/t/crypt/smime/bad-recipients.t
new file mode 100644
index 0000000..ddbc7cc
--- /dev/null
+++ b/t/crypt/smime/bad-recipients.t
@@ -0,0 +1,66 @@
+#!/usr/bin/perl
+use strict;
+use warnings;
+
+use RT::Test::SMIME tests => 10;
+
+use RT::Tickets;
+
+RT::Test->import_smime_key('sender at example.com');
+my $queue = RT::Test->load_or_create_queue(
+    Name              => 'General',
+    CorrespondAddress => 'sender at example.com',
+);
+ok $queue && $queue->id, 'loaded or created queue';
+
+{
+    my ($status, $msg) = $queue->SetEncrypt(1);
+    ok $status, "turn on encyption by default"
+        or diag "error: $msg";
+}
+
+{
+    my $cf = RT::CustomField->new( $RT::SystemUser );
+    my ($ret, $msg) = $cf->Create(
+        Name       => 'SMIME Key',
+        LookupType => RT::User->new( $RT::SystemUser )->CustomFieldLookupType,
+        Type       => 'TextSingle',
+    );
+    ok($ret, "Custom Field created");
+
+    my $OCF = RT::ObjectCustomField->new( $RT::SystemUser );
+    $OCF->Create(
+        CustomField => $cf->id,
+        ObjectId    => 0,
+    );
+}
+
+my $root;
+{
+    $root = RT::User->new($RT::SystemUser);
+    ok($root->LoadByEmail('root at localhost'), "Loaded user 'root'");
+    ok($root->Load('root'), "Loaded user 'root'");
+    is($root->EmailAddress, 'root at localhost');
+
+    RT::Test->import_smime_key( 'root at example.com.crt' => $root );
+}
+
+my $bad_user;
+{
+    $bad_user = RT::Test->load_or_create_user(
+        Name => 'bad_user',
+        EmailAddress => 'baduser at example.com',
+    );
+    ok $bad_user && $bad_user->id, 'created a user without key';
+}
+
+RT::Test->clean_caught_mails;
+
+{
+    my $ticket = RT::Ticket->new(RT->SystemUser);
+    my ($status, undef, $msg) = $ticket->Create( Queue => $queue->id, Requestor => [$root->id, $bad_user->id] );
+    ok $status, "created a ticket" or "error: $msg";
+
+    my @mails = RT::Test->fetch_caught_mails;
+    is scalar @mails, 3, "autoreply, to bad user, to RT owner";
+}

commit 2b976ece3bf0494f3e76e2a7a3ee77c84d6fbe27
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Wed Jul 11 19:05:41 2012 +0300

    test how we parse certificate information
    
    openssl changed output at least once during development
    of this branch.

diff --git a/t/crypt/smime/cert-parser.t b/t/crypt/smime/cert-parser.t
new file mode 100644
index 0000000..7720f79
--- /dev/null
+++ b/t/crypt/smime/cert-parser.t
@@ -0,0 +1,127 @@
+#!/usr/bin/perl
+use strict;
+use warnings;
+
+use RT::Test::SMIME tests => 3;
+
+{ # OpenSSL 0.9.8r 8 Feb 2011
+    my $cert = <<'END';
+Certificate:
+    Data:
+        Version: 3 (0x2)
+        Serial Number:
+            8a:6a:cd:51:be:94:a0:16
+        Signature Algorithm: sha1WithRSAEncryption
+        Issuer:
+            countryName=AU
+            stateOrProvinceName=Some-State
+            organizationName=Internet Widgits Pty Ltd
+            commonName=CA Owner
+            emailAddress=ca.owner at example.com
+        Validity
+            Not Before: Dec 28 21:46:42 2011 GMT
+            Not After : Aug 18 21:46:42 2036 GMT
+        Subject:
+            countryName=AU
+            stateOrProvinceName=Some-State
+            organizationName=Internet Widgits Pty Ltd
+            commonName=Enoch Root
+            emailAddress=root at example.com
+SHA1 Fingerprint=3C:CC:22:59:BA:65:41:7D:75:CE:99:54:7F:B9:9B:75:0C:8C:74:B0
+END
+    my $expected = {
+        'Certificate' => {
+            'Data' => {
+                'Version' => '3 (0x2)',
+                'Subject' => {
+                               'commonName' => 'Enoch Root',
+                               'emailAddress' => 'root at example.com',
+                               'organizationName' => 'Internet Widgits Pty Ltd',
+                               'stateOrProvinceName' => 'Some-State',
+                               'countryName' => 'AU'
+                             },
+                'Serial Number' => '8a:6a:cd:51:be:94:a0:16',
+                'Issuer' => {
+                              'commonName' => 'CA Owner',
+                              'emailAddress' => 'ca.owner at example.com',
+                              'organizationName' => 'Internet Widgits Pty Ltd',
+                              'stateOrProvinceName' => 'Some-State',
+                              'countryName' => 'AU'
+                            },
+                'Validity' => {
+                                'Not Before' => 'Dec 28 21:46:42 2011 GMT',
+                                'Not After' => 'Aug 18 21:46:42 2036 GMT'
+                              },
+                'Signature Algorithm' => 'sha1WithRSAEncryption',
+            },
+        },
+        'SHA1 Fingerprint' => '3C:CC:22:59:BA:65:41:7D:75:CE:99:54:7F:B9:9B:75:0C:8C:74:B0'
+    };
+
+    my %info = RT::Crypt::SMIME->ParseCertificateInfo( $cert );
+    is_deeply(
+        \%info,
+        $expected,
+    );
+}
+
+{ # OpenSSL 1.0.1 14 Mar 2012
+    my $cert = <<'END';
+Certificate:
+    Data:
+        Version: 3 (0x2)
+        Serial Number: 9974010075738841110 (0x8a6acd51be94a016)
+    Signature Algorithm: sha1WithRSAEncryption
+        Issuer:
+            countryName=AU
+            stateOrProvinceName=Some-State
+            organizationName=Internet Widgits Pty Ltd
+            commonName=CA Owner
+            emailAddress=ca.owner at example.com
+        Validity
+            Not Before: Dec 28 21:46:42 2011 GMT
+            Not After : Aug 18 21:46:42 2036 GMT
+        Subject:
+            countryName=AU
+            stateOrProvinceName=Some-State
+            organizationName=Internet Widgits Pty Ltd
+            commonName=Enoch Root
+            emailAddress=root at example.com
+SHA1 Fingerprint=3C:CC:22:59:BA:65:41:7D:75:CE:99:54:7F:B9:9B:75:0C:8C:74:B0
+END
+    my $expected = {
+        'Certificate' => {
+            'Data' => {
+                'Version' => '3 (0x2)',
+                'Subject' => {
+                               'commonName' => 'Enoch Root',
+                               'emailAddress' => 'root at example.com',
+                               'organizationName' => 'Internet Widgits Pty Ltd',
+                               'stateOrProvinceName' => 'Some-State',
+                               'countryName' => 'AU'
+                             },
+                'Serial Number' => '9974010075738841110 (0x8a6acd51be94a016)',
+                'Issuer' => {
+                              'commonName' => 'CA Owner',
+                              'emailAddress' => 'ca.owner at example.com',
+                              'organizationName' => 'Internet Widgits Pty Ltd',
+                              'stateOrProvinceName' => 'Some-State',
+                              'countryName' => 'AU'
+                            },
+                'Validity' => {
+                                'Not Before' => 'Dec 28 21:46:42 2011 GMT',
+                                'Not After' => 'Aug 18 21:46:42 2036 GMT'
+                              },
+            },
+            'Signature Algorithm' => 'sha1WithRSAEncryption',
+        },
+        'SHA1 Fingerprint' => '3C:CC:22:59:BA:65:41:7D:75:CE:99:54:7F:B9:9B:75:0C:8C:74:B0'
+    };
+
+    my %info = RT::Crypt::SMIME->ParseCertificateInfo( $cert );
+    is_deeply(
+        \%info,
+        $expected,
+    );
+}
+

-----------------------------------------------------------------------


More information about the Rt-commit mailing list