1 | #! /usr/bin/env perl
|
---|
2 | # Copyright 2018-2021 The OpenSSL Project Authors. All Rights Reserved.
|
---|
3 | #
|
---|
4 | # Licensed under the Apache License 2.0 (the "License"). You may not use
|
---|
5 | # this file except in compliance with the License. You can obtain a copy
|
---|
6 | # in the file LICENSE in the source distribution or at
|
---|
7 | # https://www.openssl.org/source/license.html
|
---|
8 |
|
---|
9 | use strict;
|
---|
10 | use OpenSSL::Test qw/:DEFAULT cmdstr srctop_file bldtop_dir/;
|
---|
11 | use OpenSSL::Test::Utils;
|
---|
12 | use TLSProxy::Proxy;
|
---|
13 |
|
---|
14 | my $test_name = "test_tls13alerts";
|
---|
15 | setup($test_name);
|
---|
16 |
|
---|
17 | plan skip_all => "TLSProxy isn't usable on $^O"
|
---|
18 | if $^O =~ /^(VMS)$/;
|
---|
19 |
|
---|
20 | plan skip_all => "$test_name needs the dynamic engine feature enabled"
|
---|
21 | if disabled("engine") || disabled("dynamic-engine");
|
---|
22 |
|
---|
23 | plan skip_all => "$test_name needs the sock feature enabled"
|
---|
24 | if disabled("sock");
|
---|
25 |
|
---|
26 | plan skip_all => "$test_name needs TLS1.3 enabled"
|
---|
27 | if disabled("tls1_3") || (disabled("ec") && disabled("dh"));
|
---|
28 |
|
---|
29 | $ENV{OPENSSL_ia32cap} = '~0x200000200000000';
|
---|
30 |
|
---|
31 | my $proxy = TLSProxy::Proxy->new(
|
---|
32 | undef,
|
---|
33 | cmdstr(app(["openssl"]), display => 1),
|
---|
34 | srctop_file("apps", "server.pem"),
|
---|
35 | (!$ENV{HARNESS_ACTIVE} || $ENV{HARNESS_VERBOSE})
|
---|
36 | );
|
---|
37 |
|
---|
38 | #Test 1: We test that a server can handle an unencrypted alert when normally the
|
---|
39 | # next message is encrypted
|
---|
40 | $proxy->filter(\&alert_filter);
|
---|
41 | $proxy->start() or plan skip_all => "Unable to start up Proxy for tests";
|
---|
42 | plan tests => 1;
|
---|
43 | my $alert = TLSProxy::Message->alert();
|
---|
44 | ok(TLSProxy::Message->fail() && !$alert->server() && !$alert->encrypted(), "Client sends an unecrypted alert");
|
---|
45 |
|
---|
46 | sub alert_filter
|
---|
47 | {
|
---|
48 | my $proxy = shift;
|
---|
49 |
|
---|
50 | if ($proxy->flight != 1) {
|
---|
51 | return;
|
---|
52 | }
|
---|
53 |
|
---|
54 | ${$proxy->message_list}[1]->session_id_len(1);
|
---|
55 | ${$proxy->message_list}[1]->repack();
|
---|
56 | }
|
---|