2 * Copyright 2016 The OpenSSL Project Authors. All Rights Reserved.
4 * Licensed under the OpenSSL license (the "License"). You may not use
5 * this file except in compliance with the License. You can obtain a copy
6 * in the file LICENSE in the source distribution or at
7 * https://www.openssl.org/source/license.html
10 #include <openssl/bio.h>
11 #include <openssl/crypto.h>
12 #include <openssl/ssl.h>
13 #include <openssl/err.h>
15 #include "ssltestlib.h"
17 #include "test_main_custom.h"
19 static char *cert
= NULL
;
20 static char *privkey
= NULL
;
25 #define DUMMY_CERT_STATUS_LEN 12
27 static unsigned char certstatus
[] = {
28 SSL3_RT_HANDSHAKE
, /* Content type */
29 0xfe, 0xfd, /* Record version */
31 0, 0, 0, 0, 0, 0x0f, /* Record sequence number */
32 0, DTLS1_HM_HEADER_LENGTH
+ DUMMY_CERT_STATUS_LEN
- 2,
33 SSL3_MT_CERTIFICATE_STATUS
, /* Cert Status handshake message type */
34 0, 0, DUMMY_CERT_STATUS_LEN
, /* Message len */
35 0, 5, /* Message sequence */
36 0, 0, 0, /* Fragment offset */
37 0, 0, DUMMY_CERT_STATUS_LEN
- 2, /* Fragment len */
38 0x80, 0x80, 0x80, 0x80, 0x80,
39 0x80, 0x80, 0x80, 0x80, 0x80 /* Dummy data */
42 #define RECORD_SEQUENCE 10
44 static int test_dtls_unprocessed(int testidx
)
46 SSL_CTX
*sctx
= NULL
, *cctx
= NULL
;
47 SSL
*serverssl1
= NULL
, *clientssl1
= NULL
;
48 BIO
*c_to_s_fbio
, *c_to_s_mempacket
;
51 printf("Starting Test %d\n", testidx
);
53 if (!create_ssl_ctx_pair(DTLS_server_method(), DTLS_client_method(), &sctx
,
54 &cctx
, cert
, privkey
)) {
55 printf("Unable to create SSL_CTX pair\n");
59 if (!SSL_CTX_set_cipher_list(cctx
, "AES128-SHA")) {
60 printf("Failed setting cipher list\n");
63 c_to_s_fbio
= BIO_new(bio_f_tls_dump_filter());
64 if (c_to_s_fbio
== NULL
) {
65 printf("Failed to create filter BIO\n");
69 /* BIO is freed by create_ssl_connection on error */
70 if (!create_ssl_objects(sctx
, cctx
, &serverssl1
, &clientssl1
, NULL
,
72 printf("Unable to create SSL objects\n");
73 ERR_print_errors_fp(stdout
);
78 certstatus
[RECORD_SEQUENCE
] = 0xff;
81 * Inject a dummy record from the next epoch. In test 0, this should never
82 * get used because the message sequence number is too big. In test 1 we set
83 * the record sequence number to be way off in the future. This should not
84 * have an impact on the record replay protection because the record should
85 * be dropped before it is marked as arrived
87 c_to_s_mempacket
= SSL_get_wbio(clientssl1
);
88 c_to_s_mempacket
= BIO_next(c_to_s_mempacket
);
89 mempacket_test_inject(c_to_s_mempacket
, (char *)certstatus
,
90 sizeof(certstatus
), 1, INJECT_PACKET_IGNORE_REC_SEQ
);
92 if (!create_ssl_connection(serverssl1
, clientssl1
, SSL_ERROR_NONE
)) {
93 printf("Unable to create SSL connection\n");
94 ERR_print_errors_fp(stdout
);
100 SSL_free(serverssl1
);
101 SSL_free(clientssl1
);
108 int test_main(int argc
, char *argv
[])
113 printf("Invalid argument count\n");
120 ADD_ALL_TESTS(test_dtls_unprocessed
, NUM_TESTS
);
122 testresult
= run_tests(argv
[0]);
124 bio_f_tls_dump_filter_free();
125 bio_s_mempacket_test_free();