Add a test for supported_groups in the EE message
[openssl.git] / test / recipes / 70-test_tls13messages.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 srctop_dir bldtop_dir/;
11 use OpenSSL::Test::Utils;
12 use File::Temp qw(tempfile);
13 use TLSProxy::Proxy;
14 use checkhandshake qw(checkhandshake @handmessages @extensions);
15
16 my $test_name = "test_tls13messages";
17 setup($test_name);
18
19 plan skip_all => "TLSProxy isn't usable on $^O"
20     if $^O =~ /^(VMS|MSWin32)$/;
21
22 plan skip_all => "$test_name needs the dynamic engine feature enabled"
23     if disabled("engine") || disabled("dynamic-engine");
24
25 plan skip_all => "$test_name needs the sock feature enabled"
26     if disabled("sock");
27
28 plan skip_all => "$test_name needs TLSv1.3 enabled"
29     if disabled("tls1_3");
30
31 $ENV{OPENSSL_ia32cap} = '~0x200000200000000';
32 $ENV{CTLOG_FILE} = srctop_file("test", "ct", "log_list.conf");
33
34
35 @handmessages = (
36     [TLSProxy::Message::MT_CLIENT_HELLO,
37         checkhandshake::ALL_HANDSHAKES],
38     [TLSProxy::Message::MT_HELLO_RETRY_REQUEST,
39         checkhandshake::HRR_HANDSHAKE | checkhandshake::HRR_RESUME_HANDSHAKE],
40     [TLSProxy::Message::MT_CLIENT_HELLO,
41         checkhandshake::HRR_HANDSHAKE | checkhandshake::HRR_RESUME_HANDSHAKE],
42     [TLSProxy::Message::MT_SERVER_HELLO,
43         checkhandshake::ALL_HANDSHAKES],
44     [TLSProxy::Message::MT_ENCRYPTED_EXTENSIONS,
45         checkhandshake::ALL_HANDSHAKES],
46     [TLSProxy::Message::MT_CERTIFICATE_REQUEST,
47         checkhandshake::CLIENT_AUTH_HANDSHAKE],
48     [TLSProxy::Message::MT_CERTIFICATE,
49         checkhandshake::ALL_HANDSHAKES & ~(checkhandshake::RESUME_HANDSHAKE | checkhandshake::HRR_RESUME_HANDSHAKE)],
50     [TLSProxy::Message::MT_CERTIFICATE_VERIFY,
51         checkhandshake::ALL_HANDSHAKES & ~(checkhandshake::RESUME_HANDSHAKE | checkhandshake::HRR_RESUME_HANDSHAKE)],
52     [TLSProxy::Message::MT_FINISHED,
53         checkhandshake::ALL_HANDSHAKES],
54     [TLSProxy::Message::MT_CERTIFICATE,
55         checkhandshake::CLIENT_AUTH_HANDSHAKE],
56     [TLSProxy::Message::MT_CERTIFICATE_VERIFY,
57         checkhandshake::CLIENT_AUTH_HANDSHAKE],
58     [TLSProxy::Message::MT_FINISHED,
59         checkhandshake::ALL_HANDSHAKES],
60     [0, 0]
61 );
62
63 @extensions = (
64     [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_SERVER_NAME,
65         checkhandshake::SERVER_NAME_CLI_EXTENSION],
66     [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_STATUS_REQUEST,
67         checkhandshake::STATUS_REQUEST_CLI_EXTENSION],
68     [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_SUPPORTED_GROUPS,
69         checkhandshake::DEFAULT_EXTENSIONS],
70     [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_EC_POINT_FORMATS,
71         checkhandshake::DEFAULT_EXTENSIONS],
72     [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_SIG_ALGS,
73         checkhandshake::DEFAULT_EXTENSIONS],
74     [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_ALPN,
75         checkhandshake::ALPN_CLI_EXTENSION],
76     [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_SCT,
77         checkhandshake::SCT_CLI_EXTENSION],
78     [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_ENCRYPT_THEN_MAC,
79         checkhandshake::DEFAULT_EXTENSIONS],
80     [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_EXTENDED_MASTER_SECRET,
81         checkhandshake::DEFAULT_EXTENSIONS],
82     [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_SESSION_TICKET,
83         checkhandshake::DEFAULT_EXTENSIONS],
84     [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_KEY_SHARE,
85         checkhandshake::DEFAULT_EXTENSIONS],
86     [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_SUPPORTED_VERSIONS,
87         checkhandshake::DEFAULT_EXTENSIONS],
88     [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_PSK_KEX_MODES,
89         checkhandshake::DEFAULT_EXTENSIONS],
90     [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_PSK,
91         checkhandshake::PSK_CLI_EXTENSION],
92
93     [TLSProxy::Message::MT_HELLO_RETRY_REQUEST, TLSProxy::Message::EXT_KEY_SHARE,
94         checkhandshake::KEY_SHARE_HRR_EXTENSION],
95
96     [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_SERVER_NAME,
97         checkhandshake::SERVER_NAME_CLI_EXTENSION],
98     [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_STATUS_REQUEST,
99         checkhandshake::STATUS_REQUEST_CLI_EXTENSION],
100     [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_SUPPORTED_GROUPS,
101         checkhandshake::DEFAULT_EXTENSIONS],
102     [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_SIG_ALGS,
103         checkhandshake::DEFAULT_EXTENSIONS],
104     [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_ALPN,
105         checkhandshake::ALPN_CLI_EXTENSION],
106     [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_SCT,
107         checkhandshake::SCT_CLI_EXTENSION],
108     [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_KEY_SHARE,
109         checkhandshake::DEFAULT_EXTENSIONS],
110     [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_SUPPORTED_VERSIONS,
111         checkhandshake::DEFAULT_EXTENSIONS],
112     [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_PSK_KEX_MODES,
113         checkhandshake::DEFAULT_EXTENSIONS],
114     [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_PSK,
115         checkhandshake::PSK_CLI_EXTENSION],
116
117     [TLSProxy::Message::MT_SERVER_HELLO, TLSProxy::Message::EXT_KEY_SHARE,
118         checkhandshake::DEFAULT_EXTENSIONS],
119     [TLSProxy::Message::MT_SERVER_HELLO, TLSProxy::Message::EXT_PSK,
120         checkhandshake::PSK_SRV_EXTENSION],
121
122     [TLSProxy::Message::MT_ENCRYPTED_EXTENSIONS, TLSProxy::Message::EXT_SERVER_NAME,
123         checkhandshake::SERVER_NAME_SRV_EXTENSION],
124     [TLSProxy::Message::MT_ENCRYPTED_EXTENSIONS, TLSProxy::Message::EXT_ALPN,
125         checkhandshake::ALPN_SRV_EXTENSION],
126     [TLSProxy::Message::MT_ENCRYPTED_EXTENSIONS, TLSProxy::Message::EXT_SUPPORTED_GROUPS,
127         checkhandshake::SUPPORTED_GROUPS_SRV_EXTENSION],
128
129     [TLSProxy::Message::MT_CERTIFICATE, TLSProxy::Message::EXT_STATUS_REQUEST,
130         checkhandshake::STATUS_REQUEST_SRV_EXTENSION],
131     [TLSProxy::Message::MT_CERTIFICATE, TLSProxy::Message::EXT_SCT,
132         checkhandshake::SCT_SRV_EXTENSION],
133
134     [0,0,0]
135 );
136
137 my $proxy = TLSProxy::Proxy->new(
138     undef,
139     cmdstr(app(["openssl"]), display => 1),
140     srctop_file("apps", "server.pem"),
141     (!$ENV{HARNESS_ACTIVE} || $ENV{HARNESS_VERBOSE})
142 );
143
144 #Test 1: Check we get all the right messages for a default handshake
145 (undef, my $session) = tempfile();
146 $proxy->serverconnects(2);
147 $proxy->clientflags("-sess_out ".$session);
148 $proxy->sessionfile($session);
149 $proxy->start() or plan skip_all => "Unable to start up Proxy for tests";
150 plan tests => 16;
151 checkhandshake($proxy, checkhandshake::DEFAULT_HANDSHAKE,
152                checkhandshake::DEFAULT_EXTENSIONS,
153                "Default handshake test");
154
155 #Test 2: Resumption handshake
156 $proxy->clearClient();
157 $proxy->clientflags("-sess_in ".$session);
158 $proxy->clientstart();
159 checkhandshake($proxy, checkhandshake::RESUME_HANDSHAKE,
160                checkhandshake::DEFAULT_EXTENSIONS
161                | checkhandshake::PSK_CLI_EXTENSION
162                | checkhandshake::PSK_SRV_EXTENSION,
163                "Resumption handshake test");
164
165 #Test 3: A status_request handshake (client request only)
166 $proxy->clear();
167 $proxy->clientflags("-status");
168 $proxy->start();
169 checkhandshake($proxy, checkhandshake::DEFAULT_HANDSHAKE,
170                checkhandshake::DEFAULT_EXTENSIONS
171                | checkhandshake::STATUS_REQUEST_CLI_EXTENSION,
172                "status_request handshake test (client)");
173
174 #Test 4: A status_request handshake (server support only)
175 $proxy->clear();
176 $proxy->serverflags("-status_file "
177                     .srctop_file("test", "recipes", "ocsp-response.der"));
178 $proxy->start();
179 checkhandshake($proxy, checkhandshake::DEFAULT_HANDSHAKE,
180                checkhandshake::DEFAULT_EXTENSIONS,
181                "status_request handshake test (server)");
182
183 #Test 5: A status_request handshake (client and server)
184 #TODO(TLS1.3): TLS1.3 doesn't actually have CertificateStatus messages. This is
185 #a temporary test until such time as we do proper TLS1.3 style certificate
186 #status
187 $proxy->clear();
188 $proxy->clientflags("-status");
189 $proxy->serverflags("-status_file "
190                     .srctop_file("test", "recipes", "ocsp-response.der"));
191 $proxy->start();
192 checkhandshake($proxy, checkhandshake::DEFAULT_HANDSHAKE,
193                checkhandshake::DEFAULT_EXTENSIONS
194                | checkhandshake::STATUS_REQUEST_CLI_EXTENSION
195                | checkhandshake::STATUS_REQUEST_SRV_EXTENSION,
196                "status_request handshake test");
197
198 #Test 6: A client auth handshake
199 $proxy->clear();
200 $proxy->clientflags("-cert ".srctop_file("apps", "server.pem"));
201 $proxy->serverflags("-Verify 5");
202 $proxy->start();
203 checkhandshake($proxy, checkhandshake::CLIENT_AUTH_HANDSHAKE,
204                checkhandshake::DEFAULT_EXTENSIONS,
205                "Client auth handshake test");
206
207 #Test 7: Server name handshake (no client request)
208 $proxy->clear();
209 $proxy->clientflags("-noservername");
210 $proxy->start();
211 checkhandshake($proxy, checkhandshake::DEFAULT_HANDSHAKE,
212                checkhandshake::DEFAULT_EXTENSIONS
213                & ~checkhandshake::SERVER_NAME_CLI_EXTENSION,
214                "Server name handshake test (client)");
215
216 #Test 8: Server name handshake (server support only)
217 $proxy->clear();
218 $proxy->clientflags("-noservername");
219 $proxy->serverflags("-servername testhost");
220 $proxy->start();
221 checkhandshake($proxy, checkhandshake::DEFAULT_HANDSHAKE,
222                checkhandshake::DEFAULT_EXTENSIONS
223                & ~checkhandshake::SERVER_NAME_CLI_EXTENSION,
224                "Server name handshake test (server)");
225
226 #Test 9: Server name handshake (client and server)
227 $proxy->clear();
228 $proxy->clientflags("-servername testhost");
229 $proxy->serverflags("-servername testhost");
230 $proxy->start();
231 checkhandshake($proxy, checkhandshake::DEFAULT_HANDSHAKE,
232                checkhandshake::DEFAULT_EXTENSIONS
233                | checkhandshake::SERVER_NAME_SRV_EXTENSION,
234                "Server name handshake test");
235
236 #Test 10: ALPN handshake (client request only)
237 $proxy->clear();
238 $proxy->clientflags("-alpn test");
239 $proxy->start();
240 checkhandshake($proxy, checkhandshake::DEFAULT_HANDSHAKE,
241                checkhandshake::DEFAULT_EXTENSIONS
242                | checkhandshake::ALPN_CLI_EXTENSION,
243                "ALPN handshake test (client)");
244
245 #Test 11: ALPN handshake (server support only)
246 $proxy->clear();
247 $proxy->serverflags("-alpn test");
248 $proxy->start();
249 checkhandshake($proxy, checkhandshake::DEFAULT_HANDSHAKE,
250                checkhandshake::DEFAULT_EXTENSIONS,
251                "ALPN handshake test (server)");
252
253 #Test 12: ALPN handshake (client and server)
254 $proxy->clear();
255 $proxy->clientflags("-alpn test");
256 $proxy->serverflags("-alpn test");
257 $proxy->start();
258 checkhandshake($proxy, checkhandshake::DEFAULT_HANDSHAKE,
259                checkhandshake::DEFAULT_EXTENSIONS
260                | checkhandshake::ALPN_CLI_EXTENSION
261                | checkhandshake::ALPN_SRV_EXTENSION,
262                "ALPN handshake test");
263
264 SKIP: {
265     skip "No CT, EC or OCSP support in this OpenSSL build", 1
266         if disabled("ct") || disabled("ec") || disabled("ocsp");
267
268     #Test 13: SCT handshake (client request only)
269     $proxy->clear();
270     #Note: -ct also sends status_request
271     $proxy->clientflags("-ct");
272     $proxy->serverflags("-status_file "
273                         .srctop_file("test", "recipes", "ocsp-response.der")
274                         ." -serverinfo ".srctop_file("test", "serverinfo2.pem"));
275     $proxy->start();
276     checkhandshake($proxy, checkhandshake::DEFAULT_HANDSHAKE,
277                    checkhandshake::DEFAULT_EXTENSIONS
278                    | checkhandshake::SCT_CLI_EXTENSION
279                    | checkhandshake::SCT_SRV_EXTENSION
280                    | checkhandshake::STATUS_REQUEST_CLI_EXTENSION
281                    | checkhandshake::STATUS_REQUEST_SRV_EXTENSION,
282                    "SCT handshake test");
283 }
284
285
286
287
288 #Test 14: HRR Handshake
289 $proxy->clear();
290 $proxy->serverflags("-curves P-256");
291 $proxy->start();
292 checkhandshake($proxy, checkhandshake::HRR_HANDSHAKE,
293                checkhandshake::DEFAULT_EXTENSIONS
294                | checkhandshake::KEY_SHARE_HRR_EXTENSION,
295                "HRR handshake test");
296
297 #Test 15: Resumption handshake with HRR
298 $proxy->clear();
299 $proxy->clientflags("-sess_in ".$session);
300 $proxy->serverflags("-curves P-256");
301 $proxy->start();
302 checkhandshake($proxy, checkhandshake::HRR_RESUME_HANDSHAKE,
303                checkhandshake::DEFAULT_EXTENSIONS
304                | checkhandshake::KEY_SHARE_HRR_EXTENSION
305                | checkhandshake::PSK_CLI_EXTENSION
306                | checkhandshake::PSK_SRV_EXTENSION,
307                "Resumption handshake with HRR test");
308
309 #Test 16: Acceptable but non preferred key_share
310 $proxy->clear();
311 $proxy->clientflags("-curves P-256");
312 $proxy->start();
313 checkhandshake($proxy, checkhandshake::DEFAULT_HANDSHAKE,
314                checkhandshake::DEFAULT_EXTENSIONS
315                | checkhandshake::SUPPORTED_GROUPS_SRV_EXTENSION,
316                "Default handshake test");
317
318 unlink $session;