2 # Copyright 2016-2021 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_renegotiation";
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 TLS <= 1.2 enabled"
27 if alldisabled(("ssl3", "tls1", "tls1_1", "tls1_2"));
31 $ENV{OPENSSL_ia32cap} = '~0x200000200000000';
32 my $proxy = TLSProxy::Proxy->new(
34 cmdstr(app(["openssl"]), display => 1),
35 srctop_file("apps", "server.pem"),
36 (!$ENV{HARNESS_ACTIVE} || $ENV{HARNESS_VERBOSE})
39 #Test 1: A basic renegotiation test
40 $proxy->clientflags("-no_tls1_3");
41 $proxy->serverflags("-client_renegotiation");
43 $proxy->start() or plan skip_all => "Unable to start up Proxy for tests";
44 ok(TLSProxy::Message->success(), "Basic renegotiation");
46 #Test 2: Client does not send the Reneg SCSV. Reneg should fail
48 $proxy->filter(\&reneg_filter);
49 $proxy->clientflags("-no_tls1_3");
50 $proxy->serverflags("-client_renegotiation");
53 ok(TLSProxy::Message->fail(), "No client SCSV");
56 skip "TLSv1.2 or TLSv1.1 disabled", 1
57 if disabled("tls1_2") || disabled("tls1_1");
58 #Test 3: Check that the ClientHello version remains the same in the reneg
61 $proxy->filter(undef);
62 $proxy->ciphers("DEFAULT:\@SECLEVEL=0");
63 $proxy->clientflags("-no_tls1_3 -cipher AES128-SHA:\@SECLEVEL=0");
64 $proxy->serverflags("-no_tls1_3 -no_tls1_2 -client_renegotiation");
69 foreach my $message (@{$proxy->message_list}) {
70 if ($message->mt == TLSProxy::Message::MT_CLIENT_HELLO) {
71 if (!defined $chversion) {
72 $chversion = $message->client_version;
74 if ($chversion == $message->client_version) {
80 ok(TLSProxy::Message->success() && $chmatch,
81 "Check ClientHello version is the same");
85 skip "TLSv1.2 disabled", 1
86 if disabled("tls1_2");
88 #Test 4: Test for CVE-2021-3449. client_sig_algs instead of sig_algs in
89 # resumption ClientHello
91 $proxy->filter(\&sigalgs_filter);
92 $proxy->clientflags("-tls1_2");
93 $proxy->serverflags("-client_renegotiation");
96 ok(TLSProxy::Message->fail(), "client_sig_algs instead of sig_algs");
100 skip "TLSv1.2 and TLSv1.1 disabled", 1
101 if disabled("tls1_2") && disabled("tls1_1");
102 #Test 5: Client fails to do renegotiation
104 $proxy->filter(undef);
105 $proxy->serverflags("-no_tls1_3");
106 $proxy->clientflags("-no_tls1_3");
109 ok(TLSProxy::Message->fail(),
110 "Check client renegotiation failed");
114 skip "TLSv1.2 and TLSv1.1 disabled", 1
115 if disabled("tls1_2") && disabled("tls1_1");
116 #Test 6: Server can do renegotiation
118 $proxy->filter(undef);
119 $proxy->serverflags("-no_tls1_3 -immediate_renegotiation");
120 $proxy->clientflags("-no_tls1_3");
122 ok(TLSProxy::Message->success(),
123 "Check server renegotiation succeeded");
130 # We're only interested in the initial ClientHello message
131 if ($proxy->flight != 0) {
135 foreach my $message (@{$proxy->message_list}) {
136 if ($message->mt == TLSProxy::Message::MT_CLIENT_HELLO) {
137 #Remove any SCSV ciphersuites - just leave AES128-SHA (0x002f)
138 my @ciphersuite = (0x002f);
139 $message->ciphersuites(\@ciphersuite);
140 $message->ciphersuite_len(2);
151 # We're only interested in the second ClientHello message
152 foreach my $message (@{$proxy->message_list}) {
153 if ($message->mt == TLSProxy::Message::MT_CLIENT_HELLO) {
154 next if ($cnt++ == 0);
156 my $sigs = pack "C10", 0x00, 0x08,
157 # rsa_pkcs_sha{256,384,512,1}
158 0x04, 0x01, 0x05, 0x01, 0x06, 0x01, 0x02, 0x01;
159 $message->set_extension(TLSProxy::Message::EXT_SIG_ALGS_CERT, $sigs);
160 $message->delete_extension(TLSProxy::Message::EXT_SIG_ALGS);