70-test_sslvertol.t 2.1 KB
Newer Older
R
Rich Salz 已提交
1 2
#! /usr/bin/env perl
# Copyright 2015-2016 The OpenSSL Project Authors. All Rights Reserved.
M
Matt Caswell 已提交
3
#
R
Rich Salz 已提交
4 5 6 7
# 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
M
Matt Caswell 已提交
8 9

use strict;
10
use OpenSSL::Test qw/:DEFAULT cmdstr srctop_file bldtop_dir/;
11
use OpenSSL::Test::Utils;
M
Matt Caswell 已提交
12 13
use TLSProxy::Proxy;

14 15 16
my $test_name = "test_sslextension";
setup($test_name);

17
plan skip_all => "TLSProxy isn't usable on $^O"
18
    if $^O =~ /^(VMS|MSWin32)$/;
19

20
plan skip_all => "$test_name needs the dynamic engine feature enabled"
21
    if disabled("engine") || disabled("dynamic-engine");
22

M
Matt Caswell 已提交
23 24 25
plan skip_all => "$test_name needs the sock feature enabled"
    if disabled("sock");

M
Matt Caswell 已提交
26 27 28
plan skip_all => "$test_name needs TLS enabled"
    if alldisabled(available_protocols("tls"));

29
$ENV{OPENSSL_ia32cap} = '~0x200000200000000';
M
Matt Caswell 已提交
30 31
my $proxy = TLSProxy::Proxy->new(
    \&vers_tolerance_filter,
32
    cmdstr(app(["openssl"]), display => 1),
33 34
    srctop_file("apps", "server.pem"),
    (!$ENV{HARNESS_ACTIVE} || $ENV{HARNESS_VERBOSE})
M
Matt Caswell 已提交
35 36
);

37 38
plan tests => 2;

M
Matt Caswell 已提交
39 40 41
#Test 1: Asking for TLS1.3 should pass
my $client_version = TLSProxy::Record::VERS_TLS_1_3;
$proxy->start();
42
ok(TLSProxy::Message->success(), "Version tolerance test, TLS 1.3");
M
Matt Caswell 已提交
43 44 45

#Test 2: Testing something below SSLv3 should fail
$client_version = TLSProxy::Record::VERS_SSL_3_0 - 1;
M
Matt Caswell 已提交
46 47
$proxy->clear();
$proxy->start();
48
ok(TLSProxy::Message->fail(), "Version tolerance test, SSL < 3.0");
M
Matt Caswell 已提交
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68

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
            #Anything above the max supported version (TLS1.2) should succeed
            #Anything below SSLv3 should fail
            $message->client_version($client_version);
            $message->repack();
        }
    }
}