70-test_tls13hrr.t 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. #! /usr/bin/env perl
  2. # Copyright 2017-2018 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_tls13hrr";
  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 TLS1.3 enabled"
  21. if disabled("tls1_3");
  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. use constant {
  30. CHANGE_HRR_CIPHERSUITE => 0,
  31. CHANGE_CH1_CIPHERSUITE => 1
  32. };
  33. #Test 1: A client should fail if the server changes the ciphersuite between the
  34. # HRR and the SH
  35. $proxy->filter(\&hrr_filter);
  36. $proxy->serverflags("-curves P-256");
  37. my $testtype = CHANGE_HRR_CIPHERSUITE;
  38. $proxy->start() or plan skip_all => "Unable to start up Proxy for tests";
  39. plan tests => 2;
  40. ok(TLSProxy::Message->fail(), "Server ciphersuite changes");
  41. #Test 2: It is an error if the client changes the offered ciphersuites so that
  42. # we end up selecting a different ciphersuite between HRR and the SH
  43. $proxy->clear();
  44. $proxy->serverflags("-curves P-256");
  45. $proxy->ciphersuitess("TLS_AES_128_GCM_SHA256:TLS_AES_256_GCM_SHA384");
  46. $testtype = CHANGE_CH1_CIPHERSUITE;
  47. $proxy->start();
  48. ok(TLSProxy::Message->fail(), "Client ciphersuite changes");
  49. sub hrr_filter
  50. {
  51. my $proxy = shift;
  52. if ($testtype == CHANGE_HRR_CIPHERSUITE) {
  53. # We're only interested in the HRR
  54. if ($proxy->flight != 1) {
  55. return;
  56. }
  57. my $hrr = ${$proxy->message_list}[1];
  58. # We will normally only ever select CIPHER_TLS13_AES_128_GCM_SHA256
  59. # because that's what Proxy tells s_server to do. Setting as below means
  60. # the ciphersuite will change will we get the ServerHello
  61. $hrr->ciphersuite(TLSProxy::Message::CIPHER_TLS13_AES_256_GCM_SHA384);
  62. $hrr->repack();
  63. return;
  64. }
  65. # CHANGE_CH1_CIPHERSUITE
  66. if ($proxy->flight != 0) {
  67. return;
  68. }
  69. my $ch1 = ${$proxy->message_list}[0];
  70. # The server will always pick TLS_AES_256_GCM_SHA384
  71. my @ciphersuites = (TLSProxy::Message::CIPHER_TLS13_AES_128_GCM_SHA256);
  72. $ch1->ciphersuite_len(2 * scalar @ciphersuites);
  73. $ch1->ciphersuites(\@ciphersuites);
  74. $ch1->repack();
  75. }