[Rt-commit] r7649 - in rt/branches/3.7-EXPERIMENTAL: .

ruz at bestpractical.com ruz at bestpractical.com
Mon Apr 23 19:16:30 EDT 2007


Author: ruz
Date: Mon Apr 23 19:16:29 2007
New Revision: 7649

Modified:
   rt/branches/3.7-EXPERIMENTAL/   (props changed)
   rt/branches/3.7-EXPERIMENTAL/lib/RT/Interface/Email/Auth/GnuPGNG.pm

Log:
 r5102 at cubic-pc:  cubic | 2007-04-24 03:07:09 +0400
 * handle situation when we have no public key to decrypt


Modified: rt/branches/3.7-EXPERIMENTAL/lib/RT/Interface/Email/Auth/GnuPGNG.pm
==============================================================================
--- rt/branches/3.7-EXPERIMENTAL/lib/RT/Interface/Email/Auth/GnuPGNG.pm	(original)
+++ rt/branches/3.7-EXPERIMENTAL/lib/RT/Interface/Email/Auth/GnuPGNG.pm	Mon Apr 23 19:16:29 2007
@@ -41,8 +41,11 @@
         return @args{qw(CurrentUser AuthLevel)};
     }
 
-    $RT::Logger->error("Had a problem during decrypting and verifying")
-        unless $status;
+    unless ( $status ) {
+        $RT::Logger->error("Had a problem during decrypting and verifying");
+        my $reject = HandleErrors( Message => $args{'Message'}, Result => \@res );
+        return $args{'CurrentUser'}, -2;
+    }
 
     $args{'Message'}->head->add( 'X-RT-GnuPG-Status' => $_->{'status'} )
         foreach @res;
@@ -69,6 +72,53 @@
     return @args{qw(CurrentUser AuthLevel)};
 }
 
+sub HandleErrors {
+    my %args = (
+        Message => undef,
+        Result => [],
+        @_
+    );
+
+    my $reject = 0;
+
+    my %sent_once = ();
+    foreach my $run ( @{ $args{'Result'} } ) {
+        my @status = RT::Crypt::GnuPG::ParseStatus( $run->{'status'} );
+        unless ( $sent_once{'NoPrivateKey'} ) {
+            unless ( CheckNoPrivateKey( Message => $args{'Message'}, Status => \@status ) ) {
+                $sent_once{'NoPrivateKey'}++;
+                $reject = 1;
+            }
+        }
+    }
+    return $reject;
+}
+
+sub CheckNoPrivateKey {
+    my %args = (Message => undef, Status => [], @_ );
+    my @status = @{ $args{'Status'} };
+
+    my @encrypted_to = grep $_->{'Keyword'} eq 'ENC_TO', @status;
+    return 1 unless @encrypted_to;
+    return 1 if grep !$_->{'KeyMissing'}, @encrypted_to;
+
+    $RT::Logger->error("Couldn't decrypt a message: have no private key");
+
+    my $address = (RT::Interface::Email::ParseSenderAddressFromHead( $args{'Message'}->head ))[0];
+    my $status = RT::Interface::Email::SendEmailUsingTemplate(
+        To        => $address,
+        Template  => 'Error: no private key',
+        Arguments => {
+            Message   => $args{'Message'},
+            TicketObj => $args{'Ticket'},
+        },
+    );
+    unless ( $status ) {
+        $RT::Logger->error("Couldn't send 'Error: no private key'");
+    }
+    return 0;
+}
+
 sub VerifyDecrypt {
     my %args = (
         Entity => undef,


More information about the Rt-commit mailing list