2016-04-22 11:21:51 +00:00
|
|
|
#! /usr/bin/env perl
|
|
|
|
# Copyright 2015-2016 The OpenSSL Project Authors. All Rights Reserved.
|
2015-12-07 16:09:13 +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-12-07 16:09:13 +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-12-07 16:09:13 +00:00
|
|
|
use TLSProxy::Proxy;
|
|
|
|
use File::Temp qw(tempfile);
|
|
|
|
|
|
|
|
my $test_name = "test_tlsextms";
|
|
|
|
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-12-07 16:09:13 +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-12-07 16:09:13 +00: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 13:09:28 +00:00
|
|
|
cmdstr(app(["openssl"]), display => 1),
|
2016-01-30 00:05:33 +00:00
|
|
|
srctop_file("apps", "server.pem"),
|
2016-02-12 17:26:16 +00:00
|
|
|
(!$ENV{HARNESS_ACTIVE} || $ENV{HARNESS_VERBOSE})
|
2015-12-07 16:09:13 +00: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-06-14 13:35:26 +00:00
|
|
|
$proxy->start() or plan skip_all => "Unable to start up Proxy for tests";
|
|
|
|
plan tests => 9;
|
2015-12-07 16:09:13 +00: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);
|
|
|
|
$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();
|
|
|
|
$proxy->clientflags("-no_ticket");
|
|
|
|
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();
|
|
|
|
$proxy->clientflags("-no_ticket");
|
|
|
|
setrmextms(1, 0);
|
|
|
|
$proxy->start();
|
|
|
|
checkmessages(2, "No ticket, no client extension extended master secret test", 0, 0, 1);
|
|
|
|
|
|
|
|
#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 11:56:20 +00:00
|
|
|
(undef, my $session) = tempfile();
|
2015-12-07 16:09:13 +00:00
|
|
|
$proxy->serverconnects(2);
|
|
|
|
$proxy->clientflags("-sess_out ".$session);
|
|
|
|
$proxy->start();
|
2016-03-15 16:44:26 +00:00
|
|
|
$proxy->clearClient();
|
2015-12-07 16:09:13 +00:00
|
|
|
$proxy->clientflags("-sess_in ".$session);
|
|
|
|
$proxy->clientstart();
|
|
|
|
checkmessages(5, "Session resumption extended master secret test", 1, 1, 0);
|
2016-06-03 11:56:20 +00:00
|
|
|
unlink $session;
|
2015-12-07 16:09:13 +00:00
|
|
|
|
2016-02-26 19:30:15 +00:00
|
|
|
#Test 6: Session resumption extended master secret test original session
|
2015-12-07 16:09:13 +00: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 11:56:20 +00:00
|
|
|
(undef, $session) = tempfile();
|
2015-12-07 16:09:13 +00:00
|
|
|
$proxy->serverconnects(2);
|
|
|
|
$proxy->clientflags("-sess_out ".$session);
|
|
|
|
$proxy->start();
|
2016-03-15 16:44:26 +00:00
|
|
|
$proxy->clearClient();
|
2015-12-07 16:09:13 +00:00
|
|
|
$proxy->clientflags("-sess_in ".$session);
|
|
|
|
setrmextms(0, 0);
|
|
|
|
$proxy->clientstart();
|
|
|
|
checkmessages(6, "Session resumption extended master secret test", 1, 1, 1);
|
2016-06-03 11:56:20 +00:00
|
|
|
unlink $session;
|
2015-12-07 16:09:13 +00: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 11:56:20 +00:00
|
|
|
(undef, $session) = tempfile();
|
2015-12-07 16:09:13 +00:00
|
|
|
$proxy->serverconnects(2);
|
|
|
|
$proxy->clientflags("-sess_out ".$session);
|
|
|
|
$proxy->start();
|
2016-03-15 16:44:26 +00:00
|
|
|
$proxy->clearClient();
|
2015-12-07 16:09:13 +00:00
|
|
|
$proxy->clientflags("-sess_in ".$session);
|
|
|
|
setrmextms(1, 0);
|
|
|
|
$proxy->clientstart();
|
2016-02-26 19:30:15 +00:00
|
|
|
ok(TLSProxy::Message->fail(), "Client inconsistent session resumption");
|
2016-06-03 11:56:20 +00:00
|
|
|
unlink $session;
|
2015-12-07 16:09:13 +00: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 11:56:20 +00:00
|
|
|
(undef, $session) = tempfile();
|
2015-12-07 16:09:13 +00:00
|
|
|
$proxy->serverconnects(2);
|
|
|
|
$proxy->clientflags("-sess_out ".$session);
|
|
|
|
$proxy->start();
|
2016-03-15 16:44:26 +00:00
|
|
|
$proxy->clearClient();
|
2015-12-07 16:09:13 +00:00
|
|
|
$proxy->clientflags("-sess_in ".$session);
|
|
|
|
setrmextms(0, 1);
|
|
|
|
$proxy->clientstart();
|
|
|
|
ok(TLSProxy::Message->fail(), "Server inconsistent session resumption 1");
|
2016-06-03 11:56:20 +00:00
|
|
|
unlink $session;
|
2015-12-07 16:09:13 +00: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 11:56:20 +00:00
|
|
|
(undef, $session) = tempfile();
|
2015-12-07 16:09:13 +00:00
|
|
|
$proxy->serverconnects(2);
|
|
|
|
$proxy->clientflags("-sess_out ".$session);
|
|
|
|
$proxy->start();
|
2016-03-15 16:44:26 +00:00
|
|
|
$proxy->clearClient();
|
2015-12-07 16:09:13 +00:00
|
|
|
$proxy->clientflags("-sess_in ".$session);
|
|
|
|
setrmextms(0, 0);
|
|
|
|
$proxy->clientstart();
|
|
|
|
ok(TLSProxy::Message->fail(), "Server inconsistent session resumption 2");
|
2016-06-03 11:56:20 +00:00
|
|
|
unlink $session;
|
2015-12-07 16:09:13 +00:00
|
|
|
|
|
|
|
sub extms_filter
|
|
|
|
{
|
|
|
|
my $proxy = shift;
|
|
|
|
|
|
|
|
foreach my $message (@{$proxy->message_list}) {
|
|
|
|
if ($crmextms && $message->mt == TLSProxy::Message::MT_CLIENT_HELLO) {
|
2016-02-19 16:24:44 +00:00
|
|
|
$message->delete_extension(TLSProxy::Message::EXT_EXTENDED_MASTER_SECRET);
|
2015-12-07 16:09:13 +00:00
|
|
|
$message->repack();
|
|
|
|
}
|
|
|
|
if ($srmextms && $message->mt == TLSProxy::Message::MT_SERVER_HELLO) {
|
2016-02-19 16:24:44 +00:00
|
|
|
$message->delete_extension(TLSProxy::Message::EXT_EXTENDED_MASTER_SECRET);
|
2015-12-07 16:09:13 +00: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-19 16:24:44 +00:00
|
|
|
$extensions{TLSProxy::Message::EXT_EXTENDED_MASTER_SECRET}) {
|
2015-12-07 16:09:13 +00: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();
|
|
|
|
}
|