2
0

70-test_tls13hrr.t 3.0 KB

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