1 %# BEGIN BPS TAGGED BLOCK {{{
5 %# This software is Copyright (c) 1996-2015 Best Practical Solutions, LLC
6 %# <sales@bestpractical.com>
8 %# (Except where explicitly superseded by other copyright notices)
13 %# This work is made available to you under the terms of Version 2 of
14 %# the GNU General Public License. A copy of that license should have
15 %# been provided with this software, but in any event can be snarfed
18 %# This work is distributed in the hope that it will be useful, but
19 %# WITHOUT ANY WARRANTY; without even the implied warranty of
20 %# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 %# General Public License for more details.
23 %# You should have received a copy of the GNU General Public License
24 %# along with this program; if not, write to the Free Software
25 %# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
26 %# 02110-1301 or visit their web page on the internet at
27 %# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html.
30 %# CONTRIBUTION SUBMISSION POLICY:
32 %# (The following paragraph is not intended to limit the rights granted
33 %# to you to modify and distribute this software under the terms of
34 %# the GNU General Public License and is only of importance to you if
35 %# you choose to contribute your changes and enhancements to the
36 %# community by submitting them to Best Practical Solutions, LLC.)
38 %# By intentionally submitting any modifications, corrections or
39 %# derivatives to this work, or any other work intended for use with
40 %# Request Tracker, to Best Practical Solutions, LLC, you confirm that
41 %# you are the copyright holder for those contributions and you grant
42 %# Best Practical Solutions, LLC a nonexclusive, worldwide, irrevocable,
43 %# royalty-free, perpetual, license to use, copy, create derivative
44 %# works based on those contributions, and sublicense and distribute
45 %# those contributions and any derivatives thereof.
47 %# END BPS TAGGED BLOCK }}}
50 $WarnUnsigned => undef
55 my $needs_unsigned_warning = $WarnUnsigned;
57 my @protocols = RT::Crypt->EnabledProtocols;
58 my $re_protocols = join '|', map "\Q$_\E", @protocols;
60 foreach ( $Message->SplitHeaders ) {
61 if ( s/^X-RT-($re_protocols)-Status:\s*//io ) {
62 push @runs, [ $1, RT::Crypt->ParseStatus( Protocol => "$1", Status => $_ ) ];
65 $needs_unsigned_warning = 0 if /^X-RT-Incoming-Signature:/;
67 # if this is not set, then the email is generated by RT, and so we don't
68 # need "email is unsigned" warnings
69 $needs_unsigned_warning = 0 if not /^Received:/;
72 return unless @runs or $needs_unsigned_warning;
74 my $reverify_cb = sub {
77 my $txn = $top->TransactionObj;
78 unless ( $txn && $txn->id ) {
79 return (0, "Couldn't get transaction of attachment #". $top->id);
82 my $attachments = $txn->Attachments->Clone;
83 $attachments->Limit( FIELD => 'ContentType', VALUE => 'application/x-rt-original-message' );
84 my $original = $attachments->First;
85 unless ( $original ) {
86 return (0, "Couldn't find attachment with original email of transaction #". $txn->id);
89 my $parser = RT::EmailParser->new();
90 $parser->SmartParseMIMEEntityFromScalar(
91 Message => $original->Content,
95 my $entity = $parser->Entity;
97 return (0, "Couldn't parse content of attachment #". $original->id);
100 my @res = RT::Crypt->VerifyDecrypt( Entity => $entity );
101 return (0, "Content of attachment #". $original->id ." is not signed and/or encrypted")
104 $top->DelHeader("X-RT-$_-Status") for RT::Crypt->Protocols;
105 $top->AddHeader(map { ("X-RT-". $_->{Protocol} ."-Status" => $_->{'status'} ) } @res);
106 $top->DelHeader("X-RT-Privacy");
107 my %protocols; $protocols{$_->{Protocol}}++ for @res;
108 $top->AddHeader('X-RT-Privacy' => $_ ) for sort keys %protocols;
110 $top->DelHeader('X-RT-Incoming-Signature');
111 my @status = RT::Crypt->ParseStatus(
112 Protocol => $res[0]{'Protocol'},
113 Status => $res[0]{'status'},
116 if ( $_->{'Operation'} eq 'Verify' && $_->{'Status'} eq 'DONE' ) {
117 $top->AddHeader( 'X-RT-Incoming-Signature' => $_->{'UserString'} );
118 $needs_unsigned_warning = 0;
121 return (1, "Reverified original message");
125 foreach my $run ( @runs ) {
126 my $protocol = shift @$run;
127 $protocol = $RT::Crypt::PROTOCOLS{lc $protocol};
128 foreach my $line ( @$run ) {
129 if ( $line->{'Operation'} eq 'KeyCheck' ) {
130 next unless $Reverify;
131 # if a public key was missing during verification then we want try again
132 next unless $line->{'KeyType'} eq 'public' && $line->{'Status'} eq 'MISSING';
134 # but only if we have key
135 my %key = RT::Crypt->GetPublicKeyInfo(
136 Protocol => $protocol, Key => $line->{'Key'}
138 if ( $key{'info'} ) {
139 my ($status, $msg) = $reverify_cb->($Message);
141 $RT::Logger->error($msg);
143 return $m->comp('SELF', %ARGS, Reverify => 0);
149 Classes => [qw/keycheck bad/],
150 Value => loc( "Public key '0x[_1]' is required to verify signature", $line->{'Key'} ),
154 elsif ( $line->{'Operation'} eq 'PassphraseCheck' ) {
155 next if $line->{'Status'} eq 'DONE';
158 Classes => ['passphrasecheck', lc $line->{Status}],
159 Value => loc( $line->{'Message'} ),
162 elsif ( $line->{'Operation'} eq 'Decrypt' ) {
165 Classes => ['decrypt', lc $line->{Status}],
166 Value => loc( $line->{'Message'} ),
169 elsif ( $line->{'Operation'} eq 'Verify' ) {
172 Classes => ['verify', lc $line->{Status}, 'trust-'.($line->{Trust} || 'UNKNOWN')],
173 Value => loc( $line->{'Message'} ),
177 next if $line->{'Status'} eq 'DONE';
180 Classes => [lc $line->{Operation}, lc $line->{Status}],
181 Value => loc( $line->{'Message'} ),
187 push @messages, { Tag => "Signing", Classes => ['verify', 'bad'], Value => loc('Warning! This is NOT signed!') }
188 if $needs_unsigned_warning;
189 return unless @messages;
192 @messages = grep !$seen{$_->{Value}}++, @messages;