]> git.ipfire.org Git - thirdparty/openssl.git/blob - test/dtlstest.c
Test that swapping the first app data record with Finished msg works
[thirdparty/openssl.git] / test / dtlstest.c
1 /*
2 * Copyright 2016-2021 The OpenSSL Project Authors. All Rights Reserved.
3 *
4 * Licensed under the Apache License 2.0 (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
10 #include <string.h>
11 #include <openssl/bio.h>
12 #include <openssl/crypto.h>
13 #include <openssl/ssl.h>
14 #include <openssl/err.h>
15
16 #include "helpers/ssltestlib.h"
17 #include "testutil.h"
18
19 static char *cert = NULL;
20 static char *privkey = NULL;
21 static unsigned int timer_cb_count;
22
23 #define NUM_TESTS 2
24
25
26 #define DUMMY_CERT_STATUS_LEN 12
27
28 static unsigned char certstatus[] = {
29 SSL3_RT_HANDSHAKE, /* Content type */
30 0xfe, 0xfd, /* Record version */
31 0, 1, /* Epoch */
32 0, 0, 0, 0, 0, 0x0f, /* Record sequence number */
33 0, DTLS1_HM_HEADER_LENGTH + DUMMY_CERT_STATUS_LEN - 2,
34 SSL3_MT_CERTIFICATE_STATUS, /* Cert Status handshake message type */
35 0, 0, DUMMY_CERT_STATUS_LEN, /* Message len */
36 0, 5, /* Message sequence */
37 0, 0, 0, /* Fragment offset */
38 0, 0, DUMMY_CERT_STATUS_LEN - 2, /* Fragment len */
39 0x80, 0x80, 0x80, 0x80, 0x80,
40 0x80, 0x80, 0x80, 0x80, 0x80 /* Dummy data */
41 };
42
43 #define RECORD_SEQUENCE 10
44
45 static unsigned int timer_cb(SSL *s, unsigned int timer_us)
46 {
47 ++timer_cb_count;
48
49 if (timer_us == 0)
50 return 50000;
51 else
52 return 2 * timer_us;
53 }
54
55 static int test_dtls_unprocessed(int testidx)
56 {
57 SSL_CTX *sctx = NULL, *cctx = NULL;
58 SSL *serverssl1 = NULL, *clientssl1 = NULL;
59 BIO *c_to_s_fbio, *c_to_s_mempacket;
60 int testresult = 0;
61
62 timer_cb_count = 0;
63
64 if (!TEST_true(create_ssl_ctx_pair(NULL, DTLS_server_method(),
65 DTLS_client_method(),
66 DTLS1_VERSION, 0,
67 &sctx, &cctx, cert, privkey)))
68 return 0;
69
70 #ifndef OPENSSL_NO_DTLS1_2
71 if (!TEST_true(SSL_CTX_set_cipher_list(cctx, "AES128-SHA")))
72 goto end;
73 #else
74 /* Default sigalgs are SHA1 based in <DTLS1.2 which is in security level 0 */
75 if (!TEST_true(SSL_CTX_set_cipher_list(sctx, "AES128-SHA:@SECLEVEL=0"))
76 || !TEST_true(SSL_CTX_set_cipher_list(cctx,
77 "AES128-SHA:@SECLEVEL=0")))
78 goto end;
79 #endif
80
81 c_to_s_fbio = BIO_new(bio_f_tls_dump_filter());
82 if (!TEST_ptr(c_to_s_fbio))
83 goto end;
84
85 /* BIO is freed by create_ssl_connection on error */
86 if (!TEST_true(create_ssl_objects(sctx, cctx, &serverssl1, &clientssl1,
87 NULL, c_to_s_fbio)))
88 goto end;
89
90 DTLS_set_timer_cb(clientssl1, timer_cb);
91
92 if (testidx == 1)
93 certstatus[RECORD_SEQUENCE] = 0xff;
94
95 /*
96 * Inject a dummy record from the next epoch. In test 0, this should never
97 * get used because the message sequence number is too big. In test 1 we set
98 * the record sequence number to be way off in the future.
99 */
100 c_to_s_mempacket = SSL_get_wbio(clientssl1);
101 c_to_s_mempacket = BIO_next(c_to_s_mempacket);
102 mempacket_test_inject(c_to_s_mempacket, (char *)certstatus,
103 sizeof(certstatus), 1, INJECT_PACKET_IGNORE_REC_SEQ);
104
105 /*
106 * Create the connection. We use "create_bare_ssl_connection" here so that
107 * we can force the connection to not do "SSL_read" once partly connected.
108 * We don't want to accidentally read the dummy records we injected because
109 * they will fail to decrypt.
110 */
111 if (!TEST_true(create_bare_ssl_connection(serverssl1, clientssl1,
112 SSL_ERROR_NONE, 0)))
113 goto end;
114
115 if (timer_cb_count == 0) {
116 printf("timer_callback was not called.\n");
117 goto end;
118 }
119
120 testresult = 1;
121 end:
122 SSL_free(serverssl1);
123 SSL_free(clientssl1);
124 SSL_CTX_free(sctx);
125 SSL_CTX_free(cctx);
126
127 return testresult;
128 }
129
130 #define CLI_TO_SRV_EPOCH_0_RECS 3
131 #define CLI_TO_SRV_EPOCH_1_RECS 1
132 #if !defined(OPENSSL_NO_EC) || !defined(OPENSSL_NO_DH)
133 # define SRV_TO_CLI_EPOCH_0_RECS 10
134 #else
135 /*
136 * In this case we have no ServerKeyExchange message, because we don't have
137 * ECDHE or DHE. When it is present it gets fragmented into 3 records in this
138 * test.
139 */
140 # define SRV_TO_CLI_EPOCH_0_RECS 9
141 #endif
142 #define SRV_TO_CLI_EPOCH_1_RECS 1
143 #define TOTAL_FULL_HAND_RECORDS \
144 (CLI_TO_SRV_EPOCH_0_RECS + CLI_TO_SRV_EPOCH_1_RECS + \
145 SRV_TO_CLI_EPOCH_0_RECS + SRV_TO_CLI_EPOCH_1_RECS)
146
147 #define CLI_TO_SRV_RESUME_EPOCH_0_RECS 3
148 #define CLI_TO_SRV_RESUME_EPOCH_1_RECS 1
149 #define SRV_TO_CLI_RESUME_EPOCH_0_RECS 2
150 #define SRV_TO_CLI_RESUME_EPOCH_1_RECS 1
151 #define TOTAL_RESUME_HAND_RECORDS \
152 (CLI_TO_SRV_RESUME_EPOCH_0_RECS + CLI_TO_SRV_RESUME_EPOCH_1_RECS + \
153 SRV_TO_CLI_RESUME_EPOCH_0_RECS + SRV_TO_CLI_RESUME_EPOCH_1_RECS)
154
155 #define TOTAL_RECORDS (TOTAL_FULL_HAND_RECORDS + TOTAL_RESUME_HAND_RECORDS)
156
157 /*
158 * We are assuming a ServerKeyExchange message is sent in this test. If we don't
159 * have either DH or EC, then it won't be
160 */
161 #if !defined(OPENSSL_NO_DH) || !defined(OPENSSL_NO_EC)
162 static int test_dtls_drop_records(int idx)
163 {
164 SSL_CTX *sctx = NULL, *cctx = NULL;
165 SSL *serverssl = NULL, *clientssl = NULL;
166 BIO *c_to_s_fbio, *mempackbio;
167 int testresult = 0;
168 int epoch = 0;
169 SSL_SESSION *sess = NULL;
170 int cli_to_srv_epoch0, cli_to_srv_epoch1, srv_to_cli_epoch0;
171
172 if (!TEST_true(create_ssl_ctx_pair(NULL, DTLS_server_method(),
173 DTLS_client_method(),
174 DTLS1_VERSION, 0,
175 &sctx, &cctx, cert, privkey)))
176 return 0;
177
178 #ifdef OPENSSL_NO_DTLS1_2
179 /* Default sigalgs are SHA1 based in <DTLS1.2 which is in security level 0 */
180 if (!TEST_true(SSL_CTX_set_cipher_list(sctx, "DEFAULT:@SECLEVEL=0"))
181 || !TEST_true(SSL_CTX_set_cipher_list(cctx,
182 "DEFAULT:@SECLEVEL=0")))
183 goto end;
184 #endif
185
186 if (!TEST_true(SSL_CTX_set_dh_auto(sctx, 1)))
187 goto end;
188
189 if (idx >= TOTAL_FULL_HAND_RECORDS) {
190 /* We're going to do a resumption handshake. Get a session first. */
191 if (!TEST_true(create_ssl_objects(sctx, cctx, &serverssl, &clientssl,
192 NULL, NULL))
193 || !TEST_true(create_ssl_connection(serverssl, clientssl,
194 SSL_ERROR_NONE))
195 || !TEST_ptr(sess = SSL_get1_session(clientssl)))
196 goto end;
197
198 SSL_shutdown(clientssl);
199 SSL_shutdown(serverssl);
200 SSL_free(serverssl);
201 SSL_free(clientssl);
202 serverssl = clientssl = NULL;
203
204 cli_to_srv_epoch0 = CLI_TO_SRV_RESUME_EPOCH_0_RECS;
205 cli_to_srv_epoch1 = CLI_TO_SRV_RESUME_EPOCH_1_RECS;
206 srv_to_cli_epoch0 = SRV_TO_CLI_RESUME_EPOCH_0_RECS;
207 idx -= TOTAL_FULL_HAND_RECORDS;
208 } else {
209 cli_to_srv_epoch0 = CLI_TO_SRV_EPOCH_0_RECS;
210 cli_to_srv_epoch1 = CLI_TO_SRV_EPOCH_1_RECS;
211 srv_to_cli_epoch0 = SRV_TO_CLI_EPOCH_0_RECS;
212 }
213
214 c_to_s_fbio = BIO_new(bio_f_tls_dump_filter());
215 if (!TEST_ptr(c_to_s_fbio))
216 goto end;
217
218 /* BIO is freed by create_ssl_connection on error */
219 if (!TEST_true(create_ssl_objects(sctx, cctx, &serverssl, &clientssl,
220 NULL, c_to_s_fbio)))
221 goto end;
222
223 if (sess != NULL) {
224 if (!TEST_true(SSL_set_session(clientssl, sess)))
225 goto end;
226 }
227
228 DTLS_set_timer_cb(clientssl, timer_cb);
229 DTLS_set_timer_cb(serverssl, timer_cb);
230
231 /* Work out which record to drop based on the test number */
232 if (idx >= cli_to_srv_epoch0 + cli_to_srv_epoch1) {
233 mempackbio = SSL_get_wbio(serverssl);
234 idx -= cli_to_srv_epoch0 + cli_to_srv_epoch1;
235 if (idx >= srv_to_cli_epoch0) {
236 epoch = 1;
237 idx -= srv_to_cli_epoch0;
238 }
239 } else {
240 mempackbio = SSL_get_wbio(clientssl);
241 if (idx >= cli_to_srv_epoch0) {
242 epoch = 1;
243 idx -= cli_to_srv_epoch0;
244 }
245 mempackbio = BIO_next(mempackbio);
246 }
247 BIO_ctrl(mempackbio, MEMPACKET_CTRL_SET_DROP_EPOCH, epoch, NULL);
248 BIO_ctrl(mempackbio, MEMPACKET_CTRL_SET_DROP_REC, idx, NULL);
249
250 if (!TEST_true(create_ssl_connection(serverssl, clientssl, SSL_ERROR_NONE)))
251 goto end;
252
253 if (sess != NULL && !TEST_true(SSL_session_reused(clientssl)))
254 goto end;
255
256 /* If the test did what we planned then it should have dropped a record */
257 if (!TEST_int_eq((int)BIO_ctrl(mempackbio, MEMPACKET_CTRL_GET_DROP_REC, 0,
258 NULL), -1))
259 goto end;
260
261 testresult = 1;
262 end:
263 SSL_SESSION_free(sess);
264 SSL_free(serverssl);
265 SSL_free(clientssl);
266 SSL_CTX_free(sctx);
267 SSL_CTX_free(cctx);
268
269 return testresult;
270 }
271 #endif /* !defined(OPENSSL_NO_DH) || !defined(OPENSSL_NO_EC) */
272
273 static const char dummy_cookie[] = "0123456";
274
275 static int generate_cookie_cb(SSL *ssl, unsigned char *cookie,
276 unsigned int *cookie_len)
277 {
278 memcpy(cookie, dummy_cookie, sizeof(dummy_cookie));
279 *cookie_len = sizeof(dummy_cookie);
280 return 1;
281 }
282
283 static int verify_cookie_cb(SSL *ssl, const unsigned char *cookie,
284 unsigned int cookie_len)
285 {
286 return TEST_mem_eq(cookie, cookie_len, dummy_cookie, sizeof(dummy_cookie));
287 }
288
289 static int test_cookie(void)
290 {
291 SSL_CTX *sctx = NULL, *cctx = NULL;
292 SSL *serverssl = NULL, *clientssl = NULL;
293 int testresult = 0;
294
295 if (!TEST_true(create_ssl_ctx_pair(NULL, DTLS_server_method(),
296 DTLS_client_method(),
297 DTLS1_VERSION, 0,
298 &sctx, &cctx, cert, privkey)))
299 return 0;
300
301 SSL_CTX_set_options(sctx, SSL_OP_COOKIE_EXCHANGE);
302 SSL_CTX_set_cookie_generate_cb(sctx, generate_cookie_cb);
303 SSL_CTX_set_cookie_verify_cb(sctx, verify_cookie_cb);
304
305 #ifdef OPENSSL_NO_DTLS1_2
306 /* Default sigalgs are SHA1 based in <DTLS1.2 which is in security level 0 */
307 if (!TEST_true(SSL_CTX_set_cipher_list(sctx, "DEFAULT:@SECLEVEL=0"))
308 || !TEST_true(SSL_CTX_set_cipher_list(cctx,
309 "DEFAULT:@SECLEVEL=0")))
310 goto end;
311 #endif
312
313 if (!TEST_true(create_ssl_objects(sctx, cctx, &serverssl, &clientssl,
314 NULL, NULL))
315 || !TEST_true(create_ssl_connection(serverssl, clientssl,
316 SSL_ERROR_NONE)))
317 goto end;
318
319 testresult = 1;
320 end:
321 SSL_free(serverssl);
322 SSL_free(clientssl);
323 SSL_CTX_free(sctx);
324 SSL_CTX_free(cctx);
325
326 return testresult;
327 }
328
329 static int test_dtls_duplicate_records(void)
330 {
331 SSL_CTX *sctx = NULL, *cctx = NULL;
332 SSL *serverssl = NULL, *clientssl = NULL;
333 int testresult = 0;
334
335 if (!TEST_true(create_ssl_ctx_pair(NULL, DTLS_server_method(),
336 DTLS_client_method(),
337 DTLS1_VERSION, 0,
338 &sctx, &cctx, cert, privkey)))
339 return 0;
340
341 #ifdef OPENSSL_NO_DTLS1_2
342 /* Default sigalgs are SHA1 based in <DTLS1.2 which is in security level 0 */
343 if (!TEST_true(SSL_CTX_set_cipher_list(sctx, "DEFAULT:@SECLEVEL=0"))
344 || !TEST_true(SSL_CTX_set_cipher_list(cctx,
345 "DEFAULT:@SECLEVEL=0")))
346 goto end;
347 #endif
348
349 if (!TEST_true(create_ssl_objects(sctx, cctx, &serverssl, &clientssl,
350 NULL, NULL)))
351 goto end;
352
353 DTLS_set_timer_cb(clientssl, timer_cb);
354 DTLS_set_timer_cb(serverssl, timer_cb);
355
356 BIO_ctrl(SSL_get_wbio(clientssl), MEMPACKET_CTRL_SET_DUPLICATE_REC, 1, NULL);
357 BIO_ctrl(SSL_get_wbio(serverssl), MEMPACKET_CTRL_SET_DUPLICATE_REC, 1, NULL);
358
359 if (!TEST_true(create_ssl_connection(serverssl, clientssl, SSL_ERROR_NONE)))
360 goto end;
361
362 testresult = 1;
363 end:
364 SSL_free(serverssl);
365 SSL_free(clientssl);
366 SSL_CTX_free(sctx);
367 SSL_CTX_free(cctx);
368
369 return testresult;
370 }
371
372 /*
373 * Test just sending a Finished message as the first message. Should fail due
374 * to an unexpected message.
375 */
376 static int test_just_finished(void)
377 {
378 int testresult = 0, ret;
379 SSL_CTX *sctx = NULL;
380 SSL *serverssl = NULL;
381 BIO *rbio = NULL, *wbio = NULL, *sbio = NULL;
382 unsigned char buf[] = {
383 /* Record header */
384 SSL3_RT_HANDSHAKE, /* content type */
385 (DTLS1_2_VERSION >> 8) & 0xff, /* protocol version hi byte */
386 DTLS1_2_VERSION & 0xff, /* protocol version lo byte */
387 0, 0, /* epoch */
388 0, 0, 0, 0, 0, 0, /* record sequence */
389 0, DTLS1_HM_HEADER_LENGTH + SHA_DIGEST_LENGTH, /* record length */
390
391 /* Message header */
392 SSL3_MT_FINISHED, /* message type */
393 0, 0, SHA_DIGEST_LENGTH, /* message length */
394 0, 0, /* message sequence */
395 0, 0, 0, /* fragment offset */
396 0, 0, SHA_DIGEST_LENGTH, /* fragment length */
397
398 /* Message body */
399 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
400 };
401
402
403 if (!TEST_true(create_ssl_ctx_pair(NULL, DTLS_server_method(),
404 NULL, 0, 0,
405 &sctx, NULL, cert, privkey)))
406 return 0;
407
408 #ifdef OPENSSL_NO_DTLS1_2
409 /* DTLSv1 is not allowed at the default security level */
410 if (!TEST_true(SSL_CTX_set_cipher_list(sctx, "DEFAULT:@SECLEVEL=0")))
411 goto end;
412 #endif
413
414 serverssl = SSL_new(sctx);
415 rbio = BIO_new(BIO_s_mem());
416 wbio = BIO_new(BIO_s_mem());
417
418 if (!TEST_ptr(serverssl) || !TEST_ptr(rbio) || !TEST_ptr(wbio))
419 goto end;
420
421 sbio = rbio;
422 SSL_set0_rbio(serverssl, rbio);
423 SSL_set0_wbio(serverssl, wbio);
424 rbio = wbio = NULL;
425 DTLS_set_timer_cb(serverssl, timer_cb);
426
427 if (!TEST_int_eq(BIO_write(sbio, buf, sizeof(buf)), sizeof(buf)))
428 goto end;
429
430 /* We expect the attempt to process the message to fail */
431 if (!TEST_int_le(ret = SSL_accept(serverssl), 0))
432 goto end;
433
434 /* Check that we got the error we were expecting */
435 if (!TEST_int_eq(SSL_get_error(serverssl, ret), SSL_ERROR_SSL))
436 goto end;
437
438 if (!TEST_int_eq(ERR_GET_REASON(ERR_get_error()), SSL_R_UNEXPECTED_MESSAGE))
439 goto end;
440
441 testresult = 1;
442 end:
443 BIO_free(rbio);
444 BIO_free(wbio);
445 SSL_free(serverssl);
446 SSL_CTX_free(sctx);
447
448 return testresult;
449 }
450
451 /*
452 * Test that swapping a record from the next epoch into the current epoch still
453 * works. Libssl should buffer the record until it needs it.
454 */
455 static int test_swap_epoch(void)
456 {
457 SSL_CTX *sctx = NULL, *cctx = NULL;
458 SSL *sssl = NULL, *cssl = NULL;
459 int testresult = 0;
460 BIO *bio;
461
462 if (!TEST_true(create_ssl_ctx_pair(NULL, DTLS_server_method(),
463 DTLS_client_method(),
464 DTLS1_VERSION, 0,
465 &sctx, &cctx, cert, privkey)))
466 return 0;
467
468 #ifndef OPENSSL_NO_DTLS1_2
469 if (!TEST_true(SSL_CTX_set_cipher_list(cctx, "AES128-SHA")))
470 goto end;
471 #else
472 /* Default sigalgs are SHA1 based in <DTLS1.2 which is in security level 0 */
473 if (!TEST_true(SSL_CTX_set_cipher_list(sctx, "AES128-SHA:@SECLEVEL=0"))
474 || !TEST_true(SSL_CTX_set_cipher_list(cctx,
475 "AES128-SHA:@SECLEVEL=0")))
476 goto end;
477 #endif
478
479
480 /* BIO is freed by create_ssl_connection on error */
481 if (!TEST_true(create_ssl_objects(sctx, cctx, &sssl, &cssl,
482 NULL, NULL)))
483 goto end;
484
485 /* Send flight 1: ClientHello */
486 if (!TEST_int_le(SSL_connect(cssl), 0))
487 goto end;
488
489 /* Recv flight 1, send flight 2: ServerHello, Certificate, ServerHelloDone */
490 if (!TEST_int_le(SSL_accept(sssl), 0))
491 goto end;
492
493 /* Recv flight 2, send flight 3: ClientKeyExchange, CCS, Finished */
494 if (!TEST_int_le(SSL_connect(cssl), 0))
495 goto end;
496
497 bio = SSL_get_wbio(cssl);
498 if (!TEST_ptr(bio)
499 || !TEST_true(mempacket_swap_epoch(bio)))
500 goto end;
501
502 /*
503 * Recv flight 3, send flight 4: CCS, Finished.
504 * This should work in a single call because we have all the messages we
505 * need. Even though we had out of order packets, the record for the next
506 * epoch that we read early should be buffered and used later.
507 */
508 if (!TEST_int_gt(SSL_accept(sssl), 0))
509 goto end;
510
511
512 /* Recv flight 4 */
513 if (!TEST_int_gt(SSL_connect(cssl), 0))
514 goto end;
515
516 testresult = 1;
517 end:
518 SSL_free(cssl);
519 SSL_free(sssl);
520 SSL_CTX_free(cctx);
521 SSL_CTX_free(sctx);
522 return testresult;
523 }
524
525 /*
526 * Test that swapping an app data record so that it is received before the
527 * Finished message still works.
528 */
529 static int test_swap_app_data(void)
530 {
531 SSL_CTX *sctx = NULL, *cctx = NULL;
532 SSL *sssl = NULL, *cssl = NULL;
533 int testresult = 0;
534 BIO *bio;
535 char msg[] = { 0x00, 0x01, 0x02, 0x03 };
536 char buf[10];
537
538 if (!TEST_true(create_ssl_ctx_pair(NULL, DTLS_server_method(),
539 DTLS_client_method(),
540 DTLS1_VERSION, 0,
541 &sctx, &cctx, cert, privkey)))
542 return 0;
543
544 #ifndef OPENSSL_NO_DTLS1_2
545 if (!TEST_true(SSL_CTX_set_cipher_list(cctx, "AES128-SHA")))
546 goto end;
547 #else
548 /* Default sigalgs are SHA1 based in <DTLS1.2 which is in security level 0 */
549 if (!TEST_true(SSL_CTX_set_cipher_list(sctx, "AES128-SHA:@SECLEVEL=0"))
550 || !TEST_true(SSL_CTX_set_cipher_list(cctx,
551 "AES128-SHA:@SECLEVEL=0")))
552 goto end;
553 #endif
554
555 if (!TEST_true(create_ssl_objects(sctx, cctx, &sssl, &cssl,
556 NULL, NULL)))
557 goto end;
558
559 /* Send flight 1: ClientHello */
560 if (!TEST_int_le(SSL_connect(cssl), 0))
561 goto end;
562
563 /* Recv flight 1, send flight 2: ServerHello, Certificate, ServerHelloDone */
564 if (!TEST_int_le(SSL_accept(sssl), 0))
565 goto end;
566
567 /* Recv flight 2, send flight 3: ClientKeyExchange, CCS, Finished */
568 if (!TEST_int_le(SSL_connect(cssl), 0))
569 goto end;
570
571 /* Recv flight 3, send flight 4: datagram 1(NST, CCS) datagram 2(Finished) */
572 if (!TEST_int_gt(SSL_accept(sssl), 0))
573 goto end;
574
575 /* Send flight 5: app data */
576 if (!TEST_int_eq(SSL_write(sssl, msg, sizeof(msg)), (int)sizeof(msg)))
577 goto end;
578
579 bio = SSL_get_wbio(sssl);
580 if (!TEST_ptr(bio)
581 || !TEST_true(mempacket_swap_recent(bio)))
582 goto end;
583
584 /*
585 * Recv flight 4 (datagram 1): NST, CCS, + flight 5: app data
586 * + flight 4 (datagram 2): Finished
587 */
588 if (!TEST_int_gt(SSL_connect(cssl), 0))
589 goto end;
590
591 /* The app data should be buffered already */
592 if (!TEST_int_eq(SSL_pending(cssl), (int)sizeof(msg))
593 || !TEST_true(SSL_has_pending(cssl)))
594 goto end;
595
596 /*
597 * Recv flight 5 (app data)
598 * We already buffered this so it should be available.
599 */
600 if (!TEST_int_eq(SSL_read(cssl, buf, sizeof(buf)), (int)sizeof(msg)))
601 goto end;
602
603 testresult = 1;
604 end:
605 SSL_free(cssl);
606 SSL_free(sssl);
607 SSL_CTX_free(cctx);
608 SSL_CTX_free(sctx);
609 return testresult;
610 }
611
612 OPT_TEST_DECLARE_USAGE("certfile privkeyfile\n")
613
614 int setup_tests(void)
615 {
616 if (!test_skip_common_options()) {
617 TEST_error("Error parsing test options\n");
618 return 0;
619 }
620
621 if (!TEST_ptr(cert = test_get_argument(0))
622 || !TEST_ptr(privkey = test_get_argument(1)))
623 return 0;
624
625 ADD_ALL_TESTS(test_dtls_unprocessed, NUM_TESTS);
626 #if !defined(OPENSSL_NO_DH) || !defined(OPENSSL_NO_EC)
627 ADD_ALL_TESTS(test_dtls_drop_records, TOTAL_RECORDS);
628 #endif
629 ADD_TEST(test_cookie);
630 ADD_TEST(test_dtls_duplicate_records);
631 ADD_TEST(test_just_finished);
632 ADD_TEST(test_swap_epoch);
633 ADD_TEST(test_swap_app_data);
634
635 return 1;
636 }
637
638 void cleanup_tests(void)
639 {
640 bio_f_tls_dump_filter_free();
641 bio_s_mempacket_test_free();
642 }