]>
git.ipfire.org Git - thirdparty/openssl.git/blob - test/recipes/80-test_ssl.t
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 disabled qw
/rsa dsa dh ec srp psk/;
18 my @reqcmd = ("openssl", "req");
19 my @x509cmd = ("openssl", "x509", $digest);
20 my @verifycmd = ("openssl", "verify");
21 my $dummycnf = top_file
("apps", "openssl.cnf");
23 my $CAkey = "keyCA.ss";
24 my $CAcert="certCA.ss";
25 my $CAserial="certCA.srl";
27 my $CAconf=top_file
("test","CAss.cnf");
28 my $CAreq2="req2CA.ss"; # temp
30 my $Uconf=top_file
("test","Uss.cnf");
43 my $P1conf=top_file
("test","P1ss.cnf");
46 my $P1cert="certP1.ss";
47 my $P1intermediate="tmp_intP1.ss";
49 my $P2conf=top_file
("test","P2ss.cnf");
52 my $P2cert="certP2.ss";
53 my $P2intermediate="tmp_intP2.ss";
57 + 1 # For ssltest -test_cipherlist
58 + 8 # For the first testssl
59 + 16 # For the first testsslproxy
60 + 16 # For the second testsslproxy
63 subtest
'test_ss' => sub {
65 open OUT
, ">", "intP1.ss";
66 copy
($CAcert, \
*OUT
); copy
($Ucert, \
*OUT
);
69 open OUT
, ">", "intP2.ss";
70 copy
($CAcert, \
*OUT
); copy
($Ucert, \
*OUT
); copy
($P1cert, \
*OUT
);
75 my $check = ok
(run
(test
(["ssltest","-test_cipherlist"])), "running ssltest");
78 skip
"ssltest ended with error, skipping the rest", 3
81 note
('test_ssl -- key U');
82 testssl
("keyU.ss", $Ucert, $CAcert);
84 note
('test_ssl -- key P1');
85 testsslproxy
("keyP1.ss", "certP1.ss", "intP1.ss", "AB");
87 note
('test_ssl -- key P2');
88 testsslproxy
("keyP2.ss", "certP2.ss", "intP2.ss", "BC");
94 open RND
, ">>", ".rnd";
95 print RND
"string to make the random number generator think it has entropy";
98 my @req_dsa = ("-newkey",
99 "dsa:".File
::Spec
->catfile("..", "apps", "dsa1024.pem"));;
110 skip
'failure', 16 unless
111 ok
(run
(app
([@reqcmd, "-config", $CAconf,
112 "-out", $CAreq, "-keyout", $CAkey,
114 'make cert request');
116 skip
'failure', 15 unless
117 ok
(run
(app
([@x509cmd, "-CAcreateserial", "-in", $CAreq, "-days", "30",
118 "-req", "-out", $CAcert, "-signkey", $CAkey,
119 "-extfile", $CAconf, "-extensions", "v3_ca"],
120 stdout
=> "err.ss")),
121 'convert request into self-signed cert');
123 skip
'failure', 14 unless
124 ok
(run
(app
([@x509cmd, "-in", $CAcert,
125 "-x509toreq", "-signkey", $CAkey, "-out", $CAreq2],
126 stdout
=> "err.ss")),
127 'convert cert into a cert request');
129 skip
'failure', 13 unless
130 ok
(run
(app
([@reqcmd, "-config", $dummycnf,
131 "-verify", "-in", $CAreq, "-noout"])),
135 skip
'failure', 12 unless
136 ok
(run
(app
([@reqcmd, "-config", $dummycnf,
137 "-verify", "-in", $CAreq2, "-noout"])),
140 skip
'failure', 11 unless
141 ok
(run
(app
([@verifycmd, "-CAfile", $CAcert, $CAcert])),
144 skip
'failure', 10 unless
145 ok
(run
(app
([@reqcmd, "-config", $Uconf,
146 "-out", $Ureq, "-keyout", $Ukey, @req_new],
147 stdout
=> "err.ss")),
148 'make a user cert request');
150 skip
'failure', 9 unless
151 ok
(run
(app
([@x509cmd, "-CAcreateserial", "-in", $Ureq, "-days", "30",
152 "-req", "-out", $Ucert,
153 "-CA", $CAcert, "-CAkey", $CAkey, "-CAserial", $CAserial,
154 "-extfile", $Uconf, "-extensions", "v3_ee"],
156 && run
(app
([@verifycmd, "-CAfile", $CAcert, $Ucert])),
157 'sign user cert request');
159 skip
'failure', 8 unless
160 ok
(run
(app
([@x509cmd,
161 "-subject", "-issuer", "-startdate", "-enddate",
162 "-noout", "-in", $Ucert])),
163 'Certificate details');
165 skip
'failure', 7 unless
166 subtest
'DSA certificate creation' => sub {
167 plan skip_all
=> "skipping DSA certificate creation"
173 $ENV{CN2
} = "DSA Certificate";
174 skip
'failure', 3 unless
175 ok
(run
(app
([@reqcmd, "-config", $Uconf,
176 "-out", $Dreq, "-keyout", $Dkey,
178 stdout
=> "err.ss")),
179 "make a DSA user cert request");
180 skip
'failure', 2 unless
181 ok
(run
(app
([@x509cmd, "-CAcreateserial",
186 "-CA", $CAcert, "-CAkey", $CAkey,
187 "-CAserial", $CAserial,
189 "-extensions", "v3_ee_dsa"],
190 stdout
=> "err.ss")),
191 "sign DSA user cert request");
192 skip
'failure', 1 unless
193 ok
(run
(app
([@verifycmd, "-CAfile", $CAcert, $Dcert])),
194 "verify DSA user cert");
195 skip
'failure', 0 unless
196 ok
(run
(app
([@x509cmd,
197 "-subject", "-issuer",
198 "-startdate", "-enddate", "-noout",
200 "DSA Certificate details");
204 skip
'failure', 6 unless
205 subtest
'ECDSA/ECDH certificate creation' => sub {
206 plan skip_all
=> "skipping ECDSA/ECDH certificate creation"
212 $ENV{CN2
} = "ECDSA Certificate";
213 skip
'failure', 4 unless
214 ok
(run
(app
(["openssl", "ecparam", "-name", "P-256",
216 "make EC parameters");
217 skip
'failure', 3 unless
218 ok
(run
(app
([@reqcmd, "-config", $Uconf,
219 "-out", $Ereq, "-keyout", $Ekey,
220 "-newkey", "ec:ecp.ss"],
221 stdout
=> "err.ss")),
222 "make a ECDSA/ECDH user cert request");
223 skip
'failure', 2 unless
224 ok
(run
(app
([@x509cmd, "-CAcreateserial",
229 "-CA", $CAcert, "-CAkey", $CAkey,
230 "-CAserial", $CAserial,
232 "-extensions", "v3_ee_ec"],
233 stdout
=> "err.ss")),
234 "sign ECDSA/ECDH user cert request");
235 skip
'failure', 1 unless
236 ok
(run
(app
([@verifycmd, "-CAfile", $CAcert, $Ecert])),
237 "verify ECDSA/ECDH user cert");
238 skip
'failure', 0 unless
239 ok
(run
(app
([@x509cmd,
240 "-subject", "-issuer",
241 "-startdate", "-enddate", "-noout",
243 "ECDSA Certificate details");
247 skip
'failure', 5 unless
248 ok
(run
(app
([@reqcmd, "-config", $P1conf,
249 "-out", $P1req, "-keyout", $P1key, @req_new],
250 stdout
=> "err.ss")),
251 'make a proxy cert request');
254 skip
'failure', 4 unless
255 ok
(run
(app
([@x509cmd, "-CAcreateserial", "-in", $P1req, "-days", "30",
256 "-req", "-out", $P1cert,
257 "-CA", $Ucert, "-CAkey", $Ukey,
258 "-extfile", $P1conf, "-extensions", "v3_proxy"],
259 stdout
=> "err.ss")),
260 'sign proxy with user cert');
262 copy
($Ucert, $P1intermediate);
263 run
(app
([@verifycmd, "-CAfile", $CAcert,
264 "-untrusted", $P1intermediate, $P1cert]));
265 ok
(run
(app
([@x509cmd,
266 "-subject", "-issuer", "-startdate", "-enddate",
267 "-noout", "-in", $P1cert])),
268 'Certificate details');
270 skip
'failure', 2 unless
271 ok
(run
(app
([@reqcmd, "-config", $P2conf,
272 "-out", $P2req, "-keyout", $P2key,
274 stdout
=> "err.ss")),
275 'make another proxy cert request');
278 skip
'failure', 1 unless
279 ok
(run
(app
([@x509cmd, "-CAcreateserial", "-in", $P2req, "-days", "30",
280 "-req", "-out", $P2cert,
281 "-CA", $P1cert, "-CAkey", $P1key,
282 "-extfile", $P2conf, "-extensions", "v3_proxy"],
283 stdout
=> "err.ss")),
284 'sign second proxy cert request with the first proxy cert');
287 open OUT
, ">", $P2intermediate;
288 copy
($Ucert, \
*OUT
); copy
($P1cert, \
*OUT
);
290 run
(app
([@verifycmd, "-CAfile", $CAcert,
291 "-untrusted", $P2intermediate, $P2cert]));
292 ok
(run
(app
([@x509cmd,
293 "-subject", "-issuer", "-startdate", "-enddate",
294 "-noout", "-in", $P2cert])),
295 'Certificate details');
300 my $key = shift || top_file
("apps","server.pem");
301 my $cert = shift || top_file
("apps","server.pem");
303 my @CA = $CAtmp ?
("-CAfile", $CAtmp) : ("-CApath", top_dir
("certs"));
306 my @ssltest = ("ssltest",
307 "-s_key", $key, "-s_cert", $cert,
308 "-c_key", $key, "-c_cert", $cert);
310 my $serverinfo = top_file
("test","serverinfo.pem");
313 if (grep /DSA Public Key/, run
(app
(["openssl", "x509", "-in", $cert,
314 "-text", "-noout"]), capture
=> 1)) {
321 subtest
'standard SSL tests' => sub {
322 ######################################################################
325 ok
(run
(test
([@ssltest, "-ssl3", @extra])),
327 ok
(run
(test
([@ssltest, "-ssl3", "-server_auth", @CA, @extra])),
328 'test sslv3 with server authentication');
329 ok
(run
(test
([@ssltest, "-ssl3", "-client_auth", @CA, @extra])),
330 'test sslv3 with client authentication');
331 ok
(run
(test
([@ssltest, "-ssl3", "-server_auth", "-client_auth", @CA, @extra])),
332 'test sslv3 with both server and client authentication');
333 ok
(run
(test
([@ssltest, @extra])),
335 ok
(run
(test
([@ssltest, "-server_auth", @CA, @extra])),
336 'test sslv2/sslv3 with server authentication');
337 ok
(run
(test
([@ssltest, "-client_auth", @CA, @extra])),
338 'test sslv2/sslv3 with client authentication');
339 ok
(run
(test
([@ssltest, "-server_auth", "-client_auth", @CA, @extra])),
340 'test sslv2/sslv3 with both server and client authentication');
341 ok
(run
(test
([@ssltest, "-bio_pair", "-ssl3", @extra])),
342 'test sslv3 via BIO pair');
343 ok
(run
(test
([@ssltest, "-bio_pair", "-ssl3", "-server_auth", @CA, @extra])),
344 'test sslv3 with server authentication via BIO pair');
345 ok
(run
(test
([@ssltest, "-bio_pair", "-ssl3", "-client_auth", @CA, @extra])),
346 'test sslv3 with client authentication via BIO pair');
347 ok
(run
(test
([@ssltest, "-bio_pair", "-ssl3", "-server_auth", "-client_auth", @CA, @extra])),
348 'test sslv3 with both server and client authentication via BIO pair');
349 ok
(run
(test
([@ssltest, "-bio_pair", @extra])),
350 'test sslv2/sslv3 via BIO pair');
351 ok
(run
(test
([@ssltest, "-dtls1", @extra])),
353 ok
(run
(test
([@ssltest, "-dtls1", "-server_auth", @CA, @extra])),
354 'test dtlsv1 with server authentication');
355 ok
(run
(test
([@ssltest, "-dtls1", "-client_auth", @CA, @extra])),
356 'test dtlsv1 with client authentication');
357 ok
(run
(test
([@ssltest, "-dtls1", "-server_auth", "-client_auth", @CA, @extra])),
358 'test dtlsv1 with both server and client authentication');
359 ok
(run
(test
([@ssltest, "-dtls12", @extra])),
361 ok
(run
(test
([@ssltest, "-dtls12", "-server_auth", @CA, @extra])),
362 'test dtlsv1.2 with server authentication');
363 ok
(run
(test
([@ssltest, "-dtls12", "-client_auth", @CA, @extra])),
364 'test dtlsv1.2 with client authentication');
365 ok
(run
(test
([@ssltest, "-dtls12", "-server_auth", "-client_auth", @CA, @extra])),
366 'test dtlsv1.2 with both server and client authentication');
369 skip
"skipping test of sslv2/sslv3 w/o (EC)DHE test", 1 if $dsa_cert;
371 ok
(run
(test
([@ssltest, "-bio_pair", "-no_dhe", "-no_ecdhe", @extra])),
372 'test sslv2/sslv3 w/o (EC)DHE via BIO pair');
375 ok
(run
(test
([@ssltest, "-bio_pair", "-dhe1024dsa", "-v", @extra])),
376 'test sslv2/sslv3 with 1024bit DHE via BIO pair');
377 ok
(run
(test
([@ssltest, "-bio_pair", "-server_auth", @CA, @extra])),
378 'test sslv2/sslv3 with server authentication');
379 ok
(run
(test
([@ssltest, "-bio_pair", "-client_auth", @CA, @extra])),
380 'test sslv2/sslv3 with client authentication via BIO pair');
381 ok
(run
(test
([@ssltest, "-bio_pair", "-server_auth", "-client_auth", @CA, @extra])),
382 'test sslv2/sslv3 with both client and server authentication via BIO pair');
383 ok
(run
(test
([@ssltest, "-bio_pair", "-server_auth", "-client_auth", "-app_verify", @CA, @extra])),
384 'test sslv2/sslv3 with both client and server authentication via BIO pair and app verify');
387 subtest
"Testing ciphersuites" => sub {
390 my $ciphers = "-EXP:-PSK:-SRP:-kDH:-kECDHe";
393 note
"skipping DHE tests\n";
394 $ciphers .= ":-kDHE";
397 note
"skipping DSA tests\n";
398 $ciphers .= ":-aDSA";
400 push @exkeys, "-s_cert", "certD.ss", "-s_key", "keyD.ss";
404 note
"skipping EC tests\n";
405 $ciphers .= ":!aECDSA:!kECDH";
407 push @exkeys, "-s_cert", "certE.ss", "-s_key", "keyE.ss";
410 my @protocols = ("TLSv1.2", "SSLv3");
411 my $protocolciphersuitcount = 0;
414 map { split(/:/, $_) }
415 run
(app
(["openssl", "ciphers", "${_}:$ciphers"]),
418 $protocolciphersuitcount += scalar @c;
419 $_ => [ @c ] } @protocols;
421 # The count of protocols is because in addition to the ciphersuits
422 # we got above, we're running a weak DH test for each protocol
423 plan tests
=> $protocolciphersuitcount + scalar(@protocols);
425 foreach my $protocol (@protocols) {
426 note
"Testing ciphersuites for $protocol";
427 foreach my $cipher (@
{$ciphersuites{$protocol}}) {
428 ok
(run
(test
([@ssltest, @exkeys, "-cipher", $cipher,
429 $protocol eq "SSLv3" ?
("-ssl3") : ()])),
432 is
(run
(test
([@ssltest,
434 "-c_cipher", 'EDH:@SECLEVEL=1',
436 $protocol eq "SSLv3" ?
("-ssl3") : ()])), 0,
437 "testing connection with weak DH, expecting failure");
441 subtest
'RSA/(EC)DHE/PSK tests' => sub {
442 ######################################################################
448 skip
"skipping anonymous DH tests", 1
451 ok
(run
(test
([@ssltest, "-v", "-bio_pair", "-tls1", "-cipher", "ADH", "-dhe1024dsa", "-num", "10", "-f", "-time", @extra])),
452 'test tlsv1 with 1024bit anonymous DH, multiple handshakes');
458 skip
"skipping RSA tests", 2
461 ok
(run
(test
(["ssltest", "-v", "-bio_pair", "-tls1", "-s_cert", top_file
("apps","server2.pem"), "-no_dhe", "-no_ecdhe", "-num", "10", "-f", "-time", @extra])),
462 'test tlsv1 with 1024bit RSA, no (EC)DHE, multiple handshakes');
464 skip
"skipping RSA+DHE tests", 1
467 ok
(run
(test
(["ssltest", "-v", "-bio_pair", "-tls1", "-s_cert", top_file
("apps","server2.pem"), "-dhe1024dsa", "-num", "10", "-f", "-time", @extra])),
468 'test tlsv1 with 1024bit RSA, 1024bit DHE, multiple handshakes');
471 ok
(run
(test
([@ssltest, "-tls1", "-cipher", "PSK", "-psk", "abc123", @extra])),
472 'test tls1 with PSK');
474 ok
(run
(test
([@ssltest, "-bio_pair", "-tls1", "-cipher", "PSK", "-psk", "abc123", @extra])),
475 'test tls1 with PSK via BIO pair');
478 subtest
'Next Protocol Negotiation Tests' => sub {
479 ######################################################################
483 ok
(run
(test
([@ssltest, "-bio_pair", "-tls1", "-npn_client"])));
484 ok
(run
(test
([@ssltest, "-bio_pair", "-tls1", "-npn_server"])));
485 ok
(run
(test
([@ssltest, "-bio_pair", "-tls1", "-npn_server_reject"])));
486 ok
(run
(test
([@ssltest, "-bio_pair", "-tls1", "-npn_client", "-npn_server_reject"])));
487 ok
(run
(test
([@ssltest, "-bio_pair", "-tls1", "-npn_client", "-npn_server"])));
488 ok
(run
(test
([@ssltest, "-bio_pair", "-tls1", "-npn_client", "-npn_server", "-num", "2"])));
489 ok
(run
(test
([@ssltest, "-bio_pair", "-tls1", "-npn_client", "-npn_server", "-num", "2", "-reuse"])));
492 subtest
'Custom Extension tests' => sub {
493 ######################################################################
497 ok
(run
(test
([@ssltest, "-bio_pair", "-tls1", "-custom_ext"])),
498 'test tls1 with custom extensions');
501 subtest
'Serverinfo tests' => sub {
502 ######################################################################
506 note
('echo test tls1 with serverinfo');
507 ok
(run
(test
([@ssltest, "-bio_pair", "-tls1", "-serverinfo_file", $serverinfo])));
508 ok
(run
(test
([@ssltest, "-bio_pair", "-tls1", "-serverinfo_file", $serverinfo, "-serverinfo_sct"])));
509 ok
(run
(test
([@ssltest, "-bio_pair", "-tls1", "-serverinfo_file", $serverinfo, "-serverinfo_tack"])));
510 ok
(run
(test
([@ssltest, "-bio_pair", "-tls1", "-serverinfo_file", $serverinfo, "-serverinfo_sct", "-serverinfo_tack"])));
511 ok
(run
(test
([@ssltest, "-bio_pair", "-tls1", "-custom_ext", "-serverinfo_file", $serverinfo, "-serverinfo_sct", "-serverinfo_tack"])));
514 subtest
'ALPN tests' => sub {
515 ######################################################################
519 ok
(run
(test
([@ssltest, "-bio_pair", "-tls1", "-alpn_client", "foo", "-alpn_server", "bar"])));
520 ok
(run
(test
([@ssltest, "-bio_pair", "-tls1", "-alpn_client", "foo", "-alpn_server", "foo", "-alpn_expected", "foo"])));
521 ok
(run
(test
([@ssltest, "-bio_pair", "-tls1", "-alpn_client", "foo,bar", "-alpn_server", "foo", "-alpn_expected", "foo"])));
522 ok
(run
(test
([@ssltest, "-bio_pair", "-tls1", "-alpn_client", "bar,foo", "-alpn_server", "foo", "-alpn_expected", "foo"])));
523 ok
(run
(test
([@ssltest, "-bio_pair", "-tls1", "-alpn_client", "bar,foo", "-alpn_server", "foo,bar", "-alpn_expected", "foo"])));
524 ok
(run
(test
([@ssltest, "-bio_pair", "-tls1", "-alpn_client", "bar,foo", "-alpn_server", "bar,foo", "-alpn_expected", "bar"])));
525 ok
(run
(test
([@ssltest, "-bio_pair", "-tls1", "-alpn_client", "foo,bar", "-alpn_server", "bar,foo", "-alpn_expected", "bar"])));
526 ok
(run
(test
([@ssltest, "-bio_pair", "-tls1", "-alpn_client", "baz", "-alpn_server", "bar,foo"])));
530 skip
"skipping SRP tests", 4
533 ok
(run
(test
([@ssltest, "-tls1", "-cipher", "SRP", "-srpuser", "test", "-srppass", "abc123"])),
534 'test tls1 with SRP');
536 ok
(run
(test
([@ssltest, "-bio_pair", "-tls1", "-cipher", "SRP", "-srpuser", "test", "-srppass", "abc123"])),
537 'test tls1 with SRP via BIO pair');
539 ok
(run
(test
([@ssltest, "-tls1", "-cipher", "aSRP", "-srpuser", "test", "-srppass", "abc123"])),
540 'test tls1 with SRP auth');
542 ok
(run
(test
([@ssltest, "-bio_pair", "-tls1", "-cipher", "aSRP", "-srpuser", "test", "-srppass", "abc123"])),
543 'test tls1 with SRP auth via BIO pair');
548 subtest
'Multi-buffer tests' => sub {
549 ######################################################################
555 skip
"skipping multi-buffer tests", 2
556 if @extra || (POSIX
::uname
())[4] ne "x86_64";
557 ok
(run
(test
([@ssltest, "-cipher", "AES128-SHA", "-bytes", "8m"])));
558 ok
(run
(test
([@ssltest, "-cipher", "AES128-SHA256", "-bytes", "8m"])));
565 my $key = shift || top_file
("apps","server.pem");
566 my $cert = shift || top_file
("apps","server.pem");
568 my @CA = $CAtmp ?
("-CAfile", $CAtmp) : ("-CApath", top_dir
("certs"));
571 my @ssltest = ("ssltest",
572 "-s_key", $key, "-s_cert", $cert,
573 "-c_key", $key, "-c_cert", $cert);
577 note
('Testing a lot of proxy conditions.');
579 # We happen to know that certP1.ss has policy letters "AB" and
580 # certP2.ss has policy letters "BC". However, because certP2.ss
581 # has certP1.ss as issuer, when it's used, both their policy
582 # letters get combined into just "B".
583 # The policy letter(s) then get filtered with the given auth letter
584 # in the table below, and the result gets tested with the given
585 # condition. For details, read ssltest.c
587 # certfilename => [ [ auth, cond, expected result ] ... ]
588 my %expected = ( "certP1.ss" => [ [ [ 'A', 'A' ], 1 ],
591 [ [ 'A', 'A|B&!C' ], 1 ],
595 [ [ 'B', 'A|B&!C' ], 1 ],
599 [ [ 'C', 'A|B&!C' ], 0 ],
600 [ [ 'BC', 'A' ], 0 ],
601 [ [ 'BC', 'B' ], 1 ],
602 [ [ 'BC', 'C' ], 0 ],
603 [ [ 'BC', 'A|B&!C' ], 1 ] ],
604 "certP2.ss" => [ [ [ 'A', 'A' ], 0 ],
607 [ [ 'A', 'A|B&!C' ], 0 ],
611 [ [ 'B', 'A|B&!C' ], 1 ],
615 [ [ 'C', 'A|B&!C' ], 0 ],
616 [ [ 'BC', 'A' ], 0 ],
617 [ [ 'BC', 'B' ], 1 ],
618 [ [ 'BC', 'C' ], 0 ],
619 [ [ 'BC', 'A|B&!C' ], 1 ] ] );
621 foreach (@
{$expected{$cert}}) {
622 my $auth = $_->[0]->[0];
623 my $cond = $_->[0]->[1];
625 is
(run
(test
([@ssltest, "-ssl3", "-server_auth", @CA,
626 "-proxy", "-proxy_auth", $auth,
627 "-proxy_cond", $cond])), $res,
628 "test tlsv1, server auth, proxy auth $auth and cond $cond (expect "
629 .($res ?
"success" : "failure").")");