| 1 | package Mail::DKIM2::Validate; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | 8 | ▶ | use strict; use warnings; use 5.020; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 8 | our $VERSION = '0.34'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 8 | ▶ | use Email::MIME; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 8 | ▶ | use List::Util qw(max); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 8 | ▶ | use Mail::DKIM2::Util (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 8 | ▶ | use Mail::DKIM2::Common qw(extract_mi_version parse_mime); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 8 | ▶ | use Mail::DKIM2::Address qw(domain_of to_alabel relaxed_domain_match); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 8 | ▶ | use Mail::DKIM2::Key qw(parse_dkim_pubkey); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 8 | ▶ | use Mail::DKIM2::MessageInstance; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 8 | ▶ | use Mail::DKIM2::Verifier; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 8 | ▶ | use Mail::DKIM2::Signature; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | # i= / m= of a field value; tag-names are case-sensitive (-09 §8, D10). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 153 | ▶ | sub _i { my $h = shift // ''; $h =~ /(?:\A|;)\s*i\s*=\s*(\d+)/ ? 0 + $1 : 0 } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_i: called CC=3 SCAR=12.0
Branch: 1 branch
Condition50%1/2
shift() // ""
MC/DC0%0/1
shift() // ""
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 80 | ▶ | sub _m { my $h = shift // ''; $h =~ /(?:\A|;)\s*m\s*=\s*(\d+)/ ? 0 + $1 : 0 } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_m: called CC=3 SCAR=12.0
Branch: 1 branch
Condition50%1/2
shift() // ""
MC/DC0%0/1
shift() // ""
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | # --- parsed-tag breakdown for the validator UI --------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | # A compact, human-readable rendering of every tag in a DKIM2-Signature or | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | # Message-Instance, so the validator can show the full parsed structure. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | # Unix timestamp -> "<n> (YYYY-MM-DD HH:MM:SSZ)". | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 35 | ▶ | sub _fmt_ts { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_fmt_ts: called CC=4 SCAR=15.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 35 | my $t = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 35 | ▶ | return '' unless defined $t && $t ne ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $t and $t ne ""
MC/DC0%0/2
defined $t and $t ne ""
defined $t
$t ne ""
Truth table33%1/3
A and B
A= defined $tB= $t ne ""
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 35 | ▶ | return $t unless $t =~ /^\d+$/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 35 | my @g = gmtime($t); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 35 | return sprintf('%s (%04d-%02d-%02d %02d:%02d:%02dZ)', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | $t, $g[5]+1900, $g[4]+1, $g[3], $g[2], $g[1], $g[0]); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | # Middle-truncate a long base64 blob to keep the structure compact. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 35 | ▶ | sub _trunc { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_trunc: called CC=4 SCAR=14.6
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 35 | my ($s, $keep) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 35 | ▶ | $keep //= 16; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$keep //= 16
MC/DC0%0/1
$keep //= 16
$keep
Truth table50%1/2
A
A= $keep
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 35 | ▶ | $s //= ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$s //= ""
MC/DC0%0/1
$s //= ""
$s
Truth table50%1/2
A
A= $s
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 35 | ▶ | return $s if length($s) <= 2*$keep + 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 35 | return substr($s, 0, $keep) . '…' . substr($s, -$keep); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | # Ordered [{tag,label,value}] for every tag present in a DKIM2-Signature. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 35 | ▶ | sub _sig_tags { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_sig_tags: called CC=19 SCAR=32.7
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 35 | my ($sig) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 35 | ▶ | return [] unless $sig; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 35 | my @t; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 35 | ▶ | push @t, { tag => 'i', label => 'sequence', value => ($sig->sequence // '') }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$sig->sequence // ""
MC/DC0%0/1
$sig->sequence // ""
$sig->sequence
Truth table50%1/2
A
A= $sig->sequence
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 35 | ▶ | push @t, { tag => 'm', label => 'covers MI', value => ($sig->version // '') }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$sig->version // ""
MC/DC0%0/1
$sig->version // ""
$sig->version
Truth table50%1/2
A
A= $sig->version
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 35 | push @t, { tag => 't', label => 'timestamp', value => _fmt_ts($sig->timestamp) }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 35 | ▶ | push @t, { tag => 'd', label => 'domain', value => ($sig->domain // '') }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$sig->domain // ""
MC/DC0%0/1
$sig->domain // ""
$sig->domain
Truth table50%1/2
A
A= $sig->domain
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 35 | my $nd = $sig->next_domain; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 35 | ▶ | push @t, { tag => 'nd', label => 'next-domain', value => $nd } if defined $nd; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 35 | my $mf = $sig->mail_from; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 35 | ▶ | push @t, { tag => 'mf', label => 'MAIL FROM', value => ($mf // ''), decoded => 1 } if defined $mf; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$mf // ""
MC/DC0%0/1
$mf // ""
$mf
Truth table50%1/2
A
A= $mf
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 35 | my $rt = $sig->rcpt_to; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 35 | ▶ | push @t, { tag => 'rt', label => 'RCPT TO', value => join(', ', @$rt), decoded => 1 } if $rt && @$rt; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$rt and @$rt
MC/DC50%1/2
$rt and @$rt
$rt
@$rt
Truth table66%2/3
A and B
A= $rtB= @$rt
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 35 | my $n = $sig->nonce; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 35 | ▶ | push @t, { tag => 'n', label => 'nonce', value => $n } if defined $n && length $n; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $n and length $n
MC/DC0%0/2
defined $n and length $n
defined $n
length $n
Truth table33%1/3
A and B
A= defined $nB= length $n
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 35 | my $f = $sig->flags; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 35 | ▶ | push @t, { tag => 'f', label => 'flags', value => join(', ', @$f) } if $f && @$f; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$f and @$f
MC/DC0%0/2
$f and @$f
$f
@$f
Truth table33%1/3
A and B
A= $fB= @$f
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 35 | ▶ | my $cnt = $sig->sig_count || 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$sig->sig_count || 0
MC/DC0%0/1
$sig->sig_count || 0
$sig->sig_count
Truth table50%1/2
A
A= $sig->sig_count
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 35 | for my $idx (0 .. $cnt - 1) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 35 | ▶ | my $v = $sig->signature_value($idx) // ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$sig->signature_value($idx) // ""
MC/DC0%0/1
$sig->signature_value($idx) // ""
$sig->signature_value($idx)
Truth table50%1/2
A
A= $sig->signature_value($idx)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 35 | ▶ | push @t, { tag => 's', label => 'signature', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%2/4
$sig->selector($idx) // ""
$sig->algorithm($idx) // ""
MC/DC0%0/1
$sig->selector($idx) // ""
$sig->selector($idx)
MC/DC0%0/1
$sig->algorithm($idx) // ""
$sig->algorithm($idx)
Truth table50%1/2
A
A= $sig->selector($idx)
Truth table50%1/2
A
A= $sig->algorithm($idx)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | value => sprintf('%s : %s : %s (%d bytes b64)', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | $sig->selector($idx) // '', $sig->algorithm($idx) // '', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | _trunc($v), length $v) }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 35 | return \@t; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | # Ordered [{tag,label,value}] for a Message-Instance. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 27 | ▶ | sub _mi_tags { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_mi_tags: called CC=14 SCAR=27.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 27 | my ($mi) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 27 | ▶ | return [] unless $mi; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 27 | my @t; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 27 | ▶ | push @t, { tag => 'm', label => 'instance', value => ($mi->get_tag('m') // '') }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$mi->get_tag("m") // ""
MC/DC0%0/1
$mi->get_tag("m") // ""
$mi->get_tag("m")
Truth table50%1/2
A
A= $mi->get_tag("m")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | # -09 §9.3: h= may carry a hash-set per algorithm -- show each one | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | # under its own name rather than assuming sha256. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 27 | ▶ | my $hashes = $mi->get_tag('hashes') || {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$mi->get_tag('hashes') || {}
MC/DC0%0/1
$mi->get_tag('hashes') || {}
$mi->get_tag('hashes')
Truth table50%1/2
A
A= $mi->get_tag('hashes')
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 27 | for my $alg (sort keys %$hashes) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 27 | my ($hh, $bh) = @{ $hashes->{$alg} }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 27 | ▶ | push @t, { tag => 'h', label => 'header hash', value => "$alg:" . ($hh // '') }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$hh // ""
MC/DC0%0/1
$hh // ""
$hh
Truth table50%1/2
A
A= $hh
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 27 | ▶ | push @t, { tag => 'h', label => 'body hash', value => "$alg:" . ($bh // '') }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$bh // ""
MC/DC0%0/1
$bh // ""
$bh
Truth table50%1/2
A
A= $bh
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 27 | my $rh = $mi->get_tag('rh'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 27 | my $rb = $mi->get_tag('rb'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 27 | ▶ | if ($mi->unrecoverable) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 3 | push @t, { tag => 'r', label => 'recipe', value => 'null (previous state not recoverable)' }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | ▶ | } elsif ($rh || $rb) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$rh or $rb
MC/DC50%1/2
$rh or $rb
$rh
$rb
Truth table66%2/3
A or B
A= $rhB= $rb
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 6 | my @parts; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 6 | ▶ | push @parts, 'headers: ' . join(', ', sort keys %$rh) if $rh && %$rh; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$rh and %$rh
MC/DC0%0/2
$rh and %$rh
$rh
%$rh
Truth table33%1/3
A and B
A= $rhB= %$rh
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 6 | ▶ | push @parts, 'body: ' . (ref $rb eq 'ARRAY' ? scalar(@$rb) . ' step(s)' : 'changed') if $rb; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 6 | push @t, { tag => 'r', label => 'recipe', value => join('; ', @parts) }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 27 | return \@t; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | # Default pubkey callback: LIVE DNS. A dns.json override applies only when a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | # readable $dns_path is passed in (offline testing) — production passes none, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | # so the validator uses real DNS and never masks a broken key record. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 8 | our $POLICY_CB; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | # The records of a dns.json file (util's interop key format), or undef. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 24 | ▶ | sub _dns_json { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_dns_json: called CC=5 SCAR=16.3
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 24 | my ($dns_path) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 24 | ▶ | return unless $dns_path && -r $dns_path; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$dns_path and -r $dns_path
MC/DC50%1/2
$dns_path and -r $dns_path
$dns_path
-r $dns_path
Truth table66%2/3
A and B
A= $dns_pathB= -r $dns_path
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 3 | require JSON; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 3 | ▶ | open my $fh, '<', $dns_path or return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 3 | my $dns = eval { JSON::decode_json(do { local $/; <$fh> }) }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 3 | ▶ | die $@ if ref $@; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 3 | return $dns; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | # A PolicyCallback answering from DnsPath's records for the domains it | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | # lists, else from DNS. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 21 | ▶ | sub _default_policy_cb { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_default_policy_cb: called CC=1 SCAR=4.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 21 | my $dns = _dns_json(@_); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 0 | ▶ | return sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 0 | my ($dom, $verifier) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 0 | ▶ | return [ map { $_->[1] } @{ $dns->{$dom}{_domainkey} || [] } ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$dns->{$dom}{'_domainkey'} || []
MC/DC0%0/1
$dns->{$dom}{'_domainkey'} || []
$dns->{$dom}{'_domainkey'}
Truth table0%0/2
A
A= $dns->{$dom}{'_domainkey'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 0 | ▶ | if $dns && $dns->{$dom}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$dns and $dns->{$dom}
MC/DC0%0/2
$dns and $dns->{$dom}
$dns
$dns->{$dom}
Truth table0%0/3
A and B
A= $dnsB= $dns->{$dom}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 0 | return $verifier->fetch_domain_policy($dom); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 21 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 3 | ▶ | sub _default_cb { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_default_cb: called CC=1 SCAR=0.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 3 | my $dns = _dns_json(@_); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 2 | ▶ | return sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=9 SCAR=22.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 2 | ▶ | my ($sig, $idx, $verifier) = @_; $idx //= 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$idx //= 0
MC/DC0%0/1
$idx //= 0
$idx
Truth table50%1/2
A
A= $idx
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 2 | my $sel = $sig->selector($idx); my $dom = $sig->domain; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 2 | ▶ | if ($dns && $dom && $sel && (my $rr = $dns->{$dom}{"$sel._domainkey"})) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%6/9
$dns and $dom and $sel and my $rr = $dns->{$dom}{"$sel._domainkey"}
$dns and $dom and $sel
$dns and $dom
MC/DC25%1/4
$dns and $dom and $sel and my $rr = $dns->{$dom}{"$sel._domainkey"}
$dns
$dom
$sel
my $rr = $dns->{$dom}{"$sel._domainkey"}
Truth table40%2/5
A and B and C and D
A= $dnsB= $domC= $selD= my $rr = $dns->{$dom}{"$sel._domainkey"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | # As the Verifier's own fetch: non-DKIM1 records ignored, then | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | # one record or an error (-09 section 3.7). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 1 | my @t = Mail::DKIM2::Key::key_records(map { $_->[1] } @$rr); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 1 | ▶ | die "PERMERROR: has multiple records\n" if @t > 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 1 | ▶ | if (@t) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 1 | my ($key, $why) = Mail::DKIM2::Key::parse_dkim_key_record($t[0]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 1 | ▶ | die "PERMERROR: $why\n" unless $key; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 1 | return $key; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | # Real DNS. Not eval'd: a transient failure must stay a TEMPERROR, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | # which the verifier classifies; swallowing it here read as "no key". | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 1 | return $verifier->fetch_public_key($sig, $idx); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 3 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | # report($text, %opts) — verify a DKIM2 message and return a structured report. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | # Prior to spec-06, a receiving MTA's Received-SPF header (Fastmail adds one) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | # was covered by the Message-Instance header hash and could break | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | # verification; this used to retry once with it stripped. -09 §4 excludes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | # Received-SPF from the hash via the "received-" prefix rule (should_skip()), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | # so stripping it can no longer change h_digest()/b_digest() or any verdict — | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | # the retry was provably a no-op. Removed rather than kept as a "safety net": | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | # it was hardcoded to the literal name Received-SPF, not a general mechanism, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | # so it covered nothing else anyway. Mirrored removal in | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | # deploy/www/verify/verify.js's verifyMessage(). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 22 | ▶ | sub report { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
report: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 22 | my ($text, %opts) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 22 | Mail::DKIM2::Util::check_options('Mail::DKIM2::Validate::report', \%opts, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | qw(DnsPath PubkeyCallback PolicyCallback SkipTimestampCheck)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 21 | ▶ | $text //= ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$text //= ""
MC/DC0%0/1
$text //= ""
$text
Truth table50%1/2
A
A= $text
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 21 | return _report_once($text, %opts); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 21 | ▶ | sub _report_once { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_report_once: called CC=35 SCAR=39.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 21 | my ($text, %opts) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 21 | ▶ | $text //= ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$text //= ""
MC/DC0%0/1
$text //= ""
$text
Truth table50%1/2
A
A= $text
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 21 | $text =~ s/\r?\n/\r\n/g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 21 | ▶ | my $cb = $opts{PubkeyCallback} || _default_cb($opts{DnsPath}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$opts{'PubkeyCallback'} || _default_cb($opts{'DnsPath'})
MC/DC0%0/2
$opts{'PubkeyCallback'} || _default_cb($opts{'DnsPath'})
$opts{'PubkeyCallback'}
_default_cb($opts{'DnsPath'})
Truth table66%2/3
A || B
A= $opts{'PubkeyCallback'}B= _default_cb($opts{'DnsPath'})
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | # The Domain Policy Record source every Verifier here uses (-09 section | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | # 3.8): the caller's, else DnsPath's records, else DNS. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 21 | ▶ | local $POLICY_CB = $opts{PolicyCallback} || _default_policy_cb($opts{DnsPath}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$opts{'PolicyCallback'} || _default_policy_cb($opts{'DnsPath'})
MC/DC0%0/2
$opts{'PolicyCallback'} || _default_policy_cb($opts{'DnsPath'})
$opts{'PolicyCallback'}
_default_policy_cb($opts{'DnsPath'})
Truth table33%1/3
A || B
A= $opts{'PolicyCallback'}B= _default_policy_cb($opts{'DnsPath'})
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 21 | ▶ | my $skip_ts = $opts{SkipTimestampCheck} ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 21 | my %res = (overall => 'none', summary => '', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | counts => { signatures => 0, instances => 0 }, levels => []); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 21 | my $msg = eval { parse_mime($text) }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 21 | ▶ | die $@ if ref $@; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 21 | ▶ | return { %res, overall => 'fail', summary => "could not parse message: $@" } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$@ or not $msg
MC/DC0%0/2
$@ or not $msg
$@
not $msg
Truth table33%1/3
A or not(B)
A= $@B= not $msg
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | if $@ || !$msg; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 21 | my @sig_hdrs = $msg->header('DKIM2-Signature'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 21 | my @mi_hdrs = $msg->header('Message-Instance'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 21 | $res{counts} = { signatures => scalar @sig_hdrs, instances => scalar @mi_hdrs }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | # A Message-Instance with no signature anywhere is -09 §14's | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | # "PERMERROR: Message-Instance m=<x> is not signed", not an absence of | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | # DKIM2. Reporting it as 'none' is exactly the answer someone pasting such | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | # a message here does not need: it says "nothing to see" about a message | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | # that a conforming receiver will reject. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 21 | ▶ | if (!@sig_hdrs && @mi_hdrs) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not @sig_hdrs and @mi_hdrs
MC/DC0%0/2
not @sig_hdrs and @mi_hdrs
not @sig_hdrs
@mi_hdrs
Truth table66%2/3
not(A) and B
A= not @sig_hdrsB= @mi_hdrs
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 0 | my ($top_mi) = sort { $b <=> $a } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 0 | grep { defined } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 0 | map { extract_mi_version($_) } @mi_hdrs; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 0 | ▶ | $top_mi //= '?'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$top_mi //= "?"
MC/DC0%0/1
$top_mi //= "?"
$top_mi
Truth table0%0/2
A
A= $top_mi
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 0 | return { %res, overall => 'fail', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | summary => "PERMERROR: Message-Instance m=$top_mi is not signed" }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 21 | ▶ | return { %res, overall => 'none', summary => 'NONE: No DKIM2 header fields found' } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | unless @sig_hdrs; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | # Overall verdict from the full verifier (includes the §14.7 deep MI walk). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | # Timestamp age is graded per-signature as a soft 'warn' below, so it must | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | # not hard-fail the crypto verdict here. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 19 | my $v = Mail::DKIM2::Verifier->new(PolicyCallback => $POLICY_CB); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 19 | $v->skip_timestamp_check(1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 19 | $v->set_pubkey_callback($cb); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 19 | eval { $v->PRINT($text); $v->CLOSE; 1 }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 19 | ▶ | die $@ if ref $@; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | 18 | ▶ | my $ov = $v->result // 'fail'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$v->result // "fail"
MC/DC0%0/1
$v->result // "fail"
$v->result
Truth table50%1/2
A
A= $v->result
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 18 | ▶ | $res{summary} = $v->result_detail // ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$v->result_detail // ""
MC/DC0%0/1
$v->result_detail // ""
$v->result_detail
Truth table50%1/2
A
A= $v->result_detail
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 18 | ▶ | $res{overall} = $ov eq 'pass' ? 'pass' : ($ov eq 'none' ? 'none' : 'fail'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | # Deprecated (0.29): a null body Recipe is now a PERMERROR (-09 contract | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | # E2), so this is true exactly for a pass. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 18 | $res{fully_verified} = $v->fully_verified; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 18 | my %sig_by_i = map { _i($_) => $_ } @sig_hdrs; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | # Descend the chain top-down. At each step: verify every signature whose | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | # m= equals the current top Message-Instance (content is at the right level | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | # for them), then record that MI level and undo one step. Records a level | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | # for every signature and every MI, in chain order (top hop first). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | 18 | my @levels; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | 18 | my $work = parse_mime($text); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 18 | my $stopped; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | # Set once the walk has crossed an instance with a null body Recipe: the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | # body below it is lost, so lower levels are judged on their header | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | # hashes alone, undoing header Recipes only (as Verifier.pm does). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | 18 | my $hdr_only = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 18 | while (1) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | 27 | my %sigmap = map { _i($_) => $_ } $work->header('DKIM2-Signature'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | 27 | my %mimap = map { extract_mi_version($_) => $_ } $work->header('Message-Instance'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | 27 | ▶ | my $num = %sigmap ? max(keys %sigmap) : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | 27 | ▶ | my $inst = %mimap ? max(keys %mimap) : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | 27 | ▶ | last if !$num && !$inst; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$num or $inst
MC/DC0%0/2
$num or $inst
$num
$inst
Truth table33%1/3
A or B
A= $numB= $inst
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | # Signatures covering the current top MI (highest i first). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | 27 | ▶ | while ($num > 0 && _m($sigmap{$num}) == $inst) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$num > 0 and _m($sigmap{$num}) == $inst
MC/DC100%2/2
$num > 0 and _m($sigmap{$num}) == $inst
$num > 0
_m($sigmap{$num}) == $inst
Truth table100%3/3
A and B
A= $num > 0B= _m($sigmap{$num}) == $inst
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | 35 | push @levels, _sig_level($work, $num, \%sig_by_i, $cb, $skip_ts, $hdr_only); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | $work->header_raw_set('DKIM2-Signature', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | 35 | grep { _i($_) < $num } $work->header('DKIM2-Signature')); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | 35 | %sigmap = map { _i($_) => $_ } $work->header('DKIM2-Signature'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | 35 | ▶ | $num = %sigmap ? max(keys %sigmap) : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 27 | ▶ | last unless $inst; # no more MIs to record | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 27 | my $lvl = _mi_level($work, $inst, $mimap{$inst}, $hdr_only); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | 27 | push @levels, $lvl; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | 27 | ▶ | last if $inst <= 1; # base instance recorded; done | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | 9 | ▶ | if ($lvl->{undo} eq 'unrecoverable') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | # Null body Recipe: keep going on the header history only. A | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | # header Recipe that will not apply stops the walk here. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | 3 | $hdr_only = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | 3 | my $prev = eval { Mail::DKIM2::MessageInstance->undo($work, HeadersOnly => 1) }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | 3 | ▶ | die $@ if ref $@; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | 3 | ▶ | unless ($prev) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | 0 | $stopped = "stopped below m=$inst (header history did not undo)"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | 0 | last; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | 3 | $work = parse_mime($work->as_string); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | } elsif ($lvl->{undo} eq 'clean') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | 6 | Mail::DKIM2::MessageInstance->undo($work, HeadersOnly => $hdr_only); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 6 | $work = parse_mime($work->as_string); # reset Email::MIME caches | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | 0 | $stopped = "stopped below m=$inst ($lvl->{undo})"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | 0 | last; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | 18 | ▶ | $res{summary} = ($res{summary} ? "$res{summary}; " : '') . $stopped if $stopped; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | # An old/future timestamp is a soft warning, not a hard fail: if the chain | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | # otherwise verified, surface it as an amber 'warn' overall. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | 18 | ▶ | if ($res{overall} eq 'pass' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$res{"overall"} eq "pass" and grep {($_->{"result"} // "") eq "warn";} @levels
MC/DC100%2/2
$res{"overall"} eq "pass" and grep {($_->{"result"} // "") eq "warn";} @levels
$res{"overall"} eq "pass"
grep {($_->{"result"} // "") eq "warn";} @levels
Truth table100%3/3
A and B
A= $res{"overall"} eq "pass"B= grep {($_->{"result"} // "") eq "warn";} @levels
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | 25 | ▶ | && grep { ($_->{result} // '') eq 'warn' } @levels) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$_->{"result"} // ""
MC/DC0%0/1
$_->{"result"} // ""
$_->{"result"}
Truth table50%1/2
A
A= $_->{"result"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | 1 | $res{overall} = 'warn'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | 18 | $res{levels} = \@levels; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | 18 | return \%res; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | # Level hashref for the top Message-Instance m=$inst of $msg. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | # $hdr_only: below a null body Recipe, so the body is not checkable. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | 27 | ▶ | sub _mi_level { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_mi_level: called CC=33 SCAR=36.4
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | 27 | my ($msg, $inst, $mi_raw, $hdr_only) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | 27 | my %lvl = (kind => 'mi', m => $inst, result => 'fail', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | header_hash => 'mismatch', body_hash => 'mismatch', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | recipe => 'none', undo => 'n/a', detail => '', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | header_recipes => [], body_recipe => 'none'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | 27 | my $mi = eval { Mail::DKIM2::MessageInstance->parse($mi_raw) }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | 27 | ▶ | die $@ if ref $@; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | 0 | ▶ | unless ($mi) { $lvl{detail} = 'unparseable Message-Instance'; return \%lvl; } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | 27 | $lvl{tags} = _mi_tags($mi); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | # -09 §3.5/§9.3: mirror MessageInstance::verify()'s semantics here -- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | # every implemented hash-set must match; an MI naming no implemented | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | # algorithm displays as a mismatch (fail-closed), not silently as a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | # sha256-only "no hash". | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | 27 | ▶ | my $hashes = $mi->get_tag('hashes') || {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$mi->get_tag('hashes') || {}
MC/DC0%0/1
$mi->get_tag('hashes') || {}
$mi->get_tag('hashes')
Truth table50%1/2
A
A= $mi->get_tag('hashes')
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | 27 | my $impl = Mail::DKIM2::MessageInstance::hash_algs(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | 27 | my @usable = sort grep { $impl->{$_} } keys %$hashes; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | 27 | my ($h_match, $b_match) = (0, 0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | 27 | ▶ | if (@usable) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | 27 | $h_match = $b_match = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | 27 | for my $alg (@usable) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | 27 | my ($h1, $b1) = @{ $hashes->{$alg} }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | 27 | my $hd = Mail::DKIM2::MessageInstance::h_digest($msg, $alg); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | 27 | my $bd = Mail::DKIM2::MessageInstance::b_digest($msg, $alg); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | 27 | ▶ | $h_match = 0 unless defined $h1 && $h1 eq $hd; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $h1 and $h1 eq $hd
MC/DC50%1/2
defined $h1 and $h1 eq $hd
defined $h1
$h1 eq $hd
Truth table66%2/3
A and B
A= defined $h1B= $h1 eq $hd
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | 27 | ▶ | $b_match = 0 unless defined $b1 && $b1 eq $bd; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $b1 and $b1 eq $bd
MC/DC50%1/2
defined $b1 and $b1 eq $bd
defined $b1
$b1 eq $bd
Truth table66%2/3
A and B
A= defined $b1B= $b1 eq $bd
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | 27 | ▶ | $lvl{header_hash} = $h_match ? 'match' : 'mismatch'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | 27 | ▶ | $lvl{body_hash} = $hdr_only ? 'not-checked' : $b_match ? 'match' : 'mismatch'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | 27 | my $rh = $mi->get_tag('rh'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | 27 | my $rb = $mi->get_tag('rb'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | 27 | ▶ | $lvl{recipe} = $mi->unrecoverable ? 'null' : ($rb || $rh) ? 'diff' : 'none'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%3/3
$rb or $rh
MC/DC100%2/2
$rb or $rh
$rb
$rh
Truth table100%3/3
A or B
A= $rbB= $rh
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | 27 | ▶ | $lvl{body_recipe} = $mi->unrecoverable ? 'null' : ($rb ? 'diff' : 'none'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | 27 | ▶ | if ($inst <= 1) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | 18 | $lvl{undo} = 'n/a'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | } elsif ($mi->unrecoverable) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | 3 | $lvl{undo} = 'unrecoverable'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | 6 | my $clone = parse_mime($msg->as_string); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | 6 | ▶ | my $ok = eval { Mail::DKIM2::MessageInstance->undo($clone, HeadersOnly => $hdr_only ? 1 : 0) }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | 6 | ▶ | die $@ if ref $@; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | 6 | ▶ | $lvl{undo} = ($ok && !$@) ? 'clean' : 'failed'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$ok and not $@
MC/DC0%0/2
$ok and not $@
$ok
not $@
Truth table33%1/3
A and not(B)
A= $okB= not $@
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | 6 | ▶ | if ($ok && !$@ && $rh) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
$ok and not $@ and $rh
$ok and not $@
MC/DC0%0/3
$ok and not $@ and $rh
$ok
not $@
$rh
Truth table25%1/4
A and not(B) and C
A= $okB= not $@C= $rh
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | 6 | for my $h (sort keys %$rh) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | 13 | my $cur = join(' / ', $msg->header($h)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | 13 | my $prev = join(' / ', $clone->header($h)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | 13 | ▶ | push @{$lvl{header_recipes}}, { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | name => $h, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | current => (length $cur ? $cur : '(absent)'), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | previous => (length $prev ? $prev : '(absent)'), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | $lvl{result} = ($lvl{header_hash} eq 'match' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | 27 | ▶ | && ($hdr_only || $lvl{body_hash} eq 'match')) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$lvl{"header_hash"} eq "match" and $hdr_only || $lvl{"body_hash"} eq "match"
$hdr_only or $lvl{"body_hash"} eq "match"
MC/DC100%3/3
$lvl{"header_hash"} eq "match" and $hdr_only || $lvl{"body_hash"} eq "match"
$lvl{"header_hash"} eq "match"
$hdr_only
$lvl{"body_hash"} eq "match"
Truth table100%4/4
A and B or C
A= $lvl{"header_hash"} eq "match"B= $hdr_onlyC= $lvl{"body_hash"} eq "match"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | ? 'pass' : 'fail'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | 27 | return \%lvl; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | # Signature-level hashref for i=$num, verifying the chain prefix on $work. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | 35 | ▶ | sub _sig_level { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_sig_level: called CC=54 SCAR=45.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | 35 | my ($work, $num, $sig_by_i, $cb, $skip_ts, $hdr_only) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | # $sig_by_i values come from Email::MIME->header() — already bare values. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | 35 | my $sig = eval { Mail::DKIM2::Signature->parse($sig_by_i->{$num}) }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | 35 | ▶ | die $@ if ref $@; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | 35 | ▶ | my %lvl = (kind => 'signature', i => $num, m => _m($sig_by_i->{$num}), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$sig->domain // ""
MC/DC0%0/1
$sig->domain // ""
$sig->domain
Truth table50%1/2
A
A= $sig->domain
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | domain => ($sig ? ($sig->domain // '') : ''), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | mail_from => '', rcpt_to => [], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | items => [], timestamp => { ok => 1, detail => '' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | custody => { ok => 1, detail => '' }, result => 'fail', detail => ''); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | 35 | ▶ | if ($sig) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | 35 | $lvl{tags} = _sig_tags($sig); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | 35 | ▶ | $lvl{mail_from} = $sig->mail_from // ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$sig->mail_from // ""
MC/DC100%1/1
$sig->mail_from // ""
$sig->mail_from
Truth table100%2/2
A
A= $sig->mail_from
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | 35 | my $rt = $sig->rcpt_to; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | 35 | ▶ | $lvl{rcpt_to} = [ ref $rt eq 'ARRAY' ? @$rt : (defined $rt ? ($rt) : ()) ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | 35 | ▶ | my $n = $sig->sig_count || 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$sig->sig_count || 0
MC/DC0%0/1
$sig->sig_count || 0
$sig->sig_count
Truth table50%1/2
A
A= $sig->sig_count
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | 35 | for my $idx (0 .. $n - 1) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | 35 | ▶ | push @{$lvl{items}}, { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%2/4
$sig->selector($idx) // ""
$sig->algorithm($idx) // ""
MC/DC0%0/1
$sig->selector($idx) // ""
$sig->selector($idx)
MC/DC0%0/1
$sig->algorithm($idx) // ""
$sig->algorithm($idx)
Truth table50%1/2
A
A= $sig->selector($idx)
Truth table50%1/2
A
A= $sig->algorithm($idx)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | selector => ($sig->selector($idx) // ''), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | algorithm => ($sig->algorithm($idx) // ''), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | 35 | ▶ | unless ($skip_ts) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | 1 | my $ts = $sig->timestamp; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | 1 | ▶ | if (defined $ts && $ts > 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $ts and $ts > 0
MC/DC0%0/2
defined $ts and $ts > 0
defined $ts
$ts > 0
Truth table33%1/3
A and B
A= defined $tsB= $ts > 0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | 1 | my $now = time(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | 0 | ▶ | if ($ts > $now + 86400) { $lvl{timestamp} = { ok => 0, status => 'future', detail => 'timestamp in the future' }; } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | 1 | elsif ($now > $ts + 14*24*3600) { $lvl{timestamp} = { ok => 0, status => 'old', detail => 'older than 14 days' }; } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | 35 | ▶ | if ($num > 1 && $sig_by_i->{$num - 1}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$num > 1 and $$sig_by_i{$num - 1}
MC/DC50%1/2
$num > 1 and $$sig_by_i{$num - 1}
$num > 1
$$sig_by_i{$num - 1}
Truth table66%2/3
A and B
A= $num > 1B= $$sig_by_i{$num - 1}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | 17 | my $prev = eval { Mail::DKIM2::Signature->parse($sig_by_i->{$num-1}) }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | 17 | ▶ | die $@ if ref $@; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | 17 | ▶ | if ($prev) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | # -09 section 7.1 item 1, as Verifier.pm checks it, so the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | # report and the verdict cannot disagree. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | 17 | my $p = $num - 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | 17 | ▶ | my $cur_d = $sig->domain // ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$sig->domain // ""
MC/DC0%0/1
$sig->domain // ""
$sig->domain
Truth table50%1/2
A
A= $sig->domain
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | 17 | my $prev_nd = $prev->next_domain; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | 17 | my $cur_nd = $sig->next_domain; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | 17 | my $mf = $sig->mail_from; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | 17 | ▶ | my @rts = map { [domain_of($_)] } @{ $prev->rcpt_to || [] }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$prev->rcpt_to || []
MC/DC100%1/1
$prev->rcpt_to || []
$prev->rcpt_to
Truth table100%2/2
A
A= $prev->rcpt_to
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | 17 | ▶ | if (defined $prev_nd && length $prev_nd) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition66%2/3
defined $prev_nd and length $prev_nd
MC/DC50%1/2
defined $prev_nd and length $prev_nd
defined $prev_nd
length $prev_nd
Truth table66%2/3
A and B
A= defined $prev_ndB= length $prev_nd
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | # An nd= hop names the domain that signs the next signature. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | 4 | ▶ | $lvl{custody} = ((to_alabel($prev_nd) =~ tr/A-Z/a-z/r) eq (to_alabel($cur_d) =~ tr/A-Z/a-z/r)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | ? { ok => 1, detail => "nd=$prev_nd matches d= of i=$num" } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | : { ok => 0, detail => "PERMERROR: DKIM2-Signature i=$p nd= does not match" }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | ▶ | } elsif ((defined $cur_nd && length $cur_nd) || (defined $mf && $mf =~ /\A<\s*>\z/)) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition55%5/9
defined $cur_nd and length $cur_nd or defined $mf and $mf =~ /\A<\s*>\z/u
defined $cur_nd and length $cur_nd
defined $mf and $mf =~ /\A<\s*>\z/u
MC/DC25%1/4
defined $cur_nd and length $cur_nd or defined $mf and $mf =~ /\A<\s*>\z/u
defined $cur_nd
length $cur_nd
defined $mf
$mf =~ /\A<\s*>\z/u
Truth table28%2/7
A and B or C and D
A= defined $cur_ndB= length $cur_ndC= defined $mfD= $mf =~ /\A<\s*>\z/u
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | # An nd= hop, or a null mf=: its d= against the rt= domains. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | 2 | ▶ | my $ok = grep { $_->[0] && !$_->[1] && relaxed_domain_match($_->[0], $cur_d) } @rts; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%3/6
$_->[0] && !$_->[1] && relaxed_domain_match($_->[0], $cur_d)
$_->[0] and not $_->[1]
MC/DC33%1/3
$_->[0] && !$_->[1] && relaxed_domain_match($_->[0], $cur_d)
$_->[0]
not $_->[1]
relaxed_domain_match($_->[0], $cur_d)
Truth table50%2/4
A and not(B) && C
A= $_->[0]B= not $_->[1]C= relaxed_domain_match($_->[0], $cur_d)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | 2 | ▶ | $lvl{custody} = $ok | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition33%1/3
defined $cur_nd and length $cur_nd
MC/DC0%0/2
defined $cur_nd and length $cur_nd
defined $cur_nd
length $cur_nd
Truth table33%1/3
A and B
A= defined $cur_ndB= length $cur_nd
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | ? { ok => 1, detail => ((defined $cur_nd && length $cur_nd) ? "nd= hop" : "mf=<> hop") . " d=$cur_d matches rt= of i=$p" } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | : { ok => 0, detail => "PERMERROR: DKIM2-Signature i=$num d= does not match the rt= of i=$p" }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | } elsif (defined $mf) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | 11 | my ($mfd, $lit) = domain_of($mf); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | my $ok = $mfd && !$lit | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | 11 | ▶ | && grep { $_->[0] && !$_->[1] && relaxed_domain_match($mfd, $_->[0]) } @rts; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%6/12
$mfd && !$lit && grep({$_->[0] and not $_->[1] and relaxed_domain_match($mfd, $_->[0]);} @rts)
$mfd and not $lit
$_->[0] && !$_->[1] && relaxed_domain_match($mfd, $_->[0])
$_->[0] and not $_->[1]
MC/DC33%1/3
$mfd && !$lit && grep({$_->[0] and not $_->[1] and relaxed_domain_match($mfd, $_->[0]);} @rts)
$mfd
not $lit
grep({$_->[0] and not $_->[1] and relaxed_domain_match($mfd, $_->[0]);} @rts)
MC/DC33%1/3
$_->[0] && !$_->[1] && relaxed_domain_match($mfd, $_->[0])
$_->[0]
not $_->[1]
relaxed_domain_match($mfd, $_->[0])
Truth table50%2/4
A and not(B) && C
A= $mfdB= not $litC= grep({$_->[0] and not $_->[1] and relaxed_domain_match($mfd, $_->[0]);} @rts)
Truth table50%2/4
A and not(B) && C
A= $_->[0]B= not $_->[1]C= relaxed_domain_match($mfd, $_->[0])
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | 11 | ▶ | $lvl{custody} = $ok ? { ok => 1, detail => '' } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | : { ok => 0, detail => "PERMERROR: DKIM2-Signature i=$num mf= does not match the rt= of i=$p" }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | 0 | $lvl{detail} = 'unparseable DKIM2-Signature'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | # Timestamp age never hard-fails here; it is graded as a soft warn above. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | # mid_process: $work is a partial view (higher DKIM2-Signature headers | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | # already stripped for this top-down walk), so its locally-highest i= is | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 430 | # not necessarily the true top of the whole chain. Verifier.pm's top-nd= | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 431 | # rejection must not fire here; the real top-of-chain check is done | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 432 | # separately below against $sig_by_i (the full, original signature set). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 433 | 35 | my $vv = Mail::DKIM2::Verifier->new(PolicyCallback => $POLICY_CB); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 434 | 35 | $vv->skip_timestamp_check(1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 435 | 35 | $vv->mid_process(1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 436 | 35 | ▶ | $vv->headers_only(1) if $hdr_only; # body lost below a null Recipe | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 437 | 35 | $vv->set_pubkey_callback($cb); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 438 | 35 | eval { $vv->PRINT($work->as_string); $vv->CLOSE; 1 }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 439 | 35 | ▶ | die $@ if ref $@; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 440 | 35 | ▶ | my $r = $vv->result // 'fail'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$vv->result // "fail"
MC/DC0%0/1
$vv->result // "fail"
$vv->result
Truth table50%1/2
A
A= $vv->result
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 441 | 35 | ▶ | my $crypto = ($r eq 'pass') ? 'pass' : 'fail'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 442 | 35 | $lvl{result} = $crypto; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 443 | 35 | ▶ | $lvl{detail} = ($vv->result_detail // $lvl{detail}) unless $crypto eq 'pass'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$vv->result_detail // $lvl{"detail"}
MC/DC0%0/2
$vv->result_detail // $lvl{"detail"}
$vv->result_detail
$lvl{"detail"}
Truth table33%1/3
A // B
A= $vv->result_detailB= $lvl{"detail"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 444 | # Crypto verified but timestamp old/future -> soft amber warning. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 445 | 35 | ▶ | $lvl{result} = 'warn' if $crypto eq 'pass' && !$lvl{timestamp}{ok}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$crypto eq "pass" and not $lvl{"timestamp"}{"ok"}
MC/DC100%2/2
$crypto eq "pass" and not $lvl{"timestamp"}{"ok"}
$crypto eq "pass"
not $lvl{"timestamp"}{"ok"}
Truth table100%3/3
A and not(B)
A= $crypto eq "pass"B= not $lvl{"timestamp"}{"ok"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 446 | 35 | $_->{result} = $crypto for @{$lvl{items}}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 447 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 448 | # Local policy (-09 section 14.4 allows a top nd= only by arrangement): the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 449 | # highest-numbered DKIM2-Signature in the *whole* chain MUST NOT carry | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 450 | # nd= (mirrors the Verifier.pm permerror from Task 2.1). $sig_by_i is the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 451 | # original, unmodified full signature set for every call in this walk, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 452 | # so max(keys %$sig_by_i) is the true top-of-chain i=, not merely the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 453 | # top of this step's partial $work view (a lower, legitimately-nd= | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 454 | # hop can look locally "topmost" once higher signatures are stripped | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 455 | # for the walk; that must not trip this check). Checked last so it | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 456 | # always wins over the partial-view crypto verdict above. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 457 | 35 | ▶ | if ($sig && $num == max(keys %$sig_by_i)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$sig and $num == &max(keys %$sig_by_i)
MC/DC50%1/2
$sig and $num == &max(keys %$sig_by_i)
$sig
$num == &max(keys %$sig_by_i)
Truth table66%2/3
A and B
A= $sigB= $num == &max(keys %$sig_by_i)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 458 | 18 | my $nd = $sig->next_domain; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 459 | 18 | ▶ | if (defined $nd && length $nd) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $nd and length $nd
MC/DC50%1/2
defined $nd and length $nd
defined $nd
length $nd
Truth table66%2/3
A and B
A= defined $ndB= length $nd
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 460 | 1 | $lvl{result} = 'fail'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 461 | 1 | $lvl{detail} = "DKIM2-Signature i=$num unexpected nd= tag"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 462 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 463 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 464 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 465 | 35 | return \%lvl; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 466 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 467 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 468 | 8 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 469 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 470 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||