DKIM/Verifier.pm

filter: Statementstmt 85.9% 202 / 235 Branchbran 71.2% 67 / 94 Conditioncond 61.5% 24 / 39 MC/DCmcdc 44.0% 11 / 25 Subroutinesub 84.0% 21 / 25 Podpod 35.7% 5 / 14 totaltotal 76.3% 330 / 432 CC 65 SCAR 23.0
CC
65
Cov
80%
check_signature
21.8
_check_and_verify_signature
14.3
policies
12.0
CRAP 10.0
« DKIM/Signer.pm ↑ Summary DKIM/Canonicalization/Base.pm »
1 package Mail::DKIM::Verifier;
2 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 6 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 6 our $VERSION = '1.20240923'; # VERSION
5 # ABSTRACT: verifies a DKIM-signed message
6  
7 # Copyright 2005-2009 Messiah College. All rights reserved.
8 # Jason Long <jlong@messiah.edu>
9  
10 # Copyright (c) 2004 Anthony D. Urso. All rights reserved.
11 # This program is free software; you can redistribute it and/or
12 # modify it under the same terms as Perl itself.
13  
14 6 ▶use Mail::DKIM::Signature;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 6 ▶use Mail::DKIM::DkSignature;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 6 ▶use Mail::Address;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18  
19  
20 6 ▶use base 'Mail::DKIM::Common';
Subroutine BEGIN: called CC=1 SCAR=0.0
21 6 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 6 our $MAX_SIGNATURES_TO_PROCESS = 50;
23  
24 84 ▶sub init {
Subroutine init: called CC=1 SCAR=0.0
Pod undocumented
25 84 my $self = shift;
26 84 $self->SUPER::init;
27 84 $self->{signatures} = [];
28 }
29  
30 # @{$dkim->{signatures}}
31 # array of L<Mail::DKIM::Signature> objects, representing all
32 # parseable signatures found in the header,
33 # ordered from the top of the header to the bottom.
34 #
35 # $dkim->{signature_reject_reason}
36 # simple string listing a reason, if any, for not using a signature.
37 # This may be a helpful diagnostic if there is a signature in the header,
38 # but was found not to be valid. It will be ambiguous if there are more
39 # than one signatures that could not be used.
40 #
41 # $dkim->{signature}
42 # the L<Mail::DKIM::Signature> selected as the "best" signature.
43 #
44 # @{$dkim->{headers}}
45 # array of strings, each member is one header, in its original format.
46 #
47 # $dkim->{algorithms}
48 # array of algorithms, one for each signature being verified.
49 #
50 # $dkim->{result}
51 # string; the result of the verification (see the result() method)
52 #
53  
54 709 ▶sub handle_header {
Subroutine handle_header: called CC=5 SCAR=16.2
Pod undocumented
55 709 my $self = shift;
56 709 my ( $field_name, $contents, $line ) = @_;
57  
58 709 $self->SUPER::handle_header( $field_name, $contents );
59  
60 709 ▶ if ( lc($field_name) eq 'dkim-signature' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (lc $field_name eq "dkim-signature") 72 637 709
61 eval {
62 72 local $SIG{__DIE__};
63 72 my $signature = Mail::DKIM::Signature->parse($line);
64 71 $self->add_signature($signature);
65 71 1
66 72 ▶ } || do {
Branch: 1 branch
BranchTrueFalseTotal
eval { do { local $SIG{"__DIE__"}; my $signature = "Mail::DKIM::Signature"->parse($line); $self->add_signature($signature); 1 } } or do { chomp(my $E = $@); $self->{"signature_reject_reason"} = $E } 71 1 72
67  
68 # the only reason an error should be thrown is if the
69 # signature really is unparse-able
70  
71 # otherwise, invalid signatures are caught in finish_header()
72  
73 1 chomp( my $E = $@ );
74 1 $self->{signature_reject_reason} = $E;
75 };
76 }
77  
78 709 ▶ if ( lc($field_name) eq 'domainkey-signature' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (lc $field_name eq "domainkey-signature") 17 692 709
79 eval {
80 17 local $SIG{__DIE__};
81 17 my $signature = Mail::DKIM::DkSignature->parse($line);
82 17 $self->add_signature($signature);
83 17 1
84 17 ▶ } || do {
Branch: 1 branch
BranchTrueFalseTotal
eval { do { local $SIG{"__DIE__"}; my $signature = "Mail::DKIM::DkSignature"->parse($line); $self->add_signature($signature); 1 } } or do { chomp(my $E = $@); $self->{"signature_reject_reason"} = $E } 17 0 17
85  
86 # the only reason an error should be thrown is if the
87 # signature really is unparse-able
88  
89 # otherwise, invalid signatures are caught in finish_header()
90  
91 0 chomp( my $E = $@ );
92 0 $self->{signature_reject_reason} = $E;
93 };
94 }
95 }
96  
97 88 ▶sub add_signature {
Subroutine add_signature: called CC=8 SCAR=20.8
Pod undocumented
98 88 my $self = shift;
99 88 ▶ croak 'wrong number of arguments' unless ( @_ == 1 );
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 1 0 88 88
100 88 my ($signature) = @_;
101  
102 # Set verification time if we have one
103 88 ▶ if ($self->{verify_time}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"verify_time"}) 1 87 88
104 1 $signature->set_verify_time($self->{verify_time});
105 }
106  
107 # ignore signature headers once we've seen 50 or so
108 # this protects against abuse.
109 88 ▶ return if ( @{ $self->{signatures} } > $MAX_SIGNATURES_TO_PROCESS );
Branch: 1 branch
BranchTrueFalseTotal
if @{$self->{"signatures"};} > $Mail::DKIM::Verifier::MAX_SIGNATURES_TO_PROCESS 0 88 88
110  
111 88 push @{ $self->{signatures} }, $signature;
112  
113 88 ▶ unless ( $self->check_signature($signature) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->check_signature($signature)) 14 74 88
114 14 $signature->result( 'invalid', $self->{signature_reject_reason} );
115 14 return;
116 }
117  
118 # signature looks ok, go ahead and query for the public key
119 74 $signature->fetch_public_key;
120  
121 # create a canonicalization filter and algorithm
122 74 my $algorithm_class =
123 $signature->get_algorithm_class( $signature->algorithm );
124 my $algorithm = $algorithm_class->new(
125 Signature => $signature,
126 Debug_Canonicalization => $self->{Debug_Canonicalization},
127 74 );
128  
129 # push through the headers parsed prior to the signature header
130 74 ▶ if ( $algorithm->wants_pre_signature_headers ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($algorithm->wants_pre_signature_headers) 59 15 74
131  
132 # Note: this will include the signature header that led to this
133 # "algorithm"...
134 59 foreach my $head ( @{ $self->{headers} } ) {
135 67 $algorithm->add_header($head);
136 }
137 }
138  
139 # save the algorithm
140 74 ▶ $self->{algorithms} ||= [];
Condition50%1/2
$self->{"algorithms"} ||= []
l!l
740
MC/DC0%0/1
$self->{"algorithms"} ||= []
$self->{"algorithms"}
Truth table50%1/2
A
A= $self->{"algorithms"}
Aresult
11
00
141 74 push @{ $self->{algorithms} }, $algorithm;
142 }
143  
144 88 ▶sub check_signature {
Subroutine check_signature: called CC=18 SCAR=30.8
Pod undocumented
145 88 my $self = shift;
146 88 ▶ croak 'wrong number of arguments' unless ( @_ == 1 );
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 1 0 88 88
147 88 my ($signature) = @_;
148  
149 88 ▶ unless ( $signature->check_version ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($signature->check_version) 1 87 88
150  
151 # unsupported version
152 1 ▶ if ( defined $signature->version ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $signature->version) { } 1 0 1
153 $self->{signature_reject_reason} =
154 1 'unsupported version ' . $signature->version;
155 }
156 else {
157 0 $self->{signature_reject_reason} = 'missing v tag';
158 }
159 1 return 0;
160 }
161  
162 87 ▶ unless ( $signature->algorithm
Branch: 1 branch
BranchTrueFalseTotal
unless ($signature->algorithm and $signature->get_algorithm_class($signature->algorithm)) 2 85 87
Condition66%2/3
$signature->algorithm and $signature->get_algorithm_class($signature->algorithm)
!ll&&!rl&&r
0285
MC/DC50%1/2
$signature->algorithm and $signature->get_algorithm_class($signature->algorithm)
$signature->algorithm $signature->get_algorithm_class($signature->algorithm)
Truth table66%2/3
A and B
A= $signature->algorithmB= $signature->get_algorithm_class($signature->algorithm)
ABresult
0X0
100
111
163 && $signature->get_algorithm_class( $signature->algorithm ) )
164 {
165 # unsupported algorithm
166 2 $self->{signature_reject_reason} = 'unsupported algorithm';
167 2 ▶ if ( defined $signature->algorithm ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $signature->algorithm) 2 0 2
168 2 $self->{signature_reject_reason} .= ' ' . $signature->algorithm;
169 }
170 2 return 0;
171 }
172  
173 85 ▶ if ( $self->{Strict} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"Strict"}) 4 81 85
174 4 ▶ if ( $signature->algorithm eq 'rsa-sha1' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($signature->algorithm eq "rsa-sha1") 2 2 4
175 2 $self->{signature_reject_reason} = 'unsupported algorithm';
176 2 ▶ if ( defined $signature->algorithm ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $signature->algorithm) 2 0 2
177 2 $self->{signature_reject_reason} .= ' ' . $signature->algorithm;
178 }
179 2 return 0;
180 }
181 }
182  
183 83 ▶ unless ( $signature->check_canonicalization ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($signature->check_canonicalization) 2 81 83
184  
185 # unsupported canonicalization method
186 2 $self->{signature_reject_reason} = 'unsupported canonicalization';
187 2 ▶ if ( defined $signature->canonicalization ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $signature->canonicalization) 2 0 2
188 $self->{signature_reject_reason} .=
189 2 ' ' . $signature->canonicalization;
190 }
191 2 return 0;
192 }
193  
194 81 ▶ unless ( $signature->check_protocol ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($signature->check_protocol) 4 77 81
195  
196 # unsupported query protocol
197 $self->{signature_reject_reason} =
198 4 ▶ !defined( $signature->protocol )
Branch: 1 branch
BranchTrueFalseTotal
!defined($signature->protocol) ? : 0 4 4
199 ? 'missing q tag'
200 : 'unsupported query protocol, q=' . $signature->protocol;
201 4 return 0;
202 }
203  
204 77 ▶ unless ( $signature->check_expiration ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($signature->check_expiration) 3 74 77
205  
206 # signature has expired
207 3 $self->{signature_reject_reason} = 'signature is expired';
208 3 return 0;
209 }
210  
211 74 ▶ unless ( defined $signature->domain ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $signature->domain) 0 74 74
212  
213 # no domain specified
214 0 $self->{signature_reject_reason} = 'missing d tag';
215 0 return 0;
216 }
217  
218 74 ▶ if ( $signature->domain eq '' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($signature->domain eq "") 0 74 74
219  
220 # blank domain
221 0 $self->{signature_reject_reason} = 'invalid domain in d tag';
222 0 return 0;
223 }
224  
225 74 ▶ unless ( defined $signature->selector ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $signature->selector) 0 74 74
226  
227 # no selector specified
228 0 $self->{signature_reject_reason} = 'missing s tag';
229 0 return 0;
230 }
231  
232 74 return 1;
233 }
234  
235 60 ▶sub check_public_key {
Subroutine check_public_key: called CC=5 SCAR=16.1
Pod undocumented
236 60 my $self = shift;
237 60 ▶ croak 'wrong number of arguments' unless ( @_ == 2 );
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 2 0 60 60
238 60 my ( $signature, $public_key ) = @_;
239  
240 60 my $result = 0;
241 eval {
242 60 local $SIG{__DIE__};
243 60 $@ = undef;
244  
245 # HACK- I'm indecisive here about whether I want the
246 # check_foo functions to return false or to "die"
247 # on failure
248  
249 # check public key's allowed hash algorithms
250 60 $result =
251 $public_key->check_hash_algorithm( $signature->hash_algorithm );
252  
253 # HACK- DomainKeys signatures are allowed to have an empty g=
254 # tag in the public key
255 58 my $empty_g_means_wildcard = $signature->isa('Mail::DKIM::DkSignature');
256  
257 # check public key's granularity
258 58 ▶ $result &&=
Condition66%2/3
$result &&= $public_key->check_granularity($signature->identity, $empty_g_means_wildcard)
!ll&&!rl&&r
0553
MC/DC50%1/2
$result &&= $public_key->check_granularity($signature->identity, $empty_g_means_wildcard)
$result $public_key->check_granularity($signature->identity, $empty_g_means_wildcard)
Truth table66%2/3
A &&= B
A= $resultB= $public_key->check_granularity($signature->identity, $empty_g_means_wildcard)
ABresult
0X0
100
111
259 $public_key->check_granularity( $signature->identity,
260 $empty_g_means_wildcard );
261  
262 58 ▶ die $@ if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 5 53 58
263 53 1
264 60 ▶ } || do {
Branch: 1 branch
BranchTrueFalseTotal
eval { do { local $SIG{"__DIE__"}; $@ = undef; $result = $public_key->check_hash_algorithm($signature->hash_algorithm); my $empty_g_means_wildcard = $signature->isa("Mail::DKIM::DkSignature"); $result &&= $public_key->check_granularity($signature->identity, $empty_g_means_wildcard); die $@ if $@; 1 } } or do { my $E = $@; chomp $E; $self->{"signature_reject_reason"} = "public key: $E" } 53 7 60
265 7 my $E = $@;
266 7 chomp $E;
267 7 $self->{signature_reject_reason} = "public key: $E";
268 };
269 60 return $result;
270 }
271  
272 # returns true if the i= tag is an address with a domain matching or
273 # a subdomain of the d= tag
274 #
275 74 ▶sub check_signature_identity {
Subroutine check_signature_identity: called CC=3 SCAR=12.3
Pod undocumented
276 74 my ($signature) = @_;
277  
278 74 my $d = $signature->domain;
279 74 my $i = $signature->identity;
280 74 ▶ if ( defined($i) && $i =~ /\@([^@]*)$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $i and $i =~ /\@([^\@]*)$/) 74 0 74
Condition33%1/3
defined $i and $i =~ /\@([^\@]*)$/
!ll&&!rl&&r
0074
MC/DC0%0/2
defined $i and $i =~ /\@([^\@]*)$/
defined $i $i =~ /\@([^\@]*)$/
Truth table33%1/3
A and B
A= defined $iB= $i =~ /\@([^\@]*)$/
ABresult
0X0
100
111
281 74 return match_subdomain( $1, $d );
282 }
283 0 return 0;
284 }
285  
286 74 ▶sub match_subdomain {
Subroutine match_subdomain: called CC=2 SCAR=7.0
Pod undocumented
287 74 ▶ croak 'wrong number of arguments' unless ( @_ == 2 );
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 2 0 74 74
288 74 my ( $subdomain, $superdomain ) = @_;
289  
290 74 my $tmp = substr( ".$subdomain", -1 - length($superdomain) );
291 74 return ( lc ".$superdomain" eq lc $tmp );
292 }
293  
294 #
295 # called when the verifier has received the last of the message headers
296 # (body is still to come)
297 #
298 83 ▶sub finish_header {
Subroutine finish_header: called CC=9 SCAR=22.6
Pod undocumented
299 83 my $self = shift;
300  
301 # Signatures we found and were successfully parsed are stored in
302 # $self->{signatures}. If none were found, our result is "none".
303  
304 83 ▶ if ( @{ $self->{signatures} } == 0
Branch: 1 branch
BranchTrueFalseTotal
if (@{$self->{"signatures"};} == 0 and not defined $self->{"signature_reject_reason"}) 1 82 83
Condition66%2/3
@{$self->{"signatures"};} == 0 and not defined $self->{"signature_reject_reason"}
!ll&&!rl&&r
8201
MC/DC50%1/2
@{$self->{"signatures"};} == 0 and not defined $self->{"signature_reject_reason"}
@{$self->{"signatures"};} == 0 not defined $self->{"signature_reject_reason"}
Truth table66%2/3
A and not(B)
A= @{$self->{"signatures"};} == 0B= not defined $self->{"signature_reject_reason"}
ABresult
0X0
100
111
305 && !defined( $self->{signature_reject_reason} ) )
306 {
307 1 $self->{result} = 'none';
308 1 return;
309 }
310  
311 82 foreach my $algorithm ( @{ $self->{algorithms} } ) {
312 74 $algorithm->finish_header( Headers => $self->{headers} );
313 }
314  
315 # stop processing signatures that are already known to be invalid
316 82 @{ $self->{algorithms} } = grep {
317 74 my $sig = $_->signature;
318 74 ▶ !( $sig->result && $sig->result eq 'invalid' );
Condition33%1/3
$sig->result && $sig->result eq 'invalid'
!ll&&!rl&&r
7400
MC/DC0%0/2
$sig->result && $sig->result eq 'invalid'
$sig->result $sig->result eq 'invalid'
Truth table33%1/3
A && B
A= $sig->resultB= $sig->result eq 'invalid'
ABresult
0X0
100
111
319 82 } @{ $self->{algorithms} };
320  
321 82 ▶ if ( @{ $self->{algorithms} } == 0
Branch: 1 branch
BranchTrueFalseTotal
if (@{$self->{"algorithms"};} == 0 and @{$self->{"signatures"};} > 0) 13 69 82
Condition66%2/3
@{$self->{"algorithms"};} == 0 and @{$self->{"signatures"};} > 0
!ll&&!rl&&r
69013
MC/DC50%1/2
@{$self->{"algorithms"};} == 0 and @{$self->{"signatures"};} > 0
@{$self->{"algorithms"};} == 0 @{$self->{"signatures"};} > 0
Truth table66%2/3
A and B
A= @{$self->{"algorithms"};} == 0B= @{$self->{"signatures"};} > 0
ABresult
0X0
100
111
322 13 && @{ $self->{signatures} } > 0 )
323 {
324 13 ▶ $self->{result} = $self->{signatures}->[0]->result || 'invalid';
Condition50%1/2
$self->{'signatures'}[0]->result || 'invalid'
l!l
130
MC/DC0%0/1
$self->{'signatures'}[0]->result || 'invalid'
$self->{'signatures'}[0]->result
Truth table50%1/2
A
A= $self->{'signatures'}[0]->result
Aresult
11
00
325 $self->{details} = $self->{signatures}->[0]->{verify_details}
326 13 ▶ || $self->{signature_reject_reason};
Condition33%1/3
$self->{'signatures'}[0]{'verify_details'} || $self->{'signature_reject_reason'}
l!l&&r!l&&!r
1300
MC/DC0%0/2
$self->{'signatures'}[0]{'verify_details'} || $self->{'signature_reject_reason'}
$self->{'signatures'}[0]{'verify_details'} $self->{'signature_reject_reason'}
Truth table33%1/3
A || B
A= $self->{'signatures'}[0]{'verify_details'}B= $self->{'signature_reject_reason'}
ABresult
1X1
011
000
327 13 return;
328 }
329 }
330  
331 74 ▶sub _check_and_verify_signature {
Subroutine _check_and_verify_signature: called CC=14 SCAR=26.6
332 74 my $self = shift;
333 74 my ($algorithm) = @_;
334  
335 # check signature
336 74 my $signature = $algorithm->signature;
337 74 ▶ unless ( check_signature_identity($signature) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (check_signature_identity($signature)) 3 71 74
338 3 $self->{signature_reject_reason} = 'bad identity';
339 3 return ( 'invalid', $self->{signature_reject_reason} );
340 }
341  
342 # get public key
343 71 my $pkey;
344 71 eval { $pkey = $signature->get_public_key; 1 }
345 71 ▶ || do {
Branch: 1 branch
BranchTrueFalseTotal
eval { do { $pkey = $signature->get_public_key; 1 } } or do { my $E = $@; chomp $E; $self->{"signature_reject_reason"} = "public key: $E"; return "invalid", $self->{"signature_reject_reason"} } 60 11 71
346 11 my $E = $@;
347 11 chomp $E;
348 11 $self->{signature_reject_reason} = "public key: $E";
349 11 return ( 'invalid', $self->{signature_reject_reason} );
350 };
351  
352 60 ▶ unless ( $self->check_public_key( $signature, $pkey ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->check_public_key($signature, $pkey)) 7 53 60
353 7 return ( 'invalid', $self->{signature_reject_reason} );
354 }
355  
356 # special handling for RSA signatures
357 53 ▶ my $k = $pkey->get_tag('k') || 'rsa';
Condition100%2/2
$pkey->get_tag('k') || 'rsa'
l!l
3617
MC/DC100%1/1
$pkey->get_tag('k') || 'rsa'
$pkey->get_tag('k')
Truth table100%2/2
A
A= $pkey->get_tag('k')
Aresult
11
00
358 53 ▶ if ($k eq 'rsa') {
Branch: 1 branch
BranchTrueFalseTotal
if ($k eq "rsa") 50 3 53
359 # make sure key is big enough
360 50 my $keysize = $pkey->cork->size * 8; # in bits
361 50 ▶ if ( $keysize < 1024 && $self->{Strict} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($keysize < 1024 and $self->{"Strict"}) 1 49 50
Condition100%3/3
$keysize < 1024 and $self->{"Strict"}
!ll&&!rl&&r
23261
MC/DC100%2/2
$keysize < 1024 and $self->{"Strict"}
$keysize < 1024 $self->{"Strict"}
Truth table100%3/3
A and B
A= $keysize < 1024B= $self->{"Strict"}
ABresult
0X0
100
111
362 1 $self->{signature_reject_reason} = "Key length $keysize too short";
363 1 return ( 'fail', $self->{signature_reject_reason} );
364 }
365 }
366  
367 # verify signature
368 52 my $result;
369 my $details;
370 52 local $@ = undef;
371 eval {
372 52 ▶ $result = $algorithm->verify() ? 'pass' : 'fail';
Branch: 1 branch
BranchTrueFalseTotal
$algorithm->verify ? : 40 10 50
373 50 ▶ $details = $algorithm->{verification_details} || $@;
Condition100%3/3
$algorithm->{'verification_details'} || $@
l!l&&r!l&&!r
2840
MC/DC100%2/2
$algorithm->{'verification_details'} || $@
$algorithm->{'verification_details'} $@
Truth table100%3/3
A || B
A= $algorithm->{'verification_details'}B= $@
ABresult
1X1
011
000
374 50 1
375 52 ▶ } || do {
Branch: 1 branch
BranchTrueFalseTotal
eval { do { $result = $algorithm->verify ? "pass" : "fail"; $details = $algorithm->{"verification_details"} || $@; 1 } } or do { chomp(my $E = $@); if ($E =~ /(OpenSSL error: .*?) at /) { $E = $1; } elsif ($E =~ /^(panic:.*?) at /) { $E = "OpenSSL $1"; } elsif ($E =~ /^FATAL: (.*) at /) { $E = "Ed25519 $1"; } ; $result = "fail"; $details = $E } 50 2 52
376  
377 # see also add_signature
378 2 chomp( my $E = $@ );
379 2 ▶ if ( $E =~ /(OpenSSL error: .*?) at / ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($E =~ /(OpenSSL error: .*?) at /) { } 2 0 2
elsif ($E =~ /^(panic:.*?) at /) { } 0 0 0
elsif ($E =~ /^FATAL: (.*) at /) { } 0 0 0
380 2 $E = $1;
381 }
382 elsif ( $E =~ /^(panic:.*?) at / ) {
383 0 $E = "OpenSSL $1";
384 }
385 elsif ( $E =~ /^FATAL: (.*) at / ) {
386 0 $E = "Ed25519 $1";
387 }
388 2 $result = 'fail';
389 2 $details = $E;
390 };
391 52 return ( $result, $details );
392 }
393  
394 83 ▶sub finish_body {
Subroutine finish_body: called CC=4 SCAR=13.9
Pod undocumented
395 83 my $self = shift;
396  
397 83 foreach my $algorithm ( @{ $self->{algorithms} } ) {
398  
399 # finish canonicalizing
400 74 $algorithm->finish_body;
401  
402 74 my ( $result, $details ) =
403 $self->_check_and_verify_signature($algorithm);
404  
405 # save the results of this signature verification
406 74 $algorithm->{result} = $result;
407 74 $algorithm->{details} = $details;
408 74 $algorithm->signature->result( $result, $details );
409  
410 # collate results ... ignore failed signatures if we already got
411 # one to pass
412 74 ▶ if ( !$self->{result} || $result eq 'pass' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->{"result"} or $result eq "pass") 71 3 74
Condition100%3/3
not $self->{"result"} or $result eq "pass"
l!l&&r!l&&!r
6923
MC/DC100%2/2
not $self->{"result"} or $result eq "pass"
not $self->{"result"} $result eq "pass"
Truth table100%3/3
not(A) or B
A= not $self->{"result"}B= $result eq "pass"
ABresult
1X1
011
000
413 71 $self->{signature} = $algorithm->signature;
414 71 $self->{result} = $result;
415 71 $self->{details} = $details;
416 }
417 }
418 }
419  
420  
421 0 ▶sub fetch_author_domain_policies {
Subroutine fetch_author_domain_policies: not called CC=2 SCAR=13.0
Pod documented
422 0 my $self = shift;
423 6 ▶ use Mail::DKIM::AuthorDomainPolicy;
Subroutine BEGIN: called CC=1 SCAR=0.0
424  
425 0 ▶ return () unless $self->{headers_by_name}->{from};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"headers_by_name"}{"from"} 0 0 0
426 0 my @list = Mail::Address->parse( $self->{headers_by_name}->{from} );
427 0 my @authors = map { $_->address } @list;
428  
429 # fetch the policies
430 return map {
431 0 Mail::DKIM::AuthorDomainPolicy->fetch(
432 Protocol => 'dns',
433 Author => $_,
434 )
435 } @authors;
436 }
437  
438  
439 0 ▶sub fetch_author_policy {
Subroutine fetch_author_policy: not called CC=2 SCAR=12.2
Pod documented
440 0 my $self = shift;
441 0 my ($author) = @_;
442 6 ▶ use Mail::DKIM::DkimPolicy;
Subroutine BEGIN: called CC=1 SCAR=0.0
443  
444 # determine address found in the "From"
445 0 ▶ $author ||= $self->message_originator->address;
Condition0%0/3
$author ||= $self->message_originator->address
l!l&&r!l&&!r
000
MC/DC0%0/2
$author ||= $self->message_originator->address
$author $self->message_originator->address
Truth table0%0/3
A ||= B
A= $authorB= $self->message_originator->address
ABresult
1X1
011
000
446  
447 # fetch the policy
448 0 return Mail::DKIM::DkimPolicy->fetch(
449 Protocol => 'dns',
450 Author => $author,
451 );
452 }
453  
454  
455 0 ▶sub fetch_sender_policy {
Subroutine fetch_sender_policy: not called CC=1 SCAR=1.7
Pod documented
456 0 my $self = shift;
457 6 ▶ use Mail::DKIM::DkPolicy;
Subroutine BEGIN: called CC=1 SCAR=0.0
458  
459 # determine addresses found in the "From" and "Sender" headers
460 0 my $author = $self->message_originator->address;
461 0 my $sender = $self->message_sender->address;
462  
463 # fetch the policy
464 0 return Mail::DKIM::DkPolicy->fetch(
465 Protocol => 'dns',
466 Author => $author,
467 Sender => $sender,
468 );
469 }
470  
471  
472 0 ▶sub policies {
Subroutine policies: not called CC=3 SCAR=24.8
Pod documented
473 0 my $self = shift;
474  
475 0 my $sender_policy = eval { $self->fetch_sender_policy() };
476 0 my $author_policy = eval { $self->fetch_author_policy() };
477 return (
478 0 ▶ $sender_policy ? $sender_policy : (),
Branch: 2 branches
BranchTrueFalseTotal
$sender_policy ? : 0 0 0
$author_policy ? : 0 0 0
479 $author_policy ? $author_policy : (),
480 $self->fetch_author_domain_policies(),
481 );
482 }
483  
484  
485  
486  
487 4 ▶sub signatures {
Subroutine signatures: called CC=2 SCAR=7.0
Pod documented
488 4 my $self = shift;
489 4 ▶ croak 'unexpected argument' if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 4 4
490  
491 4 return @{ $self->{signatures} };
492 }
493  
494 6 1;
495  
496 __END__
« DKIM/Signer.pm ↑ Summary DKIM/Canonicalization/Base.pm »