2 # Copyright 2017-2018 The OpenSSL Project Authors. All Rights Reserved.
4 # Licensed under the OpenSSL license (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");
50 $proxy->start() or plan skip_all => "Unable to start up Proxy for tests";
52 ok(TLSProxy::Message->success() && $cookieseen == 1, "Cookie seen");
54 #Test 2: Same as test 1 but should also work where a new key_share is also
56 $testtype = COOKIE_AND_KEY_SHARE;
58 $proxy->clientflags("-curves P-256:X25519");
59 $proxy->serverflags("-curves X25519");
61 ok(TLSProxy::Message->success() && $cookieseen == 1, "Cookie seen");
67 # We're only interested in the HRR and both ClientHellos
68 return if ($proxy->flight > 2);
71 0x00, 0x06, #Cookie Length
72 0x00, 0x01, #Dummy cookie data (6 bytes)
76 foreach my $message (@{$proxy->message_list}) {
77 if ($message->mt == TLSProxy::Message::MT_SERVER_HELLO
78 && ${$message->records}[0]->flight == 1) {
79 $message->delete_extension(TLSProxy::Message::EXT_KEY_SHARE)
80 if ($testtype == COOKIE_ONLY);
81 $message->set_extension(TLSProxy::Message::EXT_COOKIE, $ext);
83 } elsif ($message->mt == TLSProxy::Message::MT_CLIENT_HELLO) {
84 if (${$message->records}[0]->flight == 0) {
85 if ($testtype == COOKIE_ONLY) {
87 0x00, 0x05, #List Length
89 0x00, 0x01, #key_exchange data length
90 0xff; #Dummy key_share data
91 # Trick the server into thinking we got an unacceptable
93 $message->set_extension(
94 TLSProxy::Message::EXT_KEY_SHARE, $ext);
98 #cmp can behave differently dependent on locale
101 $message->extension_data->{TLSProxy::Message::EXT_COOKIE};
103 return if !defined($cookie);
105 return if ($cookie cmp $ext) != 0;