2 # Copyright 2015-2018 The OpenSSL Project Authors. All Rights Reserved.
4 # Licensed under the Apache License 2.0 (the "License"). You may not use
5 # this file except in compliance with the License. You can obtain a copy
6 # in the file LICENSE in the source distribution or at
7 # https://www.openssl.org/source/license.html
16 use OpenSSL
::Test qw
/:DEFAULT with bldtop_file srctop_file cmdstr/;
17 use OpenSSL
::Test
::Utils
;
21 $ENV{CTLOG_FILE
} = srctop_file
("test", "ct", "log_list.conf");
23 my ($no_rsa, $no_dsa, $no_dh, $no_ec, $no_psk,
24 $no_ssl3, $no_tls1, $no_tls1_1, $no_tls1_2, $no_tls1_3,
25 $no_dtls, $no_dtls1, $no_dtls1_2, $no_ct) =
26 anydisabled qw
/rsa dsa dh ec psk
27 ssl3 tls1 tls1_1 tls1_2 tls1_3
28 dtls dtls1 dtls1_2 ct
/;
29 my $no_anytls = alldisabled
(available_protocols
("tls"));
30 my $no_anydtls = alldisabled
(available_protocols
("dtls"));
32 plan skip_all
=> "No SSL/TLS/DTLS protocol is support by this OpenSSL build"
33 if $no_anytls && $no_anydtls;
36 my @reqcmd = ("openssl", "req");
37 my @x509cmd = ("openssl", "x509", $digest);
38 my @verifycmd = ("openssl", "verify");
39 my @genpkeycmd = ("openssl", "genpkey");
40 my $dummycnf = srctop_file
("apps", "openssl.cnf");
42 my $CAkey = "keyCA.ss";
43 my $CAcert="certCA.ss";
44 my $CAserial="certCA.srl";
46 my $CAconf=srctop_file
("test","CAss.cnf");
47 my $CAreq2="req2CA.ss"; # temp
49 my $Uconf=srctop_file
("test","Uss.cnf");
62 my $P1conf=srctop_file
("test","P1ss.cnf");
65 my $P1cert="certP1.ss";
66 my $P1intermediate="tmp_intP1.ss";
68 my $P2conf=srctop_file
("test","P2ss.cnf");
71 my $P2cert="certP2.ss";
72 my $P2intermediate="tmp_intP2.ss";
74 my $server_sess="server.ss";
75 my $client_sess="client.ss";
77 # ssltest_old.c is deprecated in favour of the new framework in ssl_test.c
78 # If you're adding tests here, you probably want to convert them to the
79 # new format in ssl_test.c and add recipes to 80-test_ssl_new.t instead.
82 +5 # For the first testssl
85 subtest
'test_ss' => sub {
87 open OUT
, ">", "intP1.ss";
88 copy
($CAcert, \
*OUT
); copy
($Ucert, \
*OUT
);
91 open OUT
, ">", "intP2.ss";
92 copy
($CAcert, \
*OUT
); copy
($Ucert, \
*OUT
); copy
($P1cert, \
*OUT
);
97 note
('test_ssl -- key U');
98 testssl
("keyU.ss", $Ucert, $CAcert);
103 my @req_dsa = ("-newkey",
104 "dsa:".srctop_file
("apps", "dsa1024.pem"));
105 my $dsaparams = srctop_file
("apps", "dsa1024.pem");
116 skip
'failure', 16 unless
117 ok
(run
(app
([@reqcmd, "-config", $CAconf,
118 "-out", $CAreq, "-keyout", $CAkey,
120 'make cert request');
122 skip
'failure', 15 unless
123 ok
(run
(app
([@x509cmd, "-CAcreateserial", "-in", $CAreq, "-days", "30",
124 "-req", "-out", $CAcert, "-signkey", $CAkey,
125 "-extfile", $CAconf, "-extensions", "v3_ca"],
126 stdout
=> "err.ss")),
127 'convert request into self-signed cert');
129 skip
'failure', 14 unless
130 ok
(run
(app
([@x509cmd, "-in", $CAcert,
131 "-x509toreq", "-signkey", $CAkey, "-out", $CAreq2],
132 stdout
=> "err.ss")),
133 'convert cert into a cert request');
135 skip
'failure', 13 unless
136 ok
(run
(app
([@reqcmd, "-config", $dummycnf,
137 "-verify", "-in", $CAreq, "-noout"])),
141 skip
'failure', 12 unless
142 ok
(run
(app
([@reqcmd, "-config", $dummycnf,
143 "-verify", "-in", $CAreq2, "-noout"])),
146 skip
'failure', 11 unless
147 ok
(run
(app
([@verifycmd, "-CAfile", $CAcert, $CAcert])),
150 skip
'failure', 10 unless
151 ok
(run
(app
([@reqcmd, "-config", $Uconf,
152 "-out", $Ureq, "-keyout", $Ukey, @req_new],
153 stdout
=> "err.ss")),
154 'make a user cert request');
156 skip
'failure', 9 unless
157 ok
(run
(app
([@x509cmd, "-CAcreateserial", "-in", $Ureq, "-days", "30",
158 "-req", "-out", $Ucert,
159 "-CA", $CAcert, "-CAkey", $CAkey, "-CAserial", $CAserial,
160 "-extfile", $Uconf, "-extensions", "v3_ee"],
162 && run
(app
([@verifycmd, "-CAfile", $CAcert, $Ucert])),
163 'sign user cert request');
165 skip
'failure', 8 unless
166 ok
(run
(app
([@x509cmd,
167 "-subject", "-issuer", "-startdate", "-enddate",
168 "-noout", "-in", $Ucert])),
169 'Certificate details');
171 skip
'failure', 7 unless
172 subtest
'DSA certificate creation' => sub {
173 plan skip_all
=> "skipping DSA certificate creation"
179 $ENV{CN2
} = "DSA Certificate";
180 skip
'failure', 4 unless
181 ok
(run
(app
([@genpkeycmd, "-out", $Dkey,
182 "-paramfile", $dsaparams],
183 stdout
=> "err.ss")),
185 skip
'failure', 3 unless
186 ok
(run
(app
([@reqcmd, "-new", "-config", $Uconf,
187 "-out", $Dreq, "-key", $Dkey],
188 stdout
=> "err.ss")),
189 "make a DSA user cert request");
190 skip
'failure', 2 unless
191 ok
(run
(app
([@x509cmd, "-CAcreateserial",
196 "-CA", $CAcert, "-CAkey", $CAkey,
197 "-CAserial", $CAserial,
199 "-extensions", "v3_ee_dsa"],
200 stdout
=> "err.ss")),
201 "sign DSA user cert request");
202 skip
'failure', 1 unless
203 ok
(run
(app
([@verifycmd, "-CAfile", $CAcert, $Dcert])),
204 "verify DSA user cert");
205 skip
'failure', 0 unless
206 ok
(run
(app
([@x509cmd,
207 "-subject", "-issuer",
208 "-startdate", "-enddate", "-noout",
210 "DSA Certificate details");
214 skip
'failure', 6 unless
215 subtest
'ECDSA/ECDH certificate creation' => sub {
216 plan skip_all
=> "skipping ECDSA/ECDH certificate creation"
222 $ENV{CN2
} = "ECDSA Certificate";
223 skip
'failure', 4 unless
224 ok
(run
(app
(["openssl", "genpkey", "-genparam",
226 "-pkeyopt", "ec_paramgen_curve:P-256",
227 "-pkeyopt", "ec_param_enc:named_curve",
229 "make EC parameters");
230 skip
'failure', 3 unless
231 ok
(run
(app
([@reqcmd, "-config", $Uconf,
232 "-out", $Ereq, "-keyout", $Ekey,
233 "-newkey", "ec:ecp.ss"],
234 stdout
=> "err.ss")),
235 "make a ECDSA/ECDH user cert request");
236 skip
'failure', 2 unless
237 ok
(run
(app
([@x509cmd, "-CAcreateserial",
242 "-CA", $CAcert, "-CAkey", $CAkey,
243 "-CAserial", $CAserial,
245 "-extensions", "v3_ee_ec"],
246 stdout
=> "err.ss")),
247 "sign ECDSA/ECDH user cert request");
248 skip
'failure', 1 unless
249 ok
(run
(app
([@verifycmd, "-CAfile", $CAcert, $Ecert])),
250 "verify ECDSA/ECDH user cert");
251 skip
'failure', 0 unless
252 ok
(run
(app
([@x509cmd,
253 "-subject", "-issuer",
254 "-startdate", "-enddate", "-noout",
256 "ECDSA Certificate details");
260 skip
'failure', 5 unless
261 ok
(run
(app
([@reqcmd, "-config", $P1conf,
262 "-out", $P1req, "-keyout", $P1key, @req_new],
263 stdout
=> "err.ss")),
264 'make a proxy cert request');
267 skip
'failure', 4 unless
268 ok
(run
(app
([@x509cmd, "-CAcreateserial", "-in", $P1req, "-days", "30",
269 "-req", "-out", $P1cert,
270 "-CA", $Ucert, "-CAkey", $Ukey,
271 "-extfile", $P1conf, "-extensions", "v3_proxy"],
272 stdout
=> "err.ss")),
273 'sign proxy with user cert');
275 copy
($Ucert, $P1intermediate);
276 run
(app
([@verifycmd, "-CAfile", $CAcert,
277 "-untrusted", $P1intermediate, $P1cert]));
278 ok
(run
(app
([@x509cmd,
279 "-subject", "-issuer", "-startdate", "-enddate",
280 "-noout", "-in", $P1cert])),
281 'Certificate details');
283 skip
'failure', 2 unless
284 ok
(run
(app
([@reqcmd, "-config", $P2conf,
285 "-out", $P2req, "-keyout", $P2key,
287 stdout
=> "err.ss")),
288 'make another proxy cert request');
291 skip
'failure', 1 unless
292 ok
(run
(app
([@x509cmd, "-CAcreateserial", "-in", $P2req, "-days", "30",
293 "-req", "-out", $P2cert,
294 "-CA", $P1cert, "-CAkey", $P1key,
295 "-extfile", $P2conf, "-extensions", "v3_proxy"],
296 stdout
=> "err.ss")),
297 'sign second proxy cert request with the first proxy cert');
300 open OUT
, ">", $P2intermediate;
301 copy
($Ucert, \
*OUT
); copy
($P1cert, \
*OUT
);
303 run
(app
([@verifycmd, "-CAfile", $CAcert,
304 "-untrusted", $P2intermediate, $P2cert]));
305 ok
(run
(app
([@x509cmd,
306 "-subject", "-issuer", "-startdate", "-enddate",
307 "-noout", "-in", $P2cert])),
308 'Certificate details');
313 my ($key, $cert, $CAtmp) = @_;
314 my @CA = $CAtmp ?
("-CAfile", $CAtmp) : ("-CApath", bldtop_dir
("certs"));
316 my @ssltest = ("ssltest_old",
317 "-s_key", $key, "-s_cert", $cert,
318 "-c_key", $key, "-c_cert", $cert);
320 my $serverinfo = srctop_file
("test","serverinfo.pem");
323 if (grep /DSA Public Key/, run
(app
(["openssl", "x509", "-in", $cert,
324 "-text", "-noout"]), capture
=> 1)) {
331 subtest
'standard SSL tests' => sub {
332 ######################################################################
336 skip
"SSLv3 is not supported by this OpenSSL build", 4
339 ok
(run
(test
([@ssltest, "-bio_pair", "-ssl3"])),
340 'test sslv3 via BIO pair');
341 ok
(run
(test
([@ssltest, "-bio_pair", "-ssl3", "-server_auth", @CA])),
342 'test sslv3 with server authentication via BIO pair');
343 ok
(run
(test
([@ssltest, "-bio_pair", "-ssl3", "-client_auth", @CA])),
344 'test sslv3 with client authentication via BIO pair');
345 ok
(run
(test
([@ssltest, "-bio_pair", "-ssl3", "-server_auth", "-client_auth", @CA])),
346 'test sslv3 with both server and client authentication via BIO pair');
350 skip
"Neither SSLv3 nor any TLS version are supported by this OpenSSL build", 1
353 ok
(run
(test
([@ssltest, "-bio_pair"])),
354 'test sslv2/sslv3 via BIO pair');
358 skip
"Neither SSLv3 nor any TLS version are supported by this OpenSSL build", 8
362 skip
"skipping test of sslv2/sslv3 w/o (EC)DHE test", 1 if $dsa_cert;
364 ok
(run
(test
([@ssltest, "-bio_pair", "-no_dhe", "-no_ecdhe"])),
365 'test sslv2/sslv3 w/o (EC)DHE via BIO pair');
368 ok
(run
(test
([@ssltest, "-bio_pair", "-dhe1024dsa", "-v"])),
369 'test sslv2/sslv3 with 1024bit DHE via BIO pair');
370 ok
(run
(test
([@ssltest, "-bio_pair", "-server_auth", @CA])),
371 'test sslv2/sslv3 with server authentication');
372 ok
(run
(test
([@ssltest, "-bio_pair", "-client_auth", @CA])),
373 'test sslv2/sslv3 with client authentication via BIO pair');
374 ok
(run
(test
([@ssltest, "-bio_pair", "-server_auth", "-client_auth", @CA])),
375 'test sslv2/sslv3 with both client and server authentication via BIO pair');
376 ok
(run
(test
([@ssltest, "-bio_pair", "-server_auth", "-client_auth", "-app_verify", @CA])),
377 'test sslv2/sslv3 with both client and server authentication via BIO pair and app verify');
380 skip
"No IPv4 available on this machine", 1
381 unless !disabled
("sock") && have_IPv4
();
382 ok
(run
(test
([@ssltest, "-ipv4"])),
383 'test TLS via IPv4');
387 skip
"No IPv6 available on this machine", 1
388 unless !disabled
("sock") && have_IPv6
();
389 ok
(run
(test
([@ssltest, "-ipv6"])),
390 'test TLS via IPv6');
395 subtest
"Testing ciphersuites" => sub {
398 my $ciphers = "-PSK:-SRP";
401 push @exkeys, "-s_cert", "certD.ss", "-s_key", "keyD.ss";
405 push @exkeys, "-s_cert", "certE.ss", "-s_key", "keyE.ss";
409 # We only use the flags that ssltest_old understands
410 push @protocols, "-tls1_3" unless $no_tls1_3;
411 push @protocols, "-tls1_2" unless $no_tls1_2;
412 push @protocols, "-tls1" unless $no_tls1;
413 push @protocols, "-ssl3" unless $no_ssl3;
414 my $protocolciphersuitecount = 0;
415 my %ciphersuites = ();
416 my %ciphersstatus = ();
417 foreach my $protocol (@protocols) {
418 my $ciphersstatus = undef;
419 my @ciphers = run
(app
(["openssl", "ciphers", "-s", $protocol,
421 capture
=> 1, statusvar
=> \
$ciphersstatus);
422 $ciphersstatus{$protocol} = $ciphersstatus;
423 if ($ciphersstatus) {
424 $ciphersuites{$protocol} = [ map { s
|\R
||; split(/:/, $_) }
426 $protocolciphersuitecount += scalar @
{$ciphersuites{$protocol}};
430 plan skip_all
=> "None of the ciphersuites to test are available in this OpenSSL build"
431 if $protocolciphersuitecount + scalar(keys %ciphersuites) == 0;
433 # The count of protocols is because in addition to the ciphersuites
434 # we got above, we're running a weak DH test for each protocol (except
436 my $testcount = scalar(@protocols) + $protocolciphersuitecount
437 + scalar(keys %ciphersuites);
438 $testcount-- unless $no_tls1_3;
439 plan tests
=> $testcount;
441 foreach my $protocol (@protocols) {
442 ok
($ciphersstatus{$protocol}, "Getting ciphers for $protocol");
445 foreach my $protocol (sort keys %ciphersuites) {
446 note
"Testing ciphersuites for $protocol";
447 # ssltest_old doesn't know -tls1_3, but that's fine, since that's
448 # the default choice if TLSv1.3 enabled
449 my $flag = $protocol eq "-tls1_3" ?
"" : $protocol;
450 my $ciphersuites = "";
451 foreach my $cipher (@
{$ciphersuites{$protocol}}) {
452 if ($protocol eq "-ssl3" && $cipher =~ /ECDH/ ) {
453 note
"*****SKIPPING $protocol $cipher";
456 if ($protocol eq "-tls1_3") {
457 $ciphersuites = $cipher;
460 ok
(run
(test
([@ssltest, @exkeys, "-cipher", $cipher,
461 "-ciphersuites", $ciphersuites, $flag || ()])),
465 next if $protocol eq "-tls1_3";
466 is
(run
(test
([@ssltest,
468 "-c_cipher", 'EDH:@SECLEVEL=1',
471 "testing connection with weak DH, expecting failure");
475 subtest
'RSA/(EC)DHE/PSK tests' => sub {
476 ######################################################################
481 skip
"TLSv1.0 is not supported by this OpenSSL build", 5
485 skip
"skipping anonymous DH tests", 1
488 ok
(run
(test
([@ssltest, "-v", "-bio_pair", "-tls1", "-cipher", "ADH", "-dhe1024dsa", "-num", "10", "-f", "-time"])),
489 'test tlsv1 with 1024bit anonymous DH, multiple handshakes');
493 skip
"skipping RSA tests", 2
496 ok
(run
(test
(["ssltest_old", "-v", "-bio_pair", "-tls1", "-s_cert", srctop_file
("apps","server2.pem"), "-no_dhe", "-no_ecdhe", "-num", "10", "-f", "-time"])),
497 'test tlsv1 with 1024bit RSA, no (EC)DHE, multiple handshakes');
499 skip
"skipping RSA+DHE tests", 1
502 ok
(run
(test
(["ssltest_old", "-v", "-bio_pair", "-tls1", "-s_cert", srctop_file
("apps","server2.pem"), "-dhe1024dsa", "-num", "10", "-f", "-time"])),
503 'test tlsv1 with 1024bit RSA, 1024bit DHE, multiple handshakes');
507 skip
"skipping PSK tests", 2
510 ok
(run
(test
([@ssltest, "-tls1", "-cipher", "PSK", "-psk", "abc123"])),
511 'test tls1 with PSK');
513 ok
(run
(test
([@ssltest, "-bio_pair", "-tls1", "-cipher", "PSK", "-psk", "abc123"])),
514 'test tls1 with PSK via BIO pair');
520 subtest
'Custom Extension tests' => sub {
521 ######################################################################
526 skip
"TLSv1.0 is not supported by this OpenSSL build", 1
529 ok
(run
(test
([@ssltest, "-bio_pair", "-tls1", "-custom_ext"])),
530 'test tls1 with custom extensions');
534 subtest
'Serverinfo tests' => sub {
535 ######################################################################
540 skip
"TLSv1.0 is not supported by this OpenSSL build", 5
543 note
('echo test tls1 with serverinfo');
544 ok
(run
(test
([@ssltest, "-bio_pair", "-tls1", "-serverinfo_file", $serverinfo])));
545 ok
(run
(test
([@ssltest, "-bio_pair", "-tls1", "-serverinfo_file", $serverinfo, "-serverinfo_sct"])));
546 ok
(run
(test
([@ssltest, "-bio_pair", "-tls1", "-serverinfo_file", $serverinfo, "-serverinfo_tack"])));
547 ok
(run
(test
([@ssltest, "-bio_pair", "-tls1", "-serverinfo_file", $serverinfo, "-serverinfo_sct", "-serverinfo_tack"])));
548 ok
(run
(test
([@ssltest, "-bio_pair", "-tls1", "-custom_ext", "-serverinfo_file", $serverinfo, "-serverinfo_sct", "-serverinfo_tack"])));