2 # Copyright 2015-2016 The OpenSSL Project Authors. All Rights Reserved.
4 # Licensed under the OpenSSL license (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_srp, $no_psk,
24 $no_ssl3, $no_tls1, $no_tls1_1, $no_tls1_2,
25 $no_dtls, $no_dtls1, $no_dtls1_2, $no_ct) =
26 anydisabled qw/rsa dsa dh ec srp psk
27 ssl3 tls1 tls1_1 tls1_2
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 $dummycnf = srctop_file("apps", "openssl.cnf");
41 my $CAkey = "keyCA.ss";
42 my $CAcert="certCA.ss";
43 my $CAserial="certCA.srl";
45 my $CAconf=srctop_file("test","CAss.cnf");
46 my $CAreq2="req2CA.ss"; # temp
48 my $Uconf=srctop_file("test","Uss.cnf");
61 my $P1conf=srctop_file("test","P1ss.cnf");
64 my $P1cert="certP1.ss";
65 my $P1intermediate="tmp_intP1.ss";
67 my $P2conf=srctop_file("test","P2ss.cnf");
70 my $P2cert="certP2.ss";
71 my $P2intermediate="tmp_intP2.ss";
73 my $server_sess="server.ss";
74 my $client_sess="client.ss";
76 # ssltest_old.c is deprecated in favour of the new framework in ssl_test.c
77 # If you're adding tests here, you probably want to convert them to the
78 # new format in ssl_test.c and add recipes to 80-test_ssl_new.t instead.
81 + 14 # For the first testssl
84 subtest 'test_ss' => sub {
86 open OUT, ">", "intP1.ss";
87 copy($CAcert, \*OUT); copy($Ucert, \*OUT);
90 open OUT, ">", "intP2.ss";
91 copy($CAcert, \*OUT); copy($Ucert, \*OUT); copy($P1cert, \*OUT);
96 note('test_ssl -- key U');
97 testssl("keyU.ss", $Ucert, $CAcert);
102 open RND, ">>", ".rnd";
103 print RND "string to make the random number generator think it has entropy";
106 my @req_dsa = ("-newkey",
107 "dsa:".srctop_file("apps", "dsa1024.pem"));
118 skip 'failure', 16 unless
119 ok(run(app([@reqcmd, "-config", $CAconf,
120 "-out", $CAreq, "-keyout", $CAkey,
122 'make cert request');
124 skip 'failure', 15 unless
125 ok(run(app([@x509cmd, "-CAcreateserial", "-in", $CAreq, "-days", "30",
126 "-req", "-out", $CAcert, "-signkey", $CAkey,
127 "-extfile", $CAconf, "-extensions", "v3_ca"],
128 stdout => "err.ss")),
129 'convert request into self-signed cert');
131 skip 'failure', 14 unless
132 ok(run(app([@x509cmd, "-in", $CAcert,
133 "-x509toreq", "-signkey", $CAkey, "-out", $CAreq2],
134 stdout => "err.ss")),
135 'convert cert into a cert request');
137 skip 'failure', 13 unless
138 ok(run(app([@reqcmd, "-config", $dummycnf,
139 "-verify", "-in", $CAreq, "-noout"])),
143 skip 'failure', 12 unless
144 ok(run(app([@reqcmd, "-config", $dummycnf,
145 "-verify", "-in", $CAreq2, "-noout"])),
148 skip 'failure', 11 unless
149 ok(run(app([@verifycmd, "-CAfile", $CAcert, $CAcert])),
152 skip 'failure', 10 unless
153 ok(run(app([@reqcmd, "-config", $Uconf,
154 "-out", $Ureq, "-keyout", $Ukey, @req_new],
155 stdout => "err.ss")),
156 'make a user cert request');
158 skip 'failure', 9 unless
159 ok(run(app([@x509cmd, "-CAcreateserial", "-in", $Ureq, "-days", "30",
160 "-req", "-out", $Ucert,
161 "-CA", $CAcert, "-CAkey", $CAkey, "-CAserial", $CAserial,
162 "-extfile", $Uconf, "-extensions", "v3_ee"],
164 && run(app([@verifycmd, "-CAfile", $CAcert, $Ucert])),
165 'sign user cert request');
167 skip 'failure', 8 unless
168 ok(run(app([@x509cmd,
169 "-subject", "-issuer", "-startdate", "-enddate",
170 "-noout", "-in", $Ucert])),
171 'Certificate details');
173 skip 'failure', 7 unless
174 subtest 'DSA certificate creation' => sub {
175 plan skip_all => "skipping DSA certificate creation"
181 $ENV{CN2} = "DSA Certificate";
182 skip 'failure', 3 unless
183 ok(run(app([@reqcmd, "-config", $Uconf,
184 "-out", $Dreq, "-keyout", $Dkey,
186 stdout => "err.ss")),
187 "make a DSA user cert request");
188 skip 'failure', 2 unless
189 ok(run(app([@x509cmd, "-CAcreateserial",
194 "-CA", $CAcert, "-CAkey", $CAkey,
195 "-CAserial", $CAserial,
197 "-extensions", "v3_ee_dsa"],
198 stdout => "err.ss")),
199 "sign DSA user cert request");
200 skip 'failure', 1 unless
201 ok(run(app([@verifycmd, "-CAfile", $CAcert, $Dcert])),
202 "verify DSA user cert");
203 skip 'failure', 0 unless
204 ok(run(app([@x509cmd,
205 "-subject", "-issuer",
206 "-startdate", "-enddate", "-noout",
208 "DSA Certificate details");
212 skip 'failure', 6 unless
213 subtest 'ECDSA/ECDH certificate creation' => sub {
214 plan skip_all => "skipping ECDSA/ECDH certificate creation"
220 $ENV{CN2} = "ECDSA Certificate";
221 skip 'failure', 4 unless
222 ok(run(app(["openssl", "ecparam", "-name", "P-256",
224 "make EC parameters");
225 skip 'failure', 3 unless
226 ok(run(app([@reqcmd, "-config", $Uconf,
227 "-out", $Ereq, "-keyout", $Ekey,
228 "-newkey", "ec:ecp.ss"],
229 stdout => "err.ss")),
230 "make a ECDSA/ECDH user cert request");
231 skip 'failure', 2 unless
232 ok(run(app([@x509cmd, "-CAcreateserial",
237 "-CA", $CAcert, "-CAkey", $CAkey,
238 "-CAserial", $CAserial,
240 "-extensions", "v3_ee_ec"],
241 stdout => "err.ss")),
242 "sign ECDSA/ECDH user cert request");
243 skip 'failure', 1 unless
244 ok(run(app([@verifycmd, "-CAfile", $CAcert, $Ecert])),
245 "verify ECDSA/ECDH user cert");
246 skip 'failure', 0 unless
247 ok(run(app([@x509cmd,
248 "-subject", "-issuer",
249 "-startdate", "-enddate", "-noout",
251 "ECDSA Certificate details");
255 skip 'failure', 5 unless
256 ok(run(app([@reqcmd, "-config", $P1conf,
257 "-out", $P1req, "-keyout", $P1key, @req_new],
258 stdout => "err.ss")),
259 'make a proxy cert request');
262 skip 'failure', 4 unless
263 ok(run(app([@x509cmd, "-CAcreateserial", "-in", $P1req, "-days", "30",
264 "-req", "-out", $P1cert,
265 "-CA", $Ucert, "-CAkey", $Ukey,
266 "-extfile", $P1conf, "-extensions", "v3_proxy"],
267 stdout => "err.ss")),
268 'sign proxy with user cert');
270 copy($Ucert, $P1intermediate);
271 run(app([@verifycmd, "-CAfile", $CAcert,
272 "-untrusted", $P1intermediate, $P1cert]));
273 ok(run(app([@x509cmd,
274 "-subject", "-issuer", "-startdate", "-enddate",
275 "-noout", "-in", $P1cert])),
276 'Certificate details');
278 skip 'failure', 2 unless
279 ok(run(app([@reqcmd, "-config", $P2conf,
280 "-out", $P2req, "-keyout", $P2key,
282 stdout => "err.ss")),
283 'make another proxy cert request');
286 skip 'failure', 1 unless
287 ok(run(app([@x509cmd, "-CAcreateserial", "-in", $P2req, "-days", "30",
288 "-req", "-out", $P2cert,
289 "-CA", $P1cert, "-CAkey", $P1key,
290 "-extfile", $P2conf, "-extensions", "v3_proxy"],
291 stdout => "err.ss")),
292 'sign second proxy cert request with the first proxy cert');
295 open OUT, ">", $P2intermediate;
296 copy($Ucert, \*OUT); copy($P1cert, \*OUT);
298 run(app([@verifycmd, "-CAfile", $CAcert,
299 "-untrusted", $P2intermediate, $P2cert]));
300 ok(run(app([@x509cmd,
301 "-subject", "-issuer", "-startdate", "-enddate",
302 "-noout", "-in", $P2cert])),
303 'Certificate details');
308 my $key = shift || bldtop_file("apps","server.pem");
309 my $cert = shift || bldtop_file("apps","server.pem");
311 my @CA = $CAtmp ? ("-CAfile", $CAtmp) : ("-CApath", bldtop_dir("certs"));
314 my @ssltest = ("ssltest_old",
315 "-s_key", $key, "-s_cert", $cert,
316 "-c_key", $key, "-c_cert", $cert);
318 my $serverinfo = srctop_file("test","serverinfo.pem");
321 if (grep /DSA Public Key/, run(app(["openssl", "x509", "-in", $cert,
322 "-text", "-noout"]), capture => 1)) {
329 subtest 'standard SSL tests' => sub {
330 ######################################################################
334 skip "SSLv3 is not supported by this OpenSSL build", 4
337 ok(run(test([@ssltest, "-ssl3", @extra])),
339 ok(run(test([@ssltest, "-ssl3", "-server_auth", @CA, @extra])),
340 'test sslv3 with server authentication');
341 ok(run(test([@ssltest, "-ssl3", "-client_auth", @CA, @extra])),
342 'test sslv3 with client authentication');
343 ok(run(test([@ssltest, "-ssl3", "-server_auth", "-client_auth", @CA, @extra])),
344 'test sslv3 with both server and client authentication');
348 skip "Neither SSLv3 nor any TLS version are supported by this OpenSSL build", 4
351 ok(run(test([@ssltest, @extra])),
353 ok(run(test([@ssltest, "-server_auth", @CA, @extra])),
354 'test sslv2/sslv3 with server authentication');
355 ok(run(test([@ssltest, "-client_auth", @CA, @extra])),
356 'test sslv2/sslv3 with client authentication');
357 ok(run(test([@ssltest, "-server_auth", "-client_auth", @CA, @extra])),
358 'test sslv2/sslv3 with both server and client authentication');
362 skip "SSLv3 is not supported by this OpenSSL build", 4
365 ok(run(test([@ssltest, "-bio_pair", "-ssl3", @extra])),
366 'test sslv3 via BIO pair');
367 ok(run(test([@ssltest, "-bio_pair", "-ssl3", "-server_auth", @CA, @extra])),
368 'test sslv3 with server authentication via BIO pair');
369 ok(run(test([@ssltest, "-bio_pair", "-ssl3", "-client_auth", @CA, @extra])),
370 'test sslv3 with client authentication via BIO pair');
371 ok(run(test([@ssltest, "-bio_pair", "-ssl3", "-server_auth", "-client_auth", @CA, @extra])),
372 'test sslv3 with both server and client authentication via BIO pair');
376 skip "Neither SSLv3 nor any TLS version are supported by this OpenSSL build", 1
379 ok(run(test([@ssltest, "-bio_pair", @extra])),
380 'test sslv2/sslv3 via BIO pair');
384 skip "DTLSv1 is not supported by this OpenSSL build", 4
385 if disabled("dtls1");
387 ok(run(test([@ssltest, "-dtls1", @extra])),
389 ok(run(test([@ssltest, "-dtls1", "-server_auth", @CA, @extra])),
390 'test dtlsv1 with server authentication');
391 ok(run(test([@ssltest, "-dtls1", "-client_auth", @CA, @extra])),
392 'test dtlsv1 with client authentication');
393 ok(run(test([@ssltest, "-dtls1", "-server_auth", "-client_auth", @CA, @extra])),
394 'test dtlsv1 with both server and client authentication');
398 skip "DTLSv1.2 is not supported by this OpenSSL build", 4
399 if disabled("dtls1_2");
401 ok(run(test([@ssltest, "-dtls12", @extra])),
403 ok(run(test([@ssltest, "-dtls12", "-server_auth", @CA, @extra])),
404 'test dtlsv1.2 with server authentication');
405 ok(run(test([@ssltest, "-dtls12", "-client_auth", @CA, @extra])),
406 'test dtlsv1.2 with client authentication');
407 ok(run(test([@ssltest, "-dtls12", "-server_auth", "-client_auth", @CA, @extra])),
408 'test dtlsv1.2 with both server and client authentication');
412 skip "Neither SSLv3 nor any TLS version are supported by this OpenSSL build", 8
416 skip "skipping test of sslv2/sslv3 w/o (EC)DHE test", 1 if $dsa_cert;
418 ok(run(test([@ssltest, "-bio_pair", "-no_dhe", "-no_ecdhe", @extra])),
419 'test sslv2/sslv3 w/o (EC)DHE via BIO pair');
422 ok(run(test([@ssltest, "-bio_pair", "-dhe1024dsa", "-v", @extra])),
423 'test sslv2/sslv3 with 1024bit DHE via BIO pair');
424 ok(run(test([@ssltest, "-bio_pair", "-server_auth", @CA, @extra])),
425 'test sslv2/sslv3 with server authentication');
426 ok(run(test([@ssltest, "-bio_pair", "-client_auth", @CA, @extra])),
427 'test sslv2/sslv3 with client authentication via BIO pair');
428 ok(run(test([@ssltest, "-bio_pair", "-server_auth", "-client_auth", @CA, @extra])),
429 'test sslv2/sslv3 with both client and server authentication via BIO pair');
430 ok(run(test([@ssltest, "-bio_pair", "-server_auth", "-client_auth", "-app_verify", @CA, @extra])),
431 'test sslv2/sslv3 with both client and server authentication via BIO pair and app verify');
434 skip "No IPv4 available on this machine", 1
435 unless !disabled("sock") && have_IPv4();
436 ok(run(test([@ssltest, "-ipv4", @extra])),
437 'test TLS via IPv4');
441 skip "No IPv6 available on this machine", 1
442 unless !disabled("sock") && have_IPv6();
443 ok(run(test([@ssltest, "-ipv6", @extra])),
444 'test TLS via IPv6');
449 subtest "Testing ciphersuites" => sub {
452 my $ciphers = "-EXP:-PSK:-SRP:-kDH:-kECDHe";
455 note "skipping DHE tests\n";
456 $ciphers .= ":-kDHE";
459 note "skipping DSA tests\n";
460 $ciphers .= ":-aDSA";
462 push @exkeys, "-s_cert", "certD.ss", "-s_key", "keyD.ss";
466 note "skipping EC tests\n";
467 $ciphers .= ":!aECDSA:!kECDH";
469 push @exkeys, "-s_cert", "certE.ss", "-s_key", "keyE.ss";
473 # FIXME: I feel unsure about the following line, is that really just TLSv1.2, or is it all of the SSLv3/TLS protocols?
474 push(@protocols, "TLSv1.2") unless $no_tls1_2;
475 push(@protocols, "SSLv3") unless $no_ssl3;
476 my $protocolciphersuitcount = 0;
479 map { split(/:/, $_) }
480 run(app(["openssl", "ciphers", "${_}:$ciphers"]),
482 map { s/\R//; } @c; # chomp @c;
483 $protocolciphersuitcount += scalar @c;
484 $_ => [ @c ] } @protocols;
486 plan skip_all => "None of the ciphersuites to test are available in this OpenSSL build"
487 if $protocolciphersuitcount + scalar(@protocols) == 0;
489 # The count of protocols is because in addition to the ciphersuits
490 # we got above, we're running a weak DH test for each protocol
491 plan tests => $protocolciphersuitcount + scalar(@protocols);
493 foreach my $protocol (@protocols) {
494 note "Testing ciphersuites for $protocol";
495 foreach my $cipher (@{$ciphersuites{$protocol}}) {
496 ok(run(test([@ssltest, @exkeys, "-cipher", $cipher,
497 $protocol eq "SSLv3" ? ("-ssl3") : ()])),
500 is(run(test([@ssltest,
502 "-c_cipher", 'EDH:@SECLEVEL=1',
504 $protocol eq "SSLv3" ? ("-ssl3") : ()])), 0,
505 "testing connection with weak DH, expecting failure");
509 subtest 'RSA/(EC)DHE/PSK tests' => sub {
510 ######################################################################
515 skip "TLSv1.0 is not supported by this OpenSSL build", 5
519 skip "skipping anonymous DH tests", 1
522 ok(run(test([@ssltest, "-v", "-bio_pair", "-tls1", "-cipher", "ADH", "-dhe1024dsa", "-num", "10", "-f", "-time", @extra])),
523 'test tlsv1 with 1024bit anonymous DH, multiple handshakes');
527 skip "skipping RSA tests", 2
530 ok(run(test(["ssltest_old", "-v", "-bio_pair", "-tls1", "-s_cert", srctop_file("apps","server2.pem"), "-no_dhe", "-no_ecdhe", "-num", "10", "-f", "-time", @extra])),
531 'test tlsv1 with 1024bit RSA, no (EC)DHE, multiple handshakes');
533 skip "skipping RSA+DHE tests", 1
536 ok(run(test(["ssltest_old", "-v", "-bio_pair", "-tls1", "-s_cert", srctop_file("apps","server2.pem"), "-dhe1024dsa", "-num", "10", "-f", "-time", @extra])),
537 'test tlsv1 with 1024bit RSA, 1024bit DHE, multiple handshakes');
541 skip "skipping PSK tests", 2
544 ok(run(test([@ssltest, "-tls1", "-cipher", "PSK", "-psk", "abc123", @extra])),
545 'test tls1 with PSK');
547 ok(run(test([@ssltest, "-bio_pair", "-tls1", "-cipher", "PSK", "-psk", "abc123", @extra])),
548 'test tls1 with PSK via BIO pair');
554 subtest 'Next Protocol Negotiation Tests' => sub {
555 ######################################################################
560 skip "TLSv1.0 is not supported by this OpenSSL build", 7
562 skip "Next Protocol Negotiation is not supported by this OpenSSL build", 7
563 if disabled("nextprotoneg");
565 ok(run(test([@ssltest, "-bio_pair", "-tls1", "-npn_client"])));
566 ok(run(test([@ssltest, "-bio_pair", "-tls1", "-npn_server"])));
567 ok(run(test([@ssltest, "-bio_pair", "-tls1", "-npn_server_reject"])));
568 ok(run(test([@ssltest, "-bio_pair", "-tls1", "-npn_client", "-npn_server_reject"])));
569 ok(run(test([@ssltest, "-bio_pair", "-tls1", "-npn_client", "-npn_server"])));
570 ok(run(test([@ssltest, "-bio_pair", "-tls1", "-npn_client", "-npn_server", "-num", "2"])));
571 ok(run(test([@ssltest, "-bio_pair", "-tls1", "-npn_client", "-npn_server", "-num", "2", "-reuse"])));
575 subtest 'Custom Extension tests' => sub {
576 ######################################################################
581 skip "TLSv1.0 is not supported by this OpenSSL build", 1
584 ok(run(test([@ssltest, "-bio_pair", "-tls1", "-custom_ext"])),
585 'test tls1 with custom extensions');
589 subtest 'Serverinfo tests' => sub {
590 ######################################################################
595 skip "TLSv1.0 is not supported by this OpenSSL build", 5
598 note('echo test tls1 with serverinfo');
599 ok(run(test([@ssltest, "-bio_pair", "-tls1", "-serverinfo_file", $serverinfo])));
600 ok(run(test([@ssltest, "-bio_pair", "-tls1", "-serverinfo_file", $serverinfo, "-serverinfo_sct"])));
601 ok(run(test([@ssltest, "-bio_pair", "-tls1", "-serverinfo_file", $serverinfo, "-serverinfo_tack"])));
602 ok(run(test([@ssltest, "-bio_pair", "-tls1", "-serverinfo_file", $serverinfo, "-serverinfo_sct", "-serverinfo_tack"])));
603 ok(run(test([@ssltest, "-bio_pair", "-tls1", "-custom_ext", "-serverinfo_file", $serverinfo, "-serverinfo_sct", "-serverinfo_tack"])));
607 subtest 'SNI tests' => sub {
612 skip "TLSv1.x is not supported by this OpenSSL build", 7
613 if $no_tls1 && $no_tls1_1 && $no_tls1_2;
615 ok(run(test([@ssltest, "-bio_pair", "-sn_client", "foo"])));
616 ok(run(test([@ssltest, "-bio_pair", "-sn_server1", "foo"])));
617 ok(run(test([@ssltest, "-bio_pair", "-sn_client", "foo", "-sn_server1", "foo", "-sn_expect1"])));
618 ok(run(test([@ssltest, "-bio_pair", "-sn_client", "foo", "-sn_server1", "bar", "-sn_expect1"])));
619 ok(run(test([@ssltest, "-bio_pair", "-sn_client", "foo", "-sn_server1", "foo", "-sn_server2", "bar", "-sn_expect1"])));
620 ok(run(test([@ssltest, "-bio_pair", "-sn_client", "bar", "-sn_server1", "foo", "-sn_server2", "bar", "-sn_expect2"])));
621 # Negative test - make sure it doesn't crash, and doesn't switch contexts
622 ok(run(test([@ssltest, "-bio_pair", "-sn_client", "foobar", "-sn_server1", "foo", "-sn_server2", "bar", "-sn_expect1"])));
626 subtest 'ALPN tests' => sub {
627 ######################################################################
632 skip "TLSv1.0 is not supported by this OpenSSL build", 13
635 ok(run(test([@ssltest, "-bio_pair", "-tls1", "-alpn_client", "foo"])));
636 ok(run(test([@ssltest, "-bio_pair", "-tls1", "-alpn_server", "foo"])));
637 ok(run(test([@ssltest, "-bio_pair", "-tls1", "-alpn_client", "foo", "-alpn_server", "foo", "-alpn_expected", "foo"])));
638 ok(run(test([@ssltest, "-bio_pair", "-tls1", "-alpn_client", "foo,bar", "-alpn_server", "foo", "-alpn_expected", "foo"])));
639 ok(run(test([@ssltest, "-bio_pair", "-tls1", "-alpn_client", "bar,foo", "-alpn_server", "foo", "-alpn_expected", "foo"])));
640 ok(run(test([@ssltest, "-bio_pair", "-tls1", "-alpn_client", "bar,foo", "-alpn_server", "foo,bar", "-alpn_expected", "foo"])));
641 ok(run(test([@ssltest, "-bio_pair", "-tls1", "-alpn_client", "bar,foo", "-alpn_server", "bar,foo", "-alpn_expected", "bar"])));
642 ok(run(test([@ssltest, "-bio_pair", "-tls1", "-alpn_client", "foo,bar", "-alpn_server", "bar,foo", "-alpn_expected", "bar"])));
644 is(run(test([@ssltest, "-bio_pair", "-tls1", "-alpn_client", "foo", "-alpn_server", "bar"])), 0,
645 "Testing ALPN with protocol mismatch, expecting failure");
646 is(run(test([@ssltest, "-bio_pair", "-tls1", "-alpn_client", "baz", "-alpn_server", "bar,foo"])), 0,
647 "Testing ALPN with protocol mismatch, expecting failure");
650 ok(run(test([@ssltest, "-bio_pair",
651 "-alpn_client", "foo,bar", "-sn_client", "alice",
652 "-alpn_server1", "foo,123", "-sn_server1", "alice",
653 "-alpn_server2", "bar,456", "-sn_server2", "bob",
654 "-alpn_expected", "foo"])));
655 ok(run(test([@ssltest, "-bio_pair",
656 "-alpn_client", "foo,bar", "-sn_client", "bob",
657 "-alpn_server1", "foo,123", "-sn_server1", "alice",
658 "-alpn_server2", "bar,456", "-sn_server2", "bob",
659 "-alpn_expected", "bar"])));
660 ok(run(test([@ssltest, "-bio_pair",
661 "-alpn_client", "foo,bar", "-sn_client", "bob",
662 "-alpn_server2", "bar,456", "-sn_server2", "bob",
663 "-alpn_expected", "bar"])));
667 subtest 'SRP tests' => sub {
672 skip "skipping SRP tests", 4
675 ok(run(test([@ssltest, "-tls1", "-cipher", "SRP", "-srpuser", "test", "-srppass", "abc123"])),
676 'test tls1 with SRP');
678 ok(run(test([@ssltest, "-bio_pair", "-tls1", "-cipher", "SRP", "-srpuser", "test", "-srppass", "abc123"])),
679 'test tls1 with SRP via BIO pair');
681 ok(run(test([@ssltest, "-tls1", "-cipher", "aSRP", "-srpuser", "test", "-srppass", "abc123"])),
682 'test tls1 with SRP auth');
684 ok(run(test([@ssltest, "-bio_pair", "-tls1", "-cipher", "aSRP", "-srpuser", "test", "-srppass", "abc123"])),
685 'test tls1 with SRP auth via BIO pair');
689 subtest 'Multi-buffer tests' => sub {
690 ######################################################################
695 skip "Neither SSLv3 nor any TLS version are supported by this OpenSSL build", 2
698 skip "skipping multi-buffer tests", 2
699 if @extra || (POSIX::uname())[4] ne "x86_64";
701 ok(run(test([@ssltest, "-cipher", "AES128-SHA", "-bytes", "8m"])));
703 # We happen to know that AES128-SHA256 is TLSv1.2 only... for now.
704 skip "TLSv1.2 is not supported by this OpenSSL configuration", 1
707 ok(run(test([@ssltest, "-cipher", "AES128-SHA256", "-bytes", "8m"])));
711 subtest 'DTLS Version min/max tests' => sub {
713 push(@protos, "dtls1") unless ($no_dtls1 || $no_dtls);
714 push(@protos, "dtls1.2") unless ($no_dtls1_2 || $no_dtls);
715 my @minprotos = (undef, @protos);
716 my @maxprotos = (@protos, undef);
717 my @shdprotos = (@protos, $protos[$#protos]);
718 my $n = ((@protos+2) * (@protos+3))/2 - 2;
719 my $ntests = $n * $n;
720 plan tests => $ntests;
722 skip "DTLS disabled", 1 if $ntests == 1;
725 for (my $smin = 0; $smin < @minprotos; ++$smin) {
726 for (my $smax = $smin ? $smin - 1 : 0; $smax < @maxprotos; ++$smax) {
727 for (my $cmin = 0; $cmin < @minprotos; ++$cmin) {
728 for (my $cmax = $cmin ? $cmin - 1 : 0; $cmax < @maxprotos; ++$cmax) {
729 if ($cmax < $smin-1) {
730 $should = "fail-server";
731 } elsif ($smax < $cmin-1) {
732 $should = "fail-client";
733 } elsif ($cmax > $smax) {
734 $should = $shdprotos[$smax];
736 $should = $shdprotos[$cmax];
739 my @args = (@ssltest, "-dtls");
740 push(@args, "-should_negotiate", $should);
741 push(@args, "-server_min_proto", $minprotos[$smin])
742 if (defined($minprotos[$smin]));
743 push(@args, "-server_max_proto", $maxprotos[$smax])
744 if (defined($maxprotos[$smax]));
745 push(@args, "-client_min_proto", $minprotos[$cmin])
746 if (defined($minprotos[$cmin]));
747 push(@args, "-client_max_proto", $maxprotos[$cmax])
748 if (defined($maxprotos[$cmax]));
749 my $ok = run(test[@args]);
751 print STDERR "\nsmin=$smin, smax=$smax, cmin=$cmin, cmax=$cmax\n";
752 print STDERR "\nFailed: @args\n";
758 subtest 'TLS session reuse' => sub {
762 skip "TLS1.1 or TLS1.2 disabled", 12 if $no_tls1_1 || $no_tls1_2;
763 ok(run(test([@ssltest, "-server_sess_out", $server_sess, "-client_sess_out", $client_sess])));
764 ok(run(test([@ssltest, "-server_sess_in", $server_sess, "-client_sess_in", $client_sess, "-should_reuse", "1", "-should_negotiate", "tls1.2"])));
765 ok(run(test([@ssltest, "-server_max_proto", "tls1.1", "-server_sess_in", $server_sess, "-client_sess_in", $client_sess, "-should_reuse", "0", "-should_negotiate", "tls1.1"])));
767 ok(run(test([@ssltest, "-server_max_proto", "tls1.1", "-server_sess_out", $server_sess, "-client_sess_out", $client_sess])));
768 ok(run(test([@ssltest, "-server_max_proto", "tls1.1", "-server_sess_in", $server_sess, "-client_sess_in", $client_sess, "-should_reuse", "1", "-should_negotiate", "tls1.1"])));
769 ok(run(test([@ssltest, "-server_sess_in", $server_sess, "-client_sess_in", $client_sess, "-should_reuse", "0", "-should_negotiate", "tls1.2"])));
771 ok(run(test([@ssltest, "-no_ticket", "-server_sess_out", $server_sess, "-client_sess_out", $client_sess])));
772 ok(run(test([@ssltest, "-no_ticket", "-server_sess_in", $server_sess, "-client_sess_in", $client_sess, "-should_reuse", "1", "-should_negotiate", "tls1.2"])));
773 ok(run(test([@ssltest, "-no_ticket", "-server_max_proto", "tls1.1", "-server_sess_in", $server_sess, "-client_sess_in", $client_sess, "-should_reuse", "0", "-should_negotiate", "tls1.1"])));
775 ok(run(test([@ssltest, "-no_ticket", "-server_max_proto", "tls1.1", "-server_sess_out", $server_sess, "-client_sess_out", $client_sess])));
776 ok(run(test([@ssltest, "-no_ticket", "-server_max_proto", "tls1.1", "-server_sess_in", $server_sess, "-client_sess_in", $client_sess, "-should_reuse", "1", "-should_negotiate", "tls1.1"])));
777 ok(run(test([@ssltest, "-no_ticket", "-server_sess_in", $server_sess, "-client_sess_in", $client_sess, "-should_reuse", "0", "-should_negotiate", "tls1.2"])));
781 subtest 'DTLS session reuse' => sub {
784 skip "DTLS disabled", 12 if $no_dtls;
786 ok(run(test([@ssltest, "-dtls", "-server_sess_out", $server_sess, "-client_sess_out", $client_sess])));
787 ok(run(test([@ssltest, "-dtls", "-server_sess_in", $server_sess, "-client_sess_in", $client_sess, "-should_reuse", "1", "-should_negotiate", "dtls1.2"])));
788 ok(run(test([@ssltest, "-dtls", "-server_max_proto", "dtls1", "-server_sess_in", $server_sess, "-client_sess_in", $client_sess, "-should_reuse", "0", "-should_negotiate", "dtls1"])));
790 ok(run(test([@ssltest, "-dtls", "-server_max_proto", "dtls1", "-server_sess_out", $server_sess, "-client_sess_out", $client_sess])));
791 ok(run(test([@ssltest, "-dtls", "-server_max_proto", "dtls1", "-server_sess_in", $server_sess, "-client_sess_in", $client_sess, "-should_reuse", "1", "-should_negotiate", "dtls1"])));
792 ok(run(test([@ssltest, "-dtls", "-server_sess_in", $server_sess, "-client_sess_in", $client_sess, "-should_reuse", "0", "-should_negotiate", "dtls1.2"])));
794 ok(run(test([@ssltest, "-dtls", "-no_ticket", "-server_sess_out", $server_sess, "-client_sess_out", $client_sess])));
795 ok(run(test([@ssltest, "-dtls", "-no_ticket", "-server_sess_in", $server_sess, "-client_sess_in", $client_sess, "-should_reuse", "1", "-should_negotiate", "dtls1.2"])));
796 ok(run(test([@ssltest, "-dtls", "-no_ticket", "-server_max_proto", "dtls1", "-server_sess_in", $server_sess, "-client_sess_in", $client_sess, "-should_reuse", "0", "-should_negotiate", "dtls1"])));
798 ok(run(test([@ssltest, "-dtls", "-no_ticket", "-server_max_proto", "dtls1", "-server_sess_out", $server_sess, "-client_sess_out", $client_sess])));
799 ok(run(test([@ssltest, "-dtls", "-no_ticket", "-server_max_proto", "dtls1", "-server_sess_in", $server_sess, "-client_sess_in", $client_sess, "-should_reuse", "1", "-should_negotiate", "dtls1"])));
800 ok(run(test([@ssltest, "-dtls", "-no_ticket", "-server_sess_in", $server_sess, "-client_sess_in", $client_sess, "-should_reuse", "0", "-should_negotiate", "dtls1.2"])));
804 subtest 'Certificate Transparency tests' => sub {
805 ######################################################################
810 skip "Certificate Transparency is not supported by this OpenSSL build", 3
812 skip "TLSv1.0 is not supported by this OpenSSL build", 3
815 $ENV{CTLOG_FILE} = srctop_file("test", "ct", "log_list.conf");
816 my @ca = qw(-CAfile certCA.ss);
817 ok(run(test([@ssltest, @ca, "-bio_pair", "-tls1", "-noct"])));
818 # No SCTs provided, so this should fail.
819 ok(run(test([@ssltest, @ca, "-bio_pair", "-tls1", "-ct",
820 "-should_negotiate", "fail-client"])));
821 # No SCTs provided, unverified chains still succeed.
822 ok(run(test([@ssltest, "-bio_pair", "-tls1", "-ct"])));