summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjsing <>2026-04-25 14:36:12 +0000
committerjsing <>2026-04-25 14:36:12 +0000
commitb4ec5423044982c2b2b2b182abe4cb2b99808e57 (patch)
tree46247640eae6b7f08c41cc30384a4e4f3f2b0d19
parent7e7d161332b52626dc0726b3ad604fb2221b29b1 (diff)
downloadopenbsd-b4ec5423044982c2b2b2b182abe4cb2b99808e57.tar.gz
openbsd-b4ec5423044982c2b2b2b182abe4cb2b99808e57.tar.bz2
openbsd-b4ec5423044982c2b2b2b182abe4cb2b99808e57.zip
Add DTLS wire tests.
Add tests that ensure the wire bytes for DTLS are what we expect for both CCS and fragmented handshake messages.
-rw-r--r--src/regress/lib/libssl/dtls/Makefile14
-rw-r--r--src/regress/lib/libssl/dtls/dtls_wire_test.c376
2 files changed, 386 insertions, 4 deletions
diff --git a/src/regress/lib/libssl/dtls/Makefile b/src/regress/lib/libssl/dtls/Makefile
index b58dae61b6..a8d888c882 100644
--- a/src/regress/lib/libssl/dtls/Makefile
+++ b/src/regress/lib/libssl/dtls/Makefile
@@ -1,6 +1,8 @@
1# $OpenBSD: Makefile,v 1.4 2024/03/20 10:38:05 jsing Exp $ 1# $OpenBSD: Makefile,v 1.5 2026/04/25 14:36:12 jsing Exp $
2
3PROGS += dtlstest
4PROGS += dtls_wire_test
2 5
3PROG= dtlstest
4LDADD= ${SSL_INT} -lcrypto 6LDADD= ${SSL_INT} -lcrypto
5DPADD= ${LIBSSL} ${LIBCRYPTO} 7DPADD= ${LIBSSL} ${LIBCRYPTO}
6WARNINGS= Yes 8WARNINGS= Yes
@@ -9,13 +11,17 @@ CFLAGS+= -I${.CURDIR}/../../../../lib/libcrypto/bio
9CFLAGS+= -I${.CURDIR}/../../../../lib/libssl 11CFLAGS+= -I${.CURDIR}/../../../../lib/libssl
10 12
11REGRESS_TARGETS= \ 13REGRESS_TARGETS= \
12 regress-dtlstest 14 regress-dtlstest \
15 regress-dtls_wire_test
13 16
14# XXX(jsing): use CA root and chain 17# XXX(jsing): use CA root and chain
15regress-dtlstest: ${PROG} 18regress-dtlstest: dtlstest
16 ./dtlstest \ 19 ./dtlstest \
17 ${.CURDIR}/../../libssl/certs/server1-rsa.pem \ 20 ${.CURDIR}/../../libssl/certs/server1-rsa.pem \
18 ${.CURDIR}/../../libssl/certs/server1-rsa.pem \ 21 ${.CURDIR}/../../libssl/certs/server1-rsa.pem \
19 ${.CURDIR}/../../libssl/certs/ca-int-rsa.pem 22 ${.CURDIR}/../../libssl/certs/ca-int-rsa.pem
20 23
24regress-dtls_wire_test: dtls_wire_test
25 ./dtls_wire_test
26
21.include <bsd.regress.mk> 27.include <bsd.regress.mk>
diff --git a/src/regress/lib/libssl/dtls/dtls_wire_test.c b/src/regress/lib/libssl/dtls/dtls_wire_test.c
new file mode 100644
index 0000000000..fa9717a3e1
--- /dev/null
+++ b/src/regress/lib/libssl/dtls/dtls_wire_test.c
@@ -0,0 +1,376 @@
1/* $OpenBSD: dtls_wire_test.c,v 1.1 2026/04/25 14:36:12 jsing Exp $ */
2/*
3 * Copyright (c) 2026 Joel Sing <jsing@openbsd.org>
4 *
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 */
17
18#include <stdio.h>
19
20#include <openssl/bio.h>
21#include <openssl/ssl.h>
22
23#include "dtls_local.h"
24#include "ssl_local.h"
25
26static void
27hexdump(const unsigned char *buf, size_t len)
28{
29 size_t i;
30
31 for (i = 1; i <= len; i++)
32 fprintf(stderr, " 0x%02hhx,%s", buf[i - 1], i % 8 ? "" : "\n");
33
34 fprintf(stderr, "\n");
35}
36
37static const uint8_t dtls12_hm_wire_bytes[] = {
38 0x16, 0xfe, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00,
39 0x00, 0x00, 0x00, 0x01, 0xf3, 0x16, 0x00, 0x04,
40 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
41 0xe7, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
42 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
43 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
44 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
45 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
46 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
47 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
48 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
49 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
50 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
51 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
52 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
53 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
54 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
55 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
56 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
57 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
58 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
59 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
60 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
61 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
62 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
63 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
64 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
65 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
66 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
67 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
68 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
69 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
70 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
71 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
72 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
73 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
74 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
75 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
76 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
77 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
78 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
79 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
80 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
81 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
82 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
83 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
84 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
85 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
86 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
87 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
88 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
89 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
90 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
91 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
92 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
93 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
94 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
95 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
96 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
97 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
98 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
99 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
100 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
101 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
102 0x16, 0xfe, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00,
103 0x00, 0x00, 0x01, 0x01, 0xf3, 0x16, 0x00, 0x04,
104 0x00, 0x00, 0x00, 0x00, 0x01, 0xe7, 0x00, 0x01,
105 0xe7, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
106 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
107 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
108 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
109 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
110 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
111 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
112 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
113 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
114 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
115 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
116 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
117 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
118 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
119 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
120 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
121 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
122 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
123 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
124 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
125 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
126 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
127 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
128 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
129 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
130 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
131 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
132 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
133 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
134 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
135 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
136 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
137 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
138 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
139 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
140 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
141 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
142 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
143 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
144 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
145 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
146 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
147 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
148 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
149 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
150 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
151 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
152 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
153 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
154 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
155 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
156 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
157 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
158 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
159 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
160 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
161 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
162 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
163 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
164 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
165 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
166 0x16, 0xfe, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00,
167 0x00, 0x00, 0x02, 0x00, 0x3e, 0x16, 0x00, 0x04,
168 0x00, 0x00, 0x00, 0x00, 0x03, 0xce, 0x00, 0x00,
169 0x32, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
170 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
171 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
172 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
173 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
174 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
175 0x41, 0x41, 0x41,
176};
177
178static int
179dtls_send_handshake_message_test(void)
180{
181 BIO *rbio = NULL, *wbio = NULL;
182 char *wbuf, rbuf[1];
183 CBB handshake, body;
184 uint8_t *p;
185 SSL_CTX *ssl_ctx = NULL;
186 SSL *ssl = NULL;
187 long len;
188 int failed = 1;
189
190 if ((ssl_ctx = SSL_CTX_new(DTLS_client_method())) == NULL) {
191 fprintf(stderr, "FAIL: failed to create SSL_CTX\n");
192 goto failure;
193 }
194 if ((ssl = SSL_new(ssl_ctx)) == NULL) {
195 fprintf(stderr, "FAIL: failed to create SSL\n");
196 goto failure;
197 }
198
199 if ((rbio = BIO_new_mem_buf(rbuf, sizeof(rbuf))) == NULL) {
200 fprintf(stderr, "FAIL: failed to create rbio\n");
201 goto failure;
202 }
203 if ((wbio = BIO_new(BIO_s_mem())) == NULL) {
204 fprintf(stderr, "FAIL: failed to create wbio\n");
205 goto failure;
206 }
207
208 BIO_up_ref(rbio);
209 BIO_up_ref(wbio);
210 SSL_set_bio(ssl, rbio, wbio);
211
212 if (!ssl3_setup_init_buffer(ssl)) {
213 fprintf(stderr, "FAIL: failed to setup init buffer\n");
214 goto failure;
215 }
216 if (!ssl3_setup_write_buffer(ssl)) {
217 fprintf(stderr, "FAIL: failed to setup write buffer\n");
218 goto failure;
219 }
220 if (!ssl_get_new_session(ssl, 0)) {
221 fprintf(stderr, "FAIL: failed to create session\n");
222 goto failure;
223 }
224 if (!tls1_transcript_init(ssl)) {
225 fprintf(stderr, "FAIL: failed to init transcript\n");
226 goto failure;
227 }
228
229 ssl->s3->hs.cipher = ssl3_get_cipher_by_value(
230 TLS1_CK_ECDHE_RSA_WITH_AES_128_SHA256 & 0xffff);
231
232 ssl->s3->hs.state = SSL3_ST_CW_CLNT_HELLO_B;
233 ssl->d1->mtu = 512;
234
235 if (!ssl3_handshake_msg_start(ssl, &handshake, &body, SSL3_RT_HANDSHAKE)) {
236 fprintf(stderr, "FAIL: failed to start handshake message\n");
237 goto failure;
238 }
239 if (!CBB_add_space(&body, &p, 1024))
240 goto failure;
241 memset(p, 'A', 1024);
242 if (!ssl3_handshake_msg_finish(ssl, &handshake)) {
243 fprintf(stderr, "FAIL: failed to finish handshake message\n");
244 goto failure;
245 }
246
247 ssl3_connect(ssl);
248
249 if (ssl->s3->hs.state != SSL3_ST_CR_SRVR_HELLO_A) {
250 fprintf(stderr, "FAIL: got state 0x%x, want 0x%x\n",
251 ssl->s3->hs.state, SSL3_ST_CR_SRVR_HELLO_A);
252 goto failure;
253 }
254
255 if ((len = BIO_get_mem_data(wbio, &wbuf)) != sizeof(dtls12_hm_wire_bytes)) {
256 fprintf(stderr, "FAIL: got handshake message length = %ld, want %zu\n",
257 len, sizeof(dtls12_hm_wire_bytes));
258 goto failure;
259 }
260 if (memcmp(wbuf, dtls12_hm_wire_bytes, len) != 0) {
261 fprintf(stderr, "FAIL: got handshake message wire bytes:\n");
262 hexdump(wbuf, len);
263 fprintf(stderr, "want handshake message wire bytes:\n");
264 hexdump(dtls12_hm_wire_bytes, len);
265 }
266
267 failed = 0;
268
269 failure:
270 SSL_CTX_free(ssl_ctx);
271 SSL_free(ssl);
272
273 BIO_free(rbio);
274 BIO_free(wbio);
275
276 return failed;
277}
278
279static const uint8_t dtls12_ccs_wire_bytes[] = {
280 0x14, 0xfe, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00,
281 0x00, 0x00, 0x00, 0x00, 0x01, 0x01,
282};
283
284static int
285dtls_send_ccs_test(void)
286{
287 BIO *rbio = NULL, *wbio = NULL;
288 char *wbuf, rbuf[1];
289 SSL_CTX *ssl_ctx = NULL;
290 SSL *ssl = NULL;
291 long len;
292 int failed = 1;
293
294 if ((ssl_ctx = SSL_CTX_new(DTLS_client_method())) == NULL) {
295 fprintf(stderr, "FAIL: failed to create SSL_CTX\n");
296 goto failure;
297 }
298 if ((ssl = SSL_new(ssl_ctx)) == NULL) {
299 fprintf(stderr, "FAIL: failed to create SSL\n");
300 goto failure;
301 }
302
303 if ((rbio = BIO_new_mem_buf(rbuf, sizeof(rbuf))) == NULL) {
304 fprintf(stderr, "FAIL: failed to create rbio\n");
305 goto failure;
306 }
307 if ((wbio = BIO_new(BIO_s_mem())) == NULL) {
308 fprintf(stderr, "FAIL: failed to create wbio\n");
309 goto failure;
310 }
311
312 BIO_up_ref(rbio);
313 BIO_up_ref(wbio);
314 SSL_set_bio(ssl, rbio, wbio);
315
316 if (!ssl3_setup_init_buffer(ssl)) {
317 fprintf(stderr, "FAIL: failed to setup init buffer\n");
318 goto failure;
319 }
320 if (!ssl3_setup_write_buffer(ssl)) {
321 fprintf(stderr, "FAIL: failed to setup write buffer\n");
322 goto failure;
323 }
324 if (!ssl_get_new_session(ssl, 0)) {
325 fprintf(stderr, "FAIL: failed to create session\n");
326 goto failure;
327 }
328
329 ssl->s3->hs.cipher = ssl3_get_cipher_by_value(
330 TLS1_CK_ECDHE_RSA_WITH_AES_128_SHA256 & 0xffff);
331
332 ssl->s3->hs.state = SSL3_ST_CW_CHANGE_A;
333 ssl->d1->mtu = 512;
334
335 ssl3_connect(ssl);
336
337 if (ssl->s3->hs.state != SSL3_ST_CW_FINISHED_A) {
338 fprintf(stderr, "FAIL: got state 0x%x, want 0x%x\n",
339 ssl->s3->hs.state, SSL3_ST_CW_FINISHED_A);
340 goto failure;
341 }
342
343 if ((len = BIO_get_mem_data(wbio, &wbuf)) != sizeof(dtls12_ccs_wire_bytes)) {
344 fprintf(stderr, "FAIL: got CCS length = %ld, want %zu\n", len,
345 sizeof(dtls12_ccs_wire_bytes));
346 goto failure;
347 }
348 if (memcmp(wbuf, dtls12_ccs_wire_bytes, len) != 0) {
349 fprintf(stderr, "FAIL: got CCS wire bytes:\n");
350 hexdump(wbuf, len);
351 fprintf(stderr, "want CCS wire bytes:\n");
352 hexdump(dtls12_ccs_wire_bytes, len);
353 }
354
355 failed = 0;
356
357 failure:
358 SSL_CTX_free(ssl_ctx);
359 SSL_free(ssl);
360
361 BIO_free(rbio);
362 BIO_free(wbio);
363
364 return failed;
365}
366
367int
368main(int argc, char **argv)
369{
370 int failed = 0;
371
372 failed |= dtls_send_handshake_message_test();
373 failed |= dtls_send_ccs_test();
374
375 return failed;
376}