Debian Codegraph @

crt/s2n/tests/unit/s2n_tls13_handshake_state_machine_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
19 #include "api/s2n.h"
20 #include "crypto/s2n_fips.h"
21 #include "s2n_test.h"
22 #include "testlib/s2n_testlib.h"
23 #include "tls/s2n_cipher_suites.h"
24 #include "tls/s2n_connection.h"
25 #include "tls/s2n_handshake.h"
26 #include "tls/s2n_quic_support.h"
27 #include "tls/s2n_tls13.h"
28
29 /* Just to get access to the static functions / variables we need to test */
30 #include "tls/s2n_handshake_io.c"
31
32 static message_type_t invalid_handshake[S2N_MAX_HANDSHAKE_LENGTH] = { 0 };
33
34 static int expected_handler_called;
35 static int unexpected_handler_called;
36
37 static int s2n_test_handler(struct s2n_connection *conn)
38 {
39 unexpected_handler_called = 1;
40 return 0;
41 }
42
43 static int s2n_test_expected_handler(struct s2n_connection *conn)
44 {
45 expected_handler_called = 1;
46 return 0;
47 }
48
49 static int s2n_setup_handler_to_expect(message_type_t expected, uint8_t direction)
50 {
51 for (int i = 0; i < s2n_array_len(tls13_state_machine); i++) {
52 tls13_state_machine[i].handler[0] = s2n_test_handler;
53 tls13_state_machine[i].handler[1] = s2n_test_handler;
54 }
55
56 tls13_state_machine[expected].handler[direction] = s2n_test_expected_handler;
57
58 expected_handler_called = 0;
59 unexpected_handler_called = 0;
60
61 return 0;
62 }
63
64 static int s2n_test_write_header(struct s2n_stuffer *output, uint8_t record_type, uint8_t message_type)
65 {
66 POSIX_GUARD(s2n_stuffer_write_uint8(output, record_type));
67
68 /* TLS1.2 protocol version */
69 POSIX_GUARD(s2n_stuffer_write_uint8(output, 3));
70 POSIX_GUARD(s2n_stuffer_write_uint8(output, 3));
71
72 if (record_type == TLS_HANDSHAKE) {
73 /* Total message size */
74 POSIX_GUARD(s2n_stuffer_write_uint16(output, 4));
75
76 POSIX_GUARD(s2n_stuffer_write_uint8(output, message_type));
77
78 /* Handshake message data size */
79 POSIX_GUARD(s2n_stuffer_write_uint24(output, 0));
80 return 0;
81 }
82
83 if (record_type == TLS_CHANGE_CIPHER_SPEC) {
84 /* Total message size */
85 POSIX_GUARD(s2n_stuffer_write_uint16(output, 1));
86
87 /* change spec is always just 0x01 */
88 POSIX_GUARD(s2n_stuffer_write_uint8(output, 1));
89 return 0;
90 }
91
92 return 0;
93 }
94
95 int main(int argc, char **argv)
96 {
97 BEGIN_TEST();
98
99 EXPECT_SUCCESS(s2n_enable_tls13_in_test());
100
101 /* Construct an array of all valid tls1.3 handshake_types */
102 uint16_t valid_tls13_handshakes[S2N_HANDSHAKES_COUNT];
103 int valid_tls13_handshakes_size = 0;
104 for (int i = 0; i < S2N_HANDSHAKES_COUNT; i++) {
105 if (memcmp(tls13_handshakes[i], invalid_handshake, S2N_MAX_HANDSHAKE_LENGTH) != 0) {
106 valid_tls13_handshakes[valid_tls13_handshakes_size] = i;
107 valid_tls13_handshakes_size++;
108 }
109 }
110 EXPECT_TRUE(valid_tls13_handshakes_size > 0);
111 EXPECT_TRUE(valid_tls13_handshakes_size < S2N_HANDSHAKES_COUNT);
112
113 /* Use handler stubs to avoid errors in handler implementation */
114 for (int i = 0; i < s2n_array_len(tls13_state_machine); i++) {
115 tls13_state_machine[i].handler[0] = s2n_test_handler;
116 tls13_state_machine[i].handler[1] = s2n_test_handler;
117 }
118
119 /* Test: A WITH_EARLY_DATA form of every non-full, non-retry handshake exists
120 * and matches the non-WITH_EARLY_DATA form EXCEPT for the END_OF_EARLY_DATA
121 * message and client CCS messages.
122 */
123 {
124 uint32_t original_handshake_type = 0, early_data_handshake_type = 0;
125 message_type_t *original_messages = NULL, *early_data_messages = NULL;
126
127 for (size_t i = 0; i < valid_tls13_handshakes_size; i++) {
128 original_handshake_type = valid_tls13_handshakes[i];
129 original_messages = tls13_handshakes[original_handshake_type];
130
131 /* WITH_EARLY_DATA form of the handshake */
132 early_data_handshake_type = original_handshake_type | WITH_EARLY_DATA;
133 early_data_messages = tls13_handshakes[early_data_handshake_type];
134
135 /* No handshake exists for INITIAL, FULL_HANDSHAKE, or HELLO_RETRY_REQUEST handshakes */
136 if (!(original_handshake_type & NEGOTIATED) || (original_handshake_type & FULL_HANDSHAKE)
137 || (original_handshake_type & HELLO_RETRY_REQUEST)) {
138 EXPECT_BYTEARRAY_EQUAL(early_data_messages, invalid_handshake, sizeof(invalid_handshake));
139 continue;
140 }
141
142 /* Ignore identical handshakes */
143 if (original_handshake_type == early_data_handshake_type) {
144 continue;
145 }
146
147 size_t end_of_early_data_messages = 0;
148 size_t j = 0, j_ed = 0;
149 while (j < S2N_MAX_HANDSHAKE_LENGTH && j_ed < S2N_MAX_HANDSHAKE_LENGTH) {
150 /* The original handshake must NOT contain END_OF_EARLY_DATA messages */
151 EXPECT_NOT_EQUAL(original_messages[j], END_OF_EARLY_DATA);
152
153 /* Count END_OF_EARLY_DATA messages in the WITH_EARLY_DATA handshake */
154 if (early_data_messages[j_ed] == END_OF_EARLY_DATA) {
155 end_of_early_data_messages++;
156 j_ed++;
157 continue;
158 }
159
160 /* Skip client CCS message in both handshakes - they won't appear at the same point */
161 if (early_data_messages[j_ed] == CLIENT_CHANGE_CIPHER_SPEC) {
162 j_ed++;
163 continue;
164 }
165 if (original_messages[j] == CLIENT_CHANGE_CIPHER_SPEC) {
166 j++;
167 continue;
168 }
169
170 /* The handshakes must be otherwise equivalent */
171 EXPECT_EQUAL(original_messages[j], early_data_messages[j_ed]);
172 j++;
173 j_ed++;
174 }
175 if (original_handshake_type & NEGOTIATED) {
176 EXPECT_EQUAL(end_of_early_data_messages, 1);
177 } else {
178 EXPECT_EQUAL(end_of_early_data_messages, 0);
179 }
180 }
181 };
182
183 /* Test: A MIDDLEBOX_COMPAT form of every valid, negotiated handshake exists
184 * and matches the non-MIDDLEBOX_COMPAT form EXCEPT for CCS messages */
185 {
186 uint32_t handshake_type_original = 0, handshake_type_mc = 0;
187 message_type_t *messages_original = NULL, *messages_mc = NULL;
188
189 for (size_t i = 0; i < valid_tls13_handshakes_size; i++) {
190 handshake_type_original = valid_tls13_handshakes[i];
191 messages_original = tls13_handshakes[handshake_type_original];
192
193 /* Ignore INITIAL and MIDDLEBOX_COMPAT handshakes */
194 if (!(handshake_type_original & NEGOTIATED) || (handshake_type_original & MIDDLEBOX_COMPAT)) {
195 continue;
196 }
197
198 /* MIDDLEBOX_COMPAT form of the handshake */
199 handshake_type_mc = handshake_type_original | MIDDLEBOX_COMPAT;
200 messages_mc = tls13_handshakes[handshake_type_mc];
201
202 for (size_t j = 0, j_mc = 0; j < S2N_MAX_HANDSHAKE_LENGTH && j_mc < S2N_MAX_HANDSHAKE_LENGTH; j++, j_mc++) {
203 /* The original handshake cannot contain CCS messages */
204 EXPECT_NOT_EQUAL(messages_original[j], SERVER_CHANGE_CIPHER_SPEC);
205 EXPECT_NOT_EQUAL(messages_original[j], CLIENT_CHANGE_CIPHER_SPEC);
206
207 /* Skip CCS messages in the MIDDLEBOX_COMPAT handshake */
208 while (messages_mc[j_mc] == SERVER_CHANGE_CIPHER_SPEC
209 || messages_mc[j_mc] == CLIENT_CHANGE_CIPHER_SPEC) {
210 j_mc++;
211 }
212
213 /* The handshakes must be otherwise equivalent */
214 EXPECT_EQUAL(messages_original[j], messages_mc[j_mc]);
215 }
216 }
217 };
218
219 /* Test: A non-FULL_HANDSHAKE form of every valid, negotiated handshake exists */
220 {
221 uint32_t handshake_type_original = 0, handshake_type_fh = 0;
222 message_type_t *messages_original = NULL, *messages_fh = NULL;
223
224 for (size_t i = 0; i < valid_tls13_handshakes_size; i++) {
225 handshake_type_original = valid_tls13_handshakes[i];
226 messages_original = tls13_handshakes[handshake_type_original];
227
228 /* Ignore INITIAL and FULL_HANDSHAKE handshakes */
229 if (!(handshake_type_original & NEGOTIATED) || (handshake_type_original & FULL_HANDSHAKE)) {
230 continue;
231 }
232
233 /* FULL_HANDSHAKE form of the handshake */
234 handshake_type_fh = handshake_type_original | FULL_HANDSHAKE;
235 messages_fh = tls13_handshakes[handshake_type_fh];
236
237 /* No FULL handshake exists for INITIAL or WITH_EARLY_DATA handshakes */
238 if (!(handshake_type_original & NEGOTIATED) || (handshake_type_original & WITH_EARLY_DATA)) {
239 EXPECT_BYTEARRAY_EQUAL(messages_fh, invalid_handshake, sizeof(invalid_handshake));
240 continue;
241 }
242
243 /* Ignore identical handshakes */
244 if (handshake_type_original == handshake_type_fh) {
245 continue;
246 }
247
248 for (size_t j = 0, j_fh = 0; j < S2N_MAX_HANDSHAKE_LENGTH && j_fh < S2N_MAX_HANDSHAKE_LENGTH; j++, j_fh++) {
249 /* The original handshake cannot contain authentication messages */
250 EXPECT_NOT_EQUAL(messages_original[j], SERVER_CERT);
251 EXPECT_NOT_EQUAL(messages_original[j], SERVER_CERT_VERIFY);
252
253 /* Skip authentication messages in the FULL_HANDSHAKE handshake */
254 while (messages_fh[j_fh] == SERVER_CERT || messages_fh[j_fh] == SERVER_CERT_VERIFY) {
255 j_fh++;
256 }
257
258 /* The handshakes must be otherwise equivalent */
259 EXPECT_EQUAL(messages_original[j], messages_fh[j_fh]);
260 }
261 }
262 };
263
264 /* Test: A EARLY_CLIENT_CCS form of every middlebox compatible handshake exists.
265 * Any handshake could start with early data, even if that early data is later rejected. */
266 {
267 uint32_t handshake_type_original = 0, handshake_type_test = 0;
268 message_type_t *messages_original = NULL, *messages_test = NULL;
269
270 for (size_t i = 0; i < valid_tls13_handshakes_size; i++) {
271 handshake_type_original = valid_tls13_handshakes[i];
272 messages_original = tls13_handshakes[handshake_type_original];
273
274 /* Ignore non-MIDDLEBOX_COMPAT handshakes */
275 if (!(handshake_type_original & MIDDLEBOX_COMPAT)) {
276 continue;
277 }
278
279 /* EARLY_CLIENT_CCS form of the handshake */
280 handshake_type_test = handshake_type_original | EARLY_CLIENT_CCS;
281 messages_test = tls13_handshakes[handshake_type_test];
282
283 /* Ignore identical handshakes */
284 if (handshake_type_original == handshake_type_test) {
285 continue;
286 }
287
288 for (size_t j = 0, j_test = 0; j < S2N_MAX_HANDSHAKE_LENGTH && j_test < S2N_MAX_HANDSHAKE_LENGTH; j++, j_test++) {
289 /* Skip Client CCS messages */
290 while (messages_original[j] == CLIENT_CHANGE_CIPHER_SPEC) {
291 j++;
292 }
293 while (messages_test[j_test] == CLIENT_CHANGE_CIPHER_SPEC) {
294 j_test++;
295 }
296
297 /* The handshakes must be otherwise equivalent */
298 EXPECT_EQUAL(messages_original[j], messages_test[j_test]);
299 }
300 }
301 };
302
303 /* Test: When using TLS 1.3, use the new state machine and handshakes */
304 {
305 struct s2n_connection *conn = s2n_connection_new(S2N_CLIENT);
306 conn->actual_protocol_version = S2N_TLS13;
307 EXPECT_OK(s2n_conn_choose_state_machine(conn, S2N_TLS13));
308 EXPECT_EQUAL(&ACTIVE_STATE_MACHINE(conn)[0], &tls13_state_machine[0]);
309 EXPECT_EQUAL(&ACTIVE_HANDSHAKES(conn)[0], &tls13_handshakes[0]);
310 EXPECT_SUCCESS(s2n_connection_free(conn));
311 };
312
313 /* Test: TLS1.3 server does not wait for client cipher change requests */
314 {
315 struct s2n_connection *conn = s2n_connection_new(S2N_SERVER);
316 conn->actual_protocol_version = S2N_TLS13;
317 EXPECT_OK(s2n_conn_choose_state_machine(conn, S2N_TLS13));
318
319 for (int i = 0; i < valid_tls13_handshakes_size; i++) {
320 int handshake = valid_tls13_handshakes[i];
321
322 conn->handshake.handshake_type = handshake;
323
324 for (int j = 0; j < S2N_MAX_HANDSHAKE_LENGTH; j++) {
325 if (tls13_handshakes[handshake][j] == CLIENT_CHANGE_CIPHER_SPEC) {
326 conn->handshake.message_number = j - 1;
327
328 EXPECT_SUCCESS(s2n_advance_message(conn));
329
330 EXPECT_EQUAL(conn->handshake.message_number, j + 1);
331 EXPECT_NOT_EQUAL(ACTIVE_MESSAGE(conn), CLIENT_CHANGE_CIPHER_SPEC);
332
333 break;
334 }
335 }
336 }
337
338 EXPECT_SUCCESS(s2n_connection_free(conn));
339 };
340
341 /* Test: TLS1.3 server does not skip server cipher change requests */
342 {
343 struct s2n_connection *conn = s2n_connection_new(S2N_SERVER);
344 conn->actual_protocol_version = S2N_TLS13;
345 EXPECT_OK(s2n_conn_choose_state_machine(conn, S2N_TLS13));
346
347 for (int i = 0; i < valid_tls13_handshakes_size; i++) {
348 int handshake = valid_tls13_handshakes[i];
349
350 conn->handshake.handshake_type = handshake;
351
352 for (int j = 0; j < S2N_MAX_HANDSHAKE_LENGTH; j++) {
353 if (tls13_handshakes[handshake][j] == SERVER_CHANGE_CIPHER_SPEC) {
354 conn->handshake.message_number = j - 1;
355
356 EXPECT_SUCCESS(s2n_advance_message(conn));
357
358 EXPECT_EQUAL(conn->handshake.message_number, j);
359 EXPECT_EQUAL(ACTIVE_MESSAGE(conn), SERVER_CHANGE_CIPHER_SPEC);
360
361 break;
362 }
363 }
364 }
365
366 EXPECT_SUCCESS(s2n_connection_free(conn));
367 };
368
369 /* Test: TLS1.3 client does not wait for server cipher change requests */
370 {
371 struct s2n_connection *conn = s2n_connection_new(S2N_CLIENT);
372 conn->actual_protocol_version = S2N_TLS13;
373 EXPECT_OK(s2n_conn_choose_state_machine(conn, S2N_TLS13));
374
375 for (int i = 0; i < valid_tls13_handshakes_size; i++) {
376 int handshake = valid_tls13_handshakes[i];
377
378 conn->handshake.handshake_type = handshake;
379
380 for (int j = 0; j < S2N_MAX_HANDSHAKE_LENGTH; j++) {
381 if (tls13_handshakes[handshake][j] == SERVER_CHANGE_CIPHER_SPEC) {
382 conn->handshake.message_number = j - 1;
383
384 EXPECT_SUCCESS(s2n_advance_message(conn));
385
386 EXPECT_EQUAL(conn->handshake.message_number, j + 1);
387 EXPECT_NOT_EQUAL(ACTIVE_MESSAGE(conn), SERVER_CHANGE_CIPHER_SPEC);
388
389 break;
390 }
391 }
392 }
393
394 EXPECT_SUCCESS(s2n_connection_free(conn));
395 };
396
397 /* Test: TLS1.3 client does not skip client cipher change requests */
398 {
399 struct s2n_connection *conn = s2n_connection_new(S2N_CLIENT);
400 conn->actual_protocol_version = S2N_TLS13;
401 EXPECT_OK(s2n_conn_choose_state_machine(conn, S2N_TLS13));
402
403 for (int i = 0; i < valid_tls13_handshakes_size; i++) {
404 int handshake = valid_tls13_handshakes[i];
405
406 conn->handshake.handshake_type = handshake;
407
408 for (int j = 0; j < S2N_MAX_HANDSHAKE_LENGTH; j++) {
409 if (tls13_handshakes[handshake][j] == CLIENT_CHANGE_CIPHER_SPEC) {
410 conn->handshake.message_number = j - 1;
411
412 EXPECT_SUCCESS(s2n_advance_message(conn));
413
414 EXPECT_EQUAL(conn->handshake.message_number, j);
415 EXPECT_EQUAL(ACTIVE_MESSAGE(conn), CLIENT_CHANGE_CIPHER_SPEC);
416
417 break;
418 }
419 }
420 }
421
422 EXPECT_SUCCESS(s2n_connection_free(conn));
423 };
424
425 /* Test: TLS1.3 client can receive a server cipher change spec at any time. */
426 {
427 struct s2n_connection *conn = s2n_connection_new(S2N_CLIENT);
428 conn->actual_protocol_version = S2N_TLS13;
429 EXPECT_OK(s2n_conn_choose_state_machine(conn, S2N_TLS13));
430
431 struct s2n_stuffer input = { 0 };
432 EXPECT_SUCCESS(s2n_stuffer_growable_alloc(&input, 0));
433 EXPECT_SUCCESS(s2n_connection_set_io_stuffers(&input, NULL, conn));
434
435 EXPECT_SUCCESS(s2n_setup_handler_to_expect(SERVER_CHANGE_CIPHER_SPEC, S2N_CLIENT));
436
437 for (int i = 0; i < valid_tls13_handshakes_size; i++) {
438 int handshake = valid_tls13_handshakes[i];
439
440 conn->handshake.handshake_type = handshake;
441 conn->in_status = ENCRYPTED;
442
443 for (int j = 1; j < S2N_MAX_HANDSHAKE_LENGTH; j++) {
444 conn->handshake.message_number = j;
445
446 EXPECT_SUCCESS(s2n_test_write_header(&input, TLS_CHANGE_CIPHER_SPEC, 0));
447
448 EXPECT_SUCCESS(s2n_handshake_read_io(conn));
449
450 if (tls13_handshakes[handshake][j] == SERVER_CHANGE_CIPHER_SPEC) {
451 EXPECT_EQUAL(conn->handshake.message_number, j + 1);
452 } else {
453 EXPECT_EQUAL(conn->handshake.message_number, j);
454 }
455
456 EXPECT_FALSE(unexpected_handler_called);
457 EXPECT_TRUE(expected_handler_called);
458
459 EXPECT_SUCCESS(s2n_stuffer_wipe(&input));
460 }
461 }
462
463 EXPECT_SUCCESS(s2n_stuffer_free(&input));
464 EXPECT_SUCCESS(s2n_connection_free(conn));
465 };
466
467 /* Test: TLS1.3 server can receive a client cipher change request at any time. */
468 {
469 struct s2n_connection *conn = s2n_connection_new(S2N_SERVER);
470 conn->actual_protocol_version = S2N_TLS13;
471 EXPECT_OK(s2n_conn_choose_state_machine(conn, S2N_TLS13));
472
473 struct s2n_stuffer input = { 0 };
474 EXPECT_SUCCESS(s2n_stuffer_growable_alloc(&input, 0));
475 EXPECT_SUCCESS(s2n_connection_set_io_stuffers(&input, NULL, conn));
476
477 EXPECT_SUCCESS(s2n_setup_handler_to_expect(CLIENT_CHANGE_CIPHER_SPEC, S2N_SERVER));
478
479 for (int i = 0; i < valid_tls13_handshakes_size; i++) {
480 int handshake = valid_tls13_handshakes[i];
481
482 conn->handshake.handshake_type = handshake;
483 conn->in_status = ENCRYPTED;
484
485 for (int j = 1; j < S2N_MAX_HANDSHAKE_LENGTH; j++) {
486 conn->handshake.message_number = j;
487
488 EXPECT_SUCCESS(s2n_test_write_header(&input, TLS_CHANGE_CIPHER_SPEC, 0));
489
490 EXPECT_SUCCESS(s2n_handshake_read_io(conn));
491
492 if (tls13_handshakes[handshake][j] == CLIENT_CHANGE_CIPHER_SPEC) {
493 EXPECT_EQUAL(conn->handshake.message_number, j + 1);
494 } else {
495 EXPECT_EQUAL(conn->handshake.message_number, j);
496 }
497
498 EXPECT_FALSE(unexpected_handler_called);
499 EXPECT_TRUE(expected_handler_called);
500
501 EXPECT_SUCCESS(s2n_stuffer_wipe(&input));
502 }
503 }
504
505 EXPECT_SUCCESS(s2n_stuffer_free(&input));
506 EXPECT_SUCCESS(s2n_connection_free(conn));
507 };
508
509 /* Test: TLS1.3 s2n_handshake_read_io should accept only the expected message */
510 {
511 /* TLS1.3 should accept the expected message */
512 {
513 struct s2n_connection *conn = s2n_connection_new(S2N_SERVER);
514 conn->actual_protocol_version = S2N_TLS13;
515 EXPECT_OK(s2n_conn_choose_state_machine(conn, S2N_TLS13));
516
517 struct s2n_stuffer input = { 0 };
518 EXPECT_SUCCESS(s2n_stuffer_growable_alloc(&input, 0));
519 EXPECT_SUCCESS(s2n_connection_set_io_stuffers(&input, NULL, conn));
520
521 conn->handshake.handshake_type = 0;
522 conn->handshake.message_number = 0;
523 conn->secure->cipher_suite = &s2n_tls13_aes_128_gcm_sha256;
524 EXPECT_EQUAL(ACTIVE_MESSAGE(conn), CLIENT_HELLO);
525 EXPECT_SUCCESS(s2n_setup_handler_to_expect(CLIENT_HELLO, S2N_SERVER));
526
527 EXPECT_SUCCESS(s2n_test_write_header(&input, TLS_HANDSHAKE, TLS_CLIENT_HELLO));
528 EXPECT_SUCCESS(s2n_handshake_read_io(conn));
529
530 EXPECT_EQUAL(conn->handshake.message_number, 1);
531 EXPECT_FALSE(unexpected_handler_called);
532 EXPECT_TRUE(expected_handler_called);
533
534 EXPECT_SUCCESS(s2n_stuffer_free(&input));
535 EXPECT_SUCCESS(s2n_connection_free(conn));
536 };
537
538 /* TLS1.3 should error for an unexpected message */
539 {
540 struct s2n_connection *conn = s2n_connection_new(S2N_SERVER);
541 conn->actual_protocol_version = S2N_TLS13;
542 EXPECT_OK(s2n_conn_choose_state_machine(conn, S2N_TLS13));
543
544 struct s2n_stuffer input = { 0 };
545 EXPECT_SUCCESS(s2n_stuffer_growable_alloc(&input, 0));
546 EXPECT_SUCCESS(s2n_connection_set_io_stuffers(&input, NULL, conn));
547
548 conn->handshake.handshake_type = 0;
549 conn->handshake.message_number = 0;
550 EXPECT_EQUAL(ACTIVE_MESSAGE(conn), CLIENT_HELLO);
551 EXPECT_SUCCESS(s2n_setup_handler_to_expect(CLIENT_HELLO, S2N_SERVER));
552
553 EXPECT_SUCCESS(s2n_test_write_header(&input, TLS_HANDSHAKE, TLS_CERTIFICATE));
554 EXPECT_FAILURE_WITH_ERRNO(s2n_handshake_read_io(conn), S2N_ERR_BAD_MESSAGE);
555
556 EXPECT_EQUAL(conn->handshake.message_number, 0);
557 EXPECT_FALSE(unexpected_handler_called);
558 EXPECT_FALSE(expected_handler_called);
559
560 EXPECT_SUCCESS(s2n_stuffer_free(&input));
561 EXPECT_SUCCESS(s2n_connection_free(conn));
562 };
563
564 /* TLS1.3 should error for an expected message from the wrong writer */
565 {
566 struct s2n_connection *conn = s2n_connection_new(S2N_CLIENT);
567 conn->actual_protocol_version = S2N_TLS13;
568 EXPECT_OK(s2n_conn_choose_state_machine(conn, S2N_TLS13));
569
570 struct s2n_stuffer input = { 0 };
571 EXPECT_SUCCESS(s2n_stuffer_growable_alloc(&input, 0));
572 EXPECT_SUCCESS(s2n_connection_set_io_stuffers(&input, NULL, conn));
573
574 conn->handshake.handshake_type = 0;
575 conn->handshake.message_number = 0;
576 EXPECT_EQUAL(ACTIVE_MESSAGE(conn), CLIENT_HELLO);
577 EXPECT_SUCCESS(s2n_setup_handler_to_expect(CLIENT_HELLO, S2N_SERVER));
578
579 EXPECT_SUCCESS(s2n_test_write_header(&input, TLS_HANDSHAKE, TLS_CLIENT_HELLO));
580 EXPECT_FAILURE_WITH_ERRNO(s2n_handshake_read_io(conn), S2N_ERR_BAD_MESSAGE);
581
582 EXPECT_EQUAL(conn->handshake.message_number, 0);
583 EXPECT_FALSE(unexpected_handler_called);
584 EXPECT_FALSE(expected_handler_called);
585
586 EXPECT_SUCCESS(s2n_stuffer_free(&input));
587 EXPECT_SUCCESS(s2n_connection_free(conn));
588 };
589
590 /* TLS1.3 should error for an expected message from the wrong record type */
591 {
592 /* Unfortunately, all our non-handshake record types have a message type of 0,
593 * and the combination of TLS_HANDSHAKE + "0" is actually a message (TLS_HELLO_REQUEST)
594 * which can appear at any point in a TLS1.2 handshake.
595 *
596 * To test, temporarily modify the actions table.
597 * We MUST restore this after this test.
598 */
599 uint8_t old_message_type = state_machine[SERVER_CHANGE_CIPHER_SPEC].message_type;
600 state_machine[SERVER_CHANGE_CIPHER_SPEC].message_type = 1;
601
602 struct s2n_connection *conn = s2n_connection_new(S2N_CLIENT);
603 conn->actual_protocol_version = S2N_TLS13;
604 EXPECT_OK(s2n_conn_choose_state_machine(conn, S2N_TLS13));
605
606 struct s2n_stuffer input = { 0 };
607 EXPECT_SUCCESS(s2n_stuffer_growable_alloc(&input, 0));
608 EXPECT_SUCCESS(s2n_connection_set_io_stuffers(&input, NULL, conn));
609
610 uint8_t server_css_message_number = 2;
611 conn->handshake.handshake_type = NEGOTIATED | FULL_HANDSHAKE | MIDDLEBOX_COMPAT;
612 conn->handshake.message_number = server_css_message_number;
613 EXPECT_EQUAL(ACTIVE_MESSAGE(conn), SERVER_CHANGE_CIPHER_SPEC);
614 EXPECT_SUCCESS(s2n_setup_handler_to_expect(SERVER_CHANGE_CIPHER_SPEC, S2N_CLIENT));
615
616 EXPECT_SUCCESS(s2n_test_write_header(&input, TLS_HANDSHAKE, ACTIVE_STATE(conn).message_type));
617 EXPECT_FAILURE_WITH_ERRNO(s2n_handshake_read_io(conn), S2N_ERR_BAD_MESSAGE);
618
619 EXPECT_EQUAL(conn->handshake.message_number, server_css_message_number);
620 EXPECT_FALSE(unexpected_handler_called);
621 EXPECT_FALSE(expected_handler_called);
622
623 EXPECT_SUCCESS(s2n_stuffer_free(&input));
624 EXPECT_SUCCESS(s2n_connection_free(conn));
625 state_machine[SERVER_CHANGE_CIPHER_SPEC].message_type = old_message_type;
626 };
627
628 /* Error if a client receives a client cert request in non-FULL_HANDSHAKE mode */
629 {
630 struct s2n_connection *conn = s2n_connection_new(S2N_CLIENT);
631 conn->actual_protocol_version = S2N_TLS13;
632 EXPECT_OK(s2n_conn_choose_state_machine(conn, S2N_TLS13));
633 POSIX_GUARD(s2n_connection_set_client_auth_type(conn, S2N_CERT_AUTH_OPTIONAL));
634
635 struct s2n_stuffer input = { 0 };
636 EXPECT_SUCCESS(s2n_stuffer_growable_alloc(&input, 0));
637 EXPECT_SUCCESS(s2n_connection_set_io_stuffers(&input, NULL, conn));
638
639 EXPECT_SUCCESS(s2n_test_write_header(&input, TLS_HANDSHAKE, TLS_CERT_REQ));
640 EXPECT_FAILURE_WITH_ERRNO(s2n_handshake_read_io(conn), S2N_ERR_HANDSHAKE_STATE);
641
642 EXPECT_SUCCESS(s2n_stuffer_free(&input));
643 EXPECT_SUCCESS(s2n_connection_free(conn));
644 };
645 };
646
647 /* Test: TLS 1.3 MIDDLEBOX_COMPAT handshakes all follow CCS middlebox compatibility rules.
648 *
649 *= https://www.rfc-editor.org/rfc/rfc8446#appendix-D.4
650 *= type=test
651 *# Field measurements [Ben17a] [Ben17b] [Res17a] [Res17b] have found
652 *# that a significant number of middleboxes misbehave when a TLS
653 *# client/server pair negotiates TLS 1.3. Implementations can increase
654 *# the chance of making connections through those middleboxes by making
655 *# the TLS 1.3 handshake look more like a TLS 1.2 handshake:
656 */
657 {
658 /*
659 *= https://www.rfc-editor.org/rfc/rfc8446#appendix-D.4
660 *= type=test
661 *# If not offering early data, the client sends a dummy
662 *# change_cipher_spec record (see the third paragraph of Section 5)
663 *# immediately before its second flight. This may either be before
664 *# its second ClientHello or before its encrypted handshake flight.
665 **/
666 for (size_t i = 0; i < valid_tls13_handshakes_size; i++) {
667 bool change_cipher_spec_found = false;
668 uint32_t handshake_type = valid_tls13_handshakes[i];
669 message_type_t *messages = tls13_handshakes[handshake_type];
670
671 /* Ignore INITIAL and non-MIDDLEBOX_COMPAT handshakes */
672 if (!(handshake_type & NEGOTIATED)
673 || !(handshake_type & MIDDLEBOX_COMPAT)
674 || (handshake_type & EARLY_CLIENT_CCS)) {
675 continue;
676 }
677
678 for (size_t j = 1; j < S2N_MAX_HANDSHAKE_LENGTH; j++) {
679 /* Is it the second client flight?
680 * Have we switched from the server sending to the client sending? */
681 if (tls13_state_machine[messages[j]].writer != 'C'
682 || tls13_state_machine[messages[j - 1]].writer != 'S') {
683 continue;
684 }
685
686 EXPECT_EQUAL(messages[j], CLIENT_CHANGE_CIPHER_SPEC);
687 EXPECT_EQUAL(tls13_state_machine[messages[j + 1]].writer, 'C');
688
689 /* CCS message found. We are done with this handshake. */
690 change_cipher_spec_found = true;
691 break;
692 }
693
694 EXPECT_TRUE(change_cipher_spec_found);
695 }
696
697 /**
698 *= https://www.rfc-editor.org/rfc/rfc8446#appendix-D.4
699 *= type=test
700 *# If offering early data, the record is placed immediately after the
701 *# first ClientHello.
702 */
703 for (size_t i = 0; i < valid_tls13_handshakes_size; i++) {
704 uint32_t handshake_type = valid_tls13_handshakes[i];
705 message_type_t *messages = tls13_handshakes[handshake_type];
706
707 /* Ignore handshakes where early data did not trigger the change in CCS behavior */
708 if (!(handshake_type & EARLY_CLIENT_CCS)) {
709 continue;
710 }
711
712 EXPECT_EQUAL(messages[0], CLIENT_HELLO);
713 EXPECT_EQUAL(messages[1], CLIENT_CHANGE_CIPHER_SPEC);
714 for (size_t j = 2; j < S2N_MAX_HANDSHAKE_LENGTH; j++) {
715 EXPECT_NOT_EQUAL(messages[j], CLIENT_CHANGE_CIPHER_SPEC);
716 }
717 }
718
719 /**
720 *= https://www.rfc-editor.org/rfc/rfc8446#appendix-D.4
721 *= type=test
722 *# The server sends a dummy change_cipher_spec record immediately
723 *# after its first handshake message. This may either be after a
724 *# ServerHello or a HelloRetryRequest.
725 **/
726 for (size_t i = 0; i < valid_tls13_handshakes_size; i++) {
727 bool change_cipher_spec_found = false;
728 uint32_t handshake_type = valid_tls13_handshakes[i];
729 message_type_t *messages = tls13_handshakes[handshake_type];
730
731 /* Ignore INITIAL and non-MIDDLEBOX_COMPAT handshakes */
732 if (!(handshake_type & NEGOTIATED) || !(handshake_type & MIDDLEBOX_COMPAT)) {
733 continue;
734 }
735
736 for (size_t j = 1; j < S2N_MAX_HANDSHAKE_LENGTH; j++) {
737 /* Is it the first server flight?
738 * Have we switched from the client sending to the server sending? */
739 if (tls13_state_machine[messages[j]].writer != 'S'
740 || tls13_state_machine[messages[j - 1]].writer != 'C') {
741 continue;
742 }
743
744 EXPECT_EQUAL(messages[j + 1], SERVER_CHANGE_CIPHER_SPEC);
745 EXPECT_TRUE(messages[j] == SERVER_HELLO || messages[j] == HELLO_RETRY_MSG);
746
747 /* CCS message found. We are done with this handshake. */
748 change_cipher_spec_found = true;
749 break;
750 }
751
752 EXPECT_TRUE(change_cipher_spec_found);
753 }
754 };
755
756 /* Test: TLS1.3 s2n_conn_set_handshake_type sets only handshake flags allowed by TLS1.3 */
757 {
758 struct s2n_connection *conn = s2n_connection_new(S2N_CLIENT);
759
760 /* Ensure WITH_SESSION_TICKETS is set */
761 conn->config->use_tickets = 1;
762 conn->session_ticket_status = S2N_NEW_TICKET;
763
764 /* Ensure CLIENT_AUTH is set */
765 EXPECT_SUCCESS(s2n_connection_set_client_auth_type(conn, S2N_CERT_AUTH_REQUIRED));
766
767 /* Ensure TLS12_PERFECT_FORWARD_SECRECY is set by choosing a cipher suite with is_ephemeral=1 on the kex */
768 conn->secure->cipher_suite = &s2n_dhe_rsa_with_chacha20_poly1305_sha256;
769
770 /* Ensure OCSP_STATUS is set by setting the connection status_type */
771 conn->status_type = S2N_STATUS_REQUEST_OCSP;
772
773 /* Verify that tls1.2 DOES set the flags allowed by tls1.2 */
774 conn->actual_protocol_version = S2N_TLS12;
775 EXPECT_SUCCESS(s2n_conn_set_handshake_type(conn));
776 EXPECT_TRUE(conn->handshake.handshake_type & TLS12_PERFECT_FORWARD_SECRECY);
777 EXPECT_TRUE(conn->handshake.handshake_type & OCSP_STATUS);
778 EXPECT_TRUE(conn->handshake.handshake_type & WITH_SESSION_TICKET);
779 EXPECT_TRUE(conn->handshake.handshake_type & CLIENT_AUTH);
780
781 /* Reset which state machine we're on */
782 EXPECT_OK(s2n_handshake_type_reset(conn));
783 conn->handshake.state_machine = S2N_STATE_MACHINE_INITIAL;
784
785 /* Verify that tls1.3 ONLY sets the flags allowed by tls1.3 */
786 conn->actual_protocol_version = S2N_TLS13;
787 EXPECT_OK(s2n_conn_choose_state_machine(conn, S2N_TLS13));
788 EXPECT_SUCCESS(s2n_conn_set_handshake_type(conn));
789 EXPECT_EQUAL(conn->handshake.handshake_type, NEGOTIATED | FULL_HANDSHAKE | CLIENT_AUTH | MIDDLEBOX_COMPAT);
790
791 EXPECT_SUCCESS(s2n_connection_free(conn));
792 };
793
794 /* Test: s2n_conn_set_handshake_type only allows HELLO_RETRY_REQUEST with TLS1.3 */
795 {
796 struct s2n_connection *conn = s2n_connection_new(S2N_CLIENT);
797
798 /* HELLO_RETRY_REQUEST allowed with tls1.3 */
799 conn->actual_protocol_version = S2N_TLS13;
800 EXPECT_OK(s2n_conn_choose_state_machine(conn, S2N_TLS13));
801 conn->handshake.handshake_type = INITIAL | HELLO_RETRY_REQUEST;
802 EXPECT_SUCCESS(s2n_conn_set_handshake_type(conn));
803 EXPECT_TRUE(conn->handshake.handshake_type & HELLO_RETRY_REQUEST);
804
805 /* Reset state machine */
806 conn->handshake.state_machine = S2N_STATE_MACHINE_INITIAL;
807
808 /* HELLO_RETRY_REQUEST not allowed with tls1.2 */
809 conn->actual_protocol_version = S2N_TLS12;
810 EXPECT_OK(s2n_conn_choose_state_machine(conn, S2N_TLS12));
811 conn->handshake.handshake_type = INITIAL | HELLO_RETRY_REQUEST;
812 EXPECT_SUCCESS(s2n_conn_set_handshake_type(conn));
813 EXPECT_FALSE(conn->handshake.handshake_type & HELLO_RETRY_REQUEST);
814
815 EXPECT_SUCCESS(s2n_connection_free(conn));
816 };
817
818 /* Test: s2n_conn_set_tls13_handshake_type does not set FULL_HANDSHAKE if
819 * a pre-shared key has been chosen. */
820 {
821 struct s2n_connection *conn = s2n_connection_new(S2N_CLIENT);
822 struct s2n_psk *psk = NULL;
823 conn->actual_protocol_version = S2N_TLS13;
824 EXPECT_OK(s2n_conn_choose_state_machine(conn, S2N_TLS13));
825 EXPECT_OK(s2n_array_pushback(&conn->psk_params.psk_list, (void **) &psk));
826
827 conn->psk_params.chosen_psk = psk;
828 EXPECT_NOT_NULL(conn->psk_params.chosen_psk);
829 EXPECT_OK(s2n_conn_set_tls13_handshake_type(conn));
830 EXPECT_FALSE(conn->handshake.handshake_type & FULL_HANDSHAKE);
831
832 conn->psk_params.chosen_psk = NULL;
833 EXPECT_OK(s2n_conn_set_tls13_handshake_type(conn));
834 EXPECT_TRUE(conn->handshake.handshake_type & FULL_HANDSHAKE);
835
836 EXPECT_SUCCESS(s2n_connection_free(conn));
837 };
838
839 /* Test: s2n_conn_set_tls13_handshake_type ignores client auth type if a pre-shared key is
840 * chosen and s2n is a client. */
841 {
842 struct s2n_connection *client_conn = s2n_connection_new(S2N_CLIENT);
843
844 struct s2n_psk *psk = NULL;
845 EXPECT_OK(s2n_array_pushback(&client_conn->psk_params.psk_list, (void **) &psk));
846 client_conn->psk_params.chosen_psk = psk;
847 EXPECT_NOT_NULL(client_conn->psk_params.chosen_psk);
848
849 EXPECT_SUCCESS(s2n_connection_set_client_auth_type(client_conn, S2N_CERT_AUTH_REQUIRED));
850
851 EXPECT_OK(s2n_conn_set_tls13_handshake_type(client_conn));
852 EXPECT_FALSE(client_conn->handshake.handshake_type & CLIENT_AUTH);
853 EXPECT_FALSE(client_conn->handshake.handshake_type & FULL_HANDSHAKE);
854
855 EXPECT_SUCCESS(s2n_connection_free(client_conn));
856 };
857
858 /* Test: s2n_conn_set_tls13_handshake_type ignores client auth type if a pre-shared key is
859 * chosen and s2n is a server. */
860 {
861 struct s2n_connection *server_conn = s2n_connection_new(S2N_SERVER);
862 struct s2n_psk *psk = NULL;
863
864 EXPECT_OK(s2n_array_pushback(&server_conn->psk_params.psk_list, (void **) &psk));
865 server_conn->psk_params.chosen_psk = psk;
866 EXPECT_NOT_NULL(server_conn->psk_params.chosen_psk);
867
868 EXPECT_SUCCESS(s2n_connection_set_client_auth_type(server_conn, S2N_CERT_AUTH_REQUIRED));
869
870 EXPECT_OK(s2n_conn_set_tls13_handshake_type(server_conn));
871 EXPECT_FALSE(server_conn->handshake.handshake_type & CLIENT_AUTH);
872 EXPECT_FALSE(server_conn->handshake.handshake_type & FULL_HANDSHAKE);
873
874 EXPECT_SUCCESS(s2n_connection_free(server_conn));
875 };
876
877 /* Test: s2n_conn_set_tls13_handshake_type sets WITH_EARLY_DATA */
878 {
879 struct s2n_connection *server_conn = s2n_connection_new(S2N_SERVER);
880 server_conn->actual_protocol_version = S2N_TLS13;
881
882 server_conn->early_data_state = S2N_EARLY_DATA_ACCEPTED;
883 EXPECT_OK(s2n_conn_set_tls13_handshake_type(server_conn));
884 EXPECT_TRUE(server_conn->handshake.handshake_type & WITH_EARLY_DATA);
885 EXPECT_TRUE(server_conn->handshake.handshake_type & NEGOTIATED);
886
887 EXPECT_SUCCESS(s2n_connection_free(server_conn));
888 };
889
890 /* Test: s2n_conn_set_tls13_handshake_type does not set WITH_EARLY_DATA if wrong state */
891 {
892 struct s2n_connection *server_conn = s2n_connection_new(S2N_SERVER);
893 server_conn->actual_protocol_version = S2N_TLS13;
894
895 server_conn->early_data_state = S2N_EARLY_DATA_REJECTED;
896 EXPECT_OK(s2n_conn_set_tls13_handshake_type(server_conn));
897 EXPECT_FALSE(server_conn->handshake.handshake_type & WITH_EARLY_DATA);
898 EXPECT_TRUE(server_conn->handshake.handshake_type & NEGOTIATED);
899
900 EXPECT_SUCCESS(s2n_connection_free(server_conn));
901 };
902
903 /* Test: TLS1.3 handshake type name maximum size is set correctly.
904 * The maximum size is the size of a name with all flags set. */
905 {
906 size_t correct_size = 0;
907 for (size_t i = 0; i < s2n_array_len(tls13_handshake_type_names); i++) {
908 correct_size += strlen(tls13_handshake_type_names[i]);
909 }
910 if (correct_size > MAX_HANDSHAKE_TYPE_LEN) {
911 fprintf(stderr, "\nMAX_HANDSHAKE_TYPE_LEN should be at least %lu\n", (unsigned long) correct_size);
912 FAIL_MSG("MAX_HANDSHAKE_TYPE_LEN wrong for TLS1.3 handshakes");
913 }
914 };
915
916 /* Test: TLS 1.3 handshake types are all properly printed */
917 {
918 struct s2n_connection *conn = s2n_connection_new(S2N_SERVER);
919 conn->actual_protocol_version = S2N_TLS13;
920
921 conn->handshake.handshake_type = INITIAL;
922 EXPECT_STRING_EQUAL("INITIAL", s2n_connection_get_handshake_type_name(conn));
923
924 conn->handshake.handshake_type = NEGOTIATED | FULL_HANDSHAKE;
925 EXPECT_STRING_EQUAL("NEGOTIATED|FULL_HANDSHAKE", s2n_connection_get_handshake_type_name(conn));
926
927 conn->handshake.handshake_type = NEGOTIATED | FULL_HANDSHAKE | HELLO_RETRY_REQUEST;
928 EXPECT_STRING_EQUAL("NEGOTIATED|FULL_HANDSHAKE|HELLO_RETRY_REQUEST", s2n_connection_get_handshake_type_name(conn));
929
930 const char *all_flags_handshake_type_name = "NEGOTIATED|FULL_HANDSHAKE|CLIENT_AUTH|NO_CLIENT_CERT"
931 "|MIDDLEBOX_COMPAT|WITH_EARLY_DATA|EARLY_CLIENT_CCS";
932 conn->handshake.handshake_type = NEGOTIATED | FULL_HANDSHAKE | CLIENT_AUTH | NO_CLIENT_CERT
933 | MIDDLEBOX_COMPAT | WITH_EARLY_DATA | EARLY_CLIENT_CCS;
934 EXPECT_STRING_EQUAL(all_flags_handshake_type_name, s2n_connection_get_handshake_type_name(conn));
935
936 const char *handshake_type_name = NULL;
937 for (int i = 0; i < valid_tls13_handshakes_size; i++) {
938 conn->handshake.handshake_type = valid_tls13_handshakes[i];
939
940 handshake_type_name = s2n_connection_get_handshake_type_name(conn);
941
942 /* The handshake type names must be unique */
943 for (int j = 0; j < valid_tls13_handshakes_size; j++) {
944 conn->handshake.handshake_type = valid_tls13_handshakes[j];
945 if (i == j) {
946 EXPECT_STRING_EQUAL(handshake_type_name, s2n_connection_get_handshake_type_name(conn));
947 } else {
948 EXPECT_STRING_NOT_EQUAL(handshake_type_name, s2n_connection_get_handshake_type_name(conn));
949 }
950 }
951 }
952
953 EXPECT_SUCCESS(s2n_connection_free(conn));
954 };
955
956 /* Test: TLS 1.3 message types are all properly printed */
957 {
958 uint32_t test_handshake_type = NEGOTIATED | FULL_HANDSHAKE | MIDDLEBOX_COMPAT;
959 const char *expected[] = { "CLIENT_HELLO", "SERVER_HELLO", "SERVER_CHANGE_CIPHER_SPEC",
960 "ENCRYPTED_EXTENSIONS", "SERVER_CERT", "SERVER_CERT_VERIFY", "SERVER_FINISHED",
961 "CLIENT_CHANGE_CIPHER_SPEC", "CLIENT_FINISHED", "APPLICATION_DATA" };
962
963 struct s2n_connection *conn = s2n_connection_new(S2N_SERVER);
964 conn->actual_protocol_version = S2N_TLS13;
965 EXPECT_OK(s2n_conn_choose_state_machine(conn, S2N_TLS13));
966
967 conn->handshake.handshake_type = test_handshake_type;
968
969 for (int i = 0; i < s2n_array_len(expected); i++) {
970 conn->handshake.message_number = i;
971 EXPECT_STRING_EQUAL(expected[i], s2n_connection_get_last_message_name(conn));
972 }
973
974 EXPECT_SUCCESS(s2n_connection_free(conn));
975 };
976
977 /* Test: TLS 1.3 message types are all properly printed for client auth */
978 {
979 uint32_t test_handshake_type = NEGOTIATED | FULL_HANDSHAKE | CLIENT_AUTH;
980 const char *expected[] = { "CLIENT_HELLO",
981 "SERVER_HELLO", "ENCRYPTED_EXTENSIONS", "SERVER_CERT_REQ", "SERVER_CERT", "SERVER_CERT_VERIFY", "SERVER_FINISHED",
982 "CLIENT_CERT", "CLIENT_CERT_VERIFY", "CLIENT_FINISHED",
983 "APPLICATION_DATA" };
984
985 struct s2n_connection *conn = s2n_connection_new(S2N_SERVER);
986 conn->actual_protocol_version = S2N_TLS13;
987 EXPECT_OK(s2n_conn_choose_state_machine(conn, S2N_TLS13));
988
989 conn->handshake.handshake_type = test_handshake_type;
990
991 for (int i = 0; i < s2n_array_len(expected); i++) {
992 conn->handshake.message_number = i;
993 EXPECT_STRING_EQUAL(expected[i], s2n_connection_get_last_message_name(conn));
994 }
995
996 EXPECT_SUCCESS(s2n_connection_free(conn));
997 };
998
999 /* Test: Make sure not to miss out populating any message names */
1000 {
1001 for (int i = CLIENT_HELLO; i <= APPLICATION_DATA; i++) {
1002 EXPECT_NOT_NULL(message_names[i]);
1003 }
1004 };
1005
1006 END_TEST();
1007 }