]> git.ipfire.org Git - thirdparty/openssl.git/blame - test/recipes/80-test_ssl.t
Change default CT log list filename to "ct_log_list.cnf"
[thirdparty/openssl.git] / test / recipes / 80-test_ssl.t
CommitLineData
88b8a527
RL
1#! /usr/bin/perl
2
3use strict;
4use warnings;
5
6use POSIX;
7use File::Spec;
8use File::Copy;
42e0ccdf 9use OpenSSL::Test qw/:DEFAULT with bldtop_file srctop_file cmdstr/;
340166a9 10use OpenSSL::Test::Utils;
88b8a527
RL
11
12setup("test_ssl");
13
6b01bed2
VD
14my ($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) =
90d48e5e
RL
17 anydisabled qw/rsa dsa dh ec srp psk
18 ssl3 tls1 tls1_1 tls1_2
19 dtls dtls1 dtls1_2/;
20my $no_anytls = alldisabled(available_protocols("tls"));
21my $no_anydtls = alldisabled(available_protocols("dtls"));
3ea75c63
RL
22
23plan skip_all => "No SSL/TLS/DTLS protocol is support by this OpenSSL build"
24 if $no_anytls && $no_anydtls;
340166a9 25
88b8a527
RL
26my $digest = "-sha1";
27my @reqcmd = ("openssl", "req");
28my @x509cmd = ("openssl", "x509", $digest);
29my @verifycmd = ("openssl", "verify");
42e0ccdf 30my $dummycnf = srctop_file("apps", "openssl.cnf");
88b8a527
RL
31
32my $CAkey = "keyCA.ss";
33my $CAcert="certCA.ss";
34my $CAserial="certCA.srl";
35my $CAreq="reqCA.ss";
42e0ccdf 36my $CAconf=srctop_file("test","CAss.cnf");
88b8a527
RL
37my $CAreq2="req2CA.ss"; # temp
38
42e0ccdf 39my $Uconf=srctop_file("test","Uss.cnf");
88b8a527
RL
40my $Ukey="keyU.ss";
41my $Ureq="reqU.ss";
42my $Ucert="certU.ss";
43
5beb63c4
RL
44my $Dkey="keyD.ss";
45my $Dreq="reqD.ss";
46my $Dcert="certD.ss";
47
48my $Ekey="keyE.ss";
49my $Ereq="reqE.ss";
50my $Ecert="certE.ss";
51
42e0ccdf 52my $P1conf=srctop_file("test","P1ss.cnf");
88b8a527
RL
53my $P1key="keyP1.ss";
54my $P1req="reqP1.ss";
55my $P1cert="certP1.ss";
56my $P1intermediate="tmp_intP1.ss";
57
42e0ccdf 58my $P2conf=srctop_file("test","P2ss.cnf");
88b8a527
RL
59my $P2key="keyP2.ss";
60my $P2req="reqP2.ss";
61my $P2cert="certP2.ss";
62my $P2intermediate="tmp_intP2.ss";
63
64plan tests =>
65 1 # For testss
66 + 1 # For ssltest -test_cipherlist
6b01bed2 67 + 10 # For the first testssl
49b147f8
RL
68 + 16 # For the first testsslproxy
69 + 16 # For the second testsslproxy
88b8a527
RL
70 ;
71
72subtest 'test_ss' => sub {
73 if (testss()) {
74 open OUT, ">", "intP1.ss";
75 copy($CAcert, \*OUT); copy($Ucert, \*OUT);
76 close OUT;
77
78 open OUT, ">", "intP2.ss";
79 copy($CAcert, \*OUT); copy($Ucert, \*OUT); copy($P1cert, \*OUT);
80 close OUT;
81 }
82};
83
84my $check = ok(run(test(["ssltest","-test_cipherlist"])), "running ssltest");
85
86 SKIP: {
87 skip "ssltest ended with error, skipping the rest", 3
88 if !$check;
89
90 note('test_ssl -- key U');
91 testssl("keyU.ss", $Ucert, $CAcert);
92
93 note('test_ssl -- key P1');
49b147f8 94 testsslproxy("keyP1.ss", "certP1.ss", "intP1.ss", "AB");
88b8a527
RL
95
96 note('test_ssl -- key P2');
49b147f8 97 testsslproxy("keyP2.ss", "certP2.ss", "intP2.ss", "BC");
88b8a527
RL
98 }
99
100# -----------
101# subtest functions
102sub testss {
103 open RND, ">>", ".rnd";
104 print RND "string to make the random number generator think it has entropy";
105 close RND;
106
5beb63c4 107 my @req_dsa = ("-newkey",
42e0ccdf 108 "dsa:".srctop_file("apps", "dsa1024.pem"));
88b8a527 109 my @req_new;
340166a9 110 if ($no_rsa) {
5beb63c4 111 @req_new = @req_dsa;
88b8a527
RL
112 } else {
113 @req_new = ("-new");
114 }
115
5beb63c4 116 plan tests => 17;
88b8a527
RL
117
118 SKIP: {
5beb63c4 119 skip 'failure', 16 unless
88b8a527
RL
120 ok(run(app([@reqcmd, "-config", $CAconf,
121 "-out", $CAreq, "-keyout", $CAkey,
122 @req_new])),
123 'make cert request');
124
5beb63c4 125 skip 'failure', 15 unless
88b8a527
RL
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');
131
5beb63c4 132 skip 'failure', 14 unless
88b8a527
RL
133 ok(run(app([@x509cmd, "-in", $CAcert,
134 "-x509toreq", "-signkey", $CAkey, "-out", $CAreq2],
135 stdout => "err.ss")),
136 'convert cert into a cert request');
137
5beb63c4 138 skip 'failure', 13 unless
88b8a527
RL
139 ok(run(app([@reqcmd, "-config", $dummycnf,
140 "-verify", "-in", $CAreq, "-noout"])),
141 'verify request 1');
142
143
5beb63c4 144 skip 'failure', 12 unless
88b8a527
RL
145 ok(run(app([@reqcmd, "-config", $dummycnf,
146 "-verify", "-in", $CAreq2, "-noout"])),
147 'verify request 2');
148
5beb63c4 149 skip 'failure', 11 unless
88b8a527
RL
150 ok(run(app([@verifycmd, "-CAfile", $CAcert, $CAcert])),
151 'verify signature');
152
5beb63c4 153 skip 'failure', 10 unless
88b8a527
RL
154 ok(run(app([@reqcmd, "-config", $Uconf,
155 "-out", $Ureq, "-keyout", $Ukey, @req_new],
156 stdout => "err.ss")),
157 'make a user cert request');
158
5beb63c4 159 skip 'failure', 9 unless
88b8a527
RL
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"],
164 stdout => "err.ss"))
165 && run(app([@verifycmd, "-CAfile", $CAcert, $Ucert])),
166 'sign user cert request');
167
5beb63c4 168 skip 'failure', 8 unless
88b8a527
RL
169 ok(run(app([@x509cmd,
170 "-subject", "-issuer", "-startdate", "-enddate",
171 "-noout", "-in", $Ucert])),
172 'Certificate details');
173
5beb63c4
RL
174 skip 'failure', 7 unless
175 subtest 'DSA certificate creation' => sub {
176 plan skip_all => "skipping DSA certificate creation"
340166a9 177 if $no_dsa;
5beb63c4
RL
178
179 plan tests => 4;
180
181 SKIP: {
182 $ENV{CN2} = "DSA Certificate";
183 skip 'failure', 3 unless
184 ok(run(app([@reqcmd, "-config", $Uconf,
185 "-out", $Dreq, "-keyout", $Dkey,
186 @req_dsa],
187 stdout => "err.ss")),
188 "make a DSA user cert request");
189 skip 'failure', 2 unless
190 ok(run(app([@x509cmd, "-CAcreateserial",
191 "-in", $Dreq,
192 "-days", "30",
193 "-req",
194 "-out", $Dcert,
195 "-CA", $CAcert, "-CAkey", $CAkey,
196 "-CAserial", $CAserial,
197 "-extfile", $Uconf,
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",
208 "-in", $Dcert])),
209 "DSA Certificate details");
210 }
211 };
212
213 skip 'failure', 6 unless
214 subtest 'ECDSA/ECDH certificate creation' => sub {
215 plan skip_all => "skipping ECDSA/ECDH certificate creation"
340166a9 216 if $no_ec;
5beb63c4
RL
217
218 plan tests => 5;
219
220 SKIP: {
221 $ENV{CN2} = "ECDSA Certificate";
222 skip 'failure', 4 unless
223 ok(run(app(["openssl", "ecparam", "-name", "P-256",
224 "-out", "ecp.ss"])),
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",
234 "-in", $Ereq,
235 "-days", "30",
236 "-req",
237 "-out", $Ecert,
238 "-CA", $CAcert, "-CAkey", $CAkey,
239 "-CAserial", $CAserial,
240 "-extfile", $Uconf,
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",
251 "-in", $Ecert])),
252 "ECDSA Certificate details");
253 }
254 };
88b8a527
RL
255
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');
261
262
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');
270
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');
278
279 skip 'failure', 2 unless
280 ok(run(app([@reqcmd, "-config", $P2conf,
281 "-out", $P2req, "-keyout", $P2key,
282 @req_new],
283 stdout => "err.ss")),
284 'make another proxy cert request');
285
286
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');
294
295
296 open OUT, ">", $P2intermediate;
297 copy($Ucert, \*OUT); copy($P1cert, \*OUT);
298 close 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');
305 }
306}
307
308sub testssl {
42e0ccdf
RL
309 my $key = shift || bldtop_file("apps","server.pem");
310 my $cert = shift || bldtop_file("apps","server.pem");
88b8a527 311 my $CAtmp = shift;
42e0ccdf 312 my @CA = $CAtmp ? ("-CAfile", $CAtmp) : ("-CApath", bldtop_dir("certs"));
88b8a527
RL
313 my @extra = @_;
314
315 my @ssltest = ("ssltest",
5beb63c4 316 "-s_key", $key, "-s_cert", $cert,
88b8a527
RL
317 "-c_key", $key, "-c_cert", $cert);
318
42e0ccdf 319 my $serverinfo = srctop_file("test","serverinfo.pem");
88b8a527
RL
320
321 my $dsa_cert = 0;
322 if (grep /DSA Public Key/, run(app(["openssl", "x509", "-in", $cert,
323 "-text", "-noout"]), capture => 1)) {
324 $dsa_cert = 1;
325 }
326
327
6b01bed2 328 # plan tests => 10;
88b8a527
RL
329
330 subtest 'standard SSL tests' => sub {
331 ######################################################################
75d5bd4e 332 plan tests => 29;
88b8a527 333
3ea75c63
RL
334 SKIP: {
335 skip "SSLv3 is not supported by this OpenSSL build", 4
336 if disabled("ssl3");
337
338 ok(run(test([@ssltest, "-ssl3", @extra])),
339 'test sslv3');
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');
346 }
347
348 SKIP: {
349 skip "Neither SSLv3 nor any TLS version are supported by this OpenSSL build", 4
350 if $no_anytls;
351
352 ok(run(test([@ssltest, @extra])),
353 'test sslv2/sslv3');
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');
360 }
361
362 SKIP: {
363 skip "SSLv3 is not supported by this OpenSSL build", 4
364 if disabled("ssl3");
365
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');
374 }
375
376 SKIP: {
377 skip "Neither SSLv3 nor any TLS version are supported by this OpenSSL build", 1
378 if $no_anytls;
379
380 ok(run(test([@ssltest, "-bio_pair", @extra])),
381 'test sslv2/sslv3 via BIO pair');
382 }
383
384 SKIP: {
385 skip "DTLSv1 is not supported by this OpenSSL build", 4
386 if disabled("dtls1");
387
388 ok(run(test([@ssltest, "-dtls1", @extra])),
389 'test dtlsv1');
390 ok(run(test([@ssltest, "-dtls1", "-server_auth", @CA, @extra])),
88b8a527 391 'test dtlsv1 with server authentication');
3ea75c63
RL
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');
396 }
397
398 SKIP: {
399 skip "DTLSv1.2 is not supported by this OpenSSL build", 4
400 if disabled("dtls1_2");
401
402 ok(run(test([@ssltest, "-dtls12", @extra])),
403 'test dtlsv1.2');
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');
410 }
411
412 SKIP: {
75d5bd4e 413 skip "Neither SSLv3 nor any TLS version are supported by this OpenSSL build", 8
3ea75c63
RL
414 if $no_anytls;
415
416 SKIP: {
417 skip "skipping test of sslv2/sslv3 w/o (EC)DHE test", 1 if $dsa_cert;
418
419 ok(run(test([@ssltest, "-bio_pair", "-no_dhe", "-no_ecdhe", @extra])),
420 'test sslv2/sslv3 w/o (EC)DHE via BIO pair');
421 }
422
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');
75d5bd4e 433
b7be6d22
RL
434 SKIP: {
435 skip "No IPv4 available on this machine", 1
436 unless have_IPv4();
437 ok(run(test([@ssltest, "-ipv4", @extra])),
438 'test TLS via IPv4');
439 }
440
441 SKIP: {
442 skip "No IPv6 available on this machine", 1
443 unless have_IPv6();
444 ok(run(test([@ssltest, "-ipv6", @extra])),
445 'test TLS via IPv6');
446 }
447 }
88b8a527
RL
448 };
449
450 subtest "Testing ciphersuites" => sub {
451
5beb63c4
RL
452 my @exkeys = ();
453 my $ciphers = "-EXP:-PSK:-SRP:-kDH:-kECDHe";
454
340166a9 455 if ($no_dh) {
5beb63c4
RL
456 note "skipping DHE tests\n";
457 $ciphers .= ":-kDHE";
458 }
340166a9 459 if ($no_dsa) {
5beb63c4
RL
460 note "skipping DSA tests\n";
461 $ciphers .= ":-aDSA";
462 } else {
463 push @exkeys, "-s_cert", "certD.ss", "-s_key", "keyD.ss";
464 }
465
340166a9 466 if ($no_ec) {
5beb63c4
RL
467 note "skipping EC tests\n";
468 $ciphers .= ":!aECDSA:!kECDH";
469 } else {
470 push @exkeys, "-s_cert", "certE.ss", "-s_key", "keyE.ss";
471 }
88b8a527 472
6b01bed2 473 my @protocols = ();
3ea75c63 474 # FIXME: I feel unsure about the following line, is that really just TLSv1.2, or is it all of the SSLv3/TLS protocols?
6b01bed2
VD
475 push(@protocols, "TLSv1.2") unless $no_tls1_2;
476 push(@protocols, "SSLv3") unless $no_ssl3;
88b8a527
RL
477 my $protocolciphersuitcount = 0;
478 my %ciphersuites =
479 map { my @c =
480 map { split(/:/, $_) }
5beb63c4
RL
481 run(app(["openssl", "ciphers", "${_}:$ciphers"]),
482 capture => 1);
4ada8be2 483 map { s/\R//; } @c; # chomp @c;
88b8a527
RL
484 $protocolciphersuitcount += scalar @c;
485 $_ => [ @c ] } @protocols;
486
49dc5404
RL
487 plan skip_all => "None of the ciphersuites to test are available in this OpenSSL build"
488 if $protocolciphersuitcount + scalar(@protocols) == 0;
489
5beb63c4
RL
490 # The count of protocols is because in addition to the ciphersuits
491 # we got above, we're running a weak DH test for each protocol
492 plan tests => $protocolciphersuitcount + scalar(@protocols);
88b8a527
RL
493
494 foreach my $protocol (@protocols) {
495 note "Testing ciphersuites for $protocol";
496 foreach my $cipher (@{$ciphersuites{$protocol}}) {
5beb63c4 497 ok(run(test([@ssltest, @exkeys, "-cipher", $cipher,
88b8a527
RL
498 $protocol eq "SSLv3" ? ("-ssl3") : ()])),
499 "Testing $cipher");
500 }
5beb63c4
RL
501 is(run(test([@ssltest,
502 "-s_cipher", "EDH",
503 "-c_cipher", 'EDH:@SECLEVEL=1',
504 "-dhe512",
505 $protocol eq "SSLv3" ? ("-ssl3") : ()])), 0,
506 "testing connection with weak DH, expecting failure");
88b8a527
RL
507 }
508 };
509
510 subtest 'RSA/(EC)DHE/PSK tests' => sub {
511 ######################################################################
512
513 plan tests => 5;
514
3ea75c63
RL
515 SKIP: {
516 skip "TLSv1.0 is not supported by this OpenSSL build", 5
517 if $no_tls1;
88b8a527 518
3ea75c63
RL
519 SKIP: {
520 skip "skipping anonymous DH tests", 1
521 if ($no_dh);
88b8a527 522
3ea75c63
RL
523 ok(run(test([@ssltest, "-v", "-bio_pair", "-tls1", "-cipher", "ADH", "-dhe1024dsa", "-num", "10", "-f", "-time", @extra])),
524 'test tlsv1 with 1024bit anonymous DH, multiple handshakes');
525 }
88b8a527 526
3ea75c63
RL
527 SKIP: {
528 skip "skipping RSA tests", 2
529 if $no_rsa;
88b8a527 530
42e0ccdf 531 ok(run(test(["ssltest", "-v", "-bio_pair", "-tls1", "-s_cert", srctop_file("apps","server2.pem"), "-no_dhe", "-no_ecdhe", "-num", "10", "-f", "-time", @extra])),
3ea75c63 532 'test tlsv1 with 1024bit RSA, no (EC)DHE, multiple handshakes');
88b8a527 533
3ea75c63
RL
534 skip "skipping RSA+DHE tests", 1
535 if $no_dh;
536
42e0ccdf 537 ok(run(test(["ssltest", "-v", "-bio_pair", "-tls1", "-s_cert", srctop_file("apps","server2.pem"), "-dhe1024dsa", "-num", "10", "-f", "-time", @extra])),
3ea75c63
RL
538 'test tlsv1 with 1024bit RSA, 1024bit DHE, multiple handshakes');
539 }
540
541 SKIP: {
542 skip "skipping PSK tests", 2
71a64af3
DSH
543 if ($no_psk);
544
3ea75c63
RL
545 ok(run(test([@ssltest, "-tls1", "-cipher", "PSK", "-psk", "abc123", @extra])),
546 'test tls1 with PSK');
71a64af3 547
3ea75c63
RL
548 ok(run(test([@ssltest, "-bio_pair", "-tls1", "-cipher", "PSK", "-psk", "abc123", @extra])),
549 'test tls1 with PSK via BIO pair');
550 }
551 }
88b8a527 552
88b8a527
RL
553 };
554
555 subtest 'Next Protocol Negotiation Tests' => sub {
556 ######################################################################
557
558 plan tests => 7;
559
3ea75c63
RL
560 SKIP: {
561 skip "TLSv1.0 is not supported by this OpenSSL build", 7
562 if $no_tls1;
563
564 ok(run(test([@ssltest, "-bio_pair", "-tls1", "-npn_client"])));
565 ok(run(test([@ssltest, "-bio_pair", "-tls1", "-npn_server"])));
566 ok(run(test([@ssltest, "-bio_pair", "-tls1", "-npn_server_reject"])));
567 ok(run(test([@ssltest, "-bio_pair", "-tls1", "-npn_client", "-npn_server_reject"])));
568 ok(run(test([@ssltest, "-bio_pair", "-tls1", "-npn_client", "-npn_server"])));
569 ok(run(test([@ssltest, "-bio_pair", "-tls1", "-npn_client", "-npn_server", "-num", "2"])));
570 ok(run(test([@ssltest, "-bio_pair", "-tls1", "-npn_client", "-npn_server", "-num", "2", "-reuse"])));
571 }
88b8a527
RL
572 };
573
574 subtest 'Custom Extension tests' => sub {
575 ######################################################################
576
577 plan tests => 1;
578
3ea75c63 579 SKIP: {
f006217b 580 skip "TLSv1.0 is not supported by this OpenSSL build", 1
3ea75c63
RL
581 if $no_tls1;
582
583 ok(run(test([@ssltest, "-bio_pair", "-tls1", "-custom_ext"])),
584 'test tls1 with custom extensions');
585 }
88b8a527
RL
586 };
587
588 subtest 'Serverinfo tests' => sub {
589 ######################################################################
590
591 plan tests => 5;
592
3ea75c63
RL
593 SKIP: {
594 skip "TLSv1.0 is not supported by this OpenSSL build", 5
595 if $no_tls1;
596
597 note('echo test tls1 with serverinfo');
598 ok(run(test([@ssltest, "-bio_pair", "-tls1", "-serverinfo_file", $serverinfo])));
599 ok(run(test([@ssltest, "-bio_pair", "-tls1", "-serverinfo_file", $serverinfo, "-serverinfo_sct"])));
600 ok(run(test([@ssltest, "-bio_pair", "-tls1", "-serverinfo_file", $serverinfo, "-serverinfo_tack"])));
601 ok(run(test([@ssltest, "-bio_pair", "-tls1", "-serverinfo_file", $serverinfo, "-serverinfo_sct", "-serverinfo_tack"])));
602 ok(run(test([@ssltest, "-bio_pair", "-tls1", "-custom_ext", "-serverinfo_file", $serverinfo, "-serverinfo_sct", "-serverinfo_tack"])));
603 }
88b8a527
RL
604 };
605
606 subtest 'ALPN tests' => sub {
607 ######################################################################
608
06217867 609 plan tests => 14;
88b8a527 610
3ea75c63
RL
611 SKIP: {
612 skip "TLSv1.0 is not supported by this OpenSSL build", 12
613 if $no_tls1;
614
06217867
EK
615 ok(run(test([@ssltest, "-bio_pair", "-tls1", "-alpn_client", "foo"])));
616 ok(run(test([@ssltest, "-bio_pair", "-tls1", "-alpn_server", "foo"])));
3ea75c63
RL
617 ok(run(test([@ssltest, "-bio_pair", "-tls1", "-alpn_client", "foo", "-alpn_server", "foo", "-alpn_expected", "foo"])));
618 ok(run(test([@ssltest, "-bio_pair", "-tls1", "-alpn_client", "foo,bar", "-alpn_server", "foo", "-alpn_expected", "foo"])));
619 ok(run(test([@ssltest, "-bio_pair", "-tls1", "-alpn_client", "bar,foo", "-alpn_server", "foo", "-alpn_expected", "foo"])));
620 ok(run(test([@ssltest, "-bio_pair", "-tls1", "-alpn_client", "bar,foo", "-alpn_server", "foo,bar", "-alpn_expected", "foo"])));
621 ok(run(test([@ssltest, "-bio_pair", "-tls1", "-alpn_client", "bar,foo", "-alpn_server", "bar,foo", "-alpn_expected", "bar"])));
622 ok(run(test([@ssltest, "-bio_pair", "-tls1", "-alpn_client", "foo,bar", "-alpn_server", "bar,foo", "-alpn_expected", "bar"])));
06217867
EK
623
624 is(run(test([@ssltest, "-bio_pair", "-tls1", "-alpn_client", "foo", "-alpn_server", "bar"])), 0,
625 "Testing ALPN with protocol mismatch, expecting failure");
626 is(run(test([@ssltest, "-bio_pair", "-tls1", "-alpn_client", "baz", "-alpn_server", "bar,foo"])), 0,
627 "Testing ALPN with protocol mismatch, expecting failure");
88b8a527 628
3ea75c63
RL
629 SKIP: {
630 skip "skipping SRP tests", 4
631 if $no_srp;
88b8a527 632
3ea75c63
RL
633 ok(run(test([@ssltest, "-tls1", "-cipher", "SRP", "-srpuser", "test", "-srppass", "abc123"])),
634 'test tls1 with SRP');
88b8a527 635
3ea75c63
RL
636 ok(run(test([@ssltest, "-bio_pair", "-tls1", "-cipher", "SRP", "-srpuser", "test", "-srppass", "abc123"])),
637 'test tls1 with SRP via BIO pair');
88b8a527 638
3ea75c63 639 ok(run(test([@ssltest, "-tls1", "-cipher", "aSRP", "-srpuser", "test", "-srppass", "abc123"])),
88b8a527
RL
640 'test tls1 with SRP auth');
641
3ea75c63
RL
642 ok(run(test([@ssltest, "-bio_pair", "-tls1", "-cipher", "aSRP", "-srpuser", "test", "-srppass", "abc123"])),
643 'test tls1 with SRP auth via BIO pair');
644 }
88b8a527
RL
645 }
646 };
647
648 subtest 'Multi-buffer tests' => sub {
649 ######################################################################
650
651 plan tests => 2;
652
3ea75c63
RL
653 SKIP: {
654 skip "Neither SSLv3 nor any TLS version are supported by this OpenSSL build", 2
655 if $no_anytls;
656
657 skip "skipping multi-buffer tests", 2
658 if @extra || (POSIX::uname())[4] ne "x86_64";
659
660 ok(run(test([@ssltest, "-cipher", "AES128-SHA", "-bytes", "8m"])));
661
662 # We happen to know that AES128-SHA256 is TLSv1.2 only... for now.
663 skip "TLSv1.2 is not supported by this OpenSSL configuration", 1
664 if $no_tls1_2;
665
666 ok(run(test([@ssltest, "-cipher", "AES128-SHA256", "-bytes", "8m"])));
88b8a527
RL
667 }
668 };
7946ab33 669
6b01bed2
VD
670 subtest 'TLS Version min/max tests' => sub {
671 my @protos;
672 push(@protos, "ssl3") unless $no_ssl3;
673 push(@protos, "tls1") unless $no_tls1;
674 push(@protos, "tls1.1") unless $no_tls1_1;
675 push(@protos, "tls1.2") unless $no_tls1_2;
676 my @minprotos = (undef, @protos);
677 my @maxprotos = (@protos, undef);
678 my @shdprotos = (@protos, $protos[$#protos]);
679 my $n = ((@protos+2) * (@protos+3))/2 - 2;
680 my $ntests = $n * $n;
681 plan tests => $ntests;
835894d1 682 SKIP: {
6b01bed2
VD
683 skip "TLS disabled", 1 if $ntests == 1;
684
685 my $should;
686 for (my $smin = 0; $smin < @minprotos; ++$smin) {
687 for (my $smax = $smin ? $smin - 1 : 0; $smax < @maxprotos; ++$smax) {
688 for (my $cmin = 0; $cmin < @minprotos; ++$cmin) {
689 for (my $cmax = $cmin ? $cmin - 1 : 0; $cmax < @maxprotos; ++$cmax) {
690 if ($cmax < $smin-1) {
691 $should = "fail-server";
692 } elsif ($smax < $cmin-1) {
693 $should = "fail-client";
694 } elsif ($cmax > $smax) {
695 $should = $shdprotos[$smax];
696 } else {
697 $should = $shdprotos[$cmax];
698 }
699
700 my @args = @ssltest;
701 push(@args, "-should_negotiate", $should);
702 push(@args, "-server_min_proto", $minprotos[$smin])
703 if (defined($minprotos[$smin]));
704 push(@args, "-server_max_proto", $maxprotos[$smax])
705 if (defined($maxprotos[$smax]));
706 push(@args, "-client_min_proto", $minprotos[$cmin])
707 if (defined($minprotos[$cmin]));
708 push(@args, "-client_max_proto", $maxprotos[$cmax])
709 if (defined($maxprotos[$cmax]));
710 my $ok = run(test[@args]);
711 if (! $ok) {
712 print STDERR "\nsmin=$smin, smax=$smax, cmin=$cmin, cmax=$cmax\n";
713 print STDERR "\nFailed: @args\n";
714 }
715 ok($ok);
835894d1 716 }}}}}
6b01bed2 717 };
7946ab33 718
6b01bed2
VD
719 subtest 'DTLS Version min/max tests' => sub {
720 my @protos;
721 push(@protos, "dtls1") unless ($no_dtls1 || $no_dtls);
722 push(@protos, "dtls1.2") unless ($no_dtls1_2 || $no_dtls);
723 my @minprotos = (undef, @protos);
724 my @maxprotos = (@protos, undef);
725 my @shdprotos = (@protos, $protos[$#protos]);
726 my $n = ((@protos+2) * (@protos+3))/2 - 2;
727 my $ntests = $n * $n;
728 plan tests => $ntests;
835894d1 729 SKIP: {
6b01bed2
VD
730 skip "DTLS disabled", 1 if $ntests == 1;
731
732 my $should;
733 for (my $smin = 0; $smin < @minprotos; ++$smin) {
734 for (my $smax = $smin ? $smin - 1 : 0; $smax < @maxprotos; ++$smax) {
735 for (my $cmin = 0; $cmin < @minprotos; ++$cmin) {
736 for (my $cmax = $cmin ? $cmin - 1 : 0; $cmax < @maxprotos; ++$cmax) {
737 if ($cmax < $smin-1) {
738 $should = "fail-server";
739 } elsif ($smax < $cmin-1) {
740 $should = "fail-client";
741 } elsif ($cmax > $smax) {
742 $should = $shdprotos[$smax];
743 } else {
744 $should = $shdprotos[$cmax];
745 }
746
747 my @args = (@ssltest, "-dtls");
748 push(@args, "-should_negotiate", $should);
749 push(@args, "-server_min_proto", $minprotos[$smin])
750 if (defined($minprotos[$smin]));
751 push(@args, "-server_max_proto", $maxprotos[$smax])
752 if (defined($maxprotos[$smax]));
753 push(@args, "-client_min_proto", $minprotos[$cmin])
754 if (defined($minprotos[$cmin]));
755 push(@args, "-client_max_proto", $maxprotos[$cmax])
756 if (defined($maxprotos[$cmax]));
757 my $ok = run(test[@args]);
758 if (! $ok) {
759 print STDERR "\nsmin=$smin, smax=$smax, cmin=$cmin, cmax=$cmax\n";
760 print STDERR "\nFailed: @args\n";
761 }
762 ok($ok);
835894d1 763 }}}}}
7946ab33 764 };
88b8a527
RL
765}
766
767sub testsslproxy {
42e0ccdf
RL
768 my $key = shift || srctop_file("apps","server.pem");
769 my $cert = shift || srctop_file("apps","server.pem");
49b147f8 770 my $CAtmp = shift;
42e0ccdf 771 my @CA = $CAtmp ? ("-CAfile", $CAtmp) : ("-CApath", bldtop_dir("certs"));
49b147f8
RL
772 my @extra = @_;
773
774 my @ssltest = ("ssltest",
775 "-s_key", $key, "-s_cert", $cert,
776 "-c_key", $key, "-c_cert", $cert);
88b8a527
RL
777
778 # plan tests => 16;
779
780 note('Testing a lot of proxy conditions.');
49b147f8
RL
781
782 # We happen to know that certP1.ss has policy letters "AB" and
783 # certP2.ss has policy letters "BC". However, because certP2.ss
784 # has certP1.ss as issuer, when it's used, both their policy
785 # letters get combined into just "B".
786 # The policy letter(s) then get filtered with the given auth letter
787 # in the table below, and the result gets tested with the given
788 # condition. For details, read ssltest.c
789 #
790 # certfilename => [ [ auth, cond, expected result ] ... ]
791 my %expected = ( "certP1.ss" => [ [ [ 'A', 'A' ], 1 ],
792 [ [ 'A', 'B' ], 0 ],
793 [ [ 'A', 'C' ], 0 ],
794 [ [ 'A', 'A|B&!C' ], 1 ],
795 [ [ 'B', 'A' ], 0 ],
796 [ [ 'B', 'B' ], 1 ],
797 [ [ 'B', 'C' ], 0 ],
798 [ [ 'B', 'A|B&!C' ], 1 ],
799 [ [ 'C', 'A' ], 0 ],
800 [ [ 'C', 'B' ], 0 ],
801 [ [ 'C', 'C' ], 0 ],
802 [ [ 'C', 'A|B&!C' ], 0 ],
803 [ [ 'BC', 'A' ], 0 ],
804 [ [ 'BC', 'B' ], 1 ],
805 [ [ 'BC', 'C' ], 0 ],
806 [ [ 'BC', 'A|B&!C' ], 1 ] ],
807 "certP2.ss" => [ [ [ 'A', 'A' ], 0 ],
808 [ [ 'A', 'B' ], 0 ],
809 [ [ 'A', 'C' ], 0 ],
810 [ [ 'A', 'A|B&!C' ], 0 ],
811 [ [ 'B', 'A' ], 0 ],
812 [ [ 'B', 'B' ], 1 ],
813 [ [ 'B', 'C' ], 0 ],
814 [ [ 'B', 'A|B&!C' ], 1 ],
815 [ [ 'C', 'A' ], 0 ],
816 [ [ 'C', 'B' ], 0 ],
817 [ [ 'C', 'C' ], 0 ],
818 [ [ 'C', 'A|B&!C' ], 0 ],
819 [ [ 'BC', 'A' ], 0 ],
820 [ [ 'BC', 'B' ], 1 ],
821 [ [ 'BC', 'C' ], 0 ],
822 [ [ 'BC', 'A|B&!C' ], 1 ] ] );
823
3ea75c63
RL
824 SKIP: {
825 skip "Neither SSLv3 nor any TLS version are supported by this OpenSSL build", scalar(@{$expected{$cert}})
826 if $no_anytls;
827
828 foreach (@{$expected{$cert}}) {
829 my $auth = $_->[0]->[0];
830 my $cond = $_->[0]->[1];
831 my $res = $_->[1];
832 is(run(test([@ssltest, "-server_auth", @CA,
833 "-proxy", "-proxy_auth", $auth,
834 "-proxy_cond", $cond])), $res,
835 "test tlsv1, server auth, proxy auth $auth and cond $cond (expect "
836 .($res ? "success" : "failure").")");
837 }
88b8a527
RL
838 }
839}