| 1 | package App::WebPerimeterScan::TLS; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 28 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 28 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 28 | ▶ | use autodie qw(:all); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | # A failed TLS close is not worth an exception: the inspection is done. | ||||||||||||||||||||||||||||||||||||||||||
| 8 | 28 | ▶ | no autodie qw(close); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | 28 | ▶ | use IO::Socket::SSL; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | 28 | ▶ | use Net::SSLeay (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | 28 | ▶ | use Params::Get qw(get_params); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | 28 | ▶ | use Params::Validate::Strict qw(validate_strict); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | 28 | ▶ | use Readonly; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | 28 | ▶ | use Sub::Private { mode => 'enforce' }; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 16 | 28 | ▶ | use Time::HiRes qw(time); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 17 | 28 | ▶ | use Time::Local qw(timegm); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||
| 19 | 28 | ▶ | use App::WebPerimeterScan::I18N (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 20 | 28 | ▶ | use parent -norequire, 'App::WebPerimeterScan::I18N'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||
| 22 | 28 | our $VERSION = '0.001.0'; | |||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||
| 24 | # Defaults for inspect(); a plain hash so Object::Configure or a caller can | ||||||||||||||||||||||||||||||||||||||||||
| 25 | # change them. | ||||||||||||||||||||||||||||||||||||||||||
| 26 | 28 | our %config = ( | |||||||||||||||||||||||||||||||||||||||||
| 27 | port => 443, | ||||||||||||||||||||||||||||||||||||||||||
| 28 | timeout => 10, | ||||||||||||||||||||||||||||||||||||||||||
| 29 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||
| 31 | # Which protocol versions the server will still negotiate. Anything below | ||||||||||||||||||||||||||||||||||||||||||
| 32 | # TLS 1.2 is deprecated by RFC 8996. | ||||||||||||||||||||||||||||||||||||||||||
| 33 | 28 | Readonly::Array my @PROBE_VERSIONS => qw(TLSv1 TLSv1_1 TLSv1_2 TLSv1_3); | |||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||
| 35 | # OpenSSL 3 refuses to offer TLS 1.0 or 1.1 at its default security level, | ||||||||||||||||||||||||||||||||||||||||||
| 36 | # so a probe for them fails locally before a byte reaches the server and an | ||||||||||||||||||||||||||||||||||||||||||
| 37 | # old protocol is never detected. Level 0 lets the client offer them; it | ||||||||||||||||||||||||||||||||||||||||||
| 38 | # only applies to these probes, never to the request that reads the site. | ||||||||||||||||||||||||||||||||||||||||||
| 39 | 28 | Readonly::Hash my %PROBE_CIPHERS => ( | |||||||||||||||||||||||||||||||||||||||||
| 40 | TLSv1 => 'DEFAULT:@SECLEVEL=0', | ||||||||||||||||||||||||||||||||||||||||||
| 41 | TLSv1_1 => 'DEFAULT:@SECLEVEL=0', | ||||||||||||||||||||||||||||||||||||||||||
| 42 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||
| 44 | # The certificate name fields shown in reports, most specific first. | ||||||||||||||||||||||||||||||||||||||||||
| 45 | 28 | Readonly::Array my @NAME_FIELDS => qw(commonName organizationName organizationalUnitName countryName); | |||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||
| 47 | 28 | Readonly::Scalar my $SECONDS_PER_DAY => 86_400; | |||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||
| 49 | 28 | Readonly::Hash my %MONTH => ( | |||||||||||||||||||||||||||||||||||||||||
| 50 | Jan => 0, Feb => 1, Mar => 2, Apr => 3, May => 4, Jun => 5, | ||||||||||||||||||||||||||||||||||||||||||
| 51 | Jul => 6, Aug => 7, Sep => 8, Oct => 9, Nov => 10, Dec => 11, | ||||||||||||||||||||||||||||||||||||||||||
| 52 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||
| 54 | # "Jun 1 12:00:00 2027 GMT" and "2026-12-25T22:56:35Z". ASN.1 times are | ||||||||||||||||||||||||||||||||||||||||||
| 55 | # always UTC. | ||||||||||||||||||||||||||||||||||||||||||
| 56 | 28 | Readonly::Scalar my $ASN1_TEXT => qr/\A\s*([A-Z][a-z]{2})\s+(\d{1,2})\s+(\d{2}):(\d{2}):(\d{2})\s+(\d{4})/; | |||||||||||||||||||||||||||||||||||||||||
| 57 | 28 | Readonly::Scalar my $ASN1_ISO => qr/\A\s*(\d{4})-(\d{2})-(\d{2})[T ](\d{2}):(\d{2}):(\d{2})/; | |||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||
| 59 | =encoding utf8 | ||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||
| 61 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||
| 63 | App::WebPerimeterScan::TLS - certificate and protocol inspection | ||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||
| 65 | =head1 VERSION | ||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||
| 67 | Version 0.001.0 | ||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||
| 69 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||
| 71 | Check when the certificate expires: | ||||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||
| 73 | use App::WebPerimeterScan::TLS; | ||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||
| 75 | my $tls = App::WebPerimeterScan::TLS->inspect(host => 'example.com'); | ||||||||||||||||||||||||||||||||||||||||||
| 76 | if($tls->{ok} && defined $tls->{days_left}) { | ||||||||||||||||||||||||||||||||||||||||||
| 77 | printf "expires in %d days\n", $tls->{days_left}; | ||||||||||||||||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||
| 80 | Check that a browser would trust the certificate: | ||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||
| 82 | if(!$tls->{ok}) { | ||||||||||||||||||||||||||||||||||||||||||
| 83 | print "no TLS handshake: $tls->{error}\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 84 | } elsif(defined $tls->{verify_error}) { | ||||||||||||||||||||||||||||||||||||||||||
| 85 | print "not trusted: $tls->{verify_error}\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 86 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 87 | print "trusted; $tls->{protocol} with $tls->{cipher}\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||
| 90 | Find old protocol versions that the server still accepts, on a port that | ||||||||||||||||||||||||||||||||||||||||||
| 91 | is not 443: | ||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||
| 93 | my $mail = App::WebPerimeterScan::TLS->inspect(host => 'mail.example.com', port => 993); | ||||||||||||||||||||||||||||||||||||||||||
| 94 | my @old = grep { $_ eq 'TLSv1' || $_ eq 'TLSv1_1' } @{ $mail->{protocols} }; | ||||||||||||||||||||||||||||||||||||||||||
| 95 | print "old protocols: @old\n" if @old; | ||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||
| 97 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||
| 99 | This module connects to a TLS service (for example HTTPS on port 443) and | ||||||||||||||||||||||||||||||||||||||||||
| 100 | describes it. It answers four questions: | ||||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||
| 102 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||
| 104 | =item 1. Which certificate does the server send? The subject, issuer, | ||||||||||||||||||||||||||||||||||||||||||
| 105 | fingerprint and expiry date are read, without checking if the certificate | ||||||||||||||||||||||||||||||||||||||||||
| 106 | is trusted. | ||||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||
| 108 | =item 2. Would a browser trust it? A second handshake checks the | ||||||||||||||||||||||||||||||||||||||||||
| 109 | certificate chain and the host name. Any problem is put in | ||||||||||||||||||||||||||||||||||||||||||
| 110 | C<verify_error>. | ||||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||
| 112 | =item 3. Which protocol and cipher does the server choose by default? | ||||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||
| 114 | =item 4. Which protocol versions does the server accept? One handshake is | ||||||||||||||||||||||||||||||||||||||||||
| 115 | tried for each of TLS 1.0, 1.1, 1.2 and 1.3. The names in C<protocols> | ||||||||||||||||||||||||||||||||||||||||||
| 116 | are C<TLSv1>, C<TLSv1_1>, C<TLSv1_2> and C<TLSv1_3>. | ||||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||||
| 118 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||||||
| 120 | That is up to six handshakes for each call. The host name is sent in | ||||||||||||||||||||||||||||||||||||||||||
| 121 | every handshake (as SNI), so a server that hosts many sites sends the | ||||||||||||||||||||||||||||||||||||||||||
| 122 | certificate for this one. | ||||||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||||||
| 124 | =head1 REQUIREMENTS | ||||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||
| 126 | C<IO::Socket::SSL> 2.000 and C<Net::SSLeay> 1.92, the first release with | ||||||||||||||||||||||||||||||||||||||||||
| 127 | OpenSSL 3 support. The expiry date is read through Net::SSLeay when | ||||||||||||||||||||||||||||||||||||||||||
| 128 | IO::Socket::SSL does not offer it, so the build must provide | ||||||||||||||||||||||||||||||||||||||||||
| 129 | C<X509_get_notAfter> and C<P_ASN1_TIME_put2string>. | ||||||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||||||
| 131 | =head1 SUBROUTINES/METHODS | ||||||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||||||
| 133 | =head2 inspect | ||||||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||||
| 135 | Purpose: describe the TLS service on a host and port. | ||||||||||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||||||||
| 137 | Args: named C<host> (required), C<port> (default 443) and C<timeout> | ||||||||||||||||||||||||||||||||||||||||||
| 138 | (seconds per handshake, default 10). A class method. | ||||||||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||||||||
| 140 | Returns: a hash reference. Always: C<host>, C<port>, C<protocols> (array | ||||||||||||||||||||||||||||||||||||||||||
| 141 | reference of the versions a version-pinned handshake completed with; this is | ||||||||||||||||||||||||||||||||||||||||||
| 142 | filled in even when the default handshake fails). When the default | ||||||||||||||||||||||||||||||||||||||||||
| 143 | handshake fails: C<error>. Otherwise C<ok> (1), C<protocol>, C<cipher>, C<self_signed>, | ||||||||||||||||||||||||||||||||||||||||||
| 144 | C<subject>, C<issuer>, C<fingerprint>, C<verify_error> (C<undef> when the | ||||||||||||||||||||||||||||||||||||||||||
| 145 | chain verifies) and, when the expiry could be read, C<not_after>, | ||||||||||||||||||||||||||||||||||||||||||
| 146 | C<expires_at> (epoch) and C<days_left> (negative once expired). | ||||||||||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||||||||||
| 148 | Side Effects: up to six TLS handshakes with the host (five when the | ||||||||||||||||||||||||||||||||||||||||||
| 149 | default handshake fails, as verification is then skipped). | ||||||||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||||||||
| 151 | Usage: C<< my $tls = App::WebPerimeterScan::TLS->inspect(host => $host); >> | ||||||||||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||||||||||
| 153 | =head3 EXAMPLE | ||||||||||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||||||||||
| 155 | my $tls = App::WebPerimeterScan::TLS->inspect(host => 'example.com', timeout => 5); | ||||||||||||||||||||||||||||||||||||||||||
| 156 | if(!$tls->{ok}) { | ||||||||||||||||||||||||||||||||||||||||||
| 157 | print "no TLS: $tls->{error}\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 158 | } elsif($tls->{verify_error}) { | ||||||||||||||||||||||||||||||||||||||||||
| 159 | print "untrusted: $tls->{verify_error}\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 160 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 161 | print "accepts: @{ $tls->{protocols} }\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||||||||
| 164 | =head3 API SPECIFICATION | ||||||||||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||||||||||
| 166 | =head4 INPUT | ||||||||||||||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||||||||||||||
| 168 | { | ||||||||||||||||||||||||||||||||||||||||||
| 169 | host => { type => 'string', min => 1 }, | ||||||||||||||||||||||||||||||||||||||||||
| 170 | port => { type => 'integer', min => 1, max => 65535, optional => 1 }, | ||||||||||||||||||||||||||||||||||||||||||
| 171 | timeout => { type => 'number', min => 0, optional => 1 }, | ||||||||||||||||||||||||||||||||||||||||||
| 172 | } | ||||||||||||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||||||||||
| 174 | =head4 OUTPUT | ||||||||||||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||||||||||||
| 176 | { | ||||||||||||||||||||||||||||||||||||||||||
| 177 | type => 'hashref', | ||||||||||||||||||||||||||||||||||||||||||
| 178 | schema => { | ||||||||||||||||||||||||||||||||||||||||||
| 179 | host => { type => 'string' }, | ||||||||||||||||||||||||||||||||||||||||||
| 180 | port => { type => 'integer' }, | ||||||||||||||||||||||||||||||||||||||||||
| 181 | protocols => { type => 'arrayref' }, | ||||||||||||||||||||||||||||||||||||||||||
| 182 | ok => { type => 'boolean', optional => 1 }, | ||||||||||||||||||||||||||||||||||||||||||
| 183 | error => { type => 'string', optional => 1 }, | ||||||||||||||||||||||||||||||||||||||||||
| 184 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 185 | } | ||||||||||||||||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||||||||||||||||
| 187 | =head3 MESSAGES | ||||||||||||||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||||||||||||
| 189 | Returned in C<error> or C<verify_error>, not thrown: | ||||||||||||||||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||||||||||||||||
| 191 | Message Meaning / resolution | ||||||||||||||||||||||||||||||||||||||||||
| 192 | --------------------------------- ---------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 193 | (OpenSSL or socket text) The handshake failed; the text is | ||||||||||||||||||||||||||||||||||||||||||
| 194 | IO::Socket::SSL's reason. | ||||||||||||||||||||||||||||||||||||||||||
| 195 | certificate verification failed Verification failed and OpenSSL | ||||||||||||||||||||||||||||||||||||||||||
| 196 | gave no more specific reason. | ||||||||||||||||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||||||||||||||||
| 198 | =head3 PSEUDOCODE | ||||||||||||||||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||||||||||||||||
| 200 | handshake without verification | ||||||||||||||||||||||||||||||||||||||||||
| 201 | if it worked | ||||||||||||||||||||||||||||||||||||||||||
| 202 | record protocol, cipher, subject, issuer, fingerprint, self-signed | ||||||||||||||||||||||||||||||||||||||||||
| 203 | read the expiry, from IO::Socket::SSL or else Net::SSLeay | ||||||||||||||||||||||||||||||||||||||||||
| 204 | handshake again with verification; record any error | ||||||||||||||||||||||||||||||||||||||||||
| 205 | otherwise record the error | ||||||||||||||||||||||||||||||||||||||||||
| 206 | handshake once per protocol version; record those that succeed | ||||||||||||||||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||||||||||||||||
| 208 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||||||||||||
| 210 | sub inspect | ||||||||||||||||||||||||||||||||||||||||||
| 211 | 3 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
inspect: called CC=8 SCAR=23.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 212 | 3 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||||||||||||||||
| 214 | 3 | ▶ | my $args = validate_strict( | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
get_params(undef, \@_) // {}
MC/DC0%0/1
get_params(undef, \@_) // {}
get_params(undef, \@_)
Truth table50%1/2
A
A= get_params(undef, \@_)
| |||||||||||||||||||||||||||||||||||||||||||
| 215 | schema => { | ||||||||||||||||||||||||||||||||||||||||||
| 216 | host => { type => 'string', min => 1 }, | ||||||||||||||||||||||||||||||||||||||||||
| 217 | port => { type => 'integer', min => 1, max => 65_535, optional => 1 }, | ||||||||||||||||||||||||||||||||||||||||||
| 218 | timeout => { type => 'number', min => 0, optional => 1 }, | ||||||||||||||||||||||||||||||||||||||||||
| 219 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 220 | input => get_params(undef, \@_) // {}, | ||||||||||||||||||||||||||||||||||||||||||
| 221 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||||||||||||||||
| 223 | 1 | my $host = $args->{host}; | |||||||||||||||||||||||||||||||||||||||||
| 224 | 1 | ▶ | my $port = $args->{port} || $config{port}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$args->{'port'} || $App::WebPerimeterScan::TLS::config{'port'}
MC/DC0%0/2
$args->{'port'} || $App::WebPerimeterScan::TLS::config{'port'}
$args->{'port'}
$App::WebPerimeterScan::TLS::config{'port'}
Truth table33%1/3
A || B
A= $args->{'port'}B= $App::WebPerimeterScan::TLS::config{'port'}
| |||||||||||||||||||||||||||||||||||||||||||
| 225 | 1 | ▶ | my $timeout = $args->{timeout} || $config{timeout}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$args->{'timeout'} || $App::WebPerimeterScan::TLS::config{'timeout'}
MC/DC0%0/2
$args->{'timeout'} || $App::WebPerimeterScan::TLS::config{'timeout'}
$args->{'timeout'}
$App::WebPerimeterScan::TLS::config{'timeout'}
Truth table33%1/3
A || B
A= $args->{'timeout'}B= $App::WebPerimeterScan::TLS::config{'timeout'}
| |||||||||||||||||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||||||||||||||||
| 227 | 1 | my $result = { host => $host, port => $port, protocols => [] }; | |||||||||||||||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||||||||||||||||
| 229 | 1 | my $sock = _connect($host, $port, $timeout); | |||||||||||||||||||||||||||||||||||||||||
| 230 | 1 | ▶ | if($sock) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 231 | 0 | _describe($sock, $result); | |||||||||||||||||||||||||||||||||||||||||
| 232 | 0 | close $sock; | |||||||||||||||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||||||||||||||||
| 234 | # Verification is a separate handshake: the inspection socket | ||||||||||||||||||||||||||||||||||||||||||
| 235 | # above deliberately does not verify, so a broken chain cannot | ||||||||||||||||||||||||||||||||||||||||||
| 236 | # hide a site. | ||||||||||||||||||||||||||||||||||||||||||
| 237 | 0 | $result->{verify_error} = $class->_verify($host, $port, $timeout); | |||||||||||||||||||||||||||||||||||||||||
| 238 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 239 | 1 | ▶ | $result->{error} = _ssl_error() // $class->i18n('tls.unknown_error'); | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
_ssl_error() // $class->i18n("tls.unknown_error")
MC/DC0%0/2
_ssl_error() // $class->i18n("tls.unknown_error")
_ssl_error()
$class->i18n("tls.unknown_error")
Truth table33%1/3
A // B
A= _ssl_error()B= $class->i18n("tls.unknown_error")
| |||||||||||||||||||||||||||||||||||||||||||
| 240 | } | ||||||||||||||||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||||||||||||||||
| 242 | # The version probes run even when the default handshake failed: a | ||||||||||||||||||||||||||||||||||||||||||
| 243 | # server that only speaks TLS 1.0 fails it, and that is exactly the | ||||||||||||||||||||||||||||||||||||||||||
| 244 | # server whose protocol list matters most. | ||||||||||||||||||||||||||||||||||||||||||
| 245 | 1 | for my $version (@PROBE_VERSIONS) { | |||||||||||||||||||||||||||||||||||||||||
| 246 | 4 | ▶ | my $probe = _connect($host, $port, $timeout, $version) or next; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 247 | 1 | push @{ $result->{protocols} }, $version; | |||||||||||||||||||||||||||||||||||||||||
| 248 | 1 | close $probe; | |||||||||||||||||||||||||||||||||||||||||
| 249 | } | ||||||||||||||||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||||||||||||||||
| 251 | 1 | return $result; | |||||||||||||||||||||||||||||||||||||||||
| 252 | } | ||||||||||||||||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||||||||||||||||
| 254 | # _describe | ||||||||||||||||||||||||||||||||||||||||||
| 255 | # Purpose: record what the first handshake learned. | ||||||||||||||||||||||||||||||||||||||||||
| 256 | # Entry: $sock is a connected IO::Socket::SSL; $result a hashref. | ||||||||||||||||||||||||||||||||||||||||||
| 257 | # Exit: $result, filled in. | ||||||||||||||||||||||||||||||||||||||||||
| 258 | # Side effects: modifies $result. | ||||||||||||||||||||||||||||||||||||||||||
| 259 | 0 | ▶ | sub _describe :Private | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_describe: not called CC=8 SCAR=42.8
| |||||||||||||||||||||||||||||||||||||||||||
| 260 | { | ||||||||||||||||||||||||||||||||||||||||||
| 261 | 0 | my ($sock, $result) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||||||||||||||||
| 263 | 0 | $result->{ok} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 264 | 0 | ▶ | $result->{protocol} = $sock->get_sslversion // ''; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$sock->get_sslversion // ""
MC/DC0%0/1
$sock->get_sslversion // ""
$sock->get_sslversion
Truth table0%0/2
A
A= $sock->get_sslversion
| |||||||||||||||||||||||||||||||||||||||||||
| 265 | 0 | ▶ | $result->{cipher} = $sock->get_cipher // ''; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$sock->get_cipher // ""
MC/DC0%0/1
$sock->get_cipher // ""
$sock->get_cipher
Truth table0%0/2
A
A= $sock->get_cipher
| |||||||||||||||||||||||||||||||||||||||||||
| 266 | 0 | $result->{self_signed} = _self_signed($sock); | |||||||||||||||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||||||||||||||||
| 268 | # Each field is optional: some builds do not offer every one. | ||||||||||||||||||||||||||||||||||||||||||
| 269 | 0 | for my $field (qw(subject issuer fingerprint)) { | |||||||||||||||||||||||||||||||||||||||||
| 270 | 0 | ▶ | my $value = eval { $sock->peer_certificate($field) } or next; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 271 | 0 | ▶ | $result->{$field} = $field eq 'fingerprint' ? $value : _name($value); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 272 | } | ||||||||||||||||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||||||||||||||||
| 274 | 0 | ▶ | if(defined(my $not_after = _not_after($sock))) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 275 | 0 | $result->{not_after} = $not_after; | |||||||||||||||||||||||||||||||||||||||||
| 276 | 0 | ▶ | if(defined(my $epoch = _parse_asn1_time($not_after))) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 277 | 0 | $result->{expires_at} = $epoch; | |||||||||||||||||||||||||||||||||||||||||
| 278 | 0 | $result->{days_left} = int(($epoch - time) / $SECONDS_PER_DAY); | |||||||||||||||||||||||||||||||||||||||||
| 279 | } | ||||||||||||||||||||||||||||||||||||||||||
| 280 | } | ||||||||||||||||||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||||||||||||||||
| 282 | 0 | return $result; | |||||||||||||||||||||||||||||||||||||||||
| 283 | 28 | ▶ | } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||||||||||||||||
| 285 | # _connect | ||||||||||||||||||||||||||||||||||||||||||
| 286 | # Purpose: one unverified handshake, optionally pinned to a version. | ||||||||||||||||||||||||||||||||||||||||||
| 287 | # Entry: $version, if given, is one of @PROBE_VERSIONS. | ||||||||||||||||||||||||||||||||||||||||||
| 288 | # Exit: the socket, or undef (SSL_ERROR / $! set). | ||||||||||||||||||||||||||||||||||||||||||
| 289 | # Side effects: a TLS handshake. | ||||||||||||||||||||||||||||||||||||||||||
| 290 | 5 | ▶ | sub _connect :Private | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_connect: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||
| 291 | { | ||||||||||||||||||||||||||||||||||||||||||
| 292 | 5 | my ($host, $port, $timeout, $version) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 293 | |||||||||||||||||||||||||||||||||||||||||||
| 294 | 5 | my %args = ( | |||||||||||||||||||||||||||||||||||||||||
| 295 | PeerHost => $host, | ||||||||||||||||||||||||||||||||||||||||||
| 296 | PeerPort => $port, | ||||||||||||||||||||||||||||||||||||||||||
| 297 | Timeout => $timeout, | ||||||||||||||||||||||||||||||||||||||||||
| 298 | SSL_hostname => $host, | ||||||||||||||||||||||||||||||||||||||||||
| 299 | SSL_verify_mode => SSL_VERIFY_NONE, | ||||||||||||||||||||||||||||||||||||||||||
| 300 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 301 | 5 | ▶ | $args{SSL_version} = $version if $version; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 302 | 5 | ▶ | $args{SSL_cipher_list} = $PROBE_CIPHERS{$version} if $version && $PROBE_CIPHERS{$version}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$version and $PROBE_CIPHERS{$version}
MC/DC100%2/2
$version and $PROBE_CIPHERS{$version}
$version
$PROBE_CIPHERS{$version}
Truth table100%3/3
A and B
A= $versionB= $PROBE_CIPHERS{$version}
| |||||||||||||||||||||||||||||||||||||||||||
| 303 | |||||||||||||||||||||||||||||||||||||||||||
| 304 | 5 | return IO::Socket::SSL->new(%args); | |||||||||||||||||||||||||||||||||||||||||
| 305 | 28 | ▶ | } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||||||||||||||||
| 307 | # _verify | ||||||||||||||||||||||||||||||||||||||||||
| 308 | # Purpose: would a browser trust this chain for this name? | ||||||||||||||||||||||||||||||||||||||||||
| 309 | # Entry: as _connect. | ||||||||||||||||||||||||||||||||||||||||||
| 310 | # Exit: undef if it verifies, else the reason. | ||||||||||||||||||||||||||||||||||||||||||
| 311 | # Side effects: a TLS handshake. | ||||||||||||||||||||||||||||||||||||||||||
| 312 | 0 | ▶ | sub _verify :Private | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_verify: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||
| 313 | { | ||||||||||||||||||||||||||||||||||||||||||
| 314 | 0 | my ($class, $host, $port, $timeout) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 315 | |||||||||||||||||||||||||||||||||||||||||||
| 316 | 0 | my $sock = IO::Socket::SSL->new( | |||||||||||||||||||||||||||||||||||||||||
| 317 | PeerHost => $host, | ||||||||||||||||||||||||||||||||||||||||||
| 318 | PeerPort => $port, | ||||||||||||||||||||||||||||||||||||||||||
| 319 | Timeout => $timeout, | ||||||||||||||||||||||||||||||||||||||||||
| 320 | SSL_hostname => $host, | ||||||||||||||||||||||||||||||||||||||||||
| 321 | SSL_verify_mode => SSL_VERIFY_PEER, | ||||||||||||||||||||||||||||||||||||||||||
| 322 | SSL_verifycn_name => $host, | ||||||||||||||||||||||||||||||||||||||||||
| 323 | SSL_verifycn_scheme => 'http', | ||||||||||||||||||||||||||||||||||||||||||
| 324 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 325 | 0 | ▶ | close $sock if $sock; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 326 | |||||||||||||||||||||||||||||||||||||||||||
| 327 | 0 | ▶ | return $sock ? undef : (_ssl_error() // $class->i18n('tls.verify_failed')); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
_ssl_error() // $class->i18n("tls.verify_failed")
MC/DC0%0/2
_ssl_error() // $class->i18n("tls.verify_failed")
_ssl_error()
$class->i18n("tls.verify_failed")
Truth table0%0/3
A // B
A= _ssl_error()B= $class->i18n("tls.verify_failed")
| |||||||||||||||||||||||||||||||||||||||||||
| 328 | 28 | ▶ | } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 329 | |||||||||||||||||||||||||||||||||||||||||||
| 330 | # _ssl_error | ||||||||||||||||||||||||||||||||||||||||||
| 331 | # Purpose: IO::Socket::SSL's last error, or $! when it has none. | ||||||||||||||||||||||||||||||||||||||||||
| 332 | # Entry: straight after a failed IO::Socket::SSL->new. | ||||||||||||||||||||||||||||||||||||||||||
| 333 | # Exit: a non-empty string, or undef if neither says anything. | ||||||||||||||||||||||||||||||||||||||||||
| 334 | # Side effects: none. | ||||||||||||||||||||||||||||||||||||||||||
| 335 | 1 | ▶ | sub _ssl_error :Private | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_ssl_error: called CC=4 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||
| 336 | { | ||||||||||||||||||||||||||||||||||||||||||
| 337 | 1 | my $error = $IO::Socket::SSL::SSL_ERROR; | |||||||||||||||||||||||||||||||||||||||||
| 338 | 1 | ▶ | $error = "$!" unless defined $error && length $error; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $error and length $error
MC/DC0%0/2
defined $error and length $error
defined $error
length $error
Truth table33%1/3
A and B
A= defined $errorB= length $error
| |||||||||||||||||||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||||||||||||||||
| 340 | 1 | ▶ | return length $error ? $error : undef; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 341 | 28 | ▶ | } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 342 | |||||||||||||||||||||||||||||||||||||||||||
| 343 | # _self_signed | ||||||||||||||||||||||||||||||||||||||||||
| 344 | # Purpose: are the certificate's subject and issuer the same name? | ||||||||||||||||||||||||||||||||||||||||||
| 345 | # Entry: $sock is a connected IO::Socket::SSL. | ||||||||||||||||||||||||||||||||||||||||||
| 346 | # Exit: 1 or 0; 0 when either name cannot be read. | ||||||||||||||||||||||||||||||||||||||||||
| 347 | # Side effects: none. | ||||||||||||||||||||||||||||||||||||||||||
| 348 | 0 | ▶ | sub _self_signed :Private | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_self_signed: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||
| 349 | { | ||||||||||||||||||||||||||||||||||||||||||
| 350 | 0 | my ($sock) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 351 | |||||||||||||||||||||||||||||||||||||||||||
| 352 | 0 | my $subject = eval { $sock->peer_certificate('subject') }; | |||||||||||||||||||||||||||||||||||||||||
| 353 | 0 | my $issuer = eval { $sock->peer_certificate('issuer') }; | |||||||||||||||||||||||||||||||||||||||||
| 354 | |||||||||||||||||||||||||||||||||||||||||||
| 355 | 0 | ▶ | return ($subject && $issuer && _name($subject) eq _name($issuer)) ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$subject and $issuer and _name($subject) eq _name($issuer)
$subject and $issuer
MC/DC0%0/3
$subject and $issuer and _name($subject) eq _name($issuer)
$subject
$issuer
_name($subject) eq _name($issuer)
Truth table0%0/4
A and B and C
A= $subjectB= $issuerC= _name($subject) eq _name($issuer)
| |||||||||||||||||||||||||||||||||||||||||||
| 356 | 28 | ▶ | } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 357 | |||||||||||||||||||||||||||||||||||||||||||
| 358 | # _name | ||||||||||||||||||||||||||||||||||||||||||
| 359 | # Purpose: a certificate name as one string. | ||||||||||||||||||||||||||||||||||||||||||
| 360 | # Entry: $name is a string, a hash of fields, or undef. | ||||||||||||||||||||||||||||||||||||||||||
| 361 | # Exit: the name; '' for undef; 'unknown' for a hash with no fields | ||||||||||||||||||||||||||||||||||||||||||
| 362 | # we know. | ||||||||||||||||||||||||||||||||||||||||||
| 363 | # Side effects: none. | ||||||||||||||||||||||||||||||||||||||||||
| 364 | # | ||||||||||||||||||||||||||||||||||||||||||
| 365 | # Some IO::Socket::SSL builds return the whole name as one string, others as | ||||||||||||||||||||||||||||||||||||||||||
| 366 | # a hash of fields whose values are array references. Both shapes are | ||||||||||||||||||||||||||||||||||||||||||
| 367 | # accepted: reporting an empty name for one of them made subject and issuer | ||||||||||||||||||||||||||||||||||||||||||
| 368 | # compare equal, which turned every certificate into a self-signed one. | ||||||||||||||||||||||||||||||||||||||||||
| 369 | 7 | ▶ | sub _name :Private | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_name: called CC=8 SCAR=21.6
| |||||||||||||||||||||||||||||||||||||||||||
| 370 | { | ||||||||||||||||||||||||||||||||||||||||||
| 371 | 7 | my ($name) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 372 | |||||||||||||||||||||||||||||||||||||||||||
| 373 | 7 | ▶ | return '' unless defined $name; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 374 | 6 | ▶ | return $name unless ref $name; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 375 | 3 | ▶ | return '' unless ref $name eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 376 | |||||||||||||||||||||||||||||||||||||||||||
| 377 | 2 | ▶ | my @parts = grep { defined && !ref && length } | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%2/6
defined $_ && !ref($_) && length $_
defined $_ and not ref $_
MC/DC0%0/3
defined $_ && !ref($_) && length $_
defined $_
not ref $_
length $_
Truth table25%1/4
A and not(B) && C
A= defined $_B= not ref $_C= length $_
| |||||||||||||||||||||||||||||||||||||||||||
| 378 | 2 | ▶ | map { ref eq 'ARRAY' ? $_->[0] : $_ } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 379 | 3 | grep { defined } @{$name}{@NAME_FIELDS}; | |||||||||||||||||||||||||||||||||||||||||
| 380 | |||||||||||||||||||||||||||||||||||||||||||
| 381 | 3 | ▶ | return join(', ', @parts) || __PACKAGE__->i18n('tls.unknown_name'); | ||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
join(', ', @parts) || __PACKAGE__->i18n('tls.unknown_name')
MC/DC0%0/2
join(', ', @parts) || __PACKAGE__->i18n('tls.unknown_name')
join(', ', @parts)
__PACKAGE__->i18n('tls.unknown_name')
Truth table66%2/3
A || B
A= join(', ', @parts)B= __PACKAGE__->i18n('tls.unknown_name')
| |||||||||||||||||||||||||||||||||||||||||||
| 382 | 28 | ▶ | } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 383 | |||||||||||||||||||||||||||||||||||||||||||
| 384 | # _not_after | ||||||||||||||||||||||||||||||||||||||||||
| 385 | # Purpose: the certificate's notAfter date as a string. | ||||||||||||||||||||||||||||||||||||||||||
| 386 | # Entry: $sock is a connected IO::Socket::SSL (or a test double). | ||||||||||||||||||||||||||||||||||||||||||
| 387 | # Exit: a date _parse_asn1_time understands, or undef. | ||||||||||||||||||||||||||||||||||||||||||
| 388 | # Side effects: none (the X509 copy is freed). | ||||||||||||||||||||||||||||||||||||||||||
| 389 | # | ||||||||||||||||||||||||||||||||||||||||||
| 390 | # peer_certificate() exposes only a handful of fields, and where not_after is | ||||||||||||||||||||||||||||||||||||||||||
| 391 | # not one of them the expiry checks used to be skipped; the certificate itself | ||||||||||||||||||||||||||||||||||||||||||
| 392 | # is still reachable through Net::SSLeay. | ||||||||||||||||||||||||||||||||||||||||||
| 393 | 2 | ▶ | sub _not_after :Private | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_not_after: called CC=9 SCAR=34.4
| |||||||||||||||||||||||||||||||||||||||||||
| 394 | { | ||||||||||||||||||||||||||||||||||||||||||
| 395 | 2 | my ($sock) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 396 | |||||||||||||||||||||||||||||||||||||||||||
| 397 | 2 | my $not_after = eval { $sock->peer_certificate('not_after') }; | |||||||||||||||||||||||||||||||||||||||||
| 398 | 2 | ▶ | return $not_after if defined $not_after && !ref $not_after && length $not_after; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
defined $not_after and not ref $not_after and length $not_after
defined $not_after and not ref $not_after
MC/DC33%1/3
defined $not_after and not ref $not_after and length $not_after
defined $not_after
not ref $not_after
length $not_after
Truth table50%2/4
A and not(B) and C
A= defined $not_afterB= not ref $not_afterC= length $not_after
| |||||||||||||||||||||||||||||||||||||||||||
| 399 | |||||||||||||||||||||||||||||||||||||||||||
| 400 | 1 | ▶ | my $ssl = eval { $sock->_get_ssl_object } or return undef; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 401 | 0 | ▶ | my $x509 = eval { Net::SSLeay::get_peer_certificate($ssl) } or return undef; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 402 | 0 | my $asn1 = eval { Net::SSLeay::X509_get_notAfter($x509) }; | |||||||||||||||||||||||||||||||||||||||||
| 403 | |||||||||||||||||||||||||||||||||||||||||||
| 404 | # Prefer the text form; fall back to ISO 8601 if this build's text | ||||||||||||||||||||||||||||||||||||||||||
| 405 | # form does not parse. | ||||||||||||||||||||||||||||||||||||||||||
| 406 | 0 | my $string; | |||||||||||||||||||||||||||||||||||||||||
| 407 | 0 | ▶ | if(defined $asn1) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 408 | 0 | $string = eval { Net::SSLeay::P_ASN1_TIME_put2string($asn1) }; | |||||||||||||||||||||||||||||||||||||||||
| 409 | 0 | ▶ | $string = eval { Net::SSLeay::P_ASN1_TIME_get_isotime($asn1) } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 410 | unless defined _parse_asn1_time($string); | ||||||||||||||||||||||||||||||||||||||||||
| 411 | } | ||||||||||||||||||||||||||||||||||||||||||
| 412 | 0 | eval { Net::SSLeay::X509_free($x509) }; | |||||||||||||||||||||||||||||||||||||||||
| 413 | |||||||||||||||||||||||||||||||||||||||||||
| 414 | 0 | ▶ | return defined _parse_asn1_time($string) ? $string =~ s/\A\s+//r : undef; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 415 | 28 | ▶ | } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 416 | |||||||||||||||||||||||||||||||||||||||||||
| 417 | # _parse_asn1_time | ||||||||||||||||||||||||||||||||||||||||||
| 418 | # Purpose: an ASN.1 time string to an epoch. | ||||||||||||||||||||||||||||||||||||||||||
| 419 | # Entry: $string in either text or ISO 8601 form, or undef. | ||||||||||||||||||||||||||||||||||||||||||
| 420 | # Exit: seconds since the epoch (UTC), or undef if it does not parse. | ||||||||||||||||||||||||||||||||||||||||||
| 421 | # Side effects: none. | ||||||||||||||||||||||||||||||||||||||||||
| 422 | # | ||||||||||||||||||||||||||||||||||||||||||
| 423 | # Time::Piece->strptime was tried and rejected: it prints to STDERR when a | ||||||||||||||||||||||||||||||||||||||||||
| 424 | # month name does not parse, which would leak into a report. | ||||||||||||||||||||||||||||||||||||||||||
| 425 | 7 | ▶ | sub _parse_asn1_time :Private | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_parse_asn1_time: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||
| 426 | { | ||||||||||||||||||||||||||||||||||||||||||
| 427 | 7 | my ($string) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 428 | |||||||||||||||||||||||||||||||||||||||||||
| 429 | 7 | my ($sec, $min, $hour, $day, $month, $year); | |||||||||||||||||||||||||||||||||||||||||
| 430 | 7 | ▶ | if(!defined $string) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 431 | 1 | return undef; | |||||||||||||||||||||||||||||||||||||||||
| 432 | } elsif($string =~ $ASN1_ISO) { | ||||||||||||||||||||||||||||||||||||||||||
| 433 | 1 | ($year, $month, $day, $hour, $min, $sec) = ($1, $2 - 1, $3, $4, $5, $6); | |||||||||||||||||||||||||||||||||||||||||
| 434 | ▶ | } elsif($string =~ $ASN1_TEXT && exists $MONTH{$1}) { | |||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$string =~ /$ASN1_TEXT/ and exists $MONTH{$1}
MC/DC100%2/2
$string =~ /$ASN1_TEXT/ and exists $MONTH{$1}
$string =~ /$ASN1_TEXT/
exists $MONTH{$1}
Truth table100%3/3
A and B
A= $string =~ /$ASN1_TEXT/B= exists $MONTH{$1}
| |||||||||||||||||||||||||||||||||||||||||||
| 435 | 3 | ($month, $day, $hour, $min, $sec, $year) = ($MONTH{$1}, $2, $3, $4, $5, $6); | |||||||||||||||||||||||||||||||||||||||||
| 436 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 437 | 2 | return undef; | |||||||||||||||||||||||||||||||||||||||||
| 438 | } | ||||||||||||||||||||||||||||||||||||||||||
| 439 | |||||||||||||||||||||||||||||||||||||||||||
| 440 | # timegm croaks on an impossible date such as Feb 31. | ||||||||||||||||||||||||||||||||||||||||||
| 441 | 4 | return eval { timegm($sec, $min, $hour, $day, $month, $year) }; | |||||||||||||||||||||||||||||||||||||||||
| 442 | 28 | ▶ | } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 443 | |||||||||||||||||||||||||||||||||||||||||||
| 444 | 28 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 445 | |||||||||||||||||||||||||||||||||||||||||||
| 446 | __END__ | ||||||||||||||||||||||||||||||||||||||||||