2
0

70-test_tls13alerts.t 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #! /usr/bin/env perl
  2. # Copyright 2018-2021 The OpenSSL Project Authors. All Rights Reserved.
  3. #
  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
  8. use strict;
  9. use OpenSSL::Test qw/:DEFAULT cmdstr srctop_file bldtop_dir/;
  10. use OpenSSL::Test::Utils;
  11. use TLSProxy::Proxy;
  12. my $test_name = "test_tls13alerts";
  13. setup($test_name);
  14. plan skip_all => "TLSProxy isn't usable on $^O"
  15. if $^O =~ /^(VMS)$/;
  16. plan skip_all => "$test_name needs the dynamic engine feature enabled"
  17. if disabled("engine") || disabled("dynamic-engine");
  18. plan skip_all => "$test_name needs the sock feature enabled"
  19. if disabled("sock");
  20. plan skip_all => "$test_name needs TLS1.3 enabled"
  21. if disabled("tls1_3") || (disabled("ec") && disabled("dh"));
  22. my $proxy = TLSProxy::Proxy->new(
  23. undef,
  24. cmdstr(app(["openssl"]), display => 1),
  25. srctop_file("apps", "server.pem"),
  26. (!$ENV{HARNESS_ACTIVE} || $ENV{HARNESS_VERBOSE})
  27. );
  28. #Test 1: We test that a server can handle an unencrypted alert when normally the
  29. # next message is encrypted
  30. $proxy->filter(\&alert_filter);
  31. $proxy->start() or plan skip_all => "Unable to start up Proxy for tests";
  32. plan tests => 1;
  33. my $alert = TLSProxy::Message->alert();
  34. ok(TLSProxy::Message->fail() && !$alert->server() && !$alert->encrypted(), "Client sends an unecrypted alert");
  35. sub alert_filter
  36. {
  37. my $proxy = shift;
  38. if ($proxy->flight != 1) {
  39. return;
  40. }
  41. ${$proxy->message_list}[1]->session_id_len(1);
  42. ${$proxy->message_list}[1]->repack();
  43. }