70-test_comp.t 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. #! /usr/bin/env perl
  2. # Copyright 2017-2020 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 srctop_dir bldtop_dir/;
  10. use OpenSSL::Test::Utils;
  11. use File::Temp qw(tempfile);
  12. use TLSProxy::Proxy;
  13. my $test_name = "test_comp";
  14. setup($test_name);
  15. plan skip_all => "TLSProxy isn't usable on $^O"
  16. if $^O =~ /^(VMS)$/;
  17. plan skip_all => "$test_name needs the dynamic engine feature enabled"
  18. if disabled("engine") || disabled("dynamic-engine");
  19. plan skip_all => "$test_name needs the sock feature enabled"
  20. if disabled("sock");
  21. plan skip_all => "$test_name needs TLSv1.3 or TLSv1.2 enabled"
  22. if disabled("tls1_3") && disabled("tls1_2");
  23. $ENV{OPENSSL_ia32cap} = '~0x200000200000000';
  24. use constant {
  25. MULTIPLE_COMPRESSIONS => 0,
  26. NON_NULL_COMPRESSION => 1
  27. };
  28. my $testtype;
  29. my $proxy = TLSProxy::Proxy->new(
  30. undef,
  31. cmdstr(app(["openssl"]), display => 1),
  32. srctop_file("apps", "server.pem"),
  33. (!$ENV{HARNESS_ACTIVE} || $ENV{HARNESS_VERBOSE})
  34. );
  35. $proxy->start() or plan skip_all => "Unable to start up Proxy for tests";
  36. plan tests => 4;
  37. SKIP: {
  38. skip "TLSv1.2 disabled", 2 if disabled("tls1_2");
  39. #Test 1: Check that sending multiple compression methods in a TLSv1.2
  40. # ClientHello succeeds
  41. $proxy->clear();
  42. $proxy->filter(\&add_comp_filter);
  43. $proxy->clientflags("-no_tls1_3");
  44. $testtype = MULTIPLE_COMPRESSIONS;
  45. $proxy->start();
  46. ok(TLSProxy::Message->success(), "Non null compression");
  47. #Test 2: NULL compression method must be present in TLSv1.2
  48. $proxy->clear();
  49. $proxy->clientflags("-no_tls1_3");
  50. $testtype = NON_NULL_COMPRESSION;
  51. $proxy->start();
  52. ok(TLSProxy::Message->fail(), "NULL compression missing");
  53. }
  54. SKIP: {
  55. skip "TLSv1.3 disabled", 2 if disabled("tls1_3");
  56. #Test 3: Check that sending multiple compression methods in a TLSv1.3
  57. # ClientHello fails
  58. $proxy->clear();
  59. $proxy->filter(\&add_comp_filter);
  60. $testtype = MULTIPLE_COMPRESSIONS;
  61. $proxy->start();
  62. ok(TLSProxy::Message->fail(), "Non null compression (TLSv1.3)");
  63. #Test 4: NULL compression method must be present in TLSv1.3
  64. $proxy->clear();
  65. $testtype = NON_NULL_COMPRESSION;
  66. $proxy->start();
  67. ok(TLSProxy::Message->fail(), "NULL compression missing (TLSv1.3)");
  68. }
  69. sub add_comp_filter
  70. {
  71. my $proxy = shift;
  72. my $flight;
  73. my $message;
  74. my @comp;
  75. # Only look at the ClientHello
  76. return if $proxy->flight != 0;
  77. $message = ${$proxy->message_list}[0];
  78. return if (!defined $message
  79. || $message->mt != TLSProxy::Message::MT_CLIENT_HELLO);
  80. if ($testtype == MULTIPLE_COMPRESSIONS) {
  81. @comp = (
  82. 0x00, #Null compression method
  83. 0xff); #Unknown compression
  84. } elsif ($testtype == NON_NULL_COMPRESSION) {
  85. @comp = (0xff); #Unknown compression
  86. }
  87. $message->comp_meths(\@comp);
  88. $message->comp_meth_len(scalar @comp);
  89. $message->repack();
  90. }