Fix incorrect function name in BN_bn2bin manpage
[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                & ~checkhandshake::SERVER_NAME_CLI_EXTENSION,
164                "Resumption handshake test");
165
166 #Test 3: A status_request handshake (client request only)
167 $proxy->clear();
168 $proxy->clientflags("-status");
169 $proxy->start();
170 checkhandshake($proxy, checkhandshake::DEFAULT_HANDSHAKE,
171                checkhandshake::DEFAULT_EXTENSIONS
172                | checkhandshake::STATUS_REQUEST_CLI_EXTENSION,
173                "status_request handshake test (client)");
174
175 #Test 4: A status_request handshake (server support only)
176 $proxy->clear();
177 $proxy->serverflags("-status_file "
178                     .srctop_file("test", "recipes", "ocsp-response.der"));
179 $proxy->start();
180 checkhandshake($proxy, checkhandshake::DEFAULT_HANDSHAKE,
181                checkhandshake::DEFAULT_EXTENSIONS,
182                "status_request handshake test (server)");
183
184 #Test 5: A status_request handshake (client and server)
185 #TODO(TLS1.3): TLS1.3 doesn't actually have CertificateStatus messages. This is
186 #a temporary test until such time as we do proper TLS1.3 style certificate
187 #status
188 $proxy->clear();
189 $proxy->clientflags("-status");
190 $proxy->serverflags("-status_file "
191                     .srctop_file("test", "recipes", "ocsp-response.der"));
192 $proxy->start();
193 checkhandshake($proxy, checkhandshake::DEFAULT_HANDSHAKE,
194                checkhandshake::DEFAULT_EXTENSIONS
195                | checkhandshake::STATUS_REQUEST_CLI_EXTENSION
196                | checkhandshake::STATUS_REQUEST_SRV_EXTENSION,
197                "status_request handshake test");
198
199 #Test 6: A client auth handshake
200 $proxy->clear();
201 $proxy->clientflags("-cert ".srctop_file("apps", "server.pem"));
202 $proxy->serverflags("-Verify 5");
203 $proxy->start();
204 checkhandshake($proxy, checkhandshake::CLIENT_AUTH_HANDSHAKE,
205                checkhandshake::DEFAULT_EXTENSIONS,
206                "Client auth handshake test");
207
208 #Test 7: Server name handshake (no client request)
209 $proxy->clear();
210 $proxy->clientflags("-noservername");
211 $proxy->start();
212 checkhandshake($proxy, checkhandshake::DEFAULT_HANDSHAKE,
213                checkhandshake::DEFAULT_EXTENSIONS
214                & ~checkhandshake::SERVER_NAME_CLI_EXTENSION,
215                "Server name handshake test (client)");
216
217 #Test 8: Server name handshake (server support only)
218 $proxy->clear();
219 $proxy->clientflags("-noservername");
220 $proxy->serverflags("-servername testhost");
221 $proxy->start();
222 checkhandshake($proxy, checkhandshake::DEFAULT_HANDSHAKE,
223                checkhandshake::DEFAULT_EXTENSIONS
224                & ~checkhandshake::SERVER_NAME_CLI_EXTENSION,
225                "Server name handshake test (server)");
226
227 #Test 9: Server name handshake (client and server)
228 $proxy->clear();
229 $proxy->clientflags("-servername testhost");
230 $proxy->serverflags("-servername testhost");
231 $proxy->start();
232 checkhandshake($proxy, checkhandshake::DEFAULT_HANDSHAKE,
233                checkhandshake::DEFAULT_EXTENSIONS
234                | checkhandshake::SERVER_NAME_SRV_EXTENSION,
235                "Server name handshake test");
236
237 #Test 10: ALPN handshake (client request only)
238 $proxy->clear();
239 $proxy->clientflags("-alpn test");
240 $proxy->start();
241 checkhandshake($proxy, checkhandshake::DEFAULT_HANDSHAKE,
242                checkhandshake::DEFAULT_EXTENSIONS
243                | checkhandshake::ALPN_CLI_EXTENSION,
244                "ALPN handshake test (client)");
245
246 #Test 11: ALPN handshake (server support only)
247 $proxy->clear();
248 $proxy->serverflags("-alpn test");
249 $proxy->start();
250 checkhandshake($proxy, checkhandshake::DEFAULT_HANDSHAKE,
251                checkhandshake::DEFAULT_EXTENSIONS,
252                "ALPN handshake test (server)");
253
254 #Test 12: ALPN handshake (client and server)
255 $proxy->clear();
256 $proxy->clientflags("-alpn test");
257 $proxy->serverflags("-alpn test");
258 $proxy->start();
259 checkhandshake($proxy, checkhandshake::DEFAULT_HANDSHAKE,
260                checkhandshake::DEFAULT_EXTENSIONS
261                | checkhandshake::ALPN_CLI_EXTENSION
262                | checkhandshake::ALPN_SRV_EXTENSION,
263                "ALPN handshake test");
264
265 SKIP: {
266     skip "No CT, EC or OCSP support in this OpenSSL build", 1
267         if disabled("ct") || disabled("ec") || disabled("ocsp");
268
269     #Test 13: SCT handshake (client request only)
270     $proxy->clear();
271     #Note: -ct also sends status_request
272     $proxy->clientflags("-ct");
273     $proxy->serverflags("-status_file "
274                         .srctop_file("test", "recipes", "ocsp-response.der")
275                         ." -serverinfo ".srctop_file("test", "serverinfo2.pem"));
276     $proxy->start();
277     checkhandshake($proxy, checkhandshake::DEFAULT_HANDSHAKE,
278                    checkhandshake::DEFAULT_EXTENSIONS
279                    | checkhandshake::SCT_CLI_EXTENSION
280                    | checkhandshake::SCT_SRV_EXTENSION
281                    | checkhandshake::STATUS_REQUEST_CLI_EXTENSION
282                    | checkhandshake::STATUS_REQUEST_SRV_EXTENSION,
283                    "SCT handshake test");
284 }
285
286
287
288
289 #Test 14: HRR Handshake
290 $proxy->clear();
291 $proxy->serverflags("-curves P-256");
292 $proxy->start();
293 checkhandshake($proxy, checkhandshake::HRR_HANDSHAKE,
294                checkhandshake::DEFAULT_EXTENSIONS
295                | checkhandshake::KEY_SHARE_HRR_EXTENSION,
296                "HRR handshake test");
297
298 #Test 15: Resumption handshake with HRR
299 $proxy->clear();
300 $proxy->clientflags("-sess_in ".$session);
301 $proxy->serverflags("-curves P-256");
302 $proxy->start();
303 checkhandshake($proxy, checkhandshake::HRR_RESUME_HANDSHAKE,
304                (checkhandshake::DEFAULT_EXTENSIONS
305                 | checkhandshake::KEY_SHARE_HRR_EXTENSION
306                 | checkhandshake::PSK_CLI_EXTENSION
307                 | checkhandshake::PSK_SRV_EXTENSION)
308                & ~checkhandshake::SERVER_NAME_CLI_EXTENSION,
309                "Resumption handshake with HRR test");
310
311 #Test 16: Acceptable but non preferred key_share
312 $proxy->clear();
313 $proxy->clientflags("-curves P-256");
314 $proxy->start();
315 checkhandshake($proxy, checkhandshake::DEFAULT_HANDSHAKE,
316                checkhandshake::DEFAULT_EXTENSIONS
317                | checkhandshake::SUPPORTED_GROUPS_SRV_EXTENSION,
318                "Default handshake test");
319
320 unlink $session;