SSL.pm

filter: Statementstmt 74.6% 1469 / 1967 Branchbran 54.8% 753 / 1372 Conditioncond 50.2% 324 / 645 MC/DCmcdc 23.6% 87 / 368 Subroutinesub 74.2% 150 / 202 Podpod 65.0% 54 / 83 totaltotal 61.1% 2837 / 4637 CC 951 SCAR 66.1
CC
951
Cov
64%
new
3284.1
add_response
812.0
__ANON__
394.4
CRAP 739.5
↑ Summary SSL/Utils.pm »
1 #vim: set sts=4 sw=4 ts=8 ai:
2 #
3 # IO::Socket::SSL:
4 # provide an interface to SSL connections similar to IO::Socket modules
5 #
6 # Current Code Shepherd: Steffen Ullrich <sullr at cpan.org>
7 # Code Shepherd before: Peter Behroozi, <behrooz at fas.harvard.edu>
8 #
9 # The original version of this module was written by
10 # Marko Asplund, <marko.asplund at kronodoc.fi>, who drew from
11 # Crypt::SSLeay (Net::SSL) by Gisle Aas.
12 #
13  
14 package IO::Socket::SSL;
15  
16 82 our $VERSION = '2.082';
17  
18 82 ▶use IO::Socket;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 82 ▶use Net::SSLeay 1.46;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 82 ▶use IO::Socket::SSL::PublicSuffix;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 82 ▶use Exporter ();
Subroutine BEGIN: called CC=1 SCAR=0.0
22 82 ▶use Errno qw( EWOULDBLOCK EAGAIN ETIMEDOUT EINTR EPIPE );
Subroutine BEGIN: called CC=1 SCAR=0.0
23 82 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 82 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
25  
26 82 my $use_threads;
27 BEGIN {
28 82 ▶ die "no support for weaken - please install Scalar::Util" if ! do {
Subroutine BEGIN: called CC=3 SCAR=12.0
Branch: 1 branch
BranchTrueFalseTotal
unless do { local $SIG{"__DIE__"}; eval { do { require Scalar::Util; "Scalar::Util"->import("weaken"); 1 } } or eval { do { require WeakRef; "WeakRef"->import("weaken"); 1 } } } 0 82 82
29 82 local $SIG{__DIE__};
30 82 eval { require Scalar::Util; Scalar::Util->import("weaken"); 1 }
31 82 ▶ || eval { require WeakRef; WeakRef->import("weaken"); 1 }
Branch: 1 branch
BranchTrueFalseTotal
eval { do { require Scalar::Util; "Scalar::Util"->import("weaken"); 1 } } or eval { do { require WeakRef; "WeakRef"->import("weaken"); 1 } } 0 82 82
32 };
33 82 require Config;
34 82 $use_threads = $Config::Config{usethreads};
35 }
36  
37  
38 # results from commonly used constant functions from Net::SSLeay for fast access
39 82 my $Net_SSLeay_ERROR_WANT_READ = Net::SSLeay::ERROR_WANT_READ();
40 82 my $Net_SSLeay_ERROR_WANT_WRITE = Net::SSLeay::ERROR_WANT_WRITE();
41 82 my $Net_SSLeay_ERROR_SYSCALL = Net::SSLeay::ERROR_SYSCALL();
42 82 my $Net_SSLeay_ERROR_SSL = Net::SSLeay::ERROR_SSL();
43 82 my $Net_SSLeay_VERIFY_NONE = Net::SSLeay::VERIFY_NONE();
44 82 my $Net_SSLeay_VERIFY_PEER = Net::SSLeay::VERIFY_PEER();
45  
46  
47 82 ▶use constant SSL_VERIFY_NONE => &Net::SSLeay::VERIFY_NONE;
Subroutine BEGIN: called CC=1 SCAR=0.0
48 82 ▶use constant SSL_VERIFY_PEER => &Net::SSLeay::VERIFY_PEER;
Subroutine BEGIN: called CC=1 SCAR=0.0
49 82 ▶use constant SSL_VERIFY_FAIL_IF_NO_PEER_CERT => Net::SSLeay::VERIFY_FAIL_IF_NO_PEER_CERT();
Subroutine BEGIN: called CC=1 SCAR=0.0
50 82 ▶use constant SSL_VERIFY_CLIENT_ONCE => Net::SSLeay::VERIFY_CLIENT_ONCE();
Subroutine BEGIN: called CC=1 SCAR=0.0
51  
52 # from openssl/ssl.h; should be better in Net::SSLeay
53 82 ▶use constant SSL_SENT_SHUTDOWN => 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
54 82 ▶use constant SSL_RECEIVED_SHUTDOWN => 2;
Subroutine BEGIN: called CC=1 SCAR=0.0
55  
56 82 ▶use constant SSL_OCSP_NO_STAPLE => 0b00001;
Subroutine BEGIN: called CC=1 SCAR=0.0
57 82 ▶use constant SSL_OCSP_MUST_STAPLE => 0b00010;
Subroutine BEGIN: called CC=1 SCAR=0.0
58 82 ▶use constant SSL_OCSP_FAIL_HARD => 0b00100;
Subroutine BEGIN: called CC=1 SCAR=0.0
59 82 ▶use constant SSL_OCSP_FULL_CHAIN => 0b01000;
Subroutine BEGIN: called CC=1 SCAR=0.0
60 82 ▶use constant SSL_OCSP_TRY_STAPLE => 0b10000;
Subroutine BEGIN: called CC=1 SCAR=0.0
61  
62 # capabilities of underlying Net::SSLeay/openssl
63 82 my $can_client_sni; # do we support SNI on the client side
64 my $can_server_sni; # do we support SNI on the server side
65 82 my $can_multi_cert; # RSA and ECC certificate in same context
66 82 my $can_npn; # do we support NPN (obsolete)
67 82 my $can_alpn; # do we support ALPN
68 82 my $can_ecdh; # do we support ECDH key exchange
69 82 my $set_groups_list; # SSL_CTX_set1_groups_list || SSL_CTX_set1_curves_list || undef
70 82 my $can_ocsp; # do we support OCSP
71 82 my $can_ocsp_staple; # do we support OCSP stapling
72 82 my $can_tckt_keycb; # TLS ticket key callback
73 82 my $can_pha; # do we support PHA
74 82 my $session_upref; # SSL_SESSION_up_ref is implemented
75 82 my %sess_cb; # SSL_CTX_sess_set_(new|remove)_cb
76 82 my $check_partial_chain; # use X509_V_FLAG_PARTIAL_CHAIN if available
77 82 my $auto_retry; # (clear|set)_mode SSL_MODE_AUTO_RETRY with OpenSSL 1.1.1+ with non-blocking
78 82 my $ssl_mode_release_buffers = 0; # SSL_MODE_RELEASE_BUFFERS if available
79 82 my $can_ciphersuites; # support for SSL_CTX_set_ciphersuites (TLS 1.3)
80  
81 my $openssl_version;
82 82 my $netssleay_version;
83  
84 BEGIN {
85 82 ▶ $openssl_version = Net::SSLeay::OPENSSL_VERSION_NUMBER();
Subroutine BEGIN: called CC=24 SCAR=40.5
86 82 ▶ $netssleay_version = do { no warnings; $Net::SSLeay::VERSION + 0.0; };
Subroutine BEGIN: called CC=1 SCAR=0.0
87 82 $can_client_sni = $openssl_version >= 0x10000000;
88 82 $can_server_sni = defined &Net::SSLeay::get_servername;
89 82 ▶ $can_npn = defined &Net::SSLeay::P_next_proto_negotiated &&
Condition33%1/3
defined &Net::SSLeay::P_next_proto_negotiated && !&Net::SSLeay::constant('LIBRESSL_VERSION_NUMBER')
!ll&&!rl&&r
0082
MC/DC0%0/2
defined &Net::SSLeay::P_next_proto_negotiated && !&Net::SSLeay::constant('LIBRESSL_VERSION_NUMBER')
defined &Net::SSLeay::P_next_proto_negotiated !&Net::SSLeay::constant('LIBRESSL_VERSION_NUMBER')
Truth table33%1/3
A && not(B)
A= defined &Net::SSLeay::P_next_proto_negotiatedB= !&Net::SSLeay::constant('LIBRESSL_VERSION_NUMBER')
ABresult
0X0
100
111
90 ! Net::SSLeay::constant("LIBRESSL_VERSION_NUMBER");
91 # LibreSSL 2.6.1 disabled NPN by keeping the relevant functions
92 # available but removed the actual functionality from these functions.
93 82 $can_alpn = defined &Net::SSLeay::CTX_set_alpn_protos;
94 82 ▶ $can_ecdh =
Branch: 3 branches
BranchTrueFalseTotal
$openssl_version >= 269484047 ? : 82 0 82
defined &Net::SSLeay::CTX_set_ecdh_auto ? : 0 0 0
defined &Net::SSLeay::CTX_set_tmp_ecdh && ($openssl_version != 268439631 || length pack('P', 0) == 4) ? : 0 0 0
Condition0%0/6
defined &Net::SSLeay::CTX_set_tmp_ecdh and $openssl_version != 268439631 || length pack("P", 0) == 4
!ll&&!rl&&r
000
$openssl_version != 268439631 or length pack("P", 0) == 4
l!l&&r!l&&!r
000
MC/DC0%0/3
defined &Net::SSLeay::CTX_set_tmp_ecdh and $openssl_version != 268439631 || length pack("P", 0) == 4
defined &Net::SSLeay::CTX_set_tmp_ecdh $openssl_version != 268439631 length pack("P", 0) == 4
Truth table0%0/4
A and B or C
A= defined &Net::SSLeay::CTX_set_tmp_ecdhB= $openssl_version != 268439631C= length pack("P", 0) == 4
ABCresult
0XX0
1000
11X1
1011
95 ($openssl_version >= 0x1010000f) ? 'auto' :
96 defined(&Net::SSLeay::CTX_set_ecdh_auto) ? 'can_auto' :
97 (defined &Net::SSLeay::CTX_set_tmp_ecdh &&
98 # There is a regression with elliptic curves on 1.0.1d with 64bit
99 # http://rt.openssl.org/Ticket/Display.html?id=2975
100 ( $openssl_version != 0x1000104f
101 || length(pack("P",0)) == 4 )) ? 'tmp_ecdh' :
102 '';
103 82 ▶ $set_groups_list =
Branch: 2 branches
BranchTrueFalseTotal
defined &Net::SSLeay::CTX_set1_groups_list ? : 82 0 82
defined &Net::SSLeay::CTX_set1_curves_list ? : 0 0 0
104 defined &Net::SSLeay::CTX_set1_groups_list ? \&Net::SSLeay::CTX_set1_groups_list :
105 defined &Net::SSLeay::CTX_set1_curves_list ? \&Net::SSLeay::CTX_set1_curves_list :
106 undef;
107 82 ▶ $can_multi_cert = $can_ecdh
Condition33%1/3
$can_ecdh && $openssl_version >= 268443648
!ll&&!rl&&r
0082
MC/DC0%0/2
$can_ecdh && $openssl_version >= 268443648
$can_ecdh $openssl_version >= 268443648
Truth table33%1/3
A && B
A= $can_ecdhB= $openssl_version >= 268443648
ABresult
0X0
100
111
108 && $openssl_version >= 0x10002000;
109 82 ▶ $can_ocsp = defined &Net::SSLeay::OCSP_cert2ids
Condition33%2/6
defined &Net::SSLeay::OCSP_cert2ids && ($netssleay_version < 1.75 || $netssleay_version > 1.77)
!ll&&!rl&&r
0082
$netssleay_version < "1.75" or $netssleay_version > "1.77"
l!l&&r!l&&!r
0820
MC/DC0%0/3
defined &Net::SSLeay::OCSP_cert2ids && ($netssleay_version < 1.75 || $netssleay_version > 1.77)
defined &Net::SSLeay::OCSP_cert2ids $netssleay_version < "1.75" $netssleay_version > "1.77"
Truth table25%1/4
A && B or C
A= defined &Net::SSLeay::OCSP_cert2idsB= $netssleay_version < "1.75"C= $netssleay_version > "1.77"
ABCresult
0XX0
1000
11X1
1011
110 # OCSP got broken in 1.75..1.77
111 && ($netssleay_version < 1.75 || $netssleay_version > 1.77);
112 82 ▶ $can_ocsp_staple = $can_ocsp
Condition33%1/3
$can_ocsp && defined &Net::SSLeay::set_tlsext_status_type
!ll&&!rl&&r
0082
MC/DC0%0/2
$can_ocsp && defined &Net::SSLeay::set_tlsext_status_type
$can_ocsp defined &Net::SSLeay::set_tlsext_status_type
Truth table33%1/3
A && B
A= $can_ocspB= defined &Net::SSLeay::set_tlsext_status_type
ABresult
0X0
100
111
113 && defined &Net::SSLeay::set_tlsext_status_type;
114 82 ▶ $can_tckt_keycb = defined &Net::SSLeay::CTX_set_tlsext_ticket_getkey_cb
Condition33%1/3
defined &Net::SSLeay::CTX_set_tlsext_ticket_getkey_cb && $netssleay_version >= 1.8
!ll&&!rl&&r
0082
MC/DC0%0/2
defined &Net::SSLeay::CTX_set_tlsext_ticket_getkey_cb && $netssleay_version >= 1.8
defined &Net::SSLeay::CTX_set_tlsext_ticket_getkey_cb $netssleay_version >= 1.8
Truth table33%1/3
A && B
A= defined &Net::SSLeay::CTX_set_tlsext_ticket_getkey_cbB= $netssleay_version >= 1.8
ABresult
0X0
100
111
115 && $netssleay_version >= 1.80;
116 82 $can_pha = defined &Net::SSLeay::CTX_set_post_handshake_auth;
117 82 $can_ciphersuites = defined &Net::SSLeay::CTX_set_ciphersuites;
118  
119 82 ▶ if (defined &Net::SSLeay::SESSION_up_ref) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined &Net::SSLeay::SESSION_up_ref) 82 0 82
120 82 $session_upref = 1;
121 }
122  
123 82 ▶ if ($session_upref
Branch: 1 branch
BranchTrueFalseTotal
if ($session_upref and defined &Net::SSLeay::CTX_sess_set_new_cb and defined &Net::SSLeay::CTX_sess_set_remove_cb) 82 0 82
Condition33%2/6
$session_upref and defined &Net::SSLeay::CTX_sess_set_new_cb and defined &Net::SSLeay::CTX_sess_set_remove_cb
!ll&&!rl&&r
0082
$session_upref and defined &Net::SSLeay::CTX_sess_set_new_cb
!ll&&!rl&&r
0082
MC/DC0%0/3
$session_upref and defined &Net::SSLeay::CTX_sess_set_new_cb and defined &Net::SSLeay::CTX_sess_set_remove_cb
$session_upref defined &Net::SSLeay::CTX_sess_set_new_cb defined &Net::SSLeay::CTX_sess_set_remove_cb
Truth table25%1/4
A and B and C
A= $session_uprefB= defined &Net::SSLeay::CTX_sess_set_new_cbC= defined &Net::SSLeay::CTX_sess_set_remove_cb
ABCresult
0XX0
10X0
1100
1111
124 && defined &Net::SSLeay::CTX_sess_set_new_cb
125 && defined &Net::SSLeay::CTX_sess_set_remove_cb) {
126 82 %sess_cb = (
127 new => \&Net::SSLeay::CTX_sess_set_new_cb,
128 remove => \&Net::SSLeay::CTX_sess_set_remove_cb,
129 );
130 }
131  
132 82 ▶ if (my $c = defined &Net::SSLeay::CTX_get0_param
Branch: 1 branch
BranchTrueFalseTotal
if (my $c = defined &Net::SSLeay::CTX_get0_param && eval { do { Net::SSLeay::X509_V_FLAG_PARTIAL_CHAIN() } }) 82 0 82
Condition33%1/3
defined &Net::SSLeay::CTX_get0_param && eval { do { Net::SSLeay::X509_V_FLAG_PARTIAL_CHAIN() } }
!ll&&!rl&&r
0082
MC/DC0%0/2
defined &Net::SSLeay::CTX_get0_param && eval { do { Net::SSLeay::X509_V_FLAG_PARTIAL_CHAIN() } }
defined &Net::SSLeay::CTX_get0_param eval { do { Net::SSLeay::X509_V_FLAG_PARTIAL_CHAIN() } }
Truth table33%1/3
A && B
A= defined &Net::SSLeay::CTX_get0_paramB= eval { do { Net::SSLeay::X509_V_FLAG_PARTIAL_CHAIN() } }
ABresult
0X0
100
111
133 82 && eval { Net::SSLeay::X509_V_FLAG_PARTIAL_CHAIN() }) {
134 $check_partial_chain = sub {
135 266 ▶ my $ctx = shift;
Subroutine __ANON__: called CC=1 SCAR=0.0
136 266 my $param = Net::SSLeay::CTX_get0_param($ctx);
137 266 Net::SSLeay::X509_VERIFY_PARAM_set_flags($param, $c);
138 82 };
139 }
140  
141 82 ▶ if (!defined &Net::SSLeay::clear_mode) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined &Net::SSLeay::clear_mode) 82 0 82
142 # assume SSL_CTRL_CLEAR_MODE being 78 since it was always this way
143 *Net::SSLeay::clear_mode = sub {
144 37 ▶ my ($ctx,$opt) = @_;
Subroutine __ANON__: called CC=1 SCAR=0.0
145 37 Net::SSLeay::ctrl($ctx,78,$opt,0);
146 82 };
147 }
148  
149 82 ▶ if ($openssl_version >= 0x10101000) {
Branch: 1 branch
BranchTrueFalseTotal
if ($openssl_version >= 269488128) 82 0 82
150 # openssl 1.1.1 enabled SSL_MODE_AUTO_RETRY by default, which is bad for
151 # non-blocking sockets
152 my $mode_auto_retry =
153 # was always 0x00000004
154 82 ▶ eval { Net::SSLeay::MODE_AUTO_RETRY() } || 0x00000004;
Condition50%1/2
eval { do { Net::SSLeay::MODE_AUTO_RETRY() } } || 4
l!l
820
MC/DC0%0/1
eval { do { Net::SSLeay::MODE_AUTO_RETRY() } } || 4
eval { do { Net::SSLeay::MODE_AUTO_RETRY() } }
Truth table50%1/2
A
A= eval { do { Net::SSLeay::MODE_AUTO_RETRY() } }
Aresult
11
00
155 $auto_retry = sub {
156 334 ▶ my ($ssl,$on) = @_;
Subroutine __ANON__: called CC=2 SCAR=6.9
157 334 ▶ if ($on) {
Branch: 1 branch
BranchTrueFalseTotal
if ($on) { } 297 37 334
158 297 Net::SSLeay::set_mode($ssl, $mode_auto_retry);
159 } else {
160 37 Net::SSLeay::clear_mode($ssl, $mode_auto_retry);
161 }
162 }
163 82 }
164 82 ▶ if ($openssl_version >= 0x10000000) {
Branch: 1 branch
BranchTrueFalseTotal
if ($openssl_version >= 268435456) 82 0 82
165 # ssl/ssl.h:#define SSL_MODE_RELEASE_BUFFERS 0x00000010L
166 82 $ssl_mode_release_buffers = 0x00000010;
167 }
168 }
169  
170 82 my $algo2digest = do {
171 82 my %digest;
172 sub {
173 31 ▶ my $digest_name = shift;
Subroutine __ANON__: called CC=3 SCAR=11.3
174 31 ▶ return $digest{$digest_name} ||= do {
Condition66%2/3
$digest{$digest_name} ||= do { &Net::SSLeay::SSLeay_add_ssl_algorithms(); &Net::SSLeay::EVP_get_digestbyname($digest_name) or die "Digest algorithm $digest_name is not available" }
l!l&&r!l&&!r
2560
MC/DC0%0/2
$digest{$digest_name} ||= do { &Net::SSLeay::SSLeay_add_ssl_algorithms(); &Net::SSLeay::EVP_get_digestbyname($digest_name) or die "Digest algorithm $digest_name is not available" }
$digest{$digest_name} do { &Net::SSLeay::SSLeay_add_ssl_algorithms(); &Net::SSLeay::EVP_get_digestbyname($digest_name) or die "Digest algorithm $digest_name is not available" }
Truth table66%2/3
A ||= B
A= $digest{$digest_name}B= do { &Net::SSLeay::SSLeay_add_ssl_algorithms(); &Net::SSLeay::EVP_get_digestbyname($digest_name) or die "Digest algorithm $digest_name is not available" }
ABresult
1X1
011
000
175 6 Net::SSLeay::SSLeay_add_ssl_algorithms();
176 6 ▶ Net::SSLeay::EVP_get_digestbyname($digest_name)
Branch: 1 branch
BranchTrueFalseTotal
&Net::SSLeay::EVP_get_digestbyname($digest_name) or die "Digest algorithm $digest_name is not available" 0 6 6
177 or die "Digest algorithm $digest_name is not available";
178 };
179 }
180 82 };
181  
182 82 my $CTX_tlsv1_3_new;
183 82 ▶if ( defined &Net::SSLeay::CTX_set_min_proto_version
Branch: 1 branch
BranchTrueFalseTotal
if (defined &Net::SSLeay::CTX_set_min_proto_version and defined &Net::SSLeay::CTX_set_max_proto_version and my $tls13 = eval { do { Net::SSLeay::TLS1_3_VERSION() } }) 82 0 82
Condition33%2/6
defined &Net::SSLeay::CTX_set_min_proto_version and defined &Net::SSLeay::CTX_set_max_proto_version and my $tls13 = eval { do { Net::SSLeay::TLS1_3_VERSION() } }
!ll&&!rl&&r
0082
defined &Net::SSLeay::CTX_set_min_proto_version and defined &Net::SSLeay::CTX_set_max_proto_version
!ll&&!rl&&r
0082
MC/DC0%0/3
defined &Net::SSLeay::CTX_set_min_proto_version and defined &Net::SSLeay::CTX_set_max_proto_version and my $tls13 = eval { do { Net::SSLeay::TLS1_3_VERSION() } }
defined &Net::SSLeay::CTX_set_min_proto_version defined &Net::SSLeay::CTX_set_max_proto_version my $tls13 = eval { do { Net::SSLeay::TLS1_3_VERSION() } }
Truth table0%0/4
A and B and C
A= defined &Net::SSLeay::CTX_set_min_proto_versionB= defined &Net::SSLeay::CTX_set_max_proto_versionC= my $tls13 = eval { do { Net::SSLeay::TLS1_3_VERSION() } }
ABCresult
0XX0
10X0
1100
1111
184 and defined &Net::SSLeay::CTX_set_max_proto_version
185 82 and my $tls13 = eval { Net::SSLeay::TLS1_3_VERSION() }
186 ) {
187 $CTX_tlsv1_3_new = sub {
188 2 ▶ my $ctx = Net::SSLeay::CTX_new();
Subroutine __ANON__: called CC=3 SCAR=15.1
189 2 ▶ return $ctx if Net::SSLeay::CTX_set_min_proto_version($ctx,$tls13)
Branch: 1 branch
BranchTrueFalseTotal
if &Net::SSLeay::CTX_set_min_proto_version($ctx, $tls13) and &Net::SSLeay::CTX_set_max_proto_version($ctx, $tls13) 2 0 2
Condition33%1/3
&Net::SSLeay::CTX_set_min_proto_version($ctx, $tls13) and &Net::SSLeay::CTX_set_max_proto_version($ctx, $tls13)
!ll&&!rl&&r
002
MC/DC0%0/2
&Net::SSLeay::CTX_set_min_proto_version($ctx, $tls13) and &Net::SSLeay::CTX_set_max_proto_version($ctx, $tls13)
&Net::SSLeay::CTX_set_min_proto_version($ctx, $tls13) &Net::SSLeay::CTX_set_max_proto_version($ctx, $tls13)
Truth table33%1/3
A and B
A= &Net::SSLeay::CTX_set_min_proto_version($ctx, $tls13)B= &Net::SSLeay::CTX_set_max_proto_version($ctx, $tls13)
ABresult
0X0
100
111
190 && Net::SSLeay::CTX_set_max_proto_version($ctx,$tls13);
191 0 Net::SSLeay::CTX_free($ctx);
192 0 return;
193 82 };
194 }
195  
196 # global defaults
197 82 my %DEFAULT_SSL_ARGS = (
198 SSL_check_crl => 0,
199 # TLS 1.1 and lower are deprecated with RFC 8996
200 SSL_version => 'SSLv23:!TLSv1:!TLSv1_1:!SSLv3:!SSLv2',
201 SSL_verify_callback => undef,
202 SSL_verifycn_scheme => undef, # fallback cn verification
203 SSL_verifycn_publicsuffix => undef, # fallback default list verification
204 #SSL_verifycn_name => undef, # use from PeerAddr/PeerHost - do not override in set_args_filter_hack 'use_defaults'
205 SSL_npn_protocols => undef, # meaning depends whether on server or client side
206 SSL_alpn_protocols => undef, # list of protocols we'll accept/send, for example ['http/1.1','spdy/3.1']
207  
208 # rely on system default but be sure to disable some definitely bad ones
209 SSL_cipher_list => 'DEFAULT !EXP !MEDIUM !LOW !eNULL !aNULL !RC4 !DES !MD5 !PSK !SRP',
210 );
211  
212 82 my %DEFAULT_SSL_CLIENT_ARGS = (
213 %DEFAULT_SSL_ARGS,
214 SSL_verify_mode => SSL_VERIFY_PEER,
215  
216 SSL_ca_file => undef,
217 SSL_ca_path => undef,
218 );
219  
220 # set values inside _init to work with perlcc, RT#95452
221 82 my %DEFAULT_SSL_SERVER_ARGS;
222  
223 # Initialization of OpenSSL internals
224 # This will be called once during compilation - perlcc users might need to
225 # call it again by hand, see RT#95452
226 {
227 82 sub init {
228 # library_init returns false if the library was already initialized.
229 # This way we can find out if the library needs to be re-initialized
230 # inside code compiled with perlcc
231 163 ▶ Net::SSLeay::library_init() or return;
Subroutine init: called CC=6 SCAR=19.2
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
&Net::SSLeay::library_init() or return 81 82 163
232  
233 82 Net::SSLeay::load_error_strings();
234 82 Net::SSLeay::OpenSSL_add_all_digests();
235 82 Net::SSLeay::randomize();
236  
237 %DEFAULT_SSL_SERVER_ARGS = (
238 %DEFAULT_SSL_ARGS,
239 SSL_verify_mode => SSL_VERIFY_NONE,
240 SSL_honor_cipher_order => 1, # trust server to know the best cipher
241 82 SSL_dh => do {
242 82 my $bio = Net::SSLeay::BIO_new(Net::SSLeay::BIO_s_mem());
243 # generated with: openssl dhparam 2048
244 82 Net::SSLeay::BIO_write($bio,<<'DH');
245 -----BEGIN DH PARAMETERS-----
246 MIIBCAKCAQEAr8wskArj5+1VCVsnWt/RUR7tXkHJ7mGW7XxrLSPOaFyKyWf8lZht
247 iSY2Lc4oa4Zw8wibGQ3faeQu/s8fvPq/aqTxYmyHPKCMoze77QJHtrYtJAosB9SY
248 CN7s5Hexxb5/vQ4qlQuOkVrZDiZO9GC4KaH9mJYnCoAsXDhDft6JT0oRVSgtZQnU
249 gWFKShIm+JVjN94kGs0TcBEesPTK2g8XVHK9H8AtSUb9BwW2qD/T5RmgNABysApO
250 Ps2vlkxjAHjJcqc3O+OiImKik/X2rtBTZjpKmzN3WWTB0RJZCOWaLlDO81D01o1E
251 aZecz3Np9KIYey900f+X7zC2bJxEHp95ywIBAg==
252 -----END DH PARAMETERS-----
253 DH
254 82 my $dh = Net::SSLeay::PEM_read_bio_DHparams($bio);
255 82 Net::SSLeay::BIO_free($bio);
256 82 ▶ $dh or die "no DH";
Branch: 1 branch
BranchTrueFalseTotal
$dh or die "no DH" 0 82 82
257 82 ▶ $dh;
Branch: 3 branches
BranchTrueFalseTotal
$can_ecdh eq 'auto' ? : 82 0 82
$can_ecdh eq 'can_auto' ? : 0 0 0
$can_ecdh eq 'tmp_ecdh' ? : 0 0 0
258 },
259 (
260 $can_ecdh eq 'auto' ? () : # automatically enabled by openssl
261 $can_ecdh eq 'can_auto' ? (SSL_ecdh_curve => 'auto') :
262 $can_ecdh eq 'tmp_ecdh' ? ( SSL_ecdh_curve => 'prime256v1' ) :
263 (),
264 )
265 );
266 }
267 # Call it once at compile time and try it at INIT.
268 # This should catch all cases of including the module, e.g. 'use' (INIT) or
269 # 'require' (compile time) and works also with perlcc
270 {
271 82 ▶ no warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
272 81 ▶ INIT { init() }
Subroutine INIT: called CC=1 SCAR=0.0
273 82 init();
274 }
275 }
276  
277 # global defaults which can be changed using set_defaults
278 # either key/value can be set or it can just be set to an external hash
279 82 my $GLOBAL_SSL_ARGS = {};
280 82 my $GLOBAL_SSL_CLIENT_ARGS = {};
281 82 my $GLOBAL_SSL_SERVER_ARGS = {};
282  
283 # hack which is used to filter bad settings from used modules
284 82 my $FILTER_SSL_ARGS = undef;
285  
286 # non-XS Versions of Scalar::Util will fail
287 BEGIN{
288 82 ▶ die "You need the XS Version of Scalar::Util for dualvar() support" if !do {
Subroutine BEGIN: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
if not do { local $SIG{"__DIE__"}; local $SIG{"__WARN__"}; eval { do { &dualvar(0, ""); 1 } } } 0 82 82
289 82 local $SIG{__DIE__}; local $SIG{__WARN__}; # be silent
290 82 ▶ eval { use Scalar::Util 'dualvar'; dualvar(0,''); 1 };
Subroutine BEGIN: called CC=1 SCAR=0.0
291 };
292 }
293  
294 # get constants for SSL_OP_NO_* now, instead calling the related functions
295 # every time we setup a connection
296 82 my %SSL_OP_NO;
297 82 for(qw( SSLv2 SSLv3 TLSv1 TLSv1_1 TLSv11:TLSv1_1 TLSv1_2 TLSv12:TLSv1_2
298 TLSv1_3 TLSv13:TLSv1_3 )) {
299 738 ▶ my ($k,$op) = m{:} ? split(m{:},$_,2) : ($_,$_);
Branch: 1 branch
BranchTrueFalseTotal
/:/ ? : 246 492 738
300 738 my $sub = "Net::SSLeay::OP_NO_$op";
301 738 local $SIG{__DIE__};
302 82 ▶ $SSL_OP_NO{$k} = eval { no strict 'refs'; &$sub } || 0;
Subroutine BEGIN: called CC=1 SCAR=0.0
Condition100%2/2
eval { do { no strict 'refs'; &$sub } } || 0
l!l
65682
MC/DC100%1/1
eval { do { no strict 'refs'; &$sub } } || 0
eval { do { no strict 'refs'; &$sub } }
Truth table100%2/2
A
A= eval { do { no strict 'refs'; &$sub } }
Aresult
11
00
303 }
304  
305 # Make SSL_CTX_clear_options accessible through SSL_CTX_ctrl unless it is
306 # already implemented in Net::SSLeay
307 82 ▶if (!defined &Net::SSLeay::CTX_clear_options) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined &Net::SSLeay::CTX_clear_options) 82 0 82
308 *Net::SSLeay::CTX_clear_options = sub {
309 20 ▶ my ($ctx,$opt) = @_;
Subroutine __ANON__: called CC=1 SCAR=0.0
310 # 77 = SSL_CTRL_CLEAR_OPTIONS
311 20 Net::SSLeay::CTX_ctrl($ctx,77,$opt,0);
312 82 };
313 }
314  
315 # Try to work around problems with alternative trust path by default, RT#104759
316 82 my $DEFAULT_X509_STORE_flags = 0;
317 {
318 82 local $SIG{__DIE__};
319 82 eval { $DEFAULT_X509_STORE_flags |= Net::SSLeay::X509_V_FLAG_TRUSTED_FIRST() };
320 }
321  
322 82 our $DEBUG;
323 82 ▶use vars qw(@ISA $SSL_ERROR @EXPORT);
Subroutine BEGIN: called CC=1 SCAR=0.0
324  
325 {
326 # These constants will be used in $! at return from SSL_connect,
327 # SSL_accept, _generic_(read|write), thus notifying the caller
328 # the usual way of problems. Like with EWOULDBLOCK, EINPROGRESS..
329 # these are especially important for non-blocking sockets
330  
331 82 my $x = $Net_SSLeay_ERROR_WANT_READ;
332 82 ▶ use constant SSL_WANT_READ => dualvar( \$x, 'SSL wants a read first' );
Subroutine BEGIN: called CC=1 SCAR=0.0
333 82 my $y = $Net_SSLeay_ERROR_WANT_WRITE;
334 82 ▶ use constant SSL_WANT_WRITE => dualvar( \$y, 'SSL wants a write first' );
Subroutine BEGIN: called CC=1 SCAR=0.0
335  
336 82 @EXPORT = qw(
337 SSL_WANT_READ SSL_WANT_WRITE SSL_VERIFY_NONE SSL_VERIFY_PEER
338 SSL_VERIFY_FAIL_IF_NO_PEER_CERT SSL_VERIFY_CLIENT_ONCE
339 SSL_OCSP_NO_STAPLE SSL_OCSP_TRY_STAPLE SSL_OCSP_MUST_STAPLE
340 SSL_OCSP_FAIL_HARD SSL_OCSP_FULL_CHAIN
341 $SSL_ERROR GEN_DNS GEN_IPADD
342 );
343 }
344  
345 82 my @caller_force_inet4; # in case inet4 gets forced we store here who forced it
346  
347 my $IOCLASS;
348 82 my $family_key; # 'Domain'||'Family'
349 BEGIN {
350 # declare @ISA depending of the installed socket class
351  
352 # try to load inet_pton from Socket or Socket6 and make sure it is usable
353 82 ▶ local $SIG{__DIE__}; local $SIG{__WARN__}; # be silent
Subroutine BEGIN: called CC=12 SCAR=32.2
354 my $ip6 = eval {
355 82 require Socket;
356 82 Socket->VERSION(1.95);
357 82 ▶ Socket::inet_pton( AF_INET6(),'::1') && AF_INET6() or die;
Branch: 1 branch
BranchTrueFalseTotal
Socket::inet_pton(10, "::1") and 10 or die 0 82 82
Condition50%1/2
Socket::inet_pton(10, "::1") and 10
!ll
082
MC/DC0%0/1
Socket::inet_pton(10, "::1") and 10
Socket::inet_pton(10, "::1")
Truth table50%1/2
A
A= Socket::inet_pton(10, "::1")
Aresult
00
11
358 82 Socket->import( qw/inet_pton NI_NUMERICHOST NI_NUMERICSERV/ );
359 # behavior different to Socket6::getnameinfo - wrap
360 *_getnameinfo = sub {
361 0 ▶ my ($err,$host,$port) = Socket::getnameinfo(@_) or return;
Subroutine __ANON__: not called CC=3 SCAR=24.8
Branch: 1 branch
BranchTrueFalseTotal
() = Socket::getnameinfo(@_) or return 0 0 0
362 0 ▶ return if $err;
Branch: 1 branch
BranchTrueFalseTotal
if $err 0 0 0
363 0 return ($host,$port);
364 82 };
365 82 'Socket';
366 82 ▶ } || eval {
Condition40%2/5
eval { do { require Socket; 'Socket'->VERSION(1.95); Socket::inet_pton(10, '::1') and 10 or die; 'Socket'->import('inet_pton', 'NI_NUMERICHOST', 'NI_NUMERICSERV'); *_getnameinfo = sub { my($err, $host, $port) = Socket::getnameinfo(@_) or return; return if $err; return $host, $port; } ; 'Socket' } } || eval { do { require Socket6; Socket6::inet_pton(10, '::1') and 10 or die; 'Socket6'->import('inet_pton', 'NI_NUMERICHOST', 'NI_NUMERICSERV'); *_getnameinfo = sub { return Socket6::getnameinfo(@_); } ; 'Socket6' } } || undef
l!l
820
eval { do { require Socket; "Socket"->VERSION("1.95"); Socket::inet_pton(10, "::1") and 10 or die; "Socket"->import("inet_pton", "NI_NUMERICHOST", "NI_NUMERICSERV"); *_getnameinfo = sub { my($err, $host, $port) = Socket::getnameinfo(@_) or return; return if $err; return $host, $port; } ; "Socket" } } or eval { do { require Socket6; Socket6::inet_pton(10, "::1") and 10 or die; "Socket6"->import("inet_pton", "NI_NUMERICHOST", "NI_NUMERICSERV"); *_getnameinfo = sub { return Socket6::getnameinfo(@_); } ; "Socket6" } }
l!l&&r!l&&!r
8200
MC/DC0%0/2
eval { do { require Socket; 'Socket'->VERSION(1.95); Socket::inet_pton(10, '::1') and 10 or die; 'Socket'->import('inet_pton', 'NI_NUMERICHOST', 'NI_NUMERICSERV'); *_getnameinfo = sub { my($err, $host, $port) = Socket::getnameinfo(@_) or return; return if $err; return $host, $port; } ; 'Socket' } } || eval { do { require Socket6; Socket6::inet_pton(10, '::1') and 10 or die; 'Socket6'->import('inet_pton', 'NI_NUMERICHOST', 'NI_NUMERICSERV'); *_getnameinfo = sub { return Socket6::getnameinfo(@_); } ; 'Socket6' } } || undef
eval { do { require Socket; "Socket"->VERSION("1.95"); Socket::inet_pton(10, "::1") and 10 or die; "Socket"->import("inet_pton", "NI_NUMERICHOST", "NI_NUMERICSERV"); *_getnameinfo = sub { my($err, $host, $port) = Socket::getnameinfo(@_) or return; return if $err; return $host, $port; } ; "Socket" } } eval { do { require Socket6; Socket6::inet_pton(10, "::1") and 10 or die; "Socket6"->import("inet_pton", "NI_NUMERICHOST", "NI_NUMERICSERV"); *_getnameinfo = sub { return Socket6::getnameinfo(@_); } ; "Socket6" } }
Truth table33%1/3
A or B
A= eval { do { require Socket; "Socket"->VERSION("1.95"); Socket::inet_pton(10, "::1") and 10 or die; "Socket"->import("inet_pton", "NI_NUMERICHOST", "NI_NUMERICSERV"); *_getnameinfo = sub { my($err, $host, $port) = Socket::getnameinfo(@_) or return; return if $err; return $host, $port; } ; "Socket" } }B= eval { do { require Socket6; Socket6::inet_pton(10, "::1") and 10 or die; "Socket6"->import("inet_pton", "NI_NUMERICHOST", "NI_NUMERICSERV"); *_getnameinfo = sub { return Socket6::getnameinfo(@_); } ; "Socket6" } }
ABresult
1X1
011
000
367 0 require Socket6;
368 0 ▶ Socket6::inet_pton( AF_INET6(),'::1') && AF_INET6() or die;
Branch: 1 branch
BranchTrueFalseTotal
Socket6::inet_pton(10, "::1") and 10 or die 0 0 0
Condition0%0/2
Socket6::inet_pton(10, "::1") and 10
!ll
00
MC/DC0%0/1
Socket6::inet_pton(10, "::1") and 10
Socket6::inet_pton(10, "::1")
Truth table0%0/2
A
A= Socket6::inet_pton(10, "::1")
Aresult
00
11
369 0 Socket6->import( qw/inet_pton NI_NUMERICHOST NI_NUMERICSERV/ );
370 # behavior different to Socket::getnameinfo - wrap
371 0 ▶ *_getnameinfo = sub { return Socket6::getnameinfo(@_); };
Subroutine __ANON__: not called CC=1 SCAR=6.9
372 0 'Socket6';
373 } || undef;
374  
375 # try IO::Socket::IP or IO::Socket::INET6 for IPv6 support
376 82 $family_key = 'Domain'; # traditional
377 82 ▶ if ($ip6) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ip6) 82 0 82
378 # if we have IO::Socket::IP >= 0.31 we will use this in preference
379 # because it can handle both IPv4 and IPv6
380 82 ▶ if ( eval {
Branch: 2 branches
BranchTrueFalseTotal
if (eval { do { require IO::Socket::IP; 'IO::Socket::IP'->VERSION(0.31) } }) { } 81 1 82
elsif (eval { do { require IO::Socket::INET6; 'IO::Socket::INET6'->VERSION(2.62) } }) { } 0 1 1
381 82 require IO::Socket::IP;
382 81 IO::Socket::IP->VERSION(0.31)
383 }) {
384 81 @ISA = qw(IO::Socket::IP);
385 81 constant->import( CAN_IPV6 => "IO::Socket::IP" );
386 81 $family_key = 'Family';
387 81 $IOCLASS = "IO::Socket::IP";
388  
389 # if we have IO::Socket::INET6 we will use this not IO::Socket::INET
390 # because it can handle both IPv4 and IPv6
391 # require at least 2.62 because of several problems before that version
392 1 } elsif( eval { require IO::Socket::INET6; IO::Socket::INET6->VERSION(2.62) } ) {
393 0 @ISA = qw(IO::Socket::INET6);
394 0 constant->import( CAN_IPV6 => "IO::Socket::INET6" );
395 0 $IOCLASS = "IO::Socket::INET6";
396 } else {
397 1 $ip6 = ''
398 }
399 }
400  
401 # fall back to IO::Socket::INET for IPv4 only
402 82 ▶ if (!$ip6) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ip6) 1 81 82
403 1 @ISA = qw(IO::Socket::INET);
404 1 $IOCLASS = "IO::Socket::INET";
405 1 constant->import(CAN_IPV6 => '');
406 1 ▶ if (!defined $ip6) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $ip6) 0 1 1
407 0 constant->import(NI_NUMERICHOST => 1);
408 0 constant->import(NI_NUMERICSERV => 2);
409 }
410 }
411  
412 #Make $DEBUG another name for $Net::SSLeay::trace
413 82 *DEBUG = \$Net::SSLeay::trace;
414  
415 #Compatibility
416 82 *ERROR = \$SSL_ERROR;
417 }
418  
419  
420 sub DEBUG {
421 0 ▶ $DEBUG or return;
Subroutine DEBUG: not called CC=6 SCAR=37.4
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
$IO::Socket::SSL::DEBUG or return 0 0 0
422 0 my (undef,$file,$line,$sub) = caller(1);
423 0 ▶ if ($sub =~m{^IO::Socket::SSL::(?:error|(_internal_error))$}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sub =~ /^IO::Socket::SSL::(?:error|(_internal_error))$/) { } 0 0 0
424 0 ▶ (undef,$file,$line) = caller(2) if $1;
Branch: 1 branch
BranchTrueFalseTotal
if $1 0 0 0
425 } else {
426 0 (undef,$file,$line) = caller;
427 }
428 0 my $msg = shift;
429 0 ▶ $file = '...'.substr( $file,-17 ) if length($file)>20;
Branch: 1 branch
BranchTrueFalseTotal
if length $file > 20 0 0 0
430 0 ▶ $msg = sprintf $msg,@_ if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
431 0 print STDERR "DEBUG: $file:$line: $msg\n";
432 }
433  
434 BEGIN {
435 # import some constants from Net::SSLeay or use hard-coded defaults
436 # if Net::SSLeay isn't recent enough to provide the constants
437 82 ▶ my %const = (
Subroutine BEGIN: called CC=3 SCAR=11.1
438 NID_CommonName => 13,
439 GEN_DNS => 2,
440 GEN_IPADD => 7,
441 );
442 82 ▶ while ( my ($name,$value) = each %const ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %const) 246 82 328
443 82 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
444 246 ▶ *{$name} = UNIVERSAL::can( 'Net::SSLeay', $name ) || sub { $value };
Subroutine __ANON__: called CC=1 SCAR=0.4
Condition33%1/3
UNIVERSAL::can('Net::SSLeay', $name) || sub { $value; }
l!l&&r!l&&!r
02460
MC/DC0%0/2
UNIVERSAL::can('Net::SSLeay', $name) || sub { $value; }
UNIVERSAL::can('Net::SSLeay', $name) sub { $value; }
Truth table33%1/3
A || B
A= UNIVERSAL::can('Net::SSLeay', $name)B= sub { $value; }
ABresult
1X1
011
000
445 }
446  
447 82 *idn_to_ascii = \&IO::Socket::SSL::PublicSuffix::idn_to_ascii;
448 82 *idn_to_unicode = \&IO::Socket::SSL::PublicSuffix::idn_to_unicode;
449 }
450  
451 82 ▶my $OPENSSL_LIST_SEPARATOR = $^O =~m{^(?:(dos|os2|mswin32|netware)|vms)$}i
Branch: 2 branches
BranchTrueFalseTotal
$^O =~ /^(?:(dos|os2|mswin32|netware)|vms)$/i ? : 0 82 82
$1 ? : 0 0 0
452 ? $1 ? ';' : ',' : ':';
453 my $CHECK_SSL_PATH = sub {
454 31 ▶ my %args = (@_ == 1) ? ('',@_) : @_;
Subroutine __ANON__: called CC=17 SCAR=43.0
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 ? : 3 28 31
455 31 for my $type (keys %args) {
456 31 my $path = $args{$type};
457 31 ▶ if (!$type) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($type) 3 28 31
458 3 delete $args{$type};
459 3 ▶ $type = (ref($path) || -d $path) ? 'SSL_ca_path' : 'SSL_ca_file';
Branch: 1 branch
BranchTrueFalseTotal
ref $path || -d $path ? : 0 3 3
Condition33%1/3
ref $path or -d $path
l!l&&r!l&&!r
003
MC/DC0%0/2
ref $path or -d $path
ref $path -d $path
Truth table33%1/3
A or B
A= ref $pathB= -d $path
ABresult
1X1
011
000
460 3 $args{$type} = $path;
461 }
462  
463 31 ▶ next if ref($path) eq 'SCALAR' && ! $$path;
Branch: 1 branch
BranchTrueFalseTotal
if ref $path eq "SCALAR" and not $$path 0 31 31
Condition33%1/3
ref $path eq "SCALAR" and not $$path
!ll&&!rl&&r
3100
MC/DC0%0/2
ref $path eq "SCALAR" and not $$path
ref $path eq "SCALAR" not $$path
Truth table33%1/3
A and not(B)
A= ref $path eq "SCALAR"B= not $$path
ABresult
0X0
100
111
464 31 ▶ if ($type eq 'SSL_ca_file') {
Branch: 2 branches
BranchTrueFalseTotal
if ($type eq 'SSL_ca_file') { } 31 0 31
elsif ($type eq 'SSL_ca_path') { } 0 0 0
465 31 ▶ die "SSL_ca_file $path can't be used: $!"
Branch: 1 branch
BranchTrueFalseTotal
unless open my $fh, "<", $path 0 31 31
466 if ! open(my $fh,'<',$path);
467 } elsif ($type eq 'SSL_ca_path') {
468 0 ▶ $path = [ split($OPENSSL_LIST_SEPARATOR,$path) ] if !ref($path);
Branch: 1 branch
BranchTrueFalseTotal
unless ref $path 0 0 0
469 0 my @err;
470 0 ▶ for my $d (ref($path) ? @$path : $path) {
Branch: 1 branch
BranchTrueFalseTotal
ref $path ? : 0 0 0
471 0 ▶ if (! -d $d) {
Branch: 2 branches
BranchTrueFalseTotal
if (not -d $d) { } 0 0 0
elsif (not opendir(my $dh, $d)) { } 0 0 0
472 0 push @err, "SSL_ca_path $d does not exist";
473 } elsif (! opendir(my $dh,$d)) {
474 0 push @err, "SSL_ca_path $d is not accessible: $!"
475 } else {
476 0 @err = ();
477 last
478 0 }
479 }
480 0 ▶ die "@err" if @err;
Branch: 1 branch
BranchTrueFalseTotal
if @err 0 0 0
481 }
482 }
483 31 return %args;
484 82 };
485  
486  
487 {
488 82 my %default_ca;
489 my $ca_detected; # 0: never detect, undef: need to (re)detect
490 82 my $openssldir;
491  
492 sub default_ca {
493 155 ▶ if (@_) {
Subroutine default_ca: called CC=22 SCAR=39.1
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 3 152 155
494 # user defined default CA or reset
495 3 ▶ if ( @_ > 1 ) {
Branch: 2 branches
BranchTrueFalseTotal
if (@_ > 1) { } 0 3 3
elsif (my $path = shift()) { } 3 0 3
496 0 %default_ca = @_;
497 0 $ca_detected = 0;
498 } elsif ( my $path = shift ) {
499 3 %default_ca = $CHECK_SSL_PATH->($path);
500 3 $ca_detected = 0;
501 } else {
502 0 $ca_detected = undef;
503 }
504 }
505 155 ▶ return %default_ca if defined $ca_detected;
Branch: 1 branch
BranchTrueFalseTotal
if defined $ca_detected 108 47 155
506  
507 # SSLEAY_DIR was 5 up to OpenSSL 1.1, then switched to 4 and got
508 # renamed to OPENSSL_DIR. Unfortunately it is not exported as constant
509 # by Net::SSLeay so we use the fixed number.
510 47 ▶ $openssldir ||=
Branch: 2 branches
BranchTrueFalseTotal
&Net::SSLeay::SSLeay_version(5) =~ /^OPENSSLDIR: "(.+)"$/ ? : 0 47 47
&Net::SSLeay::SSLeay_version(4) =~ /^OPENSSLDIR: "(.+)"$/ ? : 47 0 47
Condition33%1/3
$openssldir ||= &Net::SSLeay::SSLeay_version(5) =~ /^OPENSSLDIR: "(.+)"$/ ? $1 : (&Net::SSLeay::SSLeay_version(4) =~ /^OPENSSLDIR: "(.+)"$/ ? $1 : "cannot-determine-openssldir-from-ssleay-version")
l!l&&r!l&&!r
0470
MC/DC0%0/2
$openssldir ||= &Net::SSLeay::SSLeay_version(5) =~ /^OPENSSLDIR: "(.+)"$/ ? $1 : (&Net::SSLeay::SSLeay_version(4) =~ /^OPENSSLDIR: "(.+)"$/ ? $1 : "cannot-determine-openssldir-from-ssleay-version")
$openssldir &Net::SSLeay::SSLeay_version(5) =~ /^OPENSSLDIR: "(.+)"$/ ? $1 : (&Net::SSLeay::SSLeay_version(4) =~ /^OPENSSLDIR: "(.+)"$/ ? $1 : "cannot-determine-openssldir-from-ssleay-version")
Truth table33%1/3
A ||= B
A= $openssldirB= &Net::SSLeay::SSLeay_version(5) =~ /^OPENSSLDIR: "(.+)"$/ ? $1 : (&Net::SSLeay::SSLeay_version(4) =~ /^OPENSSLDIR: "(.+)"$/ ? $1 : "cannot-determine-openssldir-from-ssleay-version")
ABresult
1X1
011
000
511 Net::SSLeay::SSLeay_version(5) =~m{^OPENSSLDIR: "(.+)"$} ? $1 :
512 Net::SSLeay::SSLeay_version(4) =~m{^OPENSSLDIR: "(.+)"$} ? $1 :
513 'cannot-determine-openssldir-from-ssleay-version';
514  
515 # (re)detect according to openssl crypto/cryptlib.h
516 my $dir = $ENV{SSL_CERT_DIR}
517 47 ▶ || ( $^O =~m{vms}i ? "SSLCERTS:":"$openssldir/certs" );
Branch: 1 branch
BranchTrueFalseTotal
$^O =~ /vms/i ? : 0 47 47
Condition33%1/3
$ENV{'SSL_CERT_DIR'} || ($^O =~ /vms/i ? 'SSLCERTS:' : "$openssldir/certs")
l!l&&r!l&&!r
0470
MC/DC0%0/2
$ENV{'SSL_CERT_DIR'} || ($^O =~ /vms/i ? 'SSLCERTS:' : "$openssldir/certs")
$ENV{'SSL_CERT_DIR'} ($^O =~ /vms/i ? 'SSLCERTS:' : "$openssldir/certs")
Truth table33%1/3
A || B
A= $ENV{'SSL_CERT_DIR'}B= ($^O =~ /vms/i ? 'SSLCERTS:' : "$openssldir/certs")
ABresult
1X1
011
000
518 47 ▶ if ( opendir(my $dh,$dir)) {
Branch: 1 branch
BranchTrueFalseTotal
if (opendir my $dh, $dir) 47 0 47
519 47 FILES: for my $f ( grep { m{^[a-f\d]{8}(\.\d+)?$} } readdir($dh) ) {
520 47 ▶ open( my $fh,'<',"$dir/$f") or next;
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<", "$dir/$f" or next 0 47 47
521 47 ▶ while (my $line = <$fh>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $line = CORE::readline $fh)) 47 0 47
522 47 ▶ $line =~m{^-+BEGIN (X509 |TRUSTED |)CERTIFICATE-} or next;
Branch: 1 branch
BranchTrueFalseTotal
$line =~ /^-+BEGIN (X509 |TRUSTED |)CERTIFICATE-/ or next 0 47 47
523 47 $default_ca{SSL_ca_path} = $dir;
524 47 last FILES;
525 }
526 }
527 }
528 my $file = $ENV{SSL_CERT_FILE}
529 47 ▶ || ( $^O =~m{vms}i ? "SSLCERTS:cert.pem":"$openssldir/cert.pem" );
Branch: 1 branch
BranchTrueFalseTotal
$^O =~ /vms/i ? : 0 47 47
Condition33%1/3
$ENV{'SSL_CERT_FILE'} || ($^O =~ /vms/i ? 'SSLCERTS:cert.pem' : "$openssldir/cert.pem")
l!l&&r!l&&!r
0470
MC/DC0%0/2
$ENV{'SSL_CERT_FILE'} || ($^O =~ /vms/i ? 'SSLCERTS:cert.pem' : "$openssldir/cert.pem")
$ENV{'SSL_CERT_FILE'} ($^O =~ /vms/i ? 'SSLCERTS:cert.pem' : "$openssldir/cert.pem")
Truth table33%1/3
A || B
A= $ENV{'SSL_CERT_FILE'}B= ($^O =~ /vms/i ? 'SSLCERTS:cert.pem' : "$openssldir/cert.pem")
ABresult
1X1
011
000
530 47 ▶ if ( open(my $fh,'<',$file)) {
Branch: 1 branch
BranchTrueFalseTotal
if (open my $fh, "<", $file) 47 0 47
531 47 ▶ while (my $line = <$fh>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $line = CORE::readline $fh)) 47 0 47
532 47 ▶ $line =~m{^-+BEGIN (X509 |TRUSTED |)CERTIFICATE-} or next;
Branch: 1 branch
BranchTrueFalseTotal
$line =~ /^-+BEGIN (X509 |TRUSTED |)CERTIFICATE-/ or next 0 47 47
533 47 $default_ca{SSL_ca_file} = $file;
534 47 last;
535 }
536 }
537  
538 47 ▶ $default_ca{SSL_ca_file} = Mozilla::CA::SSL_ca_file() if ! %default_ca && do {
Branch: 1 branch
BranchTrueFalseTotal
if not %default_ca and do { local $SIG{"__DIE__"}; eval { do { require Mozilla::CA; 1 } } } 0 47 47
Condition33%1/3
not %default_ca and do { local $SIG{"__DIE__"}; eval { do { require Mozilla::CA; 1 } } }
!ll&&!rl&&r
4700
MC/DC0%0/2
not %default_ca and do { local $SIG{"__DIE__"}; eval { do { require Mozilla::CA; 1 } } }
not %default_ca do { local $SIG{"__DIE__"}; eval { do { require Mozilla::CA; 1 } } }
Truth table33%1/3
not(A) and B
A= not %default_caB= do { local $SIG{"__DIE__"}; eval { do { require Mozilla::CA; 1 } } }
ABresult
0X0
100
111
539 0 local $SIG{__DIE__};
540 0 eval { require Mozilla::CA; 1 };
541 };
542  
543 47 $ca_detected = 1;
544 47 return %default_ca;
545 }
546 }
547  
548  
549 # Export some stuff
550 # inet4|inet6|debug will be handled by myself, everything
551 # else will be handled the Exporter way
552 82 sub import {
553 164 ▶ my $class = shift;
Subroutine import: called CC=7 SCAR=27.5
554  
555 164 my @export;
556 164 foreach (@_) {
557 1 ▶ if ( /^inet4$/i ) {
Branch: 3 branches
BranchTrueFalseTotal
if (/^inet4$/i) { } 0 1 1
elsif (/^inet6$/i) { } 0 1 1
elsif (/^:?debug(\d+)/) { } 1 0 1
558 # explicitly fall back to inet4
559 0 @ISA = 'IO::Socket::INET';
560 0 @caller_force_inet4 = caller(); # save for warnings for 'inet6' case
561 } elsif ( /^inet6$/i ) {
562 # check if we have already ipv6 as base
563 0 ▶ if ( ! UNIVERSAL::isa( $class, 'IO::Socket::INET6')
Branch: 1 branch
BranchTrueFalseTotal
unless (UNIVERSAL::isa($class, "IO::Socket::INET6") or UNIVERSAL::isa($class, "IO::Socket::IP")) 0 0 0
Condition0%0/3
UNIVERSAL::isa($class, "IO::Socket::INET6") or UNIVERSAL::isa($class, "IO::Socket::IP")
l!l&&r!l&&!r
000
MC/DC0%0/2
UNIVERSAL::isa($class, "IO::Socket::INET6") or UNIVERSAL::isa($class, "IO::Socket::IP")
UNIVERSAL::isa($class, "IO::Socket::INET6") UNIVERSAL::isa($class, "IO::Socket::IP")
Truth table0%0/3
A or B
A= UNIVERSAL::isa($class, "IO::Socket::INET6")B= UNIVERSAL::isa($class, "IO::Socket::IP")
ABresult
1X1
011
000
564 and ! UNIVERSAL::isa( $class, 'IO::Socket::IP' )) {
565 # either we don't support it or we disabled it by explicitly
566 # loading it with 'inet4'. In this case re-enable but warn
567 # because this is probably an error
568 0 if ( CAN_IPV6 ) {
569 0 @ISA = ( CAN_IPV6 );
570 0 warn "IPv6 support re-enabled in __PACKAGE__, got disabled in file $caller_force_inet4[1] line $caller_force_inet4[2]";
571 } else {
572 die "INET6 is not supported, install IO::Socket::IP";
573 }
574 }
575 } elsif ( /^:?debug(\d+)/ ) {
576 1 $DEBUG=$1;
577 } else {
578 2 push @export,$_
579 }
580 }
581  
582 164 @_ = ( $class,@export );
583 162 goto &Exporter::import;
584 }
585  
586 82 my %SSL_OBJECT;
587 my %CREATED_IN_THIS_THREAD;
588 0 ▶sub CLONE { %CREATED_IN_THIS_THREAD = (); }
Subroutine CLONE: not called CC=1 SCAR=6.9
589  
590 # all keys used internally, these should be cleaned up at end
591 82 my @all_my_keys = qw(
592 _SSL_arguments
593 _SSL_certificate
594 _SSL_ctx
595 _SSL_fileno
596 _SSL_in_DESTROY
597 _SSL_ioclass_downgrade
598 _SSL_ioclass_upgraded
599 _SSL_last_err
600 _SSL_object
601 _SSL_ocsp_verify
602 _SSL_opened
603 _SSL_opening
604 _SSL_servername
605 _SSL_msg_callback
606 );
607  
608  
609 # we have callbacks associated with contexts, but have no way to access the
610 # current SSL object from these callbacks. To work around this
611 # CURRENT_SSL_OBJECT will be set before calling Net::SSLeay::{connect,accept}
612 # and reset afterwards, so we have access to it inside _internal_error.
613 82 my $CURRENT_SSL_OBJECT;
614  
615 # You might be expecting to find a new() subroutine here, but that is
616 # not how IO::Socket::INET works. All configuration gets performed in
617 # the calls to configure() and either connect() or accept().
618  
619 #Call to configure occurs when a new socket is made using
620 #IO::Socket::INET. Returns false (empty list) on failure.
621 sub configure {
622 126 ▶ my ($self, $arg_hash) = @_;
Subroutine configure: called CC=12 SCAR=25.7
Pod undocumented
623 126 ▶ return _invalid_object() unless($self);
Branch: 1 branch
BranchTrueFalseTotal
unless $self 0 126 126
624  
625 # force initial blocking
626 # otherwise IO::Socket::SSL->new might return undef if the
627 # socket is nonblocking and it fails to connect immediately
628 # for real nonblocking behavior one should create a nonblocking
629 # socket and later call connect explicitly
630 126 my $blocking = delete $arg_hash->{Blocking};
631  
632 # because Net::HTTPS simple redefines blocking() to {} (e.g.
633 # return undef) and IO::Socket::INET does not like this we
634 # set Blocking only explicitly if it was set
635 126 ▶ $arg_hash->{Blocking} = 1 if defined ($blocking);
Branch: 1 branch
BranchTrueFalseTotal
if defined $blocking 2 124 126
636  
637 126 ▶ $self->configure_SSL($arg_hash) || return;
Branch: 1 branch
BranchTrueFalseTotal
$self->configure_SSL($arg_hash) or return 1 125 126
638  
639 125 ▶ if ($arg_hash->{$family_key} ||= $arg_hash->{Domain} || $arg_hash->{Family}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($arg_hash->{$family_key} ||= $arg_hash->{"Domain"} || $arg_hash->{"Family"}) 72 53 125
Condition66%4/6
$arg_hash->{$family_key} ||= $arg_hash->{"Domain"} || $arg_hash->{"Family"}
l!l&&r!l&&!r
07253
$arg_hash->{'Domain'} || $arg_hash->{'Family'}
l!l&&r!l&&!r
72053
MC/DC0%0/3
$arg_hash->{$family_key} ||= $arg_hash->{"Domain"} || $arg_hash->{"Family"}
$arg_hash->{$family_key} $arg_hash->{'Domain'} $arg_hash->{'Family'}
Truth table0%0/4
A ||= B || C
A= $arg_hash->{$family_key}B= $arg_hash->{'Domain'}C= $arg_hash->{'Family'}
ABCresult
1XX1
01X1
0011
0000
640 # Hack to work around the problem that IO::Socket::IP defaults to
641 # AI_ADDRCONFIG which creates problems if we have only the loopback
642 # interface. If we already know the family this flag is more harmful
643 # then useful.
644 $arg_hash->{GetAddrInfoFlags} = 0 if $IOCLASS eq 'IO::Socket::IP'
645 72 ▶ && ! defined $arg_hash->{GetAddrInfoFlags};
Branch: 1 branch
BranchTrueFalseTotal
if $IOCLASS eq "IO::Socket::IP" and not defined $arg_hash->{"GetAddrInfoFlags"} 72 0 72
Condition33%1/3
$IOCLASS eq "IO::Socket::IP" and not defined $arg_hash->{"GetAddrInfoFlags"}
!ll&&!rl&&r
0072
MC/DC0%0/2
$IOCLASS eq "IO::Socket::IP" and not defined $arg_hash->{"GetAddrInfoFlags"}
$IOCLASS eq "IO::Socket::IP" not defined $arg_hash->{"GetAddrInfoFlags"}
Truth table33%1/3
A and not(B)
A= $IOCLASS eq "IO::Socket::IP"B= not defined $arg_hash->{"GetAddrInfoFlags"}
ABresult
0X0
100
111
646 }
647 125 ▶ return $self->_internal_error("@ISA configuration failed",0)
Branch: 1 branch
BranchTrueFalseTotal
unless $self->SUPER::configure($arg_hash) 7 118 125
648 if ! $self->SUPER::configure($arg_hash);
649  
650 118 ▶ $self->blocking(0) if defined $blocking && !$blocking;
Branch: 1 branch
BranchTrueFalseTotal
if defined $blocking and not $blocking 2 116 118
Condition66%2/3
defined $blocking and not $blocking
!ll&&!rl&&r
11602
MC/DC50%1/2
defined $blocking and not $blocking
defined $blocking not $blocking
Truth table66%2/3
A and not(B)
A= defined $blockingB= not $blocking
ABresult
0X0
100
111
651 118 return $self;
652 }
653  
654 sub configure_SSL {
655 272 ▶ my ($self, $arg_hash) = @_;
Subroutine configure_SSL: called CC=6 SCAR=17.9
Pod undocumented
656  
657 272 ▶ $arg_hash->{Proto} ||= 'tcp';
Condition50%1/2
$arg_hash->{"Proto"} ||= "tcp"
l!l
0272
MC/DC0%0/1
$arg_hash->{"Proto"} ||= "tcp"
$arg_hash->{"Proto"}
Truth table50%1/2
A
A= $arg_hash->{"Proto"}
Aresult
11
00
658 272 my $is_server = $arg_hash->{SSL_server};
659 272 ▶ if ( ! defined $is_server ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $is_server) 191 81 272
660 191 ▶ $is_server = $arg_hash->{SSL_server} = $arg_hash->{Listen} || 0;
Condition100%2/2
$arg_hash->{'Listen'} || 0
l!l
20171
MC/DC100%1/1
$arg_hash->{'Listen'} || 0
$arg_hash->{'Listen'}
Truth table100%2/2
A
A= $arg_hash->{'Listen'}
Aresult
11
00
661 }
662  
663 # add user defined defaults, maybe after filtering
664 272 ▶ $FILTER_SSL_ARGS->($is_server,$arg_hash) if $FILTER_SSL_ARGS;
Branch: 1 branch
BranchTrueFalseTotal
if $FILTER_SSL_ARGS 0 272 272
665  
666 272 delete @{*$self}{@all_my_keys};
667 272 ${*$self}{_SSL_opened} = $is_server;
668 272 ${*$self}{_SSL_arguments} = $arg_hash;
669  
670 # this adds defaults to $arg_hash as a side effect!
671 272 ▶ ${*$self}{'_SSL_ctx'} = IO::Socket::SSL::SSL_Context->new($arg_hash)
Branch: 1 branch
BranchTrueFalseTotal
do { *$self }->{"_SSL_ctx"} = "IO::Socket::SSL::SSL_Context"->new($arg_hash) or return 1 271 272
672 or return;
673  
674 271 return $self;
675 }
676  
677  
678 sub _skip_rw_error {
679 95 ▶ my ($self,$ssl,$rv) = @_;
Subroutine _skip_rw_error: called CC=5 SCAR=16.2
680 95 my $err = Net::SSLeay::get_error($ssl,$rv);
681 95 ▶ if ( $err == $Net_SSLeay_ERROR_WANT_READ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($err == $Net_SSLeay_ERROR_WANT_READ) { } 37 58 95
elsif ($err == $Net_SSLeay_ERROR_WANT_WRITE) { } 2 56 58
682 37 $SSL_ERROR = SSL_WANT_READ;
683 } elsif ( $err == $Net_SSLeay_ERROR_WANT_WRITE) {
684 2 $SSL_ERROR = SSL_WANT_WRITE;
685 } else {
686 56 return $err;
687 }
688 39 ▶ $! ||= EWOULDBLOCK;
Condition50%1/2
$! ||= 11
l!l
390
MC/DC0%0/1
$! ||= 11
$!
Truth table50%1/2
A
A= $!
Aresult
11
00
689 39 ▶ ${*$self}{_SSL_last_err} = [$SSL_ERROR,4] if ref($self);
Branch: 1 branch
BranchTrueFalseTotal
if ref $self 39 0 39
690 39 Net::SSLeay::ERR_clear_error();
691 39 return 0;
692 }
693  
694  
695 # Call to connect occurs when a new client socket is made using IO::Socket::*
696 sub connect {
697 83 ▶ my $self = shift || return _invalid_object();
Subroutine connect: called CC=9 SCAR=23.1
Pod documented
Condition50%1/2
shift() || (return _invalid_object())
l!l
830
MC/DC0%0/1
shift() || (return _invalid_object())
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
698 83 ▶ return $self if ${*$self}{'_SSL_opened'}; # already connected
Branch: 1 branch
BranchTrueFalseTotal
if do { *$self }->{"_SSL_opened"} 0 83 83
699  
700 83 ▶ if ( ! ${*$self}{'_SSL_opening'} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (do { *$self }->{"_SSL_opening"}) 83 0 83
701 # call SUPER::connect if the underlying socket is not connected
702 # if this fails this might not be an error (e.g. if $! = EINPROGRESS
703 # and socket is nonblocking this is normal), so keep any error
704 # handling to the client
705 83 ▶ $DEBUG>=2 && DEBUG('socket not yet connected' );
Branch: 1 branch
BranchTrueFalseTotal
$IO::Socket::SSL::DEBUG >= 2 and DEBUG("socket not yet connected") 0 83 83
706 83 ▶ $self->SUPER::connect(@_) || return;
Branch: 1 branch
BranchTrueFalseTotal
$self->SUPER::connect(@_) or return 0 83 83
707 83 ▶ $DEBUG>=2 && DEBUG('socket connected' );
Branch: 1 branch
BranchTrueFalseTotal
$IO::Socket::SSL::DEBUG >= 2 and DEBUG("socket connected") 0 83 83
708  
709 # IO::Socket works around systems, which return EISCONN or similar
710 # on non-blocking re-connect by returning true, even if $! is set
711 # but it does not clear $!, so do it here
712 83 $! = undef;
713  
714 # don't continue with connect_SSL if SSL_startHandshake is set to 0
715 83 my $sh = ${*$self}{_SSL_arguments}{SSL_startHandshake};
716 83 ▶ return $self if defined $sh && ! $sh;
Branch: 1 branch
BranchTrueFalseTotal
if defined $sh and not $sh 15 68 83
Condition66%2/3
defined $sh and not $sh
!ll&&!rl&&r
68015
MC/DC50%1/2
defined $sh and not $sh
defined $sh not $sh
Truth table66%2/3
A and not(B)
A= defined $shB= not $sh
ABresult
0X0
100
111
717 }
718 68 return $self->connect_SSL;
719 }
720  
721  
722 sub connect_SSL {
723 174 ▶ my $self = shift;
Subroutine connect_SSL: called CC=82 SCAR=55.4
Pod documented
724 174 ▶ my $args = @_>1 ? {@_}: $_[0]||{};
Branch: 1 branch
BranchTrueFalseTotal
@_ > 1 ? : 2 172 174
Condition50%1/2
$_[0] or {}
l!l
0172
MC/DC0%0/1
$_[0] or {}
$_[0]
Truth table50%1/2
A
A= $_[0]
Aresult
11
00
725 174 ▶ return $self if ${*$self}{'_SSL_opened'}; # already connected
Branch: 1 branch
BranchTrueFalseTotal
if do { *$self }->{"_SSL_opened"} 0 174 174
726  
727 174 my ($ssl,$ctx);
728 174 ▶ if ( ! ${*$self}{'_SSL_opening'} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (do { *$self }->{"_SSL_opening"}) 172 2 174
729 # start ssl connection
730 172 ▶ $DEBUG>=2 && DEBUG('ssl handshake not started' );
Branch: 1 branch
BranchTrueFalseTotal
$IO::Socket::SSL::DEBUG >= 2 and DEBUG("ssl handshake not started") 0 172 172
731 172 ${*$self}{'_SSL_opening'} = 1;
732 172 my $arg_hash = ${*$self}{'_SSL_arguments'};
733  
734 172 my $fileno = ${*$self}{'_SSL_fileno'} = fileno($self);
735 172 ▶ return $self->_internal_error("Socket has no fileno",9)
Branch: 1 branch
BranchTrueFalseTotal
unless defined $fileno 0 172 172
736 if ! defined $fileno;
737  
738 172 $ctx = ${*$self}{'_SSL_ctx'}; # Reference to real context
739 172 $ssl = ${*$self}{'_SSL_object'} = Net::SSLeay::new($ctx->{context})
740 172 ▶ || return $self->error("SSL structure creation failed");
Condition50%1/2
&Net::SSLeay::new($ctx->{'context'}) || (return $self->error('SSL structure creation failed'))
l!l
1720
MC/DC0%0/1
&Net::SSLeay::new($ctx->{'context'}) || (return $self->error('SSL structure creation failed'))
&Net::SSLeay::new($ctx->{'context'})
Truth table50%1/2
A
A= &Net::SSLeay::new($ctx->{'context'})
Aresult
11
00
741 172 ▶ $CREATED_IN_THIS_THREAD{$ssl} = 1 if $use_threads;
Branch: 1 branch
BranchTrueFalseTotal
if $use_threads 0 172 172
742 172 $SSL_OBJECT{$ssl} = [$self,0];
743 172 weaken($SSL_OBJECT{$ssl}[0]);
744  
745 172 ▶ if ($ctx->{session_cache}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ctx->{"session_cache"}) 12 160 172
746 12 ▶ $arg_hash->{SSL_session_key} ||= do {
Condition66%2/3
$arg_hash->{"SSL_session_key"} ||= do { my $host = $arg_hash->{"PeerAddr"} || $arg_hash->{"PeerHost"} || $self->_update_peer; my $port = $arg_hash->{"PeerPort"} || $arg_hash->{"PeerService"}; $port ? "${host}:$port" : $host }
l!l&&r!l&&!r
660
MC/DC0%0/2
$arg_hash->{"SSL_session_key"} ||= do { my $host = $arg_hash->{"PeerAddr"} || $arg_hash->{"PeerHost"} || $self->_update_peer; my $port = $arg_hash->{"PeerPort"} || $arg_hash->{"PeerService"}; $port ? "${host}:$port" : $host }
$arg_hash->{"SSL_session_key"} do { my $host = $arg_hash->{"PeerAddr"} || $arg_hash->{"PeerHost"} || $self->_update_peer; my $port = $arg_hash->{"PeerPort"} || $arg_hash->{"PeerService"}; $port ? "${host}:$port" : $host }
Truth table66%2/3
A ||= B
A= $arg_hash->{"SSL_session_key"}B= do { my $host = $arg_hash->{"PeerAddr"} || $arg_hash->{"PeerHost"} || $self->_update_peer; my $port = $arg_hash->{"PeerPort"} || $arg_hash->{"PeerService"}; $port ? "${host}:$port" : $host }
ABresult
1X1
011
000
747 my $host = $arg_hash->{PeerAddr} || $arg_hash->{PeerHost}
748 6 ▶ || $self->_update_peer;
Condition66%4/6
$arg_hash->{'PeerAddr'} || $arg_hash->{'PeerHost'} || $self->_update_peer
l!l&&r!l&&!r
510
$arg_hash->{"PeerAddr"} or $arg_hash->{"PeerHost"}
l!l&&r!l&&!r
051
MC/DC0%0/3
$arg_hash->{'PeerAddr'} || $arg_hash->{'PeerHost'} || $self->_update_peer
$arg_hash->{"PeerAddr"} $arg_hash->{"PeerHost"} $self->_update_peer
Truth table50%2/4
A or B || C
A= $arg_hash->{"PeerAddr"}B= $arg_hash->{"PeerHost"}C= $self->_update_peer
ABCresult
1XX1
01X1
0011
0000
749 6 ▶ my $port = $arg_hash->{PeerPort} || $arg_hash->{PeerService};
Condition66%2/3
$arg_hash->{'PeerPort'} || $arg_hash->{'PeerService'}
l!l&&r!l&&!r
150
MC/DC0%0/2
$arg_hash->{'PeerPort'} || $arg_hash->{'PeerService'}
$arg_hash->{'PeerPort'} $arg_hash->{'PeerService'}
Truth table66%2/3
A || B
A= $arg_hash->{'PeerPort'}B= $arg_hash->{'PeerService'}
ABresult
1X1
011
000
750 6 ▶ $port ? "$host:$port" : $host;
Branch: 1 branch
BranchTrueFalseTotal
$port ? : 6 0 6
751 }
752 }
753  
754 172 ▶ Net::SSLeay::set_fd($ssl, $fileno)
Branch: 1 branch
BranchTrueFalseTotal
&Net::SSLeay::set_fd($ssl, $fileno) or return $self->error("SSL filehandle association failed") 0 172 172
755 || return $self->error("SSL filehandle association failed");
756  
757 172 ▶ set_msg_callback($self) if $DEBUG>=2 || ${*$self}{_SSL_msg_callback};
Branch: 1 branch
BranchTrueFalseTotal
if $IO::Socket::SSL::DEBUG >= 2 or do { *$self }->{"_SSL_msg_callback"} 0 172 172
Condition33%1/3
$IO::Socket::SSL::DEBUG >= 2 or do { *$self }->{"_SSL_msg_callback"}
l!l&&r!l&&!r
00172
MC/DC0%0/2
$IO::Socket::SSL::DEBUG >= 2 or do { *$self }->{"_SSL_msg_callback"}
$IO::Socket::SSL::DEBUG >= 2 do { *$self }->{"_SSL_msg_callback"}
Truth table33%1/3
A or B
A= $IO::Socket::SSL::DEBUG >= 2B= do { *$self }->{"_SSL_msg_callback"}
ABresult
1X1
011
000
758  
759 172 ▶ if ( $can_client_sni ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($can_client_sni) { } 172 0 172
elsif ($arg_hash->{'SSL_hostname'}) { } 0 0 0
760 172 my $host;
761 172 ▶ if ( exists $arg_hash->{SSL_hostname} ) {
Branch: 2 branches
BranchTrueFalseTotal
if (exists $arg_hash->{'SSL_hostname'}) { } 19 153 172
elsif ($host = $arg_hash->{'PeerAddr'} || $arg_hash->{'PeerHost'}) { } 71 82 153
762 # explicitly given
763 # can be set to undef/'' to not use extension
764 $host = $arg_hash->{SSL_hostname}
765 19 ▶ } elsif ( $host = $arg_hash->{PeerAddr} || $arg_hash->{PeerHost} ) {
Condition100%3/3
$arg_hash->{'PeerAddr'} || $arg_hash->{'PeerHost'}
l!l&&r!l&&!r
26982
MC/DC100%2/2
$arg_hash->{'PeerAddr'} || $arg_hash->{'PeerHost'}
$arg_hash->{'PeerAddr'} $arg_hash->{'PeerHost'}
Truth table100%3/3
A || B
A= $arg_hash->{'PeerAddr'}B= $arg_hash->{'PeerHost'}
ABresult
1X1
011
000
766 # implicitly given
767 71 $host =~s{:[a-zA-Z0-9_\-]+$}{};
768 # should be hostname, not IPv4/6
769 71 ▶ $host = undef if $host !~m{[a-z_]}i or $host =~m{:};
Branch: 1 branch
BranchTrueFalseTotal
if not $host =~ /[a-z_]/i or $host =~ /:/ 71 0 71
Condition33%1/3
not $host =~ /[a-z_]/i or $host =~ /:/
l!l&&r!l&&!r
7100
MC/DC0%0/2
not $host =~ /[a-z_]/i or $host =~ /:/
not $host =~ /[a-z_]/i $host =~ /:/
Truth table33%1/3
not(A) or B
A= not $host =~ /[a-z_]/iB= $host =~ /:/
ABresult
1X1
011
000
770 }
771 # define SSL_CTRL_SET_TLSEXT_HOSTNAME 55
772 # define TLSEXT_NAMETYPE_host_name 0
773 172 ▶ if ($host) {
Branch: 1 branch
BranchTrueFalseTotal
if ($host) { } 19 153 172
774 19 ▶ $DEBUG>=2 && DEBUG("using SNI with hostname $host");
Branch: 1 branch
BranchTrueFalseTotal
$IO::Socket::SSL::DEBUG >= 2 and DEBUG("using SNI with hostname $host") 0 19 19
775 19 Net::SSLeay::ctrl($ssl,55,0,$host);
776 } else {
777 153 ▶ $DEBUG>=2 && DEBUG("not using SNI because hostname is unknown");
Branch: 1 branch
BranchTrueFalseTotal
$IO::Socket::SSL::DEBUG >= 2 and DEBUG("not using SNI because hostname is unknown") 0 153 153
778 }
779 } elsif ( $arg_hash->{SSL_hostname} ) {
780 0 return $self->_internal_error(
781 "Client side SNI not supported for this openssl",9);
782 } else {
783 0 ▶ $DEBUG>=2 && DEBUG("not using SNI because openssl is too old");
Branch: 1 branch
BranchTrueFalseTotal
$IO::Socket::SSL::DEBUG >= 2 and DEBUG("not using SNI because openssl is too old") 0 0 0
784 }
785  
786 172 ▶ $arg_hash->{PeerAddr} || $arg_hash->{PeerHost} || $self->_update_peer;
Branch: 1 branch
BranchTrueFalseTotal
$arg_hash->{"PeerAddr"} or $arg_hash->{"PeerHost"} or $self->_update_peer 86 86 172
Condition100%3/3
$arg_hash->{"PeerAddr"} or $arg_hash->{"PeerHost"}
l!l&&r!l&&!r
28486
MC/DC100%2/2
$arg_hash->{"PeerAddr"} or $arg_hash->{"PeerHost"}
$arg_hash->{"PeerAddr"} $arg_hash->{"PeerHost"}
Truth table100%3/3
A or B
A= $arg_hash->{"PeerAddr"}B= $arg_hash->{"PeerHost"}
ABresult
1X1
011
000
787 172 ▶ if ( $ctx->{verify_name_ref} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ctx->{"verify_name_ref"}) 99 73 172
788 # need target name for update
789 my $host = $arg_hash->{SSL_verifycn_name}
790 99 ▶ || $arg_hash->{SSL_hostname};
Condition100%3/3
$arg_hash->{'SSL_verifycn_name'} || $arg_hash->{'SSL_hostname'}
l!l&&r!l&&!r
42948
MC/DC100%2/2
$arg_hash->{'SSL_verifycn_name'} || $arg_hash->{'SSL_hostname'}
$arg_hash->{'SSL_verifycn_name'} $arg_hash->{'SSL_hostname'}
Truth table100%3/3
A || B
A= $arg_hash->{'SSL_verifycn_name'}B= $arg_hash->{'SSL_hostname'}
ABresult
1X1
011
000
791 99 ▶ if ( ! defined $host ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $host) 48 51 99
792 48 ▶ if ( $host = $arg_hash->{PeerAddr} || $arg_hash->{PeerHost} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($host = $arg_hash->{"PeerAddr"} || $arg_hash->{"PeerHost"}) 48 0 48
Condition66%2/3
$arg_hash->{'PeerAddr'} || $arg_hash->{'PeerHost'}
l!l&&r!l&&!r
21270
MC/DC0%0/2
$arg_hash->{'PeerAddr'} || $arg_hash->{'PeerHost'}
$arg_hash->{'PeerAddr'} $arg_hash->{'PeerHost'}
Truth table66%2/3
A || B
A= $arg_hash->{'PeerAddr'}B= $arg_hash->{'PeerHost'}
ABresult
1X1
011
000
793 48 $host =~s{^
794 (
795 (?:[^:\[]+) | # ipv4|host
796 (?:\[(?:.*)\]) # [ipv6|host]
797 )
798 (:[\w\-]+)? # optional :port
799 $}{$1}x; # ipv4|host|ipv6
800 }
801 }
802 99 ${$ctx->{verify_name_ref}} = $host;
803 }
804  
805 172 my $ocsp = $ctx->{ocsp_mode};
806 172 ▶ if ( $ocsp & SSL_OCSP_NO_STAPLE ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($ocsp & 1) { } 1 171 172
elsif (not $can_ocsp_staple) { } 0 171 171
elsif ($ocsp & 18) { } 98 73 171
807 # don't try stapling
808 } elsif ( ! $can_ocsp_staple ) {
809 0 ▶ croak("OCSP stapling not support") if $ocsp & SSL_OCSP_MUST_STAPLE;
Branch: 1 branch
BranchTrueFalseTotal
if $ocsp & 2 0 0 0
810 } elsif ( $ocsp & (SSL_OCSP_TRY_STAPLE|SSL_OCSP_MUST_STAPLE)) {
811 # staple by default if verification enabled
812 98 ${*$self}{_SSL_ocsp_verify} = undef;
813 98 Net::SSLeay::set_tlsext_status_type($ssl,
814 Net::SSLeay::TLSEXT_STATUSTYPE_ocsp());
815 98 ▶ $DEBUG>=2 && DEBUG("request OCSP stapling");
Branch: 1 branch
BranchTrueFalseTotal
$IO::Socket::SSL::DEBUG >= 2 and DEBUG("request OCSP stapling") 0 98 98
816 }
817  
818 172 ▶ if ($ctx->{session_cache} and my $session =
Branch: 1 branch
BranchTrueFalseTotal
if ($ctx->{"session_cache"} and my $session = $ctx->{"session_cache"}->get_session($arg_hash->{"SSL_session_key"})) 7 165 172
Condition100%3/3
$ctx->{"session_cache"} and my $session = $ctx->{"session_cache"}->get_session($arg_hash->{"SSL_session_key"})
!ll&&!rl&&r
16057
MC/DC100%2/2
$ctx->{"session_cache"} and my $session = $ctx->{"session_cache"}->get_session($arg_hash->{"SSL_session_key"})
$ctx->{"session_cache"} my $session = $ctx->{"session_cache"}->get_session($arg_hash->{"SSL_session_key"})
Truth table100%3/3
A and B
A= $ctx->{"session_cache"}B= my $session = $ctx->{"session_cache"}->get_session($arg_hash->{"SSL_session_key"})
ABresult
0X0
100
111
819 $ctx->{session_cache}->get_session($arg_hash->{SSL_session_key})
820 ) {
821 7 Net::SSLeay::set_session($ssl, $session);
822 }
823 }
824  
825 174 ▶ $ssl ||= ${*$self}{'_SSL_object'};
Condition66%2/3
$ssl ||= do { *$self }->{"_SSL_object"}
l!l&&r!l&&!r
17220
MC/DC0%0/2
$ssl ||= do { *$self }->{"_SSL_object"}
$ssl do { *$self }->{"_SSL_object"}
Truth table66%2/3
A ||= B
A= $sslB= do { *$self }->{"_SSL_object"}
ABresult
1X1
011
000
826  
827 174 $SSL_ERROR = $! = undef;
828 my $timeout = exists $args->{Timeout}
829 ? $args->{Timeout}
830 174 ▶ : ${*$self}{io_socket_timeout}; # from IO::Socket
Branch: 1 branch
BranchTrueFalseTotal
exists $args->{'Timeout'} ? : 2 172 174
831 174 ▶ if ( defined($timeout) && $timeout>0 && $self->blocking(0) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $timeout and $timeout > 0 and $self->blocking(0)) { } 8 166 174
Condition66%4/6
defined $timeout and $timeout > 0 and $self->blocking(0)
!ll&&!rl&&r
16608
defined $timeout and $timeout > 0
!ll&&!rl&&r
16608
MC/DC33%1/3
defined $timeout and $timeout > 0 and $self->blocking(0)
defined $timeout $timeout > 0 $self->blocking(0)
Truth table50%2/4
A and B and C
A= defined $timeoutB= $timeout > 0C= $self->blocking(0)
ABCresult
0XX0
10X0
1100
1111
832 8 ▶ $DEBUG>=2 && DEBUG( "set socket to non-blocking to enforce timeout=$timeout" );
Branch: 1 branch
BranchTrueFalseTotal
$IO::Socket::SSL::DEBUG >= 2 and DEBUG("set socket to non-blocking to enforce timeout=$timeout") 0 8 8
833 # timeout was given and socket was blocking
834 # enforce timeout with now non-blocking socket
835 } else {
836 # timeout does not apply because invalid or socket non-blocking
837 166 $timeout = undef;
838 166 ▶ $auto_retry && $auto_retry->($ssl,$self->blocking);
Branch: 1 branch
BranchTrueFalseTotal
$auto_retry and &$auto_retry($ssl, $self->blocking) 166 0 166
839 }
840  
841 174 ▶ my $start = defined($timeout) && time();
Condition66%2/3
defined $timeout && time
!ll&&!rl&&r
16608
MC/DC50%1/2
defined $timeout && time
defined $timeout time
Truth table66%2/3
A && B
A= defined $timeoutB= time
ABresult
0X0
100
111
842 {
843 174 $SSL_ERROR = undef;
844 185 $CURRENT_SSL_OBJECT = $self;
845 185 ▶ $DEBUG>=3 && DEBUG("call Net::SSLeay::connect" );
Branch: 1 branch
BranchTrueFalseTotal
$IO::Socket::SSL::DEBUG >= 3 and DEBUG("call Net::SSLeay::connect") 0 185 185
846 185 my $rv = Net::SSLeay::connect($ssl);
847 185 $CURRENT_SSL_OBJECT = undef;
848 185 ▶ $DEBUG>=3 && DEBUG("done Net::SSLeay::connect -> $rv" );
Branch: 1 branch
BranchTrueFalseTotal
$IO::Socket::SSL::DEBUG >= 3 and DEBUG("done Net::SSLeay::connect -> $rv") 0 185 185
849 185 ▶ if ( $rv < 0 ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($rv < 0) { } 40 145 185
elsif ($rv == 0) { } 0 145 145
850 40 ▶ if ( my $err = $self->_skip_rw_error( $ssl,$rv )) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $err = $self->_skip_rw_error($ssl, $rv)) 26 14 40
851 26 $self->error("SSL connect attempt failed");
852 26 delete ${*$self}{'_SSL_opening'};
853 26 ${*$self}{'_SSL_opened'} = -1;
854 26 ▶ $DEBUG>=1 && DEBUG( "fatal SSL error: $SSL_ERROR" );
Branch: 1 branch
BranchTrueFalseTotal
$IO::Socket::SSL::DEBUG >= 1 and DEBUG("fatal SSL error: $IO::Socket::SSL::SSL_ERROR") 0 26 26
855 26 return $self->fatal_ssl_error();
856 }
857  
858 14 ▶ $DEBUG>=2 && DEBUG('ssl handshake in progress' );
Branch: 1 branch
BranchTrueFalseTotal
$IO::Socket::SSL::DEBUG >= 2 and DEBUG("ssl handshake in progress") 0 14 14
859 # connect failed because handshake needs to be completed
860 # if socket was non-blocking or no timeout was given return with this error
861 14 ▶ return if ! defined($timeout);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $timeout 2 12 14
862  
863 # wait until socket is readable or writable
864 12 my $rv;
865 12 ▶ if ( $timeout>0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($timeout > 0) { } 12 0 12
866 12 my $vec = '';
867 12 vec($vec,$self->fileno,1) = 1;
868 12 ▶ $DEBUG>=2 && DEBUG( "waiting for fd to become ready: $SSL_ERROR" );
Branch: 1 branch
BranchTrueFalseTotal
$IO::Socket::SSL::DEBUG >= 2 and DEBUG("waiting for fd to become ready: $IO::Socket::SSL::SSL_ERROR") 0 12 12
869 12 ▶ $rv =
Branch: 2 branches
BranchTrueFalseTotal
$IO::Socket::SSL::SSL_ERROR == 109619331148320 ? : 12 0 12
$IO::Socket::SSL::SSL_ERROR == 109619331148368 ? : 0 0 0
870 $SSL_ERROR == SSL_WANT_READ ? select( $vec,undef,undef,$timeout) :
871 $SSL_ERROR == SSL_WANT_WRITE ? select( undef,$vec,undef,$timeout) :
872 undef;
873 } else {
874 0 ▶ $DEBUG>=2 && DEBUG("handshake failed because no more time" );
Branch: 1 branch
BranchTrueFalseTotal
$IO::Socket::SSL::DEBUG >= 2 and DEBUG("handshake failed because no more time") 0 0 0
875 0 $! = ETIMEDOUT
876 }
877 12 ▶ if ( ! $rv ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($rv) 1 11 12
878 1 ▶ $DEBUG>=2 && DEBUG("handshake failed because socket did not became ready" );
Branch: 1 branch
BranchTrueFalseTotal
$IO::Socket::SSL::DEBUG >= 2 and DEBUG("handshake failed because socket did not became ready") 0 1 1
879 # failed because of timeout, return
880 1 ▶ $! ||= ETIMEDOUT;
Condition50%1/2
$! ||= 110
l!l
10
MC/DC0%0/1
$! ||= 110
$!
Truth table50%1/2
A
A= $!
Aresult
11
00
881 1 delete ${*$self}{'_SSL_opening'};
882 1 ${*$self}{'_SSL_opened'} = -1;
883 1 $self->blocking(1); # was blocking before
884 return
885 1 }
886  
887 # socket is ready, try non-blocking connect again after recomputing timeout
888 11 ▶ $DEBUG>=2 && DEBUG("socket ready, retrying connect" );
Branch: 1 branch
BranchTrueFalseTotal
$IO::Socket::SSL::DEBUG >= 2 and DEBUG("socket ready, retrying connect") 0 11 11
889 11 my $now = time();
890 11 $timeout -= $now - $start;
891 11 $start = $now;
892 11 redo;
893  
894 } elsif ( $rv == 0 ) {
895 0 delete ${*$self}{'_SSL_opening'};
896 0 ▶ $DEBUG>=2 && DEBUG("connection failed - connect returned 0" );
Branch: 1 branch
BranchTrueFalseTotal
$IO::Socket::SSL::DEBUG >= 2 and DEBUG("connection failed - connect returned 0") 0 0 0
897 0 $self->error("SSL connect attempt failed because of handshake problems" );
898 0 ${*$self}{'_SSL_opened'} = -1;
899 0 return $self->fatal_ssl_error();
900 }
901 }
902  
903 145 ▶ $DEBUG>=2 && DEBUG('ssl handshake done' );
Branch: 1 branch
BranchTrueFalseTotal
$IO::Socket::SSL::DEBUG >= 2 and DEBUG("ssl handshake done") 0 145 145
904 # ssl connect successful
905 145 delete ${*$self}{'_SSL_opening'};
906 145 ${*$self}{'_SSL_opened'}=1;
907 145 ▶ if (defined($timeout)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $timeout) 6 139 145
908 6 $self->blocking(1); # reset back to blocking
909 6 $! = undef; # reset errors from non-blocking
910 }
911  
912 145 ▶ $ctx ||= ${*$self}{'_SSL_ctx'};
Condition66%2/3
$ctx ||= do { *$self }->{"_SSL_ctx"}
l!l&&r!l&&!r
14320
MC/DC0%0/2
$ctx ||= do { *$self }->{"_SSL_ctx"}
$ctx do { *$self }->{"_SSL_ctx"}
Truth table66%2/3
A ||= B
A= $ctxB= do { *$self }->{"_SSL_ctx"}
ABresult
1X1
011
000
913  
914 145 ▶ if ( my $ocsp_result = ${*$self}{_SSL_ocsp_verify} ) {
Branch: 2 branches
BranchTrueFalseTotal
if (my $ocsp_result = do { *$self }->{'_SSL_ocsp_verify'}) { } 0 145 145
elsif ($ctx->{'ocsp_mode'} & 2) { } 0 145 145
915 # got result from OCSP stapling
916 0 ▶ if ( $ocsp_result->[0] > 0 ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($ocsp_result->[0] > 0) { } 0 0 0
elsif ($ocsp_result->[0] < 0) { } 0 0 0
917 0 ▶ $DEBUG>=3 && DEBUG("got OCSP success with stapling");
Branch: 1 branch
BranchTrueFalseTotal
$IO::Socket::SSL::DEBUG >= 3 and DEBUG("got OCSP success with stapling") 0 0 0
918 # successful validated
919 } elsif ( $ocsp_result->[0] < 0 ) {
920 # Permanent problem with validation because certificate
921 # is either self-signed or the issuer cannot be found.
922 # Ignore here, because this will cause other errors too.
923 0 ▶ $DEBUG>=3 && DEBUG("got OCSP failure with stapling: %s",
Branch: 1 branch
BranchTrueFalseTotal
$IO::Socket::SSL::DEBUG >= 3 and DEBUG("got OCSP failure with stapling: %s", $ocsp_result->[1]) 0 0 0
924 $ocsp_result->[1]);
925 } else {
926 # definitely revoked
927 0 ▶ $DEBUG>=3 && DEBUG("got OCSP revocation with stapling: %s",
Branch: 1 branch
BranchTrueFalseTotal
$IO::Socket::SSL::DEBUG >= 3 and DEBUG("got OCSP revocation with stapling: %s", $ocsp_result->[1]) 0 0 0
928 $ocsp_result->[1]);
929 0 $self->_internal_error($ocsp_result->[1],5);
930 0 return $self->fatal_ssl_error();
931 }
932 } elsif ( $ctx->{ocsp_mode} & SSL_OCSP_MUST_STAPLE ) {
933 0 $self->_internal_error("did not receive the required stapled OCSP response",5);
934 0 return $self->fatal_ssl_error();
935 }
936  
937 145 ▶ if (!%sess_cb and $ctx->{session_cache}
Branch: 1 branch
BranchTrueFalseTotal
if (not %sess_cb and $ctx->{"session_cache"} and my $session = &Net::SSLeay::get1_session($ssl)) 0 145 145
Condition33%2/6
not %sess_cb and $ctx->{"session_cache"} and my $session = &Net::SSLeay::get1_session($ssl)
!ll&&!rl&&r
14500
not %sess_cb and $ctx->{"session_cache"}
!ll&&!rl&&r
14500
MC/DC0%0/3
not %sess_cb and $ctx->{"session_cache"} and my $session = &Net::SSLeay::get1_session($ssl)
not %sess_cb $ctx->{"session_cache"} my $session = &Net::SSLeay::get1_session($ssl)
Truth table25%1/4
not(A) and B and C
A= not %sess_cbB= $ctx->{"session_cache"}C= my $session = &Net::SSLeay::get1_session($ssl)
ABCresult
0XX0
10X0
1100
1111
938 and my $session = Net::SSLeay::get1_session($ssl)) {
939 $ctx->{session_cache}->add_session(
940 0 ${*$self}{_SSL_arguments}{SSL_session_key},
941 0 $session
942 );
943 }
944  
945 145 tie *{$self}, "IO::Socket::SSL::SSL_HANDLE", $self;
946  
947 145 return $self;
948 }
949  
950 # called if PeerAddr is not set in ${*$self}{'_SSL_arguments'}
951 # this can be the case if start_SSL is called with a normal IO::Socket::INET
952 # so that PeerAddr|PeerPort are not set from args
953 # returns PeerAddr
954 sub _update_peer {
955 87 ▶ my $self = shift;
Subroutine _update_peer: called CC=2 SCAR=7.3
956 87 my $arg_hash = ${*$self}{'_SSL_arguments'};
957 87 eval {
958 87 my $sockaddr = getpeername( $self );
959 87 my $af = sockaddr_family($sockaddr);
960 87 ▶ if( CAN_IPV6 && $af == AF_INET6 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($af == 10) { } 0 87 87
961 0 my (undef, $host, $port) = _getnameinfo($sockaddr,
962 NI_NUMERICHOST | NI_NUMERICSERV);
963 0 $arg_hash->{PeerPort} = $port;
964 0 $arg_hash->{PeerAddr} = $host;
965 } else {
966 87 my ($port,$addr) = sockaddr_in( $sockaddr);
967 87 $arg_hash->{PeerPort} = $port;
968 87 $arg_hash->{PeerAddr} = inet_ntoa( $addr );
969 }
970 }
971 }
972  
973 #Call to accept occurs when a new client connects to a server using
974 #IO::Socket::SSL
975 sub accept {
976 67 ▶ my $self = shift || return _invalid_object();
Subroutine accept: called CC=14 SCAR=27.5
Pod documented
Condition50%1/2
shift() || (return _invalid_object())
l!l
670
MC/DC0%0/1
shift() || (return _invalid_object())
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
977 67 ▶ my $class = shift || 'IO::Socket::SSL';
Condition50%1/2
shift() || 'IO::Socket::SSL'
l!l
067
MC/DC0%0/1
shift() || 'IO::Socket::SSL'
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
978  
979 67 my $socket = ${*$self}{'_SSL_opening'};
980 67 ▶ if ( ! $socket ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($socket) 67 0 67
981 # underlying socket not done
982 67 ▶ $DEBUG>=2 && DEBUG('no socket yet' );
Branch: 1 branch
BranchTrueFalseTotal
$IO::Socket::SSL::DEBUG >= 2 and DEBUG("no socket yet") 0 67 67
983 67 ▶ $socket = $self->SUPER::accept($class) || return;
Condition50%1/2
$self->SUPER::accept($class) || (return)
l!l
670
MC/DC0%0/1
$self->SUPER::accept($class) || (return)
$self->SUPER::accept($class)
Truth table50%1/2
A
A= $self->SUPER::accept($class)
Aresult
11
00
984 67 ▶ $DEBUG>=2 && DEBUG('accept created normal socket '.$socket );
Branch: 1 branch
BranchTrueFalseTotal
$IO::Socket::SSL::DEBUG >= 2 and DEBUG('accept created normal socket ' . $socket) 0 67 67
985  
986 # don't continue with accept_SSL if SSL_startHandshake is set to 0
987 67 my $sh = ${*$self}{_SSL_arguments}{SSL_startHandshake};
988 67 ▶ if (defined $sh && ! $sh) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $sh and not $sh) 19 48 67
Condition66%2/3
defined $sh and not $sh
!ll&&!rl&&r
48019
MC/DC50%1/2
defined $sh and not $sh
defined $sh not $sh
Truth table66%2/3
A and not(B)
A= defined $shB= not $sh
ABresult
0X0
100
111
989 19 ${*$socket}{_SSL_ctx} = ${*$self}{_SSL_ctx};
990 19 ${*$socket}{_SSL_arguments} = {
991 19 %{${*$self}{_SSL_arguments}},
992 SSL_server => 0,
993 };
994 19 ▶ $DEBUG>=2 && DEBUG('will not start SSL handshake yet');
Branch: 1 branch
BranchTrueFalseTotal
$IO::Socket::SSL::DEBUG >= 2 and DEBUG("will not start SSL handshake yet") 0 19 19
995 19 ▶ return wantarray ? ($socket, getpeername($socket) ) : $socket
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 19 19
996 }
997 }
998  
999 48 ▶ $self->accept_SSL($socket) || return;
Branch: 1 branch
BranchTrueFalseTotal
$self->accept_SSL($socket) or return 4 44 48
1000 44 ▶ $DEBUG>=2 && DEBUG('accept_SSL ok' );
Branch: 1 branch
BranchTrueFalseTotal
$IO::Socket::SSL::DEBUG >= 2 and DEBUG("accept_SSL ok") 0 44 44
1001  
1002 44 ▶ return wantarray ? ($socket, getpeername($socket) ) : $socket;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 2 42 44
1003 }
1004  
1005 sub accept_SSL {
1006 131 ▶ my $self = shift;
Subroutine accept_SSL: called CC=33 SCAR=36.8
Pod documented
1007 131 ▶ my $socket = ( @_ && UNIVERSAL::isa( $_[0], 'IO::Handle' )) ? shift : $self;
Branch: 1 branch
BranchTrueFalseTotal
@_ && UNIVERSAL::isa($_[0], 'IO::Handle') ? : 48 83 131
Condition100%3/3
@_ and UNIVERSAL::isa($_[0], "IO::Handle")
!ll&&!rl&&r
74948
MC/DC100%2/2
@_ and UNIVERSAL::isa($_[0], "IO::Handle")
@_ UNIVERSAL::isa($_[0], "IO::Handle")
Truth table100%3/3
A and B
A= @_B= UNIVERSAL::isa($_[0], "IO::Handle")
ABresult
0X0
100
111
1008 131 ▶ my $args = @_>1 ? {@_}: $_[0]||{};
Branch: 1 branch
BranchTrueFalseTotal
@_ > 1 ? : 9 122 131
Condition50%1/2
$_[0] or {}
l!l
0122
MC/DC0%0/1
$_[0] or {}
$_[0]
Truth table50%1/2
A
A= $_[0]
Aresult
11
00
1009  
1010 131 my $ssl;
1011 131 ▶ if ( ! ${*$self}{'_SSL_opening'} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (do { *$self }->{"_SSL_opening"}) 128 3 131
1012 128 ▶ $DEBUG>=2 && DEBUG('starting sslifying' );
Branch: 1 branch
BranchTrueFalseTotal
$IO::Socket::SSL::DEBUG >= 2 and DEBUG("starting sslifying") 0 128 128
1013 128 ${*$self}{'_SSL_opening'} = $socket;
1014 128 ▶ if ($socket != $self) {
Branch: 1 branch
BranchTrueFalseTotal
if ($socket != $self) 48 80 128
1015 48 ${*$socket}{_SSL_ctx} = ${*$self}{_SSL_ctx};
1016 48 ${*$socket}{_SSL_arguments} = {
1017 48 %{${*$self}{_SSL_arguments}},
1018 SSL_server => 0
1019 };
1020 }
1021  
1022 128 my $fileno = ${*$socket}{'_SSL_fileno'} = fileno($socket);
1023 128 ▶ return $socket->_internal_error("Socket has no fileno",9)
Branch: 1 branch
BranchTrueFalseTotal
unless defined $fileno 0 128 128
1024 if ! defined $fileno;
1025  
1026 128 $ssl = ${*$socket}{_SSL_object} =
1027 128 Net::SSLeay::new(${*$socket}{_SSL_ctx}{context})
1028 128 ▶ || return $socket->error("SSL structure creation failed");
Condition50%1/2
&Net::SSLeay::new(do { *$socket }->{'_SSL_ctx'}{'context'}) || (return $socket->error('SSL structure creation failed'))
l!l
1280
MC/DC0%0/1
&Net::SSLeay::new(do { *$socket }->{'_SSL_ctx'}{'context'}) || (return $socket->error('SSL structure creation failed'))
&Net::SSLeay::new(do { *$socket }->{'_SSL_ctx'}{'context'})
Truth table50%1/2
A
A= &Net::SSLeay::new(do { *$socket }->{'_SSL_ctx'}{'context'})
Aresult
11
00
1029 128 ▶ $CREATED_IN_THIS_THREAD{$ssl} = 1 if $use_threads;
Branch: 1 branch
BranchTrueFalseTotal
if $use_threads 0 128 128
1030 128 $SSL_OBJECT{$ssl} = [$socket,1];
1031 128 weaken($SSL_OBJECT{$ssl}[0]);
1032  
1033 128 ▶ Net::SSLeay::set_fd($ssl, $fileno)
Branch: 1 branch
BranchTrueFalseTotal
&Net::SSLeay::set_fd($ssl, $fileno) or return $socket->error("SSL filehandle association failed") 0 128 128
1034 || return $socket->error("SSL filehandle association failed");
1035  
1036 128 ▶ set_msg_callback($self) if $DEBUG>=2 || ${*$self}{_SSL_msg_callback};
Branch: 1 branch
BranchTrueFalseTotal
if $IO::Socket::SSL::DEBUG >= 2 or do { *$self }->{"_SSL_msg_callback"} 0 128 128
Condition33%1/3
$IO::Socket::SSL::DEBUG >= 2 or do { *$self }->{"_SSL_msg_callback"}
l!l&&r!l&&!r
00128
MC/DC0%0/2
$IO::Socket::SSL::DEBUG >= 2 or do { *$self }->{"_SSL_msg_callback"}
$IO::Socket::SSL::DEBUG >= 2 do { *$self }->{"_SSL_msg_callback"}
Truth table33%1/3
A or B
A= $IO::Socket::SSL::DEBUG >= 2B= do { *$self }->{"_SSL_msg_callback"}
ABresult
1X1
011
000
1037 }
1038  
1039 131 ▶ $ssl ||= ${*$socket}{'_SSL_object'};
Condition66%2/3
$ssl ||= do { *$socket }->{"_SSL_object"}
l!l&&r!l&&!r
12830
MC/DC0%0/2
$ssl ||= do { *$socket }->{"_SSL_object"}
$ssl do { *$socket }->{"_SSL_object"}
Truth table66%2/3
A ||= B
A= $sslB= do { *$socket }->{"_SSL_object"}
ABresult
1X1
011
000
1040  
1041 131 $SSL_ERROR = $! = undef;
1042 #$DEBUG>=2 && DEBUG('calling ssleay::accept' );
1043  
1044 my $timeout = exists $args->{Timeout}
1045 ? $args->{Timeout}
1046 131 ▶ : ${*$self}{io_socket_timeout}; # from IO::Socket
Branch: 1 branch
BranchTrueFalseTotal
exists $args->{'Timeout'} ? : 9 122 131
1047 131 ▶ if ( defined($timeout) && $timeout>0 && $socket->blocking(0) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $timeout and $timeout > 0 and $socket->blocking(0)) { } 14 117 131
Condition66%4/6
defined $timeout and $timeout > 0 and $socket->blocking(0)
!ll&&!rl&&r
117014
defined $timeout and $timeout > 0
!ll&&!rl&&r
117014
MC/DC33%1/3
defined $timeout and $timeout > 0 and $socket->blocking(0)
defined $timeout $timeout > 0 $socket->blocking(0)
Truth table50%2/4
A and B and C
A= defined $timeoutB= $timeout > 0C= $socket->blocking(0)
ABCresult
0XX0
10X0
1100
1111
1048 # timeout was given and socket was blocking
1049 # enforce timeout with now non-blocking socket
1050 } else {
1051 # timeout does not apply because invalid or socket non-blocking
1052 117 $timeout = undef;
1053 117 ▶ $auto_retry && $auto_retry->($ssl,$socket->blocking);
Branch: 1 branch
BranchTrueFalseTotal
$auto_retry and &$auto_retry($ssl, $socket->blocking) 117 0 117
1054 }
1055  
1056 131 ▶ my $start = defined($timeout) && time();
Condition66%2/3
defined $timeout && time
!ll&&!rl&&r
117014
MC/DC50%1/2
defined $timeout && time
defined $timeout time
Truth table66%2/3
A && B
A= defined $timeoutB= time
ABresult
0X0
100
111
1057 {
1058 131 $SSL_ERROR = undef;
1059 149 $CURRENT_SSL_OBJECT = $self;
1060 149 my $rv = Net::SSLeay::accept($ssl);
1061 149 $CURRENT_SSL_OBJECT = undef;
1062 149 ▶ $DEBUG>=3 && DEBUG( "Net::SSLeay::accept -> $rv" );
Branch: 1 branch
BranchTrueFalseTotal
$IO::Socket::SSL::DEBUG >= 3 and DEBUG("Net::SSLeay::accept -> $rv") 0 149 149
1063 149 ▶ if ( $rv < 0 ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($rv < 0) { } 39 110 149
elsif ($rv == 0) { } 0 110 110
1064 39 ▶ if ( my $err = $socket->_skip_rw_error( $ssl,$rv )) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $err = $socket->_skip_rw_error($ssl, $rv)) 17 22 39
1065 17 $socket->error("SSL accept attempt failed");
1066 17 delete ${*$self}{'_SSL_opening'};
1067 17 ${*$socket}{'_SSL_opened'} = -1;
1068 17 return $socket->fatal_ssl_error();
1069 }
1070  
1071 # accept failed because handshake needs to be completed
1072 # if socket was non-blocking or no timeout was given return with this error
1073 22 ▶ return if ! defined($timeout);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $timeout 3 19 22
1074  
1075 # wait until socket is readable or writable
1076 19 my $rv;
1077 19 ▶ if ( $timeout>0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($timeout > 0) { } 19 0 19
1078 19 my $vec = '';
1079 19 vec($vec,$socket->fileno,1) = 1;
1080 19 ▶ $rv =
Branch: 2 branches
BranchTrueFalseTotal
$IO::Socket::SSL::SSL_ERROR == 109619331148320 ? : 19 0 19
$IO::Socket::SSL::SSL_ERROR == 109619331148368 ? : 0 0 0
1081 $SSL_ERROR == SSL_WANT_READ ? select( $vec,undef,undef,$timeout) :
1082 $SSL_ERROR == SSL_WANT_WRITE ? select( undef,$vec,undef,$timeout) :
1083 undef;
1084 } else {
1085 0 $! = ETIMEDOUT
1086 }
1087 19 ▶ if ( ! $rv ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($rv) 1 18 19
1088 # failed because of timeout, return
1089 1 ▶ $! ||= ETIMEDOUT;
Condition50%1/2
$! ||= 110
l!l
10
MC/DC0%0/1
$! ||= 110
$!
Truth table50%1/2
A
A= $!
Aresult
11
00
1090 1 delete ${*$self}{'_SSL_opening'};
1091 1 ${*$socket}{'_SSL_opened'} = -1;
1092 1 $socket->blocking(1); # was blocking before
1093 return
1094 1 }
1095  
1096 # socket is ready, try non-blocking accept again after recomputing timeout
1097 18 my $now = time();
1098 18 $timeout -= $now - $start;
1099 18 $start = $now;
1100 18 redo;
1101  
1102 } elsif ( $rv == 0 ) {
1103 0 $socket->error("SSL accept attempt failed because of handshake problems" );
1104 0 delete ${*$self}{'_SSL_opening'};
1105 0 ${*$socket}{'_SSL_opened'} = -1;
1106 0 return $socket->fatal_ssl_error();
1107 }
1108 }
1109  
1110 110 ▶ $DEBUG>=2 && DEBUG('handshake done, socket ready' );
Branch: 1 branch
BranchTrueFalseTotal
$IO::Socket::SSL::DEBUG >= 2 and DEBUG("handshake done, socket ready") 0 110 110
1111 # socket opened
1112 110 delete ${*$self}{'_SSL_opening'};
1113 110 ${*$socket}{'_SSL_opened'} = 1;
1114 110 ▶ if (defined($timeout)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $timeout) 12 98 110
1115 12 $socket->blocking(1); # reset back to blocking
1116 12 $! = undef; # reset errors from non-blocking
1117 }
1118  
1119 110 tie *{$socket}, "IO::Socket::SSL::SSL_HANDLE", $socket;
1120  
1121 110 return $socket;
1122 }
1123  
1124  
1125 # support user defined message callback but also internal debugging
1126 sub _msg_callback {
1127 ## my ($direction, $ssl_ver, $content_type, $buf, $len, $ssl, $userp) = @_;
1128 0 ▶ IO::Socket::SSL::Trace::ossl_trace(@_) if $DEBUG>=2;
Subroutine _msg_callback: not called CC=5 SCAR=34.0
Branch: 1 branch
BranchTrueFalseTotal
if $IO::Socket::SSL::DEBUG >= 2 0 0 0
1129 0 ▶ my $self = ($SSL_OBJECT{$_[5]} || return)->[0] || return;
Condition0%0/4
+($SSL_OBJECT{$_[5]} || (return))->[0] || (return)
l!l
00
$SSL_OBJECT{$_[5]} || (return)
l!l
00
MC/DC0%0/1
+($SSL_OBJECT{$_[5]} || (return))->[0] || (return)
$SSL_OBJECT{$_[5]}
Truth table0%0/2
A
A= $SSL_OBJECT{$_[5]}
Aresult
11
00
1130 0 ▶ if (my $cb = ${*$self}{_SSL_msg_callback}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $cb = do { *$self }->{"_SSL_msg_callback"}) 0 0 0
1131 0 my ($sub,@arg) = @$cb;
1132 0 $sub->($self, @_[0..5], @arg);
1133 }
1134 }
1135  
1136 82 ▶my $ssleay_set_msg_callback = defined &Net::SSLeay::set_msg_callback
Condition50%1/2
defined &Net::SSLeay::set_msg_callback && \&Net::SSLeay::set_msg_callback
!ll
082
MC/DC0%0/1
defined &Net::SSLeay::set_msg_callback && \&Net::SSLeay::set_msg_callback
defined &Net::SSLeay::set_msg_callback
Truth table50%1/2
A
A= defined &Net::SSLeay::set_msg_callback
Aresult
00
11
1137 && \&Net::SSLeay::set_msg_callback;
1138  
1139 sub set_msg_callback {
1140 0 ▶ my $self = shift;
Subroutine set_msg_callback: not called CC=8 SCAR=42.8
Pod documented
1141 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
1142 0 ▶ if ($_[0]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_[0]) { } 0 0 0
1143 # enable user defined callback: ($cb,@arg)
1144 0 ▶ die "no support for msg callback with this version of Net::SSLeay/OpenSSL"
Branch: 1 branch
BranchTrueFalseTotal
unless $ssleay_set_msg_callback 0 0 0
1145 if !$ssleay_set_msg_callback;
1146 0 ${*$self}{_SSL_msg_callback} = [@_];
1147 } else {
1148 # disable user defined callback
1149 0 delete ${*$self}{_SSL_msg_callback};
1150 }
1151 }
1152  
1153 # activate user set callback and/or internal for debugging
1154 0 ▶ if ($ssleay_set_msg_callback and my $ssl = ${*$self}{_SSL_object}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ssleay_set_msg_callback and my $ssl = do { *$self }->{"_SSL_object"}) 0 0 0
Condition0%0/3
$ssleay_set_msg_callback and my $ssl = do { *$self }->{"_SSL_object"}
!ll&&!rl&&r
000
MC/DC0%0/2
$ssleay_set_msg_callback and my $ssl = do { *$self }->{"_SSL_object"}
$ssleay_set_msg_callback my $ssl = do { *$self }->{"_SSL_object"}
Truth table0%0/3
A and B
A= $ssleay_set_msg_callbackB= my $ssl = do { *$self }->{"_SSL_object"}
ABresult
0X0
100
111
1155 $ssleay_set_msg_callback->($ssl,
1156 0 ▶ ($DEBUG>=2 || ${*$self}{_SSL_msg_callback})? \&_msg_callback : undef)
Branch: 1 branch
BranchTrueFalseTotal
$IO::Socket::SSL::DEBUG >= 2 || do { *$self }->{'_SSL_msg_callback'} ? : 0 0 0
Condition0%0/3
$IO::Socket::SSL::DEBUG >= 2 or do { *$self }->{"_SSL_msg_callback"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$IO::Socket::SSL::DEBUG >= 2 or do { *$self }->{"_SSL_msg_callback"}
$IO::Socket::SSL::DEBUG >= 2 do { *$self }->{"_SSL_msg_callback"}
Truth table0%0/3
A or B
A= $IO::Socket::SSL::DEBUG >= 2B= do { *$self }->{"_SSL_msg_callback"}
ABresult
1X1
011
000
1157 }
1158 }
1159  
1160  
1161 ####### I/O subroutines ########################
1162  
1163 82 ▶if ($auto_retry) {
Branch: 1 branch
BranchTrueFalseTotal
if ($auto_retry) 82 0 82
1164 *blocking = sub {
1165 642 ▶ my $self = shift;
Subroutine __ANON__: called CC=3 SCAR=11.0
1166 642 ▶ { @_ && $auto_retry->(${*$self}{_SSL_object} || last, @_); }
Branch: 1 branch
BranchTrueFalseTotal
@_ and &$auto_retry(do { *$self }->{"_SSL_object"} || (last), @_) 194 448 642
Condition100%2/2
do { *$self }->{'_SSL_object'} || (last)
l!l
51143
MC/DC100%1/1
do { *$self }->{'_SSL_object'} || (last)
do { *$self }->{'_SSL_object'}
Truth table100%2/2
A
A= do { *$self }->{'_SSL_object'}
Aresult
11
00
1167 642 return $self->SUPER::blocking(@_);
1168 82 };
1169 }
1170  
1171 sub _generic_read {
1172 6117 ▶ my ($self, $read_func, undef, $length, $offset) = @_;
Subroutine _generic_read: called CC=11 SCAR=24.7
1173 6117 ▶ my $ssl = ${*$self}{_SSL_object} || return;
Condition50%1/2
do { *$self }->{'_SSL_object'} || (return)
l!l
61170
MC/DC0%0/1
do { *$self }->{'_SSL_object'} || (return)
do { *$self }->{'_SSL_object'}
Truth table50%1/2
A
A= do { *$self }->{'_SSL_object'}
Aresult
11
00
1174 6117 my $buffer=\$_[2];
1175  
1176 6117 $SSL_ERROR = $! = undef;
1177 6117 my ($data,$rwerr) = $read_func->($ssl, $length);
1178 6117 ▶ while ( ! defined($data)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $data) 8 6109 6117
1179 8 ▶ if ( my $err = $self->_skip_rw_error( $ssl, defined($rwerr) ? $rwerr:-1 )) {
Branch: 2 branches
BranchTrueFalseTotal
if (my $err = $self->_skip_rw_error($ssl, defined $rwerr ? $rwerr : -1)) 7 1 8
defined $rwerr ? : 8 0 8
1180 # OpenSSL 1.1.0c+ : EOF can now result in SSL_read returning -1 and SSL_ERROR_SYSCALL
1181 # OpenSSL 3.0 : EOF can now result in SSL_read returning -1 and SSL_ERROR_SSL
1182 7 ▶ if (not $! and $err == $Net_SSLeay_ERROR_SSL || $err == $Net_SSLeay_ERROR_SYSCALL) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $! and $err == $Net_SSLeay_ERROR_SSL || $err == $Net_SSLeay_ERROR_SYSCALL) 7 0 7
Condition33%2/6
not $! and $err == $Net_SSLeay_ERROR_SSL || $err == $Net_SSLeay_ERROR_SYSCALL
!ll&&!rl&&r
070
$err == $Net_SSLeay_ERROR_SSL or $err == $Net_SSLeay_ERROR_SYSCALL
l!l&&r!l&&!r
700
MC/DC0%0/3
not $! and $err == $Net_SSLeay_ERROR_SSL || $err == $Net_SSLeay_ERROR_SYSCALL
not $! $err == $Net_SSLeay_ERROR_SSL $err == $Net_SSLeay_ERROR_SYSCALL
Truth table0%0/4
not(A) and B or C
A= not $!B= $err == $Net_SSLeay_ERROR_SSLC= $err == $Net_SSLeay_ERROR_SYSCALL
ABCresult
0XX0
1000
11X1
1011
1183 # treat as EOF
1184 7 $data = '';
1185 7 last;
1186 }
1187 0 $self->error("SSL read error");
1188 }
1189 1 return;
1190 }
1191  
1192 6116 $length = length($data);
1193 6116 ▶ $$buffer = '' if !defined $$buffer;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $$buffer 6088 28 6116
1194 6116 ▶ $offset ||= 0;
Condition100%2/2
$offset ||= 0
l!l
106106
MC/DC100%1/1
$offset ||= 0
$offset
Truth table100%2/2
A
A= $offset
Aresult
11
00
1195 6116 ▶ if ($offset>length($$buffer)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($offset > length $$buffer) 1 6115 6116
1196 1 $$buffer.="\0" x ($offset-length($$buffer)); #mimic behavior of read
1197 }
1198  
1199 6116 substr($$buffer, $offset, length($$buffer), $data);
1200 6116 return $length;
1201 }
1202  
1203 sub read {
1204 6 ▶ my $self = shift;
Subroutine read: called CC=3 SCAR=11.4
Pod undocumented
1205 6 ▶ ${*$self}{_SSL_object} && return _generic_read($self,
Branch: 2 branches
BranchTrueFalseTotal
do { *$self }->{"_SSL_object"} and return _generic_read($self, $self->blocking ? \&Net::SSLeay::ssl_read_all : \&Net::SSLeay::read, @_) 6 0 6
$self->blocking ? : 5 1 6
1206 $self->blocking ? \&Net::SSLeay::ssl_read_all : \&Net::SSLeay::read,
1207 @_
1208 );
1209  
1210 # fall back to plain read if we are not required to use SSL yet
1211 0 return $self->SUPER::read(@_);
1212 }
1213  
1214 # contrary to the behavior of read sysread can read partial data
1215 sub sysread {
1216 6110 ▶ my $self = shift;
Subroutine sysread: called CC=2 SCAR=8.4
Pod documented
1217 6110 ▶ ${*$self}{_SSL_object} && return _generic_read( $self,
Branch: 1 branch
BranchTrueFalseTotal
do { *$self }->{"_SSL_object"} and return _generic_read($self, \&Net::SSLeay::read, @_) 6110 0 6110
1218 \&Net::SSLeay::read, @_ );
1219  
1220 # fall back to plain sysread if we are not required to use SSL yet
1221 0 my $rv = $self->SUPER::sysread(@_);
1222 0 return $rv;
1223 }
1224  
1225 sub peek {
1226 6 ▶ my $self = shift;
Subroutine peek: called CC=4 SCAR=14.0
Pod documented
1227 6 ▶ ${*$self}{_SSL_object} && return _generic_read( $self,
Branch: 1 branch
BranchTrueFalseTotal
do { *$self }->{"_SSL_object"} and return _generic_read($self, \&Net::SSLeay::peek, @_) 1 5 6
1228 \&Net::SSLeay::peek, @_ );
1229  
1230 # fall back to plain peek if we are not required to use SSL yet
1231 # emulate peek with recv(...,MS_PEEK) - peek(buf,len,offset)
1232 5 ▶ return if ! defined recv($self,my $buf,$_[1],MSG_PEEK);
Branch: 1 branch
BranchTrueFalseTotal
unless defined CORE::recv($self, my $buf, $_[1], 2) 0 5 5
1233 5 ▶ $_[0] = $_[2] ? substr($_[0],0,$_[2]).$buf : $buf;
Branch: 1 branch
BranchTrueFalseTotal
$_[2] ? : 0 5 5
1234 5 return length($buf);
1235 }
1236  
1237  
1238 sub _generic_write {
1239 9259 ▶ my ($self, $write_all, undef, $length, $offset) = @_;
Subroutine _generic_write: called CC=15 SCAR=28.0
1240  
1241 9259 ▶ my $ssl = ${*$self}{_SSL_object} || return;
Condition50%1/2
do { *$self }->{'_SSL_object'} || (return)
l!l
92590
MC/DC0%0/1
do { *$self }->{'_SSL_object'} || (return)
do { *$self }->{'_SSL_object'}
Truth table50%1/2
A
A= do { *$self }->{'_SSL_object'}
Aresult
11
00
1242 9259 my $buffer = \$_[2];
1243  
1244 9259 my $buf_len = length($$buffer);
1245 9259 ▶ $length ||= $buf_len;
Condition66%2/3
$length ||= $buf_len
l!l&&r!l&&!r
9199600
MC/DC0%0/2
$length ||= $buf_len
$length $buf_len
Truth table66%2/3
A ||= B
A= $lengthB= $buf_len
ABresult
1X1
011
000
1246 9259 ▶ $offset ||= 0;
Condition100%2/2
$offset ||= 0
l!l
29257
MC/DC100%1/1
$offset ||= 0
$offset
Truth table100%2/2
A
A= $offset
Aresult
11
00
1247 9259 ▶ return $self->_internal_error("Invalid offset for SSL write",9)
Branch: 1 branch
BranchTrueFalseTotal
if $offset > $buf_len 0 9259 9259
1248 if $offset>$buf_len;
1249 9259 ▶ return 0 if ($offset == $buf_len);
Branch: 1 branch
BranchTrueFalseTotal
if $offset == $buf_len 0 9259 9259
1250  
1251 9259 $SSL_ERROR = $! = undef;
1252 9259 my $written;
1253 9259 ▶ if ( $write_all ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($write_all) { } 59 9200 9259
1254 59 ▶ my $data = $length < $buf_len-$offset ? substr($$buffer, $offset, $length) : $$buffer;
Branch: 1 branch
BranchTrueFalseTotal
$length < $buf_len - $offset ? : 0 59 59
1255 59 ($written, my $errs) = Net::SSLeay::ssl_write_all($ssl, $data);
1256 # ssl_write_all returns number of bytes written
1257 59 ▶ $written = undef if ! $written && $errs;
Branch: 1 branch
BranchTrueFalseTotal
if not $written and $errs 0 59 59
Condition33%1/3
not $written and $errs
!ll&&!rl&&r
5900
MC/DC0%0/2
not $written and $errs
not $written $errs
Truth table33%1/3
not(A) and B
A= not $writtenB= $errs
ABresult
0X0
100
111
1258 } else {
1259 9200 $written = Net::SSLeay::write_partial( $ssl,$offset,$length,$$buffer );
1260 # write_partial does SSL_write which returns -1 on error
1261 9200 ▶ $written = undef if $written <= 0;
Branch: 1 branch
BranchTrueFalseTotal
if $written <= 0 4 9196 9200
1262 }
1263 9259 ▶ if ( !defined($written) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $written) 4 9255 9259
1264 4 ▶ if ( my $err = $self->_skip_rw_error( $ssl,-1 )) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $err = $self->_skip_rw_error($ssl, -1)) 2 2 4
1265 # if $! is not set with ERROR_SYSCALL then report as EPIPE
1266 2 ▶ $! ||= EPIPE if $err == $Net_SSLeay_ERROR_SYSCALL;
Branch: 1 branch
BranchTrueFalseTotal
if $err == $Net_SSLeay_ERROR_SYSCALL 2 0 2
Condition50%1/2
$! ||= 32
l!l
20
MC/DC0%0/1
$! ||= 32
$!
Truth table50%1/2
A
A= $!
Aresult
11
00
1267 2 $self->error("SSL write error ($err)");
1268 }
1269 4 return;
1270 }
1271  
1272 9255 return $written;
1273 }
1274  
1275 # if socket is blocking write() should return only on error or
1276 # if all data are written
1277 sub write {
1278 60 ▶ my $self = shift;
Subroutine write: called CC=2 SCAR=7.6
Pod documented
1279 60 ▶ ${*$self}{_SSL_object} && return _generic_write( $self,
Branch: 1 branch
BranchTrueFalseTotal
do { *$self }->{"_SSL_object"} and return _generic_write($self, scalar $self->blocking, @_) 60 0 60
1280 scalar($self->blocking),@_ );
1281  
1282 # fall back to plain write if we are not required to use SSL yet
1283 0 return $self->SUPER::write(@_);
1284 }
1285  
1286 # contrary to write syswrite() returns already if only
1287 # a part of the data is written
1288 sub syswrite {
1289 9199 ▶ my $self = shift;
Subroutine syswrite: called CC=2 SCAR=7.6
Pod documented
1290 9199 ▶ ${*$self}{_SSL_object} && return _generic_write($self,0,@_);
Branch: 1 branch
BranchTrueFalseTotal
do { *$self }->{"_SSL_object"} and return _generic_write($self, 0, @_) 9199 0 9199
1291  
1292 # fall back to plain syswrite if we are not required to use SSL yet
1293 0 return $self->SUPER::syswrite(@_);
1294 }
1295  
1296 sub print {
1297 57 ▶ my $self = shift;
Subroutine print: called CC=3 SCAR=11.7
Pod undocumented
1298 57 ▶ my $string = join(($, or ''), @_, ($\ or ''));
Condition50%2/4
$, || ''
l!l
057
$\ || ''
l!l
057
MC/DC0%0/1
$, || ''
$,
MC/DC0%0/1
$\ || ''
$\
Truth table50%1/2
A
A= $,
Aresult
11
00
Truth table50%1/2
A
A= $\
Aresult
11
00
1299 57 return $self->write( $string );
1300 }
1301  
1302 sub printf {
1303 2 ▶ my ($self,$format) = (shift,shift);
Subroutine printf: called CC=1 SCAR=0.0
Pod undocumented
1304 2 return $self->write(sprintf($format, @_));
1305 }
1306  
1307 sub getc {
1308 2 ▶ my ($self, $buffer) = (shift, undef);
Subroutine getc: called CC=2 SCAR=7.2
Pod undocumented
1309 2 ▶ return $buffer if $self->read($buffer, 1, 0);
Branch: 1 branch
BranchTrueFalseTotal
if $self->read($buffer, 1, 0) 2 0 2
1310 }
1311  
1312 sub readline {
1313 87 ▶ my $self = shift;
Subroutine readline: called CC=40 SCAR=41.1
Pod undocumented
1314 87 ▶ ${*$self}{_SSL_object} or return $self->SUPER::getline;
Branch: 1 branch
BranchTrueFalseTotal
do { *$self }->{"_SSL_object"} or return $self->SUPER::getline 0 87 87
1315  
1316 87 ▶ if ( not defined $/ or wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $/ or wantarray) 7 80 87
Condition100%3/3
not defined $/ or wantarray
l!l&&r!l&&!r
2580
MC/DC100%2/2
not defined $/ or wantarray
not defined $/ wantarray
Truth table100%3/3
not(A) or B
A= not defined $/B= wantarray
ABresult
1X1
011
000
1317 # read all and split
1318  
1319 7 my $buf = '';
1320 7 while (1) {
1321 14 my $rv = $self->sysread($buf,2**16,length($buf));
1322 14 ▶ if ( ! defined $rv ) {
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $rv) { } 0 14 14
elsif (not $rv) { } 7 7 14
1323 0 ▶ next if $! == EINTR; # retry
Branch: 1 branch
BranchTrueFalseTotal
if $! == 4 0 0 0
1324 0 ▶ last if $! == EWOULDBLOCK || $! == EAGAIN; # use everything so far
Branch: 1 branch
BranchTrueFalseTotal
if $! == 11 or $! == 11 0 0 0
Condition0%0/3
$! == 11 or $! == 11
l!l&&r!l&&!r
000
MC/DC0%0/2
$! == 11 or $! == 11
$! == 11 $! == 11
Truth table0%0/3
A or B
A= $! == 11B= $! == 11
ABresult
1X1
011
000
1325 0 return; # return error
1326 } elsif ( ! $rv ) {
1327 last
1328 7 }
1329 }
1330  
1331 7 ▶ if ( ! defined $/ ) {
Branch: 3 branches
BranchTrueFalseTotal
if (not defined $/) { } 2 5 7
elsif (ref $/) { } 1 4 5
elsif ($/ eq '') { } 1 3 4
1332 2 return $buf
1333 } elsif ( ref($/)) {
1334 1 my $size = ${$/};
1335 1 ▶ die "bad value in ref \$/: $size" unless $size>0;
Branch: 1 branch
BranchTrueFalseTotal
unless $size > 0 0 1 1
1336 1 return $buf=~m{\G(.{1,$size})}g;
1337 } elsif ( $/ eq '' ) {
1338 1 return $buf =~m{\G(.*\n\n+|.+)}g;
1339 } else {
1340 3 return $buf =~m{\G(.*$/|.+)}g;
1341 }
1342 }
1343  
1344 # read only one line
1345 80 ▶ if ( ref($/) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $/) 1 79 80
1346 1 my $size = ${$/};
1347 # read record of $size bytes
1348 1 ▶ die "bad value in ref \$/: $size" unless $size>0;
Branch: 1 branch
BranchTrueFalseTotal
unless $size > 0 0 1 1
1349 1 my $buf = '';
1350 1 ▶ while ( $size>length($buf)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($size > length $buf) 1 1 2
1351 1 my $rv = $self->sysread($buf,$size-length($buf),length($buf));
1352 1 ▶ if ( ! defined $rv ) {
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $rv) { } 0 1 1
elsif (not $rv) { } 0 1 1
1353 0 ▶ next if $! == EINTR; # retry
Branch: 1 branch
BranchTrueFalseTotal
if $! == 4 0 0 0
1354 0 ▶ last if $! == EWOULDBLOCK || $! == EAGAIN; # use everything so far
Branch: 1 branch
BranchTrueFalseTotal
if $! == 11 or $! == 11 0 0 0
Condition0%0/3
$! == 11 or $! == 11
l!l&&r!l&&!r
000
MC/DC0%0/2
$! == 11 or $! == 11
$! == 11 $! == 11
Truth table0%0/3
A or B
A= $! == 11B= $! == 11
ABresult
1X1
011
000
1355 0 return; # return error
1356 } elsif ( ! $rv ) {
1357 last
1358 0 }
1359 }
1360 1 return $buf;
1361 }
1362  
1363 79 ▶ my ($delim0,$delim1) = $/ eq '' ? ("\n\n","\n"):($/,'');
Branch: 1 branch
BranchTrueFalseTotal
$/ eq '' ? : 1 78 79
1364  
1365 # find first occurrence of $delim0 followed by as much as possible $delim1
1366 79 my $buf = '';
1367 79 my $eod = 0; # pointer into $buf after $delim0 $delim1*
1368 79 ▶ my $ssl = $self->_get_ssl_object or return;
Branch: 1 branch
BranchTrueFalseTotal
my $ssl = $self->_get_ssl_object or return 0 79 79
1369 79 while (1) {
1370  
1371 # wait until we have more data or eof
1372 83 my $poke = Net::SSLeay::peek($ssl,1);
1373 83 ▶ if ( ! defined $poke or $poke eq '' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $poke or $poke eq "") 25 58 83
Condition100%3/3
not defined $poke or $poke eq ""
l!l&&r!l&&!r
18758
MC/DC100%2/2
not defined $poke or $poke eq ""
not defined $poke $poke eq ""
Truth table100%3/3
not(A) or B
A= not defined $pokeB= $poke eq ""
ABresult
1X1
011
000
1374 25 ▶ next if $! == EINTR;
Branch: 1 branch
BranchTrueFalseTotal
if $! == 4 1 24 25
1375 }
1376  
1377 82 my $skip = 0;
1378  
1379 # peek into available data w/o reading
1380 82 my $pending = Net::SSLeay::pending($ssl);
1381 82 ▶ if ( $pending and
Branch: 1 branch
BranchTrueFalseTotal
if ($pending and (my $pb = &Net::SSLeay::peek($ssl, $pending)) ne '') { } 58 24 82
Condition66%2/3
$pending and (my $pb = &Net::SSLeay::peek($ssl, $pending)) ne ""
!ll&&!rl&&r
24058
MC/DC50%1/2
$pending and (my $pb = &Net::SSLeay::peek($ssl, $pending)) ne ""
$pending (my $pb = &Net::SSLeay::peek($ssl, $pending)) ne ""
Truth table66%2/3
A and B
A= $pendingB= (my $pb = &Net::SSLeay::peek($ssl, $pending)) ne ""
ABresult
0X0
100
111
1382 ( my $pb = Net::SSLeay::peek( $ssl,$pending )) ne '' ) {
1383 58 $buf .= $pb
1384 } else {
1385 24 ▶ return $buf eq '' ? ():$buf;
Branch: 1 branch
BranchTrueFalseTotal
$buf eq '' ? : 23 1 24
1386 }
1387 58 ▶ if ( !$eod ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($eod) 58 0 58
1388 58 my $pos = index( $buf,$delim0 );
1389 58 ▶ if ( $pos<0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pos < 0) { } 3 55 58
1390 3 $skip = $pending
1391 } else {
1392 55 $eod = $pos + length($delim0); # pos after delim0
1393 }
1394 }
1395  
1396 58 ▶ if ( $eod ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($eod) 55 3 58
1397 55 ▶ if ( $delim1 ne '' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($delim1 ne "") 1 54 55
1398 # delim0 found, check for as much delim1 as possible
1399 1 ▶ while ( index( $buf,$delim1,$eod ) == $eod ) {
Branch: 1 branch
BranchTrueFalseTotal
if (index($buf, $delim1, $eod) == $eod) 2 1 3
1400 2 $eod+= length($delim1);
1401 }
1402 }
1403 55 $skip = $pending - ( length($buf) - $eod );
1404 }
1405  
1406 # remove data from $self which I already have in buf
1407 58 ▶ while ( $skip>0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($skip > 0) 58 58 116
1408 58 ▶ if ($self->sysread(my $p,$skip,0)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->sysread(my $p, $skip, 0)) 58 0 58
1409 58 $skip -= length($p);
1410 58 next;
1411 }
1412 0 ▶ $! == EINTR or last;
Branch: 1 branch
BranchTrueFalseTotal
$! == 4 or last 0 0 0
1413 }
1414  
1415 58 ▶ if ( $eod and ( $delim1 eq '' or $eod < length($buf))) {
Branch: 1 branch
BranchTrueFalseTotal
if ($eod and $delim1 eq "" || $eod < length $buf) 55 3 58
Condition83%5/6
$eod and $delim1 eq "" || $eod < length $buf
!ll&&!rl&&r
3532
$delim1 eq "" or $eod < length $buf
l!l&&r!l&&!r
5410
MC/DC33%1/3
$eod and $delim1 eq "" || $eod < length $buf
$eod $delim1 eq "" $eod < length $buf
Truth table50%2/4
A and B or C
A= $eodB= $delim1 eq ""C= $eod < length $buf
ABCresult
0XX0
1000
11X1
1011
1416 # delim0 found and there can be no more delim1 pending
1417 last
1418 55 }
1419 }
1420 55 return substr($buf,0,$eod);
1421 }
1422  
1423 sub close {
1424 262 ▶ my $self = shift || return _invalid_object();
Subroutine close: called CC=5 SCAR=16.2
Pod documented
Condition50%1/2
shift() || (return _invalid_object())
l!l
2620
MC/DC0%0/1
shift() || (return _invalid_object())
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
1425 262 ▶ my $close_args = (ref($_[0]) eq 'HASH') ? $_[0] : {@_};
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq 'HASH' ? : 0 262 262
1426  
1427 262 ▶ return if ! $self->stop_SSL(
Branch: 1 branch
BranchTrueFalseTotal
unless $self->stop_SSL("SSL_fast_shutdown", 1, %$close_args, "_SSL_ioclass_downgrade", 0) 4 258 262
1428 SSL_fast_shutdown => 1,
1429 %$close_args,
1430 _SSL_ioclass_downgrade => 0,
1431 );
1432  
1433 258 ▶ if ( ! $close_args->{_SSL_in_DESTROY} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($close_args->{"_SSL_in_DESTROY"}) 56 202 258
1434 56 untie( *$self );
1435 56 undef ${*$self}{_SSL_fileno};
1436 56 return $self->SUPER::close;
1437 }
1438 202 return 1;
1439 }
1440  
1441 sub is_SSL {
1442 0 ▶ my $self = pop;
Subroutine is_SSL: not called CC=2 SCAR=17.9
Pod undocumented
1443 0 ▶ return ${*$self}{_SSL_object} && 1
Condition0%0/2
do { *$self }->{'_SSL_object'} && 1
!ll
00
MC/DC0%0/1
do { *$self }->{'_SSL_object'} && 1
do { *$self }->{'_SSL_object'}
Truth table0%0/2
A
A= do { *$self }->{'_SSL_object'}
Aresult
00
11
1444 }
1445  
1446 sub stop_SSL {
1447 304 ▶ my $self = shift || return _invalid_object();
Subroutine stop_SSL: called CC=33 SCAR=37.1
Pod documented
Condition50%1/2
shift() || (return _invalid_object())
l!l
3040
MC/DC0%0/1
shift() || (return _invalid_object())
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
1448 304 ▶ my $stop_args = (ref($_[0]) eq 'HASH') ? $_[0] : {@_};
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq 'HASH' ? : 0 304 304
1449 304 ▶ $stop_args->{SSL_no_shutdown} = 1 if ! ${*$self}{_SSL_opened};
Branch: 1 branch
BranchTrueFalseTotal
unless do { *$self }->{"_SSL_opened"} 1 303 304
1450  
1451 304 ▶ if (my $ssl = ${*$self}{'_SSL_object'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $ssl = do { *$self }->{"_SSL_object"}) 302 2 304
1452 302 ▶ if (delete ${*$self}{'_SSL_opening'}) {
Branch: 2 branches
BranchTrueFalseTotal
if (delete do { *$self }->{'_SSL_opening'}) { } 0 302 302
elsif (not $stop_args->{'SSL_no_shutdown'}) { } 99 203 302
1453 # just destroy the object further below
1454 } elsif ( ! $stop_args->{SSL_no_shutdown} ) {
1455 99 my $status = Net::SSLeay::get_shutdown($ssl);
1456  
1457 my $timeout =
1458 not($self->blocking) ? undef :
1459 exists $stop_args->{Timeout} ? $stop_args->{Timeout} :
1460 99 ▶ ${*$self}{io_socket_timeout}; # from IO::Socket
Branch: 2 branches
BranchTrueFalseTotal
!$self->blocking ? : 6 93 99
exists $stop_args->{'Timeout'} ? : 0 93 93
1461 99 ▶ if ($timeout) {
Branch: 1 branch
BranchTrueFalseTotal
if ($timeout) 3 96 99
1462 3 $self->blocking(0);
1463 3 $timeout += time();
1464 }
1465  
1466 99 while (1) {
1467 161 ▶ if ( $status & SSL_SENT_SHUTDOWN and
Branch: 1 branch
BranchTrueFalseTotal
if ($status & 1 and $status & 2 || $stop_args->{"SSL_fast_shutdown"}) 52 109 161
Condition100%6/6
$status & 1 and $status & 2 || $stop_args->{"SSL_fast_shutdown"}
!ll&&!rl&&r
991844
$status & 2 or $stop_args->{"SSL_fast_shutdown"}
l!l&&r!l&&!r
104210
MC/DC66%2/3
$status & 1 and $status & 2 || $stop_args->{"SSL_fast_shutdown"}
$status & 1 $status & 2 $stop_args->{"SSL_fast_shutdown"}
Truth table75%3/4
A and B or C
A= $status & 1B= $status & 2C= $stop_args->{"SSL_fast_shutdown"}
ABCresult
0XX0
1000
11X1
1011
1468 # don't care for received if fast shutdown
1469 $status & SSL_RECEIVED_SHUTDOWN
1470 || $stop_args->{SSL_fast_shutdown}) {
1471 # shutdown complete
1472 52 last;
1473 }
1474 109 ▶ if ((${*$self}{'_SSL_opened'}||0) <= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ((do { *$self }->{"_SSL_opened"} || 0) <= 0) 43 66 109
Condition50%1/2
do { *$self }->{'_SSL_opened'} || 0
l!l
1090
MC/DC0%0/1
do { *$self }->{'_SSL_opened'} || 0
do { *$self }->{'_SSL_opened'}
Truth table50%1/2
A
A= do { *$self }->{'_SSL_opened'}
Aresult
11
00
1475 # not really open, thus don't expect shutdown to return
1476 # something meaningful
1477 43 last;
1478 }
1479  
1480 # initiate or complete shutdown
1481 66 local $SIG{PIPE} = 'IGNORE';
1482 66 $SSL_ERROR = $! = undef;
1483 66 my $rv = Net::SSLeay::shutdown($ssl);
1484 66 ▶ if ( $rv < 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rv < 0) 4 62 66
1485 # non-blocking socket?
1486 4 ▶ if ( ! $timeout ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($timeout) 4 0 4
1487 4 ▶ if ( my $err = $self->_skip_rw_error( $ssl, $rv )) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $err = $self->_skip_rw_error($ssl, $rv)) 4 0 4
1488 # if $! is not set with ERROR_SYSCALL then report as EPIPE
1489 4 ▶ $! ||= EPIPE if $err == $Net_SSLeay_ERROR_SYSCALL;
Branch: 1 branch
BranchTrueFalseTotal
if $err == $Net_SSLeay_ERROR_SYSCALL 4 0 4
Condition50%1/2
$! ||= 32
l!l
40
MC/DC0%0/1
$! ||= 32
$!
Truth table50%1/2
A
A= $!
Aresult
11
00
1490 4 $self->error("SSL shutdown error ($err)");
1491 }
1492 # need to try again
1493 4 return;
1494 }
1495  
1496 # don't use _skip_rw_error so that existing error does
1497 # not get cleared
1498 0 my $wait = $timeout - time();
1499 0 ▶ last if $wait<=0;
Branch: 1 branch
BranchTrueFalseTotal
if $wait <= 0 0 0 0
1500 0 vec(my $vec = '',fileno($self),1) = 1;
1501 0 my $err = Net::SSLeay::get_error($ssl,$rv);
1502 0 ▶ if ( $err == $Net_SSLeay_ERROR_WANT_READ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($err == $Net_SSLeay_ERROR_WANT_READ) { } 0 0 0
elsif ($err == $Net_SSLeay_ERROR_WANT_READ) { } 0 0 0
1503 0 select($vec,undef,undef,$wait)
1504 } elsif ( $err == $Net_SSLeay_ERROR_WANT_READ) {
1505 0 select(undef,$vec,undef,$wait)
1506 } else {
1507 0 last;
1508 }
1509 }
1510  
1511 62 $status |= SSL_SENT_SHUTDOWN;
1512 62 ▶ $status |= SSL_RECEIVED_SHUTDOWN if $rv>0;
Branch: 1 branch
BranchTrueFalseTotal
if $rv > 0 10 52 62
1513 }
1514 95 ▶ $self->blocking(1) if $timeout;
Branch: 1 branch
BranchTrueFalseTotal
if $timeout 3 92 95
1515 }
1516  
1517 # destroy allocated objects for SSL and untie
1518 # do not destroy CTX unless explicitly specified
1519 298 Net::SSLeay::free($ssl);
1520 298 ▶ if (my $cert = delete ${*$self}{'_SSL_certificate'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $cert = delete do { *$self }->{"_SSL_certificate"}) 31 267 298
1521 31 Net::SSLeay::X509_free($cert);
1522 }
1523 298 delete ${*$self}{_SSL_object};
1524 298 ${*$self}{'_SSL_opened'} = 0;
1525 298 delete $SSL_OBJECT{$ssl};
1526 298 delete $CREATED_IN_THIS_THREAD{$ssl};
1527 298 untie(*$self);
1528 }
1529  
1530 300 ▶ if ($stop_args->{'SSL_ctx_free'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($stop_args->{"SSL_ctx_free"}) 3 297 300
1531 3 my $ctx = delete ${*$self}{'_SSL_ctx'};
1532 3 ▶ $ctx && $ctx->DESTROY();
Branch: 1 branch
BranchTrueFalseTotal
$ctx and $ctx->DESTROY 3 0 3
1533 }
1534  
1535  
1536 300 ▶ if ( ! $stop_args->{_SSL_in_DESTROY} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($stop_args->{"_SSL_in_DESTROY"}) 98 202 300
1537  
1538 98 my $downgrade = $stop_args->{_SSL_ioclass_downgrade};
1539 98 ▶ if ( $downgrade || ! defined $downgrade ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($downgrade or not defined $downgrade) 42 56 98
Condition66%2/3
$downgrade or not defined $downgrade
l!l&&r!l&&!r
04256
MC/DC50%1/2
$downgrade or not defined $downgrade
$downgrade not defined $downgrade
Truth table66%2/3
A or not(B)
A= $downgradeB= not defined $downgrade
ABresult
1X1
011
000
1540 # rebless to original class from start_SSL
1541 42 ▶ if ( my $orig_class = delete ${*$self}{'_SSL_ioclass_upgraded'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $orig_class = delete do { *$self }->{"_SSL_ioclass_upgraded"}) 35 7 42
1542 35 bless $self,$orig_class;
1543 # FIXME: if original class was tied too we need to restore the tie
1544 # remove all _SSL related from *$self
1545 35 my @sslkeys = grep { m{^_?SSL_} } keys %{*$self};
1546 35 ▶ delete @{*$self}{@sslkeys} if @sslkeys;
Branch: 1 branch
BranchTrueFalseTotal
if @sslkeys 35 0 35
1547 }
1548 }
1549 }
1550 300 return 1;
1551 }
1552  
1553  
1554 sub fileno {
1555 9356 ▶ my $self = shift;
Subroutine fileno: called CC=2 SCAR=6.9
Pod undocumented
1556 9356 my $fn = ${*$self}{'_SSL_fileno'};
1557 9356 ▶ return defined($fn) ? $fn : $self->SUPER::fileno();
Branch: 1 branch
BranchTrueFalseTotal
defined $fn ? : 9229 127 9356
1558 }
1559  
1560  
1561 ####### IO::Socket::SSL specific functions #######
1562 # _get_ssl_object is for internal use ONLY!
1563 sub _get_ssl_object {
1564 232 ▶ my $self = shift;
Subroutine _get_ssl_object: called CC=2 SCAR=7.6
1565 232 ▶ return ${*$self}{'_SSL_object'} ||
Condition33%1/3
do { *$self }->{'_SSL_object'} || 'IO::Socket::SSL'->_internal_error('Undefined SSL object', 9)
l!l&&r!l&&!r
23200
MC/DC0%0/2
do { *$self }->{'_SSL_object'} || 'IO::Socket::SSL'->_internal_error('Undefined SSL object', 9)
do { *$self }->{'_SSL_object'} 'IO::Socket::SSL'->_internal_error('Undefined SSL object', 9)
Truth table33%1/3
A || B
A= do { *$self }->{'_SSL_object'}B= 'IO::Socket::SSL'->_internal_error('Undefined SSL object', 9)
ABresult
1X1
011
000
1566 IO::Socket::SSL->_internal_error("Undefined SSL object",9);
1567 }
1568  
1569 # _get_ctx_object is for internal use ONLY!
1570 sub _get_ctx_object {
1571 0 ▶ my $self = shift;
Subroutine _get_ctx_object: not called CC=2 SCAR=17.9
1572 0 my $ctx_object = ${*$self}{_SSL_ctx};
1573 0 ▶ return $ctx_object && $ctx_object->{context};
Condition0%0/3
$ctx_object && $ctx_object->{'context'}
!ll&&!rl&&r
000
MC/DC0%0/2
$ctx_object && $ctx_object->{'context'}
$ctx_object $ctx_object->{'context'}
Truth table0%0/3
A && B
A= $ctx_objectB= $ctx_object->{'context'}
ABresult
0X0
100
111
1574 }
1575  
1576 # default error for undefined arguments
1577 sub _invalid_object {
1578 0 ▶ return IO::Socket::SSL->_internal_error("Undefined IO::Socket::SSL object",9);
Subroutine _invalid_object: not called CC=1 SCAR=6.9
1579 }
1580  
1581  
1582 sub pending {
1583 1 ▶ my $ssl = shift()->_get_ssl_object || return;
Subroutine pending: called CC=2 SCAR=7.2
Pod documented
Condition50%1/2
(shift())->_get_ssl_object || (return)
l!l
10
MC/DC0%0/1
(shift())->_get_ssl_object || (return)
(shift())->_get_ssl_object
Truth table50%1/2
A
A= (shift())->_get_ssl_object
Aresult
11
00
1584 1 return Net::SSLeay::pending($ssl);
1585 }
1586  
1587 sub start_SSL {
1588 147 ▶ my ($class,$socket) = (shift,shift);
Subroutine start_SSL: called CC=21 SCAR=33.4
Pod documented
1589 147 ▶ return $class->_internal_error("Not a socket",9) if ! ref($socket);
Branch: 1 branch
BranchTrueFalseTotal
unless ref $socket 0 147 147
1590 147 ▶ my $arg_hash = @_ == 1 ? $_[0] : {@_};
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 ? : 1 146 147
1591 147 ▶ my %to = exists $arg_hash->{Timeout} ? ( Timeout => delete $arg_hash->{Timeout} ) :();
Branch: 1 branch
BranchTrueFalseTotal
exists $arg_hash->{'Timeout'} ? : 11 136 147
1592 147 my $original_class = ref($socket);
1593 147 ▶ if ( ! $original_class ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($original_class) 0 147 147
1594 0 ▶ $socket = ($original_class = $ISA[0])->new_from_fd($socket,'<+')
Branch: 1 branch
BranchTrueFalseTotal
$socket = ($original_class = $IO::Socket::SSL::ISA[0])->new_from_fd($socket, "<+") or return $class->_internal_error("creating $original_class from file handle failed", 9) 0 0 0
1595 or return $class->_internal_error(
1596 "creating $original_class from file handle failed",9);
1597 }
1598 147 ▶ my $original_fileno = (UNIVERSAL::can($socket, "fileno"))
Branch: 1 branch
BranchTrueFalseTotal
UNIVERSAL::can($socket, 'fileno') ? : 147 0 147
1599 ? $socket->fileno : CORE::fileno($socket);
1600 147 ▶ return $class->_internal_error("Socket has no fileno",9)
Branch: 1 branch
BranchTrueFalseTotal
unless defined $original_fileno 1 146 147
1601 if ! defined $original_fileno;
1602  
1603 146 bless $socket, $class;
1604 146 ▶ $socket->configure_SSL($arg_hash) or bless($socket, $original_class) && return;
Branch: 1 branch
BranchTrueFalseTotal
$socket->configure_SSL($arg_hash) or bless $socket, $original_class and return 0 146 146
Condition20%1/5
$socket->configure_SSL($arg_hash) || bless($socket, $original_class) && (return)
l!l&&r!l&&!r
14600
bless $socket, $original_class and return
!ll
00
MC/DC0%0/2
$socket->configure_SSL($arg_hash) || bless($socket, $original_class) && (return)
$socket->configure_SSL($arg_hash) bless $socket, $original_class
Truth table33%1/3
A || B
A= $socket->configure_SSL($arg_hash)B= bless $socket, $original_class
ABresult
1X1
011
000
1605  
1606 146 ${*$socket}{'_SSL_fileno'} = $original_fileno;
1607 146 ▶ ${*$socket}{'_SSL_ioclass_upgraded'} = $original_class
Branch: 1 branch
BranchTrueFalseTotal
if $class ne $original_class 145 1 146
1608 if $class ne $original_class;
1609  
1610 146 my $start_handshake = $arg_hash->{SSL_startHandshake};
1611 146 ▶ if ( ! defined($start_handshake) || $start_handshake ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $start_handshake or $start_handshake) { } 142 4 146
Condition66%2/3
not defined $start_handshake or $start_handshake
l!l&&r!l&&!r
14204
MC/DC50%1/2
not defined $start_handshake or $start_handshake
not defined $start_handshake $start_handshake
Truth table66%2/3
not(A) or B
A= not defined $start_handshakeB= $start_handshake
ABresult
1X1
011
000
1612 # if we have no callback force blocking mode
1613 142 ▶ $DEBUG>=2 && DEBUG( "start handshake" );
Branch: 1 branch
BranchTrueFalseTotal
$IO::Socket::SSL::DEBUG >= 2 and DEBUG("start handshake") 0 142 142
1614 142 my $was_blocking = $socket->blocking(1);
1615 142 my $result = ${*$socket}{'_SSL_arguments'}{SSL_server}
1616 142 ▶ ? $socket->accept_SSL(%to)
Branch: 1 branch
BranchTrueFalseTotal
do { *$socket }->{'_SSL_arguments'}{'SSL_server'} ? : 57 85 142
1617 : $socket->connect_SSL(%to);
1618 142 ▶ if ( $result ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($result) { } 108 34 142
1619 108 ▶ $socket->blocking(0) if ! $was_blocking;
Branch: 1 branch
BranchTrueFalseTotal
unless $was_blocking 0 108 108
1620 108 return $socket;
1621 } else {
1622 # upgrade to SSL failed, downgrade socket to original class
1623 34 ▶ if ( $original_class ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($original_class) 34 0 34
1624 34 bless($socket,$original_class);
1625 34 ▶ $socket->blocking(0) if ! $was_blocking
Branch: 1 branch
BranchTrueFalseTotal
if not $was_blocking and $socket->can("blocking") 0 34 34
Condition33%1/3
not $was_blocking and $socket->can("blocking")
!ll&&!rl&&r
3400
MC/DC0%0/2
not $was_blocking and $socket->can("blocking")
not $was_blocking $socket->can("blocking")
Truth table33%1/3
not(A) and B
A= not $was_blockingB= $socket->can("blocking")
ABresult
0X0
100
111
1626 && $socket->can('blocking');
1627 }
1628 34 return;
1629 }
1630 } else {
1631 4 ▶ $DEBUG>=2 && DEBUG( "don't start handshake: $socket" );
Branch: 1 branch
BranchTrueFalseTotal
$IO::Socket::SSL::DEBUG >= 2 and DEBUG("don't start handshake: $socket") 0 4 4
1632 4 return $socket; # just return upgraded socket
1633 }
1634  
1635 }
1636  
1637 sub new_from_fd {
1638 1 ▶ my ($class, $fd) = (shift,shift);
Subroutine new_from_fd: called CC=4 SCAR=14.3
Pod documented
1639 # Check for accidental inclusion of MODE in the argument list
1640 1 ▶ if (length($_[0]) < 4) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $_[0] < 4) 1 0 1
1641 1 (my $mode = $_[0]) =~ tr/+<>//d;
1642 1 ▶ shift unless length($mode);
Branch: 1 branch
BranchTrueFalseTotal
unless length $mode 1 0 1
1643 }
1644 1 ▶ my $handle = $ISA[0]->new_from_fd($fd, '+<')
Condition50%1/2
$IO::Socket::SSL::ISA[0]->new_from_fd($fd, '+<') || (return $class->error('Could not create socket from file descriptor.'))
l!l
10
MC/DC0%0/1
$IO::Socket::SSL::ISA[0]->new_from_fd($fd, '+<') || (return $class->error('Could not create socket from file descriptor.'))
$IO::Socket::SSL::ISA[0]->new_from_fd($fd, '+<')
Truth table50%1/2
A
A= $IO::Socket::SSL::ISA[0]->new_from_fd($fd, '+<')
Aresult
11
00
1645 || return($class->error("Could not create socket from file descriptor."));
1646  
1647 # Annoying workaround for Perl 5.6.1 and below:
1648 1 $handle = $ISA[0]->new_from_fd($handle, '+<');
1649  
1650 1 return $class->start_SSL($handle, @_);
1651 }
1652  
1653  
1654 sub dump_peer_certificate {
1655 1 ▶ my $ssl = shift()->_get_ssl_object || return;
Subroutine dump_peer_certificate: called CC=2 SCAR=7.2
Pod documented
Condition50%1/2
(shift())->_get_ssl_object || (return)
l!l
10
MC/DC0%0/1
(shift())->_get_ssl_object || (return)
(shift())->_get_ssl_object
Truth table50%1/2
A
A= (shift())->_get_ssl_object
Aresult
11
00
1656 1 return Net::SSLeay::dump_peer_certificate($ssl);
1657 }
1658  
1659 82 ▶if ( defined &Net::SSLeay::get_peer_cert_chain
Branch: 1 branch
BranchTrueFalseTotal
if (defined &Net::SSLeay::get_peer_cert_chain and $netssleay_version >= 1.58) { } 82 0 82
Condition33%1/3
defined &Net::SSLeay::get_peer_cert_chain and $netssleay_version >= "1.58"
!ll&&!rl&&r
0082
MC/DC0%0/2
defined &Net::SSLeay::get_peer_cert_chain and $netssleay_version >= "1.58"
defined &Net::SSLeay::get_peer_cert_chain $netssleay_version >= "1.58"
Truth table33%1/3
A and B
A= defined &Net::SSLeay::get_peer_cert_chainB= $netssleay_version >= "1.58"
ABresult
0X0
100
111
1660 && $netssleay_version >= 1.58 ) {
1661 *peer_certificates = sub {
1662 0 ▶ my $self = shift;
Subroutine __ANON__: not called CC=6 SCAR=37.4
1663 0 ▶ my $ssl = $self->_get_ssl_object || return;
Condition0%0/2
$self->_get_ssl_object || (return)
l!l
00
MC/DC0%0/1
$self->_get_ssl_object || (return)
$self->_get_ssl_object
Truth table0%0/2
A
A= $self->_get_ssl_object
Aresult
11
00
1664 0 my @chain = Net::SSLeay::get_peer_cert_chain($ssl);
1665 0 ▶ @chain = () if @chain && !$self->peer_certificate; # work around #96013
Branch: 1 branch
BranchTrueFalseTotal
if @chain and not $self->peer_certificate 0 0 0
Condition0%0/3
@chain and not $self->peer_certificate
!ll&&!rl&&r
000
MC/DC0%0/2
@chain and not $self->peer_certificate
@chain not $self->peer_certificate
Truth table0%0/3
A and not(B)
A= @chainB= not $self->peer_certificate
ABresult
0X0
100
111
1666 0 ▶ if ( ${*$self}{_SSL_arguments}{SSL_server} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (do { *$self }->{"_SSL_arguments"}{"SSL_server"}) 0 0 0
1667 # in the client case the chain contains the peer certificate,
1668 # in the server case not
1669 # this one has an increased reference counter, the other not
1670 0 ▶ if ( my $peer = Net::SSLeay::get_peer_certificate($ssl)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $peer = &Net::SSLeay::get_peer_certificate($ssl)) 0 0 0
1671 0 Net::SSLeay::X509_free($peer);
1672 0 unshift @chain, $peer;
1673 }
1674 }
1675 0 return @chain;
1676  
1677 }
1678 82 } else {
1679 *peer_certificates = sub {
1680 0 ▶ die "peer_certificates needs Net::SSLeay>=1.58";
Subroutine __ANON__: not called CC=1 SCAR=6.9
1681 }
1682 0 }
1683  
1684 {
1685 my %dispatcher = (
1686 10 ▶ issuer => sub { Net::SSLeay::X509_NAME_oneline( Net::SSLeay::X509_get_issuer_name( shift )) },
Subroutine __ANON__: called CC=1 SCAR=0.0
1687 7 ▶ subject => sub { Net::SSLeay::X509_NAME_oneline( Net::SSLeay::X509_get_subject_name( shift )) },
Subroutine __ANON__: called CC=1 SCAR=0.0
1688 commonName => sub {
1689 209 ▶ my $cn = Net::SSLeay::X509_NAME_get_text_by_NID(
Subroutine __ANON__: called CC=1 SCAR=0.0
1690 Net::SSLeay::X509_get_subject_name( shift ), NID_CommonName);
1691 209 $cn;
1692 },
1693 209 ▶ subjectAltNames => sub { Net::SSLeay::X509_get_subjectAltNames( shift ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
1694 82 );
1695  
1696 # alternative names
1697 82 $dispatcher{authority} = $dispatcher{issuer};
1698 82 $dispatcher{owner} = $dispatcher{subject};
1699 82 $dispatcher{cn} = $dispatcher{commonName};
1700  
1701 sub peer_certificate {
1702 73 ▶ my ($self,$field,$reload) = @_;
Subroutine peer_certificate: called CC=8 SCAR=23.4
Pod documented
1703 73 ▶ my $ssl = $self->_get_ssl_object or return;
Branch: 1 branch
BranchTrueFalseTotal
my $ssl = $self->_get_ssl_object or return 0 73 73
1704  
1705 0 Net::SSLeay::X509_free(delete ${*$self}{_SSL_certificate})
1706 73 ▶ if $reload && ${*$self}{_SSL_certificate};
Branch: 1 branch
BranchTrueFalseTotal
if $reload and do { *$self }->{"_SSL_certificate"} 0 73 73
Condition33%1/3
$reload and do { *$self }->{"_SSL_certificate"}
!ll&&!rl&&r
7300
MC/DC0%0/2
$reload and do { *$self }->{"_SSL_certificate"}
$reload do { *$self }->{"_SSL_certificate"}
Truth table33%1/3
A and B
A= $reloadB= do { *$self }->{"_SSL_certificate"}
ABresult
0X0
100
111
1707 73 my $cert = ${*$self}{_SSL_certificate}
1708 73 ▶ ||= Net::SSLeay::get_peer_certificate($ssl)
Branch: 1 branch
BranchTrueFalseTotal
my $cert = (do { *$self }->{"_SSL_certificate"} ||= &Net::SSLeay::get_peer_certificate($ssl)) or return $self->error("Could not retrieve peer certificate") 0 73 73
Condition66%2/3
do { *$self }->{"_SSL_certificate"} ||= &Net::SSLeay::get_peer_certificate($ssl)
l!l&&r!l&&!r
42310
MC/DC0%0/2
do { *$self }->{"_SSL_certificate"} ||= &Net::SSLeay::get_peer_certificate($ssl)
do { *$self }->{"_SSL_certificate"} &Net::SSLeay::get_peer_certificate($ssl)
Truth table66%2/3
A ||= B
A= do { *$self }->{"_SSL_certificate"}B= &Net::SSLeay::get_peer_certificate($ssl)
ABresult
1X1
011
000
1709 or return $self->error("Could not retrieve peer certificate");
1710  
1711 73 ▶ if ($field) {
Branch: 1 branch
BranchTrueFalseTotal
if ($field) { } 15 58 73
1712 15 ▶ my $sub = $dispatcher{$field} or croak
Branch: 1 branch
BranchTrueFalseTotal
my $sub = $dispatcher{$field} or croak('invalid argument for peer_certificate, valid are: ' . join(" ", keys %dispatcher) . "\nMaybe you need to upgrade your Net::SSLeay") 0 15 15
1713 "invalid argument for peer_certificate, valid are: ".join( " ",keys %dispatcher ).
1714 "\nMaybe you need to upgrade your Net::SSLeay";
1715 15 return $sub->($cert);
1716 } else {
1717 58 return $cert
1718 }
1719 }
1720  
1721 sub sock_certificate {
1722 6 ▶ my ($self,$field) = @_;
Subroutine sock_certificate: called CC=5 SCAR=16.5
Pod documented
1723 6 ▶ my $ssl = $self->_get_ssl_object || return;
Condition50%1/2
$self->_get_ssl_object || (return)
l!l
60
MC/DC0%0/1
$self->_get_ssl_object || (return)
$self->_get_ssl_object
Truth table50%1/2
A
A= $self->_get_ssl_object
Aresult
11
00
1724 6 ▶ my $cert = Net::SSLeay::get_certificate( $ssl ) || return;
Condition50%1/2
&Net::SSLeay::get_certificate($ssl) || (return)
l!l
60
MC/DC0%0/1
&Net::SSLeay::get_certificate($ssl) || (return)
&Net::SSLeay::get_certificate($ssl)
Truth table50%1/2
A
A= &Net::SSLeay::get_certificate($ssl)
Aresult
11
00
1725 6 ▶ if ($field) {
Branch: 1 branch
BranchTrueFalseTotal
if ($field) { } 4 2 6
1726 4 ▶ my $sub = $dispatcher{$field} or croak
Branch: 1 branch
BranchTrueFalseTotal
my $sub = $dispatcher{$field} or croak('invalid argument for sock_certificate, valid are: ' . join(" ", keys %dispatcher) . "\nMaybe you need to upgrade your Net::SSLeay") 0 4 4
1727 "invalid argument for sock_certificate, valid are: ".join( " ",keys %dispatcher ).
1728 "\nMaybe you need to upgrade your Net::SSLeay";
1729 4 return $sub->($cert);
1730 } else {
1731 2 return $cert
1732 }
1733 }
1734  
1735  
1736 # known schemes, possible attributes are:
1737 # - wildcards_in_alt (0, 'full_label', 'anywhere')
1738 # - wildcards_in_cn (0, 'full_label', 'anywhere')
1739 # - check_cn (0, 'always', 'when_only')
1740 # unfortunately there are a lot of different schemes used, see RFC 6125 for a
1741 # summary, which references all of the following except RFC4217/ftp
1742  
1743 82 my %scheme = (
1744 none => {}, # do not check
1745 # default set is a superset of all the others and thus worse than a more
1746 # specific set, but much better than not verifying name at all
1747 default => {
1748 wildcards_in_cn => 'anywhere',
1749 wildcards_in_alt => 'anywhere',
1750 check_cn => 'always',
1751 ip_in_cn => 1,
1752 },
1753 );
1754  
1755 82 for(qw(
1756 rfc2818
1757 rfc3920 xmpp
1758 rfc4217 ftp
1759 )) {
1760 410 $scheme{$_} = {
1761 wildcards_in_cn => 'anywhere',
1762 wildcards_in_alt => 'anywhere',
1763 check_cn => 'when_only',
1764 }
1765 }
1766  
1767 82 for(qw(www http)) {
1768 164 $scheme{$_} = {
1769 wildcards_in_cn => 'anywhere',
1770 wildcards_in_alt => 'anywhere',
1771 check_cn => 'when_only',
1772 ip_in_cn => 4,
1773 }
1774 }
1775  
1776 82 for(qw(
1777 rfc4513 ldap
1778 )) {
1779 164 $scheme{$_} = {
1780 wildcards_in_cn => 0,
1781 wildcards_in_alt => 'full_label',
1782 check_cn => 'always',
1783 };
1784 }
1785  
1786 82 for(qw(
1787 rfc2595 smtp
1788 rfc4642 imap pop3 acap
1789 rfc5539 nntp
1790 rfc5538 netconf
1791 rfc5425 syslog
1792 rfc5953 snmp
1793 )) {
1794 1148 $scheme{$_} = {
1795 wildcards_in_cn => 'full_label',
1796 wildcards_in_alt => 'full_label',
1797 check_cn => 'always'
1798 };
1799 }
1800 82 for(qw(
1801 rfc5971 gist
1802 )) {
1803 164 $scheme{$_} = {
1804 wildcards_in_cn => 'full_label',
1805 wildcards_in_alt => 'full_label',
1806 check_cn => 'when_only',
1807 };
1808 }
1809  
1810 82 for(qw(
1811 rfc5922 sip
1812 )) {
1813 164 $scheme{$_} = {
1814 wildcards_in_cn => 0,
1815 wildcards_in_alt => 0,
1816 check_cn => 'always',
1817 };
1818 }
1819  
1820  
1821 # function to verify the hostname
1822 #
1823 # as every application protocol has its own rules to do this
1824 # we provide some default rules as well as a user-defined
1825 # callback
1826  
1827 sub verify_hostname_of_cert {
1828 208 ▶ my $identity = shift;
Subroutine verify_hostname_of_cert: called CC=36 SCAR=36.5
Pod undocumented
1829 208 my $cert = shift;
1830 208 ▶ my $scheme = shift || 'default';
Condition100%2/2
shift() || 'default'
l!l
16147
MC/DC100%1/1
shift() || 'default'
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
1831 208 my $publicsuffix = shift;
1832 208 ▶ if ( ! ref($scheme) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $scheme) 208 0 208
1833 208 ▶ $DEBUG>=3 && DEBUG( "scheme=$scheme cert=$cert" );
Branch: 1 branch
BranchTrueFalseTotal
$IO::Socket::SSL::DEBUG >= 3 and DEBUG("scheme=$scheme cert=$cert") 0 208 208
1834 208 ▶ $scheme = $scheme{$scheme} || croak("scheme $scheme not defined");
Condition33%1/3
$scheme{$scheme} || croak("scheme $scheme not defined")
l!l&&r!l&&!r
20800
MC/DC0%0/2
$scheme{$scheme} || croak("scheme $scheme not defined")
$scheme{$scheme} croak("scheme $scheme not defined")
Truth table33%1/3
A || B
A= $scheme{$scheme}B= croak("scheme $scheme not defined")
ABresult
1X1
011
000
1835 }
1836  
1837 208 ▶ return 1 if ! %$scheme; # 'none'
Branch: 1 branch
BranchTrueFalseTotal
unless %$scheme 0 208 208
1838 208 $identity =~s{\.+$}{}; # ignore absolutism
1839  
1840 # get data from certificate
1841 208 my $commonName = $dispatcher{cn}->($cert);
1842 208 my @altNames = $dispatcher{subjectAltNames}->($cert);
1843 208 ▶ $DEBUG>=3 && DEBUG("identity=$identity cn=$commonName alt=@altNames" );
Branch: 1 branch
BranchTrueFalseTotal
$IO::Socket::SSL::DEBUG >= 3 and DEBUG("identity=$identity cn=$commonName alt=@altNames") 0 208 208
1844  
1845 208 ▶ if ( my $sub = $scheme->{callback} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $sub = $scheme->{"callback"}) 0 208 208
1846 # use custom callback
1847 0 return $sub->($identity,$commonName,@altNames);
1848 }
1849  
1850 # is the given hostname an IP address? Then we have to convert to network byte order [RFC791][RFC2460]
1851  
1852 208 my $ipn;
1853 208 ▶ if ( CAN_IPV6 and $identity =~m{:} ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($identity =~ /:/) { } 12 196 208
elsif (my(@ip) = $identity =~ /^(\d+)(?:\.(\d+)\.(\d+)\.(\d+)|[\d\.]*)$/) { } 53 143 196
1854 # no IPv4 or hostname have ':' in it, try IPv6.
1855 12 ▶ $identity =~m{[^\da-fA-F:\.]} and return; # invalid characters in name
Branch: 1 branch
BranchTrueFalseTotal
$identity =~ /[^\da-fA-F:\.]/ and return 3 9 12
1856 9 ▶ $ipn = inet_pton(AF_INET6,$identity) or return; # invalid name
Branch: 1 branch
BranchTrueFalseTotal
$ipn = inet_pton(10, $identity) or return 0 9 9
1857 } elsif ( my @ip = $identity =~m{^(\d+)(?:\.(\d+)\.(\d+)\.(\d+)|[\d\.]*)$} ) {
1858 # check for invalid IP/hostname
1859 53 ▶ return if 4 != @ip or 4 != grep { defined($_) && $_<256 } @ip;
Branch: 2 branches
BranchTrueFalseTotal
if 4 != @ip or 4 != grep({defined $_ and $_ < 256;} @ip) 3 50 53
defined $_ and $_ < 256 206 6 212
Condition66%2/3
4 != @ip or 4 != grep({defined $_ and $_ < 256;} @ip)
l!l&&r!l&&!r
0350
MC/DC50%1/2
4 != @ip or 4 != grep({defined $_ and $_ < 256;} @ip)
4 != @ip 4 != grep({defined $_ and $_ < 256;} @ip)
Truth table66%2/3
A or B
A= 4 != @ipB= 4 != grep({defined $_ and $_ < 256;} @ip)
ABresult
1X1
011
000
1860 50 $ipn = pack("CCCC",@ip);
1861 } else {
1862 # assume hostname, check for umlauts etc
1863 143 ▶ if ( $identity =~m{[^a-zA-Z0-9_.\-]} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($identity =~ /[^a-zA-Z0-9_.\-]/) 5 138 143
1864 5 ▶ $identity =~m{\0} and return; # $identity has \\0 byte
Branch: 1 branch
BranchTrueFalseTotal
$identity =~ /\0/ and return 0 5 5
1865 5 ▶ $identity = idn_to_ascii($identity)
Branch: 1 branch
BranchTrueFalseTotal
$identity = idn_to_ascii($identity) or return 0 5 5
1866 or return; # conversation to IDNA failed
1867 5 ▶ $identity =~m{[^a-zA-Z0-9_.\-]}
Branch: 1 branch
BranchTrueFalseTotal
$identity =~ /[^a-zA-Z0-9_.\-]/ and return 2 3 5
1868 and return; # still junk inside
1869 }
1870 }
1871  
1872 # do the actual verification
1873 my $check_name = sub {
1874 292 ▶ my ($name,$identity,$wtyp,$publicsuffix) = @_;
Subroutine __ANON__: called CC=14 SCAR=26.4
1875 292 $name =~s{\.+$}{}; # ignore absolutism
1876 292 ▶ $name eq '' and return;
Branch: 1 branch
BranchTrueFalseTotal
$name eq "" and return 1 291 292
1877 291 ▶ $wtyp ||= '';
Condition100%2/2
$wtyp ||= ""
l!l
28110
MC/DC100%1/1
$wtyp ||= ""
$wtyp
Truth table100%2/2
A
A= $wtyp
Aresult
11
00
1878 291 my $pattern;
1879 ### IMPORTANT!
1880 # We accept only a single wildcard and only for a single part of the FQDN
1881 # e.g. *.example.org does match www.example.org but not bla.www.example.org
1882 # The RFCs are in this regard unspecific but we don't want to have to
1883 # deal with certificates like *.com, *.co.uk or even *
1884 # see also http://nils.toedtmann.net/pub/subjectAltName.txt .
1885 # Also, we fall back to full_label matches if the identity is an IDNA
1886 # name, see RFC6125 and the discussion at
1887 # http://bugs.python.org/issue17997#msg194950
1888 291 ▶ if ( $wtyp eq 'anywhere' and $name =~m{^([a-zA-Z0-9_\-]*)\*(.+)} ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($wtyp eq 'anywhere' and $name =~ /^([a-zA-Z0-9_\-]*)\*(.+)/) { } 118 173 291
elsif ($wtyp =~ /^(?:full_label|leftmost)$/ and $name =~ /^\*(\..+)$/) { } 26 147 173
Condition100%3/3
$wtyp eq "anywhere" and $name =~ /^([a-zA-Z0-9_\-]*)\*(.+)/
!ll&&!rl&&r
10667118
MC/DC100%2/2
$wtyp eq "anywhere" and $name =~ /^([a-zA-Z0-9_\-]*)\*(.+)/
$wtyp eq "anywhere" $name =~ /^([a-zA-Z0-9_\-]*)\*(.+)/
Truth table100%3/3
A and B
A= $wtyp eq "anywhere"B= $name =~ /^([a-zA-Z0-9_\-]*)\*(.+)/
ABresult
0X0
100
111
1889 118 ▶ return if $1 ne '' and substr($identity,0,4) eq 'xn--'; # IDNA
Branch: 1 branch
BranchTrueFalseTotal
if $1 ne "" and substr($identity, 0, 4) eq "xn--" 4 114 118
Condition100%3/3
$1 ne "" and substr($identity, 0, 4) eq "xn--"
!ll&&!rl&&r
84304
MC/DC100%2/2
$1 ne "" and substr($identity, 0, 4) eq "xn--"
$1 ne "" substr($identity, 0, 4) eq "xn--"
Truth table100%3/3
A and B
A= $1 ne ""B= substr($identity, 0, 4) eq "xn--"
ABresult
0X0
100
111
1890 114 $pattern = qr{^\Q$1\E[a-zA-Z0-9_\-]+\Q$2\E$}i;
1891 ▶ } elsif ( $wtyp =~ m{^(?:full_label|leftmost)$}
Condition100%3/3
$wtyp =~ /^(?:full_label|leftmost)$/ and $name =~ /^\*(\..+)$/
!ll&&!rl&&r
777026
MC/DC100%2/2
$wtyp =~ /^(?:full_label|leftmost)$/ and $name =~ /^\*(\..+)$/
$wtyp =~ /^(?:full_label|leftmost)$/ $name =~ /^\*(\..+)$/
Truth table100%3/3
A and B
A= $wtyp =~ /^(?:full_label|leftmost)$/B= $name =~ /^\*(\..+)$/
ABresult
0X0
100
111
1892 and $name =~m{^\*(\..+)$} ) {
1893 26 $pattern = qr{^[a-zA-Z0-9_\-]+\Q$1\E$}i;
1894 } else {
1895 147 return lc($identity) eq lc($name);
1896 }
1897 140 ▶ if ( $identity =~ $pattern ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($identity =~ /$pattern/) 56 84 140
1898 56 ▶ $publicsuffix = IO::Socket::SSL::PublicSuffix->default
Branch: 1 branch
BranchTrueFalseTotal
unless defined $publicsuffix 56 0 56
1899 if ! defined $publicsuffix;
1900 56 ▶ return 1 if $publicsuffix eq '';
Branch: 1 branch
BranchTrueFalseTotal
if $publicsuffix eq "" 0 56 56
1901 56 my @labels = split( m{\.+}, $identity );
1902 56 my $tld = $publicsuffix->public_suffix(\@labels,+1);
1903 56 ▶ return 1 if @labels > ( $tld ? 0+@$tld : 1 );
Branch: 2 branches
BranchTrueFalseTotal
if @labels > ($tld ? 0 + @$tld : 1) 41 15 56
$tld ? : 56 0 56
1904 }
1905 99 return;
1906 200 };
1907  
1908  
1909 200 my $alt_dnsNames = 0;
1910 200 ▶ while (@altNames) {
Branch: 1 branch
BranchTrueFalseTotal
if (@altNames) 345 118 463
1911 345 my ($type, $name) = splice (@altNames, 0, 2);
1912 345 ▶ if ( $ipn and $type == GEN_IPADD ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($ipn and $type == GEN_IPADD()) { } 51 294 345
elsif (not $ipn and $type == GEN_DNS()) { } 203 135 338
Condition100%3/3
$ipn and $type == GEN_IPADD()
!ll&&!rl&&r
2504451
MC/DC100%2/2
$ipn and $type == GEN_IPADD()
$ipn $type == GEN_IPADD()
Truth table100%3/3
A and B
A= $ipnB= $type == GEN_IPADD()
ABresult
0X0
100
111
1913 # exact match needed for IP
1914 # $name is already packed format (inet_xton)
1915 51 ▶ return 1 if $ipn eq $name;
Branch: 1 branch
BranchTrueFalseTotal
if $ipn eq $name 44 7 51
1916  
1917 ▶ } elsif ( ! $ipn and $type == GEN_DNS ) {
Condition100%3/3
not $ipn and $type == GEN_DNS()
!ll&&!rl&&r
4447203
MC/DC100%2/2
not $ipn and $type == GEN_DNS()
not $ipn $type == GEN_DNS()
Truth table100%3/3
not(A) and B
A= not $ipnB= $type == GEN_DNS()
ABresult
0X0
100
111
1918 203 $name =~s/\s+$//; $name =~s/^\s+//;
1919 203 $alt_dnsNames++;
1920 203 ▶ $check_name->($name,$identity,$scheme->{wildcards_in_alt},$publicsuffix)
Branch: 1 branch
BranchTrueFalseTotal
&$check_name($name, $identity, $scheme->{"wildcards_in_alt"}, $publicsuffix) and return 1 38 165 203
1921 and return 1;
1922 }
1923 }
1924  
1925 118 ▶ if ( $scheme->{check_cn} eq 'always' or
Branch: 1 branch
BranchTrueFalseTotal
if ($scheme->{"check_cn"} eq "always" or $scheme->{"check_cn"} eq "when_only" and not $alt_dnsNames) 104 14 118
Condition83%5/6
$scheme->{"check_cn"} eq "always" or $scheme->{"check_cn"} eq "when_only" and not $alt_dnsNames
l!l&&r!l&&!r
178714
$scheme->{"check_cn"} eq "when_only" and not $alt_dnsNames
!ll&&!rl&&r
01487
MC/DC66%2/3
$scheme->{"check_cn"} eq "always" or $scheme->{"check_cn"} eq "when_only" and not $alt_dnsNames
$scheme->{"check_cn"} eq "always" $scheme->{"check_cn"} eq "when_only" not $alt_dnsNames
Truth table75%3/4
A or B and not(C)
A= $scheme->{"check_cn"} eq "always"B= $scheme->{"check_cn"} eq "when_only"C= not $alt_dnsNames
ABCresult
1XX1
0111
00X0
0100
1926 $scheme->{check_cn} eq 'when_only' and !$alt_dnsNames ) {
1927 104 ▶ if ( ! $ipn ) {
Branch: 2 branches
BranchTrueFalseTotal
if (not $ipn) { } 89 15 104
elsif ($scheme->{'ip_in_cn'}) { } 15 0 15
1928 89 ▶ $check_name->($commonName,$identity,$scheme->{wildcards_in_cn},$publicsuffix)
Branch: 1 branch
BranchTrueFalseTotal
&$check_name($commonName, $identity, $scheme->{"wildcards_in_cn"}, $publicsuffix) and return 1 44 45 89
1929 and return 1;
1930 } elsif ( $scheme->{ip_in_cn} ) {
1931 15 ▶ if ( $identity eq $commonName ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($identity eq $commonName) 5 10 15
1932 return 1 if
1933 $scheme->{ip_in_cn} == 4 ? length($ipn) == 4 :
1934 5 ▶ $scheme->{ip_in_cn} == 6 ? length($ipn) == 16 :
Branch: 3 branches
BranchTrueFalseTotal
if $scheme->{"ip_in_cn"} == 4 ? length $ipn == 4 : ($scheme->{"ip_in_cn"} == 6 ? length $ipn == 16 : 1) 3 2 5
$scheme->{'ip_in_cn'} == 4 ? : 5 0 5
$scheme->{'ip_in_cn'} == 6 ? : 0 0 0
1935 1;
1936 }
1937 }
1938 }
1939  
1940 71 return 0; # no match
1941 }
1942 }
1943  
1944 82 sub verify_hostname {
1945 41 ▶ my $self = shift;
Subroutine verify_hostname: called CC=1 SCAR=0.0
Pod documented
1946 41 my $host = shift;
1947 41 my $cert = $self->peer_certificate;
1948 41 return verify_hostname_of_cert( $host,$cert,@_ );
1949 }
1950  
1951  
1952 sub get_servername {
1953 8 ▶ my $self = shift;
Subroutine get_servername: called CC=3 SCAR=11.8
Pod documented
1954 8 ▶ return ${*$self}{_SSL_servername} ||= do {
Condition33%1/3
do { *$self }->{"_SSL_servername"} ||= do { my $ssl = $self->_get_ssl_object or return; &Net::SSLeay::get_servername($ssl) }
l!l&&r!l&&!r
080
MC/DC0%0/2
do { *$self }->{"_SSL_servername"} ||= do { my $ssl = $self->_get_ssl_object or return; &Net::SSLeay::get_servername($ssl) }
do { *$self }->{"_SSL_servername"} do { my $ssl = $self->_get_ssl_object or return; &Net::SSLeay::get_servername($ssl) }
Truth table33%1/3
A ||= B
A= do { *$self }->{"_SSL_servername"}B= do { my $ssl = $self->_get_ssl_object or return; &Net::SSLeay::get_servername($ssl) }
ABresult
1X1
011
000
1955 8 ▶ my $ssl = $self->_get_ssl_object or return;
Branch: 1 branch
BranchTrueFalseTotal
my $ssl = $self->_get_ssl_object or return 0 8 8
1956 8 Net::SSLeay::get_servername($ssl);
1957 };
1958 }
1959  
1960 sub get_fingerprint_bin {
1961 19 ▶ my ($self,$algo,$cert,$key_only) = @_;
Subroutine get_fingerprint_bin: called CC=5 SCAR=16.8
Pod documented
1962 19 ▶ $cert ||= $self->peer_certificate;
Condition66%2/3
$cert ||= $self->peer_certificate
l!l&&r!l&&!r
2170
MC/DC0%0/2
$cert ||= $self->peer_certificate
$cert $self->peer_certificate
Truth table66%2/3
A ||= B
A= $certB= $self->peer_certificate
ABresult
1X1
011
000
1963 19 ▶ return $key_only
Branch: 1 branch
BranchTrueFalseTotal
$key_only ? : 5 14 19
Condition50%2/4
$algo || 'sha256'
l!l
50
$algo || 'sha256'
l!l
140
MC/DC0%0/1
$algo || 'sha256'
$algo
MC/DC0%0/1
$algo || 'sha256'
$algo
Truth table50%1/2
A
A= $algo
Aresult
11
00
Truth table50%1/2
A
A= $algo
Aresult
11
00
1964 ? Net::SSLeay::X509_pubkey_digest($cert, $algo2digest->($algo || 'sha256'))
1965 : Net::SSLeay::X509_digest($cert, $algo2digest->($algo || 'sha256'));
1966 }
1967  
1968 sub get_fingerprint {
1969 19 ▶ my ($self,$algo,$cert,$key_only) = @_;
Subroutine get_fingerprint: called CC=4 SCAR=13.9
Pod documented
1970 19 ▶ $algo ||= 'sha256';
Condition100%2/2
$algo ||= "sha256"
l!l
172
MC/DC100%1/1
$algo ||= "sha256"
$algo
Truth table100%2/2
A
A= $algo
Aresult
11
00
1971 19 ▶ my $fp = get_fingerprint_bin($self,$algo,$cert,$key_only) or return;
Branch: 1 branch
BranchTrueFalseTotal
my $fp = get_fingerprint_bin($self, $algo, $cert, $key_only) or return 0 19 19
1972 19 ▶ return $algo.'$'.($key_only ? 'pub$':'').unpack('H*',$fp);
Branch: 1 branch
BranchTrueFalseTotal
$key_only ? : 5 14 19
1973 }
1974  
1975 sub get_cipher {
1976 11 ▶ my $ssl = shift()->_get_ssl_object || return;
Subroutine get_cipher: called CC=2 SCAR=7.2
Pod documented
Condition50%1/2
(shift())->_get_ssl_object || (return)
l!l
110
MC/DC0%0/1
(shift())->_get_ssl_object || (return)
(shift())->_get_ssl_object
Truth table50%1/2
A
A= (shift())->_get_ssl_object
Aresult
11
00
1977 11 return Net::SSLeay::get_cipher($ssl);
1978 }
1979  
1980 sub get_sslversion {
1981 34 ▶ my $ssl = shift()->_get_ssl_object || return;
Subroutine get_sslversion: called CC=10 SCAR=28.8
Pod documented
Condition50%1/2
(shift())->_get_ssl_object || (return)
l!l
340
MC/DC0%0/1
(shift())->_get_ssl_object || (return)
(shift())->_get_ssl_object
Truth table50%1/2
A
A= (shift())->_get_ssl_object
Aresult
11
00
1982 34 ▶ my $version = Net::SSLeay::version($ssl) or return;
Branch: 1 branch
BranchTrueFalseTotal
my $version = &Net::SSLeay::version($ssl) or return 0 34 34
1983 return
1984 34 ▶ $version == 0x0304 ? 'TLSv1_3' :
Branch: 7 branches
BranchTrueFalseTotal
$version == 772 ? : 16 18 34
$version == 771 ? : 6 12 18
$version == 770 ? : 6 6 12
$version == 769 ? : 6 0 6
$version == 768 ? : 0 0 0
$version == 2 ? : 0 0 0
$version == 65279 ? : 0 0 0
1985 $version == 0x0303 ? 'TLSv1_2' :
1986 $version == 0x0302 ? 'TLSv1_1' :
1987 $version == 0x0301 ? 'TLSv1' :
1988 $version == 0x0300 ? 'SSLv3' :
1989 $version == 0x0002 ? 'SSLv2' :
1990 $version == 0xfeff ? 'DTLS1' :
1991 undef;
1992 }
1993  
1994 sub get_sslversion_int {
1995 0 ▶ my $ssl = shift()->_get_ssl_object || return;
Subroutine get_sslversion_int: not called CC=2 SCAR=17.9
Pod documented
Condition0%0/2
(shift())->_get_ssl_object || (return)
l!l
00
MC/DC0%0/1
(shift())->_get_ssl_object || (return)
(shift())->_get_ssl_object
Truth table0%0/2
A
A= (shift())->_get_ssl_object
Aresult
11
00
1996 0 return Net::SSLeay::version($ssl);
1997 }
1998  
1999 sub get_session_reused {
2000 3 ▶ return Net::SSLeay::session_reused(
Subroutine get_session_reused: called CC=2 SCAR=7.6
Pod documented
Condition50%1/2
(shift())->_get_ssl_object || (return)
l!l
30
MC/DC0%0/1
(shift())->_get_ssl_object || (return)
(shift())->_get_ssl_object
Truth table50%1/2
A
A= (shift())->_get_ssl_object
Aresult
11
00
2001 shift()->_get_ssl_object || return);
2002 }
2003  
2004 82 ▶if ($can_ocsp) {
Branch: 1 branch
BranchTrueFalseTotal
if ($can_ocsp) 82 0 82
2005 82 ▶ no warnings 'once';
Subroutine BEGIN: called CC=1 SCAR=0.0
2006 *ocsp_resolver = sub {
2007 0 ▶ my $self = shift;
Subroutine __ANON__: not called CC=5 SCAR=34.0
2008 0 ▶ my $ssl = $self->_get_ssl_object || return;
Condition0%0/2
$self->_get_ssl_object || (return)
l!l
00
MC/DC0%0/1
$self->_get_ssl_object || (return)
$self->_get_ssl_object
Truth table0%0/2
A
A= $self->_get_ssl_object
Aresult
11
00
2009 0 my $ctx = ${*$self}{_SSL_ctx};
2010 return IO::Socket::SSL::OCSP_Resolver->new(
2011 $ssl,
2012 $ctx->{ocsp_cache} ||= IO::Socket::SSL::OCSP_Cache->new,
2013 $ctx->{ocsp_mode} & SSL_OCSP_FAIL_HARD,
2014 @_ ? \@_ :
2015 0 ▶ $ctx->{ocsp_mode} & SSL_OCSP_FULL_CHAIN ? [ $self->peer_certificates ]:
Branch: 2 branches
BranchTrueFalseTotal
@_ ? : 0 0 0
$ctx->{'ocsp_mode'} & 8 ? : 0 0 0
Condition0%0/3
$ctx->{"ocsp_cache"} ||= "IO::Socket::SSL::OCSP_Cache"->new
l!l&&r!l&&!r
000
MC/DC0%0/2
$ctx->{"ocsp_cache"} ||= "IO::Socket::SSL::OCSP_Cache"->new
$ctx->{"ocsp_cache"} "IO::Socket::SSL::OCSP_Cache"->new
Truth table0%0/3
A ||= B
A= $ctx->{"ocsp_cache"}B= "IO::Socket::SSL::OCSP_Cache"->new
ABresult
1X1
011
000
2016 [ $self->peer_certificate ]
2017 );
2018 82 };
2019 }
2020  
2021 sub errstr {
2022 44 ▶ my $self = shift;
Subroutine errstr: called CC=4 SCAR=17.1
Pod documented
2023 44 ▶ my $oe = ref($self) && ${*$self}{_SSL_last_err};
Condition33%1/3
ref $self && do { *$self }->{'_SSL_last_err'}
!ll&&!rl&&r
0044
MC/DC0%0/2
ref $self && do { *$self }->{'_SSL_last_err'}
ref $self do { *$self }->{'_SSL_last_err'}
Truth table33%1/3
A && B
A= ref $selfB= do { *$self }->{'_SSL_last_err'}
ABresult
0X0
100
111
2024 44 ▶ return $oe ? $oe->[0] : $SSL_ERROR || '';
Branch: 1 branch
BranchTrueFalseTotal
$oe ? : 44 0 44
Condition0%0/2
$IO::Socket::SSL::SSL_ERROR or ""
l!l
00
MC/DC0%0/1
$IO::Socket::SSL::SSL_ERROR or ""
$IO::Socket::SSL::SSL_ERROR
Truth table0%0/2
A
A= $IO::Socket::SSL::SSL_ERROR
Aresult
11
00
2025 }
2026  
2027 sub fatal_ssl_error {
2028 43 ▶ my $self = shift;
Subroutine fatal_ssl_error: called CC=7 SCAR=19.7
Pod undocumented
2029 43 my $error_trap = ${*$self}{'_SSL_arguments'}->{'SSL_error_trap'};
2030 43 $@ = $self->errstr;
2031 43 my $saved_error = $SSL_ERROR;
2032 43 ▶ if (defined $error_trap and ref($error_trap) eq 'CODE') {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $error_trap and ref $error_trap eq 'CODE') { } 1 42 43
elsif (do { *$self }->{'_SSL_ioclass_upgraded'} or do { *$self }->{'_SSL_arguments'}{'SSL_keepSocketOnError'}) { } 32 10 42
Condition66%2/3
defined $error_trap and ref $error_trap eq "CODE"
!ll&&!rl&&r
4201
MC/DC50%1/2
defined $error_trap and ref $error_trap eq "CODE"
defined $error_trap ref $error_trap eq "CODE"
Truth table66%2/3
A and B
A= defined $error_trapB= ref $error_trap eq "CODE"
ABresult
0X0
100
111
2033 1 $error_trap->($self, $self->errstr()."\n".$self->get_ssleay_error());
2034 42 ▶ } elsif ( ${*$self}{'_SSL_ioclass_upgraded'}
Condition66%2/3
do { *$self }->{"_SSL_ioclass_upgraded"} or do { *$self }->{"_SSL_arguments"}{"SSL_keepSocketOnError"}
l!l&&r!l&&!r
32010
MC/DC50%1/2
do { *$self }->{"_SSL_ioclass_upgraded"} or do { *$self }->{"_SSL_arguments"}{"SSL_keepSocketOnError"}
do { *$self }->{"_SSL_ioclass_upgraded"} do { *$self }->{"_SSL_arguments"}{"SSL_keepSocketOnError"}
Truth table66%2/3
A or B
A= do { *$self }->{"_SSL_ioclass_upgraded"}B= do { *$self }->{"_SSL_arguments"}{"SSL_keepSocketOnError"}
ABresult
1X1
011
000
2035 10 || ${*$self}{_SSL_arguments}{SSL_keepSocketOnError}) {
2036 # downgrade only
2037 32 ▶ $DEBUG>=3 && DEBUG('downgrading SSL only, not closing socket' );
Branch: 1 branch
BranchTrueFalseTotal
$IO::Socket::SSL::DEBUG >= 3 and DEBUG("downgrading SSL only, not closing socket") 0 32 32
2038 32 $self->stop_SSL;
2039 } else {
2040 # kill socket
2041 10 $self->close
2042 }
2043 43 ▶ $SSL_ERROR = $saved_error if $saved_error;
Branch: 1 branch
BranchTrueFalseTotal
if $saved_error 43 0 43
2044 43 return;
2045 }
2046  
2047 sub get_ssleay_error {
2048 #Net::SSLeay will print out the errors itself unless we explicitly
2049 #undefine $Net::SSLeay::trace while running print_errs()
2050 1 ▶ local $Net::SSLeay::trace;
Subroutine get_ssleay_error: called CC=2 SCAR=7.2
Pod undocumented
2051 1 ▶ return Net::SSLeay::print_errs('SSL error: ') || '';
Condition50%1/2
Net::SSLeay::print_errs('SSL error: ') || ''
l!l
01
MC/DC0%0/1
Net::SSLeay::print_errs('SSL error: ') || ''
Net::SSLeay::print_errs('SSL error: ')
Truth table50%1/2
A
A= Net::SSLeay::print_errs('SSL error: ')
Aresult
11
00
2052 }
2053  
2054 # internal errors, e.g. unsupported features, hostname check failed etc
2055 # _SSL_last_err contains severity so that on error chains we can decide if one
2056 # error should replace the previous one or if this is just a less specific
2057 # follow-up error, e.g. configuration failed because certificate failed because
2058 # hostname check went wrong:
2059 # 0 - fallback errors
2060 # 4 - errors bubbled up from OpenSSL (sub error, r/w error)
2061 # 5 - hostname or OCSP verification failed
2062 # 9 - fatal problems, e.g. missing feature, no fileno...
2063 # _SSL_last_err and SSL_ERROR are only replaced if the error has a higher
2064 # severity than the previous one
2065  
2066 sub _internal_error {
2067 76 ▶ my ($self, $error, $severity) = @_;
Subroutine _internal_error: called CC=9 SCAR=22.0
2068 76 $error = dualvar( -1, $error );
2069 76 ▶ $self = $CURRENT_SSL_OBJECT if !ref($self) && $CURRENT_SSL_OBJECT;
Branch: 1 branch
BranchTrueFalseTotal
if not ref $self and $CURRENT_SSL_OBJECT 18 58 76
Condition100%3/3
not ref $self and $CURRENT_SSL_OBJECT
!ll&&!rl&&r
56218
MC/DC100%2/2
not ref $self and $CURRENT_SSL_OBJECT
not ref $self $CURRENT_SSL_OBJECT
Truth table100%3/3
not(A) and B
A= not ref $selfB= $CURRENT_SSL_OBJECT
ABresult
0X0
100
111
2070 76 ▶ if (ref($self)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self) { } 74 2 76
2071 74 my $oe = ${*$self}{_SSL_last_err};
2072 74 ▶ if (!$oe || $oe->[1] <= $severity) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $oe or $oe->[1] <= $severity) { } 49 25 74
Condition100%3/3
not $oe or $oe->[1] <= $severity
l!l&&r!l&&!r
46325
MC/DC100%2/2
not $oe or $oe->[1] <= $severity
not $oe $oe->[1] <= $severity
Truth table100%3/3
not(A) or B
A= not $oeB= $oe->[1] <= $severity
ABresult
1X1
011
000
2073 49 ${*$self}{_SSL_last_err} = [$error,$severity];
2074 49 $SSL_ERROR = $error;
2075 49 ▶ $DEBUG && DEBUG("local error: $error");
Branch: 1 branch
BranchTrueFalseTotal
$IO::Socket::SSL::DEBUG and DEBUG("local error: $error") 0 49 49
2076 } else {
2077 25 ▶ $DEBUG && DEBUG("ignoring less severe local error '$error', keep '$oe->[0]'");
Branch: 1 branch
BranchTrueFalseTotal
$IO::Socket::SSL::DEBUG and DEBUG("ignoring less severe local error '${error}', keep '$oe->[0]'") 0 25 25
2078 }
2079 } else {
2080 2 $SSL_ERROR = $error;
2081 2 ▶ $DEBUG && DEBUG("global error: $error");
Branch: 1 branch
BranchTrueFalseTotal
$IO::Socket::SSL::DEBUG and DEBUG("global error: $error") 0 2 2
2082 }
2083 76 return;
2084 }
2085  
2086 # OpenSSL errors
2087 sub error {
2088 49 ▶ my ($self, $error) = @_;
Subroutine error: called CC=5 SCAR=16.4
Pod documented
2089 49 my @err;
2090 49 ▶ while ( my $err = Net::SSLeay::ERR_get_error()) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $err = &Net::SSLeay::ERR_get_error()) 43 49 92
2091 43 push @err, Net::SSLeay::ERR_error_string($err);
2092 43 ▶ $DEBUG>=2 && DEBUG( $error."\n".$self->get_ssleay_error());
Branch: 1 branch
BranchTrueFalseTotal
$IO::Socket::SSL::DEBUG >= 2 and DEBUG($error . "\n" . $self->get_ssleay_error) 0 43 43
2093 }
2094 49 ▶ $error .= ' '.join(' ',@err) if @err;
Branch: 1 branch
BranchTrueFalseTotal
if @err 43 6 49
2095 49 ▶ return $self->_internal_error($error,4) if $error;
Branch: 1 branch
BranchTrueFalseTotal
if $error 49 0 49
2096 0 return;
2097 }
2098  
2099 sub _errstack {
2100 5 ▶ my @err;
Subroutine _errstack: called CC=2 SCAR=6.9
2101 5 ▶ while (my $err = Net::SSLeay::ERR_get_error()) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $err = &Net::SSLeay::ERR_get_error()) 14 5 19
2102 14 push @err, Net::SSLeay::ERR_error_string($err);
2103 }
2104 5 return @err;
2105 }
2106  
2107 7 ▶sub can_client_sni { return $can_client_sni }
Subroutine can_client_sni: called CC=1 SCAR=0.0
Pod undocumented
2108 6 ▶sub can_server_sni { return $can_server_sni }
Subroutine can_server_sni: called CC=1 SCAR=0.0
Pod undocumented
2109 2 ▶sub can_multi_cert { return $can_multi_cert }
Subroutine can_multi_cert: called CC=1 SCAR=0.0
Pod undocumented
2110 2 ▶sub can_npn { return $can_npn }
Subroutine can_npn: called CC=1 SCAR=0.0
Pod undocumented
2111 2 ▶sub can_alpn { return $can_alpn }
Subroutine can_alpn: called CC=1 SCAR=0.0
Pod undocumented
2112 2 ▶sub can_ecdh { return $can_ecdh }
Subroutine can_ecdh: called CC=1 SCAR=0.0
Pod undocumented
2113 4 ▶sub can_ipv6 { return CAN_IPV6 }
Subroutine can_ipv6: called CC=1 SCAR=0.0
Pod undocumented
2114 1 ▶sub can_ocsp { return $can_ocsp }
Subroutine can_ocsp: called CC=1 SCAR=0.0
Pod undocumented
2115 1 ▶sub can_ticket_keycb { return $can_tckt_keycb }
Subroutine can_ticket_keycb: called CC=1 SCAR=0.0
Pod undocumented
2116 0 ▶sub can_pha { return $can_pha }
Subroutine can_pha: not called CC=1 SCAR=6.9
Pod undocumented
2117 2 ▶sub can_partial_chain { return $check_partial_chain && 1 }
Subroutine can_partial_chain: called CC=2 SCAR=7.6
Pod undocumented
Condition50%1/2
$check_partial_chain && 1
!ll
02
MC/DC0%0/1
$check_partial_chain && 1
$check_partial_chain
Truth table50%1/2
A
A= $check_partial_chain
Aresult
00
11
2118 0 ▶sub can_ciphersuites { return $can_ciphersuites }
Subroutine can_ciphersuites: not called CC=1 SCAR=6.9
Pod undocumented
2119  
2120 sub DESTROY {
2121 300 ▶ my $self = shift or return;
Subroutine DESTROY: called CC=5 SCAR=16.7
Branch: 1 branch
BranchTrueFalseTotal
my $self = shift() or return 0 300 300
2122 300 ▶ if (my $ssl = ${*$self}{_SSL_object}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $ssl = do { *$self }->{"_SSL_object"}) 202 98 300
2123 202 delete $SSL_OBJECT{$ssl};
2124 202 ▶ if (!$use_threads or delete $CREATED_IN_THIS_THREAD{$ssl}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $use_threads or delete $CREATED_IN_THIS_THREAD{$ssl}) 202 0 202
Condition33%1/3
not $use_threads or delete $CREATED_IN_THIS_THREAD{$ssl}
l!l&&r!l&&!r
20200
MC/DC0%0/2
not $use_threads or delete $CREATED_IN_THIS_THREAD{$ssl}
not $use_threads delete $CREATED_IN_THIS_THREAD{$ssl}
Truth table33%1/3
not(A) or B
A= not $use_threadsB= delete $CREATED_IN_THIS_THREAD{$ssl}
ABresult
1X1
011
000
2125 202 $self->close(_SSL_in_DESTROY => 1, SSL_no_shutdown => 1);
2126 }
2127 }
2128 300 delete @{*$self}{@all_my_keys};
2129 }
2130  
2131  
2132 #######Extra Backwards Compatibility Functionality#######
2133 1 ▶sub socket_to_SSL { IO::Socket::SSL->start_SSL(@_); }
Subroutine socket_to_SSL: called CC=1 SCAR=0.0
Pod documented
2134 1 ▶sub socketToSSL { IO::Socket::SSL->start_SSL(@_); }
Subroutine socketToSSL: called CC=1 SCAR=0.0
Pod documented
2135 0 ▶sub kill_socket { shift->close }
Subroutine kill_socket: not called CC=1 SCAR=6.9
Pod documented
2136  
2137 1 ▶sub issuer_name { return(shift()->peer_certificate("issuer")) }
Subroutine issuer_name: called CC=1 SCAR=0.0
Pod documented
2138 1 ▶sub subject_name { return(shift()->peer_certificate("subject")) }
Subroutine subject_name: called CC=1 SCAR=0.0
Pod documented
2139 0 ▶sub get_peer_certificate { return shift() }
Subroutine get_peer_certificate: not called CC=1 SCAR=6.9
Pod documented
2140  
2141 sub context_init {
2142 2 ▶ return($GLOBAL_SSL_ARGS = (ref($_[0]) eq 'HASH') ? $_[0] : {@_});
Subroutine context_init: called CC=2 SCAR=7.6
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq 'HASH' ? : 0 2 2
2143 }
2144  
2145 sub set_default_context {
2146 1 ▶ $GLOBAL_SSL_ARGS->{'SSL_reuse_ctx'} = shift;
Subroutine set_default_context: called CC=1 SCAR=0.0
Pod documented
2147 }
2148  
2149 sub set_default_session_cache {
2150 0 ▶ $GLOBAL_SSL_ARGS->{SSL_session_cache} = shift;
Subroutine set_default_session_cache: not called CC=1 SCAR=6.9
Pod documented
2151 }
2152  
2153  
2154 {
2155 my $set_defaults = sub {
2156 0 ▶ my $args = shift;
Subroutine __ANON__: not called CC=9 SCAR=45.0
2157 0 ▶ for(my $i=0;$i<@$args;$i+=2 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @$args) 0 0 0
2158 0 my ($k,$v) = @{$args}[$i,$i+1];
2159 0 ▶ if ( $k =~m{^SSL_} ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($k =~ /^SSL_/) { } 0 0 0
elsif ($k =~ /^(name|scheme)$/) { } 0 0 0
elsif ($k =~ /^(callback|mode)$/) { } 0 0 0
2160 0 $_->{$k} = $v for(@_);
2161 } elsif ( $k =~m{^(name|scheme)$} ) {
2162 0 $_->{"SSL_verifycn_$k"} = $v for (@_);
2163 } elsif ( $k =~m{^(callback|mode)$} ) {
2164 0 $_->{"SSL_verify_$k"} = $v for(@_);
2165 } else {
2166 0 $_->{"SSL_$k"} = $v for(@_);
2167 }
2168 }
2169 82 };
2170 sub set_defaults {
2171 0 ▶ my %args = @_;
Subroutine set_defaults: not called CC=1 SCAR=6.9
Pod documented
2172 0 $set_defaults->(\@_,
2173 $GLOBAL_SSL_ARGS,
2174 $GLOBAL_SSL_CLIENT_ARGS,
2175 $GLOBAL_SSL_SERVER_ARGS
2176 );
2177 }
2178 { # deprecated API
2179 82 ▶ no warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
2180 82 *set_ctx_defaults = \&set_defaults;
2181 }
2182 sub set_client_defaults {
2183 0 ▶ my %args = @_;
Subroutine set_client_defaults: not called CC=1 SCAR=6.9
Pod documented
2184 0 $set_defaults->(\@_, $GLOBAL_SSL_CLIENT_ARGS );
2185 }
2186 sub set_server_defaults {
2187 0 ▶ my %args = @_;
Subroutine set_server_defaults: not called CC=1 SCAR=6.9
Pod documented
2188 0 $set_defaults->(\@_, $GLOBAL_SSL_SERVER_ARGS );
2189 }
2190 }
2191  
2192 82 sub set_args_filter_hack {
2193 0 ▶ my $sub = shift;
Subroutine set_args_filter_hack: not called CC=3 SCAR=24.8
Pod documented
2194 0 ▶ if ( ref $sub ) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $sub) { } 0 0 0
elsif ($sub eq 'use_defaults') { } 0 0 0
2195 0 $FILTER_SSL_ARGS = $sub;
2196 } elsif ( $sub eq 'use_defaults' ) {
2197 # override args with defaults
2198 $FILTER_SSL_ARGS = sub {
2199 0 ▶ my ($is_server,$args) = @_;
Subroutine __ANON__: not called CC=2 SCAR=17.9
2200 0 ▶ %$args = ( %$args, $is_server
Branch: 1 branch
BranchTrueFalseTotal
$is_server ? : 0 0 0
2201 ? ( %DEFAULT_SSL_SERVER_ARGS, %$GLOBAL_SSL_SERVER_ARGS )
2202 : ( %DEFAULT_SSL_CLIENT_ARGS, %$GLOBAL_SSL_CLIENT_ARGS )
2203 );
2204 }
2205 0 }
2206 }
2207  
2208 sub next_proto_negotiated {
2209 2 ▶ my $self = shift;
Subroutine next_proto_negotiated: called CC=3 SCAR=11.4
Pod documented
2210 2 ▶ return $self->_internal_error("NPN not supported in Net::SSLeay",9) if ! $can_npn;
Branch: 1 branch
BranchTrueFalseTotal
unless $can_npn 0 2 2
2211 2 ▶ my $ssl = $self->_get_ssl_object || return;
Condition50%1/2
$self->_get_ssl_object || (return)
l!l
20
MC/DC0%0/1
$self->_get_ssl_object || (return)
$self->_get_ssl_object
Truth table50%1/2
A
A= $self->_get_ssl_object
Aresult
11
00
2212 2 return Net::SSLeay::P_next_proto_negotiated($ssl);
2213 }
2214  
2215 sub alpn_selected {
2216 2 ▶ my $self = shift;
Subroutine alpn_selected: called CC=3 SCAR=11.4
Pod documented
2217 2 ▶ return $self->_internal_error("ALPN not supported in Net::SSLeay",9) if ! $can_alpn;
Branch: 1 branch
BranchTrueFalseTotal
unless $can_alpn 0 2 2
2218 2 ▶ my $ssl = $self->_get_ssl_object || return;
Condition50%1/2
$self->_get_ssl_object || (return)
l!l
20
MC/DC0%0/1
$self->_get_ssl_object || (return)
$self->_get_ssl_object
Truth table50%1/2
A
A= $self->_get_ssl_object
Aresult
11
00
2219 2 return Net::SSLeay::P_alpn_selected($ssl);
2220 }
2221  
2222 sub opened {
2223 5 ▶ my $self = shift;
Subroutine opened: called CC=2 SCAR=7.0
Pod documented
2224 5 ▶ return IO::Handle::opened($self) && ${*$self}{'_SSL_opened'};
Condition66%2/3
IO::Handle::opened($self) && do { *$self }->{'_SSL_opened'}
!ll&&!rl&&r
104
MC/DC50%1/2
IO::Handle::opened($self) && do { *$self }->{'_SSL_opened'}
IO::Handle::opened($self) do { *$self }->{'_SSL_opened'}
Truth table66%2/3
A && B
A= IO::Handle::opened($self)B= do { *$self }->{'_SSL_opened'}
ABresult
0X0
100
111
2225 }
2226  
2227 sub opening {
2228 0 ▶ my $self = shift;
Subroutine opening: not called CC=1 SCAR=6.9
Pod undocumented
2229 0 return ${*$self}{'_SSL_opening'};
2230 }
2231  
2232 0 ▶sub want_read { shift->errstr == SSL_WANT_READ }
Subroutine want_read: not called CC=1 SCAR=6.9
Pod undocumented
2233 0 ▶sub want_write { shift->errstr == SSL_WANT_WRITE }
Subroutine want_write: not called CC=1 SCAR=6.9
Pod undocumented
2234  
2235  
2236 #Redundant IO::Handle functionality
2237 1 ▶sub getline { return(scalar shift->readline()) }
Subroutine getline: called CC=1 SCAR=0.0
Pod documented
2238 sub getlines {
2239 1 ▶ return(shift->readline()) if wantarray();
Subroutine getlines: called CC=2 SCAR=9.2
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
if wantarray 1 0 1
2240 0 croak("Use of getlines() not allowed in scalar context");
2241 }
2242  
2243 #Useless IO::Handle functionality
2244 0 ▶sub truncate { croak("Use of truncate() not allowed with SSL") }
Subroutine truncate: not called CC=1 SCAR=6.9
Pod documented
2245 0 ▶sub stat { croak("Use of stat() not allowed with SSL" ) }
Subroutine stat: not called CC=1 SCAR=6.9
Pod documented
2246 0 ▶sub setbuf { croak("Use of setbuf() not allowed with SSL" ) }
Subroutine setbuf: not called CC=1 SCAR=6.9
Pod documented
2247 0 ▶sub setvbuf { croak("Use of setvbuf() not allowed with SSL" ) }
Subroutine setvbuf: not called CC=1 SCAR=6.9
Pod documented
2248 0 ▶sub fdopen { croak("Use of fdopen() not allowed with SSL" ) }
Subroutine fdopen: not called CC=1 SCAR=6.9
Pod documented
2249  
2250 #Unsupported socket functionality
2251 0 ▶sub ungetc { croak("Use of ungetc() not implemented in IO::Socket::SSL") }
Subroutine ungetc: not called CC=1 SCAR=6.9
Pod documented
2252 0 ▶sub send { croak("Use of send() not implemented in IO::Socket::SSL; use print/printf/syswrite instead") }
Subroutine send: not called CC=1 SCAR=6.9
Pod documented
2253 0 ▶sub recv { croak("Use of recv() not implemented in IO::Socket::SSL; use read/sysread instead") }
Subroutine recv: not called CC=1 SCAR=6.9
Pod documented
2254  
2255 package IO::Socket::SSL::SSL_HANDLE;
2256 82 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2257 82 ▶use Errno 'EBADF';
Subroutine BEGIN: called CC=1 SCAR=0.0
2258 82 *weaken = *IO::Socket::SSL::weaken;
2259  
2260 sub TIEHANDLE {
2261 255 ▶ my ($class, $handle) = @_;
Subroutine TIEHANDLE: called CC=1 SCAR=0.0
2262 255 weaken($handle);
2263 255 bless \$handle, $class;
2264 }
2265  
2266 6036 ▶sub READ { ${shift()}->sysread(@_) }
Subroutine READ: called CC=1 SCAR=0.0
2267 85 ▶sub READLINE { ${shift()}->readline(@_) }
Subroutine READLINE: called CC=1 SCAR=0.0
2268 1 ▶sub GETC { ${shift()}->getc(@_) }
Subroutine GETC: called CC=1 SCAR=0.0
2269  
2270 47 ▶sub PRINT { ${shift()}->print(@_) }
Subroutine PRINT: called CC=1 SCAR=0.0
2271 1 ▶sub PRINTF { ${shift()}->printf(@_) }
Subroutine PRINTF: called CC=1 SCAR=0.0
2272 9198 ▶sub WRITE { ${shift()}->syswrite(@_) }
Subroutine WRITE: called CC=1 SCAR=0.0
2273  
2274 9196 ▶sub FILENO { ${shift()}->fileno(@_) }
Subroutine FILENO: called CC=1 SCAR=0.0
2275  
2276 0 ▶sub TELL { $! = EBADF; return -1 }
Subroutine TELL: not called CC=1 SCAR=6.9
2277 0 ▶sub BINMODE { return 0 } # not perfect, but better than not implementing the method
Subroutine BINMODE: not called CC=1 SCAR=6.9
2278  
2279 sub CLOSE { #<---- Do not change this function!
2280 43 ▶ my $ssl = ${$_[0]};
Subroutine CLOSE: called CC=1 SCAR=0.0
2281 43 local @_;
2282 43 $ssl->close();
2283 }
2284  
2285  
2286 package IO::Socket::SSL::SSL_Context;
2287 82 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
2288 82 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2289  
2290 82 my %CTX_CREATED_IN_THIS_THREAD;
2291 82 *DEBUG = *IO::Socket::SSL::DEBUG;
2292 82 *_errstack = \&IO::Socket::SSL::_errstack;
2293  
2294 82 ▶use constant SSL_MODE_ENABLE_PARTIAL_WRITE => 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
2295 82 ▶use constant SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER => 2;
Subroutine BEGIN: called CC=1 SCAR=0.0
2296  
2297 82 ▶use constant FILETYPE_PEM => Net::SSLeay::FILETYPE_PEM();
Subroutine BEGIN: called CC=1 SCAR=0.0
2298 82 ▶use constant FILETYPE_ASN1 => Net::SSLeay::FILETYPE_ASN1();
Subroutine BEGIN: called CC=1 SCAR=0.0
2299  
2300 82 ▶my $DEFAULT_SSL_OP = &Net::SSLeay::OP_ALL
Branch: 1 branch
BranchTrueFalseTotal
$can_ecdh ? : 82 0 82
2301 | &Net::SSLeay::OP_SINGLE_DH_USE
2302 | ($can_ecdh ? &Net::SSLeay::OP_SINGLE_ECDH_USE : 0);
2303  
2304 # Note that the final object will actually be a reference to the scalar
2305 # (C-style pointer) returned by Net::SSLeay::CTX_*_new() so that
2306 # it can be blessed.
2307 sub new {
2308 279 ▶ my $class = shift;
Subroutine new: called CC=236 SCAR=81.0
2309 #DEBUG( "$class @_" );
2310 279 ▶ my $arg_hash = (ref($_[0]) eq 'HASH') ? $_[0] : {@_};
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq 'HASH' ? : 272 7 279
2311  
2312 279 my $is_server = $arg_hash->{SSL_server};
2313 279 ▶ my %defaults = $is_server
Branch: 1 branch
BranchTrueFalseTotal
$is_server ? : 105 174 279
2314 ? (%DEFAULT_SSL_SERVER_ARGS, %$GLOBAL_SSL_ARGS, %$GLOBAL_SSL_SERVER_ARGS)
2315 : (%DEFAULT_SSL_CLIENT_ARGS, %$GLOBAL_SSL_ARGS, %$GLOBAL_SSL_CLIENT_ARGS);
2316 279 ▶ if ( $defaults{SSL_reuse_ctx} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($defaults{"SSL_reuse_ctx"}) 6 273 279
2317 # ignore default context if there are args to override it
2318 delete $defaults{SSL_reuse_ctx}
2319 6 ▶ if grep { m{^SSL_(?!verifycn_name|hostname)$} } keys %$arg_hash;
Branch: 1 branch
BranchTrueFalseTotal
if grep {/^SSL_(?!verifycn_name|hostname)$/;} keys %$arg_hash 0 6 6
2320 }
2321 279 ▶ %$arg_hash = ( %defaults, %$arg_hash ) if %defaults;
Branch: 1 branch
BranchTrueFalseTotal
if %defaults 279 0 279
2322  
2323 279 ▶ if (my $ctx = $arg_hash->{'SSL_reuse_ctx'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $ctx = $arg_hash->{"SSL_reuse_ctx"}) 26 253 279
2324 26 ▶ if ($ctx->isa('IO::Socket::SSL::SSL_Context') and
Branch: 2 branches
BranchTrueFalseTotal
if ($ctx->isa('IO::Socket::SSL::SSL_Context') and $ctx->{'context'}) { } 24 2 26
elsif ($ctx = do { *$ctx }->{'_SSL_ctx'}) { } 2 0 2
Condition66%2/3
$ctx->isa("IO::Socket::SSL::SSL_Context") and $ctx->{"context"}
!ll&&!rl&&r
2024
MC/DC50%1/2
$ctx->isa("IO::Socket::SSL::SSL_Context") and $ctx->{"context"}
$ctx->isa("IO::Socket::SSL::SSL_Context") $ctx->{"context"}
Truth table66%2/3
A and B
A= $ctx->isa("IO::Socket::SSL::SSL_Context")B= $ctx->{"context"}
ABresult
0X0
100
111
2325 $ctx->{context}) {
2326 # valid context
2327 2 } elsif ( $ctx = ${*$ctx}{_SSL_ctx} ) {
2328 # reuse context from existing SSL object
2329 }
2330 26 return $ctx
2331 }
2332  
2333 # common problem forgetting to set SSL_use_cert
2334 # if client cert is given by user but SSL_use_cert is undef, assume that it
2335 # should be set
2336 253 ▶ if ( ! $is_server && ! defined $arg_hash->{SSL_use_cert}
Branch: 1 branch
BranchTrueFalseTotal
if (not $is_server || defined $arg_hash->{"SSL_use_cert"} and grep {$arg_hash->{$_};} "SSL_cert", "SSL_cert_file" and grep {$arg_hash->{$_};} "SSL_key", "SSL_key_file") 6 247 253
Condition88%8/9
not $is_server || defined $arg_hash->{"SSL_use_cert"} and grep {$arg_hash->{$_};} "SSL_cert", "SSL_cert_file" and grep {$arg_hash->{$_};} "SSL_key", "SSL_key_file"
!ll&&!rl&&r
24706
not $is_server || defined $arg_hash->{"SSL_use_cert"} and grep {$arg_hash->{$_};} "SSL_cert", "SSL_cert_file"
!ll&&!rl&&r
951526
$is_server || defined $arg_hash->{'SSL_use_cert'}
l!l&&r!l&&!r
932158
MC/DC75%3/4
not $is_server || defined $arg_hash->{"SSL_use_cert"} and grep {$arg_hash->{$_};} "SSL_cert", "SSL_cert_file" and grep {$arg_hash->{$_};} "SSL_key", "SSL_key_file"
$is_server defined $arg_hash->{'SSL_use_cert'} grep {$arg_hash->{$_};} "SSL_cert", "SSL_cert_file" grep {$arg_hash->{$_};} "SSL_key", "SSL_key_file"
Truth table80%4/5
not(A || B) and C and D
A= $is_serverB= defined $arg_hash->{'SSL_use_cert'}C= grep {$arg_hash->{$_};} "SSL_cert", "SSL_cert_file"D= grep {$arg_hash->{$_};} "SSL_key", "SSL_key_file"
ABCDresult
1XXX0
01XX0
000X0
00100
00111
2337 316 && ( grep { $arg_hash->{$_} } qw(SSL_cert SSL_cert_file))
2338 12 && ( grep { $arg_hash->{$_} } qw(SSL_key SSL_key_file)) ) {
2339 6 $arg_hash->{SSL_use_cert} = 1
2340 }
2341  
2342 # if any of SSL_ca* is set don't set the other SSL_ca*
2343 # from defaults
2344 253 ▶ if ( $arg_hash->{SSL_ca} ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($arg_hash->{'SSL_ca'}) { } 32 221 253
elsif ($arg_hash->{'SSL_ca_path'}) { } 0 221 221
elsif ($arg_hash->{'SSL_ca_file'}) { } 69 152 221
2345 $arg_hash->{SSL_ca_file} ||= undef
2346 $arg_hash->{SSL_ca_path} ||= undef
2347 32 ▶ } elsif ( $arg_hash->{SSL_ca_path} ) {
Condition40%2/5
$arg_hash->{"SSL_ca_file"} ||= (undef $arg_hash->{"SSL_ca_path"} ||= undef)
l!l&&r!l&&!r
0032
undef $arg_hash->{"SSL_ca_path"} ||= undef
l!l
032
MC/DC0%0/2
$arg_hash->{"SSL_ca_file"} ||= (undef $arg_hash->{"SSL_ca_path"} ||= undef)
$arg_hash->{"SSL_ca_file"} (undef $arg_hash->{"SSL_ca_path"} ||= undef)
MC/DC0%0/1
undef $arg_hash->{"SSL_ca_path"} ||= undef
undef $arg_hash->{"SSL_ca_path"}
Truth table33%1/3
A ||= B
A= $arg_hash->{"SSL_ca_file"}B= (undef $arg_hash->{"SSL_ca_path"} ||= undef)
ABresult
1X1
011
000
Truth table50%1/2
A
A= undef $arg_hash->{"SSL_ca_path"}
Aresult
11
00
2348 $arg_hash->{SSL_ca_file} ||= undef
2349 0 ▶ } elsif ( $arg_hash->{SSL_ca_file} ) {
Condition0%0/2
$arg_hash->{"SSL_ca_file"} ||= undef
l!l
00
MC/DC0%0/1
$arg_hash->{"SSL_ca_file"} ||= undef
$arg_hash->{"SSL_ca_file"}
Truth table0%0/2
A
A= $arg_hash->{"SSL_ca_file"}
Aresult
11
00
2350 69 ▶ $arg_hash->{SSL_ca_path} ||= undef;
Condition50%1/2
$arg_hash->{"SSL_ca_path"} ||= undef
l!l
069
MC/DC0%0/1
$arg_hash->{"SSL_ca_path"} ||= undef
$arg_hash->{"SSL_ca_path"}
Truth table50%1/2
A
A= $arg_hash->{"SSL_ca_path"}
Aresult
11
00
2351 }
2352  
2353 # add library defaults
2354 253 ▶ $arg_hash->{SSL_use_cert} = $is_server if ! defined $arg_hash->{SSL_use_cert};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $arg_hash->{"SSL_use_cert"} 243 10 253
2355  
2356  
2357 # Avoid passing undef arguments to Net::SSLeay
2358 253 ▶ defined($arg_hash->{$_}) or delete($arg_hash->{$_}) for(keys %$arg_hash);
Branch: 1 branch
BranchTrueFalseTotal
defined $arg_hash->{$_} or delete $arg_hash->{$_} 1553 2685 4238
2359  
2360 # check SSL CA, cert etc arguments
2361 # some apps set keys '' to signal that it is not set, replace with undef
2362 253 for (qw( SSL_cert SSL_cert_file SSL_key SSL_key_file
2363 SSL_ca SSL_ca_file SSL_ca_path
2364 SSL_fingerprint )) {
2365 $arg_hash->{$_} = undef if defined $arg_hash->{$_}
2366 2024 ▶ and $arg_hash->{$_} eq '';
Branch: 1 branch
BranchTrueFalseTotal
if defined $arg_hash->{$_} and $arg_hash->{$_} eq "" 0 2024 2024
Condition66%2/3
defined $arg_hash->{$_} and $arg_hash->{$_} eq ""
!ll&&!rl&&r
17153090
MC/DC0%0/2
defined $arg_hash->{$_} and $arg_hash->{$_} eq ""
defined $arg_hash->{$_} $arg_hash->{$_} eq ""
Truth table66%2/3
A and B
A= defined $arg_hash->{$_}B= $arg_hash->{$_} eq ""
ABresult
0X0
100
111
2367 }
2368 253 for(qw(SSL_cert_file SSL_key_file)) {
2369 506 ▶ defined( my $file = $arg_hash->{$_} ) or next;
Branch: 1 branch
BranchTrueFalseTotal
defined(my $file = $arg_hash->{$_}) or next 366 140 506
2370 140 ▶ for my $f (ref($file) eq 'HASH' ? values(%$file):$file ) {
Branch: 1 branch
BranchTrueFalseTotal
ref $file eq 'HASH' ? : 12 128 140
2371 172 ▶ die "$_ $f can't be used: $!" if ! open(my $fh,'<',$f)
Branch: 1 branch
BranchTrueFalseTotal
unless open my $fh, "<", $f 0 172 172
2372 }
2373 }
2374  
2375 253 ▶ my $verify_mode = $arg_hash->{SSL_verify_mode} || 0;
Condition100%2/2
$arg_hash->{'SSL_verify_mode'} || 0
l!l
89164
MC/DC100%1/1
$arg_hash->{'SSL_verify_mode'} || 0
$arg_hash->{'SSL_verify_mode'}
Truth table100%2/2
A
A= $arg_hash->{'SSL_verify_mode'}
Aresult
11
00
2376 253 ▶ if ( $verify_mode != $Net_SSLeay_VERIFY_NONE) {
Branch: 2 branches
BranchTrueFalseTotal
if ($verify_mode != $Net_SSLeay_VERIFY_NONE) { } 89 164 253
elsif ($verify_mode ne '0') { } 0 164 164
2377 89 for (qw(SSL_ca_file SSL_ca_path)) {
2378 178 ▶ $CHECK_SSL_PATH->($_ => $arg_hash->{$_} || next);
Condition100%2/2
$arg_hash->{$_} || (next)
l!l
28150
MC/DC100%1/1
$arg_hash->{$_} || (next)
$arg_hash->{$_}
Truth table100%2/2
A
A= $arg_hash->{$_}
Aresult
11
00
2379 }
2380 } elsif ( $verify_mode ne '0' ) {
2381 # some users use the string 'SSL_VERIFY_PEER' instead of the constant
2382 0 die "SSL_verify_mode must be a number and not a string";
2383 }
2384  
2385 253 my $self = bless {},$class;
2386  
2387 253 my $vcn_scheme = delete $arg_hash->{SSL_verifycn_scheme};
2388 253 my $vcn_publicsuffix = delete $arg_hash->{SSL_verifycn_publicsuffix};
2389 253 ▶ if ( ! $is_server and $verify_mode & 0x01 and
Branch: 1 branch
BranchTrueFalseTotal
if (not $is_server and $verify_mode & 1 and !$vcn_scheme || $vcn_scheme ne "none") 86 167 253
Condition88%8/9
not $is_server and $verify_mode & 1 and !$vcn_scheme || $vcn_scheme ne "none"
!ll&&!rl&&r
1674442
not $is_server and $verify_mode & 1
!ll&&!rl&&r
937486
not $vcn_scheme or $vcn_scheme ne "none"
l!l&&r!l&&!r
44420
MC/DC50%2/4
not $is_server and $verify_mode & 1 and !$vcn_scheme || $vcn_scheme ne "none"
not $is_server $verify_mode & 1 not $vcn_scheme $vcn_scheme ne "none"
Truth table60%3/5
not(A) and B and not(C) or D
A= not $is_serverB= $verify_mode & 1C= not $vcn_schemeD= $vcn_scheme ne "none"
ABCDresult
0XXX0
10XX0
11000
111X1
11011
2390 ! $vcn_scheme || $vcn_scheme ne 'none' ) {
2391  
2392 # gets updated during configure_SSL
2393 86 my $verify_name;
2394 86 $self->{verify_name_ref} = \$verify_name;
2395  
2396 86 my $vcb = $arg_hash->{SSL_verify_callback};
2397 $arg_hash->{SSL_verify_callback} = sub {
2398 187 ▶ my ($ok,$ctx_store,$certname,$error,$cert,$depth) = @_;
Subroutine __ANON__: called CC=10 SCAR=28.8
2399 187 ▶ $ok = $vcb->($ok,$ctx_store,$certname,$error,$cert,$depth) if $vcb;
Branch: 1 branch
BranchTrueFalseTotal
if $vcb 4 183 187
2400 187 ▶ $ok or return 0;
Branch: 1 branch
BranchTrueFalseTotal
$ok or return 0 10 177 187
2401  
2402 177 ▶ return $ok if $depth != 0;
Branch: 1 branch
BranchTrueFalseTotal
if $depth != 0 88 89 177
2403  
2404 89 ▶ my $host = $verify_name || ref($vcn_scheme) && $vcn_scheme->{callback} && 'unknown';
Condition12%1/8
$verify_name || ref $vcn_scheme && $vcn_scheme->{'callback'} && 'unknown'
l!l&&r!l&&!r
8900
ref $vcn_scheme and $vcn_scheme->{"callback"} and "unknown"
!ll
00
ref $vcn_scheme and $vcn_scheme->{"callback"}
!ll&&!rl&&r
000
MC/DC0%0/3
$verify_name || ref $vcn_scheme && $vcn_scheme->{'callback'} && 'unknown'
$verify_name ref $vcn_scheme $vcn_scheme->{"callback"}
Truth table25%1/4
A || B and C
A= $verify_nameB= ref $vcn_schemeC= $vcn_scheme->{"callback"}
ABCresult
1XX1
0111
00X0
0100
2405 89 ▶ if ( ! $host ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($host) 0 89 89
2406 0 ▶ if ( $vcn_scheme ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($vcn_scheme) 0 0 0
2407 0 IO::Socket::SSL->_internal_error(
2408 "Cannot determine peer hostname for verification",8);
2409 0 return 0;
2410 }
2411 0 warn "Cannot determine hostname of peer for verification. ".
2412 "Disabling default hostname verification for now. ".
2413 "Please specify hostname with SSL_verifycn_name and better set SSL_verifycn_scheme too.\n";
2414 0 return $ok;
2415 }
2416  
2417  
2418 # verify name
2419 89 my $rv = IO::Socket::SSL::verify_hostname_of_cert(
2420 $host,$cert,$vcn_scheme,$vcn_publicsuffix );
2421 89 ▶ if ( ! $rv ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($rv) 18 71 89
2422 18 IO::Socket::SSL->_internal_error(
2423 "hostname verification failed",5);
2424 }
2425 89 return $rv;
2426 86 };
2427 }
2428  
2429 253 ▶ if ($is_server) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_server) 93 160 253
2430 93 ▶ if ($arg_hash->{SSL_ticket_keycb} && !$can_tckt_keycb) {
Branch: 1 branch
BranchTrueFalseTotal
if ($arg_hash->{"SSL_ticket_keycb"} and not $can_tckt_keycb) 0 93 93
Condition33%1/3
$arg_hash->{"SSL_ticket_keycb"} and not $can_tckt_keycb
!ll&&!rl&&r
9300
MC/DC0%0/2
$arg_hash->{"SSL_ticket_keycb"} and not $can_tckt_keycb
$arg_hash->{"SSL_ticket_keycb"} not $can_tckt_keycb
Truth table33%1/3
A and not(B)
A= $arg_hash->{"SSL_ticket_keycb"}B= not $can_tckt_keycb
ABresult
0X0
100
111
2431 0 warn "Ticket Key Callback is not supported - ignoring option SSL_ticket_keycb\n";
2432 0 delete $arg_hash->{SSL_ticket_keycb};
2433 }
2434 }
2435  
2436  
2437 253 my $ssl_op = $DEFAULT_SSL_OP;
2438  
2439 253 my $ver;
2440 253 for (split(/\s*:\s*/,$arg_hash->{SSL_version})) {
2441 1160 ▶ m{^(!?)(?:(SSL(?:v2|v3|v23|v2/3))|(TLSv1(?:_?[123])?))$}i
Branch: 1 branch
BranchTrueFalseTotal
m[^(!?)(?:(SSL(?:v2|v3|v23|v2/3))|(TLSv1(?:_?[123])?))$]i or croak("invalid SSL_version specified") 0 1160 1160
2442 or croak("invalid SSL_version specified");
2443 1160 my $not = $1;
2444 1160 ▶ ( my $v = lc($2||$3) ) =~s{^(...)}{\U$1};
Condition66%2/3
$2 || $3
l!l&&r!l&&!r
6874730
MC/DC0%0/2
$2 || $3
$2 $3
Truth table66%2/3
A || B
A= $2B= $3
ABresult
1X1
011
000
2445 1160 ▶ if ( $not ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($not) { } 907 253 1160
2446 907 $ssl_op |= $SSL_OP_NO{$v};
2447 } else {
2448 253 ▶ croak("cannot set multiple SSL protocols in SSL_version")
Branch: 1 branch
BranchTrueFalseTotal
if $ver and $v ne $ver 0 253 253
Condition33%1/3
$ver and $v ne $ver
!ll&&!rl&&r
25300
MC/DC0%0/2
$ver and $v ne $ver
$ver $v ne $ver
Truth table33%1/3
A and B
A= $verB= $v ne $ver
ABresult
0X0
100
111
2449 if $ver && $v ne $ver;
2450 253 $ver = $v;
2451 253 $ver =~s{/}{}; # interpret SSLv2/3 as SSLv23
2452 253 $ver =~s{(TLSv1)(\d)}{$1\_$2}; # TLSv1_1
2453 }
2454 }
2455  
2456 253 ▶ my $ctx_new_sub =
Branch: 7 branches
BranchTrueFalseTotal
my $ctx_new_sub = $ver eq "TLSv1_3" ? $CTX_tlsv1_3_new : UNIVERSAL::can("Net::SSLeay", $ver eq "SSLv2" ? "CTX_v2_new" : ($ver eq "SSLv3" ? "CTX_v3_new" : ($ver eq "TLSv1" ? "CTX_tlsv1_new" : ($ver eq "TLSv1_1" ? "CTX_tlsv1_1_new" : ($ver eq "TLSv1_2" ? "CTX_tlsv1_2_new" : "CTX_new"))))) or return "IO::Socket::SSL"->_internal_error("SSL Version $ver not supported", 9) 1 252 253
$ver eq 'TLSv1_3' ? : 2 251 253
$ver eq 'SSLv2' ? : 0 251 251
$ver eq 'SSLv3' ? : 1 250 251
$ver eq 'TLSv1' ? : 2 248 250
$ver eq 'TLSv1_1' ? : 2 246 248
$ver eq 'TLSv1_2' ? : 4 242 246
2457 $ver eq 'TLSv1_3' ? $CTX_tlsv1_3_new :
2458 UNIVERSAL::can( 'Net::SSLeay',
2459 $ver eq 'SSLv2' ? 'CTX_v2_new' :
2460 $ver eq 'SSLv3' ? 'CTX_v3_new' :
2461 $ver eq 'TLSv1' ? 'CTX_tlsv1_new' :
2462 $ver eq 'TLSv1_1' ? 'CTX_tlsv1_1_new' :
2463 $ver eq 'TLSv1_2' ? 'CTX_tlsv1_2_new' :
2464 'CTX_new'
2465 )
2466 or return IO::Socket::SSL->_internal_error("SSL Version $ver not supported",9);
2467  
2468 # For SNI in server mode we need a separate context for each certificate.
2469 252 my %ctx;
2470 252 ▶ if ($is_server) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_server) 93 159 252
2471 93 my %sni;
2472 93 for my $opt (qw(SSL_key SSL_key_file SSL_cert SSL_cert_file)) {
2473 372 ▶ my $val = $arg_hash->{$opt} or next;
Branch: 1 branch
BranchTrueFalseTotal
my $val = $arg_hash->{$opt} or next 191 181 372
2474 181 ▶ if ( ref($val) eq 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $val eq "HASH") 12 169 181
2475 12 ▶ while ( my ($host,$v) = each %$val ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$val) 44 12 56
2476 44 $sni{lc($host)}{$opt} = $v;
2477 }
2478 }
2479 }
2480 93 ▶ while (my ($host,$v) = each %sni) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %sni) 22 93 115
2481 22 ▶ $ctx{$host} = $host =~m{%} ? $v : { %$arg_hash, %$v };
Branch: 1 branch
BranchTrueFalseTotal
$host =~ /%/ ? : 2 20 22
2482 }
2483 }
2484 252 ▶ $ctx{''} = $arg_hash if ! %ctx;
Branch: 1 branch
BranchTrueFalseTotal
unless %ctx 246 6 252
2485  
2486 252 for my $host (sort keys %ctx) {
2487 268 my $arg_hash = delete $ctx{$host};
2488 268 my $ctx;
2489 268 ▶ if ($host =~m{^([^%]*)%}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($host =~ /^([^%]*)%/) 2 266 268
2490 2 ▶ $ctx = $ctx{$1} or return IO::Socket::SSL->error(
Branch: 1 branch
BranchTrueFalseTotal
$ctx = $ctx{$1} or return "IO::Socket::SSL"->error("SSL Context init for $host failed - no config for $1") 0 2 2
2491 "SSL Context init for $host failed - no config for $1");
2492 2 ▶ if (my @k = grep { !m{^SSL_(?:cert|key)(?:_file)?$} }
Branch: 1 branch
BranchTrueFalseTotal
if (my(@k) = grep({not /^SSL_(?:cert|key)(?:_file)?$/;} keys %$arg_hash)) 0 2 2
2493 keys %$arg_hash) {
2494 0 return IO::Socket::SSL->error(
2495 "invalid keys @k in configuration '$host' of additional certs");
2496 }
2497 2 ▶ $can_multi_cert or return IO::Socket::SSL->error(
Branch: 1 branch
BranchTrueFalseTotal
$can_multi_cert or return "IO::Socket::SSL"->error("no support for both RSA and ECC certificate in same context") 0 2 2
2498 "no support for both RSA and ECC certificate in same context");
2499 2 $host = $1;
2500 2 goto just_configure_certs;
2501 }
2502  
2503 266 ▶ $ctx = $ctx_new_sub->() or return
Branch: 1 branch
BranchTrueFalseTotal
$ctx = &$ctx_new_sub() or return "IO::Socket::SSL"->error("SSL Context init failed") 0 266 266
2504 IO::Socket::SSL->error("SSL Context init failed");
2505 266 ▶ $CTX_CREATED_IN_THIS_THREAD{$ctx} = 1 if $use_threads;
Branch: 1 branch
BranchTrueFalseTotal
if $use_threads 0 266 266
2506 266 $ctx{$host} = $ctx; # replace value in %ctx with real context
2507  
2508 # SSL_OP_CIPHER_SERVER_PREFERENCE
2509 266 ▶ $ssl_op |= 0x00400000 if $arg_hash->{SSL_honor_cipher_order};
Branch: 1 branch
BranchTrueFalseTotal
if $arg_hash->{"SSL_honor_cipher_order"} 103 163 266
2510  
2511 266 ▶ if ($ver eq 'SSLv23' && !($ssl_op & $SSL_OP_NO{SSLv3})) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ver eq "SSLv23" and not $ssl_op & $SSL_OP_NO{"SSLv3"}) 20 246 266
Condition100%3/3
$ver eq "SSLv23" and not $ssl_op & $SSL_OP_NO{"SSLv3"}
!ll&&!rl&&r
1023620
MC/DC100%2/2
$ver eq "SSLv23" and not $ssl_op & $SSL_OP_NO{"SSLv3"}
$ver eq "SSLv23" not $ssl_op & $SSL_OP_NO{"SSLv3"}
Truth table100%3/3
A and not(B)
A= $ver eq "SSLv23"B= not $ssl_op & $SSL_OP_NO{"SSLv3"}
ABresult
0X0
100
111
2512 # At least LibreSSL disables SSLv3 by default in SSL_CTX_new.
2513 # If we really want SSL3.0 we need to explicitly allow it with
2514 # SSL_CTX_clear_options.
2515 20 Net::SSLeay::CTX_clear_options($ctx,$SSL_OP_NO{SSLv3});
2516 }
2517  
2518 266 Net::SSLeay::CTX_set_options($ctx,$ssl_op);
2519  
2520 # enable X509_V_FLAG_PARTIAL_CHAIN if possible (OpenSSL 1.1.0+)
2521 266 ▶ $check_partial_chain && $check_partial_chain->($ctx);
Branch: 1 branch
BranchTrueFalseTotal
$check_partial_chain and &$check_partial_chain($ctx) 266 0 266
2522  
2523 # if we don't set session_id_context if client certificate is expected
2524 # client session caching will fail
2525 # if user does not provide explicit id just use the stringification
2526 # of the context
2527 266 ▶ if($arg_hash->{SSL_server} and my $id =
Branch: 1 branch
BranchTrueFalseTotal
if ($arg_hash->{"SSL_server"} and my $id = $arg_hash->{"SSL_session_id_context"} || $arg_hash->{"SSL_verify_mode"} & 1 && "$ctx") 9 257 266
Condition77%7/9
$arg_hash->{"SSL_server"} and my $id = $arg_hash->{"SSL_session_id_context"} || $arg_hash->{"SSL_verify_mode"} & 1 && "$ctx"
!ll&&!rl&&r
159989
$arg_hash->{'SSL_session_id_context'} || $arg_hash->{'SSL_verify_mode'} & 1 && "$ctx"
l!l&&r!l&&!r
0998
$arg_hash->{"SSL_verify_mode"} & 1 and "$ctx"
!ll&&!rl&&r
9809
MC/DC50%2/4
$arg_hash->{"SSL_server"} and my $id = $arg_hash->{"SSL_session_id_context"} || $arg_hash->{"SSL_verify_mode"} & 1 && "$ctx"
$arg_hash->{"SSL_server"} $arg_hash->{'SSL_session_id_context'} $arg_hash->{"SSL_verify_mode"} & 1 "$ctx"
Truth table60%3/5
A and B || C and D
A= $arg_hash->{"SSL_server"}B= $arg_hash->{'SSL_session_id_context'}C= $arg_hash->{"SSL_verify_mode"} & 1D= "$ctx"
ABCDresult
0XXX0
100X0
10100
11XX1
10111
2528 $arg_hash->{SSL_session_id_context} ||
2529 ( $arg_hash->{SSL_verify_mode} & 0x01 ) && "$ctx" ) {
2530 9 Net::SSLeay::CTX_set_session_id_context($ctx,$id,length($id));
2531 }
2532  
2533 # SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER makes syswrite return if at least one
2534 # buffer was written and not block for the rest
2535 # SSL_MODE_ENABLE_PARTIAL_WRITE can be necessary for non-blocking because we
2536 # cannot guarantee, that the location of the buffer stays constant
2537 Net::SSLeay::CTX_set_mode( $ctx,
2538 SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER |
2539 SSL_MODE_ENABLE_PARTIAL_WRITE |
2540 266 ▶ ($arg_hash->{SSL_mode_release_buffers} ? $ssl_mode_release_buffers : 0)
Branch: 1 branch
BranchTrueFalseTotal
$arg_hash->{'SSL_mode_release_buffers'} ? : 0 266 266
2541 );
2542  
2543 266 ▶ if ( my $proto_list = $arg_hash->{SSL_npn_protocols} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $proto_list = $arg_hash->{"SSL_npn_protocols"}) 3 263 266
2544 3 ▶ return IO::Socket::SSL->_internal_error("NPN not supported in Net::SSLeay",9)
Branch: 1 branch
BranchTrueFalseTotal
unless $can_npn 0 3 3
2545 if ! $can_npn;
2546 3 ▶ if($arg_hash->{SSL_server}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($arg_hash->{'SSL_server'}) { } 2 1 3
2547 # on server side SSL_npn_protocols means a list of advertised protocols
2548 2 Net::SSLeay::CTX_set_next_protos_advertised_cb($ctx, $proto_list);
2549 } else {
2550 # on client side SSL_npn_protocols means a list of preferred protocols
2551 # negotiation algorithm used is "as-openssl-implements-it"
2552 1 Net::SSLeay::CTX_set_next_proto_select_cb($ctx, $proto_list);
2553 }
2554 }
2555  
2556 266 ▶ if ( my $proto_list = $arg_hash->{SSL_alpn_protocols} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $proto_list = $arg_hash->{"SSL_alpn_protocols"}) 3 263 266
2557 3 ▶ return IO::Socket::SSL->_internal_error("ALPN not supported in Net::SSLeay",9)
Branch: 1 branch
BranchTrueFalseTotal
unless $can_alpn 0 3 3
2558 if ! $can_alpn;
2559 3 ▶ if($arg_hash->{SSL_server}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($arg_hash->{'SSL_server'}) { } 2 1 3
2560 2 Net::SSLeay::CTX_set_alpn_select_cb($ctx, $proto_list);
2561 } else {
2562 1 Net::SSLeay::CTX_set_alpn_protos($ctx, $proto_list);
2563 }
2564 }
2565  
2566 266 ▶ if ($arg_hash->{SSL_ticket_keycb}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($arg_hash->{"SSL_ticket_keycb"}) 0 266 266
2567 0 my $cb = $arg_hash->{SSL_ticket_keycb};
2568 0 ▶ ($cb,my $arg) = ref($cb) eq 'CODE' ? ($cb):@$cb;
Branch: 1 branch
BranchTrueFalseTotal
ref $cb eq 'CODE' ? : 0 0 0
2569 0 Net::SSLeay::CTX_set_tlsext_ticket_getkey_cb($ctx,$cb,$arg);
2570 }
2571  
2572 # Try to apply SSL_ca even if SSL_verify_mode is 0, so that they can be
2573 # used to verify OCSP responses.
2574 # If applying fails complain only if verify_mode != VERIFY_NONE.
2575 266 ▶ if ( $arg_hash->{SSL_ca}
Branch: 2 branches
BranchTrueFalseTotal
if ($arg_hash->{'SSL_ca'} or defined $arg_hash->{'SSL_ca_file'} or defined $arg_hash->{'SSL_ca_path'}) { } 115 151 266
elsif (my(%ca) = IO::Socket::SSL::default_ca()) { } 151 0 151
Condition83%5/6
$arg_hash->{"SSL_ca"} or defined $arg_hash->{"SSL_ca_file"} or defined $arg_hash->{"SSL_ca_path"}
l!l&&r!l&&!r
1150151
$arg_hash->{"SSL_ca"} or defined $arg_hash->{"SSL_ca_file"}
l!l&&r!l&&!r
3283151
MC/DC66%2/3
$arg_hash->{"SSL_ca"} or defined $arg_hash->{"SSL_ca_file"} or defined $arg_hash->{"SSL_ca_path"}
$arg_hash->{"SSL_ca"} defined $arg_hash->{"SSL_ca_file"} defined $arg_hash->{"SSL_ca_path"}
Truth table75%3/4
A or B or C
A= $arg_hash->{"SSL_ca"}B= defined $arg_hash->{"SSL_ca_file"}C= defined $arg_hash->{"SSL_ca_path"}
ABCresult
1XX1
01X1
0011
0000
2576 || defined $arg_hash->{SSL_ca_file}
2577 || defined $arg_hash->{SSL_ca_path} ) {
2578 115 my $file = $arg_hash->{SSL_ca_file};
2579 115 ▶ $file = undef if ref($file) eq 'SCALAR' && ! $$file;
Branch: 1 branch
BranchTrueFalseTotal
if ref $file eq "SCALAR" and not $$file 0 115 115
Condition33%1/3
ref $file eq "SCALAR" and not $$file
!ll&&!rl&&r
11500
MC/DC0%0/2
ref $file eq "SCALAR" and not $$file
ref $file eq "SCALAR" not $$file
Truth table33%1/3
A and not(B)
A= ref $file eq "SCALAR"B= not $$file
ABresult
0X0
100
111
2580 115 my $dir = $arg_hash->{SSL_ca_path};
2581 115 ▶ $dir = undef if ref($dir) eq 'SCALAR' && ! $$dir;
Branch: 1 branch
BranchTrueFalseTotal
if ref $dir eq "SCALAR" and not $$dir 0 115 115
Condition33%1/3
ref $dir eq "SCALAR" and not $$dir
!ll&&!rl&&r
11500
MC/DC0%0/2
ref $dir eq "SCALAR" and not $$dir
ref $dir eq "SCALAR" not $$dir
Truth table33%1/3
A and not(B)
A= ref $dir eq "SCALAR"B= not $$dir
ABresult
0X0
100
111
2582 115 ▶ if ( $arg_hash->{SSL_ca} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($arg_hash->{"SSL_ca"}) 32 83 115
2583 32 my $store = Net::SSLeay::CTX_get_cert_store($ctx);
2584 32 for (@{$arg_hash->{SSL_ca}}) {
2585 33 ▶ Net::SSLeay::X509_STORE_add_cert($store,$_) or
Branch: 1 branch
BranchTrueFalseTotal
&Net::SSLeay::X509_STORE_add_cert($store, $_) or return "IO::Socket::SSL"->error("Failed to add certificate to CA store") 0 33 33
2586 return IO::Socket::SSL->error(
2587 "Failed to add certificate to CA store");
2588 }
2589 }
2590 115 ▶ $dir = join($OPENSSL_LIST_SEPARATOR,@$dir) if ref($dir);
Branch: 1 branch
BranchTrueFalseTotal
if ref $dir 0 115 115
2591 115 ▶ if ( $file || $dir and ! Net::SSLeay::CTX_load_verify_locations(
Branch: 1 branch
BranchTrueFalseTotal
if ($file || $dir and not &Net::SSLeay::CTX_load_verify_locations($ctx, scalar($file || ""), scalar($dir || ""))) 0 115 115
Condition60%6/10
$file || $dir and not &Net::SSLeay::CTX_load_verify_locations($ctx, scalar($file || ""), scalar($dir || ""))
!ll&&!rl&&r
32830
$file or $dir
l!l&&r!l&&!r
83032
$file || ''
l!l
830
$dir || ''
l!l
083
MC/DC0%0/3
$file || $dir and not &Net::SSLeay::CTX_load_verify_locations($ctx, scalar($file || ""), scalar($dir || ""))
$file $dir not &Net::SSLeay::CTX_load_verify_locations($ctx, scalar($file || ""), scalar($dir || ""))
MC/DC0%0/1
$file || ''
$file
MC/DC0%0/1
$dir || ''
$dir
Truth table40%2/5
A or B and not(C)
A= $fileB= $dirC= not &Net::SSLeay::CTX_load_verify_locations($ctx, scalar($file || ""), scalar($dir || ""))
ABCresult
00X0
1X00
0100
1X11
0111
Truth table50%1/2
A
A= $file
Aresult
11
00
Truth table50%1/2
A
A= $dir
Aresult
11
00
2592 $ctx, $file || '', $dir || '')) {
2593 0 ▶ return IO::Socket::SSL->error(
Branch: 1 branch
BranchTrueFalseTotal
if $verify_mode != $Net_SSLeay_VERIFY_NONE 0 0 0
2594 "Invalid certificate authority locations")
2595 if $verify_mode != $Net_SSLeay_VERIFY_NONE;
2596 }
2597 } elsif ( my %ca = IO::Socket::SSL::default_ca()) {
2598 # no CA path given, continue with system defaults
2599 151 my $dir = $ca{SSL_ca_path};
2600 151 ▶ $dir = join($OPENSSL_LIST_SEPARATOR,@$dir) if ref($dir);
Branch: 1 branch
BranchTrueFalseTotal
if ref $dir 0 151 151
2601 151 ▶ if (! Net::SSLeay::CTX_load_verify_locations( $ctx,
Branch: 1 branch
BranchTrueFalseTotal
if (not &Net::SSLeay::CTX_load_verify_locations($ctx, scalar($ca{"SSL_ca_file"} || ""), scalar($dir || "")) and $verify_mode != $Net_SSLeay_VERIFY_NONE) 0 151 151
Condition57%4/7
not &Net::SSLeay::CTX_load_verify_locations($ctx, scalar($ca{"SSL_ca_file"} || ""), scalar($dir || "")) and $verify_mode != $Net_SSLeay_VERIFY_NONE
!ll&&!rl&&r
15100
$ca{'SSL_ca_file'} || ''
l!l
1510
$dir || ''
l!l
12922
MC/DC0%0/2
not &Net::SSLeay::CTX_load_verify_locations($ctx, scalar($ca{"SSL_ca_file"} || ""), scalar($dir || "")) and $verify_mode != $Net_SSLeay_VERIFY_NONE
not &Net::SSLeay::CTX_load_verify_locations($ctx, scalar($ca{"SSL_ca_file"} || ""), scalar($dir || "")) $verify_mode != $Net_SSLeay_VERIFY_NONE
MC/DC0%0/1
$ca{'SSL_ca_file'} || ''
$ca{'SSL_ca_file'}
MC/DC100%1/1
$dir || ''
$dir
Truth table33%1/3
not(A) and B
A= not &Net::SSLeay::CTX_load_verify_locations($ctx, scalar($ca{"SSL_ca_file"} || ""), scalar($dir || ""))B= $verify_mode != $Net_SSLeay_VERIFY_NONE
ABresult
0X0
100
111
Truth table50%1/2
A
A= $ca{'SSL_ca_file'}
Aresult
11
00
Truth table100%2/2
A
A= $dir
Aresult
11
00
2602 $ca{SSL_ca_file} || '',$dir || '')
2603 && $verify_mode != $Net_SSLeay_VERIFY_NONE) {
2604 0 return IO::Socket::SSL->error(
2605 "Invalid default certificate authority locations")
2606 }
2607 }
2608  
2609 266 ▶ if ($is_server && ($verify_mode & $Net_SSLeay_VERIFY_PEER)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_server and $verify_mode & $Net_SSLeay_VERIFY_PEER) 9 257 266
Condition100%3/3
$is_server and $verify_mode & $Net_SSLeay_VERIFY_PEER
!ll&&!rl&&r
159989
MC/DC100%2/2
$is_server and $verify_mode & $Net_SSLeay_VERIFY_PEER
$is_server $verify_mode & $Net_SSLeay_VERIFY_PEER
Truth table100%3/3
A and B
A= $is_serverB= $verify_mode & $Net_SSLeay_VERIFY_PEER
ABresult
0X0
100
111
2610 9 ▶ if ($arg_hash->{SSL_client_ca}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($arg_hash->{"SSL_client_ca"}) 0 9 9
2611 0 for (@{$arg_hash->{SSL_client_ca}}) {
2612 0 ▶ return IO::Socket::SSL->error(
Branch: 1 branch
BranchTrueFalseTotal
unless &Net::SSLeay::CTX_add_client_CA($ctx, $_) 0 0 0
2613 "Failed to add certificate to client CA list") if
2614 ! Net::SSLeay::CTX_add_client_CA($ctx,$_);
2615 }
2616 }
2617 9 ▶ if ($arg_hash->{SSL_client_ca_file}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($arg_hash->{"SSL_client_ca_file"}) 0 9 9
2618 my $list = Net::SSLeay::load_client_CA_file(
2619 0 ▶ $arg_hash->{SSL_client_ca_file}) or
Branch: 1 branch
BranchTrueFalseTotal
my $list = &Net::SSLeay::load_client_CA_file($arg_hash->{"SSL_client_ca_file"}) or return "IO::Socket::SSL"->error("Failed to load certificate to client CA list") 0 0 0
2620 return IO::Socket::SSL->error(
2621 "Failed to load certificate to client CA list");
2622 0 Net::SSLeay::CTX_set_client_CA_list($ctx,$list);
2623 }
2624 }
2625  
2626 266 my $X509_STORE_flags = $DEFAULT_X509_STORE_flags;
2627 266 ▶ if ($arg_hash->{'SSL_check_crl'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($arg_hash->{"SSL_check_crl"}) 0 266 266
2628 0 $X509_STORE_flags |= Net::SSLeay::X509_V_FLAG_CRL_CHECK();
2629 0 ▶ if ($arg_hash->{'SSL_crl_file'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($arg_hash->{"SSL_crl_file"}) 0 0 0
2630 0 my $bio = Net::SSLeay::BIO_new_file($arg_hash->{'SSL_crl_file'}, 'r');
2631 0 my $crl = Net::SSLeay::PEM_read_bio_X509_CRL($bio);
2632 0 Net::SSLeay::BIO_free($bio);
2633 0 ▶ if ( $crl ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($crl) { } 0 0 0
2634 0 Net::SSLeay::X509_STORE_add_crl(Net::SSLeay::CTX_get_cert_store($ctx), $crl);
2635 0 Net::SSLeay::X509_CRL_free($crl);
2636 } else {
2637 0 return IO::Socket::SSL->error("Invalid certificate revocation list");
2638 }
2639 }
2640 }
2641  
2642 Net::SSLeay::X509_STORE_set_flags(
2643 266 ▶ Net::SSLeay::CTX_get_cert_store($ctx),
Branch: 1 branch
BranchTrueFalseTotal
if $X509_STORE_flags 266 0 266
2644 $X509_STORE_flags
2645 ) if $X509_STORE_flags;
2646  
2647 Net::SSLeay::CTX_set_default_passwd_cb($ctx,$arg_hash->{SSL_passwd_cb})
2648 266 ▶ if $arg_hash->{SSL_passwd_cb};
Branch: 1 branch
BranchTrueFalseTotal
if $arg_hash->{"SSL_passwd_cb"} 12 254 266
2649  
2650 268 just_configure_certs:
2651 my ($havekey,$havecert);
2652 268 ▶ if ( my $x509 = $arg_hash->{SSL_cert} ) {
Branch: 2 branches
BranchTrueFalseTotal
if (my $x509 = $arg_hash->{'SSL_cert'}) { } 31 237 268
elsif (my $f = $arg_hash->{'SSL_cert_file'}) { } 84 153 237
2653 # binary, e.g. X509*
2654 # we have either a single certificate or a list with
2655 # a chain of certificates
2656 31 ▶ my @x509 = ref($x509) eq 'ARRAY' ? @$x509: ($x509);
Branch: 1 branch
BranchTrueFalseTotal
ref $x509 eq 'ARRAY' ? : 1 30 31
2657 31 my $cert = shift @x509;
2658 31 ▶ Net::SSLeay::CTX_use_certificate( $ctx,$cert )
Branch: 1 branch
BranchTrueFalseTotal
&Net::SSLeay::CTX_use_certificate($ctx, $cert) or return "IO::Socket::SSL"->error("Failed to use Certificate") 0 31 31
2659 || return IO::Socket::SSL->error("Failed to use Certificate");
2660 31 foreach my $ca (@x509) {
2661 1 ▶ Net::SSLeay::CTX_add_extra_chain_cert( $ctx,$ca )
Branch: 1 branch
BranchTrueFalseTotal
&Net::SSLeay::CTX_add_extra_chain_cert($ctx, $ca) or return "IO::Socket::SSL"->error("Failed to use Certificate") 0 1 1
2662 || return IO::Socket::SSL->error("Failed to use Certificate");
2663 }
2664 31 $havecert = 'OBJ';
2665 } elsif ( my $f = $arg_hash->{SSL_cert_file} ) {
2666 # try to load chain from PEM or certificate from ASN1
2667 84 my @err;
2668 84 ▶ if (Net::SSLeay::CTX_use_certificate_chain_file($ctx,$f)) {
Branch: 2 branches
BranchTrueFalseTotal
if (&Net::SSLeay::CTX_use_certificate_chain_file($ctx, $f)) { } 81 3 84
elsif (do { push @err, ['PEM', _errstack()]; &Net::SSLeay::CTX_use_certificate_file($ctx, $f, 2) }) { } 1 2 3
2669 81 $havecert = 'PEM';
2670 } elsif (do {
2671 3 push @err, [ PEM => _errstack() ];
2672 3 Net::SSLeay::CTX_use_certificate_file($ctx,$f,FILETYPE_ASN1)
2673 }) {
2674 1 $havecert = 'DER';
2675 } else {
2676 2 push @err, [ DER => _errstack() ];
2677 # try to load certificate, key and chain from PKCS12 file
2678 2 my ($key,$cert,@chain) = Net::SSLeay::P_PKCS12_load_file($f,1);
2679 2 ▶ if (!$cert and $arg_hash->{SSL_passwd_cb}
Branch: 1 branch
BranchTrueFalseTotal
if (not $cert and $arg_hash->{"SSL_passwd_cb"} and defined(my $pw = $arg_hash->{"SSL_passwd_cb"}->(0))) 1 1 2
Condition66%4/6
not $cert and $arg_hash->{"SSL_passwd_cb"} and defined(my $pw = $arg_hash->{"SSL_passwd_cb"}->(0))
!ll&&!rl&&r
101
not $cert and $arg_hash->{"SSL_passwd_cb"}
!ll&&!rl&&r
101
MC/DC33%1/3
not $cert and $arg_hash->{"SSL_passwd_cb"} and defined(my $pw = $arg_hash->{"SSL_passwd_cb"}->(0))
not $cert $arg_hash->{"SSL_passwd_cb"} defined(my $pw = $arg_hash->{"SSL_passwd_cb"}->(0))
Truth table50%2/4
not(A) and B and C
A= not $certB= $arg_hash->{"SSL_passwd_cb"}C= defined(my $pw = $arg_hash->{"SSL_passwd_cb"}->(0))
ABCresult
0XX0
10X0
1100
1111
2680 and defined( my $pw = $arg_hash->{SSL_passwd_cb}->(0))) {
2681 1 ($key,$cert,@chain) = Net::SSLeay::P_PKCS12_load_file($f,1,$pw);
2682 }
2683 2 ▶ PKCS12: while ($cert) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cert) 2 0 2
2684 2 ▶ Net::SSLeay::CTX_use_certificate($ctx,$cert) or last;
Branch: 1 branch
BranchTrueFalseTotal
&Net::SSLeay::CTX_use_certificate($ctx, $cert) or last 0 2 2
2685 # Net::SSLeay::P_PKCS12_load_file is implemented using
2686 # OpenSSL PKCS12_parse which according to the source code
2687 # returns the chain with the last CA certificate first (i.e.
2688 # reverse order as in the PKCS12 file). This is not
2689 # documented but given the age of this function we'll assume
2690 # that this will stay this way in the future.
2691 2 ▶ while (my $ca = pop @chain) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $ca = pop @chain) 0 2 2
2692 0 ▶ Net::SSLeay::CTX_add_extra_chain_cert($ctx,$ca)
Branch: 1 branch
BranchTrueFalseTotal
&Net::SSLeay::CTX_add_extra_chain_cert($ctx, $ca) or last PKCS12 0 0 0
2693 or last PKCS12;
2694 }
2695 2 ▶ last if $key && ! Net::SSLeay::CTX_use_PrivateKey($ctx,$key);
Branch: 1 branch
BranchTrueFalseTotal
if $key and not &Net::SSLeay::CTX_use_PrivateKey($ctx, $key) 0 2 2
Condition33%1/3
$key and not &Net::SSLeay::CTX_use_PrivateKey($ctx, $key)
!ll&&!rl&&r
020
MC/DC0%0/2
$key and not &Net::SSLeay::CTX_use_PrivateKey($ctx, $key)
$key not &Net::SSLeay::CTX_use_PrivateKey($ctx, $key)
Truth table33%1/3
A and not(B)
A= $keyB= not &Net::SSLeay::CTX_use_PrivateKey($ctx, $key)
ABresult
0X0
100
111
2696 2 $havecert = 'PKCS12';
2697 2 last;
2698 }
2699 2 ▶ $havekey = 'PKCS12' if $key;
Branch: 1 branch
BranchTrueFalseTotal
if $key 2 0 2
2700 2 ▶ Net::SSLeay::X509_free($cert) if $cert;
Branch: 1 branch
BranchTrueFalseTotal
if $cert 2 0 2
2701 2 ▶ Net::SSLeay::EVP_PKEY_free($key) if $key;
Branch: 1 branch
BranchTrueFalseTotal
if $key 2 0 2
2702 # don't free @chain, because CTX_add_extra_chain_cert
2703 # did not duplicate the certificates
2704 }
2705 84 ▶ if (!$havecert) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($havecert) 0 84 84
2706 0 push @err, [ PKCS12 => _errstack() ];
2707 0 my $err = "Failed to load certificate from file $f:";
2708 0 for(@err) {
2709 0 my ($type,@e) = @$_;
2710 0 ▶ $err .= " [format:$type] @e **" if @e;
Branch: 1 branch
BranchTrueFalseTotal
if @e 0 0 0
2711 }
2712 0 return IO::Socket::SSL->error($err);
2713 }
2714 }
2715  
2716 268 ▶ if (!$havecert || $havekey) {
Branch: 3 branches
BranchTrueFalseTotal
if (not $havecert or $havekey) { } 155 113 268
elsif (my $pkey = $arg_hash->{'SSL_key'}) { } 28 85 113
elsif (my $f = $arg_hash->{'SSL_key_file'} || ($havecert eq 'PEM' ? $arg_hash->{'SSL_cert_file'} : undef)) { } 85 0 85
Condition100%3/3
not $havecert or $havekey
l!l&&r!l&&!r
1532113
MC/DC100%2/2
not $havecert or $havekey
not $havecert $havekey
Truth table100%3/3
not(A) or B
A= not $havecertB= $havekey
ABresult
1X1
011
000
2717 # skip SSL_key_*
2718 } elsif ( my $pkey = $arg_hash->{SSL_key} ) {
2719 # binary, e.g. EVP_PKEY*
2720 28 ▶ Net::SSLeay::CTX_use_PrivateKey($ctx, $pkey)
Branch: 1 branch
BranchTrueFalseTotal
&Net::SSLeay::CTX_use_PrivateKey($ctx, $pkey) or return "IO::Socket::SSL"->error("Failed to use Private Key") 0 28 28
2721 || return IO::Socket::SSL->error("Failed to use Private Key");
2722 28 $havekey = 'MEM';
2723 ▶ } elsif ( my $f = $arg_hash->{SSL_key_file}
Branch: 1 branch
BranchTrueFalseTotal
$havecert eq 'PEM' ? : 1 0 1
Condition66%2/3
$arg_hash->{'SSL_key_file'} || ($havecert eq 'PEM' ? $arg_hash->{'SSL_cert_file'} : undef)
l!l&&r!l&&!r
8410
MC/DC0%0/2
$arg_hash->{'SSL_key_file'} || ($havecert eq 'PEM' ? $arg_hash->{'SSL_cert_file'} : undef)
$arg_hash->{'SSL_key_file'} ($havecert eq 'PEM' ? $arg_hash->{'SSL_cert_file'} : undef)
Truth table66%2/3
A || B
A= $arg_hash->{'SSL_key_file'}B= ($havecert eq 'PEM' ? $arg_hash->{'SSL_cert_file'} : undef)
ABresult
1X1
011
000
2724 || (($havecert eq 'PEM') ? $arg_hash->{SSL_cert_file}:undef) ) {
2725 85 for my $ft ( FILETYPE_PEM, FILETYPE_ASN1 ) {
2726 86 ▶ if (Net::SSLeay::CTX_use_PrivateKey_file($ctx,$f,$ft)) {
Branch: 1 branch
BranchTrueFalseTotal
if (&Net::SSLeay::CTX_use_PrivateKey_file($ctx, $f, $ft)) 85 1 86
2727 85 ▶ $havekey = ($ft == FILETYPE_PEM) ? 'PEM':'DER';
Branch: 1 branch
BranchTrueFalseTotal
$ft == 1 ? : 84 1 85
2728 85 last;
2729 }
2730 }
2731 85 ▶ $havekey or return IO::Socket::SSL->error(
Branch: 1 branch
BranchTrueFalseTotal
$havekey or return "IO::Socket::SSL"->error("Failed to load key from file (no PEM or DER)") 0 85 85
2732 "Failed to load key from file (no PEM or DER)");
2733 }
2734  
2735 268 ▶ Net::SSLeay::CTX_set_post_handshake_auth($ctx,1)
Branch: 1 branch
BranchTrueFalseTotal
if not $is_server and $can_pha and $havecert and $havekey 8 260 268
Condition77%7/9
not $is_server and $can_pha and $havecert and $havekey
!ll&&!rl&&r
26008
not $is_server and $can_pha and $havecert
!ll&&!rl&&r
1091518
not $is_server and $can_pha
!ll&&!rl&&r
1090159
MC/DC50%2/4
not $is_server and $can_pha and $havecert and $havekey
not $is_server $can_pha $havecert $havekey
Truth table60%3/5
not(A) and B and C and D
A= not $is_serverB= $can_phaC= $havecertD= $havekey
ABCDresult
0XXX0
10XX0
110X0
11100
11111
2736 if (!$is_server && $can_pha && $havecert && $havekey);
2737 }
2738  
2739 252 ▶ if ($arg_hash->{SSL_server}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($arg_hash->{"SSL_server"}) 93 159 252
2740  
2741 93 ▶ if ( my $f = $arg_hash->{SSL_dh_file} ) {
Branch: 2 branches
BranchTrueFalseTotal
if (my $f = $arg_hash->{'SSL_dh_file'}) { } 0 93 93
elsif (my $dh = $arg_hash->{'SSL_dh'}) { } 93 0 93
2742 0 ▶ my $bio = Net::SSLeay::BIO_new_file( $f,'r' )
Condition0%0/2
&Net::SSLeay::BIO_new_file($f, 'r') || (return 'IO::Socket::SSL'->error("Failed to open DH file $f"))
l!l
00
MC/DC0%0/1
&Net::SSLeay::BIO_new_file($f, 'r') || (return 'IO::Socket::SSL'->error("Failed to open DH file $f"))
&Net::SSLeay::BIO_new_file($f, 'r')
Truth table0%0/2
A
A= &Net::SSLeay::BIO_new_file($f, 'r')
Aresult
11
00
2743 || return IO::Socket::SSL->error( "Failed to open DH file $f" );
2744 0 my $dh = Net::SSLeay::PEM_read_bio_DHparams($bio);
2745 0 Net::SSLeay::BIO_free($bio);
2746 0 ▶ $dh || return IO::Socket::SSL->error( "Failed to read PEM for DH from $f - wrong format?" );
Branch: 1 branch
BranchTrueFalseTotal
$dh or return "IO::Socket::SSL"->error("Failed to read PEM for DH from $f - wrong format?") 0 0 0
2747 0 my $rv;
2748 0 for (values (%ctx)) {
2749 0 ▶ $rv = Net::SSLeay::CTX_set_tmp_dh( $_,$dh ) or last;
Branch: 1 branch
BranchTrueFalseTotal
$rv = &Net::SSLeay::CTX_set_tmp_dh($_, $dh) or last 0 0 0
2750 }
2751 0 Net::SSLeay::DH_free( $dh );
2752 0 ▶ $rv || return IO::Socket::SSL->error( "Failed to set DH from $f" );
Branch: 1 branch
BranchTrueFalseTotal
$rv or return "IO::Socket::SSL"->error("Failed to set DH from $f") 0 0 0
2753 } elsif ( my $dh = $arg_hash->{SSL_dh} ) {
2754 # binary, e.g. DH*
2755  
2756 93 for( values %ctx ) {
2757 107 ▶ Net::SSLeay::CTX_set_tmp_dh( $_,$dh ) || return
Branch: 1 branch
BranchTrueFalseTotal
&Net::SSLeay::CTX_set_tmp_dh($_, $dh) or return "IO::Socket::SSL"->error("Failed to set DH from SSL_dh") 0 107 107
2758 IO::Socket::SSL->error( "Failed to set DH from SSL_dh" );
2759 }
2760 }
2761 }
2762  
2763 252 ▶ if ( my $curve = $arg_hash->{SSL_ecdh_curve} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $curve = $arg_hash->{"SSL_ecdh_curve"}) 10 242 252
2764 10 ▶ return IO::Socket::SSL->_internal_error(
Branch: 1 branch
BranchTrueFalseTotal
unless $can_ecdh 0 10 10
2765 "ECDH curve needs Net::SSLeay>=1.56 and OpenSSL>=1.0",9)
2766 if ! $can_ecdh;
2767  
2768 10 for(values %ctx) {
2769 10 ▶ if ($arg_hash->{SSL_server} and $curve eq 'auto') {
Branch: 4 branches
BranchTrueFalseTotal
if ($arg_hash->{'SSL_server'} and $curve eq 'auto') { } 0 10 10
elsif ($set_groups_list) { } 10 0 10
elsif ($curve =~ /:/) { } 0 0 0
elsif ($arg_hash->{'SSL_server'}) { } 0 0 0
Condition66%2/3
$arg_hash->{"SSL_server"} and $curve eq "auto"
!ll&&!rl&&r
640
MC/DC0%0/2
$arg_hash->{"SSL_server"} and $curve eq "auto"
$arg_hash->{"SSL_server"} $curve eq "auto"
Truth table66%2/3
A and B
A= $arg_hash->{"SSL_server"}B= $curve eq "auto"
ABresult
0X0
100
111
2770 0 ▶ if ($can_ecdh eq 'can_auto') {
Branch: 2 branches
BranchTrueFalseTotal
if ($can_ecdh eq 'can_auto') { } 0 0 0
elsif ($can_ecdh eq 'auto') { } 0 0 0
2771 0 ▶ Net::SSLeay::CTX_set_ecdh_auto($_,1) or
Branch: 1 branch
BranchTrueFalseTotal
Net::SSLeay::CTX_set_ecdh_auto($_, 1) or return "IO::Socket::SSL"->error("failed to set ECDH curve context") 0 0 0
2772 return IO::Socket::SSL->error(
2773 "failed to set ECDH curve context");
2774 } elsif ($can_ecdh eq 'auto') {
2775 # automatically enabled anyway
2776 } else {
2777 0 return IO::Socket::SSL->error(
2778 "SSL_CTX_set_ecdh_auto not implemented");
2779 }
2780  
2781 } elsif ($set_groups_list) {
2782 10 ▶ $set_groups_list->($_,$curve) or return IO::Socket::SSL->error(
Branch: 1 branch
BranchTrueFalseTotal
&$set_groups_list($_, $curve) or return "IO::Socket::SSL"->error("failed to set ECDH groups/curves on context") 0 10 10
2783 "failed to set ECDH groups/curves on context");
2784 # needed for OpenSSL 1.0.2 if ($can_ecdh eq 'can_auto') {
2785 10 ▶ Net::SSLeay::CTX_set_ecdh_auto($_,1) if $can_ecdh eq 'can_auto';
Branch: 1 branch
BranchTrueFalseTotal
if $can_ecdh eq "can_auto" 0 10 10
2786 } elsif ($curve =~m{:}) {
2787 0 return IO::Socket::SSL->error(
2788 "SSL_CTX_groups_list or SSL_CTX_curves_list not implemented");
2789  
2790 } elsif ($arg_hash->{SSL_server}) {
2791 0 ▶ if ( $curve !~ /^\d+$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($curve =~ /^\d+$/) 0 0 0
2792 # name of curve, find NID
2793 0 ▶ $curve = Net::SSLeay::OBJ_txt2nid($curve)
Condition0%0/2
&Net::SSLeay::OBJ_txt2nid($curve) || (return 'IO::Socket::SSL'->error("cannot find NID for curve name '${curve}'"))
l!l
00
MC/DC0%0/1
&Net::SSLeay::OBJ_txt2nid($curve) || (return 'IO::Socket::SSL'->error("cannot find NID for curve name '${curve}'"))
&Net::SSLeay::OBJ_txt2nid($curve)
Truth table0%0/2
A
A= &Net::SSLeay::OBJ_txt2nid($curve)
Aresult
11
00
2794 || return IO::Socket::SSL->error(
2795 "cannot find NID for curve name '$curve'");
2796 }
2797 0 ▶ my $ecdh = Net::SSLeay::EC_KEY_new_by_curve_name($curve) or
Branch: 1 branch
BranchTrueFalseTotal
my $ecdh = &Net::SSLeay::EC_KEY_new_by_curve_name($curve) or return "IO::Socket::SSL"->error("cannot create curve for NID $curve") 0 0 0
2798 return IO::Socket::SSL->error(
2799 "cannot create curve for NID $curve");
2800 0 for( values %ctx ) {
2801 0 ▶ Net::SSLeay::CTX_set_tmp_ecdh($_,$ecdh) or
Branch: 1 branch
BranchTrueFalseTotal
&Net::SSLeay::CTX_set_tmp_ecdh($_, $ecdh) or return "IO::Socket::SSL"->error("failed to set ECDH curve context") 0 0 0
2802 return IO::Socket::SSL->error(
2803 "failed to set ECDH curve context");
2804 }
2805 0 Net::SSLeay::EC_KEY_free($ecdh);
2806 }
2807 }
2808 }
2809  
2810 252 my $verify_cb = $arg_hash->{SSL_verify_callback};
2811 252 my @accept_fp;
2812 252 ▶ if ( my $fp = $arg_hash->{SSL_fingerprint} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $fp = $arg_hash->{"SSL_fingerprint"}) 9 243 252
2813 9 ▶ for( ref($fp) ? @$fp : $fp) {
Branch: 1 branch
BranchTrueFalseTotal
ref $fp ? : 2 7 9
2814 11 ▶ my ($algo,$pubkey,$digest) = m{^(?:([\w-]+)\$)?(pub\$)?([a-f\d:]+)$}i
Branch: 1 branch
BranchTrueFalseTotal
() = /^(?:([\w-]+)\$)?(pub\$)?([a-f\d:]+)$/i or return "IO::Socket::SSL"->_internal_error("invalid fingerprint '${_}'", 9) 0 11 11
2815 or return IO::Socket::SSL->_internal_error("invalid fingerprint '$_'",9);
2816 11 ( $digest = lc($digest) ) =~s{:}{}g;
2817 11 ▶ $algo ||=
Branch: 3 branches
BranchTrueFalseTotal
length $digest == 32 ? : 0 0 0
length $digest == 40 ? : 0 0 0
length $digest == 64 ? : 0 0 0
Condition33%1/3
$algo ||= length $digest == 32 ? "md5" : (length $digest == 40 ? "sha1" : (length $digest == 64 ? "sha256" : (return "IO::Socket::SSL"->_internal_error("cannot detect hash algorithm from fingerprint '${_}'", 9))))
l!l&&r!l&&!r
1100
MC/DC0%0/2
$algo ||= length $digest == 32 ? "md5" : (length $digest == 40 ? "sha1" : (length $digest == 64 ? "sha256" : (return "IO::Socket::SSL"->_internal_error("cannot detect hash algorithm from fingerprint '${_}'", 9))))
$algo length $digest == 32 ? "md5" : (length $digest == 40 ? "sha1" : (length $digest == 64 ? "sha256" : (return "IO::Socket::SSL"->_internal_error("cannot detect hash algorithm from fingerprint '${_}'", 9))))
Truth table33%1/3
A ||= B
A= $algoB= length $digest == 32 ? "md5" : (length $digest == 40 ? "sha1" : (length $digest == 64 ? "sha256" : (return "IO::Socket::SSL"->_internal_error("cannot detect hash algorithm from fingerprint '${_}'", 9))))
ABresult
1X1
011
000
2818 length($digest) == 32 ? 'md5' :
2819 length($digest) == 40 ? 'sha1' :
2820 length($digest) == 64 ? 'sha256' :
2821 return IO::Socket::SSL->_internal_error(
2822 "cannot detect hash algorithm from fingerprint '$_'",9);
2823 11 $algo = lc($algo);
2824 11 ▶ push @accept_fp,[ $algo, $pubkey || '', pack('H*',$digest) ]
Condition100%2/2
$pubkey || ''
l!l
110
MC/DC100%1/1
$pubkey || ''
$pubkey
Truth table100%2/2
A
A= $pubkey
Aresult
11
00
2825 }
2826 }
2827 252 ▶ my $verify_fingerprint = @accept_fp && do {
Condition66%2/3
@accept_fp && do { my $fail; sub { my($ok, $cert, $depth) = @_; $fail = 1 unless $ok; return 1 if $depth > 0; my %fp; foreach $_ (@accept_fp) { my $fp = ($fp{join $;, $_->[0], $_->[1]} ||= $_->[1] ? &Net::SSLeay::X509_pubkey_digest($cert, scalar &$algo2digest($_->[0])) : &Net::SSLeay::X509_digest($cert, scalar &$algo2digest($_->[0]))); next if $fp ne $_->[2]; return 1; } ; return !$fail; } }
!ll&&!rl&&r
24309
MC/DC50%1/2
@accept_fp && do { my $fail; sub { my($ok, $cert, $depth) = @_; $fail = 1 unless $ok; return 1 if $depth > 0; my %fp; foreach $_ (@accept_fp) { my $fp = ($fp{join $;, $_->[0], $_->[1]} ||= $_->[1] ? &Net::SSLeay::X509_pubkey_digest($cert, scalar &$algo2digest($_->[0])) : &Net::SSLeay::X509_digest($cert, scalar &$algo2digest($_->[0]))); next if $fp ne $_->[2]; return 1; } ; return !$fail; } }
@accept_fp do { my $fail; sub { my($ok, $cert, $depth) = @_; $fail = 1 unless $ok; return 1 if $depth > 0; my %fp; foreach $_ (@accept_fp) { my $fp = ($fp{join $;, $_->[0], $_->[1]} ||= $_->[1] ? &Net::SSLeay::X509_pubkey_digest($cert, scalar &$algo2digest($_->[0])) : &Net::SSLeay::X509_digest($cert, scalar &$algo2digest($_->[0]))); next if $fp ne $_->[2]; return 1; } ; return !$fail; } }
Truth table66%2/3
A && B
A= @accept_fpB= do { my $fail; sub { my($ok, $cert, $depth) = @_; $fail = 1 unless $ok; return 1 if $depth > 0; my %fp; foreach $_ (@accept_fp) { my $fp = ($fp{join $;, $_->[0], $_->[1]} ||= $_->[1] ? &Net::SSLeay::X509_pubkey_digest($cert, scalar &$algo2digest($_->[0])) : &Net::SSLeay::X509_digest($cert, scalar &$algo2digest($_->[0]))); next if $fp ne $_->[2]; return 1; } ; return !$fail; } }
ABresult
0X0
100
111
2828 9 my $fail;
2829 sub {
2830 22 ▶ my ($ok,$cert,$depth) = @_;
Subroutine __ANON__: called CC=7 SCAR=19.5
2831 22 ▶ $fail = 1 if ! $ok;
Branch: 1 branch
BranchTrueFalseTotal
unless $ok 9 13 22
2832 22 ▶ return 1 if $depth>0; # to let us continue with verification
Branch: 1 branch
BranchTrueFalseTotal
if $depth > 0 10 12 22
2833 # Check fingerprint only from top certificate.
2834 12 my %fp;
2835 12 for(@accept_fp) {
2836 13 ▶ my $fp = $fp{$_->[0],$_->[1]} ||= $_->[1]
Branch: 1 branch
BranchTrueFalseTotal
$_->[1] ? : 2 10 12
Condition66%2/3
$fp{join $;, $_->[0], $_->[1]} ||= $_->[1] ? &Net::SSLeay::X509_pubkey_digest($cert, scalar &$algo2digest($_->[0])) : &Net::SSLeay::X509_digest($cert, scalar &$algo2digest($_->[0]))
l!l&&r!l&&!r
1120
MC/DC0%0/2
$fp{join $;, $_->[0], $_->[1]} ||= $_->[1] ? &Net::SSLeay::X509_pubkey_digest($cert, scalar &$algo2digest($_->[0])) : &Net::SSLeay::X509_digest($cert, scalar &$algo2digest($_->[0]))
$fp{join $;, $_->[0], $_->[1]} $_->[1] ? &Net::SSLeay::X509_pubkey_digest($cert, scalar &$algo2digest($_->[0])) : &Net::SSLeay::X509_digest($cert, scalar &$algo2digest($_->[0]))
Truth table66%2/3
A ||= B
A= $fp{join $;, $_->[0], $_->[1]}B= $_->[1] ? &Net::SSLeay::X509_pubkey_digest($cert, scalar &$algo2digest($_->[0])) : &Net::SSLeay::X509_digest($cert, scalar &$algo2digest($_->[0]))
ABresult
1X1
011
000
2837 ? Net::SSLeay::X509_pubkey_digest($cert,$algo2digest->($_->[0]))
2838 : Net::SSLeay::X509_digest($cert,$algo2digest->($_->[0]));
2839 13 ▶ next if $fp ne $_->[2];
Branch: 1 branch
BranchTrueFalseTotal
if $fp ne $_->[2] 4 9 13
2840 9 return 1;
2841 }
2842 3 return ! $fail;
2843 }
2844 9 };
2845 my $verify_callback = ( $verify_cb || @accept_fp ) && sub {
2846 187 ▶ my ($ok, $ctx_store) = @_;
Subroutine __ANON__: called CC=7 SCAR=19.9
2847 187 my ($certname,$cert,$error,$depth);
2848 187 ▶ if ($ctx_store) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ctx_store) 187 0 187
2849 187 $cert = Net::SSLeay::X509_STORE_CTX_get_current_cert($ctx_store);
2850 187 $error = Net::SSLeay::X509_STORE_CTX_get_error($ctx_store);
2851 187 $depth = Net::SSLeay::X509_STORE_CTX_get_error_depth($ctx_store);
2852 187 $certname =
2853 Net::SSLeay::X509_NAME_oneline(Net::SSLeay::X509_get_issuer_name($cert)).
2854 Net::SSLeay::X509_NAME_oneline(Net::SSLeay::X509_get_subject_name($cert));
2855 187 ▶ $error &&= Net::SSLeay::ERR_error_string($error);
Condition66%2/3
$error &&= &Net::SSLeay::ERR_error_string($error)
!ll&&!rl&&r
164023
MC/DC50%1/2
$error &&= &Net::SSLeay::ERR_error_string($error)
$error &Net::SSLeay::ERR_error_string($error)
Truth table66%2/3
A &&= B
A= $errorB= &Net::SSLeay::ERR_error_string($error)
ABresult
0X0
100
111
2856 }
2857 187 ▶ $DEBUG>=3 && DEBUG( "ok=$ok [$depth] $certname" );
Branch: 1 branch
BranchTrueFalseTotal
$IO::Socket::SSL::DEBUG >= 3 and DEBUG("ok=$ok [$depth] $certname") 0 187 187
2858 187 ▶ $ok = $verify_cb->($ok,$ctx_store,$certname,$error,$cert,$depth) if $verify_cb;
Branch: 1 branch
BranchTrueFalseTotal
if $verify_cb 187 0 187
2859 187 ▶ $ok = $verify_fingerprint->($ok,$cert,$depth) if $verify_fingerprint && $cert;
Branch: 1 branch
BranchTrueFalseTotal
if $verify_fingerprint and $cert 22 165 187
Condition66%2/3
$verify_fingerprint and $cert
!ll&&!rl&&r
165022
MC/DC50%1/2
$verify_fingerprint and $cert
$verify_fingerprint $cert
Truth table66%2/3
A and B
A= $verify_fingerprintB= $cert
ABresult
0X0
100
111
2860 187 return $ok;
2861 252 ▶ };
Condition66%4/6
($verify_cb || @accept_fp) && sub { my($ok, $ctx_store) = @_; my($certname, $cert, $error, $depth); if ($ctx_store) { $cert = &Net::SSLeay::X509_STORE_CTX_get_current_cert($ctx_store); $error = &Net::SSLeay::X509_STORE_CTX_get_error($ctx_store); $depth = &Net::SSLeay::X509_STORE_CTX_get_error_depth($ctx_store); $certname = &Net::SSLeay::X509_NAME_oneline(scalar &Net::SSLeay::X509_get_issuer_name($cert)) . &Net::SSLeay::X509_NAME_oneline(scalar &Net::SSLeay::X509_get_subject_name($cert)); $error &&= &Net::SSLeay::ERR_error_string($error); } ; $IO::Socket::SSL::DEBUG >= 3 and DEBUG("ok=$ok [$depth] $certname"); $ok = &$verify_cb($ok, $ctx_store, $certname, $error, $cert, $depth) if $verify_cb; $ok = &$verify_fingerprint($ok, $cert, $depth) if $verify_fingerprint and $cert; return $ok; }
!ll&&!rl&&r
166086
$verify_cb or @accept_fp
l!l&&r!l&&!r
860166
MC/DC33%1/3
($verify_cb || @accept_fp) && sub { my($ok, $ctx_store) = @_; my($certname, $cert, $error, $depth); if ($ctx_store) { $cert = &Net::SSLeay::X509_STORE_CTX_get_current_cert($ctx_store); $error = &Net::SSLeay::X509_STORE_CTX_get_error($ctx_store); $depth = &Net::SSLeay::X509_STORE_CTX_get_error_depth($ctx_store); $certname = &Net::SSLeay::X509_NAME_oneline(scalar &Net::SSLeay::X509_get_issuer_name($cert)) . &Net::SSLeay::X509_NAME_oneline(scalar &Net::SSLeay::X509_get_subject_name($cert)); $error &&= &Net::SSLeay::ERR_error_string($error); } ; $IO::Socket::SSL::DEBUG >= 3 and DEBUG("ok=$ok [$depth] $certname"); $ok = &$verify_cb($ok, $ctx_store, $certname, $error, $cert, $depth) if $verify_cb; $ok = &$verify_fingerprint($ok, $cert, $depth) if $verify_fingerprint and $cert; return $ok; }
$verify_cb @accept_fp sub { my($ok, $ctx_store) = @_; my($certname, $cert, $error, $depth); if ($ctx_store) { $cert = &Net::SSLeay::X509_STORE_CTX_get_current_cert($ctx_store); $error = &Net::SSLeay::X509_STORE_CTX_get_error($ctx_store); $depth = &Net::SSLeay::X509_STORE_CTX_get_error_depth($ctx_store); $certname = &Net::SSLeay::X509_NAME_oneline(scalar &Net::SSLeay::X509_get_issuer_name($cert)) . &Net::SSLeay::X509_NAME_oneline(scalar &Net::SSLeay::X509_get_subject_name($cert)); $error &&= &Net::SSLeay::ERR_error_string($error); } ; $IO::Socket::SSL::DEBUG >= 3 and DEBUG("ok=$ok [$depth] $certname"); $ok = &$verify_cb($ok, $ctx_store, $certname, $error, $cert, $depth) if $verify_cb; $ok = &$verify_fingerprint($ok, $cert, $depth) if $verify_fingerprint and $cert; return $ok; }
Truth table40%2/5
A or B && C
A= $verify_cbB= @accept_fpC= sub { my($ok, $ctx_store) = @_; my($certname, $cert, $error, $depth); if ($ctx_store) { $cert = &Net::SSLeay::X509_STORE_CTX_get_current_cert($ctx_store); $error = &Net::SSLeay::X509_STORE_CTX_get_error($ctx_store); $depth = &Net::SSLeay::X509_STORE_CTX_get_error_depth($ctx_store); $certname = &Net::SSLeay::X509_NAME_oneline(scalar &Net::SSLeay::X509_get_issuer_name($cert)) . &Net::SSLeay::X509_NAME_oneline(scalar &Net::SSLeay::X509_get_subject_name($cert)); $error &&= &Net::SSLeay::ERR_error_string($error); } ; $IO::Socket::SSL::DEBUG >= 3 and DEBUG("ok=$ok [$depth] $certname"); $ok = &$verify_cb($ok, $ctx_store, $certname, $error, $cert, $depth) if $verify_cb; $ok = &$verify_fingerprint($ok, $cert, $depth) if $verify_fingerprint and $cert; return $ok; }
ABCresult
00X0
1X00
0100
1X11
0111
2862  
2863 252 ▶ if ( $^O eq 'darwin' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($^O eq "darwin") 0 252 252
2864 # explicitly set error code to disable use of apples TEA patch
2865 # https://hynek.me/articles/apple-openssl-verification-surprises/
2866 0 my $vcb = $verify_callback;
2867 $verify_callback = sub {
2868 0 ▶ my $rv = $vcb ? &$vcb : $_[0];
Subroutine __ANON__: not called CC=3 SCAR=24.8
Branch: 1 branch
BranchTrueFalseTotal
$vcb ? : 0 0 0
2869 0 ▶ if ( $rv != 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rv != 1) 0 0 0
2870 # 50 - X509_V_ERR_APPLICATION_VERIFICATION: application verification failure
2871 0 Net::SSLeay::X509_STORE_CTX_set_error($_[1], 50);
2872 }
2873 0 return $rv;
2874 0 };
2875 }
2876 Net::SSLeay::CTX_set_verify($_, $verify_mode, $verify_callback)
2877 252 for (values %ctx);
2878  
2879 252 my $staple_callback = $arg_hash->{SSL_ocsp_staple_callback};
2880 252 ▶ if ( !$is_server && $can_ocsp_staple && ! $verify_fingerprint) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $is_server and $can_ocsp_staple and not $verify_fingerprint) 150 102 252
Condition83%5/6
not $is_server and $can_ocsp_staple and not $verify_fingerprint
!ll&&!rl&&r
939150
not $is_server and $can_ocsp_staple
!ll&&!rl&&r
930159
MC/DC66%2/3
not $is_server and $can_ocsp_staple and not $verify_fingerprint
not $is_server $can_ocsp_staple not $verify_fingerprint
Truth table75%3/4
not(A) and B and not(C)
A= not $is_serverB= $can_ocsp_stapleC= not $verify_fingerprint
ABCresult
0XX0
10X0
1100
1111
2881 150 $self->{ocsp_cache} = $arg_hash->{SSL_ocsp_cache};
2882 my $status_cb = sub {
2883 69 ▶ my ($ssl,$resp) = @_;
Subroutine __ANON__: called CC=24 SCAR=59.8
2884 69 ▶ my $iossl = $SSL_OBJECT{$ssl} or
Branch: 1 branch
BranchTrueFalseTotal
my $iossl = $SSL_OBJECT{$ssl} or die "no IO::Socket::SSL object found for SSL $ssl" 0 69 69
2885 die "no IO::Socket::SSL object found for SSL $ssl";
2886 69 ▶ $iossl->[1] and do {
Branch: 1 branch
BranchTrueFalseTotal
$iossl->[1] and do { Carp::cluck($IO::Socket::SSL::SSL_ERROR = "OCSP callback on server side"); return 1 } 0 69 69
2887 # we must return with 1 or it will be called again
2888 # and because we have no SSL object we must make the error global
2889 0 Carp::cluck($IO::Socket::SSL::SSL_ERROR
2890 = "OCSP callback on server side");
2891 0 return 1;
2892 };
2893 69 $iossl = $iossl->[0];
2894  
2895 # if we have a callback use this
2896 # callback must not free or copy $resp !!
2897 69 ▶ if ( $staple_callback ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($staple_callback) 0 69 69
2898 0 $staple_callback->($iossl,$resp);
2899 0 return 1;
2900 }
2901  
2902 # default callback does verification
2903 69 ▶ if ( ! $resp ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($resp) 69 0 69
2904 69 ▶ $DEBUG>=3 && DEBUG("did not get stapled OCSP response");
Branch: 1 branch
BranchTrueFalseTotal
$IO::Socket::SSL::DEBUG >= 3 and DEBUG("did not get stapled OCSP response") 0 69 69
2905 69 return 1;
2906 }
2907 0 ▶ $DEBUG>=3 && DEBUG("got stapled OCSP response");
Branch: 1 branch
BranchTrueFalseTotal
$IO::Socket::SSL::DEBUG >= 3 and DEBUG("got stapled OCSP response") 0 0 0
2908 0 my $status = Net::SSLeay::OCSP_response_status($resp);
2909 0 ▶ if ($status != Net::SSLeay::OCSP_RESPONSE_STATUS_SUCCESSFUL()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($status != Net::SSLeay::OCSP_RESPONSE_STATUS_SUCCESSFUL()) 0 0 0
2910 0 ▶ $DEBUG>=3 && DEBUG("bad status of stapled OCSP response: ".
Branch: 1 branch
BranchTrueFalseTotal
$IO::Socket::SSL::DEBUG >= 3 and DEBUG('bad status of stapled OCSP response: ' . &Net::SSLeay::OCSP_response_status_str($status)) 0 0 0
2911 Net::SSLeay::OCSP_response_status_str($status));
2912 0 return 1;
2913 }
2914 0 ▶ if (!eval { Net::SSLeay::OCSP_response_verify($ssl,$resp) }) {
Branch: 1 branch
BranchTrueFalseTotal
unless (eval { do { &Net::SSLeay::OCSP_response_verify($ssl, $resp) } }) 0 0 0
2915 0 ▶ $DEBUG>=3 && DEBUG("verify of stapled OCSP response failed");
Branch: 1 branch
BranchTrueFalseTotal
$IO::Socket::SSL::DEBUG >= 3 and DEBUG("verify of stapled OCSP response failed") 0 0 0
2916 0 return 1;
2917 }
2918 0 my (@results,$hard_error);
2919 0 my @chain = $iossl->peer_certificates;
2920 0 for my $cert (@chain) {
2921 0 my $certid = eval { Net::SSLeay::OCSP_cert2ids($ssl,$cert) };
2922 0 ▶ if (!$certid) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($certid) 0 0 0
2923 0 ▶ $DEBUG>=3 && DEBUG("cannot create OCSP_CERTID: $@");
Branch: 1 branch
BranchTrueFalseTotal
$IO::Socket::SSL::DEBUG >= 3 and DEBUG("cannot create OCSP_CERTID: $@") 0 0 0
2924 0 push @results,[-1,$@];
2925 0 last;
2926 }
2927 0 ($status) = Net::SSLeay::OCSP_response_results($resp,$certid);
2928 0 ▶ if ($status && $status->[2]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($status and $status->[2]) 0 0 0
Condition0%0/3
$status and $status->[2]
!ll&&!rl&&r
000
MC/DC0%0/2
$status and $status->[2]
$status $status->[2]
Truth table0%0/3
A and B
A= $statusB= $status->[2]
ABresult
0X0
100
111
2929 0 my $cache = ${*$iossl}{_SSL_ctx}{ocsp_cache};
2930 0 ▶ if (!$status->[1]) {
Branch: 2 branches
BranchTrueFalseTotal
if (not $status->[1]) { } 0 0 0
elsif ($status->[2]{'statusType'} == Net::SSLeay::V_OCSP_CERTSTATUS_GOOD()) { } 0 0 0
2931 0 push @results,[1,$status->[2]{nextUpdate}];
2932 0 ▶ $cache && $cache->put($certid,$status->[2]);
Branch: 1 branch
BranchTrueFalseTotal
$cache and $cache->put($certid, $status->[2]) 0 0 0
2933 } elsif ( $status->[2]{statusType} ==
2934 Net::SSLeay::V_OCSP_CERTSTATUS_GOOD()) {
2935 0 push @results,[1,$status->[2]{nextUpdate}];
2936 $cache && $cache->put($certid,{
2937 0 ▶ %{$status->[2]},
Branch: 1 branch
BranchTrueFalseTotal
$cache and $cache->put($certid, {%{$status->[2];}, "expire", time + 120, "soft_error", $status->[1]}) 0 0 0
2938 expire => time()+120,
2939 soft_error => $status->[1],
2940 });
2941 } else {
2942 0 push @results,($hard_error = [0,$status->[1]]);
2943 $cache && $cache->put($certid,{
2944 0 ▶ %{$status->[2]},
Branch: 1 branch
BranchTrueFalseTotal
$cache and $cache->put($certid, {%{$status->[2];}, "hard_error", $status->[1]}) 0 0 0
2945 hard_error => $status->[1],
2946 });
2947 }
2948 }
2949 }
2950 # return result of lead certificate, this should be in chain[0] and
2951 # thus result[0], but we better check. But if we had any hard_error
2952 # return this instead
2953 0 ▶ if ($hard_error) {
Branch: 2 branches
BranchTrueFalseTotal
if ($hard_error) { } 0 0 0
elsif (@results and $chain[0] == $iossl->peer_certificate) { } 0 0 0
2954 0 ${*$iossl}{_SSL_ocsp_verify} = $hard_error;
2955 ▶ } elsif (@results and $chain[0] == $iossl->peer_certificate) {
Condition0%0/3
@results and $chain[0] == $iossl->peer_certificate
!ll&&!rl&&r
000
MC/DC0%0/2
@results and $chain[0] == $iossl->peer_certificate
@results $chain[0] == $iossl->peer_certificate
Truth table0%0/3
A and B
A= @resultsB= $chain[0] == $iossl->peer_certificate
ABresult
0X0
100
111
2956 0 ${*$iossl}{_SSL_ocsp_verify} = $results[0];
2957 }
2958 0 return 1;
2959 150 };
2960 150 Net::SSLeay::CTX_set_tlsext_status_cb($_,$status_cb) for (values %ctx);
2961 }
2962  
2963 252 ▶ if ( my $cl = $arg_hash->{SSL_cipher_list} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $cl = $arg_hash->{"SSL_cipher_list"}) 252 0 252
2964 252 for (keys %ctx) {
2965 Net::SSLeay::CTX_set_cipher_list($ctx{$_}, ref($cl)
2966 ? $cl->{$_} || $cl->{''} || $DEFAULT_SSL_ARGS{SSL_cipher_list} || next
2967 266 ▶ : $cl
Branch: 2 branches
BranchTrueFalseTotal
&Net::SSLeay::CTX_set_cipher_list($ctx{$_}, scalar(ref $cl ? $cl->{$_} || $cl->{""} || $DEFAULT_SSL_ARGS{"SSL_cipher_list"} || (next) : $cl)) or return "IO::Socket::SSL"->error("Failed to set SSL cipher list") 0 266 266
ref $cl ? : 0 266 266
Condition0%0/8
$cl->{$_} or $cl->{""} or $DEFAULT_SSL_ARGS{"SSL_cipher_list"} or next
l!l
00
$cl->{$_} or $cl->{""} or $DEFAULT_SSL_ARGS{"SSL_cipher_list"}
l!l&&r!l&&!r
000
$cl->{$_} or $cl->{""}
l!l&&r!l&&!r
000
MC/DC0%0/3
$cl->{$_} or $cl->{""} or $DEFAULT_SSL_ARGS{"SSL_cipher_list"} or next
$cl->{$_} $cl->{""} $DEFAULT_SSL_ARGS{"SSL_cipher_list"}
Truth table0%0/4
A or B or C
A= $cl->{$_}B= $cl->{""}C= $DEFAULT_SSL_ARGS{"SSL_cipher_list"}
ABCresult
1XX1
01X1
0011
0000
2968 ) || return IO::Socket::SSL->error("Failed to set SSL cipher list");
2969 }
2970 }
2971 252 ▶ if ( my $cl = $arg_hash->{SSL_ciphersuites} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $cl = $arg_hash->{"SSL_ciphersuites"}) 0 252 252
2972 0 ▶ return IO::Socket::SSL->error("no support for SSL_ciphersuites in Net::SSLeay")
Branch: 1 branch
BranchTrueFalseTotal
unless $can_ciphersuites 0 0 0
2973 if ! $can_ciphersuites;
2974 0 for (keys %ctx) {
2975 Net::SSLeay::CTX_set_ciphersuites($ctx{$_}, ref($cl)
2976 ? $cl->{$_} || $cl->{''} || $DEFAULT_SSL_ARGS{SSL_cipher_list} || next
2977 0 ▶ : $cl
Branch: 2 branches
BranchTrueFalseTotal
&Net::SSLeay::CTX_set_ciphersuites($ctx{$_}, scalar(ref $cl ? $cl->{$_} || $cl->{""} || $DEFAULT_SSL_ARGS{"SSL_cipher_list"} || (next) : $cl)) or return "IO::Socket::SSL"->error("Failed to set SSL cipher list") 0 0 0
ref $cl ? : 0 0 0
Condition0%0/8
$cl->{$_} or $cl->{""} or $DEFAULT_SSL_ARGS{"SSL_cipher_list"} or next
l!l
00
$cl->{$_} or $cl->{""} or $DEFAULT_SSL_ARGS{"SSL_cipher_list"}
l!l&&r!l&&!r
000
$cl->{$_} or $cl->{""}
l!l&&r!l&&!r
000
MC/DC0%0/3
$cl->{$_} or $cl->{""} or $DEFAULT_SSL_ARGS{"SSL_cipher_list"} or next
$cl->{$_} $cl->{""} $DEFAULT_SSL_ARGS{"SSL_cipher_list"}
Truth table0%0/4
A or B or C
A= $cl->{$_}B= $cl->{""}C= $DEFAULT_SSL_ARGS{"SSL_cipher_list"}
ABCresult
1XX1
01X1
0011
0000
2978 ) || return IO::Socket::SSL->error("Failed to set SSL cipher list");
2979 }
2980 }
2981  
2982 # Main context is default context or any other if no default context.
2983 252 ▶ my $ctx = $ctx{''} || (values %ctx)[0];
Condition33%1/3
$ctx{''} || (values %ctx)[0]
l!l&&r!l&&!r
25200
MC/DC0%0/2
$ctx{''} || (values %ctx)[0]
$ctx{''} (values %ctx)[0]
Truth table33%1/3
A || B
A= $ctx{''}B= (values %ctx)[0]
ABresult
1X1
011
000
2984 252 ▶ if (keys(%ctx) > 1 || ! exists $ctx{''}) {
Branch: 1 branch
BranchTrueFalseTotal
if (keys %ctx > 1 or not exists $ctx{""}) 6 246 252
Condition66%2/3
keys %ctx > 1 or not exists $ctx{""}
l!l&&r!l&&!r
60246
MC/DC50%1/2
keys %ctx > 1 or not exists $ctx{""}
keys %ctx > 1 not exists $ctx{""}
Truth table66%2/3
A or not(B)
A= keys %ctx > 1B= not exists $ctx{""}
ABresult
1X1
011
000
2985 6 ▶ $can_server_sni or return IO::Socket::SSL->_internal_error(
Branch: 1 branch
BranchTrueFalseTotal
$can_server_sni or return "IO::Socket::SSL"->_internal_error("Server side SNI not supported for this openssl/Net::SSLeay", 9) 0 6 6
2986 "Server side SNI not supported for this openssl/Net::SSLeay",9);
2987  
2988 Net::SSLeay::CTX_set_tlsext_servername_callback($ctx, sub {
2989 19 ▶ my $ssl = shift;
Subroutine __ANON__: called CC=7 SCAR=21.5
2990 19 my $host = Net::SSLeay::get_servername($ssl);
2991 19 ▶ $host = '' if ! defined $host;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $host 4 15 19
2992 19 ▶ my $snictx = $ctx{lc($host)} || $ctx{''} or do {
Branch: 1 branch
BranchTrueFalseTotal
my $snictx = $ctx{lc $host} || $ctx{""} or do { $IO::Socket::SSL::DEBUG > 1 and DEBUG("cannot get context from servername '${host}'"); return 2 } 0 19 19
Condition66%2/3
$ctx{lc $host} || $ctx{''}
l!l&&r!l&&!r
1360
MC/DC0%0/2
$ctx{lc $host} || $ctx{''}
$ctx{lc $host} $ctx{''}
Truth table66%2/3
A || B
A= $ctx{lc $host}B= $ctx{''}
ABresult
1X1
011
000
2993 0 ▶ $DEBUG>1 and DEBUG(
Branch: 1 branch
BranchTrueFalseTotal
$IO::Socket::SSL::DEBUG > 1 and DEBUG("cannot get context from servername '${host}'") 0 0 0
2994 "cannot get context from servername '$host'");
2995 0 return 2; # SSL_TLSEXT_ERR_ALERT_FATAL
2996 };
2997 19 ▶ $DEBUG>1 and DEBUG("set context from servername $host");
Branch: 1 branch
BranchTrueFalseTotal
$IO::Socket::SSL::DEBUG > 1 and DEBUG("set context from servername $host") 0 19 19
2998 19 ▶ Net::SSLeay::set_SSL_CTX($ssl,$snictx) if $snictx != $ctx;
Branch: 1 branch
BranchTrueFalseTotal
if $snictx != $ctx 9 10 19
2999 19 return 0; # SSL_TLSEXT_ERR_OK
3000 6 });
3001 }
3002  
3003 252 ▶ if ( my $cb = $arg_hash->{SSL_create_ctx_callback} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $cb = $arg_hash->{"SSL_create_ctx_callback"}) 0 252 252
3004 0 $cb->($_) for values (%ctx);
3005 }
3006  
3007 252 $self->{context} = $ctx;
3008 252 $self->{verify_mode} = $arg_hash->{SSL_verify_mode};
3009 $self->{ocsp_mode} =
3010 defined($arg_hash->{SSL_ocsp_mode}) ? $arg_hash->{SSL_ocsp_mode} :
3011 252 ▶ $self->{verify_mode} ? IO::Socket::SSL::SSL_OCSP_TRY_STAPLE() :
Branch: 2 branches
BranchTrueFalseTotal
defined $arg_hash->{'SSL_ocsp_mode'} ? : 1 251 252
$self->{'verify_mode'} ? : 88 163 251
3012 0;
3013 252 ▶ $DEBUG>=3 && DEBUG( "new ctx $ctx" );
Branch: 1 branch
BranchTrueFalseTotal
$IO::Socket::SSL::DEBUG >= 3 and DEBUG("new ctx $ctx") 0 252 252
3014  
3015 252 ▶ if ( my $cache = $arg_hash->{SSL_session_cache} ) {
Branch: 2 branches
BranchTrueFalseTotal
if (my $cache = $arg_hash->{'SSL_session_cache'}) { } 0 252 252
elsif (my $size = $arg_hash->{'SSL_session_cache_size'}) { } 3 249 252
3016 # use predefined cache
3017 0 $self->{session_cache} = $cache
3018 } elsif ( my $size = $arg_hash->{SSL_session_cache_size}) {
3019 3 $self->{session_cache} = IO::Socket::SSL::Session_Cache->new( $size );
3020 }
3021  
3022  
3023 252 ▶ if ($self->{session_cache} and %sess_cb) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"session_cache"} and %sess_cb) 3 249 252
Condition66%2/3
$self->{"session_cache"} and %sess_cb
!ll&&!rl&&r
24903
MC/DC50%1/2
$self->{"session_cache"} and %sess_cb
$self->{"session_cache"} %sess_cb
Truth table66%2/3
A and B
A= $self->{"session_cache"}B= %sess_cb
ABresult
0X0
100
111
3024 3 Net::SSLeay::CTX_set_session_cache_mode($ctx,
3025 Net::SSLeay::SESS_CACHE_CLIENT());
3026 3 my $cache = $self->{session_cache};
3027 $sess_cb{new}($ctx, sub {
3028 15 ▶ my ($ssl,$session) = @_;
Subroutine __ANON__: called CC=4 SCAR=16.5
3029 15 ▶ my $self = ($SSL_OBJECT{$ssl} || do {
Condition33%1/3
$SSL_OBJECT{$ssl} || do { warn "callback session new: no known SSL object for $ssl"; return }
l!l&&r!l&&!r
1500
MC/DC0%0/2
$SSL_OBJECT{$ssl} || do { warn "callback session new: no known SSL object for $ssl"; return }
$SSL_OBJECT{$ssl} do { warn "callback session new: no known SSL object for $ssl"; return }
Truth table33%1/3
A || B
A= $SSL_OBJECT{$ssl}B= do { warn "callback session new: no known SSL object for $ssl"; return }
ABresult
1X1
011
000
3030 0 warn "callback session new: no known SSL object for $ssl";
3031 0 return;
3032 })->[0];
3033 15 my $args = ${*$self}{_SSL_arguments};
3034 15 ▶ my $key = $args->{SSL_session_key} or do {
Branch: 1 branch
BranchTrueFalseTotal
my $key = $args->{"SSL_session_key"} or do { warn "callback session new: no known SSL_session_key for $ssl"; return } 0 15 15
3035 0 warn "callback session new: no known SSL_session_key for $ssl";
3036 0 return;
3037 };
3038 15 ▶ $DEBUG>=3 && DEBUG("callback session new <$key> $session");
Branch: 1 branch
BranchTrueFalseTotal
$IO::Socket::SSL::DEBUG >= 3 and DEBUG("callback session new <$key> $session") 0 15 15
3039 15 Net::SSLeay::SESSION_up_ref($session);
3040 15 $cache->add_session($key,$session);
3041 3 });
3042 $sess_cb{remove}($ctx, sub {
3043 12 ▶ my ($ctx,$session) = @_;
Subroutine __ANON__: called CC=2 SCAR=7.1
3044 12 ▶ $DEBUG>=3 && DEBUG("callback session remove $session");
Branch: 1 branch
BranchTrueFalseTotal
$IO::Socket::SSL::DEBUG >= 3 and DEBUG("callback session remove $session") 0 12 12
3045 12 $cache->del_session(undef,$session);
3046 3 });
3047 }
3048  
3049 252 return $self;
3050 }
3051  
3052  
3053 sub has_session_cache {
3054 0 ▶ return defined shift->{session_cache};
Subroutine has_session_cache: not called CC=1 SCAR=6.9
3055 }
3056  
3057  
3058 0 ▶sub CLONE { %CTX_CREATED_IN_THIS_THREAD = (); }
Subroutine CLONE: not called CC=1 SCAR=6.9
3059 sub DESTROY {
3060 254 ▶ my $self = shift;
Subroutine DESTROY: called CC=10 SCAR=26.2
3061 254 ▶ if ( my $ctx = $self->{context} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $ctx = $self->{"context"}) 250 4 254
3062 250 ▶ $DEBUG>=3 && DEBUG("free ctx $ctx open=".join( " ",keys %CTX_CREATED_IN_THIS_THREAD ));
Branch: 1 branch
BranchTrueFalseTotal
$IO::Socket::SSL::DEBUG >= 3 and DEBUG("free ctx $ctx open=" . join(" ", keys %CTX_CREATED_IN_THIS_THREAD)) 0 250 250
3063 250 ▶ if (!$use_threads or delete $CTX_CREATED_IN_THIS_THREAD{$ctx} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $use_threads or delete $CTX_CREATED_IN_THIS_THREAD{$ctx}) 250 0 250
Condition33%1/3
not $use_threads or delete $CTX_CREATED_IN_THIS_THREAD{$ctx}
l!l&&r!l&&!r
25000
MC/DC0%0/2
not $use_threads or delete $CTX_CREATED_IN_THIS_THREAD{$ctx}
not $use_threads delete $CTX_CREATED_IN_THIS_THREAD{$ctx}
Truth table33%1/3
not(A) or B
A= not $use_threadsB= delete $CTX_CREATED_IN_THIS_THREAD{$ctx}
ABresult
1X1
011
000
3064 # remove any verify callback for this context
3065 250 ▶ if ( $self->{verify_mode}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"verify_mode"}) 88 162 250
3066 88 ▶ $DEBUG>=3 && DEBUG("free ctx $ctx callback" );
Branch: 1 branch
BranchTrueFalseTotal
$IO::Socket::SSL::DEBUG >= 3 and DEBUG("free ctx $ctx callback") 0 88 88
3067 88 Net::SSLeay::CTX_set_verify($ctx, 0,undef);
3068 }
3069 250 ▶ if ( $self->{ocsp_error_ref}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"ocsp_error_ref"}) 0 250 250
3070 0 ▶ $DEBUG>=3 && DEBUG("free ctx $ctx tlsext_status_cb" );
Branch: 1 branch
BranchTrueFalseTotal
$IO::Socket::SSL::DEBUG >= 3 and DEBUG("free ctx $ctx tlsext_status_cb") 0 0 0
3071 0 Net::SSLeay::CTX_set_tlsext_status_cb($ctx,undef);
3072 }
3073 250 ▶ $DEBUG>=3 && DEBUG("OK free ctx $ctx" );
Branch: 1 branch
BranchTrueFalseTotal
$IO::Socket::SSL::DEBUG >= 3 and DEBUG("OK free ctx $ctx") 0 250 250
3074 250 Net::SSLeay::CTX_free($ctx);
3075 }
3076 }
3077 254 delete(@{$self}{'context','session_cache'});
3078 }
3079  
3080 package IO::Socket::SSL::Session_Cache;
3081 82 *DEBUG = *IO::Socket::SSL::DEBUG;
3082 use constant {
3083 82 SESSION => 0,
3084 KEY => 1,
3085 GNEXT => 2,
3086 GPREV => 3,
3087 SNEXT => 4,
3088 SPREV => 5,
3089 82 ▶};
Subroutine BEGIN: called CC=1 SCAR=0.0
3090  
3091 sub new {
3092 3 ▶ my ($class, $size) = @_;
Subroutine new: called CC=2 SCAR=7.1
3093 3 ▶ $size>0 or return;
Branch: 1 branch
BranchTrueFalseTotal
$size > 0 or return 0 3 3
3094 3 return bless {
3095 room => $size,
3096 ghead => undef,
3097 shead => {},
3098 }, $class;
3099 }
3100  
3101 sub add_session {
3102 19 ▶ my ($self, $key, $session) = @_;
Subroutine add_session: called CC=2 SCAR=7.0
3103  
3104 # create new
3105 19 my $v = [];
3106 19 $v->[SESSION] = $session;
3107 19 $v->[KEY] = $key;
3108 19 ▶ $DEBUG>=3 && DEBUG("add_session($key,$session)");
Branch: 1 branch
BranchTrueFalseTotal
$IO::Socket::SSL::DEBUG >= 3 and DEBUG("add_session($key,$session)") 0 19 19
3109 19 _add_entry($self,$v);
3110 }
3111  
3112 sub replace_session {
3113 0 ▶ my ($self, $key, $session) = @_;
Subroutine replace_session: not called CC=1 SCAR=6.9
3114 0 $self->del_session($key);
3115 0 $self->add_session($key, $session);
3116 }
3117  
3118 sub del_session {
3119 13 ▶ my ($self, $key, $session) = @_;
Subroutine del_session: called CC=12 SCAR=26.0
3120 my ($head,$inext) = $key
3121 13 ▶ ? ($self->{shead}{$key},SNEXT) : ($self->{ghead},GNEXT);
Branch: 1 branch
BranchTrueFalseTotal
$key ? : 1 12 13
3122 13 my $v = $head;
3123 13 my @del;
3124 13 ▶ while ($v) {
Branch: 1 branch
BranchTrueFalseTotal
if ($v) 18 0 18
3125 18 ▶ if (!$session) {
Branch: 2 branches
BranchTrueFalseTotal
if (not $session) { } 3 15 18
elsif ($v->[0] == $session) { } 12 3 15
3126 3 push @del,$v
3127 } elsif ($v->[SESSION] == $session) {
3128 12 push @del, $v;
3129 12 last;
3130 }
3131 6 $v = $v->[$inext];
3132 6 ▶ last if $v == $head;
Branch: 1 branch
BranchTrueFalseTotal
if $v == $head 1 5 6
3133 }
3134 13 ▶ $DEBUG>=3 && DEBUG("del_session("
Branch: 3 branches
BranchTrueFalseTotal
$IO::Socket::SSL::DEBUG >= 3 and DEBUG('del_session(' . ($key ? $key : "undef") . ($session ? ",$session) -> " : ") -> ") . (~~@del || "none")) 0 13 13
$key ? : 0 0 0
$session ? : 0 0 0
Condition0%0/2
~~@del || 'none'
l!l
00
MC/DC0%0/1
~~@del || 'none'
~~@del
Truth table0%0/2
A
A= ~~@del
Aresult
11
00
3135 . ($key ? $key : "undef")
3136 . ($session ? ",$session) -> " : ") -> ")
3137 . (~~@del || 'none'));
3138 13 for (@del) {
3139 15 _del_entry($self,$_);
3140 15 ▶ Net::SSLeay::SESSION_free($_->[SESSION]) if $_->[SESSION];
Branch: 1 branch
BranchTrueFalseTotal
if $_->[0] 12 3 15
3141 15 @$_ = ();
3142 }
3143 13 return ~~@del;
3144 }
3145  
3146 sub get_session {
3147 16 ▶ my ($self, $key, $session) = @_;
Subroutine get_session: called CC=11 SCAR=27.6
3148 16 my $v = $self->{shead}{$key};
3149 16 ▶ if ($session) {
Branch: 1 branch
BranchTrueFalseTotal
if ($session) 3 13 16
3150 3 my $shead = $v;
3151 3 ▶ while ($v) {
Branch: 1 branch
BranchTrueFalseTotal
if ($v) 3 0 3
3152 3 ▶ $DEBUG>=3 && DEBUG("check $session - $v->[SESSION]");
Branch: 1 branch
BranchTrueFalseTotal
$IO::Socket::SSL::DEBUG >= 3 and DEBUG("check $session - $v->[0]") 0 3 3
3153 3 ▶ last if $v->[SESSION] == $session;
Branch: 1 branch
BranchTrueFalseTotal
if $v->[0] == $session 3 0 3
3154 0 $v = $v->[SNEXT];
3155 0 ▶ $v = undef if $v == $shead; # session not found
Branch: 1 branch
BranchTrueFalseTotal
if $v == $shead 0 0 0
3156 }
3157 }
3158 16 ▶ if ($v) {
Branch: 1 branch
BranchTrueFalseTotal
if ($v) 11 5 16
3159 11 _del_entry($self, $v); # remove
3160 11 _add_entry($self, $v); # and add back on top
3161 }
3162 16 ▶ $DEBUG>=3 && DEBUG("get_session($key"
Branch: 3 branches
BranchTrueFalseTotal
$IO::Socket::SSL::DEBUG >= 3 and DEBUG("get_session($key" . ($session ? ",$session) -> " : ") -> ") . ($v ? $v->[0] : "none")) 0 16 16
$session ? : 0 0 0
$v ? : 0 0 0
3163 . ( $session ? ",$session) -> " : ") -> ")
3164 . ($v? $v->[SESSION]:"none"));
3165 16 ▶ return $v && $v->[SESSION];
Condition100%3/3
$v && $v->[0]
!ll&&!rl&&r
5110
MC/DC50%1/2
$v && $v->[0]
$v $v->[0]
Truth table66%2/3
A && B
A= $vB= $v->[0]
ABresult
0X0
100
111
3166 }
3167  
3168 sub _add_entry {
3169 30 ▶ my ($self,$v) = @_;
Subroutine _add_entry: called CC=5 SCAR=16.1
3170 30 for(
3171 [ SNEXT, SPREV, \$self->{shead}{$v->[KEY]} ],
3172 [ GNEXT, GPREV, \$self->{ghead} ],
3173 ) {
3174 60 my ($inext,$iprev,$rhead) = @$_;
3175 60 ▶ if ($$rhead) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$rhead) { } 46 14 60
3176 46 $v->[$inext] = $$rhead;
3177 46 $v->[$iprev] = ${$rhead}->[$iprev];
3178 46 ${$rhead}->[$iprev][$inext] = $v;
3179 46 ${$rhead}->[$iprev] = $v;
3180 } else {
3181 14 $v->[$inext] = $v->[$iprev] = $v;
3182 }
3183 60 $$rhead = $v;
3184 }
3185  
3186 30 $self->{room}--;
3187  
3188 # drop old entries if necessary
3189 30 ▶ if ($self->{room}<0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"room"} < 0) 1 29 30
3190 1 my $l = $self->{ghead}[GPREV];
3191 1 _del_entry($self,$l);
3192 1 ▶ Net::SSLeay::SESSION_free($l->[SESSION]) if $l->[SESSION];
Branch: 1 branch
BranchTrueFalseTotal
if $l->[0] 0 1 1
3193 1 @$l = ();
3194 }
3195 }
3196  
3197 sub _del_entry {
3198 27 ▶ my ($self,$v) = @_;
Subroutine _del_entry: called CC=6 SCAR=17.9
3199 27 for(
3200 [ SNEXT, SPREV, \$self->{shead}{$v->[KEY]} ],
3201 [ GNEXT, GPREV, \$self->{ghead} ],
3202 ) {
3203 54 my ($inext,$iprev,$rhead) = @$_;
3204 54 ▶ $$rhead or return;
Branch: 1 branch
BranchTrueFalseTotal
$$rhead or return 0 54 54
3205 54 $v->[$inext][$iprev] = $v->[$iprev];
3206 54 $v->[$iprev][$inext] = $v->[$inext];
3207 54 ▶ if ($v != $$rhead) {
Branch: 2 branches
BranchTrueFalseTotal
if ($v != $$rhead) { } 11 43 54
elsif ($v->[$inext] == $v) { } 10 33 43
3208 # not removed from top of list
3209 } elsif ($v->[$inext] == $v) {
3210 # was only element on list, drop list
3211 10 ▶ if ($inext == SNEXT) {
Branch: 1 branch
BranchTrueFalseTotal
if ($inext == 4) { } 6 4 10
3212 6 delete $self->{shead}{$v->[KEY]};
3213 } else {
3214 4 $$rhead = undef;
3215 }
3216 } else {
3217 # was top element, keep others
3218 33 $$rhead = $v->[$inext];
3219 }
3220 }
3221 27 $self->{room}++;
3222 }
3223  
3224 sub _dump {
3225 0 ▶ my $self = shift;
Subroutine _dump: not called CC=9 SCAR=45.0
3226  
3227 0 my %v2i;
3228 0 my $v = $self->{ghead};
3229 0 ▶ while ($v) {
Branch: 1 branch
BranchTrueFalseTotal
if ($v) 0 0 0
3230 0 ▶ exists $v2i{$v} and die;
Branch: 1 branch
BranchTrueFalseTotal
exists $v2i{$v} and die 0 0 0
3231 0 $v2i{$v} = int(keys %v2i);
3232 0 $v = $v->[GNEXT];
3233 0 ▶ last if $v == $self->{ghead};
Branch: 1 branch
BranchTrueFalseTotal
if $v == $self->{"ghead"} 0 0 0
3234 }
3235  
3236 0 my $out = "room: $self->{room}\nghead:\n";
3237 0 $v = $self->{ghead};
3238 0 ▶ while ($v) {
Branch: 1 branch
BranchTrueFalseTotal
if ($v) 0 0 0
3239 $out .= sprintf(" - [%d] <%d,%d> '%s' <%s>\n",
3240 0 $v2i{$v}, $v2i{$v->[GPREV]}, $v2i{$v->[GNEXT]},
3241 $v->[KEY], $v->[SESSION]);
3242 0 $v = $v->[GNEXT];
3243 0 ▶ last if $v == $self->{ghead};
Branch: 1 branch
BranchTrueFalseTotal
if $v == $self->{"ghead"} 0 0 0
3244 }
3245 0 $out .= "shead:\n";
3246 0 for my $key (sort keys %{$self->{shead}}) {
3247 0 $out .= " - '$key'\n";
3248 0 my $shead = $self->{shead}{$key};
3249 0 my $v = $shead;
3250 0 ▶ while ($v) {
Branch: 1 branch
BranchTrueFalseTotal
if ($v) 0 0 0
3251 $out .= sprintf(" - [%d] <%d,%d> '%s' <%s>\n",
3252 0 $v2i{$v}, $v2i{$v->[SPREV]}, $v2i{$v->[SNEXT]},
3253 $v->[KEY], $v->[SESSION]);
3254 0 $v = $v->[SNEXT];
3255 0 ▶ last if $v == $shead;
Branch: 1 branch
BranchTrueFalseTotal
if $v == $shead 0 0 0
3256 }
3257 }
3258 0 return $out;
3259 }
3260  
3261 sub DESTROY {
3262 2 ▶ my $self = shift;
Subroutine DESTROY: called CC=3 SCAR=15.7
3263 2 delete $self->{shead};
3264 2 my $v = delete $self->{ghead};
3265 2 ▶ while ($v) {
Branch: 1 branch
BranchTrueFalseTotal
if ($v) 0 2 2
3266 0 ▶ Net::SSLeay::SESSION_free($v->[SESSION]) if $v->[SESSION];
Branch: 1 branch
BranchTrueFalseTotal
if $v->[0] 0 0 0
3267 0 my $next = $v->[GNEXT];
3268 0 @$v = ();
3269 0 $v = $next;
3270 }
3271 }
3272  
3273  
3274  
3275 package IO::Socket::SSL::OCSP_Cache;
3276  
3277 sub new {
3278 0 ▶ my ($class,$size) = @_;
Subroutine new: not called CC=2 SCAR=17.9
3279 0 ▶ return bless {
Condition0%0/2
$size || 100
l!l
00
MC/DC0%0/1
$size || 100
$size
Truth table0%0/2
A
A= $size
Aresult
11
00
3280 '' => { _lru => 0, size => $size || 100 }
3281 },$class;
3282 }
3283 sub get {
3284 0 ▶ my ($self,$id) = @_;
Subroutine get: not called CC=6 SCAR=37.4
3285 0 ▶ my $e = $self->{$id} or return;
Branch: 1 branch
BranchTrueFalseTotal
my $e = $self->{$id} or return 0 0 0
3286 0 $e->{_lru} = $self->{''}{_lru}++;
3287 0 ▶ if ( $e->{expire} && time()<$e->{expire}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($e->{"expire"} and time < $e->{"expire"}) 0 0 0
Condition0%0/3
$e->{"expire"} and time < $e->{"expire"}
!ll&&!rl&&r
000
MC/DC0%0/2
$e->{"expire"} and time < $e->{"expire"}
$e->{"expire"} time < $e->{"expire"}
Truth table0%0/3
A and B
A= $e->{"expire"}B= time < $e->{"expire"}
ABresult
0X0
100
111
3288 0 delete $self->{$id};
3289 0 return;
3290 }
3291 0 ▶ if ( $e->{nextUpdate} && time()<$e->{nextUpdate} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($e->{"nextUpdate"} and time < $e->{"nextUpdate"}) 0 0 0
Condition0%0/3
$e->{"nextUpdate"} and time < $e->{"nextUpdate"}
!ll&&!rl&&r
000
MC/DC0%0/2
$e->{"nextUpdate"} and time < $e->{"nextUpdate"}
$e->{"nextUpdate"} time < $e->{"nextUpdate"}
Truth table0%0/3
A and B
A= $e->{"nextUpdate"}B= time < $e->{"nextUpdate"}
ABresult
0X0
100
111
3292 0 delete $self->{$id};
3293 0 return;
3294 }
3295 0 return $e;
3296 }
3297  
3298 sub put {
3299 0 ▶ my ($self,$id,$e) = @_;
Subroutine put: not called CC=2 SCAR=17.9
3300 0 $self->{$id} = $e;
3301 0 $e->{_lru} = $self->{''}{_lru}++;
3302 0 my $del = keys(%$self) - $self->{''}{size};
3303 0 ▶ if ($del>0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($del > 0) 0 0 0
3304 0 my @k = sort { $self->{$a}{_lru} <=> $self->{$b}{_lru} } keys %$self;
3305 0 delete @{$self}{ splice(@k,0,$del) };
3306 }
3307 0 return $e;
3308 }
3309  
3310 package IO::Socket::SSL::OCSP_Resolver;
3311 82 *DEBUG = *IO::Socket::SSL::DEBUG;
3312  
3313 # create a new resolver
3314 # $ssl - the ssl object
3315 # $cache - OCSP_Cache object (put,get)
3316 # $failhard - flag if we should fail hard on OCSP problems
3317 # $certs - list of certs to verify
3318 sub new {
3319 0 ▶ my ($class,$ssl,$cache,$failhard,$certs) = @_;
Subroutine new: not called CC=13 SCAR=52.0
3320 0 my (%todo,$done,$hard_error,@soft_error);
3321 0 for my $cert (@$certs) {
3322 # skip entries which have no OCSP uri or where we cannot get a certid
3323 # (e.g. self-signed or where we don't have the issuer)
3324 0 my $subj = Net::SSLeay::X509_NAME_oneline(Net::SSLeay::X509_get_subject_name($cert));
3325 0 ▶ my $uri = Net::SSLeay::P_X509_get_ocsp_uri($cert) or do {
Branch: 1 branch
BranchTrueFalseTotal
my $uri = &Net::SSLeay::P_X509_get_ocsp_uri($cert) or do { $IO::Socket::SSL::DEBUG > 2 and DEBUG("no URI for certificate $subj"); push @soft_error, "no ocsp_uri for $subj"; next } 0 0 0
3326 0 ▶ $DEBUG>2 && DEBUG("no URI for certificate $subj");
Branch: 1 branch
BranchTrueFalseTotal
$IO::Socket::SSL::DEBUG > 2 and DEBUG("no URI for certificate $subj") 0 0 0
3327 0 push @soft_error,"no ocsp_uri for $subj";
3328 0 next;
3329 };
3330 0 ▶ my $certid = eval { Net::SSLeay::OCSP_cert2ids($ssl,$cert) } or do {
Branch: 1 branch
BranchTrueFalseTotal
my $certid = eval { do { &Net::SSLeay::OCSP_cert2ids($ssl, $cert) } } or do { $IO::Socket::SSL::DEBUG > 2 and DEBUG("no OCSP_CERTID for certificate ${subj}: $@"); push @soft_error, "no certid for ${subj}: $@"; next } 0 0 0
3331 0 ▶ $DEBUG>2 && DEBUG("no OCSP_CERTID for certificate $subj: $@");
Branch: 1 branch
BranchTrueFalseTotal
$IO::Socket::SSL::DEBUG > 2 and DEBUG("no OCSP_CERTID for certificate ${subj}: $@") 0 0 0
3332 0 push @soft_error,"no certid for $subj: $@";
3333 0 next;
3334 };
3335 0 ▶ if (!($done = $cache->get($certid))) {
Branch: 3 branches
BranchTrueFalseTotal
if (not $done = $cache->get($certid)) { } 0 0 0
elsif ($done->{'hard_error'}) { } 0 0 0
elsif ($done->{'soft_error'}) { } 0 0 0
3336 0 push @{ $todo{$uri}{ids} }, $certid;
3337 0 push @{ $todo{$uri}{subj} }, $subj;
3338 } elsif ( $done->{hard_error} ) {
3339 # one error is enough to fail validation
3340 0 $hard_error = $done->{hard_error};
3341 0 %todo = ();
3342 0 last;
3343 } elsif ( $done->{soft_error} ) {
3344 0 push @soft_error,$done->{soft_error};
3345 }
3346 }
3347 0 ▶ while ( my($uri,$v) = each %todo) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %todo) 0 0 0
3348 0 my $ids = $v->{ids};
3349 0 $v->{req} = Net::SSLeay::i2d_OCSP_REQUEST(
3350 Net::SSLeay::OCSP_ids2req(@$ids));
3351 }
3352 0 ▶ $hard_error ||= '' if ! %todo;
Branch: 1 branch
BranchTrueFalseTotal
unless %todo 0 0 0
Condition0%0/2
$hard_error ||= ""
l!l
00
MC/DC0%0/1
$hard_error ||= ""
$hard_error
Truth table0%0/2
A
A= $hard_error
Aresult
11
00
3353 0 ▶ return bless {
Branch: 1 branch
BranchTrueFalseTotal
@soft_error ? : 0 0 0
3354 ssl => $ssl,
3355 cache => $cache,
3356 failhard => $failhard,
3357 hard_error => $hard_error,
3358 soft_error => @soft_error ? join("; ",@soft_error) : undef,
3359 todo => \%todo,
3360 },$class;
3361 }
3362  
3363 # return current result, e.g. '' for no error, else error
3364 # if undef we have no final result yet
3365 0 ▶sub hard_error { return shift->{hard_error} }
Subroutine hard_error: not called CC=1 SCAR=6.9
3366 0 ▶sub soft_error { return shift->{soft_error} }
Subroutine soft_error: not called CC=1 SCAR=6.9
3367  
3368 # return hash with uri => ocsp_request_data for open requests
3369 sub requests {
3370 0 ▶ my $todo = shift()->{todo};
Subroutine requests: not called CC=1 SCAR=6.9
3371 0 return map { ($_,$todo->{$_}{req}) } keys %$todo;
3372 }
3373  
3374 # add new response
3375 sub add_response {
3376 0 ▶ my ($self,$uri,$resp) = @_;
Subroutine add_response: not called CC=28 SCAR=67.0
3377 0 my $todo = delete $self->{todo}{$uri};
3378 0 ▶ return $self->{error} if ! $todo || $self->{error};
Branch: 1 branch
BranchTrueFalseTotal
if not $todo or $self->{"error"} 0 0 0
Condition0%0/3
not $todo or $self->{"error"}
l!l&&r!l&&!r
000
MC/DC0%0/2
not $todo or $self->{"error"}
not $todo $self->{"error"}
Truth table0%0/3
not(A) or B
A= not $todoB= $self->{"error"}
ABresult
1X1
011
000
3379  
3380 0 my ($req,@soft_error,@hard_error);
3381  
3382 # do we have a response
3383 0 ▶ if (!$resp) {
Branch: 5 branches
BranchTrueFalseTotal
if (not $resp) { } 0 0 0
elsif (not eval { do { $resp = &Net::SSLeay::d2i_OCSP_RESPONSE($resp) } }) { } 0 0 0
elsif ((my $status = &Net::SSLeay::OCSP_response_status($resp)) != Net::SSLeay::OCSP_RESPONSE_STATUS_SUCCESSFUL()) { } 0 0 0
elsif (not eval { do { $req = &Net::SSLeay::d2i_OCSP_REQUEST($todo->{'req'}); &Net::SSLeay::OCSP_response_verify($self->{'ssl'}, $resp, $req) } }) { } 0 0 0
elsif (my(@result) = &Net::SSLeay::OCSP_response_results($resp, @{$$todo{'ids'};})) { } 0 0 0
3384 @soft_error = "http request for OCSP failed; subject: ".
3385 0 join("; ",@{$todo->{subj}});
3386  
3387 # is it a valid OCSP_RESPONSE
3388 0 } elsif ( ! eval { $resp = Net::SSLeay::d2i_OCSP_RESPONSE($resp) }) {
3389 @soft_error = "invalid response (no OCSP_RESPONSE); subject: ".
3390 0 join("; ",@{$todo->{subj}});
3391 # hopefully short-time error
3392 $self->{cache}->put($_,{
3393 soft_error => "@soft_error",
3394 expire => time()+10,
3395 0 }) for (@{$todo->{ids}});
3396 # is the OCSP response status success
3397 } elsif (
3398 ( my $status = Net::SSLeay::OCSP_response_status($resp))
3399 != Net::SSLeay::OCSP_RESPONSE_STATUS_SUCCESSFUL()
3400 ){
3401 @soft_error = "OCSP response failed: ".
3402 Net::SSLeay::OCSP_response_status_str($status).
3403 0 "; subject: ".join("; ",@{$todo->{subj}});
3404 # hopefully short-time error
3405 $self->{cache}->put($_,{
3406 soft_error => "@soft_error",
3407 expire => time()+10,
3408 0 }) for (@{$todo->{ids}});
3409  
3410 # does nonce match the request and can the signature be verified
3411 } elsif ( ! eval {
3412 0 $req = Net::SSLeay::d2i_OCSP_REQUEST($todo->{req});
3413 0 Net::SSLeay::OCSP_response_verify($self->{ssl},$resp,$req);
3414 }) {
3415 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) { } 0 0 0
3416 0 @soft_error = $@
3417 } else {
3418 0 my @err;
3419 0 ▶ while ( my $err = Net::SSLeay::ERR_get_error()) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $err = &Net::SSLeay::ERR_get_error()) 0 0 0
3420 0 push @soft_error, Net::SSLeay::ERR_error_string($err);
3421 }
3422 @soft_error = 'failed to verify OCSP response; subject: '.
3423 0 ▶ join("; ",@{$todo->{subj}}) if ! @soft_error;
Branch: 1 branch
BranchTrueFalseTotal
unless @soft_error 0 0 0
3424 }
3425 # configuration problem or we don't know the signer
3426 $self->{cache}->put($_,{
3427 soft_error => "@soft_error",
3428 expire => time()+120,
3429 0 }) for (@{$todo->{ids}});
3430  
3431 # extract results from response
3432 } elsif ( my @result =
3433 0 Net::SSLeay::OCSP_response_results($resp,@{$todo->{ids}})) {
3434 0 my (@found,@miss);
3435 0 for my $rv (@result) {
3436 0 ▶ if ($rv->[2]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rv->[2]) { } 0 0 0
3437 0 push @found,$rv->[0];
3438 0 ▶ if (!$rv->[1]) {
Branch: 2 branches
BranchTrueFalseTotal
if (not $rv->[1]) { } 0 0 0
elsif ($rv->[2]{'statusType'} == Net::SSLeay::V_OCSP_CERTSTATUS_GOOD()) { } 0 0 0
3439 # no error
3440 0 $self->{cache}->put($rv->[0],$rv->[2]);
3441 } elsif ( $rv->[2]{statusType} ==
3442 Net::SSLeay::V_OCSP_CERTSTATUS_GOOD()) {
3443 # soft error, like response after nextUpdate
3444 push @soft_error,$rv->[1]."; subject: ".
3445 0 join("; ",@{$todo->{subj}});
3446 $self->{cache}->put($rv->[0],{
3447 0 %{$rv->[2]},
3448 soft_error => "@soft_error",
3449 expire => time()+120,
3450 });
3451 } else {
3452 # hard error
3453 0 $self->{cache}->put($rv->[0],$rv->[2]);
3454 push @hard_error, $rv->[1]."; subject: ".
3455 0 join("; ",@{$todo->{subj}});
3456 }
3457 } else {
3458 0 push @miss,$rv->[0];
3459 }
3460 }
3461 0 ▶ if (@miss && @found) {
Branch: 1 branch
BranchTrueFalseTotal
if (@miss and @found) 0 0 0
Condition0%0/3
@miss and @found
!ll&&!rl&&r
000
MC/DC0%0/2
@miss and @found
@miss @found
Truth table0%0/3
A and B
A= @missB= @found
ABresult
0X0
100
111
3462 # we sent multiple responses, but server answered only to one
3463 # try again
3464 0 $self->{todo}{$uri} = $todo;
3465 0 $todo->{ids} = \@miss;
3466 0 $todo->{req} = Net::SSLeay::i2d_OCSP_REQUEST(
3467 Net::SSLeay::OCSP_ids2req(@miss));
3468 0 ▶ $DEBUG>=2 && DEBUG("$uri just answered ".@found." of ".(@found+@miss)." requests");
Branch: 1 branch
BranchTrueFalseTotal
$IO::Socket::SSL::DEBUG >= 2 and DEBUG("$uri just answered " . @found . ' of ' . (@found + @miss) . ' requests') 0 0 0
3469 }
3470 } else {
3471 @soft_error = "no data in response; subject: ".
3472 0 join("; ",@{$todo->{subj}});
3473 # probably configuration problem
3474 $self->{cache}->put($_,{
3475 soft_error => "@soft_error",
3476 expire => time()+120,
3477 0 }) for (@{$todo->{ids}});
3478 }
3479  
3480 0 ▶ Net::SSLeay::OCSP_REQUEST_free($req) if $req;
Branch: 1 branch
BranchTrueFalseTotal
if $req 0 0 0
3481 0 ▶ if ($self->{failhard}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"failhard"}) 0 0 0
3482 0 push @hard_error,@soft_error;
3483 0 @soft_error = ();
3484 }
3485 0 ▶ if (@soft_error) {
Branch: 1 branch
BranchTrueFalseTotal
if (@soft_error) 0 0 0
3486 0 ▶ $self->{soft_error} .= "; " if $self->{soft_error};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"soft_error"} 0 0 0
3487 0 $self->{soft_error} .= "$uri: ".join('; ',@soft_error);
3488 }
3489 0 ▶ if (@hard_error) {
Branch: 2 branches
BranchTrueFalseTotal
if (@hard_error) { } 0 0 0
elsif (not %{$self->{'todo'};}) { } 0 0 0
3490 0 $self->{hard_error} = "$uri: ".join('; ',@hard_error);
3491 0 %{$self->{todo}} = ();
3492 0 } elsif ( ! %{$self->{todo}} ) {
3493 0 $self->{hard_error} = ''
3494 }
3495 0 return $self->{hard_error};
3496 }
3497  
3498 # make all necessary requests to get OCSP responses blocking
3499 sub resolve_blocking {
3500 0 ▶ my ($self,%args) = @_;
Subroutine resolve_blocking: not called CC=9 SCAR=45.0
3501 0 ▶ while ( my %todo = $self->requests ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(%todo) = $self->requests) 0 0 0
3502 0 ▶ eval { require HTTP::Tiny } or die "need HTTP::Tiny installed";
Branch: 1 branch
BranchTrueFalseTotal
eval { do { require HTTP::Tiny } } or die "need HTTP::Tiny installed" 0 0 0
3503 # OCSP responses have their own signature, so we don't need SSL verification
3504 0 my $ua = HTTP::Tiny->new(verify_SSL => 0,%args);
3505 0 ▶ while (my ($uri,$reqdata) = each %todo) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %todo) 0 0 0
3506 0 ▶ $DEBUG && DEBUG("sending OCSP request to $uri");
Branch: 1 branch
BranchTrueFalseTotal
$IO::Socket::SSL::DEBUG and DEBUG("sending OCSP request to $uri") 0 0 0
3507 0 my $resp = $ua->request('POST',$uri, {
3508 headers => { 'Content-type' => 'application/ocsp-request' },
3509 content => $reqdata
3510 });
3511 0 ▶ $DEBUG && DEBUG("got OCSP response from $uri code=$resp->{status}");
Branch: 1 branch
BranchTrueFalseTotal
$IO::Socket::SSL::DEBUG and DEBUG(qq[got OCSP response from $uri code=$resp->{"status"}]) 0 0 0
3512 defined ($self->add_response($uri,
3513 0 ▶ $resp->{success} && $resp->{content}))
Branch: 1 branch
BranchTrueFalseTotal
defined $self->add_response($uri, $resp->{"success"} && $resp->{"content"}) and last 0 0 0
Condition0%0/3
$resp->{'success'} && $resp->{'content'}
!ll&&!rl&&r
000
MC/DC0%0/2
$resp->{'success'} && $resp->{'content'}
$resp->{'success'} $resp->{'content'}
Truth table0%0/3
A && B
A= $resp->{'success'}B= $resp->{'content'}
ABresult
0X0
100
111
3514 && last;
3515 }
3516 }
3517 0 ▶ $DEBUG>=2 && DEBUG("no more open OCSP requests");
Branch: 1 branch
BranchTrueFalseTotal
$IO::Socket::SSL::DEBUG >= 2 and DEBUG("no more open OCSP requests") 0 0 0
3518 0 return $self->{hard_error};
3519 }
3520  
3521 package IO::Socket::SSL::Trace;
3522 82 *DEBUG = *IO::Socket::SSL::DEBUG;
3523  
3524 # Exhaustive list of constants we need for tracing
3525 82 ▶my %trace_constants = map { $_ => eval { Net::SSLeay->$_ } || -1 } qw(
Branch: 1 branch
BranchTrueFalseTotal
eval { do { "Net::SSLeay"->$_ } } or -1 984 2460 3444
3526 SSL2_VERSION
3527 SSL3_VERSION
3528 TLS1_VERSION
3529 TLS1_1_VERSION
3530 TLS1_2_VERSION
3531 TLS1_3_VERSION
3532 DTLS1_VERSION
3533 DTLS1_2_VERSION
3534 DTLS1_BAD_VER
3535 SSL3_RT_INNER_CONTENT_TYPE
3536 SSL3_RT_CHANGE_CIPHER_SPEC
3537 SSL3_RT_ALERT
3538 SSL3_RT_HEADER
3539 SSL3_RT_HANDSHAKE
3540 SSL3_RT_APPLICATION_DATA
3541 SSL2_MT_ERROR
3542 SSL2_MT_CLIENT_HELLO
3543 SSL2_MT_CLIENT_MASTER_KEY
3544 SSL2_MT_CLIENT_FINISHED
3545 SSL2_MT_SERVER_HELLO
3546 SSL2_MT_SERVER_VERIFY
3547 SSL2_MT_SERVER_FINISHED
3548 SSL2_MT_REQUEST_CERTIFICATE
3549 SSL2_MT_CLIENT_CERTIFICATE
3550 SSL3_MT_HELLO_REQUEST
3551 SSL3_MT_CLIENT_HELLO
3552 SSL3_MT_SERVER_HELLO
3553 SSL3_MT_NEWSESSION_TICKET
3554 SSL3_MT_CERTIFICATE
3555 SSL3_MT_SERVER_KEY_EXCHANGE
3556 SSL3_MT_CLIENT_KEY_EXCHANGE
3557 SSL3_MT_CERTIFICATE_REQUEST
3558 SSL3_MT_SERVER_DONE
3559 SSL3_MT_CERTIFICATE_VERIFY
3560 SSL3_MT_FINISHED
3561 SSL3_MT_CERTIFICATE_STATUS
3562 SSL3_MT_ENCRYPTED_EXTENSIONS
3563 SSL3_MT_SUPPLEMENTAL_DATA
3564 SSL3_MT_END_OF_EARLY_DATA
3565 SSL3_MT_KEY_UPDATE
3566 SSL3_MT_NEXT_PROTO
3567 SSL3_MT_MESSAGE_HASH
3568 );
3569  
3570 #
3571 # Major versions
3572 #
3573 82 $trace_constants{SSL2_VERSION_MAJOR} = $trace_constants{SSL2_VERSION} >> 8;
3574 82 $trace_constants{SSL3_VERSION_MAJOR} = $trace_constants{SSL3_VERSION} >> 8;
3575  
3576 #
3577 # Mapping between trace constant and version string
3578 #
3579 82 my %tc_ver2s;
3580 82 for (
3581 [ SSL2_VERSION => "SSLv2" ],
3582 [ SSL2_VERSION => "SSLv2" ],
3583 [ SSL3_VERSION => "SSLv3" ],
3584 [ TLS1_VERSION => "TLSv1.0" ],
3585 [ TLS1_1_VERSION => "TLSv1.1" ],
3586 [ TLS1_2_VERSION => "TLSv1.2" ],
3587 [ TLS1_3_VERSION => "TLSv1.3" ],
3588 [ DTLS1_VERSION => "DTLSv1.0" ],
3589 [ DTLS1_2_VERSION => "DTLSv1.2" ],
3590 [ DTLS1_BAD_VER => "DTLSv1.0 (bad)" ]
3591 ) {
3592 820 ▶ next if $trace_constants{$_->[0]} == -1;
Branch: 1 branch
BranchTrueFalseTotal
if $trace_constants{$_->[0]} == -1 246 574 820
3593 574 $tc_ver2s{$trace_constants{$_->[0]}} = $_->[1];
3594 }
3595  
3596 82 my %tc_type2s;
3597 82 for (
3598 [ SSL3_RT_HEADER => "TLS header" ],
3599 [ SSL3_RT_CHANGE_CIPHER_SPEC => "TLS change cipher" ],
3600 [ SSL3_RT_ALERT => "TLS alert" ],
3601 [ SSL3_RT_HANDSHAKE => "TLS handshake" ],
3602 [ SSL3_RT_APPLICATION_DATA => "TLS app data" ]
3603 ) {
3604 410 ▶ next if $trace_constants{$_->[0]} == -1;
Branch: 1 branch
BranchTrueFalseTotal
if $trace_constants{$_->[0]} == -1 0 410 410
3605 410 $tc_type2s{$trace_constants{$_->[0]}} = $_->[1];
3606 }
3607  
3608 82 my %tc_msgtype2s;
3609 82 for(
3610 [ SSL2_MT_ERROR => "Error" ],
3611 [ SSL2_MT_CLIENT_HELLO => "Client hello" ],
3612 [ SSL2_MT_CLIENT_MASTER_KEY => "Client key" ],
3613 [ SSL2_MT_CLIENT_FINISHED => "Client finished" ],
3614 [ SSL2_MT_SERVER_HELLO => "Server hello" ],
3615 [ SSL2_MT_SERVER_VERIFY => "Server verify" ],
3616 [ SSL2_MT_SERVER_FINISHED => "Server finished" ],
3617 [ SSL2_MT_REQUEST_CERTIFICATE => "Request CERT" ],
3618 [ SSL2_MT_REQUEST_CERTIFICATE => "Client CERT" ]
3619 ) {
3620 738 ▶ next if $trace_constants{$_->[0]} == -1;
Branch: 1 branch
BranchTrueFalseTotal
if $trace_constants{$_->[0]} == -1 656 82 738
3621 82 $tc_msgtype2s{$trace_constants{SSL2_VERSION_MAJOR}, $trace_constants{$_->[0]}} = $_->[1];
3622 }
3623 82 for(
3624 [ SSL3_MT_HELLO_REQUEST => "Hello request" ],
3625 [ SSL3_MT_CLIENT_HELLO => "Client hello" ],
3626 [ SSL3_MT_SERVER_HELLO => "Server hello" ],
3627 [ SSL3_MT_NEWSESSION_TICKET => "Newsession Ticket" ],
3628 [ SSL3_MT_CERTIFICATE => "Certificate" ],
3629 [ SSL3_MT_SERVER_KEY_EXCHANGE => "Server key exchange" ],
3630 [ SSL3_MT_CLIENT_KEY_EXCHANGE => "Client key exchange" ],
3631 [ SSL3_MT_CERTIFICATE_REQUEST => "Request CERT" ],
3632 [ SSL3_MT_SERVER_DONE => "Server finished" ],
3633 [ SSL3_MT_CERTIFICATE_VERIFY => "CERT verify" ],
3634 [ SSL3_MT_FINISHED => "Finished" ],
3635 [ SSL3_MT_CERTIFICATE_STATUS => "Certificate Status" ],
3636 [ SSL3_MT_ENCRYPTED_EXTENSIONS => "Encrypted Extensions" ],
3637 [ SSL3_MT_SUPPLEMENTAL_DATA => "Supplemental data" ],
3638 [ SSL3_MT_END_OF_EARLY_DATA => "End of early data" ],
3639 [ SSL3_MT_KEY_UPDATE => "Key update" ],
3640 [ SSL3_MT_NEXT_PROTO => "Next protocol" ],
3641 [ SSL3_MT_MESSAGE_HASH => "Message hash" ]
3642 ) {
3643 1476 ▶ next if $trace_constants{$_->[0]} == -1;
Branch: 1 branch
BranchTrueFalseTotal
if $trace_constants{$_->[0]} == -1 82 1394 1476
3644 1394 $tc_msgtype2s{$trace_constants{SSL3_VERSION_MAJOR}, $trace_constants{$_->[0]}} = $_->[1];
3645 }
3646  
3647 #
3648 # Translation of curl ossl_trace
3649 #
3650  
3651 sub ossl_trace {
3652 0 ▶ $DEBUG>=2 or return;
Subroutine ossl_trace: not called CC=14 SCAR=53.5
Branch: 1 branch
BranchTrueFalseTotal
$IO::Socket::SSL::DEBUG >= 2 or return 0 0 0
3653 0 my ($direction, $ssl_ver, $content_type, $buf, $len, $ssl) = @_;
3654  
3655 0 ▶ my $verstr = $tc_ver2s{$ssl_ver} || "(version=$ssl_ver)";
Condition0%0/2
$tc_ver2s{$ssl_ver} || "(version=$ssl_ver)"
l!l
00
MC/DC0%0/1
$tc_ver2s{$ssl_ver} || "(version=$ssl_ver)"
$tc_ver2s{$ssl_ver}
Truth table0%0/2
A
A= $tc_ver2s{$ssl_ver}
Aresult
11
00
3656  
3657 # Log progress for interesting records only (like Handshake or Alert), skip
3658 # all raw record headers (content_type == SSL3_RT_HEADER or ssl_ver == 0).
3659 # For TLS 1.3, skip notification of the decrypted inner Content-Type.
3660  
3661 0 ▶ if ($ssl_ver
Branch: 1 branch
BranchTrueFalseTotal
if ($ssl_ver and $content_type != $trace_constants{"SSL3_RT_HEADER"} and $content_type != $trace_constants{"SSL3_RT_INNER_CONTENT_TYPE"}) 0 0 0
Condition0%0/6
$ssl_ver and $content_type != $trace_constants{"SSL3_RT_HEADER"} and $content_type != $trace_constants{"SSL3_RT_INNER_CONTENT_TYPE"}
!ll&&!rl&&r
000
$ssl_ver and $content_type != $trace_constants{"SSL3_RT_HEADER"}
!ll&&!rl&&r
000
MC/DC0%0/3
$ssl_ver and $content_type != $trace_constants{"SSL3_RT_HEADER"} and $content_type != $trace_constants{"SSL3_RT_INNER_CONTENT_TYPE"}
$ssl_ver $content_type != $trace_constants{"SSL3_RT_HEADER"} $content_type != $trace_constants{"SSL3_RT_INNER_CONTENT_TYPE"}
Truth table0%0/4
A and B and C
A= $ssl_verB= $content_type != $trace_constants{"SSL3_RT_HEADER"}C= $content_type != $trace_constants{"SSL3_RT_INNER_CONTENT_TYPE"}
ABCresult
0XX0
10X0
1100
1111
3662 && ($content_type != $trace_constants{SSL3_RT_HEADER})
3663 && ($content_type != $trace_constants{SSL3_RT_INNER_CONTENT_TYPE})
3664 ) {
3665  
3666 # the info given when the version is zero is not that useful for us
3667 0 $ssl_ver >>= 8; # check the upper 8 bits only below */
3668  
3669 # SSLv2 doesn't seem to have TLS record-type headers, so OpenSSL
3670 # always pass-up content-type as 0. But the interesting message-type
3671 # is at 'buf[0]'.
3672  
3673 my $tls_rt_name = ($ssl_ver == $trace_constants{SSL3_VERSION_MAJOR} && $content_type)
3674 0 ▶ ? $tc_type2s{$content_type} || "TLS Unknown (type=$content_type)"
Branch: 1 branch
BranchTrueFalseTotal
$ssl_ver == $trace_constants{'SSL3_VERSION_MAJOR'} && $content_type ? : 0 0 0
Condition0%0/5
$ssl_ver == $trace_constants{"SSL3_VERSION_MAJOR"} and $content_type
!ll&&!rl&&r
000
$tc_type2s{$content_type} or "TLS Unknown (type=$content_type)"
l!l
00
MC/DC0%0/2
$ssl_ver == $trace_constants{"SSL3_VERSION_MAJOR"} and $content_type
$ssl_ver == $trace_constants{"SSL3_VERSION_MAJOR"} $content_type
MC/DC0%0/1
$tc_type2s{$content_type} or "TLS Unknown (type=$content_type)"
$tc_type2s{$content_type}
Truth table0%0/3
A and B
A= $ssl_ver == $trace_constants{"SSL3_VERSION_MAJOR"}B= $content_type
ABresult
0X0
100
111
Truth table0%0/2
A
A= $tc_type2s{$content_type}
Aresult
11
00
3675 : "";
3676  
3677 0 my $msg_type;
3678 my $msg_name;
3679 0 ▶ if ($content_type == $trace_constants{SSL3_RT_CHANGE_CIPHER_SPEC}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($content_type == $trace_constants{'SSL3_RT_CHANGE_CIPHER_SPEC'}) { } 0 0 0
elsif ($content_type == $trace_constants{'SSL3_RT_ALERT'}) { } 0 0 0
3680 0 $msg_type = unpack('c1', $buf);
3681 0 $msg_name = "Change cipher spec";
3682 } elsif ($content_type == $trace_constants{SSL3_RT_ALERT}) {
3683 0 my @c = unpack('c2', $buf);
3684 0 $msg_type = ($c[0] << 8) + $c[1];
3685 0 ▶ $msg_name = eval { Net::SSLeay::alert_desc_string_long($msg_type) } || "Unknown alert";
Condition0%0/2
eval { do { &Net::SSLeay::alert_desc_string_long($msg_type) } } || 'Unknown alert'
l!l
00
MC/DC0%0/1
eval { do { &Net::SSLeay::alert_desc_string_long($msg_type) } } || 'Unknown alert'
eval { do { &Net::SSLeay::alert_desc_string_long($msg_type) } }
Truth table0%0/2
A
A= eval { do { &Net::SSLeay::alert_desc_string_long($msg_type) } }
Aresult
11
00
3686 } else {
3687 0 $msg_type = unpack('c1', $buf);
3688 0 ▶ $msg_name = $tc_msgtype2s{$ssl_ver, $msg_type} || "Unknown (ssl_ver=$ssl_ver, msg=$msg_type)";
Condition0%0/2
$tc_msgtype2s{join $;, $ssl_ver, $msg_type} || "Unknown (ssl_ver=$ssl_ver, msg=$msg_type)"
l!l
00
MC/DC0%0/1
$tc_msgtype2s{join $;, $ssl_ver, $msg_type} || "Unknown (ssl_ver=$ssl_ver, msg=$msg_type)"
$tc_msgtype2s{join $;, $ssl_ver, $msg_type}
Truth table0%0/2
A
A= $tc_msgtype2s{join $;, $ssl_ver, $msg_type}
Aresult
11
00
3689 }
3690 0 ▶ DEBUG(sprintf("* %s (%s), %s, %s (%d)",
Branch: 1 branch
BranchTrueFalseTotal
$direction ? : 0 0 0
3691 $verstr, $direction ? "OUT" : "IN", $tls_rt_name, $msg_name, $msg_type));
3692 }
3693  
3694 #
3695 # Here one might want to hexdump $buf (?)
3696 #
3697 # $DEBUG>=4 && printf STDERR "%s", hexdump($buf);
3698 }
3699  
3700  
3701 82 1;
3702  
3703 __END__
↑ Summary SSL/Utils.pm »