70-test_sslmessages.t: Don't check EXT_SIG_ALGS if TLS 1.2 is disabled
[openssl.git] / test / recipes / 70-test_sslmessages.t
index 8f7cfb0..9221529 100755 (executable)
@@ -7,11 +7,13 @@
 # https://www.openssl.org/source/license.html
 
 use strict;
-use OpenSSL::Test qw/:DEFAULT cmdstr srctop_file bldtop_dir/;
+use OpenSSL::Test qw/:DEFAULT cmdstr srctop_file srctop_dir bldtop_dir/;
 use OpenSSL::Test::Utils;
 use File::Temp qw(tempfile);
 use TLSProxy::Proxy;
-my $test_name = "test_tls13messages";
+use checkhandshake qw(checkhandshake @handmessages @extensions);
+
+my $test_name = "test_sslmessages";
 setup($test_name);
 
 plan skip_all => "TLSProxy isn't usable on $^O"
@@ -27,78 +29,7 @@ plan skip_all => "$test_name needs TLS enabled"
     if alldisabled(available_protocols("tls"));
 
 $ENV{OPENSSL_ia32cap} = '~0x200000200000000';
-
-use constant {
-    DEFAULT_HANDSHAKE => 1,
-    OCSP_HANDSHAKE => 2,
-    RESUME_HANDSHAKE => 4,
-    CLIENT_AUTH_HANDSHAKE => 8,
-    RENEG_HANDSHAKE => 16,
-
-    ALL_HANDSHAKES => 31
-};
-
-use constant {
-    #DEFAULT ALSO INCLUDES SESSION_TICKET_SRV_EXTENSION
-    DEFAULT_EXTENSIONS => 0x00000003,
-    SESSION_TICKET_SRV_EXTENSION => 0x00000002,
-    SERVER_NAME_CLI_EXTENSION => 0x00000004,
-    SERVER_NAME_SRV_EXTENSION => 0x00000008,
-    STATUS_REQUEST_CLI_EXTENSION => 0x00000010,
-    STATUS_REQUEST_SRV_EXTENSION => 0x00000020,
-    ALPN_CLI_EXTENSION => 0x00000040,
-    ALPN_SRV_EXTENSION => 0x00000080,
-    SCT_CLI_EXTENSION => 0x00000100,
-    RENEGOTIATE_CLI_EXTENSION => 0x00000200
-};
-
-my @handmessages = (
-    [TLSProxy::Message::MT_CLIENT_HELLO, ALL_HANDSHAKES],
-    [TLSProxy::Message::MT_SERVER_HELLO, ALL_HANDSHAKES],
-    [TLSProxy::Message::MT_CERTIFICATE, ALL_HANDSHAKES & ~RESUME_HANDSHAKE],
-    [TLSProxy::Message::MT_CERTIFICATE_STATUS, OCSP_HANDSHAKE],
-    #ServerKeyExchange handshakes not currently supported by TLSProxy
-    [TLSProxy::Message::MT_CERTIFICATE_REQUEST, CLIENT_AUTH_HANDSHAKE],
-    [TLSProxy::Message::MT_SERVER_HELLO_DONE, ALL_HANDSHAKES & ~RESUME_HANDSHAKE],
-    [TLSProxy::Message::MT_CERTIFICATE, CLIENT_AUTH_HANDSHAKE],
-    [TLSProxy::Message::MT_CLIENT_KEY_EXCHANGE, ALL_HANDSHAKES & ~RESUME_HANDSHAKE],
-    [TLSProxy::Message::MT_CERTIFICATE_VERIFY, CLIENT_AUTH_HANDSHAKE],
-    [TLSProxy::Message::MT_FINISHED, ALL_HANDSHAKES],
-    [TLSProxy::Message::MT_NEW_SESSION_TICKET, ALL_HANDSHAKES & ~RESUME_HANDSHAKE],
-    [TLSProxy::Message::MT_FINISHED, ALL_HANDSHAKES],
-    [TLSProxy::Message::MT_CLIENT_HELLO, RENEG_HANDSHAKE],
-    [TLSProxy::Message::MT_SERVER_HELLO, RENEG_HANDSHAKE],
-    [TLSProxy::Message::MT_CERTIFICATE, RENEG_HANDSHAKE],
-    [TLSProxy::Message::MT_SERVER_HELLO_DONE, RENEG_HANDSHAKE],
-    [TLSProxy::Message::MT_CLIENT_KEY_EXCHANGE, RENEG_HANDSHAKE],
-    [TLSProxy::Message::MT_FINISHED, RENEG_HANDSHAKE],
-    [TLSProxy::Message::MT_NEW_SESSION_TICKET, RENEG_HANDSHAKE],
-    [TLSProxy::Message::MT_FINISHED, RENEG_HANDSHAKE],
-    [0, 0]
-);
-
-my @extensions = (
-    [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_SERVER_NAME, SERVER_NAME_CLI_EXTENSION],
-    [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_STATUS_REQUEST, STATUS_REQUEST_CLI_EXTENSION],
-    [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_SUPPORTED_GROUPS, DEFAULT_EXTENSIONS],
-    [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_EC_POINT_FORMATS, DEFAULT_EXTENSIONS],
-    [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_SIG_ALGS, DEFAULT_EXTENSIONS],
-    [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_ALPN, ALPN_CLI_EXTENSION],
-    [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_SCT, SCT_CLI_EXTENSION],
-    [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_ENCRYPT_THEN_MAC, DEFAULT_EXTENSIONS],
-    [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_EXTENDED_MASTER_SECRET, DEFAULT_EXTENSIONS],
-    [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_SESSION_TICKET, DEFAULT_EXTENSIONS],
-    [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_RENEGOTIATE, RENEGOTIATE_CLI_EXTENSION],
-
-    [TLSProxy::Message::MT_SERVER_HELLO, TLSProxy::Message::EXT_RENEGOTIATE, DEFAULT_EXTENSIONS],
-    [TLSProxy::Message::MT_SERVER_HELLO, TLSProxy::Message::EXT_ENCRYPT_THEN_MAC, DEFAULT_EXTENSIONS],
-    [TLSProxy::Message::MT_SERVER_HELLO, TLSProxy::Message::EXT_EXTENDED_MASTER_SECRET, DEFAULT_EXTENSIONS],
-    [TLSProxy::Message::MT_SERVER_HELLO, TLSProxy::Message::EXT_SESSION_TICKET, SESSION_TICKET_SRV_EXTENSION],
-    [TLSProxy::Message::MT_SERVER_HELLO, TLSProxy::Message::EXT_SERVER_NAME, SERVER_NAME_SRV_EXTENSION],
-    [TLSProxy::Message::MT_SERVER_HELLO, TLSProxy::Message::EXT_STATUS_REQUEST, STATUS_REQUEST_SRV_EXTENSION],
-    [TLSProxy::Message::MT_SERVER_HELLO, TLSProxy::Message::EXT_ALPN, ALPN_SRV_EXTENSION],
-    [0,0,0]
-);
+$ENV{CTLOG_FILE} = srctop_file("test", "ct", "log_list.conf");
 
 my $proxy = TLSProxy::Proxy->new(
     undef,
@@ -107,122 +38,348 @@ my $proxy = TLSProxy::Proxy->new(
     (!$ENV{HARNESS_ACTIVE} || $ENV{HARNESS_VERBOSE})
 );
 
-sub checkmessages($$$);
+@handmessages = (
+    [TLSProxy::Message::MT_CLIENT_HELLO,
+        checkhandshake::ALL_HANDSHAKES],
+    [TLSProxy::Message::MT_SERVER_HELLO,
+        checkhandshake::ALL_HANDSHAKES],
+    [TLSProxy::Message::MT_CERTIFICATE,
+        checkhandshake::ALL_HANDSHAKES
+        & ~checkhandshake::RESUME_HANDSHAKE],
+    (disabled("ec") ? () :
+                      [TLSProxy::Message::MT_SERVER_KEY_EXCHANGE,
+                          checkhandshake::EC_HANDSHAKE]),
+    [TLSProxy::Message::MT_CERTIFICATE_STATUS,
+        checkhandshake::OCSP_HANDSHAKE],
+    #ServerKeyExchange handshakes not currently supported by TLSProxy
+    [TLSProxy::Message::MT_CERTIFICATE_REQUEST,
+        checkhandshake::CLIENT_AUTH_HANDSHAKE],
+    [TLSProxy::Message::MT_SERVER_HELLO_DONE,
+        checkhandshake::ALL_HANDSHAKES
+        & ~checkhandshake::RESUME_HANDSHAKE],
+    [TLSProxy::Message::MT_CERTIFICATE,
+        checkhandshake::CLIENT_AUTH_HANDSHAKE],
+    [TLSProxy::Message::MT_CLIENT_KEY_EXCHANGE,
+        checkhandshake::ALL_HANDSHAKES
+        & ~checkhandshake::RESUME_HANDSHAKE],
+    [TLSProxy::Message::MT_CERTIFICATE_VERIFY,
+        checkhandshake::CLIENT_AUTH_HANDSHAKE],
+    [TLSProxy::Message::MT_NEXT_PROTO,
+        checkhandshake::NPN_HANDSHAKE],
+    [TLSProxy::Message::MT_FINISHED,
+        checkhandshake::ALL_HANDSHAKES],
+    [TLSProxy::Message::MT_NEW_SESSION_TICKET,
+        checkhandshake::ALL_HANDSHAKES
+        & ~checkhandshake::RESUME_HANDSHAKE],
+    [TLSProxy::Message::MT_FINISHED,
+        checkhandshake::ALL_HANDSHAKES],
+    [TLSProxy::Message::MT_CLIENT_HELLO,
+        checkhandshake::RENEG_HANDSHAKE],
+    [TLSProxy::Message::MT_SERVER_HELLO,
+        checkhandshake::RENEG_HANDSHAKE],
+    [TLSProxy::Message::MT_CERTIFICATE,
+        checkhandshake::RENEG_HANDSHAKE],
+    [TLSProxy::Message::MT_SERVER_HELLO_DONE,
+        checkhandshake::RENEG_HANDSHAKE],
+    [TLSProxy::Message::MT_CLIENT_KEY_EXCHANGE,
+        checkhandshake::RENEG_HANDSHAKE],
+    [TLSProxy::Message::MT_FINISHED,
+        checkhandshake::RENEG_HANDSHAKE],
+    [TLSProxy::Message::MT_NEW_SESSION_TICKET,
+        checkhandshake::RENEG_HANDSHAKE],
+    [TLSProxy::Message::MT_FINISHED,
+        checkhandshake::RENEG_HANDSHAKE],
+    [0, 0]
+);
+
+@extensions = (
+    [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_SERVER_NAME,
+        checkhandshake::SERVER_NAME_CLI_EXTENSION],
+    [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_STATUS_REQUEST,
+        checkhandshake::STATUS_REQUEST_CLI_EXTENSION],
+    (disabled("ec") ? () :
+                      [TLSProxy::Message::MT_CLIENT_HELLO,
+                       TLSProxy::Message::EXT_SUPPORTED_GROUPS,
+                       checkhandshake::DEFAULT_EXTENSIONS]),
+    (disabled("ec") ? () :
+                      [TLSProxy::Message::MT_CLIENT_HELLO,
+                       TLSProxy::Message::EXT_EC_POINT_FORMATS,
+                       checkhandshake::DEFAULT_EXTENSIONS]),
+    (disabled("tls1_2") ? () :
+     [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_SIG_ALGS,
+         checkhandshake::DEFAULT_EXTENSIONS]),
+    [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_ALPN,
+        checkhandshake::ALPN_CLI_EXTENSION],
+    [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_SCT,
+        checkhandshake::SCT_CLI_EXTENSION],
+    [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_ENCRYPT_THEN_MAC,
+        checkhandshake::DEFAULT_EXTENSIONS],
+    [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_EXTENDED_MASTER_SECRET,
+        checkhandshake::DEFAULT_EXTENSIONS],
+    [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_SESSION_TICKET,
+        checkhandshake::DEFAULT_EXTENSIONS],
+    [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_RENEGOTIATE,
+        checkhandshake::RENEGOTIATE_CLI_EXTENSION],
+    [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_NPN,
+        checkhandshake::NPN_CLI_EXTENSION],
+    [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_SRP,
+        checkhandshake::SRP_CLI_EXTENSION],
+
+    [TLSProxy::Message::MT_SERVER_HELLO, TLSProxy::Message::EXT_RENEGOTIATE,
+        checkhandshake::DEFAULT_EXTENSIONS],
+    [TLSProxy::Message::MT_SERVER_HELLO, TLSProxy::Message::EXT_ENCRYPT_THEN_MAC,
+        checkhandshake::DEFAULT_EXTENSIONS],
+    [TLSProxy::Message::MT_SERVER_HELLO, TLSProxy::Message::EXT_EXTENDED_MASTER_SECRET,
+        checkhandshake::DEFAULT_EXTENSIONS],
+    [TLSProxy::Message::MT_SERVER_HELLO, TLSProxy::Message::EXT_SESSION_TICKET,
+        checkhandshake::SESSION_TICKET_SRV_EXTENSION],
+    [TLSProxy::Message::MT_SERVER_HELLO, TLSProxy::Message::EXT_SERVER_NAME,
+        checkhandshake::SERVER_NAME_SRV_EXTENSION],
+    [TLSProxy::Message::MT_SERVER_HELLO, TLSProxy::Message::EXT_STATUS_REQUEST,
+        checkhandshake::STATUS_REQUEST_SRV_EXTENSION],
+    [TLSProxy::Message::MT_SERVER_HELLO, TLSProxy::Message::EXT_ALPN,
+        checkhandshake::ALPN_SRV_EXTENSION],
+    [TLSProxy::Message::MT_SERVER_HELLO, TLSProxy::Message::EXT_SCT,
+        checkhandshake::SCT_SRV_EXTENSION],
+    [TLSProxy::Message::MT_SERVER_HELLO, TLSProxy::Message::EXT_NPN,
+        checkhandshake::NPN_SRV_EXTENSION],
+    [TLSProxy::Message::MT_SERVER_HELLO, TLSProxy::Message::EXT_EC_POINT_FORMATS,
+        checkhandshake::EC_POINT_FORMAT_SRV_EXTENSION],
+    [0,0,0]
+);
 
 #Test 1: Check we get all the right messages for a default handshake
 (undef, my $session) = tempfile();
 $proxy->serverconnects(2);
 $proxy->clientflags("-no_tls1_3 -sess_out ".$session);
 $proxy->start() or plan skip_all => "Unable to start up Proxy for tests";
-plan tests => 5;
-checkmessages(DEFAULT_HANDSHAKE, DEFAULT_EXTENSIONS, "Default handshake test");
+plan tests => 21;
+checkhandshake($proxy, checkhandshake::DEFAULT_HANDSHAKE,
+               checkhandshake::DEFAULT_EXTENSIONS,
+               "Default handshake test");
 
 #Test 2: Resumption handshake
 $proxy->clearClient();
 $proxy->clientflags("-no_tls1_3 -sess_in ".$session);
 $proxy->clientstart();
-checkmessages(RESUME_HANDSHAKE,
-              DEFAULT_EXTENSIONS & ~SESSION_TICKET_SRV_EXTENSION,
-              "Resumption handshake test");
+checkhandshake($proxy, checkhandshake::RESUME_HANDSHAKE,
+               checkhandshake::DEFAULT_EXTENSIONS
+               & ~checkhandshake::SESSION_TICKET_SRV_EXTENSION,
+               "Resumption handshake test");
 unlink $session;
 
-#Test 3: A default handshake, but with a CertificateStatus message
+#Test 3: A status_request handshake (client request only)
+$proxy->clear();
+$proxy->clientflags("-no_tls1_3 -status");
+$proxy->start();
+checkhandshake($proxy, checkhandshake::DEFAULT_HANDSHAKE,
+               checkhandshake::DEFAULT_EXTENSIONS
+               | checkhandshake::STATUS_REQUEST_CLI_EXTENSION,
+               "status_request handshake test (client)");
+
+#Test 4: A status_request handshake (server support only)
+$proxy->clear();
+$proxy->clientflags("-no_tls1_3");
+$proxy->serverflags("-status_file "
+                    .srctop_file("test", "recipes", "ocsp-response.der"));
+$proxy->start();
+checkhandshake($proxy, checkhandshake::DEFAULT_HANDSHAKE,
+               checkhandshake::DEFAULT_EXTENSIONS,
+               "status_request handshake test (server)");
+
+#Test 5: A status_request handshake (client and server)
 $proxy->clear();
 $proxy->clientflags("-no_tls1_3 -status");
 $proxy->serverflags("-status_file "
                     .srctop_file("test", "recipes", "ocsp-response.der"));
 $proxy->start();
-checkmessages(OCSP_HANDSHAKE,
-              DEFAULT_EXTENSIONS | STATUS_REQUEST_CLI_EXTENSION
-              | STATUS_REQUEST_SRV_EXTENSION,
-              "OCSP handshake test");
+checkhandshake($proxy, checkhandshake::OCSP_HANDSHAKE,
+               checkhandshake::DEFAULT_EXTENSIONS
+               | checkhandshake::STATUS_REQUEST_CLI_EXTENSION
+               | checkhandshake::STATUS_REQUEST_SRV_EXTENSION,
+               "status_request handshake test");
 
-#Test 4: A client auth handshake
+#Test 6: A client auth handshake
 $proxy->clear();
 $proxy->clientflags("-no_tls1_3 -cert ".srctop_file("apps", "server.pem"));
 $proxy->serverflags("-Verify 5");
 $proxy->start();
-checkmessages(CLIENT_AUTH_HANDSHAKE, DEFAULT_EXTENSIONS,
-              "Client auth handshake test");
+checkhandshake($proxy, checkhandshake::CLIENT_AUTH_HANDSHAKE,
+               checkhandshake::DEFAULT_EXTENSIONS,
+               "Client auth handshake test");
 
-#Test 5: A handshake with a renegotiation
+#Test 7: A handshake with a renegotiation
 $proxy->clear();
 $proxy->clientflags("-no_tls1_3");
 $proxy->reneg(1);
 $proxy->start();
-checkmessages(RENEG_HANDSHAKE, DEFAULT_EXTENSIONS,
-              "Rengotiation handshake test");
-
-sub checkmessages($$$)
-{
-    my ($handtype, $exttype, $testname) = @_;
-
-    subtest $testname => sub {
-        my $loop = 0;
-        my $numtests;
-        my $extcount;
-        my $clienthelloseen = 0;
-
-        #First count the number of tests
-        for ($numtests = 0; $handmessages[$loop][1] != 0; $loop++) {
-            $numtests++ if (($handmessages[$loop][1] & $handtype) != 0);
-        }
-
-        #Add number of extensions we check plus 2 for the number of messages
-        #that contain extensions
-        $numtests += $#extensions + 2;
-        #In a renegotiation we will have double the number of extension tests
-        if (($handtype & RENEG_HANDSHAKE) != 0) {
-            $numtests += $#extensions + 2;
-        }
-
-        plan tests => $numtests;
-
-        my $nextmess = 0;
-        my $message = undef;
-        for ($loop = 0; $handmessages[$loop][1] != 0; $loop++) {
-            next if (($handmessages[$loop][1] & $handtype) == 0);
-            if (scalar @{$proxy->message_list} > $nextmess) {
-                $message = ${$proxy->message_list}[$nextmess];
-                $nextmess++;
-            } else {
-                $message = undef;
-            }
-            if (!defined $message) {
-                fail("Message type check. Got nothing, expected "
-                     .$handmessages[$loop][0]);
-                next;
-            } else {
-                ok($message->mt == $handmessages[$loop][0],
-                   "Message type check. Got ".$message->mt
-                   .", expected ".$handmessages[$loop][0]);
-            }
-
-            next if ($message->mt() != TLSProxy::Message::MT_CLIENT_HELLO
-                    && $message->mt() != TLSProxy::Message::MT_SERVER_HELLO
-                    && $message->mt() !=
-                       TLSProxy::Message::MT_ENCRYPTED_EXTENSIONS);
-
-            if ($message->mt() == TLSProxy::Message::MT_CLIENT_HELLO) {
-                #Add renegotiate extension we will expect if renegotiating
-                $exttype |= RENEGOTIATE_CLI_EXTENSION if ($clienthelloseen);
-                $clienthelloseen = 1;
-            }
-             #Now check that we saw the extensions we expected
-             my $msgexts = $message->extension_data();
-             for (my $extloop = 0, $extcount = 0; $extensions[$extloop][2] != 0;
-                                $extloop++) {
-                next if ($message->mt() != $extensions[$extloop][0]);
-                ok (($extensions[$extloop][2] & $exttype) == 0
-                      || defined ($msgexts->{$extensions[$extloop][1]}),
-                    "Extension presence check (Message: ".$message->mt()
-                    ." Extension: ".($extensions[$extloop][2] & $exttype).", "
-                    .$extloop.")");
-                $extcount++ if (($extensions[$extloop][2] & $exttype) != 0);
-             }
-            ok($extcount == keys %$msgexts, "Extensions count mismatch ("
-                                            .$extcount.", ".(keys %$msgexts)
-                                            .")");
-        }
-    }
+checkhandshake($proxy, checkhandshake::RENEG_HANDSHAKE,
+               checkhandshake::DEFAULT_EXTENSIONS,
+               "Rengotiation handshake test");
+
+#Test 8: Server name handshake (client request only)
+$proxy->clear();
+$proxy->clientflags("-no_tls1_3 -servername testhost");
+$proxy->start();
+checkhandshake($proxy, checkhandshake::DEFAULT_HANDSHAKE,
+               checkhandshake::DEFAULT_EXTENSIONS
+               | checkhandshake::SERVER_NAME_CLI_EXTENSION,
+               "Server name handshake test (client)");
+
+#Test 9: Server name handshake (server support only)
+$proxy->clear();
+$proxy->clientflags("-no_tls1_3");
+$proxy->serverflags("-servername testhost");
+$proxy->start();
+checkhandshake($proxy, checkhandshake::DEFAULT_HANDSHAKE,
+               checkhandshake::DEFAULT_EXTENSIONS,
+               "Server name handshake test (server)");
+
+#Test 10: Server name handshake (client and server)
+$proxy->clear();
+$proxy->clientflags("-no_tls1_3 -servername testhost");
+$proxy->serverflags("-servername testhost");
+$proxy->start();
+checkhandshake($proxy, checkhandshake::DEFAULT_HANDSHAKE,
+               checkhandshake::DEFAULT_EXTENSIONS
+               | checkhandshake::SERVER_NAME_CLI_EXTENSION
+               | checkhandshake::SERVER_NAME_SRV_EXTENSION,
+               "Server name handshake test");
+
+#Test 11: ALPN handshake (client request only)
+$proxy->clear();
+$proxy->clientflags("-no_tls1_3 -alpn test");
+$proxy->start();
+checkhandshake($proxy, checkhandshake::DEFAULT_HANDSHAKE,
+               checkhandshake::DEFAULT_EXTENSIONS
+               | checkhandshake::ALPN_CLI_EXTENSION,
+               "ALPN handshake test (client)");
+
+#Test 12: ALPN handshake (server support only)
+$proxy->clear();
+$proxy->clientflags("-no_tls1_3");
+$proxy->serverflags("-alpn test");
+$proxy->start();
+checkhandshake($proxy, checkhandshake::DEFAULT_HANDSHAKE,
+               checkhandshake::DEFAULT_EXTENSIONS,
+               "ALPN handshake test (server)");
+
+#Test 13: ALPN handshake (client and server)
+$proxy->clear();
+$proxy->clientflags("-no_tls1_3 -alpn test");
+$proxy->serverflags("-alpn test");
+$proxy->start();
+checkhandshake($proxy, checkhandshake::DEFAULT_HANDSHAKE,
+               checkhandshake::DEFAULT_EXTENSIONS
+               | checkhandshake::ALPN_CLI_EXTENSION
+               | checkhandshake::ALPN_SRV_EXTENSION,
+               "ALPN handshake test");
+
+SKIP: {
+    skip "No CT and/or EC support in this OpenSSL build", 1
+        if disabled("ct") || disabled("ec");
+
+    #Test 14: SCT handshake (client request only)
+    $proxy->clear();
+    #Note: -ct also sends status_request
+    $proxy->clientflags("-no_tls1_3 -ct");
+    $proxy->serverflags("-status_file "
+                        .srctop_file("test", "recipes", "ocsp-response.der"));
+    $proxy->start();
+    checkhandshake($proxy, checkhandshake::OCSP_HANDSHAKE,
+                   checkhandshake::DEFAULT_EXTENSIONS
+                   | checkhandshake::SCT_CLI_EXTENSION
+                   | checkhandshake::STATUS_REQUEST_CLI_EXTENSION
+                   | checkhandshake::STATUS_REQUEST_SRV_EXTENSION,
+                   "SCT handshake test (client)");
+}
+
+#Test 15: SCT handshake (server support only)
+$proxy->clear();
+#Note: -ct also sends status_request
+$proxy->clientflags("-no_tls1_3");
+$proxy->serverflags("-status_file "
+                    .srctop_file("test", "recipes", "ocsp-response.der"));
+$proxy->start();
+checkhandshake($proxy, checkhandshake::DEFAULT_HANDSHAKE,
+               checkhandshake::DEFAULT_EXTENSIONS,
+               "SCT handshake test (server)");
+
+SKIP: {
+    skip "No CT and/or EC support in this OpenSSL build", 1
+        if disabled("ct") || disabled("ec");
+
+    #Test 16: SCT handshake (client and server)
+    #There is no built-in server side support for this so we are actually also
+    #testing custom extensions here
+    $proxy->clear();
+    #Note: -ct also sends status_request
+    $proxy->clientflags("-no_tls1_3 -ct");
+    $proxy->serverflags("-status_file "
+                        .srctop_file("test", "recipes", "ocsp-response.der")
+                        ." -serverinfo ".srctop_file("test", "serverinfo.pem"));
+    $proxy->start();
+    checkhandshake($proxy, checkhandshake::OCSP_HANDSHAKE,
+                   checkhandshake::DEFAULT_EXTENSIONS
+                   | checkhandshake::SCT_CLI_EXTENSION
+                   | checkhandshake::SCT_SRV_EXTENSION
+                   | checkhandshake::STATUS_REQUEST_CLI_EXTENSION
+                   | checkhandshake::STATUS_REQUEST_SRV_EXTENSION,
+                   "SCT handshake test");
+}
+
+
+#Test 17: NPN handshake (client request only)
+$proxy->clear();
+$proxy->clientflags("-no_tls1_3 -nextprotoneg test");
+$proxy->start();
+checkhandshake($proxy, checkhandshake::DEFAULT_HANDSHAKE,
+               checkhandshake::DEFAULT_EXTENSIONS
+               | checkhandshake::NPN_CLI_EXTENSION,
+              "NPN handshake test (client)");
+
+#Test 18: NPN handshake (server support only)
+$proxy->clear();
+$proxy->clientflags("-no_tls1_3");
+$proxy->serverflags("-nextprotoneg test");
+$proxy->start();
+checkhandshake($proxy, checkhandshake::DEFAULT_HANDSHAKE,
+               checkhandshake::DEFAULT_EXTENSIONS,
+              "NPN handshake test (server)");
+
+#Test 19: NPN handshake (client and server)
+$proxy->clear();
+$proxy->clientflags("-no_tls1_3 -nextprotoneg test");
+$proxy->serverflags("-nextprotoneg test");
+$proxy->start();
+checkhandshake($proxy, checkhandshake::NPN_HANDSHAKE,
+               checkhandshake::DEFAULT_EXTENSIONS
+               | checkhandshake::NPN_CLI_EXTENSION
+               | checkhandshake::NPN_SRV_EXTENSION,
+               "NPN handshake test");
+
+#Test 20: SRP extension
+#Note: We are not actually going to perform an SRP handshake (TLSProxy does not
+#support it). However it is sufficient for us to check that the SRP extension
+#gets added on the client side. There is no SRP extension generated on the
+#server side anyway.
+$proxy->clear();
+$proxy->clientflags("-no_tls1_3 -srpuser user -srppass pass:pass");
+$proxy->start();
+checkhandshake($proxy, checkhandshake::DEFAULT_HANDSHAKE,
+               checkhandshake::DEFAULT_EXTENSIONS
+               | checkhandshake::SRP_CLI_EXTENSION,
+               "SRP extension test");
+
+#Test 21: EC handshake
+SKIP: {
+    skip "No EC support in this OpenSSL build", 1 if disabled("ec");
+    $proxy->clear();
+    $proxy->clientflags("-no_tls1_3");
+    $proxy->ciphers("ECDHE-RSA-AES128-SHA");
+    $proxy->start();
+    checkhandshake($proxy, checkhandshake::EC_HANDSHAKE,
+                   checkhandshake::DEFAULT_EXTENSIONS
+                   | checkhandshake::EC_POINT_FORMAT_SRV_EXTENSION,
+                   "EC handshake test");
 }