2 * Copyright 2023 The OpenSSL Project Authors. All Rights Reserved.
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
9 #include <openssl/ssl.h>
10 #include <openssl/quic.h>
11 #include <openssl/bio.h>
12 #include <openssl/lhash.h>
13 #include "internal/quic_tserver.h"
14 #include "internal/quic_ssl.h"
15 #include "internal/quic_error.h"
17 #include "helpers/quictestlib.h"
18 #if defined(OPENSSL_THREADS)
19 # include "internal/thread_arch.h"
22 static const char *certfile, *keyfile;
24 #if defined(OPENSSL_THREADS)
25 struct child_thread_args {
27 const struct script_op *script;
28 const char *script_name;
38 typedef struct stream_info {
44 DEFINE_LHASH_OF_EX(STREAM_INFO);
48 BIO *s_net_bio, *s_net_bio_own, *s_qtf_wbio, *s_qtf_wbio_own;
49 BIO_ADDR *s_net_bio_addr;
51 LHASH_OF(STREAM_INFO) *s_streams;
54 BIO *c_net_bio, *c_net_bio_own;
57 LHASH_OF(STREAM_INFO) *c_streams;
59 #if defined(OPENSSL_THREADS)
60 struct child_thread_args *threads;
67 * This is a duration recording the amount of time we have skipped forwards
68 * for testing purposes relative to the real ossl_time_now() clock. We add
69 * a quantity of time to this every time we skip some time.
71 CRYPTO_RWLOCK *time_lock;
72 OSSL_TIME time_slip; /* protected by time_lock */
76 int init, blocking, check_spin_again;
77 int free_order, need_injector;
79 int (*qtf_packet_plain_cb)(struct helper *h, QUIC_PKT_HDR *hdr,
80 unsigned char *buf, size_t buf_len);
81 uint64_t inject_word0, inject_word1;
82 uint64_t scratch0, scratch1;
87 LHASH_OF(STREAM_INFO) *c_streams;
95 int (*check_func)(struct helper *h, const struct script_op *op);
96 const char *stream_name;
98 int (*qtf_packet_plain_cb)(struct helper *h, QUIC_PKT_HDR *hdr,
99 unsigned char *buf, size_t buf_len);
104 #define OPK_C_SET_ALPN 2
105 #define OPK_C_CONNECT_WAIT 3
106 #define OPK_C_WRITE 4
107 #define OPK_S_WRITE 5
108 #define OPK_C_READ_EXPECT 6
109 #define OPK_S_READ_EXPECT 7
110 #define OPK_C_EXPECT_FIN 8
111 #define OPK_S_EXPECT_FIN 9
112 #define OPK_C_CONCLUDE 10
113 #define OPK_S_CONCLUDE 11
114 #define OPK_C_DETACH 12
115 #define OPK_C_ATTACH 13
116 #define OPK_C_NEW_STREAM 14
117 #define OPK_S_NEW_STREAM 15
118 #define OPK_C_ACCEPT_STREAM_WAIT 16
119 #define OPK_C_ACCEPT_STREAM_NONE 17
120 #define OPK_C_FREE_STREAM 18
121 #define OPK_C_SET_DEFAULT_STREAM_MODE 19
122 #define OPK_C_SET_INCOMING_STREAM_POLICY 20
123 #define OPK_C_SHUTDOWN_WAIT 21
124 #define OPK_C_EXPECT_CONN_CLOSE_INFO 22
125 #define OPK_S_EXPECT_CONN_CLOSE_INFO 23
126 #define OPK_S_BIND_STREAM_ID 24
127 #define OPK_C_WAIT_FOR_DATA 25
128 #define OPK_C_WRITE_FAIL 26
129 #define OPK_S_WRITE_FAIL 27
130 #define OPK_C_READ_FAIL 28
131 #define OPK_C_STREAM_RESET 29
132 #define OPK_S_ACCEPT_STREAM_WAIT 30
133 #define OPK_NEW_THREAD 31
134 #define OPK_BEGIN_REPEAT 32
135 #define OPK_END_REPEAT 33
136 #define OPK_S_UNBIND_STREAM_ID 34
137 #define OPK_C_READ_FAIL_WAIT 35
138 #define OPK_C_CLOSE_SOCKET 36
139 #define OPK_C_EXPECT_SSL_ERR 37
140 #define OPK_EXPECT_ERR_REASON 38
141 #define OPK_EXPECT_ERR_LIB 39
143 #define OPK_S_READ_FAIL 41
144 #define OPK_S_SET_INJECT_PLAIN 42
145 #define OPK_SET_INJECT_WORD 43
146 #define OPK_C_INHIBIT_TICK 44
147 #define OPK_C_SET_WRITE_BUF_SIZE 45
149 #define EXPECT_CONN_CLOSE_APP (1U << 0)
150 #define EXPECT_CONN_CLOSE_REMOTE (1U << 1)
152 #define C_BIDI_ID(ordinal) \
153 (((ordinal) << 2) | QUIC_STREAM_INITIATOR_CLIENT | QUIC_STREAM_DIR_BIDI)
154 #define S_BIDI_ID(ordinal) \
155 (((ordinal) << 2) | QUIC_STREAM_INITIATOR_SERVER | QUIC_STREAM_DIR_BIDI)
156 #define C_UNI_ID(ordinal) \
157 (((ordinal) << 2) | QUIC_STREAM_INITIATOR_CLIENT | QUIC_STREAM_DIR_UNI)
158 #define S_UNI_ID(ordinal) \
159 (((ordinal) << 2) | QUIC_STREAM_INITIATOR_SERVER | QUIC_STREAM_DIR_UNI)
161 #define ANY_ID UINT64_MAX
165 #define OP_CHECK(func, arg2) \
166 {OPK_CHECK, NULL, 0, (func), NULL, (arg2)},
167 #define OP_C_SET_ALPN(alpn) \
168 {OPK_C_SET_ALPN, (alpn), 0, NULL, NULL},
169 #define OP_C_CONNECT_WAIT() \
170 {OPK_C_CONNECT_WAIT, NULL, 0, NULL, NULL},
171 #define OP_C_CONNECT_WAIT_OR_FAIL() \
172 {OPK_C_CONNECT_WAIT, NULL, 1, NULL, NULL},
173 #define OP_C_WRITE(stream_name, buf, buf_len) \
174 {OPK_C_WRITE, (buf), (buf_len), NULL, #stream_name},
175 #define OP_S_WRITE(stream_name, buf, buf_len) \
176 {OPK_S_WRITE, (buf), (buf_len), NULL, #stream_name},
177 #define OP_C_READ_EXPECT(stream_name, buf, buf_len) \
178 {OPK_C_READ_EXPECT, (buf), (buf_len), NULL, #stream_name},
179 #define OP_S_READ_EXPECT(stream_name, buf, buf_len) \
180 {OPK_S_READ_EXPECT, (buf), (buf_len), NULL, #stream_name},
181 #define OP_C_EXPECT_FIN(stream_name) \
182 {OPK_C_EXPECT_FIN, NULL, 0, NULL, #stream_name},
183 #define OP_S_EXPECT_FIN(stream_name) \
184 {OPK_S_EXPECT_FIN, NULL, 0, NULL, #stream_name},
185 #define OP_C_CONCLUDE(stream_name) \
186 {OPK_C_CONCLUDE, NULL, 0, NULL, #stream_name},
187 #define OP_S_CONCLUDE(stream_name) \
188 {OPK_S_CONCLUDE, NULL, 0, NULL, #stream_name},
189 #define OP_C_DETACH(stream_name) \
190 {OPK_C_DETACH, NULL, 0, NULL, #stream_name},
191 #define OP_C_ATTACH(stream_name) \
192 {OPK_C_ATTACH, NULL, 0, NULL, #stream_name},
193 #define OP_C_NEW_STREAM_BIDI(stream_name, expect_id) \
194 {OPK_C_NEW_STREAM, NULL, 0, NULL, #stream_name, (expect_id)},
195 #define OP_C_NEW_STREAM_UNI(stream_name, expect_id) \
196 {OPK_C_NEW_STREAM, NULL, 1, NULL, #stream_name, (expect_id)},
197 #define OP_S_NEW_STREAM_BIDI(stream_name, expect_id) \
198 {OPK_S_NEW_STREAM, NULL, 0, NULL, #stream_name, (expect_id)},
199 #define OP_S_NEW_STREAM_UNI(stream_name, expect_id) \
200 {OPK_S_NEW_STREAM, NULL, 1, NULL, #stream_name, (expect_id)},
201 #define OP_C_ACCEPT_STREAM_WAIT(stream_name) \
202 {OPK_C_ACCEPT_STREAM_WAIT, NULL, 0, NULL, #stream_name},
203 #define OP_C_ACCEPT_STREAM_NONE() \
204 {OPK_C_ACCEPT_STREAM_NONE, NULL, 0, NULL, NULL},
205 #define OP_C_FREE_STREAM(stream_name) \
206 {OPK_C_FREE_STREAM, NULL, 0, NULL, #stream_name},
207 #define OP_C_SET_DEFAULT_STREAM_MODE(mode) \
208 {OPK_C_SET_DEFAULT_STREAM_MODE, NULL, (mode), NULL, NULL},
209 #define OP_C_SET_INCOMING_STREAM_POLICY(policy) \
210 {OPK_C_SET_INCOMING_STREAM_POLICY, NULL, (policy), NULL, NULL},
211 #define OP_C_SHUTDOWN_WAIT() \
212 {OPK_C_SHUTDOWN_WAIT, NULL, 0, NULL, NULL},
213 #define OP_C_EXPECT_CONN_CLOSE_INFO(ec, app, remote) \
214 {OPK_C_EXPECT_CONN_CLOSE_INFO, NULL, \
215 ((app) ? EXPECT_CONN_CLOSE_APP : 0) | \
216 ((remote) ? EXPECT_CONN_CLOSE_REMOTE : 0), \
218 #define OP_S_EXPECT_CONN_CLOSE_INFO(ec, app, remote) \
219 {OPK_S_EXPECT_CONN_CLOSE_INFO, NULL, \
220 ((app) ? EXPECT_CONN_CLOSE_APP : 0) | \
221 ((remote) ? EXPECT_CONN_CLOSE_REMOTE : 0), \
223 #define OP_S_BIND_STREAM_ID(stream_name, stream_id) \
224 {OPK_S_BIND_STREAM_ID, NULL, 0, NULL, #stream_name, (stream_id)},
225 #define OP_C_WAIT_FOR_DATA(stream_name) \
226 {OPK_C_WAIT_FOR_DATA, NULL, 0, NULL, #stream_name},
227 #define OP_C_WRITE_FAIL(stream_name) \
228 {OPK_C_WRITE_FAIL, NULL, 0, NULL, #stream_name},
229 #define OP_S_WRITE_FAIL(stream_name) \
230 {OPK_S_WRITE_FAIL, NULL, 0, NULL, #stream_name},
231 #define OP_C_READ_FAIL(stream_name) \
232 {OPK_C_READ_FAIL, NULL, 0, NULL, #stream_name},
233 #define OP_S_READ_FAIL(stream_name) \
234 {OPK_S_READ_FAIL, NULL, 0, NULL, #stream_name},
235 #define OP_C_STREAM_RESET(stream_name, aec) \
236 {OPK_C_STREAM_RESET, NULL, 0, NULL, #stream_name, (aec)},
237 #define OP_S_ACCEPT_STREAM_WAIT(stream_name) \
238 {OPK_S_ACCEPT_STREAM_WAIT, NULL, 0, NULL, #stream_name},
239 #define OP_NEW_THREAD(num_threads, script) \
240 {OPK_NEW_THREAD, (script), (num_threads), NULL, NULL, 0 },
241 #define OP_BEGIN_REPEAT(n) \
242 {OPK_BEGIN_REPEAT, NULL, (n)},
243 #define OP_END_REPEAT() \
245 #define OP_S_UNBIND_STREAM_ID(stream_name) \
246 {OPK_S_UNBIND_STREAM_ID, NULL, 0, NULL, #stream_name},
247 #define OP_C_READ_FAIL_WAIT(stream_name) \
248 {OPK_C_READ_FAIL_WAIT, NULL, 0, NULL, #stream_name},
249 #define OP_C_CLOSE_SOCKET() \
250 {OPK_C_CLOSE_SOCKET},
251 #define OP_C_EXPECT_SSL_ERR(stream_name, err) \
252 {OPK_C_EXPECT_SSL_ERR, NULL, (err), NULL, #stream_name},
253 #define OP_EXPECT_ERR_REASON(err) \
254 {OPK_EXPECT_ERR_REASON, NULL, (err)},
255 #define OP_EXPECT_ERR_LIB(lib) \
256 {OPK_EXPECT_ERR_LIB, NULL, (lib)},
257 #define OP_SLEEP(ms) \
258 {OPK_SLEEP, NULL, 0, NULL, NULL, (ms)},
259 #define OP_S_SET_INJECT_PLAIN(f) \
260 {OPK_S_SET_INJECT_PLAIN, NULL, 0, NULL, NULL, 0, (f)},
261 #define OP_SET_INJECT_WORD(w0, w1) \
262 {OPK_SET_INJECT_WORD, NULL, (w0), NULL, NULL, (w1), NULL},
263 #define OP_C_INHIBIT_TICK(inhibit) \
264 {OPK_C_INHIBIT_TICK, NULL, (inhibit), NULL, NULL, 0, NULL},
265 #define OP_C_SET_WRITE_BUF_SIZE(stream_name, size) \
266 {OPK_C_SET_WRITE_BUF_SIZE, NULL, (size), NULL, #stream_name},
268 static OSSL_TIME get_time(void *arg)
270 struct helper *h = arg;
273 if (!TEST_true(CRYPTO_THREAD_read_lock(h->time_lock)))
274 return ossl_time_zero();
276 t = ossl_time_add(ossl_time_now(), h->time_slip);
278 CRYPTO_THREAD_unlock(h->time_lock);
282 static int skip_time_ms(struct helper *h, const struct script_op *op)
284 if (!TEST_true(CRYPTO_THREAD_write_lock(h->time_lock)))
287 h->time_slip = ossl_time_add(h->time_slip, ossl_ms2time(op->arg2));
289 CRYPTO_THREAD_unlock(h->time_lock);
293 static int check_rejected(struct helper *h, const struct script_op *op)
295 uint64_t stream_id = op->arg2;
297 if (!ossl_quic_tserver_stream_has_peer_stop_sending(h->s, stream_id, NULL)
298 || !ossl_quic_tserver_stream_has_peer_reset_stream(h->s, stream_id, NULL)) {
299 h->check_spin_again = 1;
306 static int check_stream_reset(struct helper *h, const struct script_op *op)
308 uint64_t stream_id = op->arg2, aec = 0;
310 if (!ossl_quic_tserver_stream_has_peer_reset_stream(h->s, stream_id, &aec)) {
311 h->check_spin_again = 1;
315 return TEST_uint64_t_eq(aec, 42);
318 static int check_stream_stopped(struct helper *h, const struct script_op *op)
320 uint64_t stream_id = op->arg2;
322 if (!ossl_quic_tserver_stream_has_peer_stop_sending(h->s, stream_id, NULL)) {
323 h->check_spin_again = 1;
330 static int override_key_update(struct helper *h, const struct script_op *op)
332 QUIC_CHANNEL *ch = ossl_quic_conn_get_channel(h->c_conn);
334 ossl_quic_channel_set_txku_threshold_override(ch, op->arg2);
338 static int trigger_key_update(struct helper *h, const struct script_op *op)
340 if (!TEST_true(SSL_key_update(h->c_conn, SSL_KEY_UPDATE_REQUESTED)))
346 static int check_key_update_ge(struct helper *h, const struct script_op *op)
348 QUIC_CHANNEL *ch = ossl_quic_conn_get_channel(h->c_conn);
349 int64_t txke = (int64_t)ossl_quic_channel_get_tx_key_epoch(ch);
350 int64_t rxke = (int64_t)ossl_quic_channel_get_rx_key_epoch(ch);
351 int64_t diff = txke - rxke;
354 * TXKE must always be equal to or ahead of RXKE.
355 * It can be ahead of RXKE by at most 1.
357 if (!TEST_int64_t_ge(diff, 0) || !TEST_int64_t_le(diff, 1))
360 /* Caller specifies a minimum number of RXKEs which must have happened. */
361 if (!TEST_uint64_t_ge((uint64_t)rxke, op->arg2))
367 static int check_key_update_lt(struct helper *h, const struct script_op *op)
369 QUIC_CHANNEL *ch = ossl_quic_conn_get_channel(h->c_conn);
370 uint64_t txke = ossl_quic_channel_get_tx_key_epoch(ch);
372 /* Caller specifies a maximum number of TXKEs which must have happened. */
373 if (!TEST_uint64_t_lt(txke, op->arg2))
379 static unsigned long stream_info_hash(const STREAM_INFO *info)
381 return OPENSSL_LH_strhash(info->name);
384 static int stream_info_cmp(const STREAM_INFO *a, const STREAM_INFO *b)
386 return strcmp(a->name, b->name);
389 static void cleanup_stream(STREAM_INFO *info)
391 SSL_free(info->c_stream);
395 static void helper_cleanup_streams(LHASH_OF(STREAM_INFO) **lh)
400 lh_STREAM_INFO_doall(*lh, cleanup_stream);
401 lh_STREAM_INFO_free(*lh);
405 #if defined(OPENSSL_THREADS)
406 static CRYPTO_THREAD_RETVAL run_script_child_thread(void *arg);
408 static int join_threads(struct child_thread_args *threads, size_t num_threads)
412 CRYPTO_THREAD_RETVAL rv;
414 for (i = 0; i < num_threads; ++i) {
415 if (threads[i].t != NULL) {
416 ossl_crypto_thread_native_join(threads[i].t, &rv);
418 if (!threads[i].testresult)
419 /* Do not log failure here, worker will do it. */
422 ossl_crypto_thread_native_clean(threads[i].t);
426 ossl_crypto_mutex_free(&threads[i].m);
433 static void helper_cleanup(struct helper *h)
435 #if defined(OPENSSL_THREADS)
436 join_threads(h->threads, h->num_threads);
437 OPENSSL_free(h->threads);
442 if (h->free_order == 0) {
443 /* order 0: streams, then conn */
444 helper_cleanup_streams(&h->c_streams);
449 /* order 1: conn, then streams */
453 helper_cleanup_streams(&h->c_streams);
456 helper_cleanup_streams(&h->s_streams);
457 ossl_quic_tserver_free(h->s);
460 BIO_free(h->s_net_bio_own);
461 h->s_net_bio_own = NULL;
463 BIO_free(h->c_net_bio_own);
464 h->c_net_bio_own = NULL;
466 BIO_free(h->s_qtf_wbio_own);
467 h->s_qtf_wbio_own = NULL;
469 qtest_fault_free(h->qtf);
473 BIO_closesocket(h->s_fd);
478 BIO_closesocket(h->c_fd);
482 BIO_ADDR_free(h->s_net_bio_addr);
483 h->s_net_bio_addr = NULL;
485 SSL_CTX_free(h->c_ctx);
488 CRYPTO_THREAD_lock_free(h->time_lock);
492 static int helper_init(struct helper *h, int free_order, int need_injector)
495 struct in_addr ina = {0};
496 QUIC_TSERVER_ARGS s_args = {0};
498 memset(h, 0, sizeof(*h));
501 h->free_order = free_order;
502 h->need_injector = need_injector;
503 h->time_slip = ossl_time_zero();
505 if (!TEST_ptr(h->time_lock = CRYPTO_THREAD_lock_new()))
508 if (!TEST_ptr(h->s_streams = lh_STREAM_INFO_new(stream_info_hash,
512 if (!TEST_ptr(h->c_streams = lh_STREAM_INFO_new(stream_info_hash,
516 ina.s_addr = htonl(0x7f000001UL);
518 h->s_fd = BIO_socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP, 0);
519 if (!TEST_int_ge(h->s_fd, 0))
522 if (!TEST_true(BIO_socket_nbio(h->s_fd, 1)))
525 if (!TEST_ptr(h->s_net_bio_addr = BIO_ADDR_new()))
528 if (!TEST_true(BIO_ADDR_rawmake(h->s_net_bio_addr, AF_INET, &ina, sizeof(ina),
532 if (!TEST_true(BIO_bind(h->s_fd, h->s_net_bio_addr, 0)))
535 if (!TEST_int_gt(BIO_ADDR_rawport(h->s_net_bio_addr), 0))
538 if (!TEST_ptr(h->s_net_bio = h->s_net_bio_own = BIO_new_dgram(h->s_fd, 0)))
541 if (!BIO_up_ref(h->s_net_bio))
545 h->s_qtf_wbio = h->s_qtf_wbio_own = BIO_new(qtest_get_bio_method());
546 if (!TEST_ptr(h->s_qtf_wbio))
549 if (!TEST_ptr(BIO_push(h->s_qtf_wbio, h->s_net_bio)))
552 s_args.net_wbio = h->s_qtf_wbio;
554 s_args.net_wbio = h->s_net_bio;
557 s_args.net_rbio = h->s_net_bio;
559 s_args.now_cb = get_time;
560 s_args.now_cb_arg = h;
563 if (!TEST_ptr(h->s = ossl_quic_tserver_new(&s_args, certfile, keyfile)))
567 h->qtf = qtest_create_injector(h->s);
568 if (!TEST_ptr(h->qtf))
571 BIO_set_data(h->s_qtf_wbio, h->qtf);
575 h->s_net_bio_own = NULL;
577 h->s_qtf_wbio_own = NULL;
579 h->c_fd = BIO_socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP, 0);
580 if (!TEST_int_ge(h->c_fd, 0))
583 if (!TEST_true(BIO_socket_nbio(h->c_fd, 1)))
586 if (!TEST_ptr(h->c_net_bio = h->c_net_bio_own = BIO_new_dgram(h->c_fd, 0)))
589 if (!TEST_true(BIO_dgram_set_peer(h->c_net_bio, h->s_net_bio_addr)))
592 if (!TEST_ptr(h->c_ctx = SSL_CTX_new(OSSL_QUIC_client_method())))
595 if (!TEST_ptr(h->c_conn = SSL_new(h->c_ctx)))
598 /* Use custom time function for virtual time skip. */
599 if (!TEST_true(ossl_quic_conn_set_override_now_cb(h->c_conn, get_time, h)))
602 /* Takes ownership of our reference to the BIO. */
603 SSL_set0_rbio(h->c_conn, h->c_net_bio);
604 h->c_net_bio_own = NULL;
606 if (!TEST_true(BIO_up_ref(h->c_net_bio)))
609 SSL_set0_wbio(h->c_conn, h->c_net_bio);
611 if (!TEST_true(SSL_set_blocking_mode(h->c_conn, 0)))
614 h->start_time = ossl_time_now();
623 static int helper_local_init(struct helper_local *hl, struct helper *h,
627 hl->c_streams = NULL;
628 hl->thread_idx = thread_idx;
633 if (thread_idx < 0) {
634 hl->c_streams = h->c_streams;
636 if (!TEST_ptr(hl->c_streams = lh_STREAM_INFO_new(stream_info_hash,
644 static void helper_local_cleanup(struct helper_local *hl)
649 if (hl->thread_idx >= 0)
650 helper_cleanup_streams(&hl->c_streams);
655 static STREAM_INFO *get_stream_info(LHASH_OF(STREAM_INFO) *lh,
656 const char *stream_name)
658 STREAM_INFO key, *info;
660 if (!TEST_ptr(stream_name))
663 if (!strcmp(stream_name, "DEFAULT"))
666 key.name = stream_name;
667 info = lh_STREAM_INFO_retrieve(lh, &key);
669 info = OPENSSL_zalloc(sizeof(*info));
673 info->name = stream_name;
674 info->s_stream_id = UINT64_MAX;
675 lh_STREAM_INFO_insert(lh, info);
681 static int helper_local_set_c_stream(struct helper_local *hl,
682 const char *stream_name,
685 STREAM_INFO *info = get_stream_info(hl->c_streams, stream_name);
690 info->c_stream = c_stream;
691 info->s_stream_id = UINT64_MAX;
695 static SSL *helper_local_get_c_stream(struct helper_local *hl,
696 const char *stream_name)
700 if (!strcmp(stream_name, "DEFAULT"))
701 return hl->h->c_conn;
703 info = get_stream_info(hl->c_streams, stream_name);
707 return info->c_stream;
711 helper_set_s_stream(struct helper *h, const char *stream_name,
712 uint64_t s_stream_id)
716 if (!strcmp(stream_name, "DEFAULT"))
719 info = get_stream_info(h->s_streams, stream_name);
723 info->c_stream = NULL;
724 info->s_stream_id = s_stream_id;
728 static uint64_t helper_get_s_stream(struct helper *h, const char *stream_name)
732 if (!strcmp(stream_name, "DEFAULT"))
735 info = get_stream_info(h->s_streams, stream_name);
739 return info->s_stream_id;
742 static int helper_packet_plain_listener(QTEST_FAULT *qtf, QUIC_PKT_HDR *hdr,
743 unsigned char *buf, size_t buf_len,
746 struct helper *h = arg;
748 return h->qtf_packet_plain_cb(h, hdr, buf, buf_len);
751 static int is_want(SSL *s, int ret)
753 int ec = SSL_get_error(s, ret);
755 return ec == SSL_ERROR_WANT_READ || ec == SSL_ERROR_WANT_WRITE;
758 static int run_script_worker(struct helper *h, const struct script_op *script,
759 const char *script_name,
763 unsigned char *tmp_buf = NULL;
764 int connect_started = 0;
767 const struct script_op *op = NULL;
768 int no_advance = 0, first = 1;
769 #if defined(OPENSSL_THREADS)
770 int end_wait_warning = 0;
772 OSSL_TIME op_start_time = ossl_time_zero(), op_deadline = ossl_time_zero();
773 struct helper_local hl;
774 #define REPEAT_SLOTS 8
775 size_t repeat_stack_idx[REPEAT_SLOTS], repeat_stack_done[REPEAT_SLOTS];
776 size_t repeat_stack_limit[REPEAT_SLOTS];
777 size_t repeat_stack_len = 0;
779 if (!TEST_true(helper_local_init(&hl, h, thread_idx)))
782 #define SPIN_AGAIN() { OSSL_sleep(1); no_advance = 1; continue; }
785 SSL *c_tgt = h->c_conn;
786 uint64_t s_stream_id = UINT64_MAX;
796 op_start_time = ossl_time_now();
797 op_deadline = ossl_time_add(op_start_time, ossl_ms2time(8000));
800 if (!TEST_int_le(ossl_time_compare(ossl_time_now(), op_deadline), 0)) {
801 TEST_error("op %zu timed out on thread %d", op_idx + 1, thread_idx);
805 op = &script[op_idx];
807 if (op->stream_name != NULL) {
808 c_tgt = helper_local_get_c_stream(&hl, op->stream_name);
810 s_stream_id = helper_get_s_stream(h, op->stream_name);
812 s_stream_id = UINT64_MAX;
816 ossl_quic_tserver_tick(h->s);
818 if (thread_idx >= 0 || connect_started)
819 SSL_handle_events(h->c_conn);
821 if (thread_idx >= 0) {
822 /* Only allow certain opcodes on child threads. */
825 case OPK_C_ACCEPT_STREAM_WAIT:
826 case OPK_C_NEW_STREAM:
827 case OPK_C_READ_EXPECT:
828 case OPK_C_EXPECT_FIN:
831 case OPK_C_FREE_STREAM:
832 case OPK_BEGIN_REPEAT:
834 case OPK_C_READ_FAIL_WAIT:
835 case OPK_C_EXPECT_SSL_ERR:
836 case OPK_EXPECT_ERR_REASON:
837 case OPK_EXPECT_ERR_LIB:
842 TEST_error("opcode %lu not allowed on child thread",
843 (unsigned long)op->op);
850 if (!TEST_size_t_eq(repeat_stack_len, 0))
853 #if defined(OPENSSL_THREADS)
854 if (thread_idx < 0) {
858 for (i = 0; i < h->num_threads; ++i) {
859 if (h->threads[i].m == NULL)
862 ossl_crypto_mutex_lock(h->threads[i].m);
863 done = h->threads[i].done;
864 ossl_crypto_mutex_unlock(h->threads[i].m);
867 if (!end_wait_warning) {
868 TEST_info("still waiting for other threads to finish (%zu)", i);
869 end_wait_warning = 1;
878 TEST_info("script \"%s\" finished on thread %d", script_name, thread_idx);
882 case OPK_BEGIN_REPEAT:
883 if (!TEST_size_t_lt(repeat_stack_len, OSSL_NELEM(repeat_stack_idx)))
886 if (!TEST_size_t_gt(op->arg1, 0))
889 repeat_stack_idx[repeat_stack_len] = op_idx + 1;
890 repeat_stack_done[repeat_stack_len] = 0;
891 repeat_stack_limit[repeat_stack_len] = op->arg1;
896 if (!TEST_size_t_gt(repeat_stack_len, 0))
899 if (++repeat_stack_done[repeat_stack_len - 1]
900 == repeat_stack_limit[repeat_stack_len - 1]) {
903 op_idx = repeat_stack_idx[repeat_stack_len - 1];
912 int ok = op->check_func(h, op);
913 if (h->check_spin_again) {
914 h->check_spin_again = 0;
925 const char *alpn = op->arg0;
926 size_t alpn_len = strlen(alpn);
928 if (!TEST_size_t_le(alpn_len, UINT8_MAX)
929 || !TEST_ptr(tmp_buf = (unsigned char *)OPENSSL_malloc(alpn_len + 1)))
932 memcpy(tmp_buf + 1, alpn, alpn_len);
933 tmp_buf[0] = (unsigned char)alpn_len;
935 /* 0 is the success case for SSL_set_alpn_protos(). */
936 if (!TEST_false(SSL_set_alpn_protos(h->c_conn, tmp_buf,
940 OPENSSL_free(tmp_buf);
945 case OPK_C_CONNECT_WAIT:
951 ret = SSL_connect(h->c_conn);
952 if (!TEST_true((ret == 1 || op->arg1 > 0)
953 || (!h->blocking && is_want(h->c_conn, ret))))
956 if (!h->blocking && ret < 0)
963 size_t bytes_written = 0;
965 if (!TEST_ptr(c_tgt))
968 if (!TEST_true(SSL_write_ex(c_tgt, op->arg0, op->arg1,
970 || !TEST_size_t_eq(bytes_written, op->arg1))
977 size_t bytes_written = 0;
979 if (!TEST_uint64_t_ne(s_stream_id, UINT64_MAX))
982 if (!TEST_true(ossl_quic_tserver_write(h->s, s_stream_id,
985 || !TEST_size_t_eq(bytes_written, op->arg1))
992 if (!TEST_true(SSL_stream_conclude(c_tgt, 0)))
999 if (!TEST_uint64_t_ne(s_stream_id, UINT64_MAX))
1002 ossl_quic_tserver_conclude(h->s, s_stream_id);
1006 case OPK_C_WAIT_FOR_DATA:
1009 size_t bytes_read = 0;
1011 if (!TEST_ptr(c_tgt))
1014 if (!SSL_peek_ex(c_tgt, buf, sizeof(buf), &bytes_read)
1020 case OPK_C_READ_EXPECT:
1022 size_t bytes_read = 0;
1024 if (op->arg1 > 0 && tmp_buf == NULL
1025 && !TEST_ptr(tmp_buf = OPENSSL_malloc(op->arg1)))
1028 if (!SSL_read_ex(c_tgt, tmp_buf + offset, op->arg1 - offset,
1032 if (bytes_read + offset != op->arg1) {
1033 offset += bytes_read;
1038 && !TEST_mem_eq(tmp_buf, op->arg1, op->arg0, op->arg1))
1041 OPENSSL_free(tmp_buf);
1046 case OPK_S_READ_EXPECT:
1048 size_t bytes_read = 0;
1050 if (!TEST_uint64_t_ne(s_stream_id, UINT64_MAX))
1053 if (op->arg1 > 0 && tmp_buf == NULL
1054 && !TEST_ptr(tmp_buf = OPENSSL_malloc(op->arg1)))
1057 if (!TEST_true(ossl_quic_tserver_read(h->s, s_stream_id,
1063 if (bytes_read + offset != op->arg1) {
1064 offset += bytes_read;
1069 && !TEST_mem_eq(tmp_buf, op->arg1, op->arg0, op->arg1))
1072 OPENSSL_free(tmp_buf);
1077 case OPK_C_EXPECT_FIN:
1080 size_t bytes_read = 0;
1082 if (!TEST_false(SSL_read_ex(c_tgt, buf, sizeof(buf),
1084 || !TEST_size_t_eq(bytes_read, 0))
1087 if (is_want(c_tgt, 0))
1090 if (!TEST_int_eq(SSL_get_error(c_tgt, 0),
1091 SSL_ERROR_ZERO_RETURN))
1096 case OPK_S_EXPECT_FIN:
1098 if (!TEST_uint64_t_ne(s_stream_id, UINT64_MAX))
1101 if (!ossl_quic_tserver_has_read_ended(h->s, s_stream_id))
1110 if (!TEST_ptr_null(c_tgt))
1111 goto out; /* don't overwrite existing stream with same name */
1113 if (!TEST_ptr(c_stream = ossl_quic_detach_stream(h->c_conn)))
1116 if (!TEST_true(helper_local_set_c_stream(&hl, op->stream_name, c_stream)))
1123 if (!TEST_ptr(c_tgt))
1126 if (!TEST_true(ossl_quic_attach_stream(h->c_conn, c_tgt)))
1129 if (!TEST_true(helper_local_set_c_stream(&hl, op->stream_name, NULL)))
1134 case OPK_C_NEW_STREAM:
1139 if (!TEST_ptr_null(c_tgt))
1140 goto out; /* don't overwrite existing stream with same name */
1143 flags |= SSL_STREAM_FLAG_UNI;
1145 if (!TEST_ptr(c_stream = SSL_new_stream(h->c_conn, flags)))
1148 if (op->arg2 != UINT64_MAX
1149 && !TEST_uint64_t_eq(SSL_get_stream_id(c_stream),
1153 if (!TEST_true(helper_local_set_c_stream(&hl, op->stream_name, c_stream)))
1158 case OPK_S_NEW_STREAM:
1160 uint64_t stream_id = UINT64_MAX;
1162 if (!TEST_uint64_t_eq(s_stream_id, UINT64_MAX))
1163 goto out; /* don't overwrite existing stream with same name */
1165 if (!TEST_true(ossl_quic_tserver_stream_new(h->s,
1170 if (op->arg2 != UINT64_MAX
1171 && !TEST_uint64_t_eq(stream_id, op->arg2))
1174 if (!TEST_true(helper_set_s_stream(h, op->stream_name,
1180 case OPK_C_ACCEPT_STREAM_WAIT:
1184 if (!TEST_ptr_null(c_tgt))
1185 goto out; /* don't overwrite existing stream with same name */
1187 if ((c_stream = SSL_accept_stream(h->c_conn, 0)) == NULL)
1190 if (!TEST_true(helper_local_set_c_stream(&hl, op->stream_name,
1196 case OPK_S_ACCEPT_STREAM_WAIT:
1198 uint64_t new_stream_id;
1200 if (!TEST_uint64_t_eq(s_stream_id, UINT64_MAX))
1203 new_stream_id = ossl_quic_tserver_pop_incoming_stream(h->s);
1204 if (new_stream_id == UINT64_MAX)
1207 if (!TEST_true(helper_set_s_stream(h, op->stream_name, new_stream_id)))
1212 case OPK_C_ACCEPT_STREAM_NONE:
1216 if (!TEST_ptr_null(c_stream = SSL_accept_stream(h->c_conn, 0))) {
1223 case OPK_C_FREE_STREAM:
1225 if (!TEST_ptr(c_tgt)
1226 || !TEST_true(!SSL_is_connection(c_tgt)))
1229 if (!TEST_true(helper_local_set_c_stream(&hl, op->stream_name, NULL)))
1237 case OPK_C_SET_DEFAULT_STREAM_MODE:
1239 if (!TEST_ptr(c_tgt))
1242 if (!TEST_true(SSL_set_default_stream_mode(c_tgt, op->arg1)))
1247 case OPK_C_SET_INCOMING_STREAM_POLICY:
1249 if (!TEST_ptr(c_tgt))
1252 if (!TEST_true(SSL_set_incoming_stream_policy(c_tgt,
1258 case OPK_C_SHUTDOWN_WAIT:
1261 QUIC_CHANNEL *ch = ossl_quic_conn_get_channel(h->c_conn);
1263 ossl_quic_channel_set_inhibit_tick(ch, 0);
1265 if (!TEST_ptr(c_tgt))
1268 ret = SSL_shutdown_ex(c_tgt, 0, NULL, 0);
1269 if (!TEST_int_ge(ret, 0))
1277 case OPK_C_EXPECT_CONN_CLOSE_INFO:
1279 SSL_CONN_CLOSE_INFO cc_info = {0};
1280 int expect_app = (op->arg1 & EXPECT_CONN_CLOSE_APP) != 0;
1281 int expect_remote = (op->arg1 & EXPECT_CONN_CLOSE_REMOTE) != 0;
1282 uint64_t error_code = op->arg2;
1284 if (!TEST_ptr(c_tgt))
1287 if (!SSL_get_conn_close_info(c_tgt, &cc_info, sizeof(cc_info)))
1290 if (!TEST_int_eq(expect_app, !cc_info.is_transport)
1291 || !TEST_int_eq(expect_remote, !cc_info.is_local)
1292 || !TEST_uint64_t_eq(error_code, cc_info.error_code))
1297 case OPK_S_EXPECT_CONN_CLOSE_INFO:
1299 const QUIC_TERMINATE_CAUSE *tc;
1300 int expect_app = (op->arg1 & EXPECT_CONN_CLOSE_APP) != 0;
1301 int expect_remote = (op->arg1 & EXPECT_CONN_CLOSE_REMOTE) != 0;
1302 uint64_t error_code = op->arg2;
1304 if (!ossl_quic_tserver_is_term_any(h->s)) {
1305 ossl_quic_tserver_ping(h->s);
1309 if (!TEST_ptr(tc = ossl_quic_tserver_get_terminate_cause(h->s)))
1312 if (!TEST_uint64_t_eq(error_code, tc->error_code)
1313 || !TEST_int_eq(expect_app, tc->app)
1314 || !TEST_int_eq(expect_remote, tc->remote))
1319 case OPK_S_BIND_STREAM_ID:
1321 if (!TEST_uint64_t_eq(s_stream_id, UINT64_MAX))
1324 if (!TEST_true(helper_set_s_stream(h, op->stream_name, op->arg2)))
1329 case OPK_S_UNBIND_STREAM_ID:
1331 if (!TEST_uint64_t_ne(s_stream_id, UINT64_MAX))
1334 if (!TEST_true(helper_set_s_stream(h, op->stream_name, UINT64_MAX)))
1339 case OPK_C_WRITE_FAIL:
1341 size_t bytes_written = 0;
1343 if (!TEST_ptr(c_tgt))
1346 if (!TEST_false(SSL_write_ex(c_tgt, "apple", 5, &bytes_written)))
1351 case OPK_S_WRITE_FAIL:
1353 size_t bytes_written = 0;
1355 if (!TEST_uint64_t_ne(s_stream_id, UINT64_MAX))
1358 if (!TEST_false(ossl_quic_tserver_write(h->s, s_stream_id,
1359 (const unsigned char *)"apple", 5,
1365 case OPK_C_READ_FAIL:
1367 size_t bytes_read = 0;
1370 if (!TEST_ptr(c_tgt))
1373 if (!TEST_false(SSL_read_ex(c_tgt, buf, sizeof(buf), &bytes_read)))
1378 case OPK_C_READ_FAIL_WAIT:
1380 size_t bytes_read = 0;
1383 if (!TEST_ptr(c_tgt))
1386 if (!TEST_false(SSL_read_ex(c_tgt, buf, sizeof(buf), &bytes_read)))
1389 if (is_want(c_tgt, 0))
1394 case OPK_S_READ_FAIL:
1396 size_t bytes_read = 0;
1397 unsigned char buf[1];
1399 if (!TEST_uint64_t_ne(s_stream_id, UINT64_MAX))
1402 if (!TEST_false(ossl_quic_tserver_read(h->s, s_stream_id,
1409 case OPK_C_STREAM_RESET:
1411 SSL_STREAM_RESET_ARGS args = {0};
1413 if (!TEST_ptr(c_tgt))
1416 args.quic_error_code = op->arg2;
1418 if (!TEST_true(SSL_stream_reset(c_tgt, &args, sizeof(args))))
1423 case OPK_NEW_THREAD:
1425 #if !defined(OPENSSL_THREADS)
1427 * If this test script requires threading and we do not have
1428 * support for it, skip the rest of it.
1430 TEST_skip("threading not supported, skipping");
1436 if (!TEST_ptr_null(h->threads)) {
1437 TEST_error("max one NEW_THREAD operation per script");
1441 h->threads = OPENSSL_zalloc(op->arg1 * sizeof(struct child_thread_args));
1442 if (!TEST_ptr(h->threads))
1445 h->num_threads = op->arg1;
1447 for (i = 0; i < op->arg1; ++i) {
1448 h->threads[i].h = h;
1449 h->threads[i].script = op->arg0;
1450 h->threads[i].script_name = script_name;
1451 h->threads[i].thread_idx = i;
1453 h->threads[i].m = ossl_crypto_mutex_new();
1454 if (!TEST_ptr(h->threads[i].m))
1458 = ossl_crypto_thread_native_start(run_script_child_thread,
1460 if (!TEST_ptr(h->threads[i].t))
1467 case OPK_C_CLOSE_SOCKET:
1469 BIO_closesocket(h->c_fd);
1473 case OPK_C_EXPECT_SSL_ERR:
1475 if (!TEST_size_t_eq((size_t)SSL_get_error(c_tgt, 0), op->arg1))
1480 case OPK_EXPECT_ERR_REASON:
1482 if (!TEST_size_t_eq((size_t)ERR_GET_REASON(ERR_get_error()), op->arg1))
1487 case OPK_EXPECT_ERR_LIB:
1489 if (!TEST_size_t_eq((size_t)ERR_GET_LIB(ERR_get_error()), op->arg1))
1496 OSSL_sleep(op->arg2);
1500 case OPK_S_SET_INJECT_PLAIN:
1501 h->qtf_packet_plain_cb = op->qtf_packet_plain_cb;
1503 if (!TEST_true(qtest_fault_set_packet_plain_listener(h->qtf,
1504 h->qtf_packet_plain_cb != NULL ?
1505 helper_packet_plain_listener : NULL,
1511 case OPK_SET_INJECT_WORD:
1512 h->inject_word0 = op->arg1;
1513 h->inject_word1 = op->arg2;
1516 case OPK_C_INHIBIT_TICK:
1518 QUIC_CHANNEL *ch = ossl_quic_conn_get_channel(h->c_conn);
1520 ossl_quic_channel_set_inhibit_tick(ch, op->arg1);
1524 case OPK_C_SET_WRITE_BUF_SIZE:
1525 if (!TEST_ptr(c_tgt))
1528 if (!TEST_true(ossl_quic_set_write_buffer_size(c_tgt, op->arg1)))
1534 TEST_error("unknown op");
1543 TEST_error("failed in script \"%s\" at op %zu, thread %d\n",
1544 script_name, op_idx + 1, thread_idx);
1546 for (i = 0; i < repeat_stack_len; ++i)
1547 TEST_info("while repeating, iteration %zu of %zu, starting at script op %zu",
1548 repeat_stack_done[i],
1549 repeat_stack_limit[i],
1550 repeat_stack_idx[i]);
1553 OPENSSL_free(tmp_buf);
1554 helper_local_cleanup(&hl);
1558 static int run_script(const struct script_op *script,
1559 const char *script_name,
1565 if (!TEST_true(helper_init(&h, free_order, 1)))
1568 if (!TEST_true(run_script_worker(&h, script, script_name, -1)))
1571 #if defined(OPENSSL_THREADS)
1572 if (!TEST_true(join_threads(h.threads, h.num_threads)))
1582 #if defined(OPENSSL_THREADS)
1583 static CRYPTO_THREAD_RETVAL run_script_child_thread(void *arg)
1586 struct child_thread_args *args = arg;
1588 testresult = run_script_worker(args->h, args->script,
1592 ossl_crypto_mutex_lock(args->m);
1593 args->testresult = testresult;
1595 ossl_crypto_mutex_unlock(args->m);
1600 /* 1. Simple single-stream test */
1601 static const struct script_op script_1[] = {
1602 OP_C_SET_ALPN ("ossltest")
1603 OP_C_CONNECT_WAIT ()
1604 OP_C_WRITE (DEFAULT, "apple", 5)
1605 OP_C_CONCLUDE (DEFAULT)
1606 OP_S_BIND_STREAM_ID (a, C_BIDI_ID(0))
1607 OP_S_READ_EXPECT (a, "apple", 5)
1609 OP_S_WRITE (a, "orange", 6)
1611 OP_C_READ_EXPECT (DEFAULT, "orange", 6)
1612 OP_C_EXPECT_FIN (DEFAULT)
1616 /* 2. Multi-stream test */
1617 static const struct script_op script_2[] = {
1618 OP_C_SET_ALPN ("ossltest")
1619 OP_C_CONNECT_WAIT ()
1620 OP_C_SET_INCOMING_STREAM_POLICY(SSL_INCOMING_STREAM_POLICY_ACCEPT)
1621 OP_C_WRITE (DEFAULT, "apple", 5)
1622 OP_S_BIND_STREAM_ID (a, C_BIDI_ID(0))
1623 OP_S_READ_EXPECT (a, "apple", 5)
1624 OP_S_WRITE (a, "orange", 6)
1625 OP_C_READ_EXPECT (DEFAULT, "orange", 6)
1627 OP_C_NEW_STREAM_BIDI (b, C_BIDI_ID(1))
1628 OP_C_WRITE (b, "flamingo", 8)
1630 OP_S_BIND_STREAM_ID (b, C_BIDI_ID(1))
1631 OP_S_READ_EXPECT (b, "flamingo", 8)
1633 OP_S_WRITE (b, "gargoyle", 8)
1635 OP_C_READ_EXPECT (b, "gargoyle", 8)
1638 OP_C_NEW_STREAM_UNI (c, C_UNI_ID(0))
1639 OP_C_WRITE (c, "elephant", 8)
1641 OP_S_BIND_STREAM_ID (c, C_UNI_ID(0))
1642 OP_S_READ_EXPECT (c, "elephant", 8)
1646 OP_C_ACCEPT_STREAM_NONE ()
1648 OP_S_NEW_STREAM_BIDI (d, S_BIDI_ID(0))
1649 OP_S_WRITE (d, "frog", 4)
1652 OP_C_ACCEPT_STREAM_WAIT (d)
1653 OP_C_ACCEPT_STREAM_NONE ()
1654 OP_C_READ_EXPECT (d, "frog", 4)
1657 OP_S_NEW_STREAM_BIDI (e, S_BIDI_ID(1))
1658 OP_S_WRITE (e, "mixture", 7)
1661 OP_C_ACCEPT_STREAM_WAIT (e)
1662 OP_C_READ_EXPECT (e, "mixture", 7)
1664 OP_C_WRITE (e, "ramble", 6)
1665 OP_S_READ_EXPECT (e, "ramble", 6)
1669 OP_S_NEW_STREAM_UNI (f, S_UNI_ID(0))
1670 OP_S_WRITE (f, "yonder", 6)
1673 OP_C_ACCEPT_STREAM_WAIT (f)
1674 OP_C_ACCEPT_STREAM_NONE ()
1675 OP_C_READ_EXPECT (f, "yonder", 6)
1679 OP_C_SET_INCOMING_STREAM_POLICY(SSL_INCOMING_STREAM_POLICY_REJECT)
1680 OP_S_NEW_STREAM_BIDI (g, S_BIDI_ID(2))
1681 OP_S_WRITE (g, "unseen", 6)
1684 OP_C_ACCEPT_STREAM_NONE ()
1686 OP_C_SET_INCOMING_STREAM_POLICY(SSL_INCOMING_STREAM_POLICY_AUTO)
1687 OP_S_NEW_STREAM_BIDI (h, S_BIDI_ID(3))
1688 OP_S_WRITE (h, "UNSEEN", 6)
1691 OP_C_ACCEPT_STREAM_NONE ()
1694 * Streams g, h should have been rejected, so server should have got
1695 * STOP_SENDING/RESET_STREAM.
1697 OP_CHECK (check_rejected, S_BIDI_ID(2))
1698 OP_CHECK (check_rejected, S_BIDI_ID(3))
1703 /* 3. Default stream detach/reattach test */
1704 static const struct script_op script_3[] = {
1705 OP_C_SET_ALPN ("ossltest")
1706 OP_C_CONNECT_WAIT ()
1708 OP_C_WRITE (DEFAULT, "apple", 5)
1709 OP_C_DETACH (a) /* DEFAULT becomes stream 'a' */
1710 OP_C_WRITE_FAIL (DEFAULT)
1712 OP_C_WRITE (a, "by", 2)
1714 OP_S_BIND_STREAM_ID (a, C_BIDI_ID(0))
1715 OP_S_READ_EXPECT (a, "appleby", 7)
1717 OP_S_WRITE (a, "hello", 5)
1718 OP_C_READ_EXPECT (a, "hello", 5)
1720 OP_C_WRITE_FAIL (DEFAULT)
1722 OP_C_WRITE (DEFAULT, "is here", 7)
1723 OP_S_READ_EXPECT (a, "is here", 7)
1732 /* 4. Default stream mode test */
1733 static const struct script_op script_4[] = {
1734 OP_C_SET_ALPN ("ossltest")
1735 OP_C_CONNECT_WAIT ()
1737 OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE)
1738 OP_C_WRITE_FAIL (DEFAULT)
1740 OP_S_NEW_STREAM_BIDI (a, S_BIDI_ID(0))
1741 OP_S_WRITE (a, "apple", 5)
1743 OP_C_READ_FAIL (DEFAULT)
1745 OP_C_ACCEPT_STREAM_WAIT (a)
1746 OP_C_READ_EXPECT (a, "apple", 5)
1749 OP_C_WRITE (DEFAULT, "orange", 6)
1750 OP_S_READ_EXPECT (a, "orange", 6)
1755 /* 5. Test stream reset functionality */
1756 static const struct script_op script_5[] = {
1757 OP_C_SET_ALPN ("ossltest")
1758 OP_C_CONNECT_WAIT ()
1760 OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE)
1761 OP_C_NEW_STREAM_BIDI (a, C_BIDI_ID(0))
1762 OP_C_NEW_STREAM_BIDI (b, C_BIDI_ID(1))
1764 OP_C_WRITE (a, "apple", 5)
1765 OP_C_STREAM_RESET (a, 42)
1767 OP_C_WRITE (b, "strawberry", 10)
1769 OP_S_BIND_STREAM_ID (a, C_BIDI_ID(0))
1770 OP_S_BIND_STREAM_ID (b, C_BIDI_ID(1))
1771 OP_S_READ_EXPECT (b, "strawberry", 10)
1772 /* Reset disrupts read of already sent data */
1774 OP_CHECK (check_stream_reset, C_BIDI_ID(0))
1779 /* 6. Test STOP_SENDING functionality */
1780 static const struct script_op script_6[] = {
1781 OP_C_SET_ALPN ("ossltest")
1782 OP_C_CONNECT_WAIT ()
1784 OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE)
1785 OP_S_NEW_STREAM_BIDI (a, S_BIDI_ID(0))
1786 OP_S_WRITE (a, "apple", 5)
1788 OP_C_ACCEPT_STREAM_WAIT (a)
1789 OP_C_FREE_STREAM (a)
1790 OP_C_ACCEPT_STREAM_NONE ()
1792 OP_CHECK (check_stream_stopped, S_BIDI_ID(0))
1797 /* 7. Unidirectional default stream mode test (client sends first) */
1798 static const struct script_op script_7[] = {
1799 OP_C_SET_ALPN ("ossltest")
1800 OP_C_CONNECT_WAIT ()
1802 OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_AUTO_UNI)
1803 OP_C_WRITE (DEFAULT, "apple", 5)
1805 OP_S_BIND_STREAM_ID (a, C_UNI_ID(0))
1806 OP_S_READ_EXPECT (a, "apple", 5)
1812 /* 8. Unidirectional default stream mode test (server sends first) */
1813 static const struct script_op script_8[] = {
1814 OP_C_SET_ALPN ("ossltest")
1815 OP_C_CONNECT_WAIT ()
1817 OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_AUTO_UNI)
1818 OP_S_NEW_STREAM_UNI (a, S_UNI_ID(0))
1819 OP_S_WRITE (a, "apple", 5)
1820 OP_C_READ_EXPECT (DEFAULT, "apple", 5)
1821 OP_C_WRITE_FAIL (DEFAULT)
1826 /* 9. Unidirectional default stream mode test (server sends first on bidi) */
1827 static const struct script_op script_9[] = {
1828 OP_C_SET_ALPN ("ossltest")
1829 OP_C_CONNECT_WAIT ()
1831 OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_AUTO_UNI)
1832 OP_S_NEW_STREAM_BIDI (a, S_BIDI_ID(0))
1833 OP_S_WRITE (a, "apple", 5)
1834 OP_C_READ_EXPECT (DEFAULT, "apple", 5)
1835 OP_C_WRITE (DEFAULT, "orange", 6)
1836 OP_S_READ_EXPECT (a, "orange", 6)
1842 static const struct script_op script_10[] = {
1843 OP_C_SET_ALPN ("ossltest")
1844 OP_C_CONNECT_WAIT ()
1846 OP_C_WRITE (DEFAULT, "apple", 5)
1847 OP_S_BIND_STREAM_ID (a, C_BIDI_ID(0))
1848 OP_S_READ_EXPECT (a, "apple", 5)
1850 OP_C_SHUTDOWN_WAIT ()
1851 OP_C_EXPECT_CONN_CLOSE_INFO(0, 1, 0)
1852 OP_S_EXPECT_CONN_CLOSE_INFO(0, 1, 1)
1857 /* 11. Many threads accepted on the same client connection */
1858 static const struct script_op script_11_child[] = {
1859 OP_C_ACCEPT_STREAM_WAIT (a)
1860 OP_C_READ_EXPECT (a, "foo", 3)
1866 static const struct script_op script_11[] = {
1867 OP_C_SET_ALPN ("ossltest")
1868 OP_C_CONNECT_WAIT ()
1869 OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE)
1871 OP_NEW_THREAD (5, script_11_child)
1873 OP_S_NEW_STREAM_BIDI (a, ANY_ID)
1874 OP_S_WRITE (a, "foo", 3)
1877 OP_S_NEW_STREAM_BIDI (b, ANY_ID)
1878 OP_S_WRITE (b, "foo", 3)
1881 OP_S_NEW_STREAM_BIDI (c, ANY_ID)
1882 OP_S_WRITE (c, "foo", 3)
1885 OP_S_NEW_STREAM_BIDI (d, ANY_ID)
1886 OP_S_WRITE (d, "foo", 3)
1889 OP_S_NEW_STREAM_BIDI (e, ANY_ID)
1890 OP_S_WRITE (e, "foo", 3)
1896 /* 12. Many threads initiated on the same client connection */
1897 static const struct script_op script_12_child[] = {
1898 OP_C_NEW_STREAM_BIDI (a, ANY_ID)
1899 OP_C_WRITE (a, "foo", 3)
1901 OP_C_FREE_STREAM (a)
1906 static const struct script_op script_12[] = {
1907 OP_C_SET_ALPN ("ossltest")
1908 OP_C_CONNECT_WAIT ()
1909 OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE)
1911 OP_NEW_THREAD (5, script_12_child)
1913 OP_S_BIND_STREAM_ID (a, C_BIDI_ID(0))
1914 OP_S_READ_EXPECT (a, "foo", 3)
1916 OP_S_BIND_STREAM_ID (b, C_BIDI_ID(1))
1917 OP_S_READ_EXPECT (b, "foo", 3)
1919 OP_S_BIND_STREAM_ID (c, C_BIDI_ID(2))
1920 OP_S_READ_EXPECT (c, "foo", 3)
1922 OP_S_BIND_STREAM_ID (d, C_BIDI_ID(3))
1923 OP_S_READ_EXPECT (d, "foo", 3)
1925 OP_S_BIND_STREAM_ID (e, C_BIDI_ID(4))
1926 OP_S_READ_EXPECT (e, "foo", 3)
1932 /* 13. Many threads accepted on the same client connection (stress test) */
1933 static const struct script_op script_13_child[] = {
1934 OP_BEGIN_REPEAT (10)
1936 OP_C_ACCEPT_STREAM_WAIT (a)
1937 OP_C_READ_EXPECT (a, "foo", 3)
1939 OP_C_FREE_STREAM (a)
1946 static const struct script_op script_13[] = {
1947 OP_C_SET_ALPN ("ossltest")
1948 OP_C_CONNECT_WAIT ()
1949 OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE)
1951 OP_NEW_THREAD (5, script_13_child)
1953 OP_BEGIN_REPEAT (50)
1955 OP_S_NEW_STREAM_BIDI (a, ANY_ID)
1956 OP_S_WRITE (a, "foo", 3)
1958 OP_S_UNBIND_STREAM_ID (a)
1965 /* 14. Many threads initiating on the same client connection (stress test) */
1966 static const struct script_op script_14_child[] = {
1967 OP_BEGIN_REPEAT (10)
1969 OP_C_NEW_STREAM_BIDI (a, ANY_ID)
1970 OP_C_WRITE (a, "foo", 3)
1972 OP_C_FREE_STREAM (a)
1979 static const struct script_op script_14[] = {
1980 OP_C_SET_ALPN ("ossltest")
1981 OP_C_CONNECT_WAIT ()
1982 OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE)
1984 OP_NEW_THREAD (5, script_14_child)
1986 OP_BEGIN_REPEAT (50)
1988 OP_S_ACCEPT_STREAM_WAIT (a)
1989 OP_S_READ_EXPECT (a, "foo", 3)
1991 OP_S_UNBIND_STREAM_ID (a)
1998 /* 15. Client sending large number of streams, MAX_STREAMS test */
1999 static const struct script_op script_15[] = {
2000 OP_C_SET_ALPN ("ossltest")
2001 OP_C_CONNECT_WAIT ()
2002 OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE)
2005 * This will cause a protocol violation to be raised by the server if we are
2006 * not handling the stream limit correctly on the TX side.
2008 OP_BEGIN_REPEAT (200)
2010 OP_C_NEW_STREAM_BIDI (a, ANY_ID)
2011 OP_C_WRITE (a, "foo", 3)
2013 OP_C_FREE_STREAM (a)
2017 /* Prove the connection is still good. */
2018 OP_S_NEW_STREAM_BIDI (a, S_BIDI_ID(0))
2019 OP_S_WRITE (a, "bar", 3)
2022 OP_C_ACCEPT_STREAM_WAIT (a)
2023 OP_C_READ_EXPECT (a, "bar", 3)
2027 * Drain the queue of incoming streams. We should be able to get all 200
2028 * even though only 100 can be initiated at a time.
2030 OP_BEGIN_REPEAT (200)
2032 OP_S_ACCEPT_STREAM_WAIT (b)
2033 OP_S_READ_EXPECT (b, "foo", 3)
2035 OP_S_UNBIND_STREAM_ID (b)
2042 /* 16. Server sending large number of streams, MAX_STREAMS test */
2043 static const struct script_op script_16[] = {
2044 OP_C_SET_ALPN ("ossltest")
2045 OP_C_CONNECT_WAIT ()
2046 OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE)
2049 * This will cause a protocol violation to be raised by the client if we are
2050 * not handling the stream limit correctly on the TX side.
2052 OP_BEGIN_REPEAT (200)
2054 OP_S_NEW_STREAM_BIDI (a, ANY_ID)
2055 OP_S_WRITE (a, "foo", 3)
2057 OP_S_UNBIND_STREAM_ID (a)
2061 /* Prove that the connection is still good. */
2062 OP_C_NEW_STREAM_BIDI (a, ANY_ID)
2063 OP_C_WRITE (a, "bar", 3)
2066 OP_S_ACCEPT_STREAM_WAIT (b)
2067 OP_S_READ_EXPECT (b, "bar", 3)
2070 /* Drain the queue of incoming streams. */
2071 OP_BEGIN_REPEAT (200)
2073 OP_C_ACCEPT_STREAM_WAIT (b)
2074 OP_C_READ_EXPECT (b, "foo", 3)
2076 OP_C_FREE_STREAM (b)
2083 /* 17. Key update test - unlimited */
2084 static const struct script_op script_17[] = {
2085 OP_C_SET_ALPN ("ossltest")
2086 OP_C_CONNECT_WAIT ()
2088 OP_C_WRITE (DEFAULT, "apple", 5)
2090 OP_S_BIND_STREAM_ID (a, C_BIDI_ID(0))
2091 OP_S_READ_EXPECT (a, "apple", 5)
2093 OP_CHECK (override_key_update, 1)
2095 OP_BEGIN_REPEAT (200)
2097 OP_C_WRITE (DEFAULT, "apple", 5)
2098 OP_S_READ_EXPECT (a, "apple", 5)
2101 * TXKU frequency is bounded by RTT because a previous TXKU needs to be
2102 * acknowledged by the peer first before another one can be begin. By
2103 * waiting this long, we eliminate any such concern and ensure as many key
2104 * updates as possible can occur for the purposes of this test.
2106 OP_CHECK (skip_time_ms, 100)
2110 /* At least 5 RXKUs detected */
2111 OP_CHECK (check_key_update_ge, 5)
2114 * Prove the connection is still healthy by sending something in both
2117 OP_C_WRITE (DEFAULT, "xyzzy", 5)
2118 OP_S_READ_EXPECT (a, "xyzzy", 5)
2120 OP_S_WRITE (a, "plugh", 5)
2121 OP_C_READ_EXPECT (DEFAULT, "plugh", 5)
2126 /* 18. Key update test - RTT-bounded */
2127 static const struct script_op script_18[] = {
2128 OP_C_SET_ALPN ("ossltest")
2129 OP_C_CONNECT_WAIT ()
2131 OP_C_WRITE (DEFAULT, "apple", 5)
2133 OP_S_BIND_STREAM_ID (a, C_BIDI_ID(0))
2134 OP_S_READ_EXPECT (a, "apple", 5)
2136 OP_CHECK (override_key_update, 1)
2138 OP_BEGIN_REPEAT (200)
2140 OP_C_WRITE (DEFAULT, "apple", 5)
2141 OP_S_READ_EXPECT (a, "apple", 5)
2142 OP_CHECK (skip_time_ms, 8)
2147 * This time we simulate far less time passing between writes, so there are
2148 * fewer opportunities to initiate TXKUs. Note that we ask for a TXKU every
2149 * 1 packet above, which is absurd; thus this ensures we only actually
2150 * generate TXKUs when we are allowed to.
2152 OP_CHECK (check_key_update_lt, 240)
2155 * Prove the connection is still healthy by sending something in both
2158 OP_C_WRITE (DEFAULT, "xyzzy", 5)
2159 OP_S_READ_EXPECT (a, "xyzzy", 5)
2161 OP_S_WRITE (a, "plugh", 5)
2162 OP_C_READ_EXPECT (DEFAULT, "plugh", 5)
2167 /* 19. Key update test - artificially triggered */
2168 static const struct script_op script_19[] = {
2169 OP_C_SET_ALPN ("ossltest")
2170 OP_C_CONNECT_WAIT ()
2172 OP_C_WRITE (DEFAULT, "apple", 5)
2174 OP_S_BIND_STREAM_ID (a, C_BIDI_ID(0))
2175 OP_S_READ_EXPECT (a, "apple", 5)
2177 OP_C_WRITE (DEFAULT, "orange", 6)
2178 OP_S_READ_EXPECT (a, "orange", 6)
2180 OP_S_WRITE (a, "strawberry", 10)
2181 OP_C_READ_EXPECT (DEFAULT, "strawberry", 10)
2183 OP_CHECK (check_key_update_lt, 1)
2184 OP_CHECK (trigger_key_update, 0)
2186 OP_C_WRITE (DEFAULT, "orange", 6)
2187 OP_S_READ_EXPECT (a, "orange", 6)
2188 OP_S_WRITE (a, "ok", 2)
2190 OP_C_READ_EXPECT (DEFAULT, "ok", 2)
2191 OP_CHECK (check_key_update_ge, 1)
2196 /* 20. Multiple threads accept stream with socket forcibly closed (error test) */
2197 static const struct script_op script_20_child[] = {
2198 OP_C_ACCEPT_STREAM_WAIT (a)
2199 OP_C_READ_EXPECT (a, "foo", 3)
2203 OP_C_READ_FAIL_WAIT (a)
2204 OP_C_EXPECT_SSL_ERR (a, SSL_ERROR_SYSCALL)
2205 OP_EXPECT_ERR_LIB (ERR_LIB_SYS)
2206 OP_EXPECT_ERR_REASON (SSL_R_QUIC_NETWORK_ERROR)
2207 OP_C_FREE_STREAM (a)
2212 static const struct script_op script_20[] = {
2213 OP_C_SET_ALPN ("ossltest")
2214 OP_C_CONNECT_WAIT ()
2215 OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE)
2217 OP_NEW_THREAD (5, script_20_child)
2221 OP_S_NEW_STREAM_BIDI (a, ANY_ID)
2222 OP_S_WRITE (a, "foo", 3)
2223 OP_S_UNBIND_STREAM_ID (a)
2229 OP_C_CLOSE_SOCKET ()
2234 /* 21. Fault injection - unknown frame in 1-RTT packet */
2235 static int script_21_inject_plain(struct helper *h, QUIC_PKT_HDR *hdr,
2236 unsigned char *buf, size_t len)
2240 unsigned char frame_buf[8];
2243 if (h->inject_word0 == 0 || hdr->type != h->inject_word0)
2246 if (!TEST_true(WPACKET_init_static_len(&wpkt, frame_buf,
2247 sizeof(frame_buf), 0)))
2250 if (!TEST_true(WPACKET_quic_write_vlint(&wpkt, h->inject_word1)))
2253 if (!TEST_true(WPACKET_get_total_written(&wpkt, &written)))
2256 if (!qtest_fault_prepend_frame(h->qtf, frame_buf, written))
2262 WPACKET_finish(&wpkt);
2264 WPACKET_cleanup(&wpkt);
2268 static const struct script_op script_21[] = {
2269 OP_S_SET_INJECT_PLAIN (script_21_inject_plain)
2270 OP_C_SET_ALPN ("ossltest")
2271 OP_C_CONNECT_WAIT ()
2273 OP_C_WRITE (DEFAULT, "apple", 5)
2274 OP_S_BIND_STREAM_ID (a, C_BIDI_ID(0))
2275 OP_S_READ_EXPECT (a, "apple", 5)
2277 OP_SET_INJECT_WORD (QUIC_PKT_TYPE_1RTT, OSSL_QUIC_VLINT_MAX)
2279 OP_S_WRITE (a, "orange", 6)
2281 OP_C_EXPECT_CONN_CLOSE_INFO(QUIC_ERR_FRAME_ENCODING_ERROR,0,0)
2286 /* 22. Fault injection - non-zero packet header reserved bits */
2287 static int script_22_inject_plain(struct helper *h, QUIC_PKT_HDR *hdr,
2288 unsigned char *buf, size_t len)
2290 if (h->inject_word0 == 0)
2297 static const struct script_op script_22[] = {
2298 OP_S_SET_INJECT_PLAIN (script_22_inject_plain)
2299 OP_C_SET_ALPN ("ossltest")
2300 OP_C_CONNECT_WAIT ()
2302 OP_C_WRITE (DEFAULT, "apple", 5)
2303 OP_S_BIND_STREAM_ID (a, C_BIDI_ID(0))
2304 OP_S_READ_EXPECT (a, "apple", 5)
2306 OP_SET_INJECT_WORD (1, 0)
2308 OP_S_WRITE (a, "orange", 6)
2310 OP_C_EXPECT_CONN_CLOSE_INFO(QUIC_ERR_PROTOCOL_VIOLATION,0,0)
2315 /* 23. Fault injection - empty NEW_TOKEN */
2316 static int script_23_inject_plain(struct helper *h, QUIC_PKT_HDR *hdr,
2317 unsigned char *buf, size_t len)
2321 unsigned char frame_buf[16];
2324 if (h->inject_word0 == 0)
2327 if (!TEST_true(WPACKET_init_static_len(&wpkt, frame_buf,
2328 sizeof(frame_buf), 0)))
2331 if (!TEST_true(WPACKET_quic_write_vlint(&wpkt, OSSL_QUIC_FRAME_TYPE_NEW_TOKEN))
2332 || !TEST_true(WPACKET_quic_write_vlint(&wpkt, 0)))
2335 if (!TEST_true(WPACKET_get_total_written(&wpkt, &written)))
2338 if (!qtest_fault_prepend_frame(h->qtf, frame_buf, written))
2344 WPACKET_finish(&wpkt);
2346 WPACKET_cleanup(&wpkt);
2350 static const struct script_op script_23[] = {
2351 OP_S_SET_INJECT_PLAIN (script_23_inject_plain)
2352 OP_C_SET_ALPN ("ossltest")
2353 OP_C_CONNECT_WAIT ()
2355 OP_C_WRITE (DEFAULT, "apple", 5)
2356 OP_S_BIND_STREAM_ID (a, C_BIDI_ID(0))
2357 OP_S_READ_EXPECT (a, "apple", 5)
2359 OP_SET_INJECT_WORD (1, 0)
2361 OP_S_WRITE (a, "orange", 6)
2363 OP_C_EXPECT_CONN_CLOSE_INFO(QUIC_ERR_FRAME_ENCODING_ERROR,0,0)
2368 /* 24. Fault injection - excess value of MAX_STREAMS_BIDI */
2369 static int script_24_inject_plain(struct helper *h, QUIC_PKT_HDR *hdr,
2370 unsigned char *buf, size_t len)
2374 unsigned char frame_buf[16];
2377 if (h->inject_word0 == 0)
2380 if (!TEST_true(WPACKET_init_static_len(&wpkt, frame_buf,
2381 sizeof(frame_buf), 0)))
2384 if (!TEST_true(WPACKET_quic_write_vlint(&wpkt, h->inject_word1))
2385 || !TEST_true(WPACKET_quic_write_vlint(&wpkt, (((uint64_t)1) << 60) + 1)))
2388 if (!TEST_true(WPACKET_get_total_written(&wpkt, &written)))
2391 if (!qtest_fault_prepend_frame(h->qtf, frame_buf, written))
2397 WPACKET_finish(&wpkt);
2399 WPACKET_cleanup(&wpkt);
2403 static const struct script_op script_24[] = {
2404 OP_S_SET_INJECT_PLAIN (script_24_inject_plain)
2405 OP_C_SET_ALPN ("ossltest")
2406 OP_C_CONNECT_WAIT ()
2408 OP_C_WRITE (DEFAULT, "apple", 5)
2409 OP_S_BIND_STREAM_ID (a, C_BIDI_ID(0))
2410 OP_S_READ_EXPECT (a, "apple", 5)
2412 OP_SET_INJECT_WORD (1, OSSL_QUIC_FRAME_TYPE_MAX_STREAMS_BIDI)
2414 OP_S_WRITE (a, "orange", 6)
2416 OP_C_EXPECT_CONN_CLOSE_INFO(QUIC_ERR_FRAME_ENCODING_ERROR,0,0)
2421 /* 25. Fault injection - excess value of MAX_STREAMS_UNI */
2422 static const struct script_op script_25[] = {
2423 OP_S_SET_INJECT_PLAIN (script_24_inject_plain)
2424 OP_C_SET_ALPN ("ossltest")
2425 OP_C_CONNECT_WAIT ()
2427 OP_C_WRITE (DEFAULT, "apple", 5)
2428 OP_S_BIND_STREAM_ID (a, C_BIDI_ID(0))
2429 OP_S_READ_EXPECT (a, "apple", 5)
2431 OP_SET_INJECT_WORD (1, OSSL_QUIC_FRAME_TYPE_MAX_STREAMS_UNI)
2433 OP_S_WRITE (a, "orange", 6)
2435 OP_C_EXPECT_CONN_CLOSE_INFO(QUIC_ERR_FRAME_ENCODING_ERROR,0,0)
2440 /* 26. Fault injection - excess value of STREAMS_BLOCKED_BIDI */
2441 static const struct script_op script_26[] = {
2442 OP_S_SET_INJECT_PLAIN (script_24_inject_plain)
2443 OP_C_SET_ALPN ("ossltest")
2444 OP_C_CONNECT_WAIT ()
2446 OP_C_WRITE (DEFAULT, "apple", 5)
2447 OP_S_BIND_STREAM_ID (a, C_BIDI_ID(0))
2448 OP_S_READ_EXPECT (a, "apple", 5)
2450 OP_SET_INJECT_WORD (1, OSSL_QUIC_FRAME_TYPE_STREAMS_BLOCKED_BIDI)
2452 OP_S_WRITE (a, "orange", 6)
2454 OP_C_EXPECT_CONN_CLOSE_INFO(QUIC_ERR_STREAM_LIMIT_ERROR,0,0)
2459 /* 27. Fault injection - excess value of STREAMS_BLOCKED_UNI */
2460 static const struct script_op script_27[] = {
2461 OP_S_SET_INJECT_PLAIN (script_24_inject_plain)
2462 OP_C_SET_ALPN ("ossltest")
2463 OP_C_CONNECT_WAIT ()
2465 OP_C_WRITE (DEFAULT, "apple", 5)
2466 OP_S_BIND_STREAM_ID (a, C_BIDI_ID(0))
2467 OP_S_READ_EXPECT (a, "apple", 5)
2469 OP_SET_INJECT_WORD (1, OSSL_QUIC_FRAME_TYPE_STREAMS_BLOCKED_UNI)
2471 OP_S_WRITE (a, "orange", 6)
2473 OP_C_EXPECT_CONN_CLOSE_INFO(QUIC_ERR_STREAM_LIMIT_ERROR,0,0)
2478 /* 28. Fault injection - received RESET_STREAM for send-only stream */
2479 static int script_28_inject_plain(struct helper *h, QUIC_PKT_HDR *hdr,
2480 unsigned char *buf, size_t len)
2484 unsigned char frame_buf[32];
2487 if (h->inject_word0 == 0)
2490 if (!TEST_true(WPACKET_init_static_len(&wpkt, frame_buf,
2491 sizeof(frame_buf), 0)))
2494 if (!TEST_true(WPACKET_quic_write_vlint(&wpkt, h->inject_word1))
2495 || !TEST_true(WPACKET_quic_write_vlint(&wpkt, /* stream ID */
2496 h->inject_word0 - 1))
2497 || !TEST_true(WPACKET_quic_write_vlint(&wpkt, 123))
2498 || (h->inject_word1 == OSSL_QUIC_FRAME_TYPE_RESET_STREAM
2499 && !TEST_true(WPACKET_quic_write_vlint(&wpkt, 5)))) /* final size */
2502 if (!TEST_true(WPACKET_get_total_written(&wpkt, &written)))
2505 if (!qtest_fault_prepend_frame(h->qtf, frame_buf, written))
2511 WPACKET_finish(&wpkt);
2513 WPACKET_cleanup(&wpkt);
2517 static const struct script_op script_28[] = {
2518 OP_S_SET_INJECT_PLAIN (script_28_inject_plain)
2519 OP_C_SET_ALPN ("ossltest")
2520 OP_C_CONNECT_WAIT ()
2521 OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE)
2523 OP_C_NEW_STREAM_BIDI (a, C_BIDI_ID(0))
2524 OP_C_WRITE (a, "orange", 6)
2526 OP_S_BIND_STREAM_ID (a, C_BIDI_ID(0))
2527 OP_S_READ_EXPECT (a, "orange", 6)
2529 OP_C_NEW_STREAM_UNI (b, C_UNI_ID(0))
2530 OP_C_WRITE (b, "apple", 5)
2532 OP_S_BIND_STREAM_ID (b, C_UNI_ID(0))
2533 OP_S_READ_EXPECT (b, "apple", 5)
2535 OP_SET_INJECT_WORD (C_UNI_ID(0) + 1, OSSL_QUIC_FRAME_TYPE_RESET_STREAM)
2536 OP_S_WRITE (a, "fruit", 5)
2538 OP_C_EXPECT_CONN_CLOSE_INFO(QUIC_ERR_STREAM_STATE_ERROR,0,0)
2543 /* 29. Fault injection - received RESET_STREAM for nonexistent send-only stream */
2544 static const struct script_op script_29[] = {
2545 OP_S_SET_INJECT_PLAIN (script_28_inject_plain)
2546 OP_C_SET_ALPN ("ossltest")
2547 OP_C_CONNECT_WAIT ()
2548 OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE)
2550 OP_C_NEW_STREAM_BIDI (a, C_BIDI_ID(0))
2551 OP_C_WRITE (a, "orange", 6)
2553 OP_S_BIND_STREAM_ID (a, C_BIDI_ID(0))
2554 OP_S_READ_EXPECT (a, "orange", 6)
2556 OP_C_NEW_STREAM_UNI (b, C_UNI_ID(0))
2557 OP_C_WRITE (b, "apple", 5)
2559 OP_S_BIND_STREAM_ID (b, C_UNI_ID(0))
2560 OP_S_READ_EXPECT (b, "apple", 5)
2562 OP_SET_INJECT_WORD (C_UNI_ID(1) + 1, OSSL_QUIC_FRAME_TYPE_RESET_STREAM)
2563 OP_S_WRITE (a, "fruit", 5)
2565 OP_C_EXPECT_CONN_CLOSE_INFO(QUIC_ERR_STREAM_STATE_ERROR,0,0)
2570 /* 30. Fault injection - received STOP_SENDING for receive-only stream */
2571 static const struct script_op script_30[] = {
2572 OP_S_SET_INJECT_PLAIN (script_28_inject_plain)
2573 OP_C_SET_ALPN ("ossltest")
2574 OP_C_CONNECT_WAIT ()
2575 OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE)
2577 OP_S_NEW_STREAM_UNI (a, S_UNI_ID(0))
2578 OP_S_WRITE (a, "apple", 5)
2580 OP_C_ACCEPT_STREAM_WAIT (a)
2581 OP_C_READ_EXPECT (a, "apple", 5)
2583 OP_SET_INJECT_WORD (S_UNI_ID(0) + 1, OSSL_QUIC_FRAME_TYPE_STOP_SENDING)
2584 OP_S_WRITE (a, "orange", 6)
2586 OP_C_EXPECT_CONN_CLOSE_INFO(QUIC_ERR_STREAM_STATE_ERROR,0,0)
2591 /* 31. Fault injection - received STOP_SENDING for nonexistent receive-only stream */
2592 static const struct script_op script_31[] = {
2593 OP_S_SET_INJECT_PLAIN (script_28_inject_plain)
2594 OP_C_SET_ALPN ("ossltest")
2595 OP_C_CONNECT_WAIT ()
2596 OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE)
2598 OP_S_NEW_STREAM_UNI (a, S_UNI_ID(0))
2599 OP_S_WRITE (a, "apple", 5)
2601 OP_C_ACCEPT_STREAM_WAIT (a)
2602 OP_C_READ_EXPECT (a, "apple", 5)
2604 OP_SET_INJECT_WORD (C_UNI_ID(0) + 1, OSSL_QUIC_FRAME_TYPE_STOP_SENDING)
2605 OP_S_WRITE (a, "orange", 6)
2607 OP_C_EXPECT_CONN_CLOSE_INFO(QUIC_ERR_STREAM_STATE_ERROR,0,0)
2612 /* 32. Fault injection - STREAM frame for nonexistent stream */
2613 static int script_32_inject_plain(struct helper *h, QUIC_PKT_HDR *hdr,
2614 unsigned char *buf, size_t len)
2618 unsigned char frame_buf[64];
2620 uint64_t type = OSSL_QUIC_FRAME_TYPE_STREAM_OFF_LEN, offset, flen, i;
2622 switch (h->inject_word1) {
2632 offset = (((uint64_t)1)<<62) - 1;
2636 offset = 1 * 1024 * 1024 * 1024; /* 1G */
2641 if (!TEST_true(WPACKET_init_static_len(&wpkt, frame_buf,
2642 sizeof(frame_buf), 0)))
2645 if (!TEST_true(WPACKET_quic_write_vlint(&wpkt, type))
2646 || !TEST_true(WPACKET_quic_write_vlint(&wpkt, /* stream ID */
2647 h->inject_word0 - 1))
2648 || !TEST_true(WPACKET_quic_write_vlint(&wpkt, offset))
2649 || !TEST_true(WPACKET_quic_write_vlint(&wpkt, flen)))
2652 for (i = 0; i < flen; ++i)
2653 if (!TEST_true(WPACKET_put_bytes_u8(&wpkt, 0x42)))
2656 if (!TEST_true(WPACKET_get_total_written(&wpkt, &written)))
2659 if (!qtest_fault_prepend_frame(h->qtf, frame_buf, written))
2665 WPACKET_finish(&wpkt);
2667 WPACKET_cleanup(&wpkt);
2671 static const struct script_op script_32[] = {
2672 OP_S_SET_INJECT_PLAIN (script_32_inject_plain)
2673 OP_C_SET_ALPN ("ossltest")
2674 OP_C_CONNECT_WAIT ()
2675 OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE)
2677 OP_S_NEW_STREAM_UNI (a, S_UNI_ID(0))
2678 OP_S_WRITE (a, "apple", 5)
2680 OP_C_ACCEPT_STREAM_WAIT (a)
2681 OP_C_READ_EXPECT (a, "apple", 5)
2683 OP_SET_INJECT_WORD (C_UNI_ID(0) + 1, 1)
2684 OP_S_WRITE (a, "orange", 6)
2686 OP_C_EXPECT_CONN_CLOSE_INFO(QUIC_ERR_STREAM_STATE_ERROR,0,0)
2691 /* 33. Fault injection - STREAM frame with illegal offset */
2692 static const struct script_op script_33[] = {
2693 OP_S_SET_INJECT_PLAIN (script_32_inject_plain)
2694 OP_C_SET_ALPN ("ossltest")
2695 OP_C_CONNECT_WAIT ()
2696 OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE)
2698 OP_C_NEW_STREAM_BIDI (a, C_BIDI_ID(0))
2699 OP_C_WRITE (a, "apple", 5)
2701 OP_S_BIND_STREAM_ID (a, C_BIDI_ID(0))
2702 OP_S_READ_EXPECT (a, "apple", 5)
2704 OP_SET_INJECT_WORD (C_BIDI_ID(0) + 1, 2)
2705 OP_S_WRITE (a, "orange", 6)
2707 OP_C_EXPECT_CONN_CLOSE_INFO(QUIC_ERR_FRAME_ENCODING_ERROR,0,0)
2712 /* 34. Fault injection - STREAM frame which exceeds FC */
2713 static const struct script_op script_34[] = {
2714 OP_S_SET_INJECT_PLAIN (script_32_inject_plain)
2715 OP_C_SET_ALPN ("ossltest")
2716 OP_C_CONNECT_WAIT ()
2717 OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE)
2719 OP_C_NEW_STREAM_BIDI (a, C_BIDI_ID(0))
2720 OP_C_WRITE (a, "apple", 5)
2722 OP_S_BIND_STREAM_ID (a, C_BIDI_ID(0))
2723 OP_S_READ_EXPECT (a, "apple", 5)
2725 OP_SET_INJECT_WORD (C_BIDI_ID(0) + 1, 3)
2726 OP_S_WRITE (a, "orange", 6)
2728 OP_C_EXPECT_CONN_CLOSE_INFO(QUIC_ERR_FLOW_CONTROL_ERROR,0,0)
2733 /* 35. Fault injection - MAX_STREAM_DATA for receive-only stream */
2734 static const struct script_op script_35[] = {
2735 OP_S_SET_INJECT_PLAIN (script_28_inject_plain)
2736 OP_C_SET_ALPN ("ossltest")
2737 OP_C_CONNECT_WAIT ()
2738 OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE)
2740 OP_S_NEW_STREAM_UNI (a, S_UNI_ID(0))
2741 OP_S_WRITE (a, "apple", 5)
2743 OP_C_ACCEPT_STREAM_WAIT (a)
2744 OP_C_READ_EXPECT (a, "apple", 5)
2746 OP_SET_INJECT_WORD (S_UNI_ID(0) + 1, OSSL_QUIC_FRAME_TYPE_MAX_STREAM_DATA)
2747 OP_S_WRITE (a, "orange", 6)
2749 OP_C_EXPECT_CONN_CLOSE_INFO(QUIC_ERR_STREAM_STATE_ERROR,0,0)
2754 /* 36. Fault injection - MAX_STREAM_DATA for nonexistent stream */
2755 static const struct script_op script_36[] = {
2756 OP_S_SET_INJECT_PLAIN (script_28_inject_plain)
2757 OP_C_SET_ALPN ("ossltest")
2758 OP_C_CONNECT_WAIT ()
2759 OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE)
2761 OP_S_NEW_STREAM_UNI (a, S_UNI_ID(0))
2762 OP_S_WRITE (a, "apple", 5)
2764 OP_C_ACCEPT_STREAM_WAIT (a)
2765 OP_C_READ_EXPECT (a, "apple", 5)
2767 OP_SET_INJECT_WORD (C_BIDI_ID(0) + 1, OSSL_QUIC_FRAME_TYPE_MAX_STREAM_DATA)
2768 OP_S_WRITE (a, "orange", 6)
2770 OP_C_EXPECT_CONN_CLOSE_INFO(QUIC_ERR_STREAM_STATE_ERROR,0,0)
2775 /* 37. Fault injection - STREAM_DATA_BLOCKED for send-only stream */
2776 static const struct script_op script_37[] = {
2777 OP_S_SET_INJECT_PLAIN (script_28_inject_plain)
2778 OP_C_SET_ALPN ("ossltest")
2779 OP_C_CONNECT_WAIT ()
2780 OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE)
2782 OP_C_NEW_STREAM_UNI (a, C_UNI_ID(0))
2783 OP_C_WRITE (a, "apple", 5)
2785 OP_S_BIND_STREAM_ID (a, C_UNI_ID(0))
2786 OP_S_READ_EXPECT (a, "apple", 5)
2788 OP_S_NEW_STREAM_UNI (b, S_UNI_ID(0))
2789 OP_SET_INJECT_WORD (C_UNI_ID(0) + 1, OSSL_QUIC_FRAME_TYPE_STREAM_DATA_BLOCKED)
2790 OP_S_WRITE (b, "orange", 5)
2792 OP_C_EXPECT_CONN_CLOSE_INFO(QUIC_ERR_STREAM_STATE_ERROR,0,0)
2797 /* 38. Fault injection - STREAM_DATA_BLOCKED for non-existent stream */
2798 static const struct script_op script_38[] = {
2799 OP_S_SET_INJECT_PLAIN (script_28_inject_plain)
2800 OP_C_SET_ALPN ("ossltest")
2801 OP_C_CONNECT_WAIT ()
2802 OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE)
2804 OP_S_NEW_STREAM_UNI (b, S_UNI_ID(0))
2805 OP_SET_INJECT_WORD (C_BIDI_ID(0) + 1, OSSL_QUIC_FRAME_TYPE_STREAM_DATA_BLOCKED)
2806 OP_S_WRITE (b, "orange", 5)
2808 OP_C_EXPECT_CONN_CLOSE_INFO(QUIC_ERR_STREAM_STATE_ERROR,0,0)
2813 /* 39. Fault injection - NEW_CONN_ID with zero-len CID */
2814 static int script_39_inject_plain(struct helper *h, QUIC_PKT_HDR *hdr,
2815 unsigned char *buf, size_t len)
2819 unsigned char frame_buf[64];
2822 if (h->inject_word1 == 0)
2825 if (!TEST_true(WPACKET_init_static_len(&wpkt, frame_buf,
2826 sizeof(frame_buf), 0)))
2829 if (!TEST_true(WPACKET_quic_write_vlint(&wpkt, OSSL_QUIC_FRAME_TYPE_NEW_CONN_ID))
2830 || !TEST_true(WPACKET_quic_write_vlint(&wpkt, 0)) /* seq no */
2831 || !TEST_true(WPACKET_quic_write_vlint(&wpkt, 0)) /* retire prior to */
2832 || !TEST_true(WPACKET_put_bytes_u8(&wpkt, 0))) /* len */
2835 for (i = 0; i < QUIC_STATELESS_RESET_TOKEN_LEN; ++i)
2836 if (!TEST_true(WPACKET_put_bytes_u8(&wpkt, 0x42)))
2839 if (!TEST_true(WPACKET_get_total_written(&wpkt, &written)))
2842 if (!qtest_fault_prepend_frame(h->qtf, frame_buf, written))
2848 WPACKET_finish(&wpkt);
2850 WPACKET_cleanup(&wpkt);
2854 static const struct script_op script_39[] = {
2855 OP_S_SET_INJECT_PLAIN (script_39_inject_plain)
2856 OP_C_SET_ALPN ("ossltest")
2857 OP_C_CONNECT_WAIT ()
2858 OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE)
2860 OP_C_NEW_STREAM_BIDI (a, C_BIDI_ID(0))
2861 OP_C_WRITE (a, "apple", 5)
2862 OP_S_BIND_STREAM_ID (a, C_BIDI_ID(0))
2863 OP_S_READ_EXPECT (a, "apple", 5)
2865 OP_SET_INJECT_WORD (0, 1)
2866 OP_S_WRITE (a, "orange", 5)
2868 OP_C_EXPECT_CONN_CLOSE_INFO(QUIC_ERR_FRAME_ENCODING_ERROR,0,0)
2873 /* 40. Shutdown flush test */
2874 static const unsigned char script_40_data[1024] = "strawberry";
2876 static const struct script_op script_40[] = {
2877 OP_C_SET_ALPN ("ossltest")
2878 OP_C_CONNECT_WAIT ()
2879 OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE)
2881 OP_C_NEW_STREAM_BIDI (a, C_BIDI_ID(0))
2882 OP_C_WRITE (a, "apple", 5)
2884 OP_C_INHIBIT_TICK (1)
2885 OP_C_SET_WRITE_BUF_SIZE (a, 1024 * 100 * 3)
2887 OP_BEGIN_REPEAT (100)
2889 OP_C_WRITE (a, script_40_data, sizeof(script_40_data))
2894 OP_C_SHUTDOWN_WAIT () /* disengages tick inhibition */
2896 OP_S_BIND_STREAM_ID (a, C_BIDI_ID(0))
2897 OP_S_READ_EXPECT (a, "apple", 5)
2899 OP_BEGIN_REPEAT (100)
2901 OP_S_READ_EXPECT (a, script_40_data, sizeof(script_40_data))
2907 OP_C_EXPECT_CONN_CLOSE_INFO(0, 1, 0)
2908 OP_S_EXPECT_CONN_CLOSE_INFO(0, 1, 1)
2913 /* 41. Fault injection - PATH_CHALLENGE yields PATH_RESPONSE */
2914 static const uint64_t path_challenge = UINT64_C(0xbdeb9451169c83aa);
2916 static int script_41_inject_plain(struct helper *h, QUIC_PKT_HDR *hdr,
2917 unsigned char *buf, size_t len)
2921 unsigned char frame_buf[16];
2924 if (h->inject_word0 == 0)
2927 if (!TEST_true(WPACKET_init_static_len(&wpkt, frame_buf,
2928 sizeof(frame_buf), 0)))
2931 if (!TEST_true(WPACKET_quic_write_vlint(&wpkt, OSSL_QUIC_FRAME_TYPE_PATH_CHALLENGE))
2932 || !TEST_true(WPACKET_put_bytes_u64(&wpkt, path_challenge)))
2935 if (!TEST_true(WPACKET_get_total_written(&wpkt, &written))
2936 || !TEST_size_t_eq(written, 9))
2939 if (!qtest_fault_prepend_frame(h->qtf, frame_buf, written))
2946 WPACKET_finish(&wpkt);
2948 WPACKET_cleanup(&wpkt);
2952 static void script_41_trace(int write_p, int version, int content_type,
2953 const void *buf, size_t len, SSL *ssl, void *arg)
2955 uint64_t frame_type, frame_data;
2957 struct helper *h = arg;
2960 if (version != OSSL_QUIC1_VERSION
2961 || content_type != SSL3_RT_QUIC_FRAME_FULL
2965 if (!TEST_true(PACKET_buf_init(&pkt, buf, len))) {
2970 if (!TEST_true(ossl_quic_wire_peek_frame_header(&pkt, &frame_type,
2976 if (frame_type != OSSL_QUIC_FRAME_TYPE_PATH_RESPONSE)
2979 if (!TEST_true(ossl_quic_wire_decode_frame_path_response(&pkt, &frame_data))
2980 || !TEST_uint64_t_eq(frame_data, path_challenge)) {
2988 static int script_41_setup(struct helper *h, const struct script_op *op)
2990 ossl_quic_tserver_set_msg_callback(h->s, script_41_trace, h);
2994 static int script_41_check(struct helper *h, const struct script_op *op)
2996 /* At least one valid challenge/response echo? */
2997 if (!TEST_uint64_t_gt(h->scratch0, 0))
3000 /* No failed tests? */
3001 if (!TEST_uint64_t_eq(h->scratch1, 0))
3007 static const struct script_op script_41[] = {
3008 OP_S_SET_INJECT_PLAIN (script_41_inject_plain)
3009 OP_C_SET_ALPN ("ossltest")
3010 OP_C_CONNECT_WAIT ()
3011 OP_CHECK (script_41_setup, 0)
3013 OP_C_WRITE (DEFAULT, "apple", 5)
3014 OP_S_BIND_STREAM_ID (a, C_BIDI_ID(0))
3015 OP_S_READ_EXPECT (a, "apple", 5)
3017 OP_SET_INJECT_WORD (1, 0)
3019 OP_S_WRITE (a, "orange", 6)
3020 OP_C_READ_EXPECT (DEFAULT, "orange", 6)
3022 OP_C_WRITE (DEFAULT, "strawberry", 10)
3023 OP_S_READ_EXPECT (a, "strawberry", 10)
3025 OP_CHECK (script_41_check, 0)
3029 /* 42. Fault injection - CRYPTO frame with illegal offset */
3030 static int script_42_inject_plain(struct helper *h, QUIC_PKT_HDR *hdr,
3031 unsigned char *buf, size_t len)
3034 unsigned char frame_buf[64];
3038 if (h->inject_word0 == 0)
3043 if (!TEST_true(WPACKET_init_static_len(&wpkt, frame_buf,
3044 sizeof(frame_buf), 0)))
3047 if (!TEST_true(WPACKET_quic_write_vlint(&wpkt, OSSL_QUIC_FRAME_TYPE_CRYPTO))
3048 || !TEST_true(WPACKET_quic_write_vlint(&wpkt, h->inject_word1))
3049 || !TEST_true(WPACKET_quic_write_vlint(&wpkt, 1))
3050 || !TEST_true(WPACKET_put_bytes_u8(&wpkt, 0x42)))
3053 if (!TEST_true(WPACKET_get_total_written(&wpkt, &written)))
3056 if (!qtest_fault_prepend_frame(h->qtf, frame_buf, written))
3062 WPACKET_finish(&wpkt);
3064 WPACKET_cleanup(&wpkt);
3068 static const struct script_op script_42[] = {
3069 OP_S_SET_INJECT_PLAIN (script_42_inject_plain)
3070 OP_C_SET_ALPN ("ossltest")
3071 OP_C_CONNECT_WAIT ()
3072 OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE)
3074 OP_C_NEW_STREAM_BIDI (a, C_BIDI_ID(0))
3075 OP_C_WRITE (a, "apple", 5)
3077 OP_S_BIND_STREAM_ID (a, C_BIDI_ID(0))
3078 OP_S_READ_EXPECT (a, "apple", 5)
3080 OP_SET_INJECT_WORD (1, (((uint64_t)1) << 62) - 1)
3081 OP_S_WRITE (a, "orange", 6)
3083 OP_C_EXPECT_CONN_CLOSE_INFO(QUIC_ERR_FRAME_ENCODING_ERROR,0,0)
3088 /* 43. Fault injection - CRYPTO frame exceeding FC */
3089 static const struct script_op script_43[] = {
3090 OP_S_SET_INJECT_PLAIN (script_42_inject_plain)
3091 OP_C_SET_ALPN ("ossltest")
3092 OP_C_CONNECT_WAIT ()
3093 OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE)
3095 OP_C_NEW_STREAM_BIDI (a, C_BIDI_ID(0))
3096 OP_C_WRITE (a, "apple", 5)
3098 OP_S_BIND_STREAM_ID (a, C_BIDI_ID(0))
3099 OP_S_READ_EXPECT (a, "apple", 5)
3101 OP_SET_INJECT_WORD (1, 0x100000 /* 1 MiB */)
3102 OP_S_WRITE (a, "orange", 6)
3104 OP_C_EXPECT_CONN_CLOSE_INFO(QUIC_ERR_CRYPTO_BUFFER_EXCEEDED,0,0)
3109 static const struct script_op *const scripts[] = {
3155 static int test_script(int idx)
3157 int script_idx = idx >> 1;
3158 int free_order = idx & 1;
3159 char script_name[64];
3161 snprintf(script_name, sizeof(script_name), "script %d", script_idx + 1);
3163 TEST_info("Running script %d (order=%d)", script_idx + 1, free_order);
3164 return run_script(scripts[script_idx], script_name, free_order);
3167 /* Dynamically generated tests. */
3168 static struct script_op dyn_frame_types_script[] = {
3169 OP_S_SET_INJECT_PLAIN (script_21_inject_plain)
3170 OP_SET_INJECT_WORD (0, 0) /* dynamic */
3172 OP_C_SET_ALPN ("ossltest")
3173 OP_C_CONNECT_WAIT_OR_FAIL()
3175 OP_C_EXPECT_CONN_CLOSE_INFO(QUIC_ERR_FRAME_ENCODING_ERROR,0,0)
3180 struct forbidden_frame_type {
3181 uint64_t pkt_type, frame_type, expected_err;
3184 static const struct forbidden_frame_type forbidden_frame_types[] = {
3185 { QUIC_PKT_TYPE_INITIAL, OSSL_QUIC_VLINT_MAX, QUIC_ERR_FRAME_ENCODING_ERROR },
3186 { QUIC_PKT_TYPE_HANDSHAKE, OSSL_QUIC_VLINT_MAX, QUIC_ERR_FRAME_ENCODING_ERROR },
3187 { QUIC_PKT_TYPE_1RTT, OSSL_QUIC_VLINT_MAX, QUIC_ERR_FRAME_ENCODING_ERROR },
3189 { QUIC_PKT_TYPE_INITIAL, OSSL_QUIC_FRAME_TYPE_STREAM, QUIC_ERR_PROTOCOL_VIOLATION },
3190 { QUIC_PKT_TYPE_INITIAL, OSSL_QUIC_FRAME_TYPE_RESET_STREAM, QUIC_ERR_PROTOCOL_VIOLATION },
3191 { QUIC_PKT_TYPE_INITIAL, OSSL_QUIC_FRAME_TYPE_STOP_SENDING, QUIC_ERR_PROTOCOL_VIOLATION },
3192 { QUIC_PKT_TYPE_INITIAL, OSSL_QUIC_FRAME_TYPE_NEW_TOKEN, QUIC_ERR_PROTOCOL_VIOLATION },
3193 { QUIC_PKT_TYPE_INITIAL, OSSL_QUIC_FRAME_TYPE_MAX_DATA, QUIC_ERR_PROTOCOL_VIOLATION },
3194 { QUIC_PKT_TYPE_INITIAL, OSSL_QUIC_FRAME_TYPE_MAX_STREAM_DATA, QUIC_ERR_PROTOCOL_VIOLATION },
3195 { QUIC_PKT_TYPE_INITIAL, OSSL_QUIC_FRAME_TYPE_MAX_STREAMS_BIDI, QUIC_ERR_PROTOCOL_VIOLATION },
3196 { QUIC_PKT_TYPE_INITIAL, OSSL_QUIC_FRAME_TYPE_MAX_STREAMS_UNI, QUIC_ERR_PROTOCOL_VIOLATION },
3197 { QUIC_PKT_TYPE_INITIAL, OSSL_QUIC_FRAME_TYPE_DATA_BLOCKED, QUIC_ERR_PROTOCOL_VIOLATION },
3198 { QUIC_PKT_TYPE_INITIAL, OSSL_QUIC_FRAME_TYPE_STREAM_DATA_BLOCKED, QUIC_ERR_PROTOCOL_VIOLATION },
3199 { QUIC_PKT_TYPE_INITIAL, OSSL_QUIC_FRAME_TYPE_STREAMS_BLOCKED_BIDI, QUIC_ERR_PROTOCOL_VIOLATION },
3200 { QUIC_PKT_TYPE_INITIAL, OSSL_QUIC_FRAME_TYPE_STREAMS_BLOCKED_UNI, QUIC_ERR_PROTOCOL_VIOLATION },
3201 { QUIC_PKT_TYPE_INITIAL, OSSL_QUIC_FRAME_TYPE_NEW_CONN_ID, QUIC_ERR_PROTOCOL_VIOLATION },
3202 { QUIC_PKT_TYPE_INITIAL, OSSL_QUIC_FRAME_TYPE_RETIRE_CONN_ID, QUIC_ERR_PROTOCOL_VIOLATION },
3203 { QUIC_PKT_TYPE_INITIAL, OSSL_QUIC_FRAME_TYPE_PATH_CHALLENGE, QUIC_ERR_PROTOCOL_VIOLATION },
3204 { QUIC_PKT_TYPE_INITIAL, OSSL_QUIC_FRAME_TYPE_PATH_RESPONSE, QUIC_ERR_PROTOCOL_VIOLATION },
3205 { QUIC_PKT_TYPE_INITIAL, OSSL_QUIC_FRAME_TYPE_CONN_CLOSE_APP, QUIC_ERR_PROTOCOL_VIOLATION },
3206 { QUIC_PKT_TYPE_INITIAL, OSSL_QUIC_FRAME_TYPE_HANDSHAKE_DONE, QUIC_ERR_PROTOCOL_VIOLATION },
3208 { QUIC_PKT_TYPE_HANDSHAKE, OSSL_QUIC_FRAME_TYPE_STREAM, QUIC_ERR_PROTOCOL_VIOLATION },
3209 { QUIC_PKT_TYPE_HANDSHAKE, OSSL_QUIC_FRAME_TYPE_RESET_STREAM, QUIC_ERR_PROTOCOL_VIOLATION },
3210 { QUIC_PKT_TYPE_HANDSHAKE, OSSL_QUIC_FRAME_TYPE_STOP_SENDING, QUIC_ERR_PROTOCOL_VIOLATION },
3211 { QUIC_PKT_TYPE_HANDSHAKE, OSSL_QUIC_FRAME_TYPE_NEW_TOKEN, QUIC_ERR_PROTOCOL_VIOLATION },
3212 { QUIC_PKT_TYPE_HANDSHAKE, OSSL_QUIC_FRAME_TYPE_MAX_DATA, QUIC_ERR_PROTOCOL_VIOLATION },
3213 { QUIC_PKT_TYPE_HANDSHAKE, OSSL_QUIC_FRAME_TYPE_MAX_STREAM_DATA, QUIC_ERR_PROTOCOL_VIOLATION },
3214 { QUIC_PKT_TYPE_HANDSHAKE, OSSL_QUIC_FRAME_TYPE_MAX_STREAMS_BIDI, QUIC_ERR_PROTOCOL_VIOLATION },
3215 { QUIC_PKT_TYPE_HANDSHAKE, OSSL_QUIC_FRAME_TYPE_MAX_STREAMS_UNI, QUIC_ERR_PROTOCOL_VIOLATION },
3216 { QUIC_PKT_TYPE_HANDSHAKE, OSSL_QUIC_FRAME_TYPE_DATA_BLOCKED, QUIC_ERR_PROTOCOL_VIOLATION },
3217 { QUIC_PKT_TYPE_HANDSHAKE, OSSL_QUIC_FRAME_TYPE_STREAM_DATA_BLOCKED, QUIC_ERR_PROTOCOL_VIOLATION },
3218 { QUIC_PKT_TYPE_HANDSHAKE, OSSL_QUIC_FRAME_TYPE_STREAMS_BLOCKED_BIDI, QUIC_ERR_PROTOCOL_VIOLATION },
3219 { QUIC_PKT_TYPE_HANDSHAKE, OSSL_QUIC_FRAME_TYPE_STREAMS_BLOCKED_UNI, QUIC_ERR_PROTOCOL_VIOLATION },
3220 { QUIC_PKT_TYPE_HANDSHAKE, OSSL_QUIC_FRAME_TYPE_NEW_CONN_ID, QUIC_ERR_PROTOCOL_VIOLATION },
3221 { QUIC_PKT_TYPE_HANDSHAKE, OSSL_QUIC_FRAME_TYPE_RETIRE_CONN_ID, QUIC_ERR_PROTOCOL_VIOLATION },
3222 { QUIC_PKT_TYPE_HANDSHAKE, OSSL_QUIC_FRAME_TYPE_PATH_CHALLENGE, QUIC_ERR_PROTOCOL_VIOLATION },
3223 { QUIC_PKT_TYPE_HANDSHAKE, OSSL_QUIC_FRAME_TYPE_PATH_RESPONSE, QUIC_ERR_PROTOCOL_VIOLATION },
3224 { QUIC_PKT_TYPE_HANDSHAKE, OSSL_QUIC_FRAME_TYPE_CONN_CLOSE_APP, QUIC_ERR_PROTOCOL_VIOLATION },
3225 { QUIC_PKT_TYPE_HANDSHAKE, OSSL_QUIC_FRAME_TYPE_HANDSHAKE_DONE, QUIC_ERR_PROTOCOL_VIOLATION },
3227 /* Client uses a zero-length CID so this is not allowed. */
3228 { QUIC_PKT_TYPE_1RTT, OSSL_QUIC_FRAME_TYPE_RETIRE_CONN_ID, QUIC_ERR_PROTOCOL_VIOLATION },
3231 static ossl_unused int test_dyn_frame_types(int idx)
3234 char script_name[64];
3235 struct script_op *s = dyn_frame_types_script;
3237 for (i = 0; i < OSSL_NELEM(dyn_frame_types_script); ++i)
3238 if (s[i].op == OPK_SET_INJECT_WORD) {
3239 s[i].arg1 = (size_t)forbidden_frame_types[idx].pkt_type;
3240 s[i].arg2 = forbidden_frame_types[idx].frame_type;
3241 } else if (s[i].op == OPK_C_EXPECT_CONN_CLOSE_INFO) {
3242 s[i].arg2 = forbidden_frame_types[idx].expected_err;
3245 snprintf(script_name, sizeof(script_name),
3246 "dyn script %d", idx);
3248 return run_script(dyn_frame_types_script, script_name, 0);
3251 OPT_TEST_DECLARE_USAGE("certfile privkeyfile\n")
3253 int setup_tests(void)
3255 if (!test_skip_common_options()) {
3256 TEST_error("Error parsing test options\n");
3260 if (!TEST_ptr(certfile = test_get_argument(0))
3261 || !TEST_ptr(keyfile = test_get_argument(1)))
3264 ADD_ALL_TESTS(test_dyn_frame_types, OSSL_NELEM(forbidden_frame_types));
3265 ADD_ALL_TESTS(test_script, OSSL_NELEM(scripts) * 2);