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 + 1 # For ssltest_old -test_cipherlist
82 + 14 # For the first testssl
83 + 16 # For the first testsslproxy
84 + 16 # For the second testsslproxy
87 subtest 'test_ss' => sub {
89 open OUT, ">", "intP1.ss";
90 copy($CAcert, \*OUT); copy($Ucert, \*OUT);
93 open OUT, ">", "intP2.ss";
94 copy($CAcert, \*OUT); copy($Ucert, \*OUT); copy($P1cert, \*OUT);
99 my $check = ok(run(test(["ssltest_old","-test_cipherlist"])), "running ssltest_old");
102 skip "ssltest_old ended with error, skipping the rest", 3
105 note('test_ssl -- key U');
106 testssl("keyU.ss", $Ucert, $CAcert);
108 note('test_ssl -- key P1');
109 testsslproxy("keyP1.ss", "certP1.ss", "intP1.ss", "AB");
111 note('test_ssl -- key P2');
112 testsslproxy("keyP2.ss", "certP2.ss", "intP2.ss", "BC");
118 open RND, ">>", ".rnd";
119 print RND "string to make the random number generator think it has entropy";
122 my @req_dsa = ("-newkey",
123 "dsa:".srctop_file("apps", "dsa1024.pem"));
134 skip 'failure', 16 unless
135 ok(run(app([@reqcmd, "-config", $CAconf,
136 "-out", $CAreq, "-keyout", $CAkey,
138 'make cert request');
140 skip 'failure', 15 unless
141 ok(run(app([@x509cmd, "-CAcreateserial", "-in", $CAreq, "-days", "30",
142 "-req", "-out", $CAcert, "-signkey", $CAkey,
143 "-extfile", $CAconf, "-extensions", "v3_ca"],
144 stdout => "err.ss")),
145 'convert request into self-signed cert');
147 skip 'failure', 14 unless
148 ok(run(app([@x509cmd, "-in", $CAcert,
149 "-x509toreq", "-signkey", $CAkey, "-out", $CAreq2],
150 stdout => "err.ss")),
151 'convert cert into a cert request');
153 skip 'failure', 13 unless
154 ok(run(app([@reqcmd, "-config", $dummycnf,
155 "-verify", "-in", $CAreq, "-noout"])),
159 skip 'failure', 12 unless
160 ok(run(app([@reqcmd, "-config", $dummycnf,
161 "-verify", "-in", $CAreq2, "-noout"])),
164 skip 'failure', 11 unless
165 ok(run(app([@verifycmd, "-CAfile", $CAcert, $CAcert])),
168 skip 'failure', 10 unless
169 ok(run(app([@reqcmd, "-config", $Uconf,
170 "-out", $Ureq, "-keyout", $Ukey, @req_new],
171 stdout => "err.ss")),
172 'make a user cert request');
174 skip 'failure', 9 unless
175 ok(run(app([@x509cmd, "-CAcreateserial", "-in", $Ureq, "-days", "30",
176 "-req", "-out", $Ucert,
177 "-CA", $CAcert, "-CAkey", $CAkey, "-CAserial", $CAserial,
178 "-extfile", $Uconf, "-extensions", "v3_ee"],
180 && run(app([@verifycmd, "-CAfile", $CAcert, $Ucert])),
181 'sign user cert request');
183 skip 'failure', 8 unless
184 ok(run(app([@x509cmd,
185 "-subject", "-issuer", "-startdate", "-enddate",
186 "-noout", "-in", $Ucert])),
187 'Certificate details');
189 skip 'failure', 7 unless
190 subtest 'DSA certificate creation' => sub {
191 plan skip_all => "skipping DSA certificate creation"
197 $ENV{CN2} = "DSA Certificate";
198 skip 'failure', 3 unless
199 ok(run(app([@reqcmd, "-config", $Uconf,
200 "-out", $Dreq, "-keyout", $Dkey,
202 stdout => "err.ss")),
203 "make a DSA user cert request");
204 skip 'failure', 2 unless
205 ok(run(app([@x509cmd, "-CAcreateserial",
210 "-CA", $CAcert, "-CAkey", $CAkey,
211 "-CAserial", $CAserial,
213 "-extensions", "v3_ee_dsa"],
214 stdout => "err.ss")),
215 "sign DSA user cert request");
216 skip 'failure', 1 unless
217 ok(run(app([@verifycmd, "-CAfile", $CAcert, $Dcert])),
218 "verify DSA user cert");
219 skip 'failure', 0 unless
220 ok(run(app([@x509cmd,
221 "-subject", "-issuer",
222 "-startdate", "-enddate", "-noout",
224 "DSA Certificate details");
228 skip 'failure', 6 unless
229 subtest 'ECDSA/ECDH certificate creation' => sub {
230 plan skip_all => "skipping ECDSA/ECDH certificate creation"
236 $ENV{CN2} = "ECDSA Certificate";
237 skip 'failure', 4 unless
238 ok(run(app(["openssl", "ecparam", "-name", "P-256",
240 "make EC parameters");
241 skip 'failure', 3 unless
242 ok(run(app([@reqcmd, "-config", $Uconf,
243 "-out", $Ereq, "-keyout", $Ekey,
244 "-newkey", "ec:ecp.ss"],
245 stdout => "err.ss")),
246 "make a ECDSA/ECDH user cert request");
247 skip 'failure', 2 unless
248 ok(run(app([@x509cmd, "-CAcreateserial",
253 "-CA", $CAcert, "-CAkey", $CAkey,
254 "-CAserial", $CAserial,
256 "-extensions", "v3_ee_ec"],
257 stdout => "err.ss")),
258 "sign ECDSA/ECDH user cert request");
259 skip 'failure', 1 unless
260 ok(run(app([@verifycmd, "-CAfile", $CAcert, $Ecert])),
261 "verify ECDSA/ECDH user cert");
262 skip 'failure', 0 unless
263 ok(run(app([@x509cmd,
264 "-subject", "-issuer",
265 "-startdate", "-enddate", "-noout",
267 "ECDSA Certificate details");
271 skip 'failure', 5 unless
272 ok(run(app([@reqcmd, "-config", $P1conf,
273 "-out", $P1req, "-keyout", $P1key, @req_new],
274 stdout => "err.ss")),
275 'make a proxy cert request');
278 skip 'failure', 4 unless
279 ok(run(app([@x509cmd, "-CAcreateserial", "-in", $P1req, "-days", "30",
280 "-req", "-out", $P1cert,
281 "-CA", $Ucert, "-CAkey", $Ukey,
282 "-extfile", $P1conf, "-extensions", "v3_proxy"],
283 stdout => "err.ss")),
284 'sign proxy with user cert');
286 copy($Ucert, $P1intermediate);
287 run(app([@verifycmd, "-CAfile", $CAcert,
288 "-untrusted", $P1intermediate, $P1cert]));
289 ok(run(app([@x509cmd,
290 "-subject", "-issuer", "-startdate", "-enddate",
291 "-noout", "-in", $P1cert])),
292 'Certificate details');
294 skip 'failure', 2 unless
295 ok(run(app([@reqcmd, "-config", $P2conf,
296 "-out", $P2req, "-keyout", $P2key,
298 stdout => "err.ss")),
299 'make another proxy cert request');
302 skip 'failure', 1 unless
303 ok(run(app([@x509cmd, "-CAcreateserial", "-in", $P2req, "-days", "30",
304 "-req", "-out", $P2cert,
305 "-CA", $P1cert, "-CAkey", $P1key,
306 "-extfile", $P2conf, "-extensions", "v3_proxy"],
307 stdout => "err.ss")),
308 'sign second proxy cert request with the first proxy cert');
311 open OUT, ">", $P2intermediate;
312 copy($Ucert, \*OUT); copy($P1cert, \*OUT);
314 run(app([@verifycmd, "-CAfile", $CAcert,
315 "-untrusted", $P2intermediate, $P2cert]));
316 ok(run(app([@x509cmd,
317 "-subject", "-issuer", "-startdate", "-enddate",
318 "-noout", "-in", $P2cert])),
319 'Certificate details');
324 my $key = shift || bldtop_file("apps","server.pem");
325 my $cert = shift || bldtop_file("apps","server.pem");
327 my @CA = $CAtmp ? ("-CAfile", $CAtmp) : ("-CApath", bldtop_dir("certs"));
330 my @ssltest = ("ssltest_old",
331 "-s_key", $key, "-s_cert", $cert,
332 "-c_key", $key, "-c_cert", $cert);
334 my $serverinfo = srctop_file("test","serverinfo.pem");
337 if (grep /DSA Public Key/, run(app(["openssl", "x509", "-in", $cert,
338 "-text", "-noout"]), capture => 1)) {
345 subtest 'standard SSL tests' => sub {
346 ######################################################################
350 skip "SSLv3 is not supported by this OpenSSL build", 4
353 ok(run(test([@ssltest, "-ssl3", @extra])),
355 ok(run(test([@ssltest, "-ssl3", "-server_auth", @CA, @extra])),
356 'test sslv3 with server authentication');
357 ok(run(test([@ssltest, "-ssl3", "-client_auth", @CA, @extra])),
358 'test sslv3 with client authentication');
359 ok(run(test([@ssltest, "-ssl3", "-server_auth", "-client_auth", @CA, @extra])),
360 'test sslv3 with both server and client authentication');
364 skip "Neither SSLv3 nor any TLS version are supported by this OpenSSL build", 4
367 ok(run(test([@ssltest, @extra])),
369 ok(run(test([@ssltest, "-server_auth", @CA, @extra])),
370 'test sslv2/sslv3 with server authentication');
371 ok(run(test([@ssltest, "-client_auth", @CA, @extra])),
372 'test sslv2/sslv3 with client authentication');
373 ok(run(test([@ssltest, "-server_auth", "-client_auth", @CA, @extra])),
374 'test sslv2/sslv3 with both server and client authentication');
378 skip "SSLv3 is not supported by this OpenSSL build", 4
381 ok(run(test([@ssltest, "-bio_pair", "-ssl3", @extra])),
382 'test sslv3 via BIO pair');
383 ok(run(test([@ssltest, "-bio_pair", "-ssl3", "-server_auth", @CA, @extra])),
384 'test sslv3 with server authentication via BIO pair');
385 ok(run(test([@ssltest, "-bio_pair", "-ssl3", "-client_auth", @CA, @extra])),
386 'test sslv3 with client authentication via BIO pair');
387 ok(run(test([@ssltest, "-bio_pair", "-ssl3", "-server_auth", "-client_auth", @CA, @extra])),
388 'test sslv3 with both server and client authentication via BIO pair');
392 skip "Neither SSLv3 nor any TLS version are supported by this OpenSSL build", 1
395 ok(run(test([@ssltest, "-bio_pair", @extra])),
396 'test sslv2/sslv3 via BIO pair');
400 skip "DTLSv1 is not supported by this OpenSSL build", 4
401 if disabled("dtls1");
403 ok(run(test([@ssltest, "-dtls1", @extra])),
405 ok(run(test([@ssltest, "-dtls1", "-server_auth", @CA, @extra])),
406 'test dtlsv1 with server authentication');
407 ok(run(test([@ssltest, "-dtls1", "-client_auth", @CA, @extra])),
408 'test dtlsv1 with client authentication');
409 ok(run(test([@ssltest, "-dtls1", "-server_auth", "-client_auth", @CA, @extra])),
410 'test dtlsv1 with both server and client authentication');
414 skip "DTLSv1.2 is not supported by this OpenSSL build", 4
415 if disabled("dtls1_2");
417 ok(run(test([@ssltest, "-dtls12", @extra])),
419 ok(run(test([@ssltest, "-dtls12", "-server_auth", @CA, @extra])),
420 'test dtlsv1.2 with server authentication');
421 ok(run(test([@ssltest, "-dtls12", "-client_auth", @CA, @extra])),
422 'test dtlsv1.2 with client authentication');
423 ok(run(test([@ssltest, "-dtls12", "-server_auth", "-client_auth", @CA, @extra])),
424 'test dtlsv1.2 with both server and client authentication');
428 skip "Neither SSLv3 nor any TLS version are supported by this OpenSSL build", 8
432 skip "skipping test of sslv2/sslv3 w/o (EC)DHE test", 1 if $dsa_cert;
434 ok(run(test([@ssltest, "-bio_pair", "-no_dhe", "-no_ecdhe", @extra])),
435 'test sslv2/sslv3 w/o (EC)DHE via BIO pair');
438 ok(run(test([@ssltest, "-bio_pair", "-dhe1024dsa", "-v", @extra])),
439 'test sslv2/sslv3 with 1024bit DHE via BIO pair');
440 ok(run(test([@ssltest, "-bio_pair", "-server_auth", @CA, @extra])),
441 'test sslv2/sslv3 with server authentication');
442 ok(run(test([@ssltest, "-bio_pair", "-client_auth", @CA, @extra])),
443 'test sslv2/sslv3 with client authentication via BIO pair');
444 ok(run(test([@ssltest, "-bio_pair", "-server_auth", "-client_auth", @CA, @extra])),
445 'test sslv2/sslv3 with both client and server authentication via BIO pair');
446 ok(run(test([@ssltest, "-bio_pair", "-server_auth", "-client_auth", "-app_verify", @CA, @extra])),
447 'test sslv2/sslv3 with both client and server authentication via BIO pair and app verify');
450 skip "No IPv4 available on this machine", 1
451 unless !disabled("sock") && have_IPv4();
452 ok(run(test([@ssltest, "-ipv4", @extra])),
453 'test TLS via IPv4');
457 skip "No IPv6 available on this machine", 1
458 unless !disabled("sock") && have_IPv6();
459 ok(run(test([@ssltest, "-ipv6", @extra])),
460 'test TLS via IPv6');
465 subtest "Testing ciphersuites" => sub {
468 my $ciphers = "-EXP:-PSK:-SRP:-kDH:-kECDHe";
471 note "skipping DHE tests\n";
472 $ciphers .= ":-kDHE";
475 note "skipping DSA tests\n";
476 $ciphers .= ":-aDSA";
478 push @exkeys, "-s_cert", "certD.ss", "-s_key", "keyD.ss";
482 note "skipping EC tests\n";
483 $ciphers .= ":!aECDSA:!kECDH";
485 push @exkeys, "-s_cert", "certE.ss", "-s_key", "keyE.ss";
489 # FIXME: I feel unsure about the following line, is that really just TLSv1.2, or is it all of the SSLv3/TLS protocols?
490 push(@protocols, "TLSv1.2") unless $no_tls1_2;
491 push(@protocols, "SSLv3") unless $no_ssl3;
492 my $protocolciphersuitcount = 0;
495 map { split(/:/, $_) }
496 run(app(["openssl", "ciphers", "${_}:$ciphers"]),
498 map { s/\R//; } @c; # chomp @c;
499 $protocolciphersuitcount += scalar @c;
500 $_ => [ @c ] } @protocols;
502 plan skip_all => "None of the ciphersuites to test are available in this OpenSSL build"
503 if $protocolciphersuitcount + scalar(@protocols) == 0;
505 # The count of protocols is because in addition to the ciphersuits
506 # we got above, we're running a weak DH test for each protocol
507 plan tests => $protocolciphersuitcount + scalar(@protocols);
509 foreach my $protocol (@protocols) {
510 note "Testing ciphersuites for $protocol";
511 foreach my $cipher (@{$ciphersuites{$protocol}}) {
512 ok(run(test([@ssltest, @exkeys, "-cipher", $cipher,
513 $protocol eq "SSLv3" ? ("-ssl3") : ()])),
516 is(run(test([@ssltest,
518 "-c_cipher", 'EDH:@SECLEVEL=1',
520 $protocol eq "SSLv3" ? ("-ssl3") : ()])), 0,
521 "testing connection with weak DH, expecting failure");
525 subtest 'RSA/(EC)DHE/PSK tests' => sub {
526 ######################################################################
531 skip "TLSv1.0 is not supported by this OpenSSL build", 5
535 skip "skipping anonymous DH tests", 1
538 ok(run(test([@ssltest, "-v", "-bio_pair", "-tls1", "-cipher", "ADH", "-dhe1024dsa", "-num", "10", "-f", "-time", @extra])),
539 'test tlsv1 with 1024bit anonymous DH, multiple handshakes');
543 skip "skipping RSA tests", 2
546 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])),
547 'test tlsv1 with 1024bit RSA, no (EC)DHE, multiple handshakes');
549 skip "skipping RSA+DHE tests", 1
552 ok(run(test(["ssltest_old", "-v", "-bio_pair", "-tls1", "-s_cert", srctop_file("apps","server2.pem"), "-dhe1024dsa", "-num", "10", "-f", "-time", @extra])),
553 'test tlsv1 with 1024bit RSA, 1024bit DHE, multiple handshakes');
557 skip "skipping PSK tests", 2
560 ok(run(test([@ssltest, "-tls1", "-cipher", "PSK", "-psk", "abc123", @extra])),
561 'test tls1 with PSK');
563 ok(run(test([@ssltest, "-bio_pair", "-tls1", "-cipher", "PSK", "-psk", "abc123", @extra])),
564 'test tls1 with PSK via BIO pair');
570 subtest 'Next Protocol Negotiation Tests' => sub {
571 ######################################################################
576 skip "TLSv1.0 is not supported by this OpenSSL build", 7
578 skip "Next Protocol Negotiation is not supported by this OpenSSL build", 7
579 if disabled("nextprotoneg");
581 ok(run(test([@ssltest, "-bio_pair", "-tls1", "-npn_client"])));
582 ok(run(test([@ssltest, "-bio_pair", "-tls1", "-npn_server"])));
583 ok(run(test([@ssltest, "-bio_pair", "-tls1", "-npn_server_reject"])));
584 ok(run(test([@ssltest, "-bio_pair", "-tls1", "-npn_client", "-npn_server_reject"])));
585 ok(run(test([@ssltest, "-bio_pair", "-tls1", "-npn_client", "-npn_server"])));
586 ok(run(test([@ssltest, "-bio_pair", "-tls1", "-npn_client", "-npn_server", "-num", "2"])));
587 ok(run(test([@ssltest, "-bio_pair", "-tls1", "-npn_client", "-npn_server", "-num", "2", "-reuse"])));
591 subtest 'Custom Extension tests' => sub {
592 ######################################################################
597 skip "TLSv1.0 is not supported by this OpenSSL build", 1
600 ok(run(test([@ssltest, "-bio_pair", "-tls1", "-custom_ext"])),
601 'test tls1 with custom extensions');
605 subtest 'Serverinfo tests' => sub {
606 ######################################################################
611 skip "TLSv1.0 is not supported by this OpenSSL build", 5
614 note('echo test tls1 with serverinfo');
615 ok(run(test([@ssltest, "-bio_pair", "-tls1", "-serverinfo_file", $serverinfo])));
616 ok(run(test([@ssltest, "-bio_pair", "-tls1", "-serverinfo_file", $serverinfo, "-serverinfo_sct"])));
617 ok(run(test([@ssltest, "-bio_pair", "-tls1", "-serverinfo_file", $serverinfo, "-serverinfo_tack"])));
618 ok(run(test([@ssltest, "-bio_pair", "-tls1", "-serverinfo_file", $serverinfo, "-serverinfo_sct", "-serverinfo_tack"])));
619 ok(run(test([@ssltest, "-bio_pair", "-tls1", "-custom_ext", "-serverinfo_file", $serverinfo, "-serverinfo_sct", "-serverinfo_tack"])));
623 subtest 'SNI tests' => sub {
628 skip "TLSv1.x is not supported by this OpenSSL build", 7
629 if $no_tls1 && $no_tls1_1 && $no_tls1_2;
631 ok(run(test([@ssltest, "-bio_pair", "-sn_client", "foo"])));
632 ok(run(test([@ssltest, "-bio_pair", "-sn_server1", "foo"])));
633 ok(run(test([@ssltest, "-bio_pair", "-sn_client", "foo", "-sn_server1", "foo", "-sn_expect1"])));
634 ok(run(test([@ssltest, "-bio_pair", "-sn_client", "foo", "-sn_server1", "bar", "-sn_expect1"])));
635 ok(run(test([@ssltest, "-bio_pair", "-sn_client", "foo", "-sn_server1", "foo", "-sn_server2", "bar", "-sn_expect1"])));
636 ok(run(test([@ssltest, "-bio_pair", "-sn_client", "bar", "-sn_server1", "foo", "-sn_server2", "bar", "-sn_expect2"])));
637 # Negative test - make sure it doesn't crash, and doesn't switch contexts
638 ok(run(test([@ssltest, "-bio_pair", "-sn_client", "foobar", "-sn_server1", "foo", "-sn_server2", "bar", "-sn_expect1"])));
642 subtest 'ALPN tests' => sub {
643 ######################################################################
648 skip "TLSv1.0 is not supported by this OpenSSL build", 13
651 ok(run(test([@ssltest, "-bio_pair", "-tls1", "-alpn_client", "foo"])));
652 ok(run(test([@ssltest, "-bio_pair", "-tls1", "-alpn_server", "foo"])));
653 ok(run(test([@ssltest, "-bio_pair", "-tls1", "-alpn_client", "foo", "-alpn_server", "foo", "-alpn_expected", "foo"])));
654 ok(run(test([@ssltest, "-bio_pair", "-tls1", "-alpn_client", "foo,bar", "-alpn_server", "foo", "-alpn_expected", "foo"])));
655 ok(run(test([@ssltest, "-bio_pair", "-tls1", "-alpn_client", "bar,foo", "-alpn_server", "foo", "-alpn_expected", "foo"])));
656 ok(run(test([@ssltest, "-bio_pair", "-tls1", "-alpn_client", "bar,foo", "-alpn_server", "foo,bar", "-alpn_expected", "foo"])));
657 ok(run(test([@ssltest, "-bio_pair", "-tls1", "-alpn_client", "bar,foo", "-alpn_server", "bar,foo", "-alpn_expected", "bar"])));
658 ok(run(test([@ssltest, "-bio_pair", "-tls1", "-alpn_client", "foo,bar", "-alpn_server", "bar,foo", "-alpn_expected", "bar"])));
660 is(run(test([@ssltest, "-bio_pair", "-tls1", "-alpn_client", "foo", "-alpn_server", "bar"])), 0,
661 "Testing ALPN with protocol mismatch, expecting failure");
662 is(run(test([@ssltest, "-bio_pair", "-tls1", "-alpn_client", "baz", "-alpn_server", "bar,foo"])), 0,
663 "Testing ALPN with protocol mismatch, expecting failure");
666 ok(run(test([@ssltest, "-bio_pair",
667 "-alpn_client", "foo,bar", "-sn_client", "alice",
668 "-alpn_server1", "foo,123", "-sn_server1", "alice",
669 "-alpn_server2", "bar,456", "-sn_server2", "bob",
670 "-alpn_expected", "foo"])));
671 ok(run(test([@ssltest, "-bio_pair",
672 "-alpn_client", "foo,bar", "-sn_client", "bob",
673 "-alpn_server1", "foo,123", "-sn_server1", "alice",
674 "-alpn_server2", "bar,456", "-sn_server2", "bob",
675 "-alpn_expected", "bar"])));
676 ok(run(test([@ssltest, "-bio_pair",
677 "-alpn_client", "foo,bar", "-sn_client", "bob",
678 "-alpn_server2", "bar,456", "-sn_server2", "bob",
679 "-alpn_expected", "bar"])));
683 subtest 'SRP tests' => sub {
688 skip "skipping SRP tests", 4
691 ok(run(test([@ssltest, "-tls1", "-cipher", "SRP", "-srpuser", "test", "-srppass", "abc123"])),
692 'test tls1 with SRP');
694 ok(run(test([@ssltest, "-bio_pair", "-tls1", "-cipher", "SRP", "-srpuser", "test", "-srppass", "abc123"])),
695 'test tls1 with SRP via BIO pair');
697 ok(run(test([@ssltest, "-tls1", "-cipher", "aSRP", "-srpuser", "test", "-srppass", "abc123"])),
698 'test tls1 with SRP auth');
700 ok(run(test([@ssltest, "-bio_pair", "-tls1", "-cipher", "aSRP", "-srpuser", "test", "-srppass", "abc123"])),
701 'test tls1 with SRP auth via BIO pair');
705 subtest 'Multi-buffer tests' => sub {
706 ######################################################################
711 skip "Neither SSLv3 nor any TLS version are supported by this OpenSSL build", 2
714 skip "skipping multi-buffer tests", 2
715 if @extra || (POSIX::uname())[4] ne "x86_64";
717 ok(run(test([@ssltest, "-cipher", "AES128-SHA", "-bytes", "8m"])));
719 # We happen to know that AES128-SHA256 is TLSv1.2 only... for now.
720 skip "TLSv1.2 is not supported by this OpenSSL configuration", 1
723 ok(run(test([@ssltest, "-cipher", "AES128-SHA256", "-bytes", "8m"])));
727 subtest 'DTLS Version min/max tests' => sub {
729 push(@protos, "dtls1") unless ($no_dtls1 || $no_dtls);
730 push(@protos, "dtls1.2") unless ($no_dtls1_2 || $no_dtls);
731 my @minprotos = (undef, @protos);
732 my @maxprotos = (@protos, undef);
733 my @shdprotos = (@protos, $protos[$#protos]);
734 my $n = ((@protos+2) * (@protos+3))/2 - 2;
735 my $ntests = $n * $n;
736 plan tests => $ntests;
738 skip "DTLS disabled", 1 if $ntests == 1;
741 for (my $smin = 0; $smin < @minprotos; ++$smin) {
742 for (my $smax = $smin ? $smin - 1 : 0; $smax < @maxprotos; ++$smax) {
743 for (my $cmin = 0; $cmin < @minprotos; ++$cmin) {
744 for (my $cmax = $cmin ? $cmin - 1 : 0; $cmax < @maxprotos; ++$cmax) {
745 if ($cmax < $smin-1) {
746 $should = "fail-server";
747 } elsif ($smax < $cmin-1) {
748 $should = "fail-client";
749 } elsif ($cmax > $smax) {
750 $should = $shdprotos[$smax];
752 $should = $shdprotos[$cmax];
755 my @args = (@ssltest, "-dtls");
756 push(@args, "-should_negotiate", $should);
757 push(@args, "-server_min_proto", $minprotos[$smin])
758 if (defined($minprotos[$smin]));
759 push(@args, "-server_max_proto", $maxprotos[$smax])
760 if (defined($maxprotos[$smax]));
761 push(@args, "-client_min_proto", $minprotos[$cmin])
762 if (defined($minprotos[$cmin]));
763 push(@args, "-client_max_proto", $maxprotos[$cmax])
764 if (defined($maxprotos[$cmax]));
765 my $ok = run(test[@args]);
767 print STDERR "\nsmin=$smin, smax=$smax, cmin=$cmin, cmax=$cmax\n";
768 print STDERR "\nFailed: @args\n";
774 subtest 'TLS session reuse' => sub {
778 skip "TLS1.1 or TLS1.2 disabled", 12 if $no_tls1_1 || $no_tls1_2;
779 ok(run(test([@ssltest, "-server_sess_out", $server_sess, "-client_sess_out", $client_sess])));
780 ok(run(test([@ssltest, "-server_sess_in", $server_sess, "-client_sess_in", $client_sess, "-should_reuse", "1", "-should_negotiate", "tls1.2"])));
781 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"])));
783 ok(run(test([@ssltest, "-server_max_proto", "tls1.1", "-server_sess_out", $server_sess, "-client_sess_out", $client_sess])));
784 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"])));
785 ok(run(test([@ssltest, "-server_sess_in", $server_sess, "-client_sess_in", $client_sess, "-should_reuse", "0", "-should_negotiate", "tls1.2"])));
787 ok(run(test([@ssltest, "-no_ticket", "-server_sess_out", $server_sess, "-client_sess_out", $client_sess])));
788 ok(run(test([@ssltest, "-no_ticket", "-server_sess_in", $server_sess, "-client_sess_in", $client_sess, "-should_reuse", "1", "-should_negotiate", "tls1.2"])));
789 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"])));
791 ok(run(test([@ssltest, "-no_ticket", "-server_max_proto", "tls1.1", "-server_sess_out", $server_sess, "-client_sess_out", $client_sess])));
792 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"])));
793 ok(run(test([@ssltest, "-no_ticket", "-server_sess_in", $server_sess, "-client_sess_in", $client_sess, "-should_reuse", "0", "-should_negotiate", "tls1.2"])));
797 subtest 'DTLS session reuse' => sub {
800 skip "DTLS disabled", 12 if $no_dtls;
802 ok(run(test([@ssltest, "-dtls", "-server_sess_out", $server_sess, "-client_sess_out", $client_sess])));
803 ok(run(test([@ssltest, "-dtls", "-server_sess_in", $server_sess, "-client_sess_in", $client_sess, "-should_reuse", "1", "-should_negotiate", "dtls1.2"])));
804 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"])));
806 ok(run(test([@ssltest, "-dtls", "-server_max_proto", "dtls1", "-server_sess_out", $server_sess, "-client_sess_out", $client_sess])));
807 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"])));
808 ok(run(test([@ssltest, "-dtls", "-server_sess_in", $server_sess, "-client_sess_in", $client_sess, "-should_reuse", "0", "-should_negotiate", "dtls1.2"])));
810 ok(run(test([@ssltest, "-dtls", "-no_ticket", "-server_sess_out", $server_sess, "-client_sess_out", $client_sess])));
811 ok(run(test([@ssltest, "-dtls", "-no_ticket", "-server_sess_in", $server_sess, "-client_sess_in", $client_sess, "-should_reuse", "1", "-should_negotiate", "dtls1.2"])));
812 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"])));
814 ok(run(test([@ssltest, "-dtls", "-no_ticket", "-server_max_proto", "dtls1", "-server_sess_out", $server_sess, "-client_sess_out", $client_sess])));
815 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"])));
816 ok(run(test([@ssltest, "-dtls", "-no_ticket", "-server_sess_in", $server_sess, "-client_sess_in", $client_sess, "-should_reuse", "0", "-should_negotiate", "dtls1.2"])));
820 subtest 'Certificate Transparency tests' => sub {
821 ######################################################################
826 skip "Certificate Transparency is not supported by this OpenSSL build", 3
828 skip "TLSv1.0 is not supported by this OpenSSL build", 3
831 $ENV{CTLOG_FILE} = srctop_file("test", "ct", "log_list.conf");
832 my @ca = qw(-CAfile certCA.ss);
833 ok(run(test([@ssltest, @ca, "-bio_pair", "-tls1", "-noct"])));
834 # No SCTs provided, so this should fail.
835 ok(run(test([@ssltest, @ca, "-bio_pair", "-tls1", "-ct",
836 "-should_negotiate", "fail-client"])));
837 # No SCTs provided, unverified chains still succeed.
838 ok(run(test([@ssltest, "-bio_pair", "-tls1", "-ct"])));
844 my $key = shift || srctop_file("apps","server.pem");
845 my $cert = shift || srctop_file("apps","server.pem");
847 my @CA = $CAtmp ? ("-CAfile", $CAtmp) : ("-CApath", bldtop_dir("certs"));
850 my @ssltest = ("ssltest_old",
851 "-s_key", $key, "-s_cert", $cert,
852 "-c_key", $key, "-c_cert", $cert);
856 note('Testing a lot of proxy conditions.');
858 # We happen to know that certP1.ss has policy letters "AB" and
859 # certP2.ss has policy letters "BC". However, because certP2.ss
860 # has certP1.ss as issuer, when it's used, both their policy
861 # letters get combined into just "B".
862 # The policy letter(s) then get filtered with the given auth letter
863 # in the table below, and the result gets tested with the given
864 # condition. For details, read ssltest_old.c
866 # certfilename => [ [ auth, cond, expected result ] ... ]
867 my %expected = ( "certP1.ss" => [ [ [ 'A', 'A' ], 1 ],
870 [ [ 'A', 'A|B&!C' ], 1 ],
874 [ [ 'B', 'A|B&!C' ], 1 ],
878 [ [ 'C', 'A|B&!C' ], 0 ],
879 [ [ 'BC', 'A' ], 0 ],
880 [ [ 'BC', 'B' ], 1 ],
881 [ [ 'BC', 'C' ], 0 ],
882 [ [ 'BC', 'A|B&!C' ], 1 ] ],
883 "certP2.ss" => [ [ [ 'A', 'A' ], 0 ],
886 [ [ 'A', 'A|B&!C' ], 0 ],
890 [ [ 'B', 'A|B&!C' ], 1 ],
894 [ [ 'C', 'A|B&!C' ], 0 ],
895 [ [ 'BC', 'A' ], 0 ],
896 [ [ 'BC', 'B' ], 1 ],
897 [ [ 'BC', 'C' ], 0 ],
898 [ [ 'BC', 'A|B&!C' ], 1 ] ] );
901 skip "Neither SSLv3 nor any TLS version are supported by this OpenSSL build", scalar(@{$expected{$cert}})
904 foreach (@{$expected{$cert}}) {
905 my $auth = $_->[0]->[0];
906 my $cond = $_->[0]->[1];
908 is(run(test([@ssltest, "-server_auth", @CA,
909 "-proxy", "-proxy_auth", $auth,
910 "-proxy_cond", $cond])), $res,
911 "test tlsv1, server auth, proxy auth $auth and cond $cond (expect "
912 .($res ? "success" : "failure").")");