blib/lib/LWP/Protocol/https.pm

filter: Statementstmt 87.0% 47 / 54 Branchbran 46.1% 12 / 26 Conditioncond 21.4% 3 / 14 MC/DCmcdc 0.0% 0 / 8 Subroutinesub 100% 8 / 8 Podpod 0.0% 0 / 1 totaltotal 63.0% 70 / 111 SCAR 34.3
CC
18
Cov
66%
_extra_sock_opts
31.3
_get_sock_info
7.2
__ANON__
2.0
CRAP 30.8
↑ Summary
1 package LWP::Protocol::https;
2  
3 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 3 our $VERSION = '6.11';
7  
8 3 ▶use base qw(LWP::Protocol::http);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 3 require Net::HTTPS;
10  
11 sub socket_type
12 {
13 12 ▶ return "https";
Subroutine socket_type: called CC=1 SCAR=0.0
Pod undocumented
14 }
15  
16 sub _extra_sock_opts
17 {
18 10 ▶ my $self = shift;
Subroutine _extra_sock_opts: called CC=12 SCAR=34.4
19 10 ▶ my %ssl_opts = %{$self->{ua}{ssl_opts} || {}};
Branch: 1 branch
BranchTrueFalseTotal
$self->{"ua"}{"ssl_opts"} or {} 0 10 10
20 10 ▶ if (delete $ssl_opts{verify_hostname}) {
Branch: 1 branch
BranchTrueFalseTotal
if (delete $ssl_opts{'verify_hostname'}) { } 6 4 10
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 4 ▶ if ( $Net::HTTPS::SSL_SOCKET_CLASS eq 'Net::SSL' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Net::HTTPS::SSL_SOCKET_CLASS eq 'Net::SSL') { } 0 4 4
26 0 $ssl_opts{SSL_verifycn_scheme} = '';
27 } else {
28 4 $ssl_opts{SSL_verifycn_scheme} = 'none';
29 }
30 }
31 10 ▶ if ($ssl_opts{SSL_verify_mode}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ssl_opts{"SSL_verify_mode"}) 6 4 10
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 completly 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 10 $self->{ssl_opts} = \%ssl_opts;
59 10 return (%ssl_opts, $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 {
72 8 ▶ my $self = shift;
Subroutine _get_sock_info: called CC=6 SCAR=19.7
73 8 $self->SUPER::_get_sock_info(@_);
74 8 my($res, $sock) = @_;
75 8 ▶ 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) 8 0 8
Condition33%1/3
$sock->can("get_sslversion") and my $sslversion = $sock->get_sslversion
!ll&&!rl&&r
008
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 8 $res->header("Client-SSL-Version" => $sslversion);
77 }
78 8 $res->header("Client-SSL-Cipher" => $sock->get_cipher);
79 8 my $cert = $sock->get_peer_certificate;
80 8 ▶ if ($cert) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cert) 8 0 8
81 8 $res->header("Client-SSL-Cert-Subject" => $cert->subject_name);
82 8 $res->header("Client-SSL-Cert-Issuer" => $cert->issuer_name);
83 }
84 8 ▶ if (!$self->{ssl_opts}{SSL_verify_mode}) {
Branch: 2 branches
BranchTrueFalseTotal
if (not $self->{'ssl_opts'}{'SSL_verify_mode'}) { } 8 0 8
elsif (not $self->{'ssl_opts'}{'SSL_verifycn_scheme'}) { } 0 0 0
85 8 $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 8 $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 3 ▶if ( $Net::HTTPS::SSL_SOCKET_CLASS->can('start_SSL')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Net::HTTPS::SSL_SOCKET_CLASS->can("start_SSL")) 3 0 3
97 *_upgrade_sock = sub {
98 6 ▶ my ($self,$sock,$url) = @_;
Subroutine __ANON__: called CC=2 SCAR=7.0
99 6 $sock = LWP::Protocol::https::Socket->start_SSL( $sock,
100 SSL_verifycn_name => $url->host,
101 SSL_hostname => $url->host,
102 $self->_extra_sock_opts,
103 );
104 6 ▶ $@ = LWP::Protocol::https::Socket->errstr if ! $sock;
Branch: 1 branch
BranchTrueFalseTotal
unless $sock 0 6 6
105 6 return $sock;
106 }
107 3 }
108  
109 #-----------------------------------------------------------
110 package LWP::Protocol::https::Socket;
111  
112 3 ▶use base qw(Net::HTTPS LWP::Protocol::http::SocketMethods);
Subroutine BEGIN: called CC=1 SCAR=0.0
113  
114 3 1;
115  
116 __END__
↑ Summary