Authentication/Handler/DKIM.pm

filter: Statementstmt 77.2% 224 / 290 Branchbran 57.5% 76 / 132 Conditioncond 49.1% 29 / 59 MC/DCmcdc 21.2% 7 / 33 Subroutinesub 95.0% 19 / 20 Podpod 10.0% 1 / 10 totaltotal 65.4% 356 / 544 CC 93 SCAR 45.5
CC
93
Cov
68%
eom_callback
159.9
_check_error
72.0
header_callback
13.8
CRAP 95.0
« Authentication/Handler/DMARC.pm ↑ Summary Authentication.pm »
1 package Mail::Milter::Authentication::Handler::DKIM;
2 43 ▶use 5.20.0;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 43 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 43 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 43 ▶use Mail::Milter::Authentication::Pragmas;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 # ABSTRACT: Handler class for DKIM
7 43 our $VERSION = '4.20261111'; # VERSION
8 43 ▶use base 'Mail::Milter::Authentication::Handler';
Subroutine BEGIN: called CC=1 SCAR=0.0
9 43 ▶use Mail::DKIM 1.20200824;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 43 ▶use Mail::DKIM::DNS;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 43 ▶use Mail::DKIM::KeyValueList;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 43 ▶use Mail::DKIM::Verifier;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 1 ▶sub default_config {
Subroutine default_config: called CC=1 SCAR=0.0
Pod undocumented
15 return {
16 1 'hide_none' => 0,
17 'hide_domainkeys' => 0,
18 'check_adsp' => 1,
19 'show_default_adsp' => 0,
20 'adsp_hide_none' => 0,
21 'extra_properties' => 0,
22 'no_strict' => 0,
23 'early_lookup_limit' => 10,
24 };
25 }
26  
27 1 ▶sub grafana_rows {
Subroutine grafana_rows: called CC=1 SCAR=0.0
Pod undocumented
28 1 my ( $self ) = @_;
29 1 my @rows;
30 1 push @rows, $self->get_json( 'DKIM_metrics' );
31 1 return \@rows;
32 }
33  
34 75 ▶sub register_metrics {
Subroutine register_metrics: called CC=1 SCAR=0.0
Pod documented
35 return {
36 75 'dkim_total' => 'The number of emails processed for DKIM',
37 'dkim_signatures' => 'The number of signatures processed for DKIM',
38 };
39 }
40  
41 256 ▶sub envfrom_callback {
Subroutine envfrom_callback: called CC=1 SCAR=0.0
Pod undocumented
42 256 my ( $self, $env_from ) = @_;
43 256 $self->{'failmode'} = 0;
44 256 $self->{'headers'} = [];
45 256 $self->{'has_dkim'} = 0;
46 256 $self->{'valid_domains'} = {};
47 256 $self->{'early_lookups'} = {};
48 256 $self->{'carry'} = q{};
49 256 $self->destroy_object('dkim');
50 }
51  
52 36 ▶sub show_domainkeys {
Subroutine show_domainkeys: called CC=3 SCAR=15.1
Pod undocumented
53 36 my ( $self ) = @_;
54 36 my $config = $self->handler_config();
55 36 ▶ return 1 if ! exists $config->{'hide_domainkeys'};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $config->{"hide_domainkeys"} 36 0 36
56 0 ▶ return 0 if $config->{'hide_domainkeys'};
Branch: 1 branch
BranchTrueFalseTotal
if $config->{"hide_domainkeys"} 0 0 0
57 0 return 1;
58 }
59  
60 1810 ▶sub header_callback {
Subroutine header_callback: called CC=13 SCAR=26.2
Pod undocumented
61 1810 my ( $self, $header, $value, $original ) = @_;
62 1810 ▶ return if ( $self->{'failmode'} );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"failmode"} 0 1810 1810
63 1810 my $EOL = "\015\012";
64 1810 my $dkim_chunk = $original . $EOL;
65 1810 $dkim_chunk =~ s/\015?\012/$EOL/g;
66 1810 push @{$self->{'headers'}} , $dkim_chunk;
67  
68 1810 ▶ if ( lc($header) eq 'dkim-signature' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (lc $header eq "dkim-signature") 257 1553 1810
69 257 $self->{'has_dkim'} = 1;
70  
71 257 my $parsed = eval{ Mail::DKIM::KeyValueList->parse( $value ) };
72 257 $self->handle_exception( $@ );
73 257 ▶ if ( $parsed ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($parsed) 257 0 257
74 257 my $domain = $parsed->get_tag('d');
75 257 my $selector = $parsed->get_tag('s');
76 257 ▶ if ( defined $selector && defined $domain ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $selector and defined $domain) 257 0 257
Condition33%1/3
defined $selector and defined $domain
!ll&&!rl&&r
00257
MC/DC0%0/2
defined $selector and defined $domain
defined $selector defined $domain
Truth table33%1/3
A and B
A= defined $selectorB= defined $domain
ABresult
0X0
100
111
77 257 my $config = $self->handler_config();
78 257 ▶ my $lookup_limit = $config->{'early_lookup_limit'} // 10;
Condition100%2/2
$config->{"early_lookup_limit"} // 10
l!l
40217
MC/DC100%1/1
$config->{"early_lookup_limit"} // 10
$config->{"early_lookup_limit"}
Truth table100%2/2
A
A= $config->{"early_lookup_limit"}
Aresult
11
00
79 257 my @lookups = ( $selector.'._domainkey.'.$domain );
80 257 ▶ push @lookups, '_adsp._domainkey.'.$domain if $config->{'check_adsp'};
Branch: 1 branch
BranchTrueFalseTotal
if $config->{"check_adsp"} 95 162 257
81 257 my $resolver = $self->get_object('resolver');
82 LOOKUP:
83 257 foreach my $lookup ( @lookups ) {
84 317 ▶ next LOOKUP if $self->{'early_lookups'}->{ lc $lookup };
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"early_lookups"}{lc $lookup} 19 298 317
85 298 ▶ last LOOKUP if scalar keys $self->{'early_lookups'}->%* >= $lookup_limit;
Branch: 1 branch
BranchTrueFalseTotal
if scalar keys %{$$self{"early_lookups"}} >= $lookup_limit 62 236 298
86 236 $self->{'early_lookups'}->{ lc $lookup } = 1;
87 236 eval{ $resolver->bgsend( $lookup, 'TXT' ) };
88 236 $self->handle_exception( $@ );
89 236 $self->dbgout( 'DNSEarlyLookup', "$lookup TXT", LOG_DEBUG );
90 }
91 }
92 }
93 }
94 1810 ▶ if ( lc($header) eq 'domainkey-signature' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (lc $header eq "domainkey-signature") 0 1810 1810
95 0 ▶ $self->{'has_dkim'} = 1 if $self->show_domainkeys();
Branch: 1 branch
BranchTrueFalseTotal
if $self->show_domainkeys 0 0 0
96 }
97 }
98  
99 249 ▶sub eoh_callback {
Subroutine eoh_callback: called CC=7 SCAR=21.1
Pod undocumented
100 249 my ($self) = @_;
101 249 ▶ return if ( $self->{'failmode'} );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"failmode"} 0 249 249
102 249 my $config = $self->handler_config();
103  
104 249 ▶ if ( $self->{'has_dkim'} == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'has_dkim'} == 0) { } 115 134 249
105 115 $self->metric_count( 'dkim_total', { 'result' => 'none' } );
106 115 $self->dbgout( 'DKIMResult', 'No DKIM headers', LOG_DEBUG );
107 115 ▶ if ( !( $config->{'hide_none'} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($config->{"hide_none"}) 108 7 115
108 108 my $header = Mail::AuthenticationResults::Header::Entry->new()->set_key( 'dkim' )->safe_set_value( 'none' );
109 108 $header->add_child( Mail::AuthenticationResults::Header::Comment->new()->safe_set_value( 'no signatures found' ) );
110 108 $self->add_auth_header( $header );
111 }
112 115 delete $self->{'headers'};
113 }
114 else {
115  
116 134 my $dkim;
117 134 eval {
118 134 my $UseStrict = 1;
119 134 ▶ if ( $config->{ 'no_strict' } ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($config->{"no_strict"}) 2 132 134
120 2 $UseStrict = 0;
121 }
122 134 $dkim = Mail::DKIM::Verifier->new( 'Strict' => $UseStrict );
123 134 my $resolver = $self->get_object('resolver');
124 134 Mail::DKIM::DNS::resolver($resolver);
125 134 $self->set_object('dkim', $dkim, 1);
126 };
127 134 ▶ if ( my $error = $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $error = $@) 0 134 134
128 0 $self->handle_exception( $error );
129 0 $self->log_error( 'DKIM Setup Error ' . $error );
130 0 $self->{'failmode'} = 1;
131 0 $self->_check_error( $error );
132 0 $self->metric_count( 'dkim_total', { 'result' => 'error' } );
133 0 delete $self->{'headers'};
134 0 return;
135 }
136  
137 134 eval {
138 $dkim->PRINT( join q{},
139 134 @{ $self->{'headers'} },
140 "\015\012",
141 );
142 };
143 134 ▶ if ( my $error = $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $error = $@) 0 134 134
144 0 $self->handle_exception( $error );
145 0 $self->log_error( 'DKIM Headers Error ' . $error );
146 0 $self->{'failmode'} = 1;
147 0 $self->_check_error( $error );
148 0 $self->metric_count( 'dkim_total', { 'result' => 'error' } );
149 }
150  
151 134 delete $self->{'headers'};
152 }
153  
154 249 $self->{'carry'} = q{};
155 }
156  
157 247 ▶sub body_callback {
Subroutine body_callback: called CC=6 SCAR=21.3
Pod undocumented
158 247 my ( $self, $body_chunk ) = @_;
159 247 ▶ return if ( $self->{'failmode'} );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"failmode"} 0 247 247
160 247 ▶ return if ( $self->{'has_dkim'} == 0 );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"has_dkim"} == 0 113 134 247
161 134 my $EOL = "\015\012";
162  
163 134 my $dkim_chunk;
164 134 ▶ if ( $self->{'carry'} ne q{} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'carry'} ne '') { } 0 134 134
165 0 $dkim_chunk = $self->{'carry'} . $body_chunk;
166 0 $self->{'carry'} = q{};
167 }
168 else {
169 134 $dkim_chunk = $body_chunk;
170 }
171  
172 134 ▶ if ( substr( $dkim_chunk, -1 ) eq "\015" ) {
Branch: 1 branch
BranchTrueFalseTotal
if (substr($dkim_chunk, -1) eq "\r") 0 134 134
173 0 $self->{'carry'} = "\015";
174 0 $dkim_chunk = substr( $dkim_chunk, 0, -1 );
175 }
176  
177 134 $dkim_chunk =~ s/\015?\012/$EOL/g;
178  
179 134 my $dkim = $self->get_object('dkim');
180 134 eval {
181 134 $dkim->PRINT( $dkim_chunk );
182 };
183 134 ▶ if ( my $error = $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $error = $@) 0 134 134
184 0 $self->handle_exception( $error );
185 0 $self->log_error( 'DKIM Body Error ' . $error );
186 0 $self->{'failmode'} = 1;
187 0 $self->_check_error( $error );
188 0 $self->metric_count( 'dkim_total', { 'result' => 'error' } );
189 }
190 }
191  
192 249 ▶sub eom_callback {
Subroutine eom_callback: called CC=61 SCAR=50.7
Pod undocumented
193 249 my ($self) = @_;
194  
195 249 ▶ return if ( $self->{'has_dkim'} == 0 );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"has_dkim"} == 0 115 134 249
196 134 ▶ return if ( $self->{'failmode'} );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"failmode"} 0 134 134
197  
198 134 my $config = $self->handler_config();
199  
200 134 my $dkim = $self->get_object('dkim');
201  
202 134 eval {
203 134 $dkim->PRINT( $self->{'carry'} );
204 134 $dkim->CLOSE();
205 134 $self->check_timeout();
206  
207 134 my $dkim_result = $dkim->result;
208 134 my $dkim_result_detail = $dkim->result_detail;
209  
210 134 $self->metric_count( 'dkim_total', { 'result' => $dkim_result } );
211  
212 134 $self->dbgout( 'DKIMResult', $dkim_result_detail, LOG_DEBUG );
213  
214 134 ▶ if ( !$dkim->signatures() ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($dkim->signatures) 0 134 134
215 0 ▶ if ( !( $config->{'hide_none'} && $dkim_result eq 'none' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($config->{"hide_none"} and $dkim_result eq "none") 0 0 0
Condition0%0/3
$config->{"hide_none"} and $dkim_result eq "none"
!ll&&!rl&&r
000
MC/DC0%0/2
$config->{"hide_none"} and $dkim_result eq "none"
$config->{"hide_none"} $dkim_result eq "none"
Truth table0%0/3
A and B
A= $config->{"hide_none"}B= $dkim_result eq "none"
ABresult
0X0
100
111
216 0 my $header = Mail::AuthenticationResults::Header::Entry->new()->set_key( 'dkim' )->safe_set_value( $dkim_result );
217 0 $header->add_child( Mail::AuthenticationResults::Header::Comment->new()->safe_set_value( 'no signatures found' ) );
218 0 $self->add_auth_header( $header );
219 }
220 }
221 134 foreach my $signature ( $dkim->signatures() ) {
222  
223 166 my $otype = ref $signature;
224 166 ▶ my $type =
Branch: 2 branches
BranchTrueFalseTotal
$otype eq 'Mail::DKIM::DkSignature' ? : 0 166 166
$otype eq 'Mail::DKIM::Signature' ? : 166 0 166
225 $otype eq 'Mail::DKIM::DkSignature' ? 'domainkeys'
226 : $otype eq 'Mail::DKIM::Signature' ? 'dkim'
227 : 'dkim';
228 166 $self->dbgout( 'DKIMSignatureType', $type, LOG_DEBUG );
229  
230 166 $self->dbgout( 'DKIMSignatureDomain', $signature->domain, LOG_DEBUG );
231 166 $self->dbgout( 'DKIMSignatureIdentity', $signature->identity, LOG_DEBUG );
232 166 $self->dbgout( 'DKIMSignatureResult', $signature->result_detail, LOG_DEBUG );
233 166 my $signature_result = $signature->result();
234 166 my $signature_result_detail = $signature->result_detail();
235  
236 166 ▶ if ( $signature_result eq 'pass' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($signature_result eq "pass") 101 65 166
237 101 $self->{'valid_domains'}->{ lc $signature->domain } = 1;
238 }
239  
240 166 ▶ if ( $signature_result eq 'invalid' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($signature_result eq "invalid") 24 142 166
241 24 ▶ if ( $signature_result_detail =~ /DNS query timeout for (.*) at / ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($signature_result_detail =~ /DNS query timeout for (.*) at /u) 0 24 24
242 0 my $timeout_domain = $1;
243 0 $self->log_error( "TIMEOUT DETECTED: in DKIM result: $timeout_domain" );
244 0 $signature_result_detail = "DNS query timeout for $timeout_domain";
245 }
246 }
247  
248 166 my $result_comment = q{};
249 166 ▶ if ( $signature_result ne 'pass' and $signature_result ne 'none' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($signature_result ne "pass" and $signature_result ne "none") 65 101 166
Condition66%2/3
$signature_result ne "pass" and $signature_result ne "none"
!ll&&!rl&&r
101065
MC/DC50%1/2
$signature_result ne "pass" and $signature_result ne "none"
$signature_result ne "pass" $signature_result ne "none"
Truth table66%2/3
A and B
A= $signature_result ne "pass"B= $signature_result ne "none"
ABresult
0X0
100
111
250 65 $signature_result_detail =~ /$signature_result \((.*)\)/;
251 65 ▶ if ( $1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($1) 65 0 65
252 65 $result_comment = $1 . ', ';
253 }
254 }
255 166 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
unless ($config->{"hide_none"} and $signature_result eq "none") 166 0 166
Condition66%2/3
$config->{"hide_none"} and $signature_result eq "none"
!ll&&!rl&&r
146200
MC/DC0%0/2
$config->{"hide_none"} and $signature_result eq "none"
$config->{"hide_none"} $signature_result eq "none"
Truth table66%2/3
A and B
A= $config->{"hide_none"}B= $signature_result eq "none"
ABresult
0X0
100
111
256 !(
257 $config->{'hide_none'} && $signature_result eq 'none'
258 )
259 )
260 {
261  
262 166 ▶ my $selector = eval{ $signature->selector } // q{};
Condition50%1/2
eval { do { $signature->selector } } // ""
l!l
1660
MC/DC0%0/1
eval { do { $signature->selector } } // ""
eval { do { $signature->selector } }
Truth table50%1/2
A
A= eval { do { $signature->selector } }
Aresult
11
00
263 166 my $key = eval {$signature->get_public_key()};
264 166 ▶ my $key_type = eval{ $key->type() } // 'unknown';
Condition50%1/2
eval { do { $key->type } } // "unknown"
l!l
1660
MC/DC0%0/1
eval { do { $key->type } } // "unknown"
eval { do { $key->type } }
Truth table50%1/2
A
A= eval { do { $key->type } }
Aresult
11
00
265 # Key size for ed25519 does not make sense
266 166 ▶ my $key_size = $key_type eq 'rsa' ? ( eval{ $key->size() } // 0 ) : 0;
Branch: 1 branch
BranchTrueFalseTotal
$key_type eq 'rsa' ? : 166 0 166
Condition50%1/2
eval { do { $key->size } } // 0
l!l
1660
MC/DC0%0/1
eval { do { $key->size } } // 0
eval { do { $key->size } }
Truth table50%1/2
A
A= eval { do { $key->size } }
Aresult
11
00
267  
268 166 ▶ my $hash_algorithm = eval { $signature->hash_algorithm(); } // '';
Condition50%1/2
eval { do { $signature->hash_algorithm } } // ""
l!l
1660
MC/DC0%0/1
eval { do { $signature->hash_algorithm } } // ""
eval { do { $signature->hash_algorithm } }
Truth table50%1/2
A
A= eval { do { $signature->hash_algorithm } }
Aresult
11
00
269 166 ▶ my $canonicalization = eval { $signature->canonicalization(); } // '';
Condition50%1/2
eval { do { $signature->canonicalization } } // ""
l!l
1660
MC/DC0%0/1
eval { do { $signature->canonicalization } } // ""
eval { do { $signature->canonicalization } }
Truth table50%1/2
A
A= eval { do { $signature->canonicalization } }
Aresult
11
00
270  
271 166 my @key_data_parts;
272 166 ▶ push @key_data_parts, $key_size . '-bit' if $key_size;
Branch: 1 branch
BranchTrueFalseTotal
if $key_size 166 0 166
273 166 push @key_data_parts, "$key_type key";
274 166 ▶ push @key_data_parts, $hash_algorithm if $hash_algorithm;
Branch: 1 branch
BranchTrueFalseTotal
if $hash_algorithm 166 0 166
275 166 my $key_data = join ' ', @key_data_parts;
276  
277 166 $self->metric_count( 'dkim_signatures', {
278 'type' => $type,
279 'result' => $signature_result,
280 'key_size' => $key_size,
281 'key_type' => $key_type,
282 'hash_algorithm' => $hash_algorithm,
283 'canonicalization' => $canonicalization,
284 } );
285  
286 166 ▶ if ( $type eq 'domainkeys' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq 'domainkeys') { } 0 166 166
287 0 ▶ if ( $self->show_domainkeys() ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->show_domainkeys) 0 0 0
288 0 my $header = Mail::AuthenticationResults::Header::Entry->new()->set_key( $type )->safe_set_value( $signature_result );
289 0 $header->add_child( Mail::AuthenticationResults::Header::Comment->new()->safe_set_value( $result_comment . $key_data ) );
290 0 $header->add_child( Mail::AuthenticationResults::Header::SubEntry->new()->set_key( 'header.d' )->safe_set_value( $signature->domain() ) );
291 0 $header->add_child( Mail::AuthenticationResults::Header::SubEntry->new()->set_key( 'header.b' )->safe_set_value( substr( $signature->data(), 0, 8 ) ) );
292 0 ▶ if ( $config->{'extra_properties'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($config->{"extra_properties"}) 0 0 0
293 0 ▶ $header->add_child( Mail::AuthenticationResults::Header::SubEntry->new()->set_key( 'x-bits' )->safe_set_value( $key_size ) ) if $key_size;
Branch: 1 branch
BranchTrueFalseTotal
if $key_size 0 0 0
294 0 $header->add_child( Mail::AuthenticationResults::Header::SubEntry->new()->set_key( 'x-keytype' )->safe_set_value( $key_type ) );
295 0 ▶ $header->add_child( Mail::AuthenticationResults::Header::SubEntry->new()->set_key( 'x-algorithm' )->safe_set_value( $hash_algorithm ) ) if $hash_algorithm;
Branch: 1 branch
BranchTrueFalseTotal
if $hash_algorithm 0 0 0
296 0 $header->add_child( Mail::AuthenticationResults::Header::SubEntry->new()->set_key( 'x-selector' )->safe_set_value( $selector ) );
297 }
298 0 $self->add_auth_header($header);
299 }
300 }
301 else {
302 166 my $header = Mail::AuthenticationResults::Header::Entry->new()->set_key( $type )->safe_set_value( $signature_result );
303 166 $header->add_child( Mail::AuthenticationResults::Header::Comment->new()->safe_set_value( $result_comment . $key_data ) );
304 166 $header->add_child( Mail::AuthenticationResults::Header::SubEntry->new()->set_key( 'header.d' )->safe_set_value( $signature->domain() ) );
305 166 $header->add_child( Mail::AuthenticationResults::Header::SubEntry->new()->set_key( 'header.i' )->safe_set_value( $signature->identity() ) );
306 166 $header->add_child( Mail::AuthenticationResults::Header::SubEntry->new()->set_key( 'header.b' )->safe_set_value( substr( $signature->data(), 0, 8 ) ) );
307 166 ▶ $header->add_child( Mail::AuthenticationResults::Header::SubEntry->new()->set_key( 'header.a' )->safe_set_value( $key_type . '-' . $hash_algorithm ) ) if ($key_type && $hash_algorithm);
Branch: 1 branch
BranchTrueFalseTotal
if $key_type and $hash_algorithm 166 0 166
Condition33%1/3
$key_type and $hash_algorithm
!ll&&!rl&&r
00166
MC/DC0%0/2
$key_type and $hash_algorithm
$key_type $hash_algorithm
Truth table33%1/3
A and B
A= $key_typeB= $hash_algorithm
ABresult
0X0
100
111
308 166 $header->add_child( Mail::AuthenticationResults::Header::SubEntry->new()->set_key( 'header.s' )->safe_set_value( $selector ) );
309 166 ▶ if ( $config->{'extra_properties'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($config->{"extra_properties"}) 12 154 166
310 12 ▶ $header->add_child( Mail::AuthenticationResults::Header::SubEntry->new()->set_key( 'x-bits' )->safe_set_value( $key_size ) ) if $key_size;
Branch: 1 branch
BranchTrueFalseTotal
if $key_size 12 0 12
311 }
312 166 ▶ if ( $config->{'log_dns_record'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($config->{"log_dns_record"}) 2 164 166
313 2 eval {
314 2 my $dkim_dns_name = $selector . '._domainkey.' . $signature->domain();
315 2 my $resolver = $self->get_object('resolver');
316 2 my $reply = $resolver->query( $dkim_dns_name, 'TXT' );
317 2 ▶ if ( $reply ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($reply) 2 0 2
318 2 my @txt_parts;
319 2 for my $rr ( $reply->answer ) {
320 2 ▶ next unless $rr->type eq 'TXT';
Branch: 1 branch
BranchTrueFalseTotal
unless $rr->type eq "TXT" 0 2 2
321 2 push @txt_parts, join( '', $rr->txtdata );
322 }
323 2 ▶ if ( @txt_parts ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@txt_parts) 2 0 2
324 2 $header->add_child( Mail::AuthenticationResults::Header::Comment->new()->safe_set_value( 'x-dns-record=' . $self->escape_non_printable_ascii( join( ' ', @txt_parts ) ) ) );
325 }
326 }
327 };
328 2 $self->handle_exception( $@ );
329 }
330 166 $self->add_auth_header($header);
331 }
332 }
333 166 $self->check_timeout();
334 }
335  
336 # the alleged author of the email may specify how to handle email
337 134 ▶ if ( $config->{'check_adsp'}
Branch: 1 branch
BranchTrueFalseTotal
if ($config->{"check_adsp"} and $self->is_local_ip_address == 0 and $self->is_trusted_ip_address == 0 and $self->is_authenticated == 0) 36 98 134
Condition88%8/9
$config->{"check_adsp"} and $self->is_local_ip_address == 0 and $self->is_trusted_ip_address == 0 and $self->is_authenticated == 0
!ll&&!rl&&r
98036
$config->{"check_adsp"} and $self->is_local_ip_address == 0 and $self->is_trusted_ip_address == 0
!ll&&!rl&&r
96236
$config->{"check_adsp"} and $self->is_local_ip_address == 0
!ll&&!rl&&r
88838
MC/DC75%3/4
$config->{"check_adsp"} and $self->is_local_ip_address == 0 and $self->is_trusted_ip_address == 0 and $self->is_authenticated == 0
$config->{"check_adsp"} $self->is_local_ip_address == 0 $self->is_trusted_ip_address == 0 $self->is_authenticated == 0
Truth table80%4/5
A and B and C and D
A= $config->{"check_adsp"}B= $self->is_local_ip_address == 0C= $self->is_trusted_ip_address == 0D= $self->is_authenticated == 0
ABCDresult
0XXX0
10XX0
110X0
11100
11111
338 && ( $self->is_local_ip_address() == 0 )
339 && ( $self->is_trusted_ip_address() == 0 )
340 && ( $self->is_authenticated() == 0 ) )
341 {
342 POLICY:
343 36 foreach my $policy ( $dkim->policies() ) {
344 108 my $apply = $policy->apply($dkim);
345 108 my $string = $policy->as_string();
346 108 ▶ my $location = $policy->location() || q{};
Condition100%2/2
$policy->location || ''
l!l
3672
MC/DC100%1/1
$policy->location || ''
$policy->location
Truth table100%2/2
A
A= $policy->location
Aresult
11
00
347 108 my $name = $policy->name();
348 108 my $default = $policy->is_implied_default_policy();
349  
350 108 my $otype = ref $policy;
351 108 ▶ my $type =
Branch: 3 branches
BranchTrueFalseTotal
$otype eq 'Mail::DKIM::AuthorDomainPolicy' ? : 36 72 108
$otype eq 'Mail::DKIM::DkimPolicy' ? : 36 36 72
$otype eq 'Mail::DKIM::DkPolicy' ? : 36 0 36
352 $otype eq 'Mail::DKIM::AuthorDomainPolicy' ? 'dkim-adsp'
353 : $otype eq 'Mail::DKIM::DkimPolicy' ? 'x-dkim-ssp'
354 : $otype eq 'Mail::DKIM::DkPolicy' ? 'x-dkim-dkssp'
355 : 'x-dkim-policy';
356  
357 108 $self->dbgout( 'DKIMPolicy', $apply, LOG_DEBUG );
358 108 $self->dbgout( 'DKIMPolicyString', $string, LOG_DEBUG );
359 108 $self->dbgout( 'DKIMPolicyLocation', $location, LOG_DEBUG );
360 108 $self->dbgout( 'DKIMPolicyName', $name, LOG_DEBUG );
361 108 ▶ $self->dbgout( 'DKIMPolicyDefault', $default ? 'yes' : 'no', LOG_DEBUG );
Branch: 1 branch
BranchTrueFalseTotal
$default ? : 72 36 108
362  
363 108 ▶ next POLICY if ( ( $type eq 'x-dkim-dkssp' ) && ( ! $self->show_domainkeys() ) );
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "x-dkim-dkssp" and not $self->show_domainkeys 0 108 108
Condition66%2/3
$type eq "x-dkim-dkssp" and not $self->show_domainkeys
!ll&&!rl&&r
72360
MC/DC0%0/2
$type eq "x-dkim-dkssp" and not $self->show_domainkeys
$type eq "x-dkim-dkssp" not $self->show_domainkeys
Truth table66%2/3
A and not(B)
A= $type eq "x-dkim-dkssp"B= not $self->show_domainkeys
ABresult
0X0
100
111
364  
365 108 ▶ my $result =
Branch: 3 branches
BranchTrueFalseTotal
$apply eq 'accept' ? : 72 36 108
$apply eq 'reject' ? : 0 36 36
$apply eq 'neutral' ? : 36 0 36
366 $apply eq 'accept' ? 'pass'
367 : $apply eq 'reject' ? 'discard'
368 : $apply eq 'neutral' ? 'unknown'
369 : 'unknown';
370  
371 108 ▶ if ( ! ( $config->{'adsp_hide_none'} && $result eq 'none' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($config->{"adsp_hide_none"} and $result eq "none") 108 0 108
Condition66%2/3
$config->{"adsp_hide_none"} and $result eq "none"
!ll&&!rl&&r
84240
MC/DC0%0/2
$config->{"adsp_hide_none"} and $result eq "none"
$config->{"adsp_hide_none"} $result eq "none"
Truth table66%2/3
A and B
A= $config->{"adsp_hide_none"}B= $result eq "none"
ABresult
0X0
100
111
372 108 ▶ if ( ( ! $default ) or $config->{'show_default_adsp'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $default or $config->{"show_default_adsp"}) 36 72 108
Condition66%2/3
not $default or $config->{"show_default_adsp"}
l!l&&r!l&&!r
36072
MC/DC50%1/2
not $default or $config->{"show_default_adsp"}
not $default $config->{"show_default_adsp"}
Truth table66%2/3
not(A) or B
A= not $defaultB= $config->{"show_default_adsp"}
ABresult
1X1
011
000
373 36 my $header = Mail::AuthenticationResults::Header::Entry->new()->set_key( $type )->safe_set_value( $result );
374 36 ▶ my $comment = ( $default ? 'default ' : q{} )
Branch: 2 branches
BranchTrueFalseTotal
$default ? : 0 36 36
$location ? : 36 0 36
375 . "$name policy"
376 . ( $location ? " from $location" : q{} )
377 # . ( $string ? ", $string" : q{} )
378 ;
379 36 $header->add_child( Mail::AuthenticationResults::Header::Comment->new()->safe_set_value( $comment ) );
380 36 $self->add_auth_header( $header );
381 }
382 }
383 108 $self->check_timeout();
384 }
385 }
386 };
387 134 ▶ if ( my $error = $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $error = $@) 0 134 134
388 0 $self->handle_exception( $error );
389  
390 # Also in DMARC module
391 0 $self->log_error( 'DKIM EOM Error ' . $error );
392 0 $self->{'failmode'} = 1;
393 0 $self->_check_error( $error );
394 0 $self->metric_count( 'dkim_total', { 'result' => 'error' } );
395 0 return;
396 }
397 }
398  
399 126 ▶sub close_callback {
Subroutine close_callback: called CC=1 SCAR=0.0
Pod undocumented
400 126 my ( $self ) = @_;
401 126 delete $self->{'failmode'};
402 126 delete $self->{'headers'};
403 126 delete $self->{'body'};
404 126 delete $self->{'carry'};
405 126 delete $self->{'has_dkim'};
406 126 delete $self->{'valid_domains'};
407 126 delete $self->{'early_lookups'};
408 126 $self->destroy_object('dkim');
409 }
410  
411 0 ▶sub _check_error {
Subroutine _check_error: not called CC=8 SCAR=42.8
412 0 my ( $self, $error ) = @_;
413 0 ▶ if ( $error =~ /^DNS error: query timed out/
Branch: 3 branches
BranchTrueFalseTotal
if ($error =~ /^DNS error: query timed out/u or $error =~ /^DNS query timeout/u) { } 0 0 0
elsif ($error =~ /^DNS error: SERVFAIL/u) { } 0 0 0
elsif ($error =~ /^no domain to fetch policy for$/u or $error =~ /^policy syntax error$/u or $error =~ /^empty domain label/u or $error =~ /^invalid name /u) { } 0 0 0
Condition0%0/3
$error =~ /^DNS error: query timed out/u or $error =~ /^DNS query timeout/u
l!l&&r!l&&!r
000
MC/DC0%0/2
$error =~ /^DNS error: query timed out/u or $error =~ /^DNS query timeout/u
$error =~ /^DNS error: query timed out/u $error =~ /^DNS query timeout/u
Truth table0%0/3
A or B
A= $error =~ /^DNS error: query timed out/uB= $error =~ /^DNS query timeout/u
ABresult
1X1
011
000
414 or $error =~ /^DNS query timeout/
415 ){
416 0 $self->log_error( 'Temp DKIM Error - ' . $error );
417 0 my $header = Mail::AuthenticationResults::Header::Entry->new()->set_key( 'dkim' )->safe_set_value( 'temperror' );
418 0 $header->add_child( Mail::AuthenticationResults::Header::Comment->new()->safe_set_value( 'dns timeout' ) );
419 0 $self->add_auth_header( $header );
420 }
421 elsif ( $error =~ /^DNS error: SERVFAIL/ ){
422 0 $self->log_error( 'Temp DKIM Error - ' . $error );
423 0 my $header = Mail::AuthenticationResults::Header::Entry->new()->set_key( 'dkim' )->safe_set_value( 'temperror' );
424 0 $header->add_child( Mail::AuthenticationResults::Header::Comment->new()->safe_set_value( 'dns servfail' ) );
425 0 $self->add_auth_header( $header );
426 }
427 ▶ elsif ( $error =~ /^no domain to fetch policy for$/
Condition0%0/9
$error =~ /^no domain to fetch policy for$/u or $error =~ /^policy syntax error$/u or $error =~ /^empty domain label/u or $error =~ /^invalid name /u
l!l&&r!l&&!r
000
$error =~ /^no domain to fetch policy for$/u or $error =~ /^policy syntax error$/u or $error =~ /^empty domain label/u
l!l&&r!l&&!r
000
$error =~ /^no domain to fetch policy for$/u or $error =~ /^policy syntax error$/u
l!l&&r!l&&!r
000
MC/DC0%0/4
$error =~ /^no domain to fetch policy for$/u or $error =~ /^policy syntax error$/u or $error =~ /^empty domain label/u or $error =~ /^invalid name /u
$error =~ /^no domain to fetch policy for$/u $error =~ /^policy syntax error$/u $error =~ /^empty domain label/u $error =~ /^invalid name /u
Truth table0%0/5
A or B or C or D
A= $error =~ /^no domain to fetch policy for$/uB= $error =~ /^policy syntax error$/uC= $error =~ /^empty domain label/uD= $error =~ /^invalid name /u
ABCDresult
1XXX1
01XX1
001X1
00011
00000
428 or $error =~ /^policy syntax error$/
429 or $error =~ /^empty domain label/
430 or $error =~ /^invalid name /
431 ){
432 0 $self->log_error( 'Perm DKIM Error - ' . $error );
433 0 my $header = Mail::AuthenticationResults::Header::Entry->new()->set_key( 'dkim' )->safe_set_value( 'permerror' );
434 0 $header->add_child( Mail::AuthenticationResults::Header::Comment->new()->safe_set_value( 'syntax or domain error' ) );
435 0 $self->add_auth_header( $header );
436 }
437 else {
438 0 $self->exit_on_close( 'Unexpected DKIM Error - ' . $error );
439 0 my $header = Mail::AuthenticationResults::Header::Entry->new()->set_key( 'dkim' )->safe_set_value( 'temperror' );
440 0 $self->add_auth_header( $header );
441 # Fill these in as they occur, but for unknowns err on the side of caution
442 # and tempfail/exit
443 0 $self->tempfail_on_error();
444 }
445 }
446  
447 43 1;
448  
449 __END__
« Authentication/Handler/DMARC.pm ↑ Summary Authentication.pm »