2 # Copyright 2017-2021 The OpenSSL Project Authors. All Rights Reserved.
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
10 use OpenSSL::Test qw/:DEFAULT cmdstr srctop_file srctop_dir bldtop_dir/;
11 use OpenSSL::Test::Utils;
12 use File::Temp qw(tempfile);
15 my $test_name = "test_comp";
18 plan skip_all => "TLSProxy isn't usable on $^O"
21 plan skip_all => "$test_name needs the dynamic engine feature enabled"
22 if disabled("engine") || disabled("dynamic-engine");
24 plan skip_all => "$test_name needs the sock feature enabled"
27 plan skip_all => "$test_name needs TLSv1.3 or TLSv1.2 enabled"
28 if disabled("tls1_3") && disabled("tls1_2");
30 $ENV{OPENSSL_ia32cap} = '~0x200000200000000';
33 MULTIPLE_COMPRESSIONS => 0,
34 NON_NULL_COMPRESSION => 1
38 my $proxy = TLSProxy::Proxy->new(
40 cmdstr(app(["openssl"]), display => 1),
41 srctop_file("apps", "server.pem"),
42 (!$ENV{HARNESS_ACTIVE} || $ENV{HARNESS_VERBOSE})
45 $proxy->start() or plan skip_all => "Unable to start up Proxy for tests";
49 skip "TLSv1.2 disabled", 2 if disabled("tls1_2");
50 #Test 1: Check that sending multiple compression methods in a TLSv1.2
51 # ClientHello succeeds
53 $proxy->filter(\&add_comp_filter);
54 $proxy->clientflags("-no_tls1_3");
55 $testtype = MULTIPLE_COMPRESSIONS;
57 ok(TLSProxy::Message->success(), "Non null compression");
59 #Test 2: NULL compression method must be present in TLSv1.2
61 $proxy->clientflags("-no_tls1_3");
62 $testtype = NON_NULL_COMPRESSION;
64 ok(TLSProxy::Message->fail(), "NULL compression missing");
68 skip "TLSv1.3 disabled", 2
69 if disabled("tls1_3") || (disabled("ec") && disabled("dh"));
70 #Test 3: Check that sending multiple compression methods in a TLSv1.3
73 $proxy->filter(\&add_comp_filter);
74 $testtype = MULTIPLE_COMPRESSIONS;
76 ok(TLSProxy::Message->fail(), "Non null compression (TLSv1.3)");
78 #Test 4: NULL compression method must be present in TLSv1.3
80 $testtype = NON_NULL_COMPRESSION;
82 ok(TLSProxy::Message->fail(), "NULL compression missing (TLSv1.3)");
92 # Only look at the ClientHello
93 return if $proxy->flight != 0;
95 $message = ${$proxy->message_list}[0];
97 return if (!defined $message
98 || $message->mt != TLSProxy::Message::MT_CLIENT_HELLO);
100 if ($testtype == MULTIPLE_COMPRESSIONS) {
102 0x00, #Null compression method
103 0xff); #Unknown compression
104 } elsif ($testtype == NON_NULL_COMPRESSION) {
105 @comp = (0xff); #Unknown compression
107 $message->comp_meths(\@comp);
108 $message->comp_meth_len(scalar @comp);