70-test_comp.t 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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 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. $ENV{CTLOG_FILE} = srctop_file("test", "ct", "log_list.conf");
  25. use constant {
  26. MULTIPLE_COMPRESSIONS => 0,
  27. NON_NULL_COMPRESSION => 1
  28. };
  29. my $testtype;
  30. my $proxy = TLSProxy::Proxy->new(
  31. undef,
  32. cmdstr(app(["openssl"]), display => 1),
  33. srctop_file("apps", "server.pem"),
  34. (!$ENV{HARNESS_ACTIVE} || $ENV{HARNESS_VERBOSE})
  35. );
  36. $proxy->start() or plan skip_all => "Unable to start up Proxy for tests";
  37. plan tests => 4;
  38. SKIP: {
  39. skip "TLSv1.2 disabled", 2 if disabled("tls1_2");
  40. #Test 1: Check that sending multiple compression methods in a TLSv1.2
  41. # ClientHello succeeds
  42. $proxy->clear();
  43. $proxy->filter(\&add_comp_filter);
  44. $proxy->clientflags("-no_tls1_3");
  45. $testtype = MULTIPLE_COMPRESSIONS;
  46. $proxy->start();
  47. ok(TLSProxy::Message->success(), "Non null compression");
  48. #Test 2: NULL compression method must be present in TLSv1.2
  49. $proxy->clear();
  50. $proxy->clientflags("-no_tls1_3");
  51. $testtype = NON_NULL_COMPRESSION;
  52. $proxy->start();
  53. ok(TLSProxy::Message->fail(), "NULL compression missing");
  54. }
  55. SKIP: {
  56. skip "TLSv1.3 disabled", 2 if disabled("tls1_3");
  57. #Test 3: Check that sending multiple compression methods in a TLSv1.3
  58. # ClientHello fails
  59. $proxy->clear();
  60. $proxy->filter(\&add_comp_filter);
  61. $testtype = MULTIPLE_COMPRESSIONS;
  62. $proxy->start();
  63. ok(TLSProxy::Message->fail(), "Non null compression (TLSv1.3)");
  64. #Test 4: NULL compression method must be present in TLSv1.3
  65. $proxy->clear();
  66. $testtype = NON_NULL_COMPRESSION;
  67. $proxy->start();
  68. ok(TLSProxy::Message->fail(), "NULL compression missing (TLSv1.3)");
  69. }
  70. sub add_comp_filter
  71. {
  72. my $proxy = shift;
  73. my $flight;
  74. my $message;
  75. my @comp;
  76. # Only look at the ClientHello
  77. return if $proxy->flight != 0;
  78. $message = ${$proxy->message_list}[0];
  79. return if (!defined $message
  80. || $message->mt != TLSProxy::Message::MT_CLIENT_HELLO);
  81. if ($testtype == MULTIPLE_COMPRESSIONS) {
  82. @comp = (
  83. 0x00, #Null compression method
  84. 0xff); #Unknown compression
  85. } elsif ($testtype == NON_NULL_COMPRESSION) {
  86. @comp = (0xff); #Unknown compression
  87. }
  88. $message->comp_meths(\@comp);
  89. $message->comp_meth_len(scalar @comp);
  90. $message->repack();
  91. }