2017-03-10 21:54:32 +08:00
|
|
|
#! /usr/bin/env perl
|
2018-02-13 20:51:29 +08:00
|
|
|
# Copyright 2017-2018 The OpenSSL Project Authors. All Rights Reserved.
|
2017-03-10 21:54:32 +08:00
|
|
|
#
|
2018-12-06 20:05:25 +08:00
|
|
|
# Licensed under the Apache License 2.0 (the "License"). You may not use
|
2017-03-10 21:54:32 +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 srctop_dir bldtop_dir/;
|
|
|
|
use OpenSSL::Test::Utils;
|
|
|
|
use File::Temp qw(tempfile);
|
|
|
|
use TLSProxy::Proxy;
|
|
|
|
|
|
|
|
my $test_name = "test_tls13psk";
|
|
|
|
setup($test_name);
|
|
|
|
|
|
|
|
plan skip_all => "TLSProxy isn't usable on $^O"
|
2018-01-17 17:39:28 +08:00
|
|
|
if $^O =~ /^(VMS)$/;
|
2017-03-10 21:54:32 +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 TLSv1.3 enabled"
|
|
|
|
if disabled("tls1_3");
|
|
|
|
|
|
|
|
$ENV{OPENSSL_ia32cap} = '~0x200000200000000';
|
|
|
|
$ENV{CTLOG_FILE} = srctop_file("test", "ct", "log_list.conf");
|
|
|
|
|
|
|
|
my $proxy = TLSProxy::Proxy->new(
|
|
|
|
undef,
|
|
|
|
cmdstr(app(["openssl"]), display => 1),
|
|
|
|
srctop_file("apps", "server.pem"),
|
|
|
|
(!$ENV{HARNESS_ACTIVE} || $ENV{HARNESS_VERBOSE})
|
|
|
|
);
|
|
|
|
|
2017-03-16 02:44:05 +08:00
|
|
|
use constant {
|
|
|
|
PSK_LAST_FIRST_CH => 0,
|
|
|
|
ILLEGAL_EXT_SECOND_CH => 1
|
|
|
|
};
|
|
|
|
|
2017-05-16 19:05:57 +08:00
|
|
|
#Most PSK tests are done in test_ssl_new. This tests various failure scenarios
|
|
|
|
#around PSK
|
2017-03-10 21:54:32 +08:00
|
|
|
|
|
|
|
#Test 1: First get a session
|
|
|
|
(undef, my $session) = tempfile();
|
|
|
|
$proxy->clientflags("-sess_out ".$session);
|
2017-08-01 22:46:29 +08:00
|
|
|
$proxy->serverflags("-servername localhost");
|
2017-03-10 21:54:32 +08:00
|
|
|
$proxy->sessionfile($session);
|
|
|
|
$proxy->start() or plan skip_all => "Unable to start up Proxy for tests";
|
2017-05-16 19:05:57 +08:00
|
|
|
plan tests => 5;
|
2017-03-10 21:54:32 +08:00
|
|
|
ok(TLSProxy::Message->success(), "Initial connection");
|
|
|
|
|
|
|
|
#Test 2: Attempt a resume with PSK not in last place. Should fail
|
|
|
|
$proxy->clear();
|
|
|
|
$proxy->clientflags("-sess_in ".$session);
|
|
|
|
$proxy->filter(\&modify_psk_filter);
|
2017-03-16 02:44:05 +08:00
|
|
|
my $testtype = PSK_LAST_FIRST_CH;
|
2017-03-10 21:54:32 +08:00
|
|
|
$proxy->start();
|
|
|
|
ok(TLSProxy::Message->fail(), "PSK not last");
|
|
|
|
|
2017-03-16 02:44:05 +08:00
|
|
|
#Test 3: Attempt a resume after an HRR where PSK hash matches selected
|
2018-02-16 22:45:32 +08:00
|
|
|
# ciphersuite. Should see PSK on second ClientHello
|
2017-03-16 02:44:05 +08:00
|
|
|
$proxy->clear();
|
|
|
|
$proxy->clientflags("-sess_in ".$session);
|
2019-06-13 18:06:12 +08:00
|
|
|
if (disabled("ec")) {
|
|
|
|
$proxy->serverflags("-curves ffdhe3072");
|
|
|
|
} else {
|
|
|
|
$proxy->serverflags("-curves P-256");
|
|
|
|
}
|
2017-03-16 02:44:05 +08:00
|
|
|
$proxy->filter(undef);
|
|
|
|
$proxy->start();
|
|
|
|
#Check if the PSK is present in the second ClientHello
|
|
|
|
my $ch2 = ${$proxy->message_list}[2];
|
|
|
|
my $ch2seen = defined $ch2 && $ch2->mt() == TLSProxy::Message::MT_CLIENT_HELLO;
|
|
|
|
my $pskseen = $ch2seen
|
|
|
|
&& defined ${$ch2->{extension_data}}{TLSProxy::Message::EXT_PSK};
|
|
|
|
ok($pskseen, "PSK hash matches");
|
|
|
|
|
|
|
|
#Test 4: Attempt a resume after an HRR where PSK hash does not match selected
|
|
|
|
# ciphersuite. Should not see PSK on second ClientHello
|
|
|
|
$proxy->clear();
|
|
|
|
$proxy->clientflags("-sess_in ".$session);
|
|
|
|
$proxy->filter(\&modify_psk_filter);
|
2019-06-13 18:06:12 +08:00
|
|
|
if (disabled("ec")) {
|
|
|
|
$proxy->serverflags("-curves ffdhe3072");
|
|
|
|
} else {
|
|
|
|
$proxy->serverflags("-curves P-256");
|
|
|
|
}
|
2018-02-16 19:26:02 +08:00
|
|
|
$proxy->ciphersuitesc("TLS_AES_128_GCM_SHA256:TLS_AES_256_GCM_SHA384");
|
|
|
|
$proxy->ciphersuitess("TLS_AES_256_GCM_SHA384");
|
2017-03-16 02:44:05 +08:00
|
|
|
#We force an early failure because TLS Proxy doesn't actually support
|
2018-02-16 19:26:02 +08:00
|
|
|
#TLS_AES_256_GCM_SHA384. That doesn't matter for this test though.
|
2017-03-16 02:44:05 +08:00
|
|
|
$testtype = ILLEGAL_EXT_SECOND_CH;
|
|
|
|
$proxy->start();
|
|
|
|
#Check if the PSK is present in the second ClientHello
|
|
|
|
$ch2 = ${$proxy->message_list}[2];
|
|
|
|
$ch2seen = defined $ch2 && $ch2->mt() == TLSProxy::Message::MT_CLIENT_HELLO;
|
|
|
|
$pskseen = $ch2seen
|
|
|
|
&& defined ${$ch2->extension_data}{TLSProxy::Message::EXT_PSK};
|
|
|
|
ok($ch2seen && !$pskseen, "PSK hash does not match");
|
|
|
|
|
2017-05-16 19:05:57 +08:00
|
|
|
#Test 5: Attempt a resume without a sig agls extension. Should succeed because
|
|
|
|
# sig algs is not needed in a resumption.
|
|
|
|
$proxy->clear();
|
|
|
|
$proxy->clientflags("-sess_in ".$session);
|
|
|
|
$proxy->filter(\&remove_sig_algs_filter);
|
|
|
|
$proxy->start();
|
|
|
|
ok(TLSProxy::Message->success(), "Remove sig algs");
|
2017-03-16 02:44:05 +08:00
|
|
|
|
2017-03-10 21:54:32 +08:00
|
|
|
unlink $session;
|
|
|
|
|
|
|
|
sub modify_psk_filter
|
|
|
|
{
|
|
|
|
my $proxy = shift;
|
2017-03-16 02:44:05 +08:00
|
|
|
my $flight;
|
|
|
|
my $message;
|
|
|
|
|
|
|
|
if ($testtype == PSK_LAST_FIRST_CH) {
|
|
|
|
$flight = 0;
|
|
|
|
} else {
|
|
|
|
$flight = 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
# Only look at the first or second ClientHello
|
|
|
|
return if $proxy->flight != $flight;
|
|
|
|
|
|
|
|
if ($testtype == PSK_LAST_FIRST_CH) {
|
|
|
|
$message = ${$proxy->message_list}[0];
|
|
|
|
} else {
|
|
|
|
$message = ${$proxy->message_list}[2];
|
|
|
|
}
|
2017-03-10 21:54:32 +08:00
|
|
|
|
2017-03-16 02:44:05 +08:00
|
|
|
return if (!defined $message
|
|
|
|
|| $message->mt != TLSProxy::Message::MT_CLIENT_HELLO);
|
2017-03-10 21:54:32 +08:00
|
|
|
|
2017-03-16 02:44:05 +08:00
|
|
|
if ($testtype == PSK_LAST_FIRST_CH) {
|
|
|
|
$message->set_extension(TLSProxy::Message::EXT_FORCE_LAST, "");
|
|
|
|
} else {
|
|
|
|
#Deliberately break the connection
|
|
|
|
$message->set_extension(TLSProxy::Message::EXT_SUPPORTED_GROUPS, "");
|
2017-03-10 21:54:32 +08:00
|
|
|
}
|
2017-03-16 02:44:05 +08:00
|
|
|
$message->repack();
|
2017-03-10 21:54:32 +08:00
|
|
|
}
|
2017-05-16 19:05:57 +08:00
|
|
|
|
|
|
|
sub remove_sig_algs_filter
|
|
|
|
{
|
|
|
|
my $proxy = shift;
|
|
|
|
my $message;
|
|
|
|
|
|
|
|
# Only look at the first ClientHello
|
|
|
|
return if $proxy->flight != 0;
|
|
|
|
|
|
|
|
$message = ${$proxy->message_list}[0];
|
|
|
|
$message->delete_extension(TLSProxy::Message::EXT_SIG_ALGS);
|
|
|
|
$message->repack();
|
|
|
|
}
|