| 1 | #!/usr/bin/perl | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | 79 | ▶ | use 5.20.0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 79 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 79 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 79 | ▶ | use Getopt::Long; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 79 | ▶ | use Pod::Usage; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 79 | ▶ | use FindBin; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 79 | ▶ | use lib -d "$FindBin::Bin/../lib/Mail/DKIM2" ? "$FindBin::Bin/../lib" : (); # running from a checkout | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=2 SCAR=7.1
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 79 | ▶ | use Sendmail::PMilter 1.28 ':all'; # 1.27 never answered MAIL FROM:<> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | # Imported before _dkim2_info/_header_list_for_hash so the constants and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | # should_skip are known at compile time. Spec version constants are the single | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | # source of truth in Mail::DKIM2::Common. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 79 | ▶ | use Mail::DKIM2::Common qw( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | extract_mi_version | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | strip_mi_versions | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | parse_mime | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | DKIM2_DRAFT | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | DKIM2_REPO | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | DKIM2_DATE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 79 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 79 | ▶ | use Mail::DKIM2::Address qw(from_refusal_note); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 79 | ▶ | use Mail::DKIM2::Canon qw(should_skip); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 79 | ▶ | use Mail::DKIM2::Fold qw(fold_header); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 79 | ▶ | use Mail::DKIM2::Key qw(parse_dkim_pubkey load_private_key); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 79 | ▶ | use constant DKIM2_SOFTWARE => 'dkim2-milter'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | # X-DKIM2-Info value per draft-gondwana-dkim2-debug-header-01: a tag-list in | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | # the DKIM2 syntax, every tag (the last included) followed by ";". A ";" has | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | # no escape and ends a tag, so one inside a value becomes ",". | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 104 | ▶ | sub _dkim2_info { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_dkim2_info: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 104 | my ($action, %extra) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 104 | my @tags = ("draft=" . DKIM2_DRAFT, "repo=" . DKIM2_REPO, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | "date=" . DKIM2_DATE, "sw=" . DKIM2_SOFTWARE, "action=$action"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 104 | push @tags, "$_=$extra{$_}" for grep { defined $extra{$_} } sort keys %extra; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 104 | my $val = join ' ', map { (my $t = $_) =~ s/;/,/g; "$t;" } @tags; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | # Fold only after a ";" or a "," (Section 5): never inside a token, so a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | # long hn= list breaks between names and a snaps= digest stays whole. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | # X-DKIM2-Info is excluded from the header hash by the x-* rule, so how it | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | # is folded can never affect a signature. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | # fold_header() budgets for the field name, so fold with it attached and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | # then strip it -- insheader() takes the value alone, in LF form for the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | # milter protocol. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 104 | (my $folded = fold_header("X-DKIM2-Info: $val", undef, delimiters_only => 1)) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | =~ s/^X-DKIM2-Info:\s*//; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 104 | $folded =~ s/\r\n/\n/g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 104 | return $folded; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | # Return (count, comma-separated-names) of headers that would be included | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | # in the header hash for the given Email::MIME message object. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 63 | ▶ | sub _header_list_for_hash { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_header_list_for_hash: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 63 | my ($msg) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 63 | my @fields; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 63 | for my $header (sort { lc($a) cmp lc($b) } $msg->header_names) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 609 | ▶ | next if should_skip($header); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 454 | my @vals = $msg->header_raw($header); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 454 | push @fields, (lc($header)) x scalar(@vals); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 63 | return (scalar(@fields), join(',', @fields)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 79 | ▶ | use Mail::DKIM2::Signer; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 79 | ▶ | use Mail::DKIM2::Verifier; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 79 | ▶ | use Mail::DKIM2::Gate; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 79 | ▶ | use Mail::DKIM2::Hop; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 79 | ▶ | use Mail::DKIM2::MessageInstance; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 79 | ▶ | use Mail::DKIM2::MessageStore; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 79 | ▶ | use Mail::DKIM2::Wrap qw(wrap_single_part); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 79 | ▶ | use Crypt::PRNG qw(random_bytes); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 79 | ▶ | use Email::MIME; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | # --- Command-line options --- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 79 | my %opts; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 79 | ▶ | GetOptions(\%opts, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 'socket|s=s', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 'mode|m=s', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 'domain|d=s', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 'selector=s', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 'keyfile|k=s', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 'keydir=s', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 'parent-from=s@', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 'algorithm|a=s', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 'snapshot-dir=s', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 'dns-json=s', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 'allow-null-body-recipe', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 'max-recipe-literals=i', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 'wrap-single-part', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 'no-envelope-check', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 'help|h', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | ) or pod2usage(2); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 77 | ▶ | pod2usage(-exitval => 0, -verbose => 2, -noperldoc => 1) if $opts{help}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 77 | ▶ | if (defined $opts{'max-recipe-literals'} && $opts{'max-recipe-literals'} < 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $opts{"max-recipe-literals"} and $opts{"max-recipe-literals"} < 0
MC/DC50%1/2
defined $opts{"max-recipe-literals"} and $opts{"max-recipe-literals"} < 0
defined $opts{"max-recipe-literals"}
$opts{"max-recipe-literals"} < 0
Truth table66%2/3
A and B
A= defined $opts{"max-recipe-literals"}B= $opts{"max-recipe-literals"} < 0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 1 | die "--max-recipe-literals must not be negative\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | # Retired in 0.29 (-09 contract E2): this hop's own null body Recipe is | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | # always signed. Still accepted so an existing unit file starts. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | warn "dkim2-milter: --allow-null-body-recipe is deprecated and does nothing: " | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | . "an unsigned null body Recipe is always signed (Mail::DKIM2 0.29)\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 76 | ▶ | if $opts{'allow-null-body-recipe'}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 76 | ▶ | $opts{socket} //= 'unix:/var/run/dkim2-milter.sock'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$opts{"socket"} //= "unix:/var/run/dkim2-milter.sock"
MC/DC100%1/1
$opts{"socket"} //= "unix:/var/run/dkim2-milter.sock"
$opts{"socket"}
Truth table100%2/2
A
A= $opts{"socket"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 76 | ▶ | $opts{algorithm} //= 'rsa-sha256'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$opts{"algorithm"} //= "rsa-sha256"
MC/DC0%0/1
$opts{"algorithm"} //= "rsa-sha256"
$opts{"algorithm"}
Truth table50%1/2
A
A= $opts{"algorithm"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 76 | ▶ | $opts{mode} //= 'both'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$opts{"mode"} //= "both"
MC/DC0%0/1
$opts{"mode"} //= "both"
$opts{"mode"}
Truth table50%1/2
A
A= $opts{"mode"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 76 | ▶ | unless ($opts{mode} =~ /^(inbound|outbound|both)$/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 0 | die "Invalid --mode: must be inbound, outbound, or both\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 76 | ▶ | if ($opts{'wrap-single-part'}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 13 | ▶ | die "--wrap-single-part needs --mode inbound\n" unless $opts{mode} eq 'inbound'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 12 | ▶ | die "--wrap-single-part needs --snapshot-dir\n" unless $opts{'snapshot-dir'}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 74 | ▶ | my $do_verify = $opts{mode} eq 'inbound' || $opts{mode} eq 'both'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$opts{'mode'} eq 'inbound' || $opts{'mode'} eq 'both'
MC/DC50%1/2
$opts{'mode'} eq 'inbound' || $opts{'mode'} eq 'both'
$opts{'mode'} eq 'inbound'
$opts{'mode'} eq 'both'
Truth table66%2/3
A || B
A= $opts{'mode'} eq 'inbound'B= $opts{'mode'} eq 'both'
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 74 | ▶ | my $do_sign = $opts{mode} eq 'outbound' || $opts{mode} eq 'both'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$opts{'mode'} eq 'outbound' || $opts{'mode'} eq 'both'
MC/DC50%1/2
$opts{'mode'} eq 'outbound' || $opts{'mode'} eq 'both'
$opts{'mode'} eq 'outbound'
$opts{'mode'} eq 'both'
Truth table66%2/3
A || B
A= $opts{'mode'} eq 'outbound'B= $opts{'mode'} eq 'both'
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | # -09 section 14.4: the envelope must match the top signature. Only where the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | # transaction is the one the message arrived in: in --mode both it is the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | # outgoing one. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 74 | ▶ | my $check_envelope = $opts{mode} eq 'inbound' && !$opts{'no-envelope-check'}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$opts{'mode'} eq 'inbound' && !$opts{'no-envelope-check'}
MC/DC100%2/2
$opts{'mode'} eq 'inbound' && !$opts{'no-envelope-check'}
$opts{'mode'} eq 'inbound'
!$opts{'no-envelope-check'}
Truth table100%3/3
A && not(B)
A= $opts{'mode'} eq 'inbound'B= !$opts{'no-envelope-check'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | # Determine if signing is possible | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 74 | ▶ | my $can_sign_single = $opts{domain} && $opts{selector} && $opts{keyfile}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%2/6
$opts{'domain'} && $opts{'selector'} && $opts{'keyfile'}
$opts{"domain"} and $opts{"selector"}
MC/DC0%0/3
$opts{'domain'} && $opts{'selector'} && $opts{'keyfile'}
$opts{"domain"}
$opts{"selector"}
$opts{'keyfile'}
Truth table25%1/4
A and B && C
A= $opts{"domain"}B= $opts{"selector"}C= $opts{'keyfile'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 74 | ▶ | my $can_sign_keydir = $opts{keydir} && -d $opts{keydir}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$opts{'keydir'} && -d $opts{'keydir'}
MC/DC0%0/2
$opts{'keydir'} && -d $opts{'keydir'}
$opts{'keydir'}
-d $opts{'keydir'}
Truth table33%1/3
A && B
A= $opts{'keydir'}B= -d $opts{'keydir'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 74 | ▶ | my $can_sign = $can_sign_single || $can_sign_keydir; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$can_sign_single || $can_sign_keydir
MC/DC0%0/2
$can_sign_single || $can_sign_keydir
$can_sign_single
$can_sign_keydir
Truth table33%1/3
A || B
A= $can_sign_singleB= $can_sign_keydir
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 74 | ▶ | if ($do_sign && !$can_sign) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$do_sign and not $can_sign
MC/DC0%0/2
$do_sign and not $can_sign
$do_sign
not $can_sign
Truth table66%2/3
A and not(B)
A= $do_signB= not $can_sign
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 0 | die "Signing (--mode $opts{mode}) requires --keydir OR (--domain, --selector, and --keyfile)\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 74 | ▶ | if ($can_sign_single && $can_sign_keydir) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$can_sign_single and $can_sign_keydir
MC/DC0%0/2
$can_sign_single and $can_sign_keydir
$can_sign_single
$can_sign_keydir
Truth table33%1/3
A and B
A= $can_sign_singleB= $can_sign_keydir
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 0 | die "Cannot use both --keydir and --domain/--selector/--keyfile\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | # Preload single-domain signing key | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 74 | my $sign_key; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 74 | ▶ | if ($can_sign_single) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 0 | $sign_key = load_private_key($opts{keyfile}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 0 | warn "dkim2-milter: signing enabled for $opts{domain} " | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | . "(selector=$opts{selector}, algorithm=$opts{algorithm})\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | # Key cache for keydir mode: { domain => { selector, key, algorithm } } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 74 | my %keydir_cache; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 74 | ▶ | if ($can_sign_keydir) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 74 | warn "dkim2-milter: signing enabled via keydir $opts{keydir}\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 74 | warn "dkim2-milter: mode=$opts{mode}\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 74 | ▶ | warn "dkim2-milter: wrapping single-part posts\n" if $opts{'wrap-single-part'}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | # Preload DNS overrides if specified | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 74 | my $dns_data; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 74 | ▶ | if ($opts{'dns-json'}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 74 | require JSON; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 74 | ▶ | open my $fh, '<', $opts{'dns-json'} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | or die "Cannot read $opts{'dns-json'}: $!\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 74 | local $/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 74 | $dns_data = JSON::decode_json(<$fh>); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 74 | close $fh; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 74 | warn "dkim2-milter: using DNS overrides from $opts{'dns-json'}\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | # Snapshot store | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 74 | my $snapshot_store; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 74 | ▶ | if ($opts{'snapshot-dir'}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | $snapshot_store = Mail::DKIM2::MessageStore->new( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 74 | directory => $opts{'snapshot-dir'}, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 74 | warn "dkim2-milter: snapshots in $opts{'snapshot-dir'}\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | # Options passed to MessageInstance->calculate() for diff-based MI | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 74 | my %mi_opts; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 74 | ▶ | if (defined $opts{'max-recipe-literals'}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 0 | $mi_opts{MaxRecipeLiterals} = $opts{'max-recipe-literals'}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 0 | warn "dkim2-milter: MI strategy: MaxRecipeLiterals=$opts{'max-recipe-literals'}\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | # --- Key directory lookup --- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | # The parent From domains a keydir domain may sign for (-09 contract E3.4): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | # <keydir>/<domain>/parent-from, one domain per line, "#" comments. None | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | # when the file is absent. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 38 | ▶ | sub _read_parent_from { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_read_parent_from: called CC=2 SCAR=11.6
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 38 | my ($file) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | 38 | ▶ | open my $fh, '<', $file or return []; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 0 | my @d = map { s/#.*//r =~ s/\A\s+|\s+\z//gr } <$fh>; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | 0 | close $fh; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 0 | return [ grep { length } @d ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | # Look up signing config for a domain from the keydir. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | # Tries exact domain first, then walks up parent domains. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | # Returns { domain, selector, key, algorithm } or undef. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 40 | ▶ | sub _keydir_lookup { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_keydir_lookup: called CC=12 SCAR=25.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 40 | my ($domain) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 40 | $domain = lc($domain); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | # Check cache | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 40 | ▶ | return $keydir_cache{$domain} if exists $keydir_cache{$domain}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 40 | my $try = $domain; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 40 | ▶ | while ($try) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | 43 | my $dir = "$opts{keydir}/$try"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | # A directory we cannot read is treated like one that is not there, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | # and the walk-up below still runs: `next` here would never advance | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | # $try and the milter would spin forever on a permissions mistake. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 43 | ▶ | if (-d $dir && opendir(my $dh, $dir)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%3/3
-d $dir and opendir my $dh, $dir
MC/DC100%2/2
-d $dir and opendir my $dh, $dir
-d $dir
opendir my $dh, $dir
Truth table100%3/3
A and B
A= -d $dirB= opendir my $dh, $dir
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | # Find the newest .key file (by ctime) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 38 | my @keys = map { $_->[0] } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | 0 | sort { $b->[1] <=> $a->[1] } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 38 | ▶ | map { [$_, (stat("$dir/$_"))[10] || 0] } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
(stat "$dir/$_")[10] || 0
MC/DC0%0/1
(stat "$dir/$_")[10] || 0
(stat "$dir/$_")[10]
Truth table50%1/2
A
A= (stat "$dir/$_")[10]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 38 | grep { /\.key$/ } readdir $dh; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | 38 | closedir $dh; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 38 | ▶ | if (@keys) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 38 | my $file = $keys[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 38 | (my $selector = $file) =~ s/\.key$//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | 38 | my $key = eval { load_private_key("$dir/$file") }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 38 | ▶ | if ($key) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | # Detect algorithm from key type | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 38 | ▶ | my $alg = ref($key) =~ /Ed25519/ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | ? 'ed25519-sha256' : 'rsa-sha256'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | 38 | my $config = { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | domain => $try, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | selector => $selector, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | key => $key, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | algorithm => $alg, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | parent_from => _read_parent_from("$dir/parent-from"), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | # Cache for both the looked-up domain and the matched domain | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 38 | $keydir_cache{$domain} = $config; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | 38 | ▶ | $keydir_cache{$try} = $config if $try ne $domain; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | 38 | return $config; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | } elsif (-d $dir) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | 1 | warn "dkim2-milter: key directory $dir is not readable: $!\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | # Walk up: sub.example.com -> example.com -> (stop) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | 5 | ▶ | $try =~ s/^[^.]+\.// or last; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | # Cache the miss too | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | 2 | $keydir_cache{$domain} = undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | 2 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | # --- Milter setup --- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | 74 | my $milter = Sendmail::PMilter->new(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 74 | $milter->setconn($opts{socket}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | # Insert, change and delete headers; replace the body (--wrap-single-part). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | 74 | $milter->register('dkim2-milter', { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | envfrom => \&cb_envfrom, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | envrcpt => \&cb_envrcpt, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | header => \&cb_header, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | eoh => \&cb_eoh, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | body => \&cb_body, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | eom => \&cb_eom, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | close => \&cb_close, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | }, SMFIF_ADDHDRS | SMFIF_CHGHDRS | SMFIF_CHGBODY); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | 74 | warn "dkim2-milter: listening on $opts{socket}\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | 74 | $milter->main(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | # --- Milter callbacks --- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | 74 | ▶ | sub cb_envfrom { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
cb_envfrom: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | 74 | my ($ctx, $from) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | 74 | $from =~ s/^<//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | 74 | $from =~ s/>$//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | 74 | $ctx->setpriv({ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | env_from => $from, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | env_rcpt => [], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | headers => [], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | raw_hdrs => [], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | body => '', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | 74 | return SMFIS_CONTINUE; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | 75 | ▶ | sub cb_envrcpt { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
cb_envrcpt: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | 75 | my ($ctx, $rcpt) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | 75 | $rcpt =~ s/^<//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | 75 | $rcpt =~ s/>$//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | 75 | push @{$ctx->getpriv->{env_rcpt}}, $rcpt; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | 75 | return SMFIS_CONTINUE; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | 756 | ▶ | sub cb_header { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
cb_header: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | 756 | my ($ctx, $field, $value) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | 756 | my $priv = $ctx->getpriv; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | 756 | my $EOL = "\015\012"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | # Postfix delivers folded header values with LF continuations; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | # normalize to CRLF so the reconstructed message is RFC 5322 compliant. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | 756 | $value =~ s/\r?\n/$EOL/g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | # Store parsed form and raw form | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | 756 | push @{$priv->{headers}}, [$field, $value]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | 756 | push @{$priv->{raw_hdrs}}, "$field: $value$EOL"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | 756 | return SMFIS_CONTINUE; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | 74 | ▶ | sub cb_eoh { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
cb_eoh: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | 74 | my ($ctx) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | 74 | my $priv = $ctx->getpriv; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | 74 | ▶ | $priv->{verify} = _start_verify($priv) if $do_verify; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | 74 | return SMFIS_CONTINUE; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | 74 | ▶ | sub cb_body { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
cb_body: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | 74 | my ($ctx, $chunk) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | 74 | my $priv = $ctx->getpriv; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | 74 | my $EOL = "\015\012"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | 74 | $chunk =~ s/\015?\012/$EOL/g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | 74 | $priv->{body} .= $chunk; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | 74 | ▶ | _feed_verify($priv->{verify}, $chunk) if $priv->{verify}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | 74 | return SMFIS_CONTINUE; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | 74 | ▶ | sub cb_eom { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
cb_eom: called CC=96 SCAR=48.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | 74 | my ($ctx) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | 74 | my $priv = $ctx->getpriv; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | 74 | my $EOL = "\015\012"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | # Reconstruct the full message | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | 74 | my $message = join('', @{$priv->{raw_hdrs}}) . $EOL . $priv->{body}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | # X-DKIM2-Snapshot names the snapshot an inbound milter on this host took | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | # of this message. Nothing from outside may supply one, and it never | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | # leaves: every mode removes it on sight (inbound adds a fresh one). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | 74 | my @snapshot_tokens = _strip_snapshot_header($ctx, $priv, \$message); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | # X-DKIM2-Arrival says how the chain verified when the message arrived | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | # from outside. Only an inbound milter on this host writes one, and it | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | # never leaves: every mode removes it on sight (inbound adds its own). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | # A verdict other than pass or none is final. The outbound milter does | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | # not sign such a message, and an inbound milter on an internal hop | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | # (--no-envelope-check: it cannot see the envelope the message arrived | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | # in) hands it on rather than replace it with a better one of its own. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | # The edge milter, and --mode both, believe none: there the message is | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | # arriving from outside. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | 19 | my ($arrival_bad) = grep { !/\A(?:pass|none)\z/ } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | 74 | ▶ | map { /\A([a-z]{1,20})\z/ ? $1 : 'permerror' } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | _strip_header($ctx, $priv, \$message, 'X-DKIM2-Arrival'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | 74 | ▶ | undef $arrival_bad if $do_verify && ($do_sign || $check_envelope); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
$do_verify and $do_sign || $check_envelope
$do_sign or $check_envelope
MC/DC66%2/3
$do_verify and $do_sign || $check_envelope
$do_verify
$do_sign
$check_envelope
Truth table75%3/4
A and B or C
A= $do_verifyB= $do_signC= $check_envelope
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | # X-DKIM2-Exploded: a list manager on this host (Mailman, Sympa) marks each | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | # distribution copy, asking the signer for the -08 "exploded" flag. Only | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | # a signing milter acts on it, and it never leaves: removed before signing. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | 74 | ▶ | $priv->{exploded} = _strip_exploded_header($ctx, $priv, \$message) if $do_sign; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | # A List-Id says the same without being asked: a list sent this copy, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | # and a list sends copies to more than one address. That covers a list | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | # manager that adds no hint (stock Mailman). The Signer drops the flag | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | # from a first signature (-09 section 12.5), so an unsigned post the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | # list originates as i=1 is unaffected. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | 74 | ▶ | $priv->{exploded} ||= 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%5/5
$do_sign and substr($message, 0, (index($message, "\r\n\r\n") + 2)) =~ /^List-Id[ \t]*:/imu
$priv->{"exploded"} ||= 1
MC/DC100%2/2
$do_sign and substr($message, 0, (index($message, "\r\n\r\n") + 2)) =~ /^List-Id[ \t]*:/imu
$do_sign
substr($message, 0, (index($message, "\r\n\r\n") + 2)) =~ /^List-Id[ \t]*:/imu
MC/DC100%1/1
$priv->{"exploded"} ||= 1
$priv->{"exploded"}
Truth table100%3/3
A and B
A= $do_signB= substr($message, 0, (index($message, "\r\n\r\n") + 2)) =~ /^List-Id[ \t]*:/imu
Truth table100%2/2
A
A= $priv->{"exploded"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | if $do_sign && substr($message, 0, index($message, "\r\n\r\n") + 2) =~ /^List-Id[ \t]*:/mi; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | # Extract message-id for logging | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | 74 | my $msgid = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | 74 | for my $hdr (@{$priv->{headers}}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | 371 | ▶ | if (lc($hdr->[0]) eq 'message-id') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | 74 | $msgid = $hdr->[1]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | 74 | $msgid =~ s/^\s+//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | 74 | last; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | 74 | warn "dkim2-milter: processing $msgid from=$priv->{env_from} mode=$opts{mode}\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | # Verification result, shared between the verify and sign blocks. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | # 'none' means no DKIM2-Signature headers were present. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | 74 | my $verify_result = 'none'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | # --- Inbound: verify and cache snapshot --- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | 74 | ▶ | if ($do_verify) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | # Started at the end of the headers; should no eoh have come, here. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | 34 | ▶ | $verify_result = _finish_verify($priv->{verify} // do { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$priv->{"verify"} // do {
my $state = _start_verify($priv);
_feed_verify($state, $priv->{"body"});
$state
}
MC/DC0%0/2
$priv->{"verify"} // do {
my $state = _start_verify($priv);
_feed_verify($state, $priv->{"body"});
$state
}
$priv->{"verify"}
do {
my $state = _start_verify($priv);
_feed_verify($state, $priv->{"body"});
$state
}
Truth table33%1/3
A // B
A= $priv->{"verify"}B= do {
my $state = _start_verify($priv);
_feed_verify($state, $priv->{"body"});
$state
}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | 0 | my $state = _start_verify($priv); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | 0 | _feed_verify($state, $priv->{body}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | 0 | $state; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | 34 | my $result = $verify_result; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | 34 | warn "dkim2-milter: verify $msgid result=$result\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | # The verdict as one word, for the hops behind us. Only pass and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | # none are vouched for: a snapshot, an instance of ours, a wrap. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | 34 | my ($arrival_word) = $result =~ /\A([a-z]+)/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | 34 | ▶ | $arrival_word = $arrival_bad // $arrival_word // 'permerror'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition60%3/5
($arrival_bad // $arrival_word) // "permerror"
$arrival_bad // $arrival_word
MC/DC0%0/2
($arrival_bad // $arrival_word) // "permerror"
$arrival_bad
$arrival_word
Truth table66%2/3
A // B
A= $arrival_badB= $arrival_word
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | 34 | my $vouched = $arrival_word =~ /\A(?:pass|none)\z/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | 34 | ▶ | $ctx->insheader('X-DKIM2-Arrival', $arrival_word, 0) unless $do_sign; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | # Build the A-R and X-DKIM2-Info headers we're about to add. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | # Authentication-Results is not in the spec exclusion list so it | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | # is included in the header hash. The MI must be computed over | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | # a synthetic message that already contains these headers. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | 34 | my $ar_value = "localhost; dkim2=" . _ar_result($result); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | 34 | my $info_value = _dkim2_info("verify=" . _ar_result($result)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | 34 | my $ar_raw = "Authentication-Results: $ar_value$EOL"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | # _dkim2_info() folds with bare LF (the milter wire form); the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | # message we stamp, snapshot and may wrap is CRLF throughout. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | 34 | my $info_raw = "X-DKIM2-Info: " . ($info_value =~ s/\r?\n/$EOL/gr) . $EOL; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | 34 | my $message_with_ar = $info_raw . $ar_raw . $message; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | # Insert the headers into the milter output | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | 34 | $ctx->insheader('Authentication-Results', $ar_value, 0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | 34 | $ctx->insheader('X-DKIM2-Info', _milter_value($info_value), 0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | # Compute MI from the message that includes A-R | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | 34 | my $mi_header; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | my %mi_info; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | 34 | ▶ | if ($snapshot_store) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | # Fail closed: an exception computing the instance (a crafted | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | # message must never take the callback down with it) means no | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | # Message-Instance; the message passes with its A-R. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | # On arrival: stamp m=1, or accept a top instance that matches | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | # the content. A top that does not match gets no snapshot, and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | # nor does anything whose chain did not verify. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | 34 | ▶ | my $ok = !$vouched || eval { $mi_header = _compute_mi($message_with_ar, \%mi_info); 1 }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
!$vouched || eval {
do {
$mi_header = _compute_mi($message_with_ar, \%mi_info);
1
}
}
MC/DC100%2/2
!$vouched || eval {
do {
$mi_header = _compute_mi($message_with_ar, \%mi_info);
1
}
}
!$vouched
eval {
do {
$mi_header = _compute_mi($message_with_ar, \%mi_info);
1
}
}
Truth table100%3/3
not(A) || B
A= !$vouchedB= eval {
do {
$mi_header = _compute_mi($message_with_ar, \%mi_info);
1
}
}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | 34 | ▶ | unless ($ok) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | 1 | warn "dkim2-milter: no Message-Instance for $msgid: internal error: " | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | . _error_text($@) . "\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 430 | 1 | $mi_header = undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 431 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 432 | 34 | ▶ | if ($mi_header) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 433 | 12 | warn "dkim2-milter: computed MI for $msgid\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 434 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 435 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 436 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 437 | # The arrival snapshot: our own m=1 over everything, or a top | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 438 | # instance that matches the content. Nothing else is vouched for. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 439 | my $arrival = !$vouched ? undef | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 440 | : $mi_header ? "Message-Instance: $mi_header$EOL" . $message_with_ar | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 441 | 34 | ▶ | : $mi_info{matched} ? $message_with_ar | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 442 | : undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 443 | 34 | ▶ | my $token = defined $arrival ? unpack('H*', random_bytes(16)) : undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 444 | 34 | my $snapshot = $arrival; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 445 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 446 | 34 | ▶ | if ($mi_header) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 447 | 12 | $ctx->insheader('Message-Instance', _milter_value($mi_header), 0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 448 | 12 | my ($mi_ver) = $mi_header =~ /m=(\d+)/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 449 | $ctx->insheader('X-DKIM2-Info', _dkim2_info("mi-m=$mi_ver", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 450 | hc => $mi_info{hc}, hn => $mi_info{hn}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 451 | 12 | ▶ | snaps => $token && $snapshot_store->rel_path_for_mi(_snapshot_key($token))), 0); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$token && $snapshot_store->rel_path_for_mi(_snapshot_key($token))
MC/DC0%0/2
$token && $snapshot_store->rel_path_for_mi(_snapshot_key($token))
$token
$snapshot_store->rel_path_for_mi(_snapshot_key($token))
Truth table33%1/3
A && B
A= $tokenB= $snapshot_store->rel_path_for_mi(_snapshot_key($token))
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 452 | 12 | warn "dkim2-milter: added MI header for $msgid\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 453 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 454 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 455 | # --wrap-single-part: stock Mailman pastes a footer into a single-part | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 456 | # body (re-encoding it); a multipart/mixed gets the footer as an extra | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 457 | # part instead. Wrap here, record the wrap as its own unsigned | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 458 | # instance, and snapshot the wrapped message for the outbound diff. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 459 | # Everything is computed before anything is sent, so any failure | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 460 | # leaves the message unwrapped with only its arrival headers. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 461 | 34 | ▶ | if ($opts{'wrap-single-part'}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 462 | 11 | my ($wrap, $wrap_mi, %wrap_info); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 463 | 11 | ▶ | if (!$vouched) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 464 | 3 | warn "dkim2-milter: not wrapping $msgid: arrival result $arrival_word\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 465 | } elsif (!defined $arrival) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 466 | 0 | warn "dkim2-milter: not wrapping $msgid: no arrival snapshot\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 467 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 468 | 8 | my $ok = eval { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 469 | 8 | my $why; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 470 | 8 | ($wrap, $why) = wrap_single_part($arrival); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 471 | 8 | ▶ | warn "dkim2-milter: not wrapping $msgid: $why\n" unless $wrap; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 472 | 8 | ▶ | $wrap_mi = _compute_mi($wrap->{message}, \%wrap_info, Snapshot => $arrival) if $wrap; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 473 | 8 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 474 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 475 | 8 | ▶ | if (!$ok) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 476 | 0 | warn "dkim2-milter: not wrapping $msgid: internal error: " . _error_text($@) . "\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 477 | 0 | $wrap = undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 478 | ▶ | } elsif ($wrap && !$wrap_mi) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$wrap and not $wrap_mi
MC/DC0%0/2
$wrap and not $wrap_mi
$wrap
not $wrap_mi
Truth table66%2/3
A and not(B)
A= $wrapB= not $wrap_mi
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 479 | 0 | warn "dkim2-milter: not wrapping $msgid: no Message-Instance for the wrap\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 480 | 0 | $wrap = undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 481 | ▶ | } elsif ($wrap && $wrap_info{strip_mi_versions}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$wrap and $wrap_info{"strip_mi_versions"}
MC/DC0%0/2
$wrap and $wrap_info{"strip_mi_versions"}
$wrap
$wrap_info{"strip_mi_versions"}
Truth table66%2/3
A and B
A= $wrapB= $wrap_info{"strip_mi_versions"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 482 | # The inbound side never removes instances; a diff that | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 483 | # wants to is not one to put on the wire. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 484 | 0 | warn "dkim2-milter: not wrapping $msgid: the wrap's diff would strip instances\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 485 | 0 | $wrap = undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 486 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 487 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 488 | 11 | ▶ | if ($wrap) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 489 | 7 | for my $e (@{$wrap->{edits}}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 490 | 0 | ▶ | if ($e->{op} eq 'delete') { $ctx->chgheader($e->{name}, $e->{index}, '') } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 491 | 7 | elsif ($e->{op} eq 'change') { $ctx->chgheader($e->{name}, $e->{index}, $e->{value}) } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 492 | 0 | else { $ctx->addheader($e->{name}, $e->{value}) } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 493 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 494 | 7 | my $body = $wrap->{body}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 495 | 7 | ▶ | for (my $o = 0; $o < length $body; $o += 65535) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 496 | 9 | $ctx->replacebody(substr($body, $o, 65535)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 497 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 498 | 7 | $ctx->insheader('Message-Instance', _milter_value($wrap_mi), 0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 499 | 7 | my ($wrap_ver) = $wrap_mi =~ /m=(\d+)/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 500 | 7 | $ctx->insheader('X-DKIM2-Info', _milter_value(_dkim2_info("wrap-single-part")), 0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 501 | $ctx->insheader('X-DKIM2-Info', _dkim2_info("mi-m=$wrap_ver", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 502 | hc => $wrap_info{hc}, hn => $wrap_info{hn}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 503 | 7 | snaps => $snapshot_store->rel_path_for_mi(_snapshot_key($token))), 0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 504 | 7 | warn "dkim2-milter: wrapped $msgid as m=$wrap_ver\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 505 | 7 | $snapshot = "Message-Instance: $wrap_mi$EOL" . $wrap->{message}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 506 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 507 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 508 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 509 | # Keep the snapshot (the wrapped form, if wrapped) under a fresh | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 510 | # random token, and name it on the message for the outbound milter. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 511 | 34 | ▶ | if (defined $snapshot && $snapshot_store) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $snapshot and $snapshot_store
MC/DC50%1/2
defined $snapshot and $snapshot_store
defined $snapshot
$snapshot_store
Truth table66%2/3
A and B
A= defined $snapshotB= $snapshot_store
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 512 | 21 | $snapshot_store->store(_snapshot_key($token), $snapshot); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 513 | 21 | $ctx->insheader('X-DKIM2-Snapshot', $token, 0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 514 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 515 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 516 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 517 | # --- Outbound: compute MI diff if needed, then sign --- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 518 | 74 | ▶ | if ($do_sign) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 519 | # No key for this sender: this message is not ours to sign, so it | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 520 | # leaves exactly as it came -- no Message-Instance (unsigned, a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 521 | # receiver reports it as permerror), no X-DKIM2-Info, no snapshot. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 522 | # The From: domain is the null-sender fallback for the key lookup, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 523 | # and is logged for alignment below. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 524 | 40 | my $from_hdr_domain = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 525 | 40 | for my $hdr (@{$priv->{headers}}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 526 | 332 | ▶ | if (lc($hdr->[0]) eq 'from') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 527 | 40 | ($from_hdr_domain) = $hdr->[1] =~ /\@([\w.-]+)/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 528 | 40 | ▶ | $from_hdr_domain = lc($from_hdr_domain // ''); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$from_hdr_domain // ""
MC/DC0%0/1
$from_hdr_domain // ""
$from_hdr_domain
Truth table50%1/2
A
A= $from_hdr_domain
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 529 | 40 | last; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 530 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 531 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 532 | 40 | my $sign_config = _get_sign_config($priv->{env_from}, $from_hdr_domain); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 533 | 40 | ▶ | unless ($sign_config) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 534 | 2 | warn "dkim2-milter: no signing key for $msgid from=$priv->{env_from}\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 535 | 2 | _remove_unsigned_instances($ctx, $priv, $msgid); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 536 | 2 | return SMFIS_CONTINUE; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 537 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 538 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 539 | # A chain that did not verify when the message arrived is never | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 540 | # extended: nothing is computed and nothing is looked up. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 541 | 38 | ▶ | if (defined $arrival_bad) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 542 | 3 | return _refuse($ctx, $priv, $msgid, "arrival result $arrival_bad"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 543 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 544 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 545 | # If there are upstream DKIM2-Signature headers the chain must have | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 546 | # verified before we extend it. In mode=both the verify block already | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 547 | # ran. In mode=outbound a snapshot of this message is the proof: the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 548 | # inbound milter took it only of a message whose chain verified (or | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 549 | # that had none), so the signatures are not checked again, only the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 550 | # instances (below). With no snapshot the Gate verifies it all now. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 551 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 552 | # allow_unsigned_mi: the message may carry a Message-Instance above the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 553 | # top signature that is OURS to sign. A list manager on this host | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 554 | # (Mailman, Sympa) records its changes as a new m= and hands the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 555 | # message to us unsigned; the milter is the step that signs it. -08 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 556 | # §14's "Message-Instance m=<x> is not signed" PERMERROR is a receiver's | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 557 | # rule about mail on the wire, and applying it here refused to sign | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 558 | # every list post whose upstream chain was signed. The opt-out does not | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 559 | # loosen the chain gate: i=1..n still have to verify, and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 560 | # chain_verifies() below still requires the unsigned instance to match | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 561 | # the content and undo cleanly. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 562 | # The decision itself lives in Mail::DKIM2::Gate, shared with | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 563 | # bin/dkim2sign so the two front ends cannot drift apart: verify the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 564 | # upstream signatures (allowing our own unsigned instance on top), run | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 565 | # the full undo check on the Message-Instance chain (an upstream that | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 566 | # emitted a non-reversible Recipe would give a signature that fails at | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 567 | # every recipient). A null body Recipe on an UNSIGNED instance (no | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 568 | # upstream signature has its m=: a null this hop is introducing) is | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 569 | # signed; one that arrived signed fails the upstream verification | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 570 | # and is refused (-09 contract E2). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 571 | # nd= bridge: when the top signature carries nd= we may extend it only | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 572 | # if nd= names the domain we sign as, so tell the gate which. (The | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 573 | # gate ignores this unless the top signature has nd=.) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 574 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 575 | # The gate judges the message as it will be signed: with this hop's | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 576 | # own Message-Instance (the diff against the snapshot) on top and any | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 577 | # broken intermediate instances removed. A list manager that changed | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 578 | # the message without recording an instance (stock Mailman: the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 579 | # snapshot diff is its instance) leaves a top instance that no longer | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 580 | # matches; gating before the diff refused every such copy. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 581 | # DKIM2Sign has always computed first and gated second. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 582 | 35 | my $mi_header; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 583 | my %mi_info; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 584 | 35 | my $arrival_verdict; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 585 | 35 | ▶ | if ($snapshot_store) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 586 | # Fail closed: an exception computing the instance means no | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 587 | # Message-Instance and no signature. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 588 | # The snapshot is the one the inbound milter named on this very | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 589 | # message (X-DKIM2-Snapshot, stripped above); one token or none. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 590 | # In --mode both the message came from outside in this same | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 591 | # transaction, so a token on it is not one we gave it. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 592 | 35 | my $snap; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 593 | 35 | ▶ | if (!$do_verify && @snapshot_tokens == 1 && $snapshot_tokens[0] =~ /^[0-9a-f]{32}\z/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
not $do_verify and @snapshot_tokens == 1 and $snapshot_tokens[0] =~ /^[0-9a-f]{32}\z/u
not $do_verify and @snapshot_tokens == 1
MC/DC33%1/3
not $do_verify and @snapshot_tokens == 1 and $snapshot_tokens[0] =~ /^[0-9a-f]{32}\z/u
not $do_verify
@snapshot_tokens == 1
$snapshot_tokens[0] =~ /^[0-9a-f]{32}\z/u
Truth table50%2/4
not(A) and B and C
A= not $do_verifyB= @snapshot_tokens == 1C= $snapshot_tokens[0] =~ /^[0-9a-f]{32}\z/u
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 594 | 11 | $snap = $snapshot_store->fetch(_snapshot_key($snapshot_tokens[0])); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 595 | 11 | ▶ | $mi_info{snapf} = $snapshot_store->rel_path_for_mi(_snapshot_key($snapshot_tokens[0])) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 596 | if defined $snap; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 597 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 598 | # The token on a message names the snapshot of that message, or | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 599 | # something is badly wrong: never signed. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 600 | 35 | ▶ | if (defined $snap) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 601 | 9 | my ($same, $why) = eval { Mail::DKIM2::Hop->snapshot_vouches($message, $snap) }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 602 | 9 | ▶ | $why = 'the snapshot is not of this message: ' . _error_text($@) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 603 | unless defined $same; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 604 | 9 | ▶ | return _refuse($ctx, $priv, $msgid, $why) unless $same; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 605 | 8 | ▶ | $arrival_verdict = (grep { lc $_->[0] eq 'dkim2-signature' } @{$priv->{headers}}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 606 | ? 'pass' : 'none'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 607 | 8 | warn "dkim2-milter: $msgid arrived $arrival_verdict (snapshot $snapshot_tokens[0])\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 608 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 609 | 34 | ▶ | my $ok = eval { $mi_header = _compute_mi($message, \%mi_info, Outbound => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 610 | 33 | (defined $snap ? (Snapshot => $snap) : ())); 1 }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 611 | 34 | ▶ | unless ($ok) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 612 | 1 | warn "dkim2-milter: not signing $msgid: internal error computing the " | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 613 | . "Message-Instance: " . _error_text($@) . "\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 614 | 1 | _remove_unsigned_instances($ctx, $priv, $msgid); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 615 | 1 | return SMFIS_CONTINUE; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 616 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 617 | 33 | ▶ | warn "dkim2-milter: computed MI for $msgid\n" if $mi_header; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 618 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 619 | my $sign_msg = $mi_info{strip_mi_versions} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 620 | 33 | ▶ | ? strip_mi_versions($message, @{$mi_info{strip_mi_versions}}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 621 | : $message; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 622 | 33 | ▶ | $sign_msg = "Message-Instance: $mi_header$EOL" . $sign_msg if $mi_header; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 623 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 624 | 33 | my $gate_sd = $sign_config->{domain}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 625 | # Fail closed: an exception anywhere in the gate (a crafted message | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 626 | # must never take the callback down with it) is a logged refusal. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 627 | # The inbound verdict (mode both) still describes the message only if | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 628 | # this hop added and removed nothing. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 629 | 33 | my $gate = eval { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 630 | 33 | ▶ | Mail::DKIM2::Gate->check($sign_msg, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition33%1/3
$do_verify and $sign_msg eq $message
MC/DC0%0/2
$do_verify and $sign_msg eq $message
$do_verify
$sign_msg eq $message
Truth table33%1/3
A and B
A= $do_verifyB= $sign_msg eq $message
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 631 | (defined $gate_sd ? (SigningDomain => $gate_sd) : ()), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 632 | ($do_verify && $sign_msg eq $message ? (VerifyResult => $verify_result) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 633 | : defined $arrival_verdict ? (VerifyResult => $arrival_verdict) : ()), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 634 | _gate_pubkey_cb()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 635 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 636 | 33 | ▶ | unless ($gate) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 637 | 1 | my $err = _error_text($@); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 638 | 1 | $gate = { reason => 'error', verify_result => $verify_result, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 639 | message => "internal error checking the upstream chain: $err" }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 640 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 641 | 33 | $verify_result = $gate->{verify_result}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 642 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 643 | # -09 section 13: a message that carries DKIM2 header fields but is | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 644 | # not one this hop can sign MUST NOT be sent on -- so a refusal of a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 645 | # message with an upstream DKIM2-Signature is a 550 5.7.1 with the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 646 | # reason (section 13.3). One with no signature (only instances this | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 647 | # host's list manager added, which are removed) goes on unsigned. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 648 | 33 | ▶ | if ($gate->{reason} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$gate->{"reason"} and grep {lc $_->[0] eq "dkim2-signature";} @{$$priv{"headers"};}
MC/DC100%2/2
$gate->{"reason"} and grep {lc $_->[0] eq "dkim2-signature";} @{$$priv{"headers"};}
$gate->{"reason"}
grep {lc $_->[0] eq "dkim2-signature";} @{$$priv{"headers"};}
Truth table100%3/3
A and B
A= $gate->{"reason"}B= grep {lc $_->[0] eq "dkim2-signature";} @{$$priv{"headers"};}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 649 | 109 | && grep { lc $_->[0] eq 'dkim2-signature' } @{$priv->{headers}}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 650 | 8 | warn "dkim2-milter: not signing $msgid: $gate->{message} (rejected 550 5.7.1)\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 651 | 8 | return _reject($ctx, "not signing: $gate->{message}"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 652 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 653 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 654 | 25 | ▶ | if ($gate->{reason} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition50%3/6
$gate->{"reason"} and $gate->{"reason"} eq "upstream-chain" || $gate->{"reason"} eq "error"
$gate->{"reason"} eq "upstream-chain" or $gate->{"reason"} eq "error"
MC/DC0%0/3
$gate->{"reason"} and $gate->{"reason"} eq "upstream-chain" || $gate->{"reason"} eq "error"
$gate->{"reason"}
$gate->{"reason"} eq "upstream-chain"
$gate->{"reason"} eq "error"
Truth table50%2/4
A and B or C
A= $gate->{"reason"}B= $gate->{"reason"} eq "upstream-chain"C= $gate->{"reason"} eq "error"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 655 | && ($gate->{reason} eq 'upstream-chain' || $gate->{reason} eq 'error')) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 656 | # Upstream chain is broken — don't extend it with a new signature. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 657 | 0 | warn "dkim2-milter: not signing $msgid: $gate->{message}\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 658 | 0 | _remove_unsigned_instances($ctx, $priv, $msgid); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 659 | ▶ | } elsif ($gate->{reason} && $gate->{reason} eq 'broken-mi-chain') { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$gate->{"reason"} and $gate->{"reason"} eq "broken-mi-chain"
MC/DC50%1/2
$gate->{"reason"} and $gate->{"reason"} eq "broken-mi-chain"
$gate->{"reason"}
$gate->{"reason"} eq "broken-mi-chain"
Truth table66%2/3
A and B
A= $gate->{"reason"}B= $gate->{"reason"} eq "broken-mi-chain"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 660 | 1 | warn "dkim2-milter: not signing $msgid: $gate->{message}\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 661 | 1 | $ctx->insheader('X-DKIM2-Info', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 662 | _milter_value(_dkim2_info("not-signed=broken-mi-chain")), 0); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 663 | 1 | _remove_unsigned_instances($ctx, $priv, $msgid); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 664 | } elsif ($gate->{reason}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 665 | 0 | warn "dkim2-milter: not signing $msgid: $gate->{message}\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 666 | 0 | $ctx->insheader('X-DKIM2-Info', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 667 | _milter_value(_dkim2_info("not-signed=$gate->{reason}")), 0); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 668 | 0 | _remove_unsigned_instances($ctx, $priv, $msgid); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 669 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 670 | # Chain is valid (or there is no upstream chain) — proceed. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 671 | # Log domain alignment: signing domain vs envelope-from and From: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 672 | 24 | ▶ | my ($env_domain) = ($priv->{env_from} || '') =~ /\@(.+)$/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$priv->{'env_from'} || ''
MC/DC0%0/1
$priv->{'env_from'} || ''
$priv->{'env_from'}
Truth table50%1/2
A
A= $priv->{'env_from'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 673 | 24 | ▶ | $env_domain = lc($env_domain // ''); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$env_domain // ""
MC/DC0%0/1
$env_domain // ""
$env_domain
Truth table50%1/2
A
A= $env_domain
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 674 | 24 | ▶ | my $env_aligned = ($env_domain eq lc($sign_config->{domain})) ? 'yes' : 'no'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 675 | 24 | ▶ | my $from_aligned = ($from_hdr_domain eq lc($sign_config->{domain})) ? 'yes' : 'no'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 676 | 24 | warn "dkim2-milter: domain alignment $msgid" | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 677 | . " signing=$sign_config->{domain}" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 678 | . " env_from=$env_domain aligned=$env_aligned" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 679 | . " from_hdr=$from_hdr_domain aligned=$from_aligned\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 680 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 681 | # Sign before touching the headers, so a signer failure leaves no | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 682 | # instance of ours behind. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 683 | 24 | my ($sig_header, $sign_why) = _do_sign($sign_msg, $priv, $sign_config); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 684 | # A list posting domain that is not the signing domain (or below | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 685 | # it) has every rewritten post refused here: say which two. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 686 | warn "dkim2-milter: $msgid: " | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 687 | . from_refusal_note($sign_config->{domain}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 688 | 24 | ▶ | map { $_->[1] } grep { lc $_->[0] eq 'from' } @{$priv->{headers}}) . "\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition60%3/5
not $sig_header and ($sign_why // "") =~ /From header field is not Authentic/u
$sign_why // ""
MC/DC50%1/2
not $sig_header and ($sign_why // "") =~ /From header field is not Authentic/u
not $sig_header
$sign_why
Truth table66%2/3
not(A) and B
A= not $sig_headerB= $sign_why
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 689 | if !$sig_header && ($sign_why // '') =~ /From header field is not Authentic/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 690 | # As for a gate refusal: with an upstream DKIM2-Signature on it | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 691 | # (and this hop's change unsigned) the message is not sent on. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 692 | return _reject($ctx, "not signing: $sign_why") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 693 | if !$sig_header | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 694 | 24 | ▶ | && grep { lc $_->[0] eq 'dkim2-signature' } @{$priv->{headers}}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not $sig_header and grep {lc $_->[0] eq "dkim2-signature";} @{$$priv{"headers"};}
MC/DC100%2/2
not $sig_header and grep {lc $_->[0] eq "dkim2-signature";} @{$$priv{"headers"};}
not $sig_header
grep {lc $_->[0] eq "dkim2-signature";} @{$$priv{"headers"};}
Truth table100%3/3
not(A) and B
A= not $sig_headerB= grep {lc $_->[0] eq "dkim2-signature";} @{$$priv{"headers"};}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 695 | 23 | ▶ | unless ($sig_header) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 696 | 1 | _remove_unsigned_instances($ctx, $priv, $msgid); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 697 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 698 | # If _compute_mi stripped broken intermediate MI headers, delete them | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 699 | # from the wire message and log a warning. Deletes go first: their | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 700 | # indexes count the Message-Instance fields as received, and an | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 701 | # MTA that counts fields inserted earlier in this end-of-message | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 702 | # would otherwise delete one place off (our own new instance). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 703 | # Last index first, so each index still counts the fields | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 704 | # as received. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 705 | 22 | ▶ | if ($mi_info{strip_mi_versions}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 706 | 5 | my %gone = map { $_ => 1 } @{$mi_info{strip_mi_versions}}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 707 | 5 | my ($count, @del) = (0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 708 | 5 | for my $hdr (@{$priv->{headers}}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 709 | 78 | ▶ | next unless lc($hdr->[0]) eq 'message-instance'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 710 | 9 | $count++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 711 | 9 | ▶ | my $v = extract_mi_version($hdr->[1] =~ s/^\s+//r) // 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
extract_mi_version($hdr->[1] =~ s/^\s+//ru) // 0
MC/DC0%0/1
extract_mi_version($hdr->[1] =~ s/^\s+//ru) // 0
extract_mi_version($hdr->[1] =~ s/^\s+//ru)
Truth table50%1/2
A
A= extract_mi_version($hdr->[1] =~ s/^\s+//ru)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 712 | 9 | ▶ | push @del, [$count, $v] if $gone{$v}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 713 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 714 | 5 | for my $d (reverse @del) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 715 | 8 | $ctx->chgheader('Message-Instance', $d->[0], ''); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 716 | 8 | ▶ | warn "dkim2-milter: deleted " . ($mi_info{restart} ? 'unsigned' : 'broken') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 717 | . " MI m=$d->[1] from wire message\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 718 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 719 | 5 | my $stripped_str = join(',', map { "m=$_" } @{$mi_info{strip_mi_versions}}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 720 | 5 | my $recomp_from = $mi_info{strip_mi_versions}[0] - 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 721 | $ctx->insheader('X-DKIM2-Info', $mi_info{restart} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 722 | 5 | ▶ | ? _dkim2_info("restarted-unsigned-mi=$stripped_str") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 723 | : _dkim2_info("stripped-broken-mi=$stripped_str,recomputed-from=m$recomp_from"), 0); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 724 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 725 | 22 | ▶ | if ($mi_header) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 726 | 11 | $ctx->insheader('Message-Instance', _milter_value($mi_header), 0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 727 | 11 | my ($mi_ver) = $mi_header =~ /m=(\d+)/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 728 | $ctx->insheader('X-DKIM2-Info', _dkim2_info("mi-m=$mi_ver", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 729 | hc => $mi_info{hc}, hn => $mi_info{hn}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 730 | 11 | snapf => $mi_info{snapf}), 0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 731 | 11 | warn "dkim2-milter: added MI header for $msgid\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 732 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 733 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 734 | 22 | $ctx->insheader('DKIM2-Signature', _milter_value($sig_header), 0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 735 | 22 | $ctx->insheader('X-DKIM2-Info', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 736 | _dkim2_info("sign d=$sign_config->{domain} a=$sign_config->{algorithm}"), 0); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 737 | 22 | warn "dkim2-milter: signed $msgid d=$sign_config->{domain} " | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 738 | . "a=$sign_config->{algorithm} sel=$sign_config->{selector}\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 739 | # Informational: we signed over this hop's own null body | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 740 | # Recipe (an unsigned one, our own diff's included: the gate | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 741 | # sees this hop's instance as unsigned too). The message | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 742 | # will PERMERROR downstream, but our header changes are signed. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 743 | $ctx->insheader('X-DKIM2-Info', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 744 | _milter_value(_dkim2_info("null-body-recipe")), 0) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 745 | 22 | ▶ | if $gate->{unsigned_null}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 746 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 747 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 748 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 749 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 750 | 58 | return SMFIS_CONTINUE; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 751 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 752 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 753 | # Not signing, for $why: a message with a DKIM2-Signature on it is refused | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 754 | # (-09 section 13: it is not sent on by a hop that cannot sign it); one with | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 755 | # none goes on without the instances this host added. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 756 | 4 | ▶ | sub _refuse { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_refuse: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 757 | 4 | my ($ctx, $priv, $msgid, $why) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 758 | 4 | ▶ | if (grep { lc $_->[0] eq 'dkim2-signature' } @{$priv->{headers}}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 759 | 3 | warn "dkim2-milter: not signing $msgid: $why (rejected 550 5.7.1)\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 760 | 3 | return _reject($ctx, "not signing: $why"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 761 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 762 | 1 | warn "dkim2-milter: not signing $msgid: $why\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 763 | 1 | _remove_unsigned_instances($ctx, $priv, $msgid); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 764 | 1 | return SMFIS_CONTINUE; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 765 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 766 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 767 | # Refuse the message with 550 5.7.1 and $reason as the reply text (-08 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 768 | # section 13.3), one line, with sendmail's "%" expansion escaped. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 769 | 12 | ▶ | sub _reject { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_reject: called CC=3 SCAR=11.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 770 | 12 | my ($ctx, $reason) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 771 | 12 | ▶ | (my $text = $reason // 'not signing') =~ s/[\r\n]+/ /g; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$reason // "not signing"
MC/DC0%0/1
$reason // "not signing"
$reason
Truth table50%1/2
A
A= $reason
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 772 | 12 | $text =~ s/%/%%/g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 773 | 12 | ▶ | $text = substr($text, 0, 900) if length $text > 900; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 774 | 12 | $ctx->setreply('550', '5.7.1', $text); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 775 | 12 | return SMFIS_REJECT; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 776 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 777 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 778 | 74 | ▶ | sub cb_close { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
cb_close: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 779 | 74 | my ($ctx) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 780 | 74 | $ctx->setpriv(undef); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 781 | 74 | return SMFIS_CONTINUE; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 782 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 783 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 784 | # --- Signing config lookup --- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 785 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 786 | # Returns { domain, selector, key, algorithm } or undef. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 787 | 40 | ▶ | sub _get_sign_config { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_sign_config: called CC=9 SCAR=29.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 788 | 40 | my ($env_from, $from_domain_fallback) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 789 | 40 | ▶ | my ($from_domain) = ($env_from || '') =~ /\@(.+)$/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$env_from || ''
MC/DC0%0/1
$env_from || ''
$env_from
Truth table50%1/2
A
A= $env_from
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 790 | # Null sender (bounce/DSN): no envelope domain — fall back to the From: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 791 | # header domain so our own Postfix-generated bounces still get signed. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 792 | 40 | ▶ | $from_domain = $from_domain_fallback | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
not $from_domain and defined $from_domain_fallback and length $from_domain_fallback
not $from_domain and defined $from_domain_fallback
MC/DC0%0/3
not $from_domain and defined $from_domain_fallback and length $from_domain_fallback
not $from_domain
defined $from_domain_fallback
length $from_domain_fallback
Truth table25%1/4
not(A) and B and C
A= not $from_domainB= defined $from_domain_fallbackC= length $from_domain_fallback
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 793 | if (!$from_domain && defined $from_domain_fallback && length $from_domain_fallback); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 794 | 40 | ▶ | return unless $from_domain; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 795 | 40 | $from_domain = lc($from_domain); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 796 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 797 | # Single-domain mode — sign regardless of alignment; caller logs alignment. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 798 | 40 | ▶ | if ($can_sign_single) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 799 | return { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 800 | domain => $opts{domain}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 801 | selector => $opts{selector}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 802 | key => $sign_key, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 803 | algorithm => $opts{algorithm}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 804 | 0 | ▶ | parent_from => [ @{ $opts{'parent-from'} || [] } ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$opts{'parent-from'} || []
MC/DC0%0/1
$opts{'parent-from'} || []
$opts{'parent-from'}
Truth table0%0/2
A
A= $opts{'parent-from'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 805 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 806 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 807 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 808 | # Keydir mode | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 809 | 40 | ▶ | if ($can_sign_keydir) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 810 | 40 | return _keydir_lookup($from_domain); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 811 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 812 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 813 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 814 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 815 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 816 | # --- Verification --- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 817 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 818 | # _gate_pubkey_cb(): PubkeyCallback option answering from --dns-json, else real DNS. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 819 | # The Domain Policy Record (-09 section 3.8) for the gate's Verifier, from | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 820 | # --dns-json's records for the domains it lists, else DNS. Nothing without | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 821 | # --dns-json: the Verifier then uses DNS. (The Signer never looks it up: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 822 | # --parent-from / the keydir parent-from file, contract E3.4.) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 823 | 67 | ▶ | sub _policy_cb { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_policy_cb: called CC=2 SCAR=13.4
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 824 | 67 | ▶ | return unless $dns_data; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 825 | 0 | ▶ | return (PolicyCallback => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 826 | 0 | my ($dom, $who) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 827 | 0 | ▶ | return [ map { $_->[1] } @{ $dns_data->{$dom}{_domainkey} || [] } ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$dns_data->{$dom}{'_domainkey'} || []
MC/DC0%0/1
$dns_data->{$dom}{'_domainkey'} || []
$dns_data->{$dom}{'_domainkey'}
Truth table0%0/2
A
A= $dns_data->{$dom}{'_domainkey'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 828 | 0 | ▶ | if $dns_data->{$dom}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 829 | 0 | return $who->fetch_domain_policy($dom); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 830 | 67 | }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 831 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 832 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 833 | 67 | ▶ | sub _gate_pubkey_cb { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_gate_pubkey_cb: called CC=2 SCAR=7.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 834 | 67 | ▶ | return unless $dns_data; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 835 | 21 | ▶ | return (_policy_cb(), PubkeyCallback => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=5 SCAR=18.4
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 836 | 21 | my ($sig, $idx, $v) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 837 | 21 | ▶ | $idx //= 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$idx //= 0
MC/DC0%0/1
$idx //= 0
$idx
Truth table50%1/2
A
A= $idx
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 838 | 21 | my $sel = $sig->selector($idx); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 839 | 21 | my $dom = $sig->domain; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 840 | my $key_txt = $dns_data->{$dom}{"$sel._domainkey"}[0][1] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 841 | 21 | ▶ | if $dns_data->{$dom} && $dns_data->{$dom}{"$sel._domainkey"}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$dns_data->{$dom} and $dns_data->{$dom}{"$sel._domainkey"}
MC/DC0%0/2
$dns_data->{$dom} and $dns_data->{$dom}{"$sel._domainkey"}
$dns_data->{$dom}
$dns_data->{$dom}{"$sel._domainkey"}
Truth table33%1/3
A and B
A= $dns_data->{$dom}B= $dns_data->{$dom}{"$sel._domainkey"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 842 | 21 | ▶ | return parse_dkim_pubkey($key_txt) if $key_txt; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 843 | 0 | return $v->fetch_public_key($sig, $idx); # fall back to real DNS | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 844 | 67 | }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 845 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 846 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 847 | # Verification runs as the message arrives: the Verifier gets the header | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 848 | # fields at the end of the headers -- and sends for every signature's key | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 849 | # then, so the answers come back while the body is still arriving -- then | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 850 | # each body chunk, and its verdict at the end of the message. The fields | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 851 | # are the message's less any X-DKIM2-Snapshot, which cb_eom strips. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 852 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 853 | # Fail closed: a verifier exception, at any step, is reported as temperror | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 854 | # (never pass) and logged at the end, rather than killing the callback. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 855 | # A verdict ("fail (FAIL: ...)") as Authentication-Results carries it: the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 856 | # result word, then the detail as an RFC 5322 comment. The detail quotes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 857 | # signature fields (a bad i= or m= value, as written), so it is cut to | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 858 | # printable ASCII, its "\", "(" and ")" quoted, and kept short: a crafted | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 859 | # i= must not close the comment and add properties of its own. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 860 | 68 | ▶ | sub _ar_result { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_ar_result: called CC=6 SCAR=19.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 861 | 68 | my ($verdict) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 862 | 68 | ▶ | my ($word, $detail) = ($verdict // '') =~ /\A([a-z]+)(?: \((.*)\))?\z/s | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$verdict // ""
MC/DC0%0/1
$verdict // ""
$verdict
Truth table50%1/2
A
A= $verdict
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 863 | or return 'temperror (unreadable verdict)'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 864 | 68 | ▶ | return $word unless defined $detail && length $detail; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $detail and length $detail
MC/DC0%0/2
defined $detail and length $detail
defined $detail
length $detail
Truth table33%1/3
A and B
A= defined $detailB= length $detail
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 865 | 68 | $detail =~ s/[^\x20-\x7e]//g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 866 | 68 | ▶ | $detail = substr($detail, 0, 200) . '...' if length $detail > 200; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 867 | 68 | $detail =~ s/([\\()])/\\$1/g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 868 | 68 | return "$word ($detail)"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 869 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 870 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 871 | 34 | ▶ | sub _start_verify { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_start_verify: called CC=10 SCAR=23.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 872 | 34 | my ($priv) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 873 | 34 | my $raw_hdrs = $priv->{raw_hdrs}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 874 | 34 | my $state = {}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 875 | eval { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 876 | my $verifier = Mail::DKIM2::Verifier->new($check_envelope ? ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 877 | MailFrom => '<' . ($priv->{env_from} // '') . '>', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 878 | 34 | ▶ | RcptTo => [ map { "<$_>" } @{ $priv->{env_rcpt} || [] } ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%2/4
$priv->{"env_from"} // ""
$priv->{'env_rcpt'} || []
MC/DC0%0/1
$priv->{"env_from"} // ""
$priv->{"env_from"}
MC/DC0%0/1
$priv->{'env_rcpt'} || []
$priv->{'env_rcpt'}
Truth table50%1/2
A
A= $priv->{"env_from"}
Truth table50%1/2
A
A= $priv->{'env_rcpt'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 879 | ) : ()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 880 | 34 | my %cb = _gate_pubkey_cb(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 881 | 34 | ▶ | $verifier->set_pubkey_callback($cb{PubkeyCallback}) if $cb{PubkeyCallback}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 882 | # Behind an inbound milter of ours that gave pass or none (an | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 883 | # internal hop: --no-envelope-check), a Message-Instance nobody has | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 884 | # signed is this host's own -- the m=1 that milter stamped -- and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 885 | # not a broken chain. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 886 | 34 | my @arrived = map { $_->[1] } grep { lc $_->[0] eq 'x-dkim2-arrival' } @{$priv->{headers}}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 887 | $verifier->allow_unsigned_mi(1) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 888 | if $opts{mode} eq 'inbound' && !$check_envelope | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 889 | 34 | ▶ | && @arrived && !grep { !/\A\s*(?:pass|none)\s*\z/ } @arrived; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition88%8/9
$opts{"mode"} eq "inbound" and not $check_envelope and @arrived and not grep({not /\A\s*(?:pass|none)\s*\z/u;} @arrived)
$opts{"mode"} eq "inbound" and not $check_envelope and @arrived
$opts{"mode"} eq "inbound" and not $check_envelope
MC/DC75%3/4
$opts{"mode"} eq "inbound" and not $check_envelope and @arrived and not grep({not /\A\s*(?:pass|none)\s*\z/u;} @arrived)
$opts{"mode"} eq "inbound"
not $check_envelope
@arrived
not grep({not /\A\s*(?:pass|none)\s*\z/u;} @arrived)
Truth table80%4/5
A and not(B) and C and not(D)
A= $opts{"mode"} eq "inbound"B= not $check_envelopeC= @arrivedD= not grep({not /\A\s*(?:pass|none)\s*\z/u;} @arrived)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 890 | 34 | $state->{verifier} = $verifier; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 891 | 34 | $verifier->PRINT(join('', grep { !/\AX-DKIM2-Snapshot[ \t]*:/i } @$raw_hdrs) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 892 | . "\015\012"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 893 | 33 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 894 | 34 | ▶ | } or $state->{error} = $@; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 895 | 34 | return $state; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 896 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 897 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 898 | 34 | ▶ | sub _feed_verify { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_feed_verify: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 899 | 34 | my ($state, $chunk) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 900 | 34 | ▶ | return if defined $state->{error} || $state->{verifier}->stopped; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $state->{"error"} or $state->{"verifier"}->stopped
MC/DC100%2/2
defined $state->{"error"} or $state->{"verifier"}->stopped
defined $state->{"error"}
$state->{"verifier"}->stopped
Truth table100%3/3
A or B
A= defined $state->{"error"}B= $state->{"verifier"}->stopped
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 901 | 16 | ▶ | eval { $state->{verifier}->PRINT($chunk); 1 } or $state->{error} = $@; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 902 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 903 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 904 | 34 | ▶ | sub _finish_verify { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_finish_verify: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 905 | 34 | my ($state) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 906 | 34 | ▶ | unless (defined $state->{error}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 907 | 33 | ▶ | eval { $state->{verifier}->CLOSE(); 1 } or $state->{error} = $@; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 908 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 909 | 34 | ▶ | if (defined $state->{error}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 910 | warn "dkim2-milter: verify failed with an internal error: " | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 911 | 2 | . _error_text($state->{error}) . "\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 912 | 2 | return 'temperror (internal error)'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 913 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 914 | 32 | return $state->{verifier}->result_detail(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 915 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 916 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 917 | # One line of an exception, for the log. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 918 | 5 | ▶ | sub _error_text { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_error_text: called CC=4 SCAR=15.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 919 | 5 | my ($err) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 920 | 5 | ▶ | $err = "$err" if defined $err; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 921 | 5 | ▶ | $err = 'unknown error' unless defined $err && length $err; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $err and length $err
MC/DC0%0/2
defined $err and length $err
defined $err
length $err
Truth table33%1/3
A and B
A= defined $errB= length $err
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 922 | 5 | $err =~ s/\s+\z//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 923 | 5 | $err =~ s/\s*\n\s*/ /g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 924 | 5 | return $err; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 925 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 926 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 927 | # --- Message-Instance --- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 928 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 929 | # _compute_mi($message, \%info, %o): the Message-Instance this hop adds, or | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 930 | # undef when none is needed or none can be justified. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 931 | # Snapshot => $previous the message as this host last vouched for it (the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 932 | # snapshot the X-DKIM2-Snapshot token names); a top | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 933 | # instance that no longer matches is explained by a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 934 | # diff against it and nothing else. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 935 | # Outbound => 1 the instance the signer is about to sign. On a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 936 | # message with no DKIM2-Signature, every instance is | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 937 | # this host's own and unsigned, and the copy leaves | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 938 | # with ONE m=1 (-09 section 12.1): hashes of what is | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 939 | # sent, Recipes back to the message as it arrived. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 940 | # $info->{restart} then lists the instances that | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 941 | # go (in $info->{strip_mi_versions} too). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 942 | # Sets $info->{matched} when the top instance matches the content, and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 943 | # $info->{hc}/{hn} (the hashed header names) for X-DKIM2-Info. Stores nothing: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 944 | # the callers decide what becomes a snapshot. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 945 | 63 | ▶ | sub _compute_mi { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_compute_mi: called CC=10 SCAR=23.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 946 | 63 | my ($message, $info, %o) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 947 | 63 | ▶ | $info //= {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$info //= {}
MC/DC0%0/1
$info //= {}
$info
Truth table50%1/2
A
A= $info
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 948 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 949 | 63 | my $msg = eval { parse_mime($message) }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 950 | 63 | ▶ | return unless $msg; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 951 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 952 | # Record which headers will be included in any hash we compute. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 953 | 63 | my ($hcount, $hnames) = _header_list_for_hash($msg); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 954 | 63 | $info->{hc} = $hcount; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 955 | 63 | $info->{hn} = $hnames; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 956 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 957 | # Which instance, if any, and over what: Mail::DKIM2::Hop decides. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 958 | my $next = Mail::DKIM2::Hop->next_instance($message, %mi_opts, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 959 | 63 | ▶ | map { defined $o{$_} ? ($_ => $o{$_}) : () } qw(Snapshot Outbound)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 960 | 61 | ▶ | $info->{matched} = 1 if $next->{matched}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 961 | 61 | ▶ | if (@{ $next->{removed} }) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 962 | 5 | $info->{strip_mi_versions} = $next->{removed}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 963 | 5 | ▶ | $info->{restart} = $next->{removed} if $next->{restart}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 964 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 965 | warn "dkim2-milter: $next->{detail}\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 966 | 61 | ▶ | if $next->{reason} !~ /\A(?:unchanged|first|changed)\z/ || @{ $next->{removed} }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not $next->{"reason"} =~ /\A(?:unchanged|first|changed)\z/u or @{$next->{"removed"};}
MC/DC100%2/2
not $next->{"reason"} =~ /\A(?:unchanged|first|changed)\z/u or @{$next->{"removed"};}
not $next->{"reason"} =~ /\A(?:unchanged|first|changed)\z/u
@{$next->{"removed"};}
Truth table100%3/3
not(A) or B
A= not $next->{"reason"} =~ /\A(?:unchanged|first|changed)\z/uB= @{$next->{"removed"};}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 967 | 61 | ▶ | return $next->{instance} ? $next->{instance}->as_header_value : undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 968 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 969 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 970 | # Not signing: remove every Message-Instance no DKIM2-Signature on the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 971 | # message covers (m= above every signature's m=). Those are instances hops on | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 972 | # this host added for a signature that is not going to be made; left in, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 973 | # every receiver reports "m=N is not signed". Without them an unsigned post | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 974 | # has no DKIM2 at all, and a signed one fails honestly against the last | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 975 | # signature (a hop changed it without signing). Deletes go last first, by | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 976 | # index among the fields as received; nothing of ours has been inserted. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 977 | 6 | ▶ | sub _remove_unsigned_instances { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_remove_unsigned_instances: called CC=9 SCAR=23.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 978 | 6 | my ($ctx, $priv, $msgid) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 979 | 6 | my $covered = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 980 | 6 | for my $h (grep { lc $_->[0] eq 'dkim2-signature' } @{$priv->{headers}}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 981 | 0 | my ($m) = $h->[1] =~ /(?:\A|;)\s*m\s*=\s*(\d+)/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 982 | 0 | ▶ | $covered = $m if defined $m && $m > $covered; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $m and $m > $covered
MC/DC0%0/2
defined $m and $m > $covered
defined $m
$m > $covered
Truth table0%0/3
A and B
A= defined $mB= $m > $covered
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 983 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 984 | 6 | my @mi = grep { lc $_->[0] eq 'message-instance' } @{$priv->{headers}}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 985 | 6 | my @gone; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 986 | 6 | for my $i (0 .. $#mi) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 987 | 5 | ▶ | my $v = extract_mi_version($mi[$i][1] =~ s/^\s+//r) // 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
extract_mi_version($mi[$i][1] =~ s/^\s+//ru) // 0
MC/DC0%0/1
extract_mi_version($mi[$i][1] =~ s/^\s+//ru) // 0
extract_mi_version($mi[$i][1] =~ s/^\s+//ru)
Truth table50%1/2
A
A= extract_mi_version($mi[$i][1] =~ s/^\s+//ru)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 988 | 5 | ▶ | push @gone, [$i + 1, $v] if $v > $covered; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 989 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 990 | 6 | ▶ | return unless @gone; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 991 | 3 | $ctx->chgheader('Message-Instance', $_->[0], '') for reverse @gone; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 992 | 3 | my $list = join(',', map { "m=$_->[1]" } sort { $a->[1] <=> $b->[1] } @gone); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 993 | 3 | $ctx->insheader('X-DKIM2-Info', _milter_value(_dkim2_info("removed-unsigned-mi=$list")), 0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 994 | 3 | warn "dkim2-milter: not signing $msgid: removed unsigned $list\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 995 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 996 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 997 | # The snapshot store key for an X-DKIM2-Snapshot token. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 998 | 60 | ▶ | sub _snapshot_key { "X-DKIM2-Snapshot:$_[0]" } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_snapshot_key: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 999 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1000 | # Remove every X-DKIM2-Snapshot field: from the wire (deleted last first, by | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1001 | # index among the fields as received, before anything is inserted) and from | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1002 | # the reconstructed message. Returns the tokens that were there. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1003 | 74 | ▶ | sub _strip_snapshot_header { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_strip_snapshot_header: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1004 | 74 | my ($ctx, $priv, $message_ref) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1005 | 74 | return _strip_header($ctx, $priv, $message_ref, 'X-DKIM2-Snapshot'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1006 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1007 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1008 | # Remove every X-DKIM2-Exploded field, as above. True if there was one: the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1009 | # -07 contract makes its presence, whatever its value, the request. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1010 | 40 | ▶ | sub _strip_exploded_header { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_strip_exploded_header: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1011 | 40 | my ($ctx, $priv, $message_ref) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1012 | 40 | my @values = _strip_header($ctx, $priv, $message_ref, 'X-DKIM2-Exploded'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1013 | 40 | ▶ | return @values ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1014 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1015 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1016 | # Remove every $name field from the wire (deleted last first, by index among | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1017 | # the fields as received, before anything is inserted) and from the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1018 | # reconstructed message. Returns the values that were there, trimmed. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1019 | 188 | ▶ | sub _strip_header { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_strip_header: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1020 | 188 | my ($ctx, $priv, $message_ref, $name) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1021 | 35 | my @val = map { $_->[1] =~ s/^\s+|\s+$//gr } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1022 | 188 | grep { lc $_->[0] eq lc $name } @{$priv->{headers}}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1023 | 188 | ▶ | return () unless @val; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1024 | 35 | $ctx->chgheader($name, $_, '') for reverse 1 .. @val; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1025 | 35 | my $sep = index($$message_ref, "\015\012\015\012"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1026 | 35 | ▶ | if ($sep >= 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1027 | 35 | my $head = substr($$message_ref, 0, $sep + 2); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1028 | 35 | $head =~ s/^\Q$name\E[ \t]*:[^\r\n]*\r\n(?:[ \t][^\r\n]*\r\n)*//mig; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1029 | 35 | substr($$message_ref, 0, $sep + 2) = $head; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1030 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1031 | 35 | return @val; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1032 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1033 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1034 | # Convert CRLF folding to LF for milter insheader (CRLF = end of value) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1035 | 99 | ▶ | sub _milter_value { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_milter_value: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1036 | 99 | my ($val) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1037 | 99 | $val =~ s/\r\n/\n/g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1038 | 99 | return $val; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1039 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1040 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1041 | # --- Signing --- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1042 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1043 | 24 | ▶ | sub _do_sign { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_do_sign: called CC=12 SCAR=28.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1044 | 24 | my ($message, $priv, $config) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1045 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1046 | 24 | my $signer; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1047 | # Fail closed, as for the gate: an exception means no signature. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1048 | 24 | my $ok = eval { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1049 | $signer = Mail::DKIM2::Signer->new( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1050 | Domain => $config->{domain}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1051 | Selector => $config->{selector}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1052 | Key => $config->{key}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1053 | Algorithm => $config->{algorithm}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1054 | MailFrom => ( length($priv->{env_from} // '') ? $priv->{env_from} : '<>' ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1055 | RcptTo => $priv->{env_rcpt}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1056 | ($priv->{exploded} ? (Exploded => 1) : ()), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1057 | # -09 contract E3.4: a d= below the From domain signs only for | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1058 | # a parent the configuration lists; no DNS lookup. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1059 | ParentFromCallback => Mail::DKIM2::Address::parent_from_matcher( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1060 | 24 | ▶ | @{ $config->{parent_from} || [] }), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition50%2/4
$priv->{"env_from"} // ""
$config->{'parent_from'} || []
MC/DC0%0/1
$priv->{"env_from"} // ""
$priv->{"env_from"}
MC/DC0%0/1
$config->{'parent_from'} || []
$config->{'parent_from'}
Truth table50%1/2
A
A= $priv->{"env_from"}
Truth table50%1/2
A
A= $config->{'parent_from'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1061 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1062 | 24 | $signer->PRINT($message); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1063 | 24 | $signer->CLOSE(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1064 | 24 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1065 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1066 | 24 | ▶ | unless ($ok) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1067 | 0 | my $why = "internal error in the signer: " . _error_text($@); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1068 | 0 | warn "dkim2-milter: not signing: $why\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1069 | 0 | return (undef, $why); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1070 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1071 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1072 | 24 | ▶ | unless (($signer->result // '') eq 'signed') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$signer->result // ""
MC/DC0%0/1
$signer->result // ""
$signer->result
Truth table50%1/2
A
A= $signer->result
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1073 | 2 | ▶ | my $why = $signer->details // $signer->result // 'no result'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition40%2/5
($signer->details // $signer->result) // "no result"
$signer->details // $signer->result
MC/DC0%0/2
($signer->details // $signer->result) // "no result"
$signer->details
$signer->result
Truth table33%1/3
A // B
A= $signer->detailsB= $signer->result
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1074 | 2 | ▶ | warn "dkim2-milter: not signing: signer result=" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition40%2/5
($signer->result_detail // $signer->result) // "none"
$signer->result_detail // $signer->result
MC/DC0%0/2
($signer->result_detail // $signer->result) // "none"
$signer->result_detail
$signer->result
Truth table33%1/3
A // B
A= $signer->result_detailB= $signer->result
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1075 | . ($signer->result_detail // $signer->result // 'none') . "\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1076 | 2 | return (undef, $why); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1077 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1078 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1079 | 22 | my $header = $signer->as_string(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1080 | # Strip "DKIM2-Signature: " prefix for insheader | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1081 | 22 | $header =~ s/^DKIM2-Signature:\s*//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1082 | # Convert CRLF folding to LF folding for milter protocol | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1083 | 22 | $header =~ s/\r\n/\n/g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1084 | 22 | return $header; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1085 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1086 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1087 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||