| 1 | #!/usr/bin/perl -w | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 19 | ▶ | use 5.020; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 19 | ▶ | use Path::Tiny; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 19 | ▶ | use Email::MIME; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 19 | ▶ | use lib 'lib'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 19 | ▶ | use Mail::DKIM2::Common qw( | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | extract_mi_version | ||||||||||||||||||||||||||||
| 9 | parse_mime | ||||||||||||||||||||||||||||
| 10 | valid_sequence | ||||||||||||||||||||||||||||
| 11 | chain_number_error | ||||||||||||||||||||||||||||
| 12 | mi_version_tag | ||||||||||||||||||||||||||||
| 13 | unkeyable_signature_error | ||||||||||||||||||||||||||||
| 14 | 19 | ); | |||||||||||||||||||||||||||
| 15 | 19 | ▶ | use Mail::DKIM2::Key qw(parse_dkim_key_record); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | 19 | ▶ | use Mail::DKIM2::Signature; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | 19 | ▶ | use Mail::DKIM2::MessageInstance; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | 19 | ▶ | use Mail::DKIM2::Verifier; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 19 | 19 | ▶ | use List::Util qw(max); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 20 | 19 | ▶ | use JSON; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 21 | 19 | ▶ | use Getopt::Long qw(GetOptions); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 19 | my $ignore_ts = 0; | |||||||||||||||||||||||||||
| 24 | 19 | my $dns_json; | |||||||||||||||||||||||||||
| 25 | 19 | ▶ | GetOptions('ignore-timestamps' => \$ignore_ts, 'dns-json=s' => \$dns_json) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 26 | or die "usage: $0 [--ignore-timestamps] [--dns-json FILE] <file>\n"; | ||||||||||||||||||||||||||||
| 27 | # Keys come from a dns.json (interop test fixture), never live DNS: this is the | ||||||||||||||||||||||||||||
| 28 | # cross-implementation checker, not the production verifier. Default to the | ||||||||||||||||||||||||||||
| 29 | # copy shipped with the tests, then the interop repository's shared file. | ||||||||||||||||||||||||||||
| 30 | $dns_json //= $ENV{DKIM2_DNS_JSON} | ||||||||||||||||||||||||||||
| 31 | 19 | ▶ | // (-e 't/data/dns.json' ? 't/data/dns.json' : '../dns.json'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%2/4
$dns_json //= $ENV{"DKIM2_DNS_JSON"} // (-e "t/data/dns.json" ? "t/data/dns.json" : "../dns.json")
$ENV{"DKIM2_DNS_JSON"} // (-e "t/data/dns.json" ? "t/data/dns.json" : "../dns.json")
MC/DC0%0/1
$dns_json //= $ENV{"DKIM2_DNS_JSON"} // (-e "t/data/dns.json" ? "t/data/dns.json" : "../dns.json")
$dns_json
Truth table50%1/2
A
A= $dns_json
| |||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 19 | my $f1 = shift; | |||||||||||||||||||||||||||
| 34 | 19 | my $data = path($f1)->slurp; | |||||||||||||||||||||||||||
| 35 | 19 | $data =~ s/\r//gs; | |||||||||||||||||||||||||||
| 36 | 19 | $data =~ s/\n/\r\n/gs; | |||||||||||||||||||||||||||
| 37 | 19 | my $msg1 = parse_mime($data); | |||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 19 | my $dns = decode_json(path($dns_json)->slurp); | |||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | # The whole message through the Verifier first, so a message with several | ||||||||||||||||||||||||||||
| 42 | # faults reports the primary error in the library's order (contract C9), | ||||||||||||||||||||||||||||
| 43 | # not the order the walk below happens to meet them. | ||||||||||||||||||||||||||||
| 44 | { | ||||||||||||||||||||||||||||
| 45 | 19 | my $verifier = Mail::DKIM2::Verifier->new(); | |||||||||||||||||||||||||||
| 46 | 19 | ▶ | $verifier->skip_timestamp_check(1) if $ignore_ts; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 47 | 19 | ▶ | $verifier->set_pubkey_callback(sub { find_key(@_) }); | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 48 | 0 | ▶ | $verifier->set_policy_callback(sub { find_policy(@_) }); | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||
| 49 | # The bytes as given, not Email::MIME's re-serialisation of them: that | ||||||||||||||||||||||||||||
| 50 | # rewrites a header section it cannot parse (a first line starting with | ||||||||||||||||||||||||||||
| 51 | # WSP vanished), and the Verifier must judge what arrived. | ||||||||||||||||||||||||||||
| 52 | 19 | $verifier->PRINT($data); | |||||||||||||||||||||||||||
| 53 | 19 | $verifier->CLOSE; | |||||||||||||||||||||||||||
| 54 | 19 | ▶ | unless ($verifier->result =~ /\A(?:pass|none)\z/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 55 | 15 | ▶ | say STDERR $verifier->details if $verifier->details; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 56 | 15 | die "DKIM2: " . $verifier->result_detail() . "\n"; | |||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | # Header-level PERMERRORs, as the Verifier reports them. The walk below | ||||||||||||||||||||||||||||
| 61 | # is driven by the i= and m= values it can read, so without this a junk | ||||||||||||||||||||||||||||
| 62 | # DKIM2-Signature with no usable i= -- even the only one -- would simply never | ||||||||||||||||||||||||||||
| 63 | # be visited, and an i= or m= above MAX_CHAIN_LENGTH would be a loop bound. | ||||||||||||||||||||||||||||
| 64 | 4 | for my $h ($msg1->header_raw('DKIM2-Signature')) { | |||||||||||||||||||||||||||
| 65 | 8 | my $sig = eval { Mail::DKIM2::Signature->parse($h) }; | |||||||||||||||||||||||||||
| 66 | 8 | ▶ | my $i = $sig ? $sig->sequence : undef; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 67 | 8 | ▶ | die unkeyable_signature_error($h) . "\n" unless valid_sequence($i); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 68 | 8 | ▶ | my $e = chain_number_error('DKIM2-Signature', 'i', $i) | ||||||||||||||||||||||||||
|
Condition33%1/3
chain_number_error("DKIM2-Signature", "i", $i) // chain_number_error("DKIM2-Signature", "m", $sig->version, $i)
MC/DC0%0/2
chain_number_error("DKIM2-Signature", "i", $i) // chain_number_error("DKIM2-Signature", "m", $sig->version, $i)
chain_number_error("DKIM2-Signature", "i", $i)
chain_number_error("DKIM2-Signature", "m", $sig->version, $i)
Truth table33%1/3
A // B
A= chain_number_error("DKIM2-Signature", "i", $i)B= chain_number_error("DKIM2-Signature", "m", $sig->version, $i)
| |||||||||||||||||||||||||||||
| 69 | // chain_number_error('DKIM2-Signature', 'm', $sig->version, $i); | ||||||||||||||||||||||||||||
| 70 | 8 | ▶ | die "$e\n" if $e; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||
| 72 | 4 | for my $h ($msg1->header_raw('Message-Instance')) { | |||||||||||||||||||||||||||
| 73 | 5 | my $e = chain_number_error('Message-Instance', 'm', mi_version_tag($h)); | |||||||||||||||||||||||||||
| 74 | 5 | ▶ | die "$e\n" if $e; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | 4 | my %map = map { _geti($_) => $_ } $msg1->header('DKIM2-Signature'); | |||||||||||||||||||||||||||
| 78 | 4 | ▶ | my $num = %map ? max(keys %map) : 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 79 | 4 | my %mimap = map { extract_mi_version($_) => $_ } $msg1->header('Message-Instance'); | |||||||||||||||||||||||||||
| 80 | 4 | ▶ | my $instance = %mimap ? max(keys %mimap) : 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | # The true top of the chain, remembered before the walk below starts stripping | ||||||||||||||||||||||||||||
| 83 | # signatures off $msg1. Every step after the first verifies a PARTIAL view, in | ||||||||||||||||||||||||||||
| 84 | # which the locally-highest i= is not the real top -- see mid_process below. | ||||||||||||||||||||||||||||
| 85 | 4 | my $top_i = $num; | |||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | # -09 §14: "there MUST NOT be a Message-Instance field with a higher m= | ||||||||||||||||||||||||||||
| 88 | # value than occurs in any DKIM2-Signature field" -- reported as "PERMERROR | ||||||||||||||||||||||||||||
| 89 | # Message-Instance m=<x> is not signed". Checked up front because the walk | ||||||||||||||||||||||||||||
| 90 | # below happily verifies and reports "OK Message-Instance" for an instance | ||||||||||||||||||||||||||||
| 91 | # above every signature, which is precisely the unaccountable instance the | ||||||||||||||||||||||||||||
| 92 | # rule exists to reject. This tool is a conformance checker, so it is strict | ||||||||||||||||||||||||||||
| 93 | # even though our own inbound path stamps an unsigned MI internally. | ||||||||||||||||||||||||||||
| 94 | 4 | ▶ | if ($instance) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 95 | 4 | ▶ | my $top_signed = %map ? max(map { _getv($_) } values %map) : 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 96 | 4 | ▶ | die "PERMERROR: Message-Instance m=$instance is not signed\n" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 97 | if $instance > $top_signed; | ||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | # Set once past an instance with a null body Recipe: the body below it is | ||||||||||||||||||||||||||||
| 101 | # lost, so lower levels check header hashes only, undoing header Recipes only. | ||||||||||||||||||||||||||||
| 102 | 4 | my $hdr_only = 0; | |||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | 4 | while (1) { | |||||||||||||||||||||||||||
| 105 | 12 | ▶ | my $hi = $num ? _getv($map{$num}) : 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 106 | 12 | ▶ | while ($instance > $hi) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 107 | 5 | my ($check, $error) = Mail::DKIM2::MessageInstance->verify($msg1, HeadersOnly => $hdr_only); | |||||||||||||||||||||||||||
| 108 | 5 | ▶ | die "ERROR: failed to verify instance $instance: $error\n" unless $check; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 109 | 5 | ▶ | die "DIDN'T FIND TOP $instance <> $check" unless $instance == $check; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 110 | 5 | say "OK Message-Instance: m=$check"; | |||||||||||||||||||||||||||
| 111 | 5 | my $mi = Mail::DKIM2::MessageInstance->parse($mimap{$instance}); | |||||||||||||||||||||||||||
| 112 | 5 | ▶ | $hdr_only = 1 if $mi && $mi->unrecoverable; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$mi and $mi->unrecoverable
MC/DC0%0/2
$mi and $mi->unrecoverable
$mi
$mi->unrecoverable
Truth table33%1/3
A and B
A= $miB= $mi->unrecoverable
| |||||||||||||||||||||||||||||
| 113 | 5 | ▶ | die "Failed to undo" unless Mail::DKIM2::MessageInstance->undo($msg1, HeadersOnly => $hdr_only); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 114 | # Email::MIME keeps internal caches which get broken by replacing the body | ||||||||||||||||||||||||||||
| 115 | 5 | $instance--; | |||||||||||||||||||||||||||
| 116 | 5 | ▶ | last unless $instance; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 117 | 1 | $msg1 = parse_mime($msg1->as_string); | |||||||||||||||||||||||||||
| 118 | 1 | %mimap = map { extract_mi_version($_) => $_ } $msg1->header('Message-Instance'); | |||||||||||||||||||||||||||
| 119 | 0 | %map = map { _geti($_) => $_ } $msg1->header('DKIM2-Signature'); | |||||||||||||||||||||||||||
| 120 | 1 | ▶ | my $newnum = %map ? max(keys %map) : 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 121 | 1 | ▶ | my $newinstance = %mimap ? max(keys %mimap) : 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 122 | 1 | ▶ | die "MISMATCH TOP DKIM" unless $num == $newnum; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 123 | 1 | ▶ | die "MISMATCH TOP VERSION $instance <> $newinstance" unless $instance == $newinstance; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 124 | 1 | ▶ | die "NO SUCH Message-Instance m=$instance" unless $mimap{$instance}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||
| 126 | 12 | ▶ | last unless $num; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 127 | 8 | my $h = $map{$num}; | |||||||||||||||||||||||||||
| 128 | 8 | ▶ | die "NO SUCH DKIM2-Header i=$num" unless $h; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||
| 130 | # Create a verifier for this specific signature | ||||||||||||||||||||||||||||
| 131 | 8 | my $verifier = Mail::DKIM2::Verifier->new(); | |||||||||||||||||||||||||||
| 132 | 8 | ▶ | $verifier->skip_timestamp_check(1) if $ignore_ts; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 133 | # After the first step this is a partial view (higher DKIM2-Signature | ||||||||||||||||||||||||||||
| 134 | # headers have been stripped), so its locally-highest i= is not the real | ||||||||||||||||||||||||||||
| 135 | # top of the chain and Verifier.pm's top-nd= rejection must not fire: a | ||||||||||||||||||||||||||||
| 136 | # legitimate §12.3 nd= bridge below the top looks locally topmost here. | ||||||||||||||||||||||||||||
| 137 | # The first step still sees the whole chain, so a true top nd= is caught. | ||||||||||||||||||||||||||||
| 138 | 8 | ▶ | $verifier->mid_process(1) if $num < $top_i; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 139 | 8 | ▶ | $verifier->headers_only(1) if $hdr_only; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 140 | 8 | ▶ | $verifier->set_pubkey_callback(sub { find_key(@_) }); | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 141 | 0 | ▶ | $verifier->set_policy_callback(sub { find_policy(@_) }); | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||
| 142 | 8 | $verifier->PRINT($msg1->as_string()); | |||||||||||||||||||||||||||
| 143 | 8 | $verifier->CLOSE; | |||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||
| 145 | 8 | ▶ | if ($verifier->result eq 'pass') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 146 | 8 | say "OK DKIM2-Signature: i=$num; m=$instance"; | |||||||||||||||||||||||||||
| 147 | } else { | ||||||||||||||||||||||||||||
| 148 | # The primary error (contract C9) on a line of its own, first, then | ||||||||||||||||||||||||||||
| 149 | # the result word with it. | ||||||||||||||||||||||||||||
| 150 | 0 | ▶ | say STDERR $verifier->details if $verifier->details; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 151 | 0 | die "DKIM2-Signature i=$num: " . $verifier->result_detail() . "\n"; | |||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||
| 153 | 8 | $msg1->header_raw_set('DKIM2-Signature', grep { _geti($_) < $num } $msg1->header('DKIM2-Signature')); | |||||||||||||||||||||||||||
| 154 | 8 | $num--; | |||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||
| 157 | # i= and m= of a DKIM2-Signature, read with the tag-list parser so FWS around | ||||||||||||||||||||||||||||
| 158 | # "=" (which the syntax allows) is no obstacle. Both are already known to be | ||||||||||||||||||||||||||||
| 159 | # in range (checked above). | ||||||||||||||||||||||||||||
| 160 | 22 | ▶ | sub _geti { return _sigtag(shift, 'sequence') } | ||||||||||||||||||||||||||
|
Subroutine
_geti: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 161 | 16 | ▶ | sub _getv { return _sigtag(shift, 'version') } | ||||||||||||||||||||||||||
|
Subroutine
_getv: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||
| 163 | 38 | ▶ | sub _sigtag { | ||||||||||||||||||||||||||
|
Subroutine
_sigtag: called CC=4 SCAR=15.2
| |||||||||||||||||||||||||||||
| 164 | 38 | my ($arg, $tag) = @_; | |||||||||||||||||||||||||||
| 165 | 38 | ▶ | my $sig = eval { Mail::DKIM2::Signature->parse($arg) } or return 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 166 | 38 | my $v = $sig->$tag; | |||||||||||||||||||||||||||
| 167 | 38 | ▶ | return (defined $v && $v =~ /\A[0-9]+\z/) ? 0 + $v : 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $v and $v =~ /\A[0-9]+\z/u
MC/DC0%0/2
defined $v and $v =~ /\A[0-9]+\z/u
defined $v
$v =~ /\A[0-9]+\z/u
Truth table33%1/3
A and B
A= defined $vB= $v =~ /\A[0-9]+\z/u
| |||||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||
| 170 | # The Domain Policy Record (-09 section 3.8) from the same dns.json: the TXT | ||||||||||||||||||||||||||||
| 171 | # strings at _domainkey.<domain>, none for a domain it does not list. | ||||||||||||||||||||||||||||
| 172 | 0 | ▶ | sub find_policy { | ||||||||||||||||||||||||||
|
Subroutine
find_policy: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 173 | 0 | my ($dom) = @_; | |||||||||||||||||||||||||||
| 174 | 0 | ▶ | return [ map { $_->[1] } @{ $dns->{$dom} && $dns->{$dom}{_domainkey} || [] } ]; | ||||||||||||||||||||||||||
|
Condition0%0/5
$dns->{$dom} && $dns->{$dom}{'_domainkey'} || []
$dns->{$dom} and $dns->{$dom}{"_domainkey"}
MC/DC0%0/2
$dns->{$dom} && $dns->{$dom}{'_domainkey'} || []
$dns->{$dom}
$dns->{$dom}{"_domainkey"}
Truth table0%0/3
A and B
A= $dns->{$dom}B= $dns->{$dom}{"_domainkey"}
| |||||||||||||||||||||||||||||
| 175 | } | ||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||
| 177 | 22 | ▶ | sub find_key { | ||||||||||||||||||||||||||
|
Subroutine
find_key: called CC=6 SCAR=18.7
| |||||||||||||||||||||||||||||
| 178 | 22 | my ($signature, $idx) = @_; | |||||||||||||||||||||||||||
| 179 | 22 | ▶ | $idx //= 0; | ||||||||||||||||||||||||||
|
Condition50%1/2
$idx //= 0
MC/DC0%0/1
$idx //= 0
$idx
Truth table50%1/2
A
A= $idx
| |||||||||||||||||||||||||||||
| 180 | 22 | my $sel = $signature->selector($idx); | |||||||||||||||||||||||||||
| 181 | 22 | my $dom = $signature->domain; | |||||||||||||||||||||||||||
| 182 | 22 | ▶ | my $records = $dns->{$dom}{"$sel._domainkey"} or return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 183 | # As the Verifier's own DNS fetch does (-09 sections 3.7, 14.5): records | ||||||||||||||||||||||||||||
| 184 | # beginning v= other than DKIM1 are ignored; no record is "does not | ||||||||||||||||||||||||||||
| 185 | # exist"; one that is there but unusable is a PERMERROR with its reason | ||||||||||||||||||||||||||||
| 186 | # ("is malformed", "has been revoked", ...). | ||||||||||||||||||||||||||||
| 187 | 22 | ▶ | my @txt = Mail::DKIM2::Key::key_records(map { $_->[1] } @$records) or return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 188 | 22 | ▶ | die "PERMERROR: has multiple records\n" if @txt > 1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 189 | 22 | my ($key, $why) = parse_dkim_key_record($txt[0]); | |||||||||||||||||||||||||||
| 190 | 22 | ▶ | die "PERMERROR: $why\n" unless $key; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 191 | 22 | return $key; | |||||||||||||||||||||||||||
| 192 | } | ||||||||||||||||||||||||||||