Enable TLSProxy tests on Windows
[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)$/;
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_SERVER_HELLO,
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_SERVER_HELLO, TLSProxy::Message::EXT_SUPPORTED_VERSIONS,
94         checkhandshake::DEFAULT_EXTENSIONS],
95     [TLSProxy::Message::MT_SERVER_HELLO, TLSProxy::Message::EXT_KEY_SHARE,
96         checkhandshake::KEY_SHARE_HRR_EXTENSION],
97
98     [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_SERVER_NAME,
99         checkhandshake::SERVER_NAME_CLI_EXTENSION],
100     [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_STATUS_REQUEST,
101         checkhandshake::STATUS_REQUEST_CLI_EXTENSION],
102     [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_SUPPORTED_GROUPS,
103         checkhandshake::DEFAULT_EXTENSIONS],
104     [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_EC_POINT_FORMATS,
105         checkhandshake::DEFAULT_EXTENSIONS],
106     [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_SIG_ALGS,
107         checkhandshake::DEFAULT_EXTENSIONS],
108     [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_ALPN,
109         checkhandshake::ALPN_CLI_EXTENSION],
110     [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_SCT,
111         checkhandshake::SCT_CLI_EXTENSION],
112     [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_ENCRYPT_THEN_MAC,
113         checkhandshake::DEFAULT_EXTENSIONS],
114     [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_EXTENDED_MASTER_SECRET,
115         checkhandshake::DEFAULT_EXTENSIONS],
116     [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_SESSION_TICKET,
117         checkhandshake::DEFAULT_EXTENSIONS],
118     [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_KEY_SHARE,
119         checkhandshake::DEFAULT_EXTENSIONS],
120     [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_SUPPORTED_VERSIONS,
121         checkhandshake::DEFAULT_EXTENSIONS],
122     [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_PSK_KEX_MODES,
123         checkhandshake::DEFAULT_EXTENSIONS],
124     [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_PSK,
125         checkhandshake::PSK_CLI_EXTENSION],
126
127     [TLSProxy::Message::MT_SERVER_HELLO, TLSProxy::Message::EXT_SUPPORTED_VERSIONS,
128         checkhandshake::DEFAULT_EXTENSIONS],
129     [TLSProxy::Message::MT_SERVER_HELLO, TLSProxy::Message::EXT_KEY_SHARE,
130         checkhandshake::DEFAULT_EXTENSIONS],
131     [TLSProxy::Message::MT_SERVER_HELLO, TLSProxy::Message::EXT_PSK,
132         checkhandshake::PSK_SRV_EXTENSION],
133
134     [TLSProxy::Message::MT_ENCRYPTED_EXTENSIONS, TLSProxy::Message::EXT_SERVER_NAME,
135         checkhandshake::SERVER_NAME_SRV_EXTENSION],
136     [TLSProxy::Message::MT_ENCRYPTED_EXTENSIONS, TLSProxy::Message::EXT_ALPN,
137         checkhandshake::ALPN_SRV_EXTENSION],
138     [TLSProxy::Message::MT_ENCRYPTED_EXTENSIONS, TLSProxy::Message::EXT_SUPPORTED_GROUPS,
139         checkhandshake::SUPPORTED_GROUPS_SRV_EXTENSION],
140
141     [TLSProxy::Message::MT_CERTIFICATE, TLSProxy::Message::EXT_STATUS_REQUEST,
142         checkhandshake::STATUS_REQUEST_SRV_EXTENSION],
143     [TLSProxy::Message::MT_CERTIFICATE, TLSProxy::Message::EXT_SCT,
144         checkhandshake::SCT_SRV_EXTENSION],
145
146     [0,0,0]
147 );
148
149 my $proxy = TLSProxy::Proxy->new(
150     undef,
151     cmdstr(app(["openssl"]), display => 1),
152     srctop_file("apps", "server.pem"),
153     (!$ENV{HARNESS_ACTIVE} || $ENV{HARNESS_VERBOSE})
154 );
155
156 #Test 1: Check we get all the right messages for a default handshake
157 (undef, my $session) = tempfile();
158 $proxy->serverconnects(2);
159 $proxy->clientflags("-sess_out ".$session);
160 $proxy->sessionfile($session);
161 $proxy->start() or plan skip_all => "Unable to start up Proxy for tests";
162 plan tests => 16;
163 checkhandshake($proxy, checkhandshake::DEFAULT_HANDSHAKE,
164                checkhandshake::DEFAULT_EXTENSIONS,
165                "Default handshake test");
166
167 #Test 2: Resumption handshake
168 $proxy->clearClient();
169 $proxy->clientflags("-sess_in ".$session);
170 $proxy->clientstart();
171 checkhandshake($proxy, checkhandshake::RESUME_HANDSHAKE,
172                (checkhandshake::DEFAULT_EXTENSIONS
173                 | checkhandshake::PSK_CLI_EXTENSION
174                 | checkhandshake::PSK_SRV_EXTENSION),
175                "Resumption handshake test");
176
177 SKIP: {
178     skip "No OCSP support in this OpenSSL build", 3
179         if disabled("ct") || disabled("ec") || disabled("ocsp");
180     #Test 3: A status_request handshake (client request only)
181     $proxy->clear();
182     $proxy->clientflags("-status");
183     $proxy->start();
184     checkhandshake($proxy, checkhandshake::DEFAULT_HANDSHAKE,
185                    checkhandshake::DEFAULT_EXTENSIONS
186                    | checkhandshake::STATUS_REQUEST_CLI_EXTENSION,
187                    "status_request handshake test (client)");
188
189     #Test 4: A status_request handshake (server support only)
190     $proxy->clear();
191     $proxy->serverflags("-status_file "
192                         .srctop_file("test", "recipes", "ocsp-response.der"));
193     $proxy->start();
194     checkhandshake($proxy, checkhandshake::DEFAULT_HANDSHAKE,
195                    checkhandshake::DEFAULT_EXTENSIONS,
196                    "status_request handshake test (server)");
197
198     #Test 5: A status_request handshake (client and server)
199     $proxy->clear();
200     $proxy->clientflags("-status");
201     $proxy->serverflags("-status_file "
202                         .srctop_file("test", "recipes", "ocsp-response.der"));
203     $proxy->start();
204     checkhandshake($proxy, checkhandshake::DEFAULT_HANDSHAKE,
205                    checkhandshake::DEFAULT_EXTENSIONS
206                    | checkhandshake::STATUS_REQUEST_CLI_EXTENSION
207                    | checkhandshake::STATUS_REQUEST_SRV_EXTENSION,
208                    "status_request handshake test");
209 }
210
211 #Test 6: A client auth handshake
212 $proxy->clear();
213 $proxy->clientflags("-cert ".srctop_file("apps", "server.pem"));
214 $proxy->serverflags("-Verify 5");
215 $proxy->start();
216 checkhandshake($proxy, checkhandshake::CLIENT_AUTH_HANDSHAKE,
217                checkhandshake::DEFAULT_EXTENSIONS,
218                "Client auth handshake test");
219
220 #Test 7: Server name handshake (no client request)
221 $proxy->clear();
222 $proxy->clientflags("-noservername");
223 $proxy->start();
224 checkhandshake($proxy, checkhandshake::DEFAULT_HANDSHAKE,
225                checkhandshake::DEFAULT_EXTENSIONS
226                & ~checkhandshake::SERVER_NAME_CLI_EXTENSION,
227                "Server name handshake test (client)");
228
229 #Test 8: Server name handshake (server support only)
230 $proxy->clear();
231 $proxy->clientflags("-noservername");
232 $proxy->serverflags("-servername testhost");
233 $proxy->start();
234 checkhandshake($proxy, checkhandshake::DEFAULT_HANDSHAKE,
235                checkhandshake::DEFAULT_EXTENSIONS
236                & ~checkhandshake::SERVER_NAME_CLI_EXTENSION,
237                "Server name handshake test (server)");
238
239 #Test 9: Server name handshake (client and server)
240 $proxy->clear();
241 $proxy->clientflags("-servername testhost");
242 $proxy->serverflags("-servername testhost");
243 $proxy->start();
244 checkhandshake($proxy, checkhandshake::DEFAULT_HANDSHAKE,
245                checkhandshake::DEFAULT_EXTENSIONS
246                | checkhandshake::SERVER_NAME_SRV_EXTENSION,
247                "Server name handshake test");
248
249 #Test 10: ALPN handshake (client request only)
250 $proxy->clear();
251 $proxy->clientflags("-alpn test");
252 $proxy->start();
253 checkhandshake($proxy, checkhandshake::DEFAULT_HANDSHAKE,
254                checkhandshake::DEFAULT_EXTENSIONS
255                | checkhandshake::ALPN_CLI_EXTENSION,
256                "ALPN handshake test (client)");
257
258 #Test 11: ALPN handshake (server support only)
259 $proxy->clear();
260 $proxy->serverflags("-alpn test");
261 $proxy->start();
262 checkhandshake($proxy, checkhandshake::DEFAULT_HANDSHAKE,
263                checkhandshake::DEFAULT_EXTENSIONS,
264                "ALPN handshake test (server)");
265
266 #Test 12: ALPN handshake (client and server)
267 $proxy->clear();
268 $proxy->clientflags("-alpn test");
269 $proxy->serverflags("-alpn test");
270 $proxy->start();
271 checkhandshake($proxy, checkhandshake::DEFAULT_HANDSHAKE,
272                checkhandshake::DEFAULT_EXTENSIONS
273                | checkhandshake::ALPN_CLI_EXTENSION
274                | checkhandshake::ALPN_SRV_EXTENSION,
275                "ALPN handshake test");
276
277 SKIP: {
278     skip "No CT, EC or OCSP support in this OpenSSL build", 1
279         if disabled("ct") || disabled("ec") || disabled("ocsp");
280
281     #Test 13: SCT handshake (client request only)
282     $proxy->clear();
283     #Note: -ct also sends status_request
284     $proxy->clientflags("-ct");
285     $proxy->serverflags("-status_file "
286                         .srctop_file("test", "recipes", "ocsp-response.der")
287                         ." -serverinfo ".srctop_file("test", "serverinfo2.pem"));
288     $proxy->start();
289     checkhandshake($proxy, checkhandshake::DEFAULT_HANDSHAKE,
290                    checkhandshake::DEFAULT_EXTENSIONS
291                    | checkhandshake::SCT_CLI_EXTENSION
292                    | checkhandshake::SCT_SRV_EXTENSION
293                    | checkhandshake::STATUS_REQUEST_CLI_EXTENSION
294                    | checkhandshake::STATUS_REQUEST_SRV_EXTENSION,
295                    "SCT handshake test");
296 }
297
298
299
300
301 #Test 14: HRR Handshake
302 $proxy->clear();
303 $proxy->serverflags("-curves P-256");
304 $proxy->start();
305 checkhandshake($proxy, checkhandshake::HRR_HANDSHAKE,
306                checkhandshake::DEFAULT_EXTENSIONS
307                | checkhandshake::KEY_SHARE_HRR_EXTENSION,
308                "HRR handshake test");
309
310 #Test 15: Resumption handshake with HRR
311 $proxy->clear();
312 $proxy->clientflags("-sess_in ".$session);
313 $proxy->serverflags("-curves P-256");
314 $proxy->start();
315 checkhandshake($proxy, checkhandshake::HRR_RESUME_HANDSHAKE,
316                (checkhandshake::DEFAULT_EXTENSIONS
317                 | checkhandshake::KEY_SHARE_HRR_EXTENSION
318                 | checkhandshake::PSK_CLI_EXTENSION
319                 | checkhandshake::PSK_SRV_EXTENSION),
320                "Resumption handshake with HRR test");
321
322 #Test 16: Acceptable but non preferred key_share
323 $proxy->clear();
324 $proxy->clientflags("-curves P-256");
325 $proxy->start();
326 checkhandshake($proxy, checkhandshake::DEFAULT_HANDSHAKE,
327                checkhandshake::DEFAULT_EXTENSIONS
328                | checkhandshake::SUPPORTED_GROUPS_SRV_EXTENSION,
329                "Acceptable but non preferred key_share");
330
331 unlink $session;