Protocol/https_paranoid.pm untested

filter: Statementstmt 0.0% 0 / 55 Branchbran 0.0% 0 / 18 Conditioncond 0.0% 0 / 9 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 0.0% 0 / 9 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 99 CC 10 SCAR 29.3
CC
10
Cov
0%
_extra_sock_opts
42.0
_check_sock
12.0
_get_sock_info
12.0
CRAP 18.7
1 #
2 package LWPx::Protocol::https_paranoid;
3  
4 # $Id: https_paranoid.pm 2 2005-06-01 23:12:25Z bradfitz $
5  
6 use strict;
7  
8 use vars qw(@ISA);
9 require LWPx::Protocol::http_paranoid;
10 @ISA = qw(LWPx::Protocol::http_paranoid);
11  
12 sub _check_sock
13 {
14 my($self, $req, $sock) = @_;
15 my $check = $req->header("If-SSL-Cert-Subject");
16 if (defined $check) {
17 my $cert = $sock->get_peer_certificate ||
18 die "Missing SSL certificate";
19 my $subject = $cert->subject_name;
20 die "Bad SSL certificate subject: '$subject' !~ /$check/"
21 unless $subject =~ /$check/;
22 $req->remove_header("If-SSL-Cert-Subject"); # don't pass it on
23 }
24 }
25  
26 sub _get_sock_info
27 {
28 my $self = shift;
29 $self->SUPER::_get_sock_info(@_);
30 my($res, $sock) = @_;
31 $res->header("Client-SSL-Cipher" => $sock->get_cipher);
32 my $cert = $sock->get_peer_certificate;
33 if ($cert) {
34 $res->header("Client-SSL-Cert-Subject" => $cert->subject_name);
35 $res->header("Client-SSL-Cert-Issuer" => $cert->issuer_name);
36 }
37 if(! eval { $sock->get_peer_verify }) {
38 $res->header("Client-SSL-Warning" => "Peer certificate not verified");
39 }
40 }
41  
42 sub _extra_sock_opts
43 {
44 my $self = shift;
45 my %ssl_opts = %{$self->{ua}{ssl_opts} || {}};
46 if (delete $ssl_opts{verify_hostname}) {
47 $ssl_opts{SSL_verify_mode} ||= 1;
48 $ssl_opts{SSL_verifycn_scheme} = 'www';
49 }
50 else {
51 $ssl_opts{SSL_verify_mode} = 0;
52 }
53 if ($ssl_opts{SSL_verify_mode}) {
54 unless (exists $ssl_opts{SSL_ca_file} || exists $ssl_opts{SSL_ca_path}) {
55 eval {
56 require Mozilla::CA;
57 };
58 if ($@) {
59 if ($@ =! /^Can't locate Mozilla\/CA\.pm/) {
60 $@ = <<'EOT';
61 Can't verify SSL peers without knowing which Certificate Authorities to trust
62  
63 This problem can be fixed by either setting the PERL_LWP_SSL_CA_FILE
64 environment variable or by installing the Mozilla::CA module.
65  
66 To disable verification of SSL peers set the PERL_LWP_SSL_VERIFY_HOSTNAME
67 environment variable to 0. If you do this you can't be sure that you
68 communicate with the expected peer.
69 EOT
70 }
71 die $@;
72 }
73 $ssl_opts{SSL_ca_file} = Mozilla::CA::SSL_ca_file();
74 }
75 }
76 $self->{ssl_opts} = \%ssl_opts;
77 return (%ssl_opts, $self->SUPER::_extra_sock_opts);
78 }
79  
80 #-----------------------------------------------------------
81 package LWPx::Protocol::https_paranoid::Socket;
82  
83 use vars qw(@ISA);
84 require Net::HTTPS;
85 @ISA = qw(Net::HTTPS LWPx::Protocol::http_paranoid::SocketMethods);
86  
87 1;