70-test_renegotiation.t 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. #! /usr/bin/env perl
  2. # Copyright 2016-2018 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. $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 => 3;
  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->ciphers("DEFAULT:\@SECLEVEL=0");
  50. $proxy->clientflags("-no_tls1_3 -cipher AES128-SHA:\@SECLEVEL=0");
  51. $proxy->serverflags("-no_tls1_3 -no_tls1_2");
  52. $proxy->reneg(1);
  53. $proxy->start();
  54. my $chversion;
  55. my $chmatch = 0;
  56. foreach my $message (@{$proxy->message_list}) {
  57. if ($message->mt == TLSProxy::Message::MT_CLIENT_HELLO) {
  58. if (!defined $chversion) {
  59. $chversion = $message->client_version;
  60. } else {
  61. if ($chversion == $message->client_version) {
  62. $chmatch = 1;
  63. }
  64. }
  65. }
  66. }
  67. ok(TLSProxy::Message->success() && $chmatch,
  68. "Check ClientHello version is the same");
  69. }
  70. sub reneg_filter
  71. {
  72. my $proxy = shift;
  73. # We're only interested in the initial ClientHello message
  74. if ($proxy->flight != 0) {
  75. return;
  76. }
  77. foreach my $message (@{$proxy->message_list}) {
  78. if ($message->mt == TLSProxy::Message::MT_CLIENT_HELLO) {
  79. #Remove any SCSV ciphersuites - just leave AES128-SHA (0x002f)
  80. my @ciphersuite = (0x002f);
  81. $message->ciphersuites(\@ciphersuite);
  82. $message->ciphersuite_len(2);
  83. $message->repack();
  84. }
  85. }
  86. }