| 1 | package Mail::DKIM2::Key; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | 222 | ▶ | use 5.20.0; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 222 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 222 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 222 | our $VERSION = '0.34'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 222 | ▶ | use Scalar::Util (); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 222 | ▶ | use MIME::Base64 qw(decode_base64); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 222 | ▶ | use Crypt::PK::RSA; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 222 | ▶ | use Crypt::PK::Ed25519; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 222 | ▶ | use Crypt::Digest::SHA256 qw(sha256); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 222 | ▶ | use Mail::DKIM2::TagValueList (); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 222 | ▶ | use Mail::DKIM2::Util (); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 222 | ▶ | use Exporter 'import'; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 222 | our @EXPORT_OK = qw( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | signature_algorithm | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | signature_algorithm_for_key | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | load_private_key | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | load_private_key_data | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | parse_dkim_pubkey | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | parse_dkim_key_record | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | key_records | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | domain_policy | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | query_domain_policy | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | policy_from_source | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | # The signing algorithms this library implements (-09 sections 3.2, 3.3), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | # for the Signer and the Verifier alike: the key class each needs, how it | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | # signs and verifies the signing input of section 12.8, and the smallest key | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | # it accepts. Names are case-sensitive (section 2.14) and match exactly. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | my %SIGNATURE_ALGORITHM = ( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 'rsa-sha256' => { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | name => 'rsa-sha256', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | key_class => 'Crypt::PK::RSA', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | min_bits => 1024, # section 3.2: Signers MUST use at least this | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 532 | ▶ | sign => sub { $_[0]->sign_message($_[1], 'SHA256', 'v1.5') }, | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 770 | ▶ | verify => sub { $_[0]->verify_message($_[2], $_[1], 'SHA256', 'v1.5') }, | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 'ed25519-sha256' => { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | name => 'ed25519-sha256', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | key_class => 'Crypt::PK::Ed25519', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | # The SHA-256 of the input is what PureEdDSA signs (section 3.3). | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 2 | ▶ | sign => sub { $_[0]->sign_message(sha256($_[1])) }, | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 1 | ▶ | verify => sub { $_[0]->verify_message($_[2], sha256($_[1])) }, | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 222 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | # signature_algorithm($name): the entry above for an s= item's algorithm | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | # name -- a hashref with name, key_class, sign->($key, $input) and | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | # verify->($key, $input, $signature), and min_bits for RSA -- or undef for a | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | # name this library does not implement. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 3246 | ▶ | sub signature_algorithm { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
signature_algorithm: called CC=2 SCAR=9.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 0 | ▶ | my ($name) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
signature_algorithm: not called CC=2 SCAR=9.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 0 | ▶ | return defined $name ? $SIGNATURE_ALGORITHM{$name} : undef; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | # signature_algorithm_for_key($key): the name of the algorithm a key object | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | # signs with, or undef for a key of no implemented type. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 552 | ▶ | sub signature_algorithm_for_key { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
signature_algorithm_for_key: called CC=4 SCAR=19.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 0 | ▶ | my ($key) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
signature_algorithm_for_key: not called CC=4 SCAR=19.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 0 | ▶ | return unless Scalar::Util::blessed($key); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 0 | for my $name (sort keys %SIGNATURE_ALGORITHM) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 0 | ▶ | return $name if $key->isa($SIGNATURE_ALGORITHM{$name}{key_class}); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | # Load a private key from a PEM file. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | # Returns a Crypt::PK::RSA or Crypt::PK::Ed25519 object depending on key type. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 163 | ▶ | sub load_private_key { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
load_private_key: called CC=3 SCAR=15.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 0 | ▶ | my ($file) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
load_private_key: not called CC=3 SCAR=15.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | # Try RSA first, then Ed25519 | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 0 | my $key = eval { Crypt::PK::RSA->new($file) }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 0 | ▶ | die $@ if ref $@; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 0 | ▶ | return $key if $key; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 0 | return Crypt::PK::Ed25519->new($file); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | # Load a private key from key MATERIAL rather than a filename, for callers whose | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | # keys live in a database rather than on disk. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | # Accepts PEM as stored, and also bare base64 with the armor stripped, which is | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | # how some key stores keep it. Returns a Crypt::PK::RSA or Crypt::PK::Ed25519 | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | # object, or undef -- never dies, so a caller signing live mail can log and | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | # carry on rather than losing the message. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 12 | ▶ | sub load_private_key_data { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
load_private_key_data: called CC=14 SCAR=39.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 0 | ▶ | my ($data) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
load_private_key_data: not called CC=14 SCAR=39.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 0 | ▶ | return unless defined $data && length $data; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition50%3/6
defined $data and length $data
defined $data and length $data
MC/DC100%2/2
defined $data and length $data
defined $data
length $data
MC/DC0%0/2
defined $data and length $data
defined $data
length $data
Truth table100%3/3
A and B
A= defined $dataB= length $data
Truth table0%0/3
A and B
A= defined $dataB= length $data
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 0 | ▶ | if ($data =~ /-----BEGIN/) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 0 | my $key = eval { Crypt::PK::RSA->new(\$data) }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 0 | ▶ | die $@ if ref $@; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 0 | ▶ | return $key if $key; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 0 | $key = eval { Crypt::PK::Ed25519->new(\$data) }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 0 | ▶ | die $@ if ref $@; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 0 | return $key; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 0 | (my $b64 = $data) =~ s/\s+//g; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 0 | ▶ | return unless length $b64; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 0 | my $der = eval { decode_base64($b64) }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 0 | ▶ | die $@ if ref $@; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 0 | ▶ | return unless defined $der && length $der; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition16%1/6
defined $der and length $der
defined $der and length $der
MC/DC0%0/2
defined $der and length $der
defined $der
length $der
MC/DC0%0/2
defined $der and length $der
defined $der
length $der
Truth table33%1/3
A and B
A= defined $derB= length $der
Truth table0%0/3
A and B
A= defined $derB= length $der
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 0 | my $key = eval { Crypt::PK::RSA->new(\$der) }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 0 | ▶ | die $@ if ref $@; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 0 | ▶ | return $key if $key; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 0 | $key = eval { Crypt::PK::Ed25519->new(\$der) }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 0 | ▶ | die $@ if ref $@; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 0 | return $key; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | # A key object from a valid record: the key, or nothing (a key type this | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | # library does not implement, or p= that is not a key of that type). | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 622 | ▶ | sub parse_dkim_pubkey { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse_dkim_pubkey: called CC=1 SCAR=1.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 0 | ▶ | my ($key_txt) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse_dkim_pubkey: not called CC=1 SCAR=1.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 0 | my ($key) = parse_dkim_key_record($key_txt); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 0 | return $key; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | # Parse and validate a key record (draft-ietf-dkim-dkim2-dns §3.2, §3.4.1; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | # -09 §14.5 says a Verifier MUST NOT use a malformed one). Returns the | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | # key object, or (undef, $why) where $why completes "public key <selector> | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | # ...": "has a syntax error", "has been revoked" or "has an unsupported key | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | # type". The whole record is checked, not searched: a repeated tag (an empty | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | # p= before a good one, say) makes it invalid, and v=, if present, must be | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | # the first tag and exactly DKIM1. Tag names are case sensitive here, as in | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | # DKIM1. Unknown and retired tags (h=, n=, s=, t=) are ignored, once their | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | # values have passed the tag-list grammar. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 761 | ▶ | sub parse_dkim_key_record { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse_dkim_key_record: called CC=14 SCAR=36.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 0 | ▶ | my ($txt) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse_dkim_key_record: not called CC=14 SCAR=36.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 0 | my $syntax = 'has a syntax error'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 0 | ▶ | my ($tag, $order) = _parse_dns_tag_list($txt) or return (undef, $syntax); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 0 | my %tag = %$tag; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 0 | ▶ | if (exists $tag{v}) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 0 | ▶ | return (undef, $syntax) unless $order->[0] eq 'v' && $tag{v} eq 'DKIM1'; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition50%3/6
$order->[0] eq "v" and $tag{"v"} eq "DKIM1"
$order->[0] eq "v" and $tag{"v"} eq "DKIM1"
MC/DC100%2/2
$order->[0] eq "v" and $tag{"v"} eq "DKIM1"
$order->[0] eq "v"
$tag{"v"} eq "DKIM1"
MC/DC0%0/2
$order->[0] eq "v" and $tag{"v"} eq "DKIM1"
$order->[0] eq "v"
$tag{"v"} eq "DKIM1"
Truth table100%3/3
A and B
A= $order->[0] eq "v"B= $tag{"v"} eq "DKIM1"
Truth table0%0/3
A and B
A= $order->[0] eq "v"B= $tag{"v"} eq "DKIM1"
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 0 | ▶ | return (undef, $syntax) unless exists $tag{p}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 0 | (my $p = $tag{p}) =~ s/[ \t\r\n]//g; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 0 | ▶ | return (undef, 'has been revoked') unless length $p; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 0 | ▶ | return (undef, $syntax) unless Mail::DKIM2::Util::is_base64string($p); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 0 | ▶ | my $k = $tag{k} // 'rsa'; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%2/4
$tag{"k"} // "rsa"
$tag{"k"} // "rsa"
MC/DC100%1/1
$tag{"k"} // "rsa"
$tag{"k"}
MC/DC0%0/1
$tag{"k"} // "rsa"
$tag{"k"}
Truth table100%2/2
A
A= $tag{"k"}
Truth table0%0/2
A
A= $tag{"k"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 0 | my $key = _key_from_p($k, $p); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 0 | ▶ | return $key if $key; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | # -09 section 14.6 (contract E5): an RSA key this verifier regards as | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | # too short. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 0 | ▶ | return (undef, 'too short') if $k eq 'rsa' && _rsa_bits($p); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition50%3/6
$k eq "rsa" and _rsa_bits($p)
$k eq "rsa" and _rsa_bits($p)
MC/DC100%2/2
$k eq "rsa" and _rsa_bits($p)
$k eq "rsa"
_rsa_bits($p)
MC/DC0%0/2
$k eq "rsa" and _rsa_bits($p)
$k eq "rsa"
_rsa_bits($p)
Truth table100%3/3
A and B
A= $k eq "rsa"B= _rsa_bits($p)
Truth table0%0/3
A and B
A= $k eq "rsa"B= _rsa_bits($p)
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | # -09 §14.5 (contract D7): base64 that is not a usable key of its type. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 0 | ▶ | return (undef, $k eq 'rsa' || $k eq 'ed25519' ? 'is malformed' : 'has an unsupported key type'); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition50%3/6
$k eq "rsa" or $k eq "ed25519"
$k eq "rsa" or $k eq "ed25519"
MC/DC100%2/2
$k eq "rsa" or $k eq "ed25519"
$k eq "rsa"
$k eq "ed25519"
MC/DC0%0/2
$k eq "rsa" or $k eq "ed25519"
$k eq "rsa"
$k eq "ed25519"
Truth table100%3/3
A or B
A= $k eq "rsa"B= $k eq "ed25519"
Truth table0%0/3
A or B
A= $k eq "rsa"B= $k eq "ed25519"
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | # A TXT record as a DNS tag=value list (DKIMKEYS -03 section 2.6: the | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | # Tag=Value rules of the spec's section 8): (\%tags, \@names_in_order), or | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | # the empty list for a syntax error -- a repeated tag, a spec that is not | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | # name=value, a value outside the tag-list grammar, or no tag at all. Tag | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | # names are case sensitive. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 777 | ▶ | sub _parse_dns_tag_list { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_parse_dns_tag_list: called CC=8 SCAR=28.3
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 0 | ▶ | my ($txt) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_parse_dns_tag_list: not called CC=8 SCAR=28.3
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 0 | ▶ | return unless defined $txt; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 0 | my (%tag, @order); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 0 | for my $spec (split /;/, $txt, -1) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 0 | ▶ | next if $spec =~ /\A[ \t\r\n]*\z/; # empty spec, e.g. after a trailing ";" | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 0 | ▶ | my ($name, $value) = $spec =~ /\A[ \t\r\n]*([A-Za-z][A-Za-z0-9_]*)[ \t\r\n]*=(.*)\z/s | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | or return; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 0 | ▶ | return if exists $tag{$name}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 0 | $value = _trim_wsp($value); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | # Every value, unknown tags' included, must fit the tag-list grammar | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | # (RFC 6376 §3.2 VALCHAR): ignoring a tag comes after parsing it | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | # (follow-up review F5). | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 0 | ▶ | return unless $value =~ /\A$Mail::DKIM2::TagValueList::TAG_VALUE\z/; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 0 | $tag{$name} = $value; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 0 | push @order, $name; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 0 | ▶ | return unless @order; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 0 | return (\%tag, \@order); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 739 | ▶ | sub _key_from_p { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_key_from_p: called CC=8 SCAR=27.7
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 0 | ▶ | my ($k, $p) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_key_from_p: not called CC=8 SCAR=27.7
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 0 | ▶ | if ($k eq 'ed25519') { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | # -09 §14.5: an Ed25519 key is exactly 32 octets (RFC 8032), the | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | # raw key; anything else -- a DER SubjectPublicKeyInfo included -- | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | # is malformed. Never die on one: return undef so the verifier | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | # reports a clean permerror instead of aborting the whole operation | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | # (the RSA branch below is likewise eval-wrapped). | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 0 | my $raw = decode_base64($p); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 0 | ▶ | return unless length($raw) == 32; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 0 | my $key = eval { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | 0 | my $pk = Crypt::PK::Ed25519->new(); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 0 | $pk->import_key_raw($raw, 'public'); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | 0 | $pk; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 0 | ▶ | die $@ if ref $@; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 0 | return $key; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | # Any other key type is unrecognised, and ignored: never read as RSA. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 0 | ▶ | return unless $k eq 'rsa'; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | # RSA: p= is base64-encoded SubjectPublicKeyInfo DER. A key under | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | # 1024 bits is too short: -09 section 3.2 leaves it to the Verifier, and | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | # we refuse it (contract E5). | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 0 | my $der = decode_base64($p); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | 0 | my $rsa = eval { Crypt::PK::RSA->new(\$der) }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 0 | ▶ | die $@ if ref $@; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 0 | ▶ | return unless $rsa && $rsa->size * 8 >= 1024; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition50%3/6
$rsa and $rsa->size * 8 >= 1024
$rsa and $rsa->size * 8 >= 1024
MC/DC100%2/2
$rsa and $rsa->size * 8 >= 1024
$rsa
$rsa->size * 8 >= 1024
MC/DC0%0/2
$rsa and $rsa->size * 8 >= 1024
$rsa
$rsa->size * 8 >= 1024
Truth table100%3/3
A and B
A= $rsaB= $rsa->size * 8 >= 1024
Truth table0%0/3
A and B
A= $rsaB= $rsa->size * 8 >= 1024
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 0 | return $rsa; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | # True when $p (base64) loads as an RSA key, of whatever size: tells a key | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | # that is too short from one that is malformed. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 5 | ▶ | sub _rsa_bits { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_rsa_bits: called CC=3 SCAR=15.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 0 | ▶ | my ($p) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_rsa_bits: not called CC=3 SCAR=15.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 0 | my $der = decode_base64($p); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 0 | my $rsa = eval { Crypt::PK::RSA->new(\$der) }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | 0 | ▶ | die $@ if ref $@; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 0 | ▶ | return $rsa ? $rsa->size * 8 : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | # key_records(@txt): the TXT records at a selector that are candidate key | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | # records (-09 section 3.7, DKIMKEYS -03 section 3): each one but those that | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | # begin with a "v=" tag whose value is not DKIM1. More than one left is the | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | # caller's "has multiple records". | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | 112 | ▶ | sub key_records { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
key_records: called CC=2 SCAR=9.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 0 | ▶ | return grep { my $v = _leading_v($_); !defined $v || $v eq 'DKIM1' } @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
key_records: not called CC=2 SCAR=9.2
Pod
documented
Condition50%3/6
!defined($v) || $v eq 'DKIM1'
!defined($v) || $v eq 'DKIM1'
MC/DC100%2/2
!defined($v) || $v eq 'DKIM1'
!defined($v)
$v eq 'DKIM1'
MC/DC0%0/2
!defined($v) || $v eq 'DKIM1'
!defined($v)
$v eq 'DKIM1'
Truth table100%3/3
not(A) || B
A= !defined($v)B= $v eq 'DKIM1'
Truth table0%0/3
not(A) || B
A= !defined($v)B= $v eq 'DKIM1'
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | # The value of a TXT record's first tag when that tag is "v", else undef: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | # read without parsing the rest, since -09 section 3.7 sorts records on it | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | # before any is used. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 145 | ▶ | sub _leading_v { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_leading_v: called CC=3 SCAR=15.3
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | 0 | ▶ | my ($txt) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_leading_v: not called CC=3 SCAR=15.3
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | 0 | ▶ | return unless defined $txt; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | 0 | ▶ | $txt =~ /\A[ \t\r\n]*v[ \t\r\n]*=[ \t\r\n]*([^;]*?)[ \t\r\n]*(?:;|\z)/ or return; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | 0 | return $1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | # $s without leading or trailing WSP, in linear time: a TXT record is | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | # whatever the signer's DNS serves (up to 64 KB), and a trailing-WSP match | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | # tried at every position of a long inner run of spaces is quadratic. The | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | # lookbehind starts it only at the beginning of a run. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | 2312 | ▶ | sub _trim_wsp { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_trim_wsp: called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | 0 | ▶ | my ($s) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_trim_wsp: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | 0 | $s =~ s/\A[ \t\r\n]+//; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | 0 | $s =~ s/(?<![ \t\r\n])[ \t\r\n]+\z//; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | 0 | return $s; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | # domain_policy(@txt): the Domain Policy Record held by the TXT records at | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | # _domainkey.<domain> (-09 section 3.8, DKIMKEYS -03 section 6): 'strict' | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | # when subdomains are not authorized to make that domain's From Authentic, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | # 'open' when they are (no record, no f=, or no "strict" flag), or | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | # 'multiple' for more than one record. Only records beginning with the tag | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | # v=DKIM1 count. A record that does so but does not parse is 'strict': the | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | # spec gives it no outcome, so it fails closed (contract E3.2). | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | 29 | ▶ | sub domain_policy { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
domain_policy: called CC=9 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 0 | ▶ | my @dpr = grep { (_leading_v($_) // '') eq 'DKIM1' } @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
domain_policy: not called CC=9 SCAR=30.0
Pod
documented
Condition50%2/4
_leading_v($_) // ""
_leading_v($_) // ""
MC/DC100%1/1
_leading_v($_) // ""
_leading_v($_)
MC/DC0%0/1
_leading_v($_) // ""
_leading_v($_)
Truth table100%2/2
A
A= _leading_v($_)
Truth table0%0/2
A
A= _leading_v($_)
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | 0 | ▶ | return 'open' unless @dpr; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | 0 | ▶ | return 'multiple' if @dpr > 1; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | 0 | ▶ | my ($tag) = _parse_dns_tag_list($dpr[0]) or return 'strict'; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | 0 | my $f = $tag->{f}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | 0 | ▶ | return 'open' unless defined $f && length $f; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition50%3/6
defined $f and length $f
defined $f and length $f
MC/DC100%2/2
defined $f and length $f
defined $f
length $f
MC/DC0%0/2
defined $f and length $f
defined $f
length $f
Truth table100%3/3
A and B
A= defined $fB= length $f
Truth table0%0/3
A and B
A= defined $fB= length $f
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | 0 | my @flags = map { _trim_wsp($_) } split /:/, $f, -1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | 0 | ▶ | return 'strict' if grep { !/\A[A-Za-z](?:[A-Za-z0-9-]*[A-Za-z0-9])?\z/ } @flags; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | 0 | ▶ | return (grep { $_ eq 'strict' } @flags) ? 'strict' : 'open'; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | # query_domain_policy($resolver, $domain): the TXT records at | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | # _domainkey.$domain (each RR's strings joined) through $resolver's query(), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | # as an arrayref; [] for NXDOMAIN or no TXT. Dies "TEMPERROR: ..." for any | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | # other failure. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 2 | ▶ | sub query_domain_policy { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
query_domain_policy: called CC=4 SCAR=19.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | 0 | ▶ | my ($resolver, $dom) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
query_domain_policy: not called CC=4 SCAR=19.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | 0 | my $fqdn = "_domainkey.$dom"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | 0 | my $reply = $resolver->query($fqdn, 'TXT'); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | 0 | ▶ | unless ($reply) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | 0 | ▶ | my $err = $resolver->errorstring // ''; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition25%1/4
$resolver->errorstring // ""
$resolver->errorstring // ""
MC/DC0%0/1
$resolver->errorstring // ""
$resolver->errorstring
MC/DC0%0/1
$resolver->errorstring // ""
$resolver->errorstring
Truth table50%1/2
A
A= $resolver->errorstring
Truth table0%0/2
A
A= $resolver->errorstring
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | 0 | ▶ | return [] if $err =~ /^(?:NXDOMAIN|NOERROR|NODATA)\s*$/i; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | 0 | die "TEMPERROR: DNS lookup for $fqdn failed: $err\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | 0 | return [ map { join '', $_->txtdata } grep { $_->type eq 'TXT' } $reply->answer ]; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | # policy_from_source($dom, $callback, $resolver_sub, @cb_args): the Domain | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | # Policy Record of $dom ('open', 'strict', 'multiple' or 'temperror') from | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | # $callback->($dom, @cb_args) when given, else query_domain_policy through | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | # $resolver_sub->(); a die (a TEMPERROR) is 'temperror', with the reason | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | # returned second. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | 20 | ▶ | sub policy_from_source { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
policy_from_source: called CC=5 SCAR=22.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | 0 | ▶ | my ($dom, $callback, $resolver_sub, @cb_args) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
policy_from_source: not called CC=5 SCAR=22.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | 0 | my $txt = eval { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | 0 | ▶ | $callback ? $callback->($dom, @cb_args) : query_domain_policy($resolver_sub->(), $dom); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | 0 | ▶ | if (my $err = $@) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | 0 | ▶ | die $err if ref $err; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | 0 | (my $why = $err) =~ s/\s+at\s+\S+\s+line\s+\d+\.?\s*\z//; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | 0 | return ('temperror', $why =~ s/\s+\z//r); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | 0 | ▶ | return domain_policy(@{ $txt || [] }); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition25%1/4
$txt || []
$txt || []
MC/DC0%0/1
$txt || []
$txt
MC/DC0%0/1
$txt || []
$txt
Truth table50%1/2
A
A= $txt
Truth table0%0/2
A
A= $txt
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | 222 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||