Suppress CT warnings in test_ssl
[openssl.git] / test / recipes / 80-test_ssl.t
index d0bb79a8d37435da43d5262bda67e31e1ad33594..ba57695b22f32314ce00955764365993dd9f0704 100644 (file)
@@ -6,17 +6,19 @@ use warnings;
 use POSIX;
 use File::Spec;
 use File::Copy;
-use OpenSSL::Test qw/:DEFAULT with top_file cmdstr/;
+use OpenSSL::Test qw/:DEFAULT with bldtop_file srctop_file cmdstr/;
 use OpenSSL::Test::Utils;
 
 setup("test_ssl");
 
+$ENV{CTLOG_FILE} = srctop_file("test", "ct", "log_list.conf");
+
 my ($no_rsa, $no_dsa, $no_dh, $no_ec, $no_srp, $no_psk,
     $no_ssl3, $no_tls1, $no_tls1_1, $no_tls1_2,
-    $no_dtls, $no_dtls1, $no_dtls1_2) =
+    $no_dtls, $no_dtls1, $no_dtls1_2, $no_ct) =
     anydisabled qw/rsa dsa dh ec srp psk
                    ssl3 tls1 tls1_1 tls1_2
-                   dtls dtls1 dtls1_2/;
+                   dtls dtls1 dtls1_2 ct/;
 my $no_anytls = alldisabled(available_protocols("tls"));
 my $no_anydtls = alldisabled(available_protocols("dtls"));
 
@@ -27,16 +29,16 @@ my $digest = "-sha1";
 my @reqcmd = ("openssl", "req");
 my @x509cmd = ("openssl", "x509", $digest);
 my @verifycmd = ("openssl", "verify");
-my $dummycnf = top_file("apps", "openssl.cnf");
+my $dummycnf = srctop_file("apps", "openssl.cnf");
 
 my $CAkey = "keyCA.ss";
 my $CAcert="certCA.ss";
 my $CAserial="certCA.srl";
 my $CAreq="reqCA.ss";
-my $CAconf=top_file("test","CAss.cnf");
+my $CAconf=srctop_file("test","CAss.cnf");
 my $CAreq2="req2CA.ss";        # temp
 
-my $Uconf=top_file("test","Uss.cnf");
+my $Uconf=srctop_file("test","Uss.cnf");
 my $Ukey="keyU.ss";
 my $Ureq="reqU.ss";
 my $Ucert="certU.ss";
@@ -49,13 +51,13 @@ my $Ekey="keyE.ss";
 my $Ereq="reqE.ss";
 my $Ecert="certE.ss";
 
-my $P1conf=top_file("test","P1ss.cnf");
+my $P1conf=srctop_file("test","P1ss.cnf");
 my $P1key="keyP1.ss";
 my $P1req="reqP1.ss";
 my $P1cert="certP1.ss";
 my $P1intermediate="tmp_intP1.ss";
 
-my $P2conf=top_file("test","P2ss.cnf");
+my $P2conf=srctop_file("test","P2ss.cnf");
 my $P2key="keyP2.ss";
 my $P2req="reqP2.ss";
 my $P2cert="certP2.ss";
@@ -64,7 +66,7 @@ my $P2intermediate="tmp_intP2.ss";
 plan tests =>
     1                          # For testss
     + 1                                # For ssltest -test_cipherlist
-    + 10                       # For the first testssl
+    + 13                       # For the first testssl
     + 16                       # For the first testsslproxy
     + 16                       # For the second testsslproxy
     ;
