SSL/Intercept.pm

filter: Statementstmt 18.8% 17 / 90 Branchbran 0.0% 0 / 48 Conditioncond 0.0% 0 / 16 MC/DCmcdc 0.0% 0 / 10 Subroutinesub 35.7% 5 / 14 Podpod 66.6% 4 / 6 totaltotal 14.1% 26 / 184 CC 33 SCAR 37.5
CC
33
Cov
11%
new
90.0
DESTROY
56.0
unserialize
56.0
CRAP 42.4
« SSL/PublicSuffix.pm ↑ Summary
1  
2 package IO::Socket::SSL::Intercept;
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use Carp 'croak';
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use IO::Socket::SSL::Utils;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use Net::SSLeay;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 1 our $VERSION = '1.93';
10  
11 sub new {
12 0 ▶ my ($class,%args) = @_;
Subroutine new: not called CC=9 SCAR=45.0
Pod documented
13  
14 0 my $cacert = delete $args{proxy_cert};
15 0 ▶ if ( ! $cacert ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($cacert) 0 0 0
16 0 ▶ if ( my $f = delete $args{proxy_cert_file} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $f = delete $args{'proxy_cert_file'}) { } 0 0 0
17 0 $cacert = PEM_file2cert($f);
18 } else {
19 0 croak "no proxy_cert or proxy_cert_file given";
20 }
21 }
22  
23 0 my $cakey = delete $args{proxy_key};
24 0 ▶ if ( ! $cakey ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($cakey) 0 0 0
25 0 ▶ if ( my $f = delete $args{proxy_key_file} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $f = delete $args{'proxy_key_file'}) { } 0 0 0
26 0 $cakey = PEM_file2key($f);
27 } else {
28 0 croak "no proxy_cert or proxy_cert_file given";
29 }
30 }
31  
32 0 my $certkey = delete $args{cert_key};
33 0 ▶ if ( ! $certkey ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($certkey) 0 0 0
34 0 ▶ if ( my $f = delete $args{cert_key_file} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $f = delete $args{"cert_key_file"}) 0 0 0
35 0 $certkey = PEM_file2key($f);
36 }
37 }
38  
39 0 ▶ my $cache = delete $args{cache} || {};
Condition0%0/2
delete $args{'cache'} || {}
l!l
00
MC/DC0%0/1
delete $args{'cache'} || {}
delete $args{'cache'}
Truth table0%0/2
A
A= delete $args{'cache'}
Aresult
11
00
40  
41 my $self = bless {
42 cacert => $cacert,
43 cakey => $cakey,
44 certkey => $certkey,
45 0 ▶ serial => delete $args{serial} || 1,
Condition0%0/2
delete $args{'serial'} || 1
l!l
00
MC/DC0%0/1
delete $args{'serial'} || 1
delete $args{'serial'}
Truth table0%0/2
A
A= delete $args{'serial'}
Aresult
11
00
46 cache => $cache,
47 };
48 0 return $self;
49 }
50  
51 sub DESTROY {
52 # call various ssl _free routines
53 0 ▶ my $self = shift or return;
Subroutine DESTROY: not called CC=7 SCAR=40.3
Branch: 1 branch
BranchTrueFalseTotal
my $self = shift() or return 0 0 0
54 0 for ( \$self->{cacert},
55 0 ▶ map { \$_->{cert} } ref($self->{cache}) ne 'CODE' ? values %{$self->{cache}} :()) {
Branch: 1 branch
BranchTrueFalseTotal
ref $self->{'cache'} ne 'CODE' ? : 0 0 0
56 0 ▶ $$_ or next;
Branch: 1 branch
BranchTrueFalseTotal
$$_ or next 0 0 0
57 0 CERT_free($$_);
58 0 $$_ = undef;
59 }
60 0 for ( \$self->{cakey}, \$self->{pubkey} ) {
61 0 ▶ $$_ or next;
Branch: 1 branch
BranchTrueFalseTotal
$$_ or next 0 0 0
62 0 KEY_free($$_);
63 0 $$_ = undef;
64 }
65 }
66  
67 sub clone_cert {
68 0 ▶ my ($self,$old_cert,$clone_key) = @_;
Subroutine clone_cert: not called CC=3 SCAR=24.8
Pod documented
69  
70 0 ▶ $clone_key ||= substr(unpack("H*",Net::SSLeay::X509_get_fingerprint($old_cert,'sha1')),0,16);
Condition0%0/3
$clone_key ||= substr(unpack("H*", &Net::SSLeay::X509_get_fingerprint($old_cert, "sha1")), 0, 16)
l!l&&r!l&&!r
000
MC/DC0%0/2
$clone_key ||= substr(unpack("H*", &Net::SSLeay::X509_get_fingerprint($old_cert, "sha1")), 0, 16)
$clone_key substr(unpack("H*", &Net::SSLeay::X509_get_fingerprint($old_cert, "sha1")), 0, 16)
Truth table0%0/3
A ||= B
A= $clone_keyB= substr(unpack("H*", &Net::SSLeay::X509_get_fingerprint($old_cert, "sha1")), 0, 16)
ABresult
1X1
011
000
71 0 ▶ if ( my ($clone,$key) = _get_cached($self,$clone_key)) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = _get_cached($self, $clone_key)) 0 0 0
72 0 return ($clone,$key);
73 }
74  
75 # create new certificate based on original
76 my ($clone,$key) = CERT_create(
77 0 %{ CERT_asHash($old_cert) },
78 serial => $self->{serial}++,
79 issuer_cert => $self->{cacert},
80 issuer_key => $self->{cakey},
81 key => $self->{certkey},
82 0 );
83  
84 # put into cache
85 0 _set_cached($self,$clone_key,$clone,$key);
86  
87 0 return ($clone,$key);
88 }
89  
90 sub _get_cached {
91 0 ▶ my ($self,$clone_key) = @_;
Subroutine _get_cached: not called CC=4 SCAR=30.0
92 0 my $c = $self->{cache};
93 0 ▶ return $c->($clone_key) if ref($c) eq 'CODE';
Branch: 1 branch
BranchTrueFalseTotal
if ref $c eq "CODE" 0 0 0
94 0 ▶ my $e = $c->{$clone_key} or return;
Branch: 1 branch
BranchTrueFalseTotal
my $e = $c->{$clone_key} or return 0 0 0
95 0 $e->{atime} = time();
96 0 ▶ return ($e->{cert},$e->{key} || $self->{certkey});
Condition0%0/3
$e->{'key'} || $self->{'certkey'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$e->{'key'} || $self->{'certkey'}
$e->{'key'} $self->{'certkey'}
Truth table0%0/3
A || B
A= $e->{'key'}B= $self->{'certkey'}
ABresult
1X1
011
000
97 }
98  
99 sub _set_cached {
100 0 ▶ my ($self,$clone_key,$cert,$key) = @_;
Subroutine _set_cached: not called CC=4 SCAR=30.0
101 0 my $c = $self->{cache};
102 0 ▶ return $c->($clone_key,$cert,$key) if ref($c) eq 'CODE';
Branch: 1 branch
BranchTrueFalseTotal
if ref $c eq "CODE" 0 0 0
103 $c->{$clone_key} = {
104 cert => $cert,
105 0 ▶ $self->{certkey} && $self->{certkey} == $key ? () : ( key => $key ),
Branch: 1 branch
BranchTrueFalseTotal
$self->{'certkey'} && $self->{'certkey'} == $key ? : 0 0 0
Condition0%0/3
$self->{"certkey"} and $self->{"certkey"} == $key
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"certkey"} and $self->{"certkey"} == $key
$self->{"certkey"} $self->{"certkey"} == $key
Truth table0%0/3
A and B
A= $self->{"certkey"}B= $self->{"certkey"} == $key
ABresult
0X0
100
111
106 atime => time()
107 };
108 }
109  
110  
111 0 ▶sub STORABLE_freeze { my $self = shift; $self->serialize() }
Subroutine STORABLE_freeze: not called CC=1 SCAR=6.9
Pod undocumented
112 0 ▶sub STORABLE_thaw { my ($class,undef,$data) = @_; $class->unserialize($data) }
Subroutine STORABLE_thaw: not called CC=1 SCAR=6.9
Pod undocumented
113  
114 sub serialize {
115 0 ▶ my $self = shift;
Subroutine serialize: not called CC=5 SCAR=34.0
Pod documented
116 0 my $data = pack("N",2); # version
117 0 $data .= pack("N/a", PEM_cert2string($self->{cacert}));
118 0 $data .= pack("N/a", PEM_key2string($self->{cakey}));
119 0 ▶ if ( $self->{certkey} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'certkey'}) { } 0 0 0
120 0 $data .= pack("N/a", PEM_key2string($self->{certkey}));
121 } else {
122 0 $data .= pack("N/a", '');
123 }
124 0 $data .= pack("N",$self->{serial});
125 0 ▶ if ( ref($self->{cache}) eq 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self->{"cache"} eq "HASH") 0 0 0
126 0 ▶ while ( my($k,$v) = each %{ $self->{cache}} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %{$$self{"cache"};}) 0 0 0
127 $data .= pack("N/aN/aN/aN", $k,
128 PEM_cert2string($k->{cert}),
129 $k->{key} ? PEM_key2string($k->{key}) : '',
130 0 ▶ $k->{atime});
Branch: 1 branch
BranchTrueFalseTotal
$k->{'key'} ? : 0 0 0
131 }
132 }
133 0 return $data;
134 }
135  
136 sub unserialize {
137 0 ▶ my ($class,$data) = @_;
Subroutine unserialize: not called CC=7 SCAR=40.3
Pod documented
138 0 ▶ unpack("N",substr($data,0,4,'')) == 2 or
Branch: 1 branch
BranchTrueFalseTotal
unpack("N", substr($data, 0, 4, '')) == 2 or croak("serialized with wrong version") 0 0 0
139 croak("serialized with wrong version");
140 0 ( my $cacert,my $cakey,my $certkey,my $serial,$data)
141 = unpack("N/aN/aN/aNa*",$data);
142 0 ▶ my $self = bless {
Branch: 1 branch
BranchTrueFalseTotal
$certkey ? : 0 0 0
Condition0%0/3
ref $class || $class
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $class || $class
ref $class $class
Truth table0%0/3
A || B
A= ref $classB= $class
ABresult
1X1
011
000
143 serial => $serial,
144 cacert => PEM_string2cert($cacert),
145 cakey => PEM_string2key($cakey),
146 $certkey ? ( certkey => PEM_string2key($certkey)):(),
147 }, ref($class)||$class;
148  
149 0 ▶ $self->{cache} = {} if $data ne '';
Branch: 1 branch
BranchTrueFalseTotal
if $data ne "" 0 0 0
150 0 ▶ while ( $data ne '' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($data ne "") 0 0 0
151 0 (my $key,my $cert,my $certkey, my $atime,$data) = unpack("N/aN/aNa*",$data);
152 0 ▶ $self->{cache}{$key} = {
Branch: 1 branch
BranchTrueFalseTotal
$key ? : 0 0 0
153 cert => PEM_string2cert($cert),
154 $key ? ( key => PEM_string2key($certkey)):(),
155 atime => $atime
156 };
157 }
158 0 return $self;
159 }
160  
161 1 1;
162  
163 __END__
« SSL/PublicSuffix.pm ↑ Summary