| 1 | package Mail::DKIM::Verifier; | ||||||||||||||||||||||||||||
| 2 | 9 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 9 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 9 | our $VERSION = '1.20261116'; # VERSION | |||||||||||||||||||||||||||
| 5 | # ABSTRACT: verifies a DKIM-signed message | ||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | # Copyright 2005-2009 Messiah College. All rights reserved. | ||||||||||||||||||||||||||||
| 8 | # Jason Long <jlong@messiah.edu> | ||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | # Copyright (c) 2004 Anthony D. Urso. All rights reserved. | ||||||||||||||||||||||||||||
| 11 | # This program is free software; you can redistribute it and/or | ||||||||||||||||||||||||||||
| 12 | # modify it under the same terms as Perl itself. | ||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 9 | ▶ | use Mail::DKIM::Signature; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | 9 | ▶ | use Mail::DKIM::DkSignature; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | 9 | ▶ | use Mail::Address; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 9 | ▶ | use base 'Mail::DKIM::Common'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 21 | 9 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 22 | 9 | our $MAX_SIGNATURES_TO_PROCESS = 50; | |||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 101 | ▶ | sub init { | ||||||||||||||||||||||||||
|
Subroutine
init: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 25 | 101 | my $self = shift; | |||||||||||||||||||||||||||
| 26 | 101 | $self->SUPER::init; | |||||||||||||||||||||||||||
| 27 | 101 | $self->{signatures} = []; | |||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | # @{$dkim->{signatures}} | ||||||||||||||||||||||||||||
| 31 | # array of L<Mail::DKIM::Signature> objects, representing all | ||||||||||||||||||||||||||||
| 32 | # parseable signatures found in the header, | ||||||||||||||||||||||||||||
| 33 | # ordered from the top of the header to the bottom. | ||||||||||||||||||||||||||||
| 34 | # | ||||||||||||||||||||||||||||
| 35 | # $dkim->{signature_reject_reason} | ||||||||||||||||||||||||||||
| 36 | # simple string listing a reason, if any, for not using a signature. | ||||||||||||||||||||||||||||
| 37 | # This may be a helpful diagnostic if there is a signature in the header, | ||||||||||||||||||||||||||||
| 38 | # but was found not to be valid. It will be ambiguous if there are more | ||||||||||||||||||||||||||||
| 39 | # than one signatures that could not be used. | ||||||||||||||||||||||||||||
| 40 | # | ||||||||||||||||||||||||||||
| 41 | # $dkim->{signature} | ||||||||||||||||||||||||||||
| 42 | # the L<Mail::DKIM::Signature> selected as the "best" signature. | ||||||||||||||||||||||||||||
| 43 | # | ||||||||||||||||||||||||||||
| 44 | # @{$dkim->{headers}} | ||||||||||||||||||||||||||||
| 45 | # array of strings, each member is one header, in its original format. | ||||||||||||||||||||||||||||
| 46 | # | ||||||||||||||||||||||||||||
| 47 | # $dkim->{algorithms} | ||||||||||||||||||||||||||||
| 48 | # array of algorithms, one for each signature being verified. | ||||||||||||||||||||||||||||
| 49 | # | ||||||||||||||||||||||||||||
| 50 | # $dkim->{result} | ||||||||||||||||||||||||||||
| 51 | # string; the result of the verification (see the result() method) | ||||||||||||||||||||||||||||
| 52 | # | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 402767 | ▶ | sub handle_header { | ||||||||||||||||||||||||||
|
Subroutine
handle_header: called CC=5 SCAR=16.2
Pod
undocumented
| |||||||||||||||||||||||||||||
| 55 | 402767 | my $self = shift; | |||||||||||||||||||||||||||
| 56 | 402767 | my ( $field_name, $contents, $line ) = @_; | |||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 402767 | $self->SUPER::handle_header( $field_name, $contents ); | |||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 402767 | ▶ | if ( lc($field_name) eq 'dkim-signature' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 61 | eval { | ||||||||||||||||||||||||||||
| 62 | 95 | local $SIG{__DIE__}; | |||||||||||||||||||||||||||
| 63 | 95 | my $signature = Mail::DKIM::Signature->parse($line); | |||||||||||||||||||||||||||
| 64 | 94 | $self->add_signature($signature); | |||||||||||||||||||||||||||
| 65 | 94 | 1 | |||||||||||||||||||||||||||
| 66 | 95 | ▶ | } || do { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | # the only reason an error should be thrown is if the | ||||||||||||||||||||||||||||
| 69 | # signature really is unparse-able | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | # otherwise, invalid signatures are caught in finish_header() | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | 1 | chomp( my $E = $@ ); | |||||||||||||||||||||||||||
| 74 | 1 | $self->{signature_reject_reason} = $E; | |||||||||||||||||||||||||||
| 75 | }; | ||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | 402767 | ▶ | if ( lc($field_name) eq 'domainkey-signature' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 79 | eval { | ||||||||||||||||||||||||||||
| 80 | 17 | local $SIG{__DIE__}; | |||||||||||||||||||||||||||
| 81 | 17 | my $signature = Mail::DKIM::DkSignature->parse($line); | |||||||||||||||||||||||||||
| 82 | 17 | $self->add_signature($signature); | |||||||||||||||||||||||||||
| 83 | 17 | 1 | |||||||||||||||||||||||||||
| 84 | 17 | ▶ | } || do { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | # the only reason an error should be thrown is if the | ||||||||||||||||||||||||||||
| 87 | # signature really is unparse-able | ||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | # otherwise, invalid signatures are caught in finish_header() | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | 0 | chomp( my $E = $@ ); | |||||||||||||||||||||||||||
| 92 | 0 | $self->{signature_reject_reason} = $E; | |||||||||||||||||||||||||||
| 93 | }; | ||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | 111 | ▶ | sub add_signature { | ||||||||||||||||||||||||||
|
Subroutine
add_signature: called CC=7 SCAR=19.5
Pod
undocumented
| |||||||||||||||||||||||||||||
| 98 | 111 | my $self = shift; | |||||||||||||||||||||||||||
| 99 | 111 | ▶ | croak 'wrong number of arguments' unless ( @_ == 1 ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 100 | 111 | my ($signature) = @_; | |||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | # Set verification time if we have one | ||||||||||||||||||||||||||||
| 103 | 111 | ▶ | if ($self->{verify_time}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 104 | 1 | $signature->set_verify_time($self->{verify_time}); | |||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | # ignore signature headers once we've seen 50 or so | ||||||||||||||||||||||||||||
| 108 | # this protects against abuse. | ||||||||||||||||||||||||||||
| 109 | 111 | ▶ | return if ( @{ $self->{signatures} } > $MAX_SIGNATURES_TO_PROCESS ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | 111 | push @{ $self->{signatures} }, $signature; | |||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | 111 | ▶ | unless ( $self->check_signature($signature) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 114 | 21 | $signature->result( 'invalid', $self->{signature_reject_reason} ); | |||||||||||||||||||||||||||
| 115 | 21 | return; | |||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | # signature looks ok, go ahead and query for the public key | ||||||||||||||||||||||||||||
| 119 | 90 | $signature->fetch_public_key; | |||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | # create a canonicalization filter and algorithm | ||||||||||||||||||||||||||||
| 122 | 90 | my $algorithm_class = | |||||||||||||||||||||||||||
| 123 | $signature->get_algorithm_class( $signature->algorithm ); | ||||||||||||||||||||||||||||
| 124 | my $algorithm = $algorithm_class->new( | ||||||||||||||||||||||||||||
| 125 | Signature => $signature, | ||||||||||||||||||||||||||||
| 126 | Debug_Canonicalization => $self->{Debug_Canonicalization}, | ||||||||||||||||||||||||||||
| 127 | 90 | ); | |||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | # an algorithm that wants the headers prior to the signature header | ||||||||||||||||||||||||||||
| 130 | # canonicalizes the whole header from finish_header(), so only the | ||||||||||||||||||||||||||||
| 131 | # others need each header field as it is parsed | ||||||||||||||||||||||||||||
| 132 | 90 | ▶ | push @{ $self->{header_algorithms} }, $algorithm | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 133 | unless $algorithm->wants_pre_signature_headers; | ||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||
| 135 | # save the algorithm | ||||||||||||||||||||||||||||
| 136 | 90 | ▶ | $self->{algorithms} ||= []; | ||||||||||||||||||||||||||
|
Condition100%2/2
$self->{"algorithms"} ||= []
MC/DC100%1/1
$self->{"algorithms"} ||= []
$self->{"algorithms"}
Truth table100%2/2
A
A= $self->{"algorithms"}
| |||||||||||||||||||||||||||||
| 137 | 90 | push @{ $self->{algorithms} }, $algorithm; | |||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | 111 | ▶ | sub check_signature { | ||||||||||||||||||||||||||
|
Subroutine
check_signature: called CC=22 SCAR=32.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 141 | 111 | my $self = shift; | |||||||||||||||||||||||||||
| 142 | 111 | ▶ | croak 'wrong number of arguments' unless ( @_ == 1 ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 143 | 111 | my ($signature) = @_; | |||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||
| 145 | 111 | ▶ | unless ( $signature->check_version ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||
| 147 | # unsupported version | ||||||||||||||||||||||||||||
| 148 | 1 | ▶ | if ( defined $signature->version ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 149 | $self->{signature_reject_reason} = | ||||||||||||||||||||||||||||
| 150 | 1 | 'unsupported version ' . $signature->version; | |||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||
| 152 | else { | ||||||||||||||||||||||||||||
| 153 | 0 | $self->{signature_reject_reason} = 'missing v tag'; | |||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||
| 155 | 1 | return 0; | |||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||
| 158 | 110 | ▶ | unless ( $signature->algorithm | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$signature->algorithm and $signature->get_algorithm_class($signature->algorithm)
MC/DC50%1/2
$signature->algorithm and $signature->get_algorithm_class($signature->algorithm)
$signature->algorithm
$signature->get_algorithm_class($signature->algorithm)
Truth table66%2/3
A and B
A= $signature->algorithmB= $signature->get_algorithm_class($signature->algorithm)
| |||||||||||||||||||||||||||||
| 159 | && $signature->get_algorithm_class( $signature->algorithm ) ) | ||||||||||||||||||||||||||||
| 160 | { | ||||||||||||||||||||||||||||
| 161 | # unsupported algorithm | ||||||||||||||||||||||||||||
| 162 | 2 | $self->{signature_reject_reason} = 'unsupported algorithm'; | |||||||||||||||||||||||||||
| 163 | 2 | ▶ | if ( defined $signature->algorithm ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 164 | 2 | $self->{signature_reject_reason} .= ' ' . $signature->algorithm; | |||||||||||||||||||||||||||
| 165 | } | ||||||||||||||||||||||||||||
| 166 | 2 | return 0; | |||||||||||||||||||||||||||
| 167 | } | ||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||
| 169 | 108 | ▶ | if ( $self->{Strict} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 170 | 4 | ▶ | if ( $signature->algorithm eq 'rsa-sha1' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 171 | 2 | $self->{signature_reject_reason} = 'unsupported algorithm'; | |||||||||||||||||||||||||||
| 172 | 2 | ▶ | if ( defined $signature->algorithm ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 173 | 2 | $self->{signature_reject_reason} .= ' ' . $signature->algorithm; | |||||||||||||||||||||||||||
| 174 | } | ||||||||||||||||||||||||||||
| 175 | 2 | return 0; | |||||||||||||||||||||||||||
| 176 | } | ||||||||||||||||||||||||||||
| 177 | } | ||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||
| 179 | 106 | ▶ | unless ( $signature->check_canonicalization ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||
| 181 | # unsupported canonicalization method | ||||||||||||||||||||||||||||
| 182 | 2 | $self->{signature_reject_reason} = 'unsupported canonicalization'; | |||||||||||||||||||||||||||
| 183 | 2 | ▶ | if ( defined $signature->canonicalization ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 184 | $self->{signature_reject_reason} .= | ||||||||||||||||||||||||||||
| 185 | 2 | ' ' . $signature->canonicalization; | |||||||||||||||||||||||||||
| 186 | } | ||||||||||||||||||||||||||||
| 187 | 2 | return 0; | |||||||||||||||||||||||||||
| 188 | } | ||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||
| 190 | 104 | ▶ | unless ( $signature->check_protocol ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||
| 192 | # unsupported query protocol | ||||||||||||||||||||||||||||
| 193 | $self->{signature_reject_reason} = | ||||||||||||||||||||||||||||
| 194 | 4 | ▶ | !defined( $signature->protocol ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 195 | ? 'missing q tag' | ||||||||||||||||||||||||||||
| 196 | : 'unsupported query protocol, q=' . $signature->protocol; | ||||||||||||||||||||||||||||
| 197 | 4 | return 0; | |||||||||||||||||||||||||||
| 198 | } | ||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||
| 200 | 100 | ▶ | unless ( $signature->check_expiration ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||
| 202 | # signature has expired | ||||||||||||||||||||||||||||
| 203 | 3 | $self->{signature_reject_reason} = 'signature is expired'; | |||||||||||||||||||||||||||
| 204 | 3 | return 0; | |||||||||||||||||||||||||||
| 205 | } | ||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||
| 207 | 97 | ▶ | unless ( defined $signature->domain ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||
| 209 | # no domain specified | ||||||||||||||||||||||||||||
| 210 | 0 | $self->{signature_reject_reason} = 'missing d tag'; | |||||||||||||||||||||||||||
| 211 | 0 | return 0; | |||||||||||||||||||||||||||
| 212 | } | ||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||
| 214 | 97 | ▶ | if ( $signature->domain eq '' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||
| 216 | # blank domain | ||||||||||||||||||||||||||||
| 217 | 0 | $self->{signature_reject_reason} = 'invalid domain in d tag'; | |||||||||||||||||||||||||||
| 218 | 0 | return 0; | |||||||||||||||||||||||||||
| 219 | } | ||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||
| 221 | 97 | ▶ | unless ( defined $signature->selector ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||
| 223 | # no selector specified | ||||||||||||||||||||||||||||
| 224 | 0 | $self->{signature_reject_reason} = 'missing s tag'; | |||||||||||||||||||||||||||
| 225 | 0 | return 0; | |||||||||||||||||||||||||||
| 226 | } | ||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||
| 228 | # DomainKeys signatures have no bh= tag, and their h= tag is optional | ||||||||||||||||||||||||||||
| 229 | 97 | ▶ | return 1 if $signature->isa('Mail::DKIM::DkSignature'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||
| 231 | 82 | ▶ | unless ( $signature->body_hash ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||
| 233 | # no body hash, so the signature wouldn't cover the body | ||||||||||||||||||||||||||||
| 234 | 3 | $self->{signature_reject_reason} = 'missing bh tag'; | |||||||||||||||||||||||||||
| 235 | 3 | return 0; | |||||||||||||||||||||||||||
| 236 | } | ||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||
| 238 | 79 | my @headers = $signature->headerlist; | |||||||||||||||||||||||||||
| 239 | 79 | ▶ | unless (@headers) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||
| 241 | # no signed header fields (RFC 6376, 3.5: h= MUST NOT be empty) | ||||||||||||||||||||||||||||
| 242 | 3 | $self->{signature_reject_reason} = 'missing h tag'; | |||||||||||||||||||||||||||
| 243 | 3 | return 0; | |||||||||||||||||||||||||||
| 244 | } | ||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||
| 246 | 76 | ▶ | unless ( grep { $_ eq 'from' } @headers ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||
| 248 | # RFC 6376, 6.1.1: a signature that doesn't cover From is ignored | ||||||||||||||||||||||||||||
| 249 | 1 | $self->{signature_reject_reason} = 'From field not signed'; | |||||||||||||||||||||||||||
| 250 | 1 | return 0; | |||||||||||||||||||||||||||
| 251 | } | ||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||
| 253 | 75 | return 1; | |||||||||||||||||||||||||||
| 254 | } | ||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||
| 256 | 63 | ▶ | sub check_public_key { | ||||||||||||||||||||||||||
|
Subroutine
check_public_key: called CC=5 SCAR=16.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 257 | 63 | my $self = shift; | |||||||||||||||||||||||||||
| 258 | 63 | ▶ | croak 'wrong number of arguments' unless ( @_ == 2 ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 259 | 63 | my ( $signature, $public_key ) = @_; | |||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||
| 261 | 63 | my $result = 0; | |||||||||||||||||||||||||||
| 262 | eval { | ||||||||||||||||||||||||||||
| 263 | 63 | local $SIG{__DIE__}; | |||||||||||||||||||||||||||
| 264 | 63 | $@ = undef; | |||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||
| 266 | # HACK- I'm indecisive here about whether I want the | ||||||||||||||||||||||||||||
| 267 | # check_foo functions to return false or to "die" | ||||||||||||||||||||||||||||
| 268 | # on failure | ||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||
| 270 | # check public key's allowed hash algorithms | ||||||||||||||||||||||||||||
| 271 | 63 | $result = | |||||||||||||||||||||||||||
| 272 | $public_key->check_hash_algorithm( $signature->hash_algorithm ); | ||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||
| 274 | # HACK- DomainKeys signatures are allowed to have an empty g= | ||||||||||||||||||||||||||||
| 275 | # tag in the public key | ||||||||||||||||||||||||||||
| 276 | 61 | my $empty_g_means_wildcard = $signature->isa('Mail::DKIM::DkSignature'); | |||||||||||||||||||||||||||
| 277 | |||||||||||||||||||||||||||||
| 278 | # check public key's granularity | ||||||||||||||||||||||||||||
| 279 | 61 | ▶ | $result &&= | ||||||||||||||||||||||||||
|
Condition66%2/3
$result &&= $public_key->check_granularity($signature->identity, $empty_g_means_wildcard)
MC/DC50%1/2
$result &&= $public_key->check_granularity($signature->identity, $empty_g_means_wildcard)
$result
$public_key->check_granularity($signature->identity, $empty_g_means_wildcard)
Truth table66%2/3
A &&= B
A= $resultB= $public_key->check_granularity($signature->identity, $empty_g_means_wildcard)
| |||||||||||||||||||||||||||||
| 280 | $public_key->check_granularity( $signature->identity, | ||||||||||||||||||||||||||||
| 281 | $empty_g_means_wildcard ); | ||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||
| 283 | 61 | ▶ | die $@ if $@; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 284 | 56 | 1 | |||||||||||||||||||||||||||
| 285 | 63 | ▶ | } || do { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 286 | 7 | my $E = $@; | |||||||||||||||||||||||||||
| 287 | 7 | chomp $E; | |||||||||||||||||||||||||||
| 288 | 7 | $self->{signature_reject_reason} = "public key: $E"; | |||||||||||||||||||||||||||
| 289 | }; | ||||||||||||||||||||||||||||
| 290 | 63 | return $result; | |||||||||||||||||||||||||||
| 291 | } | ||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||
| 293 | # returns true if the i= tag is an address with a domain matching or | ||||||||||||||||||||||||||||
| 294 | # a subdomain of the d= tag | ||||||||||||||||||||||||||||
| 295 | # | ||||||||||||||||||||||||||||
| 296 | 90 | ▶ | sub check_signature_identity { | ||||||||||||||||||||||||||
|
Subroutine
check_signature_identity: called CC=3 SCAR=12.3
Pod
undocumented
| |||||||||||||||||||||||||||||
| 297 | 90 | my ($signature) = @_; | |||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||
| 299 | 90 | my $d = $signature->domain; | |||||||||||||||||||||||||||
| 300 | 90 | my $i = $signature->identity; | |||||||||||||||||||||||||||
| 301 | 90 | ▶ | if ( defined($i) && $i =~ /\@([^@]*)$/ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $i and $i =~ /\@([^\@]*)$/
MC/DC0%0/2
defined $i and $i =~ /\@([^\@]*)$/
defined $i
$i =~ /\@([^\@]*)$/
Truth table33%1/3
A and B
A= defined $iB= $i =~ /\@([^\@]*)$/
| |||||||||||||||||||||||||||||
| 302 | 90 | return match_subdomain( $1, $d ); | |||||||||||||||||||||||||||
| 303 | } | ||||||||||||||||||||||||||||
| 304 | 0 | return 0; | |||||||||||||||||||||||||||
| 305 | } | ||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||
| 307 | 90 | ▶ | sub match_subdomain { | ||||||||||||||||||||||||||
|
Subroutine
match_subdomain: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 308 | 90 | ▶ | croak 'wrong number of arguments' unless ( @_ == 2 ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 309 | 90 | my ( $subdomain, $superdomain ) = @_; | |||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||
| 311 | 90 | my $tmp = substr( ".$subdomain", -1 - length($superdomain) ); | |||||||||||||||||||||||||||
| 312 | 90 | return ( lc ".$superdomain" eq lc $tmp ); | |||||||||||||||||||||||||||
| 313 | } | ||||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||
| 315 | # | ||||||||||||||||||||||||||||
| 316 | # called when the verifier has received the last of the message headers | ||||||||||||||||||||||||||||
| 317 | # (body is still to come) | ||||||||||||||||||||||||||||
| 318 | # | ||||||||||||||||||||||||||||
| 319 | 100 | ▶ | sub finish_header { | ||||||||||||||||||||||||||
|
Subroutine
finish_header: called CC=9 SCAR=22.5
Pod
undocumented
| |||||||||||||||||||||||||||||
| 320 | 100 | my $self = shift; | |||||||||||||||||||||||||||
| 321 | |||||||||||||||||||||||||||||
| 322 | # Signatures we found and were successfully parsed are stored in | ||||||||||||||||||||||||||||
| 323 | # $self->{signatures}. If none were found, our result is "none". | ||||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||
| 325 | 100 | ▶ | if ( @{ $self->{signatures} } == 0 | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
@{$self->{"signatures"};} == 0 and not defined $self->{"signature_reject_reason"}
MC/DC50%1/2
@{$self->{"signatures"};} == 0 and not defined $self->{"signature_reject_reason"}
@{$self->{"signatures"};} == 0
not defined $self->{"signature_reject_reason"}
Truth table66%2/3
A and not(B)
A= @{$self->{"signatures"};} == 0B= not defined $self->{"signature_reject_reason"}
| |||||||||||||||||||||||||||||
| 326 | && !defined( $self->{signature_reject_reason} ) ) | ||||||||||||||||||||||||||||
| 327 | { | ||||||||||||||||||||||||||||
| 328 | 4 | $self->{result} = 'none'; | |||||||||||||||||||||||||||
| 329 | 4 | return; | |||||||||||||||||||||||||||
| 330 | } | ||||||||||||||||||||||||||||
| 331 | |||||||||||||||||||||||||||||
| 332 | # share the header indexes between the signatures | ||||||||||||||||||||||||||||
| 333 | 96 | my $index = {}; | |||||||||||||||||||||||||||
| 334 | 96 | foreach my $algorithm ( @{ $self->{algorithms} } ) { | |||||||||||||||||||||||||||
| 335 | $algorithm->finish_header( | ||||||||||||||||||||||||||||
| 336 | Headers => $self->{headers}, | ||||||||||||||||||||||||||||
| 337 | 90 | HeaderIndex => $index | |||||||||||||||||||||||||||
| 338 | ); | ||||||||||||||||||||||||||||
| 339 | } | ||||||||||||||||||||||||||||
| 340 | |||||||||||||||||||||||||||||
| 341 | # stop processing signatures that are already known to be invalid | ||||||||||||||||||||||||||||
| 342 | 96 | @{ $self->{algorithms} } = grep { | |||||||||||||||||||||||||||
| 343 | 90 | my $sig = $_->signature; | |||||||||||||||||||||||||||
| 344 | 90 | ▶ | !( $sig->result && $sig->result eq 'invalid' ); | ||||||||||||||||||||||||||
|
Condition33%1/3
$sig->result && $sig->result eq 'invalid'
MC/DC0%0/2
$sig->result && $sig->result eq 'invalid'
$sig->result
$sig->result eq 'invalid'
Truth table33%1/3
A && B
A= $sig->resultB= $sig->result eq 'invalid'
| |||||||||||||||||||||||||||||
| 345 | 96 | } @{ $self->{algorithms} }; | |||||||||||||||||||||||||||
| 346 | |||||||||||||||||||||||||||||
| 347 | 96 | ▶ | if ( @{ $self->{algorithms} } == 0 | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
@{$self->{"algorithms"};} == 0 and @{$self->{"signatures"};} > 0
MC/DC50%1/2
@{$self->{"algorithms"};} == 0 and @{$self->{"signatures"};} > 0
@{$self->{"algorithms"};} == 0
@{$self->{"signatures"};} > 0
Truth table66%2/3
A and B
A= @{$self->{"algorithms"};} == 0B= @{$self->{"signatures"};} > 0
| |||||||||||||||||||||||||||||
| 348 | 20 | && @{ $self->{signatures} } > 0 ) | |||||||||||||||||||||||||||
| 349 | { | ||||||||||||||||||||||||||||
| 350 | 20 | ▶ | $self->{result} = $self->{signatures}->[0]->result || 'invalid'; | ||||||||||||||||||||||||||
|
Condition50%1/2
$self->{'signatures'}[0]->result || 'invalid'
MC/DC0%0/1
$self->{'signatures'}[0]->result || 'invalid'
$self->{'signatures'}[0]->result
Truth table50%1/2
A
A= $self->{'signatures'}[0]->result
| |||||||||||||||||||||||||||||
| 351 | $self->{details} = $self->{signatures}->[0]->{verify_details} | ||||||||||||||||||||||||||||
| 352 | 20 | ▶ | || $self->{signature_reject_reason}; | ||||||||||||||||||||||||||
|
Condition33%1/3
$self->{'signatures'}[0]{'verify_details'} || $self->{'signature_reject_reason'}
MC/DC0%0/2
$self->{'signatures'}[0]{'verify_details'} || $self->{'signature_reject_reason'}
$self->{'signatures'}[0]{'verify_details'}
$self->{'signature_reject_reason'}
Truth table33%1/3
A || B
A= $self->{'signatures'}[0]{'verify_details'}B= $self->{'signature_reject_reason'}
| |||||||||||||||||||||||||||||
| 353 | 20 | return; | |||||||||||||||||||||||||||
| 354 | } | ||||||||||||||||||||||||||||
| 355 | } | ||||||||||||||||||||||||||||
| 356 | |||||||||||||||||||||||||||||
| 357 | 90 | ▶ | sub _check_and_verify_signature { | ||||||||||||||||||||||||||
|
Subroutine
_check_and_verify_signature: called CC=14 SCAR=26.6
| |||||||||||||||||||||||||||||
| 358 | 90 | my $self = shift; | |||||||||||||||||||||||||||
| 359 | 90 | my ($algorithm) = @_; | |||||||||||||||||||||||||||
| 360 | |||||||||||||||||||||||||||||
| 361 | # check signature | ||||||||||||||||||||||||||||
| 362 | 90 | my $signature = $algorithm->signature; | |||||||||||||||||||||||||||
| 363 | 90 | ▶ | unless ( check_signature_identity($signature) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 364 | 3 | $self->{signature_reject_reason} = 'bad identity'; | |||||||||||||||||||||||||||
| 365 | 3 | return ( 'invalid', $self->{signature_reject_reason} ); | |||||||||||||||||||||||||||
| 366 | } | ||||||||||||||||||||||||||||
| 367 | |||||||||||||||||||||||||||||
| 368 | # get public key | ||||||||||||||||||||||||||||
| 369 | 87 | my $pkey; | |||||||||||||||||||||||||||
| 370 | 87 | eval { $pkey = $signature->get_public_key; 1 } | |||||||||||||||||||||||||||
| 371 | 87 | ▶ | || do { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 372 | 24 | my $E = $@; | |||||||||||||||||||||||||||
| 373 | 24 | chomp $E; | |||||||||||||||||||||||||||
| 374 | 24 | $self->{signature_reject_reason} = "public key: $E"; | |||||||||||||||||||||||||||
| 375 | 24 | return ( 'invalid', $self->{signature_reject_reason} ); | |||||||||||||||||||||||||||
| 376 | }; | ||||||||||||||||||||||||||||
| 377 | |||||||||||||||||||||||||||||
| 378 | 63 | ▶ | unless ( $self->check_public_key( $signature, $pkey ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 379 | 7 | return ( 'invalid', $self->{signature_reject_reason} ); | |||||||||||||||||||||||||||
| 380 | } | ||||||||||||||||||||||||||||
| 381 | |||||||||||||||||||||||||||||
| 382 | # special handling for RSA signatures | ||||||||||||||||||||||||||||
| 383 | 56 | ▶ | my $k = $pkey->get_tag('k') || 'rsa'; | ||||||||||||||||||||||||||
|
Condition100%2/2
$pkey->get_tag('k') || 'rsa'
MC/DC100%1/1
$pkey->get_tag('k') || 'rsa'
$pkey->get_tag('k')
Truth table100%2/2
A
A= $pkey->get_tag('k')
| |||||||||||||||||||||||||||||
| 384 | 56 | ▶ | if ($k eq 'rsa') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 385 | # make sure key is big enough | ||||||||||||||||||||||||||||
| 386 | 53 | my $keysize = $pkey->cork->size * 8; # in bits | |||||||||||||||||||||||||||
| 387 | 53 | ▶ | if ( $keysize < 1024 && $self->{Strict} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$keysize < 1024 and $self->{"Strict"}
MC/DC100%2/2
$keysize < 1024 and $self->{"Strict"}
$keysize < 1024
$self->{"Strict"}
Truth table100%3/3
A and B
A= $keysize < 1024B= $self->{"Strict"}
| |||||||||||||||||||||||||||||
| 388 | 1 | $self->{signature_reject_reason} = "Key length $keysize too short"; | |||||||||||||||||||||||||||
| 389 | 1 | return ( 'fail', $self->{signature_reject_reason} ); | |||||||||||||||||||||||||||
| 390 | } | ||||||||||||||||||||||||||||
| 391 | } | ||||||||||||||||||||||||||||
| 392 | |||||||||||||||||||||||||||||
| 393 | # verify signature | ||||||||||||||||||||||||||||
| 394 | 55 | my $result; | |||||||||||||||||||||||||||
| 395 | my $details; | ||||||||||||||||||||||||||||
| 396 | 55 | local $@ = undef; | |||||||||||||||||||||||||||
| 397 | eval { | ||||||||||||||||||||||||||||
| 398 | 55 | ▶ | $result = $algorithm->verify() ? 'pass' : 'fail'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 399 | 53 | ▶ | $details = $algorithm->{verification_details} || $@; | ||||||||||||||||||||||||||
|
Condition100%3/3
$algorithm->{'verification_details'} || $@
MC/DC100%2/2
$algorithm->{'verification_details'} || $@
$algorithm->{'verification_details'}
$@
Truth table100%3/3
A || B
A= $algorithm->{'verification_details'}B= $@
| |||||||||||||||||||||||||||||
| 400 | 53 | 1 | |||||||||||||||||||||||||||
| 401 | 55 | ▶ | } || do { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 402 | |||||||||||||||||||||||||||||
| 403 | # see also add_signature | ||||||||||||||||||||||||||||
| 404 | 2 | chomp( my $E = $@ ); | |||||||||||||||||||||||||||
| 405 | 2 | ▶ | if ( $E =~ /(OpenSSL error: .*?) at / ) { | ||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||
| 406 | 2 | $E = $1; | |||||||||||||||||||||||||||
| 407 | } | ||||||||||||||||||||||||||||
| 408 | elsif ( $E =~ /^(panic:.*?) at / ) { | ||||||||||||||||||||||||||||
| 409 | 0 | $E = "OpenSSL $1"; | |||||||||||||||||||||||||||
| 410 | } | ||||||||||||||||||||||||||||
| 411 | elsif ( $E =~ /^FATAL: (.*) at / ) { | ||||||||||||||||||||||||||||
| 412 | 0 | $E = "Ed25519 $1"; | |||||||||||||||||||||||||||
| 413 | } | ||||||||||||||||||||||||||||
| 414 | 2 | $result = 'fail'; | |||||||||||||||||||||||||||
| 415 | 2 | $details = $E; | |||||||||||||||||||||||||||
| 416 | }; | ||||||||||||||||||||||||||||
| 417 | 55 | return ( $result, $details ); | |||||||||||||||||||||||||||
| 418 | } | ||||||||||||||||||||||||||||
| 419 | |||||||||||||||||||||||||||||
| 420 | 100 | ▶ | sub finish_body { | ||||||||||||||||||||||||||
|
Subroutine
finish_body: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 421 | 100 | my $self = shift; | |||||||||||||||||||||||||||
| 422 | |||||||||||||||||||||||||||||
| 423 | 100 | foreach my $algorithm ( @{ $self->{algorithms} } ) { | |||||||||||||||||||||||||||
| 424 | |||||||||||||||||||||||||||||
| 425 | # finish canonicalizing | ||||||||||||||||||||||||||||
| 426 | 90 | $algorithm->finish_body; | |||||||||||||||||||||||||||
| 427 | |||||||||||||||||||||||||||||
| 428 | 90 | my ( $result, $details ) = | |||||||||||||||||||||||||||
| 429 | $self->_check_and_verify_signature($algorithm); | ||||||||||||||||||||||||||||
| 430 | |||||||||||||||||||||||||||||
| 431 | # save the results of this signature verification | ||||||||||||||||||||||||||||
| 432 | 90 | $algorithm->{result} = $result; | |||||||||||||||||||||||||||
| 433 | 90 | $algorithm->{details} = $details; | |||||||||||||||||||||||||||
| 434 | 90 | $algorithm->signature->result( $result, $details ); | |||||||||||||||||||||||||||
| 435 | |||||||||||||||||||||||||||||
| 436 | # collate results ... ignore failed signatures if we already got | ||||||||||||||||||||||||||||
| 437 | # one to pass | ||||||||||||||||||||||||||||
| 438 | 90 | ▶ | if ( !$self->{result} || $result eq 'pass' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not $self->{"result"} or $result eq "pass"
MC/DC100%2/2
not $self->{"result"} or $result eq "pass"
not $self->{"result"}
$result eq "pass"
Truth table100%3/3
not(A) or B
A= not $self->{"result"}B= $result eq "pass"
| |||||||||||||||||||||||||||||
| 439 | 78 | $self->{signature} = $algorithm->signature; | |||||||||||||||||||||||||||
| 440 | 78 | $self->{result} = $result; | |||||||||||||||||||||||||||
| 441 | 78 | $self->{details} = $details; | |||||||||||||||||||||||||||
| 442 | } | ||||||||||||||||||||||||||||
| 443 | } | ||||||||||||||||||||||||||||
| 444 | } | ||||||||||||||||||||||||||||
| 445 | |||||||||||||||||||||||||||||
| 446 | |||||||||||||||||||||||||||||
| 447 | 0 | ▶ | sub fetch_author_domain_policies { | ||||||||||||||||||||||||||
|
Subroutine
fetch_author_domain_policies: not called CC=2 SCAR=13.0
Pod
documented
| |||||||||||||||||||||||||||||
| 448 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 449 | 9 | ▶ | use Mail::DKIM::AuthorDomainPolicy; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 450 | |||||||||||||||||||||||||||||
| 451 | 0 | ▶ | return () unless $self->{headers_by_name}->{from}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 452 | 0 | my @list = Mail::Address->parse( $self->{headers_by_name}->{from} ); | |||||||||||||||||||||||||||
| 453 | 0 | my @authors = map { $_->address } @list; | |||||||||||||||||||||||||||
| 454 | |||||||||||||||||||||||||||||
| 455 | # fetch the policies | ||||||||||||||||||||||||||||
| 456 | return map { | ||||||||||||||||||||||||||||
| 457 | 0 | Mail::DKIM::AuthorDomainPolicy->fetch( | |||||||||||||||||||||||||||
| 458 | Protocol => 'dns', | ||||||||||||||||||||||||||||
| 459 | Author => $_, | ||||||||||||||||||||||||||||
| 460 | ) | ||||||||||||||||||||||||||||
| 461 | } @authors; | ||||||||||||||||||||||||||||
| 462 | } | ||||||||||||||||||||||||||||
| 463 | |||||||||||||||||||||||||||||
| 464 | |||||||||||||||||||||||||||||
| 465 | 0 | ▶ | sub fetch_author_policy { | ||||||||||||||||||||||||||
|
Subroutine
fetch_author_policy: not called CC=2 SCAR=12.2
Pod
documented
| |||||||||||||||||||||||||||||
| 466 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 467 | 0 | my ($author) = @_; | |||||||||||||||||||||||||||
| 468 | 9 | ▶ | use Mail::DKIM::DkimPolicy; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 469 | |||||||||||||||||||||||||||||
| 470 | # determine address found in the "From" | ||||||||||||||||||||||||||||
| 471 | 0 | ▶ | $author ||= $self->message_originator->address; | ||||||||||||||||||||||||||
|
Condition0%0/3
$author ||= $self->message_originator->address
MC/DC0%0/2
$author ||= $self->message_originator->address
$author
$self->message_originator->address
Truth table0%0/3
A ||= B
A= $authorB= $self->message_originator->address
| |||||||||||||||||||||||||||||
| 472 | |||||||||||||||||||||||||||||
| 473 | # fetch the policy | ||||||||||||||||||||||||||||
| 474 | 0 | return Mail::DKIM::DkimPolicy->fetch( | |||||||||||||||||||||||||||
| 475 | Protocol => 'dns', | ||||||||||||||||||||||||||||
| 476 | Author => $author, | ||||||||||||||||||||||||||||
| 477 | ); | ||||||||||||||||||||||||||||
| 478 | } | ||||||||||||||||||||||||||||
| 479 | |||||||||||||||||||||||||||||
| 480 | |||||||||||||||||||||||||||||
| 481 | 0 | ▶ | sub fetch_sender_policy { | ||||||||||||||||||||||||||
|
Subroutine
fetch_sender_policy: not called CC=1 SCAR=1.7
Pod
documented
| |||||||||||||||||||||||||||||
| 482 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 483 | 9 | ▶ | use Mail::DKIM::DkPolicy; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 484 | |||||||||||||||||||||||||||||
| 485 | # determine addresses found in the "From" and "Sender" headers | ||||||||||||||||||||||||||||
| 486 | 0 | my $author = $self->message_originator->address; | |||||||||||||||||||||||||||
| 487 | 0 | my $sender = $self->message_sender->address; | |||||||||||||||||||||||||||
| 488 | |||||||||||||||||||||||||||||
| 489 | # fetch the policy | ||||||||||||||||||||||||||||
| 490 | 0 | return Mail::DKIM::DkPolicy->fetch( | |||||||||||||||||||||||||||
| 491 | Protocol => 'dns', | ||||||||||||||||||||||||||||
| 492 | Author => $author, | ||||||||||||||||||||||||||||
| 493 | Sender => $sender, | ||||||||||||||||||||||||||||
| 494 | ); | ||||||||||||||||||||||||||||
| 495 | } | ||||||||||||||||||||||||||||
| 496 | |||||||||||||||||||||||||||||
| 497 | |||||||||||||||||||||||||||||
| 498 | 0 | ▶ | sub policies { | ||||||||||||||||||||||||||
|
Subroutine
policies: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 499 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 500 | |||||||||||||||||||||||||||||
| 501 | 0 | my $sender_policy = eval { $self->fetch_sender_policy() }; | |||||||||||||||||||||||||||
| 502 | 0 | my $author_policy = eval { $self->fetch_author_policy() }; | |||||||||||||||||||||||||||
| 503 | return ( | ||||||||||||||||||||||||||||
| 504 | 0 | ▶ | $sender_policy ? $sender_policy : (), | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 505 | $author_policy ? $author_policy : (), | ||||||||||||||||||||||||||||
| 506 | $self->fetch_author_domain_policies(), | ||||||||||||||||||||||||||||
| 507 | ); | ||||||||||||||||||||||||||||
| 508 | } | ||||||||||||||||||||||||||||
| 509 | |||||||||||||||||||||||||||||
| 510 | |||||||||||||||||||||||||||||
| 511 | |||||||||||||||||||||||||||||
| 512 | |||||||||||||||||||||||||||||
| 513 | 4 | ▶ | sub signatures { | ||||||||||||||||||||||||||
|
Subroutine
signatures: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||
| 514 | 4 | my $self = shift; | |||||||||||||||||||||||||||
| 515 | 4 | ▶ | croak 'unexpected argument' if @_; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 516 | |||||||||||||||||||||||||||||
| 517 | 4 | return @{ $self->{signatures} }; | |||||||||||||||||||||||||||
| 518 | } | ||||||||||||||||||||||||||||
| 519 | |||||||||||||||||||||||||||||
| 520 | 9 | 1; | |||||||||||||||||||||||||||
| 521 | |||||||||||||||||||||||||||||
| 522 | __END__ | ||||||||||||||||||||||||||||