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})
39 # Test 1: Sending a zero length extension block should pass
41 ok(TLSProxy::Message->success, "Zero extension length test");
47 # We're only interested in the initial ClientHello
48 if ($proxy->flight != 0) {
52 foreach my $message (@{$proxy->message_list}) {
53 if ($message->mt == TLSProxy::Message::MT_CLIENT_HELLO) {
54 # Remove all extensions and set the extension len to zero
55 $message->extension_data({});
56 $message->extensions_len(0);
57 # Extensions have been removed so make sure we don't try to use them
58 $message->process_extensions();
65 # Test 2-3: Sending a duplicate extension should fail.
66 sub inject_duplicate_extension
68 my ($proxy, $message_type) = @_;
70 foreach my $message (@{$proxy->message_list}) {
71 if ($message->mt == $message_type) {
72 my %extensions = %{$message->extension_data};
73 # Add a duplicate (unknown) extension.
74 $message->set_extension(TLSProxy::Message::EXT_DUPLICATE_EXTENSION, "");
75 $message->set_extension(TLSProxy::Message::EXT_DUPLICATE_EXTENSION, "");
81 sub inject_duplicate_extension_clienthello
85 # We're only interested in the initial ClientHello
86 if ($proxy->flight != 0) {
90 inject_duplicate_extension($proxy, TLSProxy::Message::MT_CLIENT_HELLO);
93 sub inject_duplicate_extension_serverhello
97 # We're only interested in the initial ServerHello
98 if ($proxy->flight != 1) {
102 inject_duplicate_extension($proxy, TLSProxy::Message::MT_SERVER_HELLO);
106 $proxy->filter(\&inject_duplicate_extension_clienthello);
108 ok(TLSProxy::Message->fail(), "Duplicate ClientHello extension");
111 $proxy->filter(\&inject_duplicate_extension_serverhello);
113 ok(TLSProxy::Message->fail(), "Duplicate ServerHello extension");