2
0

70-test_renegotiation.t 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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->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. sub reneg_filter
  70. {
  71. my $proxy = shift;
  72. # We're only interested in the initial ClientHello message
  73. if ($proxy->flight != 0) {
  74. return;
  75. }
  76. foreach my $message (@{$proxy->message_list}) {
  77. if ($message->mt == TLSProxy::Message::MT_CLIENT_HELLO) {
  78. #Remove any SCSV ciphersuites - just leave AES128-SHA (0x002f)
  79. my @ciphersuite = (0x002f);
  80. $message->ciphersuites(\@ciphersuite);
  81. $message->ciphersuite_len(2);
  82. $message->repack();
  83. }
  84. }
  85. }