d6512b57ad1be81fe7296dfca06c60fd590ff7f9
[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
85     [TLSProxy::Message::MT_SERVER_HELLO, TLSProxy::Message::EXT_KEY_SHARE,
86         checkhandshake::DEFAULT_EXTENSIONS],
87
88     [TLSProxy::Message::MT_ENCRYPTED_EXTENSIONS, TLSProxy::Message::EXT_SERVER_NAME,
89         checkhandshake::SERVER_NAME_SRV_EXTENSION],
90     [TLSProxy::Message::MT_ENCRYPTED_EXTENSIONS, TLSProxy::Message::EXT_ALPN,
91         checkhandshake::ALPN_SRV_EXTENSION],
92
93     [TLSProxy::Message::MT_CERTIFICATE, TLSProxy::Message::EXT_STATUS_REQUEST,
94         checkhandshake::STATUS_REQUEST_SRV_EXTENSION],
95
96     [0,0,0]
97 );
98
99 my $proxy = TLSProxy::Proxy->new(
100     undef,
101     cmdstr(app(["openssl"]), display => 1),
102     srctop_file("apps", "server.pem"),
103     (!$ENV{HARNESS_ACTIVE} || $ENV{HARNESS_VERBOSE})
104 );
105
106 #Test 1: Check we get all the right messages for a default handshake
107 (undef, my $session) = tempfile();
108 #$proxy->serverconnects(2);
109 $proxy->clientflags("-sess_out ".$session);
110 $proxy->start() or plan skip_all => "Unable to start up Proxy for tests";
111 plan tests => 12;
112 checkhandshake($proxy, checkhandshake::DEFAULT_HANDSHAKE,
113                checkhandshake::DEFAULT_EXTENSIONS,
114                "Default handshake test");
115
116 #TODO(TLS1.3): Test temporarily disabled until we implement TLS1.3 resumption
117 #Test 2: Resumption handshake
118 #$proxy->clearClient();
119 #$proxy->clientflags("-sess_in ".$session);
120 #$proxy->clientstart();
121 #checkmessages(RESUME_HANDSHAKE, "Resumption handshake test");
122 unlink $session;
123
124 #Test 3: A status_request handshake (client request only)
125 $proxy->clear();
126 $proxy->clientflags("-status");
127 $proxy->start();
128 checkhandshake($proxy, checkhandshake::DEFAULT_HANDSHAKE,
129                checkhandshake::DEFAULT_EXTENSIONS
130                | checkhandshake::STATUS_REQUEST_CLI_EXTENSION,
131                "status_request handshake test (client)");
132
133 #Test 4: A status_request handshake (server support only)
134 $proxy->clear();
135 $proxy->serverflags("-status_file "
136                     .srctop_file("test", "recipes", "ocsp-response.der"));
137 $proxy->start();
138 checkhandshake($proxy, checkhandshake::DEFAULT_HANDSHAKE,
139                checkhandshake::DEFAULT_EXTENSIONS,
140                "status_request handshake test (server)");
141
142 #Test 5: A status_request handshake (client and server)
143 #TODO(TLS1.3): TLS1.3 doesn't actually have CertificateStatus messages. This is
144 #a temporary test until such time as we do proper TLS1.3 style certificate
145 #status
146 $proxy->clear();
147 $proxy->clientflags("-status");
148 $proxy->serverflags("-status_file "
149                     .srctop_file("test", "recipes", "ocsp-response.der"));
150 $proxy->start();
151 checkhandshake($proxy, checkhandshake::DEFAULT_HANDSHAKE,
152                checkhandshake::DEFAULT_EXTENSIONS
153                | checkhandshake::STATUS_REQUEST_CLI_EXTENSION
154                | checkhandshake::STATUS_REQUEST_SRV_EXTENSION,
155                "status_request handshake test");
156
157 #Test 6: A client auth handshake
158 $proxy->clear();
159 $proxy->clientflags("-cert ".srctop_file("apps", "server.pem"));
160 $proxy->serverflags("-Verify 5");
161 $proxy->start();
162 checkhandshake($proxy, checkhandshake::CLIENT_AUTH_HANDSHAKE,
163                checkhandshake::DEFAULT_EXTENSIONS,
164                "Client auth handshake test");
165
166 #Test 7: Server name handshake (client request only)
167 $proxy->clear();
168 $proxy->clientflags("-servername testhost");
169 $proxy->start();
170 checkhandshake($proxy, checkhandshake::DEFAULT_HANDSHAKE,
171                checkhandshake::DEFAULT_EXTENSIONS
172                | checkhandshake::SERVER_NAME_CLI_EXTENSION,
173                "Server name handshake test (client)");
174
175 #Test 8: Server name handshake (server support only)
176 $proxy->clear();
177 $proxy->serverflags("-servername testhost");
178 $proxy->start();
179 checkhandshake($proxy, checkhandshake::DEFAULT_HANDSHAKE,
180                checkhandshake::DEFAULT_EXTENSIONS,
181                "Server name handshake test (server)");
182
183 #Test 9: Server name handshake (client and server)
184 $proxy->clear();
185 $proxy->clientflags("-servername testhost");
186 $proxy->serverflags("-servername testhost");
187 $proxy->start();
188 checkhandshake($proxy, checkhandshake::DEFAULT_HANDSHAKE,
189                checkhandshake::DEFAULT_EXTENSIONS
190                | checkhandshake::SERVER_NAME_CLI_EXTENSION
191                | checkhandshake::SERVER_NAME_SRV_EXTENSION,
192                "Server name handshake test");
193
194 #Test 10: ALPN handshake (client request only)
195 $proxy->clear();
196 $proxy->clientflags("-alpn test");
197 $proxy->start();
198 checkhandshake($proxy, checkhandshake::DEFAULT_HANDSHAKE,
199                checkhandshake::DEFAULT_EXTENSIONS
200                | checkhandshake::ALPN_CLI_EXTENSION,
201                "ALPN handshake test (client)");
202
203 #Test 11: ALPN handshake (server support only)
204 $proxy->clear();
205 $proxy->serverflags("-alpn test");
206 $proxy->start();
207 checkhandshake($proxy, checkhandshake::DEFAULT_HANDSHAKE,
208                checkhandshake::DEFAULT_EXTENSIONS,
209                "ALPN handshake test (server)");
210
211 #Test 12: ALPN handshake (client and server)
212 $proxy->clear();
213 $proxy->clientflags("-alpn test");
214 $proxy->serverflags("-alpn test");
215 $proxy->start();
216 checkhandshake($proxy, checkhandshake::DEFAULT_HANDSHAKE,
217                checkhandshake::DEFAULT_EXTENSIONS
218                | checkhandshake::ALPN_CLI_EXTENSION
219                | checkhandshake::ALPN_SRV_EXTENSION,
220                "ALPN handshake test");
221
222 #Test 13: SCT handshake (client request only)
223 #TODO(TLS1.3): This only checks that the client side extension appears. The
224 #SCT extension is unusual in that we have no built-in server side implementation
225 #The server side implementation can nomrally be added using the custom
226 #extensions framework (e.g. by using the "-serverinfo" s_server option). However
227 #currently we only support <= TLS1.2 for custom extensions because the existing
228 #framework and API has no knowledge of the TLS1.3 messages
229 $proxy->clear();
230 #Note: -ct also sends status_request
231 $proxy->clientflags("-ct");
232 $proxy->serverflags("-status_file "
233                     .srctop_file("test", "recipes", "ocsp-response.der"));
234 $proxy->start();
235 checkhandshake($proxy, checkhandshake::DEFAULT_HANDSHAKE,
236                checkhandshake::DEFAULT_EXTENSIONS
237                | checkhandshake::SCT_CLI_EXTENSION
238                | checkhandshake::STATUS_REQUEST_CLI_EXTENSION
239                | checkhandshake::STATUS_REQUEST_SRV_EXTENSION,
240                "SCT handshake test");