1*e0c4386eSCy Schubert#! /usr/bin/env perl 2*e0c4386eSCy Schubert# Copyright 2017-2021 The OpenSSL Project Authors. All Rights Reserved. 3*e0c4386eSCy Schubert# 4*e0c4386eSCy Schubert# Licensed under the Apache License 2.0 (the "License"). You may not use 5*e0c4386eSCy Schubert# this file except in compliance with the License. You can obtain a copy 6*e0c4386eSCy Schubert# in the file LICENSE in the source distribution or at 7*e0c4386eSCy Schubert# https://www.openssl.org/source/license.html 8*e0c4386eSCy Schubert 9*e0c4386eSCy Schubertuse strict; 10*e0c4386eSCy Schubertuse OpenSSL::Test qw/:DEFAULT cmdstr srctop_file srctop_dir bldtop_dir/; 11*e0c4386eSCy Schubertuse OpenSSL::Test::Utils; 12*e0c4386eSCy Schubertuse File::Temp qw(tempfile); 13*e0c4386eSCy Schubertuse TLSProxy::Proxy; 14*e0c4386eSCy Schubert 15*e0c4386eSCy Schubertmy $test_name = "test_comp"; 16*e0c4386eSCy Schubertsetup($test_name); 17*e0c4386eSCy Schubert 18*e0c4386eSCy Schubertplan skip_all => "TLSProxy isn't usable on $^O" 19*e0c4386eSCy Schubert if $^O =~ /^(VMS)$/; 20*e0c4386eSCy Schubert 21*e0c4386eSCy Schubertplan skip_all => "$test_name needs the dynamic engine feature enabled" 22*e0c4386eSCy Schubert if disabled("engine") || disabled("dynamic-engine"); 23*e0c4386eSCy Schubert 24*e0c4386eSCy Schubertplan skip_all => "$test_name needs the sock feature enabled" 25*e0c4386eSCy Schubert if disabled("sock"); 26*e0c4386eSCy Schubert 27*e0c4386eSCy Schubertplan skip_all => "$test_name needs TLSv1.3 or TLSv1.2 enabled" 28*e0c4386eSCy Schubert if disabled("tls1_3") && disabled("tls1_2"); 29*e0c4386eSCy Schubert 30*e0c4386eSCy Schubert$ENV{OPENSSL_ia32cap} = '~0x200000200000000'; 31*e0c4386eSCy Schubert 32*e0c4386eSCy Schubertuse constant { 33*e0c4386eSCy Schubert MULTIPLE_COMPRESSIONS => 0, 34*e0c4386eSCy Schubert NON_NULL_COMPRESSION => 1 35*e0c4386eSCy Schubert}; 36*e0c4386eSCy Schubertmy $testtype; 37*e0c4386eSCy Schubert 38*e0c4386eSCy Schubertmy $proxy = TLSProxy::Proxy->new( 39*e0c4386eSCy Schubert undef, 40*e0c4386eSCy Schubert cmdstr(app(["openssl"]), display => 1), 41*e0c4386eSCy Schubert srctop_file("apps", "server.pem"), 42*e0c4386eSCy Schubert (!$ENV{HARNESS_ACTIVE} || $ENV{HARNESS_VERBOSE}) 43*e0c4386eSCy Schubert); 44*e0c4386eSCy Schubert 45*e0c4386eSCy Schubert$proxy->start() or plan skip_all => "Unable to start up Proxy for tests"; 46*e0c4386eSCy Schubertplan tests => 4; 47*e0c4386eSCy Schubert 48*e0c4386eSCy SchubertSKIP: { 49*e0c4386eSCy Schubert skip "TLSv1.2 disabled", 2 if disabled("tls1_2"); 50*e0c4386eSCy Schubert #Test 1: Check that sending multiple compression methods in a TLSv1.2 51*e0c4386eSCy Schubert # ClientHello succeeds 52*e0c4386eSCy Schubert $proxy->clear(); 53*e0c4386eSCy Schubert $proxy->filter(\&add_comp_filter); 54*e0c4386eSCy Schubert $proxy->clientflags("-no_tls1_3"); 55*e0c4386eSCy Schubert $testtype = MULTIPLE_COMPRESSIONS; 56*e0c4386eSCy Schubert $proxy->start(); 57*e0c4386eSCy Schubert ok(TLSProxy::Message->success(), "Non null compression"); 58*e0c4386eSCy Schubert 59*e0c4386eSCy Schubert #Test 2: NULL compression method must be present in TLSv1.2 60*e0c4386eSCy Schubert $proxy->clear(); 61*e0c4386eSCy Schubert $proxy->clientflags("-no_tls1_3"); 62*e0c4386eSCy Schubert $testtype = NON_NULL_COMPRESSION; 63*e0c4386eSCy Schubert $proxy->start(); 64*e0c4386eSCy Schubert ok(TLSProxy::Message->fail(), "NULL compression missing"); 65*e0c4386eSCy Schubert} 66*e0c4386eSCy Schubert 67*e0c4386eSCy SchubertSKIP: { 68*e0c4386eSCy Schubert skip "TLSv1.3 disabled", 2 69*e0c4386eSCy Schubert if disabled("tls1_3") || (disabled("ec") && disabled("dh")); 70*e0c4386eSCy Schubert #Test 3: Check that sending multiple compression methods in a TLSv1.3 71*e0c4386eSCy Schubert # ClientHello fails 72*e0c4386eSCy Schubert $proxy->clear(); 73*e0c4386eSCy Schubert $proxy->filter(\&add_comp_filter); 74*e0c4386eSCy Schubert $testtype = MULTIPLE_COMPRESSIONS; 75*e0c4386eSCy Schubert $proxy->start(); 76*e0c4386eSCy Schubert ok(TLSProxy::Message->fail(), "Non null compression (TLSv1.3)"); 77*e0c4386eSCy Schubert 78*e0c4386eSCy Schubert #Test 4: NULL compression method must be present in TLSv1.3 79*e0c4386eSCy Schubert $proxy->clear(); 80*e0c4386eSCy Schubert $testtype = NON_NULL_COMPRESSION; 81*e0c4386eSCy Schubert $proxy->start(); 82*e0c4386eSCy Schubert ok(TLSProxy::Message->fail(), "NULL compression missing (TLSv1.3)"); 83*e0c4386eSCy Schubert} 84*e0c4386eSCy Schubert 85*e0c4386eSCy Schubertsub add_comp_filter 86*e0c4386eSCy Schubert{ 87*e0c4386eSCy Schubert my $proxy = shift; 88*e0c4386eSCy Schubert my $flight; 89*e0c4386eSCy Schubert my $message; 90*e0c4386eSCy Schubert my @comp; 91*e0c4386eSCy Schubert 92*e0c4386eSCy Schubert # Only look at the ClientHello 93*e0c4386eSCy Schubert return if $proxy->flight != 0; 94*e0c4386eSCy Schubert 95*e0c4386eSCy Schubert $message = ${$proxy->message_list}[0]; 96*e0c4386eSCy Schubert 97*e0c4386eSCy Schubert return if (!defined $message 98*e0c4386eSCy Schubert || $message->mt != TLSProxy::Message::MT_CLIENT_HELLO); 99*e0c4386eSCy Schubert 100*e0c4386eSCy Schubert if ($testtype == MULTIPLE_COMPRESSIONS) { 101*e0c4386eSCy Schubert @comp = ( 102*e0c4386eSCy Schubert 0x00, #Null compression method 103*e0c4386eSCy Schubert 0xff); #Unknown compression 104*e0c4386eSCy Schubert } elsif ($testtype == NON_NULL_COMPRESSION) { 105*e0c4386eSCy Schubert @comp = (0xff); #Unknown compression 106*e0c4386eSCy Schubert } 107*e0c4386eSCy Schubert $message->comp_meths(\@comp); 108*e0c4386eSCy Schubert $message->comp_meth_len(scalar @comp); 109*e0c4386eSCy Schubert $message->repack(); 110*e0c4386eSCy Schubert} 111