Authentication/Handler/DKIM.pm

filter: Statementstmt 77.2% 224 / 290 Branchbran 59.0% 78 / 132 Conditioncond 50.8% 30 / 59 MC/DCmcdc 24.2% 8 / 33 Subroutinesub 95.0% 19 / 20 Podpod 10.0% 1 / 10 totaltotal 66.1% 360 / 544 CC 93 SCAR 44.9
CC
93
Cov
69%
eom_callback
148.3
_check_error
72.0
header_callback
13.8
CRAP 88.7
« Authentication.pm ↑ Summary Authentication/Protocol/Milter.pm »
1 package Mail::Milter::Authentication::Handler::DKIM;
2 44 ▶use 5.20.0;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 44 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 44 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 44 ▶use Mail::Milter::Authentication::Pragmas;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 # ABSTRACT: Handler class for DKIM
7 44 our $VERSION = '4.20261116'; # VERSION
8 44 ▶use base 'Mail::Milter::Authentication::Handler';
Subroutine BEGIN: called CC=1 SCAR=0.0
9 44 ▶use Mail::DKIM 1.20200824;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 44 ▶use Mail::DKIM::DNS;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 44 ▶use Mail::DKIM::KeyValueList;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 44 ▶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 76 ▶sub register_metrics {
Subroutine register_metrics: called CC=1 SCAR=0.0
Pod documented
35 return {
36 76 'dkim_total' => 'The number of emails processed for DKIM',
37 'dkim_signatures' => 'The number of signatures processed for DKIM',
38 };
39 }
40  
41 257 ▶sub envfrom_callback {
Subroutine envfrom_callback: called CC=1 SCAR=0.0
Pod undocumented
42 257 my ( $self, $env_from ) = @_;
43 257 $self->{'failmode'} = 0;
44 257 $self->{'headers'} = [];
45 257 $self->{'has_dkim'} = 0;
46 257 $self->{'valid_domains'} = {};
47 257 $self->{'early_lookups'} = {};
48 257 $self->{'carry'} = q{};
49 257 $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 1816 ▶sub header_callback {
Subroutine header_callback: called CC=13 SCAR=26.2
Pod undocumented
61 1816 my ( $self, $header, $value, $original ) = @_;
62 1816 ▶ return if ( $self->{'failmode'} );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"failmode"} 0 1816 1816
63 1816 my $EOL = "\015\012";
64 1816 my $dkim_chunk = $original . $EOL;
65 1816 $dkim_chunk =~ s/\015?\012/$EOL/g;
66 1816 push @{$self->{'headers'}} , $dkim_chunk;
67  
68 1816 ▶ if ( lc($header) eq 'dkim-signature' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (lc $header eq "dkim-signature") 258 1558 1816
69 258 $self->{'has_dkim'} = 1;
70  
71 258 my $parsed = eval{ Mail::DKIM::KeyValueList->parse( $value ) };
72 258 $self->handle_exception( $@ );
73 258 ▶ if ( $parsed ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($parsed) 258 0 258
74 258 my $domain = $parsed->get_tag('d');
75 258 my $selector = $parsed->get_tag('s');
76 258 ▶ if ( defined $selector && defined $domain ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $selector and defined $domain) 258 0 258
Condition33%1/3
defined $selector and defined $domain
!ll&&!rl&&r
00258
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 258 my $config = $self->handler_config();
78 258 ▶ my $lookup_limit = $config->{'early_lookup_limit'} // 10;
Condition100%2/2
$config->{"early_lookup_limit"} // 10
l!l
40218
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 258 my @lookups = ( $selector.'._domainkey.'.$domain );
80 258 ▶ push @lookups, '_adsp._domainkey.'.$domain if $config->{'check_adsp'};
Branch: 1 branch
BranchTrueFalseTotal
if $config->{"check_adsp"} 95 163 258
81 258 my $resolver = $self->get_object('resolver');
82 LOOKUP:
83 258 foreach my $lookup ( @lookups ) {
84 318 ▶ next LOOKUP if $self->{'early_lookups'}->{ lc $lookup };
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"early_lookups"}{lc $lookup} 19 299 318
85 299 ▶ last LOOKUP if scalar keys $self->{'early_lookups'}->%* >= $lookup_limit;
Branch: 1 branch
BranchTrueFalseTotal
if scalar keys %{$$self{"early_lookups"}} >= $lookup_limit 62 237 299
86 237 $self->{'early_lookups'}->{ lc $lookup } = 1;
87 237 eval{ $resolver->bgsend( $lookup, 'TXT' ) };
88 237 $self->handle_exception( $@ );
89 237 $self->dbgout( 'DNSEarlyLookup', "$lookup TXT", LOG_DEBUG );
90 }
91 }
92 }
93 }
94 1816 ▶ if ( lc($header) eq 'domainkey-signature' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (lc $header eq "domainkey-signature") 0 1816 1816
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 250 ▶sub eoh_callback {
Subroutine eoh_callback: called CC=7 SCAR=21.1
Pod undocumented
100 250 my ($self) = @_;
101 250 ▶ return if ( $self->{'failmode'} );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"failmode"} 0 250 250
102 250 my $config = $self->handler_config();
103  
104 250 ▶ if ( $self->{'has_dkim'} == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'has_dkim'} == 0) { } 115 135 250
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 135 my $dkim;
117 135 eval {
118 135 my $UseStrict = 1;
119 135 ▶ if ( $config->{ 'no_strict' } ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($config->{"no_strict"}) 2 133 135
120 2 $UseStrict = 0;
121 }
122 135 $dkim = Mail::DKIM::Verifier->new( 'Strict' => $UseStrict );
123 135 my $resolver = $self->get_object('resolver');
124 135 Mail::DKIM::DNS::resolver($resolver);
125 135 $self->set_object('dkim', $dkim, 1);
126 };
127 135 ▶ if ( my $error = $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $error = $@) 0 135 135
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 135 eval {
138 $dkim->PRINT( join q{},
139 135 @{ $self->{'headers'} },
140 "\015\012",
141 );
142 };
143 135 ▶ if ( my $error = $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $error = $@) 0 135 135
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 135 delete $self->{'headers'};
152 }
153  
154 250 $self->{'carry'} = q{};
155 }
156  
157 248 ▶sub body_callback {
Subroutine body_callback: called CC=6 SCAR=21.3
Pod undocumented
158 248 my ( $self, $body_chunk ) = @_;
159 248 ▶ return if ( $self->{'failmode'} );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"failmode"} 0 248 248
160 248 ▶ return if ( $self->{'has_dkim'} == 0 );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"has_dkim"} == 0 113 135 248
161 135 my $EOL = "\015\012";
162  
163 135 my $dkim_chunk;
164 135 ▶ if ( $self->{'carry'} ne q{} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'carry'} ne '') { } 0 135 135
165 0 $dkim_chunk = $self->{'carry'} . $body_chunk;
166 0 $self->{'carry'} = q{};
167 }
168 else {
169 135 $dkim_chunk = $body_chunk;
170 }
171  
172 135 ▶ if ( substr( $dkim_chunk, -1 ) eq "\015" ) {
Branch: 1 branch
BranchTrueFalseTotal
if (substr($dkim_chunk, -1) eq "\r") 0 135 135
173 0 $self->{'carry'} = "\015";
174 0 $dkim_chunk = substr( $dkim_chunk, 0, -1 );
175 }
176  
177 135 $dkim_chunk =~ s/\015?\012/$EOL/g;
178  
179 135 my $dkim = $self->get_object('dkim');
180 135 eval {
181 135 $dkim->PRINT( $dkim_chunk );
182 };
183 135 ▶ if ( my $error = $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $error = $@) 0 135 135
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 250 ▶sub eom_callback {
Subroutine eom_callback: called CC=61 SCAR=50.0
Pod undocumented
193 250 my ($self) = @_;
194  
195 250 ▶ return if ( $self->{'has_dkim'} == 0 );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"has_dkim"} == 0 115 135 250
196 135 ▶ return if ( $self->{'failmode'} );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"failmode"} 0 135 135
197  
198 135 my $config = $self->handler_config();
199  
200 135 my $dkim = $self->get_object('dkim');
201  
202 135 eval {
203 135 $dkim->PRINT( $self->{'carry'} );
204 135 $dkim->CLOSE();
205 135 $self->check_timeout();
206  
207 135 my $dkim_result = $dkim->result;
208 135 my $dkim_result_detail = $dkim->result_detail;
209  
210 135 $self->metric_count( 'dkim_total', { 'result' => $dkim_result } );
211  
212 135 $self->dbgout( 'DKIMResult', $dkim_result_detail, LOG_DEBUG );
213  
214 135 ▶ if ( !$dkim->signatures() ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($dkim->signatures) 0 135 135
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 135 foreach my $signature ( $dkim->signatures() ) {
222  
223 167 my $otype = ref $signature;
224 167 ▶ my $type =
Branch: 2 branches
BranchTrueFalseTotal
$otype eq 'Mail::DKIM::DkSignature' ? : 0 167 167
$otype eq 'Mail::DKIM::Signature' ? : 167 0 167
225 $otype eq 'Mail::DKIM::DkSignature' ? 'domainkeys'
226 : $otype eq 'Mail::DKIM::Signature' ? 'dkim'
227 : 'dkim';
228 167 $self->dbgout( 'DKIMSignatureType', $type, LOG_DEBUG );
229  
230 167 $self->dbgout( 'DKIMSignatureDomain', $signature->domain, LOG_DEBUG );
231 167 $self->dbgout( 'DKIMSignatureIdentity', $signature->identity, LOG_DEBUG );
232 167 $self->dbgout( 'DKIMSignatureResult', $signature->result_detail, LOG_DEBUG );
233 167 my $signature_result = $signature->result();
234 167 my $signature_result_detail = $signature->result_detail();
235  
236 167 ▶ if ( $signature_result eq 'pass' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($signature_result eq "pass") 101 66 167
237 101 $self->{'valid_domains'}->{ lc $signature->domain } = 1;
238 }
239  
240 167 ▶ if ( $signature_result eq 'invalid' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($signature_result eq "invalid") 25 142 167
241 25 ▶ if ( $signature_result_detail =~ /DNS query timeout for (.*) at / ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($signature_result_detail =~ /DNS query timeout for (.*) at /u) 0 25 25
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 167 my $result_comment = q{};
249 167 ▶ if ( $signature_result ne 'pass' and $signature_result ne 'none' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($signature_result ne "pass" and $signature_result ne "none") 66 101 167
Condition66%2/3
$signature_result ne "pass" and $signature_result ne "none"
!ll&&!rl&&r
101066
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 66 $signature_result_detail =~ /$signature_result \((.*)\)/;
251 66 ▶ if ( $1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($1) 66 0 66
252 66 $result_comment = $1 . ', ';
253 }
254 }
255 167 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
unless ($config->{"hide_none"} and $signature_result eq "none") 167 0 167
Condition66%2/3
$config->{"hide_none"} and $signature_result eq "none"
!ll&&!rl&&r
147200
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 167 ▶ my $selector = eval{ $signature->selector } // q{};
Condition50%1/2
eval { do { $signature->selector } } // ""
l!l
1670
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 167 my $key = eval {$signature->get_public_key()};
264 167 ▶ my $key_type = eval{ $key->type() } // 'unknown';
Condition100%2/2
eval { do { $key->type } } // "unknown"
l!l
1661
MC/DC100%1/1
eval { do { $key->type } } // "unknown"
eval { do { $key->type } }
Truth table100%2/2
A
A= eval { do { $key->type } }
Aresult
11
00
265 # Key size for ed25519 does not make sense
266 167 ▶ my $key_size = $key_type eq 'rsa' ? ( eval{ $key->size() } // 0 ) : 0;
Branch: 1 branch
BranchTrueFalseTotal
$key_type eq 'rsa' ? : 166 1 167
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 167 ▶ my $hash_algorithm = eval { $signature->hash_algorithm(); } // '';
Condition50%1/2
eval { do { $signature->hash_algorithm } } // ""
l!l
1670
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 167 ▶ my $canonicalization = eval { $signature->canonicalization(); } // '';
Condition50%1/2
eval { do { $signature->canonicalization } } // ""
l!l
1670
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 167 my @key_data_parts;
272 167 ▶ push @key_data_parts, $key_size . '-bit' if $key_size;
Branch: 1 branch
BranchTrueFalseTotal
if $key_size 166 1 167
273 167 push @key_data_parts, "$key_type key";
274 167 ▶ push @key_data_parts, $hash_algorithm if $hash_algorithm;
Branch: 1 branch
BranchTrueFalseTotal
if $hash_algorithm 167 0 167
275 167 my $key_data = join ' ', @key_data_parts;
276  
277 167 $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 167 ▶ if ( $type eq 'domainkeys' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq 'domainkeys') { } 0 167 167
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 167 my $header = Mail::AuthenticationResults::Header::Entry->new()->set_key( $type )->safe_set_value( $signature_result );
303 167 $header->add_child( Mail::AuthenticationResults::Header::Comment->new()->safe_set_value( $result_comment . $key_data ) );
304 167 $header->add_child( Mail::AuthenticationResults::Header::SubEntry->new()->set_key( 'header.d' )->safe_set_value( $signature->domain() ) );
305 167 $header->add_child( Mail::AuthenticationResults::Header::SubEntry->new()->set_key( 'header.i' )->safe_set_value( $signature->identity() ) );
306 167 $header->add_child( Mail::AuthenticationResults::Header::SubEntry->new()->set_key( 'header.b' )->safe_set_value( substr( $signature->data(), 0, 8 ) ) );
307 167 ▶ $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 167 0 167
Condition33%1/3
$key_type and $hash_algorithm
!ll&&!rl&&r
00167
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 167 $header->add_child( Mail::AuthenticationResults::Header::SubEntry->new()->set_key( 'header.s' )->safe_set_value( $selector ) );
309 167 ▶ if ( $config->{'extra_properties'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($config->{"extra_properties"}) 12 155 167
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 167 ▶ if ( $config->{'log_dns_record'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($config->{"log_dns_record"}) 2 165 167
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 167 $self->add_auth_header($header);
331 }
332 }
333 167 $self->check_timeout();
334 }
335  
336 # the alleged author of the email may specify how to handle email
337 135 ▶ 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 99 135
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
99036
$config->{"check_adsp"} and $self->is_local_ip_address == 0 and $self->is_trusted_ip_address == 0
!ll&&!rl&&r
97236
$config->{"check_adsp"} and $self->is_local_ip_address == 0
!ll&&!rl&&r
89838
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 135 ▶ if ( my $error = $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $error = $@) 0 135 135
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 127 ▶sub close_callback {
Subroutine close_callback: called CC=1 SCAR=0.0
Pod undocumented
400 127 my ( $self ) = @_;
401 127 delete $self->{'failmode'};
402 127 delete $self->{'headers'};
403 127 delete $self->{'body'};
404 127 delete $self->{'carry'};
405 127 delete $self->{'has_dkim'};
406 127 delete $self->{'valid_domains'};
407 127 delete $self->{'early_lookups'};
408 127 $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 44 1;
448  
449 __END__
« Authentication.pm ↑ Summary Authentication/Protocol/Milter.pm »