DKIM/Verifier.pm

filter: Statementstmt 85.9% 201 / 234 Branchbran 71.2% 67 / 94 Conditioncond 64.1% 25 / 39 MC/DCmcdc 48.0% 12 / 25 Subroutinesub 84.0% 21 / 25 Podpod 35.7% 5 / 14 totaltotal 76.8% 331 / 431 CC 64 SCAR 22.9
CC
64
Cov
80%
check_signature
21.8
_check_and_verify_signature
14.3
policies
12.0
CRAP 9.9
« DKIM/Signer.pm ↑ Summary DKIM/Canonicalization/Base.pm »
1 package Mail::DKIM::Verifier;
2 8 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 8 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 8 our $VERSION = '1.20261105'; # 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 8 ▶use Mail::DKIM::Signature;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 8 ▶use Mail::DKIM::DkSignature;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 8 ▶use Mail::Address;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18  
19  
20 8 ▶use base 'Mail::DKIM::Common';
Subroutine BEGIN: called CC=1 SCAR=0.0
21 8 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 8 our $MAX_SIGNATURES_TO_PROCESS = 50;
23  
24 91 ▶sub init {
Subroutine init: called CC=1 SCAR=0.0
Pod undocumented
25 91 my $self = shift;
26 91 $self->SUPER::init;
27 91 $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 402737 ▶sub handle_header {
Subroutine handle_header: called CC=5 SCAR=16.2
Pod undocumented
55 402737 my $self = shift;
56 402737 my ( $field_name, $contents, $line ) = @_;
57  
58 402737 $self->SUPER::handle_header( $field_name, $contents );
59  
60 402737 ▶ if ( lc($field_name) eq 'dkim-signature' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (lc $field_name eq "dkim-signature") 85 402652 402737
61 eval {
62 85 local $SIG{__DIE__};
63 85 my $signature = Mail::DKIM::Signature->parse($line);
64 84 $self->add_signature($signature);
65 84 1
66 85 ▶ } || 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 } 84 1 85
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 402737 ▶ if ( lc($field_name) eq 'domainkey-signature' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (lc $field_name eq "domainkey-signature") 17 402720 402737
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 101 ▶sub add_signature {
Subroutine add_signature: called CC=7 SCAR=19.5
Pod undocumented
98 101 my $self = shift;
99 101 ▶ croak 'wrong number of arguments' unless ( @_ == 1 );
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 1 0 101 101
100 101 my ($signature) = @_;
101  
102 # Set verification time if we have one
103 101 ▶ if ($self->{verify_time}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"verify_time"}) 1 100 101
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 101 ▶ return if ( @{ $self->{signatures} } > $MAX_SIGNATURES_TO_PROCESS );
Branch: 1 branch
BranchTrueFalseTotal
if @{$self->{"signatures"};} > $Mail::DKIM::Verifier::MAX_SIGNATURES_TO_PROCESS 0 101 101
110  
111 101 push @{ $self->{signatures} }, $signature;
112  
113 101 ▶ unless ( $self->check_signature($signature) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->check_signature($signature)) 14 87 101
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 87 $signature->fetch_public_key;
120  
121 # create a canonicalization filter and algorithm
122 87 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 87 );
128  
129 # an algorithm that wants the headers prior to the signature header
130 # canonicalizes the whole header from finish_header(), so only the
131 # others need each header field as it is parsed
132 87 ▶ push @{ $self->{header_algorithms} }, $algorithm
Branch: 1 branch
BranchTrueFalseTotal
unless $algorithm->wants_pre_signature_headers 15 72 87
133 unless $algorithm->wants_pre_signature_headers;
134  
135 # save the algorithm
136 87 ▶ $self->{algorithms} ||= [];
Condition100%2/2
$self->{"algorithms"} ||= []
l!l
1473
MC/DC100%1/1
$self->{"algorithms"} ||= []
$self->{"algorithms"}
Truth table100%2/2
A
A= $self->{"algorithms"}
Aresult
11
00
137 87 push @{ $self->{algorithms} }, $algorithm;
138 }
139  
140 101 ▶sub check_signature {
Subroutine check_signature: called CC=18 SCAR=30.8
Pod undocumented
141 101 my $self = shift;
142 101 ▶ croak 'wrong number of arguments' unless ( @_ == 1 );
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 1 0 101 101
143 101 my ($signature) = @_;
144  
145 101 ▶ unless ( $signature->check_version ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($signature->check_version) 1 100 101
146  
147 # unsupported version
148 1 ▶ if ( defined $signature->version ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $signature->version) { } 1 0 1
149 $self->{signature_reject_reason} =
150 1 'unsupported version ' . $signature->version;
151 }
152 else {
153 0 $self->{signature_reject_reason} = 'missing v tag';
154 }
155 1 return 0;
156 }
157  
158 100 ▶ unless ( $signature->algorithm
Branch: 1 branch
BranchTrueFalseTotal
unless ($signature->algorithm and $signature->get_algorithm_class($signature->algorithm)) 2 98 100
Condition66%2/3
$signature->algorithm and $signature->get_algorithm_class($signature->algorithm)
!ll&&!rl&&r
0298
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
159 && $signature->get_algorithm_class( $signature->algorithm ) )
160 {
161 # unsupported algorithm
162 2 $self->{signature_reject_reason} = 'unsupported algorithm';
163 2 ▶ if ( defined $signature->algorithm ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $signature->algorithm) 2 0 2
164 2 $self->{signature_reject_reason} .= ' ' . $signature->algorithm;
165 }
166 2 return 0;
167 }
168  
169 98 ▶ if ( $self->{Strict} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"Strict"}) 4 94 98
170 4 ▶ if ( $signature->algorithm eq 'rsa-sha1' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($signature->algorithm eq "rsa-sha1") 2 2 4
171 2 $self->{signature_reject_reason} = 'unsupported algorithm';
172 2 ▶ if ( defined $signature->algorithm ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $signature->algorithm) 2 0 2
173 2 $self->{signature_reject_reason} .= ' ' . $signature->algorithm;
174 }
175 2 return 0;
176 }
177 }
178  
179 96 ▶ unless ( $signature->check_canonicalization ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($signature->check_canonicalization) 2 94 96
180  
181 # unsupported canonicalization method
182 2 $self->{signature_reject_reason} = 'unsupported canonicalization';
183 2 ▶ if ( defined $signature->canonicalization ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $signature->canonicalization) 2 0 2
184 $self->{signature_reject_reason} .=
185 2 ' ' . $signature->canonicalization;
186 }
187 2 return 0;
188 }
189  
190 94 ▶ unless ( $signature->check_protocol ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($signature->check_protocol) 4 90 94
191  
192 # unsupported query protocol
193 $self->{signature_reject_reason} =
194 4 ▶ !defined( $signature->protocol )
Branch: 1 branch
BranchTrueFalseTotal
!defined($signature->protocol) ? : 0 4 4
195 ? 'missing q tag'
196 : 'unsupported query protocol, q=' . $signature->protocol;
197 4 return 0;
198 }
199  
200 90 ▶ unless ( $signature->check_expiration ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($signature->check_expiration) 3 87 90
201  
202 # signature has expired
203 3 $self->{signature_reject_reason} = 'signature is expired';
204 3 return 0;
205 }
206  
207 87 ▶ unless ( defined $signature->domain ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $signature->domain) 0 87 87
208  
209 # no domain specified
210 0 $self->{signature_reject_reason} = 'missing d tag';
211 0 return 0;
212 }
213  
214 87 ▶ if ( $signature->domain eq '' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($signature->domain eq "") 0 87 87
215  
216 # blank domain
217 0 $self->{signature_reject_reason} = 'invalid domain in d tag';
218 0 return 0;
219 }
220  
221 87 ▶ unless ( defined $signature->selector ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $signature->selector) 0 87 87
222  
223 # no selector specified
224 0 $self->{signature_reject_reason} = 'missing s tag';
225 0 return 0;
226 }
227  
228 87 return 1;
229 }
230  
231 60 ▶sub check_public_key {
Subroutine check_public_key: called CC=5 SCAR=16.1
Pod undocumented
232 60 my $self = shift;
233 60 ▶ croak 'wrong number of arguments' unless ( @_ == 2 );
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 2 0 60 60
234 60 my ( $signature, $public_key ) = @_;
235  
236 60 my $result = 0;
237 eval {
238 60 local $SIG{__DIE__};
239 60 $@ = undef;
240  
241 # HACK- I'm indecisive here about whether I want the
242 # check_foo functions to return false or to "die"
243 # on failure
244  
245 # check public key's allowed hash algorithms
246 60 $result =
247 $public_key->check_hash_algorithm( $signature->hash_algorithm );
248  
249 # HACK- DomainKeys signatures are allowed to have an empty g=
250 # tag in the public key
251 58 my $empty_g_means_wildcard = $signature->isa('Mail::DKIM::DkSignature');
252  
253 # check public key's granularity
254 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
255 $public_key->check_granularity( $signature->identity,
256 $empty_g_means_wildcard );
257  
258 58 ▶ die $@ if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 5 53 58
259 53 1
260 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
261 7 my $E = $@;
262 7 chomp $E;
263 7 $self->{signature_reject_reason} = "public key: $E";
264 };
265 60 return $result;
266 }
267  
268 # returns true if the i= tag is an address with a domain matching or
269 # a subdomain of the d= tag
270 #
271 87 ▶sub check_signature_identity {
Subroutine check_signature_identity: called CC=3 SCAR=12.3
Pod undocumented
272 87 my ($signature) = @_;
273  
274 87 my $d = $signature->domain;
275 87 my $i = $signature->identity;
276 87 ▶ if ( defined($i) && $i =~ /\@([^@]*)$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $i and $i =~ /\@([^\@]*)$/) 87 0 87
Condition33%1/3
defined $i and $i =~ /\@([^\@]*)$/
!ll&&!rl&&r
0087
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
277 87 return match_subdomain( $1, $d );
278 }
279 0 return 0;
280 }
281  
282 87 ▶sub match_subdomain {
Subroutine match_subdomain: called CC=2 SCAR=7.0
Pod undocumented
283 87 ▶ croak 'wrong number of arguments' unless ( @_ == 2 );
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 2 0 87 87
284 87 my ( $subdomain, $superdomain ) = @_;
285  
286 87 my $tmp = substr( ".$subdomain", -1 - length($superdomain) );
287 87 return ( lc ".$superdomain" eq lc $tmp );
288 }
289  
290 #
291 # called when the verifier has received the last of the message headers
292 # (body is still to come)
293 #
294 90 ▶sub finish_header {
Subroutine finish_header: called CC=9 SCAR=22.5
Pod undocumented
295 90 my $self = shift;
296  
297 # Signatures we found and were successfully parsed are stored in
298 # $self->{signatures}. If none were found, our result is "none".
299  
300 90 ▶ if ( @{ $self->{signatures} } == 0
Branch: 1 branch
BranchTrueFalseTotal
if (@{$self->{"signatures"};} == 0 and not defined $self->{"signature_reject_reason"}) 4 86 90
Condition66%2/3
@{$self->{"signatures"};} == 0 and not defined $self->{"signature_reject_reason"}
!ll&&!rl&&r
8604
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
301 && !defined( $self->{signature_reject_reason} ) )
302 {
303 4 $self->{result} = 'none';
304 4 return;
305 }
306  
307 # share the header indexes between the signatures
308 86 my $index = {};
309 86 foreach my $algorithm ( @{ $self->{algorithms} } ) {
310 $algorithm->finish_header(
311 Headers => $self->{headers},
312 87 HeaderIndex => $index
313 );
314 }
315  
316 # stop processing signatures that are already known to be invalid
317 86 @{ $self->{algorithms} } = grep {
318 87 my $sig = $_->signature;
319 87 ▶ !( $sig->result && $sig->result eq 'invalid' );
Condition33%1/3
$sig->result && $sig->result eq 'invalid'
!ll&&!rl&&r
8700
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
320 86 } @{ $self->{algorithms} };
321  
322 86 ▶ if ( @{ $self->{algorithms} } == 0
Branch: 1 branch
BranchTrueFalseTotal
if (@{$self->{"algorithms"};} == 0 and @{$self->{"signatures"};} > 0) 13 73 86
Condition66%2/3
@{$self->{"algorithms"};} == 0 and @{$self->{"signatures"};} > 0
!ll&&!rl&&r
73013
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
323 13 && @{ $self->{signatures} } > 0 )
324 {
325 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
326 $self->{details} = $self->{signatures}->[0]->{verify_details}
327 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
328 13 return;
329 }
330 }
331  
332 87 ▶sub _check_and_verify_signature {
Subroutine _check_and_verify_signature: called CC=14 SCAR=26.6
333 87 my $self = shift;
334 87 my ($algorithm) = @_;
335  
336 # check signature
337 87 my $signature = $algorithm->signature;
338 87 ▶ unless ( check_signature_identity($signature) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (check_signature_identity($signature)) 3 84 87
339 3 $self->{signature_reject_reason} = 'bad identity';
340 3 return ( 'invalid', $self->{signature_reject_reason} );
341 }
342  
343 # get public key
344 84 my $pkey;
345 84 eval { $pkey = $signature->get_public_key; 1 }
346 84 ▶ || 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 24 84
347 24 my $E = $@;
348 24 chomp $E;
349 24 $self->{signature_reject_reason} = "public key: $E";
350 24 return ( 'invalid', $self->{signature_reject_reason} );
351 };
352  
353 60 ▶ unless ( $self->check_public_key( $signature, $pkey ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->check_public_key($signature, $pkey)) 7 53 60
354 7 return ( 'invalid', $self->{signature_reject_reason} );
355 }
356  
357 # special handling for RSA signatures
358 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
359 53 ▶ if ($k eq 'rsa') {
Branch: 1 branch
BranchTrueFalseTotal
if ($k eq "rsa") 50 3 53
360 # make sure key is big enough
361 50 my $keysize = $pkey->cork->size * 8; # in bits
362 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
363 1 $self->{signature_reject_reason} = "Key length $keysize too short";
364 1 return ( 'fail', $self->{signature_reject_reason} );
365 }
366 }
367  
368 # verify signature
369 52 my $result;
370 my $details;
371 52 local $@ = undef;
372 eval {
373 52 ▶ $result = $algorithm->verify() ? 'pass' : 'fail';
Branch: 1 branch
BranchTrueFalseTotal
$algorithm->verify ? : 40 10 50
374 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
375 50 1
376 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
377  
378 # see also add_signature
379 2 chomp( my $E = $@ );
380 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
381 2 $E = $1;
382 }
383 elsif ( $E =~ /^(panic:.*?) at / ) {
384 0 $E = "OpenSSL $1";
385 }
386 elsif ( $E =~ /^FATAL: (.*) at / ) {
387 0 $E = "Ed25519 $1";
388 }
389 2 $result = 'fail';
390 2 $details = $E;
391 };
392 52 return ( $result, $details );
393 }
394  
395 90 ▶sub finish_body {
Subroutine finish_body: called CC=4 SCAR=13.9
Pod undocumented
396 90 my $self = shift;
397  
398 90 foreach my $algorithm ( @{ $self->{algorithms} } ) {
399  
400 # finish canonicalizing
401 87 $algorithm->finish_body;
402  
403 87 my ( $result, $details ) =
404 $self->_check_and_verify_signature($algorithm);
405  
406 # save the results of this signature verification
407 87 $algorithm->{result} = $result;
408 87 $algorithm->{details} = $details;
409 87 $algorithm->signature->result( $result, $details );
410  
411 # collate results ... ignore failed signatures if we already got
412 # one to pass
413 87 ▶ if ( !$self->{result} || $result eq 'pass' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->{"result"} or $result eq "pass") 75 12 87
Condition100%3/3
not $self->{"result"} or $result eq "pass"
l!l&&r!l&&!r
73212
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
414 75 $self->{signature} = $algorithm->signature;
415 75 $self->{result} = $result;
416 75 $self->{details} = $details;
417 }
418 }
419 }
420  
421  
422 0 ▶sub fetch_author_domain_policies {
Subroutine fetch_author_domain_policies: not called CC=2 SCAR=13.0
Pod documented
423 0 my $self = shift;
424 8 ▶ use Mail::DKIM::AuthorDomainPolicy;
Subroutine BEGIN: called CC=1 SCAR=0.0
425  
426 0 ▶ return () unless $self->{headers_by_name}->{from};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"headers_by_name"}{"from"} 0 0 0
427 0 my @list = Mail::Address->parse( $self->{headers_by_name}->{from} );
428 0 my @authors = map { $_->address } @list;
429  
430 # fetch the policies
431 return map {
432 0 Mail::DKIM::AuthorDomainPolicy->fetch(
433 Protocol => 'dns',
434 Author => $_,
435 )
436 } @authors;
437 }
438  
439  
440 0 ▶sub fetch_author_policy {
Subroutine fetch_author_policy: not called CC=2 SCAR=12.2
Pod documented
441 0 my $self = shift;
442 0 my ($author) = @_;
443 8 ▶ use Mail::DKIM::DkimPolicy;
Subroutine BEGIN: called CC=1 SCAR=0.0
444  
445 # determine address found in the "From"
446 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
447  
448 # fetch the policy
449 0 return Mail::DKIM::DkimPolicy->fetch(
450 Protocol => 'dns',
451 Author => $author,
452 );
453 }
454  
455  
456 0 ▶sub fetch_sender_policy {
Subroutine fetch_sender_policy: not called CC=1 SCAR=1.7
Pod documented
457 0 my $self = shift;
458 8 ▶ use Mail::DKIM::DkPolicy;
Subroutine BEGIN: called CC=1 SCAR=0.0
459  
460 # determine addresses found in the "From" and "Sender" headers
461 0 my $author = $self->message_originator->address;
462 0 my $sender = $self->message_sender->address;
463  
464 # fetch the policy
465 0 return Mail::DKIM::DkPolicy->fetch(
466 Protocol => 'dns',
467 Author => $author,
468 Sender => $sender,
469 );
470 }
471  
472  
473 0 ▶sub policies {
Subroutine policies: not called CC=3 SCAR=24.8
Pod documented
474 0 my $self = shift;
475  
476 0 my $sender_policy = eval { $self->fetch_sender_policy() };
477 0 my $author_policy = eval { $self->fetch_author_policy() };
478 return (
479 0 ▶ $sender_policy ? $sender_policy : (),
Branch: 2 branches
BranchTrueFalseTotal
$sender_policy ? : 0 0 0
$author_policy ? : 0 0 0
480 $author_policy ? $author_policy : (),
481 $self->fetch_author_domain_policies(),
482 );
483 }
484  
485  
486  
487  
488 4 ▶sub signatures {
Subroutine signatures: called CC=2 SCAR=7.0
Pod documented
489 4 my $self = shift;
490 4 ▶ croak 'unexpected argument' if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 4 4
491  
492 4 return @{ $self->{signatures} };
493 }
494  
495 8 1;
496  
497 __END__
« DKIM/Signer.pm ↑ Summary DKIM/Canonicalization/Base.pm »