2016-04-22 11:21:51 +00:00
|
|
|
#! /usr/bin/env perl
|
|
|
|
# Copyright 2015-2016 The OpenSSL Project Authors. All Rights Reserved.
|
2015-06-16 12:12:37 +00:00
|
|
|
#
|
2016-04-22 11:21:51 +00:00
|
|
|
# Licensed under the OpenSSL license (the "License"). You may not use
|
|
|
|
# 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
|
2015-06-16 12:12:37 +00:00
|
|
|
|
|
|
|
use strict;
|
2016-01-30 00:05:33 +00:00
|
|
|
use OpenSSL::Test qw/:DEFAULT cmdstr srctop_file bldtop_dir/;
|
2016-01-16 23:25:44 +00:00
|
|
|
use OpenSSL::Test::Utils;
|
2015-06-16 12:12:37 +00:00
|
|
|
use TLSProxy::Proxy;
|
|
|
|
|
2015-08-13 17:38:59 +00:00
|
|
|
my $test_name = "test_sslextension";
|
|
|
|
setup($test_name);
|
|
|
|
|
2016-01-13 02:53:47 +00:00
|
|
|
plan skip_all => "TLSProxy isn't usable on $^O"
|
2016-03-05 18:59:30 +00:00
|
|
|
if $^O =~ /^(VMS|MSWin32)$/;
|
2016-01-13 02:53:47 +00:00
|
|
|
|
2016-02-19 21:13:11 +00:00
|
|
|
plan skip_all => "$test_name needs the dynamic engine feature enabled"
|
2016-02-22 01:06:05 +00:00
|
|
|
if disabled("engine") || disabled("dynamic-engine");
|
2015-08-13 17:38:59 +00:00
|
|
|
|
2016-03-21 15:32:40 +00:00
|
|
|
plan skip_all => "$test_name needs the sock feature enabled"
|
|
|
|
if disabled("sock");
|
|
|
|
|
2016-05-04 09:13:15 +00:00
|
|
|
plan skip_all => "$test_name needs TLS enabled"
|
|
|
|
if alldisabled(available_protocols("tls"));
|
|
|
|
|
2015-08-13 17:38:59 +00:00
|
|
|
$ENV{OPENSSL_ia32cap} = '~0x200000200000000';
|
2015-06-16 12:12:37 +00:00
|
|
|
my $proxy = TLSProxy::Proxy->new(
|
|
|
|
\&vers_tolerance_filter,
|
2016-04-01 13:09:28 +00:00
|
|
|
cmdstr(app(["openssl"]), display => 1),
|
2016-02-12 17:26:16 +00:00
|
|
|
srctop_file("apps", "server.pem"),
|
|
|
|
(!$ENV{HARNESS_ACTIVE} || $ENV{HARNESS_VERBOSE})
|
2015-06-16 12:12:37 +00:00
|
|
|
);
|
|
|
|
|
2016-12-25 16:56:52 +00:00
|
|
|
my @available_tls_versions = ();
|
|
|
|
foreach (available_protocols("tls")) {
|
|
|
|
unless (disabled($_)) {
|
|
|
|
note("Checking enabled protocol $_");
|
|
|
|
m|^([a-z]+)(\d)(_\d)?|;
|
|
|
|
my $versionname;
|
|
|
|
if (defined $3) {
|
|
|
|
$versionname = 'TLSProxy::Record::VERS_'.uc($1).'_'.$2.$3;
|
|
|
|
note("'$1', '$2', '$3' => $versionname");
|
|
|
|
} else {
|
|
|
|
$versionname = 'TLSProxy::Record::VERS_'.uc($1).'_'.$2.'_0';
|
|
|
|
note("'$1', '$2' => $versionname");
|
|
|
|
}
|
|
|
|
push @available_tls_versions, eval $versionname;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
note("TLS versions we can expect: ", join(", ", @available_tls_versions));
|
|
|
|
|
2016-11-02 09:09:02 +00:00
|
|
|
#This file does tests without the supported_versions extension.
|
|
|
|
#See 70-test_sslversions.t for tests with supported versions.
|
2016-12-29 12:15:13 +00:00
|
|
|
|
2016-12-25 16:56:52 +00:00
|
|
|
#Test 1: Asking for TLS1.4 should pass and negotiate the maximum
|
|
|
|
#available TLS version according to configuration below TLS1.3
|
2016-10-22 23:41:11 +00:00
|
|
|
my $client_version = TLSProxy::Record::VERS_TLS_1_4;
|
2016-12-29 12:15:13 +00:00
|
|
|
my $previous_version = tls_version_below(TLSProxy::Record::VERS_TLS_1_3);
|
2016-10-22 23:41:11 +00:00
|
|
|
$proxy->clientflags("-no_tls1_3");
|
2016-06-14 13:35:26 +00:00
|
|
|
$proxy->start() or plan skip_all => "Unable to start up Proxy for tests";
|
2016-11-02 09:09:02 +00:00
|
|
|
plan tests => 3;
|
2016-12-29 12:15:13 +00:00
|
|
|
SKIP: {
|
|
|
|
skip "There are too few protocols enabled for test 1", 1
|
|
|
|
unless defined $previous_version;
|
|
|
|
|
|
|
|
my $record = pop @{$proxy->record_list};
|
|
|
|
ok((note("Record version received: ".$record->version()),
|
|
|
|
TLSProxy::Message->success())
|
|
|
|
&& $record->version() == $previous_version,
|
|
|
|
"Version tolerance test, below TLS 1.4 and not TLS 1.3");
|
|
|
|
}
|
2015-06-16 12:12:37 +00:00
|
|
|
|
2016-12-25 16:56:52 +00:00
|
|
|
#Test 2: Asking for TLS1.3 with that disabled should succeed and negotiate
|
|
|
|
#the highest configured TLS version below that.
|
|
|
|
$client_version = TLSProxy::Record::VERS_TLS_1_3;
|
2016-12-29 12:15:13 +00:00
|
|
|
$previous_version = tls_version_below($client_version);
|
|
|
|
SKIP: {
|
|
|
|
skip "There are too few protocols enabled for test 2", 1
|
|
|
|
unless defined $previous_version;
|
|
|
|
|
|
|
|
$proxy->clear();
|
|
|
|
$proxy->clientflags("-no_tls1_3");
|
|
|
|
$proxy->start();
|
|
|
|
my $record = pop @{$proxy->record_list};
|
|
|
|
ok((note("Record version received: ".$record->version()),
|
|
|
|
TLSProxy::Message->success())
|
|
|
|
&& $record->version() == $previous_version,
|
|
|
|
"Version tolerance test, max version but not TLS 1.3");
|
|
|
|
}
|
2016-11-02 09:09:02 +00:00
|
|
|
|
2016-12-25 16:56:52 +00:00
|
|
|
#Test 3: Testing something below SSLv3 should fail. We must disable TLS 1.3
|
|
|
|
#to avoid having the 'supported_versions' extension kick in and override our
|
|
|
|
#desires.
|
2015-06-16 12:12:37 +00:00
|
|
|
$client_version = TLSProxy::Record::VERS_SSL_3_0 - 1;
|
2016-03-15 16:44:26 +00:00
|
|
|
$proxy->clear();
|
2016-10-22 23:41:11 +00:00
|
|
|
$proxy->clientflags("-no_tls1_3");
|
2016-03-15 16:44:26 +00:00
|
|
|
$proxy->start();
|
2016-12-29 12:15:13 +00:00
|
|
|
my $record = pop @{$proxy->record_list};
|
2016-12-25 16:56:52 +00:00
|
|
|
ok((note("Record version received: ".
|
|
|
|
(defined $record ? $record->version() : "none")),
|
|
|
|
TLSProxy::Message->fail()),
|
|
|
|
"Version tolerance test, SSL < 3.0");
|
2015-06-16 12:12:37 +00:00
|
|
|
|
|
|
|
sub vers_tolerance_filter
|
|
|
|
{
|
|
|
|
my $proxy = shift;
|
|
|
|
|
|
|
|
# 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) {
|
|
|
|
#Set the client version
|
2016-12-25 16:56:52 +00:00
|
|
|
#Anything above the max supported version should succeed
|
2015-06-16 12:12:37 +00:00
|
|
|
#Anything below SSLv3 should fail
|
|
|
|
$message->client_version($client_version);
|
|
|
|
$message->repack();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-12-25 16:56:52 +00:00
|
|
|
|
|
|
|
sub tls_version_below {
|
|
|
|
if (@_) {
|
|
|
|
my $term = shift;
|
|
|
|
my $res = undef;
|
|
|
|
|
|
|
|
foreach (@available_tls_versions) {
|
|
|
|
$res = $_ if $_ < $term;
|
|
|
|
}
|
|
|
|
return $res;
|
|
|
|
}
|
|
|
|
return $available_tls_versions[-1];
|
|
|
|
}
|