Debian Codegraph @

crt/s2n/tests/unit/s2n_malformed_handshake_test.c

raw symbols SCIP
1 /*
2 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License").
5 * You may not use this file except in compliance with the License.
6 * A copy of the License is located at
7 *
8 * http://aws.amazon.com/apache2.0
9 *
10 * or in the "license" file accompanying this file. This file is distributed
11 * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12 * express or implied. See the License for the specific language governing
13 * permissions and limitations under the License.
14 */
15
16 #include <stdint.h>
17 #include <stdlib.h>
18 #include <sys/wait.h>
19 #include <unistd.h>
20
21 #include "api/s2n.h"
22 #include "s2n_test.h"
23 #include "tls/s2n_connection.h"
24 #include "tls/s2n_handshake.h"
25
26 #define TLS_ALERT 21
27 #define TLS_HANDSHAKE 22
28 #define TLS_HEARTBEAT 24
29
30 #define ZERO_TO_THIRTY_ONE 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, \
31 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F
32
33 static uint8_t zero_to_thirty_one[] = { ZERO_TO_THIRTY_ONE };
34
35 static uint8_t server_hello_message[] = {
36 /* SERVER HELLO */
37 0x02,
38
39 /* Length */
40 0x00, 0x00, 0x46,
41
42 /* Protocol version */
43 0x03, 0x03,
44
45 /* Server random */
46 ZERO_TO_THIRTY_ONE,
47
48 /* SessionID len - 32 bytes */
49 0x20,
50
51 /* Session ID */
52 ZERO_TO_THIRTY_ONE,
53
54 /* Cipher suite - TLS_RSA_WITH_AES_256_CBC_SHA256 */
55 0x00, 0x3D,
56
57 /* Compression method: none */
58 0x00
59 };
60
61 static uint8_t good_certificate_list[] = {
62 /* SERVER CERT */
63 0x0B,
64
65 /* Length of the handshake message */
66 0x00, 0x03, 0x38,
67
68 /* Length of all certificates */
69 0x00, 0x03, 0x35,
70
71 /* Length of the first cert */
72 0x00, 0x03, 0x32,
73
74 /* Certificate data - via openssl x509 -in cert.pem -outform DER | xxd -i */
75 0x30, 0x82, 0x03, 0x2e, 0x30, 0x82, 0x02, 0x16, 0x02, 0x09, 0x00, 0xcb,
76 0xd6, 0x5a, 0xfa, 0x37, 0xcf, 0xe0, 0xbf, 0x30, 0x0d, 0x06, 0x09, 0x2a,
77 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x05, 0x05, 0x00, 0x30, 0x59,
78 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x41,
79 0x55, 0x31, 0x13, 0x30, 0x11, 0x06, 0x03, 0x55, 0x04, 0x08, 0x13, 0x0a,
80 0x53, 0x6f, 0x6d, 0x65, 0x2d, 0x53, 0x74, 0x61, 0x74, 0x65, 0x31, 0x21,
81 0x30, 0x1f, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x13, 0x18, 0x49, 0x6e, 0x74,
82 0x65, 0x72, 0x6e, 0x65, 0x74, 0x20, 0x57, 0x69, 0x64, 0x67, 0x69, 0x74,
83 0x73, 0x20, 0x50, 0x74, 0x79, 0x20, 0x4c, 0x74, 0x64, 0x31, 0x12, 0x30,
84 0x10, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x09, 0x6c, 0x6f, 0x63, 0x61,
85 0x6c, 0x68, 0x6f, 0x73, 0x74, 0x30, 0x1e, 0x17, 0x0d, 0x31, 0x34, 0x30,
86 0x35, 0x31, 0x30, 0x31, 0x37, 0x30, 0x38, 0x32, 0x33, 0x5a, 0x17, 0x0d,
87 0x32, 0x34, 0x30, 0x35, 0x30, 0x37, 0x31, 0x37, 0x30, 0x38, 0x32, 0x33,
88 0x5a, 0x30, 0x59, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06,
89 0x13, 0x02, 0x41, 0x55, 0x31, 0x13, 0x30, 0x11, 0x06, 0x03, 0x55, 0x04,
90 0x08, 0x13, 0x0a, 0x53, 0x6f, 0x6d, 0x65, 0x2d, 0x53, 0x74, 0x61, 0x74,
91 0x65, 0x31, 0x21, 0x30, 0x1f, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x13, 0x18,
92 0x49, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x20, 0x57, 0x69, 0x64,
93 0x67, 0x69, 0x74, 0x73, 0x20, 0x50, 0x74, 0x79, 0x20, 0x4c, 0x74, 0x64,
94 0x31, 0x12, 0x30, 0x10, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x09, 0x6c,
95 0x6f, 0x63, 0x61, 0x6c, 0x68, 0x6f, 0x73, 0x74, 0x30, 0x82, 0x01, 0x22,
96 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01,
97 0x01, 0x05, 0x00, 0x03, 0x82, 0x01, 0x0f, 0x00, 0x30, 0x82, 0x01, 0x0a,
98 0x02, 0x82, 0x01, 0x01, 0x00, 0xc8, 0x96, 0xd6, 0x94, 0x98, 0x78, 0x3e,
99 0x1b, 0xb2, 0x1d, 0x6b, 0x65, 0xc2, 0xb4, 0x44, 0x31, 0xd5, 0x87, 0x96,
100 0x0d, 0x7e, 0x35, 0x53, 0x6c, 0xc1, 0x29, 0xb6, 0x34, 0x95, 0x3f, 0x9a,
101 0xb9, 0x77, 0xfc, 0xd5, 0xc4, 0xf7, 0x75, 0x84, 0xdd, 0x7c, 0x96, 0xe5,
102 0x6f, 0xeb, 0xf8, 0x09, 0x35, 0x9a, 0x18, 0xda, 0x1f, 0xa2, 0x07, 0x33,
103 0x79, 0xb9, 0xbc, 0x07, 0x6f, 0xce, 0x17, 0xd1, 0x7e, 0x59, 0x69, 0x0a,
104 0x00, 0x98, 0x4a, 0xb1, 0x33, 0xc0, 0x13, 0xbf, 0xd2, 0x34, 0x07, 0x62,
105 0xe0, 0x4a, 0xaf, 0xe0, 0x57, 0xcd, 0x6d, 0x62, 0xa4, 0x19, 0xbe, 0x31,
106 0x69, 0xcc, 0x71, 0x6f, 0x83, 0xc7, 0xd9, 0x73, 0xfd, 0x57, 0x70, 0xa1,
107 0x27, 0xa9, 0x4c, 0x48, 0x8d, 0xd5, 0xeb, 0xc1, 0x66, 0x11, 0xfe, 0x24,
108 0x70, 0x43, 0x75, 0xe1, 0x5f, 0x2f, 0xb9, 0xf2, 0x02, 0xe4, 0x71, 0x3f,
109 0x2d, 0x3e, 0x20, 0x08, 0xf0, 0xc9, 0xe1, 0x47, 0xd4, 0x51, 0xb0, 0x20,
110 0x12, 0x14, 0x9e, 0x6d, 0x3e, 0xab, 0xfc, 0xa1, 0x58, 0x07, 0x94, 0xf7,
111 0x01, 0xe0, 0xdc, 0xd5, 0x57, 0x67, 0x69, 0xa4, 0x5b, 0x96, 0xb3, 0xfa,
112 0x2b, 0x03, 0x38, 0xe6, 0xf4, 0xec, 0xd0, 0x88, 0xb4, 0xf7, 0xf6, 0x2b,
113 0x97, 0x30, 0x71, 0x69, 0x33, 0xcc, 0x8c, 0xb1, 0x82, 0x29, 0xaf, 0x09,
114 0x32, 0xff, 0x0f, 0x5b, 0x64, 0x74, 0x53, 0xd5, 0x82, 0xa8, 0x79, 0xb3,
115 0x04, 0x7f, 0x96, 0xdd, 0x0f, 0x71, 0x3e, 0xb7, 0xe1, 0x08, 0x89, 0xe6,
116 0xe0, 0x95, 0xa8, 0x6f, 0xc5, 0xa0, 0x33, 0x53, 0x6e, 0x89, 0x8b, 0xb3,
117 0x14, 0x1d, 0x02, 0x35, 0xa4, 0x1c, 0x74, 0xc4, 0xbb, 0x87, 0x46, 0x99,
118 0x10, 0x05, 0x67, 0x6b, 0x28, 0x50, 0xf7, 0xaf, 0xcf, 0x69, 0xda, 0x63,
119 0x28, 0xd1, 0x34, 0x2e, 0xea, 0xfd, 0x9d, 0x4c, 0x5b, 0x02, 0x03, 0x01,
120 0x00, 0x01, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d,
121 0x01, 0x01, 0x05, 0x05, 0x00, 0x03, 0x82, 0x01, 0x01, 0x00, 0x64, 0x55,
122 0xef, 0x5b, 0x91, 0xb7, 0xfd, 0x5d, 0x00, 0x3b, 0x0c, 0x0f, 0xd7, 0xe0,
123 0x26, 0xfc, 0xd6, 0xf3, 0xd8, 0xc5, 0x00, 0xdf, 0x3b, 0x85, 0x70, 0x91,
124 0x85, 0x35, 0xb1, 0x7d, 0x78, 0x58, 0x33, 0x39, 0x27, 0xc4, 0x9e, 0x56,
125 0x31, 0xbd, 0x89, 0x02, 0x56, 0x8c, 0x73, 0xf8, 0x13, 0xa6, 0x20, 0xe2,
126 0x40, 0x19, 0x1b, 0xbc, 0x1f, 0xa2, 0x25, 0xee, 0x40, 0x7a, 0x98, 0x10,
127 0x59, 0xbc, 0xb1, 0x3c, 0x93, 0x6d, 0x4a, 0x50, 0x3d, 0x19, 0xf2, 0x81,
128 0xcf, 0x52, 0x0d, 0x47, 0x97, 0x05, 0xb0, 0xe2, 0xf6, 0xed, 0x5a, 0xc1,
129 0xa0, 0xc6, 0x07, 0x31, 0xaa, 0x25, 0xbd, 0xe7, 0xac, 0x95, 0xcd, 0x40,
130 0x5b, 0x61, 0xdf, 0x06, 0xd5, 0xd6, 0x5d, 0xe5, 0x92, 0x10, 0x5e, 0xc5,
131 0x40, 0xd8, 0x32, 0x7b, 0xc6, 0x43, 0x3c, 0xdc, 0xde, 0x49, 0x64, 0x88,
132 0xd1, 0x5c, 0x8a, 0xdb, 0xbe, 0xb6, 0xc2, 0xc4, 0xe0, 0x4e, 0xe5, 0x21,
133 0x1c, 0x06, 0x89, 0xe3, 0x9e, 0xba, 0xd1, 0xe5, 0xf9, 0xef, 0xe7, 0xbc,
134 0x22, 0xf6, 0x8c, 0xef, 0x13, 0x84, 0x7c, 0x13, 0xc3, 0x29, 0x8b, 0x54,
135 0xd1, 0xad, 0xbc, 0x66, 0xe8, 0x6f, 0x4a, 0xbd, 0x9a, 0x90, 0x9b, 0x46,
136 0x0b, 0x07, 0x2c, 0xd8, 0x9e, 0xab, 0xb3, 0xa2, 0x3e, 0xad, 0x5f, 0x38,
137 0x52, 0x4b, 0x43, 0xc4, 0x50, 0xbd, 0x2d, 0x47, 0xb3, 0x06, 0x8f, 0x03,
138 0xf4, 0x59, 0x0c, 0x3c, 0xba, 0x0f, 0x28, 0xa3, 0x47, 0xd5, 0xd5, 0xd1,
139 0xe8, 0xb3, 0xbc, 0x18, 0xe9, 0x2a, 0x59, 0x4a, 0xe1, 0x3c, 0x81, 0x26,
140 0x7f, 0x2f, 0x4a, 0x61, 0xeb, 0x37, 0xab, 0x66, 0x57, 0xea, 0xcb, 0xe4,
141 0xe2, 0xbc, 0x01, 0xb6, 0x89, 0xa6, 0x1d, 0x1b, 0xf7, 0xd2, 0x43, 0xf1,
142 0x9e, 0x75, 0x35, 0x61, 0x7b, 0x79, 0xd9, 0x18, 0xbe, 0x5d, 0xcc, 0xce,
143 0xc0, 0x4b
144 };
145
146 static uint8_t empty_certificate_list[] = {
147 /* SERVER CERT */
148 0x0B,
149
150 /* Length of the handshake message */
151 0x00, 0x03, 0x03,
152
153 /* Length of all certificates */
154 0x00, 0x03, 0x00
155 };
156
157 static uint8_t empty_certificate[] = {
158 /* SERVER CERT */
159 0x0B,
160
161 /* Length of the handshake message */
162 0x00, 0x00, 0x06,
163
164 /* Length of all certificates */
165 0x00, 0x00, 0x03,
166
167 /* Length of the first certificate */
168 0x00, 0x00, 0x00
169 };
170
171 static uint8_t certificate_list_too_large[] = {
172 /* SERVER CERT */
173 0x0B,
174
175 /* Length of the handshake message */
176 0x00, 0x00, 0x06,
177
178 /* Length of all certificates */
179 0x00, 0x00, 0x10,
180
181 /* Length the first certificate */
182 0x00, 0x00, 0x00
183 };
184
185 static uint8_t certificate_too_large[] = {
186 /* SERVER CERT */
187 0x0B,
188
189 /* Length of the handshake message */
190 0x00, 0x00, 0x06,
191
192 /* Length of all certificates */
193 0x00, 0x00, 0x03,
194
195 /* Length the first certificate */
196 0x00, 0x00, 0x10
197 };
198
199 void send_messages(int write_fd, uint8_t *server_hello, uint32_t server_hello_len, uint8_t *server_cert, uint32_t server_cert_len)
200 {
201 uint8_t record_header[5] = { TLS_HANDSHAKE, 0x03, 0x03, (server_hello_len >> 8), server_hello_len & 0xff };
202
203 if (write(write_fd, record_header, 5) != 5) {
204 _exit(100);
205 }
206
207 if (write(write_fd, server_hello, server_hello_len) != server_hello_len) {
208 _exit(100);
209 }
210
211 record_header[3] = (server_cert_len >> 8);
212 record_header[4] = server_cert_len & 0xff;
213
214 if (write(write_fd, record_header, 5) != 5) {
215 _exit(100);
216 }
217
218 if (write(write_fd, server_cert, server_cert_len) != server_cert_len) {
219 _exit(100);
220 }
221
222 /* Close the pipe and exit */
223 close(write_fd);
224 }
225
226 int main(int argc, char **argv)
227 {
228 s2n_blocked_status blocked;
229 int status = 0;
230 pid_t pid = 0;
231 int p[2];
232
233 BEGIN_TEST();
234 EXPECT_SUCCESS(s2n_disable_tls13_in_test());
235
236 DEFER_CLEANUP(struct s2n_config *config = s2n_config_new(), s2n_config_ptr_free);
237 DEFER_CLEANUP(struct s2n_connection *conn = s2n_connection_new(S2N_CLIENT), s2n_connection_ptr_free);
238 EXPECT_SUCCESS(s2n_config_disable_x509_verification(config));
239 EXPECT_SUCCESS(s2n_config_set_cipher_preferences(config, "test_all"));
240 EXPECT_SUCCESS(s2n_connection_set_config(conn, config));
241
242 /* Test a good certificate list */
243
244 /* Create a pipe */
245 EXPECT_SUCCESS(pipe(p));
246
247 EXPECT_SUCCESS(s2n_connection_wipe(conn));
248
249 /* Set up the connection to read from the fd */
250 EXPECT_SUCCESS(s2n_connection_set_read_fd(conn, p[0]));
251
252 /* Pretend the client hello has already been set */
253 conn->handshake.handshake_type = NEGOTIATED | FULL_HANDSHAKE;
254 conn->handshake.message_number = SERVER_HELLO;
255 conn->server_protocol_version = S2N_TLS12;
256 conn->client_protocol_version = S2N_TLS12;
257 conn->actual_protocol_version = S2N_TLS12;
258
259 /* Create a child process */
260 pid = fork();
261 if (pid == 0) {
262 /* This is the child process, close the read end of the pipe */
263 EXPECT_SUCCESS(close(p[0]));
264
265 send_messages(p[1], server_hello_message, sizeof(server_hello_message), good_certificate_list, sizeof(good_certificate_list));
266
267 EXPECT_SUCCESS(s2n_connection_free(conn));
268 EXPECT_SUCCESS(s2n_config_free(config));
269 exit(0);
270 }
271
272 /* This is the parent process, close the write end of the pipe */
273 EXPECT_SUCCESS(close(p[1]));
274
275 /* Negotiate the handshake. This will fail due to EOF, but that's ok. Turn off Blinding before negotiation so that
276 * server doesn't delay its response and test finishes quickly. */
277 EXPECT_SUCCESS(s2n_connection_set_blinding(conn, S2N_SELF_SERVICE_BLINDING));
278 EXPECT_FAILURE(s2n_negotiate(conn, &blocked));
279
280 /* Verify that the data is as we expect it */
281 EXPECT_EQUAL(memcmp(conn->handshake_params.server_random, zero_to_thirty_one, 32), 0);
282
283 /* Check that the server hello message was processed .. we should be HELLO DONE */
284 EXPECT_EQUAL(s2n_conn_get_current_message_type(conn), SERVER_HELLO_DONE);
285
286 /* Clean up */
287 EXPECT_EQUAL(waitpid(pid, &status, 0), pid);
288 EXPECT_EQUAL(status, 0);
289 EXPECT_SUCCESS(close(p[0]));
290
291 /* Test an empty certificate list */
292
293 /* Create a pipe */
294 EXPECT_SUCCESS(pipe(p));
295
296 EXPECT_SUCCESS(s2n_connection_wipe(conn));
297
298 /* Set up the connection to read from the fd */
299 EXPECT_SUCCESS(s2n_connection_set_read_fd(conn, p[0]));
300
301 /* Pretend the client hello has already been set */
302 conn->handshake.handshake_type = NEGOTIATED | FULL_HANDSHAKE;
303 conn->handshake.message_number = SERVER_HELLO;
304 conn->server_protocol_version = S2N_TLS12;
305 conn->client_protocol_version = S2N_TLS12;
306 conn->actual_protocol_version = S2N_TLS12;
307
308 /* Create a child process */
309 pid = fork();
310 if (pid == 0) {
311 /* This is the child process, close the read end of the pipe */
312 EXPECT_SUCCESS(close(p[0]));
313
314 send_messages(p[1], server_hello_message, sizeof(server_hello_message), empty_certificate_list, sizeof(empty_certificate_list));
315
316 EXPECT_SUCCESS(s2n_connection_free(conn));
317 EXPECT_SUCCESS(s2n_config_free(config));
318 exit(0);
319 }
320
321 /* This is the parent process, close the write end of the pipe */
322 EXPECT_SUCCESS(close(p[1]));
323
324 /* Negotiate the handshake. This will fail due to EOF, but that's ok. Turn off Blinding before negotiation so that
325 * server doesn't delay its response and test finishes quickly. */
326 EXPECT_SUCCESS(s2n_connection_set_blinding(conn, S2N_SELF_SERVICE_BLINDING));
327 EXPECT_FAILURE(s2n_negotiate(conn, &blocked));
328
329 /* Verify that the data is as we expect it */
330 EXPECT_EQUAL(memcmp(conn->handshake_params.server_random, zero_to_thirty_one, 32), 0);
331
332 /* Check that the server hello message was not processed, we're stuck in SERVER_CERT */
333 EXPECT_EQUAL(s2n_conn_get_current_message_type(conn), SERVER_CERT);
334
335 /* Clean up */
336 EXPECT_EQUAL(waitpid(pid, &status, 0), pid);
337 EXPECT_EQUAL(status, 0);
338 EXPECT_SUCCESS(close(p[0]));
339
340 /* Test an empty certificate */
341
342 /* Create a pipe */
343 EXPECT_SUCCESS(pipe(p));
344
345 EXPECT_SUCCESS(s2n_connection_wipe(conn));
346
347 /* Set up the connection to read from the fd */
348 EXPECT_SUCCESS(s2n_connection_set_read_fd(conn, p[0]));
349
350 /* Pretend the client hello has already been set */
351 conn->handshake.handshake_type = NEGOTIATED | FULL_HANDSHAKE;
352 conn->handshake.message_number = SERVER_HELLO;
353 conn->server_protocol_version = S2N_TLS12;
354 conn->client_protocol_version = S2N_TLS12;
355 conn->actual_protocol_version = S2N_TLS12;
356
357 /* Create a child process */
358 pid = fork();
359 if (pid == 0) {
360 /* This is the child process, close the read end of the pipe */
361 EXPECT_SUCCESS(close(p[0]));
362
363 send_messages(p[1], server_hello_message, sizeof(server_hello_message), empty_certificate, sizeof(empty_certificate));
364
365 EXPECT_SUCCESS(s2n_connection_free(conn));
366 EXPECT_SUCCESS(s2n_config_free(config));
367 exit(0);
368 }
369
370 /* This is the parent process, close the write end of the pipe */
371 EXPECT_SUCCESS(close(p[1]));
372
373 /* Negotiate the handshake. This will fail due to EOF, but that's ok. Turn off Blinding before negotiation so that
374 * server doesn't delay its response and test finishes quickly. */
375 EXPECT_SUCCESS(s2n_connection_set_blinding(conn, S2N_SELF_SERVICE_BLINDING));
376 EXPECT_FAILURE(s2n_negotiate(conn, &blocked));
377
378 /* Verify that the data is as we expect it */
379 EXPECT_EQUAL(memcmp(conn->handshake_params.server_random, zero_to_thirty_one, 32), 0);
380
381 /* Check that the server hello message was not processed, we're stuck in SERVER_CERT */
382 EXPECT_EQUAL(s2n_conn_get_current_message_type(conn), SERVER_CERT);
383
384 /* Clean up */
385 EXPECT_EQUAL(waitpid(pid, &status, 0), pid);
386 EXPECT_EQUAL(status, 0);
387 EXPECT_SUCCESS(close(p[0]));
388
389 /* Test an 'too large' certificate list */
390
391 /* Create a pipe */
392 EXPECT_SUCCESS(pipe(p));
393
394 EXPECT_SUCCESS(s2n_connection_wipe(conn));
395
396 /* Set up the connection to read from the fd */
397 EXPECT_SUCCESS(s2n_connection_set_read_fd(conn, p[0]));
398
399 /* Pretend the client hello has already been set */
400 conn->handshake.handshake_type = NEGOTIATED | FULL_HANDSHAKE;
401 conn->handshake.message_number = SERVER_HELLO;
402 conn->server_protocol_version = S2N_TLS12;
403 conn->client_protocol_version = S2N_TLS12;
404 conn->actual_protocol_version = S2N_TLS12;
405
406 /* Create a child process */
407 pid = fork();
408 if (pid == 0) {
409 /* This is the child process, close the read end of the pipe */
410 EXPECT_SUCCESS(close(p[0]));
411
412 send_messages(p[1], server_hello_message, sizeof(server_hello_message), certificate_list_too_large, sizeof(certificate_list_too_large));
413
414 EXPECT_SUCCESS(s2n_connection_free(conn));
415 EXPECT_SUCCESS(s2n_config_free(config));
416 exit(0);
417 }
418
419 /* This is the parent process, close the write end of the pipe */
420 EXPECT_SUCCESS(close(p[1]));
421
422 /* Negotiate the handshake. This will fail due to EOF, but that's ok. Turn off Blinding before negotiation so that
423 * server doesn't delay its response and test finishes quickly. */
424 EXPECT_SUCCESS(s2n_connection_set_blinding(conn, S2N_SELF_SERVICE_BLINDING));
425 EXPECT_FAILURE(s2n_negotiate(conn, &blocked));
426
427 /* Verify that the data is as we expect it */
428 EXPECT_EQUAL(memcmp(conn->handshake_params.server_random, zero_to_thirty_one, 32), 0);
429
430 /* Check that the server hello message was not processed, we're stuck in SERVER_CERT */
431 EXPECT_EQUAL(s2n_conn_get_current_message_type(conn), SERVER_CERT);
432
433 /* Clean up */
434 EXPECT_EQUAL(waitpid(pid, &status, 0), pid);
435 EXPECT_EQUAL(status, 0);
436 EXPECT_SUCCESS(close(p[0]));
437
438 /* Test an 'too large' certificate */
439
440 /* Create a pipe */
441 EXPECT_SUCCESS(pipe(p));
442
443 EXPECT_SUCCESS(s2n_connection_wipe(conn));
444
445 /* Set up the connection to read from the fd */
446 EXPECT_SUCCESS(s2n_connection_set_read_fd(conn, p[0]));
447
448 /* Pretend the client hello has already been set */
449 conn->handshake.handshake_type = NEGOTIATED | FULL_HANDSHAKE;
450 conn->handshake.message_number = SERVER_HELLO;
451 conn->server_protocol_version = S2N_TLS12;
452 conn->client_protocol_version = S2N_TLS12;
453 conn->actual_protocol_version = S2N_TLS12;
454
455 /* Create a child process */
456 pid = fork();
457 if (pid == 0) {
458 /* This is the child process, close the read end of the pipe */
459 EXPECT_SUCCESS(close(p[0]));
460
461 send_messages(p[1], server_hello_message, sizeof(server_hello_message), certificate_too_large, sizeof(certificate_too_large));
462
463 EXPECT_SUCCESS(s2n_connection_free(conn));
464 EXPECT_SUCCESS(s2n_config_free(config));
465 exit(0);
466 }
467
468 /* This is the parent process, close the write end of the pipe */
469 EXPECT_SUCCESS(close(p[1]));
470
471 /* Negotiate the handshake. This will fail due to EOF, but that's ok. Turn off Blinding before negotiation so that
472 * server doesn't delay its response and test finishes quickly. */
473 EXPECT_SUCCESS(s2n_connection_set_blinding(conn, S2N_SELF_SERVICE_BLINDING));
474 EXPECT_FAILURE(s2n_negotiate(conn, &blocked));
475
476 /* Verify that the data is as we expect it */
477 EXPECT_EQUAL(memcmp(conn->handshake_params.server_random, zero_to_thirty_one, 32), 0);
478
479 /* Check that the server hello message was not processed, we're stuck in SERVER_CERT */
480 EXPECT_EQUAL(s2n_conn_get_current_message_type(conn), SERVER_CERT);
481
482 /* Clean up */
483 EXPECT_EQUAL(waitpid(pid, &status, 0), pid);
484 EXPECT_EQUAL(status, 0);
485 EXPECT_SUCCESS(close(p[0]));
486
487 /* Test an 'too large' handshake */
488
489 /* Create a pipe */
490 EXPECT_SUCCESS(pipe(p));
491
492 EXPECT_SUCCESS(s2n_connection_wipe(conn));
493
494 /* Set up the connection to read from the fd */
495 EXPECT_SUCCESS(s2n_connection_set_read_fd(conn, p[0]));
496
497 /* Pretend the client hello has already been set */
498 conn->handshake.handshake_type = NEGOTIATED | FULL_HANDSHAKE;
499 conn->handshake.message_number = SERVER_HELLO;
500 conn->server_protocol_version = S2N_TLS12;
501 conn->client_protocol_version = S2N_TLS12;
502 conn->actual_protocol_version = S2N_TLS12;
503
504 /* Create a child process */
505 pid = fork();
506 if (pid == 0) {
507 /* This is the child process, close the read end of the pipe */
508 EXPECT_SUCCESS(close(p[0]));
509
510 send_messages(p[1], server_hello_message, sizeof(server_hello_message), certificate_list_too_large, sizeof(certificate_list_too_large));
511
512 EXPECT_SUCCESS(s2n_connection_free(conn));
513 EXPECT_SUCCESS(s2n_config_free(config));
514 exit(0);
515 }
516
517 /* This is the parent process, close the write end of the pipe */
518 EXPECT_SUCCESS(close(p[1]));
519
520 /* Negotiate the handshake. This will fail due to EOF, but that's ok. Turn off Blinding before negotiation so that
521 * server doesn't delay its response and test finishes quickly. */
522 EXPECT_SUCCESS(s2n_connection_set_blinding(conn, S2N_SELF_SERVICE_BLINDING));
523 EXPECT_FAILURE(s2n_negotiate(conn, &blocked));
524
525 /* Verify that the data is as we expect it */
526 EXPECT_EQUAL(memcmp(conn->handshake_params.server_random, zero_to_thirty_one, 32), 0);
527
528 /* Check that the server hello message was not processed, we're stuck in SERVER_CERT */
529 EXPECT_EQUAL(s2n_conn_get_current_message_type(conn), SERVER_CERT);
530
531 /* Clean up */
532 EXPECT_EQUAL(waitpid(pid, &status, 0), pid);
533 EXPECT_EQUAL(status, 0);
534 EXPECT_SUCCESS(close(p[0]));
535
536 END_TEST();
537 }