2 # Copyright 2017 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_tls13hrr";
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';
31 my $proxy = TLSProxy::Proxy->new(
33 cmdstr(app(["openssl"]), display => 1),
34 srctop_file("apps", "server.pem"),
35 (!$ENV{HARNESS_ACTIVE} || $ENV{HARNESS_VERBOSE})
39 CHANGE_HRR_CIPHERSUITE => 0,
40 CHANGE_CH1_CIPHERSUITE => 1
43 #Test 1: A client should fail if the server changes the ciphersuite between the
45 $proxy->filter(\&hrr_filter);
46 $proxy->serverflags("-curves P-256");
47 my $testtype = CHANGE_HRR_CIPHERSUITE;
48 $proxy->start() or plan skip_all => "Unable to start up Proxy for tests";
50 ok(TLSProxy::Message->fail(), "Server ciphersuite changes");
52 #Test 2: It is an error if the client changes the offered ciphersuites so that
53 # we end up selecting a different ciphersuite between HRR and the SH
55 $proxy->serverflags("-curves P-256");
56 $proxy->ciphers("TLS13-AES-128-GCM-SHA256:TLS13-AES-256-GCM-SHA384");
57 $testtype = CHANGE_CH1_CIPHERSUITE;
59 ok(TLSProxy::Message->fail(), "Client ciphersuite changes");
65 if ($testtype == CHANGE_HRR_CIPHERSUITE) {
66 # We're only interested in the HRR
67 if ($proxy->flight != 1) {
71 my $hrr = ${$proxy->message_list}[1];
73 # We will normally only ever select CIPHER_TLS13_AES_128_GCM_SHA256
74 # because that's what Proxy tells s_server to do. Setting as below means
75 # the ciphersuite will change will we get the ServerHello
76 $hrr->ciphersuite(TLSProxy::Message::CIPHER_TLS13_AES_256_GCM_SHA384);
81 # CHANGE_CH1_CIPHERSUITE
82 if ($proxy->flight != 0) {
86 my $ch1 = ${$proxy->message_list}[0];
88 # The server prefers TLS13-AES-256-GCM-SHA384 so it will pick that next
90 my @ciphersuites = (TLSProxy::Message::CIPHER_TLS13_AES_128_GCM_SHA256);
91 $ch1->ciphersuite_len(2 * scalar @ciphersuites);
92 $ch1->ciphersuites(\@ciphersuites);