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";
68 + 1 # For ssltest -test_cipherlist
69 + 13 # For the first testssl
70 + 16 # For the first testsslproxy
71 + 16 # For the second testsslproxy
74 subtest 'test_ss' => sub {
76 open OUT, ">", "intP1.ss";
77 copy($CAcert, \*OUT); copy($Ucert, \*OUT);
80 open OUT, ">", "intP2.ss";
81 copy($CAcert, \*OUT); copy($Ucert, \*OUT); copy($P1cert, \*OUT);
86 my $check = ok(run(test(["ssltest","-test_cipherlist"])), "running ssltest");
89 skip "ssltest ended with error, skipping the rest", 3
92 note('test_ssl -- key U');
93 testssl("keyU.ss", $Ucert, $CAcert);
95 note('test_ssl -- key P1');
96 testsslproxy("keyP1.ss", "certP1.ss", "intP1.ss", "AB");
98 note('test_ssl -- key P2');
99 testsslproxy("keyP2.ss", "certP2.ss", "intP2.ss", "BC");
105 open RND, ">>", ".rnd";
106 print RND "string to make the random number generator think it has entropy";
109 my @req_dsa = ("-newkey",
110 "dsa:".srctop_file("apps", "dsa1024.pem"));
121 skip 'failure', 16 unless
122 ok(run(app([@reqcmd, "-config", $CAconf,
123 "-out", $CAreq, "-keyout", $CAkey,
125 'make cert request');
127 skip 'failure', 15 unless
128 ok(run(app([@x509cmd, "-CAcreateserial", "-in", $CAreq, "-days", "30",
129 "-req", "-out", $CAcert, "-signkey", $CAkey,
130 "-extfile", $CAconf, "-extensions", "v3_ca"],
131 stdout => "err.ss")),
132 'convert request into self-signed cert');
134 skip 'failure', 14 unless
135 ok(run(app([@x509cmd, "-in", $CAcert,
136 "-x509toreq", "-signkey", $CAkey, "-out", $CAreq2],
137 stdout => "err.ss")),
138 'convert cert into a cert request');
140 skip 'failure', 13 unless
141 ok(run(app([@reqcmd, "-config", $dummycnf,
142 "-verify", "-in", $CAreq, "-noout"])),
146 skip 'failure', 12 unless
147 ok(run(app([@reqcmd, "-config", $dummycnf,
148 "-verify", "-in", $CAreq2, "-noout"])),
151 skip 'failure', 11 unless
152 ok(run(app([@verifycmd, "-CAfile", $CAcert, $CAcert])),
155 skip 'failure', 10 unless
156 ok(run(app([@reqcmd, "-config", $Uconf,
157 "-out", $Ureq, "-keyout", $Ukey, @req_new],
158 stdout => "err.ss")),
159 'make a user cert request');
161 skip 'failure', 9 unless
162 ok(run(app([@x509cmd, "-CAcreateserial", "-in", $Ureq, "-days", "30",
163 "-req", "-out", $Ucert,
164 "-CA", $CAcert, "-CAkey", $CAkey, "-CAserial", $CAserial,
165 "-extfile", $Uconf, "-extensions", "v3_ee"],
167 && run(app([@verifycmd, "-CAfile", $CAcert, $Ucert])),
168 'sign user cert request');
170 skip 'failure', 8 unless
171 ok(run(app([@x509cmd,
172 "-subject", "-issuer", "-startdate", "-enddate",
173 "-noout", "-in", $Ucert])),
174 'Certificate details');
176 skip 'failure', 7 unless
177 subtest 'DSA certificate creation' => sub {
178 plan skip_all => "skipping DSA certificate creation"
184 $ENV{CN2} = "DSA Certificate";
185 skip 'failure', 3 unless
186 ok(run(app([@reqcmd, "-config", $Uconf,
187 "-out", $Dreq, "-keyout", $Dkey,
189 stdout => "err.ss")),
190 "make a DSA user cert request");
191 skip 'failure', 2 unless
192 ok(run(app([@x509cmd, "-CAcreateserial",
197 "-CA", $CAcert, "-CAkey", $CAkey,
198 "-CAserial", $CAserial,
200 "-extensions", "v3_ee_dsa"],
201 stdout => "err.ss")),
202 "sign DSA user cert request");
203 skip 'failure', 1 unless
204 ok(run(app([@verifycmd, "-CAfile", $CAcert, $Dcert])),
205 "verify DSA user cert");
206 skip 'failure', 0 unless
207 ok(run(app([@x509cmd,
208 "-subject", "-issuer",
209 "-startdate", "-enddate", "-noout",
211 "DSA Certificate details");
215 skip 'failure', 6 unless
216 subtest 'ECDSA/ECDH certificate creation' => sub {
217 plan skip_all => "skipping ECDSA/ECDH certificate creation"
223 $ENV{CN2} = "ECDSA Certificate";
224 skip 'failure', 4 unless
225 ok(run(app(["openssl", "ecparam", "-name", "P-256",
227 "make EC parameters");
228 skip 'failure', 3 unless
229 ok(run(app([@reqcmd, "-config", $Uconf,
230 "-out", $Ereq, "-keyout", $Ekey,
231 "-newkey", "ec:ecp.ss"],
232 stdout => "err.ss")),
233 "make a ECDSA/ECDH user cert request");
234 skip 'failure', 2 unless
235 ok(run(app([@x509cmd, "-CAcreateserial",
240 "-CA", $CAcert, "-CAkey", $CAkey,
241 "-CAserial", $CAserial,
243 "-extensions", "v3_ee_ec"],
244 stdout => "err.ss")),
245 "sign ECDSA/ECDH user cert request");
246 skip 'failure', 1 unless
247 ok(run(app([@verifycmd, "-CAfile", $CAcert, $Ecert])),
248 "verify ECDSA/ECDH user cert");
249 skip 'failure', 0 unless
250 ok(run(app([@x509cmd,
251 "-subject", "-issuer",
252 "-startdate", "-enddate", "-noout",
254 "ECDSA Certificate details");
258 skip 'failure', 5 unless
259 ok(run(app([@reqcmd, "-config", $P1conf,
260 "-out", $P1req, "-keyout", $P1key, @req_new],
261 stdout => "err.ss")),
262 'make a proxy cert request');
265 skip 'failure', 4 unless
266 ok(run(app([@x509cmd, "-CAcreateserial", "-in", $P1req, "-days", "30",
267 "-req", "-out", $P1cert,
268 "-CA", $Ucert, "-CAkey", $Ukey,
269 "-extfile", $P1conf, "-extensions", "v3_proxy"],
270 stdout => "err.ss")),
271 'sign proxy with user cert');
273 copy($Ucert, $P1intermediate);
274 run(app([@verifycmd, "-CAfile", $CAcert,
275 "-untrusted", $P1intermediate, $P1cert]));
276 ok(run(app([@x509cmd,
277 "-subject", "-issuer", "-startdate", "-enddate",
278 "-noout", "-in", $P1cert])),
279 'Certificate details');
281 skip 'failure', 2 unless
282 ok(run(app([@reqcmd, "-config", $P2conf,
283 "-out", $P2req, "-keyout", $P2key,
285 stdout => "err.ss")),
286 'make another proxy cert request');
289 skip 'failure', 1 unless
290 ok(run(app([@x509cmd, "-CAcreateserial", "-in", $P2req, "-days", "30",
291 "-req", "-out", $P2cert,
292 "-CA", $P1cert, "-CAkey", $P1key,
293 "-extfile", $P2conf, "-extensions", "v3_proxy"],
294 stdout => "err.ss")),
295 'sign second proxy cert request with the first proxy cert');
298 open OUT, ">", $P2intermediate;
299 copy($Ucert, \*OUT); copy($P1cert, \*OUT);
301 run(app([@verifycmd, "-CAfile", $CAcert,
302 "-untrusted", $P2intermediate, $P2cert]));
303 ok(run(app([@x509cmd,
304 "-subject", "-issuer", "-startdate", "-enddate",
305 "-noout", "-in", $P2cert])),
306 'Certificate details');
311 my $key = shift || bldtop_file("apps","server.pem");
312 my $cert = shift || bldtop_file("apps","server.pem");
314 my @CA = $CAtmp ? ("-CAfile", $CAtmp) : ("-CApath", bldtop_dir("certs"));
317 my @ssltest = ("ssltest",
318 "-s_key", $key, "-s_cert", $cert,
319 "-c_key", $key, "-c_cert", $cert);
321 my $serverinfo = srctop_file("test","serverinfo.pem");
324 if (grep /DSA Public Key/, run(app(["openssl", "x509", "-in", $cert,
325 "-text", "-noout"]), capture => 1)) {
332 subtest 'standard SSL tests' => sub {
333 ######################################################################
337 skip "SSLv3 is not supported by this OpenSSL build", 4
340 ok(run(test([@ssltest, "-ssl3", @extra])),
342 ok(run(test([@ssltest, "-ssl3", "-server_auth", @CA, @extra])),
343 'test sslv3 with server authentication');
344 ok(run(test([@ssltest, "-ssl3", "-client_auth", @CA, @extra])),
345 'test sslv3 with client authentication');
346 ok(run(test([@ssltest, "-ssl3", "-server_auth", "-client_auth", @CA, @extra])),
347 'test sslv3 with both server and client authentication');
351 skip "Neither SSLv3 nor any TLS version are supported by this OpenSSL build", 4
354 ok(run(test([@ssltest, @extra])),
356 ok(run(test([@ssltest, "-server_auth", @CA, @extra])),
357 'test sslv2/sslv3 with server authentication');
358 ok(run(test([@ssltest, "-client_auth", @CA, @extra])),
359 'test sslv2/sslv3 with client authentication');
360 ok(run(test([@ssltest, "-server_auth", "-client_auth", @CA, @extra])),
361 'test sslv2/sslv3 with both server and client authentication');
365 skip "SSLv3 is not supported by this OpenSSL build", 4
368 ok(run(test([@ssltest, "-bio_pair", "-ssl3", @extra])),
369 'test sslv3 via BIO pair');
370 ok(run(test([@ssltest, "-bio_pair", "-ssl3", "-server_auth", @CA, @extra])),
371 'test sslv3 with server authentication via BIO pair');
372 ok(run(test([@ssltest, "-bio_pair", "-ssl3", "-client_auth", @CA, @extra])),
373 'test sslv3 with client authentication via BIO pair');
374 ok(run(test([@ssltest, "-bio_pair", "-ssl3", "-server_auth", "-client_auth", @CA, @extra])),
375 'test sslv3 with both server and client authentication via BIO pair');
379 skip "Neither SSLv3 nor any TLS version are supported by this OpenSSL build", 1
382 ok(run(test([@ssltest, "-bio_pair", @extra])),
383 'test sslv2/sslv3 via BIO pair');
387 skip "DTLSv1 is not supported by this OpenSSL build", 4
388 if disabled("dtls1");
390 ok(run(test([@ssltest, "-dtls1", @extra])),
392 ok(run(test([@ssltest, "-dtls1", "-server_auth", @CA, @extra])),
393 'test dtlsv1 with server authentication');
394 ok(run(test([@ssltest, "-dtls1", "-client_auth", @CA, @extra])),
395 'test dtlsv1 with client authentication');
396 ok(run(test([@ssltest, "-dtls1", "-server_auth", "-client_auth", @CA, @extra])),
397 'test dtlsv1 with both server and client authentication');
401 skip "DTLSv1.2 is not supported by this OpenSSL build", 4
402 if disabled("dtls1_2");
404 ok(run(test([@ssltest, "-dtls12", @extra])),
406 ok(run(test([@ssltest, "-dtls12", "-server_auth", @CA, @extra])),
407 'test dtlsv1.2 with server authentication');
408 ok(run(test([@ssltest, "-dtls12", "-client_auth", @CA, @extra])),
409 'test dtlsv1.2 with client authentication');
410 ok(run(test([@ssltest, "-dtls12", "-server_auth", "-client_auth", @CA, @extra])),
411 'test dtlsv1.2 with both server and client authentication');
415 skip "Neither SSLv3 nor any TLS version are supported by this OpenSSL build", 8
419 skip "skipping test of sslv2/sslv3 w/o (EC)DHE test", 1 if $dsa_cert;
421 ok(run(test([@ssltest, "-bio_pair", "-no_dhe", "-no_ecdhe", @extra])),
422 'test sslv2/sslv3 w/o (EC)DHE via BIO pair');
425 ok(run(test([@ssltest, "-bio_pair", "-dhe1024dsa", "-v", @extra])),
426 'test sslv2/sslv3 with 1024bit DHE via BIO pair');
427 ok(run(test([@ssltest, "-bio_pair", "-server_auth", @CA, @extra])),
428 'test sslv2/sslv3 with server authentication');
429 ok(run(test([@ssltest, "-bio_pair", "-client_auth", @CA, @extra])),
430 'test sslv2/sslv3 with client authentication via BIO pair');
431 ok(run(test([@ssltest, "-bio_pair", "-server_auth", "-client_auth", @CA, @extra])),
432 'test sslv2/sslv3 with both client and server authentication via BIO pair');
433 ok(run(test([@ssltest, "-bio_pair", "-server_auth", "-client_auth", "-app_verify", @CA, @extra])),
434 'test sslv2/sslv3 with both client and server authentication via BIO pair and app verify');
437 skip "No IPv4 available on this machine", 1
438 unless !disabled("sock") && have_IPv4();
439 ok(run(test([@ssltest, "-ipv4", @extra])),
440 'test TLS via IPv4');
444 skip "No IPv6 available on this machine", 1
445 unless !disabled("sock") && have_IPv6();
446 ok(run(test([@ssltest, "-ipv6", @extra])),
447 'test TLS via IPv6');
452 subtest "Testing ciphersuites" => sub {
455 my $ciphers = "-EXP:-PSK:-SRP:-kDH:-kECDHe";
458 note "skipping DHE tests\n";
459 $ciphers .= ":-kDHE";
462 note "skipping DSA tests\n";
463 $ciphers .= ":-aDSA";
465 push @exkeys, "-s_cert", "certD.ss", "-s_key", "keyD.ss";
469 note "skipping EC tests\n";
470 $ciphers .= ":!aECDSA:!kECDH";
472 push @exkeys, "-s_cert", "certE.ss", "-s_key", "keyE.ss";
476 # FIXME: I feel unsure about the following line, is that really just TLSv1.2, or is it all of the SSLv3/TLS protocols?
477 push(@protocols, "TLSv1.2") unless $no_tls1_2;
478 push(@protocols, "SSLv3") unless $no_ssl3;
479 my $protocolciphersuitcount = 0;
482 map { split(/:/, $_) }
483 run(app(["openssl", "ciphers", "${_}:$ciphers"]),
485 map { s/\R//; } @c; # chomp @c;
486 $protocolciphersuitcount += scalar @c;
487 $_ => [ @c ] } @protocols;
489 plan skip_all => "None of the ciphersuites to test are available in this OpenSSL build"
490 if $protocolciphersuitcount + scalar(@protocols) == 0;
492 # The count of protocols is because in addition to the ciphersuits
493 # we got above, we're running a weak DH test for each protocol
494 plan tests => $protocolciphersuitcount + scalar(@protocols);
496 foreach my $protocol (@protocols) {
497 note "Testing ciphersuites for $protocol";
498 foreach my $cipher (@{$ciphersuites{$protocol}}) {
499 ok(run(test([@ssltest, @exkeys, "-cipher", $cipher,
500 $protocol eq "SSLv3" ? ("-ssl3") : ()])),
503 is(run(test([@ssltest,
505 "-c_cipher", 'EDH:@SECLEVEL=1',
507 $protocol eq "SSLv3" ? ("-ssl3") : ()])), 0,
508 "testing connection with weak DH, expecting failure");
512 subtest 'RSA/(EC)DHE/PSK tests' => sub {
513 ######################################################################
518 skip "TLSv1.0 is not supported by this OpenSSL build", 5
522 skip "skipping anonymous DH tests", 1
525 ok(run(test([@ssltest, "-v", "-bio_pair", "-tls1", "-cipher", "ADH", "-dhe1024dsa", "-num", "10", "-f", "-time", @extra])),
526 'test tlsv1 with 1024bit anonymous DH, multiple handshakes');
530 skip "skipping RSA tests", 2
533 ok(run(test(["ssltest", "-v", "-bio_pair", "-tls1", "-s_cert", srctop_file("apps","server2.pem"), "-no_dhe", "-no_ecdhe", "-num", "10", "-f", "-time", @extra])),
534 'test tlsv1 with 1024bit RSA, no (EC)DHE, multiple handshakes');
536 skip "skipping RSA+DHE tests", 1
539 ok(run(test(["ssltest", "-v", "-bio_pair", "-tls1", "-s_cert", srctop_file("apps","server2.pem"), "-dhe1024dsa", "-num", "10", "-f", "-time", @extra])),
540 'test tlsv1 with 1024bit RSA, 1024bit DHE, multiple handshakes');
544 skip "skipping PSK tests", 2
547 ok(run(test([@ssltest, "-tls1", "-cipher", "PSK", "-psk", "abc123", @extra])),
548 'test tls1 with PSK');
550 ok(run(test([@ssltest, "-bio_pair", "-tls1", "-cipher", "PSK", "-psk", "abc123", @extra])),
551 'test tls1 with PSK via BIO pair');
557 subtest 'Next Protocol Negotiation Tests' => sub {
558 ######################################################################
563 skip "TLSv1.0 is not supported by this OpenSSL build", 7
566 ok(run(test([@ssltest, "-bio_pair", "-tls1", "-npn_client"])));
567 ok(run(test([@ssltest, "-bio_pair", "-tls1", "-npn_server"])));
568 ok(run(test([@ssltest, "-bio_pair", "-tls1", "-npn_server_reject"])));
569 ok(run(test([@ssltest, "-bio_pair", "-tls1", "-npn_client", "-npn_server_reject"])));
570 ok(run(test([@ssltest, "-bio_pair", "-tls1", "-npn_client", "-npn_server"])));
571 ok(run(test([@ssltest, "-bio_pair", "-tls1", "-npn_client", "-npn_server", "-num", "2"])));
572 ok(run(test([@ssltest, "-bio_pair", "-tls1", "-npn_client", "-npn_server", "-num", "2", "-reuse"])));
576 subtest 'Custom Extension tests' => sub {
577 ######################################################################
582 skip "TLSv1.0 is not supported by this OpenSSL build", 1
585 ok(run(test([@ssltest, "-bio_pair", "-tls1", "-custom_ext"])),
586 'test tls1 with custom extensions');
590 subtest 'Serverinfo tests' => sub {
591 ######################################################################
596 skip "TLSv1.0 is not supported by this OpenSSL build", 5
599 note('echo test tls1 with serverinfo');
600 ok(run(test([@ssltest, "-bio_pair", "-tls1", "-serverinfo_file", $serverinfo])));
601 ok(run(test([@ssltest, "-bio_pair", "-tls1", "-serverinfo_file", $serverinfo, "-serverinfo_sct"])));
602 ok(run(test([@ssltest, "-bio_pair", "-tls1", "-serverinfo_file", $serverinfo, "-serverinfo_tack"])));
603 ok(run(test([@ssltest, "-bio_pair", "-tls1", "-serverinfo_file", $serverinfo, "-serverinfo_sct", "-serverinfo_tack"])));
604 ok(run(test([@ssltest, "-bio_pair", "-tls1", "-custom_ext", "-serverinfo_file", $serverinfo, "-serverinfo_sct", "-serverinfo_tack"])));
608 subtest 'SNI tests' => sub {
613 skip "TLSv1.x is not supported by this OpenSSL build", 7
614 if $no_tls1 && $no_tls1_1 && $no_tls1_2;
616 ok(run(test([@ssltest, "-bio_pair", "-sn_client", "foo"])));
617 ok(run(test([@ssltest, "-bio_pair", "-sn_server1", "foo"])));
618 ok(run(test([@ssltest, "-bio_pair", "-sn_client", "foo", "-sn_server1", "foo", "-sn_expect1"])));
619 ok(run(test([@ssltest, "-bio_pair", "-sn_client", "foo", "-sn_server1", "bar", "-sn_expect1"])));
620 ok(run(test([@ssltest, "-bio_pair", "-sn_client", "foo", "-sn_server1", "foo", "-sn_server2", "bar", "-sn_expect1"])));
621 ok(run(test([@ssltest, "-bio_pair", "-sn_client", "bar", "-sn_server1", "foo", "-sn_server2", "bar", "-sn_expect2"])));
622 # Negative test - make sure it doesn't crash, and doesn't switch contexts
623 ok(run(test([@ssltest, "-bio_pair", "-sn_client", "foobar", "-sn_server1", "foo", "-sn_server2", "bar", "-sn_expect1"])));
627 subtest 'ALPN tests' => sub {
628 ######################################################################
633 skip "TLSv1.0 is not supported by this OpenSSL build", 13
636 ok(run(test([@ssltest, "-bio_pair", "-tls1", "-alpn_client", "foo"])));
637 ok(run(test([@ssltest, "-bio_pair", "-tls1", "-alpn_server", "foo"])));
638 ok(run(test([@ssltest, "-bio_pair", "-tls1", "-alpn_client", "foo", "-alpn_server", "foo", "-alpn_expected", "foo"])));
639 ok(run(test([@ssltest, "-bio_pair", "-tls1", "-alpn_client", "foo,bar", "-alpn_server", "foo", "-alpn_expected", "foo"])));
640 ok(run(test([@ssltest, "-bio_pair", "-tls1", "-alpn_client", "bar,foo", "-alpn_server", "foo", "-alpn_expected", "foo"])));
641 ok(run(test([@ssltest, "-bio_pair", "-tls1", "-alpn_client", "bar,foo", "-alpn_server", "foo,bar", "-alpn_expected", "foo"])));
642 ok(run(test([@ssltest, "-bio_pair", "-tls1", "-alpn_client", "bar,foo", "-alpn_server", "bar,foo", "-alpn_expected", "bar"])));
643 ok(run(test([@ssltest, "-bio_pair", "-tls1", "-alpn_client", "foo,bar", "-alpn_server", "bar,foo", "-alpn_expected", "bar"])));
645 is(run(test([@ssltest, "-bio_pair", "-tls1", "-alpn_client", "foo", "-alpn_server", "bar"])), 0,
646 "Testing ALPN with protocol mismatch, expecting failure");
647 is(run(test([@ssltest, "-bio_pair", "-tls1", "-alpn_client", "baz", "-alpn_server", "bar,foo"])), 0,
648 "Testing ALPN with protocol mismatch, expecting failure");
651 ok(run(test([@ssltest, "-bio_pair",
652 "-alpn_client", "foo,bar", "-sn_client", "alice",
653 "-alpn_server1", "foo,123", "-sn_server1", "alice",
654 "-alpn_server2", "bar,456", "-sn_server2", "bob",
655 "-alpn_expected", "foo"])));
656 ok(run(test([@ssltest, "-bio_pair",
657 "-alpn_client", "foo,bar", "-sn_client", "bob",
658 "-alpn_server1", "foo,123", "-sn_server1", "alice",
659 "-alpn_server2", "bar,456", "-sn_server2", "bob",
660 "-alpn_expected", "bar"])));
661 ok(run(test([@ssltest, "-bio_pair",
662 "-alpn_client", "foo,bar", "-sn_client", "bob",
663 "-alpn_server2", "bar,456", "-sn_server2", "bob",
664 "-alpn_expected", "bar"])));
668 subtest 'SRP tests' => sub {
673 skip "skipping SRP tests", 4
676 ok(run(test([@ssltest, "-tls1", "-cipher", "SRP", "-srpuser", "test", "-srppass", "abc123"])),
677 'test tls1 with SRP');
679 ok(run(test([@ssltest, "-bio_pair", "-tls1", "-cipher", "SRP", "-srpuser", "test", "-srppass", "abc123"])),
680 'test tls1 with SRP via BIO pair');
682 ok(run(test([@ssltest, "-tls1", "-cipher", "aSRP", "-srpuser", "test", "-srppass", "abc123"])),
683 'test tls1 with SRP auth');
685 ok(run(test([@ssltest, "-bio_pair", "-tls1", "-cipher", "aSRP", "-srpuser", "test", "-srppass", "abc123"])),
686 'test tls1 with SRP auth via BIO pair');
690 subtest 'Multi-buffer tests' => sub {
691 ######################################################################
696 skip "Neither SSLv3 nor any TLS version are supported by this OpenSSL build", 2
699 skip "skipping multi-buffer tests", 2
700 if @extra || (POSIX::uname())[4] ne "x86_64";
702 ok(run(test([@ssltest, "-cipher", "AES128-SHA", "-bytes", "8m"])));
704 # We happen to know that AES128-SHA256 is TLSv1.2 only... for now.
705 skip "TLSv1.2 is not supported by this OpenSSL configuration", 1
708 ok(run(test([@ssltest, "-cipher", "AES128-SHA256", "-bytes", "8m"])));
712 subtest 'TLS Version min/max tests' => sub {
714 push(@protos, "ssl3") unless $no_ssl3;
715 push(@protos, "tls1") unless $no_tls1;
716 push(@protos, "tls1.1") unless $no_tls1_1;
717 push(@protos, "tls1.2") unless $no_tls1_2;
718 my @minprotos = (undef, @protos);
719 my @maxprotos = (@protos, undef);
720 my @shdprotos = (@protos, $protos[$#protos]);
721 my $n = ((@protos+2) * (@protos+3))/2 - 2;
722 my $ntests = $n * $n;
723 plan tests => $ntests;
725 skip "TLS disabled", 1 if $ntests == 1;
728 for (my $smin = 0; $smin < @minprotos; ++$smin) {
729 for (my $smax = $smin ? $smin - 1 : 0; $smax < @maxprotos; ++$smax) {
730 for (my $cmin = 0; $cmin < @minprotos; ++$cmin) {
731 for (my $cmax = $cmin ? $cmin - 1 : 0; $cmax < @maxprotos; ++$cmax) {
732 if ($cmax < $smin-1) {
733 $should = "fail-server";
734 } elsif ($smax < $cmin-1) {
735 $should = "fail-client";
736 } elsif ($cmax > $smax) {
737 $should = $shdprotos[$smax];
739 $should = $shdprotos[$cmax];
743 push(@args, "-should_negotiate", $should);
744 push(@args, "-server_min_proto", $minprotos[$smin])
745 if (defined($minprotos[$smin]));
746 push(@args, "-server_max_proto", $maxprotos[$smax])
747 if (defined($maxprotos[$smax]));
748 push(@args, "-client_min_proto", $minprotos[$cmin])
749 if (defined($minprotos[$cmin]));
750 push(@args, "-client_max_proto", $maxprotos[$cmax])
751 if (defined($maxprotos[$cmax]));
752 my $ok = run(test[@args]);
754 print STDERR "\nsmin=$smin, smax=$smax, cmin=$cmin, cmax=$cmax\n";
755 print STDERR "\nFailed: @args\n";
761 subtest 'DTLS Version min/max tests' => sub {
763 push(@protos, "dtls1") unless ($no_dtls1 || $no_dtls);
764 push(@protos, "dtls1.2") unless ($no_dtls1_2 || $no_dtls);
765 my @minprotos = (undef, @protos);
766 my @maxprotos = (@protos, undef);
767 my @shdprotos = (@protos, $protos[$#protos]);
768 my $n = ((@protos+2) * (@protos+3))/2 - 2;
769 my $ntests = $n * $n;
770 plan tests => $ntests;
772 skip "DTLS disabled", 1 if $ntests == 1;
775 for (my $smin = 0; $smin < @minprotos; ++$smin) {
776 for (my $smax = $smin ? $smin - 1 : 0; $smax < @maxprotos; ++$smax) {
777 for (my $cmin = 0; $cmin < @minprotos; ++$cmin) {
778 for (my $cmax = $cmin ? $cmin - 1 : 0; $cmax < @maxprotos; ++$cmax) {
779 if ($cmax < $smin-1) {
780 $should = "fail-server";
781 } elsif ($smax < $cmin-1) {
782 $should = "fail-client";
783 } elsif ($cmax > $smax) {
784 $should = $shdprotos[$smax];
786 $should = $shdprotos[$cmax];
789 my @args = (@ssltest, "-dtls");
790 push(@args, "-should_negotiate", $should);
791 push(@args, "-server_min_proto", $minprotos[$smin])
792 if (defined($minprotos[$smin]));
793 push(@args, "-server_max_proto", $maxprotos[$smax])
794 if (defined($maxprotos[$smax]));
795 push(@args, "-client_min_proto", $minprotos[$cmin])
796 if (defined($minprotos[$cmin]));
797 push(@args, "-client_max_proto", $maxprotos[$cmax])
798 if (defined($maxprotos[$cmax]));
799 my $ok = run(test[@args]);
801 print STDERR "\nsmin=$smin, smax=$smax, cmin=$cmin, cmax=$cmax\n";
802 print STDERR "\nFailed: @args\n";
808 subtest 'Certificate Transparency tests' => sub {
809 ######################################################################
814 skip "Certificate Transparency is not supported by this OpenSSL build", 3
816 skip "TLSv1.0 is not supported by this OpenSSL build", 3
819 $ENV{CTLOG_FILE} = srctop_file("test", "ct", "log_list.conf");
820 ok(run(test([@ssltest, "-bio_pair", "-tls1", "-noct"])));
821 ok(run(test([@ssltest, "-bio_pair", "-tls1", "-requestct"])));
822 # No SCTs provided, so this should fail.
823 ok(run(test([@ssltest, "-bio_pair", "-tls1", "-requirect",
824 "-should_negotiate", "fail-client"])));
831 my $key = shift || srctop_file("apps","server.pem");
832 my $cert = shift || srctop_file("apps","server.pem");
834 my @CA = $CAtmp ? ("-CAfile", $CAtmp) : ("-CApath", bldtop_dir("certs"));
837 my @ssltest = ("ssltest",
838 "-s_key", $key, "-s_cert", $cert,
839 "-c_key", $key, "-c_cert", $cert);
843 note('Testing a lot of proxy conditions.');
845 # We happen to know that certP1.ss has policy letters "AB" and
846 # certP2.ss has policy letters "BC". However, because certP2.ss
847 # has certP1.ss as issuer, when it's used, both their policy
848 # letters get combined into just "B".
849 # The policy letter(s) then get filtered with the given auth letter
850 # in the table below, and the result gets tested with the given
851 # condition. For details, read ssltest.c
853 # certfilename => [ [ auth, cond, expected result ] ... ]
854 my %expected = ( "certP1.ss" => [ [ [ 'A', 'A' ], 1 ],
857 [ [ 'A', 'A|B&!C' ], 1 ],
861 [ [ 'B', 'A|B&!C' ], 1 ],
865 [ [ 'C', 'A|B&!C' ], 0 ],
866 [ [ 'BC', 'A' ], 0 ],
867 [ [ 'BC', 'B' ], 1 ],
868 [ [ 'BC', 'C' ], 0 ],
869 [ [ 'BC', 'A|B&!C' ], 1 ] ],
870 "certP2.ss" => [ [ [ 'A', 'A' ], 0 ],
873 [ [ 'A', 'A|B&!C' ], 0 ],
877 [ [ 'B', 'A|B&!C' ], 1 ],
881 [ [ 'C', 'A|B&!C' ], 0 ],
882 [ [ 'BC', 'A' ], 0 ],
883 [ [ 'BC', 'B' ], 1 ],
884 [ [ 'BC', 'C' ], 0 ],
885 [ [ 'BC', 'A|B&!C' ], 1 ] ] );
888 skip "Neither SSLv3 nor any TLS version are supported by this OpenSSL build", scalar(@{$expected{$cert}})
891 foreach (@{$expected{$cert}}) {
892 my $auth = $_->[0]->[0];
893 my $cond = $_->[0]->[1];
895 is(run(test([@ssltest, "-server_auth", @CA,
896 "-proxy", "-proxy_auth", $auth,
897 "-proxy_cond", $cond])), $res,
898 "test tlsv1, server auth, proxy auth $auth and cond $cond (expect "
899 .($res ? "success" : "failure").")");