|
Packit Service |
084de1 |
#! /usr/bin/env perl
|
|
Packit Service |
084de1 |
# Copyright 2015-2019 The OpenSSL Project Authors. All Rights Reserved.
|
|
Packit Service |
084de1 |
#
|
|
Packit Service |
084de1 |
# Licensed under the OpenSSL license (the "License"). You may not use
|
|
Packit Service |
084de1 |
# this file except in compliance with the License. You can obtain a copy
|
|
Packit Service |
084de1 |
# in the file LICENSE in the source distribution or at
|
|
Packit Service |
084de1 |
# https://www.openssl.org/source/license.html
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
use strict;
|
|
Packit Service |
084de1 |
use feature 'state';
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
use OpenSSL::Test qw/:DEFAULT cmdstr srctop_file bldtop_dir/;
|
|
Packit Service |
084de1 |
use OpenSSL::Test::Utils;
|
|
Packit Service |
084de1 |
use TLSProxy::Proxy;
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
my $test_name = "test_sslextension";
|
|
Packit Service |
084de1 |
setup($test_name);
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
plan skip_all => "TLSProxy isn't usable on $^O"
|
|
Packit Service |
084de1 |
if $^O =~ /^(VMS)$/;
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
plan skip_all => "$test_name needs the dynamic engine feature enabled"
|
|
Packit Service |
084de1 |
if disabled("engine") || disabled("dynamic-engine");
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
plan skip_all => "$test_name needs the sock feature enabled"
|
|
Packit Service |
084de1 |
if disabled("sock");
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
plan skip_all => "$test_name needs TLS enabled"
|
|
Packit Service |
084de1 |
if alldisabled(available_protocols("tls"));
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
my $no_below_tls13 = alldisabled(("tls1", "tls1_1", "tls1_2"))
|
|
Packit Service |
084de1 |
|| (!disabled("tls1_3") && disabled("tls1_2"));
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
use constant {
|
|
Packit Service |
084de1 |
UNSOLICITED_SERVER_NAME => 0,
|
|
Packit Service |
084de1 |
UNSOLICITED_SERVER_NAME_TLS13 => 1,
|
|
Packit Service |
084de1 |
UNSOLICITED_SCT => 2,
|
|
Packit Service |
084de1 |
NONCOMPLIANT_SUPPORTED_GROUPS => 3
|
|
Packit Service |
084de1 |
};
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
my $testtype;
|
|
Packit Service |
084de1 |
my $fatal_alert = 0; # set by filter on fatal alert
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
$ENV{OPENSSL_ia32cap} = '~0x200000200000000';
|
|
Packit Service |
084de1 |
my $proxy = TLSProxy::Proxy->new(
|
|
Packit Service |
084de1 |
\&inject_duplicate_extension_clienthello,
|
|
Packit Service |
084de1 |
cmdstr(app(["openssl"]), display => 1),
|
|
Packit Service |
084de1 |
srctop_file("apps", "server.pem"),
|
|
Packit Service |
084de1 |
(!$ENV{HARNESS_ACTIVE} || $ENV{HARNESS_VERBOSE})
|
|
Packit Service |
084de1 |
);
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
sub extension_filter
|
|
Packit Service |
084de1 |
{
|
|
Packit Service |
084de1 |
my $proxy = shift;
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
if ($proxy->flight == 1) {
|
|
Packit Service |
084de1 |
# Change the ServerRandom so that the downgrade sentinel doesn't cause
|
|
Packit Service |
084de1 |
# the connection to fail
|
|
Packit Service |
084de1 |
my $message = ${$proxy->message_list}[1];
|
|
Packit Service |
084de1 |
$message->random("\0"x32);
|
|
Packit Service |
084de1 |
$message->repack();
|
|
Packit Service |
084de1 |
return;
|
|
Packit Service |
084de1 |
}
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
# We're only interested in the initial ClientHello
|
|
Packit Service |
084de1 |
if ($proxy->flight != 0) {
|
|
Packit Service |
084de1 |
return;
|
|
Packit Service |
084de1 |
}
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
foreach my $message (@{$proxy->message_list}) {
|
|
Packit Service |
084de1 |
if ($message->mt == TLSProxy::Message::MT_CLIENT_HELLO) {
|
|
Packit Service |
084de1 |
# Remove all extensions and set the extension len to zero
|
|
Packit Service |
084de1 |
$message->extension_data({});
|
|
Packit Service |
084de1 |
$message->extensions_len(0);
|
|
Packit Service |
084de1 |
# Extensions have been removed so make sure we don't try to use them
|
|
Packit Service |
084de1 |
$message->process_extensions();
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
$message->repack();
|
|
Packit Service |
084de1 |
}
|
|
Packit Service |
084de1 |
}
|
|
Packit Service |
084de1 |
}
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
sub inject_duplicate_extension
|
|
Packit Service |
084de1 |
{
|
|
Packit Service |
084de1 |
my ($proxy, $message_type) = @_;
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
foreach my $message (@{$proxy->message_list}) {
|
|
Packit Service |
084de1 |
if ($message->mt == $message_type) {
|
|
Packit Service |
084de1 |
my %extensions = %{$message->extension_data};
|
|
Packit Service |
084de1 |
# Add a duplicate extension. We use cryptopro_bug since we never
|
|
Packit Service |
084de1 |
# normally write that one, and it is allowed as unsolicited in the
|
|
Packit Service |
084de1 |
# ServerHello
|
|
Packit Service |
084de1 |
$message->set_extension(TLSProxy::Message::EXT_CRYPTOPRO_BUG_EXTENSION, "");
|
|
Packit Service |
084de1 |
$message->dupext(TLSProxy::Message::EXT_CRYPTOPRO_BUG_EXTENSION);
|
|
Packit Service |
084de1 |
$message->repack();
|
|
Packit Service |
084de1 |
}
|
|
Packit Service |
084de1 |
}
|
|
Packit Service |
084de1 |
}
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
sub inject_duplicate_extension_clienthello
|
|
Packit Service |
084de1 |
{
|
|
Packit Service |
084de1 |
my $proxy = shift;
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
# We're only interested in the initial ClientHello
|
|
Packit Service |
084de1 |
if ($proxy->flight == 0) {
|
|
Packit Service |
084de1 |
inject_duplicate_extension($proxy, TLSProxy::Message::MT_CLIENT_HELLO);
|
|
Packit Service |
084de1 |
return;
|
|
Packit Service |
084de1 |
}
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
my $last_record = @{$proxy->{record_list}}[-1];
|
|
Packit Service |
084de1 |
$fatal_alert = 1 if $last_record->is_fatal_alert(1);
|
|
Packit Service |
084de1 |
}
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
sub inject_duplicate_extension_serverhello
|
|
Packit Service |
084de1 |
{
|
|
Packit Service |
084de1 |
my $proxy = shift;
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
# We're only interested in the initial ServerHello
|
|
Packit Service |
084de1 |
if ($proxy->flight == 0) {
|
|
Packit Service |
084de1 |
return;
|
|
Packit Service |
084de1 |
} elsif ($proxy->flight == 1) {
|
|
Packit Service |
084de1 |
inject_duplicate_extension($proxy, TLSProxy::Message::MT_SERVER_HELLO);
|
|
Packit Service |
084de1 |
return;
|
|
Packit Service |
084de1 |
}
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
my $last_record = @{$proxy->{record_list}}[-1];
|
|
Packit Service |
084de1 |
$fatal_alert = 1 if $last_record->is_fatal_alert(0);
|
|
Packit Service |
084de1 |
}
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
sub inject_unsolicited_extension
|
|
Packit Service |
084de1 |
{
|
|
Packit Service |
084de1 |
my $proxy = shift;
|
|
Packit Service |
084de1 |
my $message;
|
|
Packit Service |
084de1 |
state $sent_unsolisited_extension;
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
if ($proxy->flight == 0) {
|
|
Packit Service |
084de1 |
$sent_unsolisited_extension = 0;
|
|
Packit Service |
084de1 |
return;
|
|
Packit Service |
084de1 |
}
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
# We're only interested in the initial ServerHello/EncryptedExtensions
|
|
Packit Service |
084de1 |
if ($proxy->flight != 1) {
|
|
Packit Service |
084de1 |
if ($sent_unsolisited_extension) {
|
|
Packit Service |
084de1 |
my $last_record = @{$proxy->record_list}[-1];
|
|
Packit Service |
084de1 |
$fatal_alert = 1 if $last_record->is_fatal_alert(0);
|
|
Packit Service |
084de1 |
}
|
|
Packit Service |
084de1 |
return;
|
|
Packit Service |
084de1 |
}
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
if ($testtype == UNSOLICITED_SERVER_NAME_TLS13) {
|
|
Packit Service |
084de1 |
return if (!defined($message = ${$proxy->message_list}[2]));
|
|
Packit Service |
084de1 |
die "Expecting EE message ".($message->mt).","
|
|
Packit Service |
084de1 |
.${$proxy->message_list}[1]->mt.", "
|
|
Packit Service |
084de1 |
.${$proxy->message_list}[3]->mt
|
|
Packit Service |
084de1 |
if $message->mt != TLSProxy::Message::MT_ENCRYPTED_EXTENSIONS;
|
|
Packit Service |
084de1 |
} else {
|
|
Packit Service |
084de1 |
$message = ${$proxy->message_list}[1];
|
|
Packit Service |
084de1 |
}
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
my $ext = pack "C2",
|
|
Packit Service |
084de1 |
0x00, 0x00; #Extension length
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
my $type;
|
|
Packit Service |
084de1 |
if ($testtype == UNSOLICITED_SERVER_NAME
|
|
Packit Service |
084de1 |
|| $testtype == UNSOLICITED_SERVER_NAME_TLS13) {
|
|
Packit Service |
084de1 |
$type = TLSProxy::Message::EXT_SERVER_NAME;
|
|
Packit Service |
084de1 |
} elsif ($testtype == UNSOLICITED_SCT) {
|
|
Packit Service |
084de1 |
$type = TLSProxy::Message::EXT_SCT;
|
|
Packit Service |
084de1 |
} elsif ($testtype == NONCOMPLIANT_SUPPORTED_GROUPS) {
|
|
Packit Service |
084de1 |
$type = TLSProxy::Message::EXT_SUPPORTED_GROUPS;
|
|
Packit Service |
084de1 |
}
|
|
Packit Service |
084de1 |
$message->set_extension($type, $ext);
|
|
Packit Service |
084de1 |
$message->repack();
|
|
Packit Service |
084de1 |
$sent_unsolisited_extension = 1;
|
|
Packit Service |
084de1 |
}
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
sub inject_cryptopro_extension
|
|
Packit Service |
084de1 |
{
|
|
Packit Service |
084de1 |
my $proxy = shift;
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
# We're only interested in the initial ClientHello
|
|
Packit Service |
084de1 |
if ($proxy->flight != 0) {
|
|
Packit Service |
084de1 |
return;
|
|
Packit Service |
084de1 |
}
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
my $message = ${$proxy->message_list}[0];
|
|
Packit Service |
084de1 |
$message->set_extension(TLSProxy::Message::EXT_CRYPTOPRO_BUG_EXTENSION, "");
|
|
Packit Service |
084de1 |
$message->repack();
|
|
Packit Service |
084de1 |
}
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
# Test 1-2: Sending a duplicate extension should fail.
|
|
Packit Service |
084de1 |
$proxy->start() or plan skip_all => "Unable to start up Proxy for tests";
|
|
Packit Service |
084de1 |
plan tests => 8;
|
|
Packit Service |
084de1 |
ok($fatal_alert, "Duplicate ClientHello extension");
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
$fatal_alert = 0;
|
|
Packit Service |
084de1 |
$proxy->clear();
|
|
Packit Service |
084de1 |
$proxy->filter(\&inject_duplicate_extension_serverhello);
|
|
Packit Service |
084de1 |
$proxy->start();
|
|
Packit Service |
084de1 |
ok($fatal_alert, "Duplicate ServerHello extension");
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
SKIP: {
|
|
Packit Service |
084de1 |
skip "TLS <= 1.2 disabled", 3 if $no_below_tls13;
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
#Test 3: Sending a zero length extension block should pass
|
|
Packit Service |
084de1 |
$proxy->clear();
|
|
Packit Service |
084de1 |
$proxy->filter(\&extension_filter);
|
|
Packit Service |
084de1 |
$proxy->start();
|
|
Packit Service |
084de1 |
ok(TLSProxy::Message->success, "Zero extension length test");
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
#Test 4: Inject an unsolicited extension (<= TLSv1.2)
|
|
Packit Service |
084de1 |
$fatal_alert = 0;
|
|
Packit Service |
084de1 |
$proxy->clear();
|
|
Packit Service |
084de1 |
$proxy->filter(\&inject_unsolicited_extension);
|
|
Packit Service |
084de1 |
$testtype = UNSOLICITED_SERVER_NAME;
|
|
Packit Service |
084de1 |
$proxy->clientflags("-no_tls1_3 -noservername");
|
|
Packit Service |
084de1 |
$proxy->start();
|
|
Packit Service |
084de1 |
ok($fatal_alert, "Unsolicited server name extension");
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
#Test 5: Inject a noncompliant supported_groups extension (<= TLSv1.2)
|
|
Packit Service |
084de1 |
$proxy->clear();
|
|
Packit Service |
084de1 |
$proxy->filter(\&inject_unsolicited_extension);
|
|
Packit Service |
084de1 |
$testtype = NONCOMPLIANT_SUPPORTED_GROUPS;
|
|
Packit Service |
084de1 |
$proxy->clientflags("-no_tls1_3");
|
|
Packit Service |
084de1 |
$proxy->start();
|
|
Packit Service |
084de1 |
ok(TLSProxy::Message->success(), "Noncompliant supported_groups extension");
|
|
Packit Service |
084de1 |
}
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
SKIP: {
|
|
Packit Service |
084de1 |
skip "TLS <= 1.2 or CT disabled", 1
|
|
Packit Service |
084de1 |
if $no_below_tls13 || disabled("ct");
|
|
Packit Service |
084de1 |
#Test 6: Same as above for the SCT extension which has special handling
|
|
Packit Service |
084de1 |
$fatal_alert = 0;
|
|
Packit Service |
084de1 |
$proxy->clear();
|
|
Packit Service |
084de1 |
$testtype = UNSOLICITED_SCT;
|
|
Packit Service |
084de1 |
$proxy->clientflags("-no_tls1_3");
|
|
Packit Service |
084de1 |
$proxy->start();
|
|
Packit Service |
084de1 |
ok($fatal_alert, "Unsolicited sct extension");
|
|
Packit Service |
084de1 |
}
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
SKIP: {
|
|
Packit Service |
084de1 |
skip "TLS 1.3 disabled", 1 if disabled("tls1_3");
|
|
Packit Service |
084de1 |
#Test 7: Inject an unsolicited extension (TLSv1.3)
|
|
Packit Service |
084de1 |
$fatal_alert = 0;
|
|
Packit Service |
084de1 |
$proxy->clear();
|
|
Packit Service |
084de1 |
$proxy->filter(\&inject_unsolicited_extension);
|
|
Packit Service |
084de1 |
$testtype = UNSOLICITED_SERVER_NAME_TLS13;
|
|
Packit Service |
084de1 |
$proxy->clientflags("-noservername");
|
|
Packit Service |
084de1 |
$proxy->start();
|
|
Packit Service |
084de1 |
ok($fatal_alert, "Unsolicited server name extension (TLSv1.3)");
|
|
Packit Service |
084de1 |
}
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
#Test 8: Send the cryptopro extension in a ClientHello. Normally this is an
|
|
Packit Service |
084de1 |
# unsolicited extension only ever seen in the ServerHello. We should
|
|
Packit Service |
084de1 |
# ignore it in a ClientHello
|
|
Packit Service |
084de1 |
$proxy->clear();
|
|
Packit Service |
084de1 |
$proxy->filter(\&inject_cryptopro_extension);
|
|
Packit Service |
084de1 |
$proxy->start();
|
|
Packit Service |
084de1 |
ok(TLSProxy::Message->success(), "Cryptopro extension in ClientHello");
|