70-test_tls13downgrade.t 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. #! /usr/bin/env perl
  2. # Copyright 2017 The OpenSSL Project Authors. All Rights Reserved.
  3. #
  4. # Licensed under the OpenSSL license (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_tls13downgrade";
  13. setup($test_name);
  14. plan skip_all => "TLSProxy isn't usable on $^O"
  15. if $^O =~ /^(VMS|MSWin32)$/;
  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 and TLS1.2 enabled"
  21. if disabled("tls1_3") || disabled("tls1_2");
  22. # TODO(TLS1.3): Enable this when TLSv1.3 comes out of draft
  23. plan skip_all => "$test_name not run in pre TLSv1.3 RFC implementation"
  24. if disabled("tls13downgrade");
  25. $ENV{OPENSSL_ia32cap} = '~0x200000200000000';
  26. my $proxy = TLSProxy::Proxy->new(
  27. undef,
  28. cmdstr(app(["openssl"]), display => 1),
  29. srctop_file("apps", "server.pem"),
  30. (!$ENV{HARNESS_ACTIVE} || $ENV{HARNESS_VERBOSE})
  31. );
  32. use constant {
  33. DOWNGRADE_TO_TLS_1_2 => 0,
  34. DOWNGRADE_TO_TLS_1_1 => 1
  35. };
  36. #Test 1: Downgrade from TLSv1.3 to TLSv1.2
  37. $proxy->filter(\&downgrade_filter);
  38. my $testtype = DOWNGRADE_TO_TLS_1_2;
  39. $proxy->start() or plan skip_all => "Unable to start up Proxy for tests";
  40. plan tests => 3;
  41. ok(TLSProxy::Message->fail(), "Downgrade TLSv1.3 to TLSv1.2");
  42. #Test 2: Downgrade from TLSv1.3 to TLSv1.1
  43. $proxy->clear();
  44. $testtype = DOWNGRADE_TO_TLS_1_1;
  45. $proxy->start();
  46. ok(TLSProxy::Message->fail(), "Downgrade TLSv1.3 to TLSv1.1");
  47. #Test 3: Downgrade from TLSv1.2 to TLSv1.1
  48. $proxy->clear();
  49. $proxy->clientflags("-no_tls1_3");
  50. $proxy->serverflags("-no_tls1_3");
  51. $proxy->start();
  52. ok(TLSProxy::Message->fail(), "Downgrade TLSv1.2 to TLSv1.1");
  53. sub downgrade_filter
  54. {
  55. my $proxy = shift;
  56. # We're only interested in the initial ClientHello
  57. if ($proxy->flight != 0) {
  58. return;
  59. }
  60. my $message = ${$proxy->message_list}[0];
  61. my $ext;
  62. if ($testtype == DOWNGRADE_TO_TLS_1_2) {
  63. $ext = pack "C3",
  64. 0x02, # Length
  65. 0x03, 0x03; #TLSv1.2
  66. } else {
  67. $ext = pack "C3",
  68. 0x02, # Length
  69. 0x03, 0x02; #TLSv1.1
  70. }
  71. $message->set_extension(TLSProxy::Message::EXT_SUPPORTED_VERSIONS, $ext);
  72. $message->repack();
  73. }