blib/lib/LWP/Protocol/https.pm

filter: Statementstmt 83.5% 56 / 67 Branchbran 43.7% 14 / 32 Conditioncond 27.2% 6 / 22 MC/DCmcdc 0.0% 0 / 13 Subroutinesub 100% 8 / 8 Podpod 0.0% 0 / 1 totaltotal 58.7% 84 / 143 CC 24 SCAR 28.3
CC
24
Cov
63%
_extra_sock_opts
31.3
__ANON__
12.9
_get_sock_info
7.2
CRAP 17.0
↑ Summary
1 package LWP::Protocol::https;
2  
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 2 our $VERSION = '6.17';
7  
8 2 ▶use parent qw(LWP::Protocol::http);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 require Net::HTTPS;
10  
11 sub socket_type
12 12 ▶{
Subroutine socket_type: called CC=1 SCAR=0.0
Pod undocumented
13 12 return "https";
14 }
15  
16 sub _extra_sock_opts
17 8 ▶{
Subroutine _extra_sock_opts: called CC=12 SCAR=34.4
18 8 my $self = shift;
19 8 ▶ my %ssl_opts = %{$self->{ua}{ssl_opts} || {}};
Condition50%1/2
$self->{'ua'}{'ssl_opts'} || {}
l!l
80
MC/DC0%0/1
$self->{'ua'}{'ssl_opts'} || {}
$self->{'ua'}{'ssl_opts'}
Truth table50%1/2
A
A= $self->{'ua'}{'ssl_opts'}
Aresult
11
00
20 8 ▶ if (delete $ssl_opts{verify_hostname}) {
Branch: 1 branch
BranchTrueFalseTotal
if (delete $ssl_opts{'verify_hostname'}) { } 6 2 8
21 6 ▶ $ssl_opts{SSL_verify_mode} ||= 1;
Condition50%1/2
$ssl_opts{"SSL_verify_mode"} ||= 1
l!l
06
MC/DC0%0/1
$ssl_opts{"SSL_verify_mode"} ||= 1
$ssl_opts{"SSL_verify_mode"}
Truth table50%1/2
A
A= $ssl_opts{"SSL_verify_mode"}
Aresult
11
00
22 6 $ssl_opts{SSL_verifycn_scheme} = 'www';
23 }
24 else {
25 2 ▶ if ( $Net::HTTPS::SSL_SOCKET_CLASS eq 'Net::SSL' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Net::HTTPS::SSL_SOCKET_CLASS eq 'Net::SSL') { } 0 2 2
26 0 $ssl_opts{SSL_verifycn_scheme} = '';
27 } else {
28 2 $ssl_opts{SSL_verifycn_scheme} = 'none';
29 }
30 }
31 8 ▶ if ($ssl_opts{SSL_verify_mode}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ssl_opts{"SSL_verify_mode"}) 6 2 8
32 6 ▶ unless (exists $ssl_opts{SSL_ca_file} || exists $ssl_opts{SSL_ca_path}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $ssl_opts{"SSL_ca_file"} or exists $ssl_opts{"SSL_ca_path"}) 0 6 6
Condition33%1/3
exists $ssl_opts{"SSL_ca_file"} or exists $ssl_opts{"SSL_ca_path"}
l!l&&r!l&&!r
600
MC/DC0%0/2
exists $ssl_opts{"SSL_ca_file"} or exists $ssl_opts{"SSL_ca_path"}
exists $ssl_opts{"SSL_ca_file"} exists $ssl_opts{"SSL_ca_path"}
Truth table33%1/3
A or B
A= exists $ssl_opts{"SSL_ca_file"}B= exists $ssl_opts{"SSL_ca_path"}
ABresult
1X1
011
000
33 0 ▶ if ($Net::HTTPS::SSL_SOCKET_CLASS eq 'IO::Socket::SSL'
Branch: 2 branches
BranchTrueFalseTotal
if ($Net::HTTPS::SSL_SOCKET_CLASS eq 'IO::Socket::SSL' and defined &IO::Socket::SSL::default_ca and IO::Socket::SSL::default_ca()) { } 0 0 0
elsif (my $cafile = eval { do { require Mozilla::CA; Mozilla::CA::SSL_ca_file() } }) { } 0 0 0
Condition0%0/6
$Net::HTTPS::SSL_SOCKET_CLASS eq "IO::Socket::SSL" and defined &IO::Socket::SSL::default_ca and IO::Socket::SSL::default_ca()
!ll&&!rl&&r
000
$Net::HTTPS::SSL_SOCKET_CLASS eq "IO::Socket::SSL" and defined &IO::Socket::SSL::default_ca
!ll&&!rl&&r
000
MC/DC0%0/3
$Net::HTTPS::SSL_SOCKET_CLASS eq "IO::Socket::SSL" and defined &IO::Socket::SSL::default_ca and IO::Socket::SSL::default_ca()
$Net::HTTPS::SSL_SOCKET_CLASS eq "IO::Socket::SSL" defined &IO::Socket::SSL::default_ca IO::Socket::SSL::default_ca()
Truth table0%0/4
A and B and C
A= $Net::HTTPS::SSL_SOCKET_CLASS eq "IO::Socket::SSL"B= defined &IO::Socket::SSL::default_caC= IO::Socket::SSL::default_ca()
ABCresult
0XX0
10X0
1100
1111
34 && defined &IO::Socket::SSL::default_ca
35 && IO::Socket::SSL::default_ca() ) {
36 # IO::Socket::SSL has a usable default CA
37 } elsif ( my $cafile = eval {
38 0 require Mozilla::CA;
39 0 Mozilla::CA::SSL_ca_file()
40 }) {
41 # use Mozilla::CA
42 0 $ssl_opts{SSL_ca_file} = $cafile;
43 } else {
44 0 die <<'EOT';
45 Can't verify SSL peers without knowing which Certificate Authorities to trust.
46  
47 This problem can be fixed by either setting the PERL_LWP_SSL_CA_FILE
48 environment variable to the file where your trusted CA are, or by installing
49 the Mozilla::CA module for set of commonly trusted CAs.
50  
51 To completely disable the verification that you talk to the correct SSL peer you
52 can set SSL_verify_mode to 0 within ssl_opts. But, if you do this you can't be
53 sure that you communicate with the expected peer.
54 EOT
55 }
56 }
57 }
58 8 $self->{ssl_opts} = \%ssl_opts;
59 8 return (%ssl_opts, MultiHomed => 1, $self->SUPER::_extra_sock_opts);
60 }
61  
62 # This is a subclass of LWP::Protocol::http.
63 # That parent class calls ->_check_sock() during the
64 # request method. This allows us to hook in and run checks
65 # sub _check_sock
66 # {
67 # my($self, $req, $sock) = @_;
68 # }
69  
70 sub _get_sock_info
71 6 ▶{
Subroutine _get_sock_info: called CC=6 SCAR=19.7
72 6 my $self = shift;
73 6 $self->SUPER::_get_sock_info(@_);
74 6 my($res, $sock) = @_;
75 6 ▶ if ($sock->can('get_sslversion') and my $sslversion = $sock->get_sslversion) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sock->can("get_sslversion") and my $sslversion = $sock->get_sslversion) 6 0 6
Condition33%1/3
$sock->can("get_sslversion") and my $sslversion = $sock->get_sslversion
!ll&&!rl&&r
006
MC/DC0%0/2
$sock->can("get_sslversion") and my $sslversion = $sock->get_sslversion
$sock->can("get_sslversion") my $sslversion = $sock->get_sslversion
Truth table33%1/3
A and B
A= $sock->can("get_sslversion")B= my $sslversion = $sock->get_sslversion
ABresult
0X0
100
111
76 6 $res->header("Client-SSL-Version" => $sslversion);
77 }
78 6 $res->header("Client-SSL-Cipher" => $sock->get_cipher);
79 6 my $cert = $sock->get_peer_certificate;
80 6 ▶ if ($cert) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cert) 6 0 6
81 6 $res->header("Client-SSL-Cert-Subject" => $cert->subject_name);
82 6 $res->header("Client-SSL-Cert-Issuer" => $cert->issuer_name);
83 }
84 6 ▶ if (!$self->{ssl_opts}{SSL_verify_mode}) {
Branch: 2 branches
BranchTrueFalseTotal
if (not $self->{'ssl_opts'}{'SSL_verify_mode'}) { } 6 0 6
elsif (not $self->{'ssl_opts'}{'SSL_verifycn_scheme'}) { } 0 0 0
85 6 $res->push_header("Client-SSL-Warning" => "Peer certificate not verified");
86 }
87 elsif (!$self->{ssl_opts}{SSL_verifycn_scheme}) {
88 0 $res->push_header("Client-SSL-Warning" => "Peer hostname match with certificate not verified");
89 }
90 6 $res->header("Client-SSL-Socket-Class" => $Net::HTTPS::SSL_SOCKET_CLASS);
91 }
92  
93 # upgrade plain socket to SSL, used for CONNECT tunnel when proxying https
94 # will only work if the underlying socket class of Net::HTTPS is
95 # IO::Socket::SSL, but code will only be called in this case
96 2 ▶if ( $Net::HTTPS::SSL_SOCKET_CLASS->can('start_SSL')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Net::HTTPS::SSL_SOCKET_CLASS->can("start_SSL")) 2 0 2
97 6 ▶ *_upgrade_sock = sub {
Subroutine __ANON__: called CC=8 SCAR=25.6
98 6 my ($self,$sock,$url) = @_;
99 # SNI should be passed there only if it is not an IP address.
100 # Details: https://github.com/libwww-perl/libwww-perl/issues/449#issuecomment-1896175509
101 6 ▶ my $host = $url->host() =~ m/:|^[\d.]+$/s ? undef : $url->host();
Branch: 1 branch
BranchTrueFalseTotal
$url->host =~ /:|^[\d.]+$/s ? : 0 6 6
102 6 my $usebio = {};
103 6 ▶ if (UNIVERSAL::can($sock,'is_SSL') && $sock->is_SSL) {
Branch: 1 branch
BranchTrueFalseTotal
if (UNIVERSAL::can($sock, "is_SSL") and $sock->is_SSL) 0 6 6
Condition33%1/3
UNIVERSAL::can($sock, "is_SSL") and $sock->is_SSL
!ll&&!rl&&r
600
MC/DC0%0/2
UNIVERSAL::can($sock, "is_SSL") and $sock->is_SSL
UNIVERSAL::can($sock, "is_SSL") $sock->is_SSL
Truth table33%1/3
A and B
A= UNIVERSAL::can($sock, "is_SSL")B= $sock->is_SSL
ABresult
0X0
100
111
104 0 ▶ $usebio = eval { $Net::HTTPS::SSL_SOCKET_CLASS->can_nested_ssl } or
Branch: 1 branch
BranchTrueFalseTotal
$usebio = eval { do { $Net::HTTPS::SSL_SOCKET_CLASS->can_nested_ssl } } or die "no support for nested TLS in this IO::Socket::SSL version" 0 0 0
105 die "no support for nested TLS in this IO::Socket::SSL version";
106 }
107  
108 6 $sock = LWP::Protocol::https::Socket->start_SSL( my $osock = $sock,
109 SSL_verifycn_name => $url->host,
110 SSL_hostname => $host,
111 %$usebio,
112 $self->_extra_sock_opts,
113 );
114 6 ▶ if (!$sock) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($sock) 0 6 6
115 0 $@ = LWP::Protocol::https::Socket->errstr;
116 0 return;
117 }
118 6 ▶ if ($usebio and my @fields = grep { /^http_/ } keys %{*$osock}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($usebio and my(@fields) = grep({/^http_/;} keys %{*$osock;})) 6 0 6
Condition33%1/3
$usebio and my(@fields) = grep({/^http_/;} keys %{*$osock;})
!ll&&!rl&&r
006
MC/DC0%0/2
$usebio and my(@fields) = grep({/^http_/;} keys %{*$osock;})
$usebio my(@fields) = grep({/^http_/;} keys %{*$osock;})
Truth table33%1/3
A and B
A= $usebioB= my(@fields) = grep({/^http_/;} keys %{*$osock;})
ABresult
0X0
100
111
119 # propagate any http_ fields from osock to sock
120 6 @{*$sock}{@fields} = @{*$osock}{@fields}
121 }
122 6 return $sock;
123 }
124 2 }
125  
126 #-----------------------------------------------------------
127 package LWP::Protocol::https::Socket;
128  
129 2 ▶use parent -norequire, qw(Net::HTTPS LWP::Protocol::http::SocketMethods);
Subroutine BEGIN: called CC=1 SCAR=0.0
130  
131 2 1;
132  
133 __END__
↑ Summary