9 use OpenSSL::Test qw/:DEFAULT with bldtop_file srctop_file cmdstr/;
10 use OpenSSL::Test::Utils;
14 $ENV{CTLOG_FILE} = srctop_file("test", "ct", "log_list.conf");
16 my ($no_rsa, $no_dsa, $no_dh, $no_ec, $no_srp, $no_psk,
17 $no_ssl3, $no_tls1, $no_tls1_1, $no_tls1_2,
18 $no_dtls, $no_dtls1, $no_dtls1_2, $no_ct) =
19 anydisabled qw/rsa dsa dh ec srp psk
20 ssl3 tls1 tls1_1 tls1_2
21 dtls dtls1 dtls1_2 ct/;
22 my $no_anytls = alldisabled(available_protocols("tls"));
23 my $no_anydtls = alldisabled(available_protocols("dtls"));
25 plan skip_all => "No SSL/TLS/DTLS protocol is support by this OpenSSL build"
26 if $no_anytls && $no_anydtls;
29 my @reqcmd = ("openssl", "req");
30 my @x509cmd = ("openssl", "x509", $digest);
31 my @verifycmd = ("openssl", "verify");
32 my $dummycnf = srctop_file("apps", "openssl.cnf");
34 my $CAkey = "keyCA.ss";
35 my $CAcert="certCA.ss";
36 my $CAserial="certCA.srl";
38 my $CAconf=srctop_file("test","CAss.cnf");
39 my $CAreq2="req2CA.ss"; # temp
41 my $Uconf=srctop_file("test","Uss.cnf");
54 my $P1conf=srctop_file("test","P1ss.cnf");
57 my $P1cert="certP1.ss";
58 my $P1intermediate="tmp_intP1.ss";
60 my $P2conf=srctop_file("test","P2ss.cnf");
63 my $P2cert="certP2.ss";
64 my $P2intermediate="tmp_intP2.ss";
66 my $server_sess="server.ss";
67 my $client_sess="client.ss";
69 # ssltest_old.c is deprecated in favour of the new framework in ssl_test.c
70 # If you're adding tests here, you probably want to convert them to the
71 # new format in ssl_test.c and add recipes to 80-test_ssl_new.t instead.
74 + 1 # For ssltest_old -test_cipherlist
75 + 14 # For the first testssl
76 + 16 # For the first testsslproxy
77 + 16 # For the second testsslproxy
80 subtest 'test_ss' => sub {
82 open OUT, ">", "intP1.ss";
83 copy($CAcert, \*OUT); copy($Ucert, \*OUT);
86 open OUT, ">", "intP2.ss";
87 copy($CAcert, \*OUT); copy($Ucert, \*OUT); copy($P1cert, \*OUT);
92 my $check = ok(run(test(["ssltest_old","-test_cipherlist"])), "running ssltest_old");
95 skip "ssltest_old ended with error, skipping the rest", 3
98 note('test_ssl -- key U');
99 testssl("keyU.ss", $Ucert, $CAcert);
101 note('test_ssl -- key P1');
102 testsslproxy("keyP1.ss", "certP1.ss", "intP1.ss", "AB");
104 note('test_ssl -- key P2');
105 testsslproxy("keyP2.ss", "certP2.ss", "intP2.ss", "BC");
111 open RND, ">>", ".rnd";
112 print RND "string to make the random number generator think it has entropy";
115 my @req_dsa = ("-newkey",
116 "dsa:".srctop_file("apps", "dsa1024.pem"));
127 skip 'failure', 16 unless
128 ok(run(app([@reqcmd, "-config", $CAconf,
129 "-out", $CAreq, "-keyout", $CAkey,
131 'make cert request');
133 skip 'failure', 15 unless
134 ok(run(app([@x509cmd, "-CAcreateserial", "-in", $CAreq, "-days", "30",
135 "-req", "-out", $CAcert, "-signkey", $CAkey,
136 "-extfile", $CAconf, "-extensions", "v3_ca"],
137 stdout => "err.ss")),
138 'convert request into self-signed cert');
140 skip 'failure', 14 unless
141 ok(run(app([@x509cmd, "-in", $CAcert,
142 "-x509toreq", "-signkey", $CAkey, "-out", $CAreq2],
143 stdout => "err.ss")),
144 'convert cert into a cert request');
146 skip 'failure', 13 unless
147 ok(run(app([@reqcmd, "-config", $dummycnf,
148 "-verify", "-in", $CAreq, "-noout"])),
152 skip 'failure', 12 unless
153 ok(run(app([@reqcmd, "-config", $dummycnf,
154 "-verify", "-in", $CAreq2, "-noout"])),
157 skip 'failure', 11 unless
158 ok(run(app([@verifycmd, "-CAfile", $CAcert, $CAcert])),
161 skip 'failure', 10 unless
162 ok(run(app([@reqcmd, "-config", $Uconf,
163 "-out", $Ureq, "-keyout", $Ukey, @req_new],
164 stdout => "err.ss")),
165 'make a user cert request');
167 skip 'failure', 9 unless
168 ok(run(app([@x509cmd, "-CAcreateserial", "-in", $Ureq, "-days", "30",
169 "-req", "-out", $Ucert,
170 "-CA", $CAcert, "-CAkey", $CAkey, "-CAserial", $CAserial,
171 "-extfile", $Uconf, "-extensions", "v3_ee"],
173 && run(app([@verifycmd, "-CAfile", $CAcert, $Ucert])),
174 'sign user cert request');
176 skip 'failure', 8 unless
177 ok(run(app([@x509cmd,
178 "-subject", "-issuer", "-startdate", "-enddate",
179 "-noout", "-in", $Ucert])),
180 'Certificate details');
182 skip 'failure', 7 unless
183 subtest 'DSA certificate creation' => sub {
184 plan skip_all => "skipping DSA certificate creation"
190 $ENV{CN2} = "DSA Certificate";
191 skip 'failure', 3 unless
192 ok(run(app([@reqcmd, "-config", $Uconf,
193 "-out", $Dreq, "-keyout", $Dkey,
195 stdout => "err.ss")),
196 "make a DSA user cert request");
197 skip 'failure', 2 unless
198 ok(run(app([@x509cmd, "-CAcreateserial",
203 "-CA", $CAcert, "-CAkey", $CAkey,
204 "-CAserial", $CAserial,
206 "-extensions", "v3_ee_dsa"],
207 stdout => "err.ss")),
208 "sign DSA user cert request");
209 skip 'failure', 1 unless
210 ok(run(app([@verifycmd, "-CAfile", $CAcert, $Dcert])),
211 "verify DSA user cert");
212 skip 'failure', 0 unless
213 ok(run(app([@x509cmd,
214 "-subject", "-issuer",
215 "-startdate", "-enddate", "-noout",
217 "DSA Certificate details");
221 skip 'failure', 6 unless
222 subtest 'ECDSA/ECDH certificate creation' => sub {
223 plan skip_all => "skipping ECDSA/ECDH certificate creation"
229 $ENV{CN2} = "ECDSA Certificate";
230 skip 'failure', 4 unless
231 ok(run(app(["openssl", "ecparam", "-name", "P-256",
233 "make EC parameters");
234 skip 'failure', 3 unless
235 ok(run(app([@reqcmd, "-config", $Uconf,
236 "-out", $Ereq, "-keyout", $Ekey,
237 "-newkey", "ec:ecp.ss"],
238 stdout => "err.ss")),
239 "make a ECDSA/ECDH user cert request");
240 skip 'failure', 2 unless
241 ok(run(app([@x509cmd, "-CAcreateserial",
246 "-CA", $CAcert, "-CAkey", $CAkey,
247 "-CAserial", $CAserial,
249 "-extensions", "v3_ee_ec"],
250 stdout => "err.ss")),
251 "sign ECDSA/ECDH user cert request");
252 skip 'failure', 1 unless
253 ok(run(app([@verifycmd, "-CAfile", $CAcert, $Ecert])),
254 "verify ECDSA/ECDH user cert");
255 skip 'failure', 0 unless
256 ok(run(app([@x509cmd,
257 "-subject", "-issuer",
258 "-startdate", "-enddate", "-noout",
260 "ECDSA Certificate details");
264 skip 'failure', 5 unless
265 ok(run(app([@reqcmd, "-config", $P1conf,
266 "-out", $P1req, "-keyout", $P1key, @req_new],
267 stdout => "err.ss")),
268 'make a proxy cert request');
271 skip 'failure', 4 unless
272 ok(run(app([@x509cmd, "-CAcreateserial", "-in", $P1req, "-days", "30",
273 "-req", "-out", $P1cert,
274 "-CA", $Ucert, "-CAkey", $Ukey,
275 "-extfile", $P1conf, "-extensions", "v3_proxy"],
276 stdout => "err.ss")),
277 'sign proxy with user cert');
279 copy($Ucert, $P1intermediate);
280 run(app([@verifycmd, "-CAfile", $CAcert,
281 "-untrusted", $P1intermediate, $P1cert]));
282 ok(run(app([@x509cmd,
283 "-subject", "-issuer", "-startdate", "-enddate",
284 "-noout", "-in", $P1cert])),
285 'Certificate details');
287 skip 'failure', 2 unless
288 ok(run(app([@reqcmd, "-config", $P2conf,
289 "-out", $P2req, "-keyout", $P2key,
291 stdout => "err.ss")),
292 'make another proxy cert request');
295 skip 'failure', 1 unless
296 ok(run(app([@x509cmd, "-CAcreateserial", "-in", $P2req, "-days", "30",
297 "-req", "-out", $P2cert,
298 "-CA", $P1cert, "-CAkey", $P1key,
299 "-extfile", $P2conf, "-extensions", "v3_proxy"],
300 stdout => "err.ss")),
301 'sign second proxy cert request with the first proxy cert');
304 open OUT, ">", $P2intermediate;
305 copy($Ucert, \*OUT); copy($P1cert, \*OUT);
307 run(app([@verifycmd, "-CAfile", $CAcert,
308 "-untrusted", $P2intermediate, $P2cert]));
309 ok(run(app([@x509cmd,
310 "-subject", "-issuer", "-startdate", "-enddate",
311 "-noout", "-in", $P2cert])),
312 'Certificate details');
317 my $key = shift || bldtop_file("apps","server.pem");
318 my $cert = shift || bldtop_file("apps","server.pem");
320 my @CA = $CAtmp ? ("-CAfile", $CAtmp) : ("-CApath", bldtop_dir("certs"));
323 my @ssltest = ("ssltest_old",
324 "-s_key", $key, "-s_cert", $cert,
325 "-c_key", $key, "-c_cert", $cert);
327 my $serverinfo = srctop_file("test","serverinfo.pem");
330 if (grep /DSA Public Key/, run(app(["openssl", "x509", "-in", $cert,
331 "-text", "-noout"]), capture => 1)) {
338 subtest 'standard SSL tests' => sub {
339 ######################################################################
343 skip "SSLv3 is not supported by this OpenSSL build", 4
346 ok(run(test([@ssltest, "-ssl3", @extra])),
348 ok(run(test([@ssltest, "-ssl3", "-server_auth", @CA, @extra])),
349 'test sslv3 with server authentication');
350 ok(run(test([@ssltest, "-ssl3", "-client_auth", @CA, @extra])),
351 'test sslv3 with client authentication');
352 ok(run(test([@ssltest, "-ssl3", "-server_auth", "-client_auth", @CA, @extra])),
353 'test sslv3 with both server and client authentication');
357 skip "Neither SSLv3 nor any TLS version are supported by this OpenSSL build", 4
360 ok(run(test([@ssltest, @extra])),
362 ok(run(test([@ssltest, "-server_auth", @CA, @extra])),
363 'test sslv2/sslv3 with server authentication');
364 ok(run(test([@ssltest, "-client_auth", @CA, @extra])),
365 'test sslv2/sslv3 with client authentication');
366 ok(run(test([@ssltest, "-server_auth", "-client_auth", @CA, @extra])),
367 'test sslv2/sslv3 with both server and client authentication');
371 skip "SSLv3 is not supported by this OpenSSL build", 4
374 ok(run(test([@ssltest, "-bio_pair", "-ssl3", @extra])),
375 'test sslv3 via BIO pair');
376 ok(run(test([@ssltest, "-bio_pair", "-ssl3", "-server_auth", @CA, @extra])),
377 'test sslv3 with server authentication via BIO pair');
378 ok(run(test([@ssltest, "-bio_pair", "-ssl3", "-client_auth", @CA, @extra])),
379 'test sslv3 with client authentication via BIO pair');
380 ok(run(test([@ssltest, "-bio_pair", "-ssl3", "-server_auth", "-client_auth", @CA, @extra])),
381 'test sslv3 with both server and client authentication via BIO pair');
385 skip "Neither SSLv3 nor any TLS version are supported by this OpenSSL build", 1
388 ok(run(test([@ssltest, "-bio_pair", @extra])),
389 'test sslv2/sslv3 via BIO pair');
393 skip "DTLSv1 is not supported by this OpenSSL build", 4
394 if disabled("dtls1");
396 ok(run(test([@ssltest, "-dtls1", @extra])),
398 ok(run(test([@ssltest, "-dtls1", "-server_auth", @CA, @extra])),
399 'test dtlsv1 with server authentication');
400 ok(run(test([@ssltest, "-dtls1", "-client_auth", @CA, @extra])),
401 'test dtlsv1 with client authentication');
402 ok(run(test([@ssltest, "-dtls1", "-server_auth", "-client_auth", @CA, @extra])),
403 'test dtlsv1 with both server and client authentication');
407 skip "DTLSv1.2 is not supported by this OpenSSL build", 4
408 if disabled("dtls1_2");
410 ok(run(test([@ssltest, "-dtls12", @extra])),
412 ok(run(test([@ssltest, "-dtls12", "-server_auth", @CA, @extra])),
413 'test dtlsv1.2 with server authentication');
414 ok(run(test([@ssltest, "-dtls12", "-client_auth", @CA, @extra])),
415 'test dtlsv1.2 with client authentication');
416 ok(run(test([@ssltest, "-dtls12", "-server_auth", "-client_auth", @CA, @extra])),
417 'test dtlsv1.2 with both server and client authentication');
421 skip "Neither SSLv3 nor any TLS version are supported by this OpenSSL build", 8
425 skip "skipping test of sslv2/sslv3 w/o (EC)DHE test", 1 if $dsa_cert;
427 ok(run(test([@ssltest, "-bio_pair", "-no_dhe", "-no_ecdhe", @extra])),
428 'test sslv2/sslv3 w/o (EC)DHE via BIO pair');
431 ok(run(test([@ssltest, "-bio_pair", "-dhe1024dsa", "-v", @extra])),
432 'test sslv2/sslv3 with 1024bit DHE via BIO pair');
433 ok(run(test([@ssltest, "-bio_pair", "-server_auth", @CA, @extra])),
434 'test sslv2/sslv3 with server authentication');
435 ok(run(test([@ssltest, "-bio_pair", "-client_auth", @CA, @extra])),
436 'test sslv2/sslv3 with client authentication via BIO pair');
437 ok(run(test([@ssltest, "-bio_pair", "-server_auth", "-client_auth", @CA, @extra])),
438 'test sslv2/sslv3 with both client and server authentication via BIO pair');
439 ok(run(test([@ssltest, "-bio_pair", "-server_auth", "-client_auth", "-app_verify", @CA, @extra])),
440 'test sslv2/sslv3 with both client and server authentication via BIO pair and app verify');
443 skip "No IPv4 available on this machine", 1
444 unless !disabled("sock") && have_IPv4();
445 ok(run(test([@ssltest, "-ipv4", @extra])),
446 'test TLS via IPv4');
450 skip "No IPv6 available on this machine", 1
451 unless !disabled("sock") && have_IPv6();
452 ok(run(test([@ssltest, "-ipv6", @extra])),
453 'test TLS via IPv6');
458 subtest "Testing ciphersuites" => sub {
461 my $ciphers = "-EXP:-PSK:-SRP:-kDH:-kECDHe";
464 note "skipping DHE tests\n";
465 $ciphers .= ":-kDHE";
468 note "skipping DSA tests\n";
469 $ciphers .= ":-aDSA";
471 push @exkeys, "-s_cert", "certD.ss", "-s_key", "keyD.ss";
475 note "skipping EC tests\n";
476 $ciphers .= ":!aECDSA:!kECDH";
478 push @exkeys, "-s_cert", "certE.ss", "-s_key", "keyE.ss";
482 # FIXME: I feel unsure about the following line, is that really just TLSv1.2, or is it all of the SSLv3/TLS protocols?
483 push(@protocols, "TLSv1.2") unless $no_tls1_2;
484 push(@protocols, "SSLv3") unless $no_ssl3;
485 my $protocolciphersuitcount = 0;
488 map { split(/:/, $_) }
489 run(app(["openssl", "ciphers", "${_}:$ciphers"]),
491 map { s/\R//; } @c; # chomp @c;
492 $protocolciphersuitcount += scalar @c;
493 $_ => [ @c ] } @protocols;
495 plan skip_all => "None of the ciphersuites to test are available in this OpenSSL build"
496 if $protocolciphersuitcount + scalar(@protocols) == 0;
498 # The count of protocols is because in addition to the ciphersuits
499 # we got above, we're running a weak DH test for each protocol
500 plan tests => $protocolciphersuitcount + scalar(@protocols);
502 foreach my $protocol (@protocols) {
503 note "Testing ciphersuites for $protocol";
504 foreach my $cipher (@{$ciphersuites{$protocol}}) {
505 ok(run(test([@ssltest, @exkeys, "-cipher", $cipher,
506 $protocol eq "SSLv3" ? ("-ssl3") : ()])),
509 is(run(test([@ssltest,
511 "-c_cipher", 'EDH:@SECLEVEL=1',
513 $protocol eq "SSLv3" ? ("-ssl3") : ()])), 0,
514 "testing connection with weak DH, expecting failure");
518 subtest 'RSA/(EC)DHE/PSK tests' => sub {
519 ######################################################################
524 skip "TLSv1.0 is not supported by this OpenSSL build", 5
528 skip "skipping anonymous DH tests", 1
531 ok(run(test([@ssltest, "-v", "-bio_pair", "-tls1", "-cipher", "ADH", "-dhe1024dsa", "-num", "10", "-f", "-time", @extra])),
532 'test tlsv1 with 1024bit anonymous DH, multiple handshakes');
536 skip "skipping RSA tests", 2
539 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])),
540 'test tlsv1 with 1024bit RSA, no (EC)DHE, multiple handshakes');
542 skip "skipping RSA+DHE tests", 1
545 ok(run(test(["ssltest_old", "-v", "-bio_pair", "-tls1", "-s_cert", srctop_file("apps","server2.pem"), "-dhe1024dsa", "-num", "10", "-f", "-time", @extra])),
546 'test tlsv1 with 1024bit RSA, 1024bit DHE, multiple handshakes');
550 skip "skipping PSK tests", 2
553 ok(run(test([@ssltest, "-tls1", "-cipher", "PSK", "-psk", "abc123", @extra])),
554 'test tls1 with PSK');
556 ok(run(test([@ssltest, "-bio_pair", "-tls1", "-cipher", "PSK", "-psk", "abc123", @extra])),
557 'test tls1 with PSK via BIO pair');
563 subtest 'Next Protocol Negotiation Tests' => sub {
564 ######################################################################
569 skip "TLSv1.0 is not supported by this OpenSSL build", 7
571 skip "Next Protocol Negotiation is not supported by this OpenSSL build", 7
572 if disabled("nextprotoneg");
574 ok(run(test([@ssltest, "-bio_pair", "-tls1", "-npn_client"])));
575 ok(run(test([@ssltest, "-bio_pair", "-tls1", "-npn_server"])));
576 ok(run(test([@ssltest, "-bio_pair", "-tls1", "-npn_server_reject"])));
577 ok(run(test([@ssltest, "-bio_pair", "-tls1", "-npn_client", "-npn_server_reject"])));
578 ok(run(test([@ssltest, "-bio_pair", "-tls1", "-npn_client", "-npn_server"])));
579 ok(run(test([@ssltest, "-bio_pair", "-tls1", "-npn_client", "-npn_server", "-num", "2"])));
580 ok(run(test([@ssltest, "-bio_pair", "-tls1", "-npn_client", "-npn_server", "-num", "2", "-reuse"])));
584 subtest 'Custom Extension tests' => sub {
585 ######################################################################
590 skip "TLSv1.0 is not supported by this OpenSSL build", 1
593 ok(run(test([@ssltest, "-bio_pair", "-tls1", "-custom_ext"])),
594 'test tls1 with custom extensions');
598 subtest 'Serverinfo tests' => sub {
599 ######################################################################
604 skip "TLSv1.0 is not supported by this OpenSSL build", 5
607 note('echo test tls1 with serverinfo');
608 ok(run(test([@ssltest, "-bio_pair", "-tls1", "-serverinfo_file", $serverinfo])));
609 ok(run(test([@ssltest, "-bio_pair", "-tls1", "-serverinfo_file", $serverinfo, "-serverinfo_sct"])));
610 ok(run(test([@ssltest, "-bio_pair", "-tls1", "-serverinfo_file", $serverinfo, "-serverinfo_tack"])));
611 ok(run(test([@ssltest, "-bio_pair", "-tls1", "-serverinfo_file", $serverinfo, "-serverinfo_sct", "-serverinfo_tack"])));
612 ok(run(test([@ssltest, "-bio_pair", "-tls1", "-custom_ext", "-serverinfo_file", $serverinfo, "-serverinfo_sct", "-serverinfo_tack"])));
616 subtest 'SNI tests' => sub {
621 skip "TLSv1.x is not supported by this OpenSSL build", 7
622 if $no_tls1 && $no_tls1_1 && $no_tls1_2;
624 ok(run(test([@ssltest, "-bio_pair", "-sn_client", "foo"])));
625 ok(run(test([@ssltest, "-bio_pair", "-sn_server1", "foo"])));
626 ok(run(test([@ssltest, "-bio_pair", "-sn_client", "foo", "-sn_server1", "foo", "-sn_expect1"])));
627 ok(run(test([@ssltest, "-bio_pair", "-sn_client", "foo", "-sn_server1", "bar", "-sn_expect1"])));
628 ok(run(test([@ssltest, "-bio_pair", "-sn_client", "foo", "-sn_server1", "foo", "-sn_server2", "bar", "-sn_expect1"])));
629 ok(run(test([@ssltest, "-bio_pair", "-sn_client", "bar", "-sn_server1", "foo", "-sn_server2", "bar", "-sn_expect2"])));
630 # Negative test - make sure it doesn't crash, and doesn't switch contexts
631 ok(run(test([@ssltest, "-bio_pair", "-sn_client", "foobar", "-sn_server1", "foo", "-sn_server2", "bar", "-sn_expect1"])));
635 subtest 'ALPN tests' => sub {
636 ######################################################################
641 skip "TLSv1.0 is not supported by this OpenSSL build", 13
644 ok(run(test([@ssltest, "-bio_pair", "-tls1", "-alpn_client", "foo"])));
645 ok(run(test([@ssltest, "-bio_pair", "-tls1", "-alpn_server", "foo"])));
646 ok(run(test([@ssltest, "-bio_pair", "-tls1", "-alpn_client", "foo", "-alpn_server", "foo", "-alpn_expected", "foo"])));
647 ok(run(test([@ssltest, "-bio_pair", "-tls1", "-alpn_client", "foo,bar", "-alpn_server", "foo", "-alpn_expected", "foo"])));
648 ok(run(test([@ssltest, "-bio_pair", "-tls1", "-alpn_client", "bar,foo", "-alpn_server", "foo", "-alpn_expected", "foo"])));
649 ok(run(test([@ssltest, "-bio_pair", "-tls1", "-alpn_client", "bar,foo", "-alpn_server", "foo,bar", "-alpn_expected", "foo"])));
650 ok(run(test([@ssltest, "-bio_pair", "-tls1", "-alpn_client", "bar,foo", "-alpn_server", "bar,foo", "-alpn_expected", "bar"])));
651 ok(run(test([@ssltest, "-bio_pair", "-tls1", "-alpn_client", "foo,bar", "-alpn_server", "bar,foo", "-alpn_expected", "bar"])));
653 is(run(test([@ssltest, "-bio_pair", "-tls1", "-alpn_client", "foo", "-alpn_server", "bar"])), 0,
654 "Testing ALPN with protocol mismatch, expecting failure");
655 is(run(test([@ssltest, "-bio_pair", "-tls1", "-alpn_client", "baz", "-alpn_server", "bar,foo"])), 0,
656 "Testing ALPN with protocol mismatch, expecting failure");
659 ok(run(test([@ssltest, "-bio_pair",
660 "-alpn_client", "foo,bar", "-sn_client", "alice",
661 "-alpn_server1", "foo,123", "-sn_server1", "alice",
662 "-alpn_server2", "bar,456", "-sn_server2", "bob",
663 "-alpn_expected", "foo"])));
664 ok(run(test([@ssltest, "-bio_pair",
665 "-alpn_client", "foo,bar", "-sn_client", "bob",
666 "-alpn_server1", "foo,123", "-sn_server1", "alice",
667 "-alpn_server2", "bar,456", "-sn_server2", "bob",
668 "-alpn_expected", "bar"])));
669 ok(run(test([@ssltest, "-bio_pair",
670 "-alpn_client", "foo,bar", "-sn_client", "bob",
671 "-alpn_server2", "bar,456", "-sn_server2", "bob",
672 "-alpn_expected", "bar"])));
676 subtest 'SRP tests' => sub {
681 skip "skipping SRP tests", 4
684 ok(run(test([@ssltest, "-tls1", "-cipher", "SRP", "-srpuser", "test", "-srppass", "abc123"])),
685 'test tls1 with SRP');
687 ok(run(test([@ssltest, "-bio_pair", "-tls1", "-cipher", "SRP", "-srpuser", "test", "-srppass", "abc123"])),
688 'test tls1 with SRP via BIO pair');
690 ok(run(test([@ssltest, "-tls1", "-cipher", "aSRP", "-srpuser", "test", "-srppass", "abc123"])),
691 'test tls1 with SRP auth');
693 ok(run(test([@ssltest, "-bio_pair", "-tls1", "-cipher", "aSRP", "-srpuser", "test", "-srppass", "abc123"])),
694 'test tls1 with SRP auth via BIO pair');
698 subtest 'Multi-buffer tests' => sub {
699 ######################################################################
704 skip "Neither SSLv3 nor any TLS version are supported by this OpenSSL build", 2
707 skip "skipping multi-buffer tests", 2
708 if @extra || (POSIX::uname())[4] ne "x86_64";
710 ok(run(test([@ssltest, "-cipher", "AES128-SHA", "-bytes", "8m"])));
712 # We happen to know that AES128-SHA256 is TLSv1.2 only... for now.
713 skip "TLSv1.2 is not supported by this OpenSSL configuration", 1
716 ok(run(test([@ssltest, "-cipher", "AES128-SHA256", "-bytes", "8m"])));
720 subtest 'DTLS Version min/max tests' => sub {
722 push(@protos, "dtls1") unless ($no_dtls1 || $no_dtls);
723 push(@protos, "dtls1.2") unless ($no_dtls1_2 || $no_dtls);
724 my @minprotos = (undef, @protos);
725 my @maxprotos = (@protos, undef);
726 my @shdprotos = (@protos, $protos[$#protos]);
727 my $n = ((@protos+2) * (@protos+3))/2 - 2;
728 my $ntests = $n * $n;
729 plan tests => $ntests;
731 skip "DTLS disabled", 1 if $ntests == 1;
734 for (my $smin = 0; $smin < @minprotos; ++$smin) {
735 for (my $smax = $smin ? $smin - 1 : 0; $smax < @maxprotos; ++$smax) {
736 for (my $cmin = 0; $cmin < @minprotos; ++$cmin) {
737 for (my $cmax = $cmin ? $cmin - 1 : 0; $cmax < @maxprotos; ++$cmax) {
738 if ($cmax < $smin-1) {
739 $should = "fail-server";
740 } elsif ($smax < $cmin-1) {
741 $should = "fail-client";
742 } elsif ($cmax > $smax) {
743 $should = $shdprotos[$smax];
745 $should = $shdprotos[$cmax];
748 my @args = (@ssltest, "-dtls");
749 push(@args, "-should_negotiate", $should);
750 push(@args, "-server_min_proto", $minprotos[$smin])
751 if (defined($minprotos[$smin]));
752 push(@args, "-server_max_proto", $maxprotos[$smax])
753 if (defined($maxprotos[$smax]));
754 push(@args, "-client_min_proto", $minprotos[$cmin])
755 if (defined($minprotos[$cmin]));
756 push(@args, "-client_max_proto", $maxprotos[$cmax])
757 if (defined($maxprotos[$cmax]));
758 my $ok = run(test[@args]);
760 print STDERR "\nsmin=$smin, smax=$smax, cmin=$cmin, cmax=$cmax\n";
761 print STDERR "\nFailed: @args\n";
767 subtest 'TLS session reuse' => sub {
770 ok(run(test([@ssltest, "-server_sess_out", $server_sess, "-client_sess_out", $client_sess])));
771 ok(run(test([@ssltest, "-server_sess_in", $server_sess, "-client_sess_in", $client_sess, "-should_reuse", "1", "-should_negotiate", "tls1.2"])));
772 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"])));
774 ok(run(test([@ssltest, "-server_max_proto", "tls1.1", "-server_sess_out", $server_sess, "-client_sess_out", $client_sess])));
775 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"])));
776 ok(run(test([@ssltest, "-server_sess_in", $server_sess, "-client_sess_in", $client_sess, "-should_reuse", "0", "-should_negotiate", "tls1.2"])));
778 ok(run(test([@ssltest, "-no_ticket", "-server_sess_out", $server_sess, "-client_sess_out", $client_sess])));
779 ok(run(test([@ssltest, "-no_ticket", "-server_sess_in", $server_sess, "-client_sess_in", $client_sess, "-should_reuse", "1", "-should_negotiate", "tls1.2"])));
780 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"])));
782 ok(run(test([@ssltest, "-no_ticket", "-server_max_proto", "tls1.1", "-server_sess_out", $server_sess, "-client_sess_out", $client_sess])));
783 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"])));
784 ok(run(test([@ssltest, "-no_ticket", "-server_sess_in", $server_sess, "-client_sess_in", $client_sess, "-should_reuse", "0", "-should_negotiate", "tls1.2"])));
787 subtest 'DTLS session reuse' => sub {
790 skip "DTLS disabled", 12 if $no_dtls;
792 ok(run(test([@ssltest, "-dtls", "-server_sess_out", $server_sess, "-client_sess_out", $client_sess])));
793 ok(run(test([@ssltest, "-dtls", "-server_sess_in", $server_sess, "-client_sess_in", $client_sess, "-should_reuse", "1", "-should_negotiate", "dtls1.2"])));
794 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"])));
796 ok(run(test([@ssltest, "-dtls", "-server_max_proto", "dtls1", "-server_sess_out", $server_sess, "-client_sess_out", $client_sess])));
797 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"])));
798 ok(run(test([@ssltest, "-dtls", "-server_sess_in", $server_sess, "-client_sess_in", $client_sess, "-should_reuse", "0", "-should_negotiate", "dtls1.2"])));
800 ok(run(test([@ssltest, "-dtls", "-no_ticket", "-server_sess_out", $server_sess, "-client_sess_out", $client_sess])));
801 ok(run(test([@ssltest, "-dtls", "-no_ticket", "-server_sess_in", $server_sess, "-client_sess_in", $client_sess, "-should_reuse", "1", "-should_negotiate", "dtls1.2"])));
802 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"])));
804 ok(run(test([@ssltest, "-dtls", "-no_ticket", "-server_max_proto", "dtls1", "-server_sess_out", $server_sess, "-client_sess_out", $client_sess])));
805 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"])));
806 ok(run(test([@ssltest, "-dtls", "-no_ticket", "-server_sess_in", $server_sess, "-client_sess_in", $client_sess, "-should_reuse", "0", "-should_negotiate", "dtls1.2"])));
810 subtest 'Certificate Transparency tests' => sub {
811 ######################################################################
816 skip "Certificate Transparency is not supported by this OpenSSL build", 3
818 skip "TLSv1.0 is not supported by this OpenSSL build", 3
821 $ENV{CTLOG_FILE} = srctop_file("test", "ct", "log_list.conf");
822 my @ca = qw(-CAfile certCA.ss);
823 ok(run(test([@ssltest, @ca, "-bio_pair", "-tls1", "-noct"])));
824 # No SCTs provided, so this should fail.
825 ok(run(test([@ssltest, @ca, "-bio_pair", "-tls1", "-ct",
826 "-should_negotiate", "fail-client"])));
827 # No SCTs provided, unverified chains still succeed.
828 ok(run(test([@ssltest, "-bio_pair", "-tls1", "-ct"])));
834 my $key = shift || srctop_file("apps","server.pem");
835 my $cert = shift || srctop_file("apps","server.pem");
837 my @CA = $CAtmp ? ("-CAfile", $CAtmp) : ("-CApath", bldtop_dir("certs"));
840 my @ssltest = ("ssltest_old",
841 "-s_key", $key, "-s_cert", $cert,
842 "-c_key", $key, "-c_cert", $cert);
846 note('Testing a lot of proxy conditions.');
848 # We happen to know that certP1.ss has policy letters "AB" and
849 # certP2.ss has policy letters "BC". However, because certP2.ss
850 # has certP1.ss as issuer, when it's used, both their policy
851 # letters get combined into just "B".
852 # The policy letter(s) then get filtered with the given auth letter
853 # in the table below, and the result gets tested with the given
854 # condition. For details, read ssltest_old.c
856 # certfilename => [ [ auth, cond, expected result ] ... ]
857 my %expected = ( "certP1.ss" => [ [ [ 'A', 'A' ], 1 ],
860 [ [ 'A', 'A|B&!C' ], 1 ],
864 [ [ 'B', 'A|B&!C' ], 1 ],
868 [ [ 'C', 'A|B&!C' ], 0 ],
869 [ [ 'BC', 'A' ], 0 ],
870 [ [ 'BC', 'B' ], 1 ],
871 [ [ 'BC', 'C' ], 0 ],
872 [ [ 'BC', 'A|B&!C' ], 1 ] ],
873 "certP2.ss" => [ [ [ 'A', 'A' ], 0 ],
876 [ [ 'A', 'A|B&!C' ], 0 ],
880 [ [ 'B', 'A|B&!C' ], 1 ],
884 [ [ 'C', 'A|B&!C' ], 0 ],
885 [ [ 'BC', 'A' ], 0 ],
886 [ [ 'BC', 'B' ], 1 ],
887 [ [ 'BC', 'C' ], 0 ],
888 [ [ 'BC', 'A|B&!C' ], 1 ] ] );
891 skip "Neither SSLv3 nor any TLS version are supported by this OpenSSL build", scalar(@{$expected{$cert}})
894 foreach (@{$expected{$cert}}) {
895 my $auth = $_->[0]->[0];
896 my $cond = $_->[0]->[1];
898 is(run(test([@ssltest, "-server_auth", @CA,
899 "-proxy", "-proxy_auth", $auth,
900 "-proxy_cond", $cond])), $res,
901 "test tlsv1, server auth, proxy auth $auth and cond $cond (expect "
902 .($res ? "success" : "failure").")");