]>
git.ipfire.org Git - thirdparty/openssl.git/blob - test/recipes/80-test_ssl.t
e7472a208b9d0566b6f1063f012c92a2d5250820
9 use OpenSSL
::Test qw
/:DEFAULT with top_file cmdstr/;
10 use OpenSSL
::Test
::Utils
;
14 my ($no_rsa, $no_dsa, $no_dh, $no_ec, $no_srp, $no_psk,
15 $no_ssl3, $no_tls1, $no_tls1_1, $no_tls1_2,
16 $no_dtls, $no_dtls1, $no_dtls1_2) =
17 anydisabled qw
/rsa dsa dh ec srp psk
18 ssl3 tls1 tls1_1 tls1_2
20 my $no_anytls = alldisabled
(available_protocols
("tls"));
21 my $no_anydtls = alldisabled
(available_protocols
("dtls"));
23 plan skip_all
=> "No SSL/TLS/DTLS protocol is support by this OpenSSL build"
24 if $no_anytls && $no_anydtls;
27 my @reqcmd = ("openssl", "req");
28 my @x509cmd = ("openssl", "x509", $digest);
29 my @verifycmd = ("openssl", "verify");
30 my $dummycnf = top_file
("apps", "openssl.cnf");
32 my $CAkey = "keyCA.ss";
33 my $CAcert="certCA.ss";
34 my $CAserial="certCA.srl";
36 my $CAconf=top_file
("test","CAss.cnf");
37 my $CAreq2="req2CA.ss"; # temp
39 my $Uconf=top_file
("test","Uss.cnf");
52 my $P1conf=top_file
("test","P1ss.cnf");
55 my $P1cert="certP1.ss";
56 my $P1intermediate="tmp_intP1.ss";
58 my $P2conf=top_file
("test","P2ss.cnf");
61 my $P2cert="certP2.ss";
62 my $P2intermediate="tmp_intP2.ss";
66 + 1 # For ssltest -test_cipherlist
67 + 10 # For the first testssl
68 + 16 # For the first testsslproxy
69 + 16 # For the second testsslproxy
72 subtest
'test_ss' => sub {
74 open OUT
, ">", "intP1.ss";
75 copy
($CAcert, \
*OUT
); copy
($Ucert, \
*OUT
);
78 open OUT
, ">", "intP2.ss";
79 copy
($CAcert, \
*OUT
); copy
($Ucert, \
*OUT
); copy
($P1cert, \
*OUT
);
84 my $check = ok
(run
(test
(["ssltest","-test_cipherlist"])), "running ssltest");
87 skip
"ssltest ended with error, skipping the rest", 3
90 note
('test_ssl -- key U');
91 testssl
("keyU.ss", $Ucert, $CAcert);
93 note
('test_ssl -- key P1');
94 testsslproxy
("keyP1.ss", "certP1.ss", "intP1.ss", "AB");
96 note
('test_ssl -- key P2');
97 testsslproxy
("keyP2.ss", "certP2.ss", "intP2.ss", "BC");
103 open RND
, ">>", ".rnd";
104 print RND
"string to make the random number generator think it has entropy";
107 my @req_dsa = ("-newkey",
108 "dsa:".File
::Spec
->catfile("..", "apps", "dsa1024.pem"));;
119 skip
'failure', 16 unless
120 ok
(run
(app
([@reqcmd, "-config", $CAconf,
121 "-out", $CAreq, "-keyout", $CAkey,
123 'make cert request');
125 skip
'failure', 15 unless
126 ok
(run
(app
([@x509cmd, "-CAcreateserial", "-in", $CAreq, "-days", "30",
127 "-req", "-out", $CAcert, "-signkey", $CAkey,
128 "-extfile", $CAconf, "-extensions", "v3_ca"],
129 stdout
=> "err.ss")),
130 'convert request into self-signed cert');
132 skip
'failure', 14 unless
133 ok
(run
(app
([@x509cmd, "-in", $CAcert,
134 "-x509toreq", "-signkey", $CAkey, "-out", $CAreq2],
135 stdout
=> "err.ss")),
136 'convert cert into a cert request');
138 skip
'failure', 13 unless
139 ok
(run
(app
([@reqcmd, "-config", $dummycnf,
140 "-verify", "-in", $CAreq, "-noout"])),
144 skip
'failure', 12 unless
145 ok
(run
(app
([@reqcmd, "-config", $dummycnf,
146 "-verify", "-in", $CAreq2, "-noout"])),
149 skip
'failure', 11 unless
150 ok
(run
(app
([@verifycmd, "-CAfile", $CAcert, $CAcert])),
153 skip
'failure', 10 unless
154 ok
(run
(app
([@reqcmd, "-config", $Uconf,
155 "-out", $Ureq, "-keyout", $Ukey, @req_new],
156 stdout
=> "err.ss")),
157 'make a user cert request');
159 skip
'failure', 9 unless
160 ok
(run
(app
([@x509cmd, "-CAcreateserial", "-in", $Ureq, "-days", "30",
161 "-req", "-out", $Ucert,
162 "-CA", $CAcert, "-CAkey", $CAkey, "-CAserial", $CAserial,
163 "-extfile", $Uconf, "-extensions", "v3_ee"],
165 && run
(app
([@verifycmd, "-CAfile", $CAcert, $Ucert])),
166 'sign user cert request');
168 skip
'failure', 8 unless
169 ok
(run
(app
([@x509cmd,
170 "-subject", "-issuer", "-startdate", "-enddate",
171 "-noout", "-in", $Ucert])),
172 'Certificate details');
174 skip
'failure', 7 unless
175 subtest
'DSA certificate creation' => sub {
176 plan skip_all
=> "skipping DSA certificate creation"
182 $ENV{CN2
} = "DSA Certificate";
183 skip
'failure', 3 unless
184 ok
(run
(app
([@reqcmd, "-config", $Uconf,
185 "-out", $Dreq, "-keyout", $Dkey,
187 stdout
=> "err.ss")),
188 "make a DSA user cert request");
189 skip
'failure', 2 unless
190 ok
(run
(app
([@x509cmd, "-CAcreateserial",
195 "-CA", $CAcert, "-CAkey", $CAkey,
196 "-CAserial", $CAserial,
198 "-extensions", "v3_ee_dsa"],
199 stdout
=> "err.ss")),
200 "sign DSA user cert request");
201 skip
'failure', 1 unless
202 ok
(run
(app
([@verifycmd, "-CAfile", $CAcert, $Dcert])),
203 "verify DSA user cert");
204 skip
'failure', 0 unless
205 ok
(run
(app
([@x509cmd,
206 "-subject", "-issuer",
207 "-startdate", "-enddate", "-noout",
209 "DSA Certificate details");
213 skip
'failure', 6 unless
214 subtest
'ECDSA/ECDH certificate creation' => sub {
215 plan skip_all
=> "skipping ECDSA/ECDH certificate creation"
221 $ENV{CN2
} = "ECDSA Certificate";
222 skip
'failure', 4 unless
223 ok
(run
(app
(["openssl", "ecparam", "-name", "P-256",
225 "make EC parameters");
226 skip
'failure', 3 unless
227 ok
(run
(app
([@reqcmd, "-config", $Uconf,
228 "-out", $Ereq, "-keyout", $Ekey,
229 "-newkey", "ec:ecp.ss"],
230 stdout
=> "err.ss")),
231 "make a ECDSA/ECDH user cert request");
232 skip
'failure', 2 unless
233 ok
(run
(app
([@x509cmd, "-CAcreateserial",
238 "-CA", $CAcert, "-CAkey", $CAkey,
239 "-CAserial", $CAserial,
241 "-extensions", "v3_ee_ec"],
242 stdout
=> "err.ss")),
243 "sign ECDSA/ECDH user cert request");
244 skip
'failure', 1 unless
245 ok
(run
(app
([@verifycmd, "-CAfile", $CAcert, $Ecert])),
246 "verify ECDSA/ECDH user cert");
247 skip
'failure', 0 unless
248 ok
(run
(app
([@x509cmd,
249 "-subject", "-issuer",
250 "-startdate", "-enddate", "-noout",
252 "ECDSA Certificate details");
256 skip
'failure', 5 unless
257 ok
(run
(app
([@reqcmd, "-config", $P1conf,
258 "-out", $P1req, "-keyout", $P1key, @req_new],
259 stdout
=> "err.ss")),
260 'make a proxy cert request');
263 skip
'failure', 4 unless
264 ok
(run
(app
([@x509cmd, "-CAcreateserial", "-in", $P1req, "-days", "30",
265 "-req", "-out", $P1cert,
266 "-CA", $Ucert, "-CAkey", $Ukey,
267 "-extfile", $P1conf, "-extensions", "v3_proxy"],
268 stdout
=> "err.ss")),
269 'sign proxy with user cert');
271 copy
($Ucert, $P1intermediate);
272 run
(app
([@verifycmd, "-CAfile", $CAcert,
273 "-untrusted", $P1intermediate, $P1cert]));
274 ok
(run
(app
([@x509cmd,
275 "-subject", "-issuer", "-startdate", "-enddate",
276 "-noout", "-in", $P1cert])),
277 'Certificate details');
279 skip
'failure', 2 unless
280 ok
(run
(app
([@reqcmd, "-config", $P2conf,
281 "-out", $P2req, "-keyout", $P2key,
283 stdout
=> "err.ss")),
284 'make another proxy cert request');
287 skip
'failure', 1 unless
288 ok
(run
(app
([@x509cmd, "-CAcreateserial", "-in", $P2req, "-days", "30",
289 "-req", "-out", $P2cert,
290 "-CA", $P1cert, "-CAkey", $P1key,
291 "-extfile", $P2conf, "-extensions", "v3_proxy"],
292 stdout
=> "err.ss")),
293 'sign second proxy cert request with the first proxy cert');
296 open OUT
, ">", $P2intermediate;
297 copy
($Ucert, \
*OUT
); copy
($P1cert, \
*OUT
);
299 run
(app
([@verifycmd, "-CAfile", $CAcert,
300 "-untrusted", $P2intermediate, $P2cert]));
301 ok
(run
(app
([@x509cmd,
302 "-subject", "-issuer", "-startdate", "-enddate",
303 "-noout", "-in", $P2cert])),
304 'Certificate details');
309 my $key = shift || top_file
("apps","server.pem");
310 my $cert = shift || top_file
("apps","server.pem");
312 my @CA = $CAtmp ?
("-CAfile", $CAtmp) : ("-CApath", top_dir
("certs"));
315 my @ssltest = ("ssltest",
316 "-s_key", $key, "-s_cert", $cert,
317 "-c_key", $key, "-c_cert", $cert);
319 my $serverinfo = top_file
("test","serverinfo.pem");
322 if (grep /DSA Public Key/, run
(app
(["openssl", "x509", "-in", $cert,
323 "-text", "-noout"]), capture
=> 1)) {
330 subtest
'standard SSL tests' => sub {
331 ######################################################################
335 skip
"SSLv3 is not supported by this OpenSSL build", 4
338 ok
(run
(test
([@ssltest, "-ssl3", @extra])),
340 ok
(run
(test
([@ssltest, "-ssl3", "-server_auth", @CA, @extra])),
341 'test sslv3 with server authentication');
342 ok
(run
(test
([@ssltest, "-ssl3", "-client_auth", @CA, @extra])),
343 'test sslv3 with client authentication');
344 ok
(run
(test
([@ssltest, "-ssl3", "-server_auth", "-client_auth", @CA, @extra])),
345 'test sslv3 with both server and client authentication');
349 skip
"Neither SSLv3 nor any TLS version are supported by this OpenSSL build", 4
352 ok
(run
(test
([@ssltest, @extra])),
354 ok
(run
(test
([@ssltest, "-server_auth", @CA, @extra])),
355 'test sslv2/sslv3 with server authentication');
356 ok
(run
(test
([@ssltest, "-client_auth", @CA, @extra])),
357 'test sslv2/sslv3 with client authentication');
358 ok
(run
(test
([@ssltest, "-server_auth", "-client_auth", @CA, @extra])),
359 'test sslv2/sslv3 with both server and client authentication');
363 skip
"SSLv3 is not supported by this OpenSSL build", 4
366 ok
(run
(test
([@ssltest, "-bio_pair", "-ssl3", @extra])),
367 'test sslv3 via BIO pair');
368 ok
(run
(test
([@ssltest, "-bio_pair", "-ssl3", "-server_auth", @CA, @extra])),
369 'test sslv3 with server authentication via BIO pair');
370 ok
(run
(test
([@ssltest, "-bio_pair", "-ssl3", "-client_auth", @CA, @extra])),
371 'test sslv3 with client authentication via BIO pair');
372 ok
(run
(test
([@ssltest, "-bio_pair", "-ssl3", "-server_auth", "-client_auth", @CA, @extra])),
373 'test sslv3 with both server and client authentication via BIO pair');
377 skip
"Neither SSLv3 nor any TLS version are supported by this OpenSSL build", 1
380 ok
(run
(test
([@ssltest, "-bio_pair", @extra])),
381 'test sslv2/sslv3 via BIO pair');
385 skip
"DTLSv1 is not supported by this OpenSSL build", 4
386 if disabled
("dtls1");
388 ok
(run
(test
([@ssltest, "-dtls1", @extra])),
390 ok
(run
(test
([@ssltest, "-dtls1", "-server_auth", @CA, @extra])),
391 'test dtlsv1 with server authentication');
392 ok
(run
(test
([@ssltest, "-dtls1", "-client_auth", @CA, @extra])),
393 'test dtlsv1 with client authentication');
394 ok
(run
(test
([@ssltest, "-dtls1", "-server_auth", "-client_auth", @CA, @extra])),
395 'test dtlsv1 with both server and client authentication');
399 skip
"DTLSv1.2 is not supported by this OpenSSL build", 4
400 if disabled
("dtls1_2");
402 ok
(run
(test
([@ssltest, "-dtls12", @extra])),
404 ok
(run
(test
([@ssltest, "-dtls12", "-server_auth", @CA, @extra])),
405 'test dtlsv1.2 with server authentication');
406 ok
(run
(test
([@ssltest, "-dtls12", "-client_auth", @CA, @extra])),
407 'test dtlsv1.2 with client authentication');
408 ok
(run
(test
([@ssltest, "-dtls12", "-server_auth", "-client_auth", @CA, @extra])),
409 'test dtlsv1.2 with both server and client authentication');
413 skip
"Neither SSLv3 nor any TLS version are supported by this OpenSSL build", 6
417 skip
"skipping test of sslv2/sslv3 w/o (EC)DHE test", 1 if $dsa_cert;
419 ok
(run
(test
([@ssltest, "-bio_pair", "-no_dhe", "-no_ecdhe", @extra])),
420 'test sslv2/sslv3 w/o (EC)DHE via BIO pair');
423 ok
(run
(test
([@ssltest, "-bio_pair", "-dhe1024dsa", "-v", @extra])),
424 'test sslv2/sslv3 with 1024bit DHE via BIO pair');
425 ok
(run
(test
([@ssltest, "-bio_pair", "-server_auth", @CA, @extra])),
426 'test sslv2/sslv3 with server authentication');
427 ok
(run
(test
([@ssltest, "-bio_pair", "-client_auth", @CA, @extra])),
428 'test sslv2/sslv3 with client authentication via BIO pair');
429 ok
(run
(test
([@ssltest, "-bio_pair", "-server_auth", "-client_auth", @CA, @extra])),
430 'test sslv2/sslv3 with both client and server authentication via BIO pair');
431 ok
(run
(test
([@ssltest, "-bio_pair", "-server_auth", "-client_auth", "-app_verify", @CA, @extra])),
432 'test sslv2/sslv3 with both client and server authentication via BIO pair and app verify');
436 subtest
"Testing ciphersuites" => sub {
439 my $ciphers = "-EXP:-PSK:-SRP:-kDH:-kECDHe";
442 note
"skipping DHE tests\n";
443 $ciphers .= ":-kDHE";
446 note
"skipping DSA tests\n";
447 $ciphers .= ":-aDSA";
449 push @exkeys, "-s_cert", "certD.ss", "-s_key", "keyD.ss";
453 note
"skipping EC tests\n";
454 $ciphers .= ":!aECDSA:!kECDH";
456 push @exkeys, "-s_cert", "certE.ss", "-s_key", "keyE.ss";
460 # FIXME: I feel unsure about the following line, is that really just TLSv1.2, or is it all of the SSLv3/TLS protocols?
461 push(@protocols, "TLSv1.2") unless $no_tls1_2;
462 push(@protocols, "SSLv3") unless $no_ssl3;
463 my $protocolciphersuitcount = 0;
466 map { split(/:/, $_) }
467 run
(app
(["openssl", "ciphers", "${_}:$ciphers"]),
469 map { s/\R//; } @c; # chomp @c;
470 $protocolciphersuitcount += scalar @c;
471 $_ => [ @c ] } @protocols;
473 # The count of protocols is because in addition to the ciphersuits
474 # we got above, we're running a weak DH test for each protocol
475 plan tests
=> $protocolciphersuitcount + scalar(@protocols);
477 foreach my $protocol (@protocols) {
478 note
"Testing ciphersuites for $protocol";
479 foreach my $cipher (@
{$ciphersuites{$protocol}}) {
480 ok
(run
(test
([@ssltest, @exkeys, "-cipher", $cipher,
481 $protocol eq "SSLv3" ?
("-ssl3") : ()])),
484 is
(run
(test
([@ssltest,
486 "-c_cipher", 'EDH:@SECLEVEL=1',
488 $protocol eq "SSLv3" ?
("-ssl3") : ()])), 0,
489 "testing connection with weak DH, expecting failure");
493 subtest
'RSA/(EC)DHE/PSK tests' => sub {
494 ######################################################################
499 skip
"TLSv1.0 is not supported by this OpenSSL build", 5
503 skip
"skipping anonymous DH tests", 1
506 ok
(run
(test
([@ssltest, "-v", "-bio_pair", "-tls1", "-cipher", "ADH", "-dhe1024dsa", "-num", "10", "-f", "-time", @extra])),
507 'test tlsv1 with 1024bit anonymous DH, multiple handshakes');
511 skip
"skipping RSA tests", 2
514 ok
(run
(test
(["ssltest", "-v", "-bio_pair", "-tls1", "-s_cert", top_file
("apps","server2.pem"), "-no_dhe", "-no_ecdhe", "-num", "10", "-f", "-time", @extra])),
515 'test tlsv1 with 1024bit RSA, no (EC)DHE, multiple handshakes');
517 skip
"skipping RSA+DHE tests", 1
520 ok
(run
(test
(["ssltest", "-v", "-bio_pair", "-tls1", "-s_cert", top_file
("apps","server2.pem"), "-dhe1024dsa", "-num", "10", "-f", "-time", @extra])),
521 'test tlsv1 with 1024bit RSA, 1024bit DHE, multiple handshakes');
525 skip
"skipping PSK tests", 2
528 ok
(run
(test
([@ssltest, "-tls1", "-cipher", "PSK", "-psk", "abc123", @extra])),
529 'test tls1 with PSK');
531 ok
(run
(test
([@ssltest, "-bio_pair", "-tls1", "-cipher", "PSK", "-psk", "abc123", @extra])),
532 'test tls1 with PSK via BIO pair');
538 subtest
'Next Protocol Negotiation Tests' => sub {
539 ######################################################################
544 skip
"TLSv1.0 is not supported by this OpenSSL build", 7
547 ok
(run
(test
([@ssltest, "-bio_pair", "-tls1", "-npn_client"])));
548 ok
(run
(test
([@ssltest, "-bio_pair", "-tls1", "-npn_server"])));
549 ok
(run
(test
([@ssltest, "-bio_pair", "-tls1", "-npn_server_reject"])));
550 ok
(run
(test
([@ssltest, "-bio_pair", "-tls1", "-npn_client", "-npn_server_reject"])));
551 ok
(run
(test
([@ssltest, "-bio_pair", "-tls1", "-npn_client", "-npn_server"])));
552 ok
(run
(test
([@ssltest, "-bio_pair", "-tls1", "-npn_client", "-npn_server", "-num", "2"])));
553 ok
(run
(test
([@ssltest, "-bio_pair", "-tls1", "-npn_client", "-npn_server", "-num", "2", "-reuse"])));
557 subtest
'Custom Extension tests' => sub {
558 ######################################################################
563 skip
"TLSv1.0 is not supported by this OpenSSL build", 7
566 ok
(run
(test
([@ssltest, "-bio_pair", "-tls1", "-custom_ext"])),
567 'test tls1 with custom extensions');
571 subtest
'Serverinfo tests' => sub {
572 ######################################################################
577 skip
"TLSv1.0 is not supported by this OpenSSL build", 5
580 note
('echo test tls1 with serverinfo');
581 ok
(run
(test
([@ssltest, "-bio_pair", "-tls1", "-serverinfo_file", $serverinfo])));
582 ok
(run
(test
([@ssltest, "-bio_pair", "-tls1", "-serverinfo_file", $serverinfo, "-serverinfo_sct"])));
583 ok
(run
(test
([@ssltest, "-bio_pair", "-tls1", "-serverinfo_file", $serverinfo, "-serverinfo_tack"])));
584 ok
(run
(test
([@ssltest, "-bio_pair", "-tls1", "-serverinfo_file", $serverinfo, "-serverinfo_sct", "-serverinfo_tack"])));
585 ok
(run
(test
([@ssltest, "-bio_pair", "-tls1", "-custom_ext", "-serverinfo_file", $serverinfo, "-serverinfo_sct", "-serverinfo_tack"])));
589 subtest
'ALPN tests' => sub {
590 ######################################################################
595 skip
"TLSv1.0 is not supported by this OpenSSL build", 12
598 ok
(run
(test
([@ssltest, "-bio_pair", "-tls1", "-alpn_client", "foo", "-alpn_server", "bar"])));
599 ok
(run
(test
([@ssltest, "-bio_pair", "-tls1", "-alpn_client", "foo", "-alpn_server", "foo", "-alpn_expected", "foo"])));
600 ok
(run
(test
([@ssltest, "-bio_pair", "-tls1", "-alpn_client", "foo,bar", "-alpn_server", "foo", "-alpn_expected", "foo"])));
601 ok
(run
(test
([@ssltest, "-bio_pair", "-tls1", "-alpn_client", "bar,foo", "-alpn_server", "foo", "-alpn_expected", "foo"])));
602 ok
(run
(test
([@ssltest, "-bio_pair", "-tls1", "-alpn_client", "bar,foo", "-alpn_server", "foo,bar", "-alpn_expected", "foo"])));
603 ok
(run
(test
([@ssltest, "-bio_pair", "-tls1", "-alpn_client", "bar,foo", "-alpn_server", "bar,foo", "-alpn_expected", "bar"])));
604 ok
(run
(test
([@ssltest, "-bio_pair", "-tls1", "-alpn_client", "foo,bar", "-alpn_server", "bar,foo", "-alpn_expected", "bar"])));
605 ok
(run
(test
([@ssltest, "-bio_pair", "-tls1", "-alpn_client", "baz", "-alpn_server", "bar,foo"])));
608 skip
"skipping SRP tests", 4
611 ok
(run
(test
([@ssltest, "-tls1", "-cipher", "SRP", "-srpuser", "test", "-srppass", "abc123"])),
612 'test tls1 with SRP');
614 ok
(run
(test
([@ssltest, "-bio_pair", "-tls1", "-cipher", "SRP", "-srpuser", "test", "-srppass", "abc123"])),
615 'test tls1 with SRP via BIO pair');
617 ok
(run
(test
([@ssltest, "-tls1", "-cipher", "aSRP", "-srpuser", "test", "-srppass", "abc123"])),
618 'test tls1 with SRP auth');
620 ok
(run
(test
([@ssltest, "-bio_pair", "-tls1", "-cipher", "aSRP", "-srpuser", "test", "-srppass", "abc123"])),
621 'test tls1 with SRP auth via BIO pair');
626 subtest
'Multi-buffer tests' => sub {
627 ######################################################################
632 skip
"Neither SSLv3 nor any TLS version are supported by this OpenSSL build", 2
635 skip
"skipping multi-buffer tests", 2
636 if @extra || (POSIX
::uname
())[4] ne "x86_64";
638 ok
(run
(test
([@ssltest, "-cipher", "AES128-SHA", "-bytes", "8m"])));
640 # We happen to know that AES128-SHA256 is TLSv1.2 only... for now.
641 skip
"TLSv1.2 is not supported by this OpenSSL configuration", 1
644 ok
(run
(test
([@ssltest, "-cipher", "AES128-SHA256", "-bytes", "8m"])));
648 subtest
'TLS Version min/max tests' => sub {
650 push(@protos, "ssl3") unless $no_ssl3;
651 push(@protos, "tls1") unless $no_tls1;
652 push(@protos, "tls1.1") unless $no_tls1_1;
653 push(@protos, "tls1.2") unless $no_tls1_2;
654 my @minprotos = (undef, @protos);
655 my @maxprotos = (@protos, undef);
656 my @shdprotos = (@protos, $protos[$#protos]);
657 my $n = ((@protos+2) * (@protos+3))/2 - 2;
658 my $ntests = $n * $n;
659 plan tests
=> $ntests;
660 skip
"TLS disabled", 1 if $ntests == 1;
663 for (my $smin = 0; $smin < @minprotos; ++$smin) {
664 for (my $smax = $smin ?
$smin - 1 : 0; $smax < @maxprotos; ++$smax) {
665 for (my $cmin = 0; $cmin < @minprotos; ++$cmin) {
666 for (my $cmax = $cmin ?
$cmin - 1 : 0; $cmax < @maxprotos; ++$cmax) {
667 if ($cmax < $smin-1) {
668 $should = "fail-server";
669 } elsif ($smax < $cmin-1) {
670 $should = "fail-client";
671 } elsif ($cmax > $smax) {
672 $should = $shdprotos[$smax];
674 $should = $shdprotos[$cmax];
678 push(@args, "-should_negotiate", $should);
679 push(@args, "-server_min_proto", $minprotos[$smin])
680 if (defined($minprotos[$smin]));
681 push(@args, "-server_max_proto", $maxprotos[$smax])
682 if (defined($maxprotos[$smax]));
683 push(@args, "-client_min_proto", $minprotos[$cmin])
684 if (defined($minprotos[$cmin]));
685 push(@args, "-client_max_proto", $maxprotos[$cmax])
686 if (defined($maxprotos[$cmax]));
687 my $ok = run
(test
[@args]);
689 print STDERR
"\nsmin=$smin, smax=$smax, cmin=$cmin, cmax=$cmax\n";
690 print STDERR
"\nFailed: @args\n";
696 subtest
'DTLS Version min/max tests' => sub {
698 push(@protos, "dtls1") unless ($no_dtls1 || $no_dtls);
699 push(@protos, "dtls1.2") unless ($no_dtls1_2 || $no_dtls);
700 my @minprotos = (undef, @protos);
701 my @maxprotos = (@protos, undef);
702 my @shdprotos = (@protos, $protos[$#protos]);
703 my $n = ((@protos+2) * (@protos+3))/2 - 2;
704 my $ntests = $n * $n;
705 plan tests
=> $ntests;
706 skip
"DTLS disabled", 1 if $ntests == 1;
709 for (my $smin = 0; $smin < @minprotos; ++$smin) {
710 for (my $smax = $smin ?
$smin - 1 : 0; $smax < @maxprotos; ++$smax) {
711 for (my $cmin = 0; $cmin < @minprotos; ++$cmin) {
712 for (my $cmax = $cmin ?
$cmin - 1 : 0; $cmax < @maxprotos; ++$cmax) {
713 if ($cmax < $smin-1) {
714 $should = "fail-server";
715 } elsif ($smax < $cmin-1) {
716 $should = "fail-client";
717 } elsif ($cmax > $smax) {
718 $should = $shdprotos[$smax];
720 $should = $shdprotos[$cmax];
723 my @args = (@ssltest, "-dtls");
724 push(@args, "-should_negotiate", $should);
725 push(@args, "-server_min_proto", $minprotos[$smin])
726 if (defined($minprotos[$smin]));
727 push(@args, "-server_max_proto", $maxprotos[$smax])
728 if (defined($maxprotos[$smax]));
729 push(@args, "-client_min_proto", $minprotos[$cmin])
730 if (defined($minprotos[$cmin]));
731 push(@args, "-client_max_proto", $maxprotos[$cmax])
732 if (defined($maxprotos[$cmax]));
733 my $ok = run
(test
[@args]);
735 print STDERR
"\nsmin=$smin, smax=$smax, cmin=$cmin, cmax=$cmax\n";
736 print STDERR
"\nFailed: @args\n";
744 my $key = shift || top_file
("apps","server.pem");
745 my $cert = shift || top_file
("apps","server.pem");
747 my @CA = $CAtmp ?
("-CAfile", $CAtmp) : ("-CApath", top_dir
("certs"));
750 my @ssltest = ("ssltest",
751 "-s_key", $key, "-s_cert", $cert,
752 "-c_key", $key, "-c_cert", $cert);
756 note
('Testing a lot of proxy conditions.');
758 # We happen to know that certP1.ss has policy letters "AB" and
759 # certP2.ss has policy letters "BC". However, because certP2.ss
760 # has certP1.ss as issuer, when it's used, both their policy
761 # letters get combined into just "B".
762 # The policy letter(s) then get filtered with the given auth letter
763 # in the table below, and the result gets tested with the given
764 # condition. For details, read ssltest.c
766 # certfilename => [ [ auth, cond, expected result ] ... ]
767 my %expected = ( "certP1.ss" => [ [ [ 'A', 'A' ], 1 ],
770 [ [ 'A', 'A|B&!C' ], 1 ],
774 [ [ 'B', 'A|B&!C' ], 1 ],
778 [ [ 'C', 'A|B&!C' ], 0 ],
779 [ [ 'BC', 'A' ], 0 ],
780 [ [ 'BC', 'B' ], 1 ],
781 [ [ 'BC', 'C' ], 0 ],
782 [ [ 'BC', 'A|B&!C' ], 1 ] ],
783 "certP2.ss" => [ [ [ 'A', 'A' ], 0 ],
786 [ [ 'A', 'A|B&!C' ], 0 ],
790 [ [ 'B', 'A|B&!C' ], 1 ],
794 [ [ 'C', 'A|B&!C' ], 0 ],
795 [ [ 'BC', 'A' ], 0 ],
796 [ [ 'BC', 'B' ], 1 ],
797 [ [ 'BC', 'C' ], 0 ],
798 [ [ 'BC', 'A|B&!C' ], 1 ] ] );
801 skip
"Neither SSLv3 nor any TLS version are supported by this OpenSSL build", scalar(@
{$expected{$cert}})
804 foreach (@
{$expected{$cert}}) {
805 my $auth = $_->[0]->[0];
806 my $cond = $_->[0]->[1];
808 is
(run
(test
([@ssltest, "-server_auth", @CA,
809 "-proxy", "-proxy_auth", $auth,
810 "-proxy_cond", $cond])), $res,
811 "test tlsv1, server auth, proxy auth $auth and cond $cond (expect "
812 .($res ?
"success" : "failure").")");