2 # Copyright 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_sslsignature";
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 CORRUPT_SERVER_CERT_VERIFY => 1,
40 CORRUPT_CLIENT_CERT_VERIFY => 2,
41 CORRUPT_TLS1_2_SERVER_KEY_EXCHANGE => 3,
44 $proxy->filter(\&signature_filter);
46 #Test 1: No corruption should succeed
47 my $testtype = NO_CORRUPTION;
48 $proxy->start() or plan skip_all => "Unable to start up Proxy for tests";
50 ok(TLSProxy::Message->success, "No corruption");
53 skip "TLSv1.3 disabled", 1 if disabled("tls1_3");
55 #Test 2: Corrupting a server CertVerify signature in TLSv1.3 should fail
57 $testtype = CORRUPT_SERVER_CERT_VERIFY;
59 ok(TLSProxy::Message->fail, "Corrupt server TLSv1.3 CertVerify");
61 #Test x: Corrupting a client CertVerify signature in TLSv1.3 should fail
63 #$testtype = CORRUPT_CLIENT_CERT_VERIFY;
64 #$proxy->serverflags("-Verify 5");
65 #$proxy->clientflags("-cert ".srctop_file("apps", "server.pem"));
67 #ok(TLSProxy::Message->fail, "Corrupt client TLSv1.3 CertVerify");
68 #TODO(TLS1.3): This test fails due to a problem in s_server/TLSProxy.
69 #Currently a connection is counted as "successful" if the client ends it
70 #with a close_notify. In TLSProxy the client initiates the closure of the
71 #connection so really we should not count it as successful until s_server
72 #has also responded with a close_notify. However s_server never sends a
73 #close_notify - it just closes the connection. Fixing this would be a
74 #significant change to the long established behaviour of s_server.
75 #Unfortunately in this test, it is the server that notices the incorrect
76 #signature and responds with an appropriate alert. However s_client never
77 #sees that because it occurs after the server Finished has been sent.
78 #Therefore s_client just continues to send its application data and sends
79 #its close_notify regardless. TLSProxy sees this and thinks that the
80 #connection was successful when in fact it was not. There isn't an easy fix
81 #for this, so leaving this test commented out for now.
85 skip "TLS <= 1.2 disabled", 2
86 if alldisabled(("ssl3", "tls1", "tls1_1", "tls1_2"));
88 #Test 3: Corrupting a CertVerify signature in <=TLSv1.2 should fail
90 $testtype = CORRUPT_CLIENT_CERT_VERIFY;
91 $proxy->serverflags("-Verify 5");
92 $proxy->clientflags("-no_tls1_3 -cert ".srctop_file("apps", "server.pem"));
94 ok(TLSProxy::Message->fail, "Corrupt <=TLSv1.2 CertVerify");
97 skip "DH disabled", 1 if disabled("dh");
99 #Test 4: Corrupting a ServerKeyExchange signature in <=TLSv1.2 should
102 $testtype = CORRUPT_TLS1_2_SERVER_KEY_EXCHANGE;
103 $proxy->clientflags("-no_tls1_3");
104 $proxy->cipherc('DHE-RSA-AES128-SHA');
105 $proxy->ciphers('DHE-RSA-AES128-SHA');
107 ok(TLSProxy::Message->fail, "Corrupt <=TLSv1.2 ServerKeyExchange");
115 my $mt = TLSProxy::Message::MT_CERTIFICATE_VERIFY;
117 if ($testtype == CORRUPT_SERVER_CERT_VERIFY
118 || $testtype == CORRUPT_TLS1_2_SERVER_KEY_EXCHANGE
119 || (!disabled("tls1_3") && $testtype == NO_CORRUPTION)) {
125 # We're only interested in the initial server flight
126 return if ($proxy->flight != $flight);
128 $mt = TLSProxy::Message::MT_SERVER_KEY_EXCHANGE
129 if ($testtype == CORRUPT_TLS1_2_SERVER_KEY_EXCHANGE);
131 foreach my $message (@{$proxy->message_list}) {
132 if ($message->mt == $mt) {
133 my $sig = $message->signature();
134 my $sigbase = substr($sig, 0, -1);
135 my $sigend = unpack("C", substr($sig, -1));
137 #Flip bits in final byte of signature to corrupt the sig
138 $sigend ^= 0xff unless $testtype == NO_CORRUPTION;
140 $message->signature($sigbase.pack("C", $sigend));