2 # Copyright 2016-2021 The OpenSSL Project Authors. All Rights Reserved.
4 # Licensed under the Apache License 2.0 (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"
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 my $proxy = TLSProxy::Proxy->new(
31 cmdstr(app(["openssl"]), display => 1),
32 srctop_file("apps", "server.pem"),
33 (!$ENV{HARNESS_ACTIVE} || $ENV{HARNESS_VERBOSE})
38 CORRUPT_SERVER_CERT_VERIFY => 1,
39 CORRUPT_CLIENT_CERT_VERIFY => 2,
40 CORRUPT_TLS1_2_SERVER_KEY_EXCHANGE => 3,
43 $proxy->filter(\&signature_filter);
45 #Test 1: No corruption should succeed
46 my $testtype = NO_CORRUPTION;
47 $proxy->clientflags("-no_tls1_3") if disabled("ec") && disabled("dh");
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
54 if disabled("tls1_3") || (disabled("ec") && disabled("dh"));
56 #Test 2: Corrupting a server CertVerify signature in TLSv1.3 should fail
58 $testtype = CORRUPT_SERVER_CERT_VERIFY;
60 ok(TLSProxy::Message->fail, "Corrupt server TLSv1.3 CertVerify");
62 #Test x: Corrupting a client CertVerify signature in TLSv1.3 should fail
64 #$testtype = CORRUPT_CLIENT_CERT_VERIFY;
65 #$proxy->serverflags("-Verify 5");
66 #$proxy->clientflags("-cert ".srctop_file("apps", "server.pem"));
68 #ok(TLSProxy::Message->fail, "Corrupt client TLSv1.3 CertVerify");
69 #TODO(TLS1.3): This test fails due to a problem in s_server/TLSProxy.
70 #Currently a connection is counted as "successful" if the client ends it
71 #with a close_notify. In TLSProxy the client initiates the closure of the
72 #connection so really we should not count it as successful until s_server
73 #has also responded with a close_notify. However s_server never sends a
74 #close_notify - it just closes the connection. Fixing this would be a
75 #significant change to the long established behaviour of s_server.
76 #Unfortunately in this test, it is the server that notices the incorrect
77 #signature and responds with an appropriate alert. However s_client never
78 #sees that because it occurs after the server Finished has been sent.
79 #Therefore s_client just continues to send its application data and sends
80 #its close_notify regardless. TLSProxy sees this and thinks that the
81 #connection was successful when in fact it was not. There isn't an easy fix
82 #for this, so leaving this test commented out for now.
86 skip "TLS <= 1.2 disabled", 2
87 if alldisabled(("ssl3", "tls1", "tls1_1", "tls1_2"));
89 #Test 3: Corrupting a CertVerify signature in <=TLSv1.2 should fail
91 $testtype = CORRUPT_CLIENT_CERT_VERIFY;
92 $proxy->serverflags("-Verify 5");
93 $proxy->clientflags("-no_tls1_3 -cert ".srctop_file("apps", "server.pem"));
95 ok(TLSProxy::Message->fail, "Corrupt <=TLSv1.2 CertVerify");
98 skip "DH disabled", 1 if disabled("dh");
100 #Test 4: Corrupting a ServerKeyExchange signature in <=TLSv1.2 should
103 $testtype = CORRUPT_TLS1_2_SERVER_KEY_EXCHANGE;
104 $proxy->clientflags("-no_tls1_3");
105 $proxy->cipherc('DHE-RSA-AES128-SHA');
106 $proxy->ciphers('DHE-RSA-AES128-SHA');
108 ok(TLSProxy::Message->fail, "Corrupt <=TLSv1.2 ServerKeyExchange");
116 my $mt = TLSProxy::Message::MT_CERTIFICATE_VERIFY;
118 if ($testtype == CORRUPT_SERVER_CERT_VERIFY
119 || $testtype == CORRUPT_TLS1_2_SERVER_KEY_EXCHANGE
120 || (!disabled("tls1_3") && $testtype == NO_CORRUPTION)) {
126 # We're only interested in the initial server flight
127 return if ($proxy->flight != $flight);
129 $mt = TLSProxy::Message::MT_SERVER_KEY_EXCHANGE
130 if ($testtype == CORRUPT_TLS1_2_SERVER_KEY_EXCHANGE);
132 foreach my $message (@{$proxy->message_list}) {
133 if ($message->mt == $mt) {
134 my $sig = $message->signature();
135 my $sigbase = substr($sig, 0, -1);
136 my $sigend = unpack("C", substr($sig, -1));
138 #Flip bits in final byte of signature to corrupt the sig
139 $sigend ^= 0xff unless $testtype == NO_CORRUPTION;
141 $message->signature($sigbase.pack("C", $sigend));