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 my $proxy = TLSProxy::Proxy->new(
33 cmdstr(app(["openssl"]), display => 1),
34 srctop_file("apps", "server.pem"),
35 (!$ENV{HARNESS_ACTIVE} || $ENV{HARNESS_VERBOSE})
38 #Test 1: A basic renegotiation test
39 $proxy->clientflags("-no_tls1_3");
40 $proxy->serverflags("-client_renegotiation");
42 $proxy->start() or plan skip_all => "Unable to start up Proxy for tests";
43 ok(TLSProxy::Message->success(), "Basic renegotiation");
45 #Test 2: Client does not send the Reneg SCSV. Reneg should fail
47 $proxy->filter(\&reneg_filter);
48 $proxy->clientflags("-no_tls1_3");
49 $proxy->serverflags("-client_renegotiation");
52 ok(TLSProxy::Message->fail(), "No client SCSV");
55 skip "TLSv1.2 or TLSv1.1 disabled", 1
56 if disabled("tls1_2") || disabled("tls1_1");
57 #Test 3: Check that the ClientHello version remains the same in the reneg
60 $proxy->filter(undef);
61 $proxy->ciphers("DEFAULT:\@SECLEVEL=0");
62 $proxy->clientflags("-no_tls1_3 -cipher AES128-SHA:\@SECLEVEL=0");
63 $proxy->serverflags("-no_tls1_3 -no_tls1_2 -client_renegotiation");
68 foreach my $message (@{$proxy->message_list}) {
69 if ($message->mt == TLSProxy::Message::MT_CLIENT_HELLO) {
70 if (!defined $chversion) {
71 $chversion = $message->client_version;
73 if ($chversion == $message->client_version) {
79 ok(TLSProxy::Message->success() && $chmatch,
80 "Check ClientHello version is the same");
84 skip "TLSv1.2 disabled", 1
85 if disabled("tls1_2");
87 #Test 4: Test for CVE-2021-3449. client_sig_algs instead of sig_algs in
88 # resumption ClientHello
90 $proxy->filter(\&sigalgs_filter);
91 $proxy->clientflags("-tls1_2");
92 $proxy->serverflags("-client_renegotiation");
95 ok(TLSProxy::Message->fail(), "client_sig_algs instead of sig_algs");
99 skip "TLSv1.2 and TLSv1.1 disabled", 1
100 if disabled("tls1_2") && disabled("tls1_1");
101 #Test 5: Client fails to do renegotiation
103 $proxy->filter(undef);
104 $proxy->serverflags("-no_tls1_3");
105 $proxy->clientflags("-no_tls1_3");
108 ok(TLSProxy::Message->fail(),
109 "Check client renegotiation failed");
116 # We're only interested in the initial ClientHello message
117 if ($proxy->flight != 0) {
121 foreach my $message (@{$proxy->message_list}) {
122 if ($message->mt == TLSProxy::Message::MT_CLIENT_HELLO) {
123 #Remove any SCSV ciphersuites - just leave AES128-SHA (0x002f)
124 my @ciphersuite = (0x002f);
125 $message->ciphersuites(\@ciphersuite);
126 $message->ciphersuite_len(2);
137 # We're only interested in the second ClientHello message
138 foreach my $message (@{$proxy->message_list}) {
139 if ($message->mt == TLSProxy::Message::MT_CLIENT_HELLO) {
140 next if ($cnt++ == 0);
142 my $sigs = pack "C10", 0x00, 0x08,
143 # rsa_pkcs_sha{256,384,512,1}
144 0x04, 0x01, 0x05, 0x01, 0x06, 0x01, 0x02, 0x01;
145 $message->set_extension(TLSProxy::Message::EXT_SIG_ALGS_CERT, $sigs);
146 $message->delete_extension(TLSProxy::Message::EXT_SIG_ALGS);