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 # We're only interested in the initial ClientHello
47 if ($proxy->flight != 0) {
51 foreach my $message (@{$proxy->message_list}) {
52 if ($message->mt == TLSProxy::Message::MT_CLIENT_HELLO) {
53 # Remove all extensions and set the extension len to zero
54 $message->extension_data({});
55 $message->extensions_len(0);
56 # Extensions have been removed so make sure we don't try to use them
57 $message->process_extensions();
64 # Test 2-3: Sending a duplicate extension should fail.
65 sub inject_duplicate_extension
67 my ($proxy, $message_type) = @_;
69 foreach my $message (@{$proxy->message_list}) {
70 if ($message->mt == $message_type) {
71 my %extensions = %{$message->extension_data};
72 # Add a duplicate (unknown) extension.
73 $message->set_extension(TLSProxy::Message::EXT_DUPLICATE_EXTENSION, "");
74 $message->set_extension(TLSProxy::Message::EXT_DUPLICATE_EXTENSION, "");
80 sub inject_duplicate_extension_clienthello
84 # We're only interested in the initial ClientHello
85 if ($proxy->flight != 0) {
89 inject_duplicate_extension($proxy, TLSProxy::Message::MT_CLIENT_HELLO);
92 sub inject_duplicate_extension_serverhello
96 # We're only interested in the initial ServerHello
97 if ($proxy->flight != 1) {
101 inject_duplicate_extension($proxy, TLSProxy::Message::MT_SERVER_HELLO);
105 $proxy->filter(\&inject_duplicate_extension_clienthello);
107 ok(TLSProxy::Message->fail(), "Duplicate ClientHello extension");
110 $proxy->filter(\&inject_duplicate_extension_serverhello);
112 ok(TLSProxy::Message->fail(), "Duplicate ServerHello extension");