diff options
author | cvs2svn <admin@example.com> | 2025-04-14 17:32:06 +0000 |
---|---|---|
committer | cvs2svn <admin@example.com> | 2025-04-14 17:32:06 +0000 |
commit | eb8dd9dca1228af0cd132f515509051ecfabf6f6 (patch) | |
tree | edb6da6af7e865d488dc1a29309f1e1ec226e603 /src/regress/lib/libssl/tls | |
parent | 247f0352e0ed72a4f476db9dc91f4d982bc83eb2 (diff) | |
download | openbsd-tb_20250414.tar.gz openbsd-tb_20250414.tar.bz2 openbsd-tb_20250414.zip |
This commit was manufactured by cvs2git to create tag 'tb_20250414'.tb_20250414
Diffstat (limited to '')
-rw-r--r-- | src/regress/lib/libssl/tls/Makefile | 18 | ||||
-rw-r--r-- | src/regress/lib/libssl/tls/tlstest.c | 400 | ||||
-rw-r--r-- | src/regress/lib/libssl/tlsext/Makefile | 10 | ||||
-rw-r--r-- | src/regress/lib/libssl/tlsext/tlsexttest.c | 4702 | ||||
-rw-r--r-- | src/regress/lib/libssl/tlsfuzzer/Makefile | 51 | ||||
-rw-r--r-- | src/regress/lib/libssl/tlsfuzzer/tlsfuzzer.py | 935 | ||||
-rw-r--r-- | src/regress/lib/libssl/tlslegacy/Makefile | 9 | ||||
-rw-r--r-- | src/regress/lib/libssl/tlslegacy/tlslegacytest.c | 625 |
8 files changed, 0 insertions, 6750 deletions
diff --git a/src/regress/lib/libssl/tls/Makefile b/src/regress/lib/libssl/tls/Makefile deleted file mode 100644 index 315ac692c3..0000000000 --- a/src/regress/lib/libssl/tls/Makefile +++ /dev/null | |||
@@ -1,18 +0,0 @@ | |||
1 | # $OpenBSD: Makefile,v 1.2 2024/03/20 10:38:05 jsing Exp $ | ||
2 | |||
3 | PROG= tlstest | ||
4 | LDADD= -lssl -lcrypto | ||
5 | DPADD= ${LIBSSL} ${LIBCRYPTO} | ||
6 | WARNINGS= Yes | ||
7 | CFLAGS+= -DLIBRESSL_INTERNAL -Werror | ||
8 | |||
9 | REGRESS_TARGETS= \ | ||
10 | regress-tlstest | ||
11 | |||
12 | regress-tlstest: ${PROG} | ||
13 | ./tlstest \ | ||
14 | ${.CURDIR}/../../libssl/certs/server1-rsa.pem \ | ||
15 | ${.CURDIR}/../../libssl/certs/server1-rsa-chain.pem \ | ||
16 | ${.CURDIR}/../../libssl/certs/ca-root-rsa.pem | ||
17 | |||
18 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libssl/tls/tlstest.c b/src/regress/lib/libssl/tls/tlstest.c deleted file mode 100644 index 8154e7576c..0000000000 --- a/src/regress/lib/libssl/tls/tlstest.c +++ /dev/null | |||
@@ -1,400 +0,0 @@ | |||
1 | /* $OpenBSD: tlstest.c,v 1.2 2023/07/02 17:21:33 beck Exp $ */ | ||
2 | /* | ||
3 | * Copyright (c) 2020, 2021 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 <err.h> | ||
19 | |||
20 | #include <openssl/bio.h> | ||
21 | #include <openssl/err.h> | ||
22 | #include <openssl/ssl.h> | ||
23 | |||
24 | const char *server_ca_file; | ||
25 | const char *server_cert_file; | ||
26 | const char *server_key_file; | ||
27 | |||
28 | int debug = 0; | ||
29 | |||
30 | static void | ||
31 | hexdump(const unsigned char *buf, size_t len) | ||
32 | { | ||
33 | size_t i; | ||
34 | |||
35 | for (i = 1; i <= len; i++) | ||
36 | fprintf(stderr, " 0x%02hhx,%s", buf[i - 1], i % 8 ? "" : "\n"); | ||
37 | |||
38 | if (len % 8) | ||
39 | fprintf(stderr, "\n"); | ||
40 | } | ||
41 | |||
42 | static SSL * | ||
43 | tls_client(BIO *rbio, BIO *wbio) | ||
44 | { | ||
45 | SSL_CTX *ssl_ctx = NULL; | ||
46 | SSL *ssl = NULL; | ||
47 | |||
48 | if ((ssl_ctx = SSL_CTX_new(TLS_method())) == NULL) | ||
49 | errx(1, "client context"); | ||
50 | |||
51 | if ((ssl = SSL_new(ssl_ctx)) == NULL) | ||
52 | errx(1, "client ssl"); | ||
53 | |||
54 | BIO_up_ref(rbio); | ||
55 | BIO_up_ref(wbio); | ||
56 | |||
57 | SSL_set_bio(ssl, rbio, wbio); | ||
58 | |||
59 | SSL_CTX_free(ssl_ctx); | ||
60 | |||
61 | return ssl; | ||
62 | } | ||
63 | |||
64 | static SSL * | ||
65 | tls_server(BIO *rbio, BIO *wbio) | ||
66 | { | ||
67 | SSL_CTX *ssl_ctx = NULL; | ||
68 | SSL *ssl = NULL; | ||
69 | |||
70 | if ((ssl_ctx = SSL_CTX_new(TLS_method())) == NULL) | ||
71 | errx(1, "server context"); | ||
72 | |||
73 | SSL_CTX_set_dh_auto(ssl_ctx, 2); | ||
74 | |||
75 | if (SSL_CTX_use_certificate_file(ssl_ctx, server_cert_file, | ||
76 | SSL_FILETYPE_PEM) != 1) { | ||
77 | fprintf(stderr, "FAIL: Failed to load server certificate"); | ||
78 | goto failure; | ||
79 | } | ||
80 | if (SSL_CTX_use_PrivateKey_file(ssl_ctx, server_key_file, | ||
81 | SSL_FILETYPE_PEM) != 1) { | ||
82 | fprintf(stderr, "FAIL: Failed to load server private key"); | ||
83 | goto failure; | ||
84 | } | ||
85 | |||
86 | if ((ssl = SSL_new(ssl_ctx)) == NULL) | ||
87 | errx(1, "server ssl"); | ||
88 | |||
89 | BIO_up_ref(rbio); | ||
90 | BIO_up_ref(wbio); | ||
91 | |||
92 | SSL_set_bio(ssl, rbio, wbio); | ||
93 | |||
94 | failure: | ||
95 | SSL_CTX_free(ssl_ctx); | ||
96 | |||
97 | return ssl; | ||
98 | } | ||
99 | |||
100 | static int | ||
101 | ssl_error(SSL *ssl, const char *name, const char *desc, int ssl_ret) | ||
102 | { | ||
103 | int ssl_err; | ||
104 | |||
105 | ssl_err = SSL_get_error(ssl, ssl_ret); | ||
106 | |||
107 | if (ssl_err == SSL_ERROR_WANT_READ) { | ||
108 | return 1; | ||
109 | } else if (ssl_err == SSL_ERROR_WANT_WRITE) { | ||
110 | return 1; | ||
111 | } else if (ssl_err == SSL_ERROR_SYSCALL && errno == 0) { | ||
112 | /* Yup, this is apparently a thing... */ | ||
113 | } else { | ||
114 | fprintf(stderr, "FAIL: %s %s failed - ssl err = %d, errno = %d\n", | ||
115 | name, desc, ssl_err, errno); | ||
116 | ERR_print_errors_fp(stderr); | ||
117 | return 0; | ||
118 | } | ||
119 | |||
120 | return 1; | ||
121 | } | ||
122 | |||
123 | static int | ||
124 | do_connect(SSL *ssl, const char *name, int *done) | ||
125 | { | ||
126 | int ssl_ret; | ||
127 | |||
128 | if ((ssl_ret = SSL_connect(ssl)) == 1) { | ||
129 | fprintf(stderr, "INFO: %s connect done\n", name); | ||
130 | *done = 1; | ||
131 | return 1; | ||
132 | } | ||
133 | |||
134 | return ssl_error(ssl, name, "connect", ssl_ret); | ||
135 | } | ||
136 | |||
137 | static int | ||
138 | do_accept(SSL *ssl, const char *name, int *done) | ||
139 | { | ||
140 | int ssl_ret; | ||
141 | |||
142 | if ((ssl_ret = SSL_accept(ssl)) == 1) { | ||
143 | fprintf(stderr, "INFO: %s accept done\n", name); | ||
144 | *done = 1; | ||
145 | return 1; | ||
146 | } | ||
147 | |||
148 | return ssl_error(ssl, name, "accept", ssl_ret); | ||
149 | } | ||
150 | |||
151 | static int | ||
152 | do_read(SSL *ssl, const char *name, int *done) | ||
153 | { | ||
154 | uint8_t buf[512]; | ||
155 | int ssl_ret; | ||
156 | |||
157 | if ((ssl_ret = SSL_read(ssl, buf, sizeof(buf))) > 0) { | ||
158 | fprintf(stderr, "INFO: %s read done\n", name); | ||
159 | if (debug > 1) | ||
160 | hexdump(buf, ssl_ret); | ||
161 | *done = 1; | ||
162 | return 1; | ||
163 | } | ||
164 | |||
165 | return ssl_error(ssl, name, "read", ssl_ret); | ||
166 | } | ||
167 | |||
168 | static int | ||
169 | do_write(SSL *ssl, const char *name, int *done) | ||
170 | { | ||
171 | const uint8_t buf[] = "Hello, World!\n"; | ||
172 | int ssl_ret; | ||
173 | |||
174 | if ((ssl_ret = SSL_write(ssl, buf, sizeof(buf))) > 0) { | ||
175 | fprintf(stderr, "INFO: %s write done\n", name); | ||
176 | *done = 1; | ||
177 | return 1; | ||
178 | } | ||
179 | |||
180 | return ssl_error(ssl, name, "write", ssl_ret); | ||
181 | } | ||
182 | |||
183 | static int | ||
184 | do_shutdown(SSL *ssl, const char *name, int *done) | ||
185 | { | ||
186 | int ssl_ret; | ||
187 | |||
188 | ssl_ret = SSL_shutdown(ssl); | ||
189 | if (ssl_ret == 1) { | ||
190 | fprintf(stderr, "INFO: %s shutdown done\n", name); | ||
191 | *done = 1; | ||
192 | return 1; | ||
193 | } | ||
194 | return ssl_error(ssl, name, "shutdown", ssl_ret); | ||
195 | } | ||
196 | |||
197 | typedef int (*ssl_func)(SSL *ssl, const char *name, int *done); | ||
198 | |||
199 | static int | ||
200 | do_client_server_loop(SSL *client, ssl_func client_func, SSL *server, | ||
201 | ssl_func server_func) | ||
202 | { | ||
203 | int client_done = 0, server_done = 0; | ||
204 | int i = 0; | ||
205 | |||
206 | do { | ||
207 | if (!client_done) { | ||
208 | if (debug) | ||
209 | fprintf(stderr, "DEBUG: client loop\n"); | ||
210 | if (!client_func(client, "client", &client_done)) | ||
211 | return 0; | ||
212 | } | ||
213 | if (!server_done) { | ||
214 | if (debug) | ||
215 | fprintf(stderr, "DEBUG: server loop\n"); | ||
216 | if (!server_func(server, "server", &server_done)) | ||
217 | return 0; | ||
218 | } | ||
219 | } while (i++ < 100 && (!client_done || !server_done)); | ||
220 | |||
221 | if (!client_done || !server_done) | ||
222 | fprintf(stderr, "FAIL: gave up\n"); | ||
223 | |||
224 | return client_done && server_done; | ||
225 | } | ||
226 | |||
227 | struct tls_test { | ||
228 | const unsigned char *desc; | ||
229 | const SSL_METHOD *(*client_method)(void); | ||
230 | uint16_t client_min_version; | ||
231 | uint16_t client_max_version; | ||
232 | const char *client_ciphers; | ||
233 | const SSL_METHOD *(*server_method)(void); | ||
234 | uint16_t server_min_version; | ||
235 | uint16_t server_max_version; | ||
236 | const char *server_ciphers; | ||
237 | }; | ||
238 | |||
239 | static const struct tls_test tls_tests[] = { | ||
240 | { | ||
241 | .desc = "Default client and server", | ||
242 | }, | ||
243 | { | ||
244 | .desc = "Default client and TLSv1.2 server", | ||
245 | .server_max_version = TLS1_2_VERSION, | ||
246 | }, | ||
247 | { | ||
248 | .desc = "Default client and default server with ECDHE KEX", | ||
249 | .server_ciphers = "ECDHE-RSA-AES128-SHA", | ||
250 | }, | ||
251 | { | ||
252 | .desc = "Default client and TLSv1.2 server with ECDHE KEX", | ||
253 | .server_max_version = TLS1_2_VERSION, | ||
254 | .server_ciphers = "ECDHE-RSA-AES128-SHA", | ||
255 | }, | ||
256 | { | ||
257 | .desc = "Default client and default server with DHE KEX", | ||
258 | .server_ciphers = "DHE-RSA-AES128-SHA", | ||
259 | }, | ||
260 | { | ||
261 | .desc = "Default client and TLSv1.2 server with DHE KEX", | ||
262 | .server_max_version = TLS1_2_VERSION, | ||
263 | .server_ciphers = "DHE-RSA-AES128-SHA", | ||
264 | }, | ||
265 | { | ||
266 | .desc = "Default client and default server with RSA KEX", | ||
267 | .server_ciphers = "AES128-SHA", | ||
268 | }, | ||
269 | { | ||
270 | .desc = "Default client and TLSv1.2 server with RSA KEX", | ||
271 | .server_max_version = TLS1_2_VERSION, | ||
272 | .server_ciphers = "AES128-SHA", | ||
273 | }, | ||
274 | { | ||
275 | .desc = "TLSv1.2 client and default server", | ||
276 | .client_max_version = TLS1_2_VERSION, | ||
277 | }, | ||
278 | { | ||
279 | .desc = "TLSv1.2 client and default server with ECDHE KEX", | ||
280 | .client_max_version = TLS1_2_VERSION, | ||
281 | .client_ciphers = "ECDHE-RSA-AES128-SHA", | ||
282 | }, | ||
283 | { | ||
284 | .desc = "TLSv1.2 client and default server with DHE KEX", | ||
285 | .server_max_version = TLS1_2_VERSION, | ||
286 | .client_ciphers = "DHE-RSA-AES128-SHA", | ||
287 | }, | ||
288 | { | ||
289 | .desc = "TLSv1.2 client and default server with RSA KEX", | ||
290 | .client_max_version = TLS1_2_VERSION, | ||
291 | .client_ciphers = "AES128-SHA", | ||
292 | }, | ||
293 | }; | ||
294 | |||
295 | #define N_TLS_TESTS (sizeof(tls_tests) / sizeof(*tls_tests)) | ||
296 | |||
297 | static int | ||
298 | tlstest(const struct tls_test *tt) | ||
299 | { | ||
300 | BIO *client_wbio = NULL, *server_wbio = NULL; | ||
301 | SSL *client = NULL, *server = NULL; | ||
302 | int failed = 1; | ||
303 | |||
304 | fprintf(stderr, "\n== Testing %s... ==\n", tt->desc); | ||
305 | |||
306 | if ((client_wbio = BIO_new(BIO_s_mem())) == NULL) | ||
307 | goto failure; | ||
308 | if (BIO_set_mem_eof_return(client_wbio, -1) <= 0) | ||
309 | goto failure; | ||
310 | |||
311 | if ((server_wbio = BIO_new(BIO_s_mem())) == NULL) | ||
312 | goto failure; | ||
313 | if (BIO_set_mem_eof_return(server_wbio, -1) <= 0) | ||
314 | goto failure; | ||
315 | |||
316 | if ((client = tls_client(server_wbio, client_wbio)) == NULL) | ||
317 | goto failure; | ||
318 | if (tt->client_min_version != 0) { | ||
319 | if (!SSL_set_min_proto_version(client, tt->client_min_version)) | ||
320 | goto failure; | ||
321 | } | ||
322 | if (tt->client_max_version != 0) { | ||
323 | if (!SSL_set_max_proto_version(client, tt->client_max_version)) | ||
324 | goto failure; | ||
325 | } | ||
326 | if (tt->client_ciphers != NULL) { | ||
327 | if (!SSL_set_cipher_list(client, tt->client_ciphers)) | ||
328 | goto failure; | ||
329 | } | ||
330 | |||
331 | if ((server = tls_server(client_wbio, server_wbio)) == NULL) | ||
332 | goto failure; | ||
333 | if (tt->server_min_version != 0) { | ||
334 | if (!SSL_set_min_proto_version(server, tt->server_min_version)) | ||
335 | goto failure; | ||
336 | } | ||
337 | if (tt->server_max_version != 0) { | ||
338 | if (!SSL_set_max_proto_version(server, tt->server_max_version)) | ||
339 | goto failure; | ||
340 | } | ||
341 | if (tt->server_ciphers != NULL) { | ||
342 | if (!SSL_set_cipher_list(server, tt->server_ciphers)) | ||
343 | goto failure; | ||
344 | } | ||
345 | |||
346 | if (!do_client_server_loop(client, do_connect, server, do_accept)) { | ||
347 | fprintf(stderr, "FAIL: client and server handshake failed\n"); | ||
348 | goto failure; | ||
349 | } | ||
350 | |||
351 | if (!do_client_server_loop(client, do_write, server, do_read)) { | ||
352 | fprintf(stderr, "FAIL: client write and server read I/O failed\n"); | ||
353 | goto failure; | ||
354 | } | ||
355 | |||
356 | if (!do_client_server_loop(client, do_read, server, do_write)) { | ||
357 | fprintf(stderr, "FAIL: client read and server write I/O failed\n"); | ||
358 | goto failure; | ||
359 | } | ||
360 | |||
361 | if (!do_client_server_loop(client, do_shutdown, server, do_shutdown)) { | ||
362 | fprintf(stderr, "FAIL: client and server shutdown failed\n"); | ||
363 | goto failure; | ||
364 | } | ||
365 | |||
366 | fprintf(stderr, "INFO: Done!\n"); | ||
367 | |||
368 | failed = 0; | ||
369 | |||
370 | failure: | ||
371 | BIO_free(client_wbio); | ||
372 | BIO_free(server_wbio); | ||
373 | |||
374 | SSL_free(client); | ||
375 | SSL_free(server); | ||
376 | |||
377 | return failed; | ||
378 | } | ||
379 | |||
380 | int | ||
381 | main(int argc, char **argv) | ||
382 | { | ||
383 | int failed = 0; | ||
384 | size_t i; | ||
385 | |||
386 | if (argc != 4) { | ||
387 | fprintf(stderr, "usage: %s keyfile certfile cafile\n", | ||
388 | argv[0]); | ||
389 | exit(1); | ||
390 | } | ||
391 | |||
392 | server_key_file = argv[1]; | ||
393 | server_cert_file = argv[2]; | ||
394 | server_ca_file = argv[3]; | ||
395 | |||
396 | for (i = 0; i < N_TLS_TESTS; i++) | ||
397 | failed |= tlstest(&tls_tests[i]); | ||
398 | |||
399 | return failed; | ||
400 | } | ||
diff --git a/src/regress/lib/libssl/tlsext/Makefile b/src/regress/lib/libssl/tlsext/Makefile deleted file mode 100644 index 9ff441697f..0000000000 --- a/src/regress/lib/libssl/tlsext/Makefile +++ /dev/null | |||
@@ -1,10 +0,0 @@ | |||
1 | # $OpenBSD: Makefile,v 1.2 2022/06/29 15:06:18 tb Exp $ | ||
2 | |||
3 | PROG= tlsexttest | ||
4 | LDADD= ${SSL_INT} -lcrypto | ||
5 | DPADD= ${LIBCRYPTO} ${LIBSSL} | ||
6 | WARNINGS= Yes | ||
7 | CFLAGS+= -DLIBRESSL_INTERNAL -Wundef -Werror | ||
8 | CFLAGS+= -I${.CURDIR}/../../../../lib/libssl | ||
9 | |||
10 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libssl/tlsext/tlsexttest.c b/src/regress/lib/libssl/tlsext/tlsexttest.c deleted file mode 100644 index 4adf27421d..0000000000 --- a/src/regress/lib/libssl/tlsext/tlsexttest.c +++ /dev/null | |||
@@ -1,4702 +0,0 @@ | |||
1 | /* $OpenBSD: tlsexttest.c,v 1.92 2024/09/11 15:04:16 tb Exp $ */ | ||
2 | /* | ||
3 | * Copyright (c) 2017 Joel Sing <jsing@openbsd.org> | ||
4 | * Copyright (c) 2017 Doug Hogan <doug@openbsd.org> | ||
5 | * Copyright (c) 2019 Bob Beck <beck@openbsd.org> | ||
6 | * Copyright (c) 2022 Theo Buehler <tb@openbsd.org> | ||
7 | * | ||
8 | * Permission to use, copy, modify, and distribute this software for any | ||
9 | * purpose with or without fee is hereby granted, provided that the above | ||
10 | * copyright notice and this permission notice appear in all copies. | ||
11 | * | ||
12 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
13 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
14 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
15 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
16 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
17 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
18 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
19 | */ | ||
20 | |||
21 | #include <err.h> | ||
22 | |||
23 | #include <openssl/tls1.h> | ||
24 | |||
25 | #include "ssl_local.h" | ||
26 | |||
27 | #include "bytestring.h" | ||
28 | #include "ssl_tlsext.h" | ||
29 | |||
30 | struct tls_extension_funcs { | ||
31 | int (*needs)(SSL *s, uint16_t msg_type); | ||
32 | int (*build)(SSL *s, uint16_t msg_type, CBB *cbb); | ||
33 | int (*process)(SSL *s, uint16_t msg_type, CBS *cbs, int *alert); | ||
34 | }; | ||
35 | |||
36 | uint16_t tls_extension_type(const struct tls_extension *); | ||
37 | const struct tls_extension *tls_extension_find(uint16_t, size_t *); | ||
38 | const struct tls_extension_funcs *tlsext_funcs(const struct tls_extension *, | ||
39 | int); | ||
40 | int tlsext_linearize_build_order(SSL *); | ||
41 | |||
42 | static int | ||
43 | tls_extension_funcs(int type, const struct tls_extension_funcs **client_funcs, | ||
44 | const struct tls_extension_funcs **server_funcs) | ||
45 | { | ||
46 | const struct tls_extension *ext; | ||
47 | size_t idx; | ||
48 | |||
49 | if ((ext = tls_extension_find(type, &idx)) == NULL) | ||
50 | return 0; | ||
51 | |||
52 | if ((*client_funcs = tlsext_funcs(ext, 0)) == NULL) | ||
53 | return 0; | ||
54 | |||
55 | if ((*server_funcs = tlsext_funcs(ext, 1)) == NULL) | ||
56 | return 0; | ||
57 | |||
58 | return 1; | ||
59 | } | ||
60 | |||
61 | static void | ||
62 | hexdump(const unsigned char *buf, size_t len) | ||
63 | { | ||
64 | size_t i; | ||
65 | |||
66 | for (i = 1; i <= len; i++) | ||
67 | fprintf(stderr, " 0x%02hhx,%s", buf[i - 1], i % 8 ? "" : "\n"); | ||
68 | |||
69 | fprintf(stderr, "\n"); | ||
70 | } | ||
71 | |||
72 | static void | ||
73 | hexdump2(const uint16_t *buf, size_t len) | ||
74 | { | ||
75 | size_t i; | ||
76 | |||
77 | for (i = 1; i <= len / 2; i++) | ||
78 | fprintf(stderr, " 0x%04hx,%s", buf[i - 1], i % 8 ? "" : "\n"); | ||
79 | |||
80 | fprintf(stderr, "\n"); | ||
81 | } | ||
82 | |||
83 | static void | ||
84 | compare_data(const uint8_t *recv, size_t recv_len, const uint8_t *expect, | ||
85 | size_t expect_len) | ||
86 | { | ||
87 | fprintf(stderr, "received:\n"); | ||
88 | hexdump(recv, recv_len); | ||
89 | |||
90 | fprintf(stderr, "test data:\n"); | ||
91 | hexdump(expect, expect_len); | ||
92 | } | ||
93 | |||
94 | static void | ||
95 | compare_data2(const uint16_t *recv, size_t recv_len, const uint16_t *expect, | ||
96 | size_t expect_len) | ||
97 | { | ||
98 | fprintf(stderr, "received:\n"); | ||
99 | hexdump2(recv, recv_len); | ||
100 | |||
101 | fprintf(stderr, "test data:\n"); | ||
102 | hexdump2(expect, expect_len); | ||
103 | } | ||
104 | |||
105 | #define FAIL(msg, ...) \ | ||
106 | do { \ | ||
107 | fprintf(stderr, "[%s:%d] FAIL: ", __FILE__, __LINE__); \ | ||
108 | fprintf(stderr, msg, ##__VA_ARGS__); \ | ||
109 | } while(0) | ||
110 | |||
111 | /* | ||
112 | * Supported Application-Layer Protocol Negotiation - RFC 7301 | ||
113 | * | ||
114 | * There are already extensive unit tests for this so this just | ||
115 | * tests the state info. | ||
116 | */ | ||
117 | |||
118 | const uint8_t tlsext_alpn_multiple_protos_val[] = { | ||
119 | /* opaque ProtocolName<1..2^8-1> -- 'http/1.1' */ | ||
120 | 0x08, /* len */ | ||
121 | 0x68, 0x74, 0x74, 0x70, 0x2f, 0x31, 0x2e, 0x31, | ||
122 | /* opaque ProtocolName<1..2^8-1> -- 'stun.nat' */ | ||
123 | 0x09, /* len */ | ||
124 | 0x73, 0x74, 0x75, 0x6e, 0x2e, 0x74, 0x75, 0x72, 0x6e | ||
125 | }; | ||
126 | |||
127 | const uint8_t tlsext_alpn_multiple_protos[] = { | ||
128 | /* ProtocolName protocol_name_list<2..2^16-1> -- ALPN names */ | ||
129 | 0x00, 0x13, /* len of all names */ | ||
130 | /* opaque ProtocolName<1..2^8-1> -- 'http/1.1' */ | ||
131 | 0x08, /* len */ | ||
132 | 0x68, 0x74, 0x74, 0x70, 0x2f, 0x31, 0x2e, 0x31, | ||
133 | /* opaque ProtocolName<1..2^8-1> -- 'stun.nat' */ | ||
134 | 0x09, /* len */ | ||
135 | 0x73, 0x74, 0x75, 0x6e, 0x2e, 0x74, 0x75, 0x72, 0x6e | ||
136 | }; | ||
137 | |||
138 | const uint8_t tlsext_alpn_single_proto_val[] = { | ||
139 | /* opaque ProtocolName<1..2^8-1> -- 'http/1.1' */ | ||
140 | 0x08, /* len */ | ||
141 | 0x68, 0x74, 0x74, 0x70, 0x2f, 0x31, 0x2e, 0x31 | ||
142 | }; | ||
143 | |||
144 | const uint8_t tlsext_alpn_single_proto_name[] = { | ||
145 | 0x68, 0x74, 0x74, 0x70, 0x2f, 0x31, 0x2e, 0x31 /* 'http/1.1' */ | ||
146 | }; | ||
147 | |||
148 | const uint8_t tlsext_alpn_single_proto[] = { | ||
149 | /* ProtocolName protocol_name_list<2..2^16-1> -- ALPN names */ | ||
150 | 0x00, 0x09, /* len of all names */ | ||
151 | /* opaque ProtocolName<1..2^8-1> -- 'http/1.1' */ | ||
152 | 0x08, /* len */ | ||
153 | 0x68, 0x74, 0x74, 0x70, 0x2f, 0x31, 0x2e, 0x31 | ||
154 | }; | ||
155 | |||
156 | #define TLSEXT_TYPE_alpn TLSEXT_TYPE_application_layer_protocol_negotiation | ||
157 | |||
158 | static int | ||
159 | test_tlsext_alpn_client(void) | ||
160 | { | ||
161 | SSL_CTX *ssl_ctx = NULL; | ||
162 | SSL *ssl = NULL; | ||
163 | const struct tls_extension_funcs *client_funcs; | ||
164 | const struct tls_extension_funcs *server_funcs; | ||
165 | uint8_t *data = NULL; | ||
166 | CBB cbb; | ||
167 | CBS cbs; | ||
168 | int failure, alert; | ||
169 | size_t dlen; | ||
170 | |||
171 | failure = 1; | ||
172 | |||
173 | if (!CBB_init(&cbb, 0)) | ||
174 | errx(1, "Failed to create CBB"); | ||
175 | |||
176 | if ((ssl_ctx = SSL_CTX_new(TLS_client_method())) == NULL) | ||
177 | errx(1, "failed to create SSL_CTX"); | ||
178 | if ((ssl = SSL_new(ssl_ctx)) == NULL) | ||
179 | errx(1, "failed to create SSL"); | ||
180 | |||
181 | if (!tls_extension_funcs(TLSEXT_TYPE_alpn, &client_funcs, &server_funcs)) | ||
182 | errx(1, "failed to fetch ALPN funcs"); | ||
183 | |||
184 | /* By default, we don't need this */ | ||
185 | if (client_funcs->needs(ssl, SSL_TLSEXT_MSG_CH)) { | ||
186 | FAIL("client should not need ALPN by default\n"); | ||
187 | goto err; | ||
188 | } | ||
189 | |||
190 | /* | ||
191 | * Prereqs: | ||
192 | * 1) Set s->alpn_client_proto_list | ||
193 | * - Using SSL_set_alpn_protos() | ||
194 | * 2) We have not finished or renegotiated. | ||
195 | * - s->s3->tmp.finish_md_len == 0 | ||
196 | */ | ||
197 | if (SSL_set_alpn_protos(ssl, tlsext_alpn_single_proto_val, | ||
198 | sizeof(tlsext_alpn_single_proto_val)) != 0) { | ||
199 | FAIL("should be able to set ALPN to http/1.1\n"); | ||
200 | goto err; | ||
201 | } | ||
202 | if (!client_funcs->needs(ssl, SSL_TLSEXT_MSG_CH)) { | ||
203 | FAIL("client should need ALPN by default\n"); | ||
204 | goto err; | ||
205 | } | ||
206 | |||
207 | /* Make sure we can build the client with a single proto. */ | ||
208 | |||
209 | if (!client_funcs->build(ssl, SSL_TLSEXT_MSG_CH, &cbb)) { | ||
210 | FAIL("client failed to build ALPN\n"); | ||
211 | goto err; | ||
212 | } | ||
213 | if (!CBB_finish(&cbb, &data, &dlen)) | ||
214 | errx(1, "failed to finish CBB"); | ||
215 | |||
216 | if (dlen != sizeof(tlsext_alpn_single_proto)) { | ||
217 | FAIL("got client ALPN with length %zu, " | ||
218 | "want length %zu\n", dlen, | ||
219 | sizeof(tlsext_alpn_single_proto)); | ||
220 | compare_data(data, dlen, tlsext_alpn_single_proto, | ||
221 | sizeof(tlsext_alpn_single_proto)); | ||
222 | goto err; | ||
223 | } | ||
224 | if (memcmp(data, tlsext_alpn_single_proto, dlen) != 0) { | ||
225 | FAIL("client ALPN differs:\n"); | ||
226 | compare_data(data, dlen, tlsext_alpn_single_proto, | ||
227 | sizeof(tlsext_alpn_single_proto)); | ||
228 | goto err; | ||
229 | } | ||
230 | |||
231 | CBB_cleanup(&cbb); | ||
232 | if (!CBB_init(&cbb, 0)) | ||
233 | errx(1, "Failed to create CBB"); | ||
234 | free(data); | ||
235 | data = NULL; | ||
236 | |||
237 | /* Make sure we can parse the single proto. */ | ||
238 | |||
239 | CBS_init(&cbs, tlsext_alpn_single_proto, | ||
240 | sizeof(tlsext_alpn_single_proto)); | ||
241 | if (!server_funcs->process(ssl, SSL_TLSEXT_MSG_CH, &cbs, &alert)) { | ||
242 | FAIL("failed to parse ALPN\n"); | ||
243 | goto err; | ||
244 | } | ||
245 | if (CBS_len(&cbs) != 0) { | ||
246 | FAIL("extension data remaining\n"); | ||
247 | goto err; | ||
248 | } | ||
249 | |||
250 | if (ssl->alpn_client_proto_list_len != | ||
251 | sizeof(tlsext_alpn_single_proto_val)) { | ||
252 | FAIL("got client ALPN with length %zu, " | ||
253 | "want length %zu\n", dlen, | ||
254 | sizeof(tlsext_alpn_single_proto_val)); | ||
255 | compare_data(ssl->alpn_client_proto_list, | ||
256 | ssl->alpn_client_proto_list_len, | ||
257 | tlsext_alpn_single_proto_val, | ||
258 | sizeof(tlsext_alpn_single_proto_val)); | ||
259 | goto err; | ||
260 | } | ||
261 | if (memcmp(ssl->alpn_client_proto_list, | ||
262 | tlsext_alpn_single_proto_val, | ||
263 | sizeof(tlsext_alpn_single_proto_val)) != 0) { | ||
264 | FAIL("client ALPN differs:\n"); | ||
265 | compare_data(data, dlen, tlsext_alpn_single_proto_val, | ||
266 | sizeof(tlsext_alpn_single_proto_val)); | ||
267 | goto err; | ||
268 | } | ||
269 | |||
270 | /* Make sure we can build the clienthello with multiple entries. */ | ||
271 | |||
272 | if (SSL_set_alpn_protos(ssl, tlsext_alpn_multiple_protos_val, | ||
273 | sizeof(tlsext_alpn_multiple_protos_val)) != 0) { | ||
274 | FAIL("should be able to set ALPN to http/1.1\n"); | ||
275 | goto err; | ||
276 | } | ||
277 | if (!client_funcs->needs(ssl, SSL_TLSEXT_MSG_CH)) { | ||
278 | FAIL("client should need ALPN by now\n"); | ||
279 | goto err; | ||
280 | } | ||
281 | |||
282 | if (!client_funcs->build(ssl, SSL_TLSEXT_MSG_CH, &cbb)) { | ||
283 | FAIL("client failed to build ALPN\n"); | ||
284 | goto err; | ||
285 | } | ||
286 | if (!CBB_finish(&cbb, &data, &dlen)) | ||
287 | errx(1, "failed to finish CBB"); | ||
288 | |||
289 | if (dlen != sizeof(tlsext_alpn_multiple_protos)) { | ||
290 | FAIL("got client ALPN with length %zu, " | ||
291 | "want length %zu\n", dlen, | ||
292 | sizeof(tlsext_alpn_multiple_protos)); | ||
293 | compare_data(data, dlen, tlsext_alpn_multiple_protos, | ||
294 | sizeof(tlsext_alpn_multiple_protos)); | ||
295 | goto err; | ||
296 | } | ||
297 | if (memcmp(data, tlsext_alpn_multiple_protos, dlen) != 0) { | ||
298 | FAIL("client ALPN differs:\n"); | ||
299 | compare_data(data, dlen, tlsext_alpn_multiple_protos, | ||
300 | sizeof(tlsext_alpn_multiple_protos)); | ||
301 | goto err; | ||
302 | } | ||
303 | |||
304 | /* Make sure we can parse multiple protos */ | ||
305 | |||
306 | CBS_init(&cbs, tlsext_alpn_multiple_protos, | ||
307 | sizeof(tlsext_alpn_multiple_protos)); | ||
308 | if (!server_funcs->process(ssl, SSL_TLSEXT_MSG_CH, &cbs, &alert)) { | ||
309 | FAIL("failed to parse ALPN\n"); | ||
310 | goto err; | ||
311 | } | ||
312 | if (CBS_len(&cbs) != 0) { | ||
313 | FAIL("extension data remaining\n"); | ||
314 | goto err; | ||
315 | } | ||
316 | |||
317 | if (ssl->alpn_client_proto_list_len != | ||
318 | sizeof(tlsext_alpn_multiple_protos_val)) { | ||
319 | FAIL("got client ALPN with length %zu, " | ||
320 | "want length %zu\n", dlen, | ||
321 | sizeof(tlsext_alpn_multiple_protos_val)); | ||
322 | compare_data(ssl->alpn_client_proto_list, | ||
323 | ssl->alpn_client_proto_list_len, | ||
324 | tlsext_alpn_multiple_protos_val, | ||
325 | sizeof(tlsext_alpn_multiple_protos_val)); | ||
326 | goto err; | ||
327 | } | ||
328 | if (memcmp(ssl->alpn_client_proto_list, | ||
329 | tlsext_alpn_multiple_protos_val, | ||
330 | sizeof(tlsext_alpn_multiple_protos_val)) != 0) { | ||
331 | FAIL("client ALPN differs:\n"); | ||
332 | compare_data(data, dlen, tlsext_alpn_multiple_protos_val, | ||
333 | sizeof(tlsext_alpn_multiple_protos_val)); | ||
334 | goto err; | ||
335 | } | ||
336 | |||
337 | /* Make sure we can remove the list and avoid ALPN */ | ||
338 | |||
339 | free(ssl->alpn_client_proto_list); | ||
340 | ssl->alpn_client_proto_list = NULL; | ||
341 | ssl->alpn_client_proto_list_len = 0; | ||
342 | |||
343 | if (client_funcs->needs(ssl, SSL_TLSEXT_MSG_CH)) { | ||
344 | FAIL("client should need ALPN by default\n"); | ||
345 | goto err; | ||
346 | } | ||
347 | |||
348 | failure = 0; | ||
349 | |||
350 | err: | ||
351 | CBB_cleanup(&cbb); | ||
352 | SSL_CTX_free(ssl_ctx); | ||
353 | SSL_free(ssl); | ||
354 | free(data); | ||
355 | |||
356 | return (failure); | ||
357 | } | ||
358 | |||
359 | static int | ||
360 | test_tlsext_alpn_server(void) | ||
361 | { | ||
362 | SSL_CTX *ssl_ctx = NULL; | ||
363 | SSL *ssl = NULL; | ||
364 | const struct tls_extension_funcs *client_funcs; | ||
365 | const struct tls_extension_funcs *server_funcs; | ||
366 | uint8_t *data = NULL; | ||
367 | CBB cbb; | ||
368 | CBS cbs; | ||
369 | int failure, alert; | ||
370 | size_t dlen; | ||
371 | |||
372 | failure = 1; | ||
373 | |||
374 | if (!CBB_init(&cbb, 0)) | ||
375 | errx(1, "Failed to create CBB"); | ||
376 | |||
377 | if ((ssl_ctx = SSL_CTX_new(TLS_server_method())) == NULL) | ||
378 | errx(1, "failed to create SSL_CTX"); | ||
379 | if ((ssl = SSL_new(ssl_ctx)) == NULL) | ||
380 | errx(1, "failed to create SSL"); | ||
381 | |||
382 | if (!tls_extension_funcs(TLSEXT_TYPE_alpn, &client_funcs, &server_funcs)) | ||
383 | errx(1, "failed to fetch ALPN funcs"); | ||
384 | |||
385 | /* By default, ALPN isn't needed. */ | ||
386 | if (server_funcs->needs(ssl, SSL_TLSEXT_MSG_SH)) { | ||
387 | FAIL("server should not need ALPN by default\n"); | ||
388 | goto err; | ||
389 | } | ||
390 | |||
391 | /* | ||
392 | * The server has a single ALPN selection which is set by | ||
393 | * SSL_CTX_set_alpn_select_cb() and calls SSL_select_next_proto(). | ||
394 | * | ||
395 | * This will be a plain name and separate length. | ||
396 | */ | ||
397 | if ((ssl->s3->alpn_selected = malloc(sizeof(tlsext_alpn_single_proto_name))) == NULL) { | ||
398 | errx(1, "failed to malloc"); | ||
399 | } | ||
400 | memcpy(ssl->s3->alpn_selected, tlsext_alpn_single_proto_name, | ||
401 | sizeof(tlsext_alpn_single_proto_name)); | ||
402 | ssl->s3->alpn_selected_len = sizeof(tlsext_alpn_single_proto_name); | ||
403 | |||
404 | if (!server_funcs->needs(ssl, SSL_TLSEXT_MSG_SH)) { | ||
405 | FAIL("server should need ALPN after a protocol is selected\n"); | ||
406 | goto err; | ||
407 | } | ||
408 | |||
409 | /* Make sure we can build a server with one protocol */ | ||
410 | |||
411 | if (!server_funcs->build(ssl, SSL_TLSEXT_MSG_SH, &cbb)) { | ||
412 | FAIL("server should be able to build a response\n"); | ||
413 | goto err; | ||
414 | } | ||
415 | if (!CBB_finish(&cbb, &data, &dlen)) | ||
416 | errx(1, "failed to finish CBB"); | ||
417 | |||
418 | if (dlen != sizeof(tlsext_alpn_single_proto)) { | ||
419 | FAIL("got client ALPN with length %zu, " | ||
420 | "want length %zu\n", dlen, | ||
421 | sizeof(tlsext_alpn_single_proto)); | ||
422 | compare_data(data, dlen, tlsext_alpn_single_proto, | ||
423 | sizeof(tlsext_alpn_single_proto)); | ||
424 | goto err; | ||
425 | } | ||
426 | if (memcmp(data, tlsext_alpn_single_proto, dlen) != 0) { | ||
427 | FAIL("client ALPN differs:\n"); | ||
428 | compare_data(data, dlen, tlsext_alpn_single_proto, | ||
429 | sizeof(tlsext_alpn_single_proto)); | ||
430 | goto err; | ||
431 | } | ||
432 | |||
433 | CBB_cleanup(&cbb); | ||
434 | if (!CBB_init(&cbb, 0)) | ||
435 | errx(1, "Failed to create CBB"); | ||
436 | free(data); | ||
437 | data = NULL; | ||
438 | |||
439 | /* Make sure we can parse the single proto. */ | ||
440 | |||
441 | CBS_init(&cbs, tlsext_alpn_single_proto, | ||
442 | sizeof(tlsext_alpn_single_proto)); | ||
443 | |||
444 | /* Shouldn't be able to parse without requesting */ | ||
445 | if (client_funcs->process(ssl, SSL_TLSEXT_MSG_SH, &cbs, &alert)) { | ||
446 | FAIL("Should only parse server if we requested it\n"); | ||
447 | goto err; | ||
448 | } | ||
449 | |||
450 | /* Should be able to parse once requested. */ | ||
451 | if (SSL_set_alpn_protos(ssl, tlsext_alpn_single_proto_val, | ||
452 | sizeof(tlsext_alpn_single_proto_val)) != 0) { | ||
453 | FAIL("should be able to set ALPN to http/1.1\n"); | ||
454 | goto err; | ||
455 | } | ||
456 | if (!client_funcs->process(ssl, SSL_TLSEXT_MSG_SH, &cbs, &alert)) { | ||
457 | FAIL("Should be able to parse server when we request it\n"); | ||
458 | goto err; | ||
459 | } | ||
460 | if (CBS_len(&cbs) != 0) { | ||
461 | FAIL("extension data remaining\n"); | ||
462 | goto err; | ||
463 | } | ||
464 | |||
465 | if (ssl->s3->alpn_selected_len != | ||
466 | sizeof(tlsext_alpn_single_proto_name)) { | ||
467 | FAIL("got server ALPN with length %zu, " | ||
468 | "want length %zu\n", dlen, | ||
469 | sizeof(tlsext_alpn_single_proto_name)); | ||
470 | compare_data(ssl->s3->alpn_selected, | ||
471 | ssl->s3->alpn_selected_len, | ||
472 | tlsext_alpn_single_proto_name, | ||
473 | sizeof(tlsext_alpn_single_proto_name)); | ||
474 | goto err; | ||
475 | } | ||
476 | if (memcmp(ssl->s3->alpn_selected, | ||
477 | tlsext_alpn_single_proto_name, | ||
478 | sizeof(tlsext_alpn_single_proto_name)) != 0) { | ||
479 | FAIL("server ALPN differs:\n"); | ||
480 | compare_data(ssl->s3->alpn_selected, | ||
481 | ssl->s3->alpn_selected_len, | ||
482 | tlsext_alpn_single_proto_name, | ||
483 | sizeof(tlsext_alpn_single_proto_name)); | ||
484 | goto err; | ||
485 | } | ||
486 | |||
487 | /* | ||
488 | * We should NOT be able to build a server with multiple | ||
489 | * protocol names. However, the existing code did not check for this | ||
490 | * case because it is passed in as an encoded value. | ||
491 | */ | ||
492 | |||
493 | /* Make sure we can remove the list and avoid ALPN */ | ||
494 | |||
495 | free(ssl->s3->alpn_selected); | ||
496 | ssl->s3->alpn_selected = NULL; | ||
497 | ssl->s3->alpn_selected_len = 0; | ||
498 | |||
499 | if (server_funcs->needs(ssl, SSL_TLSEXT_MSG_SH)) { | ||
500 | FAIL("server should not need ALPN by default\n"); | ||
501 | goto err; | ||
502 | } | ||
503 | |||
504 | failure = 0; | ||
505 | |||
506 | err: | ||
507 | CBB_cleanup(&cbb); | ||
508 | SSL_CTX_free(ssl_ctx); | ||
509 | SSL_free(ssl); | ||
510 | free(data); | ||
511 | |||
512 | return (failure); | ||
513 | |||
514 | } | ||
515 | |||
516 | /* | ||
517 | * Supported Elliptic Curves - RFC 4492 section 5.1.1. | ||
518 | * | ||
519 | * This extension is only used by the client. | ||
520 | */ | ||
521 | |||
522 | static const uint8_t tlsext_supportedgroups_client_default[] = { | ||
523 | 0x00, 0x08, | ||
524 | 0x00, 0x1d, /* X25519 (29) */ | ||
525 | 0x00, 0x17, /* secp256r1 (23) */ | ||
526 | 0x00, 0x18, /* secp384r1 (24) */ | ||
527 | 0x00, 0x19, /* secp521r1 (25) */ | ||
528 | }; | ||
529 | |||
530 | static const uint16_t tlsext_supportedgroups_client_secp384r1_val[] = { | ||
531 | 0x0018 /* tls1_ec_nid2group_id(NID_secp384r1) */ | ||
532 | }; | ||
533 | static const uint8_t tlsext_supportedgroups_client_secp384r1[] = { | ||
534 | 0x00, 0x02, | ||
535 | 0x00, 0x18 /* secp384r1 (24) */ | ||
536 | }; | ||
537 | |||
538 | /* Example from RFC 4492 section 5.1.1 */ | ||
539 | static const uint16_t tlsext_supportedgroups_client_nistp192and224_val[] = { | ||
540 | 0x0013, /* tls1_ec_nid2group_id(NID_X9_62_prime192v1) */ | ||
541 | 0x0015 /* tls1_ec_nid2group_id(NID_secp224r1) */ | ||
542 | }; | ||
543 | static const uint8_t tlsext_supportedgroups_client_nistp192and224[] = { | ||
544 | 0x00, 0x04, | ||
545 | 0x00, 0x13, /* secp192r1 aka NIST P-192 */ | ||
546 | 0x00, 0x15 /* secp224r1 aka NIST P-224 */ | ||
547 | }; | ||
548 | |||
549 | static int | ||
550 | test_tlsext_supportedgroups_client(void) | ||
551 | { | ||
552 | unsigned char *data = NULL; | ||
553 | SSL_CTX *ssl_ctx = NULL; | ||
554 | SSL *ssl = NULL; | ||
555 | const struct tls_extension_funcs *client_funcs; | ||
556 | const struct tls_extension_funcs *server_funcs; | ||
557 | size_t dlen; | ||
558 | int failure, alert; | ||
559 | CBB cbb; | ||
560 | CBS cbs; | ||
561 | |||
562 | failure = 1; | ||
563 | |||
564 | if (!CBB_init(&cbb, 0)) | ||
565 | errx(1, "failed to create CBB"); | ||
566 | |||
567 | if ((ssl_ctx = SSL_CTX_new(TLS_client_method())) == NULL) | ||
568 | errx(1, "failed to create SSL_CTX"); | ||
569 | if ((ssl = SSL_new(ssl_ctx)) == NULL) | ||
570 | errx(1, "failed to create SSL"); | ||
571 | |||
572 | if (!tls_extension_funcs(TLSEXT_TYPE_supported_groups, &client_funcs, | ||
573 | &server_funcs)) | ||
574 | errx(1, "failed to fetch supported groups funcs"); | ||
575 | |||
576 | /* | ||
577 | * Default ciphers include EC so we need it by default. | ||
578 | */ | ||
579 | if (!client_funcs->needs(ssl, SSL_TLSEXT_MSG_CH)) { | ||
580 | FAIL("client should need Ellipticcurves for default " | ||
581 | "ciphers\n"); | ||
582 | goto err; | ||
583 | } | ||
584 | |||
585 | /* | ||
586 | * Exclude cipher suites so we can test not including it. | ||
587 | */ | ||
588 | if (!SSL_set_cipher_list(ssl, "TLSv1.2:!ECDHE:!ECDSA")) { | ||
589 | FAIL("client should be able to set cipher list\n"); | ||
590 | goto err; | ||
591 | } | ||
592 | if (client_funcs->needs(ssl, SSL_TLSEXT_MSG_CH)) { | ||
593 | FAIL("client should not need Ellipticcurves\n"); | ||
594 | goto err; | ||
595 | } | ||
596 | |||
597 | /* | ||
598 | * Use libtls default for the rest of the testing | ||
599 | */ | ||
600 | if (!SSL_set_cipher_list(ssl, "TLSv1.2+AEAD+ECDHE")) { | ||
601 | FAIL("client should be able to set cipher list\n"); | ||
602 | goto err; | ||
603 | } | ||
604 | if (!client_funcs->needs(ssl, SSL_TLSEXT_MSG_CH)) { | ||
605 | FAIL("client should need Ellipticcurves\n"); | ||
606 | goto err; | ||
607 | } | ||
608 | |||
609 | /* | ||
610 | * Test with a session secp384r1. The default is used instead. | ||
611 | */ | ||
612 | if ((ssl->session = SSL_SESSION_new()) == NULL) | ||
613 | errx(1, "failed to create session"); | ||
614 | |||
615 | if ((ssl->session->tlsext_supportedgroups = malloc(sizeof(uint16_t))) | ||
616 | == NULL) { | ||
617 | FAIL("client could not malloc\n"); | ||
618 | goto err; | ||
619 | } | ||
620 | if (!tls1_ec_nid2group_id(NID_secp384r1, | ||
621 | &ssl->session->tlsext_supportedgroups[0])) | ||
622 | goto err; | ||
623 | ssl->session->tlsext_supportedgroups_length = 1; | ||
624 | |||
625 | if (!client_funcs->needs(ssl, SSL_TLSEXT_MSG_CH)) { | ||
626 | FAIL("client should need Ellipticcurves\n"); | ||
627 | goto err; | ||
628 | } | ||
629 | |||
630 | if (!client_funcs->build(ssl, SSL_TLSEXT_MSG_CH, &cbb)) { | ||
631 | FAIL("client failed to build Ellipticcurves\n"); | ||
632 | goto err; | ||
633 | } | ||
634 | |||
635 | if (!CBB_finish(&cbb, &data, &dlen)) | ||
636 | errx(1, "failed to finish CBB"); | ||
637 | |||
638 | if (dlen != sizeof(tlsext_supportedgroups_client_default)) { | ||
639 | FAIL("got client Ellipticcurves with length %zu, " | ||
640 | "want length %zu\n", dlen, | ||
641 | sizeof(tlsext_supportedgroups_client_default)); | ||
642 | compare_data(data, dlen, tlsext_supportedgroups_client_default, | ||
643 | sizeof(tlsext_supportedgroups_client_default)); | ||
644 | goto err; | ||
645 | } | ||
646 | |||
647 | if (memcmp(data, tlsext_supportedgroups_client_default, dlen) != 0) { | ||
648 | FAIL("client Ellipticcurves differs:\n"); | ||
649 | compare_data(data, dlen, tlsext_supportedgroups_client_default, | ||
650 | sizeof(tlsext_supportedgroups_client_default)); | ||
651 | goto err; | ||
652 | } | ||
653 | |||
654 | /* | ||
655 | * Test parsing secp384r1 | ||
656 | */ | ||
657 | CBB_cleanup(&cbb); | ||
658 | if (!CBB_init(&cbb, 0)) | ||
659 | errx(1, "Failed to create CBB"); | ||
660 | free(data); | ||
661 | data = NULL; | ||
662 | |||
663 | SSL_SESSION_free(ssl->session); | ||
664 | if ((ssl->session = SSL_SESSION_new()) == NULL) | ||
665 | errx(1, "failed to create session"); | ||
666 | |||
667 | CBS_init(&cbs, tlsext_supportedgroups_client_secp384r1, | ||
668 | sizeof(tlsext_supportedgroups_client_secp384r1)); | ||
669 | if (!server_funcs->process(ssl, SSL_TLSEXT_MSG_CH, &cbs, &alert)) { | ||
670 | FAIL("failed to parse client Ellipticcurves\n"); | ||
671 | goto err; | ||
672 | } | ||
673 | if (CBS_len(&cbs) != 0) { | ||
674 | FAIL("extension data remaining\n"); | ||
675 | goto err; | ||
676 | } | ||
677 | |||
678 | if (ssl->session->tlsext_supportedgroups_length != | ||
679 | sizeof(tlsext_supportedgroups_client_secp384r1_val) / sizeof(uint16_t)) { | ||
680 | FAIL("no tlsext_ellipticcurves from client " | ||
681 | "Ellipticcurves\n"); | ||
682 | goto err; | ||
683 | } | ||
684 | |||
685 | if (memcmp(ssl->session->tlsext_supportedgroups, | ||
686 | tlsext_supportedgroups_client_secp384r1_val, | ||
687 | sizeof(tlsext_supportedgroups_client_secp384r1_val)) != 0) { | ||
688 | FAIL("client had an incorrect Ellipticcurves " | ||
689 | "entry\n"); | ||
690 | compare_data2(ssl->session->tlsext_supportedgroups, | ||
691 | ssl->session->tlsext_supportedgroups_length * 2, | ||
692 | tlsext_supportedgroups_client_secp384r1_val, | ||
693 | sizeof(tlsext_supportedgroups_client_secp384r1_val)); | ||
694 | goto err; | ||
695 | } | ||
696 | |||
697 | /* | ||
698 | * Use a custom order. | ||
699 | */ | ||
700 | CBB_cleanup(&cbb); | ||
701 | if (!CBB_init(&cbb, 0)) | ||
702 | errx(1, "Failed to create CBB"); | ||
703 | |||
704 | SSL_SESSION_free(ssl->session); | ||
705 | if ((ssl->session = SSL_SESSION_new()) == NULL) | ||
706 | errx(1, "failed to create session"); | ||
707 | |||
708 | if ((ssl->tlsext_supportedgroups = malloc(sizeof(uint16_t) * 2)) == NULL) { | ||
709 | FAIL("client could not malloc\n"); | ||
710 | goto err; | ||
711 | } | ||
712 | if (!tls1_ec_nid2group_id(NID_X9_62_prime192v1, | ||
713 | &ssl->tlsext_supportedgroups[0])) | ||
714 | goto err; | ||
715 | if (!tls1_ec_nid2group_id(NID_secp224r1, | ||
716 | &ssl->tlsext_supportedgroups[1])) | ||
717 | goto err; | ||
718 | ssl->tlsext_supportedgroups_length = 2; | ||
719 | |||
720 | if (!client_funcs->needs(ssl, SSL_TLSEXT_MSG_CH)) { | ||
721 | FAIL("client should need Ellipticcurves\n"); | ||
722 | goto err; | ||
723 | } | ||
724 | |||
725 | if (!client_funcs->build(ssl, SSL_TLSEXT_MSG_CH, &cbb)) { | ||
726 | FAIL("client failed to build Ellipticcurves\n"); | ||
727 | goto err; | ||
728 | } | ||
729 | |||
730 | if (!CBB_finish(&cbb, &data, &dlen)) | ||
731 | errx(1, "failed to finish CBB"); | ||
732 | |||
733 | if (dlen != sizeof(tlsext_supportedgroups_client_nistp192and224)) { | ||
734 | FAIL("got client Ellipticcurves with length %zu, " | ||
735 | "want length %zu\n", dlen, | ||
736 | sizeof(tlsext_supportedgroups_client_nistp192and224)); | ||
737 | fprintf(stderr, "received:\n"); | ||
738 | hexdump(data, dlen); | ||
739 | fprintf(stderr, "test data:\n"); | ||
740 | hexdump(tlsext_supportedgroups_client_nistp192and224, | ||
741 | sizeof(tlsext_supportedgroups_client_nistp192and224)); | ||
742 | goto err; | ||
743 | } | ||
744 | |||
745 | if (memcmp(data, tlsext_supportedgroups_client_nistp192and224, dlen) != 0) { | ||
746 | FAIL("client Ellipticcurves differs:\n"); | ||
747 | fprintf(stderr, "received:\n"); | ||
748 | hexdump(data, dlen); | ||
749 | fprintf(stderr, "test data:\n"); | ||
750 | hexdump(tlsext_supportedgroups_client_nistp192and224, | ||
751 | sizeof(tlsext_supportedgroups_client_nistp192and224)); | ||
752 | goto err; | ||
753 | } | ||
754 | |||
755 | /* | ||
756 | * Parse non-default curves to session. | ||
757 | */ | ||
758 | CBB_cleanup(&cbb); | ||
759 | if (!CBB_init(&cbb, 0)) | ||
760 | errx(1, "Failed to create CBB"); | ||
761 | free(data); | ||
762 | data = NULL; | ||
763 | |||
764 | SSL_SESSION_free(ssl->session); | ||
765 | if ((ssl->session = SSL_SESSION_new()) == NULL) | ||
766 | errx(1, "failed to create session"); | ||
767 | |||
768 | /* Reset back to the default list. */ | ||
769 | free(ssl->tlsext_supportedgroups); | ||
770 | ssl->tlsext_supportedgroups = NULL; | ||
771 | ssl->tlsext_supportedgroups_length = 0; | ||
772 | |||
773 | CBS_init(&cbs, tlsext_supportedgroups_client_nistp192and224, | ||
774 | sizeof(tlsext_supportedgroups_client_nistp192and224)); | ||
775 | if (!server_funcs->process(ssl, SSL_TLSEXT_MSG_CH, &cbs, &alert)) { | ||
776 | FAIL("failed to parse client Ellipticcurves\n"); | ||
777 | goto err; | ||
778 | } | ||
779 | if (CBS_len(&cbs) != 0) { | ||
780 | FAIL("extension data remaining\n"); | ||
781 | goto err; | ||
782 | } | ||
783 | |||
784 | if (ssl->session->tlsext_supportedgroups_length != | ||
785 | sizeof(tlsext_supportedgroups_client_nistp192and224_val) / sizeof(uint16_t)) { | ||
786 | FAIL("no tlsext_ellipticcurves from client Ellipticcurves\n"); | ||
787 | goto err; | ||
788 | } | ||
789 | |||
790 | if (memcmp(ssl->session->tlsext_supportedgroups, | ||
791 | tlsext_supportedgroups_client_nistp192and224_val, | ||
792 | sizeof(tlsext_supportedgroups_client_nistp192and224_val)) != 0) { | ||
793 | FAIL("client had an incorrect Ellipticcurves entry\n"); | ||
794 | compare_data2(ssl->session->tlsext_supportedgroups, | ||
795 | ssl->session->tlsext_supportedgroups_length * 2, | ||
796 | tlsext_supportedgroups_client_nistp192and224_val, | ||
797 | sizeof(tlsext_supportedgroups_client_nistp192and224_val)); | ||
798 | goto err; | ||
799 | } | ||
800 | |||
801 | failure = 0; | ||
802 | |||
803 | err: | ||
804 | CBB_cleanup(&cbb); | ||
805 | SSL_CTX_free(ssl_ctx); | ||
806 | SSL_free(ssl); | ||
807 | free(data); | ||
808 | |||
809 | return (failure); | ||
810 | } | ||
811 | |||
812 | |||
813 | /* elliptic_curves is only used by the client so this doesn't test much. */ | ||
814 | static int | ||
815 | test_tlsext_supportedgroups_server(void) | ||
816 | { | ||
817 | SSL_CTX *ssl_ctx = NULL; | ||
818 | SSL *ssl = NULL; | ||
819 | const struct tls_extension_funcs *client_funcs; | ||
820 | const struct tls_extension_funcs *server_funcs; | ||
821 | int failure; | ||
822 | |||
823 | failure = 1; | ||
824 | |||
825 | if ((ssl_ctx = SSL_CTX_new(TLS_server_method())) == NULL) | ||
826 | errx(1, "failed to create SSL_CTX"); | ||
827 | if ((ssl = SSL_new(ssl_ctx)) == NULL) | ||
828 | errx(1, "failed to create SSL"); | ||
829 | |||
830 | if (!tls_extension_funcs(TLSEXT_TYPE_supported_groups, &client_funcs, | ||
831 | &server_funcs)) | ||
832 | errx(1, "failed to fetch supported groups funcs"); | ||
833 | |||
834 | if (server_funcs->needs(ssl, SSL_TLSEXT_MSG_SH)) { | ||
835 | FAIL("server should not need elliptic_curves\n"); | ||
836 | goto err; | ||
837 | } | ||
838 | |||
839 | if ((ssl->session = SSL_SESSION_new()) == NULL) | ||
840 | errx(1, "failed to create session"); | ||
841 | |||
842 | if (server_funcs->needs(ssl, SSL_TLSEXT_MSG_SH)) { | ||
843 | FAIL("server should not need elliptic_curves\n"); | ||
844 | goto err; | ||
845 | } | ||
846 | |||
847 | failure = 0; | ||
848 | |||
849 | err: | ||
850 | SSL_CTX_free(ssl_ctx); | ||
851 | SSL_free(ssl); | ||
852 | |||
853 | return (failure); | ||
854 | |||
855 | } | ||
856 | |||
857 | /* | ||
858 | * Supported Point Formats - RFC 4492 section 5.1.2. | ||
859 | * | ||
860 | * Examples are from the RFC. Both client and server have the same build and | ||
861 | * parse but the needs differ. | ||
862 | */ | ||
863 | |||
864 | static const uint8_t tlsext_ecpf_hello_uncompressed_val[] = { | ||
865 | TLSEXT_ECPOINTFORMAT_uncompressed | ||
866 | }; | ||
867 | static const uint8_t tlsext_ecpf_hello_uncompressed[] = { | ||
868 | 0x01, | ||
869 | 0x00 /* TLSEXT_ECPOINTFORMAT_uncompressed */ | ||
870 | }; | ||
871 | |||
872 | static const uint8_t tlsext_ecpf_hello_prime[] = { | ||
873 | 0x01, | ||
874 | 0x01 /* TLSEXT_ECPOINTFORMAT_ansiX962_compressed_prime */ | ||
875 | }; | ||
876 | |||
877 | static const uint8_t tlsext_ecpf_hello_prefer_order_val[] = { | ||
878 | TLSEXT_ECPOINTFORMAT_ansiX962_compressed_prime, | ||
879 | TLSEXT_ECPOINTFORMAT_uncompressed, | ||
880 | TLSEXT_ECPOINTFORMAT_ansiX962_compressed_char2 | ||
881 | }; | ||
882 | static const uint8_t tlsext_ecpf_hello_prefer_order[] = { | ||
883 | 0x03, | ||
884 | 0x01, /* TLSEXT_ECPOINTFORMAT_ansiX962_compressed_prime */ | ||
885 | 0x00, /* TLSEXT_ECPOINTFORMAT_uncompressed */ | ||
886 | 0x02 /* TLSEXT_ECPOINTFORMAT_ansiX962_compressed_char2 */ | ||
887 | }; | ||
888 | |||
889 | static int | ||
890 | test_tlsext_ecpf_client(void) | ||
891 | { | ||
892 | uint8_t *data = NULL; | ||
893 | SSL_CTX *ssl_ctx = NULL; | ||
894 | SSL *ssl = NULL; | ||
895 | const struct tls_extension_funcs *client_funcs; | ||
896 | const struct tls_extension_funcs *server_funcs; | ||
897 | size_t dlen; | ||
898 | int failure, alert; | ||
899 | CBB cbb; | ||
900 | CBS cbs; | ||
901 | |||
902 | failure = 1; | ||
903 | |||
904 | if (!CBB_init(&cbb, 0)) | ||
905 | errx(1, "Failed to create CBB"); | ||
906 | |||
907 | if ((ssl_ctx = SSL_CTX_new(TLS_client_method())) == NULL) | ||
908 | errx(1, "failed to create SSL_CTX"); | ||
909 | if ((ssl = SSL_new(ssl_ctx)) == NULL) | ||
910 | errx(1, "failed to create SSL"); | ||
911 | |||
912 | if (!tls_extension_funcs(TLSEXT_TYPE_ec_point_formats, &client_funcs, | ||
913 | &server_funcs)) | ||
914 | errx(1, "failed to fetch ecpf funcs"); | ||
915 | |||
916 | /* | ||
917 | * Default ciphers include EC so we need it by default. | ||
918 | */ | ||
919 | if (!client_funcs->needs(ssl, SSL_TLSEXT_MSG_CH)) { | ||
920 | FAIL("client should need ECPointFormats for default " | ||
921 | "ciphers\n"); | ||
922 | goto err; | ||
923 | } | ||
924 | |||
925 | /* | ||
926 | * Exclude EC cipher suites so we can test not including it. | ||
927 | */ | ||
928 | if (!SSL_set_cipher_list(ssl, "ALL:!ECDHE:!ECDH")) { | ||
929 | FAIL("client should be able to set cipher list\n"); | ||
930 | goto err; | ||
931 | } | ||
932 | if (client_funcs->needs(ssl, SSL_TLSEXT_MSG_CH)) { | ||
933 | FAIL("client should not need ECPointFormats\n"); | ||
934 | goto err; | ||
935 | } | ||
936 | |||
937 | /* | ||
938 | * Use libtls default for the rest of the testing | ||
939 | */ | ||
940 | if (!SSL_set_cipher_list(ssl, "TLSv1.2+AEAD+ECDHE")) { | ||
941 | FAIL("client should be able to set cipher list\n"); | ||
942 | goto err; | ||
943 | } | ||
944 | if (!client_funcs->needs(ssl, SSL_TLSEXT_MSG_CH)) { | ||
945 | FAIL("client should need ECPointFormats\n"); | ||
946 | goto err; | ||
947 | } | ||
948 | |||
949 | /* | ||
950 | * The default ECPointFormats should only have uncompressed | ||
951 | */ | ||
952 | if ((ssl->session = SSL_SESSION_new()) == NULL) | ||
953 | errx(1, "failed to create session"); | ||
954 | |||
955 | if (!client_funcs->build(ssl, SSL_TLSEXT_MSG_CH, &cbb)) { | ||
956 | FAIL("client failed to build ECPointFormats\n"); | ||
957 | goto err; | ||
958 | } | ||
959 | |||
960 | if (!CBB_finish(&cbb, &data, &dlen)) | ||
961 | errx(1, "failed to finish CBB"); | ||
962 | |||
963 | if (dlen != sizeof(tlsext_ecpf_hello_uncompressed)) { | ||
964 | FAIL("got client ECPointFormats with length %zu, " | ||
965 | "want length %zu\n", dlen, | ||
966 | sizeof(tlsext_ecpf_hello_uncompressed)); | ||
967 | compare_data(data, dlen, tlsext_ecpf_hello_uncompressed, | ||
968 | sizeof(tlsext_ecpf_hello_uncompressed)); | ||
969 | goto err; | ||
970 | } | ||
971 | |||
972 | if (memcmp(data, tlsext_ecpf_hello_uncompressed, dlen) != 0) { | ||
973 | FAIL("client ECPointFormats differs:\n"); | ||
974 | compare_data(data, dlen, tlsext_ecpf_hello_uncompressed, | ||
975 | sizeof(tlsext_ecpf_hello_uncompressed)); | ||
976 | goto err; | ||
977 | } | ||
978 | |||
979 | /* | ||
980 | * Make sure we can parse the default. | ||
981 | */ | ||
982 | CBB_cleanup(&cbb); | ||
983 | if (!CBB_init(&cbb, 0)) | ||
984 | errx(1, "Failed to create CBB"); | ||
985 | free(data); | ||
986 | data = NULL; | ||
987 | |||
988 | SSL_SESSION_free(ssl->session); | ||
989 | if ((ssl->session = SSL_SESSION_new()) == NULL) | ||
990 | errx(1, "failed to create session"); | ||
991 | |||
992 | CBS_init(&cbs, tlsext_ecpf_hello_uncompressed, | ||
993 | sizeof(tlsext_ecpf_hello_uncompressed)); | ||
994 | if (!server_funcs->process(ssl, SSL_TLSEXT_MSG_CH, &cbs, &alert)) { | ||
995 | FAIL("failed to parse client ECPointFormats\n"); | ||
996 | goto err; | ||
997 | } | ||
998 | if (CBS_len(&cbs) != 0) { | ||
999 | FAIL("extension data remaining\n"); | ||
1000 | goto err; | ||
1001 | } | ||
1002 | |||
1003 | if (ssl->session->tlsext_ecpointformatlist_length != | ||
1004 | sizeof(tlsext_ecpf_hello_uncompressed_val)) { | ||
1005 | FAIL("no tlsext_ecpointformats from client " | ||
1006 | "ECPointFormats\n"); | ||
1007 | goto err; | ||
1008 | } | ||
1009 | |||
1010 | if (memcmp(ssl->session->tlsext_ecpointformatlist, | ||
1011 | tlsext_ecpf_hello_uncompressed_val, | ||
1012 | sizeof(tlsext_ecpf_hello_uncompressed_val)) != 0) { | ||
1013 | FAIL("client had an incorrect ECPointFormats entry\n"); | ||
1014 | goto err; | ||
1015 | } | ||
1016 | |||
1017 | /* | ||
1018 | * Test with a custom order. | ||
1019 | */ | ||
1020 | CBB_cleanup(&cbb); | ||
1021 | if (!CBB_init(&cbb, 0)) | ||
1022 | errx(1, "Failed to create CBB"); | ||
1023 | free(data); | ||
1024 | data = NULL; | ||
1025 | |||
1026 | SSL_SESSION_free(ssl->session); | ||
1027 | if ((ssl->session = SSL_SESSION_new()) == NULL) | ||
1028 | errx(1, "failed to create session"); | ||
1029 | |||
1030 | if ((ssl->tlsext_ecpointformatlist = malloc(sizeof(uint8_t) * 3)) == NULL) { | ||
1031 | FAIL("client could not malloc\n"); | ||
1032 | goto err; | ||
1033 | } | ||
1034 | ssl->tlsext_ecpointformatlist[0] = TLSEXT_ECPOINTFORMAT_ansiX962_compressed_prime; | ||
1035 | ssl->tlsext_ecpointformatlist[1] = TLSEXT_ECPOINTFORMAT_uncompressed; | ||
1036 | ssl->tlsext_ecpointformatlist[2] = TLSEXT_ECPOINTFORMAT_ansiX962_compressed_char2; | ||
1037 | ssl->tlsext_ecpointformatlist_length = 3; | ||
1038 | |||
1039 | if (!client_funcs->needs(ssl, SSL_TLSEXT_MSG_CH)) { | ||
1040 | FAIL("client should need ECPointFormats with a custom " | ||
1041 | "format\n"); | ||
1042 | goto err; | ||
1043 | } | ||
1044 | |||
1045 | if (!client_funcs->build(ssl, SSL_TLSEXT_MSG_CH, &cbb)) { | ||
1046 | FAIL("client failed to build ECPointFormats\n"); | ||
1047 | goto err; | ||
1048 | } | ||
1049 | |||
1050 | if (!CBB_finish(&cbb, &data, &dlen)) | ||
1051 | errx(1, "failed to finish CBB"); | ||
1052 | |||
1053 | if (dlen != sizeof(tlsext_ecpf_hello_prefer_order)) { | ||
1054 | FAIL("got client ECPointFormats with length %zu, " | ||
1055 | "want length %zu\n", dlen, | ||
1056 | sizeof(tlsext_ecpf_hello_prefer_order)); | ||
1057 | compare_data(data, dlen, tlsext_ecpf_hello_prefer_order, | ||
1058 | sizeof(tlsext_ecpf_hello_prefer_order)); | ||
1059 | goto err; | ||
1060 | } | ||
1061 | |||
1062 | if (memcmp(data, tlsext_ecpf_hello_prefer_order, dlen) != 0) { | ||
1063 | FAIL("client ECPointFormats differs:\n"); | ||
1064 | compare_data(data, dlen, tlsext_ecpf_hello_prefer_order, | ||
1065 | sizeof(tlsext_ecpf_hello_prefer_order)); | ||
1066 | goto err; | ||
1067 | } | ||
1068 | |||
1069 | /* | ||
1070 | * Make sure that we can parse this custom order. | ||
1071 | */ | ||
1072 | CBB_cleanup(&cbb); | ||
1073 | if (!CBB_init(&cbb, 0)) | ||
1074 | errx(1, "Failed to create CBB"); | ||
1075 | free(data); | ||
1076 | data = NULL; | ||
1077 | |||
1078 | SSL_SESSION_free(ssl->session); | ||
1079 | if ((ssl->session = SSL_SESSION_new()) == NULL) | ||
1080 | errx(1, "failed to create session"); | ||
1081 | |||
1082 | /* Reset the custom list so we go back to the default uncompressed. */ | ||
1083 | free(ssl->tlsext_ecpointformatlist); | ||
1084 | ssl->tlsext_ecpointformatlist = NULL; | ||
1085 | ssl->tlsext_ecpointformatlist_length = 0; | ||
1086 | |||
1087 | CBS_init(&cbs, tlsext_ecpf_hello_prefer_order, | ||
1088 | sizeof(tlsext_ecpf_hello_prefer_order)); | ||
1089 | if (!server_funcs->process(ssl, SSL_TLSEXT_MSG_CH, &cbs, &alert)) { | ||
1090 | FAIL("failed to parse client ECPointFormats\n"); | ||
1091 | goto err; | ||
1092 | } | ||
1093 | if (CBS_len(&cbs) != 0) { | ||
1094 | FAIL("extension data remaining\n"); | ||
1095 | goto err; | ||
1096 | } | ||
1097 | |||
1098 | if (ssl->session->tlsext_ecpointformatlist_length != | ||
1099 | sizeof(tlsext_ecpf_hello_prefer_order_val)) { | ||
1100 | FAIL("no tlsext_ecpointformats from client " | ||
1101 | "ECPointFormats\n"); | ||
1102 | goto err; | ||
1103 | } | ||
1104 | |||
1105 | if (memcmp(ssl->session->tlsext_ecpointformatlist, | ||
1106 | tlsext_ecpf_hello_prefer_order_val, | ||
1107 | sizeof(tlsext_ecpf_hello_prefer_order_val)) != 0) { | ||
1108 | FAIL("client had an incorrect ECPointFormats entry\n"); | ||
1109 | goto err; | ||
1110 | } | ||
1111 | |||
1112 | failure = 0; | ||
1113 | |||
1114 | err: | ||
1115 | CBB_cleanup(&cbb); | ||
1116 | SSL_CTX_free(ssl_ctx); | ||
1117 | SSL_free(ssl); | ||
1118 | free(data); | ||
1119 | |||
1120 | return (failure); | ||
1121 | } | ||
1122 | |||
1123 | static int | ||
1124 | test_tlsext_ecpf_server(void) | ||
1125 | { | ||
1126 | uint8_t *data = NULL; | ||
1127 | SSL_CTX *ssl_ctx = NULL; | ||
1128 | SSL *ssl = NULL; | ||
1129 | const struct tls_extension_funcs *client_funcs; | ||
1130 | const struct tls_extension_funcs *server_funcs; | ||
1131 | size_t dlen; | ||
1132 | int failure, alert; | ||
1133 | CBB cbb; | ||
1134 | CBS cbs; | ||
1135 | |||
1136 | failure = 1; | ||
1137 | |||
1138 | if (!CBB_init(&cbb, 0)) | ||
1139 | errx(1, "Failed to create CBB"); | ||
1140 | |||
1141 | if ((ssl_ctx = SSL_CTX_new(TLS_server_method())) == NULL) | ||
1142 | errx(1, "failed to create SSL_CTX"); | ||
1143 | if ((ssl = SSL_new(ssl_ctx)) == NULL) | ||
1144 | errx(1, "failed to create SSL"); | ||
1145 | |||
1146 | if (!tls_extension_funcs(TLSEXT_TYPE_ec_point_formats, &client_funcs, | ||
1147 | &server_funcs)) | ||
1148 | errx(1, "failed to fetch ecpf funcs"); | ||
1149 | |||
1150 | if ((ssl->session = SSL_SESSION_new()) == NULL) | ||
1151 | errx(1, "failed to create session"); | ||
1152 | |||
1153 | /* Setup the state so we can call needs. */ | ||
1154 | if ((ssl->s3->hs.cipher = ssl3_get_cipher_by_value(0xcca9)) == NULL) { | ||
1155 | FAIL("server cannot find cipher\n"); | ||
1156 | goto err; | ||
1157 | } | ||
1158 | if ((ssl->session->tlsext_ecpointformatlist = malloc(sizeof(uint8_t))) | ||
1159 | == NULL) { | ||
1160 | FAIL("server could not malloc\n"); | ||
1161 | goto err; | ||
1162 | } | ||
1163 | ssl->session->tlsext_ecpointformatlist[0] = TLSEXT_ECPOINTFORMAT_ansiX962_compressed_prime; | ||
1164 | ssl->session->tlsext_ecpointformatlist_length = 1; | ||
1165 | |||
1166 | if (!server_funcs->needs(ssl, SSL_TLSEXT_MSG_SH)) { | ||
1167 | FAIL("server should need ECPointFormats now\n"); | ||
1168 | goto err; | ||
1169 | } | ||
1170 | |||
1171 | /* | ||
1172 | * The server will ignore the session list and use either a custom | ||
1173 | * list or the default (uncompressed). | ||
1174 | */ | ||
1175 | if (!server_funcs->build(ssl, SSL_TLSEXT_MSG_SH, &cbb)) { | ||
1176 | FAIL("server failed to build ECPointFormats\n"); | ||
1177 | goto err; | ||
1178 | } | ||
1179 | |||
1180 | if (!CBB_finish(&cbb, &data, &dlen)) | ||
1181 | errx(1, "failed to finish CBB"); | ||
1182 | |||
1183 | if (dlen != sizeof(tlsext_ecpf_hello_uncompressed)) { | ||
1184 | FAIL("got server ECPointFormats with length %zu, " | ||
1185 | "want length %zu\n", dlen, | ||
1186 | sizeof(tlsext_ecpf_hello_uncompressed)); | ||
1187 | compare_data(data, dlen, tlsext_ecpf_hello_uncompressed, | ||
1188 | sizeof(tlsext_ecpf_hello_uncompressed)); | ||
1189 | goto err; | ||
1190 | } | ||
1191 | |||
1192 | if (memcmp(data, tlsext_ecpf_hello_uncompressed, dlen) != 0) { | ||
1193 | FAIL("server ECPointFormats differs:\n"); | ||
1194 | compare_data(data, dlen, tlsext_ecpf_hello_uncompressed, | ||
1195 | sizeof(tlsext_ecpf_hello_uncompressed)); | ||
1196 | goto err; | ||
1197 | } | ||
1198 | |||
1199 | /* | ||
1200 | * Cannot parse a non-default list without at least uncompressed. | ||
1201 | */ | ||
1202 | CBB_cleanup(&cbb); | ||
1203 | if (!CBB_init(&cbb, 0)) | ||
1204 | errx(1, "Failed to create CBB"); | ||
1205 | free(data); | ||
1206 | data = NULL; | ||
1207 | |||
1208 | SSL_SESSION_free(ssl->session); | ||
1209 | if ((ssl->session = SSL_SESSION_new()) == NULL) | ||
1210 | errx(1, "failed to create session"); | ||
1211 | |||
1212 | CBS_init(&cbs, tlsext_ecpf_hello_prime, | ||
1213 | sizeof(tlsext_ecpf_hello_prime)); | ||
1214 | if (client_funcs->process(ssl, SSL_TLSEXT_MSG_SH, &cbs, &alert)) { | ||
1215 | FAIL("must include uncompressed in server ECPointFormats\n"); | ||
1216 | goto err; | ||
1217 | } | ||
1218 | if (CBS_len(&cbs) != 0) { | ||
1219 | FAIL("extension data remaining\n"); | ||
1220 | goto err; | ||
1221 | } | ||
1222 | |||
1223 | /* | ||
1224 | * Test with a custom order that replaces the default uncompressed. | ||
1225 | */ | ||
1226 | CBB_cleanup(&cbb); | ||
1227 | if (!CBB_init(&cbb, 0)) | ||
1228 | errx(1, "Failed to create CBB"); | ||
1229 | free(data); | ||
1230 | data = NULL; | ||
1231 | |||
1232 | SSL_SESSION_free(ssl->session); | ||
1233 | if ((ssl->session = SSL_SESSION_new()) == NULL) | ||
1234 | errx(1, "failed to create session"); | ||
1235 | |||
1236 | /* Add a session list even though it will be ignored. */ | ||
1237 | if ((ssl->session->tlsext_ecpointformatlist = malloc(sizeof(uint8_t))) | ||
1238 | == NULL) { | ||
1239 | FAIL("server could not malloc\n"); | ||
1240 | goto err; | ||
1241 | } | ||
1242 | ssl->session->tlsext_ecpointformatlist[0] = TLSEXT_ECPOINTFORMAT_ansiX962_compressed_char2; | ||
1243 | ssl->session->tlsext_ecpointformatlist_length = 1; | ||
1244 | |||
1245 | /* Replace the default list with a custom one. */ | ||
1246 | if ((ssl->tlsext_ecpointformatlist = malloc(sizeof(uint8_t) * 3)) == NULL) { | ||
1247 | FAIL("server could not malloc\n"); | ||
1248 | goto err; | ||
1249 | } | ||
1250 | ssl->tlsext_ecpointformatlist[0] = TLSEXT_ECPOINTFORMAT_ansiX962_compressed_prime; | ||
1251 | ssl->tlsext_ecpointformatlist[1] = TLSEXT_ECPOINTFORMAT_uncompressed; | ||
1252 | ssl->tlsext_ecpointformatlist[2] = TLSEXT_ECPOINTFORMAT_ansiX962_compressed_char2; | ||
1253 | ssl->tlsext_ecpointformatlist_length = 3; | ||
1254 | |||
1255 | if (!server_funcs->needs(ssl, SSL_TLSEXT_MSG_SH)) { | ||
1256 | FAIL("server should need ECPointFormats\n"); | ||
1257 | goto err; | ||
1258 | } | ||
1259 | |||
1260 | if (!server_funcs->build(ssl, SSL_TLSEXT_MSG_SH, &cbb)) { | ||
1261 | FAIL("server failed to build ECPointFormats\n"); | ||
1262 | goto err; | ||
1263 | } | ||
1264 | |||
1265 | if (!CBB_finish(&cbb, &data, &dlen)) | ||
1266 | errx(1, "failed to finish CBB"); | ||
1267 | |||
1268 | if (dlen != sizeof(tlsext_ecpf_hello_prefer_order)) { | ||
1269 | FAIL("got server ECPointFormats with length %zu, " | ||
1270 | "want length %zu\n", dlen, | ||
1271 | sizeof(tlsext_ecpf_hello_prefer_order)); | ||
1272 | compare_data(data, dlen, tlsext_ecpf_hello_prefer_order, | ||
1273 | sizeof(tlsext_ecpf_hello_prefer_order)); | ||
1274 | goto err; | ||
1275 | } | ||
1276 | |||
1277 | if (memcmp(data, tlsext_ecpf_hello_prefer_order, dlen) != 0) { | ||
1278 | FAIL("server ECPointFormats differs:\n"); | ||
1279 | compare_data(data, dlen, tlsext_ecpf_hello_prefer_order, | ||
1280 | sizeof(tlsext_ecpf_hello_prefer_order)); | ||
1281 | goto err; | ||
1282 | } | ||
1283 | |||
1284 | /* | ||
1285 | * Should be able to parse the custom list into a session list. | ||
1286 | */ | ||
1287 | CBB_cleanup(&cbb); | ||
1288 | if (!CBB_init(&cbb, 0)) | ||
1289 | errx(1, "Failed to create CBB"); | ||
1290 | free(data); | ||
1291 | data = NULL; | ||
1292 | |||
1293 | SSL_SESSION_free(ssl->session); | ||
1294 | if ((ssl->session = SSL_SESSION_new()) == NULL) | ||
1295 | errx(1, "failed to create session"); | ||
1296 | |||
1297 | /* Reset back to the default (uncompressed) */ | ||
1298 | free(ssl->tlsext_ecpointformatlist); | ||
1299 | ssl->tlsext_ecpointformatlist = NULL; | ||
1300 | ssl->tlsext_ecpointformatlist_length = 0; | ||
1301 | |||
1302 | CBS_init(&cbs, tlsext_ecpf_hello_prefer_order, | ||
1303 | sizeof(tlsext_ecpf_hello_prefer_order)); | ||
1304 | if (!client_funcs->process(ssl, SSL_TLSEXT_MSG_SH, &cbs, &alert)) { | ||
1305 | FAIL("failed to parse server ECPointFormats\n"); | ||
1306 | goto err; | ||
1307 | } | ||
1308 | if (CBS_len(&cbs) != 0) { | ||
1309 | FAIL("extension data remaining\n"); | ||
1310 | goto err; | ||
1311 | } | ||
1312 | |||
1313 | if (ssl->session->tlsext_ecpointformatlist_length != | ||
1314 | sizeof(tlsext_ecpf_hello_prefer_order_val)) { | ||
1315 | FAIL("no tlsext_ecpointformats from server " | ||
1316 | "ECPointFormats\n"); | ||
1317 | goto err; | ||
1318 | } | ||
1319 | |||
1320 | if (memcmp(ssl->session->tlsext_ecpointformatlist, | ||
1321 | tlsext_ecpf_hello_prefer_order_val, | ||
1322 | sizeof(tlsext_ecpf_hello_prefer_order_val)) != 0) { | ||
1323 | FAIL("server had an incorrect ECPointFormats entry\n"); | ||
1324 | goto err; | ||
1325 | } | ||
1326 | |||
1327 | failure = 0; | ||
1328 | |||
1329 | err: | ||
1330 | CBB_cleanup(&cbb); | ||
1331 | SSL_CTX_free(ssl_ctx); | ||
1332 | SSL_free(ssl); | ||
1333 | free(data); | ||
1334 | |||
1335 | return (failure); | ||
1336 | } | ||
1337 | |||
1338 | /* | ||
1339 | * Renegotiation Indication - RFC 5746. | ||
1340 | */ | ||
1341 | |||
1342 | static const unsigned char tlsext_ri_prev_client[] = { | ||
1343 | 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, | ||
1344 | 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff, | ||
1345 | }; | ||
1346 | |||
1347 | static const unsigned char tlsext_ri_prev_server[] = { | ||
1348 | 0xff, 0xee, 0xdd, 0xcc, 0xbb, 0xaa, 0x99, 0x88, | ||
1349 | 0x77, 0x66, 0x55, 0x44, 0x33, 0x22, 0x11, 0x00, | ||
1350 | }; | ||
1351 | |||
1352 | static const unsigned char tlsext_ri_client[] = { | ||
1353 | 0x10, | ||
1354 | 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, | ||
1355 | 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff, | ||
1356 | }; | ||
1357 | |||
1358 | static const unsigned char tlsext_ri_server[] = { | ||
1359 | 0x20, | ||
1360 | 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, | ||
1361 | 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff, | ||
1362 | 0xff, 0xee, 0xdd, 0xcc, 0xbb, 0xaa, 0x99, 0x88, | ||
1363 | 0x77, 0x66, 0x55, 0x44, 0x33, 0x22, 0x11, 0x00, | ||
1364 | }; | ||
1365 | |||
1366 | static int | ||
1367 | test_tlsext_ri_client(void) | ||
1368 | { | ||
1369 | unsigned char *data = NULL; | ||
1370 | SSL_CTX *ssl_ctx = NULL; | ||
1371 | SSL *ssl = NULL; | ||
1372 | const struct tls_extension_funcs *client_funcs; | ||
1373 | const struct tls_extension_funcs *server_funcs; | ||
1374 | int failure; | ||
1375 | size_t dlen; | ||
1376 | int alert; | ||
1377 | CBB cbb; | ||
1378 | CBS cbs; | ||
1379 | |||
1380 | failure = 1; | ||
1381 | |||
1382 | if (!CBB_init(&cbb, 0)) | ||
1383 | errx(1, "Failed to create CBB"); | ||
1384 | |||
1385 | if ((ssl_ctx = SSL_CTX_new(TLSv1_2_client_method())) == NULL) | ||
1386 | errx(1, "failed to create SSL_CTX"); | ||
1387 | if ((ssl = SSL_new(ssl_ctx)) == NULL) | ||
1388 | errx(1, "failed to create SSL"); | ||
1389 | |||
1390 | if (!tls_extension_funcs(TLSEXT_TYPE_renegotiate, &client_funcs, | ||
1391 | &server_funcs)) | ||
1392 | errx(1, "failed to fetch ri funcs"); | ||
1393 | |||
1394 | if (client_funcs->needs(ssl, SSL_TLSEXT_MSG_CH)) { | ||
1395 | FAIL("client should not need RI\n"); | ||
1396 | goto err; | ||
1397 | } | ||
1398 | |||
1399 | if (!SSL_renegotiate(ssl)) { | ||
1400 | FAIL("client failed to set renegotiate\n"); | ||
1401 | goto err; | ||
1402 | } | ||
1403 | |||
1404 | if (!client_funcs->needs(ssl, SSL_TLSEXT_MSG_CH)) { | ||
1405 | FAIL("client should need RI\n"); | ||
1406 | goto err; | ||
1407 | } | ||
1408 | |||
1409 | memcpy(ssl->s3->previous_client_finished, tlsext_ri_prev_client, | ||
1410 | sizeof(tlsext_ri_prev_client)); | ||
1411 | ssl->s3->previous_client_finished_len = sizeof(tlsext_ri_prev_client); | ||
1412 | |||
1413 | ssl->s3->renegotiate_seen = 0; | ||
1414 | |||
1415 | if (!client_funcs->build(ssl, SSL_TLSEXT_MSG_CH, &cbb)) { | ||
1416 | FAIL("client failed to build RI\n"); | ||
1417 | goto err; | ||
1418 | } | ||
1419 | |||
1420 | if (!CBB_finish(&cbb, &data, &dlen)) | ||
1421 | errx(1, "failed to finish CBB"); | ||
1422 | |||
1423 | if (dlen != sizeof(tlsext_ri_client)) { | ||
1424 | FAIL("got client RI with length %zu, " | ||
1425 | "want length %zu\n", dlen, sizeof(tlsext_ri_client)); | ||
1426 | goto err; | ||
1427 | } | ||
1428 | |||
1429 | if (memcmp(data, tlsext_ri_client, dlen) != 0) { | ||
1430 | FAIL("client RI differs:\n"); | ||
1431 | fprintf(stderr, "received:\n"); | ||
1432 | hexdump(data, dlen); | ||
1433 | fprintf(stderr, "test data:\n"); | ||
1434 | hexdump(tlsext_ri_client, sizeof(tlsext_ri_client)); | ||
1435 | goto err; | ||
1436 | } | ||
1437 | |||
1438 | CBS_init(&cbs, tlsext_ri_client, sizeof(tlsext_ri_client)); | ||
1439 | if (!server_funcs->process(ssl, SSL_TLSEXT_MSG_CH, &cbs, &alert)) { | ||
1440 | FAIL("failed to parse client RI\n"); | ||
1441 | goto err; | ||
1442 | } | ||
1443 | if (CBS_len(&cbs) != 0) { | ||
1444 | FAIL("extension data remaining\n"); | ||
1445 | goto err; | ||
1446 | } | ||
1447 | |||
1448 | if (ssl->s3->renegotiate_seen != 1) { | ||
1449 | FAIL("renegotiate seen not set\n"); | ||
1450 | goto err; | ||
1451 | } | ||
1452 | if (ssl->s3->send_connection_binding != 1) { | ||
1453 | FAIL("send connection binding not set\n"); | ||
1454 | goto err; | ||
1455 | } | ||
1456 | |||
1457 | memset(ssl->s3->previous_client_finished, 0, | ||
1458 | sizeof(ssl->s3->previous_client_finished)); | ||
1459 | |||
1460 | ssl->s3->renegotiate_seen = 0; | ||
1461 | |||
1462 | CBS_init(&cbs, tlsext_ri_client, sizeof(tlsext_ri_client)); | ||
1463 | if (server_funcs->process(ssl, SSL_TLSEXT_MSG_CH, &cbs, &alert)) { | ||
1464 | FAIL("parsed invalid client RI\n"); | ||
1465 | goto err; | ||
1466 | } | ||
1467 | |||
1468 | if (ssl->s3->renegotiate_seen == 1) { | ||
1469 | FAIL("renegotiate seen set\n"); | ||
1470 | goto err; | ||
1471 | } | ||
1472 | |||
1473 | failure = 0; | ||
1474 | |||
1475 | err: | ||
1476 | CBB_cleanup(&cbb); | ||
1477 | SSL_CTX_free(ssl_ctx); | ||
1478 | SSL_free(ssl); | ||
1479 | free(data); | ||
1480 | |||
1481 | return (failure); | ||
1482 | } | ||
1483 | |||
1484 | static int | ||
1485 | test_tlsext_ri_server(void) | ||
1486 | { | ||
1487 | unsigned char *data = NULL; | ||
1488 | SSL_CTX *ssl_ctx = NULL; | ||
1489 | SSL *ssl = NULL; | ||
1490 | const struct tls_extension_funcs *client_funcs; | ||
1491 | const struct tls_extension_funcs *server_funcs; | ||
1492 | int failure; | ||
1493 | size_t dlen; | ||
1494 | int alert; | ||
1495 | CBB cbb; | ||
1496 | CBS cbs; | ||
1497 | |||
1498 | failure = 1; | ||
1499 | |||
1500 | if (!CBB_init(&cbb, 0)) | ||
1501 | errx(1, "Failed to create CBB"); | ||
1502 | |||
1503 | if ((ssl_ctx = SSL_CTX_new(TLS_server_method())) == NULL) | ||
1504 | errx(1, "failed to create SSL_CTX"); | ||
1505 | if ((ssl = SSL_new(ssl_ctx)) == NULL) | ||
1506 | errx(1, "failed to create SSL"); | ||
1507 | |||
1508 | if (!tls_extension_funcs(TLSEXT_TYPE_renegotiate, &client_funcs, | ||
1509 | &server_funcs)) | ||
1510 | errx(1, "failed to fetch ri funcs"); | ||
1511 | |||
1512 | ssl->version = TLS1_2_VERSION; | ||
1513 | if (server_funcs->needs(ssl, SSL_TLSEXT_MSG_SH)) { | ||
1514 | FAIL("server should not need RI\n"); | ||
1515 | goto err; | ||
1516 | } | ||
1517 | |||
1518 | ssl->s3->send_connection_binding = 1; | ||
1519 | |||
1520 | if (!server_funcs->needs(ssl, SSL_TLSEXT_MSG_SH)) { | ||
1521 | FAIL("server should need RI\n"); | ||
1522 | goto err; | ||
1523 | } | ||
1524 | |||
1525 | memcpy(ssl->s3->previous_client_finished, tlsext_ri_prev_client, | ||
1526 | sizeof(tlsext_ri_prev_client)); | ||
1527 | ssl->s3->previous_client_finished_len = sizeof(tlsext_ri_prev_client); | ||
1528 | |||
1529 | memcpy(ssl->s3->previous_server_finished, tlsext_ri_prev_server, | ||
1530 | sizeof(tlsext_ri_prev_server)); | ||
1531 | ssl->s3->previous_server_finished_len = sizeof(tlsext_ri_prev_server); | ||
1532 | |||
1533 | ssl->s3->renegotiate_seen = 0; | ||
1534 | |||
1535 | if (!server_funcs->build(ssl, SSL_TLSEXT_MSG_SH, &cbb)) { | ||
1536 | FAIL("server failed to build RI\n"); | ||
1537 | goto err; | ||
1538 | } | ||
1539 | |||
1540 | if (!CBB_finish(&cbb, &data, &dlen)) | ||
1541 | errx(1, "failed to finish CBB"); | ||
1542 | |||
1543 | if (dlen != sizeof(tlsext_ri_server)) { | ||
1544 | FAIL("got server RI with length %zu, " | ||
1545 | "want length %zu\n", dlen, sizeof(tlsext_ri_server)); | ||
1546 | goto err; | ||
1547 | } | ||
1548 | |||
1549 | if (memcmp(data, tlsext_ri_server, dlen) != 0) { | ||
1550 | FAIL("server RI differs:\n"); | ||
1551 | fprintf(stderr, "received:\n"); | ||
1552 | hexdump(data, dlen); | ||
1553 | fprintf(stderr, "test data:\n"); | ||
1554 | hexdump(tlsext_ri_server, sizeof(tlsext_ri_server)); | ||
1555 | goto err; | ||
1556 | } | ||
1557 | |||
1558 | CBS_init(&cbs, tlsext_ri_server, sizeof(tlsext_ri_server)); | ||
1559 | if (!client_funcs->process(ssl, SSL_TLSEXT_MSG_SH, &cbs, &alert)) { | ||
1560 | FAIL("failed to parse server RI\n"); | ||
1561 | goto err; | ||
1562 | } | ||
1563 | if (CBS_len(&cbs) != 0) { | ||
1564 | FAIL("extension data remaining\n"); | ||
1565 | goto err; | ||
1566 | } | ||
1567 | |||
1568 | if (ssl->s3->renegotiate_seen != 1) { | ||
1569 | FAIL("renegotiate seen not set\n"); | ||
1570 | goto err; | ||
1571 | } | ||
1572 | if (ssl->s3->send_connection_binding != 1) { | ||
1573 | FAIL("send connection binding not set\n"); | ||
1574 | goto err; | ||
1575 | } | ||
1576 | |||
1577 | memset(ssl->s3->previous_client_finished, 0, | ||
1578 | sizeof(ssl->s3->previous_client_finished)); | ||
1579 | memset(ssl->s3->previous_server_finished, 0, | ||
1580 | sizeof(ssl->s3->previous_server_finished)); | ||
1581 | |||
1582 | ssl->s3->renegotiate_seen = 0; | ||
1583 | |||
1584 | CBS_init(&cbs, tlsext_ri_server, sizeof(tlsext_ri_server)); | ||
1585 | if (client_funcs->process(ssl, SSL_TLSEXT_MSG_SH, &cbs, &alert)) { | ||
1586 | FAIL("parsed invalid server RI\n"); | ||
1587 | goto err; | ||
1588 | } | ||
1589 | |||
1590 | if (ssl->s3->renegotiate_seen == 1) { | ||
1591 | FAIL("renegotiate seen set\n"); | ||
1592 | goto err; | ||
1593 | } | ||
1594 | |||
1595 | failure = 0; | ||
1596 | |||
1597 | err: | ||
1598 | CBB_cleanup(&cbb); | ||
1599 | SSL_CTX_free(ssl_ctx); | ||
1600 | SSL_free(ssl); | ||
1601 | free(data); | ||
1602 | |||
1603 | return (failure); | ||
1604 | } | ||
1605 | |||
1606 | /* | ||
1607 | * Signature Algorithms - RFC 5246 section 7.4.1.4.1. | ||
1608 | */ | ||
1609 | |||
1610 | static const unsigned char tlsext_sigalgs_client[] = { | ||
1611 | 0x00, 0x16, 0x08, 0x06, 0x06, 0x01, 0x06, 0x03, | ||
1612 | 0x08, 0x05, 0x05, 0x01, 0x05, 0x03, 0x08, 0x04, | ||
1613 | 0x04, 0x01, 0x04, 0x03, 0x02, 0x01, 0x02, 0x03, | ||
1614 | }; | ||
1615 | |||
1616 | static int | ||
1617 | test_tlsext_sigalgs_client(void) | ||
1618 | { | ||
1619 | unsigned char *data = NULL; | ||
1620 | SSL_CTX *ssl_ctx = NULL; | ||
1621 | SSL *ssl = NULL; | ||
1622 | const struct tls_extension_funcs *client_funcs; | ||
1623 | const struct tls_extension_funcs *server_funcs; | ||
1624 | int failure; | ||
1625 | size_t dlen; | ||
1626 | int alert; | ||
1627 | CBB cbb; | ||
1628 | CBS cbs; | ||
1629 | |||
1630 | failure = 1; | ||
1631 | |||
1632 | if (!CBB_init(&cbb, 0)) | ||
1633 | errx(1, "Failed to create CBB"); | ||
1634 | |||
1635 | if ((ssl_ctx = SSL_CTX_new(TLS_client_method())) == NULL) | ||
1636 | errx(1, "failed to create SSL_CTX"); | ||
1637 | if ((ssl = SSL_new(ssl_ctx)) == NULL) | ||
1638 | errx(1, "failed to create SSL"); | ||
1639 | |||
1640 | if (!tls_extension_funcs(TLSEXT_TYPE_signature_algorithms, | ||
1641 | &client_funcs, &server_funcs)) | ||
1642 | errx(1, "failed to fetch sigalgs funcs"); | ||
1643 | |||
1644 | ssl->s3->hs.our_max_tls_version = TLS1_1_VERSION; | ||
1645 | |||
1646 | if (client_funcs->needs(ssl, SSL_TLSEXT_MSG_CH)) { | ||
1647 | FAIL("client should not need sigalgs\n"); | ||
1648 | goto done; | ||
1649 | } | ||
1650 | |||
1651 | ssl->s3->hs.our_max_tls_version = TLS1_2_VERSION; | ||
1652 | |||
1653 | if (!client_funcs->needs(ssl, SSL_TLSEXT_MSG_CH)) { | ||
1654 | FAIL("client should need sigalgs\n"); | ||
1655 | goto done; | ||
1656 | } | ||
1657 | |||
1658 | if (!client_funcs->build(ssl, SSL_TLSEXT_MSG_CH, &cbb)) { | ||
1659 | FAIL("client failed to build sigalgs\n"); | ||
1660 | goto done; | ||
1661 | } | ||
1662 | |||
1663 | if (!CBB_finish(&cbb, &data, &dlen)) | ||
1664 | errx(1, "failed to finish CBB"); | ||
1665 | |||
1666 | if (dlen != sizeof(tlsext_sigalgs_client)) { | ||
1667 | FAIL("got client sigalgs length %zu, " | ||
1668 | "want length %zu\n", dlen, sizeof(tlsext_sigalgs_client)); | ||
1669 | goto done; | ||
1670 | } | ||
1671 | |||
1672 | if (memcmp(data, tlsext_sigalgs_client, dlen) != 0) { | ||
1673 | FAIL("client SNI differs:\n"); | ||
1674 | fprintf(stderr, "received:\n"); | ||
1675 | hexdump(data, dlen); | ||
1676 | fprintf(stderr, "test data:\n"); | ||
1677 | hexdump(tlsext_sigalgs_client, sizeof(tlsext_sigalgs_client)); | ||
1678 | goto done; | ||
1679 | } | ||
1680 | |||
1681 | CBS_init(&cbs, tlsext_sigalgs_client, sizeof(tlsext_sigalgs_client)); | ||
1682 | if (!server_funcs->process(ssl, SSL_TLSEXT_MSG_CH, &cbs, &alert)) { | ||
1683 | FAIL("failed to parse client SNI\n"); | ||
1684 | goto done; | ||
1685 | } | ||
1686 | if (CBS_len(&cbs) != 0) { | ||
1687 | FAIL("extension data remaining\n"); | ||
1688 | goto done; | ||
1689 | } | ||
1690 | |||
1691 | failure = 0; | ||
1692 | |||
1693 | done: | ||
1694 | CBB_cleanup(&cbb); | ||
1695 | SSL_CTX_free(ssl_ctx); | ||
1696 | SSL_free(ssl); | ||
1697 | free(data); | ||
1698 | |||
1699 | return (failure); | ||
1700 | } | ||
1701 | |||
1702 | #if 0 | ||
1703 | static int | ||
1704 | test_tlsext_sigalgs_server(void) | ||
1705 | { | ||
1706 | unsigned char *data = NULL; | ||
1707 | SSL_CTX *ssl_ctx = NULL; | ||
1708 | SSL *ssl = NULL; | ||
1709 | const struct tls_extension_funcs *client_funcs; | ||
1710 | const struct tls_extension_funcs *server_funcs; | ||
1711 | int failure; | ||
1712 | size_t dlen; | ||
1713 | int alert; | ||
1714 | CBB cbb; | ||
1715 | CBS cbs; | ||
1716 | |||
1717 | failure = 1; | ||
1718 | |||
1719 | if (!CBB_init(&cbb, 0)) | ||
1720 | errx(1, "Failed to create CBB"); | ||
1721 | |||
1722 | if ((ssl_ctx = SSL_CTX_new(TLS_server_method())) == NULL) | ||
1723 | errx(1, "failed to create SSL_CTX"); | ||
1724 | if ((ssl = SSL_new(ssl_ctx)) == NULL) | ||
1725 | errx(1, "failed to create SSL"); | ||
1726 | |||
1727 | if (!tls_extension_funcs(TLSEXT_TYPE_server_name, &client_funcs, | ||
1728 | &server_funcs)) | ||
1729 | errx(1, "failed to fetch sigalgs funcs"); | ||
1730 | |||
1731 | if (server_funcs->needs(ssl, SSL_TLSEXT_MSG_SH)) { | ||
1732 | FAIL("server should not need sigalgs\n"); | ||
1733 | goto done; | ||
1734 | } | ||
1735 | |||
1736 | if (server_funcs->build(ssl, SSL_TLSEXT_MSG_SH, &cbb)) { | ||
1737 | FAIL("server should not build sigalgs\n"); | ||
1738 | goto done; | ||
1739 | } | ||
1740 | |||
1741 | if (!CBB_finish(&cbb, &data, &dlen)) | ||
1742 | errx(1, "failed to finish CBB"); | ||
1743 | |||
1744 | CBS_init(&cbs, tlsext_sigalgs_client, sizeof(tlsext_sigalgs_client)); | ||
1745 | if (!client_funcs->process(ssl, SSL_TLSEXT_MSG_SH, &cbs, &alert)) { | ||
1746 | FAIL("server should not parse sigalgs\n"); | ||
1747 | goto done; | ||
1748 | } | ||
1749 | |||
1750 | failure = 0; | ||
1751 | |||
1752 | done: | ||
1753 | CBB_cleanup(&cbb); | ||
1754 | SSL_CTX_free(ssl_ctx); | ||
1755 | SSL_free(ssl); | ||
1756 | free(data); | ||
1757 | |||
1758 | return (failure); | ||
1759 | } | ||
1760 | #endif | ||
1761 | |||
1762 | /* | ||
1763 | * Server Name Indication - RFC 6066 section 3. | ||
1764 | */ | ||
1765 | |||
1766 | #define TEST_SNI_SERVERNAME "www.libressl.org" | ||
1767 | |||
1768 | static const unsigned char tlsext_sni_client[] = { | ||
1769 | 0x00, 0x13, 0x00, 0x00, 0x10, 0x77, 0x77, 0x77, | ||
1770 | 0x2e, 0x6c, 0x69, 0x62, 0x72, 0x65, 0x73, 0x73, | ||
1771 | 0x6c, 0x2e, 0x6f, 0x72, 0x67, | ||
1772 | }; | ||
1773 | |||
1774 | /* An empty array is an incomplete type and sizeof() is undefined. */ | ||
1775 | static const unsigned char tlsext_sni_server[] = { | ||
1776 | 0x00, | ||
1777 | }; | ||
1778 | static size_t tlsext_sni_server_len = 0; | ||
1779 | |||
1780 | static int | ||
1781 | test_tlsext_sni_client(void) | ||
1782 | { | ||
1783 | unsigned char *data = NULL; | ||
1784 | SSL_CTX *ssl_ctx = NULL; | ||
1785 | SSL *ssl = NULL; | ||
1786 | const struct tls_extension_funcs *client_funcs; | ||
1787 | const struct tls_extension_funcs *server_funcs; | ||
1788 | int failure; | ||
1789 | size_t dlen; | ||
1790 | int alert; | ||
1791 | CBB cbb; | ||
1792 | CBS cbs; | ||
1793 | |||
1794 | failure = 1; | ||
1795 | |||
1796 | if (!CBB_init(&cbb, 0)) | ||
1797 | errx(1, "Failed to create CBB"); | ||
1798 | |||
1799 | if ((ssl_ctx = SSL_CTX_new(TLS_client_method())) == NULL) | ||
1800 | errx(1, "failed to create SSL_CTX"); | ||
1801 | if ((ssl = SSL_new(ssl_ctx)) == NULL) | ||
1802 | errx(1, "failed to create SSL"); | ||
1803 | |||
1804 | if (!tls_extension_funcs(TLSEXT_TYPE_server_name, &client_funcs, | ||
1805 | &server_funcs)) | ||
1806 | errx(1, "failed to fetch sni funcs"); | ||
1807 | |||
1808 | if (client_funcs->needs(ssl, SSL_TLSEXT_MSG_CH)) { | ||
1809 | FAIL("client should not need SNI\n"); | ||
1810 | goto err; | ||
1811 | } | ||
1812 | |||
1813 | if (!SSL_set_tlsext_host_name(ssl, TEST_SNI_SERVERNAME)) { | ||
1814 | FAIL("client failed to set server name\n"); | ||
1815 | goto err; | ||
1816 | } | ||
1817 | |||
1818 | if (!client_funcs->needs(ssl, SSL_TLSEXT_MSG_CH)) { | ||
1819 | FAIL("client should need SNI\n"); | ||
1820 | goto err; | ||
1821 | } | ||
1822 | |||
1823 | if (!client_funcs->build(ssl, SSL_TLSEXT_MSG_CH, &cbb)) { | ||
1824 | FAIL("client failed to build SNI\n"); | ||
1825 | goto err; | ||
1826 | } | ||
1827 | |||
1828 | if (!CBB_finish(&cbb, &data, &dlen)) { | ||
1829 | FAIL("failed to finish CBB"); | ||
1830 | goto err; | ||
1831 | } | ||
1832 | |||
1833 | if (dlen != sizeof(tlsext_sni_client)) { | ||
1834 | FAIL("got client SNI with length %zu, " | ||
1835 | "want length %zu\n", dlen, sizeof(tlsext_sni_client)); | ||
1836 | goto err; | ||
1837 | } | ||
1838 | |||
1839 | if (memcmp(data, tlsext_sni_client, dlen) != 0) { | ||
1840 | FAIL("client SNI differs:\n"); | ||
1841 | fprintf(stderr, "received:\n"); | ||
1842 | hexdump(data, dlen); | ||
1843 | fprintf(stderr, "test data:\n"); | ||
1844 | hexdump(tlsext_sni_client, sizeof(tlsext_sni_client)); | ||
1845 | goto err; | ||
1846 | } | ||
1847 | |||
1848 | /* | ||
1849 | * SSL_set_tlsext_host_name() may be called with a NULL host name to | ||
1850 | * disable SNI. | ||
1851 | */ | ||
1852 | if (!SSL_set_tlsext_host_name(ssl, NULL)) { | ||
1853 | FAIL("cannot set host name to NULL"); | ||
1854 | goto err; | ||
1855 | } | ||
1856 | |||
1857 | if (client_funcs->needs(ssl, SSL_TLSEXT_MSG_CH)) { | ||
1858 | FAIL("client should not need SNI\n"); | ||
1859 | goto err; | ||
1860 | } | ||
1861 | |||
1862 | if ((ssl->session = SSL_SESSION_new()) == NULL) { | ||
1863 | FAIL("failed to create session"); | ||
1864 | goto err; | ||
1865 | } | ||
1866 | |||
1867 | ssl->hit = 0; | ||
1868 | |||
1869 | CBS_init(&cbs, tlsext_sni_client, sizeof(tlsext_sni_client)); | ||
1870 | if (!server_funcs->process(ssl, SSL_TLSEXT_MSG_CH, &cbs, &alert)) { | ||
1871 | FAIL("failed to parse client SNI\n"); | ||
1872 | goto err; | ||
1873 | } | ||
1874 | if (CBS_len(&cbs) != 0) { | ||
1875 | FAIL("extension data remaining\n"); | ||
1876 | goto err; | ||
1877 | } | ||
1878 | |||
1879 | if (ssl->session->tlsext_hostname == NULL) { | ||
1880 | FAIL("no tlsext_hostname from client SNI\n"); | ||
1881 | goto err; | ||
1882 | } | ||
1883 | |||
1884 | if (strlen(ssl->session->tlsext_hostname) != strlen(TEST_SNI_SERVERNAME) || | ||
1885 | strncmp(ssl->session->tlsext_hostname, TEST_SNI_SERVERNAME, | ||
1886 | strlen(TEST_SNI_SERVERNAME)) != 0) { | ||
1887 | FAIL("got tlsext_hostname `%s', want `%s'\n", | ||
1888 | ssl->session->tlsext_hostname, TEST_SNI_SERVERNAME); | ||
1889 | goto err; | ||
1890 | } | ||
1891 | |||
1892 | ssl->hit = 1; | ||
1893 | |||
1894 | free(ssl->session->tlsext_hostname); | ||
1895 | if ((ssl->session->tlsext_hostname = strdup("notthesame.libressl.org")) == | ||
1896 | NULL) { | ||
1897 | FAIL("failed to strdup tlsext_hostname"); | ||
1898 | goto err; | ||
1899 | } | ||
1900 | |||
1901 | CBS_init(&cbs, tlsext_sni_client, sizeof(tlsext_sni_client)); | ||
1902 | if (server_funcs->process(ssl, SSL_TLSEXT_MSG_CH, &cbs, &alert)) { | ||
1903 | FAIL("parsed client with mismatched SNI\n"); | ||
1904 | goto err; | ||
1905 | } | ||
1906 | |||
1907 | failure = 0; | ||
1908 | |||
1909 | err: | ||
1910 | CBB_cleanup(&cbb); | ||
1911 | SSL_CTX_free(ssl_ctx); | ||
1912 | SSL_free(ssl); | ||
1913 | free(data); | ||
1914 | |||
1915 | return (failure); | ||
1916 | } | ||
1917 | |||
1918 | static int | ||
1919 | test_tlsext_sni_server(void) | ||
1920 | { | ||
1921 | unsigned char *data = NULL; | ||
1922 | SSL_CTX *ssl_ctx = NULL; | ||
1923 | SSL *ssl = NULL; | ||
1924 | const struct tls_extension_funcs *client_funcs; | ||
1925 | const struct tls_extension_funcs *server_funcs; | ||
1926 | int failure; | ||
1927 | size_t dlen; | ||
1928 | int alert; | ||
1929 | CBB cbb; | ||
1930 | CBS cbs; | ||
1931 | |||
1932 | failure = 1; | ||
1933 | |||
1934 | if (!CBB_init(&cbb, 0)) | ||
1935 | errx(1, "Failed to create CBB"); | ||
1936 | |||
1937 | if ((ssl_ctx = SSL_CTX_new(TLS_server_method())) == NULL) | ||
1938 | errx(1, "failed to create SSL_CTX"); | ||
1939 | if ((ssl = SSL_new(ssl_ctx)) == NULL) | ||
1940 | errx(1, "failed to create SSL"); | ||
1941 | |||
1942 | if (!tls_extension_funcs(TLSEXT_TYPE_server_name, &client_funcs, | ||
1943 | &server_funcs)) | ||
1944 | errx(1, "failed to fetch sni funcs"); | ||
1945 | |||
1946 | if ((ssl->session = SSL_SESSION_new()) == NULL) | ||
1947 | errx(1, "failed to create session"); | ||
1948 | |||
1949 | if (server_funcs->needs(ssl, SSL_TLSEXT_MSG_SH)) { | ||
1950 | FAIL("server should not need SNI\n"); | ||
1951 | goto err; | ||
1952 | } | ||
1953 | |||
1954 | if (!SSL_set_tlsext_host_name(ssl, TEST_SNI_SERVERNAME)) { | ||
1955 | FAIL("client failed to set server name\n"); | ||
1956 | goto err; | ||
1957 | } | ||
1958 | |||
1959 | if ((ssl->session->tlsext_hostname = strdup(TEST_SNI_SERVERNAME)) == | ||
1960 | NULL) | ||
1961 | errx(1, "failed to strdup tlsext_hostname"); | ||
1962 | |||
1963 | if (!server_funcs->needs(ssl, SSL_TLSEXT_MSG_SH)) { | ||
1964 | FAIL("server should need SNI\n"); | ||
1965 | goto err; | ||
1966 | } | ||
1967 | |||
1968 | if (!server_funcs->build(ssl, SSL_TLSEXT_MSG_SH, &cbb)) { | ||
1969 | FAIL("server failed to build SNI\n"); | ||
1970 | goto err; | ||
1971 | } | ||
1972 | |||
1973 | if (!CBB_finish(&cbb, &data, &dlen)) | ||
1974 | errx(1, "failed to finish CBB"); | ||
1975 | |||
1976 | if (dlen != tlsext_sni_server_len) { | ||
1977 | FAIL("got server SNI with length %zu, " | ||
1978 | "want length %zu\n", dlen, tlsext_sni_server_len); | ||
1979 | goto err; | ||
1980 | } | ||
1981 | |||
1982 | if (memcmp(data, tlsext_sni_server, dlen) != 0) { | ||
1983 | FAIL("server SNI differs:\n"); | ||
1984 | fprintf(stderr, "received:\n"); | ||
1985 | hexdump(data, dlen); | ||
1986 | fprintf(stderr, "test data:\n"); | ||
1987 | hexdump(tlsext_sni_server, tlsext_sni_server_len); | ||
1988 | goto err; | ||
1989 | } | ||
1990 | |||
1991 | free(ssl->session->tlsext_hostname); | ||
1992 | ssl->session->tlsext_hostname = NULL; | ||
1993 | |||
1994 | CBS_init(&cbs, tlsext_sni_server, tlsext_sni_server_len); | ||
1995 | if (!client_funcs->process(ssl, SSL_TLSEXT_MSG_SH, &cbs, &alert)) { | ||
1996 | FAIL("failed to parse server SNI\n"); | ||
1997 | goto err; | ||
1998 | } | ||
1999 | if (CBS_len(&cbs) != 0) { | ||
2000 | FAIL("extension data remaining\n"); | ||
2001 | goto err; | ||
2002 | } | ||
2003 | |||
2004 | if (ssl->session->tlsext_hostname == NULL) { | ||
2005 | FAIL("no tlsext_hostname after server SNI\n"); | ||
2006 | goto err; | ||
2007 | } | ||
2008 | |||
2009 | if (strlen(ssl->session->tlsext_hostname) != strlen(TEST_SNI_SERVERNAME) || | ||
2010 | strncmp(ssl->session->tlsext_hostname, TEST_SNI_SERVERNAME, | ||
2011 | strlen(TEST_SNI_SERVERNAME)) != 0) { | ||
2012 | FAIL("got tlsext_hostname `%s', want `%s'\n", | ||
2013 | ssl->session->tlsext_hostname, TEST_SNI_SERVERNAME); | ||
2014 | goto err; | ||
2015 | } | ||
2016 | |||
2017 | failure = 0; | ||
2018 | |||
2019 | err: | ||
2020 | CBB_cleanup(&cbb); | ||
2021 | SSL_CTX_free(ssl_ctx); | ||
2022 | SSL_free(ssl); | ||
2023 | free(data); | ||
2024 | |||
2025 | return (failure); | ||
2026 | } | ||
2027 | |||
2028 | |||
2029 | /* | ||
2030 | * QUIC transport parameters extension - RFC 90210 :) | ||
2031 | */ | ||
2032 | |||
2033 | static const unsigned char tlsext_quic_transport_data[] = { | ||
2034 | 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, | ||
2035 | 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, | ||
2036 | }; | ||
2037 | |||
2038 | static int | ||
2039 | test_tlsext_quic_transport_parameters_client(void) | ||
2040 | { | ||
2041 | const SSL_QUIC_METHOD quic_method = {0}; | ||
2042 | unsigned char *data = NULL; | ||
2043 | SSL_CTX *ssl_ctx = NULL; | ||
2044 | SSL *ssl = NULL; | ||
2045 | const struct tls_extension_funcs *client_funcs; | ||
2046 | const struct tls_extension_funcs *server_funcs; | ||
2047 | int failure; | ||
2048 | size_t dlen; | ||
2049 | CBB cbb; | ||
2050 | CBS cbs; | ||
2051 | int alert; | ||
2052 | const uint8_t *out_bytes; | ||
2053 | size_t out_bytes_len; | ||
2054 | |||
2055 | failure = 1; | ||
2056 | |||
2057 | if (!CBB_init(&cbb, 0)) | ||
2058 | errx(1, "Failed to create CBB"); | ||
2059 | |||
2060 | if ((ssl_ctx = SSL_CTX_new(TLS_client_method())) == NULL) | ||
2061 | errx(1, "failed to create SSL_CTX"); | ||
2062 | if ((ssl = SSL_new(ssl_ctx)) == NULL) | ||
2063 | errx(1, "failed to create SSL"); | ||
2064 | |||
2065 | if (!tls_extension_funcs(TLSEXT_TYPE_quic_transport_parameters, | ||
2066 | &client_funcs, &server_funcs)) | ||
2067 | errx(1, "failed to fetch quic transport parameter funcs"); | ||
2068 | |||
2069 | if (client_funcs->needs(ssl, SSL_TLSEXT_MSG_CH)) { | ||
2070 | FAIL("client should not need QUIC\n"); | ||
2071 | goto err; | ||
2072 | } | ||
2073 | |||
2074 | if (!SSL_set_quic_transport_params(ssl, | ||
2075 | tlsext_quic_transport_data, sizeof(tlsext_quic_transport_data))) { | ||
2076 | FAIL("client failed to set QUIC parameters\n"); | ||
2077 | goto err; | ||
2078 | } | ||
2079 | |||
2080 | if (client_funcs->needs(ssl, SSL_TLSEXT_MSG_CH)) { | ||
2081 | FAIL("client should not need QUIC\n"); | ||
2082 | goto err; | ||
2083 | } | ||
2084 | |||
2085 | ssl->s3->hs.our_max_tls_version = TLS1_3_VERSION; | ||
2086 | ssl->s3->hs.negotiated_tls_version = TLS1_3_VERSION; | ||
2087 | |||
2088 | if (client_funcs->needs(ssl, SSL_TLSEXT_MSG_CH)) { | ||
2089 | FAIL("client should not need QUIC\n"); | ||
2090 | goto err; | ||
2091 | } | ||
2092 | |||
2093 | ssl->quic_method = &quic_method; | ||
2094 | |||
2095 | if (!client_funcs->needs(ssl, SSL_TLSEXT_MSG_CH)) { | ||
2096 | FAIL("client should need QUIC\n"); | ||
2097 | goto err; | ||
2098 | } | ||
2099 | |||
2100 | if (!client_funcs->build(ssl, SSL_TLSEXT_MSG_CH, &cbb)) { | ||
2101 | FAIL("client failed to build QUIC\n"); | ||
2102 | goto err; | ||
2103 | } | ||
2104 | |||
2105 | if (!CBB_finish(&cbb, &data, &dlen)) { | ||
2106 | FAIL("failed to finish CBB"); | ||
2107 | goto err; | ||
2108 | } | ||
2109 | |||
2110 | if (dlen != sizeof(tlsext_quic_transport_data)) { | ||
2111 | FAIL("got client QUIC with length %zu, " | ||
2112 | "want length %zu\n", dlen, | ||
2113 | sizeof(tlsext_quic_transport_data)); | ||
2114 | goto err; | ||
2115 | } | ||
2116 | |||
2117 | if (memcmp(data, tlsext_quic_transport_data, dlen) != 0) { | ||
2118 | FAIL("client QUIC differs:\n"); | ||
2119 | fprintf(stderr, "received:\n"); | ||
2120 | hexdump(data, dlen); | ||
2121 | fprintf(stderr, "test data:\n"); | ||
2122 | hexdump(tlsext_quic_transport_data, | ||
2123 | sizeof(tlsext_quic_transport_data)); | ||
2124 | goto err; | ||
2125 | } | ||
2126 | |||
2127 | CBS_init(&cbs, tlsext_quic_transport_data, | ||
2128 | sizeof(tlsext_quic_transport_data)); | ||
2129 | if (!server_funcs->process(ssl, SSL_TLSEXT_MSG_SH, &cbs, &alert)) { | ||
2130 | FAIL("server_parse of QUIC from server failed\n"); | ||
2131 | goto err; | ||
2132 | } | ||
2133 | if (CBS_len(&cbs) != 0) { | ||
2134 | FAIL("extension data remaining\n"); | ||
2135 | goto err; | ||
2136 | } | ||
2137 | |||
2138 | SSL_get_peer_quic_transport_params(ssl, &out_bytes, &out_bytes_len); | ||
2139 | |||
2140 | if (out_bytes_len != sizeof(tlsext_quic_transport_data)) { | ||
2141 | FAIL("server_parse QUIC length differs, got %zu want %zu\n", | ||
2142 | out_bytes_len, | ||
2143 | sizeof(tlsext_quic_transport_data)); | ||
2144 | goto err; | ||
2145 | } | ||
2146 | |||
2147 | if (memcmp(out_bytes, tlsext_quic_transport_data, | ||
2148 | out_bytes_len) != 0) { | ||
2149 | FAIL("server_parse QUIC differs from sent:\n"); | ||
2150 | fprintf(stderr, "received:\n"); | ||
2151 | hexdump(data, dlen); | ||
2152 | fprintf(stderr, "test data:\n"); | ||
2153 | hexdump(tlsext_quic_transport_data, | ||
2154 | sizeof(tlsext_quic_transport_data)); | ||
2155 | goto err; | ||
2156 | } | ||
2157 | |||
2158 | failure = 0; | ||
2159 | |||
2160 | err: | ||
2161 | CBB_cleanup(&cbb); | ||
2162 | SSL_CTX_free(ssl_ctx); | ||
2163 | SSL_free(ssl); | ||
2164 | free(data); | ||
2165 | |||
2166 | return (failure); | ||
2167 | } | ||
2168 | |||
2169 | static int | ||
2170 | test_tlsext_quic_transport_parameters_server(void) | ||
2171 | { | ||
2172 | const SSL_QUIC_METHOD quic_method = {0}; | ||
2173 | unsigned char *data = NULL; | ||
2174 | SSL_CTX *ssl_ctx = NULL; | ||
2175 | SSL *ssl = NULL; | ||
2176 | const struct tls_extension_funcs *client_funcs; | ||
2177 | const struct tls_extension_funcs *server_funcs; | ||
2178 | int failure; | ||
2179 | size_t dlen; | ||
2180 | int alert; | ||
2181 | CBB cbb; | ||
2182 | CBS cbs; | ||
2183 | const uint8_t *out_bytes; | ||
2184 | size_t out_bytes_len; | ||
2185 | |||
2186 | failure = 1; | ||
2187 | |||
2188 | if (!CBB_init(&cbb, 0)) | ||
2189 | errx(1, "Failed to create CBB"); | ||
2190 | |||
2191 | if ((ssl_ctx = SSL_CTX_new(TLS_server_method())) == NULL) | ||
2192 | errx(1, "failed to create SSL_CTX"); | ||
2193 | if ((ssl = SSL_new(ssl_ctx)) == NULL) | ||
2194 | errx(1, "failed to create SSL"); | ||
2195 | |||
2196 | if (!tls_extension_funcs(TLSEXT_TYPE_quic_transport_parameters, | ||
2197 | &client_funcs, &server_funcs)) | ||
2198 | errx(1, "failed to fetch quic transport parameter funcs"); | ||
2199 | |||
2200 | if (server_funcs->needs(ssl, SSL_TLSEXT_MSG_SH)) { | ||
2201 | FAIL("server should not need QUIC\n"); | ||
2202 | goto err; | ||
2203 | } | ||
2204 | |||
2205 | if (!SSL_set_quic_transport_params(ssl, | ||
2206 | tlsext_quic_transport_data, sizeof(tlsext_quic_transport_data))) { | ||
2207 | FAIL("server failed to set QUIC parametes\n"); | ||
2208 | goto err; | ||
2209 | } | ||
2210 | |||
2211 | if (server_funcs->needs(ssl, SSL_TLSEXT_MSG_EE)) { | ||
2212 | FAIL("server should not need QUIC\n"); | ||
2213 | goto err; | ||
2214 | } | ||
2215 | |||
2216 | ssl->quic_method = &quic_method; | ||
2217 | |||
2218 | if (!server_funcs->needs(ssl, SSL_TLSEXT_MSG_EE)) { | ||
2219 | FAIL("server should need QUIC\n"); | ||
2220 | goto err; | ||
2221 | } | ||
2222 | |||
2223 | if (!server_funcs->build(ssl, SSL_TLSEXT_MSG_EE, &cbb)) { | ||
2224 | FAIL("server failed to build QUIC\n"); | ||
2225 | goto err; | ||
2226 | } | ||
2227 | |||
2228 | if (!CBB_finish(&cbb, &data, &dlen)) | ||
2229 | errx(1, "failed to finish CBB"); | ||
2230 | |||
2231 | if (dlen != sizeof(tlsext_quic_transport_data)) { | ||
2232 | FAIL("got server QUIC with length %zu, want length %zu\n", | ||
2233 | dlen, sizeof(tlsext_quic_transport_data)); | ||
2234 | goto err; | ||
2235 | } | ||
2236 | |||
2237 | if (memcmp(data, tlsext_quic_transport_data, dlen) != 0) { | ||
2238 | FAIL("saved server QUIC differs:\n"); | ||
2239 | fprintf(stderr, "received:\n"); | ||
2240 | hexdump(data, dlen); | ||
2241 | fprintf(stderr, "test data:\n"); | ||
2242 | hexdump(tlsext_quic_transport_data, | ||
2243 | sizeof(tlsext_quic_transport_data)); | ||
2244 | goto err; | ||
2245 | } | ||
2246 | |||
2247 | CBS_init(&cbs, tlsext_quic_transport_data, | ||
2248 | sizeof(tlsext_quic_transport_data)); | ||
2249 | |||
2250 | ssl->quic_method = NULL; | ||
2251 | |||
2252 | if (client_funcs->process(ssl, SSL_TLSEXT_MSG_EE, &cbs, &alert)) { | ||
2253 | FAIL("QUIC parse should have failed!\n"); | ||
2254 | goto err; | ||
2255 | } | ||
2256 | |||
2257 | ssl->quic_method = &quic_method; | ||
2258 | |||
2259 | if (!client_funcs->process(ssl, SSL_TLSEXT_MSG_SH, &cbs, &alert)) { | ||
2260 | FAIL("client_parse of QUIC from server failed\n"); | ||
2261 | goto err; | ||
2262 | } | ||
2263 | if (CBS_len(&cbs) != 0) { | ||
2264 | FAIL("extension data remaining\n"); | ||
2265 | goto err; | ||
2266 | } | ||
2267 | |||
2268 | SSL_get_peer_quic_transport_params(ssl, &out_bytes, &out_bytes_len); | ||
2269 | |||
2270 | if (out_bytes_len != sizeof(tlsext_quic_transport_data)) { | ||
2271 | FAIL("client QUIC length differs, got %zu want %zu\n", | ||
2272 | out_bytes_len, | ||
2273 | sizeof(tlsext_quic_transport_data)); | ||
2274 | goto err; | ||
2275 | } | ||
2276 | |||
2277 | if (memcmp(out_bytes, tlsext_quic_transport_data, out_bytes_len) != 0) { | ||
2278 | FAIL("client QUIC differs from sent:\n"); | ||
2279 | fprintf(stderr, "received:\n"); | ||
2280 | hexdump(data, dlen); | ||
2281 | fprintf(stderr, "test data:\n"); | ||
2282 | hexdump(tlsext_quic_transport_data, | ||
2283 | sizeof(tlsext_quic_transport_data)); | ||
2284 | goto err; | ||
2285 | } | ||
2286 | |||
2287 | failure = 0; | ||
2288 | |||
2289 | err: | ||
2290 | CBB_cleanup(&cbb); | ||
2291 | SSL_CTX_free(ssl_ctx); | ||
2292 | SSL_free(ssl); | ||
2293 | free(data); | ||
2294 | |||
2295 | return (failure); | ||
2296 | } | ||
2297 | |||
2298 | static const unsigned char tls_ocsp_client_default[] = { | ||
2299 | 0x01, 0x00, 0x00, 0x00, 0x00 | ||
2300 | }; | ||
2301 | |||
2302 | static int | ||
2303 | test_tlsext_ocsp_client(void) | ||
2304 | { | ||
2305 | unsigned char *data = NULL; | ||
2306 | SSL_CTX *ssl_ctx = NULL; | ||
2307 | SSL *ssl = NULL; | ||
2308 | const struct tls_extension_funcs *client_funcs; | ||
2309 | const struct tls_extension_funcs *server_funcs; | ||
2310 | size_t dlen; | ||
2311 | int failure; | ||
2312 | int alert; | ||
2313 | CBB cbb; | ||
2314 | CBS cbs; | ||
2315 | |||
2316 | failure = 1; | ||
2317 | |||
2318 | if (!CBB_init(&cbb, 0)) | ||
2319 | errx(1, "Failed to create CBB"); | ||
2320 | |||
2321 | if ((ssl_ctx = SSL_CTX_new(TLS_client_method())) == NULL) | ||
2322 | errx(1, "failed to create SSL_CTX"); | ||
2323 | if ((ssl = SSL_new(ssl_ctx)) == NULL) | ||
2324 | errx(1, "failed to create SSL"); | ||
2325 | |||
2326 | if (!tls_extension_funcs(TLSEXT_TYPE_status_request, &client_funcs, | ||
2327 | &server_funcs)) | ||
2328 | errx(1, "failed to fetch ocsp funcs"); | ||
2329 | |||
2330 | if (client_funcs->needs(ssl, SSL_TLSEXT_MSG_CH)) { | ||
2331 | FAIL("client should not need TLSEXT_TYPE_status_request\n"); | ||
2332 | goto err; | ||
2333 | } | ||
2334 | SSL_set_tlsext_status_type(ssl, TLSEXT_STATUSTYPE_ocsp); | ||
2335 | |||
2336 | if (!client_funcs->needs(ssl, SSL_TLSEXT_MSG_CH)) { | ||
2337 | FAIL("client should need TLSEXT_TYPE_status_request\n"); | ||
2338 | goto err; | ||
2339 | } | ||
2340 | if (!client_funcs->build(ssl, SSL_TLSEXT_MSG_CH, &cbb)) { | ||
2341 | FAIL("client failed to build SNI\n"); | ||
2342 | goto err; | ||
2343 | } | ||
2344 | if (!CBB_finish(&cbb, &data, &dlen)) | ||
2345 | errx(1, "failed to finish CBB"); | ||
2346 | |||
2347 | if (dlen != sizeof(tls_ocsp_client_default)) { | ||
2348 | FAIL("got TLSEXT_TYPE_status_request client with length %zu, " | ||
2349 | "want length %zu\n", dlen, | ||
2350 | sizeof(tls_ocsp_client_default)); | ||
2351 | goto err; | ||
2352 | } | ||
2353 | if (memcmp(data, tls_ocsp_client_default, dlen) != 0) { | ||
2354 | FAIL("TLSEXT_TYPE_status_request client differs:\n"); | ||
2355 | fprintf(stderr, "received:\n"); | ||
2356 | hexdump(data, dlen); | ||
2357 | fprintf(stderr, "test data:\n"); | ||
2358 | hexdump(tls_ocsp_client_default, | ||
2359 | sizeof(tls_ocsp_client_default)); | ||
2360 | goto err; | ||
2361 | } | ||
2362 | CBS_init(&cbs, tls_ocsp_client_default, | ||
2363 | sizeof(tls_ocsp_client_default)); | ||
2364 | if (!server_funcs->process(ssl, SSL_TLSEXT_MSG_CH, &cbs, &alert)) { | ||
2365 | FAIL("failed to parse TLSEXT_TYPE_status_request client\n"); | ||
2366 | goto err; | ||
2367 | } | ||
2368 | if (CBS_len(&cbs) != 0) { | ||
2369 | FAIL("extension data remaining\n"); | ||
2370 | goto err; | ||
2371 | } | ||
2372 | |||
2373 | failure = 0; | ||
2374 | |||
2375 | err: | ||
2376 | CBB_cleanup(&cbb); | ||
2377 | SSL_CTX_free(ssl_ctx); | ||
2378 | SSL_free(ssl); | ||
2379 | free(data); | ||
2380 | |||
2381 | return (failure); | ||
2382 | } | ||
2383 | |||
2384 | static int | ||
2385 | test_tlsext_ocsp_server(void) | ||
2386 | { | ||
2387 | unsigned char *data = NULL; | ||
2388 | SSL_CTX *ssl_ctx = NULL; | ||
2389 | SSL *ssl = NULL; | ||
2390 | const struct tls_extension_funcs *client_funcs; | ||
2391 | const struct tls_extension_funcs *server_funcs; | ||
2392 | size_t dlen; | ||
2393 | int failure; | ||
2394 | CBB cbb; | ||
2395 | |||
2396 | failure = 1; | ||
2397 | |||
2398 | if (!CBB_init(&cbb, 0)) | ||
2399 | errx(1, "Failed to create CBB"); | ||
2400 | |||
2401 | if ((ssl_ctx = SSL_CTX_new(TLS_client_method())) == NULL) | ||
2402 | errx(1, "failed to create SSL_CTX"); | ||
2403 | if ((ssl = SSL_new(ssl_ctx)) == NULL) | ||
2404 | errx(1, "failed to create SSL"); | ||
2405 | |||
2406 | if (!tls_extension_funcs(TLSEXT_TYPE_status_request, &client_funcs, | ||
2407 | &server_funcs)) | ||
2408 | errx(1, "failed to fetch ocsp funcs"); | ||
2409 | |||
2410 | if (server_funcs->needs(ssl, SSL_TLSEXT_MSG_SH)) { | ||
2411 | FAIL("server should not need TLSEXT_TYPE_status_request\n"); | ||
2412 | goto err; | ||
2413 | } | ||
2414 | |||
2415 | ssl->tlsext_status_expected = 1; | ||
2416 | |||
2417 | if (!server_funcs->needs(ssl, SSL_TLSEXT_MSG_SH)) { | ||
2418 | FAIL("server should need TLSEXT_TYPE_status_request\n"); | ||
2419 | goto err; | ||
2420 | } | ||
2421 | if (!server_funcs->build(ssl, SSL_TLSEXT_MSG_SH, &cbb)) { | ||
2422 | FAIL("server failed to build TLSEXT_TYPE_status_request\n"); | ||
2423 | goto err; | ||
2424 | } | ||
2425 | |||
2426 | if (!CBB_finish(&cbb, &data, &dlen)) | ||
2427 | errx(1, "failed to finish CBB"); | ||
2428 | |||
2429 | failure = 0; | ||
2430 | |||
2431 | err: | ||
2432 | CBB_cleanup(&cbb); | ||
2433 | SSL_CTX_free(ssl_ctx); | ||
2434 | SSL_free(ssl); | ||
2435 | free(data); | ||
2436 | |||
2437 | return (failure); | ||
2438 | } | ||
2439 | |||
2440 | /* | ||
2441 | * Session ticket - RFC 5077 since no known implementations use 4507. | ||
2442 | * | ||
2443 | * Session tickets can be length 0 (special case) to 2^16-1. | ||
2444 | * | ||
2445 | * The state is encrypted by the server so it is opaque to the client. | ||
2446 | */ | ||
2447 | static uint8_t tlsext_sessionticket_hello_min[1]; | ||
2448 | static uint8_t tlsext_sessionticket_hello_max[65535]; | ||
2449 | |||
2450 | static int | ||
2451 | test_tlsext_sessionticket_client(void) | ||
2452 | { | ||
2453 | unsigned char *data = NULL; | ||
2454 | SSL_CTX *ssl_ctx = NULL; | ||
2455 | SSL *ssl = NULL; | ||
2456 | const struct tls_extension_funcs *client_funcs; | ||
2457 | const struct tls_extension_funcs *server_funcs; | ||
2458 | int failure; | ||
2459 | CBB cbb; | ||
2460 | size_t dlen; | ||
2461 | uint8_t dummy[1234]; | ||
2462 | |||
2463 | failure = 1; | ||
2464 | |||
2465 | if (!CBB_init(&cbb, 0)) | ||
2466 | errx(1, "Failed to create CBB"); | ||
2467 | |||
2468 | /* Create fake session tickets with random data. */ | ||
2469 | arc4random_buf(tlsext_sessionticket_hello_min, | ||
2470 | sizeof(tlsext_sessionticket_hello_min)); | ||
2471 | arc4random_buf(tlsext_sessionticket_hello_max, | ||
2472 | sizeof(tlsext_sessionticket_hello_max)); | ||
2473 | |||
2474 | if ((ssl_ctx = SSL_CTX_new(TLS_client_method())) == NULL) | ||
2475 | errx(1, "failed to create SSL_CTX"); | ||
2476 | if ((ssl = SSL_new(ssl_ctx)) == NULL) | ||
2477 | errx(1, "failed to create SSL"); | ||
2478 | |||
2479 | if (!tls_extension_funcs(TLSEXT_TYPE_session_ticket, &client_funcs, | ||
2480 | &server_funcs)) | ||
2481 | errx(1, "failed to fetch session ticket funcs"); | ||
2482 | |||
2483 | /* Should need a ticket by default. */ | ||
2484 | if (!client_funcs->needs(ssl, SSL_TLSEXT_MSG_CH)) { | ||
2485 | FAIL("client should need Sessionticket for default " | ||
2486 | "ciphers\n"); | ||
2487 | goto err; | ||
2488 | } | ||
2489 | |||
2490 | /* Test disabling tickets. */ | ||
2491 | if ((SSL_set_options(ssl, SSL_OP_NO_TICKET) & SSL_OP_NO_TICKET) == 0) { | ||
2492 | FAIL("Cannot disable tickets in the TLS connection\n"); | ||
2493 | goto err; | ||
2494 | } | ||
2495 | if (client_funcs->needs(ssl, SSL_TLSEXT_MSG_CH)) { | ||
2496 | FAIL("client should not need SessionTicket if it was disabled\n"); | ||
2497 | goto err; | ||
2498 | } | ||
2499 | |||
2500 | /* Test re-enabling tickets. */ | ||
2501 | if ((SSL_clear_options(ssl, SSL_OP_NO_TICKET) & SSL_OP_NO_TICKET) != 0) { | ||
2502 | FAIL("Cannot re-enable tickets in the TLS connection\n"); | ||
2503 | goto err; | ||
2504 | } | ||
2505 | if (!client_funcs->needs(ssl, SSL_TLSEXT_MSG_CH)) { | ||
2506 | FAIL("client should need SessionTicket if it was disabled\n"); | ||
2507 | goto err; | ||
2508 | } | ||
2509 | |||
2510 | /* Since we don't have a session, we should build an empty ticket. */ | ||
2511 | if (!client_funcs->build(ssl, SSL_TLSEXT_MSG_CH, &cbb)) { | ||
2512 | FAIL("Cannot build a ticket\n"); | ||
2513 | goto err; | ||
2514 | } | ||
2515 | if (!CBB_finish(&cbb, &data, &dlen)) { | ||
2516 | FAIL("Cannot finish CBB\n"); | ||
2517 | goto err; | ||
2518 | } | ||
2519 | if (dlen != 0) { | ||
2520 | FAIL("Expected 0 length but found %zu\n", dlen); | ||
2521 | goto err; | ||
2522 | } | ||
2523 | |||
2524 | CBB_cleanup(&cbb); | ||
2525 | if (!CBB_init(&cbb, 0)) | ||
2526 | errx(1, "Failed to create CBB"); | ||
2527 | free(data); | ||
2528 | data = NULL; | ||
2529 | |||
2530 | /* With a new session (but no ticket), we should still have 0 length */ | ||
2531 | if ((ssl->session = SSL_SESSION_new()) == NULL) | ||
2532 | errx(1, "failed to create session"); | ||
2533 | if (!client_funcs->needs(ssl, SSL_TLSEXT_MSG_CH)) { | ||
2534 | FAIL("Should still want a session ticket with a new session\n"); | ||
2535 | goto err; | ||
2536 | } | ||
2537 | if (!client_funcs->build(ssl, SSL_TLSEXT_MSG_CH, &cbb)) { | ||
2538 | FAIL("Cannot build a ticket\n"); | ||
2539 | goto err; | ||
2540 | } | ||
2541 | if (!CBB_finish(&cbb, &data, &dlen)) { | ||
2542 | FAIL("Cannot finish CBB\n"); | ||
2543 | goto err; | ||
2544 | } | ||
2545 | if (dlen != 0) { | ||
2546 | FAIL("Expected 0 length but found %zu\n", dlen); | ||
2547 | goto err; | ||
2548 | } | ||
2549 | |||
2550 | CBB_cleanup(&cbb); | ||
2551 | if (!CBB_init(&cbb, 0)) | ||
2552 | errx(1, "Failed to create CBB"); | ||
2553 | free(data); | ||
2554 | data = NULL; | ||
2555 | |||
2556 | /* With a new session (and ticket), we should use that ticket */ | ||
2557 | SSL_SESSION_free(ssl->session); | ||
2558 | if ((ssl->session = SSL_SESSION_new()) == NULL) | ||
2559 | errx(1, "failed to create session"); | ||
2560 | |||
2561 | arc4random_buf(&dummy, sizeof(dummy)); | ||
2562 | if ((ssl->session->tlsext_tick = malloc(sizeof(dummy))) == NULL) { | ||
2563 | errx(1, "failed to malloc"); | ||
2564 | } | ||
2565 | memcpy(ssl->session->tlsext_tick, dummy, sizeof(dummy)); | ||
2566 | ssl->session->tlsext_ticklen = sizeof(dummy); | ||
2567 | |||
2568 | if (!client_funcs->needs(ssl, SSL_TLSEXT_MSG_CH)) { | ||
2569 | FAIL("Should still want a session ticket with a new session\n"); | ||
2570 | goto err; | ||
2571 | } | ||
2572 | if (!client_funcs->build(ssl, SSL_TLSEXT_MSG_CH, &cbb)) { | ||
2573 | FAIL("Cannot build a ticket\n"); | ||
2574 | goto err; | ||
2575 | } | ||
2576 | if (!CBB_finish(&cbb, &data, &dlen)) { | ||
2577 | FAIL("Cannot finish CBB\n"); | ||
2578 | goto err; | ||
2579 | } | ||
2580 | if (dlen != sizeof(dummy)) { | ||
2581 | FAIL("Expected %zu length but found %zu\n", sizeof(dummy), dlen); | ||
2582 | goto err; | ||
2583 | } | ||
2584 | if (memcmp(data, dummy, dlen) != 0) { | ||
2585 | FAIL("server SNI differs:\n"); | ||
2586 | compare_data(data, dlen, | ||
2587 | dummy, sizeof(dummy)); | ||
2588 | goto err; | ||
2589 | } | ||
2590 | |||
2591 | CBB_cleanup(&cbb); | ||
2592 | if (!CBB_init(&cbb, 0)) | ||
2593 | errx(1, "Failed to create CBB"); | ||
2594 | free(data); | ||
2595 | data = NULL; | ||
2596 | free(ssl->session->tlsext_tick); | ||
2597 | ssl->session->tlsext_tick = NULL; | ||
2598 | ssl->session->tlsext_ticklen = 0; | ||
2599 | |||
2600 | /* | ||
2601 | * Send in NULL to disable session tickets at runtime without going | ||
2602 | * through SSL_set_options(). | ||
2603 | */ | ||
2604 | if (!SSL_set_session_ticket_ext(ssl, NULL, 0)) { | ||
2605 | FAIL("Could not set a NULL custom ticket\n"); | ||
2606 | goto err; | ||
2607 | } | ||
2608 | /* Should not need a ticket in this case */ | ||
2609 | if (client_funcs->needs(ssl, SSL_TLSEXT_MSG_CH)) { | ||
2610 | FAIL("Should not want to use session tickets with a NULL custom\n"); | ||
2611 | goto err; | ||
2612 | } | ||
2613 | |||
2614 | /* | ||
2615 | * If you want to remove the tlsext_session_ticket behavior, you have | ||
2616 | * to do it manually. | ||
2617 | */ | ||
2618 | free(ssl->tlsext_session_ticket); | ||
2619 | ssl->tlsext_session_ticket = NULL; | ||
2620 | |||
2621 | if (!client_funcs->needs(ssl, SSL_TLSEXT_MSG_CH)) { | ||
2622 | FAIL("Should need a session ticket again when the custom one is removed\n"); | ||
2623 | goto err; | ||
2624 | } | ||
2625 | |||
2626 | /* Test a custom session ticket (not recommended in practice) */ | ||
2627 | if (!SSL_set_session_ticket_ext(ssl, tlsext_sessionticket_hello_max, | ||
2628 | sizeof(tlsext_sessionticket_hello_max))) { | ||
2629 | FAIL("Should be able to set a custom ticket\n"); | ||
2630 | goto err; | ||
2631 | } | ||
2632 | if (!client_funcs->needs(ssl, SSL_TLSEXT_MSG_CH)) { | ||
2633 | FAIL("Should need a session ticket again when the custom one is not empty\n"); | ||
2634 | goto err; | ||
2635 | } | ||
2636 | if (!client_funcs->build(ssl, SSL_TLSEXT_MSG_CH, &cbb)) { | ||
2637 | FAIL("Cannot build a ticket with a max length random payload\n"); | ||
2638 | goto err; | ||
2639 | } | ||
2640 | if (!CBB_finish(&cbb, &data, &dlen)) { | ||
2641 | FAIL("Cannot finish CBB\n"); | ||
2642 | goto err; | ||
2643 | } | ||
2644 | if (dlen != sizeof(tlsext_sessionticket_hello_max)) { | ||
2645 | FAIL("Expected %zu length but found %zu\n", | ||
2646 | sizeof(tlsext_sessionticket_hello_max), dlen); | ||
2647 | goto err; | ||
2648 | } | ||
2649 | if (memcmp(data, tlsext_sessionticket_hello_max, | ||
2650 | sizeof(tlsext_sessionticket_hello_max)) != 0) { | ||
2651 | FAIL("Expected to get what we passed in\n"); | ||
2652 | compare_data(data, dlen, | ||
2653 | tlsext_sessionticket_hello_max, | ||
2654 | sizeof(tlsext_sessionticket_hello_max)); | ||
2655 | goto err; | ||
2656 | } | ||
2657 | |||
2658 | failure = 0; | ||
2659 | |||
2660 | err: | ||
2661 | CBB_cleanup(&cbb); | ||
2662 | SSL_CTX_free(ssl_ctx); | ||
2663 | SSL_free(ssl); | ||
2664 | free(data); | ||
2665 | |||
2666 | return (failure); | ||
2667 | } | ||
2668 | |||
2669 | |||
2670 | static int | ||
2671 | test_tlsext_sessionticket_server(void) | ||
2672 | { | ||
2673 | SSL_CTX *ssl_ctx = NULL; | ||
2674 | SSL *ssl = NULL; | ||
2675 | const struct tls_extension_funcs *client_funcs; | ||
2676 | const struct tls_extension_funcs *server_funcs; | ||
2677 | int failure; | ||
2678 | uint8_t *data = NULL; | ||
2679 | size_t dlen; | ||
2680 | CBB cbb; | ||
2681 | |||
2682 | failure = 1; | ||
2683 | |||
2684 | if (!CBB_init(&cbb, 0)) | ||
2685 | errx(1, "Failed to create CBB"); | ||
2686 | |||
2687 | if ((ssl_ctx = SSL_CTX_new(TLS_server_method())) == NULL) | ||
2688 | errx(1, "failed to create SSL_CTX"); | ||
2689 | if ((ssl = SSL_new(ssl_ctx)) == NULL) | ||
2690 | errx(1, "failed to create SSL"); | ||
2691 | |||
2692 | if (!tls_extension_funcs(TLSEXT_TYPE_session_ticket, &client_funcs, | ||
2693 | &server_funcs)) | ||
2694 | errx(1, "failed to fetch session ticket funcs"); | ||
2695 | |||
2696 | /* | ||
2697 | * By default, should not need a session ticket since the ticket | ||
2698 | * is not yet expected. | ||
2699 | */ | ||
2700 | if (server_funcs->needs(ssl, SSL_TLSEXT_MSG_SH)) { | ||
2701 | FAIL("server should not need SessionTicket by default\n"); | ||
2702 | goto err; | ||
2703 | } | ||
2704 | |||
2705 | /* Test disabling tickets. */ | ||
2706 | if ((SSL_set_options(ssl, SSL_OP_NO_TICKET) & SSL_OP_NO_TICKET) == 0) { | ||
2707 | FAIL("Cannot disable tickets in the TLS connection\n"); | ||
2708 | goto err; | ||
2709 | } | ||
2710 | if (server_funcs->needs(ssl, SSL_TLSEXT_MSG_SH)) { | ||
2711 | FAIL("server should not need SessionTicket if it was disabled\n"); | ||
2712 | goto err; | ||
2713 | } | ||
2714 | |||
2715 | /* Test re-enabling tickets. */ | ||
2716 | if ((SSL_clear_options(ssl, SSL_OP_NO_TICKET) & SSL_OP_NO_TICKET) != 0) { | ||
2717 | FAIL("Cannot re-enable tickets in the TLS connection\n"); | ||
2718 | goto err; | ||
2719 | } | ||
2720 | if (server_funcs->needs(ssl, SSL_TLSEXT_MSG_SH)) { | ||
2721 | FAIL("server should not need SessionTicket yet\n"); | ||
2722 | goto err; | ||
2723 | } | ||
2724 | |||
2725 | /* Set expected to require it. */ | ||
2726 | ssl->tlsext_ticket_expected = 1; | ||
2727 | if (!server_funcs->needs(ssl, SSL_TLSEXT_MSG_SH)) { | ||
2728 | FAIL("server should now be required for SessionTicket\n"); | ||
2729 | goto err; | ||
2730 | } | ||
2731 | |||
2732 | /* server hello's session ticket should always be 0 length payload. */ | ||
2733 | if (!server_funcs->build(ssl, SSL_TLSEXT_MSG_SH, &cbb)) { | ||
2734 | FAIL("Cannot build a ticket with a max length random payload\n"); | ||
2735 | goto err; | ||
2736 | } | ||
2737 | if (!CBB_finish(&cbb, &data, &dlen)) { | ||
2738 | FAIL("Cannot finish CBB\n"); | ||
2739 | goto err; | ||
2740 | } | ||
2741 | if (dlen != 0) { | ||
2742 | FAIL("Expected 0 length but found %zu\n", dlen); | ||
2743 | goto err; | ||
2744 | } | ||
2745 | |||
2746 | failure = 0; | ||
2747 | |||
2748 | err: | ||
2749 | CBB_cleanup(&cbb); | ||
2750 | SSL_CTX_free(ssl_ctx); | ||
2751 | SSL_free(ssl); | ||
2752 | free(data); | ||
2753 | |||
2754 | return (failure); | ||
2755 | } | ||
2756 | |||
2757 | #ifndef OPENSSL_NO_SRTP | ||
2758 | /* | ||
2759 | * Supported Secure Real-time Transport Protocol (RFC 5764 section 4.1.1) | ||
2760 | */ | ||
2761 | |||
2762 | /* Colon separated string values */ | ||
2763 | const char *tlsext_srtp_single_profile = "SRTP_AES128_CM_SHA1_80"; | ||
2764 | const char *tlsext_srtp_multiple_profiles = "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32"; | ||
2765 | |||
2766 | const char *tlsext_srtp_aes128cmsha80 = "SRTP_AES128_CM_SHA1_80"; | ||
2767 | const char *tlsext_srtp_aes128cmsha32 = "SRTP_AES128_CM_SHA1_32"; | ||
2768 | |||
2769 | const uint8_t tlsext_srtp_single[] = { | ||
2770 | /* SRTPProtectionProfile SRTPProtectionProfiles<2..2^16-1> */ | ||
2771 | 0x00, 0x02, /* len */ | ||
2772 | 0x00, 0x01, /* SRTP_AES128_CM_SHA1_80 */ | ||
2773 | 0x00 /* opaque srtp_mki<0..255> */ | ||
2774 | }; | ||
2775 | |||
2776 | const uint8_t tlsext_srtp_multiple[] = { | ||
2777 | /* SRTPProtectionProfile SRTPProtectionProfiles<2..2^16-1> */ | ||
2778 | 0x00, 0x04, /* len */ | ||
2779 | 0x00, 0x01, /* SRTP_AES128_CM_SHA1_80 */ | ||
2780 | 0x00, 0x02, /* SRTP_AES128_CM_SHA1_32 */ | ||
2781 | 0x00 /* opaque srtp_mki<0..255> */ | ||
2782 | }; | ||
2783 | |||
2784 | const uint8_t tlsext_srtp_multiple_invalid[] = { | ||
2785 | /* SRTPProtectionProfile SRTPProtectionProfiles<2..2^16-1> */ | ||
2786 | 0x00, 0x04, /* len */ | ||
2787 | 0x00, 0x08, /* arbitrary value not found in known profiles */ | ||
2788 | 0x00, 0x09, /* arbitrary value not found in known profiles */ | ||
2789 | 0x00 /* opaque srtp_mki<0..255> */ | ||
2790 | }; | ||
2791 | |||
2792 | const uint8_t tlsext_srtp_single_invalid[] = { | ||
2793 | /* SRTPProtectionProfile SRTPProtectionProfiles<2..2^16-1> */ | ||
2794 | 0x00, 0x02, /* len */ | ||
2795 | 0x00, 0x08, /* arbitrary value not found in known profiles */ | ||
2796 | 0x00 /* opaque srtp_mki<0..255> */ | ||
2797 | }; | ||
2798 | |||
2799 | const uint8_t tlsext_srtp_multiple_one_valid[] = { | ||
2800 | /* SRTPProtectionProfile SRTPProtectionProfiles<2..2^16-1> */ | ||
2801 | 0x00, 0x04, /* len */ | ||
2802 | 0x00, 0x08, /* arbitrary value not found in known profiles */ | ||
2803 | 0x00, 0x02, /* SRTP_AES128_CM_SHA1_32 */ | ||
2804 | 0x00 /* opaque srtp_mki<0..255> */ | ||
2805 | }; | ||
2806 | |||
2807 | static int | ||
2808 | test_tlsext_srtp_client(void) | ||
2809 | { | ||
2810 | SRTP_PROTECTION_PROFILE *prof; | ||
2811 | SSL_CTX *ssl_ctx = NULL; | ||
2812 | SSL *ssl = NULL; | ||
2813 | const struct tls_extension_funcs *client_funcs; | ||
2814 | const struct tls_extension_funcs *server_funcs; | ||
2815 | uint8_t *data = NULL; | ||
2816 | CBB cbb; | ||
2817 | CBS cbs; | ||
2818 | int failure, alert; | ||
2819 | size_t dlen; | ||
2820 | |||
2821 | failure = 1; | ||
2822 | |||
2823 | if (!CBB_init(&cbb, 0)) | ||
2824 | errx(1, "Failed to create CBB"); | ||
2825 | |||
2826 | /* SRTP is for DTLS */ | ||
2827 | if ((ssl_ctx = SSL_CTX_new(DTLSv1_client_method())) == NULL) | ||
2828 | errx(1, "failed to create SSL_CTX"); | ||
2829 | if ((ssl = SSL_new(ssl_ctx)) == NULL) | ||
2830 | errx(1, "failed to create SSL"); | ||
2831 | |||
2832 | if (!tls_extension_funcs(TLSEXT_TYPE_use_srtp, &client_funcs, | ||
2833 | &server_funcs)) | ||
2834 | errx(1, "failed to fetch srtp funcs"); | ||
2835 | |||
2836 | /* By default, we don't need this */ | ||
2837 | if (client_funcs->needs(ssl, SSL_TLSEXT_MSG_CH)) { | ||
2838 | FAIL("client should not need SRTP by default\n"); | ||
2839 | goto err; | ||
2840 | } | ||
2841 | |||
2842 | if (SSL_set_tlsext_use_srtp(ssl, tlsext_srtp_single_profile) != 0) { | ||
2843 | FAIL("should be able to set a single SRTP\n"); | ||
2844 | goto err; | ||
2845 | } | ||
2846 | if (!client_funcs->needs(ssl, SSL_TLSEXT_MSG_CH)) { | ||
2847 | FAIL("client should need SRTP\n"); | ||
2848 | goto err; | ||
2849 | } | ||
2850 | |||
2851 | /* Make sure we can build the client with a single profile. */ | ||
2852 | |||
2853 | if (!client_funcs->build(ssl, SSL_TLSEXT_MSG_CH, &cbb)) { | ||
2854 | FAIL("client failed to build SRTP\n"); | ||
2855 | goto err; | ||
2856 | } | ||
2857 | if (!CBB_finish(&cbb, &data, &dlen)) | ||
2858 | errx(1, "failed to finish CBB"); | ||
2859 | |||
2860 | if (dlen != sizeof(tlsext_srtp_single)) { | ||
2861 | FAIL("got client SRTP with length %zu, " | ||
2862 | "want length %zu\n", dlen, | ||
2863 | sizeof(tlsext_srtp_single)); | ||
2864 | compare_data(data, dlen, tlsext_srtp_single, | ||
2865 | sizeof(tlsext_srtp_single)); | ||
2866 | goto err; | ||
2867 | } | ||
2868 | if (memcmp(data, tlsext_srtp_single, dlen) != 0) { | ||
2869 | FAIL("client SRTP differs:\n"); | ||
2870 | compare_data(data, dlen, tlsext_srtp_single, | ||
2871 | sizeof(tlsext_srtp_single)); | ||
2872 | goto err; | ||
2873 | } | ||
2874 | |||
2875 | CBB_cleanup(&cbb); | ||
2876 | if (!CBB_init(&cbb, 0)) | ||
2877 | errx(1, "Failed to create CBB"); | ||
2878 | free(data); | ||
2879 | data = NULL; | ||
2880 | |||
2881 | /* Make sure we can parse the single profile. */ | ||
2882 | |||
2883 | if (SSL_get_selected_srtp_profile(ssl) != NULL) { | ||
2884 | FAIL("SRTP profile should not be set yet\n"); | ||
2885 | goto err; | ||
2886 | } | ||
2887 | |||
2888 | CBS_init(&cbs, tlsext_srtp_single, sizeof(tlsext_srtp_single)); | ||
2889 | if (!server_funcs->process(ssl, SSL_TLSEXT_MSG_CH, &cbs, &alert)) { | ||
2890 | FAIL("failed to parse SRTP\n"); | ||
2891 | goto err; | ||
2892 | } | ||
2893 | if (CBS_len(&cbs) != 0) { | ||
2894 | FAIL("extension data remaining\n"); | ||
2895 | goto err; | ||
2896 | } | ||
2897 | |||
2898 | if ((prof = SSL_get_selected_srtp_profile(ssl)) == NULL) { | ||
2899 | FAIL("SRTP profile should be set now\n"); | ||
2900 | goto err; | ||
2901 | } | ||
2902 | if (strcmp(prof->name, tlsext_srtp_aes128cmsha80) != 0) { | ||
2903 | FAIL("SRTP profile was not set properly\n"); | ||
2904 | goto err; | ||
2905 | } | ||
2906 | |||
2907 | if (!server_funcs->needs(ssl, SSL_TLSEXT_MSG_CH)) { | ||
2908 | FAIL("should send server extension when profile selected\n"); | ||
2909 | goto err; | ||
2910 | } | ||
2911 | |||
2912 | /* Make sure we can build the clienthello with multiple entries. */ | ||
2913 | |||
2914 | if (SSL_set_tlsext_use_srtp(ssl, tlsext_srtp_multiple_profiles) != 0) { | ||
2915 | FAIL("should be able to set SRTP to multiple profiles\n"); | ||
2916 | goto err; | ||
2917 | } | ||
2918 | if (!client_funcs->needs(ssl, SSL_TLSEXT_MSG_CH)) { | ||
2919 | FAIL("client should need SRTP by now\n"); | ||
2920 | goto err; | ||
2921 | } | ||
2922 | |||
2923 | if (!client_funcs->build(ssl, SSL_TLSEXT_MSG_CH, &cbb)) { | ||
2924 | FAIL("client failed to build SRTP\n"); | ||
2925 | goto err; | ||
2926 | } | ||
2927 | if (!CBB_finish(&cbb, &data, &dlen)) | ||
2928 | errx(1, "failed to finish CBB"); | ||
2929 | |||
2930 | if (dlen != sizeof(tlsext_srtp_multiple)) { | ||
2931 | FAIL("got client SRTP with length %zu, " | ||
2932 | "want length %zu\n", dlen, | ||
2933 | sizeof(tlsext_srtp_multiple)); | ||
2934 | compare_data(data, dlen, tlsext_srtp_multiple, | ||
2935 | sizeof(tlsext_srtp_multiple)); | ||
2936 | goto err; | ||
2937 | } | ||
2938 | if (memcmp(data, tlsext_srtp_multiple, dlen) != 0) { | ||
2939 | FAIL("client SRTP differs:\n"); | ||
2940 | compare_data(data, dlen, tlsext_srtp_multiple, | ||
2941 | sizeof(tlsext_srtp_multiple)); | ||
2942 | goto err; | ||
2943 | } | ||
2944 | |||
2945 | CBB_cleanup(&cbb); | ||
2946 | if (!CBB_init(&cbb, 0)) | ||
2947 | errx(1, "Failed to create CBB"); | ||
2948 | free(data); | ||
2949 | data = NULL; | ||
2950 | |||
2951 | /* Make sure we can parse multiple profiles (selects server preferred) */ | ||
2952 | |||
2953 | ssl->srtp_profile = NULL; | ||
2954 | |||
2955 | CBS_init(&cbs, tlsext_srtp_multiple, | ||
2956 | sizeof(tlsext_srtp_multiple)); | ||
2957 | if (!server_funcs->process(ssl, SSL_TLSEXT_MSG_CH, &cbs, &alert)) { | ||
2958 | FAIL("failed to parse SRTP\n"); | ||
2959 | goto err; | ||
2960 | } | ||
2961 | if (CBS_len(&cbs) != 0) { | ||
2962 | FAIL("extension data remaining\n"); | ||
2963 | goto err; | ||
2964 | } | ||
2965 | |||
2966 | if ((prof = SSL_get_selected_srtp_profile(ssl)) == NULL) { | ||
2967 | FAIL("SRTP profile should be set now\n"); | ||
2968 | goto err; | ||
2969 | } | ||
2970 | if (strcmp(prof->name, tlsext_srtp_aes128cmsha80) != 0) { | ||
2971 | FAIL("SRTP profile was not set properly\n"); | ||
2972 | goto err; | ||
2973 | } | ||
2974 | |||
2975 | if (!server_funcs->needs(ssl, SSL_TLSEXT_MSG_CH)) { | ||
2976 | FAIL("should send server extension when profile selected\n"); | ||
2977 | goto err; | ||
2978 | } | ||
2979 | |||
2980 | /* | ||
2981 | * Make sure we can parse the clienthello with multiple entries | ||
2982 | * where one is unknown. | ||
2983 | */ | ||
2984 | ssl->srtp_profile = NULL; | ||
2985 | |||
2986 | CBS_init(&cbs, tlsext_srtp_multiple_one_valid, | ||
2987 | sizeof(tlsext_srtp_multiple_one_valid)); | ||
2988 | if (!server_funcs->process(ssl, SSL_TLSEXT_MSG_CH, &cbs, &alert)) { | ||
2989 | FAIL("failed to parse SRTP\n"); | ||
2990 | goto err; | ||
2991 | } | ||
2992 | if (CBS_len(&cbs) != 0) { | ||
2993 | FAIL("extension data remaining\n"); | ||
2994 | goto err; | ||
2995 | } | ||
2996 | |||
2997 | if ((prof = SSL_get_selected_srtp_profile(ssl)) == NULL) { | ||
2998 | FAIL("SRTP profile should be set now\n"); | ||
2999 | goto err; | ||
3000 | } | ||
3001 | if (strcmp(prof->name, tlsext_srtp_aes128cmsha32) != 0) { | ||
3002 | FAIL("SRTP profile was not set properly\n"); | ||
3003 | goto err; | ||
3004 | } | ||
3005 | |||
3006 | if (!server_funcs->needs(ssl, SSL_TLSEXT_MSG_CH)) { | ||
3007 | FAIL("should send server extension when profile selected\n"); | ||
3008 | goto err; | ||
3009 | } | ||
3010 | |||
3011 | /* Make sure we fall back to negotiated when none work. */ | ||
3012 | |||
3013 | ssl->srtp_profile = NULL; | ||
3014 | |||
3015 | CBS_init(&cbs, tlsext_srtp_multiple_invalid, | ||
3016 | sizeof(tlsext_srtp_multiple_invalid)); | ||
3017 | if (!server_funcs->process(ssl, SSL_TLSEXT_MSG_CH, &cbs, &alert)) { | ||
3018 | FAIL("should be able to fall back to negotiated\n"); | ||
3019 | goto err; | ||
3020 | } | ||
3021 | if (CBS_len(&cbs) != 0) { | ||
3022 | FAIL("extension data remaining\n"); | ||
3023 | goto err; | ||
3024 | } | ||
3025 | |||
3026 | /* If we fallback, the server should NOT send the extension. */ | ||
3027 | if (SSL_get_selected_srtp_profile(ssl) != NULL) { | ||
3028 | FAIL("should not have selected a profile when none found\n"); | ||
3029 | goto err; | ||
3030 | } | ||
3031 | if (server_funcs->needs(ssl, SSL_TLSEXT_MSG_CH)) { | ||
3032 | FAIL("should not send server tlsext when no profile found\n"); | ||
3033 | goto err; | ||
3034 | } | ||
3035 | |||
3036 | failure = 0; | ||
3037 | |||
3038 | err: | ||
3039 | CBB_cleanup(&cbb); | ||
3040 | SSL_CTX_free(ssl_ctx); | ||
3041 | SSL_free(ssl); | ||
3042 | free(data); | ||
3043 | |||
3044 | return (failure); | ||
3045 | } | ||
3046 | |||
3047 | static int | ||
3048 | test_tlsext_srtp_server(void) | ||
3049 | { | ||
3050 | const SRTP_PROTECTION_PROFILE *prof; | ||
3051 | SSL_CTX *ssl_ctx = NULL; | ||
3052 | SSL *ssl = NULL; | ||
3053 | const struct tls_extension_funcs *client_funcs; | ||
3054 | const struct tls_extension_funcs *server_funcs; | ||
3055 | uint8_t *data = NULL; | ||
3056 | CBB cbb; | ||
3057 | CBS cbs; | ||
3058 | int failure, alert; | ||
3059 | size_t dlen; | ||
3060 | |||
3061 | failure = 1; | ||
3062 | |||
3063 | if (!CBB_init(&cbb, 0)) | ||
3064 | errx(1, "Failed to create CBB"); | ||
3065 | |||
3066 | /* SRTP is for DTLS */ | ||
3067 | if ((ssl_ctx = SSL_CTX_new(DTLSv1_client_method())) == NULL) | ||
3068 | errx(1, "failed to create SSL_CTX"); | ||
3069 | if ((ssl = SSL_new(ssl_ctx)) == NULL) | ||
3070 | errx(1, "failed to create SSL"); | ||
3071 | |||
3072 | if (!tls_extension_funcs(TLSEXT_TYPE_use_srtp, &client_funcs, | ||
3073 | &server_funcs)) | ||
3074 | errx(1, "failed to fetch srtp funcs"); | ||
3075 | |||
3076 | /* By default, we don't need this */ | ||
3077 | if (server_funcs->needs(ssl, SSL_TLSEXT_MSG_SH)) { | ||
3078 | FAIL("server should not need SRTP by default\n"); | ||
3079 | goto err; | ||
3080 | } | ||
3081 | |||
3082 | if (srtp_find_profile_by_name(tlsext_srtp_aes128cmsha80, &prof, | ||
3083 | strlen(tlsext_srtp_aes128cmsha80))) { | ||
3084 | FAIL("should be able to find the given profile\n"); | ||
3085 | goto err; | ||
3086 | } | ||
3087 | ssl->srtp_profile = prof; | ||
3088 | if (!server_funcs->needs(ssl, SSL_TLSEXT_MSG_SH)) { | ||
3089 | FAIL("server should need SRTP by now\n"); | ||
3090 | goto err; | ||
3091 | } | ||
3092 | |||
3093 | /* Make sure we can build the server with a single profile. */ | ||
3094 | |||
3095 | if (!server_funcs->build(ssl, SSL_TLSEXT_MSG_SH, &cbb)) { | ||
3096 | FAIL("server failed to build SRTP\n"); | ||
3097 | goto err; | ||
3098 | } | ||
3099 | if (!CBB_finish(&cbb, &data, &dlen)) | ||
3100 | errx(1, "failed to finish CBB"); | ||
3101 | |||
3102 | if (dlen != sizeof(tlsext_srtp_single)) { | ||
3103 | FAIL("got server SRTP with length %zu, " | ||
3104 | "want length %zu\n", dlen, | ||
3105 | sizeof(tlsext_srtp_single)); | ||
3106 | compare_data(data, dlen, tlsext_srtp_single, | ||
3107 | sizeof(tlsext_srtp_single)); | ||
3108 | goto err; | ||
3109 | } | ||
3110 | if (memcmp(data, tlsext_srtp_single, dlen) != 0) { | ||
3111 | FAIL("server SRTP differs:\n"); | ||
3112 | compare_data(data, dlen, tlsext_srtp_single, | ||
3113 | sizeof(tlsext_srtp_single)); | ||
3114 | goto err; | ||
3115 | } | ||
3116 | |||
3117 | CBB_cleanup(&cbb); | ||
3118 | if (!CBB_init(&cbb, 0)) | ||
3119 | errx(1, "Failed to create CBB"); | ||
3120 | free(data); | ||
3121 | data = NULL; | ||
3122 | |||
3123 | /* Make sure we can parse the single profile. */ | ||
3124 | ssl->srtp_profile = NULL; | ||
3125 | |||
3126 | if (SSL_get_selected_srtp_profile(ssl) != NULL) { | ||
3127 | FAIL("SRTP profile should not be set yet\n"); | ||
3128 | goto err; | ||
3129 | } | ||
3130 | |||
3131 | /* Setup the environment as if a client sent a list of profiles. */ | ||
3132 | if (SSL_set_tlsext_use_srtp(ssl, tlsext_srtp_multiple_profiles) != 0) { | ||
3133 | FAIL("should be able to set multiple profiles in SRTP\n"); | ||
3134 | goto err; | ||
3135 | } | ||
3136 | |||
3137 | CBS_init(&cbs, tlsext_srtp_single, sizeof(tlsext_srtp_single)); | ||
3138 | if (!client_funcs->process(ssl, SSL_TLSEXT_MSG_SH, &cbs, &alert)) { | ||
3139 | FAIL("failed to parse SRTP\n"); | ||
3140 | goto err; | ||
3141 | } | ||
3142 | if (CBS_len(&cbs) != 0) { | ||
3143 | FAIL("extension data remaining\n"); | ||
3144 | goto err; | ||
3145 | } | ||
3146 | |||
3147 | if ((prof = SSL_get_selected_srtp_profile(ssl)) == NULL) { | ||
3148 | FAIL("SRTP profile should be set now\n"); | ||
3149 | goto err; | ||
3150 | } | ||
3151 | if (strcmp(prof->name, tlsext_srtp_aes128cmsha80) != 0) { | ||
3152 | FAIL("SRTP profile was not set properly\n"); | ||
3153 | goto err; | ||
3154 | } | ||
3155 | |||
3156 | /* Make sure we cannot parse multiple profiles */ | ||
3157 | ssl->srtp_profile = NULL; | ||
3158 | |||
3159 | CBS_init(&cbs, tlsext_srtp_multiple, | ||
3160 | sizeof(tlsext_srtp_multiple)); | ||
3161 | if (client_funcs->process(ssl, SSL_TLSEXT_MSG_SH, &cbs, &alert)) { | ||
3162 | FAIL("should not find multiple entries from the server\n"); | ||
3163 | goto err; | ||
3164 | } | ||
3165 | |||
3166 | /* Make sure we cannot parse a server with unknown profile */ | ||
3167 | ssl->srtp_profile = NULL; | ||
3168 | |||
3169 | CBS_init(&cbs, tlsext_srtp_single_invalid, | ||
3170 | sizeof(tlsext_srtp_single_invalid)); | ||
3171 | if (client_funcs->process(ssl, SSL_TLSEXT_MSG_SH, &cbs, &alert)) { | ||
3172 | FAIL("should not be able to parse this\n"); | ||
3173 | goto err; | ||
3174 | } | ||
3175 | |||
3176 | failure = 0; | ||
3177 | |||
3178 | err: | ||
3179 | CBB_cleanup(&cbb); | ||
3180 | SSL_CTX_free(ssl_ctx); | ||
3181 | SSL_free(ssl); | ||
3182 | free(data); | ||
3183 | |||
3184 | return (failure); | ||
3185 | } | ||
3186 | #endif /* OPENSSL_NO_SRTP */ | ||
3187 | |||
3188 | static const unsigned char tlsext_clienthello_default[] = { | ||
3189 | 0x00, 0x34, 0x00, 0x0a, 0x00, 0x0a, 0x00, 0x08, | ||
3190 | 0x00, 0x1d, 0x00, 0x17, 0x00, 0x18, 0x00, 0x19, | ||
3191 | 0x00, 0x0b, 0x00, 0x02, 0x01, 0x00, 0x00, 0x23, | ||
3192 | 0x00, 0x00, 0x00, 0x0d, 0x00, 0x18, 0x00, 0x16, | ||
3193 | 0x08, 0x06, 0x06, 0x01, 0x06, 0x03, 0x08, 0x05, | ||
3194 | 0x05, 0x01, 0x05, 0x03, 0x08, 0x04, 0x04, 0x01, | ||
3195 | 0x04, 0x03, 0x02, 0x01, 0x02, 0x03, | ||
3196 | }; | ||
3197 | |||
3198 | /* An empty array is an incomplete type and sizeof() is undefined. */ | ||
3199 | static const unsigned char tlsext_clienthello_disabled[] = { | ||
3200 | 0x00, | ||
3201 | }; | ||
3202 | static size_t tlsext_clienthello_disabled_len = 0; | ||
3203 | |||
3204 | static int | ||
3205 | test_tlsext_clienthello_build(void) | ||
3206 | { | ||
3207 | unsigned char *data = NULL; | ||
3208 | SSL_CTX *ssl_ctx = NULL; | ||
3209 | SSL *ssl = NULL; | ||
3210 | const struct tls_extension_funcs *client_funcs; | ||
3211 | const struct tls_extension_funcs *server_funcs; | ||
3212 | size_t dlen; | ||
3213 | int failure; | ||
3214 | CBB cbb; | ||
3215 | |||
3216 | failure = 1; | ||
3217 | |||
3218 | if (!CBB_init(&cbb, 0)) | ||
3219 | errx(1, "failed to create CBB"); | ||
3220 | |||
3221 | if ((ssl_ctx = SSL_CTX_new(TLS_client_method())) == NULL) { | ||
3222 | FAIL("failed to create SSL_CTX"); | ||
3223 | goto err; | ||
3224 | } | ||
3225 | |||
3226 | if ((ssl = SSL_new(ssl_ctx)) == NULL) { | ||
3227 | FAIL("failed to create SSL"); | ||
3228 | goto err; | ||
3229 | } | ||
3230 | |||
3231 | if (!tlsext_linearize_build_order(ssl)) { | ||
3232 | FAIL("failed to linearize build order"); | ||
3233 | goto err; | ||
3234 | } | ||
3235 | |||
3236 | if (!tls_extension_funcs(TLSEXT_TYPE_supported_versions, &client_funcs, | ||
3237 | &server_funcs)) | ||
3238 | errx(1, "failed to fetch supported versions funcs"); | ||
3239 | |||
3240 | ssl->s3->hs.our_min_tls_version = TLS1_VERSION; | ||
3241 | ssl->s3->hs.our_max_tls_version = TLS1_2_VERSION; | ||
3242 | |||
3243 | if (!tlsext_client_build(ssl, SSL_TLSEXT_MSG_CH, &cbb)) { | ||
3244 | FAIL("failed to build clienthello extensions\n"); | ||
3245 | goto err; | ||
3246 | } | ||
3247 | if (!CBB_finish(&cbb, &data, &dlen)) { | ||
3248 | FAIL("failed to finish CBB"); | ||
3249 | goto err; | ||
3250 | } | ||
3251 | |||
3252 | if (dlen != sizeof(tlsext_clienthello_default)) { | ||
3253 | FAIL("got clienthello extensions with length %zu, " | ||
3254 | "want length %zu\n", dlen, | ||
3255 | sizeof(tlsext_clienthello_default)); | ||
3256 | compare_data(data, dlen, tlsext_clienthello_default, | ||
3257 | sizeof(tlsext_clienthello_default)); | ||
3258 | goto err; | ||
3259 | } | ||
3260 | if (memcmp(data, tlsext_clienthello_default, dlen) != 0) { | ||
3261 | FAIL("clienthello extensions differs:\n"); | ||
3262 | compare_data(data, dlen, tlsext_clienthello_default, | ||
3263 | sizeof(tlsext_clienthello_default)); | ||
3264 | goto err; | ||
3265 | } | ||
3266 | |||
3267 | free(data); | ||
3268 | data = NULL; | ||
3269 | CBB_cleanup(&cbb); | ||
3270 | if (!CBB_init(&cbb, 0)) | ||
3271 | errx(1, "Failed to create CBB"); | ||
3272 | |||
3273 | /* Switch to TLSv1.1, disable EC ciphers and session tickets. */ | ||
3274 | ssl->s3->hs.our_max_tls_version = TLS1_1_VERSION; | ||
3275 | if (!SSL_set_cipher_list(ssl, "TLSv1.2:!ECDHE:!ECDSA")) { | ||
3276 | FAIL("failed to set cipher list\n"); | ||
3277 | goto err; | ||
3278 | } | ||
3279 | if ((SSL_set_options(ssl, SSL_OP_NO_TICKET) & SSL_OP_NO_TICKET) == 0) { | ||
3280 | FAIL("failed to disable session tickets\n"); | ||
3281 | goto err; | ||
3282 | } | ||
3283 | |||
3284 | if (!tlsext_client_build(ssl, SSL_TLSEXT_MSG_CH, &cbb)) { | ||
3285 | FAIL("failed to build clienthello extensions\n"); | ||
3286 | goto err; | ||
3287 | } | ||
3288 | if (!CBB_finish(&cbb, &data, &dlen)) { | ||
3289 | FAIL("failed to finish CBB"); | ||
3290 | goto err; | ||
3291 | } | ||
3292 | |||
3293 | if (dlen != tlsext_clienthello_disabled_len) { | ||
3294 | FAIL("got clienthello extensions with length %zu, " | ||
3295 | "want length %zu\n", dlen, | ||
3296 | tlsext_clienthello_disabled_len); | ||
3297 | compare_data(data, dlen, tlsext_clienthello_disabled, | ||
3298 | tlsext_clienthello_disabled_len); | ||
3299 | goto err; | ||
3300 | } | ||
3301 | if (memcmp(data, tlsext_clienthello_disabled, dlen) != 0) { | ||
3302 | FAIL("clienthello extensions differs:\n"); | ||
3303 | compare_data(data, dlen, tlsext_clienthello_disabled, | ||
3304 | tlsext_clienthello_disabled_len); | ||
3305 | goto err; | ||
3306 | } | ||
3307 | |||
3308 | failure = 0; | ||
3309 | |||
3310 | err: | ||
3311 | CBB_cleanup(&cbb); | ||
3312 | SSL_CTX_free(ssl_ctx); | ||
3313 | SSL_free(ssl); | ||
3314 | free(data); | ||
3315 | |||
3316 | return (failure); | ||
3317 | } | ||
3318 | |||
3319 | unsigned char tlsext_serverhello_default[] = { | ||
3320 | 0x00, 0x06, 0x00, 0x2b, 0x00, 0x02, 0x03, 0x04, | ||
3321 | }; | ||
3322 | |||
3323 | unsigned char tlsext_serverhello_enabled[] = { | ||
3324 | 0x00, 0x10, 0x00, 0x2b, 0x00, 0x02, 0x03, 0x04, | ||
3325 | 0x00, 0x0b, 0x00, 0x02, 0x01, 0x00, 0x00, 0x23, | ||
3326 | 0x00, 0x00, | ||
3327 | }; | ||
3328 | |||
3329 | static int | ||
3330 | test_tlsext_serverhello_build(void) | ||
3331 | { | ||
3332 | unsigned char *data = NULL; | ||
3333 | SSL_CTX *ssl_ctx = NULL; | ||
3334 | SSL *ssl = NULL; | ||
3335 | size_t dlen; | ||
3336 | int failure; | ||
3337 | CBB cbb; | ||
3338 | |||
3339 | failure = 1; | ||
3340 | |||
3341 | if (!CBB_init(&cbb, 0)) | ||
3342 | errx(1, "failed to create CBB"); | ||
3343 | |||
3344 | if ((ssl_ctx = SSL_CTX_new(TLS_server_method())) == NULL) { | ||
3345 | FAIL("failed to create SSL_CTX"); | ||
3346 | goto err; | ||
3347 | } | ||
3348 | if ((ssl = SSL_new(ssl_ctx)) == NULL) { | ||
3349 | FAIL("failed to create SSL"); | ||
3350 | goto err; | ||
3351 | } | ||
3352 | if (!tlsext_linearize_build_order(ssl)) { | ||
3353 | FAIL("failed to linearize build order"); | ||
3354 | goto err; | ||
3355 | } | ||
3356 | if ((ssl->session = SSL_SESSION_new()) == NULL) { | ||
3357 | FAIL("failed to create session"); | ||
3358 | goto err; | ||
3359 | } | ||
3360 | |||
3361 | ssl->s3->hs.our_max_tls_version = TLS1_3_VERSION; | ||
3362 | ssl->s3->hs.negotiated_tls_version = TLS1_3_VERSION; | ||
3363 | ssl->s3->hs.cipher = ssl3_get_cipher_by_value(0x003c); | ||
3364 | |||
3365 | if (!tlsext_server_build(ssl, SSL_TLSEXT_MSG_SH, &cbb)) { | ||
3366 | FAIL("failed to build serverhello extensions\n"); | ||
3367 | goto err; | ||
3368 | } | ||
3369 | if (!CBB_finish(&cbb, &data, &dlen)) { | ||
3370 | FAIL("failed to finish CBB"); | ||
3371 | goto err; | ||
3372 | } | ||
3373 | |||
3374 | if (dlen != sizeof(tlsext_serverhello_default)) { | ||
3375 | FAIL("got serverhello extensions with length %zu, " | ||
3376 | "want length %zu\n", dlen, | ||
3377 | sizeof(tlsext_serverhello_default)); | ||
3378 | compare_data(data, dlen, tlsext_serverhello_default, | ||
3379 | sizeof(tlsext_serverhello_default)); | ||
3380 | goto err; | ||
3381 | } | ||
3382 | if (memcmp(data, tlsext_serverhello_default, dlen) != 0) { | ||
3383 | FAIL("serverhello extensions differs:\n"); | ||
3384 | compare_data(data, dlen, tlsext_serverhello_default, | ||
3385 | sizeof(tlsext_serverhello_default)); | ||
3386 | goto err; | ||
3387 | } | ||
3388 | |||
3389 | CBB_cleanup(&cbb); | ||
3390 | free(data); | ||
3391 | data = NULL; | ||
3392 | if (!CBB_init(&cbb, 0)) | ||
3393 | errx(1, "Failed to create CBB"); | ||
3394 | |||
3395 | /* Turn a few things on so we get extensions... */ | ||
3396 | ssl->s3->send_connection_binding = 1; | ||
3397 | ssl->s3->hs.cipher = ssl3_get_cipher_by_value(0xc027); | ||
3398 | ssl->tlsext_status_expected = 1; | ||
3399 | ssl->tlsext_ticket_expected = 1; | ||
3400 | if ((ssl->session->tlsext_ecpointformatlist = malloc(1)) == NULL) { | ||
3401 | FAIL("malloc failed"); | ||
3402 | goto err; | ||
3403 | } | ||
3404 | ssl->session->tlsext_ecpointformatlist_length = 1; | ||
3405 | ssl->session->tlsext_ecpointformatlist[0] = | ||
3406 | TLSEXT_ECPOINTFORMAT_uncompressed; | ||
3407 | |||
3408 | if (!tlsext_server_build(ssl, SSL_TLSEXT_MSG_SH, &cbb)) { | ||
3409 | FAIL("failed to build serverhello extensions\n"); | ||
3410 | goto err; | ||
3411 | } | ||
3412 | if (!CBB_finish(&cbb, &data, &dlen)) { | ||
3413 | FAIL("failed to finish CBB"); | ||
3414 | goto err; | ||
3415 | } | ||
3416 | |||
3417 | if (dlen != sizeof(tlsext_serverhello_enabled)) { | ||
3418 | FAIL("got serverhello extensions with length %zu, " | ||
3419 | "want length %zu\n", dlen, | ||
3420 | sizeof(tlsext_serverhello_enabled)); | ||
3421 | compare_data(data, dlen, tlsext_serverhello_enabled, | ||
3422 | sizeof(tlsext_serverhello_enabled)); | ||
3423 | goto err; | ||
3424 | } | ||
3425 | if (memcmp(data, tlsext_serverhello_enabled, dlen) != 0) { | ||
3426 | FAIL("serverhello extensions differs:\n"); | ||
3427 | compare_data(data, dlen, tlsext_serverhello_enabled, | ||
3428 | sizeof(tlsext_serverhello_enabled)); | ||
3429 | goto err; | ||
3430 | } | ||
3431 | |||
3432 | failure = 0; | ||
3433 | |||
3434 | err: | ||
3435 | CBB_cleanup(&cbb); | ||
3436 | SSL_CTX_free(ssl_ctx); | ||
3437 | SSL_free(ssl); | ||
3438 | free(data); | ||
3439 | |||
3440 | return (failure); | ||
3441 | } | ||
3442 | |||
3443 | const unsigned char tlsext_versions_client[] = { | ||
3444 | 0x08, 0x03, 0x04, 0x03, 0x03, 0x03, | ||
3445 | 0x02, 0x03, 0x01, | ||
3446 | }; | ||
3447 | |||
3448 | const unsigned char tlsext_versions_server[] = { | ||
3449 | 0x03, 0x04, | ||
3450 | }; | ||
3451 | |||
3452 | static int | ||
3453 | test_tlsext_versions_client(void) | ||
3454 | { | ||
3455 | unsigned char *data = NULL; | ||
3456 | SSL_CTX *ssl_ctx = NULL; | ||
3457 | SSL *ssl = NULL; | ||
3458 | const struct tls_extension_funcs *client_funcs; | ||
3459 | const struct tls_extension_funcs *server_funcs; | ||
3460 | int failure; | ||
3461 | size_t dlen; | ||
3462 | int alert; | ||
3463 | CBB cbb; | ||
3464 | CBS cbs; | ||
3465 | |||
3466 | failure = 1; | ||
3467 | |||
3468 | if (!CBB_init(&cbb, 0)) | ||
3469 | errx(1, "Failed to create CBB"); | ||
3470 | |||
3471 | if ((ssl_ctx = SSL_CTX_new(TLS_client_method())) == NULL) | ||
3472 | errx(1, "failed to create SSL_CTX"); | ||
3473 | if ((ssl = SSL_new(ssl_ctx)) == NULL) | ||
3474 | errx(1, "failed to create SSL"); | ||
3475 | |||
3476 | if (!tls_extension_funcs(TLSEXT_TYPE_supported_versions, &client_funcs, | ||
3477 | &server_funcs)) | ||
3478 | errx(1, "failed to fetch supported versions funcs"); | ||
3479 | |||
3480 | ssl->s3->hs.our_max_tls_version = TLS1_1_VERSION; | ||
3481 | |||
3482 | if (client_funcs->needs(ssl, SSL_TLSEXT_MSG_CH)) { | ||
3483 | FAIL("client should not need versions\n"); | ||
3484 | goto done; | ||
3485 | } | ||
3486 | |||
3487 | ssl->s3->hs.our_max_tls_version = TLS1_2_VERSION; | ||
3488 | |||
3489 | if (client_funcs->needs(ssl, SSL_TLSEXT_MSG_CH)) { | ||
3490 | FAIL("client should not need versions\n"); | ||
3491 | goto done; | ||
3492 | } | ||
3493 | |||
3494 | ssl->s3->hs.our_max_tls_version = TLS1_3_VERSION; | ||
3495 | |||
3496 | if (!client_funcs->needs(ssl, SSL_TLSEXT_MSG_CH)) { | ||
3497 | FAIL("client should need versions\n"); | ||
3498 | goto done; | ||
3499 | } | ||
3500 | |||
3501 | ssl->s3->hs.our_min_tls_version = TLS1_VERSION; | ||
3502 | ssl->s3->hs.our_max_tls_version = TLS1_3_VERSION; | ||
3503 | |||
3504 | if (!client_funcs->build(ssl, SSL_TLSEXT_MSG_CH, &cbb)) { | ||
3505 | FAIL("client should have built versions\n"); | ||
3506 | goto done; | ||
3507 | } | ||
3508 | |||
3509 | if (!CBB_finish(&cbb, &data, &dlen)) { | ||
3510 | FAIL("failed to finish CBB\n"); | ||
3511 | goto done; | ||
3512 | } | ||
3513 | |||
3514 | if (dlen != sizeof(tlsext_versions_client)) { | ||
3515 | FAIL("got versions with length %zu, " | ||
3516 | "want length %zu\n", dlen, sizeof(tlsext_versions_client)); | ||
3517 | goto done; | ||
3518 | } | ||
3519 | |||
3520 | CBS_init(&cbs, data, dlen); | ||
3521 | if (!server_funcs->process(ssl, SSL_TLSEXT_MSG_CH, &cbs, &alert)) { | ||
3522 | FAIL("failed to parse client versions\n"); | ||
3523 | goto done; | ||
3524 | } | ||
3525 | if (CBS_len(&cbs) != 0) { | ||
3526 | FAIL("extension data remaining\n"); | ||
3527 | goto done; | ||
3528 | } | ||
3529 | |||
3530 | failure = 0; | ||
3531 | |||
3532 | done: | ||
3533 | CBB_cleanup(&cbb); | ||
3534 | SSL_CTX_free(ssl_ctx); | ||
3535 | SSL_free(ssl); | ||
3536 | free(data); | ||
3537 | |||
3538 | return (failure); | ||
3539 | } | ||
3540 | |||
3541 | static int | ||
3542 | test_tlsext_versions_server(void) | ||
3543 | { | ||
3544 | unsigned char *data = NULL; | ||
3545 | SSL_CTX *ssl_ctx = NULL; | ||
3546 | SSL *ssl = NULL; | ||
3547 | const struct tls_extension_funcs *client_funcs; | ||
3548 | const struct tls_extension_funcs *server_funcs; | ||
3549 | int failure; | ||
3550 | size_t dlen; | ||
3551 | int alert; | ||
3552 | CBB cbb; | ||
3553 | CBS cbs; | ||
3554 | |||
3555 | failure = 1; | ||
3556 | |||
3557 | if (!CBB_init(&cbb, 0)) | ||
3558 | errx(1, "Failed to create CBB"); | ||
3559 | |||
3560 | if ((ssl_ctx = SSL_CTX_new(TLS_client_method())) == NULL) | ||
3561 | errx(1, "failed to create SSL_CTX"); | ||
3562 | if ((ssl = SSL_new(ssl_ctx)) == NULL) | ||
3563 | errx(1, "failed to create SSL"); | ||
3564 | |||
3565 | if (!tls_extension_funcs(TLSEXT_TYPE_supported_versions, &client_funcs, | ||
3566 | &server_funcs)) | ||
3567 | errx(1, "failed to fetch supported versions funcs"); | ||
3568 | |||
3569 | ssl->s3->hs.negotiated_tls_version = TLS1_2_VERSION; | ||
3570 | |||
3571 | if (server_funcs->needs(ssl, SSL_TLSEXT_MSG_SH)) { | ||
3572 | FAIL("server should not need versions\n"); | ||
3573 | goto done; | ||
3574 | } | ||
3575 | |||
3576 | ssl->s3->hs.negotiated_tls_version = TLS1_3_VERSION; | ||
3577 | |||
3578 | if (!server_funcs->needs(ssl, SSL_TLSEXT_MSG_SH)) { | ||
3579 | FAIL("server should need versions\n"); | ||
3580 | goto done; | ||
3581 | } | ||
3582 | |||
3583 | if (!server_funcs->build(ssl, SSL_TLSEXT_MSG_SH, &cbb)) { | ||
3584 | FAIL("server should have built versions\n"); | ||
3585 | goto done; | ||
3586 | } | ||
3587 | |||
3588 | if (!CBB_finish(&cbb, &data, &dlen)) { | ||
3589 | FAIL("failed to finish CBB\n"); | ||
3590 | goto done; | ||
3591 | } | ||
3592 | |||
3593 | if (dlen != sizeof(tlsext_versions_server)) { | ||
3594 | FAIL("got versions with length %zu, " | ||
3595 | "want length %zu\n", dlen, sizeof(tlsext_versions_server)); | ||
3596 | goto done; | ||
3597 | } | ||
3598 | |||
3599 | CBS_init(&cbs, data, dlen); | ||
3600 | if (!client_funcs->process(ssl, SSL_TLSEXT_MSG_SH, &cbs, &alert)) { | ||
3601 | FAIL("failed to parse client versions\n"); | ||
3602 | goto done; | ||
3603 | } | ||
3604 | if (CBS_len(&cbs) != 0) { | ||
3605 | FAIL("extension data remaining\n"); | ||
3606 | goto done; | ||
3607 | } | ||
3608 | |||
3609 | failure = 0; | ||
3610 | |||
3611 | done: | ||
3612 | CBB_cleanup(&cbb); | ||
3613 | SSL_CTX_free(ssl_ctx); | ||
3614 | SSL_free(ssl); | ||
3615 | free(data); | ||
3616 | |||
3617 | return (failure); | ||
3618 | } | ||
3619 | |||
3620 | const unsigned char tlsext_keyshare_client[] = { | ||
3621 | 0x00, 0x24, 0x00, 0x1d, 0x00, 0x20, 0xba, 0x83, | ||
3622 | 0x2e, 0x4a, 0x18, 0xbe, 0x96, 0xd2, 0x71, 0x70, | ||
3623 | 0x18, 0x04, 0xf9, 0x9d, 0x76, 0x98, 0xef, 0xe8, | ||
3624 | 0x4f, 0x8b, 0x85, 0x41, 0xa4, 0xd9, 0x61, 0x57, | ||
3625 | 0xad, 0x5b, 0xa4, 0xe9, 0x8b, 0x6b, | ||
3626 | }; | ||
3627 | |||
3628 | const unsigned char tlsext_keyshare_server[] = { | ||
3629 | 0x00, 0x1d, 0x00, 0x20, 0xe5, 0xe8, 0x5a, 0xb9, | ||
3630 | 0x7e, 0x12, 0x62, 0xe3, 0xd8, 0x7f, 0x6e, 0x3c, | ||
3631 | 0xec, 0xa6, 0x8b, 0x99, 0x45, 0x77, 0x8e, 0x11, | ||
3632 | 0xb3, 0xb9, 0x12, 0xb6, 0xbe, 0x35, 0xca, 0x51, | ||
3633 | 0x76, 0x1e, 0xe8, 0x22 | ||
3634 | }; | ||
3635 | |||
3636 | static int | ||
3637 | test_tlsext_keyshare_client(void) | ||
3638 | { | ||
3639 | unsigned char *data = NULL; | ||
3640 | SSL_CTX *ssl_ctx = NULL; | ||
3641 | SSL *ssl = NULL; | ||
3642 | const struct tls_extension_funcs *client_funcs; | ||
3643 | const struct tls_extension_funcs *server_funcs; | ||
3644 | int failure; | ||
3645 | size_t dlen; | ||
3646 | size_t idx; | ||
3647 | int alert; | ||
3648 | CBB cbb; | ||
3649 | CBS cbs; | ||
3650 | |||
3651 | failure = 1; | ||
3652 | |||
3653 | if (!CBB_init(&cbb, 0)) | ||
3654 | errx(1, "Failed to create CBB"); | ||
3655 | |||
3656 | if ((ssl_ctx = SSL_CTX_new(TLS_client_method())) == NULL) | ||
3657 | errx(1, "failed to create SSL_CTX"); | ||
3658 | if ((ssl = SSL_new(ssl_ctx)) == NULL) | ||
3659 | errx(1, "failed to create SSL"); | ||
3660 | |||
3661 | if (!tls_extension_funcs(TLSEXT_TYPE_key_share, &client_funcs, | ||
3662 | &server_funcs)) | ||
3663 | errx(1, "failed to fetch keyshare funcs"); | ||
3664 | |||
3665 | if ((ssl->s3->hs.key_share = | ||
3666 | tls_key_share_new_nid(NID_X25519)) == NULL) | ||
3667 | errx(1, "failed to create key share"); | ||
3668 | if (!tls_key_share_generate(ssl->s3->hs.key_share)) | ||
3669 | errx(1, "failed to generate key share"); | ||
3670 | |||
3671 | ssl->s3->hs.our_max_tls_version = TLS1_2_VERSION; | ||
3672 | if (client_funcs->needs(ssl, SSL_TLSEXT_MSG_CH)) { | ||
3673 | FAIL("client should not need keyshare\n"); | ||
3674 | goto done; | ||
3675 | } | ||
3676 | |||
3677 | ssl->s3->hs.our_max_tls_version = TLS1_3_VERSION; | ||
3678 | if (!client_funcs->needs(ssl, SSL_TLSEXT_MSG_CH)) { | ||
3679 | FAIL("client should need keyshare\n"); | ||
3680 | goto done; | ||
3681 | } | ||
3682 | |||
3683 | ssl->s3->hs.our_max_tls_version = TLS1_3_VERSION; | ||
3684 | if (!client_funcs->build(ssl, SSL_TLSEXT_MSG_CH, &cbb)) { | ||
3685 | FAIL("client should have built keyshare\n"); | ||
3686 | goto done; | ||
3687 | } | ||
3688 | |||
3689 | if (!CBB_finish(&cbb, &data, &dlen)) { | ||
3690 | FAIL("failed to finish CBB\n"); | ||
3691 | goto done; | ||
3692 | } | ||
3693 | |||
3694 | if (dlen != sizeof(tlsext_keyshare_client)) { | ||
3695 | FAIL("got client keyshare with length %zu, " | ||
3696 | "want length %zu\n", dlen, (size_t) sizeof(tlsext_keyshare_client)); | ||
3697 | goto done; | ||
3698 | } | ||
3699 | |||
3700 | ssl->version = TLS1_3_VERSION; | ||
3701 | |||
3702 | /* Fake up the ssl enough so the key share can process */ | ||
3703 | tls_key_share_free(ssl->s3->hs.key_share); | ||
3704 | ssl->session = SSL_SESSION_new(); | ||
3705 | if (ssl->session == NULL) { | ||
3706 | FAIL("malloc"); | ||
3707 | goto done; | ||
3708 | } | ||
3709 | memset(ssl->s3, 0, sizeof(*ssl->s3)); | ||
3710 | ssl->session->tlsext_supportedgroups = calloc(4, | ||
3711 | sizeof(unsigned short)); | ||
3712 | if (ssl->session->tlsext_supportedgroups == NULL) { | ||
3713 | FAIL("malloc"); | ||
3714 | goto done; | ||
3715 | } | ||
3716 | ssl->session->tlsext_supportedgroups[0] = 29; | ||
3717 | ssl->session->tlsext_supportedgroups[1] = 23; | ||
3718 | ssl->session->tlsext_supportedgroups[2] = 24; | ||
3719 | ssl->session->tlsext_supportedgroups[3] = 25; | ||
3720 | ssl->session->tlsext_supportedgroups_length = 4; | ||
3721 | tls_extension_find(TLSEXT_TYPE_supported_groups, &idx); | ||
3722 | ssl->s3->hs.extensions_processed |= (1 << idx); | ||
3723 | ssl->s3->hs.extensions_seen |= (1 << idx); | ||
3724 | ssl->s3->hs.our_max_tls_version = TLS1_3_VERSION; | ||
3725 | |||
3726 | /* | ||
3727 | * We should select the key share for group 29, when group 29 | ||
3728 | * is the most preferred group | ||
3729 | */ | ||
3730 | CBS_init(&cbs, data, dlen); | ||
3731 | if (!server_funcs->process(ssl, SSL_TLSEXT_MSG_CH, &cbs, &alert)) { | ||
3732 | FAIL("failed to process client keyshare\n"); | ||
3733 | goto done; | ||
3734 | } | ||
3735 | if (CBS_len(&cbs) != 0) { | ||
3736 | FAIL("extension data remaining\n"); | ||
3737 | goto done; | ||
3738 | } | ||
3739 | if (ssl->s3->hs.key_share == NULL) { | ||
3740 | FAIL("Did not select a key share"); | ||
3741 | goto done; | ||
3742 | } | ||
3743 | |||
3744 | /* | ||
3745 | * Pretend the client did not send the supported groups extension. We | ||
3746 | * should fail to process. | ||
3747 | */ | ||
3748 | ssl->s3->hs.extensions_seen = 0; | ||
3749 | tls_key_share_free(ssl->s3->hs.key_share); | ||
3750 | ssl->s3->hs.key_share = NULL; | ||
3751 | CBS_init(&cbs, data, dlen); | ||
3752 | if (server_funcs->process(ssl, SSL_TLSEXT_MSG_CH, &cbs, &alert)) { | ||
3753 | FAIL("Processed key share when supported groups not provided"); | ||
3754 | goto done; | ||
3755 | } | ||
3756 | ssl->s3->hs.extensions_seen |= (1 << idx); | ||
3757 | |||
3758 | /* | ||
3759 | * Pretend supported groups did not get processed. We should fail to | ||
3760 | * process | ||
3761 | */ | ||
3762 | ssl->s3->hs.extensions_processed = 0; | ||
3763 | ssl->s3->hs.key_share = NULL; | ||
3764 | CBS_init(&cbs, data, dlen); | ||
3765 | if (server_funcs->process(ssl, SSL_TLSEXT_MSG_CH, &cbs, &alert)) { | ||
3766 | FAIL("Processed key share when supported groups unprocesed"); | ||
3767 | goto done; | ||
3768 | } | ||
3769 | ssl->s3->hs.extensions_processed |= (1 << idx); | ||
3770 | |||
3771 | /* | ||
3772 | * Remove group 29 by making it 0xbeef, meaning 29 has not been sent in | ||
3773 | * supported groups. This should fail to process. | ||
3774 | */ | ||
3775 | ssl->session->tlsext_supportedgroups[0] = 0xbeef; | ||
3776 | ssl->s3->hs.key_share = NULL; | ||
3777 | CBS_init(&cbs, data, dlen); | ||
3778 | if (server_funcs->process(ssl, SSL_TLSEXT_MSG_CH, &cbs, &alert)) { | ||
3779 | FAIL("Processed key share with invalid group!"); | ||
3780 | goto done; | ||
3781 | } | ||
3782 | |||
3783 | /* | ||
3784 | * Make 29 least preferred, while server supports both 29 and 25. | ||
3785 | * Client key share is for 29 but it prefers 25. We should successfully | ||
3786 | * process, but should not select this key share. | ||
3787 | */ | ||
3788 | ssl->session->tlsext_supportedgroups[0] = 25; | ||
3789 | ssl->session->tlsext_supportedgroups[3] = 29; | ||
3790 | ssl->s3->hs.key_share = NULL; | ||
3791 | CBS_init(&cbs, data, dlen); | ||
3792 | if (!server_funcs->process(ssl, SSL_TLSEXT_MSG_CH, &cbs, &alert)) { | ||
3793 | FAIL("failed to process client keyshare\n"); | ||
3794 | goto done; | ||
3795 | } | ||
3796 | if (CBS_len(&cbs) != 0) { | ||
3797 | FAIL("extension data remaining\n"); | ||
3798 | goto done; | ||
3799 | } | ||
3800 | if (ssl->s3->hs.key_share != NULL) { | ||
3801 | FAIL("Selected a key share when I should not have!"); | ||
3802 | goto done; | ||
3803 | } | ||
3804 | ssl->session->tlsext_supportedgroups[0] = 29; | ||
3805 | ssl->session->tlsext_supportedgroups[3] = 25; | ||
3806 | |||
3807 | failure = 0; | ||
3808 | |||
3809 | done: | ||
3810 | CBB_cleanup(&cbb); | ||
3811 | SSL_CTX_free(ssl_ctx); | ||
3812 | SSL_free(ssl); | ||
3813 | free(data); | ||
3814 | |||
3815 | return (failure); | ||
3816 | } | ||
3817 | |||
3818 | static const uint8_t bogokey[] = { | ||
3819 | 0xe5, 0xe8, 0x5a, 0xb9, 0x7e, 0x12, 0x62, 0xe3, | ||
3820 | 0xd8, 0x7f, 0x6e, 0x3c, 0xec, 0xa6, 0x8b, 0x99, | ||
3821 | 0x45, 0x77, 0x8e, 0x11, 0xb3, 0xb9, 0x12, 0xb6, | ||
3822 | 0xbe, 0x35, 0xca, 0x51, 0x76, 0x1e, 0xe8, 0x22, | ||
3823 | }; | ||
3824 | |||
3825 | static int | ||
3826 | test_tlsext_keyshare_server(void) | ||
3827 | { | ||
3828 | unsigned char *data = NULL; | ||
3829 | SSL_CTX *ssl_ctx = NULL; | ||
3830 | SSL *ssl = NULL; | ||
3831 | const struct tls_extension_funcs *client_funcs; | ||
3832 | const struct tls_extension_funcs *server_funcs; | ||
3833 | int decode_error; | ||
3834 | int failure; | ||
3835 | size_t dlen, idx; | ||
3836 | int alert; | ||
3837 | CBB cbb; | ||
3838 | CBS cbs; | ||
3839 | |||
3840 | failure = 1; | ||
3841 | |||
3842 | if (!CBB_init(&cbb, 0)) | ||
3843 | errx(1, "Failed to create CBB"); | ||
3844 | |||
3845 | if ((ssl_ctx = SSL_CTX_new(TLS_client_method())) == NULL) | ||
3846 | errx(1, "failed to create SSL_CTX"); | ||
3847 | if ((ssl = SSL_new(ssl_ctx)) == NULL) | ||
3848 | errx(1, "failed to create SSL"); | ||
3849 | |||
3850 | if (!tls_extension_funcs(TLSEXT_TYPE_key_share, &client_funcs, | ||
3851 | &server_funcs)) | ||
3852 | errx(1, "failed to fetch keyshare funcs"); | ||
3853 | |||
3854 | ssl->s3->hs.negotiated_tls_version = TLS1_2_VERSION; | ||
3855 | if (server_funcs->needs(ssl, SSL_TLSEXT_MSG_SH)) { | ||
3856 | FAIL("server should not need keyshare\n"); | ||
3857 | goto done; | ||
3858 | } | ||
3859 | |||
3860 | ssl->s3->hs.negotiated_tls_version = TLS1_3_VERSION; | ||
3861 | if (server_funcs->needs(ssl, SSL_TLSEXT_MSG_SH)) { | ||
3862 | FAIL("client should not need keyshare\n"); | ||
3863 | goto done; | ||
3864 | } | ||
3865 | |||
3866 | if (tls_extension_find(TLSEXT_TYPE_key_share, &idx) == NULL) { | ||
3867 | FAIL("failed to find keyshare extension\n"); | ||
3868 | goto done; | ||
3869 | } | ||
3870 | ssl->s3->hs.extensions_seen |= (1 << idx); | ||
3871 | |||
3872 | if (!server_funcs->needs(ssl, SSL_TLSEXT_MSG_SH)) { | ||
3873 | FAIL("server should need keyshare\n"); | ||
3874 | goto done; | ||
3875 | } | ||
3876 | |||
3877 | if (server_funcs->build(ssl, SSL_TLSEXT_MSG_SH, &cbb)) { | ||
3878 | FAIL("server should not have built a keyshare response\n"); | ||
3879 | goto done; | ||
3880 | } | ||
3881 | |||
3882 | if ((ssl->s3->hs.key_share = | ||
3883 | tls_key_share_new_nid(NID_X25519)) == NULL) { | ||
3884 | FAIL("failed to create key share"); | ||
3885 | goto done; | ||
3886 | } | ||
3887 | |||
3888 | if (!tls_key_share_generate(ssl->s3->hs.key_share)) { | ||
3889 | FAIL("failed to generate key share"); | ||
3890 | goto done; | ||
3891 | } | ||
3892 | |||
3893 | CBS_init(&cbs, bogokey, sizeof(bogokey)); | ||
3894 | |||
3895 | if (!tls_key_share_peer_public(ssl->s3->hs.key_share, &cbs, | ||
3896 | &decode_error, NULL)) { | ||
3897 | FAIL("failed to load peer public key\n"); | ||
3898 | goto done; | ||
3899 | } | ||
3900 | |||
3901 | if (!server_funcs->build(ssl, SSL_TLSEXT_MSG_SH, &cbb)) { | ||
3902 | FAIL("server should be able to build a keyshare response\n"); | ||
3903 | goto done; | ||
3904 | } | ||
3905 | |||
3906 | if (!CBB_finish(&cbb, &data, &dlen)) { | ||
3907 | FAIL("failed to finish CBB\n"); | ||
3908 | goto done; | ||
3909 | } | ||
3910 | |||
3911 | if (dlen != sizeof(tlsext_keyshare_server)) { | ||
3912 | FAIL("got server keyshare with length %zu, " | ||
3913 | "want length %zu\n", dlen, sizeof(tlsext_keyshare_server)); | ||
3914 | goto done; | ||
3915 | } | ||
3916 | |||
3917 | tls_key_share_free(ssl->s3->hs.key_share); | ||
3918 | |||
3919 | if ((ssl->s3->hs.key_share = | ||
3920 | tls_key_share_new_nid(NID_X25519)) == NULL) { | ||
3921 | FAIL("failed to create key share"); | ||
3922 | goto done; | ||
3923 | } | ||
3924 | if (!tls_key_share_generate(ssl->s3->hs.key_share)) { | ||
3925 | FAIL("failed to generate key share"); | ||
3926 | goto done; | ||
3927 | } | ||
3928 | |||
3929 | CBS_init(&cbs, data, dlen); | ||
3930 | |||
3931 | if (!client_funcs->process(ssl, SSL_TLSEXT_MSG_SH, &cbs, &alert)) { | ||
3932 | FAIL("failed to parse server keyshare\n"); | ||
3933 | goto done; | ||
3934 | } | ||
3935 | |||
3936 | if (CBS_len(&cbs) != 0) { | ||
3937 | FAIL("extension data remaining\n"); | ||
3938 | goto done; | ||
3939 | } | ||
3940 | |||
3941 | failure = 0; | ||
3942 | |||
3943 | done: | ||
3944 | CBB_cleanup(&cbb); | ||
3945 | SSL_CTX_free(ssl_ctx); | ||
3946 | SSL_free(ssl); | ||
3947 | free(data); | ||
3948 | |||
3949 | return (failure); | ||
3950 | } | ||
3951 | |||
3952 | /* One day I hope to be the only Muppet in this codebase */ | ||
3953 | const uint8_t cookie[] = "\n" | ||
3954 | " (o)(o) \n" | ||
3955 | " m' 'm \n" | ||
3956 | " M -****- M \n" | ||
3957 | " 'm m' \n" | ||
3958 | " m''''''''''m \n" | ||
3959 | " M M BB \n"; | ||
3960 | |||
3961 | static int | ||
3962 | test_tlsext_cookie_client(void) | ||
3963 | { | ||
3964 | unsigned char *data = NULL; | ||
3965 | SSL_CTX *ssl_ctx = NULL; | ||
3966 | SSL *ssl = NULL; | ||
3967 | const struct tls_extension_funcs *client_funcs; | ||
3968 | const struct tls_extension_funcs *server_funcs; | ||
3969 | int failure; | ||
3970 | size_t dlen; | ||
3971 | int alert; | ||
3972 | CBB cbb; | ||
3973 | CBS cbs; | ||
3974 | |||
3975 | failure = 1; | ||
3976 | |||
3977 | if (!CBB_init(&cbb, 0)) | ||
3978 | errx(1, "Failed to create CBB"); | ||
3979 | |||
3980 | if ((ssl_ctx = SSL_CTX_new(TLS_client_method())) == NULL) | ||
3981 | errx(1, "failed to create SSL_CTX"); | ||
3982 | if ((ssl = SSL_new(ssl_ctx)) == NULL) | ||
3983 | errx(1, "failed to create SSL"); | ||
3984 | |||
3985 | if (!tls_extension_funcs(TLSEXT_TYPE_cookie, &client_funcs, | ||
3986 | &server_funcs)) | ||
3987 | errx(1, "failed to fetch cookie funcs"); | ||
3988 | |||
3989 | ssl->s3->hs.our_max_tls_version = TLS1_2_VERSION; | ||
3990 | if (client_funcs->needs(ssl, SSL_TLSEXT_MSG_CH)) { | ||
3991 | FAIL("client should not need cookie\n"); | ||
3992 | goto done; | ||
3993 | } | ||
3994 | |||
3995 | |||
3996 | ssl->s3->hs.our_max_tls_version = TLS1_3_VERSION; | ||
3997 | if (client_funcs->needs(ssl, SSL_TLSEXT_MSG_CH)) { | ||
3998 | FAIL("client should not need cookie\n"); | ||
3999 | goto done; | ||
4000 | } | ||
4001 | |||
4002 | /* Normally would be set by receiving a server cookie in an HRR */ | ||
4003 | ssl->s3->hs.tls13.cookie = strdup(cookie); | ||
4004 | ssl->s3->hs.tls13.cookie_len = strlen(cookie); | ||
4005 | |||
4006 | if (!client_funcs->needs(ssl, SSL_TLSEXT_MSG_CH)) { | ||
4007 | FAIL("client should need cookie\n"); | ||
4008 | goto done; | ||
4009 | } | ||
4010 | |||
4011 | if (!client_funcs->build(ssl, SSL_TLSEXT_MSG_CH, &cbb)) { | ||
4012 | FAIL("client should have built a cookie response\n"); | ||
4013 | goto done; | ||
4014 | } | ||
4015 | |||
4016 | if (!CBB_finish(&cbb, &data, &dlen)) { | ||
4017 | FAIL("failed to finish CBB\n"); | ||
4018 | goto done; | ||
4019 | } | ||
4020 | |||
4021 | if (dlen != strlen(cookie) + sizeof(uint16_t)) { | ||
4022 | FAIL("got cookie with length %zu, " | ||
4023 | "want length %zu\n", dlen, strlen(cookie) + | ||
4024 | sizeof(uint16_t)); | ||
4025 | goto done; | ||
4026 | } | ||
4027 | |||
4028 | CBS_init(&cbs, data, dlen); | ||
4029 | |||
4030 | /* Checks cookie against what's in the hs.tls13 */ | ||
4031 | if (!server_funcs->process(ssl, SSL_TLSEXT_MSG_CH, &cbs, &alert)) { | ||
4032 | FAIL("failed to parse client cookie\n"); | ||
4033 | goto done; | ||
4034 | } | ||
4035 | |||
4036 | if (CBS_len(&cbs) != 0) { | ||
4037 | FAIL("extension data remaining\n"); | ||
4038 | goto done; | ||
4039 | } | ||
4040 | |||
4041 | failure = 0; | ||
4042 | |||
4043 | done: | ||
4044 | CBB_cleanup(&cbb); | ||
4045 | SSL_CTX_free(ssl_ctx); | ||
4046 | SSL_free(ssl); | ||
4047 | free(data); | ||
4048 | |||
4049 | return (failure); | ||
4050 | } | ||
4051 | |||
4052 | static int | ||
4053 | test_tlsext_cookie_server(void) | ||
4054 | { | ||
4055 | unsigned char *data = NULL; | ||
4056 | SSL_CTX *ssl_ctx = NULL; | ||
4057 | SSL *ssl = NULL; | ||
4058 | const struct tls_extension_funcs *client_funcs; | ||
4059 | const struct tls_extension_funcs *server_funcs; | ||
4060 | int failure; | ||
4061 | size_t dlen; | ||
4062 | int alert; | ||
4063 | CBB cbb; | ||
4064 | CBS cbs; | ||
4065 | |||
4066 | failure = 1; | ||
4067 | |||
4068 | if (!CBB_init(&cbb, 0)) | ||
4069 | errx(1, "Failed to create CBB"); | ||
4070 | |||
4071 | if ((ssl_ctx = SSL_CTX_new(TLS_client_method())) == NULL) | ||
4072 | errx(1, "failed to create SSL_CTX"); | ||
4073 | if ((ssl = SSL_new(ssl_ctx)) == NULL) | ||
4074 | errx(1, "failed to create SSL"); | ||
4075 | |||
4076 | if (!tls_extension_funcs(TLSEXT_TYPE_cookie, &client_funcs, | ||
4077 | &server_funcs)) | ||
4078 | errx(1, "failed to fetch cookie funcs"); | ||
4079 | |||
4080 | ssl->s3->hs.our_max_tls_version = TLS1_2_VERSION; | ||
4081 | if (server_funcs->needs(ssl, SSL_TLSEXT_MSG_SH)) { | ||
4082 | FAIL("server should not need cookie\n"); | ||
4083 | goto done; | ||
4084 | } | ||
4085 | |||
4086 | ssl->s3->hs.our_max_tls_version = TLS1_3_VERSION; | ||
4087 | if (server_funcs->needs(ssl, SSL_TLSEXT_MSG_SH)) { | ||
4088 | FAIL("server should not need cookie\n"); | ||
4089 | goto done; | ||
4090 | } | ||
4091 | |||
4092 | /* Normally would be set by server before sending HRR */ | ||
4093 | ssl->s3->hs.tls13.cookie = strdup(cookie); | ||
4094 | ssl->s3->hs.tls13.cookie_len = strlen(cookie); | ||
4095 | |||
4096 | if (!server_funcs->needs(ssl, SSL_TLSEXT_MSG_HRR)) { | ||
4097 | FAIL("server should need cookie\n"); | ||
4098 | goto done; | ||
4099 | } | ||
4100 | |||
4101 | if (!server_funcs->build(ssl, SSL_TLSEXT_MSG_HRR, &cbb)) { | ||
4102 | FAIL("server should have built a cookie response\n"); | ||
4103 | goto done; | ||
4104 | } | ||
4105 | |||
4106 | if (!CBB_finish(&cbb, &data, &dlen)) { | ||
4107 | FAIL("failed to finish CBB\n"); | ||
4108 | goto done; | ||
4109 | } | ||
4110 | |||
4111 | if (dlen != strlen(cookie) + sizeof(uint16_t)) { | ||
4112 | FAIL("got cookie with length %zu, " | ||
4113 | "want length %zu\n", dlen, strlen(cookie) + | ||
4114 | sizeof(uint16_t)); | ||
4115 | goto done; | ||
4116 | } | ||
4117 | |||
4118 | CBS_init(&cbs, data, dlen); | ||
4119 | |||
4120 | if (client_funcs->process(ssl, SSL_TLSEXT_MSG_SH, &cbs, &alert)) { | ||
4121 | FAIL("client should not have parsed server cookie\n"); | ||
4122 | goto done; | ||
4123 | } | ||
4124 | |||
4125 | freezero(ssl->s3->hs.tls13.cookie, ssl->s3->hs.tls13.cookie_len); | ||
4126 | ssl->s3->hs.tls13.cookie = NULL; | ||
4127 | ssl->s3->hs.tls13.cookie_len = 0; | ||
4128 | |||
4129 | if (!client_funcs->process(ssl, SSL_TLSEXT_MSG_SH, &cbs, &alert)) { | ||
4130 | FAIL("failed to parse server cookie\n"); | ||
4131 | goto done; | ||
4132 | } | ||
4133 | |||
4134 | if (memcmp(cookie, ssl->s3->hs.tls13.cookie, | ||
4135 | ssl->s3->hs.tls13.cookie_len) != 0) { | ||
4136 | FAIL("parsed server cookie does not match sent cookie\n"); | ||
4137 | goto done; | ||
4138 | } | ||
4139 | |||
4140 | if (CBS_len(&cbs) != 0) { | ||
4141 | FAIL("extension data remaining\n"); | ||
4142 | goto done; | ||
4143 | } | ||
4144 | |||
4145 | failure = 0; | ||
4146 | |||
4147 | done: | ||
4148 | CBB_cleanup(&cbb); | ||
4149 | SSL_CTX_free(ssl_ctx); | ||
4150 | SSL_free(ssl); | ||
4151 | free(data); | ||
4152 | |||
4153 | return (failure); | ||
4154 | } | ||
4155 | |||
4156 | const uint8_t tlsext_default_psk_modes[] = { | ||
4157 | 0x01, 0x01, | ||
4158 | }; | ||
4159 | |||
4160 | const uint8_t tlsext_psk_only_mode[] = { | ||
4161 | 0x01, 0x00, | ||
4162 | }; | ||
4163 | |||
4164 | const uint8_t tlsext_psk_both_modes[] = { | ||
4165 | 0x02, 0x00, 0x01, | ||
4166 | }; | ||
4167 | |||
4168 | static int | ||
4169 | test_tlsext_psk_modes_client(void) | ||
4170 | { | ||
4171 | SSL_CTX *ssl_ctx = NULL; | ||
4172 | SSL *ssl = NULL; | ||
4173 | const struct tls_extension_funcs *client_funcs; | ||
4174 | const struct tls_extension_funcs *server_funcs; | ||
4175 | int failure; | ||
4176 | uint8_t *data = NULL; | ||
4177 | size_t dlen; | ||
4178 | CBB cbb; | ||
4179 | CBS cbs; | ||
4180 | int alert; | ||
4181 | |||
4182 | failure = 1; | ||
4183 | |||
4184 | if (!CBB_init(&cbb, 0)) | ||
4185 | errx(1, "Failed to create CBB"); | ||
4186 | |||
4187 | if ((ssl_ctx = SSL_CTX_new(TLS_client_method())) == NULL) | ||
4188 | errx(1, "failed to create SSL_CTX"); | ||
4189 | if ((ssl = SSL_new(ssl_ctx)) == NULL) | ||
4190 | errx(1, "failed to create SSL"); | ||
4191 | |||
4192 | if (!tls_extension_funcs(TLSEXT_TYPE_psk_kex_modes, &client_funcs, | ||
4193 | &server_funcs)) | ||
4194 | errx(1, "failed to fetch psk funcs"); | ||
4195 | |||
4196 | /* Disabled by default. */ | ||
4197 | if (client_funcs->needs(ssl, SSL_TLSEXT_MSG_CH)) { | ||
4198 | FAIL("client should not need psk kex modes by default\n"); | ||
4199 | goto err; | ||
4200 | } | ||
4201 | |||
4202 | /* | ||
4203 | * Prerequisites: use_psk_dhe_ke flag is set and | ||
4204 | * our_max_tls_version >= TLSv1.3. | ||
4205 | */ | ||
4206 | |||
4207 | ssl->s3->hs.tls13.use_psk_dhe_ke = 1; | ||
4208 | ssl->s3->hs.our_max_tls_version = TLS1_2_VERSION; | ||
4209 | |||
4210 | if (client_funcs->needs(ssl, SSL_TLSEXT_MSG_CH)) { | ||
4211 | FAIL("client should not need psk kex modes with TLSv1.2\n"); | ||
4212 | goto err; | ||
4213 | } | ||
4214 | |||
4215 | ssl->s3->hs.tls13.use_psk_dhe_ke = 0; | ||
4216 | ssl->s3->hs.our_max_tls_version = TLS1_3_VERSION; | ||
4217 | |||
4218 | if (client_funcs->needs(ssl, SSL_TLSEXT_MSG_CH)) { | ||
4219 | FAIL("client should not need psk kex modes without " | ||
4220 | "use_psk_dhe_ke\n"); | ||
4221 | goto err; | ||
4222 | } | ||
4223 | |||
4224 | ssl->s3->hs.tls13.use_psk_dhe_ke = 1; | ||
4225 | ssl->s3->hs.our_max_tls_version = TLS1_3_VERSION; | ||
4226 | |||
4227 | if (!client_funcs->needs(ssl, SSL_TLSEXT_MSG_CH)) { | ||
4228 | FAIL("client should need psk kex modes with TLSv1.3\n"); | ||
4229 | goto err; | ||
4230 | } | ||
4231 | |||
4232 | /* Make sure we can build psk modes with DHE key establishment. */ | ||
4233 | |||
4234 | if (!client_funcs->build(ssl, SSL_TLSEXT_MSG_CH, &cbb)) { | ||
4235 | FAIL("client failed to build psk kex modes\n"); | ||
4236 | goto err; | ||
4237 | } | ||
4238 | |||
4239 | if (!CBB_finish(&cbb, &data, &dlen)) | ||
4240 | errx(1, "failed to finish psk kex CBB"); | ||
4241 | |||
4242 | if (dlen != sizeof(tlsext_default_psk_modes)) { | ||
4243 | FAIL("got client psk kex modes with length %zu, " | ||
4244 | "want length %zu\n", dlen, | ||
4245 | sizeof(tlsext_default_psk_modes)); | ||
4246 | compare_data(data, dlen, tlsext_default_psk_modes, | ||
4247 | sizeof(tlsext_default_psk_modes)); | ||
4248 | goto err; | ||
4249 | } | ||
4250 | if (memcmp(data, tlsext_default_psk_modes, dlen) != 0) { | ||
4251 | FAIL("client psk kex modes differ:\n"); | ||
4252 | compare_data(data, dlen, tlsext_default_psk_modes, | ||
4253 | sizeof(tlsext_default_psk_modes)); | ||
4254 | goto err; | ||
4255 | } | ||
4256 | |||
4257 | CBB_cleanup(&cbb); | ||
4258 | free(data); | ||
4259 | data = NULL; | ||
4260 | |||
4261 | /* | ||
4262 | * Make sure we can parse the default psk modes and that use_psk_dhe_ke | ||
4263 | * is set after parsing. | ||
4264 | */ | ||
4265 | |||
4266 | ssl->s3->hs.tls13.use_psk_dhe_ke = 0; | ||
4267 | |||
4268 | CBS_init(&cbs, tlsext_default_psk_modes, | ||
4269 | sizeof(tlsext_default_psk_modes)); | ||
4270 | if (!server_funcs->process(ssl, SSL_TLSEXT_MSG_CH, &cbs, &alert)) { | ||
4271 | FAIL("failed to parse psk kex modes\n"); | ||
4272 | goto err; | ||
4273 | } | ||
4274 | if (CBS_len(&cbs) != 0) { | ||
4275 | FAIL("extension data remaining\n"); | ||
4276 | goto err; | ||
4277 | } | ||
4278 | |||
4279 | if (ssl->s3->hs.tls13.use_psk_dhe_ke != 1) { | ||
4280 | FAIL("should have set use_psk_dhe_ke\n"); | ||
4281 | goto err; | ||
4282 | } | ||
4283 | |||
4284 | /* | ||
4285 | * Make sure we can parse the psk-only mode and that use_psk_dhe_ke | ||
4286 | * is still not set after parsing. | ||
4287 | */ | ||
4288 | |||
4289 | ssl->s3->hs.tls13.use_psk_dhe_ke = 0; | ||
4290 | |||
4291 | CBS_init(&cbs, tlsext_psk_only_mode, sizeof(tlsext_psk_only_mode)); | ||
4292 | if (!server_funcs->process(ssl, SSL_TLSEXT_MSG_CH, &cbs, &alert)) { | ||
4293 | FAIL("failed to parse psk kex modes\n"); | ||
4294 | goto err; | ||
4295 | } | ||
4296 | if (CBS_len(&cbs) != 0) { | ||
4297 | FAIL("extension data remaining\n"); | ||
4298 | goto err; | ||
4299 | } | ||
4300 | |||
4301 | if (ssl->s3->hs.tls13.use_psk_dhe_ke != 0) { | ||
4302 | FAIL("should not have set use_psk_dhe_ke\n"); | ||
4303 | goto err; | ||
4304 | } | ||
4305 | |||
4306 | /* | ||
4307 | * Make sure we can parse the extension indicating both modes and that | ||
4308 | * use_psk_dhe_ke is set after parsing. | ||
4309 | */ | ||
4310 | |||
4311 | ssl->s3->hs.tls13.use_psk_dhe_ke = 0; | ||
4312 | |||
4313 | CBS_init(&cbs, tlsext_psk_both_modes, sizeof(tlsext_psk_both_modes)); | ||
4314 | if (!server_funcs->process(ssl, SSL_TLSEXT_MSG_CH, &cbs, &alert)) { | ||
4315 | FAIL("failed to parse psk kex modes\n"); | ||
4316 | goto err; | ||
4317 | } | ||
4318 | if (CBS_len(&cbs) != 0) { | ||
4319 | FAIL("extension data remaining\n"); | ||
4320 | goto err; | ||
4321 | } | ||
4322 | |||
4323 | if (ssl->s3->hs.tls13.use_psk_dhe_ke != 1) { | ||
4324 | FAIL("should have set use_psk_dhe_ke\n"); | ||
4325 | goto err; | ||
4326 | } | ||
4327 | |||
4328 | failure = 0; | ||
4329 | |||
4330 | err: | ||
4331 | CBB_cleanup(&cbb); | ||
4332 | SSL_CTX_free(ssl_ctx); | ||
4333 | SSL_free(ssl); | ||
4334 | free(data); | ||
4335 | |||
4336 | return failure; | ||
4337 | } | ||
4338 | |||
4339 | static int | ||
4340 | test_tlsext_psk_modes_server(void) | ||
4341 | { | ||
4342 | SSL_CTX *ssl_ctx = NULL; | ||
4343 | SSL *ssl = NULL; | ||
4344 | const struct tls_extension_funcs *client_funcs; | ||
4345 | const struct tls_extension_funcs *server_funcs; | ||
4346 | int failure; | ||
4347 | |||
4348 | failure = 1; | ||
4349 | |||
4350 | if ((ssl_ctx = SSL_CTX_new(TLS_server_method())) == NULL) | ||
4351 | errx(1, "failed to create SSL_CTX"); | ||
4352 | if ((ssl = SSL_new(ssl_ctx)) == NULL) | ||
4353 | errx(1, "failed to create SSL"); | ||
4354 | |||
4355 | if (!tls_extension_funcs(TLSEXT_TYPE_psk_kex_modes, &client_funcs, | ||
4356 | &server_funcs)) | ||
4357 | errx(1, "failed to fetch psk funcs"); | ||
4358 | |||
4359 | if (server_funcs->needs(ssl, SSL_TLSEXT_MSG_SH)) { | ||
4360 | FAIL("server should not need psk kex modes\n"); | ||
4361 | goto err; | ||
4362 | } | ||
4363 | |||
4364 | failure = 0; | ||
4365 | |||
4366 | err: | ||
4367 | SSL_CTX_free(ssl_ctx); | ||
4368 | SSL_free(ssl); | ||
4369 | |||
4370 | return failure; | ||
4371 | } | ||
4372 | |||
4373 | struct tls_sni_test { | ||
4374 | const char *hostname; | ||
4375 | int is_ip; | ||
4376 | int valid; | ||
4377 | }; | ||
4378 | |||
4379 | static const struct tls_sni_test tls_sni_tests[] = { | ||
4380 | { | ||
4381 | .hostname = "openbsd.org", | ||
4382 | .valid = 1, | ||
4383 | }, | ||
4384 | { | ||
4385 | .hostname = "op3nbsd.org", | ||
4386 | .valid = 1, | ||
4387 | }, | ||
4388 | { | ||
4389 | .hostname = "org", | ||
4390 | .valid = 1, | ||
4391 | }, | ||
4392 | { | ||
4393 | .hostname = "3openbsd.com", | ||
4394 | .valid = 1, | ||
4395 | }, | ||
4396 | { | ||
4397 | .hostname = "3-0penb-d.c-m", | ||
4398 | .valid = 1, | ||
4399 | }, | ||
4400 | { | ||
4401 | .hostname = "a", | ||
4402 | .valid = 1, | ||
4403 | }, | ||
4404 | { | ||
4405 | .hostname = | ||
4406 | "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.com", | ||
4407 | .valid = 1, | ||
4408 | }, | ||
4409 | { | ||
4410 | .hostname = | ||
4411 | "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa." | ||
4412 | "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa." | ||
4413 | "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa." | ||
4414 | "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", | ||
4415 | .valid = 1, | ||
4416 | }, | ||
4417 | { | ||
4418 | .hostname = "openbsd.org.", | ||
4419 | .valid = 0, | ||
4420 | }, | ||
4421 | { | ||
4422 | .hostname = "openbsd..org", | ||
4423 | .valid = 0, | ||
4424 | }, | ||
4425 | { | ||
4426 | .hostname = "openbsd.org-", | ||
4427 | .valid = 0, | ||
4428 | }, | ||
4429 | { | ||
4430 | .hostname = | ||
4431 | "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.com", | ||
4432 | .valid = 0, | ||
4433 | }, | ||
4434 | { | ||
4435 | .hostname = | ||
4436 | "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa." | ||
4437 | "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa." | ||
4438 | "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa." | ||
4439 | "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.a", | ||
4440 | .valid = 0, | ||
4441 | }, | ||
4442 | { | ||
4443 | .hostname = "-p3nbsd.org", | ||
4444 | .valid = 0, | ||
4445 | }, | ||
4446 | { | ||
4447 | .hostname = "openbs-.org", | ||
4448 | .valid = 0, | ||
4449 | }, | ||
4450 | { | ||
4451 | .hostname = "openbsd\n.org", | ||
4452 | .valid = 0, | ||
4453 | }, | ||
4454 | { | ||
4455 | .hostname = "open_bsd.org", | ||
4456 | .valid = 0, | ||
4457 | }, | ||
4458 | { | ||
4459 | .hostname = "open\177bsd.org", | ||
4460 | .valid = 0, | ||
4461 | }, | ||
4462 | { | ||
4463 | .hostname = "open\255bsd.org", | ||
4464 | .valid = 0, | ||
4465 | }, | ||
4466 | { | ||
4467 | .hostname = "dead::beef", | ||
4468 | .is_ip = 1, | ||
4469 | .valid = 0, | ||
4470 | }, | ||
4471 | { | ||
4472 | .hostname = "192.168.0.1", | ||
4473 | .is_ip = 1, | ||
4474 | .valid = 0, | ||
4475 | }, | ||
4476 | }; | ||
4477 | |||
4478 | #define N_TLS_SNI_TESTS (sizeof(tls_sni_tests) / sizeof(*tls_sni_tests)) | ||
4479 | |||
4480 | static int | ||
4481 | test_tlsext_is_valid_hostname(const struct tls_sni_test *tst) | ||
4482 | { | ||
4483 | int failure; | ||
4484 | int is_ip; | ||
4485 | CBS cbs; | ||
4486 | |||
4487 | failure = 1; | ||
4488 | |||
4489 | CBS_init(&cbs, tst->hostname, strlen(tst->hostname)); | ||
4490 | if (tlsext_sni_is_valid_hostname(&cbs, &is_ip) != tst->valid) { | ||
4491 | if (tst->valid) { | ||
4492 | FAIL("Valid hostname '%s' rejected\n", | ||
4493 | tst->hostname); | ||
4494 | } else { | ||
4495 | FAIL("Invalid hostname '%s' accepted\n", | ||
4496 | tst->hostname); | ||
4497 | } | ||
4498 | goto done; | ||
4499 | } | ||
4500 | if (tst->is_ip != is_ip) { | ||
4501 | if (tst->is_ip) { | ||
4502 | FAIL("Hostname '%s' is an IP literal but not " | ||
4503 | "identified as one\n", tst->hostname); | ||
4504 | } else { | ||
4505 | FAIL("Hostname '%s' is not an IP literal but is " | ||
4506 | "identified as one\n", tst->hostname); | ||
4507 | } | ||
4508 | goto done; | ||
4509 | } | ||
4510 | |||
4511 | if (tst->valid) { | ||
4512 | CBS_init(&cbs, tst->hostname, | ||
4513 | strlen(tst->hostname) + 1); | ||
4514 | if (tlsext_sni_is_valid_hostname(&cbs, &is_ip)) { | ||
4515 | FAIL("hostname with NUL byte accepted\n"); | ||
4516 | goto done; | ||
4517 | } | ||
4518 | } | ||
4519 | |||
4520 | failure = 0; | ||
4521 | |||
4522 | done: | ||
4523 | |||
4524 | return failure; | ||
4525 | } | ||
4526 | |||
4527 | static int | ||
4528 | test_tlsext_valid_hostnames(void) | ||
4529 | { | ||
4530 | const struct tls_sni_test *tst; | ||
4531 | int failure = 0; | ||
4532 | size_t i; | ||
4533 | |||
4534 | for (i = 0; i < N_TLS_SNI_TESTS; i++) { | ||
4535 | tst = &tls_sni_tests[i]; | ||
4536 | failure |= test_tlsext_is_valid_hostname(tst); | ||
4537 | } | ||
4538 | |||
4539 | return failure; | ||
4540 | } | ||
4541 | |||
4542 | #define N_TLSEXT_RANDOMIZATION_TESTS 1000 | ||
4543 | |||
4544 | static int | ||
4545 | test_tlsext_check_extension_order(SSL *ssl) | ||
4546 | { | ||
4547 | const struct tls_extension *ext; | ||
4548 | uint16_t type; | ||
4549 | size_t alpn_idx, sni_idx; | ||
4550 | size_t i; | ||
4551 | |||
4552 | if (ssl->tlsext_build_order_len == 0) { | ||
4553 | FAIL("Unexpected zero build order length"); | ||
4554 | return 1; | ||
4555 | } | ||
4556 | |||
4557 | ext = ssl->tlsext_build_order[ssl->tlsext_build_order_len - 1]; | ||
4558 | if ((type = tls_extension_type(ext)) != TLSEXT_TYPE_psk) { | ||
4559 | FAIL("last extension is %u, want %u\n", type, TLSEXT_TYPE_psk); | ||
4560 | return 1; | ||
4561 | } | ||
4562 | |||
4563 | if (ssl->server) | ||
4564 | return 0; | ||
4565 | |||
4566 | alpn_idx = sni_idx = ssl->tlsext_build_order_len; | ||
4567 | for (i = 0; i < ssl->tlsext_build_order_len; i++) { | ||
4568 | ext = ssl->tlsext_build_order[i]; | ||
4569 | if (tls_extension_type(ext) == TLSEXT_TYPE_alpn) | ||
4570 | alpn_idx = i; | ||
4571 | if (tls_extension_type(ext) == TLSEXT_TYPE_server_name) | ||
4572 | sni_idx = i; | ||
4573 | } | ||
4574 | |||
4575 | if (alpn_idx == ssl->tlsext_build_order_len) { | ||
4576 | FAIL("could not find alpn extension\n"); | ||
4577 | return 1; | ||
4578 | } | ||
4579 | |||
4580 | if (sni_idx == ssl->tlsext_build_order_len) { | ||
4581 | FAIL("could not find alpn extension\n"); | ||
4582 | return 1; | ||
4583 | } | ||
4584 | |||
4585 | if (sni_idx >= alpn_idx) { | ||
4586 | FAIL("sni does not precede alpn: %zu >= %zu\n", | ||
4587 | sni_idx, alpn_idx); | ||
4588 | return 1; | ||
4589 | } | ||
4590 | |||
4591 | return 0; | ||
4592 | } | ||
4593 | |||
4594 | static int | ||
4595 | test_tlsext_randomized_extensions(SSL *ssl) | ||
4596 | { | ||
4597 | size_t i; | ||
4598 | int failed = 0; | ||
4599 | |||
4600 | for (i = 0; i < N_TLSEXT_RANDOMIZATION_TESTS; i++) { | ||
4601 | if (!tlsext_randomize_build_order(ssl)) | ||
4602 | errx(1, "failed to randomize extensions"); | ||
4603 | failed |= test_tlsext_check_extension_order(ssl); | ||
4604 | } | ||
4605 | |||
4606 | return failed; | ||
4607 | } | ||
4608 | |||
4609 | static int | ||
4610 | test_tlsext_extension_order(void) | ||
4611 | { | ||
4612 | SSL_CTX *ssl_ctx = NULL; | ||
4613 | SSL *ssl = NULL; | ||
4614 | int failure; | ||
4615 | |||
4616 | failure = 0; | ||
4617 | |||
4618 | if ((ssl_ctx = SSL_CTX_new(TLS_client_method())) == NULL) | ||
4619 | errx(1, "failed to create SSL_CTX"); | ||
4620 | if ((ssl = SSL_new(ssl_ctx)) == NULL) | ||
4621 | errx(1, "failed to create SSL"); | ||
4622 | |||
4623 | failure |= test_tlsext_randomized_extensions(ssl); | ||
4624 | |||
4625 | SSL_CTX_free(ssl_ctx); | ||
4626 | SSL_free(ssl); | ||
4627 | |||
4628 | if ((ssl_ctx = SSL_CTX_new(TLS_server_method())) == NULL) | ||
4629 | errx(1, "failed to create SSL_CTX"); | ||
4630 | if ((ssl = SSL_new(ssl_ctx)) == NULL) | ||
4631 | errx(1, "failed to create SSL"); | ||
4632 | |||
4633 | failure |= test_tlsext_randomized_extensions(ssl); | ||
4634 | |||
4635 | SSL_CTX_free(ssl_ctx); | ||
4636 | SSL_free(ssl); | ||
4637 | |||
4638 | return failure; | ||
4639 | } | ||
4640 | |||
4641 | int | ||
4642 | main(int argc, char **argv) | ||
4643 | { | ||
4644 | int failed = 0; | ||
4645 | |||
4646 | SSL_library_init(); | ||
4647 | SSL_load_error_strings(); | ||
4648 | |||
4649 | failed |= test_tlsext_alpn_client(); | ||
4650 | failed |= test_tlsext_alpn_server(); | ||
4651 | |||
4652 | failed |= test_tlsext_supportedgroups_client(); | ||
4653 | failed |= test_tlsext_supportedgroups_server(); | ||
4654 | |||
4655 | failed |= test_tlsext_ecpf_client(); | ||
4656 | failed |= test_tlsext_ecpf_server(); | ||
4657 | |||
4658 | failed |= test_tlsext_ri_client(); | ||
4659 | failed |= test_tlsext_ri_server(); | ||
4660 | |||
4661 | failed |= test_tlsext_sigalgs_client(); | ||
4662 | |||
4663 | failed |= test_tlsext_sni_client(); | ||
4664 | failed |= test_tlsext_sni_server(); | ||
4665 | |||
4666 | failed |= test_tlsext_ocsp_client(); | ||
4667 | failed |= test_tlsext_ocsp_server(); | ||
4668 | |||
4669 | failed |= test_tlsext_sessionticket_client(); | ||
4670 | failed |= test_tlsext_sessionticket_server(); | ||
4671 | |||
4672 | failed |= test_tlsext_versions_client(); | ||
4673 | failed |= test_tlsext_versions_server(); | ||
4674 | |||
4675 | failed |= test_tlsext_keyshare_client(); | ||
4676 | failed |= test_tlsext_keyshare_server(); | ||
4677 | |||
4678 | failed |= test_tlsext_cookie_client(); | ||
4679 | failed |= test_tlsext_cookie_server(); | ||
4680 | |||
4681 | #ifndef OPENSSL_NO_SRTP | ||
4682 | failed |= test_tlsext_srtp_client(); | ||
4683 | failed |= test_tlsext_srtp_server(); | ||
4684 | #else | ||
4685 | fprintf(stderr, "Skipping SRTP tests due to OPENSSL_NO_SRTP\n"); | ||
4686 | #endif | ||
4687 | |||
4688 | failed |= test_tlsext_psk_modes_client(); | ||
4689 | failed |= test_tlsext_psk_modes_server(); | ||
4690 | |||
4691 | failed |= test_tlsext_clienthello_build(); | ||
4692 | failed |= test_tlsext_serverhello_build(); | ||
4693 | |||
4694 | failed |= test_tlsext_valid_hostnames(); | ||
4695 | |||
4696 | failed |= test_tlsext_quic_transport_parameters_client(); | ||
4697 | failed |= test_tlsext_quic_transport_parameters_server(); | ||
4698 | |||
4699 | failed |= test_tlsext_extension_order(); | ||
4700 | |||
4701 | return (failed); | ||
4702 | } | ||
diff --git a/src/regress/lib/libssl/tlsfuzzer/Makefile b/src/regress/lib/libssl/tlsfuzzer/Makefile deleted file mode 100644 index f7d17c2b96..0000000000 --- a/src/regress/lib/libssl/tlsfuzzer/Makefile +++ /dev/null | |||
@@ -1,51 +0,0 @@ | |||
1 | # $OpenBSD: Makefile,v 1.7 2024/09/17 08:47:37 tb Exp $ | ||
2 | |||
3 | .if !exists(/usr/local/share/tlsfuzzer) | ||
4 | regress: | ||
5 | @echo package py3-tlsfuzzer is required for this regress | ||
6 | @echo SKIPPED | ||
7 | .else | ||
8 | |||
9 | REGRESS_TARGETS=regress-tlsfuzzer | ||
10 | |||
11 | localhost.key localhost.crt: | ||
12 | openssl req -x509 -newkey rsa -keyout localhost.key -out localhost.crt \ | ||
13 | -subj /CN=localhost -nodes -batch | ||
14 | |||
15 | certs: localhost.key localhost.crt | ||
16 | |||
17 | start-server: certs | ||
18 | openssl s_server -accept 4433 -groups X25519:P-256:P-521:P-384 \ | ||
19 | -key localhost.key -cert localhost.crt -www | ||
20 | |||
21 | CLEANFILES += localhost.key localhost.crt | ||
22 | |||
23 | PORT ?= 4433 | ||
24 | SLOW = -s | ||
25 | TIMING = # -t | ||
26 | VERBOSE = # -v | ||
27 | |||
28 | regress-tlsfuzzer: certs | ||
29 | python3 ${.CURDIR}/tlsfuzzer.py ${SLOW} ${TIMING} ${VERBOSE} | ||
30 | |||
31 | failing: certs | ||
32 | python3 ${.CURDIR}/tlsfuzzer.py -f ${SLOW} ${TIMING} ${VERBOSE} | ||
33 | |||
34 | |||
35 | port: certs | ||
36 | python3 ${.CURDIR}/tlsfuzzer.py ${SLOW} ${TIMING} ${VERBOSE} -p ${PORT} | ||
37 | |||
38 | list: | ||
39 | @python3 ${.CURDIR}/tlsfuzzer.py -l | ||
40 | |||
41 | list-failing: | ||
42 | @python3 ${.CURDIR}/tlsfuzzer.py -l -f | ||
43 | |||
44 | missing: | ||
45 | @python3 ${.CURDIR}/tlsfuzzer.py -m | ||
46 | |||
47 | .PHONY: all certs failing list list-failing missing port start-server | ||
48 | |||
49 | .endif | ||
50 | |||
51 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libssl/tlsfuzzer/tlsfuzzer.py b/src/regress/lib/libssl/tlsfuzzer/tlsfuzzer.py deleted file mode 100644 index 91aedad165..0000000000 --- a/src/regress/lib/libssl/tlsfuzzer/tlsfuzzer.py +++ /dev/null | |||
@@ -1,935 +0,0 @@ | |||
1 | # $OpenBSD: tlsfuzzer.py,v 1.56 2024/09/18 19:12:37 tb Exp $ | ||
2 | # | ||
3 | # Copyright (c) 2020 Theo Buehler <tb@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 | import getopt | ||
18 | import os | ||
19 | import subprocess | ||
20 | import sys | ||
21 | from timeit import default_timer as timer | ||
22 | |||
23 | tlsfuzzer_scriptdir = "/usr/local/share/tlsfuzzer/scripts/" | ||
24 | |||
25 | class Test: | ||
26 | """ | ||
27 | Represents a tlsfuzzer test script. | ||
28 | name: the script's name | ||
29 | args: arguments to feed to the script | ||
30 | tls12_args: override args for a TLSv1.2 server | ||
31 | tls13_args: override args for a TLSv1.3 server | ||
32 | |||
33 | XXX Add client cert support. | ||
34 | """ | ||
35 | def __init__(self, name="", args=[], tls12_args=[], tls13_args=[]): | ||
36 | self.name = name | ||
37 | self.tls12_args = args | ||
38 | self.tls13_args = args | ||
39 | if tls12_args: | ||
40 | self.tls12_args = tls12_args | ||
41 | if tls13_args: | ||
42 | self.tls13_args = tls13_args | ||
43 | |||
44 | def args(self, has_tls1_3: True): | ||
45 | if has_tls1_3: | ||
46 | return self.tls13_args | ||
47 | else: | ||
48 | return self.tls12_args | ||
49 | |||
50 | def __repr__(self): | ||
51 | return "<Test: %s tls12_args: %s tls13_args: %s>" % ( | ||
52 | self.name, self.tls12_args, self.tls13_args | ||
53 | ) | ||
54 | |||
55 | class TestGroup: | ||
56 | """ A group of Test objects to be run by TestRunner.""" | ||
57 | def __init__(self, title="Tests", tests=[]): | ||
58 | self.title = title | ||
59 | self.tests = tests | ||
60 | |||
61 | def __iter__(self): | ||
62 | return iter(self.tests) | ||
63 | |||
64 | # argument to pass to several tests | ||
65 | tls13_unsupported_ciphers = [ | ||
66 | "-e", "TLS 1.3 with ffdhe2048", | ||
67 | "-e", "TLS 1.3 with ffdhe3072", | ||
68 | "-e", "TLS 1.3 with x448", | ||
69 | ] | ||
70 | |||
71 | def substitute_alert(want, got): | ||
72 | return f"Expected alert description \"{want}\" " \ | ||
73 | + f"does not match received \"{got}\"" | ||
74 | |||
75 | # test-tls13-finished.py has 70 failing tests that expect a "decode_error" | ||
76 | # instead of the "decrypt_error" sent by tls13_server_finished_recv(). | ||
77 | # Both alerts appear to be reasonable in this context, so work around this | ||
78 | # in the test instead of the library. | ||
79 | def generate_test_tls13_finished_args(): | ||
80 | assertion = substitute_alert("decode_error", "decrypt_error"); | ||
81 | paddings = [ | ||
82 | ("TLS_AES_128_GCM_SHA256", 0, 1), | ||
83 | ("TLS_AES_128_GCM_SHA256", 0, 2), | ||
84 | ("TLS_AES_128_GCM_SHA256", 0, 4), | ||
85 | ("TLS_AES_128_GCM_SHA256", 0, 8), | ||
86 | ("TLS_AES_128_GCM_SHA256", 0, 16), | ||
87 | ("TLS_AES_128_GCM_SHA256", 0, 32), | ||
88 | ("TLS_AES_128_GCM_SHA256", 0, 48), | ||
89 | ("TLS_AES_128_GCM_SHA256", 0, 2**14-4-32), | ||
90 | ("TLS_AES_128_GCM_SHA256", 0, 0x20000), | ||
91 | ("TLS_AES_128_GCM_SHA256", 0, 0x30000), | ||
92 | ("TLS_AES_128_GCM_SHA256", 1, 0), | ||
93 | ("TLS_AES_128_GCM_SHA256", 2, 0), | ||
94 | ("TLS_AES_128_GCM_SHA256", 4, 0), | ||
95 | ("TLS_AES_128_GCM_SHA256", 8, 0), | ||
96 | ("TLS_AES_128_GCM_SHA256", 16, 0), | ||
97 | ("TLS_AES_128_GCM_SHA256", 32, 0), | ||
98 | ("TLS_AES_128_GCM_SHA256", 48, 0), | ||
99 | ("TLS_AES_128_GCM_SHA256", 2**14-4-32, 0), | ||
100 | ("TLS_AES_128_GCM_SHA256", 12, 0), | ||
101 | ("TLS_AES_128_GCM_SHA256", 1, 1), | ||
102 | ("TLS_AES_128_GCM_SHA256", 8, 8), | ||
103 | ("TLS_AES_256_GCM_SHA384", 0, 1), | ||
104 | ("TLS_AES_256_GCM_SHA384", 0, 2), | ||
105 | ("TLS_AES_256_GCM_SHA384", 0, 4), | ||
106 | ("TLS_AES_256_GCM_SHA384", 0, 8), | ||
107 | ("TLS_AES_256_GCM_SHA384", 0, 16), | ||
108 | ("TLS_AES_256_GCM_SHA384", 0, 32), | ||
109 | ("TLS_AES_256_GCM_SHA384", 0, 48), | ||
110 | ("TLS_AES_256_GCM_SHA384", 0, 2**14-4-48), | ||
111 | ("TLS_AES_256_GCM_SHA384", 0, 0x20000), | ||
112 | ("TLS_AES_256_GCM_SHA384", 0, 0x30000), | ||
113 | ("TLS_AES_256_GCM_SHA384", 0, 12), | ||
114 | ("TLS_AES_256_GCM_SHA384", 1, 0), | ||
115 | ("TLS_AES_256_GCM_SHA384", 2, 0), | ||
116 | ("TLS_AES_256_GCM_SHA384", 4, 0), | ||
117 | ("TLS_AES_256_GCM_SHA384", 8, 0), | ||
118 | ("TLS_AES_256_GCM_SHA384", 16, 0), | ||
119 | ("TLS_AES_256_GCM_SHA384", 32, 0), | ||
120 | ("TLS_AES_256_GCM_SHA384", 48, 0), | ||
121 | ("TLS_AES_256_GCM_SHA384", 2**14-4-48, 0), | ||
122 | ("TLS_AES_256_GCM_SHA384", 1, 1), | ||
123 | ("TLS_AES_256_GCM_SHA384", 8, 8), | ||
124 | ] | ||
125 | truncations = [ | ||
126 | ("TLS_AES_128_GCM_SHA256", 0, -1), | ||
127 | ("TLS_AES_128_GCM_SHA256", 0, -2), | ||
128 | ("TLS_AES_128_GCM_SHA256", 0, -4), | ||
129 | ("TLS_AES_128_GCM_SHA256", 0, -8), | ||
130 | ("TLS_AES_128_GCM_SHA256", 0, -16), | ||
131 | ("TLS_AES_128_GCM_SHA256", 0, -32), | ||
132 | ("TLS_AES_128_GCM_SHA256", 0, 12), | ||
133 | ("TLS_AES_128_GCM_SHA256", 1, None), | ||
134 | ("TLS_AES_128_GCM_SHA256", 2, None), | ||
135 | ("TLS_AES_128_GCM_SHA256", 4, None), | ||
136 | ("TLS_AES_128_GCM_SHA256", 8, None), | ||
137 | ("TLS_AES_128_GCM_SHA256", 16, None), | ||
138 | ("TLS_AES_128_GCM_SHA256", 32, None), | ||
139 | ("TLS_AES_256_GCM_SHA384", 0, -1), | ||
140 | ("TLS_AES_256_GCM_SHA384", 0, -2), | ||
141 | ("TLS_AES_256_GCM_SHA384", 0, -4), | ||
142 | ("TLS_AES_256_GCM_SHA384", 0, -8), | ||
143 | ("TLS_AES_256_GCM_SHA384", 0, -16), | ||
144 | ("TLS_AES_256_GCM_SHA384", 0, -32), | ||
145 | ("TLS_AES_256_GCM_SHA384", 0, 12), | ||
146 | ("TLS_AES_256_GCM_SHA384", 1, None), | ||
147 | ("TLS_AES_256_GCM_SHA384", 2, None), | ||
148 | ("TLS_AES_256_GCM_SHA384", 4, None), | ||
149 | ("TLS_AES_256_GCM_SHA384", 8, None), | ||
150 | ("TLS_AES_256_GCM_SHA384", 16, None), | ||
151 | ("TLS_AES_256_GCM_SHA384", 32, None), | ||
152 | ] | ||
153 | |||
154 | args = [ | ||
155 | "-x", "empty - cipher TLS_AES_128_GCM_SHA256", "-X", assertion, | ||
156 | "-x", "empty - cipher TLS_AES_256_GCM_SHA384", "-X", assertion, | ||
157 | ] | ||
158 | padding_fmt = "padding - cipher %s, pad_byte 0, pad_left %d, pad_right %d" | ||
159 | for padding in paddings: | ||
160 | args += ["-x", padding_fmt % padding, "-X", assertion] | ||
161 | truncation_fmt = "truncation - cipher %s, start %d, end %s" | ||
162 | for truncation in truncations: | ||
163 | args += ["-x", truncation_fmt % truncation, "-X", assertion] | ||
164 | return args | ||
165 | |||
166 | tls13_tests = TestGroup("TLSv1.3 tests", [ | ||
167 | Test("test-tls13-ccs.py"), | ||
168 | Test("test-tls13-conversation.py"), | ||
169 | Test("test-tls13-count-tickets.py"), | ||
170 | Test("test-tls13-empty-alert.py"), | ||
171 | Test("test-tls13-finished.py", generate_test_tls13_finished_args()), | ||
172 | Test("test-tls13-finished-plaintext.py"), | ||
173 | Test("test-tls13-hrr.py"), | ||
174 | Test("test-tls13-keyshare-omitted.py"), | ||
175 | Test("test-tls13-legacy-version.py"), | ||
176 | Test("test-tls13-nociphers.py"), | ||
177 | Test("test-tls13-record-padding.py"), | ||
178 | # Exclude QUIC transport parameters | ||
179 | Test("test-tls13-shuffled-extentions.py", [ "--exc", "57" ]), | ||
180 | Test("test-tls13-zero-content-type.py"), | ||
181 | |||
182 | # The skipped tests fail due to a bug in BIO_gets() which masks the retry | ||
183 | # signalled from an SSL_read() failure. Testing with httpd(8) shows we're | ||
184 | # handling these corner cases correctly since tls13_record_layer.c -r1.47. | ||
185 | Test("test-tls13-zero-length-data.py", [ | ||
186 | "-e", "zero-length app data", | ||
187 | "-e", "zero-length app data with large padding", | ||
188 | "-e", "zero-length app data with padding", | ||
189 | ]), | ||
190 | |||
191 | # We don't currently handle NSTs | ||
192 | Test("test-tls13-connection-abort.py", ["-e", "After NewSessionTicket"]), | ||
193 | ]) | ||
194 | |||
195 | # Tests that take a lot of time (> ~30s on an x280) | ||
196 | tls13_slow_tests = TestGroup("slow TLSv1.3 tests", [ | ||
197 | # XXX: Investigate the occasional message | ||
198 | # "Got shared secret with 1 most significant bytes equal to zero." | ||
199 | Test("test-tls13-dhe-shared-secret-padding.py", tls13_unsupported_ciphers), | ||
200 | |||
201 | Test("test-tls13-invalid-ciphers.py"), | ||
202 | Test("test-tls13-serverhello-random.py", tls13_unsupported_ciphers), | ||
203 | |||
204 | # Mark two tests cases as xfail for now. The tests expect an arguably | ||
205 | # correct decode_error while we send a decrypt_error (like fizz/boring). | ||
206 | Test("test-tls13-record-layer-limits.py", [ | ||
207 | "-x", "max size payload (2**14) of Finished msg, with 16348 bytes of left padding, cipher TLS_AES_128_GCM_SHA256", | ||
208 | "-X", substitute_alert("decode_error", "decrypt_error"), | ||
209 | "-x", "max size payload (2**14) of Finished msg, with 16348 bytes of left padding, cipher TLS_CHACHA20_POLY1305_SHA256", | ||
210 | "-X", substitute_alert("decode_error", "decrypt_error"), | ||
211 | ]), | ||
212 | # We don't accept an empty ECPF extension since it must advertise the | ||
213 | # uncompressed point format. Exclude this extension type from the test. | ||
214 | Test( | ||
215 | "test-tls13-large-number-of-extensions.py", | ||
216 | tls13_args = ["--exc", "11"], | ||
217 | ), | ||
218 | ]) | ||
219 | |||
220 | tls13_extra_cert_tests = TestGroup("TLSv1.3 certificate tests", [ | ||
221 | # need to set up client certs to run these | ||
222 | Test("test-tls13-certificate-request.py"), | ||
223 | Test("test-tls13-certificate-verify.py"), | ||
224 | Test("test-tls13-ecdsa-in-certificate-verify.py"), | ||
225 | Test("test-tls13-eddsa-in-certificate-verify.py"), | ||
226 | |||
227 | # Test expects the server to have installed three certificates: | ||
228 | # with P-256, P-384 and P-521 curve. Also SHA1+ECDSA is verified | ||
229 | # to not work. | ||
230 | Test("test-tls13-ecdsa-support.py"), | ||
231 | ]) | ||
232 | |||
233 | tls13_failing_tests = TestGroup("failing TLSv1.3 tests", [ | ||
234 | # Some tests fail because we fail later than the scripts expect us to. | ||
235 | # With X25519, we accept weak peer public keys and fail when we actually | ||
236 | # compute the keyshare. Other tests seem to indicate that we could be | ||
237 | # stricter about what keyshares we accept. | ||
238 | Test("test-tls13-crfg-curves.py", [ | ||
239 | '-e', 'all zero x448 key share', | ||
240 | '-e', 'empty x448 key share', | ||
241 | '-e', 'sanity x448 with compression ansiX962_compressed_char2', | ||
242 | '-e', 'sanity x448 with compression ansiX962_compressed_prime', | ||
243 | '-e', 'sanity x448 with compression uncompressed', | ||
244 | '-e', 'too big x448 key share', | ||
245 | '-e', 'too small x448 key share', | ||
246 | '-e', 'x448 key share of "1"', | ||
247 | ]), | ||
248 | Test("test-tls13-ecdhe-curves.py", [ | ||
249 | '-e', 'sanity - x448', | ||
250 | '-e', 'x448 - key share from other curve', | ||
251 | '-e', 'x448 - point at infinity', | ||
252 | '-e', 'x448 - right 0-padded key_share', | ||
253 | '-e', 'x448 - right-truncated key_share', | ||
254 | ]), | ||
255 | |||
256 | # The test sends records with protocol version 0x0300 instead of 0x0303 | ||
257 | # and currently fails with OpenSSL and LibreSSL for this reason. | ||
258 | # We have the logic corresponding to NSS's fix for CVE-2020-25648 | ||
259 | # https://hg.mozilla.org/projects/nss/rev/57bbefa793232586d27cee83e74411171e128361 | ||
260 | # so should not be affected by this issue. | ||
261 | Test("test-tls13-multiple-ccs-messages.py"), | ||
262 | |||
263 | # https://github.com/openssl/openssl/issues/8369 | ||
264 | Test("test-tls13-obsolete-curves.py"), | ||
265 | |||
266 | # 3 failing rsa_pss_pss tests | ||
267 | Test("test-tls13-rsa-signatures.py"), | ||
268 | |||
269 | # The failing tests all expect an ri extension. What's up with that? | ||
270 | Test("test-tls13-version-negotiation.py"), | ||
271 | ]) | ||
272 | |||
273 | tls13_slow_failing_tests = TestGroup("slow, failing TLSv1.3 tests", [ | ||
274 | # Other test failures bugs in keyshare/tlsext negotiation? | ||
275 | Test("test-tls13-unrecognised-groups.py"), # unexpected closure | ||
276 | |||
277 | # 5 occasional failures: | ||
278 | # 'app data split, conversation with KeyUpdate msg' | ||
279 | # 'fragmented keyupdate msg' | ||
280 | # 'multiple KeyUpdate messages' | ||
281 | # 'post-handshake KeyUpdate msg with update_not_request' | ||
282 | # 'post-handshake KeyUpdate msg with update_request' | ||
283 | Test("test-tls13-keyupdate.py"), | ||
284 | |||
285 | Test("test-tls13-symetric-ciphers.py"), # unexpected message from peer | ||
286 | |||
287 | # 6 tests fail: 'rsa_pkcs1_{md5,sha{1,224,256,384,512}} signature' | ||
288 | # We send server hello, but the test expects handshake_failure | ||
289 | Test("test-tls13-pkcs-signature.py"), | ||
290 | # 8 tests fail: 'tls13 signature rsa_pss_{pss,rsae}_sha{256,384,512} | ||
291 | Test("test-tls13-rsapss-signatures.py"), | ||
292 | ]) | ||
293 | |||
294 | tls13_unsupported_tests = TestGroup("TLSv1.3 tests for unsupported features", [ | ||
295 | # Tests for features we don't support | ||
296 | Test("test-tls13-0rtt-garbage.py"), | ||
297 | Test("test-tls13-ffdhe-groups.py"), | ||
298 | Test("test-tls13-ffdhe-sanity.py"), | ||
299 | Test("test-tls13-psk_dhe_ke.py"), | ||
300 | Test("test-tls13-psk_ke.py"), | ||
301 | |||
302 | # need server to react to HTTP GET for /keyupdate | ||
303 | Test("test-tls13-keyupdate-from-server.py"), | ||
304 | |||
305 | # needs an echo server | ||
306 | Test("test-tls13-lengths.py"), | ||
307 | |||
308 | # Weird test: tests servers that don't support 1.3 | ||
309 | Test("test-tls13-non-support.py"), | ||
310 | |||
311 | # broken test script | ||
312 | # UnboundLocalError: local variable 'cert' referenced before assignment | ||
313 | Test("test-tls13-post-handshake-auth.py"), | ||
314 | |||
315 | # ExpectNewSessionTicket | ||
316 | Test("test-tls13-session-resumption.py"), | ||
317 | |||
318 | # Server must be configured to support only rsa_pss_rsae_sha512 | ||
319 | Test("test-tls13-signature-algorithms.py"), | ||
320 | ]) | ||
321 | |||
322 | tls12_exclude_legacy_protocols = [ | ||
323 | # all these have BIO_read timeouts against TLSv1.3 | ||
324 | "-e", "Protocol (3, 0)", | ||
325 | "-e", "Protocol (3, 1)", | ||
326 | "-e", "Protocol (3, 2)", | ||
327 | "-e", "Protocol (3, 0) in SSLv2 compatible ClientHello", | ||
328 | # the following only fail with TLSv1.3 | ||
329 | "-e", "Protocol (3, 1) in SSLv2 compatible ClientHello", | ||
330 | "-e", "Protocol (3, 2) in SSLv2 compatible ClientHello", | ||
331 | "-e", "Protocol (3, 3) in SSLv2 compatible ClientHello", | ||
332 | "-e", "Protocol (3, 1) with x448 group", | ||
333 | "-e", "Protocol (3, 2) with x448 group", | ||
334 | "-e", "Protocol (3, 3) with x448 group", | ||
335 | # These don't work without TLSv1.0 and TLSv1.1 | ||
336 | "-e", "Protocol (3, 1) with secp256r1 group", | ||
337 | "-e", "Protocol (3, 1) with secp384r1 group", | ||
338 | "-e", "Protocol (3, 1) with secp521r1 group", | ||
339 | "-e", "Protocol (3, 1) with x25519 group", | ||
340 | "-e", "Protocol (3, 2) with secp256r1 group", | ||
341 | "-e", "Protocol (3, 2) with secp384r1 group", | ||
342 | "-e", "Protocol (3, 2) with secp521r1 group", | ||
343 | "-e", "Protocol (3, 2) with x25519 group", | ||
344 | ] | ||
345 | |||
346 | tls12_tests = TestGroup("TLSv1.2 tests", [ | ||
347 | # Tests that pass as they are. | ||
348 | Test("test-aes-gcm-nonces.py"), | ||
349 | Test("test-connection-abort.py"), | ||
350 | Test("test-conversation.py"), | ||
351 | Test("test-cve-2016-2107.py"), | ||
352 | Test("test-cve-2016-6309.py"), | ||
353 | Test("test-dhe-rsa-key-exchange.py"), | ||
354 | Test("test-early-application-data.py"), | ||
355 | Test("test-empty-extensions.py"), | ||
356 | Test("test-extensions.py"), | ||
357 | Test("test-fuzzed-MAC.py"), | ||
358 | Test("test-fuzzed-ciphertext.py"), | ||
359 | Test("test-fuzzed-finished.py"), | ||
360 | Test("test-fuzzed-padding.py"), | ||
361 | Test("test-fuzzed-plaintext.py"), # fails once in a while | ||
362 | Test("test-hello-request-by-client.py"), | ||
363 | Test("test-invalid-cipher-suites.py"), | ||
364 | Test("test-invalid-content-type.py"), | ||
365 | Test("test-invalid-session-id.py"), | ||
366 | Test("test-invalid-version.py"), | ||
367 | Test("test-large-number-of-extensions.py"), | ||
368 | Test("test-lucky13.py"), | ||
369 | Test("test-message-skipping.py"), | ||
370 | Test("test-no-heartbeat.py"), | ||
371 | Test("test-record-layer-fragmentation.py"), | ||
372 | Test("test-sslv2-connection.py"), | ||
373 | Test("test-truncating-of-finished.py"), | ||
374 | Test("test-truncating-of-kRSA-client-key-exchange.py"), | ||
375 | Test("test-unsupported-curve-fallback.py"), | ||
376 | Test("test-version-numbers.py"), | ||
377 | Test("test-zero-length-data.py"), | ||
378 | |||
379 | # Tests that need tweaking for unsupported features and ciphers. | ||
380 | Test( | ||
381 | "test-atypical-padding.py", [ | ||
382 | "-e", "sanity - encrypt then MAC", | ||
383 | "-e", "2^14 bytes of AppData with 256 bytes of padding (SHA1 + Encrypt then MAC)", | ||
384 | ] | ||
385 | ), | ||
386 | Test( | ||
387 | "test-ccs.py", [ | ||
388 | "-x", "two bytes long CCS", | ||
389 | "-X", substitute_alert("unexpected_message", "decode_error"), | ||
390 | ] | ||
391 | ), | ||
392 | Test( | ||
393 | "test-dhe-rsa-key-exchange-signatures.py", [ | ||
394 | "-e", "TLS_DHE_RSA_WITH_3DES_EDE_CBC_SHA sha224 signature", | ||
395 | "-e", "TLS_DHE_RSA_WITH_AES_128_CBC_SHA256 sha224 signature", | ||
396 | "-e", "TLS_DHE_RSA_WITH_AES_128_CBC_SHA sha224 signature", | ||
397 | "-e", "TLS_DHE_RSA_WITH_AES_256_CBC_SHA256 sha224 signature", | ||
398 | "-e", "TLS_DHE_RSA_WITH_AES_256_CBC_SHA sha224 signature", | ||
399 | ] | ||
400 | ), | ||
401 | Test("test-dhe-rsa-key-exchange-with-bad-messages.py", [ | ||
402 | "-x", "invalid dh_Yc value - missing", | ||
403 | "-X", substitute_alert("decode_error", "illegal_parameter"), | ||
404 | ]), | ||
405 | Test("test-dhe-key-share-random.py", tls12_exclude_legacy_protocols), | ||
406 | Test("test-export-ciphers-rejected.py", ["--min-ver", "TLSv1.2"]), | ||
407 | Test( | ||
408 | "test-downgrade-protection.py", | ||
409 | tls12_args = ["--server-max-protocol", "TLSv1.2"], | ||
410 | tls13_args = [ | ||
411 | "--server-max-protocol", "TLSv1.3", | ||
412 | "-e", "TLS 1.3 downgrade check for Protocol (3, 1)", | ||
413 | "-e", "TLS 1.3 downgrade check for Protocol (3, 2)", | ||
414 | ] | ||
415 | ), | ||
416 | Test( | ||
417 | "test-fallback-scsv.py", | ||
418 | tls13_args = [ | ||
419 | "--tls-1.3", | ||
420 | "-e", "FALLBACK - hello TLSv1.1 - pos 0", | ||
421 | "-e", "FALLBACK - hello TLSv1.1 - pos 1", | ||
422 | "-e", "FALLBACK - hello TLSv1.1 - pos 2", | ||
423 | "-e", "FALLBACK - record TLSv1.1 hello TLSv1.1 - pos 0", | ||
424 | "-e", "FALLBACK - record TLSv1.1 hello TLSv1.1 - pos 1", | ||
425 | "-e", "FALLBACK - record TLSv1.1 hello TLSv1.1 - pos 2", | ||
426 | "-e", "record TLSv1.1 hello TLSv1.1", | ||
427 | "-e", "sanity - TLSv1.1", | ||
428 | ] | ||
429 | ), | ||
430 | |||
431 | Test("test-invalid-compression-methods.py", [ | ||
432 | "-x", "invalid compression methods", | ||
433 | "-X", substitute_alert("illegal_parameter", "decode_error"), | ||
434 | "-x", "only deflate compression method", | ||
435 | "-X", substitute_alert("illegal_parameter", "decode_error"), | ||
436 | ]), | ||
437 | |||
438 | # Skip extended_master_secret test. Since we don't support this | ||
439 | # extension, we don't notice that it was dropped. | ||
440 | Test("test-renegotiation-changed-clienthello.py", [ | ||
441 | "-e", "drop extended_master_secret in renegotiation", | ||
442 | ]), | ||
443 | |||
444 | Test("test-sessionID-resumption.py", [ | ||
445 | "-x", "Client Hello too long session ID", | ||
446 | "-X", substitute_alert("decode_error", "illegal_parameter"), | ||
447 | ]), | ||
448 | |||
449 | # Without --sig-algs-drop-ok, two tests fail since we do not currently | ||
450 | # implement the signature_algorithms_cert extension (although we MUST). | ||
451 | Test("test-sig-algs-renegotiation-resumption.py", ["--sig-algs-drop-ok"]), | ||
452 | |||
453 | Test("test-serverhello-random.py", args = tls12_exclude_legacy_protocols), | ||
454 | |||
455 | Test("test-chacha20.py", [ "-e", "Chacha20 in TLS1.1" ]), | ||
456 | ]) | ||
457 | |||
458 | tls12_slow_tests = TestGroup("slow TLSv1.2 tests", [ | ||
459 | Test("test-cve-2016-7054.py"), | ||
460 | Test("test-dhe-no-shared-secret-padding.py", tls12_exclude_legacy_protocols), | ||
461 | Test("test-ecdhe-padded-shared-secret.py", tls12_exclude_legacy_protocols), | ||
462 | Test("test-ecdhe-rsa-key-share-random.py", tls12_exclude_legacy_protocols), | ||
463 | # Start at extension number 58 to avoid QUIC transport parameters (57) | ||
464 | Test("test-large-hello.py", [ "-m", "58" ]), | ||
465 | ]) | ||
466 | |||
467 | tls12_failing_tests = TestGroup("failing TLSv1.2 tests", [ | ||
468 | # no shared cipher | ||
469 | Test("test-aesccm.py"), | ||
470 | # need server to set up alpn | ||
471 | Test("test-alpn-negotiation.py"), | ||
472 | # Failing on TLS_RSA_WITH_AES_128_CBC_SHA because server does not support it. | ||
473 | Test("test-bleichenbacher-timing-pregenerate.py"), | ||
474 | # many tests fail due to unexpected server_name extension | ||
475 | Test("test-bleichenbacher-workaround.py"), | ||
476 | |||
477 | # need client key and cert plus extra server setup | ||
478 | Test("test-certificate-malformed.py"), | ||
479 | Test("test-certificate-request.py"), | ||
480 | Test("test-certificate-verify-malformed-sig.py"), | ||
481 | Test("test-certificate-verify-malformed.py"), | ||
482 | Test("test-certificate-verify.py"), | ||
483 | Test("test-ecdsa-in-certificate-verify.py"), | ||
484 | Test("test-eddsa-in-certificate-verify.py"), | ||
485 | Test("test-renegotiation-disabled-client-cert.py"), | ||
486 | Test("test-rsa-pss-sigs-on-certificate-verify.py"), | ||
487 | Test("test-rsa-sigs-on-certificate-verify.py"), | ||
488 | |||
489 | # test doesn't expect session ticket | ||
490 | Test("test-client-compatibility.py"), | ||
491 | # abrupt closure | ||
492 | Test("test-client-hello-max-size.py"), | ||
493 | # unknown signature algorithms | ||
494 | Test("test-clienthello-md5.py"), | ||
495 | |||
496 | # Tests expect an illegal_parameter or a decode_error alert. Should be | ||
497 | # added to ssl3_get_client_key_exchange on kex function failure. | ||
498 | Test("test-ecdhe-rsa-key-exchange-with-bad-messages.py"), | ||
499 | |||
500 | # We send a handshake_failure due to no shared ciphers while the | ||
501 | # test expects to succeed. | ||
502 | Test("test-ecdhe-rsa-key-exchange.py"), | ||
503 | |||
504 | # no shared cipher | ||
505 | Test("test-ecdsa-sig-flexibility.py"), | ||
506 | |||
507 | # Tests expect SH but we send unexpected_message or handshake_failure | ||
508 | # 'Application data inside Client Hello' | ||
509 | # 'Application data inside Client Key Exchange' | ||
510 | # 'Application data inside Finished' | ||
511 | Test("test-interleaved-application-data-and-fragmented-handshakes-in-renegotiation.py"), | ||
512 | # Tests expect SH but we send handshake_failure | ||
513 | # 'Application data before Change Cipher Spec' | ||
514 | # 'Application data before Client Key Exchange' | ||
515 | # 'Application data before Finished' | ||
516 | Test("test-interleaved-application-data-in-renegotiation.py"), | ||
517 | |||
518 | # broken test script | ||
519 | # TypeError: '<' not supported between instances of 'int' and 'NoneType' | ||
520 | Test("test-invalid-client-hello-w-record-overflow.py"), | ||
521 | |||
522 | # Lots of failures. abrupt closure | ||
523 | Test("test-invalid-client-hello.py"), | ||
524 | |||
525 | # abrupt closure | ||
526 | # 'encrypted premaster set to all zero (n)' n in 256 384 512 | ||
527 | Test("test-invalid-rsa-key-exchange-messages.py"), | ||
528 | |||
529 | # test expects illegal_parameter, we send unrecognized_name (which seems | ||
530 | # correct according to rfc 6066?) | ||
531 | Test("test-invalid-server-name-extension-resumption.py"), | ||
532 | # let through some server names without sending an alert | ||
533 | # again illegal_parameter vs unrecognized_name | ||
534 | Test("test-invalid-server-name-extension.py"), | ||
535 | |||
536 | # 4 failures: | ||
537 | # 'insecure (legacy) renegotiation with GET after 2nd handshake' | ||
538 | # 'insecure (legacy) renegotiation with incomplete GET' | ||
539 | # 'secure renegotiation with GET after 2nd handshake' | ||
540 | # 'secure renegotiation with incomplete GET' | ||
541 | Test("test-legacy-renegotiation.py"), | ||
542 | |||
543 | # 1 failure (timeout): we don't send the unexpected_message alert | ||
544 | # 'duplicate change cipher spec after Finished' | ||
545 | Test("test-message-duplication.py"), | ||
546 | |||
547 | # server should send status_request | ||
548 | Test("test-ocsp-stapling.py"), | ||
549 | |||
550 | # unexpected closure | ||
551 | Test("test-openssl-3712.py"), | ||
552 | |||
553 | # failed: 3 (expect an alert, we send AD) | ||
554 | # 'try insecure (legacy) renegotiation with incomplete GET' | ||
555 | # 'try secure renegotiation with GET after 2nd CH' | ||
556 | # 'try secure renegotiation with incomplete GET' | ||
557 | Test("test-renegotiation-disabled.py"), | ||
558 | |||
559 | # 'resumption of safe session with NULL cipher' | ||
560 | # 'resumption with cipher from old CH but not selected by server' | ||
561 | Test("test-resumption-with-wrong-ciphers.py"), | ||
562 | |||
563 | # 'session resumption with empty session_id' | ||
564 | # 'session resumption with random session_id' | ||
565 | # 'session resumption with renegotiation' | ||
566 | # AssertionError: Server did not send extension(s): session_ticket | ||
567 | Test("test-session-ticket-resumption.py"), | ||
568 | |||
569 | # 5 failures: | ||
570 | # 'empty sigalgs' | ||
571 | # 'only undefined sigalgs' | ||
572 | # 'rsa_pss_pss_sha256 only' | ||
573 | # 'rsa_pss_pss_sha384 only' | ||
574 | # 'rsa_pss_pss_sha512 only' | ||
575 | Test("test-sig-algs.py"), | ||
576 | |||
577 | # 13 failures: | ||
578 | # 'duplicated n non-rsa schemes' for n in 202 2342 8119 23741 32744 | ||
579 | # 'empty list of signature methods' | ||
580 | # 'tolerance n RSA or ECDSA methods' for n in 215 2355 8132 23754 | ||
581 | # 'tolerance 32758 methods with sig_alg_cert' | ||
582 | # 'tolerance max 32744 number of methods with sig_alg_cert' | ||
583 | # 'tolerance max (32760) number of methods' | ||
584 | Test("test-signature-algorithms.py"), | ||
585 | |||
586 | # times out | ||
587 | Test("test-ssl-death-alert.py"), | ||
588 | |||
589 | # 17 pass, 13 fail. padding and truncation | ||
590 | Test("test-truncating-of-client-hello.py"), | ||
591 | |||
592 | # x448 tests need disabling plus x25519 corner cases need sorting out | ||
593 | Test("test-x25519.py"), | ||
594 | |||
595 | # Needs TLS 1.0 or 1.1 | ||
596 | Test("test-TLSv1_2-rejected-without-TLSv1_2.py"), | ||
597 | ]) | ||
598 | |||
599 | tls12_unsupported_tests = TestGroup("TLSv1.2 for unsupported features", [ | ||
600 | # protocol_version | ||
601 | Test("test-SSLv3-padding.py"), | ||
602 | # we don't do RSA key exchanges | ||
603 | Test("test-bleichenbacher-timing.py"), | ||
604 | # no encrypt-then-mac | ||
605 | Test("test-encrypt-then-mac-renegotiation.py"), | ||
606 | Test("test-encrypt-then-mac.py"), | ||
607 | # no EME support | ||
608 | Test("test-extended-master-secret-extension-with-client-cert.py"), | ||
609 | Test("test-extended-master-secret-extension.py"), | ||
610 | # no ffdhe | ||
611 | Test("test-ffdhe-expected-params.py"), | ||
612 | Test("test-ffdhe-negotiation.py"), | ||
613 | # record_size_limit/max_fragment_length extension (RFC 8449) | ||
614 | Test("test-record-size-limit.py"), | ||
615 | # expects the server to send the heartbeat extension | ||
616 | Test("test-heartbeat.py"), | ||
617 | # needs an echo server | ||
618 | Test("test-lengths.py"), | ||
619 | ]) | ||
620 | |||
621 | # These tests take a ton of time to fail against an 1.3 server, | ||
622 | # so don't run them against 1.3 pending further investigation. | ||
623 | legacy_tests = TestGroup("Legacy protocol tests", [ | ||
624 | Test("test-sslv2-force-cipher-3des.py"), | ||
625 | Test("test-sslv2-force-cipher-non3des.py"), | ||
626 | Test("test-sslv2-force-cipher.py"), | ||
627 | Test("test-sslv2-force-export-cipher.py"), | ||
628 | Test("test-sslv2hello-protocol.py"), | ||
629 | ]) | ||
630 | |||
631 | all_groups = [ | ||
632 | tls13_tests, | ||
633 | tls13_slow_tests, | ||
634 | tls13_extra_cert_tests, | ||
635 | tls13_failing_tests, | ||
636 | tls13_slow_failing_tests, | ||
637 | tls13_unsupported_tests, | ||
638 | tls12_tests, | ||
639 | tls12_slow_tests, | ||
640 | tls12_failing_tests, | ||
641 | tls12_unsupported_tests, | ||
642 | legacy_tests, | ||
643 | ] | ||
644 | |||
645 | failing_groups = [ | ||
646 | tls13_failing_tests, | ||
647 | tls13_slow_failing_tests, | ||
648 | tls12_failing_tests, | ||
649 | ] | ||
650 | |||
651 | class TestRunner: | ||
652 | """ Runs the given tests against a server and displays stats. """ | ||
653 | |||
654 | def __init__( | ||
655 | self, timing=False, verbose=False, host="localhost", port=4433, | ||
656 | use_tls1_3=True, dry_run=False, tests=[], scriptdir=tlsfuzzer_scriptdir, | ||
657 | ): | ||
658 | self.tests = [] | ||
659 | |||
660 | self.dryrun = dry_run | ||
661 | self.use_tls1_3 = use_tls1_3 | ||
662 | self.host = host | ||
663 | self.port = str(port) | ||
664 | self.scriptdir = scriptdir | ||
665 | |||
666 | self.stats = [] | ||
667 | self.failed = [] | ||
668 | self.missing = [] | ||
669 | |||
670 | self.timing = timing | ||
671 | self.verbose = verbose | ||
672 | |||
673 | def add(self, title="tests", tests=[]): | ||
674 | # tests.sort(key=lambda test: test.name) | ||
675 | self.tests.append(TestGroup(title, tests)) | ||
676 | |||
677 | def add_group(self, group): | ||
678 | self.tests.append(group) | ||
679 | |||
680 | def run_script(self, test): | ||
681 | script = test.name | ||
682 | args = ["-h"] + [self.host] + ["-p"] + [self.port] + test.args(self.use_tls1_3) | ||
683 | |||
684 | if self.dryrun: | ||
685 | if not self.verbose: | ||
686 | args = [] | ||
687 | print(script , end=' ' if args else '') | ||
688 | print(' '.join([f"\"{arg}\"" for arg in args])) | ||
689 | return | ||
690 | |||
691 | if self.verbose: | ||
692 | print(script) | ||
693 | else: | ||
694 | print(f"{script[:68]:<72}", end=" ", flush=True) | ||
695 | start = timer() | ||
696 | scriptpath = os.path.join(self.scriptdir, script) | ||
697 | if not os.path.exists(scriptpath): | ||
698 | self.missing.append(script) | ||
699 | print("MISSING") | ||
700 | return | ||
701 | test = subprocess.run( | ||
702 | ["python3", scriptpath] + args, | ||
703 | capture_output=not self.verbose, | ||
704 | text=True, | ||
705 | ) | ||
706 | end = timer() | ||
707 | self.stats.append((script, end - start)) | ||
708 | if test.returncode == 0: | ||
709 | print("OK") | ||
710 | return | ||
711 | print("FAILED") | ||
712 | self.failed.append(script) | ||
713 | |||
714 | if self.verbose: | ||
715 | return | ||
716 | |||
717 | print('\n'.join(test.stdout.split("Test end\n", 1)[1:]), end="") | ||
718 | |||
719 | def run(self): | ||
720 | for group in self: | ||
721 | print(f"Running {group.title} ...") | ||
722 | for test in group: | ||
723 | self.run_script(test) | ||
724 | return not self.failed | ||
725 | |||
726 | def __iter__(self): | ||
727 | return iter(self.tests) | ||
728 | |||
729 | def __del__(self): | ||
730 | if self.timing and self.stats: | ||
731 | total = 0.0 | ||
732 | for (script, time) in self.stats: | ||
733 | print(f"{round(time, 2):6.2f} {script}") | ||
734 | total += time | ||
735 | print(f"{round(total, 2):6.2f} total") | ||
736 | |||
737 | if self.failed: | ||
738 | print("Failed tests:") | ||
739 | print('\n'.join(self.failed)) | ||
740 | |||
741 | if self.missing: | ||
742 | print("Missing tests (outdated package?):") | ||
743 | print('\n'.join(self.missing)) | ||
744 | |||
745 | class TlsServer: | ||
746 | """ Spawns an s_server listening on localhost:port if necessary. """ | ||
747 | |||
748 | def __init__(self, host="localhost", port=4433): | ||
749 | self.spawn = True | ||
750 | # Check whether a server is already listening on localhost:port | ||
751 | self.spawn = subprocess.run( | ||
752 | ["nc", "-c", "-z", "-T", "noverify", host, str(port)], | ||
753 | stderr=subprocess.DEVNULL, | ||
754 | ).returncode != 0 | ||
755 | |||
756 | if self.spawn: | ||
757 | self.server = subprocess.Popen( | ||
758 | [ | ||
759 | "openssl", | ||
760 | "s_server", | ||
761 | "-accept", | ||
762 | str(port), | ||
763 | "-groups", | ||
764 | "X25519:P-256:P-521:P-384", | ||
765 | "-key", | ||
766 | "localhost.key", | ||
767 | "-cert", | ||
768 | "localhost.crt", | ||
769 | "-www", | ||
770 | ], | ||
771 | stdout=subprocess.DEVNULL, | ||
772 | stderr=subprocess.PIPE, | ||
773 | text=True, | ||
774 | ) | ||
775 | |||
776 | # Check whether the server talks TLSv1.3 | ||
777 | self.has_tls1_3 = True or subprocess.run( | ||
778 | [ | ||
779 | "nc", | ||
780 | "-c", | ||
781 | "-z", | ||
782 | "-T", | ||
783 | "noverify", | ||
784 | "-T", | ||
785 | "protocols=TLSv1.3", | ||
786 | "localhost", | ||
787 | str(port), | ||
788 | ], | ||
789 | stderr=subprocess.DEVNULL, | ||
790 | ).returncode == 0 | ||
791 | |||
792 | self.check() | ||
793 | |||
794 | def check(self): | ||
795 | if self.spawn and self.server.poll() is not None: | ||
796 | print(self.server.stderr.read()) | ||
797 | raise RuntimeError( | ||
798 | f"openssl s_server died. Return code: {self.server.returncode}." | ||
799 | ) | ||
800 | if self.spawn: | ||
801 | self.server.stderr.detach() | ||
802 | |||
803 | def __del__(self): | ||
804 | if self.spawn: | ||
805 | self.server.terminate() | ||
806 | |||
807 | # Extract the arguments we pass to script | ||
808 | def defaultargs(script, has_tls1_3): | ||
809 | return next( | ||
810 | (test for group in all_groups for test in group if test.name == script), | ||
811 | Test() | ||
812 | ).args(has_tls1_3) | ||
813 | |||
814 | def list_or_missing(missing=True): | ||
815 | tests = [test.name for group in all_groups for test in group] | ||
816 | |||
817 | if missing: | ||
818 | scripts = { | ||
819 | f for f in os.listdir(tlsfuzzer_scriptdir) if f != "__pycache__" | ||
820 | } | ||
821 | missing = scripts - set(tests) | ||
822 | if missing: | ||
823 | print('\n'.join(sorted(missing))) | ||
824 | exit(0) | ||
825 | |||
826 | tests.sort() | ||
827 | print('\n'.join(tests)) | ||
828 | exit(0) | ||
829 | |||
830 | def usage(): | ||
831 | print("Usage: python3 tlsfuzzer.py [-flmnstv] [-p port] [script [test...]]") | ||
832 | print(" --help help") | ||
833 | print(" -f run failing tests") | ||
834 | print(" -l list tests") | ||
835 | print(" -m list new tests after package update") | ||
836 | print(" -n do not run tests, but list the ones that would be run") | ||
837 | print(" -p port connect to this port - defaults to 4433") | ||
838 | print(" -s run slow tests") | ||
839 | print(" -t show timing stats at end") | ||
840 | print(" -v verbose output") | ||
841 | exit(0) | ||
842 | |||
843 | def main(): | ||
844 | failing = False | ||
845 | list = False | ||
846 | missing = False | ||
847 | dryrun = False | ||
848 | host = "localhost" | ||
849 | port = 4433 | ||
850 | slow = False | ||
851 | timing = False | ||
852 | verbose = False | ||
853 | |||
854 | argv = sys.argv[1:] | ||
855 | opts, args = getopt.getopt(argv, "fh:lmnp:stv", ["help"]) | ||
856 | for opt, arg in opts: | ||
857 | if opt == '--help': | ||
858 | usage() | ||
859 | elif opt == '-f': | ||
860 | failing = True | ||
861 | elif opt == '-h': | ||
862 | host = arg | ||
863 | elif opt == '-l': | ||
864 | list = True | ||
865 | elif opt == '-m': | ||
866 | missing = True | ||
867 | elif opt == '-n': | ||
868 | dryrun = True | ||
869 | elif opt == '-p': | ||
870 | port = int(arg) | ||
871 | elif opt == '-s': | ||
872 | slow = True | ||
873 | elif opt == '-t': | ||
874 | timing = True | ||
875 | elif opt == '-v': | ||
876 | verbose = True | ||
877 | else: | ||
878 | raise ValueError(f"Unknown option: {opt}") | ||
879 | |||
880 | if not os.path.exists(tlsfuzzer_scriptdir): | ||
881 | print("package py3-tlsfuzzer is required for this regress") | ||
882 | exit(1) | ||
883 | |||
884 | if list and failing: | ||
885 | failing = [test.name for group in failing_groups for test in group] | ||
886 | failing.sort() | ||
887 | print('\n'.join(failing)) | ||
888 | exit(0) | ||
889 | |||
890 | if list or missing: | ||
891 | list_or_missing(missing) | ||
892 | |||
893 | tls_server = TlsServer(host, port) | ||
894 | |||
895 | tests = TestRunner(timing, verbose, host, port, tls_server.has_tls1_3, dryrun) | ||
896 | |||
897 | if args: | ||
898 | (dir, script) = os.path.split(args[0]) | ||
899 | if dir and not dir == '.': | ||
900 | tests.scriptdir = dir | ||
901 | |||
902 | testargs = defaultargs(script, tls_server.has_tls1_3) | ||
903 | |||
904 | tests.verbose = True | ||
905 | tests.add("test from command line", [Test(script, testargs + args[1:])]) | ||
906 | |||
907 | exit(not tests.run()) | ||
908 | |||
909 | if failing: | ||
910 | if tls_server.has_tls1_3: | ||
911 | tests.add_group(tls13_failing_tests) | ||
912 | if slow: | ||
913 | tests.add_group(tls13_slow_failing_tests) | ||
914 | tests.add_group(tls12_failing_tests) | ||
915 | |||
916 | if tls_server.has_tls1_3: | ||
917 | tests.add_group(tls13_tests) | ||
918 | if slow: | ||
919 | tests.add_group(tls13_slow_tests) | ||
920 | else: | ||
921 | tests.add_group(legacy_tests) | ||
922 | |||
923 | tests.add_group(tls12_tests) | ||
924 | if slow: | ||
925 | tests.add_group(tls12_slow_tests) | ||
926 | |||
927 | success = tests.run() | ||
928 | del tests | ||
929 | |||
930 | if not success: | ||
931 | print("FAILED") | ||
932 | exit(1) | ||
933 | |||
934 | if __name__ == "__main__": | ||
935 | main() | ||
diff --git a/src/regress/lib/libssl/tlslegacy/Makefile b/src/regress/lib/libssl/tlslegacy/Makefile deleted file mode 100644 index c39981f0b8..0000000000 --- a/src/regress/lib/libssl/tlslegacy/Makefile +++ /dev/null | |||
@@ -1,9 +0,0 @@ | |||
1 | # $OpenBSD: Makefile,v 1.1 2020/10/07 07:52:17 jsing Exp $ | ||
2 | |||
3 | PROG= tlslegacytest | ||
4 | LDADD= -lssl -lcrypto | ||
5 | DPADD= ${LIBSSL} ${LIBCRYPTO} | ||
6 | WARNINGS= Yes | ||
7 | CFLAGS+= -DLIBRESSL_INTERNAL -Werror | ||
8 | |||
9 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libssl/tlslegacy/tlslegacytest.c b/src/regress/lib/libssl/tlslegacy/tlslegacytest.c deleted file mode 100644 index 59429d716a..0000000000 --- a/src/regress/lib/libssl/tlslegacy/tlslegacytest.c +++ /dev/null | |||
@@ -1,625 +0,0 @@ | |||
1 | /* $OpenBSD: tlslegacytest.c,v 1.7 2022/10/02 16:39:39 jsing Exp $ */ | ||
2 | /* | ||
3 | * Copyright (c) 2015, 2016, 2017, 2020 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 <openssl/ssl.h> | ||
19 | |||
20 | #include <err.h> | ||
21 | #include <stdio.h> | ||
22 | #include <string.h> | ||
23 | |||
24 | /* openssl.org:443 */ | ||
25 | static uint8_t tls12_server_response[] = { | ||
26 | 0x16, 0x03, 0x03, 0x00, 0x3d, 0x02, 0x00, 0x00, | ||
27 | 0x39, 0x03, 0x03, 0x62, 0x0c, 0x8a, 0x7e, 0x29, | ||
28 | 0x60, 0xcb, 0x08, 0xd1, 0xb4, 0x95, 0x68, 0x76, | ||
29 | 0xea, 0x4e, 0x0c, 0x94, 0xf2, 0x42, 0x3d, 0xd1, | ||
30 | 0x7a, 0xc2, 0xfe, 0x6c, 0xb3, 0xe6, 0x12, 0x8a, | ||
31 | 0x33, 0x02, 0x92, 0x00, 0xc0, 0x30, 0x00, 0x00, | ||
32 | 0x11, 0xff, 0x01, 0x00, 0x01, 0x00, 0x00, 0x0b, | ||
33 | 0x00, 0x04, 0x03, 0x00, 0x01, 0x02, 0x00, 0x23, | ||
34 | 0x00, 0x00, | ||
35 | }; | ||
36 | |||
37 | /* | ||
38 | * outlook.office365.com:587 with starttls - this server response includes | ||
39 | * multiple handshake messages contained in a single TLS record. | ||
40 | */ | ||
41 | static uint8_t tls12_server_response_with_cert[] = { | ||
42 | 0x16, 0x03, 0x03, 0x0f, 0x2b, 0x02, 0x00, 0x00, | ||
43 | 0x4d, 0x03, 0x03, 0x5f, 0x7c, 0x69, 0x42, 0xe1, | ||
44 | 0x19, 0xf0, 0x22, 0xfb, 0x71, 0x9a, 0xf1, 0x63, | ||
45 | 0x34, 0xbb, 0x61, 0x46, 0xea, 0x5f, 0x0b, 0x5e, | ||
46 | 0xb1, 0x4e, 0x37, 0x96, 0x67, 0xff, 0x83, 0xea, | ||
47 | 0x0e, 0x16, 0x85, 0x20, 0x3a, 0x1b, 0x00, 0x00, | ||
48 | 0x17, 0xe9, 0xac, 0xca, 0x19, 0x61, 0xaf, 0x70, | ||
49 | 0x28, 0x3b, 0x18, 0xaa, 0x6c, 0xa0, 0x0f, 0x78, | ||
50 | 0xd0, 0x83, 0xfc, 0x5d, 0x78, 0xf9, 0x6d, 0xdb, | ||
51 | 0x16, 0x21, 0x15, 0xa2, 0xc0, 0x30, 0x00, 0x00, | ||
52 | 0x05, 0xff, 0x01, 0x00, 0x01, 0x00, 0x0b, 0x00, | ||
53 | 0x0d, 0x47, 0x00, 0x0d, 0x44, 0x00, 0x08, 0xaf, | ||
54 | 0x30, 0x82, 0x08, 0xab, 0x30, 0x82, 0x07, 0x93, | ||
55 | 0xa0, 0x03, 0x02, 0x01, 0x02, 0x02, 0x0c, 0x6d, | ||
56 | 0xea, 0x0b, 0xe1, 0x97, 0x27, 0x60, 0xa1, 0x59, | ||
57 | 0xb1, 0x85, 0x60, 0x30, 0x0d, 0x06, 0x09, 0x2a, | ||
58 | 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, | ||
59 | 0x05, 0x00, 0x30, 0x66, 0x31, 0x0b, 0x30, 0x09, | ||
60 | 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x42, | ||
61 | 0x45, 0x31, 0x19, 0x30, 0x17, 0x06, 0x03, 0x55, | ||
62 | 0x04, 0x0a, 0x13, 0x10, 0x47, 0x6c, 0x6f, 0x62, | ||
63 | 0x61, 0x6c, 0x53, 0x69, 0x67, 0x6e, 0x20, 0x6e, | ||
64 | 0x76, 0x2d, 0x73, 0x61, 0x31, 0x3c, 0x30, 0x3a, | ||
65 | 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x33, 0x47, | ||
66 | 0x6c, 0x6f, 0x62, 0x61, 0x6c, 0x53, 0x69, 0x67, | ||
67 | 0x6e, 0x20, 0x4f, 0x72, 0x67, 0x61, 0x6e, 0x69, | ||
68 | 0x7a, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x56, | ||
69 | 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x69, 0x6f, | ||
70 | 0x6e, 0x20, 0x43, 0x41, 0x20, 0x2d, 0x20, 0x53, | ||
71 | 0x48, 0x41, 0x32, 0x35, 0x36, 0x20, 0x2d, 0x20, | ||
72 | 0x47, 0x33, 0x30, 0x1e, 0x17, 0x0d, 0x32, 0x30, | ||
73 | 0x30, 0x38, 0x31, 0x33, 0x32, 0x33, 0x31, 0x38, | ||
74 | 0x34, 0x39, 0x5a, 0x17, 0x0d, 0x32, 0x32, 0x30, | ||
75 | 0x38, 0x31, 0x34, 0x32, 0x33, 0x31, 0x38, 0x34, | ||
76 | 0x39, 0x5a, 0x30, 0x6a, 0x31, 0x0b, 0x30, 0x09, | ||
77 | 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x55, | ||
78 | 0x53, 0x31, 0x13, 0x30, 0x11, 0x06, 0x03, 0x55, | ||
79 | 0x04, 0x08, 0x13, 0x0a, 0x57, 0x61, 0x73, 0x68, | ||
80 | 0x69, 0x6e, 0x67, 0x74, 0x6f, 0x6e, 0x31, 0x10, | ||
81 | 0x30, 0x0e, 0x06, 0x03, 0x55, 0x04, 0x07, 0x13, | ||
82 | 0x07, 0x52, 0x65, 0x64, 0x6d, 0x6f, 0x6e, 0x64, | ||
83 | 0x31, 0x1e, 0x30, 0x1c, 0x06, 0x03, 0x55, 0x04, | ||
84 | 0x0a, 0x13, 0x15, 0x4d, 0x69, 0x63, 0x72, 0x6f, | ||
85 | 0x73, 0x6f, 0x66, 0x74, 0x20, 0x43, 0x6f, 0x72, | ||
86 | 0x70, 0x6f, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, | ||
87 | 0x31, 0x14, 0x30, 0x12, 0x06, 0x03, 0x55, 0x04, | ||
88 | 0x03, 0x13, 0x0b, 0x6f, 0x75, 0x74, 0x6c, 0x6f, | ||
89 | 0x6f, 0x6b, 0x2e, 0x63, 0x6f, 0x6d, 0x30, 0x82, | ||
90 | 0x01, 0x22, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, | ||
91 | 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05, | ||
92 | 0x00, 0x03, 0x82, 0x01, 0x0f, 0x00, 0x30, 0x82, | ||
93 | 0x01, 0x0a, 0x02, 0x82, 0x01, 0x01, 0x00, 0xc9, | ||
94 | 0x20, 0x3f, 0x57, 0xb9, 0xf9, 0x71, 0xaa, 0x3c, | ||
95 | 0x6a, 0x0a, 0x5d, 0x3f, 0xc9, 0x8d, 0x99, 0xa5, | ||
96 | 0x50, 0x26, 0x25, 0x4e, 0xdc, 0x69, 0x52, 0xb3, | ||
97 | 0x33, 0x70, 0xe7, 0x72, 0xa2, 0x83, 0x92, 0x54, | ||
98 | 0xd1, 0xd4, 0x86, 0x15, 0xf2, 0xc4, 0x65, 0xf8, | ||
99 | 0xbc, 0xe5, 0xd2, 0x1e, 0x12, 0x25, 0x9e, 0x75, | ||
100 | 0x8e, 0x77, 0xd2, 0x8e, 0x94, 0xca, 0x03, 0x4b, | ||
101 | 0xf4, 0xc8, 0xca, 0xe3, 0xe3, 0x9b, 0x66, 0xa3, | ||
102 | 0xa1, 0x37, 0x74, 0xcc, 0xfe, 0xc4, 0x1e, 0x64, | ||
103 | 0xdc, 0xe3, 0x18, 0xba, 0xc1, 0x7b, 0x39, 0x5b, | ||
104 | 0xb1, 0x47, 0xe9, 0x11, 0x92, 0xef, 0xee, 0xe6, | ||
105 | 0x08, 0xcd, 0x93, 0x7b, 0x09, 0xc7, 0x39, 0xfe, | ||
106 | 0xe5, 0xe2, 0x47, 0x3f, 0x68, 0x78, 0xa4, 0x17, | ||
107 | 0x78, 0x13, 0xcb, 0x12, 0x38, 0x9d, 0x89, 0x2b, | ||
108 | 0x1f, 0x75, 0x9b, 0x87, 0x5d, 0x53, 0xfc, 0xb0, | ||
109 | 0x2a, 0xaf, 0x2d, 0x86, 0x8a, 0x76, 0x3b, 0xce, | ||
110 | 0x5e, 0xae, 0x43, 0x74, 0x68, 0xc3, 0x28, 0xbf, | ||
111 | 0x10, 0x2f, 0xdd, 0xd9, 0x43, 0x4b, 0x2d, 0xa6, | ||
112 | 0xdc, 0x1f, 0x6d, 0x90, 0xd0, 0xce, 0x14, 0x1e, | ||
113 | 0x6c, 0xdc, 0x7b, 0x06, 0xe4, 0x7b, 0xa9, 0x81, | ||
114 | 0x40, 0xed, 0xde, 0x18, 0xb7, 0xdf, 0x53, 0x61, | ||
115 | 0xbc, 0x18, 0x83, 0x11, 0xc7, 0xb4, 0x1b, 0x99, | ||
116 | 0xef, 0x14, 0xe4, 0x63, 0x39, 0xe3, 0x5c, 0x2f, | ||
117 | 0xe7, 0x89, 0x58, 0x5b, 0xda, 0x03, 0x3a, 0x39, | ||
118 | 0x96, 0x8a, 0xca, 0x4f, 0xd8, 0xe3, 0x6c, 0x7f, | ||
119 | 0x6e, 0xd3, 0xe7, 0x30, 0x34, 0x9c, 0xdb, 0x8b, | ||
120 | 0xe8, 0x6a, 0xa6, 0x08, 0x77, 0x1d, 0x63, 0xd6, | ||
121 | 0x57, 0x9d, 0xcd, 0xa7, 0x47, 0x05, 0x39, 0x96, | ||
122 | 0x7b, 0xfd, 0x9a, 0x09, 0x99, 0xef, 0x49, 0xb1, | ||
123 | 0x89, 0x02, 0xbe, 0x4f, 0xb8, 0xef, 0xa0, 0x04, | ||
124 | 0x29, 0x74, 0xfb, 0x9a, 0x7e, 0x9d, 0xa8, 0x10, | ||
125 | 0xfb, 0x7e, 0xb0, 0x6c, 0x60, 0x4f, 0x57, 0x02, | ||
126 | 0x03, 0x01, 0x00, 0x01, 0xa3, 0x82, 0x05, 0x53, | ||
127 | 0x30, 0x82, 0x05, 0x4f, 0x30, 0x0e, 0x06, 0x03, | ||
128 | 0x55, 0x1d, 0x0f, 0x01, 0x01, 0xff, 0x04, 0x04, | ||
129 | 0x03, 0x02, 0x05, 0xa0, 0x30, 0x81, 0x9e, 0x06, | ||
130 | 0x08, 0x2b, 0x06, 0x01, 0x05, 0x05, 0x07, 0x01, | ||
131 | 0x01, 0x04, 0x81, 0x91, 0x30, 0x81, 0x8e, 0x30, | ||
132 | 0x4b, 0x06, 0x08, 0x2b, 0x06, 0x01, 0x05, 0x05, | ||
133 | 0x07, 0x30, 0x02, 0x86, 0x3f, 0x68, 0x74, 0x74, | ||
134 | 0x70, 0x3a, 0x2f, 0x2f, 0x73, 0x65, 0x63, 0x75, | ||
135 | 0x72, 0x65, 0x2e, 0x67, 0x6c, 0x6f, 0x62, 0x61, | ||
136 | 0x6c, 0x73, 0x69, 0x67, 0x6e, 0x2e, 0x63, 0x6f, | ||
137 | 0x6d, 0x2f, 0x63, 0x61, 0x63, 0x65, 0x72, 0x74, | ||
138 | 0x2f, 0x67, 0x73, 0x6f, 0x72, 0x67, 0x61, 0x6e, | ||
139 | 0x69, 0x7a, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x76, | ||
140 | 0x61, 0x6c, 0x73, 0x68, 0x61, 0x32, 0x67, 0x33, | ||
141 | 0x2e, 0x63, 0x72, 0x74, 0x30, 0x3f, 0x06, 0x08, | ||
142 | 0x2b, 0x06, 0x01, 0x05, 0x05, 0x07, 0x30, 0x01, | ||
143 | 0x86, 0x33, 0x68, 0x74, 0x74, 0x70, 0x3a, 0x2f, | ||
144 | 0x2f, 0x6f, 0x63, 0x73, 0x70, 0x32, 0x2e, 0x67, | ||
145 | 0x6c, 0x6f, 0x62, 0x61, 0x6c, 0x73, 0x69, 0x67, | ||
146 | 0x6e, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x67, 0x73, | ||
147 | 0x6f, 0x72, 0x67, 0x61, 0x6e, 0x69, 0x7a, 0x61, | ||
148 | 0x74, 0x69, 0x6f, 0x6e, 0x76, 0x61, 0x6c, 0x73, | ||
149 | 0x68, 0x61, 0x32, 0x67, 0x33, 0x30, 0x56, 0x06, | ||
150 | 0x03, 0x55, 0x1d, 0x20, 0x04, 0x4f, 0x30, 0x4d, | ||
151 | 0x30, 0x41, 0x06, 0x09, 0x2b, 0x06, 0x01, 0x04, | ||
152 | 0x01, 0xa0, 0x32, 0x01, 0x14, 0x30, 0x34, 0x30, | ||
153 | 0x32, 0x06, 0x08, 0x2b, 0x06, 0x01, 0x05, 0x05, | ||
154 | 0x07, 0x02, 0x01, 0x16, 0x26, 0x68, 0x74, 0x74, | ||
155 | 0x70, 0x73, 0x3a, 0x2f, 0x2f, 0x77, 0x77, 0x77, | ||
156 | 0x2e, 0x67, 0x6c, 0x6f, 0x62, 0x61, 0x6c, 0x73, | ||
157 | 0x69, 0x67, 0x6e, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, | ||
158 | 0x72, 0x65, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x6f, | ||
159 | 0x72, 0x79, 0x2f, 0x30, 0x08, 0x06, 0x06, 0x67, | ||
160 | 0x81, 0x0c, 0x01, 0x02, 0x02, 0x30, 0x09, 0x06, | ||
161 | 0x03, 0x55, 0x1d, 0x13, 0x04, 0x02, 0x30, 0x00, | ||
162 | 0x30, 0x46, 0x06, 0x03, 0x55, 0x1d, 0x1f, 0x04, | ||
163 | 0x3f, 0x30, 0x3d, 0x30, 0x3b, 0xa0, 0x39, 0xa0, | ||
164 | 0x37, 0x86, 0x35, 0x68, 0x74, 0x74, 0x70, 0x3a, | ||
165 | 0x2f, 0x2f, 0x63, 0x72, 0x6c, 0x2e, 0x67, 0x6c, | ||
166 | 0x6f, 0x62, 0x61, 0x6c, 0x73, 0x69, 0x67, 0x6e, | ||
167 | 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x67, 0x73, 0x6f, | ||
168 | 0x72, 0x67, 0x61, 0x6e, 0x69, 0x7a, 0x61, 0x74, | ||
169 | 0x69, 0x6f, 0x6e, 0x76, 0x61, 0x6c, 0x73, 0x68, | ||
170 | 0x61, 0x32, 0x67, 0x33, 0x2e, 0x63, 0x72, 0x6c, | ||
171 | 0x30, 0x82, 0x02, 0x10, 0x06, 0x03, 0x55, 0x1d, | ||
172 | 0x11, 0x04, 0x82, 0x02, 0x07, 0x30, 0x82, 0x02, | ||
173 | 0x03, 0x82, 0x0b, 0x6f, 0x75, 0x74, 0x6c, 0x6f, | ||
174 | 0x6f, 0x6b, 0x2e, 0x63, 0x6f, 0x6d, 0x82, 0x16, | ||
175 | 0x2a, 0x2e, 0x63, 0x6c, 0x6f, 0x2e, 0x66, 0x6f, | ||
176 | 0x6f, 0x74, 0x70, 0x72, 0x69, 0x6e, 0x74, 0x64, | ||
177 | 0x6e, 0x73, 0x2e, 0x63, 0x6f, 0x6d, 0x82, 0x0d, | ||
178 | 0x2a, 0x2e, 0x68, 0x6f, 0x74, 0x6d, 0x61, 0x69, | ||
179 | 0x6c, 0x2e, 0x63, 0x6f, 0x6d, 0x82, 0x16, 0x2a, | ||
180 | 0x2e, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, | ||
181 | 0x6c, 0x2e, 0x6f, 0x75, 0x74, 0x6c, 0x6f, 0x6f, | ||
182 | 0x6b, 0x2e, 0x63, 0x6f, 0x6d, 0x82, 0x0a, 0x2a, | ||
183 | 0x2e, 0x6c, 0x69, 0x76, 0x65, 0x2e, 0x63, 0x6f, | ||
184 | 0x6d, 0x82, 0x16, 0x2a, 0x2e, 0x6e, 0x72, 0x62, | ||
185 | 0x2e, 0x66, 0x6f, 0x6f, 0x74, 0x70, 0x72, 0x69, | ||
186 | 0x6e, 0x74, 0x64, 0x6e, 0x73, 0x2e, 0x63, 0x6f, | ||
187 | 0x6d, 0x82, 0x0c, 0x2a, 0x2e, 0x6f, 0x66, 0x66, | ||
188 | 0x69, 0x63, 0x65, 0x2e, 0x63, 0x6f, 0x6d, 0x82, | ||
189 | 0x0f, 0x2a, 0x2e, 0x6f, 0x66, 0x66, 0x69, 0x63, | ||
190 | 0x65, 0x33, 0x36, 0x35, 0x2e, 0x63, 0x6f, 0x6d, | ||
191 | 0x82, 0x0d, 0x2a, 0x2e, 0x6f, 0x75, 0x74, 0x6c, | ||
192 | 0x6f, 0x6f, 0x6b, 0x2e, 0x63, 0x6f, 0x6d, 0x82, | ||
193 | 0x17, 0x2a, 0x2e, 0x6f, 0x75, 0x74, 0x6c, 0x6f, | ||
194 | 0x6f, 0x6b, 0x2e, 0x6f, 0x66, 0x66, 0x69, 0x63, | ||
195 | 0x65, 0x33, 0x36, 0x35, 0x2e, 0x63, 0x6f, 0x6d, | ||
196 | 0x82, 0x1b, 0x61, 0x74, 0x74, 0x61, 0x63, 0x68, | ||
197 | 0x6d, 0x65, 0x6e, 0x74, 0x2e, 0x6f, 0x75, 0x74, | ||
198 | 0x6c, 0x6f, 0x6f, 0x6b, 0x2e, 0x6c, 0x69, 0x76, | ||
199 | 0x65, 0x2e, 0x6e, 0x65, 0x74, 0x82, 0x1d, 0x61, | ||
200 | 0x74, 0x74, 0x61, 0x63, 0x68, 0x6d, 0x65, 0x6e, | ||
201 | 0x74, 0x2e, 0x6f, 0x75, 0x74, 0x6c, 0x6f, 0x6f, | ||
202 | 0x6b, 0x2e, 0x6f, 0x66, 0x66, 0x69, 0x63, 0x65, | ||
203 | 0x2e, 0x6e, 0x65, 0x74, 0x82, 0x20, 0x61, 0x74, | ||
204 | 0x74, 0x61, 0x63, 0x68, 0x6d, 0x65, 0x6e, 0x74, | ||
205 | 0x2e, 0x6f, 0x75, 0x74, 0x6c, 0x6f, 0x6f, 0x6b, | ||
206 | 0x2e, 0x6f, 0x66, 0x66, 0x69, 0x63, 0x65, 0x70, | ||
207 | 0x70, 0x65, 0x2e, 0x6e, 0x65, 0x74, 0x82, 0x16, | ||
208 | 0x61, 0x74, 0x74, 0x61, 0x63, 0x68, 0x6d, 0x65, | ||
209 | 0x6e, 0x74, 0x73, 0x2e, 0x6f, 0x66, 0x66, 0x69, | ||
210 | 0x63, 0x65, 0x2e, 0x6e, 0x65, 0x74, 0x82, 0x1a, | ||
211 | 0x61, 0x74, 0x74, 0x61, 0x63, 0x68, 0x6d, 0x65, | ||
212 | 0x6e, 0x74, 0x73, 0x2d, 0x73, 0x64, 0x66, 0x2e, | ||
213 | 0x6f, 0x66, 0x66, 0x69, 0x63, 0x65, 0x2e, 0x6e, | ||
214 | 0x65, 0x74, 0x82, 0x1d, 0x63, 0x63, 0x73, 0x2e, | ||
215 | 0x6c, 0x6f, 0x67, 0x69, 0x6e, 0x2e, 0x6d, 0x69, | ||
216 | 0x63, 0x72, 0x6f, 0x73, 0x6f, 0x66, 0x74, 0x6f, | ||
217 | 0x6e, 0x6c, 0x69, 0x6e, 0x65, 0x2e, 0x63, 0x6f, | ||
218 | 0x6d, 0x82, 0x21, 0x63, 0x63, 0x73, 0x2d, 0x73, | ||
219 | 0x64, 0x66, 0x2e, 0x6c, 0x6f, 0x67, 0x69, 0x6e, | ||
220 | 0x2e, 0x6d, 0x69, 0x63, 0x72, 0x6f, 0x73, 0x6f, | ||
221 | 0x66, 0x74, 0x6f, 0x6e, 0x6c, 0x69, 0x6e, 0x65, | ||
222 | 0x2e, 0x63, 0x6f, 0x6d, 0x82, 0x0b, 0x68, 0x6f, | ||
223 | 0x74, 0x6d, 0x61, 0x69, 0x6c, 0x2e, 0x63, 0x6f, | ||
224 | 0x6d, 0x82, 0x16, 0x6d, 0x61, 0x69, 0x6c, 0x2e, | ||
225 | 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x73, | ||
226 | 0x2e, 0x6c, 0x69, 0x76, 0x65, 0x2e, 0x63, 0x6f, | ||
227 | 0x6d, 0x82, 0x0d, 0x6f, 0x66, 0x66, 0x69, 0x63, | ||
228 | 0x65, 0x33, 0x36, 0x35, 0x2e, 0x63, 0x6f, 0x6d, | ||
229 | 0x82, 0x12, 0x6f, 0x75, 0x74, 0x6c, 0x6f, 0x6f, | ||
230 | 0x6b, 0x2e, 0x6f, 0x66, 0x66, 0x69, 0x63, 0x65, | ||
231 | 0x2e, 0x63, 0x6f, 0x6d, 0x82, 0x14, 0x73, 0x75, | ||
232 | 0x62, 0x73, 0x74, 0x72, 0x61, 0x74, 0x65, 0x2e, | ||
233 | 0x6f, 0x66, 0x66, 0x69, 0x63, 0x65, 0x2e, 0x63, | ||
234 | 0x6f, 0x6d, 0x82, 0x18, 0x73, 0x75, 0x62, 0x73, | ||
235 | 0x74, 0x72, 0x61, 0x74, 0x65, 0x2d, 0x73, 0x64, | ||
236 | 0x66, 0x2e, 0x6f, 0x66, 0x66, 0x69, 0x63, 0x65, | ||
237 | 0x2e, 0x63, 0x6f, 0x6d, 0x30, 0x1d, 0x06, 0x03, | ||
238 | 0x55, 0x1d, 0x25, 0x04, 0x16, 0x30, 0x14, 0x06, | ||
239 | 0x08, 0x2b, 0x06, 0x01, 0x05, 0x05, 0x07, 0x03, | ||
240 | 0x01, 0x06, 0x08, 0x2b, 0x06, 0x01, 0x05, 0x05, | ||
241 | 0x07, 0x03, 0x02, 0x30, 0x1f, 0x06, 0x03, 0x55, | ||
242 | 0x1d, 0x23, 0x04, 0x18, 0x30, 0x16, 0x80, 0x14, | ||
243 | 0x68, 0x86, 0xb8, 0x7d, 0x7a, 0xd9, 0x6d, 0x49, | ||
244 | 0x6b, 0x87, 0x2f, 0x18, 0x8b, 0x15, 0x34, 0x6c, | ||
245 | 0xd7, 0xb4, 0x7a, 0x0e, 0x30, 0x1d, 0x06, 0x03, | ||
246 | 0x55, 0x1d, 0x0e, 0x04, 0x16, 0x04, 0x14, 0x8a, | ||
247 | 0x7c, 0x73, 0x44, 0x70, 0xa8, 0x4d, 0x83, 0x25, | ||
248 | 0x6f, 0xa6, 0x53, 0xda, 0x42, 0x52, 0x96, 0xc9, | ||
249 | 0x15, 0x71, 0x21, 0x30, 0x82, 0x01, 0x7c, 0x06, | ||
250 | 0x0a, 0x2b, 0x06, 0x01, 0x04, 0x01, 0xd6, 0x79, | ||
251 | 0x02, 0x04, 0x02, 0x04, 0x82, 0x01, 0x6c, 0x04, | ||
252 | 0x82, 0x01, 0x68, 0x01, 0x66, 0x00, 0x76, 0x00, | ||
253 | 0x22, 0x45, 0x45, 0x07, 0x59, 0x55, 0x24, 0x56, | ||
254 | 0x96, 0x3f, 0xa1, 0x2f, 0xf1, 0xf7, 0x6d, 0x86, | ||
255 | 0xe0, 0x23, 0x26, 0x63, 0xad, 0xc0, 0x4b, 0x7f, | ||
256 | 0x5d, 0xc6, 0x83, 0x5c, 0x6e, 0xe2, 0x0f, 0x02, | ||
257 | 0x00, 0x00, 0x01, 0x73, 0xea, 0x1e, 0x7d, 0x2f, | ||
258 | 0x00, 0x00, 0x04, 0x03, 0x00, 0x47, 0x30, 0x45, | ||
259 | 0x02, 0x21, 0x00, 0xf4, 0x50, 0x8f, 0xe7, 0x38, | ||
260 | 0xc9, 0x7a, 0xd1, 0xf7, 0xf7, 0x69, 0xc5, 0x05, | ||
261 | 0xea, 0x8e, 0x03, 0x80, 0x2c, 0x87, 0x06, 0x03, | ||
262 | 0xb6, 0x9b, 0xe6, 0xa5, 0x83, 0x2f, 0xb9, 0xaf, | ||
263 | 0x7b, 0xb4, 0xac, 0x02, 0x20, 0x51, 0xa6, 0x8f, | ||
264 | 0xe8, 0xe5, 0x6c, 0xa7, 0xff, 0x16, 0x01, 0x7e, | ||
265 | 0x15, 0x42, 0x11, 0x31, 0xdc, 0xdc, 0xc7, 0x37, | ||
266 | 0x7c, 0x64, 0x2c, 0xac, 0xdd, 0x42, 0xbb, 0x3c, | ||
267 | 0x79, 0x31, 0x74, 0xcc, 0x9d, 0x00, 0x75, 0x00, | ||
268 | 0x29, 0x79, 0xbe, 0xf0, 0x9e, 0x39, 0x39, 0x21, | ||
269 | 0xf0, 0x56, 0x73, 0x9f, 0x63, 0xa5, 0x77, 0xe5, | ||
270 | 0xbe, 0x57, 0x7d, 0x9c, 0x60, 0x0a, 0xf8, 0xf9, | ||
271 | 0x4d, 0x5d, 0x26, 0x5c, 0x25, 0x5d, 0xc7, 0x84, | ||
272 | 0x00, 0x00, 0x01, 0x73, 0xea, 0x1e, 0x7a, 0xa7, | ||
273 | 0x00, 0x00, 0x04, 0x03, 0x00, 0x46, 0x30, 0x44, | ||
274 | 0x02, 0x20, 0x03, 0xf1, 0x19, 0xd7, 0x0f, 0x2f, | ||
275 | 0xc4, 0xa9, 0x84, 0xa0, 0x33, 0xd4, 0x76, 0xa6, | ||
276 | 0xee, 0xf1, 0xae, 0xe0, 0x03, 0xe7, 0xae, 0x98, | ||
277 | 0x43, 0x17, 0xb0, 0x0f, 0xfb, 0x12, 0xbb, 0x13, | ||
278 | 0xda, 0x34, 0x02, 0x20, 0x10, 0xe6, 0xa9, 0x1d, | ||
279 | 0x8b, 0x1c, 0x64, 0xd4, 0xc9, 0xf7, 0xc0, 0x3d, | ||
280 | 0x3c, 0x77, 0x49, 0xb1, 0x08, 0x3d, 0x1d, 0x5e, | ||
281 | 0x34, 0xf9, 0xd9, 0x10, 0x7c, 0x74, 0x6b, 0x18, | ||
282 | 0xc6, 0x5e, 0x6d, 0x07, 0x00, 0x75, 0x00, 0x55, | ||
283 | 0x81, 0xd4, 0xc2, 0x16, 0x90, 0x36, 0x01, 0x4a, | ||
284 | 0xea, 0x0b, 0x9b, 0x57, 0x3c, 0x53, 0xf0, 0xc0, | ||
285 | 0xe4, 0x38, 0x78, 0x70, 0x25, 0x08, 0x17, 0x2f, | ||
286 | 0xa3, 0xaa, 0x1d, 0x07, 0x13, 0xd3, 0x0c, 0x00, | ||
287 | 0x00, 0x01, 0x73, 0xea, 0x1e, 0x7d, 0xae, 0x00, | ||
288 | 0x00, 0x04, 0x03, 0x00, 0x46, 0x30, 0x44, 0x02, | ||
289 | 0x20, 0x26, 0x21, 0x64, 0xdb, 0xa6, 0xe2, 0x3d, | ||
290 | 0x32, 0x7d, 0x9f, 0xa8, 0xae, 0xb7, 0x29, 0xb7, | ||
291 | 0x42, 0x9b, 0x49, 0xaa, 0xf5, 0xa5, 0xc0, 0x12, | ||
292 | 0x01, 0xa1, 0xb6, 0xe7, 0xf2, 0x01, 0xd4, 0x2f, | ||
293 | 0x45, 0x02, 0x20, 0x4e, 0x19, 0xba, 0x47, 0x75, | ||
294 | 0x8b, 0x49, 0xd7, 0x4b, 0xba, 0x04, 0x62, 0xdd, | ||
295 | 0xa2, 0xb7, 0x6b, 0x05, 0xd0, 0x01, 0x1f, 0x7c, | ||
296 | 0x36, 0x17, 0x27, 0x29, 0xb2, 0x17, 0x1c, 0x7f, | ||
297 | 0x10, 0x81, 0x8a, 0x30, 0x0d, 0x06, 0x09, 0x2a, | ||
298 | 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, | ||
299 | 0x05, 0x00, 0x03, 0x82, 0x01, 0x01, 0x00, 0x26, | ||
300 | 0xf4, 0xa3, 0x77, 0x1d, 0xdc, 0x9e, 0xc4, 0x1a, | ||
301 | 0x88, 0x23, 0x30, 0x8c, 0xe1, 0x14, 0xf9, 0x62, | ||
302 | 0x0e, 0xbf, 0xad, 0x24, 0xc9, 0xab, 0xab, 0xd0, | ||
303 | 0x68, 0x8b, 0xbc, 0xf1, 0xec, 0x1c, 0xd0, 0x96, | ||
304 | 0xad, 0xf9, 0x5f, 0xdd, 0xe0, 0xee, 0xa8, 0xe0, | ||
305 | 0x2c, 0x3a, 0x19, 0xa5, 0x68, 0x0c, 0x6e, 0xfe, | ||
306 | 0xe6, 0x80, 0xce, 0xa3, 0x3b, 0x6c, 0x00, 0x88, | ||
307 | 0x5c, 0xbf, 0x3c, 0xd8, 0x68, 0x08, 0x36, 0xb9, | ||
308 | 0x9e, 0x84, 0x9b, 0x5f, 0x97, 0xfb, 0x77, 0xea, | ||
309 | 0x72, 0xfb, 0x73, 0x47, 0x00, 0xb0, 0xa8, 0x7c, | ||
310 | 0x64, 0x38, 0xf1, 0xcc, 0xc0, 0x29, 0x71, 0x67, | ||
311 | 0x65, 0x76, 0x4c, 0x80, 0x58, 0x97, 0xc8, 0x62, | ||
312 | 0x63, 0x3e, 0xf1, 0x3e, 0xc0, 0x0e, 0x48, 0x5f, | ||
313 | 0x55, 0x21, 0x8f, 0x96, 0x68, 0xbd, 0x41, 0x14, | ||
314 | 0x7a, 0x0b, 0x8c, 0x31, 0x5b, 0x39, 0xac, 0xa3, | ||
315 | 0xa0, 0x99, 0x58, 0x24, 0xfa, 0xd9, 0x19, 0x32, | ||
316 | 0x1c, 0x9f, 0x2d, 0xa9, 0xed, 0xb9, 0x97, 0xa4, | ||
317 | 0x66, 0x30, 0x29, 0xd8, 0x82, 0xa2, 0xf5, 0xfc, | ||
318 | 0x6d, 0x10, 0xf1, 0xac, 0x1d, 0x3f, 0xfb, 0xde, | ||
319 | 0xa1, 0x0e, 0xb6, 0x84, 0x90, 0xd4, 0x55, 0x5c, | ||
320 | 0x21, 0x1b, 0x1f, 0x21, 0x45, 0x92, 0xc5, 0x9a, | ||
321 | 0x47, 0x05, 0x0f, 0xb8, 0x1c, 0x78, 0x6e, 0xb9, | ||
322 | 0x6b, 0xa3, 0xa9, 0x8d, 0xb1, 0x59, 0xff, 0xf4, | ||
323 | 0xe6, 0x71, 0x77, 0x38, 0x12, 0xfe, 0x41, 0x8f, | ||
324 | 0x04, 0x92, 0x08, 0x3f, 0x32, 0x2a, 0x92, 0x5e, | ||
325 | 0x0a, 0x7b, 0x7e, 0x04, 0xee, 0x24, 0x10, 0x39, | ||
326 | 0xf3, 0xac, 0x5e, 0x04, 0x93, 0x91, 0xa2, 0x8f, | ||
327 | 0x90, 0x04, 0x33, 0x5c, 0x5c, 0x94, 0xb3, 0x80, | ||
328 | 0x2b, 0x43, 0xbf, 0xe3, 0x74, 0x64, 0x20, 0xf4, | ||
329 | 0x00, 0xb2, 0x6c, 0x7b, 0xa8, 0x77, 0xfb, 0x74, | ||
330 | 0x35, 0xce, 0xdd, 0xb6, 0x5f, 0x83, 0x18, 0xc4, | ||
331 | 0xe7, 0x31, 0x1a, 0x8d, 0x30, 0x0d, 0xc4, 0x00, | ||
332 | 0x04, 0x8f, 0x30, 0x82, 0x04, 0x8b, 0x30, 0x82, | ||
333 | 0x03, 0x73, 0xa0, 0x03, 0x02, 0x01, 0x02, 0x02, | ||
334 | 0x0e, 0x47, 0x07, 0xb1, 0x01, 0x9a, 0x0c, 0x57, | ||
335 | 0xad, 0x39, 0xb3, 0xe1, 0x7d, 0xa9, 0xf9, 0x30, | ||
336 | 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, | ||
337 | 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00, 0x30, 0x57, | ||
338 | 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, | ||
339 | 0x06, 0x13, 0x02, 0x42, 0x45, 0x31, 0x19, 0x30, | ||
340 | 0x17, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x13, 0x10, | ||
341 | 0x47, 0x6c, 0x6f, 0x62, 0x61, 0x6c, 0x53, 0x69, | ||
342 | 0x67, 0x6e, 0x20, 0x6e, 0x76, 0x2d, 0x73, 0x61, | ||
343 | 0x31, 0x10, 0x30, 0x0e, 0x06, 0x03, 0x55, 0x04, | ||
344 | 0x0b, 0x13, 0x07, 0x52, 0x6f, 0x6f, 0x74, 0x20, | ||
345 | 0x43, 0x41, 0x31, 0x1b, 0x30, 0x19, 0x06, 0x03, | ||
346 | 0x55, 0x04, 0x03, 0x13, 0x12, 0x47, 0x6c, 0x6f, | ||
347 | 0x62, 0x61, 0x6c, 0x53, 0x69, 0x67, 0x6e, 0x20, | ||
348 | 0x52, 0x6f, 0x6f, 0x74, 0x20, 0x43, 0x41, 0x30, | ||
349 | 0x1e, 0x17, 0x0d, 0x31, 0x35, 0x30, 0x39, 0x30, | ||
350 | 0x34, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x5a, | ||
351 | 0x17, 0x0d, 0x32, 0x35, 0x30, 0x39, 0x30, 0x34, | ||
352 | 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x5a, 0x30, | ||
353 | 0x66, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, | ||
354 | 0x04, 0x06, 0x13, 0x02, 0x42, 0x45, 0x31, 0x19, | ||
355 | 0x30, 0x17, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x13, | ||
356 | 0x10, 0x47, 0x6c, 0x6f, 0x62, 0x61, 0x6c, 0x53, | ||
357 | 0x69, 0x67, 0x6e, 0x20, 0x6e, 0x76, 0x2d, 0x73, | ||
358 | 0x61, 0x31, 0x3c, 0x30, 0x3a, 0x06, 0x03, 0x55, | ||
359 | 0x04, 0x03, 0x13, 0x33, 0x47, 0x6c, 0x6f, 0x62, | ||
360 | 0x61, 0x6c, 0x53, 0x69, 0x67, 0x6e, 0x20, 0x4f, | ||
361 | 0x72, 0x67, 0x61, 0x6e, 0x69, 0x7a, 0x61, 0x74, | ||
362 | 0x69, 0x6f, 0x6e, 0x20, 0x56, 0x61, 0x6c, 0x69, | ||
363 | 0x64, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x43, | ||
364 | 0x41, 0x20, 0x2d, 0x20, 0x53, 0x48, 0x41, 0x32, | ||
365 | 0x35, 0x36, 0x20, 0x2d, 0x20, 0x47, 0x33, 0x30, | ||
366 | 0x82, 0x01, 0x22, 0x30, 0x0d, 0x06, 0x09, 0x2a, | ||
367 | 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01, | ||
368 | 0x05, 0x00, 0x03, 0x82, 0x01, 0x0f, 0x00, 0x30, | ||
369 | 0x82, 0x01, 0x0a, 0x02, 0x82, 0x01, 0x01, 0x00, | ||
370 | 0xc9, 0x86, 0xa2, 0x05, 0x3e, 0xec, 0x77, 0x4d, | ||
371 | 0x79, 0x42, 0x81, 0xf2, 0xc5, 0x46, 0xa9, 0xc2, | ||
372 | 0x9b, 0xf9, 0x57, 0xa9, 0x48, 0xdd, 0x3c, 0x3b, | ||
373 | 0xe2, 0x16, 0x47, 0x83, 0x15, 0x0c, 0x36, 0x88, | ||
374 | 0x61, 0xb3, 0xc8, 0xb9, 0xd5, 0x20, 0x97, 0xb6, | ||
375 | 0xfe, 0x07, 0x30, 0x01, 0x9e, 0x01, 0x3a, 0xf9, | ||
376 | 0x50, 0x87, 0xa0, 0x4f, 0x60, 0xcc, 0x90, 0xf6, | ||
377 | 0xdd, 0x1f, 0xa6, 0xc7, 0x55, 0x00, 0x6c, 0x54, | ||
378 | 0x31, 0x5f, 0x02, 0x9a, 0xf7, 0x7f, 0x07, 0x9a, | ||
379 | 0xd2, 0x22, 0x53, 0x05, 0xcd, 0x9f, 0xc7, 0xbb, | ||
380 | 0x7b, 0x59, 0x3b, 0x8a, 0xb2, 0x93, 0x78, 0x0d, | ||
381 | 0x43, 0x02, 0x92, 0x76, 0xa5, 0x29, 0xf8, 0x7c, | ||
382 | 0x9d, 0x5c, 0x3a, 0xa2, 0xf8, 0x52, 0x72, 0x22, | ||
383 | 0x45, 0x91, 0xfd, 0x90, 0x12, 0x28, 0x4d, 0x75, | ||
384 | 0xe4, 0xdd, 0xaa, 0x79, 0x58, 0x68, 0x6f, 0x2a, | ||
385 | 0x7e, 0x7b, 0xef, 0xd1, 0x9e, 0x7f, 0x52, 0xdc, | ||
386 | 0xcb, 0x1c, 0x48, 0xe2, 0x3e, 0x4d, 0x5c, 0x47, | ||
387 | 0x7a, 0xb4, 0xf1, 0xce, 0xff, 0xd9, 0x60, 0x2b, | ||
388 | 0x77, 0xd1, 0x62, 0x22, 0x2d, 0xa9, 0x5a, 0x06, | ||
389 | 0x16, 0xee, 0x37, 0x6a, 0x51, 0xcf, 0x8e, 0xa5, | ||
390 | 0xd1, 0x6e, 0x70, 0x4a, 0xf0, 0xd8, 0x63, 0x60, | ||
391 | 0x6a, 0x72, 0x55, 0xd7, 0xf1, 0x99, 0x38, 0x86, | ||
392 | 0x44, 0x67, 0x18, 0xe0, 0x71, 0x8e, 0xc1, 0x40, | ||
393 | 0x6d, 0x85, 0xda, 0x4b, 0xdd, 0x31, 0x73, 0xbc, | ||
394 | 0x32, 0xcc, 0x6f, 0x8e, 0x7b, 0xb9, 0x8d, 0x4b, | ||
395 | 0x80, 0xda, 0xb9, 0xc7, 0xc6, 0x24, 0x83, 0x5e, | ||
396 | 0x32, 0xfb, 0x87, 0xe9, 0x8b, 0x61, 0x67, 0xa2, | ||
397 | 0x99, 0x76, 0xdb, 0xa5, 0xaa, 0xb4, 0xe8, 0x6c, | ||
398 | 0x41, 0x9f, 0x5f, 0x2a, 0xb3, 0xd5, 0x7d, 0xd7, | ||
399 | 0x92, 0xc8, 0x27, 0x4b, 0xec, 0x1f, 0xda, 0x05, | ||
400 | 0x6d, 0x88, 0x73, 0x8f, 0x06, 0xb2, 0x38, 0x3d, | ||
401 | 0x03, 0xa2, 0xe1, 0x87, 0x86, 0x3c, 0xc6, 0xa1, | ||
402 | 0x02, 0x03, 0x01, 0x00, 0x01, 0xa3, 0x82, 0x01, | ||
403 | 0x44, 0x30, 0x82, 0x01, 0x40, 0x30, 0x0e, 0x06, | ||
404 | 0x03, 0x55, 0x1d, 0x0f, 0x01, 0x01, 0xff, 0x04, | ||
405 | 0x04, 0x03, 0x02, 0x01, 0x06, 0x30, 0x1d, 0x06, | ||
406 | 0x03, 0x55, 0x1d, 0x25, 0x04, 0x16, 0x30, 0x14, | ||
407 | 0x06, 0x08, 0x2b, 0x06, 0x01, 0x05, 0x05, 0x07, | ||
408 | 0x03, 0x01, 0x06, 0x08, 0x2b, 0x06, 0x01, 0x05, | ||
409 | 0x05, 0x07, 0x03, 0x02, 0x30, 0x12, 0x06, 0x03, | ||
410 | 0x55, 0x1d, 0x13, 0x01, 0x01, 0xff, 0x04, 0x08, | ||
411 | 0x30, 0x06, 0x01, 0x01, 0xff, 0x02, 0x01, 0x00, | ||
412 | 0x30, 0x1d, 0x06, 0x03, 0x55, 0x1d, 0x0e, 0x04, | ||
413 | 0x16, 0x04, 0x14, 0x68, 0x86, 0xb8, 0x7d, 0x7a, | ||
414 | 0xd9, 0x6d, 0x49, 0x6b, 0x87, 0x2f, 0x18, 0x8b, | ||
415 | 0x15, 0x34, 0x6c, 0xd7, 0xb4, 0x7a, 0x0e, 0x30, | ||
416 | 0x1f, 0x06, 0x03, 0x55, 0x1d, 0x23, 0x04, 0x18, | ||
417 | 0x30, 0x16, 0x80, 0x14, 0x60, 0x7b, 0x66, 0x1a, | ||
418 | 0x45, 0x0d, 0x97, 0xca, 0x89, 0x50, 0x2f, 0x7d, | ||
419 | 0x04, 0xcd, 0x34, 0xa8, 0xff, 0xfc, 0xfd, 0x4b, | ||
420 | 0x30, 0x3d, 0x06, 0x08, 0x2b, 0x06, 0x01, 0x05, | ||
421 | 0x05, 0x07, 0x01, 0x01, 0x04, 0x31, 0x30, 0x2f, | ||
422 | 0x30, 0x2d, 0x06, 0x08, 0x2b, 0x06, 0x01, 0x05, | ||
423 | 0x05, 0x07, 0x30, 0x01, 0x86, 0x21, 0x68, 0x74, | ||
424 | 0x74, 0x70, 0x3a, 0x2f, 0x2f, 0x6f, 0x63, 0x73, | ||
425 | 0x70, 0x2e, 0x67, 0x6c, 0x6f, 0x62, 0x61, 0x6c, | ||
426 | 0x73, 0x69, 0x67, 0x6e, 0x2e, 0x63, 0x6f, 0x6d, | ||
427 | 0x2f, 0x72, 0x6f, 0x6f, 0x74, 0x72, 0x31, 0x30, | ||
428 | 0x33, 0x06, 0x03, 0x55, 0x1d, 0x1f, 0x04, 0x2c, | ||
429 | 0x30, 0x2a, 0x30, 0x28, 0xa0, 0x26, 0xa0, 0x24, | ||
430 | 0x86, 0x22, 0x68, 0x74, 0x74, 0x70, 0x3a, 0x2f, | ||
431 | 0x2f, 0x63, 0x72, 0x6c, 0x2e, 0x67, 0x6c, 0x6f, | ||
432 | 0x62, 0x61, 0x6c, 0x73, 0x69, 0x67, 0x6e, 0x2e, | ||
433 | 0x63, 0x6f, 0x6d, 0x2f, 0x72, 0x6f, 0x6f, 0x74, | ||
434 | 0x2e, 0x63, 0x72, 0x6c, 0x30, 0x47, 0x06, 0x03, | ||
435 | 0x55, 0x1d, 0x20, 0x04, 0x40, 0x30, 0x3e, 0x30, | ||
436 | 0x3c, 0x06, 0x04, 0x55, 0x1d, 0x20, 0x00, 0x30, | ||
437 | 0x34, 0x30, 0x32, 0x06, 0x08, 0x2b, 0x06, 0x01, | ||
438 | 0x05, 0x05, 0x07, 0x02, 0x01, 0x16, 0x26, 0x68, | ||
439 | 0x74, 0x74, 0x70, 0x73, 0x3a, 0x2f, 0x2f, 0x77, | ||
440 | 0x77, 0x77, 0x2e, 0x67, 0x6c, 0x6f, 0x62, 0x61, | ||
441 | 0x6c, 0x73, 0x69, 0x67, 0x6e, 0x2e, 0x63, 0x6f, | ||
442 | 0x6d, 0x2f, 0x72, 0x65, 0x70, 0x6f, 0x73, 0x69, | ||
443 | 0x74, 0x6f, 0x72, 0x79, 0x2f, 0x30, 0x0d, 0x06, | ||
444 | 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, | ||
445 | 0x01, 0x0b, 0x05, 0x00, 0x03, 0x82, 0x01, 0x01, | ||
446 | 0x00, 0x9a, 0xb9, 0x82, 0x1c, 0xdd, 0x83, 0x83, | ||
447 | 0x8b, 0x92, 0xc0, 0xc4, 0xed, 0x01, 0xad, 0x84, | ||
448 | 0xfc, 0x4e, 0xee, 0x6d, 0x9c, 0x1d, 0x01, 0xfa, | ||
449 | 0x52, 0x14, 0xdb, 0xd8, 0xc2, 0x10, 0x63, 0x9f, | ||
450 | 0x6b, 0x39, 0x9a, 0xc7, 0x1c, 0x3c, 0xa0, 0xaa, | ||
451 | 0xe3, 0x19, 0x3a, 0xfc, 0x64, 0x46, 0x2a, 0xef, | ||
452 | 0x35, 0x26, 0x03, 0xf6, 0x05, 0x67, 0xfa, 0x6e, | ||
453 | 0x74, 0xe1, 0x46, 0xfb, 0x40, 0xd8, 0x6f, 0xae, | ||
454 | 0x2d, 0x39, 0x21, 0x74, 0x86, 0x9f, 0x00, 0x05, | ||
455 | 0x1a, 0x3f, 0x2f, 0x93, 0x5b, 0xd4, 0xa4, 0x45, | ||
456 | 0xbc, 0x3d, 0x0c, 0x29, 0x17, 0x5a, 0xd3, 0xfb, | ||
457 | 0x68, 0xa6, 0x0f, 0xe0, 0x00, 0x68, 0x79, 0xb0, | ||
458 | 0x4c, 0xb1, 0x45, 0x8b, 0xc8, 0x85, 0x8c, 0x67, | ||
459 | 0x0e, 0x8c, 0x7d, 0x54, 0xf8, 0xb0, 0x75, 0xce, | ||
460 | 0x0a, 0xac, 0x1d, 0xd7, 0x6b, 0x44, 0xac, 0xfe, | ||
461 | 0x1b, 0xd4, 0xa6, 0x98, 0x21, 0x09, 0x3e, 0xa2, | ||
462 | 0x4b, 0x33, 0xba, 0xba, 0x4b, 0x12, 0xa8, 0x6b, | ||
463 | 0x57, 0x27, 0x9d, 0xfa, 0x94, 0x80, 0xb4, 0x68, | ||
464 | 0x4c, 0x77, 0x60, 0xff, 0xd7, 0x29, 0x5a, 0x38, | ||
465 | 0x3d, 0xce, 0x2d, 0x4b, 0x08, 0x56, 0x9f, 0x69, | ||
466 | 0xcb, 0x7b, 0xd8, 0xe2, 0x36, 0xf9, 0x37, 0x69, | ||
467 | 0xc5, 0xce, 0x36, 0x97, 0x1c, 0xba, 0x0d, 0x3f, | ||
468 | 0x15, 0xb3, 0x65, 0xa0, 0xec, 0x74, 0x12, 0xbd, | ||
469 | 0xb3, 0xad, 0xe8, 0xde, 0x9e, 0xa1, 0xec, 0xd3, | ||
470 | 0xbf, 0xa9, 0xe0, 0xa5, 0x91, 0x6d, 0x83, 0x59, | ||
471 | 0x12, 0x56, 0x2f, 0x13, 0xa6, 0x7e, 0x79, 0x73, | ||
472 | 0xa1, 0xa3, 0x89, 0xd5, 0xe1, 0xa5, 0x8c, 0xce, | ||
473 | 0x2d, 0xac, 0x8a, 0xcf, 0x62, 0x16, 0x65, 0xcd, | ||
474 | 0xd9, 0xee, 0xa8, 0xb6, 0x40, 0x08, 0xb5, 0x7c, | ||
475 | 0x50, 0xf9, 0x37, 0x82, 0x7a, 0xa4, 0x0b, 0x34, | ||
476 | 0x66, 0xec, 0xe9, 0x97, 0x57, 0x1f, 0x8a, 0x67, | ||
477 | 0x3e, 0x81, 0xbc, 0x3b, 0x35, 0xd3, 0x2a, 0x48, | ||
478 | 0x0c, 0x0c, 0x00, 0x01, 0x69, 0x03, 0x00, 0x18, | ||
479 | 0x61, 0x04, 0xb7, 0xa9, 0xbd, 0x74, 0x71, 0xd5, | ||
480 | 0x68, 0xbf, 0xd8, 0xa6, 0x84, 0x12, 0xaf, 0x8f, | ||
481 | 0xd4, 0x2c, 0xcf, 0xf9, 0x72, 0x2b, 0x8c, 0x6c, | ||
482 | 0x73, 0xa3, 0x13, 0x74, 0xdb, 0x83, 0x3e, 0xa6, | ||
483 | 0xf4, 0x1b, 0xee, 0xa9, 0x34, 0xe5, 0x65, 0xa7, | ||
484 | 0xaf, 0xef, 0xf2, 0xac, 0xfb, 0x87, 0xb4, 0xdb, | ||
485 | 0x8b, 0x05, 0x4f, 0xe8, 0x25, 0x3d, 0x32, 0x65, | ||
486 | 0xda, 0x47, 0xd8, 0xd2, 0x86, 0xad, 0x9b, 0x37, | ||
487 | 0xbc, 0x45, 0xef, 0xb6, 0x91, 0xa2, 0x71, 0x2f, | ||
488 | 0x13, 0x68, 0xfa, 0xa7, 0x20, 0xe4, 0x8a, 0xa8, | ||
489 | 0x9b, 0xbe, 0xf6, 0x7c, 0xc8, 0x16, 0xd4, 0x50, | ||
490 | 0x9d, 0x63, 0xb3, 0xf4, 0x6e, 0xd3, 0x8f, 0x32, | ||
491 | 0x68, 0x66, 0x04, 0x01, 0x01, 0x00, 0xaa, 0xcb, | ||
492 | 0x90, 0xbd, 0x94, 0x10, 0xab, 0xfc, 0x30, 0x1d, | ||
493 | 0x68, 0x1c, 0xb4, 0x21, 0xcf, 0x73, 0xa5, 0x4b, | ||
494 | 0x20, 0x94, 0xde, 0x66, 0x99, 0x54, 0x3f, 0xba, | ||
495 | 0x40, 0x58, 0x50, 0xe3, 0x64, 0x53, 0x90, 0x9e, | ||
496 | 0xf8, 0x67, 0xcc, 0x85, 0x4a, 0xdc, 0xd8, 0xd7, | ||
497 | 0xc8, 0xb5, 0xe0, 0x92, 0x02, 0x6b, 0xa8, 0x76, | ||
498 | 0x67, 0xc5, 0xae, 0x12, 0x56, 0xff, 0xd1, 0xda, | ||
499 | 0xc0, 0x48, 0x17, 0x99, 0xc9, 0xbe, 0x02, 0xc6, | ||
500 | 0x9e, 0x5c, 0xd9, 0x44, 0x3f, 0x06, 0xbd, 0x98, | ||
501 | 0xe3, 0x4d, 0x46, 0x10, 0xe8, 0x20, 0xed, 0x7b, | ||
502 | 0xcd, 0x73, 0xed, 0x03, 0x6a, 0x4c, 0x49, 0xaf, | ||
503 | 0xbe, 0xa3, 0xe0, 0xab, 0x9a, 0xb8, 0xf8, 0x06, | ||
504 | 0x25, 0x31, 0x8d, 0x32, 0x44, 0xfd, 0xd6, 0xb0, | ||
505 | 0xd4, 0x6c, 0x9a, 0x2a, 0x0f, 0xab, 0xe2, 0x13, | ||
506 | 0x10, 0x6d, 0x41, 0x0b, 0x97, 0x74, 0xa0, 0x04, | ||
507 | 0x16, 0x60, 0xf1, 0x8e, 0x74, 0xf3, 0x91, 0x75, | ||
508 | 0x2b, 0x92, 0x2b, 0xc7, 0x5b, 0x6f, 0x1d, 0x70, | ||
509 | 0xe2, 0xc6, 0x9a, 0x7d, 0x66, 0x55, 0x98, 0x01, | ||
510 | 0x71, 0xb8, 0xdd, 0xf4, 0x70, 0xc9, 0x74, 0x56, | ||
511 | 0xcc, 0xa5, 0x2c, 0x51, 0x70, 0x72, 0xc2, 0x44, | ||
512 | 0xb9, 0x59, 0xc3, 0xc3, 0xf8, 0x29, 0x4e, 0x79, | ||
513 | 0x40, 0x9b, 0x30, 0x35, 0x66, 0xb2, 0xd8, 0x7d, | ||
514 | 0xfe, 0x65, 0x6b, 0xf0, 0x17, 0xa3, 0x13, 0xc7, | ||
515 | 0xc7, 0xc6, 0x48, 0xb2, 0xae, 0x4f, 0x26, 0x0b, | ||
516 | 0x8a, 0x40, 0xaa, 0x06, 0x65, 0x8a, 0x95, 0x00, | ||
517 | 0xc4, 0xc9, 0xfd, 0x69, 0x0a, 0xa9, 0x0a, 0x18, | ||
518 | 0xff, 0x95, 0x40, 0xab, 0x84, 0x75, 0xfe, 0x11, | ||
519 | 0xb1, 0x6f, 0xca, 0x5e, 0xf7, 0xe4, 0x1d, 0x8d, | ||
520 | 0x08, 0x1c, 0xd3, 0x95, 0xf4, 0x9b, 0x17, 0x41, | ||
521 | 0xa8, 0x8f, 0x6e, 0xfa, 0x6c, 0x43, 0x60, 0x39, | ||
522 | 0x0a, 0xa2, 0x7e, 0xdf, 0x3e, 0x74, 0xc2, 0xbf, | ||
523 | 0xaf, 0x96, 0x96, 0xbd, 0x21, 0x4b, 0x0d, 0x00, | ||
524 | 0x00, 0x1a, 0x03, 0x01, 0x02, 0x40, 0x00, 0x12, | ||
525 | 0x04, 0x01, 0x05, 0x01, 0x02, 0x01, 0x04, 0x03, | ||
526 | 0x05, 0x03, 0x02, 0x03, 0x02, 0x02, 0x06, 0x01, | ||
527 | 0x06, 0x03, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x00, | ||
528 | }; | ||
529 | |||
530 | struct tlslegacy_client_test { | ||
531 | const unsigned char *desc; | ||
532 | unsigned char *server_response; | ||
533 | const size_t server_response_len; | ||
534 | const SSL_METHOD *(*ssl_method)(void); | ||
535 | int want_state; | ||
536 | }; | ||
537 | |||
538 | static struct tlslegacy_client_test tlslegacy_client_tests[] = { | ||
539 | { | ||
540 | .desc = "TLSv1.2 legacy fallback", | ||
541 | .server_response = tls12_server_response, | ||
542 | .server_response_len = sizeof(tls12_server_response), | ||
543 | .ssl_method = TLS_client_method, | ||
544 | .want_state = SSL3_ST_CR_CERT_A, | ||
545 | }, | ||
546 | { | ||
547 | .desc = "TLSv1.2 legacy fallback with server cert", | ||
548 | .server_response = tls12_server_response_with_cert, | ||
549 | .server_response_len = sizeof(tls12_server_response_with_cert), | ||
550 | .ssl_method = TLS_client_method, | ||
551 | .want_state = SSL3_ST_CR_KEY_EXCH_B, | ||
552 | }, | ||
553 | }; | ||
554 | |||
555 | #define N_TLSLEGACY_CLIENT_TESTS \ | ||
556 | (sizeof(tlslegacy_client_tests) / sizeof(*tlslegacy_client_tests)) | ||
557 | |||
558 | static int | ||
559 | tlslegacy_client_test(int testno, struct tlslegacy_client_test *tct) | ||
560 | { | ||
561 | BIO *rbio = NULL, *wbio = NULL; | ||
562 | SSL_CTX *ssl_ctx = NULL; | ||
563 | SSL *ssl = NULL; | ||
564 | int ret = 1; | ||
565 | |||
566 | fprintf(stderr, "Test %d - %s\n", testno, tct->desc); | ||
567 | |||
568 | if ((rbio = BIO_new_mem_buf(tct->server_response, | ||
569 | tct->server_response_len)) == NULL) { | ||
570 | fprintf(stderr, "Failed to setup rbio\n"); | ||
571 | goto failure; | ||
572 | } | ||
573 | if ((wbio = BIO_new(BIO_s_mem())) == NULL) { | ||
574 | fprintf(stderr, "Failed to setup wbio\n"); | ||
575 | goto failure; | ||
576 | } | ||
577 | |||
578 | if ((ssl_ctx = SSL_CTX_new(tct->ssl_method())) == NULL) { | ||
579 | fprintf(stderr, "SSL_CTX_new() returned NULL\n"); | ||
580 | goto failure; | ||
581 | } | ||
582 | |||
583 | if ((ssl = SSL_new(ssl_ctx)) == NULL) { | ||
584 | fprintf(stderr, "SSL_new() returned NULL\n"); | ||
585 | goto failure; | ||
586 | } | ||
587 | |||
588 | BIO_up_ref(rbio); | ||
589 | BIO_up_ref(wbio); | ||
590 | SSL_set_bio(ssl, rbio, wbio); | ||
591 | |||
592 | if (SSL_connect(ssl) == 1) { | ||
593 | fprintf(stderr, "SSL_connect() succeeded\n"); | ||
594 | goto failure; | ||
595 | } | ||
596 | |||
597 | if (SSL_state(ssl) != tct->want_state) { | ||
598 | fprintf(stderr, "FAIL: Got SSL state %x, want %x", | ||
599 | SSL_state(ssl), tct->want_state); | ||
600 | goto failure; | ||
601 | } | ||
602 | |||
603 | ret = 0; | ||
604 | |||
605 | failure: | ||
606 | SSL_CTX_free(ssl_ctx); | ||
607 | SSL_free(ssl); | ||
608 | |||
609 | BIO_free(rbio); | ||
610 | BIO_free(wbio); | ||
611 | |||
612 | return (ret); | ||
613 | } | ||
614 | |||
615 | int | ||
616 | main(int argc, char **argv) | ||
617 | { | ||
618 | int failed = 0; | ||
619 | size_t i; | ||
620 | |||
621 | for (i = 0; i < N_TLSLEGACY_CLIENT_TESTS; i++) | ||
622 | failed |= tlslegacy_client_test(i, &tlslegacy_client_tests[i]); | ||
623 | |||
624 | return (failed); | ||
625 | } | ||