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