Add testing of TLSv1.3 resumption in test_tls13messages
[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_SERVER_HELLO,
39         checkhandshake::ALL_HANDSHAKES],
40     [TLSProxy::Message::MT_ENCRYPTED_EXTENSIONS,
41         checkhandshake::ALL_HANDSHAKES],
42     [TLSProxy::Message::MT_CERTIFICATE_REQUEST,
43         checkhandshake::CLIENT_AUTH_HANDSHAKE],
44     [TLSProxy::Message::MT_CERTIFICATE,
45         checkhandshake::ALL_HANDSHAKES & ~checkhandshake::RESUME_HANDSHAKE],
46     [TLSProxy::Message::MT_CERTIFICATE_VERIFY,
47         checkhandshake::ALL_HANDSHAKES & ~checkhandshake::RESUME_HANDSHAKE],
48     [TLSProxy::Message::MT_FINISHED,
49         checkhandshake::ALL_HANDSHAKES],
50     [TLSProxy::Message::MT_CERTIFICATE,
51         checkhandshake::CLIENT_AUTH_HANDSHAKE],
52     [TLSProxy::Message::MT_CERTIFICATE_VERIFY,
53         checkhandshake::CLIENT_AUTH_HANDSHAKE],
54     [TLSProxy::Message::MT_FINISHED,
55         checkhandshake::ALL_HANDSHAKES],
56     [0, 0]
57 );
58
59 @extensions = (
60     [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_SERVER_NAME,
61         checkhandshake::SERVER_NAME_CLI_EXTENSION],
62     [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_STATUS_REQUEST,
63         checkhandshake::STATUS_REQUEST_CLI_EXTENSION],
64     [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_SUPPORTED_GROUPS,
65         checkhandshake::DEFAULT_EXTENSIONS],
66     [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_EC_POINT_FORMATS,
67         checkhandshake::DEFAULT_EXTENSIONS],
68     [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_SIG_ALGS,
69         checkhandshake::DEFAULT_EXTENSIONS],
70     [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_ALPN,
71         checkhandshake::ALPN_CLI_EXTENSION],
72     [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_SCT,
73         checkhandshake::SCT_CLI_EXTENSION],
74     [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_ENCRYPT_THEN_MAC,
75         checkhandshake::DEFAULT_EXTENSIONS],
76     [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_EXTENDED_MASTER_SECRET,
77         checkhandshake::DEFAULT_EXTENSIONS],
78     [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_SESSION_TICKET,
79         checkhandshake::DEFAULT_EXTENSIONS],
80     [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_KEY_SHARE,
81         checkhandshake::DEFAULT_EXTENSIONS],
82     [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_SUPPORTED_VERSIONS,
83         checkhandshake::DEFAULT_EXTENSIONS],
84     [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_PSK_KEX_MODES,
85         checkhandshake::DEFAULT_EXTENSIONS],
86     [TLSProxy::Message::MT_CLIENT_HELLO, TLSProxy::Message::EXT_PSK,
87         checkhandshake::PSK_CLI_EXTENSION],
88
89     [TLSProxy::Message::MT_SERVER_HELLO, TLSProxy::Message::EXT_KEY_SHARE,
90         checkhandshake::DEFAULT_EXTENSIONS],
91     [TLSProxy::Message::MT_SERVER_HELLO, TLSProxy::Message::EXT_PSK,
92         checkhandshake::PSK_SRV_EXTENSION],
93
94     [TLSProxy::Message::MT_ENCRYPTED_EXTENSIONS, TLSProxy::Message::EXT_SERVER_NAME,
95         checkhandshake::SERVER_NAME_SRV_EXTENSION],
96     [TLSProxy::Message::MT_ENCRYPTED_EXTENSIONS, TLSProxy::Message::EXT_ALPN,
97         checkhandshake::ALPN_SRV_EXTENSION],
98
99     [TLSProxy::Message::MT_CERTIFICATE, TLSProxy::Message::EXT_STATUS_REQUEST,
100         checkhandshake::STATUS_REQUEST_SRV_EXTENSION],
101
102     [0,0,0]
103 );
104
105 my $proxy = TLSProxy::Proxy->new(
106     undef,
107     cmdstr(app(["openssl"]), display => 1),
108     srctop_file("apps", "server.pem"),
109     (!$ENV{HARNESS_ACTIVE} || $ENV{HARNESS_VERBOSE})
110 );
111
112 #Test 1: Check we get all the right messages for a default handshake
113 (undef, my $session) = tempfile();
114 $proxy->serverconnects(2);
115 $proxy->clientflags("-sess_out ".$session);
116 $proxy->sessionfile($session);
117 $proxy->start() or plan skip_all => "Unable to start up Proxy for tests";
118 plan tests => 13;
119 checkhandshake($proxy, checkhandshake::DEFAULT_HANDSHAKE,
120                checkhandshake::DEFAULT_EXTENSIONS,
121                "Default handshake test");
122
123 #Test 2: Resumption handshake
124 $proxy->clearClient();
125 $proxy->clientflags("-sess_in ".$session);
126 $proxy->clientstart();
127 checkhandshake($proxy, checkhandshake::RESUME_HANDSHAKE,
128                checkhandshake::DEFAULT_EXTENSIONS
129                | checkhandshake::PSK_CLI_EXTENSION
130                | checkhandshake::PSK_SRV_EXTENSION,
131                "Resumption handshake test");
132 unlink $session;
133
134 #Test 3: A status_request handshake (client request only)
135 $proxy->clear();
136 $proxy->clientflags("-status");
137 $proxy->start();
138 checkhandshake($proxy, checkhandshake::DEFAULT_HANDSHAKE,
139                checkhandshake::DEFAULT_EXTENSIONS
140                | checkhandshake::STATUS_REQUEST_CLI_EXTENSION,
141                "status_request handshake test (client)");
142
143 #Test 4: A status_request handshake (server support only)
144 $proxy->clear();
145 $proxy->serverflags("-status_file "
146                     .srctop_file("test", "recipes", "ocsp-response.der"));
147 $proxy->start();
148 checkhandshake($proxy, checkhandshake::DEFAULT_HANDSHAKE,
149                checkhandshake::DEFAULT_EXTENSIONS,
150                "status_request handshake test (server)");
151
152 #Test 5: A status_request handshake (client and server)
153 #TODO(TLS1.3): TLS1.3 doesn't actually have CertificateStatus messages. This is
154 #a temporary test until such time as we do proper TLS1.3 style certificate
155 #status
156 $proxy->clear();
157 $proxy->clientflags("-status");
158 $proxy->serverflags("-status_file "
159                     .srctop_file("test", "recipes", "ocsp-response.der"));
160 $proxy->start();
161 checkhandshake($proxy, checkhandshake::DEFAULT_HANDSHAKE,
162                checkhandshake::DEFAULT_EXTENSIONS
163                | checkhandshake::STATUS_REQUEST_CLI_EXTENSION
164                | checkhandshake::STATUS_REQUEST_SRV_EXTENSION,
165                "status_request handshake test");
166
167 #Test 6: A client auth handshake
168 $proxy->clear();
169 $proxy->clientflags("-cert ".srctop_file("apps", "server.pem"));
170 $proxy->serverflags("-Verify 5");
171 $proxy->start();
172 checkhandshake($proxy, checkhandshake::CLIENT_AUTH_HANDSHAKE,
173                checkhandshake::DEFAULT_EXTENSIONS,
174                "Client auth handshake test");
175
176 #Test 7: Server name handshake (client request only)
177 $proxy->clear();
178 $proxy->clientflags("-servername testhost");
179 $proxy->start();
180 checkhandshake($proxy, checkhandshake::DEFAULT_HANDSHAKE,
181                checkhandshake::DEFAULT_EXTENSIONS
182                | checkhandshake::SERVER_NAME_CLI_EXTENSION,
183                "Server name handshake test (client)");
184
185 #Test 8: Server name handshake (server support only)
186 $proxy->clear();
187 $proxy->serverflags("-servername testhost");
188 $proxy->start();
189 checkhandshake($proxy, checkhandshake::DEFAULT_HANDSHAKE,
190                checkhandshake::DEFAULT_EXTENSIONS,
191                "Server name handshake test (server)");
192
193 #Test 9: Server name handshake (client and server)
194 $proxy->clear();
195 $proxy->clientflags("-servername testhost");
196 $proxy->serverflags("-servername testhost");
197 $proxy->start();
198 checkhandshake($proxy, checkhandshake::DEFAULT_HANDSHAKE,
199                checkhandshake::DEFAULT_EXTENSIONS
200                | checkhandshake::SERVER_NAME_CLI_EXTENSION
201                | checkhandshake::SERVER_NAME_SRV_EXTENSION,
202                "Server name handshake test");
203
204 #Test 10: ALPN handshake (client request only)
205 $proxy->clear();
206 $proxy->clientflags("-alpn test");
207 $proxy->start();
208 checkhandshake($proxy, checkhandshake::DEFAULT_HANDSHAKE,
209                checkhandshake::DEFAULT_EXTENSIONS
210                | checkhandshake::ALPN_CLI_EXTENSION,
211                "ALPN handshake test (client)");
212
213 #Test 11: ALPN handshake (server support only)
214 $proxy->clear();
215 $proxy->serverflags("-alpn test");
216 $proxy->start();
217 checkhandshake($proxy, checkhandshake::DEFAULT_HANDSHAKE,
218                checkhandshake::DEFAULT_EXTENSIONS,
219                "ALPN handshake test (server)");
220
221 #Test 12: ALPN handshake (client and server)
222 $proxy->clear();
223 $proxy->clientflags("-alpn test");
224 $proxy->serverflags("-alpn test");
225 $proxy->start();
226 checkhandshake($proxy, checkhandshake::DEFAULT_HANDSHAKE,
227                checkhandshake::DEFAULT_EXTENSIONS
228                | checkhandshake::ALPN_CLI_EXTENSION
229                | checkhandshake::ALPN_SRV_EXTENSION,
230                "ALPN handshake test");
231
232 #Test 13: SCT handshake (client request only)
233 #TODO(TLS1.3): This only checks that the client side extension appears. The
234 #SCT extension is unusual in that we have no built-in server side implementation
235 #The server side implementation can nomrally be added using the custom
236 #extensions framework (e.g. by using the "-serverinfo" s_server option). However
237 #currently we only support <= TLS1.2 for custom extensions because the existing
238 #framework and API has no knowledge of the TLS1.3 messages
239 $proxy->clear();
240 #Note: -ct also sends status_request
241 $proxy->clientflags("-ct");
242 $proxy->serverflags("-status_file "
243                     .srctop_file("test", "recipes", "ocsp-response.der"));
244 $proxy->start();
245 checkhandshake($proxy, checkhandshake::DEFAULT_HANDSHAKE,
246                checkhandshake::DEFAULT_EXTENSIONS
247                | checkhandshake::SCT_CLI_EXTENSION
248                | checkhandshake::STATUS_REQUEST_CLI_EXTENSION
249                | checkhandshake::STATUS_REQUEST_SRV_EXTENSION,
250                "SCT handshake test");