2 # Copyright 2015-2016 The OpenSSL Project Authors. All Rights Reserved.
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
10 use OpenSSL::Test qw/:DEFAULT cmdstr srctop_file bldtop_dir/;
11 use OpenSSL::Test::Utils;
14 my $test_name = "test_sslextension";
17 plan skip_all => "TLSProxy isn't usable on $^O"
18 if $^O =~ /^(VMS|MSWin32)$/;
20 plan skip_all => "$test_name needs the dynamic engine feature enabled"
21 if disabled("engine") || disabled("dynamic-engine");
23 plan skip_all => "$test_name needs the sock feature enabled"
26 plan skip_all => "$test_name needs TLS enabled"
27 if alldisabled(available_protocols("tls"));
29 $ENV{OPENSSL_ia32cap} = '~0x200000200000000';
30 my $proxy = TLSProxy::Proxy->new(
32 cmdstr(app(["openssl"]), display => 1),
33 srctop_file("apps", "server.pem"),
34 (!$ENV{HARNESS_ACTIVE} || $ENV{HARNESS_VERBOSE})
37 # Test 1: Sending a zero length extension block should pass
38 $proxy->start() or plan skip_all => "Unable to start up Proxy for tests";
40 ok(TLSProxy::Message->success, "Zero extension length test");
46 if ($proxy->flight == 1) {
47 # Change the ServerRandom so that the downgrade sentinel doesn't cause
48 # the connection to fail
49 my $message = ${$proxy->message_list}[1];
50 $message->random("\0"x32);
55 # We're only interested in the initial ClientHello
56 if ($proxy->flight != 0) {
60 foreach my $message (@{$proxy->message_list}) {
61 if ($message->mt == TLSProxy::Message::MT_CLIENT_HELLO) {
62 # Remove all extensions and set the extension len to zero
63 $message->extension_data({});
64 $message->extensions_len(0);
65 # Extensions have been removed so make sure we don't try to use them
66 $message->process_extensions();
73 # Test 2-3: Sending a duplicate extension should fail.
74 sub inject_duplicate_extension
76 my ($proxy, $message_type) = @_;
78 foreach my $message (@{$proxy->message_list}) {
79 if ($message->mt == $message_type) {
80 my %extensions = %{$message->extension_data};
81 # Add a duplicate (unknown) extension.
82 $message->set_extension(TLSProxy::Message::EXT_DUPLICATE_EXTENSION, "");
83 $message->set_extension(TLSProxy::Message::EXT_DUPLICATE_EXTENSION, "");
89 sub inject_duplicate_extension_clienthello
93 # We're only interested in the initial ClientHello
94 if ($proxy->flight != 0) {
98 inject_duplicate_extension($proxy, TLSProxy::Message::MT_CLIENT_HELLO);
101 sub inject_duplicate_extension_serverhello
105 # We're only interested in the initial ServerHello
106 if ($proxy->flight != 1) {
110 inject_duplicate_extension($proxy, TLSProxy::Message::MT_SERVER_HELLO);
114 $proxy->filter(\&inject_duplicate_extension_clienthello);
116 ok(TLSProxy::Message->fail(), "Duplicate ClientHello extension");
119 $proxy->filter(\&inject_duplicate_extension_serverhello);
121 ok(TLSProxy::Message->fail(), "Duplicate ServerHello extension");