70-test_tls13cookie.t 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #! /usr/bin/env perl
  2. # Copyright 2017 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_tls13cookie";
  13. setup($test_name);
  14. plan skip_all => "TLSProxy isn't usable on $^O"
  15. if $^O =~ /^(VMS|MSWin32)$/;
  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. my $cookieseen = 0;
  30. #Test 1: Inserting a cookie into an HRR should see it echoed in the ClientHello
  31. $proxy->filter(\&cookie_filter);
  32. $proxy->serverflags("-curves P-256");
  33. $proxy->start() or plan skip_all => "Unable to start up Proxy for tests";
  34. plan tests => 1;
  35. ok(TLSProxy::Message->success() && $cookieseen == 1, "Cookie seen");
  36. sub cookie_filter
  37. {
  38. my $proxy = shift;
  39. # We're only interested in the HRR and subsequent ClientHello
  40. if ($proxy->flight != 1 && $proxy->flight != 2) {
  41. return;
  42. }
  43. my $ext = pack "C8",
  44. 0x00, 0x06, #Cookie Length
  45. 0x00, 0x01, #Dummy cookie data (6 bytes)
  46. 0x02, 0x03,
  47. 0x04, 0x05;
  48. foreach my $message (@{$proxy->message_list}) {
  49. if ($message->mt == TLSProxy::Message::MT_HELLO_RETRY_REQUEST) {
  50. $message->set_extension(TLSProxy::Message::EXT_COOKIE, $ext);
  51. $message->repack();
  52. } elsif ($message->mt == TLSProxy::Message::MT_CLIENT_HELLO
  53. && ${$message->records}[0]->flight == 2) {
  54. #cmp can behave differently dependent on locale
  55. no locale;
  56. my $cookie =
  57. $message->extension_data->{TLSProxy::Message::EXT_COOKIE};
  58. return if !defined($cookie);
  59. return if ($cookie cmp $ext) != 0;
  60. $cookieseen = 1;
  61. }
  62. }
  63. }