2016-04-22 19:21:51 +08:00
|
|
|
#! /usr/bin/env perl
|
2018-02-13 20:51:29 +08:00
|
|
|
# Copyright 2015-2018 The OpenSSL Project Authors. All Rights Reserved.
|
2015-12-08 00:09:13 +08:00
|
|
|
#
|
2016-04-22 19:21:51 +08: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-12-08 00:09:13 +08:00
|
|
|
|
|
|
|
use strict;
|
2016-01-30 08:05:33 +08:00
|
|
|
use OpenSSL::Test qw/:DEFAULT cmdstr srctop_file bldtop_dir/;
|
2016-01-17 07:25:44 +08:00
|
|
|
use OpenSSL::Test::Utils;
|
2015-12-08 00:09:13 +08:00
|
|
|
use TLSProxy::Proxy;
|
|
|
|
use File::Temp qw(tempfile);
|
|
|
|
|
|
|
|
my $test_name = "test_tlsextms";
|
|
|
|
setup($test_name);
|
|
|
|
|
2016-01-13 10:53:47 +08:00
|
|
|
plan skip_all => "TLSProxy isn't usable on $^O"
|
2018-01-17 17:39:28 +08:00
|
|
|
if $^O =~ /^(VMS)$/;
|
2016-01-13 10:53:47 +08:00
|
|
|
|
2016-02-20 05:13:11 +08:00
|
|
|
plan skip_all => "$test_name needs the dynamic engine feature enabled"
|
2016-02-22 09:06:05 +08:00
|
|
|
if disabled("engine") || disabled("dynamic-engine");
|
2015-12-08 00:09:13 +08:00
|
|
|
|
2016-03-21 23:32:40 +08:00
|
|
|
plan skip_all => "$test_name needs the sock feature enabled"
|
|
|
|
if disabled("sock");
|
|
|
|
|
2016-11-02 23:03:56 +08:00
|
|
|
plan skip_all => "$test_name needs TLSv1.0, TLSv1.1 or TLSv1.2 enabled"
|
|
|
|
if disabled("tls1") && disabled("tls1_1") && disabled("tls1_2");
|
2016-05-04 17:13:15 +08:00
|
|
|
|
2015-12-08 00:09:13 +08:00
|
|
|
$ENV{OPENSSL_ia32cap} = '~0x200000200000000';
|
|
|
|
|
|
|
|
sub checkmessages($$$$$);
|
|
|
|
sub setrmextms($$);
|
|
|
|
sub clearall();
|
|
|
|
|
|
|
|
my $crmextms = 0;
|
|
|
|
my $srmextms = 0;
|
|
|
|
my $cextms = 0;
|
|
|
|
my $sextms = 0;
|
|
|
|
my $fullhand = 0;
|
|
|
|
|
|
|
|
my $proxy = TLSProxy::Proxy->new(
|
|
|
|
\&extms_filter,
|
2016-04-01 21:09:28 +08:00
|
|
|
cmdstr(app(["openssl"]), display => 1),
|
2016-01-30 08:05:33 +08:00
|
|
|
srctop_file("apps", "server.pem"),
|
2016-02-13 01:26:16 +08:00
|
|
|
(!$ENV{HARNESS_ACTIVE} || $ENV{HARNESS_VERBOSE})
|
2015-12-08 00:09:13 +08:00
|
|
|
);
|
|
|
|
|
2016-11-02 23:03:56 +08:00
|
|
|
#Note that EXTMS is only relevant for <TLS1.3
|
|
|
|
|
2015-12-08 00:09:13 +08:00
|
|
|
#Test 1: By default server and client should send extended master secret
|
|
|
|
# extension.
|
|
|
|
#Expected result: ClientHello extension seen; ServerHello extension seen
|
|
|
|
# Full handshake
|
|
|
|
|
|
|
|
setrmextms(0, 0);
|
2016-11-02 23:03:56 +08:00
|
|
|
$proxy->clientflags("-no_tls1_3");
|
2016-06-14 21:35:26 +08:00
|
|
|
$proxy->start() or plan skip_all => "Unable to start up Proxy for tests";
|
2016-11-02 23:03:56 +08:00
|
|
|
my $numtests = 9;
|
2016-11-14 22:53:31 +08:00
|
|
|
$numtests++ if (!disabled("tls1_3"));
|
2016-11-02 23:03:56 +08:00
|
|
|
plan tests => $numtests;
|
2015-12-08 00:09:13 +08:00
|
|
|
checkmessages(1, "Default extended master secret test", 1, 1, 1);
|
|
|
|
|
|
|
|
#Test 2: If client omits extended master secret extension, server should too.
|
|
|
|
#Expected result: ClientHello extension not seen; ServerHello extension not seen
|
|
|
|
# Full handshake
|
|
|
|
|
|
|
|
clearall();
|
|
|
|
setrmextms(1, 0);
|
2016-11-02 23:03:56 +08:00
|
|
|
$proxy->clientflags("-no_tls1_3");
|
2015-12-08 00:09:13 +08:00
|
|
|
$proxy->start();
|
|
|
|
checkmessages(2, "No client extension extended master secret test", 0, 0, 1);
|
|
|
|
|
|
|
|
# Test 3: same as 1 but with session tickets disabled.
|
|
|
|
# Expected result: same as test 1.
|
|
|
|
|
|
|
|
clearall();
|
2016-11-02 23:03:56 +08:00
|
|
|
$proxy->clientflags("-no_ticket -no_tls1_3");
|
2015-12-08 00:09:13 +08:00
|
|
|
setrmextms(0, 0);
|
|
|
|
$proxy->start();
|
|
|
|
checkmessages(3, "No ticket extended master secret test", 1, 1, 1);
|
|
|
|
|
|
|
|
# Test 4: same as 2 but with session tickets disabled.
|
|
|
|
# Expected result: same as test 2.
|
|
|
|
|
|
|
|
clearall();
|
2016-11-02 23:03:56 +08:00
|
|
|
$proxy->clientflags("-no_ticket -no_tls1_3");
|
2015-12-08 00:09:13 +08:00
|
|
|
setrmextms(1, 0);
|
|
|
|
$proxy->start();
|
2016-11-02 23:03:56 +08:00
|
|
|
checkmessages(4, "No ticket, no client extension extended master secret test", 0, 0, 1);
|
2015-12-08 00:09:13 +08:00
|
|
|
|
|
|
|
#Test 5: Session resumption extended master secret test
|
|
|
|
#
|
|
|
|
#Expected result: ClientHello extension seen; ServerHello extension seen
|
|
|
|
# Abbreviated handshake
|
|
|
|
|
|
|
|
clearall();
|
|
|
|
setrmextms(0, 0);
|
2016-06-03 19:56:20 +08:00
|
|
|
(undef, my $session) = tempfile();
|
2015-12-08 00:09:13 +08:00
|
|
|
$proxy->serverconnects(2);
|
2016-11-02 23:03:56 +08:00
|
|
|
$proxy->clientflags("-no_tls1_3 -sess_out ".$session);
|
2015-12-08 00:09:13 +08:00
|
|
|
$proxy->start();
|
2016-03-16 00:44:26 +08:00
|
|
|
$proxy->clearClient();
|
2016-11-02 23:03:56 +08:00
|
|
|
$proxy->clientflags("-no_tls1_3 -sess_in ".$session);
|
2015-12-08 00:09:13 +08:00
|
|
|
$proxy->clientstart();
|
|
|
|
checkmessages(5, "Session resumption extended master secret test", 1, 1, 0);
|
2016-06-03 19:56:20 +08:00
|
|
|
unlink $session;
|
2015-12-08 00:09:13 +08:00
|
|
|
|
2016-02-27 03:30:15 +08:00
|
|
|
#Test 6: Session resumption extended master secret test original session
|
2015-12-08 00:09:13 +08:00
|
|
|
# omits extension. Server must not resume session.
|
|
|
|
#Expected result: ClientHello extension seen; ServerHello extension seen
|
|
|
|
# Full handshake
|
|
|
|
|
|
|
|
clearall();
|
|
|
|
setrmextms(1, 0);
|
2016-06-03 19:56:20 +08:00
|
|
|
(undef, $session) = tempfile();
|
2015-12-08 00:09:13 +08:00
|
|
|
$proxy->serverconnects(2);
|
2016-11-02 23:03:56 +08:00
|
|
|
$proxy->clientflags("-no_tls1_3 -sess_out ".$session);
|
2015-12-08 00:09:13 +08:00
|
|
|
$proxy->start();
|
2016-03-16 00:44:26 +08:00
|
|
|
$proxy->clearClient();
|
2016-11-02 23:03:56 +08:00
|
|
|
$proxy->clientflags("-no_tls1_3 -sess_in ".$session);
|
2015-12-08 00:09:13 +08:00
|
|
|
setrmextms(0, 0);
|
|
|
|
$proxy->clientstart();
|
|
|
|
checkmessages(6, "Session resumption extended master secret test", 1, 1, 1);
|
2016-06-03 19:56:20 +08:00
|
|
|
unlink $session;
|
2015-12-08 00:09:13 +08:00
|
|
|
|
|
|
|
#Test 7: Session resumption extended master secret test resumed session
|
|
|
|
# omits client extension. Server must abort connection.
|
|
|
|
#Expected result: aborted connection.
|
|
|
|
|
|
|
|
clearall();
|
|
|
|
setrmextms(0, 0);
|
2016-06-03 19:56:20 +08:00
|
|
|
(undef, $session) = tempfile();
|
2015-12-08 00:09:13 +08:00
|
|
|
$proxy->serverconnects(2);
|
2016-11-02 23:03:56 +08:00
|
|
|
$proxy->clientflags("-no_tls1_3 -sess_out ".$session);
|
2015-12-08 00:09:13 +08:00
|
|
|
$proxy->start();
|
2016-03-16 00:44:26 +08:00
|
|
|
$proxy->clearClient();
|
2016-11-02 23:03:56 +08:00
|
|
|
$proxy->clientflags("-no_tls1_3 -sess_in ".$session);
|
2015-12-08 00:09:13 +08:00
|
|
|
setrmextms(1, 0);
|
|
|
|
$proxy->clientstart();
|
2016-02-27 03:30:15 +08:00
|
|
|
ok(TLSProxy::Message->fail(), "Client inconsistent session resumption");
|
2016-06-03 19:56:20 +08:00
|
|
|
unlink $session;
|
2015-12-08 00:09:13 +08:00
|
|
|
|
|
|
|
#Test 8: Session resumption extended master secret test resumed session
|
|
|
|
# omits server extension. Client must abort connection.
|
|
|
|
#Expected result: aborted connection.
|
|
|
|
|
|
|
|
clearall();
|
|
|
|
setrmextms(0, 0);
|
2016-06-03 19:56:20 +08:00
|
|
|
(undef, $session) = tempfile();
|
2015-12-08 00:09:13 +08:00
|
|
|
$proxy->serverconnects(2);
|
2016-11-02 23:03:56 +08:00
|
|
|
$proxy->clientflags("-no_tls1_3 -sess_out ".$session);
|
2015-12-08 00:09:13 +08:00
|
|
|
$proxy->start();
|
2016-03-16 00:44:26 +08:00
|
|
|
$proxy->clearClient();
|
2016-11-02 23:03:56 +08:00
|
|
|
$proxy->clientflags("-no_tls1_3 -sess_in ".$session);
|
2015-12-08 00:09:13 +08:00
|
|
|
setrmextms(0, 1);
|
|
|
|
$proxy->clientstart();
|
|
|
|
ok(TLSProxy::Message->fail(), "Server inconsistent session resumption 1");
|
2016-06-03 19:56:20 +08:00
|
|
|
unlink $session;
|
2015-12-08 00:09:13 +08:00
|
|
|
|
|
|
|
#Test 9: Session resumption extended master secret test initial session
|
|
|
|
# omits server extension. Client must abort connection.
|
|
|
|
#Expected result: aborted connection.
|
|
|
|
|
|
|
|
clearall();
|
|
|
|
setrmextms(0, 1);
|
2016-06-03 19:56:20 +08:00
|
|
|
(undef, $session) = tempfile();
|
2015-12-08 00:09:13 +08:00
|
|
|
$proxy->serverconnects(2);
|
2016-11-02 23:03:56 +08:00
|
|
|
$proxy->clientflags("-no_tls1_3 -sess_out ".$session);
|
2015-12-08 00:09:13 +08:00
|
|
|
$proxy->start();
|
2016-03-16 00:44:26 +08:00
|
|
|
$proxy->clearClient();
|
2016-11-02 23:03:56 +08:00
|
|
|
$proxy->clientflags("-no_tls1_3 -sess_in ".$session);
|
2015-12-08 00:09:13 +08:00
|
|
|
setrmextms(0, 0);
|
|
|
|
$proxy->clientstart();
|
|
|
|
ok(TLSProxy::Message->fail(), "Server inconsistent session resumption 2");
|
2016-06-03 19:56:20 +08:00
|
|
|
unlink $session;
|
2015-12-08 00:09:13 +08:00
|
|
|
|
2016-11-02 23:03:56 +08:00
|
|
|
#Test 10: In TLS1.3 we should not negotiate extended master secret
|
|
|
|
#Expected result: ClientHello extension seen; ServerHello extension not seen
|
|
|
|
# TLS1.3 handshake (will appear as abbreviated handshake
|
|
|
|
# because of no CKE message)
|
|
|
|
if (!disabled("tls1_3")) {
|
|
|
|
clearall();
|
|
|
|
setrmextms(0, 0);
|
|
|
|
$proxy->start();
|
|
|
|
checkmessages(10, "TLS1.3 extended master secret test", 1, 0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-12-08 00:09:13 +08:00
|
|
|
sub extms_filter
|
|
|
|
{
|
|
|
|
my $proxy = shift;
|
|
|
|
|
|
|
|
foreach my $message (@{$proxy->message_list}) {
|
|
|
|
if ($crmextms && $message->mt == TLSProxy::Message::MT_CLIENT_HELLO) {
|
2016-02-20 00:24:44 +08:00
|
|
|
$message->delete_extension(TLSProxy::Message::EXT_EXTENDED_MASTER_SECRET);
|
2015-12-08 00:09:13 +08:00
|
|
|
$message->repack();
|
|
|
|
}
|
|
|
|
if ($srmextms && $message->mt == TLSProxy::Message::MT_SERVER_HELLO) {
|
2016-02-20 00:24:44 +08:00
|
|
|
$message->delete_extension(TLSProxy::Message::EXT_EXTENDED_MASTER_SECRET);
|
2015-12-08 00:09:13 +08:00
|
|
|
$message->repack();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sub checkmessages($$$$$)
|
|
|
|
{
|
|
|
|
my ($testno, $testname, $testcextms, $testsextms, $testhand) = @_;
|
|
|
|
|
|
|
|
subtest $testname => sub {
|
|
|
|
|
|
|
|
foreach my $message (@{$proxy->message_list}) {
|
|
|
|
if ($message->mt == TLSProxy::Message::MT_CLIENT_HELLO
|
|
|
|
|| $message->mt == TLSProxy::Message::MT_SERVER_HELLO) {
|
|
|
|
#Get the extensions data
|
|
|
|
my %extensions = %{$message->extension_data};
|
|
|
|
if (defined
|
2016-02-20 00:24:44 +08:00
|
|
|
$extensions{TLSProxy::Message::EXT_EXTENDED_MASTER_SECRET}) {
|
2015-12-08 00:09:13 +08:00
|
|
|
if ($message->mt == TLSProxy::Message::MT_CLIENT_HELLO) {
|
|
|
|
$cextms = 1;
|
|
|
|
} else {
|
|
|
|
$sextms = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} elsif ($message->mt == TLSProxy::Message::MT_CLIENT_KEY_EXCHANGE) {
|
|
|
|
#Must be doing a full handshake
|
|
|
|
$fullhand = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
plan tests => 4;
|
|
|
|
|
|
|
|
ok(TLSProxy::Message->success, "Handshake");
|
|
|
|
|
|
|
|
ok($testcextms == $cextms,
|
|
|
|
"ClientHello extension extended master secret check");
|
|
|
|
ok($testsextms == $sextms,
|
|
|
|
"ServerHello extension extended master secret check");
|
|
|
|
ok($testhand == $fullhand,
|
|
|
|
"Extended master secret full handshake check");
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sub setrmextms($$)
|
|
|
|
{
|
|
|
|
($crmextms, $srmextms) = @_;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub clearall()
|
|
|
|
{
|
|
|
|
$cextms = 0;
|
|
|
|
$sextms = 0;
|
|
|
|
$fullhand = 0;
|
|
|
|
$proxy->clear();
|
|
|
|
}
|