-
Notifications
You must be signed in to change notification settings - Fork 725
/
Copy paths2n_fragmentation_coalescing_test.c
644 lines (525 loc) · 22.3 KB
/
s2n_fragmentation_coalescing_test.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/
#include <stdint.h>
#include <stdlib.h>
#include <sys/wait.h>
#include <unistd.h>
#include "api/s2n.h"
#include "s2n_test.h"
#include "tls/s2n_connection.h"
#include "tls/s2n_handshake.h"
/*
* The TLS protocol allows messages to be fragmented, interleaved and coalesced into 'records'. These
* tests check that fragmented messages are recombined, that several messages in the same record work
* and that messages interleaved with alerts (including a fragmented alert message) all work.
*
* To do this we fork() subprocesses that write records to a pipe, s2n is configured to read fragments
* from the pipe.
*/
#define TLS_ALERT 21
#define TLS_HANDSHAKE 22
#define TLS_HEARTBEAT 24
#define ZERO_TO_THIRTY_ONE 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, \
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F
uint8_t zero_to_thirty_one[] = { ZERO_TO_THIRTY_ONE };
uint8_t server_hello_message[] = { /* SERVER HELLO */
0x02,
/* Length */
0x00, 0x00, 0x46,
/* Protocol version */
0x03, 0x03,
/* Server random */
ZERO_TO_THIRTY_ONE,
/* SessionID len - 32 bytes */
0x20,
/* Session ID */
ZERO_TO_THIRTY_ONE,
/* Cipher suite - TLS_RSA_WITH_AES_256_CBC_SHA256 */
0x00, 0x3D,
/* Compression method: none */
0x00
};
uint8_t server_cert[] = { /* SERVER CERT */
0x0B,
/* Length of the handshake message */
0x00, 0x03, 0x38,
/* Length of all certificates */
0x00, 0x03, 0x35,
/* Length of the first cert */
0x00, 0x03, 0x32,
/* Certificate data - via openssl x509 -in cert.pem -outform DER | xxd -i */
0x30, 0x82, 0x03, 0x2e, 0x30, 0x82, 0x02, 0x16, 0x02, 0x09, 0x00, 0xcb,
0xd6, 0x5a, 0xfa, 0x37, 0xcf, 0xe0, 0xbf, 0x30, 0x0d, 0x06, 0x09, 0x2a,
0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x05, 0x05, 0x00, 0x30, 0x59,
0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x41,
0x55, 0x31, 0x13, 0x30, 0x11, 0x06, 0x03, 0x55, 0x04, 0x08, 0x13, 0x0a,
0x53, 0x6f, 0x6d, 0x65, 0x2d, 0x53, 0x74, 0x61, 0x74, 0x65, 0x31, 0x21,
0x30, 0x1f, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x13, 0x18, 0x49, 0x6e, 0x74,
0x65, 0x72, 0x6e, 0x65, 0x74, 0x20, 0x57, 0x69, 0x64, 0x67, 0x69, 0x74,
0x73, 0x20, 0x50, 0x74, 0x79, 0x20, 0x4c, 0x74, 0x64, 0x31, 0x12, 0x30,
0x10, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x09, 0x6c, 0x6f, 0x63, 0x61,
0x6c, 0x68, 0x6f, 0x73, 0x74, 0x30, 0x1e, 0x17, 0x0d, 0x31, 0x34, 0x30,
0x35, 0x31, 0x30, 0x31, 0x37, 0x30, 0x38, 0x32, 0x33, 0x5a, 0x17, 0x0d,
0x32, 0x34, 0x30, 0x35, 0x30, 0x37, 0x31, 0x37, 0x30, 0x38, 0x32, 0x33,
0x5a, 0x30, 0x59, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06,
0x13, 0x02, 0x41, 0x55, 0x31, 0x13, 0x30, 0x11, 0x06, 0x03, 0x55, 0x04,
0x08, 0x13, 0x0a, 0x53, 0x6f, 0x6d, 0x65, 0x2d, 0x53, 0x74, 0x61, 0x74,
0x65, 0x31, 0x21, 0x30, 0x1f, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x13, 0x18,
0x49, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x20, 0x57, 0x69, 0x64,
0x67, 0x69, 0x74, 0x73, 0x20, 0x50, 0x74, 0x79, 0x20, 0x4c, 0x74, 0x64,
0x31, 0x12, 0x30, 0x10, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x09, 0x6c,
0x6f, 0x63, 0x61, 0x6c, 0x68, 0x6f, 0x73, 0x74, 0x30, 0x82, 0x01, 0x22,
0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01,
0x01, 0x05, 0x00, 0x03, 0x82, 0x01, 0x0f, 0x00, 0x30, 0x82, 0x01, 0x0a,
0x02, 0x82, 0x01, 0x01, 0x00, 0xc8, 0x96, 0xd6, 0x94, 0x98, 0x78, 0x3e,
0x1b, 0xb2, 0x1d, 0x6b, 0x65, 0xc2, 0xb4, 0x44, 0x31, 0xd5, 0x87, 0x96,
0x0d, 0x7e, 0x35, 0x53, 0x6c, 0xc1, 0x29, 0xb6, 0x34, 0x95, 0x3f, 0x9a,
0xb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, 0x5c, 0x8a, 0xdb, 0xbe, 0xb6, 0xc2, 0xc4, 0xe0, 0x4e, 0xe5, 0x21,
0x1c, 0x06, 0x89, 0xe3, 0x9e, 0xba, 0xd1, 0xe5, 0xf9, 0xef, 0xe7, 0xbc,
0x22, 0xf6, 0x8c, 0xef, 0x13, 0x84, 0x7c, 0x13, 0xc3, 0x29, 0x8b, 0x54,
0xd1, 0xad, 0xbc, 0x66, 0xe8, 0x6f, 0x4a, 0xbd, 0x9a, 0x90, 0x9b, 0x46,
0x0b, 0x07, 0x2c, 0xd8, 0x9e, 0xab, 0xb3, 0xa2, 0x3e, 0xad, 0x5f, 0x38,
0x52, 0x4b, 0x43, 0xc4, 0x50, 0xbd, 0x2d, 0x47, 0xb3, 0x06, 0x8f, 0x03,
0xf4, 0x59, 0x0c, 0x3c, 0xba, 0x0f, 0x28, 0xa3, 0x47, 0xd5, 0xd5, 0xd1,
0xe8, 0xb3, 0xbc, 0x18, 0xe9, 0x2a, 0x59, 0x4a, 0xe1, 0x3c, 0x81, 0x26,
0x7f, 0x2f, 0x4a, 0x61, 0xeb, 0x37, 0xab, 0x66, 0x57, 0xea, 0xcb, 0xe4,
0xe2, 0xbc, 0x01, 0xb6, 0x89, 0xa6, 0x1d, 0x1b, 0xf7, 0xd2, 0x43, 0xf1,
0x9e, 0x75, 0x35, 0x61, 0x7b, 0x79, 0xd9, 0x18, 0xbe, 0x5d, 0xcc, 0xce,
0xc0, 0x4b
};
uint8_t heartbeat_message[] = {
0x01, 0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10
};
uint8_t warning_alert[] = { /* warning: user cancelled */
0x01, 0x5a
};
uint8_t fatal_alert[] = { /* Fatal: unexpected message */
0x02, 0x0a
};
void fragmented_message(int write_fd)
{
int written = 0;
/* Split the hello message into 5 fragments and write it */
for (int i = 0; i < 5; i++) {
int length = sizeof(server_hello_message) / 5;
if (i == 0) {
length += sizeof(server_hello_message) % 5;
}
uint8_t record_header[5] = { TLS_HANDSHAKE, 0x03, 0x03, (length >> 8), length & 0xff };
if (write(write_fd, record_header, 5) != 5) {
_exit(100);
}
if (write(write_fd, server_hello_message + written, length) != length) {
_exit(100);
}
written += length;
}
/* Close the pipe and exit */
close(write_fd);
}
void coalesced_message(int write_fd)
{
int length = sizeof(server_hello_message) + sizeof(server_cert);
uint8_t record_header[5] = { TLS_HANDSHAKE, 0x03, 0x03, (length >> 8), length & 0xff };
if (write(write_fd, record_header, 5) != 5) {
_exit(100);
}
if (write(write_fd, server_hello_message, sizeof(server_hello_message)) != sizeof(server_hello_message)) {
_exit(100);
}
if (write(write_fd, server_cert, sizeof(server_cert)) != sizeof(server_cert)) {
_exit(100);
}
close(write_fd);
}
void interleaved_message(int write_fd)
{
int length = sizeof(server_hello_message) / 2;
uint8_t record_header[5] = { TLS_HANDSHAKE, 0x03, 0x03, (length >> 8), length & 0xff };
int written = 0;
/* Write half of the message */
if (write(write_fd, record_header, 5) != 5) {
_exit(100);
}
if (write(write_fd, server_hello_message, length) != length) {
_exit(100);
}
written += length;
/* Write the heartbeat record */
record_header[0] = TLS_HEARTBEAT;
record_header[3] = sizeof(heartbeat_message) >> 8;
record_header[4] = sizeof(heartbeat_message) & 0xff;
if (write(write_fd, record_header, 5) != 5) {
_exit(100);
}
if (write(write_fd, heartbeat_message, sizeof(heartbeat_message)) != sizeof(heartbeat_message)) {
_exit(100);
}
/* Write the rest of the hello message */
length = sizeof(server_hello_message) - written;
record_header[0] = TLS_HANDSHAKE;
record_header[3] = length >> 8;
record_header[4] = length & 0xff;
if (write(write_fd, record_header, 5) != 5) {
_exit(100);
}
if (write(write_fd, server_hello_message + written, length) != length) {
_exit(100);
}
/* Close the pipe and exit */
close(write_fd);
}
void interleaved_fragmented_fatal_alert(int write_fd)
{
int length = sizeof(server_hello_message) / 2;
uint8_t record_header[5] = { TLS_HANDSHAKE, 0x03, 0x03, (length >> 8), length & 0xff };
int written = 0;
/* Write half of the message */
if (write(write_fd, record_header, 5) != 5) {
_exit(100);
}
if (write(write_fd, server_hello_message, length) != length) {
_exit(100);
}
written += length;
/* Write half of the alert message */
record_header[0] = TLS_ALERT;
record_header[3] = 0;
record_header[4] = 1;
if (write(write_fd, record_header, 5) != 5) {
_exit(100);
}
if (write(write_fd, fatal_alert, 1) != 1) {
_exit(100);
}
/* Write another quarter of the of the hello message */
length = sizeof(server_hello_message) / 4;
record_header[0] = TLS_HANDSHAKE;
record_header[3] = length >> 8;
record_header[4] = length & 0xff;
if (write(write_fd, record_header, 5) != 5) {
_exit(100);
}
if (write(write_fd, server_hello_message + written, length) != length) {
_exit(100);
}
written += length;
/* Write second half of the alert message */
record_header[0] = TLS_ALERT;
record_header[3] = 0;
record_header[4] = 1;
if (write(write_fd, record_header, 5) != 5) {
_exit(100);
}
if (write(write_fd, fatal_alert + 1, 1) != 1) {
_exit(100);
}
/* Write the rest of the hello message */
length = sizeof(server_hello_message) - written;
record_header[0] = TLS_HANDSHAKE;
record_header[3] = length >> 8;
record_header[4] = length & 0xff;
if (write(write_fd, record_header, 5) != 5) {
_exit(100);
}
if (write(write_fd, server_hello_message + written, length) != length) {
_exit(100);
}
/* Close the pipe and exit */
close(write_fd);
}
void interleaved_fragmented_warning_alert(int write_fd)
{
int length = sizeof(server_hello_message) / 2;
uint8_t record_header[5] = { TLS_HANDSHAKE, 0x03, 0x03, (length >> 8), length & 0xff };
int written = 0;
/* Write half of the message */
if (write(write_fd, record_header, 5) != 5) {
_exit(100);
}
if (write(write_fd, server_hello_message, length) != length) {
_exit(100);
}
written += length;
/* Write half of the alert message */
record_header[0] = TLS_ALERT;
record_header[3] = 0;
record_header[4] = 1;
if (write(write_fd, warning_alert, 1) != 1) {
_exit(100);
}
/* Write another quarter of the of the hello message */
length = sizeof(server_hello_message) / 4;
record_header[0] = TLS_HANDSHAKE;
record_header[3] = length >> 8;
record_header[4] = length & 0xff;
if (write(write_fd, record_header, 5) != 5) {
_exit(100);
}
if (write(write_fd, server_hello_message + written, length) != length) {
_exit(100);
}
written += length;
/* Write second half of the alert message */
record_header[0] = TLS_ALERT;
record_header[3] = 0;
record_header[4] = 1;
if (write(write_fd, record_header, 5) != 5) {
_exit(100);
}
if (write(write_fd, warning_alert + 1, 1) != 1) {
_exit(100);
}
/* Write the rest of the hello message */
length = sizeof(server_hello_message) - written;
record_header[0] = TLS_HANDSHAKE;
record_header[3] = length >> 8;
record_header[4] = length & 0xff;
if (write(write_fd, record_header, 5) != 5) {
_exit(100);
}
if (write(write_fd, server_hello_message + written, length) != length) {
_exit(100);
}
/* Close the pipe and exit */
close(write_fd);
}
int main(int argc, char **argv)
{
struct s2n_connection *conn = NULL;
struct s2n_config *config = NULL;
s2n_blocked_status blocked;
int status = 0;
pid_t pid = 0;
int p[2];
BEGIN_TEST();
EXPECT_SUCCESS(s2n_disable_tls13_in_test());
EXPECT_NOT_NULL(config = s2n_config_new());
EXPECT_SUCCESS(s2n_config_disable_x509_verification(config));
EXPECT_SUCCESS(s2n_config_set_check_stapled_ocsp_response(config, 0));
/* The server hello has TLS_RSA_WITH_AES_256_CBC_SHA256 hardcoded,
so we need to set a cipher preference that will accept that value */
EXPECT_SUCCESS(s2n_config_set_cipher_preferences(config, "20170328"));
EXPECT_NOT_NULL(conn = s2n_connection_new(S2N_CLIENT));
EXPECT_SUCCESS(s2n_connection_set_config(conn, config));
conn->server_protocol_version = S2N_TLS12;
conn->client_protocol_version = S2N_TLS12;
conn->actual_protocol_version = S2N_TLS12;
/* Create a pipe */
EXPECT_SUCCESS(pipe(p));
/* Set up the connection to read from the fd */
EXPECT_SUCCESS(s2n_connection_set_read_fd(conn, p[0]));
/* Pretend the client hello has already been set */
conn->handshake.handshake_type = NEGOTIATED | FULL_HANDSHAKE;
conn->handshake.message_number = SERVER_HELLO;
/* Create a child process */
pid = fork();
if (pid == 0) {
/* This is the child process, close the read end of the pipe */
EXPECT_SUCCESS(close(p[0]));
/* Write the fragmented hello message */
fragmented_message(p[1]);
EXPECT_SUCCESS(s2n_config_free(config));
EXPECT_SUCCESS(s2n_connection_free(conn));
exit(0);
}
/* This is the parent process, close the write end of the pipe */
EXPECT_SUCCESS(close(p[1]));
/* Negotiate the handshake. This will fail due to EOF, but that's ok. */
EXPECT_FAILURE(s2n_negotiate(conn, &blocked));
/* Verify that the data is as we expect it */
EXPECT_EQUAL(memcmp(conn->handshake_params.server_random, zero_to_thirty_one, 32), 0);
/* Check that the server hello message was processed */
EXPECT_EQUAL(s2n_conn_get_current_message_type(conn), SERVER_CERT);
/* Clean up */
EXPECT_EQUAL(waitpid(pid, &status, 0), pid);
EXPECT_EQUAL(status, 0);
EXPECT_SUCCESS(close(p[0]));
/* Create a pipe */
EXPECT_SUCCESS(pipe(p));
/* Wipe the connection */
EXPECT_SUCCESS(s2n_connection_wipe(conn));
conn->server_protocol_version = S2N_TLS12;
conn->client_protocol_version = S2N_TLS12;
conn->actual_protocol_version = S2N_TLS12;
/* Set up the connection to read from the fd */
EXPECT_SUCCESS(s2n_connection_set_read_fd(conn, p[0]));
/* Pretend the client hello has already been set */
conn->handshake.handshake_type = NEGOTIATED | FULL_HANDSHAKE;
conn->handshake.message_number = SERVER_HELLO;
/* Create a child process */
pid = fork();
if (pid == 0) {
/* This is the child process, close the read end of the pipe */
EXPECT_SUCCESS(close(p[0]));
/* Write the fragmented hello message */
coalesced_message(p[1]);
EXPECT_SUCCESS(s2n_connection_free(conn));
EXPECT_SUCCESS(s2n_config_free(config));
exit(0);
}
/* This is the parent process, close the write end of the pipe */
EXPECT_SUCCESS(close(p[1]));
/* Negotiate the handshake. This will fail due to EOF, but that's ok. */
EXPECT_FAILURE(s2n_negotiate(conn, &blocked));
/* Verify that the data is as we expect it */
EXPECT_EQUAL(memcmp(conn->handshake_params.server_random, zero_to_thirty_one, 32), 0);
/* Check that the server done message was processed */
EXPECT_EQUAL(s2n_conn_get_current_message_type(conn), SERVER_HELLO_DONE);
/* Clean up */
EXPECT_EQUAL(waitpid(pid, &status, 0), pid);
EXPECT_EQUAL(status, 0);
EXPECT_SUCCESS(close(p[0]));
/* Create a pipe */
EXPECT_SUCCESS(pipe(p));
/* Wipe the connection */
EXPECT_SUCCESS(s2n_connection_wipe(conn));
conn->server_protocol_version = S2N_TLS12;
conn->client_protocol_version = S2N_TLS12;
conn->actual_protocol_version = S2N_TLS12;
/* Set up the connection to read from the fd */
EXPECT_SUCCESS(s2n_connection_set_read_fd(conn, p[0]));
/* Pretend the client hello has already been set */
conn->handshake.handshake_type = NEGOTIATED | FULL_HANDSHAKE;
conn->handshake.message_number = SERVER_HELLO;
/* Create a child process */
pid = fork();
if (pid == 0) {
/* This is the child process, close the read end of the pipe */
EXPECT_SUCCESS(close(p[0]));
/* Write the fragmented hello message */
interleaved_message(p[1]);
EXPECT_SUCCESS(s2n_connection_free(conn));
EXPECT_SUCCESS(s2n_config_free(config));
exit(0);
}
/* This is the parent process, close the write end of the pipe */
EXPECT_SUCCESS(close(p[1]));
/* Negotiate the handshake. This will fail due to EOF, but that's ok. */
EXPECT_FAILURE(s2n_negotiate(conn, &blocked));
/* Verify that the data is as we expect it */
EXPECT_EQUAL(memcmp(conn->handshake_params.server_random, zero_to_thirty_one, 32), 0);
/* Check that the server hello message was processed */
EXPECT_EQUAL(s2n_conn_get_current_message_type(conn), SERVER_CERT);
/* Clean up */
EXPECT_EQUAL(waitpid(pid, &status, 0), pid);
EXPECT_EQUAL(status, 0);
EXPECT_SUCCESS(close(p[0]));
/* Create a pipe */
EXPECT_SUCCESS(pipe(p));
/* Wipe the connection */
EXPECT_SUCCESS(s2n_connection_wipe(conn));
conn->server_protocol_version = S2N_TLS12;
conn->client_protocol_version = S2N_TLS12;
conn->actual_protocol_version = S2N_TLS12;
/* Set up the connection to read from the fd */
EXPECT_SUCCESS(s2n_connection_set_read_fd(conn, p[0]));
/* Pretend the client hello has already been set */
conn->handshake.handshake_type = NEGOTIATED | FULL_HANDSHAKE;
conn->handshake.message_number = SERVER_HELLO;
/* Create a child process */
pid = fork();
if (pid == 0) {
/* This is the child process, close the read end of the pipe */
EXPECT_SUCCESS(close(p[0]));
/* Write the fragmented hello message */
interleaved_fragmented_warning_alert(p[1]);
EXPECT_SUCCESS(s2n_connection_free(conn));
EXPECT_SUCCESS(s2n_config_free(config));
exit(0);
}
/* This is the parent process, close the write end of the pipe */
EXPECT_SUCCESS(close(p[1]));
/* Negotiate the handshake. This will fail due to EOF, but that's ok. */
EXPECT_FAILURE(s2n_negotiate(conn, &blocked));
/* Verify that the data is as we expect it */
EXPECT_NOT_EQUAL(memcmp(conn->handshake_params.server_random, zero_to_thirty_one, 32), 0);
/* Check that the server hello message was not processed */
EXPECT_EQUAL(s2n_conn_get_current_message_type(conn), SERVER_HELLO);
/* Clean up */
EXPECT_EQUAL(waitpid(pid, &status, 0), pid);
EXPECT_EQUAL(status, 0);
EXPECT_SUCCESS(close(p[0]));
/* Create a pipe */
EXPECT_SUCCESS(pipe(p));
/* Wipe the connection */
EXPECT_SUCCESS(s2n_connection_wipe(conn));
conn->server_protocol_version = S2N_TLS12;
conn->client_protocol_version = S2N_TLS12;
conn->actual_protocol_version = S2N_TLS12;
/* Set up the connection to read from the fd */
EXPECT_SUCCESS(s2n_connection_set_read_fd(conn, p[0]));
/* Pretend the client hello has already been set */
conn->handshake.handshake_type = NEGOTIATED | FULL_HANDSHAKE;
conn->handshake.message_number = SERVER_HELLO;
/* Create a child process */
pid = fork();
if (pid == 0) {
/* This is the child process, close the read end of the pipe */
EXPECT_SUCCESS(close(p[0]));
/* Write the fragmented hello message */
interleaved_fragmented_fatal_alert(p[1]);
EXPECT_SUCCESS(s2n_connection_free(conn));
EXPECT_SUCCESS(s2n_config_free(config));
exit(0);
}
/* This is the parent process, close the write end of the pipe */
EXPECT_SUCCESS(close(p[1]));
/* Negotiate the handshake. This will fail due to EOF, but that's ok. */
EXPECT_FAILURE(s2n_negotiate(conn, &blocked));
/* Verify that the data failed */
EXPECT_NOT_EQUAL(memcmp(conn->handshake_params.server_random, zero_to_thirty_one, 32), 0);
/* Check that the server hello message was not processed */
EXPECT_NOT_EQUAL(s2n_conn_get_current_message_type(conn), SERVER_CERT);
/* Clean up */
EXPECT_EQUAL(waitpid(pid, &status, 0), pid);
EXPECT_EQUAL(status, 0);
EXPECT_SUCCESS(close(p[0]));
EXPECT_SUCCESS(s2n_connection_free(conn));
EXPECT_SUCCESS(s2n_config_free(config));
END_TEST();
}