70-test_renegotiation.t 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. #! /usr/bin/env perl
  2. # Copyright 2016-2021 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_renegotiation";
  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 TLS <= 1.2 enabled"
  21. if alldisabled(("ssl3", "tls1", "tls1_1", "tls1_2"));
  22. $ENV{OPENSSL_ia32cap} = '~0x200000200000000';
  23. my $proxy = TLSProxy::Proxy->new(
  24. undef,
  25. cmdstr(app(["openssl"]), display => 1),
  26. srctop_file("apps", "server.pem"),
  27. (!$ENV{HARNESS_ACTIVE} || $ENV{HARNESS_VERBOSE})
  28. );
  29. #Test 1: A basic renegotiation test
  30. $proxy->clientflags("-no_tls1_3");
  31. $proxy->reneg(1);
  32. $proxy->start() or plan skip_all => "Unable to start up Proxy for tests";
  33. plan tests => 4;
  34. ok(TLSProxy::Message->success(), "Basic renegotiation");
  35. #Test 2: Client does not send the Reneg SCSV. Reneg should fail
  36. $proxy->clear();
  37. $proxy->filter(\&reneg_filter);
  38. $proxy->clientflags("-no_tls1_3");
  39. $proxy->reneg(1);
  40. $proxy->start();
  41. ok(TLSProxy::Message->fail(), "No client SCSV");
  42. SKIP: {
  43. skip "TLSv1.2 or TLSv1.1 disabled", 1
  44. if disabled("tls1_2") || disabled("tls1_1");
  45. #Test 3: Check that the ClientHello version remains the same in the reneg
  46. # handshake
  47. $proxy->clear();
  48. $proxy->filter(undef);
  49. $proxy->clientflags("-no_tls1_3");
  50. $proxy->serverflags("-no_tls1_3 -no_tls1_2");
  51. $proxy->reneg(1);
  52. $proxy->start();
  53. my $chversion;
  54. my $chmatch = 0;
  55. foreach my $message (@{$proxy->message_list}) {
  56. if ($message->mt == TLSProxy::Message::MT_CLIENT_HELLO) {
  57. if (!defined $chversion) {
  58. $chversion = $message->client_version;
  59. } else {
  60. if ($chversion == $message->client_version) {
  61. $chmatch = 1;
  62. }
  63. }
  64. }
  65. }
  66. ok(TLSProxy::Message->success() && $chmatch,
  67. "Check ClientHello version is the same");
  68. }
  69. SKIP: {
  70. skip "TLSv1.2 disabled", 1
  71. if disabled("tls1_2");
  72. #Test 4: Test for CVE-2021-3449. client_sig_algs instead of sig_algs in
  73. # resumption ClientHello
  74. $proxy->clear();
  75. $proxy->filter(\&sigalgs_filter);
  76. $proxy->clientflags("-tls1_2");
  77. $proxy->reneg(1);
  78. $proxy->start();
  79. ok(TLSProxy::Message->fail(), "client_sig_algs instead of sig_algs");
  80. }
  81. sub reneg_filter
  82. {
  83. my $proxy = shift;
  84. # We're only interested in the initial ClientHello message
  85. if ($proxy->flight != 0) {
  86. return;
  87. }
  88. foreach my $message (@{$proxy->message_list}) {
  89. if ($message->mt == TLSProxy::Message::MT_CLIENT_HELLO) {
  90. #Remove any SCSV ciphersuites - just leave AES128-SHA (0x002f)
  91. my @ciphersuite = (0x002f);
  92. $message->ciphersuites(\@ciphersuite);
  93. $message->ciphersuite_len(2);
  94. $message->repack();
  95. }
  96. }
  97. }
  98. sub sigalgs_filter
  99. {
  100. my $proxy = shift;
  101. my $cnt = 0;
  102. # We're only interested in the second ClientHello message
  103. foreach my $message (@{$proxy->message_list}) {
  104. if ($message->mt == TLSProxy::Message::MT_CLIENT_HELLO) {
  105. next if ($cnt++ == 0);
  106. my $sigs = pack "C10", 0x00, 0x08,
  107. # rsa_pkcs_sha{256,384,512,1}
  108. 0x04, 0x01, 0x05, 0x01, 0x06, 0x01, 0x02, 0x01;
  109. $message->set_extension(TLSProxy::Message::EXT_SIG_ALGS_CERT, $sigs);
  110. $message->delete_extension(TLSProxy::Message::EXT_SIG_ALGS);
  111. $message->repack();
  112. }
  113. }
  114. }