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", "ecparam", "-name", "P-256",
226 "make EC parameters");
227 skip 'failure', 3 unless
228 ok(run(app([@reqcmd, "-config", $Uconf,
229 "-out", $Ereq, "-keyout", $Ekey,
230 "-newkey", "ec:ecp.ss"],
231 stdout => "err.ss")),
232 "make a ECDSA/ECDH user cert request");
233 skip 'failure', 2 unless
234 ok(run(app([@x509cmd, "-CAcreateserial",
239 "-CA", $CAcert, "-CAkey", $CAkey,
240 "-CAserial", $CAserial,
242 "-extensions", "v3_ee_ec"],
243 stdout => "err.ss")),
244 "sign ECDSA/ECDH user cert request");
245 skip 'failure', 1 unless
246 ok(run(app([@verifycmd, "-CAfile", $CAcert, $Ecert])),
247 "verify ECDSA/ECDH user cert");
248 skip 'failure', 0 unless
249 ok(run(app([@x509cmd,
250 "-subject", "-issuer",
251 "-startdate", "-enddate", "-noout",
253 "ECDSA Certificate details");
257 skip 'failure', 5 unless
258 ok(run(app([@reqcmd, "-config", $P1conf,
259 "-out", $P1req, "-keyout", $P1key, @req_new],
260 stdout => "err.ss")),
261 'make a proxy cert request');
264 skip 'failure', 4 unless
265 ok(run(app([@x509cmd, "-CAcreateserial", "-in", $P1req, "-days", "30",
266 "-req", "-out", $P1cert,
267 "-CA", $Ucert, "-CAkey", $Ukey,
268 "-extfile", $P1conf, "-extensions", "v3_proxy"],
269 stdout => "err.ss")),
270 'sign proxy with user cert');
272 copy($Ucert, $P1intermediate);
273 run(app([@verifycmd, "-CAfile", $CAcert,
274 "-untrusted", $P1intermediate, $P1cert]));
275 ok(run(app([@x509cmd,
276 "-subject", "-issuer", "-startdate", "-enddate",
277 "-noout", "-in", $P1cert])),
278 'Certificate details');
280 skip 'failure', 2 unless
281 ok(run(app([@reqcmd, "-config", $P2conf,
282 "-out", $P2req, "-keyout", $P2key,
284 stdout => "err.ss")),
285 'make another proxy cert request');
288 skip 'failure', 1 unless
289 ok(run(app([@x509cmd, "-CAcreateserial", "-in", $P2req, "-days", "30",
290 "-req", "-out", $P2cert,
291 "-CA", $P1cert, "-CAkey", $P1key,
292 "-extfile", $P2conf, "-extensions", "v3_proxy"],
293 stdout => "err.ss")),
294 'sign second proxy cert request with the first proxy cert');
297 open OUT, ">", $P2intermediate;
298 copy($Ucert, \*OUT); copy($P1cert, \*OUT);
300 run(app([@verifycmd, "-CAfile", $CAcert,
301 "-untrusted", $P2intermediate, $P2cert]));
302 ok(run(app([@x509cmd,
303 "-subject", "-issuer", "-startdate", "-enddate",
304 "-noout", "-in", $P2cert])),
305 'Certificate details');
310 my ($key, $cert, $CAtmp) = @_;
311 my @CA = $CAtmp ? ("-CAfile", $CAtmp) : ("-CApath", bldtop_dir("certs"));
313 my @ssltest = ("ssltest_old",
314 "-s_key", $key, "-s_cert", $cert,
315 "-c_key", $key, "-c_cert", $cert);
317 my $serverinfo = srctop_file("test","serverinfo.pem");
320 if (grep /DSA Public Key/, run(app(["openssl", "x509", "-in", $cert,
321 "-text", "-noout"]), capture => 1)) {
328 subtest 'standard SSL tests' => sub {
329 ######################################################################
333 skip "SSLv3 is not supported by this OpenSSL build", 4
336 ok(run(test([@ssltest, "-bio_pair", "-ssl3"])),
337 'test sslv3 via BIO pair');
338 ok(run(test([@ssltest, "-bio_pair", "-ssl3", "-server_auth", @CA])),
339 'test sslv3 with server authentication via BIO pair');
340 ok(run(test([@ssltest, "-bio_pair", "-ssl3", "-client_auth", @CA])),
341 'test sslv3 with client authentication via BIO pair');
342 ok(run(test([@ssltest, "-bio_pair", "-ssl3", "-server_auth", "-client_auth", @CA])),
343 'test sslv3 with both server and client authentication via BIO pair');
347 skip "Neither SSLv3 nor any TLS version are supported by this OpenSSL build", 1
350 ok(run(test([@ssltest, "-bio_pair"])),
351 'test sslv2/sslv3 via BIO pair');
355 skip "Neither SSLv3 nor any TLS version are supported by this OpenSSL build", 8
359 skip "skipping test of sslv2/sslv3 w/o (EC)DHE test", 1 if $dsa_cert;
361 ok(run(test([@ssltest, "-bio_pair", "-no_dhe", "-no_ecdhe"])),
362 'test sslv2/sslv3 w/o (EC)DHE via BIO pair');
365 ok(run(test([@ssltest, "-bio_pair", "-dhe1024dsa", "-v"])),
366 'test sslv2/sslv3 with 1024bit DHE via BIO pair');
367 ok(run(test([@ssltest, "-bio_pair", "-server_auth", @CA])),
368 'test sslv2/sslv3 with server authentication');
369 ok(run(test([@ssltest, "-bio_pair", "-client_auth", @CA])),
370 'test sslv2/sslv3 with client authentication via BIO pair');
371 ok(run(test([@ssltest, "-bio_pair", "-server_auth", "-client_auth", @CA])),
372 'test sslv2/sslv3 with both client and server authentication via BIO pair');
373 ok(run(test([@ssltest, "-bio_pair", "-server_auth", "-client_auth", "-app_verify", @CA])),
374 'test sslv2/sslv3 with both client and server authentication via BIO pair and app verify');
377 skip "No IPv4 available on this machine", 1
378 unless !disabled("sock") && have_IPv4();
379 ok(run(test([@ssltest, "-ipv4"])),
380 'test TLS via IPv4');
384 skip "No IPv6 available on this machine", 1
385 unless !disabled("sock") && have_IPv6();
386 ok(run(test([@ssltest, "-ipv6"])),
387 'test TLS via IPv6');
392 subtest "Testing ciphersuites" => sub {
395 my $ciphers = "-PSK:-SRP";
398 push @exkeys, "-s_cert", "certD.ss", "-s_key", "keyD.ss";
402 push @exkeys, "-s_cert", "certE.ss", "-s_key", "keyE.ss";
406 # We only use the flags that ssltest_old understands
407 push @protocols, "-tls1_3" unless $no_tls1_3;
408 push @protocols, "-tls1_2" unless $no_tls1_2;
409 push @protocols, "-tls1" unless $no_tls1;
410 push @protocols, "-ssl3" unless $no_ssl3;
411 my $protocolciphersuitecount = 0;
412 my %ciphersuites = ();
413 my %ciphersstatus = ();
414 foreach my $protocol (@protocols) {
415 my $ciphersstatus = undef;
416 my @ciphers = run(app(["openssl", "ciphers", "-s", $protocol,
418 capture => 1, statusvar => \$ciphersstatus);
419 $ciphersstatus{$protocol} = $ciphersstatus;
420 if ($ciphersstatus) {
421 $ciphersuites{$protocol} = [ map { s|\R||; split(/:/, $_) }
423 $protocolciphersuitecount += scalar @{$ciphersuites{$protocol}};
427 plan skip_all => "None of the ciphersuites to test are available in this OpenSSL build"
428 if $protocolciphersuitecount + scalar(keys %ciphersuites) == 0;
430 # The count of protocols is because in addition to the ciphersuites
431 # we got above, we're running a weak DH test for each protocol (except
433 my $testcount = scalar(@protocols) + $protocolciphersuitecount
434 + scalar(keys %ciphersuites);
435 $testcount-- unless $no_tls1_3;
436 plan tests => $testcount;
438 foreach my $protocol (@protocols) {
439 ok($ciphersstatus{$protocol}, "Getting ciphers for $protocol");
442 foreach my $protocol (sort keys %ciphersuites) {
443 note "Testing ciphersuites for $protocol";
444 # ssltest_old doesn't know -tls1_3, but that's fine, since that's
445 # the default choice if TLSv1.3 enabled
446 my $flag = $protocol eq "-tls1_3" ? "" : $protocol;
447 my $ciphersuites = "";
448 foreach my $cipher (@{$ciphersuites{$protocol}}) {
449 if ($protocol eq "-ssl3" && $cipher =~ /ECDH/ ) {
450 note "*****SKIPPING $protocol $cipher";
453 if ($protocol eq "-tls1_3") {
454 $ciphersuites = $cipher;
457 ok(run(test([@ssltest, @exkeys, "-cipher", $cipher,
458 "-ciphersuites", $ciphersuites, $flag || ()])),
462 next if $protocol eq "-tls1_3";
463 is(run(test([@ssltest,
465 "-c_cipher", 'EDH:@SECLEVEL=1',
468 "testing connection with weak DH, expecting failure");
472 subtest 'RSA/(EC)DHE/PSK tests' => sub {
473 ######################################################################
478 skip "TLSv1.0 is not supported by this OpenSSL build", 5
482 skip "skipping anonymous DH tests", 1
485 ok(run(test([@ssltest, "-v", "-bio_pair", "-tls1", "-cipher", "ADH", "-dhe1024dsa", "-num", "10", "-f", "-time"])),
486 'test tlsv1 with 1024bit anonymous DH, multiple handshakes');
490 skip "skipping RSA tests", 2
493 ok(run(test(["ssltest_old", "-v", "-bio_pair", "-tls1", "-s_cert", srctop_file("apps","server2.pem"), "-no_dhe", "-no_ecdhe", "-num", "10", "-f", "-time"])),
494 'test tlsv1 with 1024bit RSA, no (EC)DHE, multiple handshakes');
496 skip "skipping RSA+DHE tests", 1
499 ok(run(test(["ssltest_old", "-v", "-bio_pair", "-tls1", "-s_cert", srctop_file("apps","server2.pem"), "-dhe1024dsa", "-num", "10", "-f", "-time"])),
500 'test tlsv1 with 1024bit RSA, 1024bit DHE, multiple handshakes');
504 skip "skipping PSK tests", 2
507 ok(run(test([@ssltest, "-tls1", "-cipher", "PSK", "-psk", "abc123"])),
508 'test tls1 with PSK');
510 ok(run(test([@ssltest, "-bio_pair", "-tls1", "-cipher", "PSK", "-psk", "abc123"])),
511 'test tls1 with PSK via BIO pair');
517 subtest 'Custom Extension tests' => sub {
518 ######################################################################
523 skip "TLSv1.0 is not supported by this OpenSSL build", 1
526 ok(run(test([@ssltest, "-bio_pair", "-tls1", "-custom_ext"])),
527 'test tls1 with custom extensions');
531 subtest 'Serverinfo tests' => sub {
532 ######################################################################
537 skip "TLSv1.0 is not supported by this OpenSSL build", 5
540 note('echo test tls1 with serverinfo');
541 ok(run(test([@ssltest, "-bio_pair", "-tls1", "-serverinfo_file", $serverinfo])));
542 ok(run(test([@ssltest, "-bio_pair", "-tls1", "-serverinfo_file", $serverinfo, "-serverinfo_sct"])));
543 ok(run(test([@ssltest, "-bio_pair", "-tls1", "-serverinfo_file", $serverinfo, "-serverinfo_tack"])));
544 ok(run(test([@ssltest, "-bio_pair", "-tls1", "-serverinfo_file", $serverinfo, "-serverinfo_sct", "-serverinfo_tack"])));
545 ok(run(test([@ssltest, "-bio_pair", "-tls1", "-custom_ext", "-serverinfo_file", $serverinfo, "-serverinfo_sct", "-serverinfo_tack"])));
559 unlink basename($Ucert, '.ss').'.srl';
572 unlink basename($P1cert, '.ss').'.srl';
573 unlink $P1intermediate;
579 unlink $P2intermediate;