| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Test::Net::SSLeay; |
|
2
|
|
|
|
|
|
|
|
|
3
|
59
|
|
|
59
|
|
30880
|
use 5.008001; |
|
|
59
|
|
|
|
|
191
|
|
|
4
|
59
|
|
|
56
|
|
227
|
use strict; |
|
|
56
|
|
|
|
|
70
|
|
|
|
56
|
|
|
|
|
980
|
|
|
5
|
56
|
|
|
56
|
|
207
|
use warnings; |
|
|
56
|
|
|
|
|
315
|
|
|
|
56
|
|
|
|
|
1498
|
|
|
6
|
56
|
|
|
56
|
|
208
|
use base qw(Exporter); |
|
|
56
|
|
|
|
|
77
|
|
|
|
56
|
|
|
|
|
9844
|
|
|
7
|
|
|
|
|
|
|
|
|
8
|
56
|
|
|
56
|
|
327
|
use Carp qw(croak); |
|
|
56
|
|
|
|
|
72
|
|
|
|
56
|
|
|
|
|
2475
|
|
|
9
|
56
|
|
|
56
|
|
253
|
use Config; |
|
|
56
|
|
|
|
|
80
|
|
|
|
56
|
|
|
|
|
3141
|
|
|
10
|
56
|
|
|
56
|
|
830
|
use Cwd qw(abs_path); |
|
|
56
|
|
|
|
|
93
|
|
|
|
56
|
|
|
|
|
3908
|
|
|
11
|
56
|
|
|
56
|
|
21286
|
use English qw( $EVAL_ERROR $OSNAME $PERL_VERSION -no_match_vars ); |
|
|
56
|
|
|
|
|
90552
|
|
|
|
56
|
|
|
|
|
342
|
|
|
12
|
56
|
|
|
56
|
|
10763
|
use File::Basename qw(dirname); |
|
|
56
|
|
|
|
|
78
|
|
|
|
56
|
|
|
|
|
4416
|
|
|
13
|
56
|
|
|
56
|
|
19183
|
use File::Spec::Functions qw( abs2rel catfile ); |
|
|
56
|
|
|
|
|
38841
|
|
|
|
56
|
|
|
|
|
3059
|
|
|
14
|
56
|
|
|
56
|
|
28001
|
use Test::Builder; |
|
|
56
|
|
|
|
|
2496115
|
|
|
|
56
|
|
|
|
|
1618
|
|
|
15
|
56
|
|
|
56
|
|
22432
|
use Test::Net::SSLeay::Socket; |
|
|
56
|
|
|
|
|
123
|
|
|
|
56
|
|
|
|
|
111731
|
|
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
our $VERSION = '1.93_01'; |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
our @EXPORT_OK = qw( |
|
20
|
|
|
|
|
|
|
can_fork can_really_fork can_thread |
|
21
|
|
|
|
|
|
|
data_file_path |
|
22
|
|
|
|
|
|
|
dies_like |
|
23
|
|
|
|
|
|
|
dies_ok |
|
24
|
|
|
|
|
|
|
doesnt_warn |
|
25
|
|
|
|
|
|
|
initialise_libssl |
|
26
|
|
|
|
|
|
|
is_libressl is_openssl |
|
27
|
|
|
|
|
|
|
is_protocol_usable |
|
28
|
|
|
|
|
|
|
lives_ok |
|
29
|
|
|
|
|
|
|
new_ctx |
|
30
|
|
|
|
|
|
|
protocols |
|
31
|
|
|
|
|
|
|
tcp_socket |
|
32
|
|
|
|
|
|
|
warns_like |
|
33
|
|
|
|
|
|
|
); |
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
my $tester = Test::Builder->new(); |
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
my $data_path = catfile( dirname(__FILE__), '..', '..', '..', 't', 'data' ); |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
my $initialised = 0; |
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
my %protos = ( |
|
42
|
|
|
|
|
|
|
'TLSv1.3' => { |
|
43
|
|
|
|
|
|
|
constant => \&Net::SSLeay::TLS1_3_VERSION, |
|
44
|
|
|
|
|
|
|
constant_type => 'version', |
|
45
|
|
|
|
|
|
|
priority => 6, |
|
46
|
|
|
|
|
|
|
}, |
|
47
|
|
|
|
|
|
|
'TLSv1.2' => { |
|
48
|
|
|
|
|
|
|
constant => \&Net::SSLeay::TLSv1_2_method, |
|
49
|
|
|
|
|
|
|
constant_type => 'method', |
|
50
|
|
|
|
|
|
|
priority => 5, |
|
51
|
|
|
|
|
|
|
}, |
|
52
|
|
|
|
|
|
|
'TLSv1.1' => { |
|
53
|
|
|
|
|
|
|
constant => \&Net::SSLeay::TLSv1_1_method, |
|
54
|
|
|
|
|
|
|
constant_type => 'method', |
|
55
|
|
|
|
|
|
|
priority => 4, |
|
56
|
|
|
|
|
|
|
}, |
|
57
|
|
|
|
|
|
|
'TLSv1' => { |
|
58
|
|
|
|
|
|
|
constant => \&Net::SSLeay::TLSv1_method, |
|
59
|
|
|
|
|
|
|
constant_type => 'method', |
|
60
|
|
|
|
|
|
|
priority => 3, |
|
61
|
|
|
|
|
|
|
}, |
|
62
|
|
|
|
|
|
|
'SSLv3' => { |
|
63
|
|
|
|
|
|
|
constant => \&Net::SSLeay::SSLv3_method, |
|
64
|
|
|
|
|
|
|
constant_type => 'method', |
|
65
|
|
|
|
|
|
|
priority => 2, |
|
66
|
|
|
|
|
|
|
}, |
|
67
|
|
|
|
|
|
|
'SSLv2' => { |
|
68
|
|
|
|
|
|
|
constant => \&Net::SSLeay::SSLv2_method, |
|
69
|
|
|
|
|
|
|
constant_type => 'method', |
|
70
|
|
|
|
|
|
|
priority => 1, |
|
71
|
|
|
|
|
|
|
}, |
|
72
|
|
|
|
|
|
|
); |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
my ( $test_no_warnings, $test_no_warnings_name, @warnings ); |
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
END { |
|
77
|
56
|
100
|
|
56
|
|
5362166
|
_test_no_warnings() if $test_no_warnings; |
|
78
|
|
|
|
|
|
|
} |
|
79
|
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
sub _all { |
|
81
|
2
|
|
|
2
|
|
4
|
my ( $sub, @list ) = @_; |
|
82
|
|
|
|
|
|
|
|
|
83
|
2
|
|
|
|
|
3
|
for (@list) { |
|
84
|
2
|
50
|
|
|
|
3
|
$sub->() or return 0; |
|
85
|
|
|
|
|
|
|
} |
|
86
|
|
|
|
|
|
|
|
|
87
|
2
|
|
|
|
|
4
|
return 1; |
|
88
|
|
|
|
|
|
|
} |
|
89
|
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
sub _diag { |
|
91
|
0
|
|
|
0
|
|
0
|
my (%args) = @_; |
|
92
|
|
|
|
|
|
|
|
|
93
|
0
|
|
|
|
|
0
|
$tester->diag( ' ' x 9, 'got: ', $args{got} ); |
|
94
|
0
|
|
|
|
|
0
|
$tester->diag( ' ' x 4, 'expected: ', $args{expected} ); |
|
95
|
|
|
|
|
|
|
} |
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
sub _libssl_fatal { |
|
98
|
0
|
|
|
0
|
|
0
|
my ($context) = @_; |
|
99
|
|
|
|
|
|
|
|
|
100
|
0
|
|
|
|
|
0
|
croak "$context: " |
|
101
|
|
|
|
|
|
|
. Net::SSLeay::ERR_error_string( Net::SSLeay::ERR_get_error() ); |
|
102
|
|
|
|
|
|
|
} |
|
103
|
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
sub _load_net_ssleay { |
|
105
|
335
|
50
|
|
335
|
|
472
|
eval { require Net::SSLeay; 1; } or croak $EVAL_ERROR; |
|
|
335
|
|
|
|
|
2238
|
|
|
|
335
|
|
|
|
|
801
|
|
|
106
|
|
|
|
|
|
|
|
|
107
|
335
|
|
|
|
|
389
|
return 1; |
|
108
|
|
|
|
|
|
|
} |
|
109
|
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
sub _test_no_warnings { |
|
111
|
1
|
|
|
1
|
|
3
|
my $got_str = join q{, }, map { qq{'$_'} } @warnings; |
|
|
0
|
|
|
|
|
0
|
|
|
112
|
1
|
50
|
|
|
|
3
|
my $got_type = @warnings == 1 ? 'warning' : 'warnings'; |
|
113
|
|
|
|
|
|
|
|
|
114
|
1
|
50
|
|
|
|
2
|
$tester->ok( @warnings == 0, $test_no_warnings_name ) |
|
115
|
|
|
|
|
|
|
or _diag( |
|
116
|
|
|
|
|
|
|
got => "$got_type $got_str", |
|
117
|
|
|
|
|
|
|
expected => 'no warnings', |
|
118
|
|
|
|
|
|
|
); |
|
119
|
|
|
|
|
|
|
} |
|
120
|
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
sub import { |
|
122
|
59
|
|
|
59
|
|
2484
|
my ( $class, @imports ) = @_; |
|
123
|
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
# Enable strict and warnings in the caller |
|
125
|
59
|
|
|
|
|
409
|
strict->import; |
|
126
|
59
|
|
|
|
|
645
|
warnings->import; |
|
127
|
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
# Import common modules into the caller's namespace |
|
129
|
59
|
|
|
|
|
168
|
my $caller = caller; |
|
130
|
59
|
|
|
|
|
140
|
for (qw(Test::More)) { |
|
131
|
56
|
50
|
|
56
|
|
28865
|
eval "package $caller; use $_; 1;" or croak $EVAL_ERROR; |
|
|
56
|
|
|
|
|
260725
|
|
|
|
56
|
|
|
|
|
426
|
|
|
|
59
|
|
|
|
|
3069
|
|
|
132
|
|
|
|
|
|
|
} |
|
133
|
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
# Import requested Test::Net::SSLeay symbols into the caller's namespace |
|
135
|
59
|
|
|
|
|
7746
|
__PACKAGE__->export_to_level( 1, $class, @imports ); |
|
136
|
|
|
|
|
|
|
|
|
137
|
59
|
|
|
|
|
2256299
|
return 1; |
|
138
|
|
|
|
|
|
|
} |
|
139
|
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
sub can_fork { |
|
141
|
23
|
50
|
|
23
|
1
|
1481
|
return 1 if can_really_fork(); |
|
142
|
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
# Some platforms provide fork emulation using ithreads |
|
144
|
0
|
0
|
|
|
|
0
|
return 1 if $Config{d_pseudofork}; |
|
145
|
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
# d_pseudofork was added in Perl 5.10.0 - this is an approximation for |
|
147
|
|
|
|
|
|
|
# older Perls |
|
148
|
0
|
0
|
0
|
|
|
0
|
if ( ( $OSNAME eq 'Win32' or $OSNAME eq 'NetWare' ) |
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
149
|
|
|
|
|
|
|
and $Config{useithreads} |
|
150
|
|
|
|
|
|
|
and $Config{ccflags} =~ /-DPERL_IMPLICIT_SYS/ ) |
|
151
|
|
|
|
|
|
|
{ |
|
152
|
0
|
|
|
|
|
0
|
return 1; |
|
153
|
|
|
|
|
|
|
} |
|
154
|
|
|
|
|
|
|
|
|
155
|
0
|
|
|
|
|
0
|
return can_thread(); |
|
156
|
|
|
|
|
|
|
} |
|
157
|
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
sub can_really_fork { |
|
159
|
25
|
50
|
|
25
|
1
|
1694
|
return 1 if $Config{d_fork}; |
|
160
|
|
|
|
|
|
|
|
|
161
|
0
|
|
|
|
|
0
|
return 0; |
|
162
|
|
|
|
|
|
|
} |
|
163
|
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
sub can_thread { |
|
165
|
2
|
50
|
|
2
|
1
|
148
|
return 0 if not $Config{useithreads}; |
|
166
|
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
# Threads are broken in Perl 5.10.0 when compiled with GCC 4.8 or above |
|
168
|
|
|
|
|
|
|
# (see GH #175) |
|
169
|
0
|
0
|
0
|
|
|
0
|
if ( $PERL_VERSION == 5.010000 |
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
170
|
|
|
|
|
|
|
and $Config{ccname} eq 'gcc' |
|
171
|
|
|
|
|
|
|
and defined $Config{gccversion} |
|
172
|
|
|
|
|
|
|
# gccversion is sometimes defined for non-GCC compilers (see GH-350); |
|
173
|
|
|
|
|
|
|
# compilers that are truly GCC are identified with a version number in |
|
174
|
|
|
|
|
|
|
# gccversion |
|
175
|
|
|
|
|
|
|
and $Config{gccversion} =~ /^\d+\.\d+/ ) |
|
176
|
|
|
|
|
|
|
{ |
|
177
|
0
|
|
|
|
|
0
|
my ( $gcc_major, $gcc_minor ) = split /[.\s]+/, $Config{gccversion}; |
|
178
|
|
|
|
|
|
|
|
|
179
|
0
|
0
|
0
|
|
|
0
|
return 0 |
|
|
|
|
0
|
|
|
|
|
|
180
|
|
|
|
|
|
|
if ( $gcc_major > 4 or ( $gcc_major == 4 and $gcc_minor >= 8 ) ); |
|
181
|
|
|
|
|
|
|
} |
|
182
|
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
# Devel::Cover doesn't (currently) work with threads |
|
184
|
0
|
0
|
|
|
|
0
|
return 0 if $INC{'Devel/Cover.pm'}; |
|
185
|
|
|
|
|
|
|
|
|
186
|
0
|
|
|
|
|
0
|
return 1; |
|
187
|
|
|
|
|
|
|
} |
|
188
|
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
sub data_file_path { |
|
190
|
90
|
|
|
90
|
1
|
57154
|
my ($data_file) = @_; |
|
191
|
|
|
|
|
|
|
|
|
192
|
90
|
|
|
|
|
4191
|
my $abs_path = catfile( abs_path($data_path), $data_file ); |
|
193
|
90
|
|
|
|
|
488
|
my $rel_path = abs2rel($abs_path); |
|
194
|
|
|
|
|
|
|
|
|
195
|
90
|
50
|
|
|
|
8203
|
croak "$rel_path: data file does not exist" |
|
196
|
|
|
|
|
|
|
if not -e $abs_path; |
|
197
|
|
|
|
|
|
|
|
|
198
|
90
|
|
|
|
|
2299
|
return $rel_path; |
|
199
|
|
|
|
|
|
|
} |
|
200
|
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
sub dies_like { |
|
202
|
677
|
|
|
677
|
1
|
11038
|
my ( $sub, $expected, $name ) = @_; |
|
203
|
|
|
|
|
|
|
|
|
204
|
677
|
|
|
|
|
572
|
my ( $got, $ok ); |
|
205
|
|
|
|
|
|
|
|
|
206
|
677
|
50
|
|
|
|
552
|
if ( eval { $sub->(); 1 } ) { |
|
|
677
|
|
|
|
|
869
|
|
|
|
0
|
|
|
|
|
0
|
|
|
207
|
0
|
|
|
|
|
0
|
$ok = $tester->ok ( 0, $name ); |
|
208
|
|
|
|
|
|
|
|
|
209
|
0
|
|
|
|
|
0
|
_diag( |
|
210
|
|
|
|
|
|
|
got => 'subroutine lived', |
|
211
|
|
|
|
|
|
|
expected => "subroutine died with exception matching $expected", |
|
212
|
|
|
|
|
|
|
); |
|
213
|
|
|
|
|
|
|
} |
|
214
|
|
|
|
|
|
|
else { |
|
215
|
677
|
|
|
|
|
4200
|
$got = $EVAL_ERROR; |
|
216
|
|
|
|
|
|
|
|
|
217
|
677
|
|
|
|
|
2225
|
my $test = $got =~ $expected; |
|
218
|
|
|
|
|
|
|
|
|
219
|
677
|
50
|
|
|
|
1640
|
$ok = $tester->ok( $test, $name ) |
|
220
|
|
|
|
|
|
|
or _diag( |
|
221
|
|
|
|
|
|
|
got => qq{subroutine died with exception '$got'}, |
|
222
|
|
|
|
|
|
|
expected => "subroutine died with exception matching $expected", |
|
223
|
|
|
|
|
|
|
); |
|
224
|
|
|
|
|
|
|
} |
|
225
|
|
|
|
|
|
|
|
|
226
|
677
|
|
|
|
|
191579
|
$EVAL_ERROR = $got; |
|
227
|
|
|
|
|
|
|
|
|
228
|
677
|
|
|
|
|
1392
|
return $ok; |
|
229
|
|
|
|
|
|
|
} |
|
230
|
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
sub dies_ok { |
|
232
|
0
|
|
|
0
|
1
|
0
|
my ( $sub, $name ) = @_; |
|
233
|
|
|
|
|
|
|
|
|
234
|
0
|
|
|
|
|
0
|
my ( $got, $ok ); |
|
235
|
|
|
|
|
|
|
|
|
236
|
0
|
0
|
|
|
|
0
|
if ( eval { $sub->(); 1 } ) { |
|
|
0
|
|
|
|
|
0
|
|
|
|
0
|
|
|
|
|
0
|
|
|
237
|
0
|
|
|
|
|
0
|
$got = $EVAL_ERROR; |
|
238
|
|
|
|
|
|
|
|
|
239
|
0
|
|
|
|
|
0
|
$ok = $tester->ok ( 0, $name ); |
|
240
|
|
|
|
|
|
|
|
|
241
|
0
|
|
|
|
|
0
|
_diag( |
|
242
|
|
|
|
|
|
|
got => 'subroutine lived', |
|
243
|
|
|
|
|
|
|
expected => 'subroutine died', |
|
244
|
|
|
|
|
|
|
); |
|
245
|
|
|
|
|
|
|
} |
|
246
|
|
|
|
|
|
|
else { |
|
247
|
0
|
|
|
|
|
0
|
$got = $EVAL_ERROR; |
|
248
|
|
|
|
|
|
|
|
|
249
|
0
|
|
|
|
|
0
|
$ok = $tester->ok( 1, $name ); |
|
250
|
|
|
|
|
|
|
} |
|
251
|
|
|
|
|
|
|
|
|
252
|
0
|
|
|
|
|
0
|
$EVAL_ERROR = $got; |
|
253
|
|
|
|
|
|
|
|
|
254
|
0
|
|
|
|
|
0
|
return $ok; |
|
255
|
|
|
|
|
|
|
} |
|
256
|
|
|
|
|
|
|
|
|
257
|
|
|
|
|
|
|
sub doesnt_warn { |
|
258
|
1
|
|
|
1
|
1
|
940
|
$test_no_warnings = 1; |
|
259
|
1
|
|
|
|
|
2
|
$test_no_warnings_name = shift; |
|
260
|
|
|
|
|
|
|
|
|
261
|
1
|
|
|
0
|
|
6
|
$SIG{__WARN__} = sub { push @warnings, shift }; |
|
|
0
|
|
|
|
|
0
|
|
|
262
|
|
|
|
|
|
|
} |
|
263
|
|
|
|
|
|
|
|
|
264
|
|
|
|
|
|
|
sub initialise_libssl { |
|
265
|
305
|
100
|
|
305
|
1
|
30288
|
return 1 if $initialised; |
|
266
|
|
|
|
|
|
|
|
|
267
|
42
|
|
|
|
|
150
|
_load_net_ssleay(); |
|
268
|
|
|
|
|
|
|
|
|
269
|
42
|
|
|
|
|
349
|
Net::SSLeay::randomize(); |
|
270
|
|
|
|
|
|
|
|
|
271
|
|
|
|
|
|
|
# Error strings aren't loaded by default until OpenSSL 1.1.0, but it's safe |
|
272
|
|
|
|
|
|
|
# to load them unconditionally because these functions are simply no-ops in |
|
273
|
|
|
|
|
|
|
# later OpenSSL versions |
|
274
|
42
|
|
|
|
|
53565
|
Net::SSLeay::load_error_strings(); |
|
275
|
42
|
|
|
|
|
1035
|
Net::SSLeay::ERR_load_crypto_strings(); |
|
276
|
|
|
|
|
|
|
|
|
277
|
42
|
|
|
|
|
2923
|
Net::SSLeay::library_init(); |
|
278
|
|
|
|
|
|
|
|
|
279
|
|
|
|
|
|
|
# The test suite makes heavy use of SHA-256, but SHA-256 isn't registered by |
|
280
|
|
|
|
|
|
|
# default in all OpenSSL versions - register it manually when Net::SSLeay is |
|
281
|
|
|
|
|
|
|
# built against the following OpenSSL versions: |
|
282
|
|
|
|
|
|
|
|
|
283
|
|
|
|
|
|
|
# OpenSSL 0.9.8 series < 0.9.8o |
|
284
|
42
|
50
|
|
|
|
808
|
Net::SSLeay::OpenSSL_add_all_digests() |
|
285
|
|
|
|
|
|
|
if Net::SSLeay::constant('OPENSSL_VERSION_NUMBER') < 0x009080ff; |
|
286
|
|
|
|
|
|
|
|
|
287
|
|
|
|
|
|
|
# OpenSSL 1.0.0 series < 1.0.0a |
|
288
|
42
|
50
|
33
|
|
|
448
|
Net::SSLeay::OpenSSL_add_all_digests() |
|
289
|
|
|
|
|
|
|
if Net::SSLeay::constant('OPENSSL_VERSION_NUMBER') >= 0x10000000 |
|
290
|
|
|
|
|
|
|
&& Net::SSLeay::constant('OPENSSL_VERSION_NUMBER') < 0x1000001f; |
|
291
|
|
|
|
|
|
|
|
|
292
|
42
|
|
|
|
|
109
|
$initialised = 1; |
|
293
|
|
|
|
|
|
|
|
|
294
|
42
|
|
|
|
|
157
|
return 1; |
|
295
|
|
|
|
|
|
|
} |
|
296
|
|
|
|
|
|
|
|
|
297
|
|
|
|
|
|
|
sub is_libressl { |
|
298
|
5
|
|
|
5
|
1
|
1809
|
_load_net_ssleay(); |
|
299
|
|
|
|
|
|
|
|
|
300
|
|
|
|
|
|
|
# The most foolproof method of checking whether libssl is provided by |
|
301
|
|
|
|
|
|
|
# LibreSSL is by checking OPENSSL_VERSION_NUMBER: every version of |
|
302
|
|
|
|
|
|
|
# LibreSSL identifies itself as OpenSSL 2.0.0, which is a version number |
|
303
|
|
|
|
|
|
|
# that OpenSSL itself will never use (version 3.0.0 follows 1.1.1) |
|
304
|
5
|
50
|
|
|
|
85
|
return 0 |
|
305
|
|
|
|
|
|
|
if Net::SSLeay::constant('OPENSSL_VERSION_NUMBER') != 0x20000000; |
|
306
|
|
|
|
|
|
|
|
|
307
|
0
|
|
|
|
|
0
|
return 1; |
|
308
|
|
|
|
|
|
|
} |
|
309
|
|
|
|
|
|
|
|
|
310
|
|
|
|
|
|
|
sub is_openssl { |
|
311
|
25
|
|
|
25
|
1
|
234947
|
_load_net_ssleay(); |
|
312
|
|
|
|
|
|
|
|
|
313
|
|
|
|
|
|
|
# "OpenSSL 2.0.0" is actually LibreSSL |
|
314
|
25
|
50
|
|
|
|
206
|
return 0 |
|
315
|
|
|
|
|
|
|
if Net::SSLeay::constant('OPENSSL_VERSION_NUMBER') == 0x20000000; |
|
316
|
|
|
|
|
|
|
|
|
317
|
25
|
|
|
|
|
97
|
return 1; |
|
318
|
|
|
|
|
|
|
} |
|
319
|
|
|
|
|
|
|
|
|
320
|
|
|
|
|
|
|
sub is_protocol_usable { |
|
321
|
263
|
|
|
263
|
1
|
449
|
my ($proto) = @_; |
|
322
|
|
|
|
|
|
|
|
|
323
|
263
|
|
|
|
|
621
|
_load_net_ssleay(); |
|
324
|
263
|
|
|
|
|
594
|
initialise_libssl(); |
|
325
|
|
|
|
|
|
|
|
|
326
|
263
|
|
|
|
|
600
|
my $proto_data = $protos{$proto}; |
|
327
|
|
|
|
|
|
|
|
|
328
|
|
|
|
|
|
|
# If libssl does not support this protocol version, or if it was disabled at |
|
329
|
|
|
|
|
|
|
# compile-time, the appropriate method for that version will be missing |
|
330
|
263
|
100
|
|
|
|
540
|
if ( |
|
|
|
100
|
|
|
|
|
|
|
331
|
|
|
|
|
|
|
$proto_data->{constant_type} eq 'version' |
|
332
|
40
|
|
|
|
|
58
|
? !eval { &{ $proto_data->{constant} }; 1 } |
|
|
40
|
|
|
|
|
1568
|
|
|
|
0
|
|
|
|
|
0
|
|
|
333
|
223
|
|
|
|
|
517
|
: !defined &{ $proto_data->{constant} } |
|
334
|
|
|
|
|
|
|
) { |
|
335
|
116
|
|
|
|
|
360
|
return 0; |
|
336
|
|
|
|
|
|
|
} |
|
337
|
|
|
|
|
|
|
|
|
338
|
|
|
|
|
|
|
# If libssl was built with support for this protocol version, the only |
|
339
|
|
|
|
|
|
|
# reliable way to test whether its use is permitted by the security policy |
|
340
|
|
|
|
|
|
|
# is to attempt to create a connection that uses it - if it is permitted, |
|
341
|
|
|
|
|
|
|
# the state machine enters the following states: |
|
342
|
|
|
|
|
|
|
# |
|
343
|
|
|
|
|
|
|
# SSL_CB_HANDSHAKE_START (ret=1) |
|
344
|
|
|
|
|
|
|
# SSL_CB_CONNECT_LOOP (ret=1) |
|
345
|
|
|
|
|
|
|
# SSL_CB_CONNECT_EXIT (ret=-1) |
|
346
|
|
|
|
|
|
|
# |
|
347
|
|
|
|
|
|
|
# If it is not permitted, the state machine instead enters the following |
|
348
|
|
|
|
|
|
|
# states: |
|
349
|
|
|
|
|
|
|
# |
|
350
|
|
|
|
|
|
|
# SSL_CB_HANDSHAKE_START (ret=1) |
|
351
|
|
|
|
|
|
|
# SSL_CB_CONNECT_EXIT (ret=-1) |
|
352
|
|
|
|
|
|
|
# |
|
353
|
|
|
|
|
|
|
# Additionally, ERR_get_error() returns the error code 0x14161044, although |
|
354
|
|
|
|
|
|
|
# this might not necessarily be guaranteed for all libssl versions, so |
|
355
|
|
|
|
|
|
|
# testing for it may be unreliable |
|
356
|
|
|
|
|
|
|
|
|
357
|
147
|
|
|
|
|
940
|
my $constant = $proto_data->{constant}->(); |
|
358
|
147
|
|
|
|
|
169
|
my $ctx; |
|
359
|
|
|
|
|
|
|
|
|
360
|
147
|
50
|
|
|
|
278
|
if ( $proto_data->{constant_type} eq 'version' ) { |
|
361
|
0
|
0
|
|
|
|
0
|
$ctx = Net::SSLeay::CTX_new_with_method( Net::SSLeay::TLS_method() ) |
|
362
|
|
|
|
|
|
|
or _libssl_fatal('Failed to create libssl SSL_CTX object'); |
|
363
|
|
|
|
|
|
|
|
|
364
|
0
|
|
|
|
|
0
|
Net::SSLeay::CTX_set_min_proto_version( $ctx, $constant ); |
|
365
|
0
|
|
|
|
|
0
|
Net::SSLeay::CTX_set_max_proto_version( $ctx, $constant ); |
|
366
|
|
|
|
|
|
|
} |
|
367
|
|
|
|
|
|
|
else { |
|
368
|
147
|
50
|
|
|
|
10666
|
$ctx = Net::SSLeay::CTX_new_with_method($constant) |
|
369
|
|
|
|
|
|
|
or _libssl_fatal('Failed to create SSL_CTX object'); |
|
370
|
|
|
|
|
|
|
} |
|
371
|
|
|
|
|
|
|
|
|
372
|
147
|
50
|
|
|
|
1233
|
my $ssl = Net::SSLeay::new($ctx) |
|
373
|
|
|
|
|
|
|
or _libssl_fatal('Failed to create SSL structure'); |
|
374
|
|
|
|
|
|
|
|
|
375
|
|
|
|
|
|
|
# For the purposes of this test, it isn't necessary to link the SSL |
|
376
|
|
|
|
|
|
|
# structure to a file descriptor, since no data actually needs to be sent or |
|
377
|
|
|
|
|
|
|
# received |
|
378
|
147
|
50
|
|
|
|
582
|
Net::SSLeay::set_fd( $ssl, -1 ) |
|
379
|
|
|
|
|
|
|
or _libssl_fatal('Failed to set file descriptor for SSL structure'); |
|
380
|
|
|
|
|
|
|
|
|
381
|
147
|
|
|
|
|
183
|
my @states; |
|
382
|
|
|
|
|
|
|
|
|
383
|
|
|
|
|
|
|
Net::SSLeay::CTX_set_info_callback( |
|
384
|
|
|
|
|
|
|
$ctx, |
|
385
|
|
|
|
|
|
|
sub { |
|
386
|
441
|
|
|
441
|
|
663
|
my ( $ssl, $where, $ret, $data ) = @_; |
|
387
|
|
|
|
|
|
|
|
|
388
|
441
|
|
|
|
|
5657
|
push @states, $where; |
|
389
|
|
|
|
|
|
|
} |
|
390
|
147
|
|
|
|
|
3416
|
); |
|
391
|
|
|
|
|
|
|
|
|
392
|
147
|
50
|
|
|
|
1396
|
Net::SSLeay::connect($ssl) |
|
393
|
|
|
|
|
|
|
or _libssl_fatal('Failed to initiate connection'); |
|
394
|
|
|
|
|
|
|
|
|
395
|
147
|
|
|
|
|
3476
|
my $disabled = Net::SSLeay::CB_HANDSHAKE_START() |
|
396
|
|
|
|
|
|
|
+ Net::SSLeay::CB_CONNECT_EXIT(); |
|
397
|
|
|
|
|
|
|
|
|
398
|
147
|
|
|
|
|
1785
|
my $enabled = Net::SSLeay::CB_HANDSHAKE_START() |
|
399
|
|
|
|
|
|
|
+ Net::SSLeay::CB_CONNECT_LOOP() |
|
400
|
|
|
|
|
|
|
+ Net::SSLeay::CB_CONNECT_EXIT(); |
|
401
|
|
|
|
|
|
|
|
|
402
|
147
|
|
|
|
|
1761
|
Net::SSLeay::free($ssl); |
|
403
|
147
|
|
|
|
|
1109
|
Net::SSLeay::CTX_free($ctx); |
|
404
|
|
|
|
|
|
|
|
|
405
|
147
|
|
|
|
|
160
|
my $observed = 0; |
|
406
|
147
|
|
|
|
|
271
|
for my $state (@states) { |
|
407
|
441
|
|
|
|
|
401
|
$observed += $state; |
|
408
|
|
|
|
|
|
|
} |
|
409
|
|
|
|
|
|
|
|
|
410
|
147
|
50
|
|
|
|
1315
|
return 0 if $observed == $disabled; |
|
411
|
147
|
50
|
|
|
|
429
|
return 1 if $observed == $enabled; |
|
412
|
|
|
|
|
|
|
|
|
413
|
0
|
|
|
|
|
0
|
croak 'Unexpected TLS state machine sequence: ' . join( ', ', @states ); |
|
414
|
|
|
|
|
|
|
} |
|
415
|
|
|
|
|
|
|
|
|
416
|
|
|
|
|
|
|
sub lives_ok { |
|
417
|
10
|
|
|
10
|
1
|
1845
|
my ( $sub, $name ) = @_; |
|
418
|
|
|
|
|
|
|
|
|
419
|
10
|
|
|
|
|
17
|
my ( $got, $ok ); |
|
420
|
|
|
|
|
|
|
|
|
421
|
10
|
50
|
|
|
|
12
|
if ( !eval { $sub->(); 1 } ) { |
|
|
10
|
|
|
|
|
36
|
|
|
|
10
|
|
|
|
|
752343
|
|
|
422
|
0
|
|
|
|
|
0
|
$got = $EVAL_ERROR; |
|
423
|
|
|
|
|
|
|
|
|
424
|
0
|
|
|
|
|
0
|
$ok = $tester->ok ( 0, $name ); |
|
425
|
|
|
|
|
|
|
|
|
426
|
0
|
|
|
|
|
0
|
_diag( |
|
427
|
|
|
|
|
|
|
got => qq{subroutine died with exception '$got'}, |
|
428
|
|
|
|
|
|
|
expected => 'subroutine lived', |
|
429
|
|
|
|
|
|
|
); |
|
430
|
|
|
|
|
|
|
} |
|
431
|
|
|
|
|
|
|
else { |
|
432
|
10
|
|
|
|
|
42
|
$got = $EVAL_ERROR; |
|
433
|
|
|
|
|
|
|
|
|
434
|
10
|
|
|
|
|
50
|
$ok = $tester->ok( 1, $name ); |
|
435
|
|
|
|
|
|
|
} |
|
436
|
|
|
|
|
|
|
|
|
437
|
10
|
|
|
|
|
4933
|
$EVAL_ERROR = $got; |
|
438
|
|
|
|
|
|
|
|
|
439
|
10
|
|
|
|
|
23
|
return $ok; |
|
440
|
|
|
|
|
|
|
} |
|
441
|
|
|
|
|
|
|
|
|
442
|
|
|
|
|
|
|
sub new_ctx { |
|
443
|
53
|
|
|
53
|
1
|
11333
|
my ( $min_proto, $max_proto ) = @_; |
|
444
|
|
|
|
|
|
|
|
|
445
|
|
|
|
|
|
|
my @usable_protos = |
|
446
|
|
|
|
|
|
|
# Exclude protocol versions not supported by this libssl: |
|
447
|
|
|
|
|
|
|
grep { |
|
448
|
241
|
|
|
|
|
604
|
is_protocol_usable($_) |
|
449
|
|
|
|
|
|
|
} |
|
450
|
|
|
|
|
|
|
# Exclude protocol versions outside the desired range: |
|
451
|
|
|
|
|
|
|
grep { |
|
452
|
53
|
|
|
|
|
336
|
( |
|
453
|
|
|
|
|
|
|
defined $min_proto |
|
454
|
|
|
|
|
|
|
? $protos{$_}->{priority} >= $protos{$min_proto}->{priority} |
|
455
|
|
|
|
|
|
|
: 1 |
|
456
|
|
|
|
|
|
|
) |
|
457
|
|
|
|
|
|
|
&& ( |
|
458
|
|
|
|
|
|
|
defined $max_proto |
|
459
|
|
|
|
|
|
|
? $protos{$_}->{priority} <= $protos{$max_proto}->{priority} |
|
460
|
318
|
100
|
|
|
|
1330
|
: 1 |
|
|
|
100
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
461
|
|
|
|
|
|
|
) |
|
462
|
|
|
|
|
|
|
} |
|
463
|
|
|
|
|
|
|
protocols(); |
|
464
|
|
|
|
|
|
|
|
|
465
|
53
|
50
|
|
|
|
177
|
croak 'Failed to create libssl SSL_CTX object: no usable protocol versions' |
|
466
|
|
|
|
|
|
|
if !@usable_protos; |
|
467
|
|
|
|
|
|
|
|
|
468
|
53
|
|
|
|
|
188
|
my $proto = shift @usable_protos; |
|
469
|
53
|
|
|
|
|
184
|
my $constant = $protos{$proto}->{constant}->(); |
|
470
|
53
|
|
|
|
|
87
|
my $ctx; |
|
471
|
|
|
|
|
|
|
|
|
472
|
53
|
50
|
|
|
|
153
|
if ( $protos{$proto}->{constant_type} eq 'version' ) { |
|
473
|
0
|
0
|
|
|
|
0
|
$ctx = Net::SSLeay::CTX_new_with_method( Net::SSLeay::TLS_method() ) |
|
474
|
|
|
|
|
|
|
or _libssl_fatal('Failed to create libssl SSL_CTX object'); |
|
475
|
|
|
|
|
|
|
|
|
476
|
0
|
|
|
|
|
0
|
Net::SSLeay::CTX_set_min_proto_version( $ctx, $constant ); |
|
477
|
0
|
|
|
|
|
0
|
Net::SSLeay::CTX_set_max_proto_version( $ctx, $constant ); |
|
478
|
|
|
|
|
|
|
} |
|
479
|
|
|
|
|
|
|
else { |
|
480
|
53
|
50
|
|
|
|
2560
|
$ctx = Net::SSLeay::CTX_new_with_method($constant) |
|
481
|
|
|
|
|
|
|
or _libssl_fatal('Failed to create SSL_CTX object'); |
|
482
|
|
|
|
|
|
|
} |
|
483
|
|
|
|
|
|
|
|
|
484
|
53
|
100
|
|
|
|
314
|
return wantarray ? ( $ctx, $proto ) |
|
485
|
|
|
|
|
|
|
: $ctx; |
|
486
|
|
|
|
|
|
|
} |
|
487
|
|
|
|
|
|
|
|
|
488
|
|
|
|
|
|
|
sub protocols { |
|
489
|
|
|
|
|
|
|
return |
|
490
|
|
|
|
|
|
|
sort { |
|
491
|
53
|
|
|
53
|
1
|
944
|
$protos{$b}->{priority} <=> $protos{$a}->{priority} |
|
492
|
520
|
|
|
|
|
1107
|
} |
|
493
|
|
|
|
|
|
|
keys %protos; |
|
494
|
|
|
|
|
|
|
} |
|
495
|
|
|
|
|
|
|
|
|
496
|
|
|
|
|
|
|
sub tcp_socket { |
|
497
|
22
|
|
|
22
|
1
|
33240
|
return Test::Net::SSLeay::Socket->new( proto => 'tcp' ); |
|
498
|
|
|
|
|
|
|
} |
|
499
|
|
|
|
|
|
|
|
|
500
|
|
|
|
|
|
|
sub warns_like { |
|
501
|
2
|
|
|
2
|
1
|
37
|
my ( $sub, $expected, $name ) = @_; |
|
502
|
|
|
|
|
|
|
|
|
503
|
2
|
50
|
|
|
|
6
|
my @expected = ref $expected eq 'ARRAY' |
|
504
|
|
|
|
|
|
|
? @$expected |
|
505
|
|
|
|
|
|
|
: ($expected); |
|
506
|
|
|
|
|
|
|
|
|
507
|
2
|
|
|
|
|
2
|
my @got; |
|
508
|
|
|
|
|
|
|
|
|
509
|
2
|
|
|
2
|
|
9
|
local $SIG{__WARN__} = sub { push @got, shift }; |
|
|
2
|
|
|
|
|
12
|
|
|
510
|
|
|
|
|
|
|
|
|
511
|
2
|
|
|
|
|
5
|
$sub->(); |
|
512
|
|
|
|
|
|
|
|
|
513
|
2
|
|
|
|
|
9
|
$SIG{__WARN__} = 'DEFAULT'; |
|
514
|
|
|
|
|
|
|
|
|
515
|
|
|
|
|
|
|
my $test = scalar @got == scalar @expected |
|
516
|
2
|
|
33
|
2
|
|
13
|
&& _all( sub { $got[$_] =~ $expected[$_] }, 0 .. $#got ); |
|
|
2
|
|
|
|
|
12
|
|
|
517
|
|
|
|
|
|
|
|
|
518
|
|
|
|
|
|
|
my $ok = $tester->ok( $test, $name ) |
|
519
|
2
|
50
|
|
|
|
7
|
or do { |
|
520
|
0
|
|
|
|
|
0
|
my $got_str = join q{, }, map { qq{'$_'} } @got; |
|
|
0
|
|
|
|
|
0
|
|
|
521
|
0
|
|
|
|
|
0
|
my $expected_str = join q{, }, map { qq{'$_'} } @expected; |
|
|
0
|
|
|
|
|
0
|
|
|
522
|
|
|
|
|
|
|
|
|
523
|
0
|
0
|
|
|
|
0
|
my $got_plural = @got == 1 ? '' : 's'; |
|
524
|
0
|
0
|
|
|
|
0
|
my $expected_plural = @expected == 1 ? '' : 's'; |
|
525
|
|
|
|
|
|
|
|
|
526
|
0
|
|
|
|
|
0
|
_diag( |
|
527
|
|
|
|
|
|
|
got => "warning$got_plural $got_str", |
|
528
|
|
|
|
|
|
|
expected => "warning$expected_plural matching $expected_str", |
|
529
|
|
|
|
|
|
|
); |
|
530
|
|
|
|
|
|
|
}; |
|
531
|
|
|
|
|
|
|
|
|
532
|
2
|
|
|
|
|
659
|
return $ok; |
|
533
|
|
|
|
|
|
|
} |
|
534
|
|
|
|
|
|
|
|
|
535
|
|
|
|
|
|
|
1; |
|
536
|
|
|
|
|
|
|
|
|
537
|
|
|
|
|
|
|
__END__ |