Travis: update sanitizer configs
[openssl.git] / test / recipes / 80-test_ssl_old.t
1 #! /usr/bin/env perl
2 # Copyright 2015-2016 The OpenSSL Project Authors. All Rights Reserved.
3 #
4 # Licensed under the OpenSSL license (the "License").  You may not use
5 # this file except in compliance with the License.  You can obtain a copy
6 # in the file LICENSE in the source distribution or at
7 # https://www.openssl.org/source/license.html
8
9
10 use strict;
11 use warnings;
12
13 use POSIX;
14 use File::Spec;
15 use File::Copy;
16 use OpenSSL::Test qw/:DEFAULT with bldtop_file srctop_file cmdstr/;
17 use OpenSSL::Test::Utils;
18
19 setup("test_ssl");
20
21 $ENV{CTLOG_FILE} = srctop_file("test", "ct", "log_list.conf");
22
23 my ($no_rsa, $no_dsa, $no_dh, $no_ec, $no_srp, $no_psk,
24     $no_ssl3, $no_tls1, $no_tls1_1, $no_tls1_2,
25     $no_dtls, $no_dtls1, $no_dtls1_2, $no_ct) =
26     anydisabled qw/rsa dsa dh ec srp psk
27                    ssl3 tls1 tls1_1 tls1_2
28                    dtls dtls1 dtls1_2 ct/;
29 my $no_anytls = alldisabled(available_protocols("tls"));
30 my $no_anydtls = alldisabled(available_protocols("dtls"));
31
32 plan skip_all => "No SSL/TLS/DTLS protocol is support by this OpenSSL build"
33     if $no_anytls && $no_anydtls;
34
35 my $digest = "-sha1";
36 my @reqcmd = ("openssl", "req");
37 my @x509cmd = ("openssl", "x509", $digest);
38 my @verifycmd = ("openssl", "verify");
39 my @gendsacmd = ("openssl", "gendsa");
40 my $dummycnf = srctop_file("apps", "openssl.cnf");
41
42 my $CAkey = "keyCA.ss";
43 my $CAcert="certCA.ss";
44 my $CAserial="certCA.srl";
45 my $CAreq="reqCA.ss";
46 my $CAconf=srctop_file("test","CAss.cnf");
47 my $CAreq2="req2CA.ss"; # temp
48
49 my $Uconf=srctop_file("test","Uss.cnf");
50 my $Ukey="keyU.ss";
51 my $Ureq="reqU.ss";
52 my $Ucert="certU.ss";
53
54 my $Dkey="keyD.ss";
55 my $Dreq="reqD.ss";
56 my $Dcert="certD.ss";
57
58 my $Ekey="keyE.ss";
59 my $Ereq="reqE.ss";
60 my $Ecert="certE.ss";
61
62 my $P1conf=srctop_file("test","P1ss.cnf");
63 my $P1key="keyP1.ss";
64 my $P1req="reqP1.ss";
65 my $P1cert="certP1.ss";
66 my $P1intermediate="tmp_intP1.ss";
67
68 my $P2conf=srctop_file("test","P2ss.cnf");
69 my $P2key="keyP2.ss";
70 my $P2req="reqP2.ss";
71 my $P2cert="certP2.ss";
72 my $P2intermediate="tmp_intP2.ss";
73
74 my $server_sess="server.ss";
75 my $client_sess="client.ss";
76
77 # ssltest_old.c is deprecated in favour of the new framework in ssl_test.c
78 # If you're adding tests here, you probably want to convert them to the
79 # new format in ssl_test.c and add recipes to 80-test_ssl_new.t instead.
80 plan tests =>
81     1                           # For testss
82     + 14                        # For the first testssl
83     ;
84
85 subtest 'test_ss' => sub {
86     if (testss()) {
87         open OUT, ">", "intP1.ss";
88         copy($CAcert, \*OUT); copy($Ucert, \*OUT);
89         close OUT;
90
91         open OUT, ">", "intP2.ss";
92         copy($CAcert, \*OUT); copy($Ucert, \*OUT); copy($P1cert, \*OUT);
93         close OUT;
94     }
95 };
96
97 note('test_ssl -- key U');
98 testssl("keyU.ss", $Ucert, $CAcert);
99
100 # -----------
101 # subtest functions
102 sub testss {
103     open RND, ">>", ".rnd";
104     print RND "string to make the random number generator think it has entropy";
105     close RND;
106
107     my @req_dsa = ("-newkey",
108                    "dsa:".srctop_file("apps", "dsa1024.pem"));
109     my $dsaparams = srctop_file("apps", "dsa1024.pem");
110     my @req_new;
111     if ($no_rsa) {
112         @req_new = @req_dsa;
113     } else {
114         @req_new = ("-new");
115     }
116
117     plan tests => 17;
118
119   SKIP: {
120       skip 'failure', 16 unless
121           ok(run(app([@reqcmd, "-config", $CAconf,
122                       "-out", $CAreq, "-keyout", $CAkey,
123                       @req_new])),
124              'make cert request');
125
126       skip 'failure', 15 unless
127           ok(run(app([@x509cmd, "-CAcreateserial", "-in", $CAreq, "-days", "30",
128                       "-req", "-out", $CAcert, "-signkey", $CAkey,
129                       "-extfile", $CAconf, "-extensions", "v3_ca"],
130                      stdout => "err.ss")),
131              'convert request into self-signed cert');
132
133       skip 'failure', 14 unless
134           ok(run(app([@x509cmd, "-in", $CAcert,
135                       "-x509toreq", "-signkey", $CAkey, "-out", $CAreq2],
136                      stdout => "err.ss")),
137              'convert cert into a cert request');
138
139       skip 'failure', 13 unless
140           ok(run(app([@reqcmd, "-config", $dummycnf,
141                       "-verify", "-in", $CAreq, "-noout"])),
142              'verify request 1');
143
144
145       skip 'failure', 12 unless
146           ok(run(app([@reqcmd, "-config", $dummycnf,
147                       "-verify", "-in", $CAreq2, "-noout"])),
148              'verify request 2');
149
150       skip 'failure', 11 unless
151           ok(run(app([@verifycmd, "-CAfile", $CAcert, $CAcert])),
152              'verify signature');
153
154       skip 'failure', 10 unless
155           ok(run(app([@reqcmd, "-config", $Uconf,
156                       "-out", $Ureq, "-keyout", $Ukey, @req_new],
157                      stdout => "err.ss")),
158              'make a user cert request');
159
160       skip 'failure', 9 unless
161           ok(run(app([@x509cmd, "-CAcreateserial", "-in", $Ureq, "-days", "30",
162                       "-req", "-out", $Ucert,
163                       "-CA", $CAcert, "-CAkey", $CAkey, "-CAserial", $CAserial,
164                       "-extfile", $Uconf, "-extensions", "v3_ee"],
165                      stdout => "err.ss"))
166              && run(app([@verifycmd, "-CAfile", $CAcert, $Ucert])),
167              'sign user cert request');
168
169       skip 'failure', 8 unless
170           ok(run(app([@x509cmd,
171                       "-subject", "-issuer", "-startdate", "-enddate",
172                       "-noout", "-in", $Ucert])),
173              'Certificate details');
174
175       skip 'failure', 7 unless
176           subtest 'DSA certificate creation' => sub {
177               plan skip_all => "skipping DSA certificate creation"
178                   if $no_dsa;
179
180               plan tests => 5;
181
182             SKIP: {
183                 $ENV{CN2} = "DSA Certificate";
184                 skip 'failure', 4 unless
185                     ok(run(app([@gendsacmd, "-out", $Dkey,
186                                 $dsaparams],
187                                stdout => "err.ss")),
188                        "make a DSA key");
189                 skip 'failure', 3 unless
190                     ok(run(app([@reqcmd, "-new", "-config", $Uconf,
191                                 "-out", $Dreq, "-key", $Dkey],
192                                stdout => "err.ss")),
193                        "make a DSA user cert request");
194                 skip 'failure', 2 unless
195                     ok(run(app([@x509cmd, "-CAcreateserial",
196                                 "-in", $Dreq,
197                                 "-days", "30",
198                                 "-req",
199                                 "-out", $Dcert,
200                                 "-CA", $CAcert, "-CAkey", $CAkey,
201                                 "-CAserial", $CAserial,
202                                 "-extfile", $Uconf,
203                                 "-extensions", "v3_ee_dsa"],
204                                stdout => "err.ss")),
205                        "sign DSA user cert request");
206                 skip 'failure', 1 unless
207                     ok(run(app([@verifycmd, "-CAfile", $CAcert, $Dcert])),
208                        "verify DSA user cert");
209                 skip 'failure', 0 unless
210                     ok(run(app([@x509cmd,
211                                 "-subject", "-issuer",
212                                 "-startdate", "-enddate", "-noout",
213                                 "-in", $Dcert])),
214                        "DSA Certificate details");
215               }
216       };
217
218       skip 'failure', 6 unless
219           subtest 'ECDSA/ECDH certificate creation' => sub {
220               plan skip_all => "skipping ECDSA/ECDH certificate creation"
221                   if $no_ec;
222
223               plan tests => 5;
224
225             SKIP: {
226                 $ENV{CN2} = "ECDSA Certificate";
227                 skip 'failure', 4 unless
228                     ok(run(app(["openssl", "ecparam", "-name", "P-256",
229                                 "-out", "ecp.ss"])),
230                        "make EC parameters");
231                 skip 'failure', 3 unless
232                     ok(run(app([@reqcmd, "-config", $Uconf,
233                                 "-out", $Ereq, "-keyout", $Ekey,
234                                 "-newkey", "ec:ecp.ss"],
235                                stdout => "err.ss")),
236                        "make a ECDSA/ECDH user cert request");
237                 skip 'failure', 2 unless
238                     ok(run(app([@x509cmd, "-CAcreateserial",
239                                 "-in", $Ereq,
240                                 "-days", "30",
241                                 "-req",
242                                 "-out", $Ecert,
243                                 "-CA", $CAcert, "-CAkey", $CAkey,
244                                 "-CAserial", $CAserial,
245                                 "-extfile", $Uconf,
246                                 "-extensions", "v3_ee_ec"],
247                                stdout => "err.ss")),
248                        "sign ECDSA/ECDH user cert request");
249                 skip 'failure', 1 unless
250                     ok(run(app([@verifycmd, "-CAfile", $CAcert, $Ecert])),
251                        "verify ECDSA/ECDH user cert");
252                 skip 'failure', 0 unless
253                     ok(run(app([@x509cmd,
254                                 "-subject", "-issuer",
255                                 "-startdate", "-enddate", "-noout",
256                                 "-in", $Ecert])),
257                        "ECDSA Certificate details");
258               }
259       };
260
261       skip 'failure', 5 unless
262           ok(run(app([@reqcmd, "-config", $P1conf,
263                       "-out", $P1req, "-keyout", $P1key, @req_new],
264                      stdout => "err.ss")),
265              'make a proxy cert request');
266
267
268       skip 'failure', 4 unless
269           ok(run(app([@x509cmd, "-CAcreateserial", "-in", $P1req, "-days", "30",
270                       "-req", "-out", $P1cert,
271                       "-CA", $Ucert, "-CAkey", $Ukey,
272                       "-extfile", $P1conf, "-extensions", "v3_proxy"],
273                      stdout => "err.ss")),
274              'sign proxy with user cert');
275
276       copy($Ucert, $P1intermediate);
277       run(app([@verifycmd, "-CAfile", $CAcert,
278                "-untrusted", $P1intermediate, $P1cert]));
279       ok(run(app([@x509cmd,
280                   "-subject", "-issuer", "-startdate", "-enddate",
281                   "-noout", "-in", $P1cert])),
282          'Certificate details');
283
284       skip 'failure', 2 unless
285           ok(run(app([@reqcmd, "-config", $P2conf,
286                       "-out", $P2req, "-keyout", $P2key,
287                       @req_new],
288                      stdout => "err.ss")),
289              'make another proxy cert request');
290
291
292       skip 'failure', 1 unless
293           ok(run(app([@x509cmd, "-CAcreateserial", "-in", $P2req, "-days", "30",
294                       "-req", "-out", $P2cert,
295                       "-CA", $P1cert, "-CAkey", $P1key,
296                       "-extfile", $P2conf, "-extensions", "v3_proxy"],
297                      stdout => "err.ss")),
298              'sign second proxy cert request with the first proxy cert');
299
300
301       open OUT, ">", $P2intermediate;
302       copy($Ucert, \*OUT); copy($P1cert, \*OUT);
303       close OUT;
304       run(app([@verifycmd, "-CAfile", $CAcert,
305                "-untrusted", $P2intermediate, $P2cert]));
306       ok(run(app([@x509cmd,
307                   "-subject", "-issuer", "-startdate", "-enddate",
308                   "-noout", "-in", $P2cert])),
309          'Certificate details');
310     }
311 }
312
313 sub testssl {
314     my $key = shift || bldtop_file("apps","server.pem");
315     my $cert = shift || bldtop_file("apps","server.pem");
316     my $CAtmp = shift;
317     my @CA = $CAtmp ? ("-CAfile", $CAtmp) : ("-CApath", bldtop_dir("certs"));
318     my @extra = @_;
319
320     my @ssltest = ("ssltest_old",
321                    "-s_key", $key, "-s_cert", $cert,
322                    "-c_key", $key, "-c_cert", $cert);
323
324     my $serverinfo = srctop_file("test","serverinfo.pem");
325
326     my $dsa_cert = 0;
327     if (grep /DSA Public Key/, run(app(["openssl", "x509", "-in", $cert,
328                                         "-text", "-noout"]), capture => 1)) {
329         $dsa_cert = 1;
330     }
331
332
333     # plan tests => 11;
334
335     subtest 'standard SSL tests' => sub {
336         ######################################################################
337         plan tests => 29;
338
339       SKIP: {
340           skip "SSLv3 is not supported by this OpenSSL build", 4
341               if disabled("ssl3");
342
343           ok(run(test([@ssltest, "-ssl3", @extra])),
344              'test sslv3');
345           ok(run(test([@ssltest, "-ssl3", "-server_auth", @CA, @extra])),
346              'test sslv3 with server authentication');
347           ok(run(test([@ssltest, "-ssl3", "-client_auth", @CA, @extra])),
348              'test sslv3 with client authentication');
349           ok(run(test([@ssltest, "-ssl3", "-server_auth", "-client_auth", @CA, @extra])),
350              'test sslv3 with both server and client authentication');
351         }
352
353       SKIP: {
354           skip "Neither SSLv3 nor any TLS version are supported by this OpenSSL build", 4
355               if $no_anytls;
356
357           ok(run(test([@ssltest, @extra])),
358              'test sslv2/sslv3');
359           ok(run(test([@ssltest, "-server_auth", @CA, @extra])),
360              'test sslv2/sslv3 with server authentication');
361           ok(run(test([@ssltest, "-client_auth", @CA, @extra])),
362              'test sslv2/sslv3 with client authentication');
363           ok(run(test([@ssltest, "-server_auth", "-client_auth", @CA, @extra])),
364              'test sslv2/sslv3 with both server and client authentication');
365         }
366
367       SKIP: {
368           skip "SSLv3 is not supported by this OpenSSL build", 4
369               if disabled("ssl3");
370
371           ok(run(test([@ssltest, "-bio_pair", "-ssl3", @extra])),
372              'test sslv3 via BIO pair');
373           ok(run(test([@ssltest, "-bio_pair", "-ssl3", "-server_auth", @CA, @extra])),
374              'test sslv3 with server authentication via BIO pair');
375           ok(run(test([@ssltest, "-bio_pair", "-ssl3", "-client_auth", @CA, @extra])),
376              'test sslv3 with client authentication via BIO pair');
377           ok(run(test([@ssltest, "-bio_pair", "-ssl3", "-server_auth", "-client_auth", @CA, @extra])),
378              'test sslv3 with both server and client authentication via BIO pair');
379         }
380
381       SKIP: {
382           skip "Neither SSLv3 nor any TLS version are supported by this OpenSSL build", 1
383               if $no_anytls;
384
385           ok(run(test([@ssltest, "-bio_pair", @extra])),
386              'test sslv2/sslv3 via BIO pair');
387         }
388
389       SKIP: {
390           skip "DTLSv1 is not supported by this OpenSSL build", 4
391               if disabled("dtls1");
392
393           ok(run(test([@ssltest, "-dtls1", @extra])),
394              'test dtlsv1');
395           ok(run(test([@ssltest, "-dtls1", "-server_auth", @CA, @extra])),
396            'test dtlsv1 with server authentication');
397           ok(run(test([@ssltest, "-dtls1", "-client_auth", @CA, @extra])),
398              'test dtlsv1 with client authentication');
399           ok(run(test([@ssltest, "-dtls1", "-server_auth", "-client_auth", @CA, @extra])),
400              'test dtlsv1 with both server and client authentication');
401         }
402
403       SKIP: {
404           skip "DTLSv1.2 is not supported by this OpenSSL build", 4
405               if disabled("dtls1_2");
406
407           ok(run(test([@ssltest, "-dtls12", @extra])),
408              'test dtlsv1.2');
409           ok(run(test([@ssltest, "-dtls12", "-server_auth", @CA, @extra])),
410              'test dtlsv1.2 with server authentication');
411           ok(run(test([@ssltest, "-dtls12", "-client_auth", @CA, @extra])),
412              'test dtlsv1.2 with client authentication');
413           ok(run(test([@ssltest, "-dtls12", "-server_auth", "-client_auth", @CA, @extra])),
414              'test dtlsv1.2 with both server and client authentication');
415         }
416
417       SKIP: {
418           skip "Neither SSLv3 nor any TLS version are supported by this OpenSSL build", 8
419               if $no_anytls;
420
421         SKIP: {
422             skip "skipping test of sslv2/sslv3 w/o (EC)DHE test", 1 if $dsa_cert;
423
424             ok(run(test([@ssltest, "-bio_pair", "-no_dhe", "-no_ecdhe", @extra])),
425                'test sslv2/sslv3 w/o (EC)DHE via BIO pair');
426           }
427
428           ok(run(test([@ssltest, "-bio_pair", "-dhe1024dsa", "-v", @extra])),
429              'test sslv2/sslv3 with 1024bit DHE via BIO pair');
430           ok(run(test([@ssltest, "-bio_pair", "-server_auth", @CA, @extra])),
431              'test sslv2/sslv3 with server authentication');
432           ok(run(test([@ssltest, "-bio_pair", "-client_auth", @CA, @extra])),
433              'test sslv2/sslv3 with client authentication via BIO pair');
434           ok(run(test([@ssltest, "-bio_pair", "-server_auth", "-client_auth", @CA, @extra])),
435              'test sslv2/sslv3 with both client and server authentication via BIO pair');
436           ok(run(test([@ssltest, "-bio_pair", "-server_auth", "-client_auth", "-app_verify", @CA, @extra])),
437              'test sslv2/sslv3 with both client and server authentication via BIO pair and app verify');
438
439         SKIP: {
440             skip "No IPv4 available on this machine", 1
441                 unless !disabled("sock") && have_IPv4();
442             ok(run(test([@ssltest, "-ipv4", @extra])),
443                'test TLS via IPv4');
444           }
445
446         SKIP: {
447             skip "No IPv6 available on this machine", 1
448                 unless !disabled("sock") && have_IPv6();
449             ok(run(test([@ssltest, "-ipv6", @extra])),
450                'test TLS via IPv6');
451           }
452         }
453     };
454
455     subtest "Testing ciphersuites" => sub {
456
457         my @exkeys = ();
458         my $ciphers = "-EXP:-PSK:-SRP:-kDH:-kECDHe";
459
460         if ($no_dh) {
461             note "skipping DHE tests\n";
462             $ciphers .= ":-kDHE";
463         }
464         if ($no_dsa) {
465             note "skipping DSA tests\n";
466             $ciphers .= ":-aDSA";
467         } else {
468             push @exkeys, "-s_cert", "certD.ss", "-s_key", "keyD.ss";
469         }
470
471         if ($no_ec) {
472             note "skipping EC tests\n";
473             $ciphers .= ":!aECDSA:!kECDH";
474         } else {
475             push @exkeys, "-s_cert", "certE.ss", "-s_key", "keyE.ss";
476         }
477
478         my @protocols = ();
479         # FIXME: I feel unsure about the following line, is that really just TLSv1.2, or is it all of the SSLv3/TLS protocols?
480         push(@protocols, "TLSv1.2") unless $no_tls1_2;
481         push(@protocols, "SSLv3") unless $no_ssl3;
482         my $protocolciphersuitcount = 0;
483         my %ciphersuites =
484             map { my @c =
485                       map { split(/:/, $_) }
486                       run(app(["openssl", "ciphers", "${_}:$ciphers"]),
487                           capture => 1);
488                   map { s/\R//; } @c;  # chomp @c;
489                   $protocolciphersuitcount += scalar @c;
490                   $_ => [ @c ] } @protocols;
491
492         plan skip_all => "None of the ciphersuites to test are available in this OpenSSL build"
493             if $protocolciphersuitcount + scalar(@protocols) == 0;
494
495         # The count of protocols is because in addition to the ciphersuits
496         # we got above, we're running a weak DH test for each protocol
497         plan tests => $protocolciphersuitcount + scalar(@protocols);
498
499         foreach my $protocol (@protocols) {
500             note "Testing ciphersuites for $protocol";
501             foreach my $cipher (@{$ciphersuites{$protocol}}) {
502                 ok(run(test([@ssltest, @exkeys, "-cipher", $cipher,
503                              $protocol eq "SSLv3" ? ("-ssl3") : ()])),
504                    "Testing $cipher");
505             }
506             is(run(test([@ssltest,
507                          "-s_cipher", "EDH",
508                          "-c_cipher", 'EDH:@SECLEVEL=1',
509                          "-dhe512",
510                          $protocol eq "SSLv3" ? ("-ssl3") : ()])), 0,
511                "testing connection with weak DH, expecting failure");
512         }
513     };
514
515     subtest 'RSA/(EC)DHE/PSK tests' => sub {
516         ######################################################################
517
518         plan tests => 5;
519
520       SKIP: {
521           skip "TLSv1.0 is not supported by this OpenSSL build", 5
522               if $no_tls1;
523
524         SKIP: {
525             skip "skipping anonymous DH tests", 1
526               if ($no_dh);
527
528             ok(run(test([@ssltest, "-v", "-bio_pair", "-tls1", "-cipher", "ADH", "-dhe1024dsa", "-num", "10", "-f", "-time", @extra])),
529                'test tlsv1 with 1024bit anonymous DH, multiple handshakes');
530           }
531
532         SKIP: {
533             skip "skipping RSA tests", 2
534                 if $no_rsa;
535
536             ok(run(test(["ssltest_old", "-v", "-bio_pair", "-tls1", "-s_cert", srctop_file("apps","server2.pem"), "-no_dhe", "-no_ecdhe", "-num", "10", "-f", "-time", @extra])),
537                'test tlsv1 with 1024bit RSA, no (EC)DHE, multiple handshakes');
538
539             skip "skipping RSA+DHE tests", 1
540                 if $no_dh;
541
542             ok(run(test(["ssltest_old", "-v", "-bio_pair", "-tls1", "-s_cert", srctop_file("apps","server2.pem"), "-dhe1024dsa", "-num", "10", "-f", "-time", @extra])),
543                'test tlsv1 with 1024bit RSA, 1024bit DHE, multiple handshakes');
544           }
545
546         SKIP: {
547             skip "skipping PSK tests", 2
548                 if ($no_psk);
549
550             ok(run(test([@ssltest, "-tls1", "-cipher", "PSK", "-psk", "abc123", @extra])),
551                'test tls1 with PSK');
552
553             ok(run(test([@ssltest, "-bio_pair", "-tls1", "-cipher", "PSK", "-psk", "abc123", @extra])),
554                'test tls1 with PSK via BIO pair');
555           }
556         }
557
558     };
559
560     subtest 'Next Protocol Negotiation Tests' => sub {
561         ######################################################################
562
563         plan tests => 7;
564
565       SKIP: {
566           skip "TLSv1.0 is not supported by this OpenSSL build", 7
567               if $no_tls1;
568           skip "Next Protocol Negotiation is not supported by this OpenSSL build", 7
569               if disabled("nextprotoneg");
570
571           ok(run(test([@ssltest, "-bio_pair", "-tls1", "-npn_client"])));
572           ok(run(test([@ssltest, "-bio_pair", "-tls1", "-npn_server"])));
573           ok(run(test([@ssltest, "-bio_pair", "-tls1", "-npn_server_reject"])));
574           ok(run(test([@ssltest, "-bio_pair", "-tls1", "-npn_client", "-npn_server_reject"])));
575           ok(run(test([@ssltest, "-bio_pair", "-tls1", "-npn_client", "-npn_server"])));
576           ok(run(test([@ssltest, "-bio_pair", "-tls1", "-npn_client", "-npn_server", "-num", "2"])));
577           ok(run(test([@ssltest, "-bio_pair", "-tls1", "-npn_client", "-npn_server", "-num", "2", "-reuse"])));
578         }
579     };
580
581     subtest 'Custom Extension tests' => sub {
582         ######################################################################
583
584         plan tests => 1;
585
586       SKIP: {
587           skip "TLSv1.0 is not supported by this OpenSSL build", 1
588               if $no_tls1;
589
590           ok(run(test([@ssltest, "-bio_pair", "-tls1", "-custom_ext"])),
591              'test tls1 with custom extensions');
592         }
593     };
594
595     subtest 'Serverinfo tests' => sub {
596         ######################################################################
597
598         plan tests => 5;
599
600       SKIP: {
601           skip "TLSv1.0 is not supported by this OpenSSL build", 5
602               if $no_tls1;
603
604           note('echo test tls1 with serverinfo');
605           ok(run(test([@ssltest, "-bio_pair", "-tls1", "-serverinfo_file", $serverinfo])));
606           ok(run(test([@ssltest, "-bio_pair", "-tls1", "-serverinfo_file", $serverinfo, "-serverinfo_sct"])));
607           ok(run(test([@ssltest, "-bio_pair", "-tls1", "-serverinfo_file", $serverinfo, "-serverinfo_tack"])));
608           ok(run(test([@ssltest, "-bio_pair", "-tls1", "-serverinfo_file", $serverinfo, "-serverinfo_sct", "-serverinfo_tack"])));
609           ok(run(test([@ssltest, "-bio_pair", "-tls1", "-custom_ext", "-serverinfo_file", $serverinfo, "-serverinfo_sct", "-serverinfo_tack"])));
610         }
611     };
612
613     subtest 'SNI tests' => sub {
614
615         plan tests => 7;
616
617       SKIP: {
618           skip "TLSv1.x is not supported by this OpenSSL build", 7
619               if $no_tls1 && $no_tls1_1 && $no_tls1_2;
620
621           ok(run(test([@ssltest, "-bio_pair", "-sn_client", "foo"])));
622           ok(run(test([@ssltest, "-bio_pair", "-sn_server1", "foo"])));
623           ok(run(test([@ssltest, "-bio_pair", "-sn_client", "foo", "-sn_server1", "foo", "-sn_expect1"])));
624           ok(run(test([@ssltest, "-bio_pair", "-sn_client", "foo", "-sn_server1", "bar", "-sn_expect1"])));
625           ok(run(test([@ssltest, "-bio_pair", "-sn_client", "foo", "-sn_server1", "foo", "-sn_server2", "bar", "-sn_expect1"])));
626           ok(run(test([@ssltest, "-bio_pair", "-sn_client", "bar", "-sn_server1", "foo", "-sn_server2", "bar", "-sn_expect2"])));
627           # Negative test - make sure it doesn't crash, and doesn't switch contexts
628           ok(run(test([@ssltest, "-bio_pair", "-sn_client", "foobar", "-sn_server1", "foo", "-sn_server2", "bar", "-sn_expect1"])));
629         }
630     };
631
632     subtest 'ALPN tests' => sub {
633         ######################################################################
634
635         plan tests => 13;
636
637       SKIP: {
638           skip "TLSv1.0 is not supported by this OpenSSL build", 13
639               if $no_tls1;
640
641           ok(run(test([@ssltest, "-bio_pair", "-tls1", "-alpn_client", "foo"])));
642           ok(run(test([@ssltest, "-bio_pair", "-tls1", "-alpn_server", "foo"])));
643           ok(run(test([@ssltest, "-bio_pair", "-tls1", "-alpn_client", "foo", "-alpn_server", "foo", "-alpn_expected", "foo"])));
644           ok(run(test([@ssltest, "-bio_pair", "-tls1", "-alpn_client", "foo,bar", "-alpn_server", "foo", "-alpn_expected", "foo"])));
645           ok(run(test([@ssltest, "-bio_pair", "-tls1", "-alpn_client", "bar,foo", "-alpn_server", "foo", "-alpn_expected", "foo"])));
646           ok(run(test([@ssltest, "-bio_pair", "-tls1", "-alpn_client", "bar,foo", "-alpn_server", "foo,bar", "-alpn_expected", "foo"])));
647           ok(run(test([@ssltest, "-bio_pair", "-tls1", "-alpn_client", "bar,foo", "-alpn_server", "bar,foo", "-alpn_expected", "bar"])));
648           ok(run(test([@ssltest, "-bio_pair", "-tls1", "-alpn_client", "foo,bar", "-alpn_server", "bar,foo", "-alpn_expected", "bar"])));
649
650           is(run(test([@ssltest, "-bio_pair", "-tls1", "-alpn_client", "foo", "-alpn_server", "bar"])), 0,
651              "Testing ALPN with protocol mismatch, expecting failure");
652           is(run(test([@ssltest, "-bio_pair", "-tls1", "-alpn_client", "baz", "-alpn_server", "bar,foo"])), 0,
653              "Testing ALPN with protocol mismatch, expecting failure");
654
655           # ALPN + SNI
656           ok(run(test([@ssltest, "-bio_pair",
657                        "-alpn_client", "foo,bar", "-sn_client", "alice",
658                        "-alpn_server1", "foo,123", "-sn_server1", "alice",
659                        "-alpn_server2", "bar,456", "-sn_server2", "bob",
660                        "-alpn_expected", "foo"])));
661           ok(run(test([@ssltest, "-bio_pair",
662                        "-alpn_client", "foo,bar", "-sn_client", "bob",
663                        "-alpn_server1", "foo,123", "-sn_server1", "alice",
664                        "-alpn_server2", "bar,456", "-sn_server2", "bob",
665                        "-alpn_expected", "bar"])));
666           ok(run(test([@ssltest, "-bio_pair",
667                        "-alpn_client", "foo,bar", "-sn_client", "bob",
668                        "-alpn_server2", "bar,456", "-sn_server2", "bob",
669                        "-alpn_expected", "bar"])));
670         }
671     };
672
673     subtest 'SRP tests' => sub {
674
675         plan tests => 4;
676
677       SKIP: {
678           skip "skipping SRP tests", 4
679               if $no_srp;
680
681           ok(run(test([@ssltest, "-tls1", "-cipher", "SRP", "-srpuser", "test", "-srppass", "abc123"])),
682              'test tls1 with SRP');
683
684           ok(run(test([@ssltest, "-bio_pair", "-tls1", "-cipher", "SRP", "-srpuser", "test", "-srppass", "abc123"])),
685              'test tls1 with SRP via BIO pair');
686
687           ok(run(test([@ssltest, "-tls1", "-cipher", "aSRP", "-srpuser", "test", "-srppass", "abc123"])),
688              'test tls1 with SRP auth');
689
690           ok(run(test([@ssltest, "-bio_pair", "-tls1", "-cipher", "aSRP", "-srpuser", "test", "-srppass", "abc123"])),
691              'test tls1 with SRP auth via BIO pair');
692         }
693     };
694
695     subtest 'Multi-buffer tests' => sub {
696         ######################################################################
697
698         plan tests => 2;
699
700       SKIP: {
701           skip "Neither SSLv3 nor any TLS version are supported by this OpenSSL build", 2
702               if $no_anytls;
703
704           skip "skipping multi-buffer tests", 2
705               if @extra || (POSIX::uname())[4] ne "x86_64";
706
707           ok(run(test([@ssltest, "-cipher", "AES128-SHA",    "-bytes", "8m"])));
708
709           # We happen to know that AES128-SHA256 is TLSv1.2 only... for now.
710           skip "TLSv1.2 is not supported by this OpenSSL configuration", 1
711               if $no_tls1_2;
712
713           ok(run(test([@ssltest, "-cipher", "AES128-SHA256", "-bytes", "8m"])));
714         }
715     };
716
717     subtest 'DTLS Version min/max tests' => sub {
718         my @protos;
719         push(@protos, "dtls1") unless ($no_dtls1 || $no_dtls);
720         push(@protos, "dtls1.2") unless ($no_dtls1_2 || $no_dtls);
721         my @minprotos = (undef, @protos);
722         my @maxprotos = (@protos, undef);
723         my @shdprotos = (@protos, $protos[$#protos]);
724         my $n = ((@protos+2) * (@protos+3))/2 - 2;
725         my $ntests = $n * $n;
726         plan tests => $ntests;
727       SKIP: {
728         skip "DTLS disabled", 1 if $ntests == 1;
729
730         my $should;
731         for (my $smin = 0; $smin < @minprotos; ++$smin) {
732         for (my $smax = $smin ? $smin - 1 : 0; $smax < @maxprotos; ++$smax) {
733         for (my $cmin = 0; $cmin < @minprotos; ++$cmin) {
734         for (my $cmax = $cmin ? $cmin - 1 : 0; $cmax < @maxprotos; ++$cmax) {
735             if ($cmax < $smin-1) {
736                 $should = "fail-server";
737             } elsif ($smax < $cmin-1) {
738                 $should = "fail-client";
739             } elsif ($cmax > $smax) {
740                 $should = $shdprotos[$smax];
741             } else {
742                 $should = $shdprotos[$cmax];
743             }
744
745             my @args = (@ssltest, "-dtls");
746             push(@args, "-should_negotiate", $should);
747             push(@args, "-server_min_proto", $minprotos[$smin])
748                 if (defined($minprotos[$smin]));
749             push(@args, "-server_max_proto", $maxprotos[$smax])
750                 if (defined($maxprotos[$smax]));
751             push(@args, "-client_min_proto", $minprotos[$cmin])
752                 if (defined($minprotos[$cmin]));
753             push(@args, "-client_max_proto", $maxprotos[$cmax])
754                 if (defined($maxprotos[$cmax]));
755             my $ok = run(test[@args]);
756             if (! $ok) {
757                 print STDERR "\nsmin=$smin, smax=$smax, cmin=$cmin, cmax=$cmax\n";
758                 print STDERR "\nFailed: @args\n";
759             }
760             ok($ok);
761         }}}}}
762     };
763
764     subtest 'TLS session reuse' => sub {
765         plan tests => 12;
766
767         SKIP: {
768             skip "TLS1.1 or TLS1.2 disabled", 12 if $no_tls1_1 || $no_tls1_2;
769             ok(run(test([@ssltest, "-server_sess_out", $server_sess, "-client_sess_out", $client_sess])));
770             ok(run(test([@ssltest, "-server_sess_in", $server_sess, "-client_sess_in", $client_sess, "-should_reuse", "1", "-should_negotiate", "tls1.2"])));
771             ok(run(test([@ssltest, "-server_max_proto", "tls1.1", "-server_sess_in", $server_sess, "-client_sess_in", $client_sess, "-should_reuse", "0", "-should_negotiate", "tls1.1"])));
772
773             ok(run(test([@ssltest, "-server_max_proto", "tls1.1", "-server_sess_out", $server_sess, "-client_sess_out", $client_sess])));
774             ok(run(test([@ssltest, "-server_max_proto", "tls1.1", "-server_sess_in", $server_sess, "-client_sess_in", $client_sess, "-should_reuse", "1", "-should_negotiate", "tls1.1"])));
775             ok(run(test([@ssltest, "-server_sess_in", $server_sess, "-client_sess_in", $client_sess, "-should_reuse", "0", "-should_negotiate", "tls1.2"])));
776
777             ok(run(test([@ssltest, "-no_ticket", "-server_sess_out", $server_sess, "-client_sess_out", $client_sess])));
778             ok(run(test([@ssltest, "-no_ticket", "-server_sess_in", $server_sess, "-client_sess_in", $client_sess, "-should_reuse", "1", "-should_negotiate", "tls1.2"])));
779             ok(run(test([@ssltest, "-no_ticket", "-server_max_proto", "tls1.1", "-server_sess_in", $server_sess, "-client_sess_in", $client_sess, "-should_reuse", "0", "-should_negotiate", "tls1.1"])));
780
781             ok(run(test([@ssltest, "-no_ticket", "-server_max_proto", "tls1.1", "-server_sess_out", $server_sess, "-client_sess_out", $client_sess])));
782             ok(run(test([@ssltest, "-no_ticket", "-server_max_proto", "tls1.1", "-server_sess_in", $server_sess, "-client_sess_in", $client_sess, "-should_reuse", "1", "-should_negotiate", "tls1.1"])));
783             ok(run(test([@ssltest, "-no_ticket", "-server_sess_in", $server_sess, "-client_sess_in", $client_sess, "-should_reuse", "0", "-should_negotiate", "tls1.2"])));
784         }
785     };
786
787     subtest 'DTLS session reuse' => sub {
788         plan tests => 12;
789       SKIP: {
790         skip "DTLS disabled", 12 if $no_dtls;
791
792         ok(run(test([@ssltest, "-dtls", "-server_sess_out", $server_sess, "-client_sess_out", $client_sess])));
793         ok(run(test([@ssltest, "-dtls", "-server_sess_in", $server_sess, "-client_sess_in", $client_sess, "-should_reuse", "1", "-should_negotiate", "dtls1.2"])));
794         ok(run(test([@ssltest, "-dtls", "-server_max_proto", "dtls1", "-server_sess_in", $server_sess, "-client_sess_in", $client_sess, "-should_reuse", "0", "-should_negotiate", "dtls1"])));
795
796         ok(run(test([@ssltest, "-dtls", "-server_max_proto", "dtls1", "-server_sess_out", $server_sess, "-client_sess_out", $client_sess])));
797         ok(run(test([@ssltest, "-dtls", "-server_max_proto", "dtls1", "-server_sess_in", $server_sess, "-client_sess_in", $client_sess, "-should_reuse", "1", "-should_negotiate", "dtls1"])));
798         ok(run(test([@ssltest, "-dtls", "-server_sess_in", $server_sess, "-client_sess_in", $client_sess, "-should_reuse", "0", "-should_negotiate", "dtls1.2"])));
799
800         ok(run(test([@ssltest, "-dtls", "-no_ticket", "-server_sess_out", $server_sess, "-client_sess_out", $client_sess])));
801         ok(run(test([@ssltest, "-dtls", "-no_ticket", "-server_sess_in", $server_sess, "-client_sess_in", $client_sess, "-should_reuse", "1", "-should_negotiate", "dtls1.2"])));
802         ok(run(test([@ssltest, "-dtls", "-no_ticket", "-server_max_proto", "dtls1", "-server_sess_in", $server_sess, "-client_sess_in", $client_sess, "-should_reuse", "0", "-should_negotiate", "dtls1"])));
803
804         ok(run(test([@ssltest, "-dtls", "-no_ticket", "-server_max_proto", "dtls1", "-server_sess_out", $server_sess, "-client_sess_out", $client_sess])));
805         ok(run(test([@ssltest, "-dtls", "-no_ticket", "-server_max_proto", "dtls1", "-server_sess_in", $server_sess, "-client_sess_in", $client_sess, "-should_reuse", "1", "-should_negotiate", "dtls1"])));
806         ok(run(test([@ssltest, "-dtls", "-no_ticket", "-server_sess_in", $server_sess, "-client_sess_in", $client_sess, "-should_reuse", "0", "-should_negotiate", "dtls1.2"])));
807         }
808     };
809
810     subtest 'Certificate Transparency tests' => sub {
811         ######################################################################
812
813         plan tests => 3;
814
815       SKIP: {
816         skip "Certificate Transparency is not supported by this OpenSSL build", 3
817             if $no_ct;
818         skip "TLSv1.0 is not supported by this OpenSSL build", 3
819             if $no_tls1;
820
821         $ENV{CTLOG_FILE} = srctop_file("test", "ct", "log_list.conf");
822         my @ca = qw(-CAfile certCA.ss);
823         ok(run(test([@ssltest, @ca, "-bio_pair", "-tls1", "-noct"])));
824         # No SCTs provided, so this should fail.
825         ok(run(test([@ssltest, @ca, "-bio_pair", "-tls1", "-ct",
826                      "-should_negotiate", "fail-client"])));
827         # No SCTs provided, unverified chains still succeed.
828         ok(run(test([@ssltest, "-bio_pair", "-tls1", "-ct"])));
829         }
830     };
831 }