| 1 | package Mail::Milter::Authentication::Handler::XGoogleDKIM; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | 16 | ▶ | use 5.20.0; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 16 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 16 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 16 | ▶ | use Mail::Milter::Authentication::Pragmas; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | # ABSTRACT: Handler class for Google specific DKIM | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 16 | our $VERSION = '4.20261116'; # VERSION | |||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 16 | ▶ | use base 'Mail::Milter::Authentication::Handler'; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 16 | ▶ | use Mail::DKIM 1.20200824; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 16 | ▶ | use Mail::DKIM::DNS; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 16 | ▶ | use Mail::DKIM::Verifier; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 0 | ▶ | sub default_config { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
default_config: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | return { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 0 | 'hide_none' => 0, | |||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 'early_lookup_limit' => 10, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 0 | ▶ | sub grafana_rows { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
grafana_rows: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 0 | my ( $self ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 0 | my @rows; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 0 | push @rows, $self->get_json( 'XGoogleDKIM_metrics' ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 0 | return \@rows; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 16 | ▶ | sub register_metrics { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
register_metrics: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | return { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 16 | 'xgoogledkim_total' => 'The number of emails processed for X-Google-DKIM', | |||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 67 | ▶ | sub envfrom_callback { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
envfrom_callback: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 67 | my ( $self, $env_from ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 67 | $self->{'failmode'} = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 67 | $self->{'headers'} = []; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 67 | $self->{'has_dkim'} = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 67 | $self->{'early_lookups'} = {}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 67 | $self->{'carry'} = q{}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 67 | $self->destroy_object('xgdkim'); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 831 | ▶ | sub header_callback { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
header_callback: called CC=10 SCAR=23.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 831 | my ( $self, $header, $value, $original ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 831 | ▶ | return if ( $self->{'failmode'} ); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 831 | my $EOL = "\015\012"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 831 | my $dkim_chunk = $original . $EOL; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 831 | $dkim_chunk =~ s/\015?\012/$EOL/g; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 831 | ▶ | if ( lc($header) eq 'dkim-signature' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 41 | $dkim_chunk = 'X-Orig-' . $dkim_chunk; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 831 | ▶ | if ( lc($header) eq 'domainkey-signature' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 0 | $dkim_chunk = 'X-Orig-' . $dkim_chunk; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 831 | push @{$self->{'headers'}} , $dkim_chunk; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | # Add Google signatures to the mix. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | # Is this wise? | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 831 | ▶ | if ( $header eq 'X-Google-DKIM-Signature' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 66 | my $x_dkim_chunk = 'DKIM-Signature: ' . $value . $EOL; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 66 | $x_dkim_chunk =~ s/\015?\012/$EOL/g; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 66 | push @{$self->{'headers'}} , $x_dkim_chunk; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 66 | $self->{'has_dkim'} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 66 | my ($domain) = $value =~ /d=([^;]*);/; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 66 | my ($selector) = $value =~ /s=([^;]*);/; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 66 | my $resolver = $self->get_object('resolver'); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 66 | ▶ | if ( defined $selector && defined $domain ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $selector and defined $domain
MC/DC0%0/2
defined $selector and defined $domain
defined $selector
defined $domain
Truth table33%1/3
A and B
A= defined $selectorB= defined $domain
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 66 | my $config = $self->handler_config(); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 66 | ▶ | my $lookup_limit = $config->{'early_lookup_limit'} // 10; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$config->{"early_lookup_limit"} // 10
MC/DC100%1/1
$config->{"early_lookup_limit"} // 10
$config->{"early_lookup_limit"}
Truth table100%2/2
A
A= $config->{"early_lookup_limit"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 66 | my $lookup = $selector.'._domainkey.'.$domain; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 66 | ▶ | if ( ! $self->{'early_lookups'}->{ lc $lookup } && scalar keys $self->{'early_lookups'}->%* < $lookup_limit ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not $self->{"early_lookups"}{lc $lookup} and scalar keys %{$$self{"early_lookups"}} < $lookup_limit
MC/DC100%2/2
not $self->{"early_lookups"}{lc $lookup} and scalar keys %{$$self{"early_lookups"}} < $lookup_limit
not $self->{"early_lookups"}{lc $lookup}
scalar keys %{$$self{"early_lookups"}} < $lookup_limit
Truth table100%3/3
not(A) and B
A= not $self->{"early_lookups"}{lc $lookup}B= scalar keys %{$$self{"early_lookups"}} < $lookup_limit
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 50 | $self->{'early_lookups'}->{ lc $lookup } = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 50 | eval{ $resolver->bgsend( $lookup, 'TXT' ) }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 50 | $self->handle_exception( $@ ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 50 | $self->dbgout( 'DNSEarlyLookup', "$lookup TXT", LOG_DEBUG ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 65 | ▶ | sub eoh_callback { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
eoh_callback: called CC=6 SCAR=19.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 65 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 65 | ▶ | return if ( $self->{'failmode'} ); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 65 | my $config = $self->handler_config(); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 65 | ▶ | if ( $self->{'has_dkim'} == 0 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 27 | $self->metric_count( 'xgoogledkim_total', { 'result' => 'none' } ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 27 | $self->dbgout( 'XGoogleDKIMResult', 'No X-Google-DKIM headers', LOG_DEBUG ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 27 | ▶ | if ( !( $config->{'hide_none'} ) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 19 | my $header = Mail::AuthenticationResults::Header::Entry->new()->set_key( 'x-google-dkim' )->safe_set_value( 'none' ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 19 | $header->add_child( Mail::AuthenticationResults::Header::Comment->new()->safe_set_value( 'no signatures found' ) ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 19 | $self->add_auth_header( $header ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 27 | delete $self->{'headers'}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 38 | my $dkim; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 38 | eval { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 38 | $dkim = Mail::DKIM::Verifier->new(); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 38 | my $resolver = $self->get_object('resolver'); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 38 | Mail::DKIM::DNS::resolver($resolver); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 38 | $self->set_object('xgdkim', $dkim, 1); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 38 | ▶ | if ( my $error = $@ ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 0 | $self->handle_exception( $error ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 0 | $self->log_error( 'XGoogleDKIM Setup Error ' . $error ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 0 | $self->{'failmode'} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 0 | $self->_check_error( $error ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 0 | $self->metric_count( 'xgoogledkim_total', { 'result' => 'error' } ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 0 | delete $self->{'headers'}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 38 | eval { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | $dkim->PRINT( join q{}, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 38 | @{ $self->{'headers'} }, | |||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | "\015\012", | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 38 | ▶ | if ( my $error = $@ ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 0 | $self->handle_exception( $error ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 0 | $self->log_error( 'XGoogleDKIM Headers Error ' . $error ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 0 | $self->{'failmode'} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 0 | $self->_check_error( $error ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 0 | $self->metric_count( 'xgoogledkim_total', { 'result' => 'error' } ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 38 | delete $self->{'headers'}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 65 | $self->{'carry'} = q{}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 63 | ▶ | sub body_callback { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
body_callback: called CC=6 SCAR=21.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 63 | my ( $self, $body_chunk ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 63 | ▶ | return if ( $self->{'failmode'} ); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 63 | ▶ | return if ( $self->{'has_dkim'} == 0 ); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 38 | my $EOL = "\015\012"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 38 | my $dkim_chunk; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 38 | ▶ | if ( $self->{'carry'} ne q{} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 0 | $dkim_chunk = $self->{'carry'} . $body_chunk; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 0 | $self->{'carry'} = q{}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 38 | $dkim_chunk = $body_chunk; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 38 | ▶ | if ( substr( $dkim_chunk, -1 ) eq "\015" ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 0 | $self->{'carry'} = "\015"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 0 | $dkim_chunk = substr( $dkim_chunk, 0, -1 ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 38 | $dkim_chunk =~ s/\015?\012/$EOL/g; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 38 | my $dkim = $self->get_object('xgdkim'); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 38 | eval { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 38 | $dkim->PRINT( $dkim_chunk ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 38 | ▶ | if ( my $error = $@ ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 0 | $self->handle_exception( $error ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 0 | $self->log_error( 'XGoogleDKIM Body Error ' . $error ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 0 | $self->{'failmode'} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 0 | $self->_check_error( $error ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 0 | $self->metric_count( 'xgoogledkim_total', { 'result' => 'error' } ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 65 | ▶ | sub eom_callback { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
eom_callback: called CC=17 SCAR=34.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 65 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 65 | ▶ | return if ( $self->{'has_dkim'} == 0 ); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 38 | ▶ | return if ( $self->{'failmode'} ); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 38 | my $config = $self->handler_config(); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 38 | my $dkim = $self->get_object('xgdkim'); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 38 | eval { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 38 | $dkim->PRINT( $self->{'carry'} ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 38 | $dkim->CLOSE(); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 38 | my $dkim_result = $dkim->result; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 38 | my $dkim_result_detail = $dkim->result_detail; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 38 | $self->metric_count( 'xgoogledkim_total', { 'result' => $dkim_result } ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 38 | $self->dbgout( 'XGoogleDKIMResult', $dkim_result_detail, LOG_DEBUG ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 38 | ▶ | if ( !$dkim->signatures() ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | 0 | ▶ | if ( !( $config->{'hide_none'} && $dkim_result eq 'none' ) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$config->{"hide_none"} and $dkim_result eq "none"
MC/DC0%0/2
$config->{"hide_none"} and $dkim_result eq "none"
$config->{"hide_none"}
$dkim_result eq "none"
Truth table0%0/3
A and B
A= $config->{"hide_none"}B= $dkim_result eq "none"
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 0 | my $header = Mail::AuthenticationResults::Header::Entry->new()->set_key( 'x-google-dkim' )->safe_set_value( $dkim_result ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 0 | $header->add_child( Mail::AuthenticationResults::Header::Comment->new()->safe_set_value( 'no signatures found' ) ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 0 | $self->add_auth_header( $header ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 38 | foreach my $signature ( $dkim->signatures() ) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 38 | my $otype = ref $signature; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 38 | ▶ | my $type = | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | $otype eq 'Mail::DKIM::DkSignature' ? 'domainkeys' | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | : $otype eq 'Mail::DKIM::Signature' ? 'dkim' | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | : 'dkim'; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 38 | $self->dbgout( 'XGoogleDKIMSignatureType', $type, LOG_DEBUG ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 38 | $self->dbgout( 'XGoogleDKIMSignatureIdentity', $signature->identity, LOG_DEBUG ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | 38 | $self->dbgout( 'XGoogleDKIMSignatureResult', $signature->result_detail, LOG_DEBUG ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 38 | my $signature_result = $signature->result(); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 38 | my $signature_result_detail = $signature->result_detail(); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 38 | ▶ | if ( $signature_result eq 'invalid' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 0 | ▶ | if ( $signature_result_detail =~ /DNS query timeout for (.*) at / ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 0 | my $timeout_domain = $1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | 0 | $self->log_error( "TIMEOUT DETECTED: in XGoogleDKIM result: $timeout_domain" ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 0 | $signature_result_detail = "DNS query timeout for $timeout_domain"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 38 | my $result_comment = q{}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 38 | ▶ | if ( $signature_result ne 'pass' and $signature_result ne 'none' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$signature_result ne "pass" and $signature_result ne "none"
MC/DC50%1/2
$signature_result ne "pass" and $signature_result ne "none"
$signature_result ne "pass"
$signature_result ne "none"
Truth table66%2/3
A and B
A= $signature_result ne "pass"B= $signature_result ne "none"
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 8 | $signature_result_detail =~ /$signature_result \((.*)\)/; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | 8 | ▶ | if ( $1 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 8 | $result_comment = $1 . ', '; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 38 | ▶ | if ( | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$config->{"hide_none"} and $signature_result eq "none"
MC/DC0%0/2
$config->{"hide_none"} and $signature_result eq "none"
$config->{"hide_none"}
$signature_result eq "none"
Truth table66%2/3
A and B
A= $config->{"hide_none"}B= $signature_result eq "none"
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | !( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | $config->{'hide_none'} && $signature_result eq 'none' | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | 38 | my $key_data = q{}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | 38 | eval { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 38 | my $key = $signature->get_public_key(); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | 38 | $key_data = $key->size() . '-bit ' . $key->type() . ' key'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | 38 | my $header = Mail::AuthenticationResults::Header::Entry->new()->set_key( 'x-google-dkim' )->safe_set_value( $signature_result ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | 38 | $header->add_child( Mail::AuthenticationResults::Header::Comment->new()->safe_set_value( $result_comment . $key_data ) ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | 38 | $header->add_child( Mail::AuthenticationResults::Header::SubEntry->new()->set_key( 'header.d' )->safe_set_value( $signature->domain() ) ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | 38 | $header->add_child( Mail::AuthenticationResults::Header::SubEntry->new()->set_key( 'header.i' )->safe_set_value( $signature->identity() ) ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | 38 | $header->add_child( Mail::AuthenticationResults::Header::SubEntry->new()->set_key( 'header.b' )->safe_set_value( substr( $signature->data(), 0, 8 ) ) ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | 38 | $self->add_auth_header($header); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | 38 | ▶ | if ( my $error = $@ ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | 0 | $self->handle_exception( $error ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | # Also in DMARC module | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | 0 | $self->log_error( 'XGoogleDKIM EOM Error ' . $error ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 0 | $self->{'failmode'} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | 0 | $self->_check_error( $error ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 0 | $self->metric_count( 'xgoogledkim_total', { 'result' => 'error' } ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | 105 | ▶ | sub close_callback { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
close_callback: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | 105 | my ( $self ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | 105 | delete $self->{'failmode'}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | 105 | delete $self->{'headers'}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | 105 | delete $self->{'body'}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | 105 | delete $self->{'carry'}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | 105 | delete $self->{'has_dkim'}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | 105 | delete $self->{'early_lookups'}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | 105 | $self->destroy_object('xgdkim'); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | 0 | ▶ | sub _check_error { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_check_error: not called CC=7 SCAR=40.3
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | 0 | my ( $self, $error ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | 0 | ▶ | if ( $error =~ /^DNS error: query timed out/ | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/3
$error =~ /^DNS error: query timed out/u or $error =~ /^DNS query timeout/u
MC/DC0%0/2
$error =~ /^DNS error: query timed out/u or $error =~ /^DNS query timeout/u
$error =~ /^DNS error: query timed out/u
$error =~ /^DNS query timeout/u
Truth table0%0/3
A or B
A= $error =~ /^DNS error: query timed out/uB= $error =~ /^DNS query timeout/u
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | or $error =~ /^DNS query timeout/ | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | ){ | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | 0 | $self->log_error( 'Temp XGoogleDKIM Error - ' . $error ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | 0 | my $header = Mail::AuthenticationResults::Header::Entry->new()->set_key( 'x-google-dkim' )->safe_set_value( 'temperror' ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | 0 | $header->add_child( Mail::AuthenticationResults::Header::Comment->new()->safe_set_value( 'dns timeout' ) ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | 0 | $self->add_auth_header( $header ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | ▶ | elsif ( $error =~ /^no domain to fetch policy for$/ | |||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/9
$error =~ /^no domain to fetch policy for$/u or $error =~ /^policy syntax error$/u or $error =~ /^empty domain label/u or $error =~ /^invalid name /u
$error =~ /^no domain to fetch policy for$/u or $error =~ /^policy syntax error$/u or $error =~ /^empty domain label/u
$error =~ /^no domain to fetch policy for$/u or $error =~ /^policy syntax error$/u
MC/DC0%0/4
$error =~ /^no domain to fetch policy for$/u or $error =~ /^policy syntax error$/u or $error =~ /^empty domain label/u or $error =~ /^invalid name /u
$error =~ /^no domain to fetch policy for$/u
$error =~ /^policy syntax error$/u
$error =~ /^empty domain label/u
$error =~ /^invalid name /u
Truth table0%0/5
A or B or C or D
A= $error =~ /^no domain to fetch policy for$/uB= $error =~ /^policy syntax error$/uC= $error =~ /^empty domain label/uD= $error =~ /^invalid name /u
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | or $error =~ /^policy syntax error$/ | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | or $error =~ /^empty domain label/ | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | or $error =~ /^invalid name / | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | ){ | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | 0 | $self->log_error( 'Perm XGoogleDKIM Error - ' . $error ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | 0 | my $header = Mail::AuthenticationResults::Header::Entry->new()->set_key( 'x-google-dkim' )->safe_set_value( 'perlerror' ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | 0 | $header->add_child( Mail::AuthenticationResults::Header::Comment->new()->safe_set_value( 'syntax or domain error' ) ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | 0 | $self->add_auth_header( $header ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | 0 | $self->exit_on_close( 'Unexpected XGoogleDKIM Error - ' . $error ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | 0 | my $header = Mail::AuthenticationResults::Header::Entry->new()->set_key( 'x-google-dkim' )->safe_set_value( 'temperror' ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | 0 | $self->add_auth_header( $header ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | # Fill these in as they occur, but for unknowns err on the side of caution | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | # and tempfail/exit | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | 0 | $self->tempfail_on_error(); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | 16 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||