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_sslsigalgs";
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 TLS1.2 or TLS1.3 enabled"
27 if disabled("tls1_2") && disabled("tls1_3");
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 EMPTY_SIG_ALGS_EXT => 1,
40 NO_KNOWN_SIG_ALGS => 2,
42 PSS_ONLY_SIG_ALGS => 4
45 #Note: Throughout this test we override the default ciphersuites where TLSv1.2
46 # is expected to ensure that a ServerKeyExchange message is sent that uses
49 #Test 1: Default sig algs should succeed
50 $proxy->start() or plan skip_all => "Unable to start up Proxy for tests";
52 ok(TLSProxy::Message->success, "Default sigalgs");
56 skip "TLSv1.3 disabled", 5 if disabled("tls1_3");
58 $proxy->filter(\&sigalgs_filter);
60 #Test 2: Sending no sig algs extension in TLSv1.3 should fail
62 $testtype = NO_SIG_ALGS_EXT;
64 ok(TLSProxy::Message->fail, "No TLSv1.3 sigalgs");
66 #Test 3: Sending an empty sig algs extension in TLSv1.3 should fail
68 $testtype = EMPTY_SIG_ALGS_EXT;
70 ok(TLSProxy::Message->fail, "Empty TLSv1.3 sigalgs");
72 #Test 4: Sending a list with no recognised sig algs in TLSv1.3 should fail
74 $testtype = NO_KNOWN_SIG_ALGS;
76 ok(TLSProxy::Message->fail, "No known TLSv1.3 sigalgs");
78 #Test 5: Sending a sig algs list without pss for an RSA cert in TLSv1.3
81 $testtype = NO_PSS_SIG_ALGS;
83 ok(TLSProxy::Message->fail, "No PSS TLSv1.3 sigalgs");
85 #Test 6: Sending only TLSv1.3 PSS sig algs in TLSv1.3 should succeed
86 #TODO(TLS1.3): Do we need to verify the cert to make sure its a PSS only
89 $testtype = PSS_ONLY_SIG_ALGS;
91 ok(TLSProxy::Message->success, "PSS only sigalgs in TLSv1.3");
95 skip "EC, TLSv1.3 or TLSv1.2 disabled", 2
96 if disabled("tls1_2") || disabled("tls1_3") || disabled("ec");
98 #Test 7: Sending a valid sig algs list but not including a sig type that
99 # matches the certificate should fail in TLSv1.3. We need TLSv1.2
100 # enabled for this test - otherwise the client will not attempt to
101 # connect due to no TLSv1.3 ciphers being available.
102 # TODO(TLS1.3): When proper TLSv1.3 certificate selection is working
103 # we can move this test into the section above
105 $proxy->clientflags("-sigalgs ECDSA+SHA256");
106 $proxy->filter(undef);
108 ok(TLSProxy::Message->fail, "No matching TLSv1.3 sigalgs");
110 #Test 8: Sending a full list of TLSv1.3 sig algs but negotiating TLSv1.2
113 $proxy->serverflags("-no_tls1_3");
114 $proxy->ciphers("ECDHE-RSA-AES128-SHA:TLS13-AES-128-GCM-SHA256");
115 $proxy->filter(undef);
117 ok(TLSProxy::Message->success, "TLSv1.3 client TLSv1.2 server");
121 skip "EC or TLSv1.2 disabled", 8 if disabled("tls1_2") || disabled("ec");
123 $proxy->filter(\&sigalgs_filter);
125 #Test 9: Sending no sig algs extension in TLSv1.2 should succeed
127 $testtype = NO_SIG_ALGS_EXT;
128 $proxy->clientflags("-no_tls1_3");
129 $proxy->ciphers("ECDHE-RSA-AES128-SHA:TLS13-AES-128-GCM-SHA256");
131 ok(TLSProxy::Message->success, "No TLSv1.2 sigalgs");
133 #Test 10: Sending an empty sig algs extension in TLSv1.2 should fail
135 $testtype = EMPTY_SIG_ALGS_EXT;
136 $proxy->clientflags("-no_tls1_3");
137 $proxy->ciphers("ECDHE-RSA-AES128-SHA:TLS13-AES-128-GCM-SHA256");
139 ok(TLSProxy::Message->fail, "Empty TLSv1.2 sigalgs");
141 #Test 11: Sending a list with no recognised sig algs in TLSv1.2 should fail
143 $testtype = NO_KNOWN_SIG_ALGS;
144 $proxy->clientflags("-no_tls1_3");
145 $proxy->ciphers("ECDHE-RSA-AES128-SHA:TLS13-AES-128-GCM-SHA256");
147 ok(TLSProxy::Message->fail, "No known TLSv1.3 sigalgs");
149 #Test 12: Sending a sig algs list without pss for an RSA cert in TLSv1.2
152 $testtype = NO_PSS_SIG_ALGS;
153 $proxy->clientflags("-no_tls1_3");
154 $proxy->ciphers("ECDHE-RSA-AES128-SHA:TLS13-AES-128-GCM-SHA256");
156 ok(TLSProxy::Message->success, "No PSS TLSv1.2 sigalgs");
158 #Test 13: Sending only TLSv1.3 PSS sig algs in TLSv1.2 should succeed
160 $testtype = PSS_ONLY_SIG_ALGS;
161 $proxy->serverflags("-no_tls1_3");
162 $proxy->ciphers("ECDHE-RSA-AES128-SHA:TLS13-AES-128-GCM-SHA256");
164 ok(TLSProxy::Message->success, "PSS only sigalgs in TLSv1.2");
166 #Test 14: Responding with a sig alg we did not send in TLSv1.2 should fail
167 # We send rsa_pkcs1_sha256 and respond with rsa_pss_sha256
168 # TODO(TLS1.3): Add a similar test to the TLSv1.3 section above
169 # when we have an API capable of configuring the TLSv1.3 sig algs
171 $testtype = PSS_ONLY_SIG_ALGS;
172 $proxy->clientflags("-no_tls1_3 -sigalgs RSA+SHA256");
173 $proxy->ciphers("ECDHE-RSA-AES128-SHA:TLS13-AES-128-GCM-SHA256");
175 ok(TLSProxy::Message->fail, "Sigalg we did not send in TLSv1.2");
177 #Test 15: Sending a valid sig algs list but not including a sig type that
178 # matches the certificate should fail in TLSv1.2
180 $proxy->clientflags("-no_tls1_3 -sigalgs ECDSA+SHA256");
181 $proxy->ciphers("ECDHE-RSA-AES128-SHA:TLS13-AES-128-GCM-SHA256");
182 $proxy->filter(undef);
184 ok(TLSProxy::Message->fail, "No matching TLSv1.2 sigalgs");
185 $proxy->filter(\&sigalgs_filter);
187 #Test 16: No sig algs extension, ECDSA cert, TLSv1.2 should succeed
189 $testtype = NO_SIG_ALGS_EXT;
190 $proxy->clientflags("-no_tls1_3");
191 $proxy->serverflags("-cert " . srctop_file("test", "certs",
192 "server-ecdsa-cert.pem") .
193 " -key " . srctop_file("test", "certs",
194 "server-ecdsa-key.pem")),
195 $proxy->ciphers("ECDHE-ECDSA-AES128-SHA:TLS13-AES-128-GCM-SHA256");
197 ok(TLSProxy::Message->success, "No TLSv1.2 sigalgs, ECDSA");
206 # We're only interested in the initial ClientHello
207 if ($proxy->flight != 0) {
211 foreach my $message (@{$proxy->message_list}) {
212 if ($message->mt == TLSProxy::Message::MT_CLIENT_HELLO) {
213 if ($testtype == NO_SIG_ALGS_EXT) {
214 $message->delete_extension(TLSProxy::Message::EXT_SIG_ALGS);
217 if ($testtype == EMPTY_SIG_ALGS_EXT) {
218 $sigalg = pack "C2", 0x00, 0x00;
219 } elsif ($testtype == NO_KNOWN_SIG_ALGS) {
220 $sigalg = pack "C4", 0x00, 0x02, 0xff, 0xff;
221 } elsif ($testtype == NO_PSS_SIG_ALGS) {
222 #No PSS sig algs - just send rsa_pkcs1_sha256
223 $sigalg = pack "C4", 0x00, 0x02, 0x04, 0x01;
225 #PSS sig algs only - just send rsa_pss_sha256
226 $sigalg = pack "C4", 0x00, 0x02, 0x08, 0x04;
228 $message->set_extension(TLSProxy::Message::EXT_SIG_ALGS, $sigalg);