]>
git.ipfire.org Git - thirdparty/openssl.git/blob - test/recipes/70-test_tls13cookie.t
2 # Copyright 2017-2018 The OpenSSL Project Authors. All Rights Reserved.
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
10 use OpenSSL
::Test qw
/:DEFAULT cmdstr srctop_file bldtop_dir/;
11 use OpenSSL
::Test
::Utils
;
14 my $test_name = "test_tls13cookie";
17 plan skip_all
=> "TLSProxy isn't usable on $^O"
20 plan skip_all
=> "$test_name needs the dynamic engine feature enabled"
21 if disabled
("engine") || disabled
("dynamic-engine");
23 plan skip_all
=> "$test_name needs the sock feature enabled"
26 plan skip_all
=> "$test_name needs TLS1.3 enabled"
27 if disabled
("tls1_3");
29 $ENV{OPENSSL_ia32cap
} = '~0x200000200000000';
33 COOKIE_AND_KEY_SHARE
=> 1
36 my $proxy = TLSProxy
::Proxy
->new(
38 cmdstr
(app
(["openssl"]), display
=> 1),
39 srctop_file
("apps", "server.pem"),
40 (!$ENV{HARNESS_ACTIVE
} || $ENV{HARNESS_VERBOSE
})
46 #Test 1: Inserting a cookie into an HRR should see it echoed in the ClientHello
47 $testtype = COOKIE_ONLY
;
48 $proxy->filter(\
&cookie_filter
);
49 $proxy->serverflags("-curves X25519") if !disabled
("ec");
50 $proxy->start() or plan skip_all
=> "Unable to start up Proxy for tests";
53 skip
"EC disabled", 1, if disabled
("ec");
54 ok
(TLSProxy
::Message
->success() && $cookieseen == 1, "Cookie seen");
59 #Test 2: Same as test 1 but should also work where a new key_share is also
61 $testtype = COOKIE_AND_KEY_SHARE
;
64 $proxy->clientflags("-curves ffdhe3072:ffdhe2048");
65 $proxy->serverflags("-curves ffdhe2048");
67 $proxy->clientflags("-curves P-256:X25519");
68 $proxy->serverflags("-curves X25519");
71 ok
(TLSProxy
::Message
->success() && $cookieseen == 1, "Cookie seen");
77 # We're only interested in the HRR and both ClientHellos
78 return if ($proxy->flight > 2);
81 0x00, 0x06, #Cookie Length
82 0x00, 0x01, #Dummy cookie data (6 bytes)
86 foreach my $message (@
{$proxy->message_list}) {
87 if ($message->mt == TLSProxy
::Message
::MT_SERVER_HELLO
88 && ${$message->records}[0]->flight == 1) {
89 $message->delete_extension(TLSProxy
::Message
::EXT_KEY_SHARE
)
90 if ($testtype == COOKIE_ONLY
);
91 $message->set_extension(TLSProxy
::Message
::EXT_COOKIE
, $ext);
93 } elsif ($message->mt == TLSProxy
::Message
::MT_CLIENT_HELLO
) {
94 if (${$message->records}[0]->flight == 0) {
95 if ($testtype == COOKIE_ONLY
) {
97 0x00, 0x05, #List Length
99 0x00, 0x01, #key_exchange data length
100 0xff; #Dummy key_share data
101 # Trick the server into thinking we got an unacceptable
103 $message->set_extension(
104 TLSProxy
::Message
::EXT_KEY_SHARE
, $ext);
108 #cmp can behave differently dependent on locale
111 $message->extension_data->{TLSProxy
::Message
::EXT_COOKIE
};
113 return if !defined($cookie);
115 return if ($cookie cmp $ext) != 0;