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