2016-10-28 01:32:19 +08:00
|
|
|
#! /usr/bin/env perl
|
2018-02-13 20:51:29 +08:00
|
|
|
# Copyright 2015-2018 The OpenSSL Project Authors. All Rights Reserved.
|
2016-10-28 01:32:19 +08:00
|
|
|
#
|
2018-12-06 20:05:25 +08:00
|
|
|
# Licensed under the Apache License 2.0 (the "License"). You may not use
|
2016-10-28 01:32:19 +08:00
|
|
|
# this file except in compliance with the License. You can obtain a copy
|
|
|
|
# in the file LICENSE in the source distribution or at
|
|
|
|
# https://www.openssl.org/source/license.html
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
use OpenSSL::Test qw/:DEFAULT cmdstr srctop_file bldtop_dir/;
|
|
|
|
use OpenSSL::Test::Utils;
|
|
|
|
use TLSProxy::Proxy;
|
|
|
|
use File::Temp qw(tempfile);
|
|
|
|
|
|
|
|
use constant {
|
|
|
|
REVERSE_ORDER_VERSIONS => 1,
|
|
|
|
UNRECOGNISED_VERSIONS => 2,
|
|
|
|
NO_EXTENSION => 3,
|
|
|
|
EMPTY_EXTENSION => 4,
|
2016-11-07 23:36:00 +08:00
|
|
|
TLS1_1_AND_1_0_ONLY => 5,
|
2018-07-19 23:51:58 +08:00
|
|
|
WITH_TLS1_4 => 6,
|
|
|
|
BAD_LEGACY_VERSION => 7
|
2016-10-28 01:32:19 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
my $testtype;
|
|
|
|
|
|
|
|
my $test_name = "test_sslversions";
|
|
|
|
setup($test_name);
|
|
|
|
|
|
|
|
plan skip_all => "TLSProxy isn't usable on $^O"
|
2018-01-17 17:39:28 +08:00
|
|
|
if $^O =~ /^(VMS)$/;
|
2016-10-28 01:32:19 +08:00
|
|
|
|
|
|
|
plan skip_all => "$test_name needs the dynamic engine feature enabled"
|
|
|
|
if disabled("engine") || disabled("dynamic-engine");
|
|
|
|
|
|
|
|
plan skip_all => "$test_name needs the sock feature enabled"
|
|
|
|
if disabled("sock");
|
|
|
|
|
|
|
|
plan skip_all => "$test_name needs TLS1.3, TLS1.2 and TLS1.1 enabled"
|
|
|
|
if disabled("tls1_3") || disabled("tls1_2") || disabled("tls1_1");
|
|
|
|
|
|
|
|
$ENV{OPENSSL_ia32cap} = '~0x200000200000000';
|
|
|
|
|
|
|
|
my $proxy = TLSProxy::Proxy->new(
|
|
|
|
undef,
|
|
|
|
cmdstr(app(["openssl"]), display => 1),
|
|
|
|
srctop_file("apps", "server.pem"),
|
|
|
|
(!$ENV{HARNESS_ACTIVE} || $ENV{HARNESS_VERBOSE})
|
|
|
|
);
|
|
|
|
|
|
|
|
#We're just testing various negative and unusual scenarios here. ssltest with
|
|
|
|
#02-protocol-version.conf should check all the various combinations of normal
|
|
|
|
#version neg
|
|
|
|
|
|
|
|
#Test 1: An empty supported_versions extension should not succeed
|
|
|
|
$testtype = EMPTY_EXTENSION;
|
|
|
|
$proxy->filter(\&modify_supported_versions_filter);
|
|
|
|
$proxy->start() or plan skip_all => "Unable to start up Proxy for tests";
|
2018-07-19 23:51:58 +08:00
|
|
|
plan tests => 8;
|
2016-10-28 01:32:19 +08:00
|
|
|
ok(TLSProxy::Message->fail(), "Empty supported versions");
|
|
|
|
|
|
|
|
#Test 2: supported_versions extension with no recognised versions should not
|
|
|
|
#succeed
|
|
|
|
$proxy->clear();
|
|
|
|
$testtype = UNRECOGNISED_VERSIONS;
|
|
|
|
$proxy->start();
|
|
|
|
ok(TLSProxy::Message->fail(), "No recognised versions");
|
|
|
|
|
|
|
|
#Test 3: No supported versions extensions should succeed and select TLSv1.2
|
|
|
|
$proxy->clear();
|
|
|
|
$testtype = NO_EXTENSION;
|
|
|
|
$proxy->start();
|
|
|
|
my $record = pop @{$proxy->record_list};
|
|
|
|
ok(TLSProxy::Message->success()
|
|
|
|
&& $record->version() == TLSProxy::Record::VERS_TLS_1_2,
|
|
|
|
"No supported versions extension");
|
|
|
|
|
|
|
|
#Test 4: No supported versions extensions should fail if only TLS1.3 available
|
|
|
|
$proxy->clear();
|
|
|
|
$proxy->serverflags("-tls1_3");
|
|
|
|
$proxy->start();
|
|
|
|
ok(TLSProxy::Message->fail(), "No supported versions extension (only TLS1.3)");
|
|
|
|
|
|
|
|
#Test 5: supported versions extension with best version last should succeed
|
|
|
|
#and select TLSv1.3
|
|
|
|
$proxy->clear();
|
|
|
|
$testtype = REVERSE_ORDER_VERSIONS;
|
|
|
|
$proxy->start();
|
|
|
|
$record = pop @{$proxy->record_list};
|
|
|
|
ok(TLSProxy::Message->success()
|
2017-11-08 00:04:35 +08:00
|
|
|
&& $record->version() == TLSProxy::Record::VERS_TLS_1_2
|
2017-01-02 19:52:57 +08:00
|
|
|
&& TLSProxy::Proxy->is_tls13(),
|
2016-10-28 01:32:19 +08:00
|
|
|
"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();
|
2016-11-07 23:36:00 +08:00
|
|
|
$testtype = TLS1_1_AND_1_0_ONLY;
|
2016-10-28 01:32:19 +08:00
|
|
|
$proxy->start();
|
|
|
|
$record = pop @{$proxy->record_list};
|
|
|
|
ok(TLSProxy::Message->success()
|
|
|
|
&& $record->version() == TLSProxy::Record::VERS_TLS_1_1,
|
2016-11-07 23:36:00 +08:00
|
|
|
"TLS1.1 and TLS1.0 in supported versions extension only");
|
2016-10-28 01:32:19 +08:00
|
|
|
|
2016-11-02 17:09:02 +08:00
|
|
|
#Test 7: TLS1.4 and TLS1.3 in supported versions. Should succeed and use TLS1.3
|
|
|
|
$proxy->clear();
|
|
|
|
$testtype = WITH_TLS1_4;
|
|
|
|
$proxy->start();
|
|
|
|
$record = pop @{$proxy->record_list};
|
|
|
|
ok(TLSProxy::Message->success()
|
2017-11-08 00:04:35 +08:00
|
|
|
&& $record->version() == TLSProxy::Record::VERS_TLS_1_2
|
2017-01-02 19:52:57 +08:00
|
|
|
&& TLSProxy::Proxy->is_tls13(),
|
2016-11-02 17:09:02 +08:00
|
|
|
"TLS1.4 in supported versions extension");
|
|
|
|
|
2018-07-19 23:51:58 +08:00
|
|
|
#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");
|
|
|
|
|
2016-10-28 01:32:19 +08:00
|
|
|
sub modify_supported_versions_filter
|
|
|
|
{
|
|
|
|
my $proxy = shift;
|
|
|
|
|
2017-03-24 00:33:57 +08:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2016-10-28 01:32:19 +08:00
|
|
|
# We're only interested in the initial ClientHello
|
|
|
|
if ($proxy->flight != 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach my $message (@{$proxy->message_list}) {
|
|
|
|
if ($message->mt == TLSProxy::Message::MT_CLIENT_HELLO) {
|
|
|
|
my $ext;
|
|
|
|
if ($testtype == REVERSE_ORDER_VERSIONS) {
|
|
|
|
$ext = pack "C5",
|
|
|
|
0x04, # Length
|
|
|
|
0x03, 0x03, #TLSv1.2
|
2018-07-18 23:05:49 +08:00
|
|
|
0x03, 0x04; #TLSv1.3
|
2016-10-28 01:32:19 +08:00
|
|
|
} elsif ($testtype == UNRECOGNISED_VERSIONS) {
|
|
|
|
$ext = pack "C5",
|
|
|
|
0x04, # Length
|
|
|
|
0x04, 0x04, #Some unrecognised version
|
|
|
|
0x04, 0x03; #Another unrecognised version
|
2016-11-07 23:36:00 +08:00
|
|
|
} elsif ($testtype == TLS1_1_AND_1_0_ONLY) {
|
2016-10-28 01:32:19 +08:00
|
|
|
$ext = pack "C5",
|
|
|
|
0x04, # Length
|
|
|
|
0x03, 0x02, #TLSv1.1
|
|
|
|
0x03, 0x01; #TLSv1.0
|
2016-11-02 17:09:02 +08:00
|
|
|
} elsif ($testtype == WITH_TLS1_4) {
|
|
|
|
$ext = pack "C5",
|
|
|
|
0x04, # Length
|
2018-07-18 23:19:05 +08:00
|
|
|
0x03, 0x05, #TLSv1.4
|
2018-07-18 23:05:49 +08:00
|
|
|
0x03, 0x04; #TLSv1.3
|
2016-10-28 01:32:19 +08:00
|
|
|
}
|
|
|
|
if ($testtype == REVERSE_ORDER_VERSIONS
|
|
|
|
|| $testtype == UNRECOGNISED_VERSIONS
|
2016-11-07 23:36:00 +08:00
|
|
|
|| $testtype == TLS1_1_AND_1_0_ONLY
|
2016-11-02 17:09:02 +08:00
|
|
|
|| $testtype == WITH_TLS1_4) {
|
2016-10-28 01:32:19 +08:00
|
|
|
$message->set_extension(
|
|
|
|
TLSProxy::Message::EXT_SUPPORTED_VERSIONS, $ext);
|
|
|
|
} elsif ($testtype == EMPTY_EXTENSION) {
|
|
|
|
$message->set_extension(
|
|
|
|
TLSProxy::Message::EXT_SUPPORTED_VERSIONS, "");
|
2018-07-19 23:51:58 +08:00
|
|
|
} elsif ($testtype == NO_EXTENSION) {
|
2016-10-28 01:32:19 +08:00
|
|
|
$message->delete_extension(
|
|
|
|
TLSProxy::Message::EXT_SUPPORTED_VERSIONS);
|
2018-07-19 23:51:58 +08:00
|
|
|
} else {
|
|
|
|
# BAD_LEGACY_VERSION
|
|
|
|
$message->client_version(TLSProxy::Record::VERS_SSL_3_0);
|
2016-10-28 01:32:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
$message->repack();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|