70-test_renegotiation.t 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. #! /usr/bin/env perl
  2. # Copyright 2016-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_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. plan tests => 5;
  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->serverflags("-client_renegotiation");
  32. $proxy->reneg(1);
  33. $proxy->start() or plan skip_all => "Unable to start up Proxy for tests";
  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->serverflags("-client_renegotiation");
  40. $proxy->reneg(1);
  41. $proxy->start();
  42. ok(TLSProxy::Message->fail(), "No client SCSV");
  43. SKIP: {
  44. skip "TLSv1.2 or TLSv1.1 disabled", 1
  45. if disabled("tls1_2") || disabled("tls1_1");
  46. #Test 3: Check that the ClientHello version remains the same in the reneg
  47. # handshake
  48. $proxy->clear();
  49. $proxy->filter(undef);
  50. $proxy->ciphers("DEFAULT:\@SECLEVEL=0");
  51. $proxy->clientflags("-no_tls1_3 -cipher AES128-SHA:\@SECLEVEL=0");
  52. $proxy->serverflags("-no_tls1_3 -no_tls1_2 -client_renegotiation");
  53. $proxy->reneg(1);
  54. $proxy->start();
  55. my $chversion;
  56. my $chmatch = 0;
  57. foreach my $message (@{$proxy->message_list}) {
  58. if ($message->mt == TLSProxy::Message::MT_CLIENT_HELLO) {
  59. if (!defined $chversion) {
  60. $chversion = $message->client_version;
  61. } else {
  62. if ($chversion == $message->client_version) {
  63. $chmatch = 1;
  64. }
  65. }
  66. }
  67. }
  68. ok(TLSProxy::Message->success() && $chmatch,
  69. "Check ClientHello version is the same");
  70. }
  71. SKIP: {
  72. skip "TLSv1.2 disabled", 1
  73. if disabled("tls1_2");
  74. #Test 4: Test for CVE-2021-3449. client_sig_algs instead of sig_algs in
  75. # resumption ClientHello
  76. $proxy->clear();
  77. $proxy->filter(\&sigalgs_filter);
  78. $proxy->clientflags("-tls1_2");
  79. $proxy->serverflags("-client_renegotiation");
  80. $proxy->reneg(1);
  81. $proxy->start();
  82. ok(TLSProxy::Message->fail(), "client_sig_algs instead of sig_algs");
  83. }
  84. SKIP: {
  85. skip "TLSv1.2 and TLSv1.1 disabled", 1
  86. if disabled("tls1_2") && disabled("tls1_1");
  87. #Test 5: Client fails to do renegotiation
  88. $proxy->clear();
  89. $proxy->filter(undef);
  90. $proxy->serverflags("-no_tls1_3");
  91. $proxy->clientflags("-no_tls1_3");
  92. $proxy->reneg(1);
  93. $proxy->start();
  94. ok(TLSProxy::Message->fail(),
  95. "Check client renegotiation failed");
  96. }
  97. sub reneg_filter
  98. {
  99. my $proxy = shift;
  100. # We're only interested in the initial ClientHello message
  101. if ($proxy->flight != 0) {
  102. return;
  103. }
  104. foreach my $message (@{$proxy->message_list}) {
  105. if ($message->mt == TLSProxy::Message::MT_CLIENT_HELLO) {
  106. #Remove any SCSV ciphersuites - just leave AES128-SHA (0x002f)
  107. my @ciphersuite = (0x002f);
  108. $message->ciphersuites(\@ciphersuite);
  109. $message->ciphersuite_len(2);
  110. $message->repack();
  111. }
  112. }
  113. }
  114. sub sigalgs_filter
  115. {
  116. my $proxy = shift;
  117. my $cnt = 0;
  118. # We're only interested in the second ClientHello message
  119. foreach my $message (@{$proxy->message_list}) {
  120. if ($message->mt == TLSProxy::Message::MT_CLIENT_HELLO) {
  121. next if ($cnt++ == 0);
  122. my $sigs = pack "C10", 0x00, 0x08,
  123. # rsa_pkcs_sha{256,384,512,1}
  124. 0x04, 0x01, 0x05, 0x01, 0x06, 0x01, 0x02, 0x01;
  125. $message->set_extension(TLSProxy::Message::EXT_SIG_ALGS_CERT, $sigs);
  126. $message->delete_extension(TLSProxy::Message::EXT_SIG_ALGS);
  127. $message->repack();
  128. }
  129. }
  130. }