1 | /*
|
---|
2 | * Copyright 2022-2024 The OpenSSL Project Authors. All Rights Reserved.
|
---|
3 | *
|
---|
4 | * Licensed under the Apache License 2.0 (the "License"). You may not use
|
---|
5 | * this file except in compliance with the License. You can obtain a copy
|
---|
6 | * in the file LICENSE in the source distribution or at
|
---|
7 | * https://www.openssl.org/source/license.html
|
---|
8 | */
|
---|
9 |
|
---|
10 | #include <stdio.h>
|
---|
11 | #include <string.h>
|
---|
12 |
|
---|
13 | #include <openssl/opensslconf.h>
|
---|
14 | #include <openssl/quic.h>
|
---|
15 | #include <openssl/rand.h>
|
---|
16 |
|
---|
17 | #include "helpers/ssltestlib.h"
|
---|
18 | #include "helpers/quictestlib.h"
|
---|
19 | #include "testutil.h"
|
---|
20 | #include "testutil/output.h"
|
---|
21 | #include "../ssl/ssl_local.h"
|
---|
22 | #include "internal/quic_error.h"
|
---|
23 |
|
---|
24 | static OSSL_LIB_CTX *libctx = NULL;
|
---|
25 | static OSSL_PROVIDER *defctxnull = NULL;
|
---|
26 | static char *certsdir = NULL;
|
---|
27 | static char *cert = NULL;
|
---|
28 | static char *ccert = NULL;
|
---|
29 | static char *cauthca = NULL;
|
---|
30 | static char *privkey = NULL;
|
---|
31 | static char *cprivkey = NULL;
|
---|
32 | static char *datadir = NULL;
|
---|
33 |
|
---|
34 | static int is_fips = 0;
|
---|
35 |
|
---|
36 | /* The ssltrace test assumes some options are switched on/off */
|
---|
37 | #if !defined(OPENSSL_NO_SSL_TRACE) \
|
---|
38 | && defined(OPENSSL_NO_BROTLI) && defined(OPENSSL_NO_ZSTD) \
|
---|
39 | && !defined(OPENSSL_NO_ECX) && !defined(OPENSSL_NO_DH)
|
---|
40 | # define DO_SSL_TRACE_TEST
|
---|
41 | #endif
|
---|
42 |
|
---|
43 | /*
|
---|
44 | * Test that we read what we've written.
|
---|
45 | * Test 0: Non-blocking
|
---|
46 | * Test 1: Blocking
|
---|
47 | * Test 2: Blocking, introduce socket error, test error handling.
|
---|
48 | */
|
---|
49 | static int test_quic_write_read(int idx)
|
---|
50 | {
|
---|
51 | SSL_CTX *cctx = SSL_CTX_new_ex(libctx, NULL, OSSL_QUIC_client_method());
|
---|
52 | SSL_CTX *sctx = NULL;
|
---|
53 | SSL *clientquic = NULL;
|
---|
54 | QUIC_TSERVER *qtserv = NULL;
|
---|
55 | int j, k, ret = 0;
|
---|
56 | unsigned char buf[20], scratch[64];
|
---|
57 | static char *msg = "A test message";
|
---|
58 | size_t msglen = strlen(msg);
|
---|
59 | size_t numbytes = 0;
|
---|
60 | int ssock = 0, csock = 0;
|
---|
61 | uint64_t sid = UINT64_MAX;
|
---|
62 | SSL_SESSION *sess = NULL;
|
---|
63 |
|
---|
64 | if (idx >= 1 && !qtest_supports_blocking())
|
---|
65 | return TEST_skip("Blocking tests not supported in this build");
|
---|
66 |
|
---|
67 | for (k = 0; k < 2; k++) {
|
---|
68 | if (!TEST_ptr(cctx)
|
---|
69 | || !TEST_true(qtest_create_quic_objects(libctx, cctx, sctx,
|
---|
70 | cert, privkey,
|
---|
71 | idx >= 1
|
---|
72 | ? QTEST_FLAG_BLOCK
|
---|
73 | : 0,
|
---|
74 | &qtserv, &clientquic,
|
---|
75 | NULL, NULL))
|
---|
76 | || !TEST_true(SSL_set_tlsext_host_name(clientquic, "localhost")))
|
---|
77 | goto end;
|
---|
78 |
|
---|
79 | if (sess != NULL && !TEST_true(SSL_set_session(clientquic, sess)))
|
---|
80 | goto end;
|
---|
81 |
|
---|
82 | if (!TEST_true(qtest_create_quic_connection(qtserv, clientquic)))
|
---|
83 | goto end;
|
---|
84 |
|
---|
85 | if (idx >= 1) {
|
---|
86 | if (!TEST_true(BIO_get_fd(ossl_quic_tserver_get0_rbio(qtserv),
|
---|
87 | &ssock)))
|
---|
88 | goto end;
|
---|
89 | if (!TEST_int_gt(csock = SSL_get_rfd(clientquic), 0))
|
---|
90 | goto end;
|
---|
91 | }
|
---|
92 |
|
---|
93 | sid = 0; /* client-initiated bidirectional stream */
|
---|
94 |
|
---|
95 | for (j = 0; j < 2; j++) {
|
---|
96 | /* Check that sending and receiving app data is ok */
|
---|
97 | if (!TEST_true(SSL_write_ex(clientquic, msg, msglen, &numbytes))
|
---|
98 | || !TEST_size_t_eq(numbytes, msglen))
|
---|
99 | goto end;
|
---|
100 | if (idx >= 1) {
|
---|
101 | do {
|
---|
102 | if (!TEST_true(wait_until_sock_readable(ssock)))
|
---|
103 | goto end;
|
---|
104 |
|
---|
105 | ossl_quic_tserver_tick(qtserv);
|
---|
106 |
|
---|
107 | if (!TEST_true(ossl_quic_tserver_read(qtserv, sid, buf,
|
---|
108 | sizeof(buf),
|
---|
109 | &numbytes)))
|
---|
110 | goto end;
|
---|
111 | } while (numbytes == 0);
|
---|
112 |
|
---|
113 | if (!TEST_mem_eq(buf, numbytes, msg, msglen))
|
---|
114 | goto end;
|
---|
115 | }
|
---|
116 |
|
---|
117 | if (idx >= 2 && j > 0)
|
---|
118 | /* Introduce permanent socket error */
|
---|
119 | BIO_closesocket(csock);
|
---|
120 |
|
---|
121 | ossl_quic_tserver_tick(qtserv);
|
---|
122 | if (!TEST_true(ossl_quic_tserver_write(qtserv, sid,
|
---|
123 | (unsigned char *)msg,
|
---|
124 | msglen, &numbytes)))
|
---|
125 | goto end;
|
---|
126 | ossl_quic_tserver_tick(qtserv);
|
---|
127 | SSL_handle_events(clientquic);
|
---|
128 |
|
---|
129 | if (idx >= 2 && j > 0) {
|
---|
130 | if (!TEST_false(SSL_read_ex(clientquic, buf, 1, &numbytes))
|
---|
131 | || !TEST_int_eq(SSL_get_error(clientquic, 0),
|
---|
132 | SSL_ERROR_SYSCALL)
|
---|
133 | || !TEST_false(SSL_write_ex(clientquic, msg, msglen,
|
---|
134 | &numbytes))
|
---|
135 | || !TEST_int_eq(SSL_get_error(clientquic, 0),
|
---|
136 | SSL_ERROR_SYSCALL))
|
---|
137 | goto end;
|
---|
138 | break;
|
---|
139 | }
|
---|
140 |
|
---|
141 | /*
|
---|
142 | * In blocking mode the SSL_read_ex call will block until the socket
|
---|
143 | * is readable and has our data. In non-blocking mode we're doing
|
---|
144 | * everything in memory, so it should be immediately available
|
---|
145 | */
|
---|
146 | if (!TEST_true(SSL_read_ex(clientquic, buf, 1, &numbytes))
|
---|
147 | || !TEST_size_t_eq(numbytes, 1)
|
---|
148 | || !TEST_true(SSL_has_pending(clientquic))
|
---|
149 | || !TEST_int_eq(SSL_pending(clientquic), msglen - 1)
|
---|
150 | || !TEST_true(SSL_read_ex(clientquic, buf + 1,
|
---|
151 | sizeof(buf) - 1, &numbytes))
|
---|
152 | || !TEST_mem_eq(buf, numbytes + 1, msg, msglen))
|
---|
153 | goto end;
|
---|
154 | }
|
---|
155 |
|
---|
156 | /* Test that exporters work. */
|
---|
157 | if (!TEST_true(SSL_export_keying_material(clientquic, scratch,
|
---|
158 | sizeof(scratch), "test", 4, (unsigned char *)"ctx", 3,
|
---|
159 | 1)))
|
---|
160 | goto end;
|
---|
161 |
|
---|
162 | if (sess == NULL) {
|
---|
163 | /* We didn't supply a session so we're not expecting resumption */
|
---|
164 | if (!TEST_false(SSL_session_reused(clientquic)))
|
---|
165 | goto end;
|
---|
166 | /* We should have a session ticket by now */
|
---|
167 | sess = SSL_get1_session(clientquic);
|
---|
168 | if (!TEST_ptr(sess))
|
---|
169 | goto end;
|
---|
170 | } else {
|
---|
171 | /* We supplied a session so we should have resumed */
|
---|
172 | if (!TEST_true(SSL_session_reused(clientquic)))
|
---|
173 | goto end;
|
---|
174 | }
|
---|
175 |
|
---|
176 | if (!TEST_true(qtest_shutdown(qtserv, clientquic)))
|
---|
177 | goto end;
|
---|
178 |
|
---|
179 | if (sctx == NULL) {
|
---|
180 | sctx = ossl_quic_tserver_get0_ssl_ctx(qtserv);
|
---|
181 | if (!TEST_true(SSL_CTX_up_ref(sctx))) {
|
---|
182 | sctx = NULL;
|
---|
183 | goto end;
|
---|
184 | }
|
---|
185 | }
|
---|
186 | ossl_quic_tserver_free(qtserv);
|
---|
187 | qtserv = NULL;
|
---|
188 | SSL_free(clientquic);
|
---|
189 | clientquic = NULL;
|
---|
190 |
|
---|
191 | if (idx >= 2)
|
---|
192 | break;
|
---|
193 | }
|
---|
194 |
|
---|
195 | ret = 1;
|
---|
196 |
|
---|
197 | end:
|
---|
198 | SSL_SESSION_free(sess);
|
---|
199 | ossl_quic_tserver_free(qtserv);
|
---|
200 | SSL_free(clientquic);
|
---|
201 | SSL_CTX_free(cctx);
|
---|
202 | SSL_CTX_free(sctx);
|
---|
203 |
|
---|
204 | return ret;
|
---|
205 | }
|
---|
206 |
|
---|
207 | /*
|
---|
208 | * Test that sending FIN with no data to a client blocking in SSL_read_ex() will
|
---|
209 | * wake up the client.
|
---|
210 | */
|
---|
211 | static int test_fin_only_blocking(void)
|
---|
212 | {
|
---|
213 | SSL_CTX *cctx = SSL_CTX_new_ex(libctx, NULL, OSSL_QUIC_client_method());
|
---|
214 | SSL_CTX *sctx = NULL;
|
---|
215 | SSL *clientquic = NULL;
|
---|
216 | QUIC_TSERVER *qtserv = NULL;
|
---|
217 | const char *msg = "Hello World";
|
---|
218 | uint64_t sid;
|
---|
219 | size_t numbytes;
|
---|
220 | unsigned char buf[32];
|
---|
221 | int ret = 0;
|
---|
222 | OSSL_TIME timer, timediff;
|
---|
223 |
|
---|
224 | if (!qtest_supports_blocking())
|
---|
225 | return TEST_skip("Blocking tests not supported in this build");
|
---|
226 |
|
---|
227 | if (!TEST_ptr(cctx)
|
---|
228 | || !TEST_true(qtest_create_quic_objects(libctx, cctx, sctx,
|
---|
229 | cert, privkey,
|
---|
230 | QTEST_FLAG_BLOCK,
|
---|
231 | &qtserv, &clientquic,
|
---|
232 | NULL, NULL))
|
---|
233 | || !TEST_true(SSL_set_tlsext_host_name(clientquic, "localhost")))
|
---|
234 | goto end;
|
---|
235 |
|
---|
236 | if (!TEST_true(qtest_create_quic_connection(qtserv, clientquic)))
|
---|
237 | goto end;
|
---|
238 |
|
---|
239 | if (!TEST_true(ossl_quic_tserver_stream_new(qtserv, 0, &sid))
|
---|
240 | || !TEST_true(ossl_quic_tserver_write(qtserv, sid,
|
---|
241 | (unsigned char *)msg,
|
---|
242 | strlen(msg), &numbytes))
|
---|
243 | || !TEST_size_t_eq(strlen(msg), numbytes))
|
---|
244 | goto end;
|
---|
245 |
|
---|
246 | ossl_quic_tserver_tick(qtserv);
|
---|
247 |
|
---|
248 | if (!TEST_true(SSL_read_ex(clientquic, buf, sizeof(buf), &numbytes))
|
---|
249 | || !TEST_mem_eq(msg, strlen(msg), buf, numbytes))
|
---|
250 |
|
---|
251 |
|
---|
252 | goto end;
|
---|
253 |
|
---|
254 | if (!TEST_true(ossl_quic_tserver_conclude(qtserv, sid)))
|
---|
255 | goto end;
|
---|
256 |
|
---|
257 | timer = ossl_time_now();
|
---|
258 | if (!TEST_false(SSL_read_ex(clientquic, buf, sizeof(buf), &numbytes)))
|
---|
259 | goto end;
|
---|
260 | timediff = ossl_time_subtract(ossl_time_now(), timer);
|
---|
261 |
|
---|
262 | if (!TEST_int_eq(SSL_get_error(clientquic, 0), SSL_ERROR_ZERO_RETURN)
|
---|
263 | /*
|
---|
264 | * We expect the SSL_read_ex to not have blocked so this should
|
---|
265 | * be very fast. 20ms should be plenty.
|
---|
266 | */
|
---|
267 | || !TEST_uint64_t_le(ossl_time2ms(timediff), 20))
|
---|
268 | goto end;
|
---|
269 |
|
---|
270 | if (!TEST_true(qtest_shutdown(qtserv, clientquic)))
|
---|
271 | goto end;
|
---|
272 |
|
---|
273 | ret = 1;
|
---|
274 |
|
---|
275 | end:
|
---|
276 | ossl_quic_tserver_free(qtserv);
|
---|
277 | SSL_free(clientquic);
|
---|
278 | SSL_CTX_free(cctx);
|
---|
279 | SSL_CTX_free(sctx);
|
---|
280 |
|
---|
281 | return ret;
|
---|
282 | }
|
---|
283 |
|
---|
284 | /* Test that a vanilla QUIC SSL object has the expected ciphersuites available */
|
---|
285 | static int test_ciphersuites(void)
|
---|
286 | {
|
---|
287 | SSL_CTX *ctx = SSL_CTX_new_ex(libctx, NULL, OSSL_QUIC_client_method());
|
---|
288 | SSL *ssl;
|
---|
289 | int testresult = 0;
|
---|
290 | const STACK_OF(SSL_CIPHER) *ciphers = NULL;
|
---|
291 | const SSL_CIPHER *cipher;
|
---|
292 | /* We expect this exact list of ciphersuites by default */
|
---|
293 | int cipherids[] = {
|
---|
294 | TLS1_3_CK_AES_256_GCM_SHA384,
|
---|
295 | #if !defined(OPENSSL_NO_CHACHA) && !defined(OPENSSL_NO_POLY1305)
|
---|
296 | TLS1_3_CK_CHACHA20_POLY1305_SHA256,
|
---|
297 | #endif
|
---|
298 | TLS1_3_CK_AES_128_GCM_SHA256
|
---|
299 | };
|
---|
300 | size_t i, j;
|
---|
301 |
|
---|
302 | if (!TEST_ptr(ctx))
|
---|
303 | return 0;
|
---|
304 |
|
---|
305 | ssl = SSL_new(ctx);
|
---|
306 | if (!TEST_ptr(ssl))
|
---|
307 | goto err;
|
---|
308 |
|
---|
309 | ciphers = SSL_get_ciphers(ssl);
|
---|
310 |
|
---|
311 | for (i = 0, j = 0; i < OSSL_NELEM(cipherids); i++) {
|
---|
312 | if (cipherids[i] == TLS1_3_CK_CHACHA20_POLY1305_SHA256 && is_fips)
|
---|
313 | continue;
|
---|
314 | cipher = sk_SSL_CIPHER_value(ciphers, j++);
|
---|
315 | if (!TEST_ptr(cipher))
|
---|
316 | goto err;
|
---|
317 | if (!TEST_uint_eq(SSL_CIPHER_get_id(cipher), cipherids[i]))
|
---|
318 | goto err;
|
---|
319 | }
|
---|
320 |
|
---|
321 | /* We should have checked all the ciphers in the stack */
|
---|
322 | if (!TEST_int_eq(sk_SSL_CIPHER_num(ciphers), j))
|
---|
323 | goto err;
|
---|
324 |
|
---|
325 | testresult = 1;
|
---|
326 | err:
|
---|
327 | SSL_free(ssl);
|
---|
328 | SSL_CTX_free(ctx);
|
---|
329 |
|
---|
330 | return testresult;
|
---|
331 | }
|
---|
332 |
|
---|
333 | static int test_cipher_find(void)
|
---|
334 | {
|
---|
335 | SSL_CTX *cctx = SSL_CTX_new_ex(libctx, NULL, OSSL_QUIC_client_method());
|
---|
336 | SSL *clientquic = NULL;
|
---|
337 | struct {
|
---|
338 | const unsigned char *cipherbytes;
|
---|
339 | int ok;
|
---|
340 | } testciphers[] = {
|
---|
341 | { TLS13_AES_128_GCM_SHA256_BYTES, 1 },
|
---|
342 | { TLS13_AES_256_GCM_SHA384_BYTES, 1 },
|
---|
343 | { TLS13_CHACHA20_POLY1305_SHA256_BYTES, 1 },
|
---|
344 | { TLS13_AES_128_CCM_SHA256_BYTES, 0 },
|
---|
345 | { TLS13_AES_128_CCM_8_SHA256_BYTES, 0 }
|
---|
346 | };
|
---|
347 | size_t i;
|
---|
348 | int testresult = 0;
|
---|
349 |
|
---|
350 | if (!TEST_ptr(cctx))
|
---|
351 | goto err;
|
---|
352 |
|
---|
353 | clientquic = SSL_new(cctx);
|
---|
354 | if (!TEST_ptr(clientquic))
|
---|
355 | goto err;
|
---|
356 |
|
---|
357 | for (i = 0; i < OSSL_NELEM(testciphers); i++)
|
---|
358 | if (testciphers[i].ok) {
|
---|
359 | if (!TEST_ptr(SSL_CIPHER_find(clientquic,
|
---|
360 | testciphers[i].cipherbytes)))
|
---|
361 | goto err;
|
---|
362 | } else {
|
---|
363 | if (!TEST_ptr_null(SSL_CIPHER_find(clientquic,
|
---|
364 | testciphers[i].cipherbytes)))
|
---|
365 | goto err;
|
---|
366 | }
|
---|
367 |
|
---|
368 | testresult = 1;
|
---|
369 | err:
|
---|
370 | SSL_free(clientquic);
|
---|
371 | SSL_CTX_free(cctx);
|
---|
372 |
|
---|
373 | return testresult;
|
---|
374 | }
|
---|
375 |
|
---|
376 | /*
|
---|
377 | * Test that SSL_version, SSL_get_version, SSL_is_quic, SSL_is_tls and
|
---|
378 | * SSL_is_dtls return the expected results for a QUIC connection. Compare with
|
---|
379 | * test_version() in sslapitest.c which does the same thing for TLS/DTLS
|
---|
380 | * connections.
|
---|
381 | */
|
---|
382 | static int test_version(void)
|
---|
383 | {
|
---|
384 | SSL_CTX *cctx = SSL_CTX_new_ex(libctx, NULL, OSSL_QUIC_client_method());
|
---|
385 | SSL *clientquic = NULL;
|
---|
386 | QUIC_TSERVER *qtserv = NULL;
|
---|
387 | int testresult = 0;
|
---|
388 |
|
---|
389 | if (!TEST_ptr(cctx)
|
---|
390 | || !TEST_true(qtest_create_quic_objects(libctx, cctx, NULL, cert,
|
---|
391 | privkey, 0, &qtserv,
|
---|
392 | &clientquic, NULL, NULL))
|
---|
393 | || !TEST_true(qtest_create_quic_connection(qtserv, clientquic)))
|
---|
394 | goto err;
|
---|
395 |
|
---|
396 | if (!TEST_int_eq(SSL_version(clientquic), OSSL_QUIC1_VERSION)
|
---|
397 | || !TEST_str_eq(SSL_get_version(clientquic), "QUICv1"))
|
---|
398 | goto err;
|
---|
399 |
|
---|
400 | if (!TEST_true(SSL_is_quic(clientquic))
|
---|
401 | || !TEST_false(SSL_is_tls(clientquic))
|
---|
402 | || !TEST_false(SSL_is_dtls(clientquic)))
|
---|
403 | goto err;
|
---|
404 |
|
---|
405 |
|
---|
406 | testresult = 1;
|
---|
407 | err:
|
---|
408 | ossl_quic_tserver_free(qtserv);
|
---|
409 | SSL_free(clientquic);
|
---|
410 | SSL_CTX_free(cctx);
|
---|
411 |
|
---|
412 | return testresult;
|
---|
413 | }
|
---|
414 |
|
---|
415 | #if defined(DO_SSL_TRACE_TEST)
|
---|
416 | static void strip_line_ends(char *str)
|
---|
417 | {
|
---|
418 | size_t i;
|
---|
419 |
|
---|
420 | for (i = strlen(str);
|
---|
421 | i > 0 && (str[i - 1] == '\n' || str[i - 1] == '\r');
|
---|
422 | i--);
|
---|
423 |
|
---|
424 | str[i] = '\0';
|
---|
425 | }
|
---|
426 |
|
---|
427 | static int compare_with_file(BIO *membio)
|
---|
428 | {
|
---|
429 | BIO *file = NULL, *newfile = NULL;
|
---|
430 | char buf1[512], buf2[512];
|
---|
431 | char *reffile;
|
---|
432 | int ret = 0;
|
---|
433 | size_t i;
|
---|
434 |
|
---|
435 | #ifdef OPENSSL_NO_ZLIB
|
---|
436 | reffile = test_mk_file_path(datadir, "ssltraceref.txt");
|
---|
437 | #else
|
---|
438 | reffile = test_mk_file_path(datadir, "ssltraceref-zlib.txt");
|
---|
439 | #endif
|
---|
440 | if (!TEST_ptr(reffile))
|
---|
441 | goto err;
|
---|
442 |
|
---|
443 | file = BIO_new_file(reffile, "rb");
|
---|
444 | if (!TEST_ptr(file))
|
---|
445 | goto err;
|
---|
446 |
|
---|
447 | newfile = BIO_new_file("ssltraceref-new.txt", "wb");
|
---|
448 | if (!TEST_ptr(newfile))
|
---|
449 | goto err;
|
---|
450 |
|
---|
451 | while (BIO_gets(membio, buf2, sizeof(buf2)) > 0)
|
---|
452 | if (BIO_puts(newfile, buf2) <= 0) {
|
---|
453 | TEST_error("Failed writing new file data");
|
---|
454 | goto err;
|
---|
455 | }
|
---|
456 |
|
---|
457 | if (!TEST_int_ge(BIO_seek(membio, 0), 0))
|
---|
458 | goto err;
|
---|
459 |
|
---|
460 | while (BIO_gets(file, buf1, sizeof(buf1)) > 0) {
|
---|
461 | if (BIO_gets(membio, buf2, sizeof(buf2)) <= 0) {
|
---|
462 | TEST_error("Failed reading mem data");
|
---|
463 | goto err;
|
---|
464 | }
|
---|
465 | strip_line_ends(buf1);
|
---|
466 | strip_line_ends(buf2);
|
---|
467 | if (strlen(buf1) != strlen(buf2)) {
|
---|
468 | TEST_error("Actual and ref line data length mismatch");
|
---|
469 | TEST_info("%s", buf1);
|
---|
470 | TEST_info("%s", buf2);
|
---|
471 | goto err;
|
---|
472 | }
|
---|
473 | for (i = 0; i < strlen(buf1); i++) {
|
---|
474 | /* '?' is a wild card character in the reference text */
|
---|
475 | if (buf1[i] == '?')
|
---|
476 | buf2[i] = '?';
|
---|
477 | }
|
---|
478 | if (!TEST_str_eq(buf1, buf2))
|
---|
479 | goto err;
|
---|
480 | }
|
---|
481 | if (!TEST_true(BIO_eof(file))
|
---|
482 | || !TEST_true(BIO_eof(membio)))
|
---|
483 | goto err;
|
---|
484 |
|
---|
485 | ret = 1;
|
---|
486 | err:
|
---|
487 | OPENSSL_free(reffile);
|
---|
488 | BIO_free(file);
|
---|
489 | BIO_free(newfile);
|
---|
490 | return ret;
|
---|
491 | }
|
---|
492 |
|
---|
493 | /*
|
---|
494 | * Tests that the SSL_trace() msg_callback works as expected with a QUIC
|
---|
495 | * connection. This also provides testing of the msg_callback at the same time.
|
---|
496 | */
|
---|
497 | static int test_ssl_trace(void)
|
---|
498 | {
|
---|
499 | SSL_CTX *cctx = NULL;
|
---|
500 | SSL *clientquic = NULL;
|
---|
501 | QUIC_TSERVER *qtserv = NULL;
|
---|
502 | int testresult = 0;
|
---|
503 | BIO *bio = NULL;
|
---|
504 |
|
---|
505 | if (!TEST_ptr(cctx = SSL_CTX_new_ex(libctx, NULL, OSSL_QUIC_client_method()))
|
---|
506 | || !TEST_ptr(bio = BIO_new(BIO_s_mem()))
|
---|
507 | || !TEST_true(SSL_CTX_set_ciphersuites(cctx, "TLS_AES_128_GCM_SHA256"))
|
---|
508 | || !TEST_true(qtest_create_quic_objects(libctx, cctx, NULL, cert,
|
---|
509 | privkey,
|
---|
510 | QTEST_FLAG_FAKE_TIME,
|
---|
511 | &qtserv,
|
---|
512 | &clientquic, NULL, NULL)))
|
---|
513 | goto err;
|
---|
514 |
|
---|
515 | SSL_set_msg_callback(clientquic, SSL_trace);
|
---|
516 | SSL_set_msg_callback_arg(clientquic, bio);
|
---|
517 |
|
---|
518 | if (!TEST_true(qtest_create_quic_connection(qtserv, clientquic)))
|
---|
519 | goto err;
|
---|
520 |
|
---|
521 | /* Skip the comparison of the trace when the fips provider is used. */
|
---|
522 | if (is_fips) {
|
---|
523 | /* Check whether there was something written. */
|
---|
524 | if (!TEST_int_gt(BIO_pending(bio), 0))
|
---|
525 | goto err;
|
---|
526 | } else {
|
---|
527 | if (!TEST_true(compare_with_file(bio)))
|
---|
528 | goto err;
|
---|
529 | }
|
---|
530 |
|
---|
531 | testresult = 1;
|
---|
532 | err:
|
---|
533 | ossl_quic_tserver_free(qtserv);
|
---|
534 | SSL_free(clientquic);
|
---|
535 | SSL_CTX_free(cctx);
|
---|
536 | BIO_free(bio);
|
---|
537 |
|
---|
538 | return testresult;
|
---|
539 | }
|
---|
540 | #endif
|
---|
541 |
|
---|
542 | static int ensure_valid_ciphers(const STACK_OF(SSL_CIPHER) *ciphers)
|
---|
543 | {
|
---|
544 | size_t i;
|
---|
545 |
|
---|
546 | /* Ensure ciphersuite list is suitably subsetted. */
|
---|
547 | for (i = 0; i < (size_t)sk_SSL_CIPHER_num(ciphers); ++i) {
|
---|
548 | const SSL_CIPHER *cipher = sk_SSL_CIPHER_value(ciphers, i);
|
---|
549 | switch (SSL_CIPHER_get_id(cipher)) {
|
---|
550 | case TLS1_3_CK_AES_128_GCM_SHA256:
|
---|
551 | case TLS1_3_CK_AES_256_GCM_SHA384:
|
---|
552 | case TLS1_3_CK_CHACHA20_POLY1305_SHA256:
|
---|
553 | break;
|
---|
554 | default:
|
---|
555 | TEST_error("forbidden cipher: %s", SSL_CIPHER_get_name(cipher));
|
---|
556 | return 0;
|
---|
557 | }
|
---|
558 | }
|
---|
559 |
|
---|
560 | return 1;
|
---|
561 | }
|
---|
562 |
|
---|
563 | /*
|
---|
564 | * Test that handshake-layer APIs which shouldn't work don't work with QUIC.
|
---|
565 | */
|
---|
566 | static int test_quic_forbidden_apis_ctx(void)
|
---|
567 | {
|
---|
568 | int testresult = 0;
|
---|
569 | SSL_CTX *ctx = NULL;
|
---|
570 |
|
---|
571 | if (!TEST_ptr(ctx = SSL_CTX_new_ex(libctx, NULL, OSSL_QUIC_client_method())))
|
---|
572 | goto err;
|
---|
573 |
|
---|
574 | #ifndef OPENSSL_NO_SRTP
|
---|
575 | /* This function returns 0 on success and 1 on error, and should fail. */
|
---|
576 | if (!TEST_true(SSL_CTX_set_tlsext_use_srtp(ctx, "SRTP_AEAD_AES_128_GCM")))
|
---|
577 | goto err;
|
---|
578 | #endif
|
---|
579 |
|
---|
580 | /*
|
---|
581 | * List of ciphersuites we do and don't allow in QUIC.
|
---|
582 | */
|
---|
583 | #define QUIC_CIPHERSUITES \
|
---|
584 | "TLS_AES_128_GCM_SHA256:" \
|
---|
585 | "TLS_AES_256_GCM_SHA384:" \
|
---|
586 | "TLS_CHACHA20_POLY1305_SHA256"
|
---|
587 |
|
---|
588 | #define NON_QUIC_CIPHERSUITES \
|
---|
589 | "TLS_AES_128_CCM_SHA256:" \
|
---|
590 | "TLS_AES_256_CCM_SHA384:" \
|
---|
591 | "TLS_AES_128_CCM_8_SHA256"
|
---|
592 |
|
---|
593 | /* Set TLSv1.3 ciphersuite list for the SSL_CTX. */
|
---|
594 | if (!TEST_true(SSL_CTX_set_ciphersuites(ctx,
|
---|
595 | QUIC_CIPHERSUITES ":"
|
---|
596 | NON_QUIC_CIPHERSUITES)))
|
---|
597 | goto err;
|
---|
598 |
|
---|
599 | /*
|
---|
600 | * Forbidden ciphersuites should show up in SSL_CTX accessors, they are only
|
---|
601 | * filtered in SSL_get1_supported_ciphers, so we don't check for
|
---|
602 | * non-inclusion here.
|
---|
603 | */
|
---|
604 |
|
---|
605 | testresult = 1;
|
---|
606 | err:
|
---|
607 | SSL_CTX_free(ctx);
|
---|
608 | return testresult;
|
---|
609 | }
|
---|
610 |
|
---|
611 | static int test_quic_forbidden_apis(void)
|
---|
612 | {
|
---|
613 | int testresult = 0;
|
---|
614 | SSL_CTX *ctx = NULL;
|
---|
615 | SSL *ssl = NULL;
|
---|
616 | STACK_OF(SSL_CIPHER) *ciphers = NULL;
|
---|
617 |
|
---|
618 | if (!TEST_ptr(ctx = SSL_CTX_new_ex(libctx, NULL, OSSL_QUIC_client_method())))
|
---|
619 | goto err;
|
---|
620 |
|
---|
621 | if (!TEST_ptr(ssl = SSL_new(ctx)))
|
---|
622 | goto err;
|
---|
623 |
|
---|
624 | #ifndef OPENSSL_NO_SRTP
|
---|
625 | /* This function returns 0 on success and 1 on error, and should fail. */
|
---|
626 | if (!TEST_true(SSL_set_tlsext_use_srtp(ssl, "SRTP_AEAD_AES_128_GCM")))
|
---|
627 | goto err;
|
---|
628 | #endif
|
---|
629 |
|
---|
630 | /* Set TLSv1.3 ciphersuite list for the SSL_CTX. */
|
---|
631 | if (!TEST_true(SSL_set_ciphersuites(ssl,
|
---|
632 | QUIC_CIPHERSUITES ":"
|
---|
633 | NON_QUIC_CIPHERSUITES)))
|
---|
634 | goto err;
|
---|
635 |
|
---|
636 | /* Non-QUIC ciphersuites must not appear in supported ciphers list. */
|
---|
637 | if (!TEST_ptr(ciphers = SSL_get1_supported_ciphers(ssl))
|
---|
638 | || !TEST_true(ensure_valid_ciphers(ciphers)))
|
---|
639 | goto err;
|
---|
640 |
|
---|
641 | testresult = 1;
|
---|
642 | err:
|
---|
643 | sk_SSL_CIPHER_free(ciphers);
|
---|
644 | SSL_free(ssl);
|
---|
645 | SSL_CTX_free(ctx);
|
---|
646 | return testresult;
|
---|
647 | }
|
---|
648 |
|
---|
649 | static int test_quic_forbidden_options(void)
|
---|
650 | {
|
---|
651 | int testresult = 0;
|
---|
652 | SSL_CTX *ctx = NULL;
|
---|
653 | SSL *ssl = NULL;
|
---|
654 | char buf[16];
|
---|
655 | size_t len;
|
---|
656 |
|
---|
657 | if (!TEST_ptr(ctx = SSL_CTX_new_ex(libctx, NULL, OSSL_QUIC_client_method())))
|
---|
658 | goto err;
|
---|
659 |
|
---|
660 | /* QUIC options restrictions do not affect SSL_CTX */
|
---|
661 | SSL_CTX_set_options(ctx, UINT64_MAX);
|
---|
662 |
|
---|
663 | if (!TEST_uint64_t_eq(SSL_CTX_get_options(ctx), UINT64_MAX))
|
---|
664 | goto err;
|
---|
665 |
|
---|
666 | /* Set options on CTX which should not be inherited (tested below). */
|
---|
667 | SSL_CTX_set_read_ahead(ctx, 1);
|
---|
668 | SSL_CTX_set_max_early_data(ctx, 1);
|
---|
669 | SSL_CTX_set_recv_max_early_data(ctx, 1);
|
---|
670 | SSL_CTX_set_quiet_shutdown(ctx, 1);
|
---|
671 |
|
---|
672 | if (!TEST_ptr(ssl = SSL_new(ctx)))
|
---|
673 | goto err;
|
---|
674 |
|
---|
675 | /* Only permitted options get transferred to SSL object */
|
---|
676 | if (!TEST_uint64_t_eq(SSL_get_options(ssl), OSSL_QUIC_PERMITTED_OPTIONS))
|
---|
677 | goto err;
|
---|
678 |
|
---|
679 | /* Try again using SSL_set_options */
|
---|
680 | SSL_set_options(ssl, UINT64_MAX);
|
---|
681 |
|
---|
682 | if (!TEST_uint64_t_eq(SSL_get_options(ssl), OSSL_QUIC_PERMITTED_OPTIONS))
|
---|
683 | goto err;
|
---|
684 |
|
---|
685 | /* Clear everything */
|
---|
686 | SSL_clear_options(ssl, UINT64_MAX);
|
---|
687 |
|
---|
688 | if (!TEST_uint64_t_eq(SSL_get_options(ssl), 0))
|
---|
689 | goto err;
|
---|
690 |
|
---|
691 | /* Readahead */
|
---|
692 | if (!TEST_false(SSL_get_read_ahead(ssl)))
|
---|
693 | goto err;
|
---|
694 |
|
---|
695 | SSL_set_read_ahead(ssl, 1);
|
---|
696 | if (!TEST_false(SSL_get_read_ahead(ssl)))
|
---|
697 | goto err;
|
---|
698 |
|
---|
699 | /* Block padding */
|
---|
700 | if (!TEST_true(SSL_set_block_padding(ssl, 0))
|
---|
701 | || !TEST_true(SSL_set_block_padding(ssl, 1))
|
---|
702 | || !TEST_false(SSL_set_block_padding(ssl, 2)))
|
---|
703 | goto err;
|
---|
704 |
|
---|
705 | /* Max fragment length */
|
---|
706 | if (!TEST_true(SSL_set_tlsext_max_fragment_length(ssl, TLSEXT_max_fragment_length_DISABLED))
|
---|
707 | || !TEST_false(SSL_set_tlsext_max_fragment_length(ssl, TLSEXT_max_fragment_length_512)))
|
---|
708 | goto err;
|
---|
709 |
|
---|
710 | /* Max early data */
|
---|
711 | if (!TEST_false(SSL_set_recv_max_early_data(ssl, 1))
|
---|
712 | || !TEST_false(SSL_set_max_early_data(ssl, 1)))
|
---|
713 | goto err;
|
---|
714 |
|
---|
715 | /* Read/Write */
|
---|
716 | if (!TEST_false(SSL_read_early_data(ssl, buf, sizeof(buf), &len))
|
---|
717 | || !TEST_false(SSL_write_early_data(ssl, buf, sizeof(buf), &len)))
|
---|
718 | goto err;
|
---|
719 |
|
---|
720 | /* Buffer Management */
|
---|
721 | if (!TEST_true(SSL_alloc_buffers(ssl))
|
---|
722 | || !TEST_false(SSL_free_buffers(ssl)))
|
---|
723 | goto err;
|
---|
724 |
|
---|
725 | /* Pipelining */
|
---|
726 | if (!TEST_false(SSL_set_max_send_fragment(ssl, 2))
|
---|
727 | || !TEST_false(SSL_set_split_send_fragment(ssl, 2))
|
---|
728 | || !TEST_false(SSL_set_max_pipelines(ssl, 2)))
|
---|
729 | goto err;
|
---|
730 |
|
---|
731 | /* HRR */
|
---|
732 | if (!TEST_false(SSL_stateless(ssl)))
|
---|
733 | goto err;
|
---|
734 |
|
---|
735 | /* Quiet Shutdown */
|
---|
736 | if (!TEST_false(SSL_get_quiet_shutdown(ssl)))
|
---|
737 | goto err;
|
---|
738 |
|
---|
739 | /* No duplication */
|
---|
740 | if (!TEST_ptr_null(SSL_dup(ssl)))
|
---|
741 | goto err;
|
---|
742 |
|
---|
743 | /* No clear */
|
---|
744 | if (!TEST_false(SSL_clear(ssl)))
|
---|
745 | goto err;
|
---|
746 |
|
---|
747 | testresult = 1;
|
---|
748 | err:
|
---|
749 | SSL_free(ssl);
|
---|
750 | SSL_CTX_free(ctx);
|
---|
751 | return testresult;
|
---|
752 | }
|
---|
753 |
|
---|
754 | static int test_quic_set_fd(int idx)
|
---|
755 | {
|
---|
756 | int testresult = 0;
|
---|
757 | SSL_CTX *ctx = NULL;
|
---|
758 | SSL *ssl = NULL;
|
---|
759 | int fd = -1, resfd = -1;
|
---|
760 | BIO *bio = NULL;
|
---|
761 |
|
---|
762 | if (!TEST_ptr(ctx = SSL_CTX_new_ex(libctx, NULL, OSSL_QUIC_client_method())))
|
---|
763 | goto err;
|
---|
764 |
|
---|
765 | if (!TEST_ptr(ssl = SSL_new(ctx)))
|
---|
766 | goto err;
|
---|
767 |
|
---|
768 | if (!TEST_int_ge(fd = BIO_socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP, 0), 0))
|
---|
769 | goto err;
|
---|
770 |
|
---|
771 | if (idx == 0) {
|
---|
772 | if (!TEST_true(SSL_set_fd(ssl, fd)))
|
---|
773 | goto err;
|
---|
774 | if (!TEST_ptr(bio = SSL_get_rbio(ssl)))
|
---|
775 | goto err;
|
---|
776 | if (!TEST_ptr_eq(bio, SSL_get_wbio(ssl)))
|
---|
777 | goto err;
|
---|
778 | } else if (idx == 1) {
|
---|
779 | if (!TEST_true(SSL_set_rfd(ssl, fd)))
|
---|
780 | goto err;
|
---|
781 | if (!TEST_ptr(bio = SSL_get_rbio(ssl)))
|
---|
782 | goto err;
|
---|
783 | if (!TEST_ptr_null(SSL_get_wbio(ssl)))
|
---|
784 | goto err;
|
---|
785 | } else {
|
---|
786 | if (!TEST_true(SSL_set_wfd(ssl, fd)))
|
---|
787 | goto err;
|
---|
788 | if (!TEST_ptr(bio = SSL_get_wbio(ssl)))
|
---|
789 | goto err;
|
---|
790 | if (!TEST_ptr_null(SSL_get_rbio(ssl)))
|
---|
791 | goto err;
|
---|
792 | }
|
---|
793 |
|
---|
794 | if (!TEST_int_eq(BIO_method_type(bio), BIO_TYPE_DGRAM))
|
---|
795 | goto err;
|
---|
796 |
|
---|
797 | if (!TEST_true(BIO_get_fd(bio, &resfd))
|
---|
798 | || !TEST_int_eq(resfd, fd))
|
---|
799 | goto err;
|
---|
800 |
|
---|
801 | testresult = 1;
|
---|
802 | err:
|
---|
803 | SSL_free(ssl);
|
---|
804 | SSL_CTX_free(ctx);
|
---|
805 | if (fd >= 0)
|
---|
806 | BIO_closesocket(fd);
|
---|
807 | return testresult;
|
---|
808 | }
|
---|
809 |
|
---|
810 | #define MAXLOOPS 1000
|
---|
811 |
|
---|
812 | static int test_bio_ssl(void)
|
---|
813 | {
|
---|
814 | /*
|
---|
815 | * We just use OSSL_QUIC_client_method() rather than
|
---|
816 | * OSSL_QUIC_client_thread_method(). We will never leave the connection idle
|
---|
817 | * so we will always be implicitly handling time events anyway via other
|
---|
818 | * IO calls.
|
---|
819 | */
|
---|
820 | SSL_CTX *cctx = SSL_CTX_new_ex(libctx, NULL, OSSL_QUIC_client_method());
|
---|
821 | SSL *clientquic = NULL, *stream = NULL;
|
---|
822 | QUIC_TSERVER *qtserv = NULL;
|
---|
823 | int testresult = 0;
|
---|
824 | BIO *cbio = NULL, *strbio = NULL, *thisbio;
|
---|
825 | const char *msg = "Hello world";
|
---|
826 | int abortctr = 0, err, clienterr = 0, servererr = 0, retc = 0, rets = 0;
|
---|
827 | size_t written, readbytes, msglen;
|
---|
828 | int sid = 0, i;
|
---|
829 | unsigned char buf[80];
|
---|
830 |
|
---|
831 | if (!TEST_ptr(cctx))
|
---|
832 | goto err;
|
---|
833 |
|
---|
834 | cbio = BIO_new_ssl(cctx, 1);
|
---|
835 | if (!TEST_ptr(cbio))
|
---|
836 | goto err;
|
---|
837 |
|
---|
838 | /*
|
---|
839 | * We must configure the ALPN/peer address etc so we get the SSL object in
|
---|
840 | * order to pass it to qtest_create_quic_objects for configuration.
|
---|
841 | */
|
---|
842 | if (!TEST_int_eq(BIO_get_ssl(cbio, &clientquic), 1))
|
---|
843 | goto err;
|
---|
844 |
|
---|
845 | if (!TEST_true(qtest_create_quic_objects(libctx, NULL, NULL, cert, privkey,
|
---|
846 | 0, &qtserv, &clientquic, NULL,
|
---|
847 | NULL)))
|
---|
848 | goto err;
|
---|
849 |
|
---|
850 | msglen = strlen(msg);
|
---|
851 |
|
---|
852 | do {
|
---|
853 | err = BIO_FLAGS_WRITE;
|
---|
854 | while (!clienterr && !retc && err == BIO_FLAGS_WRITE) {
|
---|
855 | retc = BIO_write_ex(cbio, msg, msglen, &written);
|
---|
856 | if (!retc) {
|
---|
857 | if (BIO_should_retry(cbio))
|
---|
858 | err = BIO_retry_type(cbio);
|
---|
859 | else
|
---|
860 | err = 0;
|
---|
861 | }
|
---|
862 | }
|
---|
863 |
|
---|
864 | if (!clienterr && retc <= 0 && err != BIO_FLAGS_READ) {
|
---|
865 | TEST_info("BIO_write_ex() failed %d, %d", retc, err);
|
---|
866 | TEST_openssl_errors();
|
---|
867 | clienterr = 1;
|
---|
868 | }
|
---|
869 |
|
---|
870 | if (!servererr && rets <= 0) {
|
---|
871 | ossl_quic_tserver_tick(qtserv);
|
---|
872 | servererr = ossl_quic_tserver_is_term_any(qtserv);
|
---|
873 | if (!servererr)
|
---|
874 | rets = ossl_quic_tserver_is_handshake_confirmed(qtserv);
|
---|
875 | }
|
---|
876 |
|
---|
877 | if (clienterr && servererr)
|
---|
878 | goto err;
|
---|
879 |
|
---|
880 | if (++abortctr == MAXLOOPS) {
|
---|
881 | TEST_info("No progress made");
|
---|
882 | goto err;
|
---|
883 | }
|
---|
884 | } while ((!retc && !clienterr) || (rets <= 0 && !servererr));
|
---|
885 |
|
---|
886 | /*
|
---|
887 | * 2 loops: The first using the default stream, and the second using a new
|
---|
888 | * client initiated bidi stream.
|
---|
889 | */
|
---|
890 | for (i = 0, thisbio = cbio; i < 2; i++) {
|
---|
891 | if (!TEST_true(ossl_quic_tserver_read(qtserv, sid, buf, sizeof(buf),
|
---|
892 | &readbytes))
|
---|
893 | || !TEST_mem_eq(msg, msglen, buf, readbytes))
|
---|
894 | goto err;
|
---|
895 |
|
---|
896 | if (!TEST_true(ossl_quic_tserver_write(qtserv, sid, (unsigned char *)msg,
|
---|
897 | msglen, &written)))
|
---|
898 | goto err;
|
---|
899 | ossl_quic_tserver_tick(qtserv);
|
---|
900 |
|
---|
901 | if (!TEST_true(BIO_read_ex(thisbio, buf, sizeof(buf), &readbytes))
|
---|
902 | || !TEST_mem_eq(msg, msglen, buf, readbytes))
|
---|
903 | goto err;
|
---|
904 |
|
---|
905 | if (i == 1)
|
---|
906 | break;
|
---|
907 |
|
---|
908 | if (!TEST_true(SSL_set_mode(clientquic, 0)))
|
---|
909 | goto err;
|
---|
910 |
|
---|
911 | /*
|
---|
912 | * Now create a new stream and repeat. The bottom two bits of the stream
|
---|
913 | * id represents whether the stream is bidi and whether it is client
|
---|
914 | * initiated or not. For client initiated bidi they are both 0. So the
|
---|
915 | * first client initiated bidi stream is 0 and the next one is 4.
|
---|
916 | */
|
---|
917 | sid = 4;
|
---|
918 | stream = SSL_new_stream(clientquic, 0);
|
---|
919 | if (!TEST_ptr(stream))
|
---|
920 | goto err;
|
---|
921 |
|
---|
922 | if (!TEST_true(SSL_set_mode(stream, 0)))
|
---|
923 | goto err;
|
---|
924 |
|
---|
925 | thisbio = strbio = BIO_new(BIO_f_ssl());
|
---|
926 | if (!TEST_ptr(strbio))
|
---|
927 | goto err;
|
---|
928 |
|
---|
929 | if (!TEST_int_eq(BIO_set_ssl(thisbio, stream, BIO_CLOSE), 1))
|
---|
930 | goto err;
|
---|
931 | stream = NULL;
|
---|
932 |
|
---|
933 | if (!TEST_true(BIO_write_ex(thisbio, msg, msglen, &written)))
|
---|
934 | goto err;
|
---|
935 |
|
---|
936 | ossl_quic_tserver_tick(qtserv);
|
---|
937 | }
|
---|
938 |
|
---|
939 | testresult = 1;
|
---|
940 | err:
|
---|
941 | BIO_free_all(cbio);
|
---|
942 | BIO_free_all(strbio);
|
---|
943 | SSL_free(stream);
|
---|
944 | ossl_quic_tserver_free(qtserv);
|
---|
945 | SSL_CTX_free(cctx);
|
---|
946 |
|
---|
947 | return testresult;
|
---|
948 | }
|
---|
949 |
|
---|
950 | #define BACK_PRESSURE_NUM_LOOPS 10000
|
---|
951 | /*
|
---|
952 | * Test that sending data from the client to the server faster than the server
|
---|
953 | * can process it eventually results in back pressure on the client.
|
---|
954 | */
|
---|
955 | static int test_back_pressure(void)
|
---|
956 | {
|
---|
957 | SSL_CTX *cctx = SSL_CTX_new_ex(libctx, NULL, OSSL_QUIC_client_method());
|
---|
958 | SSL *clientquic = NULL;
|
---|
959 | QUIC_TSERVER *qtserv = NULL;
|
---|
960 | int testresult = 0;
|
---|
961 | unsigned char *msg = NULL;
|
---|
962 | const size_t msglen = 1024;
|
---|
963 | unsigned char buf[64];
|
---|
964 | size_t readbytes, written;
|
---|
965 | int i;
|
---|
966 |
|
---|
967 | if (!TEST_ptr(cctx)
|
---|
968 | || !TEST_true(qtest_create_quic_objects(libctx, cctx, NULL, cert,
|
---|
969 | privkey, 0, &qtserv,
|
---|
970 | &clientquic, NULL, NULL))
|
---|
971 | || !TEST_true(qtest_create_quic_connection(qtserv, clientquic)))
|
---|
972 | goto err;
|
---|
973 |
|
---|
974 | msg = OPENSSL_malloc(msglen);
|
---|
975 | if (!TEST_ptr(msg))
|
---|
976 | goto err;
|
---|
977 | if (!TEST_int_eq(RAND_bytes_ex(libctx, msg, msglen, 0), 1))
|
---|
978 | goto err;
|
---|
979 |
|
---|
980 | /*
|
---|
981 | * Limit to 10000 loops. If we've not seen any back pressure after that
|
---|
982 | * we're going to run out of memory, so abort.
|
---|
983 | */
|
---|
984 | for (i = 0; i < BACK_PRESSURE_NUM_LOOPS; i++) {
|
---|
985 | /* Send data from the client */
|
---|
986 | if (!SSL_write_ex(clientquic, msg, msglen, &written)) {
|
---|
987 | /* Check if we are seeing back pressure */
|
---|
988 | if (SSL_get_error(clientquic, 0) == SSL_ERROR_WANT_WRITE)
|
---|
989 | break;
|
---|
990 | TEST_error("Unexpected client failure");
|
---|
991 | goto err;
|
---|
992 | }
|
---|
993 |
|
---|
994 | /* Receive data at the server */
|
---|
995 | ossl_quic_tserver_tick(qtserv);
|
---|
996 | if (!TEST_true(ossl_quic_tserver_read(qtserv, 0, buf, sizeof(buf),
|
---|
997 | &readbytes)))
|
---|
998 | goto err;
|
---|
999 | }
|
---|
1000 |
|
---|
1001 | if (i == BACK_PRESSURE_NUM_LOOPS) {
|
---|
1002 | TEST_error("No back pressure seen");
|
---|
1003 | goto err;
|
---|
1004 | }
|
---|
1005 |
|
---|
1006 | testresult = 1;
|
---|
1007 | err:
|
---|
1008 | SSL_free(clientquic);
|
---|
1009 | ossl_quic_tserver_free(qtserv);
|
---|
1010 | SSL_CTX_free(cctx);
|
---|
1011 | OPENSSL_free(msg);
|
---|
1012 |
|
---|
1013 | return testresult;
|
---|
1014 | }
|
---|
1015 |
|
---|
1016 |
|
---|
1017 | static int dgram_ctr = 0;
|
---|
1018 |
|
---|
1019 | static void dgram_cb(int write_p, int version, int content_type,
|
---|
1020 | const void *buf, size_t msglen, SSL *ssl, void *arg)
|
---|
1021 | {
|
---|
1022 | if (!write_p)
|
---|
1023 | return;
|
---|
1024 |
|
---|
1025 | if (content_type != SSL3_RT_QUIC_DATAGRAM)
|
---|
1026 | return;
|
---|
1027 |
|
---|
1028 | dgram_ctr++;
|
---|
1029 | }
|
---|
1030 |
|
---|
1031 | /* Test that we send multiple datagrams in one go when appropriate */
|
---|
1032 | static int test_multiple_dgrams(void)
|
---|
1033 | {
|
---|
1034 | SSL_CTX *cctx = SSL_CTX_new_ex(libctx, NULL, OSSL_QUIC_client_method());
|
---|
1035 | SSL *clientquic = NULL;
|
---|
1036 | QUIC_TSERVER *qtserv = NULL;
|
---|
1037 | int testresult = 0;
|
---|
1038 | unsigned char *buf;
|
---|
1039 | const size_t buflen = 1400;
|
---|
1040 | size_t written;
|
---|
1041 |
|
---|
1042 | buf = OPENSSL_zalloc(buflen);
|
---|
1043 |
|
---|
1044 | if (!TEST_ptr(cctx)
|
---|
1045 | || !TEST_ptr(buf)
|
---|
1046 | || !TEST_true(qtest_create_quic_objects(libctx, cctx, NULL, cert,
|
---|
1047 | privkey, 0, &qtserv,
|
---|
1048 | &clientquic, NULL, NULL))
|
---|
1049 | || !TEST_true(qtest_create_quic_connection(qtserv, clientquic)))
|
---|
1050 | goto err;
|
---|
1051 |
|
---|
1052 | dgram_ctr = 0;
|
---|
1053 | SSL_set_msg_callback(clientquic, dgram_cb);
|
---|
1054 | if (!TEST_true(SSL_write_ex(clientquic, buf, buflen, &written))
|
---|
1055 | || !TEST_size_t_eq(written, buflen)
|
---|
1056 | /* We wrote enough data for 2 datagrams */
|
---|
1057 | || !TEST_int_eq(dgram_ctr, 2))
|
---|
1058 | goto err;
|
---|
1059 |
|
---|
1060 | testresult = 1;
|
---|
1061 | err:
|
---|
1062 | OPENSSL_free(buf);
|
---|
1063 | SSL_free(clientquic);
|
---|
1064 | ossl_quic_tserver_free(qtserv);
|
---|
1065 | SSL_CTX_free(cctx);
|
---|
1066 |
|
---|
1067 | return testresult;
|
---|
1068 | }
|
---|
1069 |
|
---|
1070 | static int non_io_retry_cert_verify_cb(X509_STORE_CTX *ctx, void *arg)
|
---|
1071 | {
|
---|
1072 | int idx = SSL_get_ex_data_X509_STORE_CTX_idx();
|
---|
1073 | SSL *ssl;
|
---|
1074 | const int *allow = (int *)arg;
|
---|
1075 |
|
---|
1076 | /* this should not happen but check anyway */
|
---|
1077 | if (idx < 0
|
---|
1078 | || (ssl = X509_STORE_CTX_get_ex_data(ctx, idx)) == NULL)
|
---|
1079 | return 0;
|
---|
1080 |
|
---|
1081 | /* If this is our first attempt then retry */
|
---|
1082 | if (*allow == 0)
|
---|
1083 | return SSL_set_retry_verify(ssl);
|
---|
1084 |
|
---|
1085 | /* Otherwise do nothing - verification succeeds. Continue as normal */
|
---|
1086 | return 1;
|
---|
1087 | }
|
---|
1088 |
|
---|
1089 | /* Test that we can handle a non-io related retry error
|
---|
1090 | * Test 0: Non-blocking
|
---|
1091 | * Test 1: Blocking
|
---|
1092 | */
|
---|
1093 | static int test_non_io_retry(int idx)
|
---|
1094 | {
|
---|
1095 | SSL_CTX *cctx;
|
---|
1096 | SSL *clientquic = NULL;
|
---|
1097 | QUIC_TSERVER *qtserv = NULL;
|
---|
1098 | int testresult = 0;
|
---|
1099 | int flags = 0, allow = 0;
|
---|
1100 |
|
---|
1101 | if (idx >= 1 && !qtest_supports_blocking())
|
---|
1102 | return TEST_skip("Blocking tests not supported in this build");
|
---|
1103 |
|
---|
1104 | cctx = SSL_CTX_new_ex(libctx, NULL, OSSL_QUIC_client_method());
|
---|
1105 | if (!TEST_ptr(cctx))
|
---|
1106 | goto err;
|
---|
1107 |
|
---|
1108 | SSL_CTX_set_cert_verify_callback(cctx, non_io_retry_cert_verify_cb, &allow);
|
---|
1109 |
|
---|
1110 | flags = (idx >= 1) ? QTEST_FLAG_BLOCK : 0;
|
---|
1111 | if (!TEST_true(qtest_create_quic_objects(libctx, cctx, NULL, cert, privkey,
|
---|
1112 | flags, &qtserv, &clientquic, NULL,
|
---|
1113 | NULL))
|
---|
1114 | || !TEST_true(qtest_create_quic_connection_ex(qtserv, clientquic,
|
---|
1115 | SSL_ERROR_WANT_RETRY_VERIFY))
|
---|
1116 | || !TEST_int_eq(SSL_want(clientquic), SSL_RETRY_VERIFY))
|
---|
1117 | goto err;
|
---|
1118 |
|
---|
1119 | allow = 1;
|
---|
1120 | if (!TEST_true(qtest_create_quic_connection(qtserv, clientquic)))
|
---|
1121 | goto err;
|
---|
1122 |
|
---|
1123 | testresult = 1;
|
---|
1124 | err:
|
---|
1125 | SSL_free(clientquic);
|
---|
1126 | ossl_quic_tserver_free(qtserv);
|
---|
1127 | SSL_CTX_free(cctx);
|
---|
1128 |
|
---|
1129 | return testresult;
|
---|
1130 | }
|
---|
1131 |
|
---|
1132 | static int use_session_cb_cnt = 0;
|
---|
1133 | static int find_session_cb_cnt = 0;
|
---|
1134 | static const char *pskid = "Identity";
|
---|
1135 | static SSL_SESSION *serverpsk = NULL, *clientpsk = NULL;
|
---|
1136 |
|
---|
1137 | static int use_session_cb(SSL *ssl, const EVP_MD *md, const unsigned char **id,
|
---|
1138 | size_t *idlen, SSL_SESSION **sess)
|
---|
1139 | {
|
---|
1140 | use_session_cb_cnt++;
|
---|
1141 |
|
---|
1142 | if (clientpsk == NULL)
|
---|
1143 | return 0;
|
---|
1144 |
|
---|
1145 | SSL_SESSION_up_ref(clientpsk);
|
---|
1146 |
|
---|
1147 | *sess = clientpsk;
|
---|
1148 | *id = (const unsigned char *)pskid;
|
---|
1149 | *idlen = strlen(pskid);
|
---|
1150 |
|
---|
1151 | return 1;
|
---|
1152 | }
|
---|
1153 |
|
---|
1154 | static int find_session_cb(SSL *ssl, const unsigned char *identity,
|
---|
1155 | size_t identity_len, SSL_SESSION **sess)
|
---|
1156 | {
|
---|
1157 | find_session_cb_cnt++;
|
---|
1158 |
|
---|
1159 | if (serverpsk == NULL)
|
---|
1160 | return 0;
|
---|
1161 |
|
---|
1162 | /* Identity should match that set by the client */
|
---|
1163 | if (strlen(pskid) != identity_len
|
---|
1164 | || strncmp(pskid, (const char *)identity, identity_len) != 0)
|
---|
1165 | return 0;
|
---|
1166 |
|
---|
1167 | SSL_SESSION_up_ref(serverpsk);
|
---|
1168 | *sess = serverpsk;
|
---|
1169 |
|
---|
1170 | return 1;
|
---|
1171 | }
|
---|
1172 |
|
---|
1173 | static int test_quic_psk(void)
|
---|
1174 | {
|
---|
1175 | SSL_CTX *cctx = SSL_CTX_new_ex(libctx, NULL, OSSL_QUIC_client_method());
|
---|
1176 | SSL *clientquic = NULL;
|
---|
1177 | QUIC_TSERVER *qtserv = NULL;
|
---|
1178 | int testresult = 0;
|
---|
1179 |
|
---|
1180 | if (!TEST_ptr(cctx)
|
---|
1181 | /* No cert or private key for the server, i.e. PSK only */
|
---|
1182 | || !TEST_true(qtest_create_quic_objects(libctx, cctx, NULL, NULL,
|
---|
1183 | NULL, 0, &qtserv,
|
---|
1184 | &clientquic, NULL, NULL)))
|
---|
1185 | goto end;
|
---|
1186 |
|
---|
1187 | SSL_set_psk_use_session_callback(clientquic, use_session_cb);
|
---|
1188 | ossl_quic_tserver_set_psk_find_session_cb(qtserv, find_session_cb);
|
---|
1189 | use_session_cb_cnt = 0;
|
---|
1190 | find_session_cb_cnt = 0;
|
---|
1191 |
|
---|
1192 | clientpsk = serverpsk = create_a_psk(clientquic, SHA384_DIGEST_LENGTH);
|
---|
1193 | if (!TEST_ptr(clientpsk))
|
---|
1194 | goto end;
|
---|
1195 | /* We already had one ref. Add another one */
|
---|
1196 | SSL_SESSION_up_ref(clientpsk);
|
---|
1197 |
|
---|
1198 | if (!TEST_true(qtest_create_quic_connection(qtserv, clientquic))
|
---|
1199 | || !TEST_int_eq(1, find_session_cb_cnt)
|
---|
1200 | || !TEST_int_eq(1, use_session_cb_cnt)
|
---|
1201 | /* Check that we actually used the PSK */
|
---|
1202 | || !TEST_true(SSL_session_reused(clientquic)))
|
---|
1203 | goto end;
|
---|
1204 |
|
---|
1205 | testresult = 1;
|
---|
1206 |
|
---|
1207 | end:
|
---|
1208 | SSL_free(clientquic);
|
---|
1209 | ossl_quic_tserver_free(qtserv);
|
---|
1210 | SSL_CTX_free(cctx);
|
---|
1211 | SSL_SESSION_free(clientpsk);
|
---|
1212 | SSL_SESSION_free(serverpsk);
|
---|
1213 | clientpsk = serverpsk = NULL;
|
---|
1214 |
|
---|
1215 | return testresult;
|
---|
1216 | }
|
---|
1217 |
|
---|
1218 | static int test_client_auth(int idx)
|
---|
1219 | {
|
---|
1220 | SSL_CTX *cctx = SSL_CTX_new_ex(libctx, NULL, OSSL_QUIC_client_method());
|
---|
1221 | SSL_CTX *sctx = SSL_CTX_new_ex(libctx, NULL, TLS_method());
|
---|
1222 | SSL *clientquic = NULL;
|
---|
1223 | QUIC_TSERVER *qtserv = NULL;
|
---|
1224 | int testresult = 0;
|
---|
1225 | unsigned char buf[20];
|
---|
1226 | static char *msg = "A test message";
|
---|
1227 | size_t msglen = strlen(msg);
|
---|
1228 | size_t numbytes = 0;
|
---|
1229 |
|
---|
1230 | if (!TEST_ptr(cctx) || !TEST_ptr(sctx))
|
---|
1231 | goto err;
|
---|
1232 |
|
---|
1233 | SSL_CTX_set_verify(sctx, SSL_VERIFY_PEER | SSL_VERIFY_FAIL_IF_NO_PEER_CERT
|
---|
1234 | | SSL_VERIFY_CLIENT_ONCE, NULL);
|
---|
1235 |
|
---|
1236 | if (!TEST_true(SSL_CTX_load_verify_file(sctx, cauthca)))
|
---|
1237 | goto err;
|
---|
1238 |
|
---|
1239 | if (idx > 0
|
---|
1240 | && (!TEST_true(SSL_CTX_use_certificate_chain_file(cctx, ccert))
|
---|
1241 | || !TEST_true(SSL_CTX_use_PrivateKey_file(cctx, cprivkey,
|
---|
1242 | SSL_FILETYPE_PEM))))
|
---|
1243 | goto err;
|
---|
1244 |
|
---|
1245 | if (!TEST_true(qtest_create_quic_objects(libctx, cctx, sctx, cert,
|
---|
1246 | privkey, 0, &qtserv,
|
---|
1247 | &clientquic, NULL, NULL)))
|
---|
1248 | goto err;
|
---|
1249 |
|
---|
1250 | if (idx > 1) {
|
---|
1251 | if (!TEST_true(ssl_ctx_add_large_cert_chain(libctx, cctx, ccert))
|
---|
1252 | || !TEST_true(ssl_ctx_add_large_cert_chain(libctx, sctx, cert)))
|
---|
1253 | goto err;
|
---|
1254 | }
|
---|
1255 |
|
---|
1256 | if (idx == 0) {
|
---|
1257 | if (!TEST_false(qtest_create_quic_connection(qtserv, clientquic)))
|
---|
1258 | goto err;
|
---|
1259 |
|
---|
1260 | /* negative test passed */
|
---|
1261 | testresult = 1;
|
---|
1262 | goto err;
|
---|
1263 | }
|
---|
1264 |
|
---|
1265 | if (!TEST_true(qtest_create_quic_connection(qtserv, clientquic)))
|
---|
1266 | goto err;
|
---|
1267 |
|
---|
1268 | /* Check that sending and receiving app data is ok */
|
---|
1269 | if (!TEST_true(SSL_write_ex(clientquic, msg, msglen, &numbytes))
|
---|
1270 | || !TEST_size_t_eq(numbytes, msglen))
|
---|
1271 | goto err;
|
---|
1272 |
|
---|
1273 | ossl_quic_tserver_tick(qtserv);
|
---|
1274 | if (!TEST_true(ossl_quic_tserver_write(qtserv, 0,
|
---|
1275 | (unsigned char *)msg,
|
---|
1276 | msglen, &numbytes)))
|
---|
1277 | goto err;
|
---|
1278 |
|
---|
1279 | ossl_quic_tserver_tick(qtserv);
|
---|
1280 | SSL_handle_events(clientquic);
|
---|
1281 |
|
---|
1282 | if (!TEST_true(SSL_read_ex(clientquic, buf, sizeof(buf), &numbytes))
|
---|
1283 | || !TEST_size_t_eq(numbytes, msglen)
|
---|
1284 | || !TEST_mem_eq(buf, numbytes, msg, msglen))
|
---|
1285 | goto err;
|
---|
1286 |
|
---|
1287 | if (!TEST_true(qtest_shutdown(qtserv, clientquic)))
|
---|
1288 | goto err;
|
---|
1289 |
|
---|
1290 | testresult = 1;
|
---|
1291 |
|
---|
1292 | err:
|
---|
1293 | SSL_free(clientquic);
|
---|
1294 | ossl_quic_tserver_free(qtserv);
|
---|
1295 | SSL_CTX_free(sctx);
|
---|
1296 | SSL_CTX_free(cctx);
|
---|
1297 |
|
---|
1298 | return testresult;
|
---|
1299 | }
|
---|
1300 |
|
---|
1301 | /*
|
---|
1302 | * Test that we correctly handle ALPN supplied by the application
|
---|
1303 | * Test 0: ALPN is provided
|
---|
1304 | * Test 1: No ALPN is provided
|
---|
1305 | */
|
---|
1306 | static int test_alpn(int idx)
|
---|
1307 | {
|
---|
1308 | SSL_CTX *cctx = SSL_CTX_new_ex(libctx, NULL, OSSL_QUIC_client_method());
|
---|
1309 | SSL *clientquic = NULL;
|
---|
1310 | QUIC_TSERVER *qtserv = NULL;
|
---|
1311 | int testresult = 0;
|
---|
1312 | int ret;
|
---|
1313 |
|
---|
1314 | /*
|
---|
1315 | * Ensure we only configure ciphersuites that are available with both the
|
---|
1316 | * default and fips providers to get the same output in both cases
|
---|
1317 | */
|
---|
1318 | if (!TEST_true(SSL_CTX_set_ciphersuites(cctx, "TLS_AES_128_GCM_SHA256")))
|
---|
1319 | goto err;
|
---|
1320 |
|
---|
1321 | if (!TEST_ptr(cctx)
|
---|
1322 | || !TEST_true(qtest_create_quic_objects(libctx, cctx, NULL, cert,
|
---|
1323 | privkey,
|
---|
1324 | QTEST_FLAG_FAKE_TIME,
|
---|
1325 | &qtserv,
|
---|
1326 | &clientquic, NULL, NULL)))
|
---|
1327 | goto err;
|
---|
1328 |
|
---|
1329 | if (idx == 0) {
|
---|
1330 | /*
|
---|
1331 | * Clear the ALPN we set in qtest_create_quic_objects. We use TEST_false
|
---|
1332 | * because SSL_set_alpn_protos returns 0 for success.
|
---|
1333 | */
|
---|
1334 | if (!TEST_false(SSL_set_alpn_protos(clientquic, NULL, 0)))
|
---|
1335 | goto err;
|
---|
1336 | }
|
---|
1337 |
|
---|
1338 | ret = SSL_connect(clientquic);
|
---|
1339 | if (!TEST_int_le(ret, 0))
|
---|
1340 | goto err;
|
---|
1341 | if (idx == 0) {
|
---|
1342 | /* We expect an immediate error due to lack of ALPN */
|
---|
1343 | if (!TEST_int_eq(SSL_get_error(clientquic, ret), SSL_ERROR_SSL))
|
---|
1344 | goto err;
|
---|
1345 | } else {
|
---|
1346 | /* ALPN was provided so we expect the connection to succeed */
|
---|
1347 | if (!TEST_int_eq(SSL_get_error(clientquic, ret), SSL_ERROR_WANT_READ)
|
---|
1348 | || !TEST_true(qtest_create_quic_connection(qtserv, clientquic)))
|
---|
1349 | goto err;
|
---|
1350 | }
|
---|
1351 |
|
---|
1352 | testresult = 1;
|
---|
1353 | err:
|
---|
1354 | ossl_quic_tserver_free(qtserv);
|
---|
1355 | SSL_free(clientquic);
|
---|
1356 | SSL_CTX_free(cctx);
|
---|
1357 |
|
---|
1358 | return testresult;
|
---|
1359 | }
|
---|
1360 |
|
---|
1361 | /*
|
---|
1362 | * Test SSL_get_shutdown() behavior.
|
---|
1363 | */
|
---|
1364 | static int test_get_shutdown(void)
|
---|
1365 | {
|
---|
1366 | SSL_CTX *cctx = SSL_CTX_new_ex(libctx, NULL, OSSL_QUIC_client_method());
|
---|
1367 | SSL *clientquic = NULL;
|
---|
1368 | QUIC_TSERVER *qtserv = NULL;
|
---|
1369 | int testresult = 0;
|
---|
1370 |
|
---|
1371 | if (!TEST_ptr(cctx)
|
---|
1372 | || !TEST_true(qtest_create_quic_objects(libctx, cctx, NULL, cert,
|
---|
1373 | privkey,
|
---|
1374 | QTEST_FLAG_FAKE_TIME,
|
---|
1375 | &qtserv, &clientquic,
|
---|
1376 | NULL, NULL))
|
---|
1377 | || !TEST_true(qtest_create_quic_connection(qtserv, clientquic)))
|
---|
1378 | goto err;
|
---|
1379 |
|
---|
1380 | if (!TEST_int_eq(SSL_get_shutdown(clientquic), 0))
|
---|
1381 | goto err;
|
---|
1382 |
|
---|
1383 | if (!TEST_int_eq(SSL_shutdown(clientquic), 0))
|
---|
1384 | goto err;
|
---|
1385 |
|
---|
1386 | if (!TEST_int_eq(SSL_get_shutdown(clientquic), SSL_SENT_SHUTDOWN))
|
---|
1387 | goto err;
|
---|
1388 |
|
---|
1389 | do {
|
---|
1390 | ossl_quic_tserver_tick(qtserv);
|
---|
1391 | qtest_add_time(100);
|
---|
1392 | } while (SSL_shutdown(clientquic) == 0);
|
---|
1393 |
|
---|
1394 | if (!TEST_int_eq(SSL_get_shutdown(clientquic),
|
---|
1395 | SSL_SENT_SHUTDOWN | SSL_RECEIVED_SHUTDOWN))
|
---|
1396 | goto err;
|
---|
1397 |
|
---|
1398 | testresult = 1;
|
---|
1399 | err:
|
---|
1400 | ossl_quic_tserver_free(qtserv);
|
---|
1401 | SSL_free(clientquic);
|
---|
1402 | SSL_CTX_free(cctx);
|
---|
1403 |
|
---|
1404 | return testresult;
|
---|
1405 | }
|
---|
1406 |
|
---|
1407 | #define MAX_LOOPS 2000
|
---|
1408 |
|
---|
1409 | /*
|
---|
1410 | * Keep retrying SSL_read_ex until it succeeds or we give up. Accept a stream
|
---|
1411 | * if we don't already have one
|
---|
1412 | */
|
---|
1413 | static int unreliable_client_read(SSL *clientquic, SSL **stream, void *buf,
|
---|
1414 | size_t buflen, size_t *readbytes,
|
---|
1415 | QUIC_TSERVER *qtserv)
|
---|
1416 | {
|
---|
1417 | int abortctr;
|
---|
1418 |
|
---|
1419 | /* We just do this in a loop with a sleep for simplicity */
|
---|
1420 | for (abortctr = 0; abortctr < MAX_LOOPS; abortctr++) {
|
---|
1421 | if (*stream == NULL) {
|
---|
1422 | SSL_handle_events(clientquic);
|
---|
1423 | *stream = SSL_accept_stream(clientquic, 0);
|
---|
1424 | }
|
---|
1425 |
|
---|
1426 | if (*stream != NULL) {
|
---|
1427 | if (SSL_read_ex(*stream, buf, buflen, readbytes))
|
---|
1428 | return 1;
|
---|
1429 | if (!TEST_int_eq(SSL_get_error(*stream, 0), SSL_ERROR_WANT_READ))
|
---|
1430 | return 0;
|
---|
1431 | }
|
---|
1432 | ossl_quic_tserver_tick(qtserv);
|
---|
1433 | qtest_add_time(1);
|
---|
1434 | qtest_wait_for_timeout(clientquic, qtserv);
|
---|
1435 | }
|
---|
1436 |
|
---|
1437 | TEST_error("No progress made");
|
---|
1438 | return 0;
|
---|
1439 | }
|
---|
1440 |
|
---|
1441 | /* Keep retrying ossl_quic_tserver_read until it succeeds or we give up */
|
---|
1442 | static int unreliable_server_read(QUIC_TSERVER *qtserv, uint64_t sid,
|
---|
1443 | void *buf, size_t buflen, size_t *readbytes,
|
---|
1444 | SSL *clientquic)
|
---|
1445 | {
|
---|
1446 | int abortctr;
|
---|
1447 |
|
---|
1448 | /* We just do this in a loop with a sleep for simplicity */
|
---|
1449 | for (abortctr = 0; abortctr < MAX_LOOPS; abortctr++) {
|
---|
1450 | if (ossl_quic_tserver_read(qtserv, sid, buf, buflen, readbytes)
|
---|
1451 | && *readbytes > 1)
|
---|
1452 | return 1;
|
---|
1453 | ossl_quic_tserver_tick(qtserv);
|
---|
1454 | SSL_handle_events(clientquic);
|
---|
1455 | qtest_add_time(1);
|
---|
1456 | qtest_wait_for_timeout(clientquic, qtserv);
|
---|
1457 | }
|
---|
1458 |
|
---|
1459 | TEST_error("No progress made");
|
---|
1460 | return 0;
|
---|
1461 | }
|
---|
1462 |
|
---|
1463 | /*
|
---|
1464 | * Create a connection and send data using an unreliable transport. We introduce
|
---|
1465 | * random noise to drop, delay and duplicate datagrams.
|
---|
1466 | * Test 0: Introduce random noise to datagrams
|
---|
1467 | * Test 1: As with test 0 but also split datagrams containing multiple packets
|
---|
1468 | * into individual datagrams so that individual packets can be affected
|
---|
1469 | * by noise - not just a whole datagram.
|
---|
1470 | */
|
---|
1471 | static int test_noisy_dgram(int idx)
|
---|
1472 | {
|
---|
1473 | SSL_CTX *cctx = SSL_CTX_new_ex(libctx, NULL, OSSL_QUIC_client_method());
|
---|
1474 | SSL *clientquic = NULL, *stream[2] = { NULL, NULL };
|
---|
1475 | QUIC_TSERVER *qtserv = NULL;
|
---|
1476 | int testresult = 0;
|
---|
1477 | uint64_t sid = 0;
|
---|
1478 | char *msg = "Hello world!";
|
---|
1479 | size_t msglen = strlen(msg), written, readbytes, i, j;
|
---|
1480 | unsigned char buf[80];
|
---|
1481 | int flags = QTEST_FLAG_NOISE | QTEST_FLAG_FAKE_TIME;
|
---|
1482 | QTEST_FAULT *fault = NULL;
|
---|
1483 |
|
---|
1484 | if (idx == 1)
|
---|
1485 | flags |= QTEST_FLAG_PACKET_SPLIT;
|
---|
1486 |
|
---|
1487 | if (!TEST_ptr(cctx)
|
---|
1488 | || !TEST_true(qtest_create_quic_objects(libctx, cctx, NULL, cert,
|
---|
1489 | privkey, flags,
|
---|
1490 | &qtserv,
|
---|
1491 | &clientquic, &fault, NULL)))
|
---|
1492 | goto err;
|
---|
1493 |
|
---|
1494 | if (!TEST_true(qtest_create_quic_connection(qtserv, clientquic)))
|
---|
1495 | goto err;
|
---|
1496 |
|
---|
1497 | if (!TEST_true(SSL_set_incoming_stream_policy(clientquic,
|
---|
1498 | SSL_INCOMING_STREAM_POLICY_ACCEPT,
|
---|
1499 | 0))
|
---|
1500 | || !TEST_true(SSL_set_default_stream_mode(clientquic,
|
---|
1501 | SSL_DEFAULT_STREAM_MODE_NONE)))
|
---|
1502 | goto err;
|
---|
1503 |
|
---|
1504 | for (j = 0; j < 2; j++) {
|
---|
1505 | if (!TEST_true(ossl_quic_tserver_stream_new(qtserv, 0, &sid)))
|
---|
1506 | goto err;
|
---|
1507 | ossl_quic_tserver_tick(qtserv);
|
---|
1508 | qtest_add_time(1);
|
---|
1509 |
|
---|
1510 | /*
|
---|
1511 | * Send data from the server to the client. Some datagrams may get
|
---|
1512 | * lost, modified, dropped or re-ordered. We repeat 20 times to ensure
|
---|
1513 | * we are sending enough datagrams for problems to be noticed.
|
---|
1514 | */
|
---|
1515 | for (i = 0; i < 20; i++) {
|
---|
1516 | if (!TEST_true(ossl_quic_tserver_write(qtserv, sid,
|
---|
1517 | (unsigned char *)msg, msglen,
|
---|
1518 | &written))
|
---|
1519 | || !TEST_size_t_eq(msglen, written))
|
---|
1520 | goto err;
|
---|
1521 | ossl_quic_tserver_tick(qtserv);
|
---|
1522 | qtest_add_time(1);
|
---|
1523 |
|
---|
1524 | /*
|
---|
1525 | * Since the underlying BIO is now noisy we may get failures that
|
---|
1526 | * need to be retried - so we use unreliable_client_read() to
|
---|
1527 | * handle that
|
---|
1528 | */
|
---|
1529 | if (!TEST_true(unreliable_client_read(clientquic, &stream[j], buf,
|
---|
1530 | sizeof(buf), &readbytes,
|
---|
1531 | qtserv))
|
---|
1532 | || !TEST_mem_eq(msg, msglen, buf, readbytes))
|
---|
1533 | goto err;
|
---|
1534 | }
|
---|
1535 |
|
---|
1536 | /* Send data from the client to the server */
|
---|
1537 | for (i = 0; i < 20; i++) {
|
---|
1538 | if (!TEST_true(SSL_write_ex(stream[j], (unsigned char *)msg,
|
---|
1539 | msglen, &written))
|
---|
1540 | || !TEST_size_t_eq(msglen, written))
|
---|
1541 | goto err;
|
---|
1542 |
|
---|
1543 | ossl_quic_tserver_tick(qtserv);
|
---|
1544 | qtest_add_time(1);
|
---|
1545 |
|
---|
1546 | /*
|
---|
1547 | * Since the underlying BIO is now noisy we may get failures that
|
---|
1548 | * need to be retried - so we use unreliable_server_read() to
|
---|
1549 | * handle that
|
---|
1550 | */
|
---|
1551 | if (!TEST_true(unreliable_server_read(qtserv, sid, buf, sizeof(buf),
|
---|
1552 | &readbytes, clientquic))
|
---|
1553 | || !TEST_mem_eq(msg, msglen, buf, readbytes))
|
---|
1554 | goto err;
|
---|
1555 | }
|
---|
1556 | }
|
---|
1557 |
|
---|
1558 | testresult = 1;
|
---|
1559 | err:
|
---|
1560 | ossl_quic_tserver_free(qtserv);
|
---|
1561 | SSL_free(stream[0]);
|
---|
1562 | SSL_free(stream[1]);
|
---|
1563 | SSL_free(clientquic);
|
---|
1564 | SSL_CTX_free(cctx);
|
---|
1565 | qtest_fault_free(fault);
|
---|
1566 |
|
---|
1567 | return testresult;
|
---|
1568 | }
|
---|
1569 |
|
---|
1570 | /*
|
---|
1571 | * Create a connection and send some big data using a transport with limited bandwidth.
|
---|
1572 | */
|
---|
1573 |
|
---|
1574 | #define TEST_TRANSFER_DATA_SIZE (2*1024*1024) /* 2 MBytes */
|
---|
1575 | #define TEST_SINGLE_WRITE_SIZE (16*1024) /* 16 kBytes */
|
---|
1576 | #define TEST_BW_LIMIT 1000 /* 1000 Bytes/ms */
|
---|
1577 | static int test_bw_limit(void)
|
---|
1578 | {
|
---|
1579 | SSL_CTX *cctx = SSL_CTX_new_ex(libctx, NULL, OSSL_QUIC_client_method());
|
---|
1580 | SSL *clientquic = NULL;
|
---|
1581 | QUIC_TSERVER *qtserv = NULL;
|
---|
1582 | int testresult = 0;
|
---|
1583 | unsigned char *msg = NULL, *recvbuf = NULL;
|
---|
1584 | size_t sendlen = TEST_TRANSFER_DATA_SIZE;
|
---|
1585 | size_t recvlen = TEST_TRANSFER_DATA_SIZE;
|
---|
1586 | size_t written, readbytes;
|
---|
1587 | int flags = QTEST_FLAG_NOISE | QTEST_FLAG_FAKE_TIME;
|
---|
1588 | QTEST_FAULT *fault = NULL;
|
---|
1589 | uint64_t real_bw;
|
---|
1590 |
|
---|
1591 | if (!TEST_ptr(cctx)
|
---|
1592 | || !TEST_true(qtest_create_quic_objects(libctx, cctx, NULL, cert,
|
---|
1593 | privkey, flags,
|
---|
1594 | &qtserv,
|
---|
1595 | &clientquic, &fault, NULL)))
|
---|
1596 | goto err;
|
---|
1597 |
|
---|
1598 | if (!TEST_ptr(msg = OPENSSL_zalloc(TEST_SINGLE_WRITE_SIZE))
|
---|
1599 | || !TEST_ptr(recvbuf = OPENSSL_zalloc(TEST_SINGLE_WRITE_SIZE)))
|
---|
1600 | goto err;
|
---|
1601 |
|
---|
1602 | /* Set BW to 1000 Bytes/ms -> 1MByte/s both ways */
|
---|
1603 | if (!TEST_true(qtest_fault_set_bw_limit(fault, 1000, 1000, 0)))
|
---|
1604 | goto err;
|
---|
1605 |
|
---|
1606 | if (!TEST_true(qtest_create_quic_connection(qtserv, clientquic)))
|
---|
1607 | goto err;
|
---|
1608 |
|
---|
1609 | qtest_start_stopwatch();
|
---|
1610 |
|
---|
1611 | while (recvlen > 0) {
|
---|
1612 | qtest_add_time(1);
|
---|
1613 |
|
---|
1614 | if (sendlen > 0) {
|
---|
1615 | if (!SSL_write_ex(clientquic, msg,
|
---|
1616 | sendlen > TEST_SINGLE_WRITE_SIZE ? TEST_SINGLE_WRITE_SIZE
|
---|
1617 | : sendlen,
|
---|
1618 | &written)) {
|
---|
1619 | TEST_info("Retrying to send: %llu", (unsigned long long) sendlen);
|
---|
1620 | if (!TEST_int_eq(SSL_get_error(clientquic, 0), SSL_ERROR_WANT_WRITE))
|
---|
1621 | goto err;
|
---|
1622 | } else {
|
---|
1623 | sendlen -= written;
|
---|
1624 | TEST_info("Remaining to send: %llu", (unsigned long long) sendlen);
|
---|
1625 | }
|
---|
1626 | } else {
|
---|
1627 | SSL_handle_events(clientquic);
|
---|
1628 | }
|
---|
1629 |
|
---|
1630 | if (ossl_quic_tserver_read(qtserv, 0, recvbuf,
|
---|
1631 | recvlen > TEST_SINGLE_WRITE_SIZE ? TEST_SINGLE_WRITE_SIZE
|
---|
1632 | : recvlen,
|
---|
1633 | &readbytes)
|
---|
1634 | && readbytes > 1) {
|
---|
1635 | recvlen -= readbytes;
|
---|
1636 | TEST_info("Remaining to recv: %llu", (unsigned long long) recvlen);
|
---|
1637 | } else {
|
---|
1638 | TEST_info("No progress on recv: %llu", (unsigned long long) recvlen);
|
---|
1639 | }
|
---|
1640 | ossl_quic_tserver_tick(qtserv);
|
---|
1641 | }
|
---|
1642 | real_bw = TEST_TRANSFER_DATA_SIZE / qtest_get_stopwatch_time();
|
---|
1643 |
|
---|
1644 | TEST_info("BW limit: %d Bytes/ms Real bandwidth reached: %llu Bytes/ms",
|
---|
1645 | TEST_BW_LIMIT, (unsigned long long)real_bw);
|
---|
1646 |
|
---|
1647 | if (!TEST_uint64_t_lt(real_bw, TEST_BW_LIMIT))
|
---|
1648 | goto err;
|
---|
1649 |
|
---|
1650 | testresult = 1;
|
---|
1651 | err:
|
---|
1652 | OPENSSL_free(msg);
|
---|
1653 | OPENSSL_free(recvbuf);
|
---|
1654 | ossl_quic_tserver_free(qtserv);
|
---|
1655 | SSL_free(clientquic);
|
---|
1656 | SSL_CTX_free(cctx);
|
---|
1657 | qtest_fault_free(fault);
|
---|
1658 |
|
---|
1659 | return testresult;
|
---|
1660 | }
|
---|
1661 |
|
---|
1662 | enum {
|
---|
1663 | TPARAM_OP_DUP,
|
---|
1664 | TPARAM_OP_DROP,
|
---|
1665 | TPARAM_OP_INJECT,
|
---|
1666 | TPARAM_OP_INJECT_TWICE,
|
---|
1667 | TPARAM_OP_INJECT_RAW,
|
---|
1668 | TPARAM_OP_DROP_INJECT,
|
---|
1669 | TPARAM_OP_MUTATE
|
---|
1670 | };
|
---|
1671 |
|
---|
1672 | #define TPARAM_CHECK_DUP(name, reason) \
|
---|
1673 | { QUIC_TPARAM_##name, TPARAM_OP_DUP, (reason) },
|
---|
1674 | #define TPARAM_CHECK_DROP(name, reason) \
|
---|
1675 | { QUIC_TPARAM_##name, TPARAM_OP_DROP, (reason) },
|
---|
1676 | #define TPARAM_CHECK_INJECT(name, buf, buf_len, reason) \
|
---|
1677 | { QUIC_TPARAM_##name, TPARAM_OP_INJECT, (reason), \
|
---|
1678 | (buf), (buf_len) },
|
---|
1679 | #define TPARAM_CHECK_INJECT_A(name, buf, reason) \
|
---|
1680 | TPARAM_CHECK_INJECT(name, buf, sizeof(buf), reason)
|
---|
1681 | #define TPARAM_CHECK_DROP_INJECT(name, buf, buf_len, reason) \
|
---|
1682 | { QUIC_TPARAM_##name, TPARAM_OP_DROP_INJECT, (reason), \
|
---|
1683 | (buf), (buf_len) },
|
---|
1684 | #define TPARAM_CHECK_DROP_INJECT_A(name, buf, reason) \
|
---|
1685 | TPARAM_CHECK_DROP_INJECT(name, buf, sizeof(buf), reason)
|
---|
1686 | #define TPARAM_CHECK_INJECT_TWICE(name, buf, buf_len, reason) \
|
---|
1687 | { QUIC_TPARAM_##name, TPARAM_OP_INJECT_TWICE, (reason), \
|
---|
1688 | (buf), (buf_len) },
|
---|
1689 | #define TPARAM_CHECK_INJECT_TWICE_A(name, buf, reason) \
|
---|
1690 | TPARAM_CHECK_INJECT_TWICE(name, buf, sizeof(buf), reason)
|
---|
1691 | #define TPARAM_CHECK_INJECT_RAW(buf, buf_len, reason) \
|
---|
1692 | { 0, TPARAM_OP_INJECT_RAW, (reason), \
|
---|
1693 | (buf), (buf_len) },
|
---|
1694 | #define TPARAM_CHECK_INJECT_RAW_A(buf, reason) \
|
---|
1695 | TPARAM_CHECK_INJECT_RAW(buf, sizeof(buf), reason)
|
---|
1696 | #define TPARAM_CHECK_MUTATE(name, reason) \
|
---|
1697 | { QUIC_TPARAM_##name, TPARAM_OP_MUTATE, (reason) },
|
---|
1698 | #define TPARAM_CHECK_INT(name, reason) \
|
---|
1699 | TPARAM_CHECK_DROP_INJECT(name, NULL, 0, reason) \
|
---|
1700 | TPARAM_CHECK_DROP_INJECT_A(name, bogus_int, reason) \
|
---|
1701 | TPARAM_CHECK_DROP_INJECT_A(name, int_with_trailer, reason)
|
---|
1702 |
|
---|
1703 | struct tparam_test {
|
---|
1704 | uint64_t id;
|
---|
1705 | int op;
|
---|
1706 | const char *expect_fail; /* substring to expect in reason */
|
---|
1707 | const void *buf;
|
---|
1708 | size_t buf_len;
|
---|
1709 | };
|
---|
1710 |
|
---|
1711 | static const unsigned char retry_scid_1[8] = { 0 };
|
---|
1712 |
|
---|
1713 | static const unsigned char disable_active_migration_1[] = {
|
---|
1714 | 0x00
|
---|
1715 | };
|
---|
1716 |
|
---|
1717 | static const unsigned char malformed_stateless_reset_token_1[] = {
|
---|
1718 | 0x02, 0xff
|
---|
1719 | };
|
---|
1720 |
|
---|
1721 | static const unsigned char malformed_stateless_reset_token_2[] = {
|
---|
1722 | 0x01
|
---|
1723 | };
|
---|
1724 |
|
---|
1725 | static const unsigned char malformed_stateless_reset_token_3[15] = { 0 };
|
---|
1726 |
|
---|
1727 | static const unsigned char malformed_stateless_reset_token_4[17] = { 0 };
|
---|
1728 |
|
---|
1729 | static const unsigned char malformed_preferred_addr_1[] = {
|
---|
1730 | 0x0d, 0xff
|
---|
1731 | };
|
---|
1732 |
|
---|
1733 | static const unsigned char malformed_preferred_addr_2[42] = {
|
---|
1734 | 0x0d, 0x28, /* too short */
|
---|
1735 | };
|
---|
1736 |
|
---|
1737 | static const unsigned char malformed_preferred_addr_3[64] = {
|
---|
1738 | 0x0d, 0x3e, /* too long */
|
---|
1739 | };
|
---|
1740 |
|
---|
1741 | static const unsigned char malformed_preferred_addr_4[] = {
|
---|
1742 | /* TPARAM too short for CID length indicated */
|
---|
1743 | 0x0d, 0x29, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
---|
1744 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
---|
1745 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
---|
1746 | 0x00, 0x00, 0x01, 0x55,
|
---|
1747 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
---|
1748 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
---|
1749 | };
|
---|
1750 |
|
---|
1751 | static const unsigned char malformed_unknown_1[] = {
|
---|
1752 | 0xff
|
---|
1753 | };
|
---|
1754 |
|
---|
1755 | static const unsigned char malformed_unknown_2[] = {
|
---|
1756 | 0x55, 0x55,
|
---|
1757 | };
|
---|
1758 |
|
---|
1759 | static const unsigned char malformed_unknown_3[] = {
|
---|
1760 | 0x55, 0x55, 0x01,
|
---|
1761 | };
|
---|
1762 |
|
---|
1763 | static const unsigned char ack_delay_exp[] = {
|
---|
1764 | 0x03
|
---|
1765 | };
|
---|
1766 |
|
---|
1767 | static const unsigned char stateless_reset_token[16] = { 0x42 };
|
---|
1768 |
|
---|
1769 | static const unsigned char preferred_addr[] = {
|
---|
1770 | 0x44, 0x44, 0x44, 0x44,
|
---|
1771 | 0x55, 0x55,
|
---|
1772 | 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66,
|
---|
1773 | 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66,
|
---|
1774 | 0x77, 0x77,
|
---|
1775 | 0x02, 0xAA, 0xBB,
|
---|
1776 | 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99,
|
---|
1777 | 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99,
|
---|
1778 | };
|
---|
1779 |
|
---|
1780 | static const unsigned char long_cid[21] = { 0x42 };
|
---|
1781 |
|
---|
1782 | static const unsigned char excess_ack_delay_exp[] = {
|
---|
1783 | 0x15,
|
---|
1784 | };
|
---|
1785 |
|
---|
1786 | static const unsigned char excess_max_ack_delay[] = {
|
---|
1787 | 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00,
|
---|
1788 | };
|
---|
1789 |
|
---|
1790 | static const unsigned char excess_initial_max_streams[] = {
|
---|
1791 | 0xD0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
|
---|
1792 | };
|
---|
1793 |
|
---|
1794 | static const unsigned char undersize_udp_payload_size[] = {
|
---|
1795 | 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0xaf,
|
---|
1796 | };
|
---|
1797 |
|
---|
1798 | static const unsigned char undersize_active_conn_id_limit[] = {
|
---|
1799 | 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
|
---|
1800 | };
|
---|
1801 |
|
---|
1802 | static const unsigned char bogus_int[9] = { 0 };
|
---|
1803 |
|
---|
1804 | static const unsigned char int_with_trailer[2] = { 0x01 };
|
---|
1805 |
|
---|
1806 | #define QUIC_TPARAM_UNKNOWN_1 0xf1f1
|
---|
1807 |
|
---|
1808 | static const struct tparam_test tparam_tests[] = {
|
---|
1809 | TPARAM_CHECK_DUP(ORIG_DCID,
|
---|
1810 | "ORIG_DCID appears multiple times")
|
---|
1811 | TPARAM_CHECK_DUP(INITIAL_SCID,
|
---|
1812 | "INITIAL_SCID appears multiple times")
|
---|
1813 | TPARAM_CHECK_DUP(INITIAL_MAX_DATA,
|
---|
1814 | "INITIAL_MAX_DATA appears multiple times")
|
---|
1815 | TPARAM_CHECK_DUP(INITIAL_MAX_STREAM_DATA_BIDI_LOCAL,
|
---|
1816 | "INITIAL_MAX_STREAM_DATA_BIDI_LOCAL appears multiple times")
|
---|
1817 | TPARAM_CHECK_DUP(INITIAL_MAX_STREAM_DATA_BIDI_REMOTE,
|
---|
1818 | "INITIAL_MAX_STREAM_DATA_BIDI_REMOTE appears multiple times")
|
---|
1819 | TPARAM_CHECK_DUP(INITIAL_MAX_STREAM_DATA_UNI,
|
---|
1820 | "INITIAL_MAX_STREAM_DATA_UNI appears multiple times")
|
---|
1821 | TPARAM_CHECK_DUP(INITIAL_MAX_STREAMS_BIDI,
|
---|
1822 | "INITIAL_MAX_STREAMS_BIDI appears multiple times")
|
---|
1823 | TPARAM_CHECK_DUP(INITIAL_MAX_STREAMS_UNI,
|
---|
1824 | "INITIAL_MAX_STREAMS_UNI appears multiple times")
|
---|
1825 | TPARAM_CHECK_DUP(MAX_IDLE_TIMEOUT,
|
---|
1826 | "MAX_IDLE_TIMEOUT appears multiple times")
|
---|
1827 | TPARAM_CHECK_DUP(MAX_UDP_PAYLOAD_SIZE,
|
---|
1828 | "MAX_UDP_PAYLOAD_SIZE appears multiple times")
|
---|
1829 | TPARAM_CHECK_DUP(ACTIVE_CONN_ID_LIMIT,
|
---|
1830 | "ACTIVE_CONN_ID_LIMIT appears multiple times")
|
---|
1831 | TPARAM_CHECK_DUP(DISABLE_ACTIVE_MIGRATION,
|
---|
1832 | "DISABLE_ACTIVE_MIGRATION appears multiple times")
|
---|
1833 |
|
---|
1834 | TPARAM_CHECK_DROP(INITIAL_SCID,
|
---|
1835 | "INITIAL_SCID was not sent but is required")
|
---|
1836 | TPARAM_CHECK_DROP(ORIG_DCID,
|
---|
1837 | "ORIG_DCID was not sent but is required")
|
---|
1838 |
|
---|
1839 | TPARAM_CHECK_INJECT_A(RETRY_SCID, retry_scid_1,
|
---|
1840 | "RETRY_SCID sent when not performing a retry")
|
---|
1841 | TPARAM_CHECK_DROP_INJECT_A(DISABLE_ACTIVE_MIGRATION, disable_active_migration_1,
|
---|
1842 | "DISABLE_ACTIVE_MIGRATION is malformed")
|
---|
1843 | TPARAM_CHECK_INJECT(UNKNOWN_1, NULL, 0,
|
---|
1844 | NULL)
|
---|
1845 | TPARAM_CHECK_INJECT_RAW_A(malformed_stateless_reset_token_1,
|
---|
1846 | "STATELESS_RESET_TOKEN is malformed")
|
---|
1847 | TPARAM_CHECK_INJECT_A(STATELESS_RESET_TOKEN,
|
---|
1848 | malformed_stateless_reset_token_2,
|
---|
1849 | "STATELESS_RESET_TOKEN is malformed")
|
---|
1850 | TPARAM_CHECK_INJECT_A(STATELESS_RESET_TOKEN,
|
---|
1851 | malformed_stateless_reset_token_3,
|
---|
1852 | "STATELESS_RESET_TOKEN is malformed")
|
---|
1853 | TPARAM_CHECK_INJECT_A(STATELESS_RESET_TOKEN,
|
---|
1854 | malformed_stateless_reset_token_4,
|
---|
1855 | "STATELESS_RESET_TOKEN is malformed")
|
---|
1856 | TPARAM_CHECK_INJECT(STATELESS_RESET_TOKEN,
|
---|
1857 | NULL, 0,
|
---|
1858 | "STATELESS_RESET_TOKEN is malformed")
|
---|
1859 | TPARAM_CHECK_INJECT_RAW_A(malformed_preferred_addr_1,
|
---|
1860 | "PREFERRED_ADDR is malformed")
|
---|
1861 | TPARAM_CHECK_INJECT_RAW_A(malformed_preferred_addr_2,
|
---|
1862 | "PREFERRED_ADDR is malformed")
|
---|
1863 | TPARAM_CHECK_INJECT_RAW_A(malformed_preferred_addr_3,
|
---|
1864 | "PREFERRED_ADDR is malformed")
|
---|
1865 | TPARAM_CHECK_INJECT_RAW_A(malformed_preferred_addr_4,
|
---|
1866 | "PREFERRED_ADDR is malformed")
|
---|
1867 | TPARAM_CHECK_INJECT_RAW_A(malformed_unknown_1,
|
---|
1868 | "bad transport parameter")
|
---|
1869 | TPARAM_CHECK_INJECT_RAW_A(malformed_unknown_2,
|
---|
1870 | "bad transport parameter")
|
---|
1871 | TPARAM_CHECK_INJECT_RAW_A(malformed_unknown_3,
|
---|
1872 | "bad transport parameter")
|
---|
1873 |
|
---|
1874 | TPARAM_CHECK_INJECT_A(ACK_DELAY_EXP, excess_ack_delay_exp,
|
---|
1875 | "ACK_DELAY_EXP is malformed")
|
---|
1876 | TPARAM_CHECK_INJECT_A(MAX_ACK_DELAY, excess_max_ack_delay,
|
---|
1877 | "MAX_ACK_DELAY is malformed")
|
---|
1878 | TPARAM_CHECK_DROP_INJECT_A(INITIAL_MAX_STREAMS_BIDI, excess_initial_max_streams,
|
---|
1879 | "INITIAL_MAX_STREAMS_BIDI is malformed")
|
---|
1880 | TPARAM_CHECK_DROP_INJECT_A(INITIAL_MAX_STREAMS_UNI, excess_initial_max_streams,
|
---|
1881 | "INITIAL_MAX_STREAMS_UNI is malformed")
|
---|
1882 |
|
---|
1883 | TPARAM_CHECK_DROP_INJECT_A(MAX_UDP_PAYLOAD_SIZE, undersize_udp_payload_size,
|
---|
1884 | "MAX_UDP_PAYLOAD_SIZE is malformed")
|
---|
1885 | TPARAM_CHECK_DROP_INJECT_A(ACTIVE_CONN_ID_LIMIT, undersize_active_conn_id_limit,
|
---|
1886 | "ACTIVE_CONN_ID_LIMIT is malformed")
|
---|
1887 |
|
---|
1888 | TPARAM_CHECK_INJECT_TWICE_A(ACK_DELAY_EXP, ack_delay_exp,
|
---|
1889 | "ACK_DELAY_EXP appears multiple times")
|
---|
1890 | TPARAM_CHECK_INJECT_TWICE_A(MAX_ACK_DELAY, ack_delay_exp,
|
---|
1891 | "MAX_ACK_DELAY appears multiple times")
|
---|
1892 | TPARAM_CHECK_INJECT_TWICE_A(STATELESS_RESET_TOKEN, stateless_reset_token,
|
---|
1893 | "STATELESS_RESET_TOKEN appears multiple times")
|
---|
1894 | TPARAM_CHECK_INJECT_TWICE_A(PREFERRED_ADDR, preferred_addr,
|
---|
1895 | "PREFERRED_ADDR appears multiple times")
|
---|
1896 |
|
---|
1897 | TPARAM_CHECK_MUTATE(ORIG_DCID,
|
---|
1898 | "ORIG_DCID does not match expected value")
|
---|
1899 | TPARAM_CHECK_MUTATE(INITIAL_SCID,
|
---|
1900 | "INITIAL_SCID does not match expected value")
|
---|
1901 |
|
---|
1902 | TPARAM_CHECK_DROP_INJECT_A(ORIG_DCID, long_cid,
|
---|
1903 | "ORIG_DCID is malformed")
|
---|
1904 | TPARAM_CHECK_DROP_INJECT_A(INITIAL_SCID, long_cid,
|
---|
1905 | "INITIAL_SCID is malformed")
|
---|
1906 |
|
---|
1907 | TPARAM_CHECK_INT(INITIAL_MAX_DATA,
|
---|
1908 | "INITIAL_MAX_DATA is malformed")
|
---|
1909 | TPARAM_CHECK_INT(INITIAL_MAX_STREAM_DATA_BIDI_LOCAL,
|
---|
1910 | "INITIAL_MAX_STREAM_DATA_BIDI_LOCAL is malformed")
|
---|
1911 | TPARAM_CHECK_INT(INITIAL_MAX_STREAM_DATA_BIDI_REMOTE,
|
---|
1912 | "INITIAL_MAX_STREAM_DATA_BIDI_REMOTE is malformed")
|
---|
1913 | TPARAM_CHECK_INT(INITIAL_MAX_STREAM_DATA_UNI,
|
---|
1914 | "INITIAL_MAX_STREAM_DATA_UNI is malformed")
|
---|
1915 | TPARAM_CHECK_INT(ACK_DELAY_EXP,
|
---|
1916 | "ACK_DELAY_EXP is malformed")
|
---|
1917 | TPARAM_CHECK_INT(MAX_ACK_DELAY,
|
---|
1918 | "MAX_ACK_DELAY is malformed")
|
---|
1919 | TPARAM_CHECK_INT(INITIAL_MAX_STREAMS_BIDI,
|
---|
1920 | "INITIAL_MAX_STREAMS_BIDI is malformed")
|
---|
1921 | TPARAM_CHECK_INT(INITIAL_MAX_STREAMS_UNI,
|
---|
1922 | "INITIAL_MAX_STREAMS_UNI is malformed")
|
---|
1923 | TPARAM_CHECK_INT(MAX_IDLE_TIMEOUT,
|
---|
1924 | "MAX_IDLE_TIMEOUT is malformed")
|
---|
1925 | TPARAM_CHECK_INT(MAX_UDP_PAYLOAD_SIZE,
|
---|
1926 | "MAX_UDP_PAYLOAD_SIZE is malformed")
|
---|
1927 | TPARAM_CHECK_INT(ACTIVE_CONN_ID_LIMIT,
|
---|
1928 | "ACTIVE_CONN_ID_LIMIT is malformed")
|
---|
1929 | };
|
---|
1930 |
|
---|
1931 | struct tparam_ctx {
|
---|
1932 | const struct tparam_test *t;
|
---|
1933 | };
|
---|
1934 |
|
---|
1935 | static int tparam_handle(struct tparam_ctx *ctx,
|
---|
1936 | uint64_t id, unsigned char *data,
|
---|
1937 | size_t data_len,
|
---|
1938 | WPACKET *wpkt)
|
---|
1939 | {
|
---|
1940 | const struct tparam_test *t = ctx->t;
|
---|
1941 |
|
---|
1942 | switch (t->op) {
|
---|
1943 | case TPARAM_OP_DUP:
|
---|
1944 | if (!TEST_ptr(ossl_quic_wire_encode_transport_param_bytes(wpkt, id,
|
---|
1945 | data, data_len)))
|
---|
1946 | return 0;
|
---|
1947 |
|
---|
1948 | /*
|
---|
1949 | * If this is the matching ID, write it again, duplicating the TPARAM.
|
---|
1950 | */
|
---|
1951 | if (id == t->id
|
---|
1952 | && !TEST_ptr(ossl_quic_wire_encode_transport_param_bytes(wpkt, id,
|
---|
1953 | data, data_len)))
|
---|
1954 | return 0;
|
---|
1955 |
|
---|
1956 | return 1;
|
---|
1957 |
|
---|
1958 | case TPARAM_OP_DROP:
|
---|
1959 | case TPARAM_OP_DROP_INJECT:
|
---|
1960 | /* Pass through unless ID matches. */
|
---|
1961 | if (id != t->id
|
---|
1962 | && !TEST_ptr(ossl_quic_wire_encode_transport_param_bytes(wpkt, id,
|
---|
1963 | data, data_len)))
|
---|
1964 | return 0;
|
---|
1965 |
|
---|
1966 | return 1;
|
---|
1967 |
|
---|
1968 | case TPARAM_OP_INJECT:
|
---|
1969 | case TPARAM_OP_INJECT_TWICE:
|
---|
1970 | case TPARAM_OP_INJECT_RAW:
|
---|
1971 | /* Always pass through. */
|
---|
1972 | if (!TEST_ptr(ossl_quic_wire_encode_transport_param_bytes(wpkt, id,
|
---|
1973 | data, data_len)))
|
---|
1974 | return 0;
|
---|
1975 |
|
---|
1976 | return 1;
|
---|
1977 |
|
---|
1978 | case TPARAM_OP_MUTATE:
|
---|
1979 | if (id == t->id) {
|
---|
1980 | if (!TEST_size_t_gt(data_len, 0))
|
---|
1981 | return 0;
|
---|
1982 |
|
---|
1983 | data[0] ^= 1;
|
---|
1984 | }
|
---|
1985 |
|
---|
1986 | if (!TEST_ptr(ossl_quic_wire_encode_transport_param_bytes(wpkt, id,
|
---|
1987 | data, data_len)))
|
---|
1988 | return 0;
|
---|
1989 |
|
---|
1990 | if (id == t->id)
|
---|
1991 | data[0] ^= 1;
|
---|
1992 |
|
---|
1993 | return 1;
|
---|
1994 |
|
---|
1995 | default:
|
---|
1996 | return 0;
|
---|
1997 | }
|
---|
1998 | }
|
---|
1999 |
|
---|
2000 | static int tparam_on_enc_ext(QTEST_FAULT *qtf, QTEST_ENCRYPTED_EXTENSIONS *ee,
|
---|
2001 | size_t ee_len, void *arg)
|
---|
2002 | {
|
---|
2003 | int rc = 0;
|
---|
2004 | struct tparam_ctx *ctx = arg;
|
---|
2005 | PACKET pkt = {0};
|
---|
2006 | WPACKET wpkt;
|
---|
2007 | int have_wpkt = 0;
|
---|
2008 | BUF_MEM *old_bufm = NULL, *new_bufm = NULL;
|
---|
2009 | unsigned char *tp_p;
|
---|
2010 | size_t tp_len, written, old_len, eb_len;
|
---|
2011 | uint64_t id;
|
---|
2012 |
|
---|
2013 | if (!TEST_ptr(old_bufm = BUF_MEM_new()))
|
---|
2014 | goto err;
|
---|
2015 |
|
---|
2016 | /*
|
---|
2017 | * Delete transport parameters TLS extension and capture the contents of the
|
---|
2018 | * extension which was removed.
|
---|
2019 | */
|
---|
2020 | if (!TEST_true(qtest_fault_delete_extension(qtf, TLSEXT_TYPE_quic_transport_parameters,
|
---|
2021 | ee->extensions, &ee->extensionslen,
|
---|
2022 | old_bufm)))
|
---|
2023 | goto err;
|
---|
2024 |
|
---|
2025 | if (!TEST_true(PACKET_buf_init(&pkt, (unsigned char *)old_bufm->data, old_bufm->length))
|
---|
2026 | || !TEST_ptr(new_bufm = BUF_MEM_new())
|
---|
2027 | || !TEST_true(WPACKET_init(&wpkt, new_bufm)))
|
---|
2028 | goto err;
|
---|
2029 |
|
---|
2030 | have_wpkt = 1;
|
---|
2031 |
|
---|
2032 | /*
|
---|
2033 | * Open transport parameters TLS extension:
|
---|
2034 | *
|
---|
2035 | * u16 Extension ID (quic_transport_parameters)
|
---|
2036 | * u16 Extension Data Length
|
---|
2037 | * ... Extension Data
|
---|
2038 | *
|
---|
2039 | */
|
---|
2040 | if (!TEST_true(WPACKET_put_bytes_u16(&wpkt,
|
---|
2041 | TLSEXT_TYPE_quic_transport_parameters))
|
---|
2042 | || !TEST_true(WPACKET_start_sub_packet_u16(&wpkt)))
|
---|
2043 | goto err;
|
---|
2044 |
|
---|
2045 | for (; PACKET_remaining(&pkt) > 0; ) {
|
---|
2046 | tp_p = (unsigned char *)ossl_quic_wire_decode_transport_param_bytes(&pkt,
|
---|
2047 | &id,
|
---|
2048 | &tp_len);
|
---|
2049 | if (!TEST_ptr(tp_p)) {
|
---|
2050 | TEST_mem_eq(PACKET_data(&pkt), PACKET_remaining(&pkt), NULL, 0);
|
---|
2051 | goto err;
|
---|
2052 | }
|
---|
2053 |
|
---|
2054 | if (!TEST_true(tparam_handle(ctx, id, tp_p, tp_len, &wpkt)))
|
---|
2055 | goto err;
|
---|
2056 | }
|
---|
2057 |
|
---|
2058 | if (ctx->t->op == TPARAM_OP_INJECT || ctx->t->op == TPARAM_OP_DROP_INJECT
|
---|
2059 | || ctx->t->op == TPARAM_OP_INJECT_TWICE) {
|
---|
2060 | if (!TEST_ptr(ossl_quic_wire_encode_transport_param_bytes(&wpkt, ctx->t->id,
|
---|
2061 | ctx->t->buf,
|
---|
2062 | ctx->t->buf_len)))
|
---|
2063 | goto err;
|
---|
2064 |
|
---|
2065 | if (ctx->t->op == TPARAM_OP_INJECT_TWICE
|
---|
2066 | && !TEST_ptr(ossl_quic_wire_encode_transport_param_bytes(&wpkt, ctx->t->id,
|
---|
2067 | ctx->t->buf,
|
---|
2068 | ctx->t->buf_len)))
|
---|
2069 | goto err;
|
---|
2070 | } else if (ctx->t->op == TPARAM_OP_INJECT_RAW) {
|
---|
2071 | if (!TEST_true(WPACKET_memcpy(&wpkt, ctx->t->buf, ctx->t->buf_len)))
|
---|
2072 | goto err;
|
---|
2073 | }
|
---|
2074 |
|
---|
2075 | if (!TEST_true(WPACKET_close(&wpkt))) /* end extension data, set length */
|
---|
2076 | goto err;
|
---|
2077 |
|
---|
2078 | if (!TEST_true(WPACKET_get_total_written(&wpkt, &written)))
|
---|
2079 | goto err;
|
---|
2080 |
|
---|
2081 | WPACKET_finish(&wpkt);
|
---|
2082 | have_wpkt = 0;
|
---|
2083 |
|
---|
2084 | /*
|
---|
2085 | * Append the constructed extension blob to the extension block.
|
---|
2086 | */
|
---|
2087 | old_len = ee->extensionslen;
|
---|
2088 |
|
---|
2089 | if (!qtest_fault_resize_message(qtf, ee->extensionslen + written))
|
---|
2090 | goto err;
|
---|
2091 |
|
---|
2092 | memcpy(ee->extensions + old_len, new_bufm->data, written);
|
---|
2093 |
|
---|
2094 | /* Fixup the extension block header (u16 length of entire block). */
|
---|
2095 | eb_len = (((uint16_t)ee->extensions[0]) << 8) + (uint16_t)ee->extensions[1];
|
---|
2096 | eb_len += written;
|
---|
2097 | ee->extensions[0] = (unsigned char)((eb_len >> 8) & 0xFF);
|
---|
2098 | ee->extensions[1] = (unsigned char)( eb_len & 0xFF);
|
---|
2099 |
|
---|
2100 | rc = 1;
|
---|
2101 | err:
|
---|
2102 | if (have_wpkt)
|
---|
2103 | WPACKET_cleanup(&wpkt);
|
---|
2104 | BUF_MEM_free(old_bufm);
|
---|
2105 | BUF_MEM_free(new_bufm);
|
---|
2106 | return rc;
|
---|
2107 | }
|
---|
2108 |
|
---|
2109 | static int test_tparam(int idx)
|
---|
2110 | {
|
---|
2111 | int testresult = 0;
|
---|
2112 | SSL_CTX *c_ctx = NULL;
|
---|
2113 | SSL *c_ssl = NULL;
|
---|
2114 | QUIC_TSERVER *s = NULL;
|
---|
2115 | QTEST_FAULT *qtf = NULL;
|
---|
2116 | struct tparam_ctx ctx = {0};
|
---|
2117 |
|
---|
2118 | ctx.t = &tparam_tests[idx];
|
---|
2119 |
|
---|
2120 | if (!TEST_ptr(c_ctx = SSL_CTX_new_ex(libctx, NULL, OSSL_QUIC_client_method())))
|
---|
2121 | goto err;
|
---|
2122 |
|
---|
2123 | if (!TEST_true(qtest_create_quic_objects(libctx, c_ctx, NULL, cert,
|
---|
2124 | privkey, 0, &s,
|
---|
2125 | &c_ssl, &qtf, NULL)))
|
---|
2126 | goto err;
|
---|
2127 |
|
---|
2128 | if (!TEST_true(qtest_fault_set_hand_enc_ext_listener(qtf, tparam_on_enc_ext,
|
---|
2129 | &ctx)))
|
---|
2130 | goto err;
|
---|
2131 |
|
---|
2132 | if (!TEST_true(qtest_create_quic_connection_ex(s, c_ssl,
|
---|
2133 | ctx.t->expect_fail != NULL)))
|
---|
2134 | goto err;
|
---|
2135 |
|
---|
2136 | if (ctx.t->expect_fail != NULL) {
|
---|
2137 | SSL_CONN_CLOSE_INFO info = {0};
|
---|
2138 |
|
---|
2139 | if (!TEST_true(SSL_get_conn_close_info(c_ssl, &info, sizeof(info))))
|
---|
2140 | goto err;
|
---|
2141 |
|
---|
2142 | if (!TEST_true((info.flags & SSL_CONN_CLOSE_FLAG_TRANSPORT) != 0)
|
---|
2143 | || !TEST_uint64_t_eq(info.error_code, OSSL_QUIC_ERR_TRANSPORT_PARAMETER_ERROR)
|
---|
2144 | || !TEST_ptr(strstr(info.reason, ctx.t->expect_fail))) {
|
---|
2145 | TEST_error("expected connection closure information mismatch"
|
---|
2146 | " during TPARAM test: flags=%llu ec=%llu reason='%s'",
|
---|
2147 | (unsigned long long)info.flags,
|
---|
2148 | (unsigned long long)info.error_code,
|
---|
2149 | info.reason);
|
---|
2150 | goto err;
|
---|
2151 | }
|
---|
2152 | }
|
---|
2153 |
|
---|
2154 | testresult = 1;
|
---|
2155 | err:
|
---|
2156 | if (!testresult) {
|
---|
2157 | if (ctx.t->expect_fail != NULL)
|
---|
2158 | TEST_info("failed during test for id=%llu, op=%d, bl=%zu, "
|
---|
2159 | "expected failure='%s'", (unsigned long long)ctx.t->id,
|
---|
2160 | ctx.t->op, ctx.t->buf_len, ctx.t->expect_fail);
|
---|
2161 | else
|
---|
2162 | TEST_info("failed during test for id=%llu, op=%d, bl=%zu",
|
---|
2163 | (unsigned long long)ctx.t->id, ctx.t->op, ctx.t->buf_len);
|
---|
2164 | }
|
---|
2165 |
|
---|
2166 | ossl_quic_tserver_free(s);
|
---|
2167 | SSL_free(c_ssl);
|
---|
2168 | SSL_CTX_free(c_ctx);
|
---|
2169 | qtest_fault_free(qtf);
|
---|
2170 | return testresult;
|
---|
2171 | }
|
---|
2172 | /***********************************************************************************/
|
---|
2173 |
|
---|
2174 | OPT_TEST_DECLARE_USAGE("provider config certsdir datadir\n")
|
---|
2175 |
|
---|
2176 | int setup_tests(void)
|
---|
2177 | {
|
---|
2178 | char *modulename;
|
---|
2179 | char *configfile;
|
---|
2180 |
|
---|
2181 | libctx = OSSL_LIB_CTX_new();
|
---|
2182 | if (!TEST_ptr(libctx))
|
---|
2183 | return 0;
|
---|
2184 |
|
---|
2185 | defctxnull = OSSL_PROVIDER_load(NULL, "null");
|
---|
2186 |
|
---|
2187 | /*
|
---|
2188 | * Verify that the default and fips providers in the default libctx are not
|
---|
2189 | * available
|
---|
2190 | */
|
---|
2191 | if (!TEST_false(OSSL_PROVIDER_available(NULL, "default"))
|
---|
2192 | || !TEST_false(OSSL_PROVIDER_available(NULL, "fips")))
|
---|
2193 | goto err;
|
---|
2194 |
|
---|
2195 | if (!test_skip_common_options()) {
|
---|
2196 | TEST_error("Error parsing test options\n");
|
---|
2197 | goto err;
|
---|
2198 | }
|
---|
2199 |
|
---|
2200 | if (!TEST_ptr(modulename = test_get_argument(0))
|
---|
2201 | || !TEST_ptr(configfile = test_get_argument(1))
|
---|
2202 | || !TEST_ptr(certsdir = test_get_argument(2))
|
---|
2203 | || !TEST_ptr(datadir = test_get_argument(3)))
|
---|
2204 | goto err;
|
---|
2205 |
|
---|
2206 | if (!TEST_true(OSSL_LIB_CTX_load_config(libctx, configfile)))
|
---|
2207 | goto err;
|
---|
2208 |
|
---|
2209 | /* Check we have the expected provider available */
|
---|
2210 | if (!TEST_true(OSSL_PROVIDER_available(libctx, modulename)))
|
---|
2211 | goto err;
|
---|
2212 |
|
---|
2213 | /* Check the default provider is not available */
|
---|
2214 | if (strcmp(modulename, "default") != 0
|
---|
2215 | && !TEST_false(OSSL_PROVIDER_available(libctx, "default")))
|
---|
2216 | goto err;
|
---|
2217 |
|
---|
2218 | if (strcmp(modulename, "fips") == 0)
|
---|
2219 | is_fips = 1;
|
---|
2220 |
|
---|
2221 | cert = test_mk_file_path(certsdir, "servercert.pem");
|
---|
2222 | if (cert == NULL)
|
---|
2223 | goto err;
|
---|
2224 |
|
---|
2225 | ccert = test_mk_file_path(certsdir, "ee-client-chain.pem");
|
---|
2226 | if (ccert == NULL)
|
---|
2227 | goto err;
|
---|
2228 |
|
---|
2229 | cauthca = test_mk_file_path(certsdir, "root-cert.pem");
|
---|
2230 | if (cauthca == NULL)
|
---|
2231 | goto err;
|
---|
2232 |
|
---|
2233 | privkey = test_mk_file_path(certsdir, "serverkey.pem");
|
---|
2234 | if (privkey == NULL)
|
---|
2235 | goto err;
|
---|
2236 |
|
---|
2237 | cprivkey = test_mk_file_path(certsdir, "ee-key.pem");
|
---|
2238 | if (privkey == NULL)
|
---|
2239 | goto err;
|
---|
2240 |
|
---|
2241 | ADD_ALL_TESTS(test_quic_write_read, 3);
|
---|
2242 | ADD_TEST(test_fin_only_blocking);
|
---|
2243 | ADD_TEST(test_ciphersuites);
|
---|
2244 | ADD_TEST(test_cipher_find);
|
---|
2245 | ADD_TEST(test_version);
|
---|
2246 | #if defined(DO_SSL_TRACE_TEST)
|
---|
2247 | ADD_TEST(test_ssl_trace);
|
---|
2248 | #endif
|
---|
2249 | ADD_TEST(test_quic_forbidden_apis_ctx);
|
---|
2250 | ADD_TEST(test_quic_forbidden_apis);
|
---|
2251 | ADD_TEST(test_quic_forbidden_options);
|
---|
2252 | ADD_ALL_TESTS(test_quic_set_fd, 3);
|
---|
2253 | ADD_TEST(test_bio_ssl);
|
---|
2254 | ADD_TEST(test_back_pressure);
|
---|
2255 | ADD_TEST(test_multiple_dgrams);
|
---|
2256 | ADD_ALL_TESTS(test_non_io_retry, 2);
|
---|
2257 | ADD_TEST(test_quic_psk);
|
---|
2258 | ADD_ALL_TESTS(test_client_auth, 3);
|
---|
2259 | ADD_ALL_TESTS(test_alpn, 2);
|
---|
2260 | ADD_ALL_TESTS(test_noisy_dgram, 2);
|
---|
2261 | ADD_TEST(test_bw_limit);
|
---|
2262 | ADD_TEST(test_get_shutdown);
|
---|
2263 | ADD_ALL_TESTS(test_tparam, OSSL_NELEM(tparam_tests));
|
---|
2264 |
|
---|
2265 | return 1;
|
---|
2266 | err:
|
---|
2267 | cleanup_tests();
|
---|
2268 | return 0;
|
---|
2269 | }
|
---|
2270 |
|
---|
2271 | void cleanup_tests(void)
|
---|
2272 | {
|
---|
2273 | bio_f_noisy_dgram_filter_free();
|
---|
2274 | bio_f_pkt_split_dgram_filter_free();
|
---|
2275 | OPENSSL_free(cert);
|
---|
2276 | OPENSSL_free(privkey);
|
---|
2277 | OPENSSL_free(ccert);
|
---|
2278 | OPENSSL_free(cauthca);
|
---|
2279 | OPENSSL_free(cprivkey);
|
---|
2280 | OSSL_PROVIDER_unload(defctxnull);
|
---|
2281 | OSSL_LIB_CTX_free(libctx);
|
---|
2282 | }
|
---|