1e1051a39Sopenharmony_ci#! /usr/bin/env perl 2e1051a39Sopenharmony_ci# Copyright 2018-2021 The OpenSSL Project Authors. All Rights Reserved. 3e1051a39Sopenharmony_ci# 4e1051a39Sopenharmony_ci# Licensed under the Apache License 2.0 (the "License"). You may not use 5e1051a39Sopenharmony_ci# this file except in compliance with the License. You can obtain a copy 6e1051a39Sopenharmony_ci# in the file LICENSE in the source distribution or at 7e1051a39Sopenharmony_ci# https://www.openssl.org/source/license.html 8e1051a39Sopenharmony_ci 9e1051a39Sopenharmony_ciuse strict; 10e1051a39Sopenharmony_ciuse OpenSSL::Test qw/:DEFAULT cmdstr srctop_file bldtop_dir/; 11e1051a39Sopenharmony_ciuse OpenSSL::Test::Utils; 12e1051a39Sopenharmony_ciuse TLSProxy::Proxy; 13e1051a39Sopenharmony_ci 14e1051a39Sopenharmony_cimy $test_name = "test_tls13alerts"; 15e1051a39Sopenharmony_cisetup($test_name); 16e1051a39Sopenharmony_ci 17e1051a39Sopenharmony_ciplan skip_all => "TLSProxy isn't usable on $^O" 18e1051a39Sopenharmony_ci if $^O =~ /^(VMS)$/; 19e1051a39Sopenharmony_ci 20e1051a39Sopenharmony_ciplan skip_all => "$test_name needs the dynamic engine feature enabled" 21e1051a39Sopenharmony_ci if disabled("engine") || disabled("dynamic-engine"); 22e1051a39Sopenharmony_ci 23e1051a39Sopenharmony_ciplan skip_all => "$test_name needs the sock feature enabled" 24e1051a39Sopenharmony_ci if disabled("sock"); 25e1051a39Sopenharmony_ci 26e1051a39Sopenharmony_ciplan skip_all => "$test_name needs TLS1.3 enabled" 27e1051a39Sopenharmony_ci if disabled("tls1_3") || (disabled("ec") && disabled("dh")); 28e1051a39Sopenharmony_ci 29e1051a39Sopenharmony_ci$ENV{OPENSSL_ia32cap} = '~0x200000200000000'; 30e1051a39Sopenharmony_ci 31e1051a39Sopenharmony_cimy $proxy = TLSProxy::Proxy->new( 32e1051a39Sopenharmony_ci undef, 33e1051a39Sopenharmony_ci cmdstr(app(["openssl"]), display => 1), 34e1051a39Sopenharmony_ci srctop_file("apps", "server.pem"), 35e1051a39Sopenharmony_ci (!$ENV{HARNESS_ACTIVE} || $ENV{HARNESS_VERBOSE}) 36e1051a39Sopenharmony_ci); 37e1051a39Sopenharmony_ci 38e1051a39Sopenharmony_ci#Test 1: We test that a server can handle an unencrypted alert when normally the 39e1051a39Sopenharmony_ci# next message is encrypted 40e1051a39Sopenharmony_ci$proxy->filter(\&alert_filter); 41e1051a39Sopenharmony_ci$proxy->start() or plan skip_all => "Unable to start up Proxy for tests"; 42e1051a39Sopenharmony_ciplan tests => 1; 43e1051a39Sopenharmony_cimy $alert = TLSProxy::Message->alert(); 44e1051a39Sopenharmony_ciok(TLSProxy::Message->fail() && !$alert->server() && !$alert->encrypted(), "Client sends an unecrypted alert"); 45e1051a39Sopenharmony_ci 46e1051a39Sopenharmony_cisub alert_filter 47e1051a39Sopenharmony_ci{ 48e1051a39Sopenharmony_ci my $proxy = shift; 49e1051a39Sopenharmony_ci 50e1051a39Sopenharmony_ci if ($proxy->flight != 1) { 51e1051a39Sopenharmony_ci return; 52e1051a39Sopenharmony_ci } 53e1051a39Sopenharmony_ci 54e1051a39Sopenharmony_ci ${$proxy->message_list}[1]->session_id_len(1); 55e1051a39Sopenharmony_ci ${$proxy->message_list}[1]->repack(); 56e1051a39Sopenharmony_ci} 57