Unified copyright for test recipes
[openssl.git] / test / recipes / 70-test_sslskewith0p.t
1 #! /usr/bin/env perl
2 # Copyright 2015-2016 The OpenSSL Project Authors. All Rights Reserved.
3 #
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
8
9 use strict;
10 use OpenSSL::Test qw/:DEFAULT cmdstr srctop_file bldtop_dir/;
11 use OpenSSL::Test::Utils;
12 use TLSProxy::Proxy;
13
14 my $test_name = "test_sslskewith0p";
15 setup($test_name);
16
17 plan skip_all => "TLSProxy isn't usable on $^O"
18     if $^O =~ /^(VMS|MSWin32)$/;
19
20 plan skip_all => "$test_name needs the dynamic engine feature enabled"
21     if disabled("engine") || disabled("dynamic-engine");
22
23 plan skip_all => "dh is not supported by this OpenSSL build"
24     if disabled("dh");
25
26 plan skip_all => "$test_name needs the sock feature enabled"
27     if disabled("sock");
28
29 $ENV{OPENSSL_ia32cap} = '~0x200000200000000';
30 my $proxy = TLSProxy::Proxy->new(
31     \&ske_0_p_filter,
32     cmdstr(app(["openssl"]), display => 1),
33     srctop_file("apps", "server.pem"),
34     (!$ENV{HARNESS_ACTIVE} || $ENV{HARNESS_VERBOSE})
35 );
36
37 plan tests => 1;
38
39 #We must use an anon DHE cipher for this test
40 $proxy->cipherc('ADH-AES128-SHA:@SECLEVEL=0');
41 $proxy->ciphers('ADH-AES128-SHA:@SECLEVEL=0');
42
43 $proxy->start();
44 ok(TLSProxy::Message->fail, "ServerKeyExchange with 0 p");
45
46 sub ske_0_p_filter
47 {
48     my $proxy = shift;
49
50     # We're only interested in the SKE - always in flight 1
51     if ($proxy->flight != 1) {
52         return;
53     }
54
55     foreach my $message (@{$proxy->message_list}) {
56         if ($message->mt == TLSProxy::Message::MT_SERVER_KEY_EXCHANGE) {
57             #Set p to a value of 0
58             $message->p(pack('C', 0));
59
60             $message->repack();
61         }
62     }
63 }