@@ -105,7 +107,7 @@ sub testss {
     close RND;
 
     my @req_dsa = ("-newkey",
-                   "dsa:".File::Spec->catfile("..", "apps", "dsa1024.pem"));;
+                   "dsa:".srctop_file("apps", "dsa1024.pem"));
     my @req_new;
     if ($no_rsa) {
        @req_new = @req_dsa;
@@ -306,17 +308,17 @@ sub testss {
 }
 
 sub testssl {
-    my $key = shift || top_file("apps","server.pem");
-    my $cert = shift || top_file("apps","server.pem");
+    my $key = shift || bldtop_file("apps","server.pem");
+    my $cert = shift || bldtop_file("apps","server.pem");
     my $CAtmp = shift;
-    my @CA = $CAtmp ? ("-CAfile", $CAtmp) : ("-CApath", top_dir("certs"));
+    my @CA = $CAtmp ? ("-CAfile", $CAtmp) : ("-CApath", bldtop_dir("certs"));
     my @extra = @_;
 
     my @ssltest = ("ssltest",
                   "-s_key", $key, "-s_cert", $cert,
                   "-c_key", $key, "-c_cert", $cert);
 
-    my $serverinfo = top_file("test","serverinfo.pem");
+    my $serverinfo = srctop_file("test","serverinfo.pem");
 
     my $dsa_cert = 0;
     if (grep /DSA Public Key/, run(app(["openssl", "x509", "-in", $cert,
@@ -325,11 +327,11 @@ sub testssl {
     }
 
 
-    # plan tests => 10;
+    # plan tests => 11;
 
     subtest 'standard SSL tests' => sub {
        ######################################################################
-       plan tests => 27;
+       plan tests => 29;
 
       SKIP: {
          skip "SSLv3 is not supported by this OpenSSL build", 4
@@ -410,7 +412,7 @@ sub testssl {
        }
 
       SKIP: {
-         skip "Neither SSLv3 nor any TLS version are supported by this OpenSSL build", 6
+         skip "Neither SSLv3 nor any TLS version are supported by this OpenSSL build", 8
              if $no_anytls;
 
        SKIP: {
@@ -430,7 +432,21 @@ sub testssl {
             'test sslv2/sslv3 with both client and server authentication via BIO pair');
          ok(run(test([@ssltest, "-bio_pair", "-server_auth", "-client_auth", "-app_verify", @CA, @extra])),
             'test sslv2/sslv3 with both client and server authentication via BIO pair and app verify');
-       }
+
+        SKIP: {
+            skip "No IPv4 available on this machine", 1
+                unless have_IPv4();
+            ok(run(test([@ssltest, "-ipv4", @extra])),
+               'test TLS via IPv4');
+          }
+          
+        SKIP: {
+            skip "No IPv6 available on this machine", 1
+                unless have_IPv6();
+            ok(run(test([@ssltest, "-ipv6", @extra])),
+               'test TLS via IPv6');
+          }
+        }
     };
 
     subtest "Testing ciphersuites" => sub {
@@ -470,6 +486,9 @@ sub testssl {
                  $protocolciphersuitcount += scalar @c;
                  $_ => [ @c ] } @protocols;
 
+        plan skip_all => "None of the ciphersuites to test are available in this OpenSSL build"
+            if $protocolciphersuitcount + scalar(@protocols) == 0;
+
         # The count of protocols is because in addition to the ciphersuits
         # we got above, we're running a weak DH test for each protocol
        plan tests => $protocolciphersuitcount + scalar(@protocols);
@@ -511,13 +530,13 @@ sub testssl {
            skip "skipping RSA tests", 2
                if $no_rsa;
 
-           ok(run(test(["ssltest", "-v", "-bio_pair", "-tls1", "-s_cert", top_file("apps","server2.pem"), "-no_dhe", "-no_ecdhe", "-num", "10", "-f", "-time", @extra])),
+           ok(run(test(["ssltest", "-v", "-bio_pair", "-tls1", "-s_cert", srctop_file("apps","server2.pem"), "-no_dhe", "-no_ecdhe", "-num", "10", "-f", "-time", @extra])),
               'test tlsv1 with 1024bit RSA, no (EC)DHE, multiple handshakes');
 
            skip "skipping RSA+DHE tests", 1
                if $no_dh;
 
-           ok(run(test(["ssltest", "-v", "-bio_pair", "-tls1", "-s_cert", top_file("apps","server2.pem"), "-dhe1024dsa", "-num", "10", "-f", "-time", @extra])),
+           ok(run(test(["ssltest", "-v", "-bio_pair", "-tls1", "-s_cert", srctop_file("apps","server2.pem"), "-dhe1024dsa", "-num", "10", "-f", "-time", @extra])),
               'test tlsv1 with 1024bit RSA, 1024bit DHE, multiple handshakes');
          }
 
@@ -560,7 +579,7 @@ sub testssl {
        plan tests => 1;
 
       SKIP: {
-         skip "TLSv1.0 is not supported by this OpenSSL build", 7
+         skip "TLSv1.0 is not supported by this OpenSSL build", 1
              if $no_tls1;
 
          ok(run(test([@ssltest, "-bio_pair", "-tls1", "-custom_ext"])),
@@ -586,6 +605,25 @@ sub testssl {
        }
     };
 
+    subtest 'SNI tests' => sub {
+
+       plan tests => 7;
+
+      SKIP: {
+         skip "TLSv1.x is not supported by this OpenSSL build", 7
+             if $no_tls1 && $no_tls1_1 && $no_tls1_2;
+
+         ok(run(test([@ssltest, "-bio_pair", "-sn_client", "foo"])));
+         ok(run(test([@ssltest, "-bio_pair", "-sn_server1", "foo"])));
+         ok(run(test([@ssltest, "-bio_pair", "-sn_client", "foo", "-sn_server1", "foo", "-sn_expect1"])));
+         ok(run(test([@ssltest, "-bio_pair", "-sn_client", "foo", "-sn_server1", "bar", "-sn_expect1"])));
+         ok(run(test([@ssltest, "-bio_pair", "-sn_client", "foo", "-sn_server1", "foo", "-sn_server2", "bar", "-sn_expect1"])));
+         ok(run(test([@ssltest, "-bio_pair", "-sn_client", "bar", "-sn_server1", "foo", "-sn_server2", "bar", "-sn_expect2"])));
+         # Negative test - make sure it doesn't crash, and doesn't switch contexts
+         ok(run(test([@ssltest, "-bio_pair", "-sn_client", "foobar", "-sn_server1", "foo", "-sn_server2", "bar", "-sn_expect1"])));
+       }
+    };
+
     subtest 'ALPN tests' => sub {
        ######################################################################
 
@@ -595,31 +633,53 @@ sub testssl {
          skip "TLSv1.0 is not supported by this OpenSSL build", 12
              if $no_tls1;
 
-         ok(run(test([@ssltest, "-bio_pair", "-tls1", "-alpn_client", "foo", "-alpn_server", "bar"])));
+         ok(run(test([@ssltest, "-bio_pair", "-tls1", "-alpn_client", "foo"])));
+         ok(run(test([@ssltest, "-bio_pair", "-tls1", "-alpn_server", "foo"])));
          ok(run(test([@ssltest, "-bio_pair", "-tls1", "-alpn_client", "foo", "-alpn_server", "foo", "-alpn_expected", "foo"])));
          ok(run(test([@ssltest, "-bio_pair", "-tls1", "-alpn_client", "foo,bar", "-alpn_server", "foo", "-alpn_expected", "foo"])));
          ok(run(test([@ssltest, "-bio_pair", "-tls1", "-alpn_client", "bar,foo", "-alpn_server", "foo", "-alpn_expected", "foo"])));
          ok(run(test([@ssltest, "-bio_pair", "-tls1", "-alpn_client", "bar,foo", "-alpn_server", "foo,bar", "-alpn_expected", "foo"])));
          ok(run(test([@ssltest, "-bio_pair", "-tls1", "-alpn_client", "bar,foo", "-alpn_server", "bar,foo", "-alpn_expected", "bar"])));
          ok(run(test([@ssltest, "-bio_pair", "-tls1", "-alpn_client", "foo,bar", "-alpn_server", "bar,foo", "-alpn_expected", "bar"])));
-         ok(run(test([@ssltest, "-bio_pair", "-tls1", "-alpn_client", "baz", "-alpn_server", "bar,foo"])));
 
-       SKIP: {
-           skip "skipping SRP tests", 4
-               if $no_srp;
+         is(run(test([@ssltest, "-bio_pair", "-tls1", "-alpn_client", "foo", "-alpn_server", "bar"])), 0,
+             "Testing ALPN with protocol mismatch, expecting failure");
+         is(run(test([@ssltest, "-bio_pair", "-tls1", "-alpn_client", "baz", "-alpn_server", "bar,foo"])), 0,
+             "Testing ALPN with protocol mismatch, expecting failure");
+
+         # ALPN + SNI
+         ok(run(test([@ssltest, "-bio_pair",
+                      "-alpn_client", "foo,bar", "-sn_client", "alice",
+                      "-alpn_server1", "foo,123", "-sn_server1", "alice",
+                      "-alpn_server2", "bar,456", "-sn_server2", "bob",
+                      "-alpn_expected", "foo"])));
+         ok(run(test([@ssltest, "-bio_pair",
+                      "-alpn_client", "foo,bar", "-sn_client", "bob",
+                      "-alpn_server1", "foo,123", "-sn_server1", "alice",
+                      "-alpn_server2", "bar,456", "-sn_server2", "bob",
+                      "-alpn_expected", "bar"])));
+       }
+    };
 
-           ok(run(test([@ssltest, "-tls1", "-cipher", "SRP", "-srpuser", "test", "-srppass", "abc123"])),
-              'test tls1 with SRP');
+    subtest 'SRP tests' => sub {
 
-           ok(run(test([@ssltest, "-bio_pair", "-tls1", "-cipher", "SRP", "-srpuser", "test", "-srppass", "abc123"])),
-              'test tls1 with SRP via BIO pair');
+       plan tests => 4;
 
-           ok(run(test([@ssltest, "-tls1", "-cipher", "aSRP", "-srpuser", "test", "-srppass", "abc123"])),
-                'test tls1 with SRP auth');
+      SKIP: {
+         skip "skipping SRP tests", 4
+             if $no_srp;
 
-           ok(run(test([@ssltest, "-bio_pair", "-tls1", "-cipher", "aSRP", "-srpuser", "test", "-srppass", "abc123"])),
-              'test tls1 with SRP auth via BIO pair');
-         }
+         ok(run(test([@ssltest, "-tls1", "-cipher", "SRP", "-srpuser", "test", "-srppass", "abc123"])),
+            'test tls1 with SRP');
+
+         ok(run(test([@ssltest, "-bio_pair", "-tls1", "-cipher", "SRP", "-srpuser", "test", "-srppass", "abc123"])),
+            'test tls1 with SRP via BIO pair');
+
+         ok(run(test([@ssltest, "-tls1", "-cipher", "aSRP", "-srpuser", "test", "-srppass", "abc123"])),
+            'test tls1 with SRP auth');
+
+         ok(run(test([@ssltest, "-bio_pair", "-tls1", "-cipher", "aSRP", "-srpuser", "test", "-srppass", "abc123"])),
+            'test tls1 with SRP auth via BIO pair');
        }
     };
 
@@ -740,13 +800,34 @@ sub testssl {
             ok($ok);
         }}}}}
     };
+
+    subtest 'Certificate Transparency tests' => sub {
+       ######################################################################
+
+       plan tests => 3;
+
+      SKIP: {
+         skip "Certificate Transparency is not supported by this OpenSSL build", 3
+             if $no_ct;
+         skip "TLSv1.0 is not supported by this OpenSSL build", 3
+             if $no_tls1;
+
+    $ENV{CTLOG_FILE} = srctop_file("test", "ct", "log_list.conf");
+         ok(run(test([@ssltest, "-bio_pair", "-tls1", "-noct"])));
+         ok(run(test([@ssltest, "-bio_pair", "-tls1", "-requestct"])));
+         # No SCTs provided, so this should fail.
+         ok(run(test([@ssltest, "-bio_pair", "-tls1", "-requirect",
+                      "-should_negotiate", "fail-client"])));
+       }
+    };
+
 }
 
 sub testsslproxy {
-    my $key = shift || top_file("apps","server.pem");
-    my $cert = shift || top_file("apps","server.pem");
+    my $key = shift || srctop_file("apps","server.pem");
+    my $cert = shift || srctop_file("apps","server.pem");
     my $CAtmp = shift;
-    my @CA = $CAtmp ? ("-CAfile", $CAtmp) : ("-CApath", top_dir("certs"));
+    my @CA = $CAtmp ? ("-CAfile", $CAtmp) : ("-CApath", bldtop_dir("certs"));
     my @extra = @_;
 
     my @ssltest = ("ssltest",