blib/lib/Net/SSL.pm

filter: Statementstmt 5.7% 15 / 259 Branchbran 0.0% 0 / 110 Conditioncond 0.0% 0 / 88 MC/DCmcdc 0.0% 0 / 53 Subroutinesub 13.1% 5 / 38 Podpod n/a totaltotal 3.6% 20 / 548 CC 90 SCAR 51.2
CC
90
Cov
3%
proxy_connect_helper
552.0
connect
272.0
configure_certs
182.0
CRAP 167.6
↑ Summary blib/lib/Crypt/SSLeay/MainContext.pm »
1 package Net::SSL;
2  
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use MIME::Base64;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use Socket;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 2 ▶use vars qw(@ISA $VERSION $NEW_ARGS);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 $VERSION = '2.86';
10 $VERSION = eval $VERSION;
11  
12 require IO::Socket;
13 @ISA=qw(IO::Socket::INET);
14  
15 my %REAL; # private to this package only
16 my $DEFAULT_VERSION = '23';
17 my $CRLF = "\015\012";
18 my $SEND_USERAGENT_TO_PROXY = 0;
19  
20 require Crypt::SSLeay;
21  
22 0 ▶sub _default_context {
Subroutine _default_context: not called CC=1 SCAR=6.9
23 0 require Crypt::SSLeay::MainContext;
24 0 Crypt::SSLeay::MainContext::main_ctx(@_);
25 }
26  
27 0 ▶sub _alarm_set {
Subroutine _alarm_set: not called CC=3 SCAR=24.8
28 0 ▶ return if $^O eq 'MSWin32' or $^O eq 'NetWare';
Branch: 1 branch
BranchTrueFalseTotal
if $^O eq "MSWin32" or $^O eq "NetWare" 0 0 0
Condition0%0/3
$^O eq "MSWin32" or $^O eq "NetWare"
l!l&&r!l&&!r
000
MC/DC0%0/2
$^O eq "MSWin32" or $^O eq "NetWare"
$^O eq "MSWin32" $^O eq "NetWare"
Truth table0%0/3
A or B
A= $^O eq "MSWin32"B= $^O eq "NetWare"
ABresult
1X1
011
000
29 0 alarm(shift);
30 }
31  
32 0 ▶sub new {
Subroutine new: not called CC=1 SCAR=6.9
33 0 my($class, %arg) = @_;
34 0 local $NEW_ARGS = \%arg;
35 0 $class->SUPER::new(%arg);
36 }
37  
38 0 ▶sub DESTROY {
Subroutine DESTROY: not called CC=1 SCAR=6.9
39 0 my $self = shift;
40 0 delete $REAL{$self};
41 0 local $@;
42 0 eval { $self->SUPER::DESTROY; };
43 }
44  
45 0 ▶sub configure {
Subroutine configure: not called CC=8 SCAR=42.8
46 0 my($self, $arg) = @_;
47 my $ssl_version = delete $arg->{SSL_Version} ||
48 0 ▶ $ENV{HTTPS_VERSION} || $DEFAULT_VERSION;
Condition0%0/6
delete $arg->{'SSL_Version'} || $ENV{'HTTPS_VERSION'} || $DEFAULT_VERSION
l!l&&r!l&&!r
000
delete $arg->{"SSL_Version"} or $ENV{"HTTPS_VERSION"}
l!l&&r!l&&!r
000
MC/DC0%0/3
delete $arg->{'SSL_Version'} || $ENV{'HTTPS_VERSION'} || $DEFAULT_VERSION
delete $arg->{"SSL_Version"} $ENV{"HTTPS_VERSION"} $DEFAULT_VERSION
Truth table0%0/4
A or B || C
A= delete $arg->{"SSL_Version"}B= $ENV{"HTTPS_VERSION"}C= $DEFAULT_VERSION
ABCresult
1XX1
01X1
0011
0000
49 0 ▶ my $ssl_debug = delete $arg->{SSL_Debug} || $ENV{HTTPS_DEBUG} || 0;
Condition0%0/5
delete $arg->{'SSL_Debug'} || $ENV{'HTTPS_DEBUG'} || 0
l!l
00
delete $arg->{"SSL_Debug"} or $ENV{"HTTPS_DEBUG"}
l!l&&r!l&&!r
000
MC/DC0%0/2
delete $arg->{'SSL_Debug'} || $ENV{'HTTPS_DEBUG'} || 0
delete $arg->{"SSL_Debug"} $ENV{"HTTPS_DEBUG"}
Truth table0%0/3
A or B
A= delete $arg->{"SSL_Debug"}B= $ENV{"HTTPS_DEBUG"}
ABresult
1X1
011
000
50  
51 0 ▶ my $ctx = delete $arg->{SSL_Context} || _default_context($ssl_version);
Condition0%0/3
delete $arg->{'SSL_Context'} || _default_context($ssl_version)
l!l&&r!l&&!r
000
MC/DC0%0/2
delete $arg->{'SSL_Context'} || _default_context($ssl_version)
delete $arg->{'SSL_Context'} _default_context($ssl_version)
Truth table0%0/3
A || B
A= delete $arg->{'SSL_Context'}B= _default_context($ssl_version)
ABresult
1X1
011
000
52  
53 0 *$self->{ssl_ctx} = $ctx;
54 0 *$self->{ssl_version} = $ssl_version;
55 0 *$self->{ssl_debug} = $ssl_debug;
56 0 *$self->{ssl_arg} = $arg;
57 0 *$self->{ssl_peer_addr} = $arg->{PeerAddr};
58 0 *$self->{ssl_peer_port} = $arg->{PeerPort};
59 0 *$self->{ssl_new_arg} = $NEW_ARGS;
60 0 *$self->{ssl_peer_verify} = 0;
61  
62 ## Crypt::SSLeay must also aware the SSL Proxy before calling
63 ## $socket->configure($args). Because the $sock->configure() will
64 ## die when failed to resolve the destination server IP address,
65 ## whether the SSL proxy is used or not!
66 ## - dqbai, 2003-05-10
67 0 ▶ if (my $proxy = $self->proxy) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $proxy = $self->proxy) 0 0 0
68 0 ($arg->{PeerAddr}, $arg->{PeerPort}) = split(':',$proxy);
69 0 ▶ $arg->{PeerPort} || croak("no port given for proxy server $proxy");
Branch: 1 branch
BranchTrueFalseTotal
$arg->{"PeerPort"} or croak("no port given for proxy server $proxy") 0 0 0
70 }
71  
72 0 $self->SUPER::configure($arg);
73 }
74  
75 # override to make sure there is really a timeout
76 0 ▶sub timeout {
Subroutine timeout: not called CC=2 SCAR=17.9
77 0 ▶ shift->SUPER::timeout || 60;
Branch: 1 branch
BranchTrueFalseTotal
(shift())->SUPER::timeout or 60 0 0 0
78 }
79  
80 0 ▶sub blocking {
Subroutine blocking: not called CC=1 SCAR=6.9
81 0 my $self = shift;
82 0 $self->SUPER::blocking(@_);
83 }
84  
85 0 ▶sub connect {
Subroutine connect: not called CC=16 SCAR=56.1
86 0 my $self = shift;
87  
88 # configure certs on connect() time, so we can throw an undef
89 # and have LWP understand the error
90 0 eval { $self->configure_certs() };
91 0 ▶ if($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
92 0 $@ = "configure certs failed: $@; $!";
93 0 $self->die_with_error($@);
94 }
95  
96 # finished, update set_verify status
97 0 ▶ if(my $rv = *$self->{ssl_ctx}->set_verify()) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $rv = *$self->{"ssl_ctx"}->set_verify) 0 0 0
98 0 *$self->{ssl_peer_verify} = $rv;
99 }
100  
101 0 ▶ if ($self->proxy) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->proxy) { } 0 0 0
102 # don't die() in connect, just return undef and set $@
103 0 my $proxy_connect = eval { $self->proxy_connect_helper(@_) };
104 0 ▶ if(! $proxy_connect || $@) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $proxy_connect or $@) 0 0 0
Condition0%0/3
not $proxy_connect or $@
l!l&&r!l&&!r
000
MC/DC0%0/2
not $proxy_connect or $@
not $proxy_connect $@
Truth table0%0/3
not(A) or B
A= not $proxy_connectB= $@
ABresult
1X1
011
000
105 0 $@ = "proxy connect failed: $@; $!";
106 0 croak($@);
107 }
108 }
109 else {
110 0 ▶ *$self->{io_socket_peername}=@_ == 1 ? $_[0] : IO::Socket::sockaddr_in(@_);
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 ? : 0 0 0
111 0 ▶ if(!$self->SUPER::connect(@_)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->SUPER::connect(@_)) 0 0 0
112 # better to die than return here
113 0 $@ = "Connect failed: $@; $!";
114 0 croak($@);
115 }
116 }
117  
118 0 ▶ my $debug = *$self->{ssl_debug} || 0;
Condition0%0/2
*$self->{'ssl_debug'} || 0
l!l
00
MC/DC0%0/1
*$self->{'ssl_debug'} || 0
*$self->{'ssl_debug'}
Truth table0%0/2
A
A= *$self->{'ssl_debug'}
Aresult
11
00
119 0 my $ssl = Crypt::SSLeay::Conn->new(*$self->{ssl_ctx}, $debug, $self);
120 0 my $arg = *$self->{ssl_arg};
121 0 my $new_arg = *$self->{ssl_new_arg};
122 0 $arg->{SSL_Debug} = $debug;
123  
124 # setup SNI if available
125 $ssl->can("set_tlsext_host_name") and
126 0 ▶ $ssl->set_tlsext_host_name(*$self->{ssl_peer_addr});
Branch: 1 branch
BranchTrueFalseTotal
$ssl->can("set_tlsext_host_name") and $ssl->set_tlsext_host_name(*$self->{"ssl_peer_addr"}) 0 0 0
127  
128 0 eval {
129 0 ▶ local $SIG{ALRM} = sub { $self->die_with_error("SSL connect timeout") };
Subroutine __ANON__: not called CC=1 SCAR=6.9
130 # timeout / 2 because we have 3 possible connects here
131 0 _alarm_set($self->timeout / 2);
132  
133 0 my $rv;
134 {
135 0 local $SIG{PIPE} = \¨
136 0 $rv = eval { $ssl->connect; };
137 }
138 0 ▶ if (not defined $rv or $rv <= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $rv or $rv <= 0) 0 0 0
Condition0%0/3
not defined $rv or $rv <= 0
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $rv or $rv <= 0
not defined $rv $rv <= 0
Truth table0%0/3
not(A) or B
A= not defined $rvB= $rv <= 0
ABresult
1X1
011
000
139 0 _alarm_set(0);
140 0 $ssl = undef;
141 # See RT #59312
142 0 my %args = (%$arg, %$new_arg);
143 0 ▶ if(*$self->{ssl_version} == 23) {
Branch: 2 branches
BranchTrueFalseTotal
if (*$self->{'ssl_version'} == 23) { } 0 0 0
elsif (*$self->{'ssl_version'} == 3) { } 0 0 0
144 0 $args{SSL_Version} = 3;
145 # the new connect might itself be overridden with a REAL SSL
146 0 my $new_ssl = Net::SSL->new(%args);
147 0 ▶ $REAL{$self} = $REAL{$new_ssl} || $new_ssl;
Condition0%0/3
$REAL{$new_ssl} || $new_ssl
l!l&&r!l&&!r
000
MC/DC0%0/2
$REAL{$new_ssl} || $new_ssl
$REAL{$new_ssl} $new_ssl
Truth table0%0/3
A || B
A= $REAL{$new_ssl}B= $new_ssl
ABresult
1X1
011
000
148 0 return $REAL{$self};
149 }
150 elsif(*$self->{ssl_version} == 3) {
151 # $self->die_with_error("SSL negotiation failed");
152 0 $args{SSL_Version} = 2;
153 0 my $new_ssl = Net::SSL->new(%args);
154 0 $REAL{$self} = $new_ssl;
155 0 return $new_ssl;
156 }
157 else {
158 # don't die, but do set $@, and return undef
159 0 eval { $self->die_with_error("SSL negotiation failed") };
160 0 croak($@);
161 }
162 }
163 0 _alarm_set(0);
164 };
165  
166 # odd error in eval {} block, maybe alarm outside the evals
167 0 ▶ if($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
168 0 $@ = "$@; $!";
169 0 croak($@);
170 }
171  
172 # successful SSL connection gets stored
173 0 *$self->{ssl_ssl} = $ssl;
174 0 $self;
175 }
176  
177 # Delegate these calls to the Crypt::SSLeay::Conn object
178 0 ▶sub get_peer_certificate {
Subroutine get_peer_certificate: not called CC=2 SCAR=17.9
179 0 my $self = shift;
180 0 ▶ $self = $REAL{$self} || $self;
Condition0%0/3
$REAL{$self} || $self
l!l&&r!l&&!r
000
MC/DC0%0/2
$REAL{$self} || $self
$REAL{$self} $self
Truth table0%0/3
A || B
A= $REAL{$self}B= $self
ABresult
1X1
011
000
181 0 *$self->{ssl_ssl}->get_peer_certificate(@_);
182 }
183  
184 0 ▶sub get_peer_verify {
Subroutine get_peer_verify: not called CC=2 SCAR=17.9
185 0 my $self = shift;
186 0 ▶ $self = $REAL{$self} || $self;
Condition0%0/3
$REAL{$self} || $self
l!l&&r!l&&!r
000
MC/DC0%0/2
$REAL{$self} || $self
$REAL{$self} $self
Truth table0%0/3
A || B
A= $REAL{$self}B= $self
ABresult
1X1
011
000
187 0 *$self->{ssl_peer_verify};
188 }
189  
190 0 ▶sub get_shared_ciphers {
Subroutine get_shared_ciphers: not called CC=2 SCAR=17.9
191 0 my $self = shift;
192 0 ▶ $self = $REAL{$self} || $self;
Condition0%0/3
$REAL{$self} || $self
l!l&&r!l&&!r
000
MC/DC0%0/2
$REAL{$self} || $self
$REAL{$self} $self
Truth table0%0/3
A || B
A= $REAL{$self}B= $self
ABresult
1X1
011
000
193 0 *$self->{ssl_ssl}->get_shared_ciphers(@_);
194 }
195  
196 0 ▶sub get_cipher {
Subroutine get_cipher: not called CC=2 SCAR=17.9
197 0 my $self = shift;
198 0 ▶ $self = $REAL{$self} || $self;
Condition0%0/3
$REAL{$self} || $self
l!l&&r!l&&!r
000
MC/DC0%0/2
$REAL{$self} || $self
$REAL{$self} $self
Truth table0%0/3
A || B
A= $REAL{$self}B= $self
ABresult
1X1
011
000
199 0 *$self->{ssl_ssl}->get_cipher(@_);
200 }
201  
202 0 ▶sub pending {
Subroutine pending: not called CC=2 SCAR=17.9
203 0 my $self = shift;
204 0 ▶ $self = $REAL{$self} || $self;
Condition0%0/3
$REAL{$self} || $self
l!l&&r!l&&!r
000
MC/DC0%0/2
$REAL{$self} || $self
$REAL{$self} $self
Truth table0%0/3
A || B
A= $REAL{$self}B= $self
ABresult
1X1
011
000
205 0 *$self->{ssl_ssl}->pending(@_);
206 }
207  
208 0 ▶sub ssl_context {
Subroutine ssl_context: not called CC=2 SCAR=17.9
209 0 my $self = shift;
210 0 ▶ $self = $REAL{$self} || $self;
Condition0%0/3
$REAL{$self} || $self
l!l&&r!l&&!r
000
MC/DC0%0/2
$REAL{$self} || $self
$REAL{$self} $self
Truth table0%0/3
A || B
A= $REAL{$self}B= $self
ABresult
1X1
011
000
211 0 *$self->{ssl_ctx};
212 }
213  
214 0 ▶sub die_with_error {
Subroutine die_with_error: not called CC=2 SCAR=17.9
215 0 my $self=shift;
216 0 my $reason=shift;
217  
218 0 my @err;
219 0 ▶ while(my $err=Crypt::SSLeay::Err::get_error_string()) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $err = Crypt::SSLeay::Err::get_error_string()) 0 0 0
220 0 push @err, $err;
221 }
222 0 croak("$reason: " . join( ' | ', @err ));
223 }
224  
225 0 ▶sub read {
Subroutine read: not called CC=3 SCAR=24.8
226 0 my $self = shift;
227 0 ▶ $self = $REAL{$self} || $self;
Condition0%0/3
$REAL{$self} || $self
l!l&&r!l&&!r
000
MC/DC0%0/2
$REAL{$self} || $self
$REAL{$self} $self
Truth table0%0/3
A || B
A= $REAL{$self}B= $self
ABresult
1X1
011
000
228  
229 0 local $SIG{__DIE__} = \&Carp::confess;
230 0 ▶ local $SIG{ALRM} = sub { $self->die_with_error("SSL read timeout") };
Subroutine __ANON__: not called CC=1 SCAR=6.9
231  
232 0 _alarm_set($self->timeout);
233 0 my $n = *$self->{ssl_ssl}->read(@_);
234 0 _alarm_set(0);
235 0 ▶ $self->die_with_error("read failed") if !defined $n;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $n 0 0 0
236  
237 0 $n;
238 }
239  
240 0 ▶sub write {
Subroutine write: not called CC=3 SCAR=24.8
241 0 my $self = shift;
242 0 ▶ $self = $REAL{$self} || $self;
Condition0%0/3
$REAL{$self} || $self
l!l&&r!l&&!r
000
MC/DC0%0/2
$REAL{$self} || $self
$REAL{$self} $self
Truth table0%0/3
A || B
A= $REAL{$self}B= $self
ABresult
1X1
011
000
243 0 my $n = *$self->{ssl_ssl}->write(@_);
244 0 ▶ $self->die_with_error("write failed") if !defined $n;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $n 0 0 0
245 0 $n;
246 }
247  
248 *sysread = \&read;
249 *syswrite = \&write;
250  
251 0 ▶sub print {
Subroutine print: not called CC=2 SCAR=17.9
252 0 my $self = shift;
253 0 ▶ $self = $REAL{$self} || $self;
Condition0%0/3
$REAL{$self} || $self
l!l&&r!l&&!r
000
MC/DC0%0/2
$REAL{$self} || $self
$REAL{$self} $self
Truth table0%0/3
A || B
A= $REAL{$self}B= $self
ABresult
1X1
011
000
254 # should we care about $, and $\??
255 # I think it is too expensive...
256 0 $self->write(join("", @_));
257 }
258  
259 0 ▶sub printf {
Subroutine printf: not called CC=2 SCAR=17.9
260 0 my $self = shift;
261 0 ▶ $self = $REAL{$self} || $self;
Condition0%0/3
$REAL{$self} || $self
l!l&&r!l&&!r
000
MC/DC0%0/2
$REAL{$self} || $self
$REAL{$self} $self
Truth table0%0/3
A || B
A= $REAL{$self}B= $self
ABresult
1X1
011
000
262 0 my $fmt = shift;
263 0 $self->write(sprintf($fmt, @_));
264 }
265  
266 0 ▶sub getchunk {
Subroutine getchunk: not called CC=3 SCAR=24.8
267 0 my $self = shift;
268 0 ▶ $self = $REAL{$self} || $self;
Condition0%0/3
$REAL{$self} || $self
l!l&&r!l&&!r
000
MC/DC0%0/2
$REAL{$self} || $self
$REAL{$self} $self
Truth table0%0/3
A || B
A= $REAL{$self}B= $self
ABresult
1X1
011
000
269 0 my $buf = ''; # warnings
270 0 my $n = $self->read($buf, 32768);
271 0 ▶ return unless defined $n;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $n 0 0 0
272 0 $buf;
273 }
274  
275 # This is really inefficient, but we only use it for reading the proxy response
276 # so that does not really matter.
277 0 ▶sub getline {
Subroutine getline: not called CC=3 SCAR=24.8
278 0 my $self = shift;
279 0 ▶ $self = $REAL{$self} || $self;
Condition0%0/3
$REAL{$self} || $self
l!l&&r!l&&!r
000
MC/DC0%0/2
$REAL{$self} || $self
$REAL{$self} $self
Truth table0%0/3
A || B
A= $REAL{$self}B= $self
ABresult
1X1
011
000
280 0 my $val="";
281 0 my $buf;
282 0 ▶ do {
Branch: 1 branch
BranchTrueFalseTotal
$buf eq "\n" or do { do { $self->SUPER::recv($buf, 1); $val .= $buf } } 0 0 0
283 0 $self->SUPER::recv($buf, 1);
284 0 $val .= $buf;
285 } until ($buf eq "\n");
286  
287 0 $val;
288 }
289  
290 # XXX: no way to disable <$sock>?? (tied handle perhaps?)
291  
292 0 ▶sub get_lwp_object {
Subroutine get_lwp_object: not called CC=5 SCAR=34.0
293 0 my $self = shift;
294  
295 0 my $lwp_object;
296 0 my $i = 0;
297 0 while(1) {
298 package DB;
299 0 my @stack = caller($i++);
300 0 ▶ last unless @stack;
Branch: 1 branch
BranchTrueFalseTotal
unless @stack 0 0 0
301 0 my @stack_args = @DB::args;
302 0 ▶ my $stack_object = $stack_args[0] || next;
Condition0%0/2
$stack_args[0] || (next)
l!l
00
MC/DC0%0/1
$stack_args[0] || (next)
$stack_args[0]
Truth table0%0/2
A
A= $stack_args[0]
Aresult
11
00
303 0 ▶ return $stack_object
Branch: 1 branch
BranchTrueFalseTotal
if ref $stack_object and $stack_object->isa("LWP::UserAgent") 0 0 0
Condition0%0/3
ref $stack_object and $stack_object->isa("LWP::UserAgent")
!ll&&!rl&&r
000
MC/DC0%0/2
ref $stack_object and $stack_object->isa("LWP::UserAgent")
ref $stack_object $stack_object->isa("LWP::UserAgent")
Truth table0%0/3
A and B
A= ref $stack_objectB= $stack_object->isa("LWP::UserAgent")
ABresult
0X0
100
111
304 if ref($stack_object)
305 and $stack_object->isa('LWP::UserAgent');
306 }
307 0 return undef;
308 }
309  
310 0 ▶sub send_useragent_to_proxy {
Subroutine send_useragent_to_proxy: not called CC=2 SCAR=17.9
311 0 ▶ if (my $val = shift) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $val = shift()) 0 0 0
312 0 $SEND_USERAGENT_TO_PROXY = $val;
313 }
314 0 return $SEND_USERAGENT_TO_PROXY;
315 }
316  
317 0 ▶sub proxy_connect_helper {
Subroutine proxy_connect_helper: not called CC=23 SCAR=63.1
318 0 my $self = shift;
319  
320 0 my $proxy = $self->proxy;
321 0 my ($proxy_host, $proxy_port) = split(':',$proxy);
322 0 ▶ $proxy_port || croak("no port given for proxy server $proxy");
Branch: 1 branch
BranchTrueFalseTotal
$proxy_port or croak("no port given for proxy server $proxy") 0 0 0
323  
324 0 my $proxy_addr = gethostbyname($proxy_host);
325 0 ▶ $proxy_addr || croak("can't resolve proxy server name: $proxy_host, $!");
Branch: 1 branch
BranchTrueFalseTotal
$proxy_addr or croak("can't resolve proxy server name: $proxy_host, $!") 0 0 0
326  
327 0 my($peer_port, $peer_addr) = (*$self->{ssl_peer_port}, *$self->{ssl_peer_addr});
328 0 ▶ $peer_addr || croak("no peer addr given");
Branch: 1 branch
BranchTrueFalseTotal
$peer_addr or croak("no peer addr given") 0 0 0
329 0 ▶ $peer_port || croak("no peer port given");
Branch: 1 branch
BranchTrueFalseTotal
$peer_port or croak("no peer port given") 0 0 0
330  
331 # see if the proxy should be bypassed
332 0 ▶ my @no_proxy = split( /\s*,\s*/, $ENV{NO_PROXY} || $ENV{no_proxy} || '');
Condition0%0/5
$ENV{'NO_PROXY'} || $ENV{'no_proxy'} || ''
l!l
00
$ENV{"NO_PROXY"} or $ENV{"no_proxy"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$ENV{'NO_PROXY'} || $ENV{'no_proxy'} || ''
$ENV{"NO_PROXY"} $ENV{"no_proxy"}
Truth table0%0/3
A or B
A= $ENV{"NO_PROXY"}B= $ENV{"no_proxy"}
ABresult
1X1
011
000
333 0 my $is_proxied = 1;
334 0 my $domain;
335 0 for $domain (@no_proxy) {
336 0 ▶ if ($peer_addr =~ /\Q$domain\E$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($peer_addr =~ /\Q$domain\E$/) 0 0 0
337 0 $is_proxied = 0;
338 0 last;
339 }
340 }
341  
342 0 ▶ if ($is_proxied) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_proxied) { } 0 0 0
343 0 ▶ $self->SUPER::connect($proxy_port, $proxy_addr)
Branch: 1 branch
BranchTrueFalseTotal
$self->SUPER::connect($proxy_port, $proxy_addr) or croak("proxy connect to ${proxy_host}:$proxy_port failed: $!") 0 0 0
344 || croak("proxy connect to $proxy_host:$proxy_port failed: $!");
345 }
346 else {
347 # see RT #57836
348 0 my $peer_addr_packed = gethostbyname($peer_addr);
349 0 ▶ $self->SUPER::connect($peer_port, $peer_addr_packed)
Branch: 1 branch
BranchTrueFalseTotal
$self->SUPER::connect($peer_port, $peer_addr_packed) or croak("proxy bypass to ${peer_addr}:$peer_addr failed: $!") 0 0 0
350 || croak("proxy bypass to $peer_addr:$peer_addr failed: $!");
351 }
352  
353 0 my $connect_string;
354 0 ▶ if ($ENV{"HTTPS_PROXY_USERNAME"} || $ENV{"HTTPS_PROXY_PASSWORD"}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ENV{'HTTPS_PROXY_USERNAME'} or $ENV{'HTTPS_PROXY_PASSWORD'}) { } 0 0 0
Condition0%0/3
$ENV{"HTTPS_PROXY_USERNAME"} or $ENV{"HTTPS_PROXY_PASSWORD"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$ENV{"HTTPS_PROXY_USERNAME"} or $ENV{"HTTPS_PROXY_PASSWORD"}
$ENV{"HTTPS_PROXY_USERNAME"} $ENV{"HTTPS_PROXY_PASSWORD"}
Truth table0%0/3
A or B
A= $ENV{"HTTPS_PROXY_USERNAME"}B= $ENV{"HTTPS_PROXY_PASSWORD"}
ABresult
1X1
011
000
355 0 my $user = $ENV{"HTTPS_PROXY_USERNAME"};
356 0 my $pass = $ENV{"HTTPS_PROXY_PASSWORD"};
357  
358 0 my $credentials = encode_base64("$user:$pass", "");
359 0 $connect_string = join($CRLF,
360 "CONNECT $peer_addr:$peer_port HTTP/1.0",
361 "Proxy-authorization: Basic $credentials"
362 );
363 }
364 else {
365 0 $connect_string = "CONNECT $peer_addr:$peer_port HTTP/1.0";
366 }
367 0 $connect_string .= $CRLF;
368  
369 0 ▶ if (send_useragent_to_proxy()) {
Branch: 1 branch
BranchTrueFalseTotal
if (send_useragent_to_proxy()) 0 0 0
370 0 my $lwp_object = $self->get_lwp_object;
371 0 ▶ if($lwp_object && $lwp_object->agent) {
Branch: 1 branch
BranchTrueFalseTotal
if ($lwp_object and $lwp_object->agent) 0 0 0
Condition0%0/3
$lwp_object and $lwp_object->agent
!ll&&!rl&&r
000
MC/DC0%0/2
$lwp_object and $lwp_object->agent
$lwp_object $lwp_object->agent
Truth table0%0/3
A and B
A= $lwp_objectB= $lwp_object->agent
ABresult
0X0
100
111
372 0 $connect_string .= "User-Agent: ".$lwp_object->agent.$CRLF;
373 }
374 }
375  
376 0 $connect_string .= $CRLF;
377 0 $self->SUPER::send($connect_string);
378  
379 0 my $timeout;
380 0 my $header = '';
381  
382 # See RT #33954
383 # See also RT #64054
384 # Handling incomplete reads and writes better (for some values of
385 # better) may actually make this problem go away, but either way,
386 # there is no good reason to use \d when checking for 0-9
387  
388 0 ▶ while ($header !~ m{HTTP/[0-9][.][0-9]\s+200\s+.*$CRLF$CRLF}s) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($header =~ m[HTTP/[0-9][.][0-9]\s+200\s+.*$CRLF$CRLF]s) 0 0 0
389 0 ▶ $timeout = $self->timeout(5) unless length $header;
Branch: 1 branch
BranchTrueFalseTotal
unless length $header 0 0 0
390 0 my $n = $self->SUPER::sysread($header, 8192, length $header);
391 0 ▶ last if $n <= 0;
Branch: 1 branch
BranchTrueFalseTotal
if $n <= 0 0 0 0
392 }
393  
394 0 ▶ $self->timeout($timeout) if defined $timeout;
Branch: 1 branch
BranchTrueFalseTotal
if defined $timeout 0 0 0
395 0 ▶ my $conn_ok = ($header =~ m{HTTP/[0-9]+[.][0-9]+\s+200\s+}is) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$header =~ m[HTTP/[0-9]+[.][0-9]+\s+200\s+]is ? : 0 0 0
396  
397 0 ▶ if (not $conn_ok) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($conn_ok) 0 0 0
398 0 croak("PROXY ERROR HEADER, could be non-SSL URL:\n$header");
399 }
400  
401 0 $conn_ok;
402 }
403  
404 # code adapted from LWP::UserAgent, with $ua->env_proxy API
405 # see also RT #57836
406 0 ▶sub proxy {
Subroutine proxy: not called CC=9 SCAR=45.0
407 0 my $self = shift;
408 0 ▶ my $proxy_server = $ENV{HTTPS_PROXY} || $ENV{https_proxy};
Condition0%0/3
$ENV{'HTTPS_PROXY'} || $ENV{'https_proxy'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$ENV{'HTTPS_PROXY'} || $ENV{'https_proxy'}
$ENV{'HTTPS_PROXY'} $ENV{'https_proxy'}
Truth table0%0/3
A || B
A= $ENV{'HTTPS_PROXY'}B= $ENV{'https_proxy'}
ABresult
1X1
011
000
409 0 ▶ return unless $proxy_server;
Branch: 1 branch
BranchTrueFalseTotal
unless $proxy_server 0 0 0
410  
411 my($peer_port, $peer_addr) = (
412 *$self->{ssl_peer_port},
413 *$self->{ssl_peer_addr}
414 0 );
415 0 ▶ $peer_addr || croak("no peer addr given");
Branch: 1 branch
BranchTrueFalseTotal
$peer_addr or croak("no peer addr given") 0 0 0
416 0 ▶ $peer_port || croak("no peer port given");
Branch: 1 branch
BranchTrueFalseTotal
$peer_port or croak("no peer port given") 0 0 0
417  
418 # see if the proxy should be bypassed
419 my @no_proxy = split( /\s*,\s*/,
420 0 ▶ $ENV{NO_PROXY} || $ENV{no_proxy} || ''
Condition0%0/5
$ENV{'NO_PROXY'} || $ENV{'no_proxy'} || ''
l!l
00
$ENV{"NO_PROXY"} or $ENV{"no_proxy"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$ENV{'NO_PROXY'} || $ENV{'no_proxy'} || ''
$ENV{"NO_PROXY"} $ENV{"no_proxy"}
Truth table0%0/3
A or B
A= $ENV{"NO_PROXY"}B= $ENV{"no_proxy"}
ABresult
1X1
011
000
421 );
422 0 my $is_proxied = 1;
423 0 for my $domain (@no_proxy) {
424 0 ▶ if ($peer_addr =~ /\Q$domain\E\z/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($peer_addr =~ /\Q$domain\E\z/) 0 0 0
425 0 return;
426 }
427 }
428  
429 0 $proxy_server =~ s|\Ahttps?://||i;
430 # sanitize the end of the string too
431 # see also http://www.nntp.perl.org/group/perl.libwww/2012/10/msg7629.html
432 # and https://github.com/nanis/Crypt-SSLeay/pull/1
433 # Thank you Mark Allen and YigangX Wen
434 0 $proxy_server =~ s|(:[1-9][0-9]{0,4})/\z|$1|;
435 0 $proxy_server;
436 }
437  
438 0 ▶sub configure_certs {
Subroutine configure_certs: not called CC=13 SCAR=52.0
439 0 my $self = shift;
440 0 my $ctx = *$self->{ssl_ctx};
441  
442 0 my $count = 0;
443 0 for (qw(HTTPS_PKCS12_FILE HTTPS_CERT_FILE HTTPS_KEY_FILE)) {
444 0 my $file = $ENV{$_};
445 0 ▶ if ($file) {
Branch: 1 branch
BranchTrueFalseTotal
if ($file) 0 0 0
446 0 ▶ (-e $file) or croak("$file file does not exist: $!");
Branch: 1 branch
BranchTrueFalseTotal
-e $file or croak("$file file does not exist: $!") 0 0 0
447 0 ▶ (-r $file) or croak("$file file is not readable");
Branch: 1 branch
BranchTrueFalseTotal
-r $file or croak("$file file is not readable") 0 0 0
448 0 $count++;
449 0 ▶ if (/PKCS12/) {
Branch: 3 branches
BranchTrueFalseTotal
if (/PKCS12/) { } 0 0 0
elsif (/CERT/) { } 0 0 0
elsif (/KEY/) { } 0 0 0
450 0 $count++;
451 0 ▶ $ctx->use_pkcs12_file($file ,$ENV{'HTTPS_PKCS12_PASSWORD'}) || croak("failed to load $file: $!");
Branch: 1 branch
BranchTrueFalseTotal
$ctx->use_pkcs12_file($file, $ENV{"HTTPS_PKCS12_PASSWORD"}) or croak("failed to load ${file}: $!") 0 0 0
452 0 last;
453 }
454 elsif (/CERT/) {
455 0 ▶ $ctx->use_certificate_file($file ,1) || croak("failed to load $file: $!");
Branch: 1 branch
BranchTrueFalseTotal
$ctx->use_certificate_file($file, 1) or croak("failed to load ${file}: $!") 0 0 0
456 }
457 elsif (/KEY/) {
458 0 ▶ $ctx->use_PrivateKey_file($file, 1) || croak("failed to load $file: $!");
Branch: 1 branch
BranchTrueFalseTotal
$ctx->use_PrivateKey_file($file, 1) or croak("failed to load ${file}: $!") 0 0 0
459 }
460 else {
461 0 croak("setting $_ not supported");
462 }
463 }
464 }
465  
466 # if both configs are set, then verify them
467 0 ▶ if ($count == 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($count == 2) 0 0 0
468 0 ▶ if (! $ctx->check_private_key) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ctx->check_private_key) 0 0 0
469 0 croak("Private key and certificate do not match");
470 }
471 }
472  
473 0 $count; # number of successful cert loads/checks
474 }
475  
476 0 ▶sub accept { shift->_unimpl("accept") }
Subroutine accept: not called CC=1 SCAR=6.9
477 0 ▶sub getc { shift->_unimpl("getc") }
Subroutine getc: not called CC=1 SCAR=6.9
478 0 ▶sub ungetc { shift->_unimpl("ungetc") }
Subroutine ungetc: not called CC=1 SCAR=6.9
479 0 ▶sub getlines { shift->_unimpl("getlines"); }
Subroutine getlines: not called CC=1 SCAR=6.9
480  
481 0 ▶sub _unimpl {
Subroutine _unimpl: not called CC=1 SCAR=6.9
482 0 my($self, $meth) = @_;
483 0 croak("$meth not implemented for Net::SSL sockets");
484 }
485  
486 1;
487  
488 __END__
↑ Summary blib/lib/Crypt/SSLeay/MainContext.pm »