Fix a bug in test_sslversions
[openssl.git] / test / recipes / 70-test_sslversions.t
old mode 100755 (executable)
new mode 100644 (file)
index 0ee1556..c2d7623
@@ -1,5 +1,5 @@
 #! /usr/bin/env perl
-# Copyright 2015-2016 The OpenSSL Project Authors. All Rights Reserved.
+# Copyright 2015-2018 The OpenSSL Project Authors. All Rights Reserved.
 #
 # Licensed under the OpenSSL license (the "License").  You may not use
 # this file except in compliance with the License.  You can obtain a copy
@@ -17,8 +17,9 @@ use constant {
     UNRECOGNISED_VERSIONS => 2,
     NO_EXTENSION => 3,
     EMPTY_EXTENSION => 4,
-    NO_TLS1_3 => 5,
-    WITH_TLS1_4 => 6
+    TLS1_1_AND_1_0_ONLY => 5,
+    WITH_TLS1_4 => 6,
+    BAD_LEGACY_VERSION => 7
 };
 
 my $testtype;
@@ -27,7 +28,7 @@ my $test_name = "test_sslversions";
 setup($test_name);
 
 plan skip_all => "TLSProxy isn't usable on $^O"
-    if $^O =~ /^(VMS|MSWin32)$/;
+    if $^O =~ /^(VMS)$/;
 
 plan skip_all => "$test_name needs the dynamic engine feature enabled"
     if disabled("engine") || disabled("dynamic-engine");
@@ -55,7 +56,7 @@ my $proxy = TLSProxy::Proxy->new(
 $testtype = EMPTY_EXTENSION;
 $proxy->filter(\&modify_supported_versions_filter);
 $proxy->start() or plan skip_all => "Unable to start up Proxy for tests";
-plan tests => 7;
+plan tests => 8;
 ok(TLSProxy::Message->fail(), "Empty supported versions");
 
 #Test 2: supported_versions extension with no recognised versions should not
@@ -87,18 +88,19 @@ $testtype = REVERSE_ORDER_VERSIONS;
 $proxy->start();
 $record = pop @{$proxy->record_list};
 ok(TLSProxy::Message->success()
-   && $record->version() == TLSProxy::Record::VERS_TLS_1_3,
+   && $record->version() == TLSProxy::Record::VERS_TLS_1_2
+   && TLSProxy::Proxy->is_tls13(),
    "Reverse order versions");
 
 #Test 6: no TLSv1.3 or TLSv1.2 version in supported versions extension, but
 #TLSv1.1 and TLSv1.0 are present. Should just use TLSv1.1 and succeed
 $proxy->clear();
-$testtype = NO_TLS1_3;
+$testtype = TLS1_1_AND_1_0_ONLY;
 $proxy->start();
 $record = pop @{$proxy->record_list};
 ok(TLSProxy::Message->success()
    && $record->version() == TLSProxy::Record::VERS_TLS_1_1,
-   "No TLS1.3 in supported versions extension");
+   "TLS1.1 and TLS1.0 in supported versions extension only");
 
 #Test 7: TLS1.4 and TLS1.3 in supported versions. Should succeed and use TLS1.3
 $proxy->clear();
@@ -106,13 +108,31 @@ $testtype = WITH_TLS1_4;
 $proxy->start();
 $record = pop @{$proxy->record_list};
 ok(TLSProxy::Message->success()
-   && $record->version() == TLSProxy::Record::VERS_TLS_1_3,
+   && $record->version() == TLSProxy::Record::VERS_TLS_1_2
+   && TLSProxy::Proxy->is_tls13(),
    "TLS1.4 in supported versions extension");
 
+#Test 8: Set the legacy version to SSLv3 with supported versions. Should fail
+$proxy->clear();
+$testtype = BAD_LEGACY_VERSION;
+$proxy->start();
+ok(TLSProxy::Message->fail(), "Legacy version is SSLv3 with supported versions");
+
 sub modify_supported_versions_filter
 {
     my $proxy = shift;
 
+    if ($proxy->flight == 1) {
+        # Change the ServerRandom so that the downgrade sentinel doesn't cause
+        # the connection to fail
+        my $message = ${$proxy->message_list}[1];
+        return if (!defined $message);
+
+        $message->random("\0"x32);
+        $message->repack();
+        return;
+    }
+
     # We're only interested in the initial ClientHello
     if ($proxy->flight != 0) {
         return;
@@ -131,7 +151,7 @@ sub modify_supported_versions_filter
                     0x04, # Length
                     0x04, 0x04, #Some unrecognised version
                     0x04, 0x03; #Another unrecognised version
-            } elsif ($testtype == NO_TLS1_3) {
+            } elsif ($testtype == TLS1_1_AND_1_0_ONLY) {
                 $ext = pack "C5",
                     0x04, # Length
                     0x03, 0x02, #TLSv1.1
@@ -144,21 +164,22 @@ sub modify_supported_versions_filter
             }
             if ($testtype == REVERSE_ORDER_VERSIONS
                     || $testtype == UNRECOGNISED_VERSIONS
-                    || $testtype == NO_TLS1_3
+                    || $testtype == TLS1_1_AND_1_0_ONLY
                     || $testtype == WITH_TLS1_4) {
                 $message->set_extension(
                     TLSProxy::Message::EXT_SUPPORTED_VERSIONS, $ext);
             } elsif ($testtype == EMPTY_EXTENSION) {
                 $message->set_extension(
                     TLSProxy::Message::EXT_SUPPORTED_VERSIONS, "");
-            } else {
+            } elsif ($testtype == NO_EXTENSION) {
                 $message->delete_extension(
                     TLSProxy::Message::EXT_SUPPORTED_VERSIONS);
+            } else {
+                # BAD_LEGACY_VERSION
+                $message->client_version(TLSProxy::Record::VERS_SSL_3_0);
             }
 
             $message->repack();
         }
     }
 }
-
-