| 1 | package Mail::BIMI::VMC; | ||||||||||||||||||||||||||||
| 2 | # ABSTRACT: Class to model a VMC | ||||||||||||||||||||||||||||
| 3 | 29 | our $VERSION = '3.20261116'; # VERSION | |||||||||||||||||||||||||||
| 4 | 29 | ▶ | use 5.20.0; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 29 | ▶ | use Moose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 29 | ▶ | use Mail::BIMI::Prelude; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 29 | ▶ | use File::Slurp qw{ read_file write_file }; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 29 | ▶ | use MIME::Base64; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 29 | ▶ | use Term::ANSIColor qw{ :constants }; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 29 | ▶ | use Mail::BIMI::Indicator; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 29 | ▶ | use Mail::BIMI::VMC::Chain; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 29 | extends 'Mail::BIMI::Base'; | |||||||||||||||||||||||||||
| 14 | 29 | with( | |||||||||||||||||||||||||||
| 15 | 'Mail::BIMI::Role::HasError', | ||||||||||||||||||||||||||||
| 16 | 'Mail::BIMI::Role::HasHTTPClient', | ||||||||||||||||||||||||||||
| 17 | 'Mail::BIMI::Role::Cacheable', | ||||||||||||||||||||||||||||
| 18 | ); | ||||||||||||||||||||||||||||
| 19 | 29 | has uri => ( is => 'rw', isa => 'Str', traits => ['CacheKey'], | |||||||||||||||||||||||||||
| 20 | documentation => 'inputs: URI of this VMC', ); | ||||||||||||||||||||||||||||
| 21 | 29 | has check_domain => ( is => 'ro', isa => 'Str', required => 1, traits => ['CacheKey'], | |||||||||||||||||||||||||||
| 22 | documentation => 'inputs: Domain to check the alt_name against', ); | ||||||||||||||||||||||||||||
| 23 | 29 | has check_selector => ( is => 'ro', isa => 'Str', required => 1, traits => ['CacheKey'], | |||||||||||||||||||||||||||
| 24 | documentation => 'inputs: Selector to check the alt_name against', ); | ||||||||||||||||||||||||||||
| 25 | 29 | has data => ( is => 'rw', isa => 'Str', lazy => 1, builder => '_build_data', traits => ['Cacheable'], | |||||||||||||||||||||||||||
| 26 | documentation => 'inputs: Raw data of the VMC contents; Fetched from authority URI if not given', ); | ||||||||||||||||||||||||||||
| 27 | 29 | has cert_list => ( is => 'rw', isa => 'ArrayRef', lazy => 1, builder => '_build_cert_list', traits => ['Cacheable'], | |||||||||||||||||||||||||||
| 28 | documentation => 'ArrayRef of individual Certificates in the chain' ); | ||||||||||||||||||||||||||||
| 29 | 29 | has chain_object => ( is => 'rw', lazy => 1, builder => '_build_chain_object', | |||||||||||||||||||||||||||
| 30 | documentation => 'Mail::BIMI::VMC::Chain object for this Chain' ); | ||||||||||||||||||||||||||||
| 31 | 29 | has is_valid => ( is => 'rw', lazy => 1, builder => '_build_is_valid', traits => ['Cacheable'], | |||||||||||||||||||||||||||
| 32 | documentation => 'Is this VMC valid' ); | ||||||||||||||||||||||||||||
| 33 | 29 | has vmc_object => ( is => 'rw', lazy => 1, builder => '_build_vmc_object', | |||||||||||||||||||||||||||
| 34 | documentation => 'Mail::BIMI::VMC::Cert object for this VMC Set' ); | ||||||||||||||||||||||||||||
| 35 | 29 | has is_cert_valid => ( is => 'rw', lazy => 1, builder => '_build_is_cert_valid', traits => ['Cacheable'], | |||||||||||||||||||||||||||
| 36 | documentation => 'Is this Certificate Set valid' ); | ||||||||||||||||||||||||||||
| 37 | 29 | has indicator_uri => ( is => 'rw', lazy => 1, builder => '_build_indicator_uri', traits => ['Cacheable'], | |||||||||||||||||||||||||||
| 38 | documentation => 'The URI of the embedded Indicator' ); | ||||||||||||||||||||||||||||
| 39 | 29 | has indicator => ( is => 'rw', lazy => 1, builder => '_build_indicator', | |||||||||||||||||||||||||||
| 40 | documentation => 'Mail::BIMI::Indicator object for the Indicator embedded in this VMC Set' ); | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 0 | ▶ | sub cache_valid_for($self) { return 3600 } | ||||||||||||||||||||||||||
|
Subroutine
cache_valid_for: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | 0 | ▶ | sub http_client_max_fetch_size($self) { return $self->bimi_object->options->vmc_max_fetch_size }; | ||||||||||||||||||||||||||
|
Subroutine
http_client_max_fetch_size: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | 0 | ▶ | sub _build_data($self) { | ||||||||||||||||||||||||||
|
Subroutine
_build_data: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||
| 50 | 0 | ▶ | if ( ! $self->uri ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 51 | 0 | $self->add_error('CODE_MISSING_AUTHORITY'); | |||||||||||||||||||||||||||
| 52 | 0 | return ''; | |||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||
| 54 | 0 | ▶ | if ($self->bimi_object->options->vmc_from_file) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 55 | 0 | return scalar read_file $self->bimi_object->options->vmc_from_file; | |||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 0 | $self->log_verbose('HTTP Fetch: '.$self->uri); | |||||||||||||||||||||||||||
| 59 | 0 | my $response = $self->http_client_get( $self->uri ); | |||||||||||||||||||||||||||
| 60 | 0 | ▶ | if ( !$response->{success} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 61 | 0 | ▶ | if ( $response->{status} == 599 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 62 | 0 | $self->add_error('VMC_FETCH_ERROR',$response->{content}); | |||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||
| 64 | else { | ||||||||||||||||||||||||||||
| 65 | 0 | $self->add_error('VMC_FETCH_ERROR',$response->{status}); | |||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||
| 67 | 0 | return ''; | |||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||
| 69 | 0 | return $response->{content}; | |||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | 0 | ▶ | sub _build_cert_list($self) { | ||||||||||||||||||||||||||
|
Subroutine
_build_cert_list: not called CC=6 SCAR=37.4
| |||||||||||||||||||||||||||||
| 73 | 0 | my @certs; | |||||||||||||||||||||||||||
| 74 | 0 | my $this_cert = []; | |||||||||||||||||||||||||||
| 75 | 0 | my $data = $self->data; | |||||||||||||||||||||||||||
| 76 | 0 | foreach my $cert_line ( split(/\n/,$data) ) { | |||||||||||||||||||||||||||
| 77 | 0 | $cert_line =~ s/\r//; | |||||||||||||||||||||||||||
| 78 | 0 | ▶ | next if ! $cert_line; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 79 | 0 | push $this_cert->@*, $cert_line; | |||||||||||||||||||||||||||
| 80 | 0 | ▶ | if ( $cert_line =~ /^\-+END CERTIFICATE\-+$/ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 81 | 0 | ▶ | push @certs, $this_cert if $this_cert->@*; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 82 | 0 | $this_cert = []; | |||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||
| 85 | 0 | ▶ | push @certs, $this_cert if $this_cert->@*; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 86 | 0 | return \@certs; | |||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | 0 | ▶ | sub _build_chain_object($self) { | ||||||||||||||||||||||||||
|
Subroutine
_build_chain_object: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 91 | 0 | return Mail::BIMI::VMC::Chain->new( bimi_object => $self->bimi_object, cert_list => $self->cert_list ); | |||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | 0 | ▶ | sub _build_vmc_object($self) { | ||||||||||||||||||||||||||
|
Subroutine
_build_vmc_object: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 96 | 0 | ▶ | return if !$self->chain_object; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 97 | 0 | ▶ | return if !$self->chain_object->vmc; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 98 | 0 | return $self->chain_object->vmc; | |||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | 0 | ▶ | sub _build_is_cert_valid($self) { | ||||||||||||||||||||||||||
|
Subroutine
_build_is_cert_valid: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 102 | 0 | ▶ | return 1 if $self->bimi_object->options->no_validate_cert; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 103 | 0 | return $self->chain_object->is_valid; | |||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | 0 | ▶ | sub subject($self) { | ||||||||||||||||||||||||||
|
Subroutine
subject: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 108 | 0 | ▶ | return if !$self->vmc_object; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 109 | 0 | return $self->vmc_object->x509_object->subject; | |||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | 7 | ▶ | sub subject_entries($self, $subject) { | ||||||||||||||||||||||||||
|
Subroutine
subject_entries: called CC=8 SCAR=20.9
Pod
documented
| |||||||||||||||||||||||||||||
| 115 | 7 | my %result; | |||||||||||||||||||||||||||
| 116 | 7 | ▶ | return \%result unless defined $subject; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 117 | 7 | ▶ | while ($subject) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 118 | # Messy regex ahead. | ||||||||||||||||||||||||||||
| 119 | # overall goal is to break apart a comma-separated list of key=value pairs, | ||||||||||||||||||||||||||||
| 120 | # where value can contain a comma, | ||||||||||||||||||||||||||||
| 121 | # The regex accepts a key (containing no commas or equals), (^,=)* | ||||||||||||||||||||||||||||
| 122 | # then an equals, then a value. This is a little tangled. To make it able to survive | ||||||||||||||||||||||||||||
| 123 | # an equals in a value, it is allowed any character (inc. =) till it reaches a comma. | ||||||||||||||||||||||||||||
| 124 | # once it gets to a comma, and equals would define a new section so we grab an equals, | ||||||||||||||||||||||||||||
| 125 | # as many non-comma characters as we can then all the non-equals characters: =([^,]*[^=]*?) | ||||||||||||||||||||||||||||
| 126 | # basically matching "key = value" - (note: *? to take the least characters possible) where | ||||||||||||||||||||||||||||
| 127 | # value is allowed = as long as there is no comma, and commas till the last one before an equals. | ||||||||||||||||||||||||||||
| 128 | # It then uses a look-ahead match to make sure that the next thing after the value | ||||||||||||||||||||||||||||
| 129 | # is a ", key=" sequence or the end of the string (?:$|,\s*(?=[^,]*?=)) | ||||||||||||||||||||||||||||
| 130 | # It does this by matching either the end of the string or comma then a set of | ||||||||||||||||||||||||||||
| 131 | # characters not including comma or equals which are then followed by an equals. | ||||||||||||||||||||||||||||
| 132 | # All the ?: are to avoid capturing unwanted segments. We capture key in $1 and | ||||||||||||||||||||||||||||
| 133 | # value in $2, and then use the uncaptured right side ($') to start the process | ||||||||||||||||||||||||||||
| 134 | # for the next key/value pair. | ||||||||||||||||||||||||||||
| 135 | 12 | $subject =~m/^(?:(?:(?:([^,=]*)=([^,]*[^=]*?))|) (?:$|,\s*(?=[^,]*?=)))/x; | |||||||||||||||||||||||||||
| 136 | 12 | ▶ | my $remainder = $' // ''; # $' is the uncaptured part of the source to the right of the match | ||||||||||||||||||||||||||
|
Condition100%2/2
$' // ""
MC/DC100%1/1
$' // ""
$'
Truth table100%2/2
A
A= $'
| |||||||||||||||||||||||||||||
| 137 | 12 | ▶ | last unless length($remainder) < length($subject); # if the remainder isn't getting shorter then bail | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 138 | 12 | $subject = $remainder; | |||||||||||||||||||||||||||
| 139 | 12 | my $key = $1; | |||||||||||||||||||||||||||
| 140 | 12 | my $value = $2; | |||||||||||||||||||||||||||
| 141 | 12 | ▶ | next unless $key; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 142 | 9 | ▶ | next unless $value; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 143 | 9 | ▶ | $result{$key} = [] unless exists $result{$key}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 144 | 9 | push $result{$key}->@*, $value; | |||||||||||||||||||||||||||
| 145 | }; | ||||||||||||||||||||||||||||
| 146 | 7 | return \%result; | |||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||
| 150 | 0 | ▶ | sub mark_type($self) { | ||||||||||||||||||||||||||
|
Subroutine
mark_type: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||
| 151 | 0 | ▶ | return unless $self->vmc_object; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||
| 153 | # Parse the subject:markType from the subject string | ||||||||||||||||||||||||||||
| 154 | # Ideally we could parse the structure, from this | ||||||||||||||||||||||||||||
| 155 | # my $subject_entries = $self->vmc_object->x509_object->subject_name->entries; | ||||||||||||||||||||||||||||
| 156 | # however the X509 object does not make this easy for a type that is not | ||||||||||||||||||||||||||||
| 157 | # compiled in, returning undef for an entry type it does not understand. | ||||||||||||||||||||||||||||
| 158 | # So we parse the string instead. | ||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||
| 160 | 0 | my $subject = $self->subject; | |||||||||||||||||||||||||||
| 161 | 0 | ▶ | return unless $subject; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||
| 163 | 0 | my $subject_entries = $self->subject_entries($subject); | |||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||
| 165 | 0 | my $subject_mark_type_oid = SUBJECT_MARK_TYPE_OID; # can't use a constant as a hash key | |||||||||||||||||||||||||||
| 166 | 0 | ▶ | if (exists $subject_entries->{$subject_mark_type_oid}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 167 | 0 | return $subject_entries->{$subject_mark_type_oid}->[0]; | |||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||
| 169 | 0 | ▶ | if (exists $subject_entries->{'markType'}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 170 | 0 | return $subject_entries->{'markType'}->[0]; | |||||||||||||||||||||||||||
| 171 | } | ||||||||||||||||||||||||||||
| 172 | 0 | return; | |||||||||||||||||||||||||||
| 173 | } | ||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||
| 176 | 0 | ▶ | sub not_before($self) { | ||||||||||||||||||||||||||
|
Subroutine
not_before: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 177 | 0 | ▶ | return if !$self->vmc_object; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 178 | 0 | return $self->vmc_object->x509_object->notBefore; | |||||||||||||||||||||||||||
| 179 | } | ||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||
| 182 | 0 | ▶ | sub not_after($self) { | ||||||||||||||||||||||||||
|
Subroutine
not_after: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 183 | 0 | ▶ | return if !$self->vmc_object; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 184 | 0 | return $self->vmc_object->x509_object->notAfter; | |||||||||||||||||||||||||||
| 185 | } | ||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||
| 188 | 0 | ▶ | sub issuer($self) { | ||||||||||||||||||||||||||
|
Subroutine
issuer: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 189 | 0 | ▶ | return if !$self->vmc_object; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 190 | 0 | return $self->vmc_object->x509_object->issuer; | |||||||||||||||||||||||||||
| 191 | } | ||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||
| 194 | 0 | ▶ | sub is_expired($self) { | ||||||||||||||||||||||||||
|
Subroutine
is_expired: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 195 | 0 | ▶ | return if !$self->vmc_object; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 196 | 0 | my $seconds = 0; | |||||||||||||||||||||||||||
| 197 | 0 | ▶ | if ($self->vmc_object->x509_object->checkend($seconds)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 198 | 0 | $self->log_verbose('Cert is expired'); | |||||||||||||||||||||||||||
| 199 | 0 | return 1; | |||||||||||||||||||||||||||
| 200 | } | ||||||||||||||||||||||||||||
| 201 | else { | ||||||||||||||||||||||||||||
| 202 | 0 | return 0; | |||||||||||||||||||||||||||
| 203 | } | ||||||||||||||||||||||||||||
| 204 | } | ||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||
| 207 | 0 | ▶ | sub alt_name($self) { | ||||||||||||||||||||||||||
|
Subroutine
alt_name: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||
| 208 | 0 | ▶ | return if !$self->vmc_object; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 209 | 0 | my $exts = eval{ $self->vmc_object->x509_object->extensions_by_oid() }; | |||||||||||||||||||||||||||
| 210 | 0 | ▶ | return if !$exts; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 211 | 0 | ▶ | return if !exists $exts->{'2.5.29.17'}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 212 | 0 | my $alt_name = $exts->{'2.5.29.17'}->to_string; | |||||||||||||||||||||||||||
| 213 | 0 | $self->log_verbose('Cert alt name '.$alt_name); | |||||||||||||||||||||||||||
| 214 | 0 | return $alt_name; | |||||||||||||||||||||||||||
| 215 | } | ||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||
| 218 | 0 | ▶ | sub is_valid_alt_name($self) { | ||||||||||||||||||||||||||
|
Subroutine
is_valid_alt_name: not called CC=10 SCAR=47.0
Pod
documented
| |||||||||||||||||||||||||||||
| 219 | 0 | ▶ | return 1 if !$self->check_domain; # Nothing to check against, default to allow | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 220 | 0 | ▶ | return 1 if $self->bimi_object->options->vmc_no_check_alt; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 221 | 0 | ▶ | return 0 if !$self->alt_name; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 222 | 0 | my @alt_names = split( ',', lc $self->alt_name ); | |||||||||||||||||||||||||||
| 223 | 0 | my $check_full_record = lc join('.', $self->check_selector, '_bimi', $self->check_domain ); | |||||||||||||||||||||||||||
| 224 | 0 | my $check_domain = lc $self->check_domain; | |||||||||||||||||||||||||||
| 225 | 0 | foreach my $alt_name ( @alt_names ) { | |||||||||||||||||||||||||||
| 226 | 0 | $alt_name =~ s/^\s+//; | |||||||||||||||||||||||||||
| 227 | 0 | $alt_name =~ s/\s+$//; | |||||||||||||||||||||||||||
| 228 | 0 | ▶ | next unless $alt_name =~ /^dns:/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 229 | 0 | $alt_name =~ s/^dns://; | |||||||||||||||||||||||||||
| 230 | 0 | ▶ | return 1 if $alt_name eq $check_domain; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 231 | 0 | ▶ | return 1 if $alt_name eq $check_full_record; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 232 | 0 | ▶ | next if !$self->bimi_object->options->cert_subdomain_is_valid; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 233 | 0 | my $alt_name_re = quotemeta($alt_name); | |||||||||||||||||||||||||||
| 234 | 0 | ▶ | return 1 if $check_domain =~ /\.$alt_name_re$/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 235 | } | ||||||||||||||||||||||||||||
| 236 | 0 | return 0; | |||||||||||||||||||||||||||
| 237 | } | ||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||
| 240 | 0 | ▶ | sub is_self_signed($self) { | ||||||||||||||||||||||||||
|
Subroutine
is_self_signed: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 241 | 0 | ▶ | return if !$self->vmc_object; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 242 | 0 | ▶ | return $self->vmc_object->x509_object->is_selfsigned ? 1 : 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 243 | } | ||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||
| 246 | 0 | ▶ | sub has_valid_usage($self) { | ||||||||||||||||||||||||||
|
Subroutine
has_valid_usage: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 247 | 0 | ▶ | return if !$self->vmc_object; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 248 | 0 | return $self->vmc_object->has_valid_usage; | |||||||||||||||||||||||||||
| 249 | } | ||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||
| 252 | 0 | ▶ | sub is_experimental($self) { | ||||||||||||||||||||||||||
|
Subroutine
is_experimental: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 253 | 0 | ▶ | return if !$self->vmc_object; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 254 | 0 | return $self->vmc_object->is_experimental; | |||||||||||||||||||||||||||
| 255 | } | ||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||
| 258 | 0 | ▶ | sub is_allowed_mark_type($self) { | ||||||||||||||||||||||||||
|
Subroutine
is_allowed_mark_type: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||
| 259 | 0 | ▶ | my $mark_type = lc ($self->mark_type // ''); | ||||||||||||||||||||||||||
|
Condition0%0/2
$self->mark_type // ""
MC/DC0%0/1
$self->mark_type // ""
$self->mark_type
Truth table0%0/2
A
A= $self->mark_type
| |||||||||||||||||||||||||||||
| 260 | 0 | my $allowed_mark_types = lc $self->bimi_object->options->allowed_mark_types; | |||||||||||||||||||||||||||
| 261 | 0 | for my $allowed_mark_type (split /, ?/, $allowed_mark_types) { | |||||||||||||||||||||||||||
| 262 | 0 | ▶ | return 1 if $allowed_mark_type eq '*'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 263 | 0 | ▶ | return 1 if $allowed_mark_type eq $mark_type; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 264 | } | ||||||||||||||||||||||||||||
| 265 | 0 | return 0; | |||||||||||||||||||||||||||
| 266 | } | ||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||
| 268 | 0 | ▶ | sub _build_indicator_uri($self) { | ||||||||||||||||||||||||||
|
Subroutine
_build_indicator_uri: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||
| 269 | 0 | ▶ | return if !$self->vmc_object; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 270 | 0 | ▶ | return if !$self->vmc_object->indicator_asn; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 271 | 0 | my $uri; | |||||||||||||||||||||||||||
| 272 | eval{ | ||||||||||||||||||||||||||||
| 273 | 0 | $uri = $self->vmc_object->indicator_asn->{subjectLogo}->{direct}->{image}->[0]->{imageDetails}->{logotypeURI}->[0]; | |||||||||||||||||||||||||||
| 274 | 0 | 1; | |||||||||||||||||||||||||||
| 275 | 0 | ▶ | } || do { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 276 | 0 | my $error = $@; | |||||||||||||||||||||||||||
| 277 | 0 | $self->add_error('VMC_PARSE_ERROR','Could not extract SVG from VMC'); | |||||||||||||||||||||||||||
| 278 | }; | ||||||||||||||||||||||||||||
| 279 | 0 | return $uri; | |||||||||||||||||||||||||||
| 280 | } | ||||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||
| 282 | 0 | ▶ | sub _build_indicator($self) { | ||||||||||||||||||||||||||
|
Subroutine
_build_indicator: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||
| 283 | # return if ! $self->_is_valid; | ||||||||||||||||||||||||||||
| 284 | 0 | ▶ | return if !$self->is_cert_valid; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 285 | 0 | my $uri = $self->indicator_uri; | |||||||||||||||||||||||||||
| 286 | 0 | ▶ | return if !$uri; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 287 | ## TODO MAKE THIS BETTER | ||||||||||||||||||||||||||||
| 288 | 0 | ▶ | if ( $uri =~ /^data:image\/svg\+xml;base64,/ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 289 | 0 | my ( $null, $base64 ) = split( ',', $uri ); | |||||||||||||||||||||||||||
| 290 | 0 | my $data = MIME::Base64::decode($base64); | |||||||||||||||||||||||||||
| 291 | 0 | return Mail::BIMI::Indicator->new( uri => $self->uri, data => $data, bimi_object => $self->bimi_object, source => 'VMC' ); | |||||||||||||||||||||||||||
| 292 | } | ||||||||||||||||||||||||||||
| 293 | else { | ||||||||||||||||||||||||||||
| 294 | 0 | $self->add_error('VMC_PARSE_ERROR','Could not extract SVG from VMC'); | |||||||||||||||||||||||||||
| 295 | 0 | return; | |||||||||||||||||||||||||||
| 296 | } | ||||||||||||||||||||||||||||
| 297 | } | ||||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||
| 300 | 0 | ▶ | sub _build_is_valid($self) { | ||||||||||||||||||||||||||
|
Subroutine
_build_is_valid: not called CC=14 SCAR=53.5
| |||||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||
| 302 | 0 | ▶ | if ($self->data eq '' && $self->errors->@*) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->data eq "" and @{$self->errors}
MC/DC0%0/2
$self->data eq "" and @{$self->errors}
$self->data eq ""
@{$self->errors}
Truth table0%0/3
A and B
A= $self->data eq ""B= @{$self->errors}
| |||||||||||||||||||||||||||||
| 303 | # We already have a fetch error, do not validate further | ||||||||||||||||||||||||||||
| 304 | 0 | return 0; | |||||||||||||||||||||||||||
| 305 | } | ||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||
| 307 | 0 | ▶ | $self->add_error('VMC_EXPIRED','Expired') if $self->is_expired; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 308 | 0 | ▶ | $self->add_error('VMC_VALIDATION_ERROR','Missing usage flag') if !$self->has_valid_usage; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 309 | 0 | ▶ | $self->add_error('VMC_VALIDATION_ERROR','Invalid alt name') if !$self->is_valid_alt_name; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 310 | 0 | ▶ | $self->add_error('VMC_DISALLOWED_TYPE', 'VMC Mark Type not supported here' ) if !$self->is_allowed_mark_type; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 311 | 0 | $self->is_cert_valid; | |||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||
| 313 | 0 | ▶ | if ( $self->chain_object && !$self->chain_object->is_valid ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->chain_object and not $self->chain_object->is_valid
MC/DC0%0/2
$self->chain_object and not $self->chain_object->is_valid
$self->chain_object
not $self->chain_object->is_valid
Truth table0%0/3
A and not(B)
A= $self->chain_objectB= not $self->chain_object->is_valid
| |||||||||||||||||||||||||||||
| 314 | 0 | $self->add_error_object( $self->chain_object->errors ); | |||||||||||||||||||||||||||
| 315 | } | ||||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||
| 317 | 0 | ▶ | if ( $self->indicator && !$self->indicator->is_valid ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->indicator and not $self->indicator->is_valid
MC/DC0%0/2
$self->indicator and not $self->indicator->is_valid
$self->indicator
not $self->indicator->is_valid
Truth table0%0/3
A and not(B)
A= $self->indicatorB= not $self->indicator->is_valid
| |||||||||||||||||||||||||||||
| 318 | 0 | $self->add_error_object( $self->indicator->errors ); | |||||||||||||||||||||||||||
| 319 | } | ||||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||
| 321 | 0 | ▶ | if ( $self->bimi_object->options->no_experimental_vmc && $self->is_experimental ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->bimi_object->options->no_experimental_vmc and $self->is_experimental
MC/DC0%0/2
$self->bimi_object->options->no_experimental_vmc and $self->is_experimental
$self->bimi_object->options->no_experimental_vmc
$self->is_experimental
Truth table0%0/3
A and B
A= $self->bimi_object->options->no_experimental_vmcB= $self->is_experimental
| |||||||||||||||||||||||||||||
| 322 | 0 | $self->add_error('VMC_NO_EXPERIMENTAL','Experimental (V)MCs are not accepted here'); | |||||||||||||||||||||||||||
| 323 | } | ||||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||
| 325 | 0 | ▶ | return 0 if $self->errors->@*; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 326 | 0 | $self->log_verbose('VMC is valid'); | |||||||||||||||||||||||||||
| 327 | 0 | return 1; | |||||||||||||||||||||||||||
| 328 | } | ||||||||||||||||||||||||||||
| 329 | |||||||||||||||||||||||||||||
| 330 | |||||||||||||||||||||||||||||
| 331 | 0 | ▶ | sub finish($self) { | ||||||||||||||||||||||||||
|
Subroutine
finish: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 332 | 0 | ▶ | $self->indicator->finish if $self->indicator; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 333 | 0 | $self->_write_cache; | |||||||||||||||||||||||||||
| 334 | } | ||||||||||||||||||||||||||||
| 335 | |||||||||||||||||||||||||||||
| 336 | |||||||||||||||||||||||||||||
| 337 | 0 | ▶ | sub app_validate($self) { | ||||||||||||||||||||||||||
|
Subroutine
app_validate: not called CC=19 SCAR=59.4
Pod
documented
| |||||||||||||||||||||||||||||
| 338 | 0 | ▶ | say 'VMC Returned: '.($self->is_valid ? GREEN."\x{2713}" : BRIGHT_RED."\x{26A0}").RESET; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 339 | 0 | ▶ | say YELLOW.' Subject '.WHITE.': '.CYAN.($self->subject//'-none-').RESET; | ||||||||||||||||||||||||||
|
Condition0%0/2
$self->subject // "-none-"
MC/DC0%0/1
$self->subject // "-none-"
$self->subject
Truth table0%0/2
A
A= $self->subject
| |||||||||||||||||||||||||||||
| 340 | 0 | ▶ | say YELLOW.' Mark Type '.WHITE.': '.CYAN.($self->mark_type//'-none-').RESET; | ||||||||||||||||||||||||||
|
Condition0%0/2
$self->mark_type // "-none-"
MC/DC0%0/1
$self->mark_type // "-none-"
$self->mark_type
Truth table0%0/2
A
A= $self->mark_type
| |||||||||||||||||||||||||||||
| 341 | 0 | ▶ | say YELLOW.' Is Allowed Type '.WHITE.': '.CYAN.($self->is_allowed_mark_type?GREEN.'Yes':BRIGHT_RED.'No').RESET; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 342 | 0 | ▶ | say YELLOW.' Not Before '.WHITE.': '.CYAN.($self->not_before//'-none-').RESET; | ||||||||||||||||||||||||||
|
Condition0%0/2
$self->not_before // "-none-"
MC/DC0%0/1
$self->not_before // "-none-"
$self->not_before
Truth table0%0/2
A
A= $self->not_before
| |||||||||||||||||||||||||||||
| 343 | 0 | ▶ | say YELLOW.' Not After '.WHITE.': '.CYAN.($self->not_after//'-none-').RESET; | ||||||||||||||||||||||||||
|
Condition0%0/2
$self->not_after // "-none-"
MC/DC0%0/1
$self->not_after // "-none-"
$self->not_after
Truth table0%0/2
A
A= $self->not_after
| |||||||||||||||||||||||||||||
| 344 | 0 | ▶ | say YELLOW.' Issuer '.WHITE.': '.CYAN.($self->issuer//'-none-').RESET; | ||||||||||||||||||||||||||
|
Condition0%0/2
$self->issuer // "-none-"
MC/DC0%0/1
$self->issuer // "-none-"
$self->issuer
Truth table0%0/2
A
A= $self->issuer
| |||||||||||||||||||||||||||||
| 345 | 0 | ▶ | say YELLOW.' Expired '.WHITE.': '.($self->is_expired?BRIGHT_RED.'Yes':GREEN.'No').RESET; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 346 | 0 | ▶ | say YELLOW.' Alt Name '.WHITE.': '.CYAN.($self->alt_name//'-none-').RESET; | ||||||||||||||||||||||||||
|
Condition0%0/2
$self->alt_name // "-none-"
MC/DC0%0/1
$self->alt_name // "-none-"
$self->alt_name
Truth table0%0/2
A
A= $self->alt_name
| |||||||||||||||||||||||||||||
| 347 | 0 | ▶ | say YELLOW.' Alt Name Valid '.WHITE.': '.CYAN.($self->is_valid_alt_name?GREEN.'Yes':BRIGHT_RED.'No').RESET; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 348 | 0 | ▶ | say YELLOW.' Has Valid Usage '.WHITE.': '.CYAN.($self->has_valid_usage?GREEN.'Yes':BRIGHT_RED.'No').RESET; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 349 | 0 | ▶ | say YELLOW.' Cert Valid '.WHITE.': '.CYAN.($self->is_cert_valid?GREEN.'Yes':BRIGHT_RED.'No').RESET; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 350 | 0 | ▶ | say YELLOW.' Is Valid '.WHITE.': '.CYAN.($self->is_valid?GREEN.'Yes':BRIGHT_RED.'No').RESET; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 351 | 0 | ▶ | if ( ! $self->is_valid ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 352 | 0 | say "Errors:"; | |||||||||||||||||||||||||||
| 353 | 0 | foreach my $error ( $self->errors->@* ) { | |||||||||||||||||||||||||||
| 354 | 0 | my $error_code = $error->code; | |||||||||||||||||||||||||||
| 355 | 0 | my $error_text = $error->description; | |||||||||||||||||||||||||||
| 356 | 0 | ▶ | my $error_detail = $error->detail // ''; | ||||||||||||||||||||||||||
|
Condition0%0/2
$error->detail // ""
MC/DC0%0/1
$error->detail // ""
$error->detail
Truth table0%0/2
A
A= $error->detail
| |||||||||||||||||||||||||||||
| 357 | 0 | $error_detail =~ s/\n/\n /g; | |||||||||||||||||||||||||||
| 358 | 0 | ▶ | say BRIGHT_RED." $error_code ".WHITE.': '.CYAN.$error_text.($error_detail?"\n ".$error_detail:'').RESET; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 359 | } | ||||||||||||||||||||||||||||
| 360 | } | ||||||||||||||||||||||||||||
| 361 | 0 | ▶ | if ($self->chain_object){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 362 | 0 | say ''; | |||||||||||||||||||||||||||
| 363 | 0 | $self->chain_object->app_validate; | |||||||||||||||||||||||||||
| 364 | } | ||||||||||||||||||||||||||||
| 365 | } | ||||||||||||||||||||||||||||
| 366 | |||||||||||||||||||||||||||||
| 367 | 29 | 1; | |||||||||||||||||||||||||||
| 368 | |||||||||||||||||||||||||||||
| 369 | __END__ | ||||||||||||||||||||||||||||