1*e0c4386eSCy Schubert#! /usr/bin/env perl 2*e0c4386eSCy Schubert# Copyright 2016-2021 The OpenSSL Project Authors. All Rights Reserved. 3*e0c4386eSCy Schubert# 4*e0c4386eSCy Schubert# Licensed under the Apache License 2.0 (the "License"). You may not use 5*e0c4386eSCy Schubert# this file except in compliance with the License. You can obtain a copy 6*e0c4386eSCy Schubert# in the file LICENSE in the source distribution or at 7*e0c4386eSCy Schubert# https://www.openssl.org/source/license.html 8*e0c4386eSCy Schubert 9*e0c4386eSCy Schubertuse strict; 10*e0c4386eSCy Schubertuse OpenSSL::Test qw/:DEFAULT cmdstr srctop_file bldtop_dir/; 11*e0c4386eSCy Schubertuse OpenSSL::Test::Utils; 12*e0c4386eSCy Schubertuse TLSProxy::Proxy; 13*e0c4386eSCy Schubert 14*e0c4386eSCy Schubertmy $test_name = "test_renegotiation"; 15*e0c4386eSCy Schubertsetup($test_name); 16*e0c4386eSCy Schubert 17*e0c4386eSCy Schubertplan skip_all => "TLSProxy isn't usable on $^O" 18*e0c4386eSCy Schubert if $^O =~ /^(VMS)$/; 19*e0c4386eSCy Schubert 20*e0c4386eSCy Schubertplan skip_all => "$test_name needs the dynamic engine feature enabled" 21*e0c4386eSCy Schubert if disabled("engine") || disabled("dynamic-engine"); 22*e0c4386eSCy Schubert 23*e0c4386eSCy Schubertplan skip_all => "$test_name needs the sock feature enabled" 24*e0c4386eSCy Schubert if disabled("sock"); 25*e0c4386eSCy Schubert 26*e0c4386eSCy Schubertplan skip_all => "$test_name needs TLS <= 1.2 enabled" 27*e0c4386eSCy Schubert if alldisabled(("ssl3", "tls1", "tls1_1", "tls1_2")); 28*e0c4386eSCy Schubert 29*e0c4386eSCy Schubertplan tests => 5; 30*e0c4386eSCy Schubert 31*e0c4386eSCy Schubert$ENV{OPENSSL_ia32cap} = '~0x200000200000000'; 32*e0c4386eSCy Schubertmy $proxy = TLSProxy::Proxy->new( 33*e0c4386eSCy Schubert undef, 34*e0c4386eSCy Schubert cmdstr(app(["openssl"]), display => 1), 35*e0c4386eSCy Schubert srctop_file("apps", "server.pem"), 36*e0c4386eSCy Schubert (!$ENV{HARNESS_ACTIVE} || $ENV{HARNESS_VERBOSE}) 37*e0c4386eSCy Schubert); 38*e0c4386eSCy Schubert 39*e0c4386eSCy Schubert#Test 1: A basic renegotiation test 40*e0c4386eSCy Schubert$proxy->clientflags("-no_tls1_3"); 41*e0c4386eSCy Schubert$proxy->serverflags("-client_renegotiation"); 42*e0c4386eSCy Schubert$proxy->reneg(1); 43*e0c4386eSCy Schubert$proxy->start() or plan skip_all => "Unable to start up Proxy for tests"; 44*e0c4386eSCy Schubertok(TLSProxy::Message->success(), "Basic renegotiation"); 45*e0c4386eSCy Schubert 46*e0c4386eSCy Schubert#Test 2: Client does not send the Reneg SCSV. Reneg should fail 47*e0c4386eSCy Schubert$proxy->clear(); 48*e0c4386eSCy Schubert$proxy->filter(\&reneg_filter); 49*e0c4386eSCy Schubert$proxy->clientflags("-no_tls1_3"); 50*e0c4386eSCy Schubert$proxy->serverflags("-client_renegotiation"); 51*e0c4386eSCy Schubert$proxy->reneg(1); 52*e0c4386eSCy Schubert$proxy->start(); 53*e0c4386eSCy Schubertok(TLSProxy::Message->fail(), "No client SCSV"); 54*e0c4386eSCy Schubert 55*e0c4386eSCy SchubertSKIP: { 56*e0c4386eSCy Schubert skip "TLSv1.2 or TLSv1.1 disabled", 1 57*e0c4386eSCy Schubert if disabled("tls1_2") || disabled("tls1_1"); 58*e0c4386eSCy Schubert #Test 3: Check that the ClientHello version remains the same in the reneg 59*e0c4386eSCy Schubert # handshake 60*e0c4386eSCy Schubert $proxy->clear(); 61*e0c4386eSCy Schubert $proxy->filter(undef); 62*e0c4386eSCy Schubert $proxy->ciphers("DEFAULT:\@SECLEVEL=0"); 63*e0c4386eSCy Schubert $proxy->clientflags("-no_tls1_3 -cipher AES128-SHA:\@SECLEVEL=0"); 64*e0c4386eSCy Schubert $proxy->serverflags("-no_tls1_3 -no_tls1_2 -client_renegotiation"); 65*e0c4386eSCy Schubert $proxy->reneg(1); 66*e0c4386eSCy Schubert $proxy->start(); 67*e0c4386eSCy Schubert my $chversion; 68*e0c4386eSCy Schubert my $chmatch = 0; 69*e0c4386eSCy Schubert foreach my $message (@{$proxy->message_list}) { 70*e0c4386eSCy Schubert if ($message->mt == TLSProxy::Message::MT_CLIENT_HELLO) { 71*e0c4386eSCy Schubert if (!defined $chversion) { 72*e0c4386eSCy Schubert $chversion = $message->client_version; 73*e0c4386eSCy Schubert } else { 74*e0c4386eSCy Schubert if ($chversion == $message->client_version) { 75*e0c4386eSCy Schubert $chmatch = 1; 76*e0c4386eSCy Schubert } 77*e0c4386eSCy Schubert } 78*e0c4386eSCy Schubert } 79*e0c4386eSCy Schubert } 80*e0c4386eSCy Schubert ok(TLSProxy::Message->success() && $chmatch, 81*e0c4386eSCy Schubert "Check ClientHello version is the same"); 82*e0c4386eSCy Schubert} 83*e0c4386eSCy Schubert 84*e0c4386eSCy SchubertSKIP: { 85*e0c4386eSCy Schubert skip "TLSv1.2 disabled", 1 86*e0c4386eSCy Schubert if disabled("tls1_2"); 87*e0c4386eSCy Schubert 88*e0c4386eSCy Schubert #Test 4: Test for CVE-2021-3449. client_sig_algs instead of sig_algs in 89*e0c4386eSCy Schubert # resumption ClientHello 90*e0c4386eSCy Schubert $proxy->clear(); 91*e0c4386eSCy Schubert $proxy->filter(\&sigalgs_filter); 92*e0c4386eSCy Schubert $proxy->clientflags("-tls1_2"); 93*e0c4386eSCy Schubert $proxy->serverflags("-client_renegotiation"); 94*e0c4386eSCy Schubert $proxy->reneg(1); 95*e0c4386eSCy Schubert $proxy->start(); 96*e0c4386eSCy Schubert ok(TLSProxy::Message->fail(), "client_sig_algs instead of sig_algs"); 97*e0c4386eSCy Schubert} 98*e0c4386eSCy Schubert 99*e0c4386eSCy SchubertSKIP: { 100*e0c4386eSCy Schubert skip "TLSv1.2 and TLSv1.1 disabled", 1 101*e0c4386eSCy Schubert if disabled("tls1_2") && disabled("tls1_1"); 102*e0c4386eSCy Schubert #Test 5: Client fails to do renegotiation 103*e0c4386eSCy Schubert $proxy->clear(); 104*e0c4386eSCy Schubert $proxy->filter(undef); 105*e0c4386eSCy Schubert $proxy->serverflags("-no_tls1_3"); 106*e0c4386eSCy Schubert $proxy->clientflags("-no_tls1_3"); 107*e0c4386eSCy Schubert $proxy->reneg(1); 108*e0c4386eSCy Schubert $proxy->start(); 109*e0c4386eSCy Schubert ok(TLSProxy::Message->fail(), 110*e0c4386eSCy Schubert "Check client renegotiation failed"); 111*e0c4386eSCy Schubert} 112*e0c4386eSCy Schubert 113*e0c4386eSCy Schubertsub reneg_filter 114*e0c4386eSCy Schubert{ 115*e0c4386eSCy Schubert my $proxy = shift; 116*e0c4386eSCy Schubert 117*e0c4386eSCy Schubert # We're only interested in the initial ClientHello message 118*e0c4386eSCy Schubert if ($proxy->flight != 0) { 119*e0c4386eSCy Schubert return; 120*e0c4386eSCy Schubert } 121*e0c4386eSCy Schubert 122*e0c4386eSCy Schubert foreach my $message (@{$proxy->message_list}) { 123*e0c4386eSCy Schubert if ($message->mt == TLSProxy::Message::MT_CLIENT_HELLO) { 124*e0c4386eSCy Schubert #Remove any SCSV ciphersuites - just leave AES128-SHA (0x002f) 125*e0c4386eSCy Schubert my @ciphersuite = (0x002f); 126*e0c4386eSCy Schubert $message->ciphersuites(\@ciphersuite); 127*e0c4386eSCy Schubert $message->ciphersuite_len(2); 128*e0c4386eSCy Schubert $message->repack(); 129*e0c4386eSCy Schubert } 130*e0c4386eSCy Schubert } 131*e0c4386eSCy Schubert} 132*e0c4386eSCy Schubert 133*e0c4386eSCy Schubertsub sigalgs_filter 134*e0c4386eSCy Schubert{ 135*e0c4386eSCy Schubert my $proxy = shift; 136*e0c4386eSCy Schubert my $cnt = 0; 137*e0c4386eSCy Schubert 138*e0c4386eSCy Schubert # We're only interested in the second ClientHello message 139*e0c4386eSCy Schubert foreach my $message (@{$proxy->message_list}) { 140*e0c4386eSCy Schubert if ($message->mt == TLSProxy::Message::MT_CLIENT_HELLO) { 141*e0c4386eSCy Schubert next if ($cnt++ == 0); 142*e0c4386eSCy Schubert 143*e0c4386eSCy Schubert my $sigs = pack "C10", 0x00, 0x08, 144*e0c4386eSCy Schubert # rsa_pkcs_sha{256,384,512,1} 145*e0c4386eSCy Schubert 0x04, 0x01, 0x05, 0x01, 0x06, 0x01, 0x02, 0x01; 146*e0c4386eSCy Schubert $message->set_extension(TLSProxy::Message::EXT_SIG_ALGS_CERT, $sigs); 147*e0c4386eSCy Schubert $message->delete_extension(TLSProxy::Message::EXT_SIG_ALGS); 148*e0c4386eSCy Schubert $message->repack(); 149*e0c4386eSCy Schubert } 150*e0c4386eSCy Schubert } 151*e0c4386eSCy Schubert} 152