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 <openssl/rand.h>
14 #include "internal/quic_tserver.h"
15 #include "internal/quic_ssl.h"
16 #include "internal/quic_error.h"
17 #include "internal/quic_stream_map.h"
18 #include "internal/quic_engine.h"
20 #include "helpers/quictestlib.h"
21 #if defined(OPENSSL_THREADS)
22 # include "internal/thread_arch.h"
24 #include "internal/numbers.h" /* UINT64_C */
26 static const char *certfile
, *keyfile
;
28 #if defined(OPENSSL_THREADS)
29 struct child_thread_args
{
31 const struct script_op
*script
;
32 const char *script_name
;
43 typedef struct stream_info
{
49 DEFINE_LHASH_OF_EX(STREAM_INFO
);
53 BIO
*s_net_bio
, *s_net_bio_own
, *s_qtf_wbio
, *s_qtf_wbio_own
;
54 /* The BIO_ADDR used for BIO_bind() */
55 BIO_ADDR
*s_net_bio_orig_addr
;
56 /* The resulting address, which is the one to connect to */
57 BIO_ADDR
*s_net_bio_addr
;
60 * When doing a blocking mode test run, s_priv always points to the TSERVER
61 * and s is NULL when the main thread should not be touching s_priv.
63 QUIC_TSERVER
*s
, *s_priv
;
64 LHASH_OF(STREAM_INFO
) *s_streams
;
67 BIO
*c_net_bio
, *c_net_bio_own
;
70 LHASH_OF(STREAM_INFO
) *c_streams
;
72 #if defined(OPENSSL_THREADS)
73 struct child_thread_args
*threads
;
76 CRYPTO_CONDVAR
*misc_cv
;
82 * This is a duration recording the amount of time we have skipped forwards
83 * for testing purposes relative to the real ossl_time_now() clock. We add
84 * a quantity of time to this every time we skip some time.
86 CRYPTO_RWLOCK
*time_lock
;
87 OSSL_TIME time_slip
; /* protected by time_lock */
91 int init
, blocking
, check_spin_again
;
92 int free_order
, need_injector
;
94 int (*qtf_packet_plain_cb
)(struct helper
*h
, QUIC_PKT_HDR
*hdr
,
95 unsigned char *buf
, size_t buf_len
);
96 int (*qtf_handshake_cb
)(struct helper
*h
,
97 unsigned char *buf
, size_t buf_len
);
98 int (*qtf_datagram_cb
)(struct helper
*h
,
99 BIO_MSG
*m
, size_t stride
);
100 uint64_t inject_word0
, inject_word1
;
101 uint64_t scratch0
, scratch1
, fail_count
;
102 #if defined(OPENSSL_THREADS)
113 struct helper_local
{
115 LHASH_OF(STREAM_INFO
) *c_streams
;
117 const struct script_op
*check_op
;
124 int (*check_func
)(struct helper
*h
, struct helper_local
*hl
);
125 const char *stream_name
;
127 int (*qtf_packet_plain_cb
)(struct helper
*h
, QUIC_PKT_HDR
*hdr
,
128 unsigned char *buf
, size_t buf_len
);
129 int (*qtf_handshake_cb
)(struct helper
*h
,
130 unsigned char *buf
, size_t buf_len
);
131 int (*qtf_datagram_cb
)(struct helper
*h
,
132 BIO_MSG
*m
, size_t stride
);
137 #define OPK_C_SET_ALPN 2
138 #define OPK_C_CONNECT_WAIT 3
139 #define OPK_C_WRITE 4
140 #define OPK_S_WRITE 5
141 #define OPK_C_READ_EXPECT 6
142 #define OPK_S_READ_EXPECT 7
143 #define OPK_C_EXPECT_FIN 8
144 #define OPK_S_EXPECT_FIN 9
145 #define OPK_C_CONCLUDE 10
146 #define OPK_S_CONCLUDE 11
147 #define OPK_C_DETACH 12
148 #define OPK_C_ATTACH 13
149 #define OPK_C_NEW_STREAM 14
150 #define OPK_S_NEW_STREAM 15
151 #define OPK_C_ACCEPT_STREAM_WAIT 16
152 #define OPK_C_ACCEPT_STREAM_NONE 17
153 #define OPK_C_FREE_STREAM 18
154 #define OPK_C_SET_DEFAULT_STREAM_MODE 19
155 #define OPK_C_SET_INCOMING_STREAM_POLICY 20
156 #define OPK_C_SHUTDOWN_WAIT 21
157 #define OPK_C_EXPECT_CONN_CLOSE_INFO 22
158 #define OPK_S_EXPECT_CONN_CLOSE_INFO 23
159 #define OPK_S_BIND_STREAM_ID 24
160 #define OPK_C_WAIT_FOR_DATA 25
161 #define OPK_C_WRITE_FAIL 26
162 #define OPK_S_WRITE_FAIL 27
163 #define OPK_C_READ_FAIL 28
164 #define OPK_C_STREAM_RESET 29
165 #define OPK_S_ACCEPT_STREAM_WAIT 30
166 #define OPK_NEW_THREAD 31
167 #define OPK_BEGIN_REPEAT 32
168 #define OPK_END_REPEAT 33
169 #define OPK_S_UNBIND_STREAM_ID 34
170 #define OPK_C_READ_FAIL_WAIT 35
171 #define OPK_C_CLOSE_SOCKET 36
172 #define OPK_C_EXPECT_SSL_ERR 37
173 #define OPK_EXPECT_ERR_REASON 38
174 #define OPK_EXPECT_ERR_LIB 39
176 #define OPK_S_READ_FAIL 41
177 #define OPK_S_SET_INJECT_PLAIN 42
178 #define OPK_SET_INJECT_WORD 43
179 #define OPK_C_INHIBIT_TICK 44
180 #define OPK_C_SET_WRITE_BUF_SIZE 45
181 #define OPK_S_SET_INJECT_HANDSHAKE 46
182 #define OPK_S_NEW_TICKET 47
183 #define OPK_C_SKIP_IF_UNBOUND 48
184 #define OPK_S_SET_INJECT_DATAGRAM 49
185 #define OPK_S_SHUTDOWN 50
186 #define OPK_POP_ERR 51
187 #define OPK_C_WRITE_EX2 52
189 #define EXPECT_CONN_CLOSE_APP (1U << 0)
190 #define EXPECT_CONN_CLOSE_REMOTE (1U << 1)
192 /* OPK_C_NEW_STREAM */
193 #define ALLOW_FAIL (1U << 16)
195 #define C_BIDI_ID(ordinal) \
196 (((ordinal) << 2) | QUIC_STREAM_INITIATOR_CLIENT | QUIC_STREAM_DIR_BIDI)
197 #define S_BIDI_ID(ordinal) \
198 (((ordinal) << 2) | QUIC_STREAM_INITIATOR_SERVER | QUIC_STREAM_DIR_BIDI)
199 #define C_UNI_ID(ordinal) \
200 (((ordinal) << 2) | QUIC_STREAM_INITIATOR_CLIENT | QUIC_STREAM_DIR_UNI)
201 #define S_UNI_ID(ordinal) \
202 (((ordinal) << 2) | QUIC_STREAM_INITIATOR_SERVER | QUIC_STREAM_DIR_UNI)
204 #define ANY_ID UINT64_MAX
208 #define OP_CHECK(func, arg2) \
209 {OPK_CHECK, NULL, 0, (func), NULL, (arg2)},
210 #define OP_C_SET_ALPN(alpn) \
211 {OPK_C_SET_ALPN, (alpn), 0, NULL, NULL},
212 #define OP_C_CONNECT_WAIT() \
213 {OPK_C_CONNECT_WAIT, NULL, 0, NULL, NULL},
214 #define OP_C_CONNECT_WAIT_OR_FAIL() \
215 {OPK_C_CONNECT_WAIT, NULL, 1, NULL, NULL},
216 #define OP_C_WRITE(stream_name, buf, buf_len) \
217 {OPK_C_WRITE, (buf), (buf_len), NULL, #stream_name},
218 #define OP_S_WRITE(stream_name, buf, buf_len) \
219 {OPK_S_WRITE, (buf), (buf_len), NULL, #stream_name},
220 #define OP_C_READ_EXPECT(stream_name, buf, buf_len) \
221 {OPK_C_READ_EXPECT, (buf), (buf_len), NULL, #stream_name},
222 #define OP_S_READ_EXPECT(stream_name, buf, buf_len) \
223 {OPK_S_READ_EXPECT, (buf), (buf_len), NULL, #stream_name},
224 #define OP_C_EXPECT_FIN(stream_name) \
225 {OPK_C_EXPECT_FIN, NULL, 0, NULL, #stream_name},
226 #define OP_S_EXPECT_FIN(stream_name) \
227 {OPK_S_EXPECT_FIN, NULL, 0, NULL, #stream_name},
228 #define OP_C_CONCLUDE(stream_name) \
229 {OPK_C_CONCLUDE, NULL, 0, NULL, #stream_name},
230 #define OP_S_CONCLUDE(stream_name) \
231 {OPK_S_CONCLUDE, NULL, 0, NULL, #stream_name},
232 #define OP_C_DETACH(stream_name) \
233 {OPK_C_DETACH, NULL, 0, NULL, #stream_name},
234 #define OP_C_ATTACH(stream_name) \
235 {OPK_C_ATTACH, NULL, 0, NULL, #stream_name},
236 #define OP_C_NEW_STREAM_BIDI(stream_name, expect_id) \
237 {OPK_C_NEW_STREAM, NULL, 0, NULL, #stream_name, (expect_id)},
238 #define OP_C_NEW_STREAM_BIDI_EX(stream_name, expect_id, flags) \
239 {OPK_C_NEW_STREAM, NULL, (flags), NULL, #stream_name, (expect_id)},
240 #define OP_C_NEW_STREAM_UNI(stream_name, expect_id) \
241 {OPK_C_NEW_STREAM, NULL, SSL_STREAM_FLAG_UNI, \
242 NULL, #stream_name, (expect_id)},
243 #define OP_C_NEW_STREAM_UNI_EX(stream_name, expect_id, flags) \
244 {OPK_C_NEW_STREAM, NULL, (flags) | SSL_STREAM_FLAG_UNI, \
245 NULL, #stream_name, (expect_id)},
246 #define OP_S_NEW_STREAM_BIDI(stream_name, expect_id) \
247 {OPK_S_NEW_STREAM, NULL, 0, NULL, #stream_name, (expect_id)},
248 #define OP_S_NEW_STREAM_UNI(stream_name, expect_id) \
249 {OPK_S_NEW_STREAM, NULL, 1, NULL, #stream_name, (expect_id)},
250 #define OP_C_ACCEPT_STREAM_WAIT(stream_name) \
251 {OPK_C_ACCEPT_STREAM_WAIT, NULL, 0, NULL, #stream_name},
252 #define OP_C_ACCEPT_STREAM_NONE() \
253 {OPK_C_ACCEPT_STREAM_NONE, NULL, 0, NULL, NULL},
254 #define OP_C_FREE_STREAM(stream_name) \
255 {OPK_C_FREE_STREAM, NULL, 0, NULL, #stream_name},
256 #define OP_C_SET_DEFAULT_STREAM_MODE(mode) \
257 {OPK_C_SET_DEFAULT_STREAM_MODE, NULL, (mode), NULL, NULL},
258 #define OP_C_SET_INCOMING_STREAM_POLICY(policy) \
259 {OPK_C_SET_INCOMING_STREAM_POLICY, NULL, (policy), NULL, NULL},
260 #define OP_C_SHUTDOWN_WAIT(reason, flags) \
261 {OPK_C_SHUTDOWN_WAIT, (reason), (flags), NULL, NULL},
262 #define OP_C_EXPECT_CONN_CLOSE_INFO(ec, app, remote) \
263 {OPK_C_EXPECT_CONN_CLOSE_INFO, NULL, \
264 ((app) ? EXPECT_CONN_CLOSE_APP : 0) | \
265 ((remote) ? EXPECT_CONN_CLOSE_REMOTE : 0), \
267 #define OP_S_EXPECT_CONN_CLOSE_INFO(ec, app, remote) \
268 {OPK_S_EXPECT_CONN_CLOSE_INFO, NULL, \
269 ((app) ? EXPECT_CONN_CLOSE_APP : 0) | \
270 ((remote) ? EXPECT_CONN_CLOSE_REMOTE : 0), \
272 #define OP_S_BIND_STREAM_ID(stream_name, stream_id) \
273 {OPK_S_BIND_STREAM_ID, NULL, 0, NULL, #stream_name, (stream_id)},
274 #define OP_C_WAIT_FOR_DATA(stream_name) \
275 {OPK_C_WAIT_FOR_DATA, NULL, 0, NULL, #stream_name},
276 #define OP_C_WRITE_FAIL(stream_name) \
277 {OPK_C_WRITE_FAIL, NULL, 0, NULL, #stream_name},
278 #define OP_S_WRITE_FAIL(stream_name) \
279 {OPK_S_WRITE_FAIL, NULL, 0, NULL, #stream_name},
280 #define OP_C_READ_FAIL(stream_name) \
281 {OPK_C_READ_FAIL, NULL, 0, NULL, #stream_name},
282 #define OP_S_READ_FAIL(stream_name) \
283 {OPK_S_READ_FAIL, NULL, 0, NULL, #stream_name},
284 #define OP_C_STREAM_RESET(stream_name, aec) \
285 {OPK_C_STREAM_RESET, NULL, 0, NULL, #stream_name, (aec)},
286 #define OP_S_ACCEPT_STREAM_WAIT(stream_name) \
287 {OPK_S_ACCEPT_STREAM_WAIT, NULL, 0, NULL, #stream_name},
288 #define OP_NEW_THREAD(num_threads, script) \
289 {OPK_NEW_THREAD, (script), (num_threads), NULL, NULL, 0 },
290 #define OP_BEGIN_REPEAT(n) \
291 {OPK_BEGIN_REPEAT, NULL, (n)},
292 #define OP_END_REPEAT() \
294 #define OP_S_UNBIND_STREAM_ID(stream_name) \
295 {OPK_S_UNBIND_STREAM_ID, NULL, 0, NULL, #stream_name},
296 #define OP_C_READ_FAIL_WAIT(stream_name) \
297 {OPK_C_READ_FAIL_WAIT, NULL, 0, NULL, #stream_name},
298 #define OP_C_CLOSE_SOCKET() \
299 {OPK_C_CLOSE_SOCKET},
300 #define OP_C_EXPECT_SSL_ERR(stream_name, err) \
301 {OPK_C_EXPECT_SSL_ERR, NULL, (err), NULL, #stream_name},
302 #define OP_EXPECT_ERR_REASON(err) \
303 {OPK_EXPECT_ERR_REASON, NULL, (err)},
304 #define OP_EXPECT_ERR_LIB(lib) \
305 {OPK_EXPECT_ERR_LIB, NULL, (lib)},
306 #define OP_SLEEP(ms) \
307 {OPK_SLEEP, NULL, 0, NULL, NULL, (ms)},
308 #define OP_S_SET_INJECT_PLAIN(f) \
309 {OPK_S_SET_INJECT_PLAIN, NULL, 0, NULL, NULL, 0, (f)},
310 #define OP_SET_INJECT_WORD(w0, w1) \
311 {OPK_SET_INJECT_WORD, NULL, (w0), NULL, NULL, (w1), NULL},
312 #define OP_C_INHIBIT_TICK(inhibit) \
313 {OPK_C_INHIBIT_TICK, NULL, (inhibit), NULL, NULL, 0, NULL},
314 #define OP_C_SET_WRITE_BUF_SIZE(stream_name, size) \
315 {OPK_C_SET_WRITE_BUF_SIZE, NULL, (size), NULL, #stream_name},
316 #define OP_S_SET_INJECT_HANDSHAKE(f) \
317 {OPK_S_SET_INJECT_HANDSHAKE, NULL, 0, NULL, NULL, 0, NULL, (f)},
318 #define OP_S_NEW_TICKET() \
320 #define OP_C_SKIP_IF_UNBOUND(stream_name, n) \
321 {OPK_C_SKIP_IF_UNBOUND, NULL, (n), NULL, #stream_name},
322 #define OP_S_SET_INJECT_DATAGRAM(f) \
323 {OPK_S_SET_INJECT_DATAGRAM, NULL, 0, NULL, NULL, 0, NULL, NULL, (f)},
324 #define OP_S_SHUTDOWN(error_code) \
325 {OPK_S_SHUTDOWN, NULL, (error_code)},
326 #define OP_POP_ERR() \
328 #define OP_C_WRITE_EX2(stream_name, buf, buf_len, flags) \
329 {OPK_C_WRITE_EX2, (buf), (buf_len), NULL, #stream_name, (flags)},
330 #define OP_CHECK2(func, arg1, arg2) \
331 {OPK_CHECK, NULL, (arg1), (func), NULL, (arg2)},
333 static OSSL_TIME
get_time(void *arg
)
335 struct helper
*h
= arg
;
338 if (!TEST_true(CRYPTO_THREAD_read_lock(h
->time_lock
)))
339 return ossl_time_zero();
341 t
= ossl_time_add(ossl_time_now(), h
->time_slip
);
343 CRYPTO_THREAD_unlock(h
->time_lock
);
347 static int skip_time_ms(struct helper
*h
, struct helper_local
*hl
)
349 if (!TEST_true(CRYPTO_THREAD_write_lock(h
->time_lock
)))
352 h
->time_slip
= ossl_time_add(h
->time_slip
, ossl_ms2time(hl
->check_op
->arg2
));
354 CRYPTO_THREAD_unlock(h
->time_lock
);
358 static QUIC_TSERVER
*s_lock(struct helper
*h
, struct helper_local
*hl
);
359 static void s_unlock(struct helper
*h
, struct helper_local
*hl
);
361 #define ACQUIRE_S() s_lock(h, hl)
362 #define ACQUIRE_S_NOHL() s_lock(h, NULL)
364 static int check_rejected(struct helper
*h
, struct helper_local
*hl
)
366 uint64_t stream_id
= hl
->check_op
->arg2
;
368 if (!ossl_quic_tserver_stream_has_peer_stop_sending(ACQUIRE_S(), stream_id
, NULL
)
369 || !ossl_quic_tserver_stream_has_peer_reset_stream(ACQUIRE_S(), stream_id
, NULL
)) {
370 h
->check_spin_again
= 1;
377 static int check_stream_reset(struct helper
*h
, struct helper_local
*hl
)
379 uint64_t stream_id
= hl
->check_op
->arg2
, aec
= 0;
381 if (!ossl_quic_tserver_stream_has_peer_reset_stream(ACQUIRE_S(), stream_id
, &aec
)) {
382 h
->check_spin_again
= 1;
386 return TEST_uint64_t_eq(aec
, 42);
389 static int check_stream_stopped(struct helper
*h
, struct helper_local
*hl
)
391 uint64_t stream_id
= hl
->check_op
->arg2
;
393 if (!ossl_quic_tserver_stream_has_peer_stop_sending(ACQUIRE_S(), stream_id
, NULL
)) {
394 h
->check_spin_again
= 1;
401 static int override_key_update(struct helper
*h
, struct helper_local
*hl
)
403 QUIC_CHANNEL
*ch
= ossl_quic_conn_get_channel(h
->c_conn
);
405 ossl_quic_channel_set_txku_threshold_override(ch
, hl
->check_op
->arg2
);
409 static int trigger_key_update(struct helper
*h
, struct helper_local
*hl
)
411 if (!TEST_true(SSL_key_update(h
->c_conn
, SSL_KEY_UPDATE_REQUESTED
)))
417 static int check_key_update_ge(struct helper
*h
, struct helper_local
*hl
)
419 QUIC_CHANNEL
*ch
= ossl_quic_conn_get_channel(h
->c_conn
);
420 int64_t txke
= (int64_t)ossl_quic_channel_get_tx_key_epoch(ch
);
421 int64_t rxke
= (int64_t)ossl_quic_channel_get_rx_key_epoch(ch
);
422 int64_t diff
= txke
- rxke
;
425 * TXKE must always be equal to or ahead of RXKE.
426 * It can be ahead of RXKE by at most 1.
428 if (!TEST_int64_t_ge(diff
, 0) || !TEST_int64_t_le(diff
, 1))
431 /* Caller specifies a minimum number of RXKEs which must have happened. */
432 if (!TEST_uint64_t_ge((uint64_t)rxke
, hl
->check_op
->arg2
))
438 static int check_key_update_lt(struct helper
*h
, struct helper_local
*hl
)
440 QUIC_CHANNEL
*ch
= ossl_quic_conn_get_channel(h
->c_conn
);
441 uint64_t txke
= ossl_quic_channel_get_tx_key_epoch(ch
);
443 /* Caller specifies a maximum number of TXKEs which must have happened. */
444 if (!TEST_uint64_t_lt(txke
, hl
->check_op
->arg2
))
450 static unsigned long stream_info_hash(const STREAM_INFO
*info
)
452 return OPENSSL_LH_strhash(info
->name
);
455 static int stream_info_cmp(const STREAM_INFO
*a
, const STREAM_INFO
*b
)
457 return strcmp(a
->name
, b
->name
);
460 static void cleanup_stream(STREAM_INFO
*info
)
462 SSL_free(info
->c_stream
);
466 static void helper_cleanup_streams(LHASH_OF(STREAM_INFO
) **lh
)
471 lh_STREAM_INFO_doall(*lh
, cleanup_stream
);
472 lh_STREAM_INFO_free(*lh
);
476 #if defined(OPENSSL_THREADS)
477 static CRYPTO_THREAD_RETVAL
run_script_child_thread(void *arg
);
479 static int join_threads(struct child_thread_args
*threads
, size_t num_threads
)
483 CRYPTO_THREAD_RETVAL rv
;
485 for (i
= 0; i
< num_threads
; ++i
) {
486 if (threads
[i
].t
!= NULL
) {
487 ossl_crypto_thread_native_join(threads
[i
].t
, &rv
);
489 if (!threads
[i
].testresult
)
490 /* Do not log failure here, worker will do it. */
493 ossl_crypto_thread_native_clean(threads
[i
].t
);
497 ossl_crypto_mutex_free(&threads
[i
].m
);
503 static int join_server_thread(struct helper
*h
)
505 CRYPTO_THREAD_RETVAL rv
;
507 if (h
->server_thread
.t
== NULL
)
510 ossl_crypto_mutex_lock(h
->server_thread
.m
);
511 h
->server_thread
.stop
= 1;
512 ossl_crypto_condvar_signal(h
->server_thread
.c
);
513 ossl_crypto_mutex_unlock(h
->server_thread
.m
);
515 ossl_crypto_thread_native_join(h
->server_thread
.t
, &rv
);
516 ossl_crypto_thread_native_clean(h
->server_thread
.t
);
517 h
->server_thread
.t
= NULL
;
521 /* Ensure the server-state lock is currently held. Idempotent. */
522 static int *s_checked_out_p(struct helper
*h
, int thread_idx
)
524 return (thread_idx
< 0) ? &h
->s_checked_out
525 : &h
->threads
[thread_idx
].s_checked_out
;
528 static QUIC_TSERVER
*s_lock(struct helper
*h
, struct helper_local
*hl
)
530 int *p_checked_out
= s_checked_out_p(h
, hl
== NULL
? -1 : hl
->thread_idx
);
532 if (h
->server_thread
.m
== NULL
|| *p_checked_out
)
535 ossl_crypto_mutex_lock(h
->server_thread
.m
);
541 /* Ensure the server-state lock is currently not held. Idempotent. */
542 static void s_unlock(struct helper
*h
, struct helper_local
*hl
)
544 int *p_checked_out
= s_checked_out_p(h
, hl
->thread_idx
);
546 if (h
->server_thread
.m
== NULL
|| !*p_checked_out
)
551 ossl_crypto_mutex_unlock(h
->server_thread
.m
);
554 static unsigned int server_helper_thread(void *arg
)
556 struct helper
*h
= arg
;
558 ossl_crypto_mutex_lock(h
->server_thread
.m
);
563 ready
= h
->server_thread
.ready
;
564 stop
= h
->server_thread
.stop
;
570 ossl_crypto_condvar_wait(h
->server_thread
.c
, h
->server_thread
.m
);
574 ossl_quic_tserver_tick(h
->s_priv
);
575 ossl_crypto_mutex_unlock(h
->server_thread
.m
);
577 * Give the main thread an opportunity to get the mutex, which is
578 * sometimes necessary in some script operations.
581 ossl_crypto_mutex_lock(h
->server_thread
.m
);
584 ossl_crypto_mutex_unlock(h
->server_thread
.m
);
590 static QUIC_TSERVER
*s_lock(struct helper
*h
, struct helper_local
*hl
)
595 static void s_unlock(struct helper
*h
, struct helper_local
*hl
)
600 static void helper_cleanup(struct helper
*h
)
602 #if defined(OPENSSL_THREADS)
603 join_threads(h
->threads
, h
->num_threads
);
604 join_server_thread(h
);
605 OPENSSL_free(h
->threads
);
610 if (h
->free_order
== 0) {
611 /* order 0: streams, then conn */
612 helper_cleanup_streams(&h
->c_streams
);
617 /* order 1: conn, then streams */
621 helper_cleanup_streams(&h
->c_streams
);
624 helper_cleanup_streams(&h
->s_streams
);
625 ossl_quic_tserver_free(h
->s_priv
);
626 h
->s_priv
= h
->s
= NULL
;
628 BIO_free(h
->s_net_bio_own
);
629 h
->s_net_bio_own
= NULL
;
631 BIO_free(h
->c_net_bio_own
);
632 h
->c_net_bio_own
= NULL
;
634 BIO_free(h
->s_qtf_wbio_own
);
635 h
->s_qtf_wbio_own
= NULL
;
637 qtest_fault_free(h
->qtf
);
641 BIO_closesocket(h
->s_fd
);
646 BIO_closesocket(h
->c_fd
);
650 BIO_ADDR_free(h
->s_net_bio_addr
);
651 h
->s_net_bio_addr
= NULL
;
652 BIO_ADDR_free(h
->s_net_bio_orig_addr
);
653 h
->s_net_bio_orig_addr
= NULL
;
655 SSL_CTX_free(h
->c_ctx
);
658 CRYPTO_THREAD_lock_free(h
->time_lock
);
661 #if defined(OPENSSL_THREADS)
662 ossl_crypto_mutex_free(&h
->misc_m
);
663 ossl_crypto_condvar_free(&h
->misc_cv
);
664 ossl_crypto_mutex_free(&h
->server_thread
.m
);
665 ossl_crypto_condvar_free(&h
->server_thread
.c
);
669 static int helper_init(struct helper
*h
, const char *script_name
,
670 int free_order
, int blocking
,
673 struct in_addr ina
= {0};
674 QUIC_TSERVER_ARGS s_args
= {0};
675 union BIO_sock_info_u info
;
678 memset(h
, 0, sizeof(*h
));
681 h
->free_order
= free_order
;
682 h
->blocking
= blocking
;
683 h
->need_injector
= need_injector
;
684 h
->time_slip
= ossl_time_zero();
686 if (!TEST_ptr(h
->time_lock
= CRYPTO_THREAD_lock_new()))
689 if (!TEST_ptr(h
->s_streams
= lh_STREAM_INFO_new(stream_info_hash
,
693 if (!TEST_ptr(h
->c_streams
= lh_STREAM_INFO_new(stream_info_hash
,
697 ina
.s_addr
= htonl(0x7f000001UL
);
699 h
->s_fd
= BIO_socket(AF_INET
, SOCK_DGRAM
, IPPROTO_UDP
, 0);
700 if (!TEST_int_ge(h
->s_fd
, 0))
703 if (!TEST_true(BIO_socket_nbio(h
->s_fd
, 1)))
706 if (!TEST_ptr(h
->s_net_bio_orig_addr
= BIO_ADDR_new())
707 || !TEST_ptr(h
->s_net_bio_addr
= BIO_ADDR_new()))
710 if (!TEST_true(BIO_ADDR_rawmake(h
->s_net_bio_orig_addr
, AF_INET
,
711 &ina
, sizeof(ina
), 0)))
714 if (!TEST_true(BIO_bind(h
->s_fd
, h
->s_net_bio_orig_addr
, 0)))
717 info
.addr
= h
->s_net_bio_addr
;
718 if (!TEST_true(BIO_sock_info(h
->s_fd
, BIO_SOCK_INFO_ADDRESS
, &info
)))
721 if (!TEST_int_gt(BIO_ADDR_rawport(h
->s_net_bio_addr
), 0))
724 if (!TEST_ptr(h
->s_net_bio
= h
->s_net_bio_own
= BIO_new_dgram(h
->s_fd
, 0)))
727 if (!BIO_up_ref(h
->s_net_bio
))
731 h
->s_qtf_wbio
= h
->s_qtf_wbio_own
= BIO_new(qtest_get_bio_method());
732 if (!TEST_ptr(h
->s_qtf_wbio
))
735 if (!TEST_ptr(BIO_push(h
->s_qtf_wbio
, h
->s_net_bio
)))
738 s_args
.net_wbio
= h
->s_qtf_wbio
;
740 s_args
.net_wbio
= h
->s_net_bio
;
743 s_args
.net_rbio
= h
->s_net_bio
;
745 s_args
.now_cb
= get_time
;
746 s_args
.now_cb_arg
= h
;
749 if (!TEST_ptr(h
->s_priv
= ossl_quic_tserver_new(&s_args
, certfile
, keyfile
)))
756 h
->qtf
= qtest_create_injector(h
->s_priv
);
757 if (!TEST_ptr(h
->qtf
))
760 BIO_set_data(h
->s_qtf_wbio
, h
->qtf
);
763 h
->s_net_bio_own
= NULL
;
764 h
->s_qtf_wbio_own
= NULL
;
766 h
->c_fd
= BIO_socket(AF_INET
, SOCK_DGRAM
, IPPROTO_UDP
, 0);
767 if (!TEST_int_ge(h
->c_fd
, 0))
770 if (!TEST_true(BIO_socket_nbio(h
->c_fd
, 1)))
773 if (!TEST_ptr(h
->c_net_bio
= h
->c_net_bio_own
= BIO_new_dgram(h
->c_fd
, 0)))
776 if (!TEST_true(BIO_dgram_set_peer(h
->c_net_bio
, h
->s_net_bio_addr
)))
779 if (!TEST_ptr(h
->c_ctx
= SSL_CTX_new(OSSL_QUIC_client_method())))
782 /* Set title for qlog purposes. */
783 snprintf(title
, sizeof(title
), "quic_multistream_test: %s", script_name
);
784 if (!TEST_true(ossl_quic_set_diag_title(h
->c_ctx
, title
)))
787 if (!TEST_ptr(h
->c_conn
= SSL_new(h
->c_ctx
)))
790 /* Use custom time function for virtual time skip. */
791 if (!TEST_true(ossl_quic_conn_set_override_now_cb(h
->c_conn
, get_time
, h
)))
794 /* Takes ownership of our reference to the BIO. */
795 SSL_set0_rbio(h
->c_conn
, h
->c_net_bio
);
796 h
->c_net_bio_own
= NULL
;
798 if (!TEST_true(BIO_up_ref(h
->c_net_bio
)))
801 SSL_set0_wbio(h
->c_conn
, h
->c_net_bio
);
803 if (!TEST_true(SSL_set_blocking_mode(h
->c_conn
, h
->blocking
)))
806 #if defined(OPENSSL_THREADS)
807 if (!TEST_ptr(h
->misc_m
= ossl_crypto_mutex_new()))
809 if (!TEST_ptr(h
->misc_cv
= ossl_crypto_condvar_new()))
814 #if defined(OPENSSL_THREADS)
815 if (!TEST_ptr(h
->server_thread
.m
= ossl_crypto_mutex_new()))
818 if (!TEST_ptr(h
->server_thread
.c
= ossl_crypto_condvar_new()))
822 = ossl_crypto_thread_native_start(server_helper_thread
, h
, 1);
823 if (!TEST_ptr(h
->server_thread
.t
))
826 TEST_error("cannot support blocking mode without threads");
831 h
->start_time
= ossl_time_now();
840 static int helper_local_init(struct helper_local
*hl
, struct helper
*h
,
844 hl
->c_streams
= NULL
;
845 hl
->thread_idx
= thread_idx
;
850 if (thread_idx
< 0) {
851 hl
->c_streams
= h
->c_streams
;
853 if (!TEST_ptr(hl
->c_streams
= lh_STREAM_INFO_new(stream_info_hash
,
861 static void helper_local_cleanup(struct helper_local
*hl
)
866 if (hl
->thread_idx
>= 0)
867 helper_cleanup_streams(&hl
->c_streams
);
872 static STREAM_INFO
*get_stream_info(LHASH_OF(STREAM_INFO
) *lh
,
873 const char *stream_name
)
875 STREAM_INFO key
, *info
;
877 if (!TEST_ptr(stream_name
))
880 if (!strcmp(stream_name
, "DEFAULT"))
883 key
.name
= stream_name
;
884 info
= lh_STREAM_INFO_retrieve(lh
, &key
);
886 info
= OPENSSL_zalloc(sizeof(*info
));
890 info
->name
= stream_name
;
891 info
->s_stream_id
= UINT64_MAX
;
892 lh_STREAM_INFO_insert(lh
, info
);
898 static int helper_local_set_c_stream(struct helper_local
*hl
,
899 const char *stream_name
,
902 STREAM_INFO
*info
= get_stream_info(hl
->c_streams
, stream_name
);
907 info
->c_stream
= c_stream
;
908 info
->s_stream_id
= UINT64_MAX
;
912 static SSL
*helper_local_get_c_stream(struct helper_local
*hl
,
913 const char *stream_name
)
917 if (!strcmp(stream_name
, "DEFAULT"))
918 return hl
->h
->c_conn
;
920 info
= get_stream_info(hl
->c_streams
, stream_name
);
924 return info
->c_stream
;
928 helper_set_s_stream(struct helper
*h
, const char *stream_name
,
929 uint64_t s_stream_id
)
933 if (!strcmp(stream_name
, "DEFAULT"))
936 info
= get_stream_info(h
->s_streams
, stream_name
);
940 info
->c_stream
= NULL
;
941 info
->s_stream_id
= s_stream_id
;
945 static uint64_t helper_get_s_stream(struct helper
*h
, const char *stream_name
)
949 if (!strcmp(stream_name
, "DEFAULT"))
952 info
= get_stream_info(h
->s_streams
, stream_name
);
956 return info
->s_stream_id
;
959 static int helper_packet_plain_listener(QTEST_FAULT
*qtf
, QUIC_PKT_HDR
*hdr
,
960 unsigned char *buf
, size_t buf_len
,
963 struct helper
*h
= arg
;
965 return h
->qtf_packet_plain_cb(h
, hdr
, buf
, buf_len
);
968 static int helper_handshake_listener(QTEST_FAULT
*fault
,
969 unsigned char *buf
, size_t buf_len
,
972 struct helper
*h
= arg
;
974 return h
->qtf_handshake_cb(h
, buf
, buf_len
);
977 static int helper_datagram_listener(QTEST_FAULT
*fault
,
978 BIO_MSG
*msg
, size_t stride
,
981 struct helper
*h
= arg
;
983 return h
->qtf_datagram_cb(h
, msg
, stride
);
986 static int is_want(SSL
*s
, int ret
)
988 int ec
= SSL_get_error(s
, ret
);
990 return ec
== SSL_ERROR_WANT_READ
|| ec
== SSL_ERROR_WANT_WRITE
;
993 static int check_consistent_want(SSL
*s
, int ret
)
995 int ec
= SSL_get_error(s
, ret
);
999 (ec
== SSL_ERROR_NONE
&& w
== SSL_NOTHING
)
1000 || (ec
== SSL_ERROR_ZERO_RETURN
&& w
== SSL_NOTHING
)
1001 || (ec
== SSL_ERROR_SSL
&& w
== SSL_NOTHING
)
1002 || (ec
== SSL_ERROR_SYSCALL
&& w
== SSL_NOTHING
)
1003 || (ec
== SSL_ERROR_WANT_READ
&& w
== SSL_READING
)
1004 || (ec
== SSL_ERROR_WANT_WRITE
&& w
== SSL_WRITING
)
1005 || (ec
== SSL_ERROR_WANT_CLIENT_HELLO_CB
&& w
== SSL_CLIENT_HELLO_CB
)
1006 || (ec
== SSL_ERROR_WANT_X509_LOOKUP
&& w
== SSL_X509_LOOKUP
)
1007 || (ec
== SSL_ERROR_WANT_RETRY_VERIFY
&& w
== SSL_RETRY_VERIFY
)
1011 TEST_error("got error=%d, want=%d", ec
, w
);
1016 static int run_script_worker(struct helper
*h
, const struct script_op
*script
,
1017 const char *script_name
,
1021 unsigned char *tmp_buf
= NULL
;
1022 int connect_started
= 0;
1025 const struct script_op
*op
= NULL
;
1026 int no_advance
= 0, first
= 1;
1027 #if defined(OPENSSL_THREADS)
1028 int end_wait_warning
= 0;
1030 OSSL_TIME op_start_time
= ossl_time_zero(), op_deadline
= ossl_time_zero();
1031 struct helper_local hl_
, *hl
= &hl_
;
1032 #define REPEAT_SLOTS 8
1033 size_t repeat_stack_idx
[REPEAT_SLOTS
], repeat_stack_done
[REPEAT_SLOTS
];
1034 size_t repeat_stack_limit
[REPEAT_SLOTS
];
1035 size_t repeat_stack_len
= 0;
1037 if (!TEST_true(helper_local_init(hl
, h
, thread_idx
)))
1040 #define COMMON_SPIN_AGAIN() \
1045 #define S_SPIN_AGAIN() \
1048 ossl_quic_tserver_tick(h->s); \
1049 COMMON_SPIN_AGAIN(); \
1051 #define C_SPIN_AGAIN() \
1053 if (h->blocking) { \
1054 TEST_error("spin again in blocking mode"); \
1057 COMMON_SPIN_AGAIN(); \
1061 SSL
*c_tgt
= h
->c_conn
;
1062 uint64_t s_stream_id
= UINT64_MAX
;
1074 op_start_time
= ossl_time_now();
1075 op_deadline
= ossl_time_add(op_start_time
, ossl_ms2time(60000));
1078 if (!TEST_int_le(ossl_time_compare(ossl_time_now(), op_deadline
), 0)) {
1079 TEST_error("op %zu timed out on thread %d", op_idx
+ 1, thread_idx
);
1083 op
= &script
[op_idx
];
1085 if (op
->stream_name
!= NULL
) {
1086 c_tgt
= helper_local_get_c_stream(hl
, op
->stream_name
);
1088 s_stream_id
= helper_get_s_stream(h
, op
->stream_name
);
1090 s_stream_id
= UINT64_MAX
;
1093 if (thread_idx
< 0) {
1095 ossl_quic_tserver_tick(h
->s
);
1097 #if defined(OPENSSL_THREADS)
1098 else if (h
->blocking
&& !h
->server_thread
.ready
) {
1099 ossl_crypto_mutex_lock(h
->server_thread
.m
);
1100 h
->server_thread
.ready
= 1;
1101 ossl_crypto_condvar_signal(h
->server_thread
.c
);
1102 ossl_crypto_mutex_unlock(h
->server_thread
.m
);
1105 assert(h
->s
== NULL
);
1109 if (thread_idx
>= 0 || connect_started
)
1110 SSL_handle_events(h
->c_conn
);
1112 if (thread_idx
>= 0) {
1113 /* Only allow certain opcodes on child threads. */
1117 case OPK_C_ACCEPT_STREAM_WAIT
:
1118 case OPK_C_NEW_STREAM
:
1119 case OPK_C_READ_EXPECT
:
1120 case OPK_C_EXPECT_FIN
:
1122 case OPK_C_WRITE_EX2
:
1123 case OPK_C_CONCLUDE
:
1124 case OPK_C_FREE_STREAM
:
1125 case OPK_BEGIN_REPEAT
:
1126 case OPK_END_REPEAT
:
1127 case OPK_C_READ_FAIL_WAIT
:
1128 case OPK_C_EXPECT_SSL_ERR
:
1129 case OPK_EXPECT_ERR_REASON
:
1130 case OPK_EXPECT_ERR_LIB
:
1136 TEST_error("opcode %lu not allowed on child thread",
1137 (unsigned long)op
->op
);
1144 if (!TEST_size_t_eq(repeat_stack_len
, 0))
1147 #if defined(OPENSSL_THREADS)
1148 if (thread_idx
< 0) {
1152 for (i
= 0; i
< h
->num_threads
; ++i
) {
1153 if (h
->threads
[i
].m
== NULL
)
1156 ossl_crypto_mutex_lock(h
->threads
[i
].m
);
1157 done
= h
->threads
[i
].done
;
1158 ossl_crypto_mutex_unlock(h
->threads
[i
].m
);
1161 if (!end_wait_warning
) {
1162 TEST_info("still waiting for other threads to finish (%zu)", i
);
1163 end_wait_warning
= 1;
1172 TEST_info("script \"%s\" finished on thread %d", script_name
, thread_idx
);
1176 case OPK_BEGIN_REPEAT
:
1177 if (!TEST_size_t_lt(repeat_stack_len
, OSSL_NELEM(repeat_stack_idx
)))
1180 if (!TEST_size_t_gt(op
->arg1
, 0))
1183 repeat_stack_idx
[repeat_stack_len
] = op_idx
+ 1;
1184 repeat_stack_done
[repeat_stack_len
] = 0;
1185 repeat_stack_limit
[repeat_stack_len
] = op
->arg1
;
1189 case OPK_C_SKIP_IF_UNBOUND
:
1196 case OPK_END_REPEAT
:
1197 if (!TEST_size_t_gt(repeat_stack_len
, 0))
1200 if (++repeat_stack_done
[repeat_stack_len
- 1]
1201 == repeat_stack_limit
[repeat_stack_len
- 1]) {
1204 op_idx
= repeat_stack_idx
[repeat_stack_len
- 1];
1216 ok
= op
->check_func(h
, hl
);
1217 hl
->check_op
= NULL
;
1219 if (thread_idx
< 0 && h
->check_spin_again
) {
1220 h
->check_spin_again
= 0;
1229 case OPK_C_SET_ALPN
:
1231 const char *alpn
= op
->arg0
;
1232 size_t alpn_len
= strlen(alpn
);
1234 if (!TEST_size_t_le(alpn_len
, UINT8_MAX
)
1235 || !TEST_ptr(tmp_buf
= (unsigned char *)OPENSSL_malloc(alpn_len
+ 1)))
1238 memcpy(tmp_buf
+ 1, alpn
, alpn_len
);
1239 tmp_buf
[0] = (unsigned char)alpn_len
;
1241 /* 0 is the success case for SSL_set_alpn_protos(). */
1242 if (!TEST_false(SSL_set_alpn_protos(h
->c_conn
, tmp_buf
,
1246 OPENSSL_free(tmp_buf
);
1251 case OPK_C_CONNECT_WAIT
:
1255 connect_started
= 1;
1257 ret
= SSL_connect(h
->c_conn
);
1258 if (!check_consistent_want(c_tgt
, ret
))
1261 if (!h
->blocking
&& is_want(h
->c_conn
, ret
))
1264 if (op
->arg1
== 0 && !TEST_int_eq(ret
, 1))
1272 size_t bytes_written
= 0;
1275 if (!TEST_ptr(c_tgt
))
1278 r
= SSL_write_ex(c_tgt
, op
->arg0
, op
->arg1
, &bytes_written
);
1280 || !check_consistent_want(c_tgt
, r
)
1281 || !TEST_size_t_eq(bytes_written
, op
->arg1
))
1286 case OPK_C_WRITE_EX2
:
1288 size_t bytes_written
= 0;
1291 if (!TEST_ptr(c_tgt
))
1294 r
= SSL_write_ex2(c_tgt
, op
->arg0
, op
->arg1
, op
->arg2
,
1297 || !check_consistent_want(c_tgt
, r
)
1298 || !TEST_size_t_eq(bytes_written
, op
->arg1
))
1305 size_t bytes_written
= 0;
1307 if (!TEST_uint64_t_ne(s_stream_id
, UINT64_MAX
))
1310 if (!TEST_true(ossl_quic_tserver_write(ACQUIRE_S(), s_stream_id
,
1313 || !TEST_size_t_eq(bytes_written
, op
->arg1
))
1318 case OPK_C_CONCLUDE
:
1320 if (!TEST_true(SSL_stream_conclude(c_tgt
, 0)))
1325 case OPK_S_CONCLUDE
:
1327 if (!TEST_uint64_t_ne(s_stream_id
, UINT64_MAX
))
1330 ossl_quic_tserver_conclude(ACQUIRE_S(), s_stream_id
);
1334 case OPK_C_WAIT_FOR_DATA
:
1337 size_t bytes_read
= 0;
1339 if (!TEST_ptr(c_tgt
))
1342 if (!SSL_peek_ex(c_tgt
, buf
, sizeof(buf
), &bytes_read
)
1348 case OPK_C_READ_EXPECT
:
1350 size_t bytes_read
= 0;
1353 if (op
->arg1
> 0 && tmp_buf
== NULL
1354 && !TEST_ptr(tmp_buf
= OPENSSL_malloc(op
->arg1
)))
1357 r
= SSL_read_ex(c_tgt
, tmp_buf
+ offset
, op
->arg1
- offset
,
1359 if (!check_consistent_want(c_tgt
, r
))
1365 if (bytes_read
+ offset
!= op
->arg1
) {
1366 offset
+= bytes_read
;
1371 && !TEST_mem_eq(tmp_buf
, op
->arg1
, op
->arg0
, op
->arg1
))
1374 OPENSSL_free(tmp_buf
);
1379 case OPK_S_READ_EXPECT
:
1381 size_t bytes_read
= 0;
1383 if (!TEST_uint64_t_ne(s_stream_id
, UINT64_MAX
))
1386 if (op
->arg1
> 0 && tmp_buf
== NULL
1387 && !TEST_ptr(tmp_buf
= OPENSSL_malloc(op
->arg1
)))
1390 if (!TEST_true(ossl_quic_tserver_read(ACQUIRE_S(), s_stream_id
,
1396 if (bytes_read
+ offset
!= op
->arg1
) {
1397 offset
+= bytes_read
;
1402 && !TEST_mem_eq(tmp_buf
, op
->arg1
, op
->arg0
, op
->arg1
))
1405 OPENSSL_free(tmp_buf
);
1410 case OPK_C_EXPECT_FIN
:
1413 size_t bytes_read
= 0;
1416 r
= SSL_read_ex(c_tgt
, buf
, sizeof(buf
), &bytes_read
);
1417 if (!check_consistent_want(c_tgt
, r
)
1419 || !TEST_size_t_eq(bytes_read
, 0))
1422 if (is_want(c_tgt
, 0))
1425 if (!TEST_int_eq(SSL_get_error(c_tgt
, 0),
1426 SSL_ERROR_ZERO_RETURN
))
1429 if (!TEST_int_eq(SSL_want(c_tgt
), SSL_NOTHING
))
1434 case OPK_S_EXPECT_FIN
:
1436 if (!TEST_uint64_t_ne(s_stream_id
, UINT64_MAX
))
1439 if (!ossl_quic_tserver_has_read_ended(ACQUIRE_S(), s_stream_id
))
1448 if (!TEST_ptr_null(c_tgt
))
1449 goto out
; /* don't overwrite existing stream with same name */
1451 if (!TEST_ptr(op
->stream_name
))
1454 if (!TEST_ptr(c_stream
= ossl_quic_detach_stream(h
->c_conn
)))
1457 if (!TEST_true(helper_local_set_c_stream(hl
, op
->stream_name
, c_stream
)))
1464 if (!TEST_ptr(c_tgt
))
1467 if (!TEST_ptr(op
->stream_name
))
1470 if (!TEST_true(ossl_quic_attach_stream(h
->c_conn
, c_tgt
)))
1473 if (!TEST_true(helper_local_set_c_stream(hl
, op
->stream_name
, NULL
)))
1478 case OPK_C_NEW_STREAM
:
1481 uint64_t flags
= op
->arg1
;
1482 int allow_fail
= ((flags
& ALLOW_FAIL
) != 0);
1484 flags
&= ~(uint64_t)ALLOW_FAIL
;
1486 if (!TEST_ptr_null(c_tgt
))
1487 goto out
; /* don't overwrite existing stream with same name */
1489 if (!TEST_ptr(op
->stream_name
))
1492 c_stream
= SSL_new_stream(h
->c_conn
, flags
);
1493 if (!allow_fail
&& !TEST_ptr(c_stream
))
1496 if (allow_fail
&& c_stream
== NULL
) {
1497 if (!TEST_size_t_eq(ERR_GET_REASON(ERR_get_error()),
1498 SSL_R_STREAM_COUNT_LIMITED
))
1505 if (op
->arg2
!= UINT64_MAX
1506 && !TEST_uint64_t_eq(SSL_get_stream_id(c_stream
),
1510 if (!TEST_true(helper_local_set_c_stream(hl
, op
->stream_name
, c_stream
)))
1515 case OPK_S_NEW_STREAM
:
1517 uint64_t stream_id
= UINT64_MAX
;
1519 if (!TEST_uint64_t_eq(s_stream_id
, UINT64_MAX
))
1520 goto out
; /* don't overwrite existing stream with same name */
1522 if (!TEST_ptr(op
->stream_name
))
1525 if (!TEST_true(ossl_quic_tserver_stream_new(ACQUIRE_S(),
1530 if (op
->arg2
!= UINT64_MAX
1531 && !TEST_uint64_t_eq(stream_id
, op
->arg2
))
1534 if (!TEST_true(helper_set_s_stream(h
, op
->stream_name
,
1540 case OPK_C_ACCEPT_STREAM_WAIT
:
1544 if (!TEST_ptr_null(c_tgt
))
1545 goto out
; /* don't overwrite existing stream with same name */
1547 if (!TEST_ptr(op
->stream_name
))
1550 if ((c_stream
= SSL_accept_stream(h
->c_conn
, 0)) == NULL
)
1553 if (!TEST_true(helper_local_set_c_stream(hl
, op
->stream_name
,
1559 case OPK_S_ACCEPT_STREAM_WAIT
:
1561 uint64_t new_stream_id
;
1563 if (!TEST_uint64_t_eq(s_stream_id
, UINT64_MAX
))
1566 if (!TEST_ptr(op
->stream_name
))
1569 new_stream_id
= ossl_quic_tserver_pop_incoming_stream(ACQUIRE_S());
1570 if (new_stream_id
== UINT64_MAX
)
1573 if (!TEST_true(helper_set_s_stream(h
, op
->stream_name
, new_stream_id
)))
1578 case OPK_C_ACCEPT_STREAM_NONE
:
1582 if (!TEST_ptr_null(c_stream
= SSL_accept_stream(h
->c_conn
,
1583 SSL_ACCEPT_STREAM_NO_BLOCK
))) {
1590 case OPK_C_FREE_STREAM
:
1592 if (!TEST_ptr(c_tgt
)
1593 || !TEST_true(!SSL_is_connection(c_tgt
)))
1596 if (!TEST_ptr(op
->stream_name
))
1599 if (!TEST_true(helper_local_set_c_stream(hl
, op
->stream_name
, NULL
)))
1607 case OPK_C_SET_DEFAULT_STREAM_MODE
:
1609 if (!TEST_ptr(c_tgt
))
1612 if (!TEST_true(SSL_set_default_stream_mode(c_tgt
, op
->arg1
)))
1617 case OPK_C_SET_INCOMING_STREAM_POLICY
:
1619 if (!TEST_ptr(c_tgt
))
1622 if (!TEST_true(SSL_set_incoming_stream_policy(c_tgt
,
1628 case OPK_C_SHUTDOWN_WAIT
:
1631 QUIC_CHANNEL
*ch
= ossl_quic_conn_get_channel(h
->c_conn
);
1632 SSL_SHUTDOWN_EX_ARGS args
= {0};
1634 ossl_quic_engine_set_inhibit_tick(ossl_quic_channel_get0_engine(ch
), 0);
1636 if (!TEST_ptr(c_tgt
))
1639 args
.quic_reason
= (const char *)op
->arg0
;
1641 ret
= SSL_shutdown_ex(c_tgt
, op
->arg1
, &args
, sizeof(args
));
1642 if (!TEST_int_ge(ret
, 0))
1650 case OPK_S_SHUTDOWN
:
1652 ossl_quic_tserver_shutdown(ACQUIRE_S(), op
->arg1
);
1656 case OPK_C_EXPECT_CONN_CLOSE_INFO
:
1658 SSL_CONN_CLOSE_INFO cc_info
= {0};
1659 int expect_app
= (op
->arg1
& EXPECT_CONN_CLOSE_APP
) != 0;
1660 int expect_remote
= (op
->arg1
& EXPECT_CONN_CLOSE_REMOTE
) != 0;
1661 uint64_t error_code
= op
->arg2
;
1663 if (!TEST_ptr(c_tgt
))
1667 && !TEST_true(SSL_shutdown_ex(c_tgt
,
1668 SSL_SHUTDOWN_FLAG_WAIT_PEER
,
1672 if (!SSL_get_conn_close_info(c_tgt
, &cc_info
, sizeof(cc_info
)))
1675 if (!TEST_int_eq(expect_app
,
1677 & SSL_CONN_CLOSE_FLAG_TRANSPORT
) == 0)
1678 || !TEST_int_eq(expect_remote
,
1680 & SSL_CONN_CLOSE_FLAG_LOCAL
) == 0)
1681 || !TEST_uint64_t_eq(error_code
, cc_info
.error_code
)) {
1682 TEST_info("Connection close reason: %s", cc_info
.reason
);
1688 case OPK_S_EXPECT_CONN_CLOSE_INFO
:
1690 const QUIC_TERMINATE_CAUSE
*tc
;
1691 int expect_app
= (op
->arg1
& EXPECT_CONN_CLOSE_APP
) != 0;
1692 int expect_remote
= (op
->arg1
& EXPECT_CONN_CLOSE_REMOTE
) != 0;
1693 uint64_t error_code
= op
->arg2
;
1695 if (!ossl_quic_tserver_is_term_any(ACQUIRE_S())) {
1696 ossl_quic_tserver_ping(ACQUIRE_S());
1700 if (!TEST_ptr(tc
= ossl_quic_tserver_get_terminate_cause(ACQUIRE_S())))
1703 if (!TEST_uint64_t_eq(error_code
, tc
->error_code
)
1704 || !TEST_int_eq(expect_app
, tc
->app
)
1705 || !TEST_int_eq(expect_remote
, tc
->remote
))
1710 case OPK_S_BIND_STREAM_ID
:
1712 if (!TEST_uint64_t_eq(s_stream_id
, UINT64_MAX
))
1715 if (!TEST_ptr(op
->stream_name
))
1718 if (!TEST_true(helper_set_s_stream(h
, op
->stream_name
, op
->arg2
)))
1723 case OPK_S_UNBIND_STREAM_ID
:
1725 if (!TEST_uint64_t_ne(s_stream_id
, UINT64_MAX
))
1728 if (!TEST_ptr(op
->stream_name
))
1731 if (!TEST_true(helper_set_s_stream(h
, op
->stream_name
, UINT64_MAX
)))
1736 case OPK_C_WRITE_FAIL
:
1738 size_t bytes_written
= 0;
1741 if (!TEST_ptr(c_tgt
))
1744 r
= SSL_write_ex(c_tgt
, "apple", 5, &bytes_written
);
1746 || !check_consistent_want(c_tgt
, r
))
1751 case OPK_S_WRITE_FAIL
:
1753 size_t bytes_written
= 0;
1755 if (!TEST_uint64_t_ne(s_stream_id
, UINT64_MAX
))
1758 if (!TEST_false(ossl_quic_tserver_write(ACQUIRE_S(), s_stream_id
,
1759 (const unsigned char *)"apple", 5,
1765 case OPK_C_READ_FAIL
:
1767 size_t bytes_read
= 0;
1771 if (!TEST_ptr(c_tgt
))
1774 r
= SSL_read_ex(c_tgt
, buf
, sizeof(buf
), &bytes_read
);
1777 if (!check_consistent_want(c_tgt
, r
))
1782 case OPK_C_READ_FAIL_WAIT
:
1784 size_t bytes_read
= 0;
1788 if (!TEST_ptr(c_tgt
))
1791 r
= SSL_read_ex(c_tgt
, buf
, sizeof(buf
), &bytes_read
);
1794 if (!check_consistent_want(c_tgt
, r
))
1797 if (is_want(c_tgt
, 0))
1802 case OPK_S_READ_FAIL
:
1804 size_t bytes_read
= 0;
1805 unsigned char buf
[1];
1807 if (!TEST_uint64_t_ne(s_stream_id
, UINT64_MAX
))
1810 if (!TEST_false(ossl_quic_tserver_read(ACQUIRE_S(), s_stream_id
,
1817 case OPK_C_STREAM_RESET
:
1819 SSL_STREAM_RESET_ARGS args
= {0};
1821 if (!TEST_ptr(c_tgt
))
1824 args
.quic_error_code
= op
->arg2
;
1826 if (!TEST_true(SSL_stream_reset(c_tgt
, &args
, sizeof(args
))))
1831 case OPK_NEW_THREAD
:
1833 #if !defined(OPENSSL_THREADS)
1835 * If this test script requires threading and we do not have
1836 * support for it, skip the rest of it.
1838 TEST_skip("threading not supported, skipping");
1844 if (!TEST_ptr_null(h
->threads
)) {
1845 TEST_error("max one NEW_THREAD operation per script");
1849 h
->threads
= OPENSSL_zalloc(op
->arg1
* sizeof(struct child_thread_args
));
1850 if (!TEST_ptr(h
->threads
))
1853 h
->num_threads
= op
->arg1
;
1855 for (i
= 0; i
< op
->arg1
; ++i
) {
1856 h
->threads
[i
].h
= h
;
1857 h
->threads
[i
].script
= op
->arg0
;
1858 h
->threads
[i
].script_name
= script_name
;
1859 h
->threads
[i
].thread_idx
= i
;
1861 h
->threads
[i
].m
= ossl_crypto_mutex_new();
1862 if (!TEST_ptr(h
->threads
[i
].m
))
1866 = ossl_crypto_thread_native_start(run_script_child_thread
,
1868 if (!TEST_ptr(h
->threads
[i
].t
))
1875 case OPK_C_CLOSE_SOCKET
:
1877 BIO_closesocket(h
->c_fd
);
1882 case OPK_C_EXPECT_SSL_ERR
:
1884 if (!TEST_size_t_eq((size_t)SSL_get_error(c_tgt
, 0), op
->arg1
))
1886 if (!TEST_int_eq(SSL_want(c_tgt
), SSL_NOTHING
))
1891 case OPK_EXPECT_ERR_REASON
:
1893 if (!TEST_size_t_eq((size_t)ERR_GET_REASON(ERR_peek_last_error()), op
->arg1
))
1898 case OPK_EXPECT_ERR_LIB
:
1900 if (!TEST_size_t_eq((size_t)ERR_GET_LIB(ERR_peek_last_error()), op
->arg1
))
1911 OSSL_sleep(op
->arg2
);
1915 case OPK_S_SET_INJECT_PLAIN
:
1916 h
->qtf_packet_plain_cb
= op
->qtf_packet_plain_cb
;
1918 if (!TEST_true(qtest_fault_set_packet_plain_listener(h
->qtf
,
1919 h
->qtf_packet_plain_cb
!= NULL
?
1920 helper_packet_plain_listener
: NULL
,
1926 case OPK_S_SET_INJECT_HANDSHAKE
:
1927 h
->qtf_handshake_cb
= op
->qtf_handshake_cb
;
1929 if (!TEST_true(qtest_fault_set_handshake_listener(h
->qtf
,
1930 h
->qtf_handshake_cb
!= NULL
?
1931 helper_handshake_listener
: NULL
,
1937 case OPK_S_SET_INJECT_DATAGRAM
:
1938 h
->qtf_datagram_cb
= op
->qtf_datagram_cb
;
1940 if (!TEST_true(qtest_fault_set_datagram_listener(h
->qtf
,
1941 h
->qtf_datagram_cb
!= NULL
?
1942 helper_datagram_listener
: NULL
,
1948 case OPK_SET_INJECT_WORD
:
1950 * Must hold server tick lock - callbacks can be called from other
1951 * thread when running test in blocking mode (tsan).
1954 h
->inject_word0
= op
->arg1
;
1955 h
->inject_word1
= op
->arg2
;
1958 case OPK_C_INHIBIT_TICK
:
1960 QUIC_CHANNEL
*ch
= ossl_quic_conn_get_channel(h
->c_conn
);
1962 ossl_quic_engine_set_inhibit_tick(ossl_quic_channel_get0_engine(ch
),
1967 case OPK_C_SET_WRITE_BUF_SIZE
:
1968 if (!TEST_ptr(c_tgt
))
1971 if (!TEST_true(ossl_quic_set_write_buffer_size(c_tgt
, op
->arg1
)))
1976 case OPK_S_NEW_TICKET
:
1977 if (!TEST_true(ossl_quic_tserver_new_ticket(ACQUIRE_S())))
1982 TEST_error("unknown op");
1988 s_unlock(h
, hl
); /* idempotent */
1991 const QUIC_TERMINATE_CAUSE
*tcause
;
1992 const char *e_str
, *f_str
;
1994 TEST_error("failed in script \"%s\" at op %zu, thread %d\n",
1995 script_name
, op_idx
+ 1, thread_idx
);
1997 for (i
= 0; i
< repeat_stack_len
; ++i
)
1998 TEST_info("while repeating, iteration %zu of %zu, starting at script op %zu",
1999 repeat_stack_done
[i
],
2000 repeat_stack_limit
[i
],
2001 repeat_stack_idx
[i
]);
2003 ERR_print_errors_fp(stderr
);
2005 if (h
->c_conn
!= NULL
) {
2006 SSL_CONN_CLOSE_INFO cc_info
= {0};
2008 if (SSL_get_conn_close_info(h
->c_conn
, &cc_info
, sizeof(cc_info
))) {
2009 e_str
= ossl_quic_err_to_string(cc_info
.error_code
);
2010 f_str
= ossl_quic_frame_type_to_string(cc_info
.frame_type
);
2017 TEST_info("client side is closed: %llu(%s)/%llu(%s), "
2018 "%s, %s, reason: \"%s\"",
2019 (unsigned long long)cc_info
.error_code
,
2021 (unsigned long long)cc_info
.frame_type
,
2023 (cc_info
.flags
& SSL_CONN_CLOSE_FLAG_LOCAL
) != 0
2024 ? "local" : "remote",
2025 (cc_info
.flags
& SSL_CONN_CLOSE_FLAG_TRANSPORT
) != 0
2026 ? "transport" : "app",
2027 cc_info
.reason
!= NULL
? cc_info
.reason
: "-");
2031 tcause
= (h
->s
!= NULL
2032 ? ossl_quic_tserver_get_terminate_cause(h
->s
) : NULL
);
2033 if (tcause
!= NULL
) {
2034 e_str
= ossl_quic_err_to_string(tcause
->error_code
);
2035 f_str
= ossl_quic_frame_type_to_string(tcause
->frame_type
);
2042 TEST_info("server side is closed: %llu(%s)/%llu(%s), "
2043 "%s, %s, reason: \"%s\"",
2044 (unsigned long long)tcause
->error_code
,
2046 (unsigned long long)tcause
->frame_type
,
2048 tcause
->remote
? "remote" : "local",
2049 tcause
->app
? "app" : "transport",
2050 tcause
->reason
!= NULL
? tcause
->reason
: "-");
2054 OPENSSL_free(tmp_buf
);
2055 helper_local_cleanup(hl
);
2059 static int run_script(const struct script_op
*script
,
2060 const char *script_name
,
2067 if (!TEST_true(helper_init(&h
, script_name
,
2068 free_order
, blocking
, 1)))
2071 if (!TEST_true(run_script_worker(&h
, script
, script_name
, -1)))
2074 #if defined(OPENSSL_THREADS)
2075 if (!TEST_true(join_threads(h
.threads
, h
.num_threads
)))
2085 #if defined(OPENSSL_THREADS)
2086 static CRYPTO_THREAD_RETVAL
run_script_child_thread(void *arg
)
2089 struct child_thread_args
*args
= arg
;
2091 testresult
= run_script_worker(args
->h
, args
->script
,
2095 ossl_crypto_mutex_lock(args
->m
);
2096 args
->testresult
= testresult
;
2098 ossl_crypto_mutex_unlock(args
->m
);
2103 /* 1. Simple single-stream test */
2104 static const struct script_op script_1
[] = {
2105 OP_C_SET_ALPN ("ossltest")
2106 OP_C_CONNECT_WAIT ()
2107 OP_C_WRITE (DEFAULT
, "apple", 5)
2108 OP_C_CONCLUDE (DEFAULT
)
2109 OP_S_BIND_STREAM_ID (a
, C_BIDI_ID(0))
2110 OP_S_READ_EXPECT (a
, "apple", 5)
2112 OP_S_WRITE (a
, "orange", 6)
2114 OP_C_READ_EXPECT (DEFAULT
, "orange", 6)
2115 OP_C_EXPECT_FIN (DEFAULT
)
2119 /* 2. Multi-stream test */
2120 static const struct script_op script_2
[] = {
2121 OP_C_SET_ALPN ("ossltest")
2122 OP_C_CONNECT_WAIT ()
2123 OP_C_SET_INCOMING_STREAM_POLICY(SSL_INCOMING_STREAM_POLICY_ACCEPT
)
2124 OP_C_WRITE (DEFAULT
, "apple", 5)
2125 OP_S_BIND_STREAM_ID (a
, C_BIDI_ID(0))
2126 OP_S_READ_EXPECT (a
, "apple", 5)
2127 OP_S_WRITE (a
, "orange", 6)
2128 OP_C_READ_EXPECT (DEFAULT
, "orange", 6)
2130 OP_C_NEW_STREAM_BIDI (b
, C_BIDI_ID(1))
2131 OP_C_WRITE (b
, "flamingo", 8)
2133 OP_S_BIND_STREAM_ID (b
, C_BIDI_ID(1))
2134 OP_S_READ_EXPECT (b
, "flamingo", 8)
2136 OP_S_WRITE (b
, "gargoyle", 8)
2138 OP_C_READ_EXPECT (b
, "gargoyle", 8)
2141 OP_C_NEW_STREAM_UNI (c
, C_UNI_ID(0))
2142 OP_C_WRITE (c
, "elephant", 8)
2144 OP_S_BIND_STREAM_ID (c
, C_UNI_ID(0))
2145 OP_S_READ_EXPECT (c
, "elephant", 8)
2149 OP_C_ACCEPT_STREAM_NONE ()
2151 OP_S_NEW_STREAM_BIDI (d
, S_BIDI_ID(0))
2152 OP_S_WRITE (d
, "frog", 4)
2155 OP_C_ACCEPT_STREAM_WAIT (d
)
2156 OP_C_ACCEPT_STREAM_NONE ()
2157 OP_C_READ_EXPECT (d
, "frog", 4)
2160 OP_S_NEW_STREAM_BIDI (e
, S_BIDI_ID(1))
2161 OP_S_WRITE (e
, "mixture", 7)
2164 OP_C_ACCEPT_STREAM_WAIT (e
)
2165 OP_C_READ_EXPECT (e
, "mixture", 7)
2167 OP_C_WRITE (e
, "ramble", 6)
2168 OP_S_READ_EXPECT (e
, "ramble", 6)
2172 OP_S_NEW_STREAM_UNI (f
, S_UNI_ID(0))
2173 OP_S_WRITE (f
, "yonder", 6)
2176 OP_C_ACCEPT_STREAM_WAIT (f
)
2177 OP_C_ACCEPT_STREAM_NONE ()
2178 OP_C_READ_EXPECT (f
, "yonder", 6)
2182 OP_C_SET_INCOMING_STREAM_POLICY(SSL_INCOMING_STREAM_POLICY_REJECT
)
2183 OP_S_NEW_STREAM_BIDI (g
, S_BIDI_ID(2))
2184 OP_S_WRITE (g
, "unseen", 6)
2187 OP_C_ACCEPT_STREAM_NONE ()
2189 OP_C_SET_INCOMING_STREAM_POLICY(SSL_INCOMING_STREAM_POLICY_AUTO
)
2190 OP_S_NEW_STREAM_BIDI (h
, S_BIDI_ID(3))
2191 OP_S_WRITE (h
, "UNSEEN", 6)
2194 OP_C_ACCEPT_STREAM_NONE ()
2197 * Streams g, h should have been rejected, so server should have got
2198 * STOP_SENDING/RESET_STREAM.
2200 OP_CHECK (check_rejected
, S_BIDI_ID(2))
2201 OP_CHECK (check_rejected
, S_BIDI_ID(3))
2206 /* 3. Default stream detach/reattach test */
2207 static const struct script_op script_3
[] = {
2208 OP_C_SET_ALPN ("ossltest")
2209 OP_C_CONNECT_WAIT ()
2211 OP_C_WRITE (DEFAULT
, "apple", 5)
2212 OP_C_DETACH (a
) /* DEFAULT becomes stream 'a' */
2213 OP_C_WRITE_FAIL (DEFAULT
)
2215 OP_C_WRITE (a
, "by", 2)
2217 OP_S_BIND_STREAM_ID (a
, C_BIDI_ID(0))
2218 OP_S_READ_EXPECT (a
, "appleby", 7)
2220 OP_S_WRITE (a
, "hello", 5)
2221 OP_C_READ_EXPECT (a
, "hello", 5)
2223 OP_C_WRITE_FAIL (DEFAULT
)
2225 OP_C_WRITE (DEFAULT
, "is here", 7)
2226 OP_S_READ_EXPECT (a
, "is here", 7)
2235 /* 4. Default stream mode test */
2236 static const struct script_op script_4
[] = {
2237 OP_C_SET_ALPN ("ossltest")
2238 OP_C_CONNECT_WAIT ()
2240 OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE
)
2241 OP_C_WRITE_FAIL (DEFAULT
)
2243 OP_S_NEW_STREAM_BIDI (a
, S_BIDI_ID(0))
2244 OP_S_WRITE (a
, "apple", 5)
2246 OP_C_READ_FAIL (DEFAULT
)
2248 OP_C_ACCEPT_STREAM_WAIT (a
)
2249 OP_C_READ_EXPECT (a
, "apple", 5)
2252 OP_C_WRITE (DEFAULT
, "orange", 6)
2253 OP_S_READ_EXPECT (a
, "orange", 6)
2258 /* 5. Test stream reset functionality */
2259 static const struct script_op script_5
[] = {
2260 OP_C_SET_ALPN ("ossltest")
2261 OP_C_CONNECT_WAIT ()
2263 OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE
)
2264 OP_C_NEW_STREAM_BIDI (a
, C_BIDI_ID(0))
2265 OP_C_NEW_STREAM_BIDI (b
, C_BIDI_ID(1))
2267 OP_C_WRITE (a
, "apple", 5)
2268 OP_C_STREAM_RESET (a
, 42)
2270 OP_C_WRITE (b
, "strawberry", 10)
2272 OP_S_BIND_STREAM_ID (a
, C_BIDI_ID(0))
2273 OP_S_BIND_STREAM_ID (b
, C_BIDI_ID(1))
2274 OP_S_READ_EXPECT (b
, "strawberry", 10)
2275 /* Reset disrupts read of already sent data */
2277 OP_CHECK (check_stream_reset
, C_BIDI_ID(0))
2282 /* 6. Test STOP_SENDING functionality */
2283 static const struct script_op script_6
[] = {
2284 OP_C_SET_ALPN ("ossltest")
2285 OP_C_CONNECT_WAIT ()
2287 OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE
)
2288 OP_S_NEW_STREAM_BIDI (a
, S_BIDI_ID(0))
2289 OP_S_WRITE (a
, "apple", 5)
2291 OP_C_ACCEPT_STREAM_WAIT (a
)
2292 OP_C_FREE_STREAM (a
)
2293 OP_C_ACCEPT_STREAM_NONE ()
2295 OP_CHECK (check_stream_stopped
, S_BIDI_ID(0))
2300 /* 7. Unidirectional default stream mode test (client sends first) */
2301 static const struct script_op script_7
[] = {
2302 OP_C_SET_ALPN ("ossltest")
2303 OP_C_CONNECT_WAIT ()
2305 OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_AUTO_UNI
)
2306 OP_C_WRITE (DEFAULT
, "apple", 5)
2308 OP_S_BIND_STREAM_ID (a
, C_UNI_ID(0))
2309 OP_S_READ_EXPECT (a
, "apple", 5)
2315 /* 8. Unidirectional default stream mode test (server sends first) */
2316 static const struct script_op script_8
[] = {
2317 OP_C_SET_ALPN ("ossltest")
2318 OP_C_CONNECT_WAIT ()
2320 OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_AUTO_UNI
)
2321 OP_S_NEW_STREAM_UNI (a
, S_UNI_ID(0))
2322 OP_S_WRITE (a
, "apple", 5)
2323 OP_C_READ_EXPECT (DEFAULT
, "apple", 5)
2324 OP_C_WRITE_FAIL (DEFAULT
)
2329 /* 9. Unidirectional default stream mode test (server sends first on bidi) */
2330 static const struct script_op script_9
[] = {
2331 OP_C_SET_ALPN ("ossltest")
2332 OP_C_CONNECT_WAIT ()
2334 OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_AUTO_UNI
)
2335 OP_S_NEW_STREAM_BIDI (a
, S_BIDI_ID(0))
2336 OP_S_WRITE (a
, "apple", 5)
2337 OP_C_READ_EXPECT (DEFAULT
, "apple", 5)
2338 OP_C_WRITE (DEFAULT
, "orange", 6)
2339 OP_S_READ_EXPECT (a
, "orange", 6)
2345 static const struct script_op script_10
[] = {
2346 OP_C_SET_ALPN ("ossltest")
2347 OP_C_CONNECT_WAIT ()
2349 OP_C_WRITE (DEFAULT
, "apple", 5)
2350 OP_S_BIND_STREAM_ID (a
, C_BIDI_ID(0))
2351 OP_S_READ_EXPECT (a
, "apple", 5)
2353 OP_C_SHUTDOWN_WAIT (NULL
, 0)
2354 OP_C_EXPECT_CONN_CLOSE_INFO(0, 1, 0)
2355 OP_S_EXPECT_CONN_CLOSE_INFO(0, 1, 1)
2360 /* 11. Many threads accepted on the same client connection */
2361 static const struct script_op script_11_child
[] = {
2362 OP_C_ACCEPT_STREAM_WAIT (a
)
2363 OP_C_READ_EXPECT (a
, "foo", 3)
2369 static const struct script_op script_11
[] = {
2370 OP_C_SET_ALPN ("ossltest")
2371 OP_C_CONNECT_WAIT ()
2372 OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE
)
2374 OP_NEW_THREAD (5, script_11_child
)
2376 OP_S_NEW_STREAM_BIDI (a
, ANY_ID
)
2377 OP_S_WRITE (a
, "foo", 3)
2380 OP_S_NEW_STREAM_BIDI (b
, ANY_ID
)
2381 OP_S_WRITE (b
, "foo", 3)
2384 OP_S_NEW_STREAM_BIDI (c
, ANY_ID
)
2385 OP_S_WRITE (c
, "foo", 3)
2388 OP_S_NEW_STREAM_BIDI (d
, ANY_ID
)
2389 OP_S_WRITE (d
, "foo", 3)
2392 OP_S_NEW_STREAM_BIDI (e
, ANY_ID
)
2393 OP_S_WRITE (e
, "foo", 3)
2399 /* 12. Many threads initiated on the same client connection */
2400 static const struct script_op script_12_child
[] = {
2401 OP_C_NEW_STREAM_BIDI (a
, ANY_ID
)
2402 OP_C_WRITE (a
, "foo", 3)
2404 OP_C_FREE_STREAM (a
)
2409 static const struct script_op script_12
[] = {
2410 OP_C_SET_ALPN ("ossltest")
2411 OP_C_CONNECT_WAIT ()
2412 OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE
)
2414 OP_NEW_THREAD (5, script_12_child
)
2416 OP_S_BIND_STREAM_ID (a
, C_BIDI_ID(0))
2417 OP_S_READ_EXPECT (a
, "foo", 3)
2419 OP_S_BIND_STREAM_ID (b
, C_BIDI_ID(1))
2420 OP_S_READ_EXPECT (b
, "foo", 3)
2422 OP_S_BIND_STREAM_ID (c
, C_BIDI_ID(2))
2423 OP_S_READ_EXPECT (c
, "foo", 3)
2425 OP_S_BIND_STREAM_ID (d
, C_BIDI_ID(3))
2426 OP_S_READ_EXPECT (d
, "foo", 3)
2428 OP_S_BIND_STREAM_ID (e
, C_BIDI_ID(4))
2429 OP_S_READ_EXPECT (e
, "foo", 3)
2435 /* 13. Many threads accepted on the same client connection (stress test) */
2436 static const struct script_op script_13_child
[] = {
2437 OP_BEGIN_REPEAT (10)
2439 OP_C_ACCEPT_STREAM_WAIT (a
)
2440 OP_C_READ_EXPECT (a
, "foo", 3)
2442 OP_C_FREE_STREAM (a
)
2449 static const struct script_op script_13
[] = {
2450 OP_C_SET_ALPN ("ossltest")
2451 OP_C_CONNECT_WAIT ()
2452 OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE
)
2454 OP_NEW_THREAD (5, script_13_child
)
2456 OP_BEGIN_REPEAT (50)
2458 OP_S_NEW_STREAM_BIDI (a
, ANY_ID
)
2459 OP_S_WRITE (a
, "foo", 3)
2461 OP_S_UNBIND_STREAM_ID (a
)
2468 /* 14. Many threads initiating on the same client connection (stress test) */
2469 static const struct script_op script_14_child
[] = {
2470 OP_BEGIN_REPEAT (10)
2472 OP_C_NEW_STREAM_BIDI (a
, ANY_ID
)
2473 OP_C_WRITE (a
, "foo", 3)
2475 OP_C_FREE_STREAM (a
)
2482 static const struct script_op script_14
[] = {
2483 OP_C_SET_ALPN ("ossltest")
2484 OP_C_CONNECT_WAIT ()
2485 OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE
)
2487 OP_NEW_THREAD (5, script_14_child
)
2489 OP_BEGIN_REPEAT (50)
2491 OP_S_ACCEPT_STREAM_WAIT (a
)
2492 OP_S_READ_EXPECT (a
, "foo", 3)
2494 OP_S_UNBIND_STREAM_ID (a
)
2501 /* 15. Client sending large number of streams, MAX_STREAMS test */
2502 static const struct script_op script_15
[] = {
2503 OP_C_SET_ALPN ("ossltest")
2504 OP_C_CONNECT_WAIT ()
2505 OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE
)
2508 * This will cause a protocol violation to be raised by the server if we are
2509 * not handling the stream limit correctly on the TX side.
2511 OP_BEGIN_REPEAT (200)
2513 OP_C_NEW_STREAM_BIDI_EX (a
, ANY_ID
, SSL_STREAM_FLAG_ADVANCE
)
2514 OP_C_WRITE (a
, "foo", 3)
2516 OP_C_FREE_STREAM (a
)
2520 /* Prove the connection is still good. */
2521 OP_S_NEW_STREAM_BIDI (a
, S_BIDI_ID(0))
2522 OP_S_WRITE (a
, "bar", 3)
2525 OP_C_ACCEPT_STREAM_WAIT (a
)
2526 OP_C_READ_EXPECT (a
, "bar", 3)
2530 * Drain the queue of incoming streams. We should be able to get all 200
2531 * even though only 100 can be initiated at a time.
2533 OP_BEGIN_REPEAT (200)
2535 OP_S_ACCEPT_STREAM_WAIT (b
)
2536 OP_S_READ_EXPECT (b
, "foo", 3)
2538 OP_S_UNBIND_STREAM_ID (b
)
2545 /* 16. Server sending large number of streams, MAX_STREAMS test */
2546 static const struct script_op script_16
[] = {
2547 OP_C_SET_ALPN ("ossltest")
2548 OP_C_CONNECT_WAIT ()
2549 OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE
)
2552 * This will cause a protocol violation to be raised by the client if we are
2553 * not handling the stream limit correctly on the TX side.
2555 OP_BEGIN_REPEAT (200)
2557 OP_S_NEW_STREAM_BIDI (a
, ANY_ID
)
2558 OP_S_WRITE (a
, "foo", 3)
2560 OP_S_UNBIND_STREAM_ID (a
)
2564 /* Prove that the connection is still good. */
2565 OP_C_NEW_STREAM_BIDI (a
, ANY_ID
)
2566 OP_C_WRITE (a
, "bar", 3)
2569 OP_S_ACCEPT_STREAM_WAIT (b
)
2570 OP_S_READ_EXPECT (b
, "bar", 3)
2573 /* Drain the queue of incoming streams. */
2574 OP_BEGIN_REPEAT (200)
2576 OP_C_ACCEPT_STREAM_WAIT (b
)
2577 OP_C_READ_EXPECT (b
, "foo", 3)
2579 OP_C_FREE_STREAM (b
)
2586 /* 17. Key update test - unlimited */
2587 static const struct script_op script_17
[] = {
2588 OP_C_SET_ALPN ("ossltest")
2589 OP_C_CONNECT_WAIT ()
2591 OP_C_WRITE (DEFAULT
, "apple", 5)
2593 OP_S_BIND_STREAM_ID (a
, C_BIDI_ID(0))
2594 OP_S_READ_EXPECT (a
, "apple", 5)
2596 OP_CHECK (override_key_update
, 1)
2598 OP_BEGIN_REPEAT (200)
2600 OP_C_WRITE (DEFAULT
, "apple", 5)
2601 OP_S_READ_EXPECT (a
, "apple", 5)
2604 * TXKU frequency is bounded by RTT because a previous TXKU needs to be
2605 * acknowledged by the peer first before another one can be begin. By
2606 * waiting this long, we eliminate any such concern and ensure as many key
2607 * updates as possible can occur for the purposes of this test.
2609 OP_CHECK (skip_time_ms
, 100)
2613 /* At least 5 RXKUs detected */
2614 OP_CHECK (check_key_update_ge
, 5)
2617 * Prove the connection is still healthy by sending something in both
2620 OP_C_WRITE (DEFAULT
, "xyzzy", 5)
2621 OP_S_READ_EXPECT (a
, "xyzzy", 5)
2623 OP_S_WRITE (a
, "plugh", 5)
2624 OP_C_READ_EXPECT (DEFAULT
, "plugh", 5)
2629 /* 18. Key update test - RTT-bounded */
2630 static const struct script_op script_18
[] = {
2631 OP_C_SET_ALPN ("ossltest")
2632 OP_C_CONNECT_WAIT ()
2634 OP_C_WRITE (DEFAULT
, "apple", 5)
2636 OP_S_BIND_STREAM_ID (a
, C_BIDI_ID(0))
2637 OP_S_READ_EXPECT (a
, "apple", 5)
2639 OP_CHECK (override_key_update
, 1)
2641 OP_BEGIN_REPEAT (200)
2643 OP_C_WRITE (DEFAULT
, "apple", 5)
2644 OP_S_READ_EXPECT (a
, "apple", 5)
2645 OP_CHECK (skip_time_ms
, 8)
2650 * This time we simulate far less time passing between writes, so there are
2651 * fewer opportunities to initiate TXKUs. Note that we ask for a TXKU every
2652 * 1 packet above, which is absurd; thus this ensures we only actually
2653 * generate TXKUs when we are allowed to.
2655 OP_CHECK (check_key_update_lt
, 240)
2658 * Prove the connection is still healthy by sending something in both
2661 OP_C_WRITE (DEFAULT
, "xyzzy", 5)
2662 OP_S_READ_EXPECT (a
, "xyzzy", 5)
2664 OP_S_WRITE (a
, "plugh", 5)
2665 OP_C_READ_EXPECT (DEFAULT
, "plugh", 5)
2670 /* 19. Key update test - artificially triggered */
2671 static const struct script_op script_19
[] = {
2672 OP_C_SET_ALPN ("ossltest")
2673 OP_C_CONNECT_WAIT ()
2675 OP_C_WRITE (DEFAULT
, "apple", 5)
2677 OP_S_BIND_STREAM_ID (a
, C_BIDI_ID(0))
2678 OP_S_READ_EXPECT (a
, "apple", 5)
2680 OP_C_WRITE (DEFAULT
, "orange", 6)
2681 OP_S_READ_EXPECT (a
, "orange", 6)
2683 OP_S_WRITE (a
, "strawberry", 10)
2684 OP_C_READ_EXPECT (DEFAULT
, "strawberry", 10)
2686 OP_CHECK (check_key_update_lt
, 1)
2687 OP_CHECK (trigger_key_update
, 0)
2689 OP_C_WRITE (DEFAULT
, "orange", 6)
2690 OP_S_READ_EXPECT (a
, "orange", 6)
2691 OP_S_WRITE (a
, "ok", 2)
2693 OP_C_READ_EXPECT (DEFAULT
, "ok", 2)
2694 OP_CHECK (check_key_update_ge
, 1)
2699 /* 20. Multiple threads accept stream with socket forcibly closed (error test) */
2700 static int script_20_trigger(struct helper
*h
, volatile uint64_t *counter
)
2702 #if defined(OPENSSL_THREADS)
2703 ossl_crypto_mutex_lock(h
->misc_m
);
2705 ossl_crypto_condvar_broadcast(h
->misc_cv
);
2706 ossl_crypto_mutex_unlock(h
->misc_m
);
2711 static int script_20_wait(struct helper
*h
, volatile uint64_t *counter
, uint64_t threshold
)
2713 #if defined(OPENSSL_THREADS)
2716 ossl_crypto_mutex_lock(h
->misc_m
);
2718 stop
= (*counter
>= threshold
);
2722 ossl_crypto_condvar_wait(h
->misc_cv
, h
->misc_m
);
2725 ossl_crypto_mutex_unlock(h
->misc_m
);
2730 static int script_20_trigger1(struct helper
*h
, struct helper_local
*hl
)
2732 return script_20_trigger(h
, &h
->scratch0
);
2735 static int script_20_wait1(struct helper
*h
, struct helper_local
*hl
)
2737 return script_20_wait(h
, &h
->scratch0
, hl
->check_op
->arg2
);
2740 static int script_20_trigger2(struct helper
*h
, struct helper_local
*hl
)
2742 return script_20_trigger(h
, &h
->scratch1
);
2745 static int script_20_wait2(struct helper
*h
, struct helper_local
*hl
)
2747 return script_20_wait(h
, &h
->scratch1
, hl
->check_op
->arg2
);
2750 static const struct script_op script_20_child
[] = {
2751 OP_C_ACCEPT_STREAM_WAIT (a
)
2752 OP_C_READ_EXPECT (a
, "foo", 3)
2754 OP_CHECK (script_20_trigger1
, 0)
2755 OP_CHECK (script_20_wait2
, 1)
2757 OP_C_READ_FAIL_WAIT (a
)
2758 OP_C_EXPECT_SSL_ERR (a
, SSL_ERROR_SYSCALL
)
2760 OP_EXPECT_ERR_LIB (ERR_LIB_SSL
)
2761 OP_EXPECT_ERR_REASON (SSL_R_PROTOCOL_IS_SHUTDOWN
)
2764 OP_EXPECT_ERR_LIB (ERR_LIB_SSL
)
2765 OP_EXPECT_ERR_REASON (SSL_R_QUIC_NETWORK_ERROR
)
2767 OP_C_FREE_STREAM (a
)
2772 static const struct script_op script_20
[] = {
2773 OP_C_SET_ALPN ("ossltest")
2774 OP_C_CONNECT_WAIT ()
2775 OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE
)
2777 OP_NEW_THREAD (5, script_20_child
)
2781 OP_S_NEW_STREAM_BIDI (a
, ANY_ID
)
2782 OP_S_WRITE (a
, "foo", 3)
2783 OP_S_UNBIND_STREAM_ID (a
)
2787 OP_CHECK (script_20_wait1
, 5)
2789 OP_C_CLOSE_SOCKET ()
2790 OP_CHECK (script_20_trigger2
, 0)
2795 /* 21. Fault injection - unknown frame in 1-RTT packet */
2796 static int script_21_inject_plain(struct helper
*h
, QUIC_PKT_HDR
*hdr
,
2797 unsigned char *buf
, size_t len
)
2801 unsigned char frame_buf
[8];
2804 if (h
->inject_word0
== 0 || hdr
->type
!= h
->inject_word0
)
2807 if (!TEST_true(WPACKET_init_static_len(&wpkt
, frame_buf
,
2808 sizeof(frame_buf
), 0)))
2811 if (!TEST_true(WPACKET_quic_write_vlint(&wpkt
, h
->inject_word1
)))
2814 if (!TEST_true(WPACKET_get_total_written(&wpkt
, &written
)))
2817 if (!qtest_fault_prepend_frame(h
->qtf
, frame_buf
, written
))
2823 WPACKET_finish(&wpkt
);
2825 WPACKET_cleanup(&wpkt
);
2829 static const struct script_op script_21
[] = {
2830 OP_S_SET_INJECT_PLAIN (script_21_inject_plain
)
2831 OP_C_SET_ALPN ("ossltest")
2832 OP_C_CONNECT_WAIT ()
2834 OP_C_WRITE (DEFAULT
, "apple", 5)
2835 OP_S_BIND_STREAM_ID (a
, C_BIDI_ID(0))
2836 OP_S_READ_EXPECT (a
, "apple", 5)
2838 OP_SET_INJECT_WORD (QUIC_PKT_TYPE_1RTT
, OSSL_QUIC_VLINT_MAX
)
2840 OP_S_WRITE (a
, "orange", 6)
2842 OP_C_EXPECT_CONN_CLOSE_INFO(QUIC_ERR_FRAME_ENCODING_ERROR
,0,0)
2847 /* 22. Fault injection - non-zero packet header reserved bits */
2848 static int script_22_inject_plain(struct helper
*h
, QUIC_PKT_HDR
*hdr
,
2849 unsigned char *buf
, size_t len
)
2851 if (h
->inject_word0
== 0)
2858 static const struct script_op script_22
[] = {
2859 OP_S_SET_INJECT_PLAIN (script_22_inject_plain
)
2860 OP_C_SET_ALPN ("ossltest")
2861 OP_C_CONNECT_WAIT ()
2863 OP_C_WRITE (DEFAULT
, "apple", 5)
2864 OP_S_BIND_STREAM_ID (a
, C_BIDI_ID(0))
2865 OP_S_READ_EXPECT (a
, "apple", 5)
2867 OP_SET_INJECT_WORD (1, 0)
2869 OP_S_WRITE (a
, "orange", 6)
2871 OP_C_EXPECT_CONN_CLOSE_INFO(QUIC_ERR_PROTOCOL_VIOLATION
,0,0)
2876 /* 23. Fault injection - empty NEW_TOKEN */
2877 static int script_23_inject_plain(struct helper
*h
, QUIC_PKT_HDR
*hdr
,
2878 unsigned char *buf
, size_t len
)
2882 unsigned char frame_buf
[16];
2885 if (h
->inject_word0
== 0 || hdr
->type
!= QUIC_PKT_TYPE_1RTT
)
2888 if (!TEST_true(WPACKET_init_static_len(&wpkt
, frame_buf
,
2889 sizeof(frame_buf
), 0)))
2892 if (!TEST_true(WPACKET_quic_write_vlint(&wpkt
, OSSL_QUIC_FRAME_TYPE_NEW_TOKEN
))
2893 || !TEST_true(WPACKET_quic_write_vlint(&wpkt
, 0)))
2896 if (!TEST_true(WPACKET_get_total_written(&wpkt
, &written
)))
2899 if (!qtest_fault_prepend_frame(h
->qtf
, frame_buf
, written
))
2905 WPACKET_finish(&wpkt
);
2907 WPACKET_cleanup(&wpkt
);
2911 static const struct script_op script_23
[] = {
2912 OP_S_SET_INJECT_PLAIN (script_23_inject_plain
)
2913 OP_C_SET_ALPN ("ossltest")
2914 OP_C_CONNECT_WAIT ()
2916 OP_C_WRITE (DEFAULT
, "apple", 5)
2917 OP_S_BIND_STREAM_ID (a
, C_BIDI_ID(0))
2918 OP_S_READ_EXPECT (a
, "apple", 5)
2920 OP_SET_INJECT_WORD (1, 0)
2922 OP_S_WRITE (a
, "orange", 6)
2924 OP_C_EXPECT_CONN_CLOSE_INFO(QUIC_ERR_FRAME_ENCODING_ERROR
,0,0)
2929 /* 24. Fault injection - excess value of MAX_STREAMS_BIDI */
2930 static int script_24_inject_plain(struct helper
*h
, QUIC_PKT_HDR
*hdr
,
2931 unsigned char *buf
, size_t len
)
2935 unsigned char frame_buf
[16];
2938 if (h
->inject_word0
== 0 || hdr
->type
!= QUIC_PKT_TYPE_1RTT
)
2941 if (!TEST_true(WPACKET_init_static_len(&wpkt
, frame_buf
,
2942 sizeof(frame_buf
), 0)))
2945 if (!TEST_true(WPACKET_quic_write_vlint(&wpkt
, h
->inject_word1
))
2946 || !TEST_true(WPACKET_quic_write_vlint(&wpkt
, (((uint64_t)1) << 60) + 1)))
2949 if (!TEST_true(WPACKET_get_total_written(&wpkt
, &written
)))
2952 if (!qtest_fault_prepend_frame(h
->qtf
, frame_buf
, written
))
2958 WPACKET_finish(&wpkt
);
2960 WPACKET_cleanup(&wpkt
);
2964 static const struct script_op script_24
[] = {
2965 OP_S_SET_INJECT_PLAIN (script_24_inject_plain
)
2966 OP_C_SET_ALPN ("ossltest")
2967 OP_C_CONNECT_WAIT ()
2969 OP_C_WRITE (DEFAULT
, "apple", 5)
2970 OP_S_BIND_STREAM_ID (a
, C_BIDI_ID(0))
2971 OP_S_READ_EXPECT (a
, "apple", 5)
2973 OP_SET_INJECT_WORD (1, OSSL_QUIC_FRAME_TYPE_MAX_STREAMS_BIDI
)
2975 OP_S_WRITE (a
, "orange", 6)
2977 OP_C_EXPECT_CONN_CLOSE_INFO(QUIC_ERR_FRAME_ENCODING_ERROR
,0,0)
2982 /* 25. Fault injection - excess value of MAX_STREAMS_UNI */
2983 static const struct script_op script_25
[] = {
2984 OP_S_SET_INJECT_PLAIN (script_24_inject_plain
)
2985 OP_C_SET_ALPN ("ossltest")
2986 OP_C_CONNECT_WAIT ()
2988 OP_C_WRITE (DEFAULT
, "apple", 5)
2989 OP_S_BIND_STREAM_ID (a
, C_BIDI_ID(0))
2990 OP_S_READ_EXPECT (a
, "apple", 5)
2992 OP_SET_INJECT_WORD (1, OSSL_QUIC_FRAME_TYPE_MAX_STREAMS_UNI
)
2994 OP_S_WRITE (a
, "orange", 6)
2996 OP_C_EXPECT_CONN_CLOSE_INFO(QUIC_ERR_FRAME_ENCODING_ERROR
,0,0)
3001 /* 26. Fault injection - excess value of STREAMS_BLOCKED_BIDI */
3002 static const struct script_op script_26
[] = {
3003 OP_S_SET_INJECT_PLAIN (script_24_inject_plain
)
3004 OP_C_SET_ALPN ("ossltest")
3005 OP_C_CONNECT_WAIT ()
3007 OP_C_WRITE (DEFAULT
, "apple", 5)
3008 OP_S_BIND_STREAM_ID (a
, C_BIDI_ID(0))
3009 OP_S_READ_EXPECT (a
, "apple", 5)
3011 OP_SET_INJECT_WORD (1, OSSL_QUIC_FRAME_TYPE_STREAMS_BLOCKED_BIDI
)
3013 OP_S_WRITE (a
, "orange", 6)
3015 OP_C_EXPECT_CONN_CLOSE_INFO(QUIC_ERR_STREAM_LIMIT_ERROR
,0,0)
3020 /* 27. Fault injection - excess value of STREAMS_BLOCKED_UNI */
3021 static const struct script_op script_27
[] = {
3022 OP_S_SET_INJECT_PLAIN (script_24_inject_plain
)
3023 OP_C_SET_ALPN ("ossltest")
3024 OP_C_CONNECT_WAIT ()
3026 OP_C_WRITE (DEFAULT
, "apple", 5)
3027 OP_S_BIND_STREAM_ID (a
, C_BIDI_ID(0))
3028 OP_S_READ_EXPECT (a
, "apple", 5)
3030 OP_SET_INJECT_WORD (1, OSSL_QUIC_FRAME_TYPE_STREAMS_BLOCKED_UNI
)
3032 OP_S_WRITE (a
, "orange", 6)
3034 OP_C_EXPECT_CONN_CLOSE_INFO(QUIC_ERR_STREAM_LIMIT_ERROR
,0,0)
3039 /* 28. Fault injection - received RESET_STREAM for send-only stream */
3040 static int script_28_inject_plain(struct helper
*h
, QUIC_PKT_HDR
*hdr
,
3041 unsigned char *buf
, size_t len
)
3045 unsigned char frame_buf
[32];
3048 if (h
->inject_word0
== 0 || hdr
->type
!= QUIC_PKT_TYPE_1RTT
)
3051 if (!TEST_true(WPACKET_init_static_len(&wpkt
, frame_buf
,
3052 sizeof(frame_buf
), 0)))
3055 if (!TEST_true(WPACKET_quic_write_vlint(&wpkt
, h
->inject_word1
))
3056 || !TEST_true(WPACKET_quic_write_vlint(&wpkt
, /* stream ID */
3057 h
->inject_word0
- 1))
3058 || !TEST_true(WPACKET_quic_write_vlint(&wpkt
, 123))
3059 || (h
->inject_word1
== OSSL_QUIC_FRAME_TYPE_RESET_STREAM
3060 && !TEST_true(WPACKET_quic_write_vlint(&wpkt
, 5)))) /* final size */
3063 if (!TEST_true(WPACKET_get_total_written(&wpkt
, &written
)))
3066 if (!qtest_fault_prepend_frame(h
->qtf
, frame_buf
, written
))
3072 WPACKET_finish(&wpkt
);
3074 WPACKET_cleanup(&wpkt
);
3078 static const struct script_op script_28
[] = {
3079 OP_S_SET_INJECT_PLAIN (script_28_inject_plain
)
3080 OP_C_SET_ALPN ("ossltest")
3081 OP_C_CONNECT_WAIT ()
3082 OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE
)
3084 OP_C_NEW_STREAM_BIDI (a
, C_BIDI_ID(0))
3085 OP_C_WRITE (a
, "orange", 6)
3087 OP_S_BIND_STREAM_ID (a
, C_BIDI_ID(0))
3088 OP_S_READ_EXPECT (a
, "orange", 6)
3090 OP_C_NEW_STREAM_UNI (b
, C_UNI_ID(0))
3091 OP_C_WRITE (b
, "apple", 5)
3093 OP_S_BIND_STREAM_ID (b
, C_UNI_ID(0))
3094 OP_S_READ_EXPECT (b
, "apple", 5)
3096 OP_SET_INJECT_WORD (C_UNI_ID(0) + 1, OSSL_QUIC_FRAME_TYPE_RESET_STREAM
)
3097 OP_S_WRITE (a
, "fruit", 5)
3099 OP_C_EXPECT_CONN_CLOSE_INFO(QUIC_ERR_STREAM_STATE_ERROR
,0,0)
3104 /* 29. Fault injection - received RESET_STREAM for nonexistent send-only stream */
3105 static const struct script_op script_29
[] = {
3106 OP_S_SET_INJECT_PLAIN (script_28_inject_plain
)
3107 OP_C_SET_ALPN ("ossltest")
3108 OP_C_CONNECT_WAIT ()
3109 OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE
)
3111 OP_C_NEW_STREAM_BIDI (a
, C_BIDI_ID(0))
3112 OP_C_WRITE (a
, "orange", 6)
3114 OP_S_BIND_STREAM_ID (a
, C_BIDI_ID(0))
3115 OP_S_READ_EXPECT (a
, "orange", 6)
3117 OP_C_NEW_STREAM_UNI (b
, C_UNI_ID(0))
3118 OP_C_WRITE (b
, "apple", 5)
3120 OP_S_BIND_STREAM_ID (b
, C_UNI_ID(0))
3121 OP_S_READ_EXPECT (b
, "apple", 5)
3123 OP_SET_INJECT_WORD (C_UNI_ID(1) + 1, OSSL_QUIC_FRAME_TYPE_RESET_STREAM
)
3124 OP_S_WRITE (a
, "fruit", 5)
3126 OP_C_EXPECT_CONN_CLOSE_INFO(QUIC_ERR_STREAM_STATE_ERROR
,0,0)
3131 /* 30. Fault injection - received STOP_SENDING for receive-only stream */
3132 static const struct script_op script_30
[] = {
3133 OP_S_SET_INJECT_PLAIN (script_28_inject_plain
)
3134 OP_C_SET_ALPN ("ossltest")
3135 OP_C_CONNECT_WAIT ()
3136 OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE
)
3138 OP_S_NEW_STREAM_UNI (a
, S_UNI_ID(0))
3139 OP_S_WRITE (a
, "apple", 5)
3141 OP_C_ACCEPT_STREAM_WAIT (a
)
3142 OP_C_READ_EXPECT (a
, "apple", 5)
3144 OP_SET_INJECT_WORD (S_UNI_ID(0) + 1, OSSL_QUIC_FRAME_TYPE_STOP_SENDING
)
3145 OP_S_WRITE (a
, "orange", 6)
3147 OP_C_EXPECT_CONN_CLOSE_INFO(QUIC_ERR_STREAM_STATE_ERROR
,0,0)
3152 /* 31. Fault injection - received STOP_SENDING for nonexistent receive-only stream */
3153 static const struct script_op script_31
[] = {
3154 OP_S_SET_INJECT_PLAIN (script_28_inject_plain
)
3155 OP_C_SET_ALPN ("ossltest")
3156 OP_C_CONNECT_WAIT ()
3157 OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE
)
3159 OP_S_NEW_STREAM_UNI (a
, S_UNI_ID(0))
3160 OP_S_WRITE (a
, "apple", 5)
3162 OP_C_ACCEPT_STREAM_WAIT (a
)
3163 OP_C_READ_EXPECT (a
, "apple", 5)
3165 OP_SET_INJECT_WORD (C_UNI_ID(0) + 1, OSSL_QUIC_FRAME_TYPE_STOP_SENDING
)
3166 OP_S_WRITE (a
, "orange", 6)
3168 OP_C_EXPECT_CONN_CLOSE_INFO(QUIC_ERR_STREAM_STATE_ERROR
,0,0)
3173 /* 32. Fault injection - STREAM frame for nonexistent stream */
3174 static int script_32_inject_plain(struct helper
*h
, QUIC_PKT_HDR
*hdr
,
3175 unsigned char *buf
, size_t len
)
3179 unsigned char frame_buf
[64];
3181 uint64_t type
= OSSL_QUIC_FRAME_TYPE_STREAM_OFF_LEN
, offset
, flen
, i
;
3183 if (hdr
->type
!= QUIC_PKT_TYPE_1RTT
)
3186 switch (h
->inject_word1
) {
3196 offset
= (((uint64_t)1)<<62) - 1;
3200 offset
= 1 * 1024 * 1024 * 1024; /* 1G */
3209 if (!TEST_true(WPACKET_init_static_len(&wpkt
, frame_buf
,
3210 sizeof(frame_buf
), 0)))
3213 if (!TEST_true(WPACKET_quic_write_vlint(&wpkt
, type
))
3214 || !TEST_true(WPACKET_quic_write_vlint(&wpkt
, /* stream ID */
3215 h
->inject_word0
- 1))
3216 || !TEST_true(WPACKET_quic_write_vlint(&wpkt
, offset
))
3217 || !TEST_true(WPACKET_quic_write_vlint(&wpkt
, flen
)))
3220 for (i
= 0; i
< flen
; ++i
)
3221 if (!TEST_true(WPACKET_put_bytes_u8(&wpkt
, 0x42)))
3224 if (!TEST_true(WPACKET_get_total_written(&wpkt
, &written
)))
3227 if (!qtest_fault_prepend_frame(h
->qtf
, frame_buf
, written
))
3233 WPACKET_finish(&wpkt
);
3235 WPACKET_cleanup(&wpkt
);
3239 static const struct script_op script_32
[] = {
3240 OP_S_SET_INJECT_PLAIN (script_32_inject_plain
)
3241 OP_C_SET_ALPN ("ossltest")
3242 OP_C_CONNECT_WAIT ()
3243 OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE
)
3245 OP_S_NEW_STREAM_UNI (a
, S_UNI_ID(0))
3246 OP_S_WRITE (a
, "apple", 5)
3248 OP_C_ACCEPT_STREAM_WAIT (a
)
3249 OP_C_READ_EXPECT (a
, "apple", 5)
3251 OP_SET_INJECT_WORD (C_UNI_ID(0) + 1, 1)
3252 OP_S_WRITE (a
, "orange", 6)
3254 OP_C_EXPECT_CONN_CLOSE_INFO(QUIC_ERR_STREAM_STATE_ERROR
,0,0)
3259 /* 33. Fault injection - STREAM frame with illegal offset */
3260 static const struct script_op script_33
[] = {
3261 OP_S_SET_INJECT_PLAIN (script_32_inject_plain
)
3262 OP_C_SET_ALPN ("ossltest")
3263 OP_C_CONNECT_WAIT ()
3264 OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE
)
3266 OP_C_NEW_STREAM_BIDI (a
, C_BIDI_ID(0))
3267 OP_C_WRITE (a
, "apple", 5)
3269 OP_S_BIND_STREAM_ID (a
, C_BIDI_ID(0))
3270 OP_S_READ_EXPECT (a
, "apple", 5)
3272 OP_SET_INJECT_WORD (C_BIDI_ID(0) + 1, 2)
3273 OP_S_WRITE (a
, "orange", 6)
3275 OP_C_EXPECT_CONN_CLOSE_INFO(QUIC_ERR_FRAME_ENCODING_ERROR
,0,0)
3280 /* 34. Fault injection - STREAM frame which exceeds FC */
3281 static const struct script_op script_34
[] = {
3282 OP_S_SET_INJECT_PLAIN (script_32_inject_plain
)
3283 OP_C_SET_ALPN ("ossltest")
3284 OP_C_CONNECT_WAIT ()
3285 OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE
)
3287 OP_C_NEW_STREAM_BIDI (a
, C_BIDI_ID(0))
3288 OP_C_WRITE (a
, "apple", 5)
3290 OP_S_BIND_STREAM_ID (a
, C_BIDI_ID(0))
3291 OP_S_READ_EXPECT (a
, "apple", 5)
3293 OP_SET_INJECT_WORD (C_BIDI_ID(0) + 1, 3)
3294 OP_S_WRITE (a
, "orange", 6)
3296 OP_C_EXPECT_CONN_CLOSE_INFO(QUIC_ERR_FLOW_CONTROL_ERROR
,0,0)
3301 /* 35. Fault injection - MAX_STREAM_DATA for receive-only stream */
3302 static const struct script_op script_35
[] = {
3303 OP_S_SET_INJECT_PLAIN (script_28_inject_plain
)
3304 OP_C_SET_ALPN ("ossltest")
3305 OP_C_CONNECT_WAIT ()
3306 OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE
)
3308 OP_S_NEW_STREAM_UNI (a
, S_UNI_ID(0))
3309 OP_S_WRITE (a
, "apple", 5)
3311 OP_C_ACCEPT_STREAM_WAIT (a
)
3312 OP_C_READ_EXPECT (a
, "apple", 5)
3314 OP_SET_INJECT_WORD (S_UNI_ID(0) + 1, OSSL_QUIC_FRAME_TYPE_MAX_STREAM_DATA
)
3315 OP_S_WRITE (a
, "orange", 6)
3317 OP_C_EXPECT_CONN_CLOSE_INFO(QUIC_ERR_STREAM_STATE_ERROR
,0,0)
3322 /* 36. Fault injection - MAX_STREAM_DATA for nonexistent stream */
3323 static const struct script_op script_36
[] = {
3324 OP_S_SET_INJECT_PLAIN (script_28_inject_plain
)
3325 OP_C_SET_ALPN ("ossltest")
3326 OP_C_CONNECT_WAIT ()
3327 OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE
)
3329 OP_S_NEW_STREAM_UNI (a
, S_UNI_ID(0))
3330 OP_S_WRITE (a
, "apple", 5)
3332 OP_C_ACCEPT_STREAM_WAIT (a
)
3333 OP_C_READ_EXPECT (a
, "apple", 5)
3335 OP_SET_INJECT_WORD (C_BIDI_ID(0) + 1, OSSL_QUIC_FRAME_TYPE_MAX_STREAM_DATA
)
3336 OP_S_WRITE (a
, "orange", 6)
3338 OP_C_EXPECT_CONN_CLOSE_INFO(QUIC_ERR_STREAM_STATE_ERROR
,0,0)
3343 /* 37. Fault injection - STREAM_DATA_BLOCKED for send-only stream */
3344 static const struct script_op script_37
[] = {
3345 OP_S_SET_INJECT_PLAIN (script_28_inject_plain
)
3346 OP_C_SET_ALPN ("ossltest")
3347 OP_C_CONNECT_WAIT ()
3348 OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE
)
3350 OP_C_NEW_STREAM_UNI (a
, C_UNI_ID(0))
3351 OP_C_WRITE (a
, "apple", 5)
3353 OP_S_BIND_STREAM_ID (a
, C_UNI_ID(0))
3354 OP_S_READ_EXPECT (a
, "apple", 5)
3356 OP_S_NEW_STREAM_UNI (b
, S_UNI_ID(0))
3357 OP_SET_INJECT_WORD (C_UNI_ID(0) + 1, OSSL_QUIC_FRAME_TYPE_STREAM_DATA_BLOCKED
)
3358 OP_S_WRITE (b
, "orange", 5)
3360 OP_C_EXPECT_CONN_CLOSE_INFO(QUIC_ERR_STREAM_STATE_ERROR
,0,0)
3365 /* 38. Fault injection - STREAM_DATA_BLOCKED for non-existent stream */
3366 static const struct script_op script_38
[] = {
3367 OP_S_SET_INJECT_PLAIN (script_28_inject_plain
)
3368 OP_C_SET_ALPN ("ossltest")
3369 OP_C_CONNECT_WAIT ()
3370 OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE
)
3372 OP_C_NEW_STREAM_UNI (a
, C_UNI_ID(0))
3373 OP_C_WRITE (a
, "apple", 5)
3375 OP_S_BIND_STREAM_ID (a
, C_UNI_ID(0))
3376 OP_S_READ_EXPECT (a
, "apple", 5)
3378 OP_SET_INJECT_WORD (C_BIDI_ID(0) + 1, OSSL_QUIC_FRAME_TYPE_STREAM_DATA_BLOCKED
)
3380 OP_S_NEW_STREAM_UNI (b
, S_UNI_ID(0))
3381 OP_S_WRITE (b
, "orange", 5)
3383 OP_C_EXPECT_CONN_CLOSE_INFO(QUIC_ERR_STREAM_STATE_ERROR
,0,0)
3388 /* 39. Fault injection - NEW_CONN_ID with zero-len CID */
3389 static int script_39_inject_plain(struct helper
*h
, QUIC_PKT_HDR
*hdr
,
3390 unsigned char *buf
, size_t len
)
3394 unsigned char frame_buf
[64];
3396 uint64_t seq_no
= 0, retire_prior_to
= 0;
3397 QUIC_CONN_ID new_cid
= {0};
3398 QUIC_CHANNEL
*ch
= ossl_quic_tserver_get_channel(h
->s_priv
);
3400 if (hdr
->type
!= QUIC_PKT_TYPE_1RTT
)
3403 switch (h
->inject_word1
) {
3410 new_cid
.id_len
= 21;
3414 new_cid
.id
[0] = 0x55;
3417 retire_prior_to
= 1;
3420 /* Use our actual CID so we don't break connectivity. */
3421 ossl_quic_channel_get_diag_local_cid(ch
, &new_cid
);
3424 retire_prior_to
= 2;
3428 * Use a bogus CID which will need to be ignored if connectivity is to
3432 new_cid
.id
[0] = 0x55;
3435 retire_prior_to
= 1;
3439 if (!TEST_true(WPACKET_init_static_len(&wpkt
, frame_buf
,
3440 sizeof(frame_buf
), 0)))
3443 if (!TEST_true(WPACKET_quic_write_vlint(&wpkt
, OSSL_QUIC_FRAME_TYPE_NEW_CONN_ID
))
3444 || !TEST_true(WPACKET_quic_write_vlint(&wpkt
, seq_no
)) /* seq no */
3445 || !TEST_true(WPACKET_quic_write_vlint(&wpkt
, retire_prior_to
)) /* retire prior to */
3446 || !TEST_true(WPACKET_put_bytes_u8(&wpkt
, new_cid
.id_len
))) /* len */
3449 for (i
= 0; i
< new_cid
.id_len
&& i
< OSSL_NELEM(new_cid
.id
); ++i
)
3450 if (!TEST_true(WPACKET_put_bytes_u8(&wpkt
, new_cid
.id
[i
])))
3453 for (; i
< new_cid
.id_len
; ++i
)
3454 if (!TEST_true(WPACKET_put_bytes_u8(&wpkt
, 0x55)))
3457 for (i
= 0; i
< QUIC_STATELESS_RESET_TOKEN_LEN
; ++i
)
3458 if (!TEST_true(WPACKET_put_bytes_u8(&wpkt
, 0x42)))
3461 if (!TEST_true(WPACKET_get_total_written(&wpkt
, &written
)))
3464 if (!qtest_fault_prepend_frame(h
->qtf
, frame_buf
, written
))
3470 WPACKET_finish(&wpkt
);
3472 WPACKET_cleanup(&wpkt
);
3476 static const struct script_op script_39
[] = {
3477 OP_S_SET_INJECT_PLAIN (script_39_inject_plain
)
3478 OP_C_SET_ALPN ("ossltest")
3479 OP_C_CONNECT_WAIT ()
3480 OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE
)
3482 OP_C_NEW_STREAM_BIDI (a
, C_BIDI_ID(0))
3483 OP_C_WRITE (a
, "apple", 5)
3484 OP_S_BIND_STREAM_ID (a
, C_BIDI_ID(0))
3485 OP_S_READ_EXPECT (a
, "apple", 5)
3487 OP_SET_INJECT_WORD (0, 1)
3488 OP_S_WRITE (a
, "orange", 5)
3490 OP_C_EXPECT_CONN_CLOSE_INFO(QUIC_ERR_FRAME_ENCODING_ERROR
,0,0)
3495 /* 40. Shutdown flush test */
3496 static const unsigned char script_40_data
[1024] = "strawberry";
3498 static const struct script_op script_40
[] = {
3499 OP_C_SET_ALPN ("ossltest")
3500 OP_C_CONNECT_WAIT ()
3501 OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE
)
3503 OP_C_NEW_STREAM_BIDI (a
, C_BIDI_ID(0))
3504 OP_C_WRITE (a
, "apple", 5)
3506 OP_C_INHIBIT_TICK (1)
3507 OP_C_SET_WRITE_BUF_SIZE (a
, 1024 * 100 * 3)
3509 OP_BEGIN_REPEAT (100)
3511 OP_C_WRITE (a
, script_40_data
, sizeof(script_40_data
))
3516 OP_C_SHUTDOWN_WAIT (NULL
, 0) /* disengages tick inhibition */
3518 OP_S_BIND_STREAM_ID (a
, C_BIDI_ID(0))
3519 OP_S_READ_EXPECT (a
, "apple", 5)
3521 OP_BEGIN_REPEAT (100)
3523 OP_S_READ_EXPECT (a
, script_40_data
, sizeof(script_40_data
))
3529 OP_C_EXPECT_CONN_CLOSE_INFO(0, 1, 0)
3530 OP_S_EXPECT_CONN_CLOSE_INFO(0, 1, 1)
3535 /* 41. Fault injection - PATH_CHALLENGE yields PATH_RESPONSE */
3536 static const uint64_t path_challenge
= UINT64_C(0xbdeb9451169c83aa);
3538 static int script_41_inject_plain(struct helper
*h
, QUIC_PKT_HDR
*hdr
,
3539 unsigned char *buf
, size_t len
)
3543 unsigned char frame_buf
[16];
3546 if (h
->inject_word0
== 0 || hdr
->type
!= QUIC_PKT_TYPE_1RTT
)
3549 if (!TEST_true(WPACKET_init_static_len(&wpkt
, frame_buf
,
3550 sizeof(frame_buf
), 0)))
3553 if (!TEST_true(WPACKET_quic_write_vlint(&wpkt
, h
->inject_word1
))
3554 || !TEST_true(WPACKET_put_bytes_u64(&wpkt
, path_challenge
)))
3557 if (!TEST_true(WPACKET_get_total_written(&wpkt
, &written
))
3558 || !TEST_size_t_eq(written
, 9))
3561 if (!qtest_fault_prepend_frame(h
->qtf
, frame_buf
, written
))
3568 WPACKET_finish(&wpkt
);
3570 WPACKET_cleanup(&wpkt
);
3574 static void script_41_trace(int write_p
, int version
, int content_type
,
3575 const void *buf
, size_t len
, SSL
*ssl
, void *arg
)
3577 uint64_t frame_type
, frame_data
;
3579 struct helper
*h
= arg
;
3582 if (version
!= OSSL_QUIC1_VERSION
3583 || content_type
!= SSL3_RT_QUIC_FRAME_FULL
3587 if (!TEST_true(PACKET_buf_init(&pkt
, buf
, len
))) {
3592 if (!TEST_true(ossl_quic_wire_peek_frame_header(&pkt
, &frame_type
,
3598 if (frame_type
!= OSSL_QUIC_FRAME_TYPE_PATH_RESPONSE
)
3601 if (!TEST_true(ossl_quic_wire_decode_frame_path_response(&pkt
, &frame_data
))
3602 || !TEST_uint64_t_eq(frame_data
, path_challenge
)) {
3610 static int script_41_setup(struct helper
*h
, struct helper_local
*hl
)
3612 ossl_quic_tserver_set_msg_callback(ACQUIRE_S(), script_41_trace
, h
);
3616 static int script_41_check(struct helper
*h
, struct helper_local
*hl
)
3618 /* At least one valid challenge/response echo? */
3619 if (!TEST_uint64_t_gt(h
->scratch0
, 0))
3622 /* No failed tests? */
3623 if (!TEST_uint64_t_eq(h
->scratch1
, 0))
3629 static const struct script_op script_41
[] = {
3630 OP_S_SET_INJECT_PLAIN (script_41_inject_plain
)
3631 OP_C_SET_ALPN ("ossltest")
3632 OP_C_CONNECT_WAIT ()
3633 OP_CHECK (script_41_setup
, 0)
3635 OP_C_WRITE (DEFAULT
, "apple", 5)
3636 OP_S_BIND_STREAM_ID (a
, C_BIDI_ID(0))
3637 OP_S_READ_EXPECT (a
, "apple", 5)
3639 OP_SET_INJECT_WORD (1, OSSL_QUIC_FRAME_TYPE_PATH_CHALLENGE
)
3641 OP_S_WRITE (a
, "orange", 6)
3642 OP_C_READ_EXPECT (DEFAULT
, "orange", 6)
3644 OP_C_WRITE (DEFAULT
, "strawberry", 10)
3645 OP_S_READ_EXPECT (a
, "strawberry", 10)
3647 OP_CHECK (script_41_check
, 0)
3651 /* 42. Fault injection - CRYPTO frame with illegal offset */
3652 static int script_42_inject_plain(struct helper
*h
, QUIC_PKT_HDR
*hdr
,
3653 unsigned char *buf
, size_t len
)
3656 unsigned char frame_buf
[64];
3660 if (h
->inject_word0
== 0)
3665 if (!TEST_true(WPACKET_init_static_len(&wpkt
, frame_buf
,
3666 sizeof(frame_buf
), 0)))
3669 if (!TEST_true(WPACKET_quic_write_vlint(&wpkt
, OSSL_QUIC_FRAME_TYPE_CRYPTO
))
3670 || !TEST_true(WPACKET_quic_write_vlint(&wpkt
, h
->inject_word1
))
3671 || !TEST_true(WPACKET_quic_write_vlint(&wpkt
, 1))
3672 || !TEST_true(WPACKET_put_bytes_u8(&wpkt
, 0x42)))
3675 if (!TEST_true(WPACKET_get_total_written(&wpkt
, &written
)))
3678 if (!qtest_fault_prepend_frame(h
->qtf
, frame_buf
, written
))
3684 WPACKET_finish(&wpkt
);
3686 WPACKET_cleanup(&wpkt
);
3690 static const struct script_op script_42
[] = {
3691 OP_S_SET_INJECT_PLAIN (script_42_inject_plain
)
3692 OP_C_SET_ALPN ("ossltest")
3693 OP_C_CONNECT_WAIT ()
3694 OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE
)
3696 OP_C_NEW_STREAM_BIDI (a
, C_BIDI_ID(0))
3697 OP_C_WRITE (a
, "apple", 5)
3699 OP_S_BIND_STREAM_ID (a
, C_BIDI_ID(0))
3700 OP_S_READ_EXPECT (a
, "apple", 5)
3702 OP_SET_INJECT_WORD (1, (((uint64_t)1) << 62) - 1)
3703 OP_S_WRITE (a
, "orange", 6)
3705 OP_C_EXPECT_CONN_CLOSE_INFO(QUIC_ERR_FRAME_ENCODING_ERROR
,0,0)
3710 /* 43. Fault injection - CRYPTO frame exceeding FC */
3711 static const struct script_op script_43
[] = {
3712 OP_S_SET_INJECT_PLAIN (script_42_inject_plain
)
3713 OP_C_SET_ALPN ("ossltest")
3714 OP_C_CONNECT_WAIT ()
3715 OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE
)
3717 OP_C_NEW_STREAM_BIDI (a
, C_BIDI_ID(0))
3718 OP_C_WRITE (a
, "apple", 5)
3720 OP_S_BIND_STREAM_ID (a
, C_BIDI_ID(0))
3721 OP_S_READ_EXPECT (a
, "apple", 5)
3723 OP_SET_INJECT_WORD (1, 0x100000 /* 1 MiB */)
3724 OP_S_WRITE (a
, "orange", 6)
3726 OP_C_EXPECT_CONN_CLOSE_INFO(QUIC_ERR_CRYPTO_BUFFER_EXCEEDED
,0,0)
3731 /* 44. Fault injection - PADDING */
3732 static int script_44_inject_plain(struct helper
*h
, QUIC_PKT_HDR
*hdr
,
3733 unsigned char *buf
, size_t len
)
3737 unsigned char frame_buf
[16];
3740 if (h
->inject_word0
== 0 || hdr
->type
!= QUIC_PKT_TYPE_1RTT
)
3743 if (!TEST_true(WPACKET_init_static_len(&wpkt
, frame_buf
,
3744 sizeof(frame_buf
), 0)))
3747 if (!TEST_true(ossl_quic_wire_encode_padding(&wpkt
, 1)))
3750 if (!TEST_true(WPACKET_get_total_written(&wpkt
, &written
)))
3753 if (!qtest_fault_prepend_frame(h
->qtf
, frame_buf
, written
))
3759 WPACKET_finish(&wpkt
);
3761 WPACKET_cleanup(&wpkt
);
3765 static const struct script_op script_44
[] = {
3766 OP_S_SET_INJECT_PLAIN (script_44_inject_plain
)
3767 OP_C_SET_ALPN ("ossltest")
3768 OP_C_CONNECT_WAIT ()
3770 OP_C_WRITE (DEFAULT
, "apple", 5)
3771 OP_S_BIND_STREAM_ID (a
, C_BIDI_ID(0))
3772 OP_S_READ_EXPECT (a
, "apple", 5)
3774 OP_SET_INJECT_WORD (1, 0)
3776 OP_S_WRITE (a
, "Strawberry", 10)
3777 OP_C_READ_EXPECT (DEFAULT
, "Strawberry", 10)
3782 /* 45. PING must generate ACK */
3783 static int force_ping(struct helper
*h
, struct helper_local
*hl
)
3785 QUIC_CHANNEL
*ch
= ossl_quic_tserver_get_channel(ACQUIRE_S());
3787 h
->scratch0
= ossl_quic_channel_get_diag_num_rx_ack(ch
);
3789 if (!TEST_true(ossl_quic_tserver_ping(ACQUIRE_S())))
3795 static int wait_incoming_acks_increased(struct helper
*h
, struct helper_local
*hl
)
3797 QUIC_CHANNEL
*ch
= ossl_quic_tserver_get_channel(ACQUIRE_S());
3800 count
= ossl_quic_channel_get_diag_num_rx_ack(ch
);
3802 if (count
== h
->scratch0
) {
3803 h
->check_spin_again
= 1;
3810 static const struct script_op script_45
[] = {
3811 OP_C_SET_ALPN ("ossltest")
3812 OP_C_CONNECT_WAIT ()
3814 OP_C_WRITE (DEFAULT
, "apple", 5)
3815 OP_S_BIND_STREAM_ID (a
, C_BIDI_ID(0))
3816 OP_S_READ_EXPECT (a
, "apple", 5)
3820 OP_CHECK (force_ping
, 0)
3821 OP_CHECK (wait_incoming_acks_increased
, 0)
3825 OP_S_WRITE (a
, "Strawberry", 10)
3826 OP_C_READ_EXPECT (DEFAULT
, "Strawberry", 10)
3831 /* 46. Fault injection - ACK - malformed initial range */
3832 static int script_46_inject_plain(struct helper
*h
, QUIC_PKT_HDR
*hdr
,
3833 unsigned char *buf
, size_t len
)
3837 unsigned char frame_buf
[16];
3839 uint64_t type
= 0, largest_acked
= 0, first_range
= 0, range_count
= 0;
3840 uint64_t agap
= 0, alen
= 0;
3841 uint64_t ect0
= 0, ect1
= 0, ecnce
= 0;
3843 if (h
->inject_word0
== 0)
3846 if (!TEST_true(WPACKET_init_static_len(&wpkt
, frame_buf
,
3847 sizeof(frame_buf
), 0)))
3850 type
= OSSL_QUIC_FRAME_TYPE_ACK_WITHOUT_ECN
;
3852 switch (h
->inject_word0
) {
3854 largest_acked
= 100;
3859 largest_acked
= 100;
3861 /* [20..100]; [0..18] */
3867 largest_acked
= 100;
3874 type
= OSSL_QUIC_FRAME_TYPE_ACK_WITH_ECN
;
3875 largest_acked
= 100;
3880 type
= OSSL_QUIC_FRAME_TYPE_ACK_WITH_ECN
;
3890 h
->inject_word0
= 0;
3892 if (!TEST_true(WPACKET_quic_write_vlint(&wpkt
, type
))
3893 || !TEST_true(WPACKET_quic_write_vlint(&wpkt
, largest_acked
))
3894 || !TEST_true(WPACKET_quic_write_vlint(&wpkt
, /*ack_delay=*/0))
3895 || !TEST_true(WPACKET_quic_write_vlint(&wpkt
, /*ack_range_count=*/range_count
))
3896 || !TEST_true(WPACKET_quic_write_vlint(&wpkt
, /*first_ack_range=*/first_range
)))
3899 if (range_count
> 0)
3900 if (!TEST_true(WPACKET_quic_write_vlint(&wpkt
, /*range[0].gap=*/agap
))
3901 || !TEST_true(WPACKET_quic_write_vlint(&wpkt
, /*range[0].len=*/alen
)))
3904 if (type
== OSSL_QUIC_FRAME_TYPE_ACK_WITH_ECN
)
3905 if (!TEST_true(WPACKET_quic_write_vlint(&wpkt
, ect0
))
3906 || !TEST_true(WPACKET_quic_write_vlint(&wpkt
, ect1
))
3907 || !TEST_true(WPACKET_quic_write_vlint(&wpkt
, ecnce
)))
3910 if (!TEST_true(WPACKET_get_total_written(&wpkt
, &written
)))
3913 if (!qtest_fault_prepend_frame(h
->qtf
, frame_buf
, written
))
3919 WPACKET_finish(&wpkt
);
3921 WPACKET_cleanup(&wpkt
);
3925 static const struct script_op script_46
[] = {
3926 OP_S_SET_INJECT_PLAIN (script_46_inject_plain
)
3927 OP_C_SET_ALPN ("ossltest")
3928 OP_C_CONNECT_WAIT ()
3930 OP_C_WRITE (DEFAULT
, "apple", 5)
3931 OP_S_BIND_STREAM_ID (a
, C_BIDI_ID(0))
3932 OP_S_READ_EXPECT (a
, "apple", 5)
3934 OP_SET_INJECT_WORD (1, 0)
3936 OP_S_WRITE (a
, "Strawberry", 10)
3938 OP_C_EXPECT_CONN_CLOSE_INFO(QUIC_ERR_FRAME_ENCODING_ERROR
,0,0)
3943 /* 47. Fault injection - ACK - malformed subsequent range */
3944 static const struct script_op script_47
[] = {
3945 OP_S_SET_INJECT_PLAIN (script_46_inject_plain
)
3946 OP_C_SET_ALPN ("ossltest")
3947 OP_C_CONNECT_WAIT ()
3949 OP_C_WRITE (DEFAULT
, "apple", 5)
3950 OP_S_BIND_STREAM_ID (a
, C_BIDI_ID(0))
3951 OP_S_READ_EXPECT (a
, "apple", 5)
3953 OP_SET_INJECT_WORD (2, 0)
3955 OP_S_WRITE (a
, "Strawberry", 10)
3957 OP_C_EXPECT_CONN_CLOSE_INFO(QUIC_ERR_FRAME_ENCODING_ERROR
,0,0)
3962 /* 48. Fault injection - ACK - malformed subsequent range */
3963 static const struct script_op script_48
[] = {
3964 OP_S_SET_INJECT_PLAIN (script_46_inject_plain
)
3965 OP_C_SET_ALPN ("ossltest")
3966 OP_C_CONNECT_WAIT ()
3968 OP_C_WRITE (DEFAULT
, "apple", 5)
3969 OP_S_BIND_STREAM_ID (a
, C_BIDI_ID(0))
3970 OP_S_READ_EXPECT (a
, "apple", 5)
3972 OP_SET_INJECT_WORD (3, 0)
3974 OP_S_WRITE (a
, "Strawberry", 10)
3976 OP_C_EXPECT_CONN_CLOSE_INFO(QUIC_ERR_FRAME_ENCODING_ERROR
,0,0)
3981 /* 49. Fault injection - ACK - fictional PN */
3982 static const struct script_op script_49
[] = {
3983 OP_S_SET_INJECT_PLAIN (script_46_inject_plain
)
3984 OP_C_SET_ALPN ("ossltest")
3985 OP_C_CONNECT_WAIT ()
3987 OP_C_WRITE (DEFAULT
, "apple", 5)
3988 OP_S_BIND_STREAM_ID (a
, C_BIDI_ID(0))
3989 OP_S_READ_EXPECT (a
, "apple", 5)
3991 OP_SET_INJECT_WORD (4, 0)
3993 OP_S_WRITE (a
, "Strawberry", 10)
3994 OP_C_READ_EXPECT (DEFAULT
, "Strawberry", 10)
3999 /* 50. Fault injection - ACK - duplicate PN */
4000 static const struct script_op script_50
[] = {
4001 OP_S_SET_INJECT_PLAIN (script_46_inject_plain
)
4002 OP_C_SET_ALPN ("ossltest")
4003 OP_C_CONNECT_WAIT ()
4005 OP_C_WRITE (DEFAULT
, "apple", 5)
4006 OP_S_BIND_STREAM_ID (a
, C_BIDI_ID(0))
4007 OP_S_READ_EXPECT (a
, "apple", 5)
4011 OP_SET_INJECT_WORD (5, 0)
4013 OP_S_WRITE (a
, "Strawberry", 10)
4014 OP_C_READ_EXPECT (DEFAULT
, "Strawberry", 10)
4021 /* 51. Fault injection - PATH_RESPONSE is ignored */
4022 static const struct script_op script_51
[] = {
4023 OP_S_SET_INJECT_PLAIN (script_41_inject_plain
)
4024 OP_C_SET_ALPN ("ossltest")
4025 OP_C_CONNECT_WAIT ()
4027 OP_C_WRITE (DEFAULT
, "apple", 5)
4028 OP_S_BIND_STREAM_ID (a
, C_BIDI_ID(0))
4029 OP_S_READ_EXPECT (a
, "apple", 5)
4031 OP_SET_INJECT_WORD (1, OSSL_QUIC_FRAME_TYPE_PATH_RESPONSE
)
4033 OP_S_WRITE (a
, "orange", 6)
4034 OP_C_READ_EXPECT (DEFAULT
, "orange", 6)
4036 OP_C_WRITE (DEFAULT
, "Strawberry", 10)
4037 OP_S_READ_EXPECT (a
, "Strawberry", 10)
4042 /* 52. Fault injection - ignore BLOCKED frames with bogus values */
4043 static int script_52_inject_plain(struct helper
*h
, QUIC_PKT_HDR
*hdr
,
4044 unsigned char *buf
, size_t len
)
4047 unsigned char frame_buf
[64];
4050 uint64_t type
= h
->inject_word1
;
4052 if (h
->inject_word0
== 0 || hdr
->type
!= QUIC_PKT_TYPE_1RTT
)
4057 if (!TEST_true(WPACKET_init_static_len(&wpkt
, frame_buf
,
4058 sizeof(frame_buf
), 0)))
4061 if (!TEST_true(WPACKET_quic_write_vlint(&wpkt
, type
)))
4064 if (type
== OSSL_QUIC_FRAME_TYPE_STREAM_DATA_BLOCKED
)
4065 if (!TEST_true(WPACKET_quic_write_vlint(&wpkt
, C_BIDI_ID(0))))
4068 if (!TEST_true(WPACKET_quic_write_vlint(&wpkt
, 0xFFFFFF)))
4071 if (!TEST_true(WPACKET_get_total_written(&wpkt
, &written
)))
4074 if (!qtest_fault_prepend_frame(h
->qtf
, frame_buf
, written
))
4080 WPACKET_finish(&wpkt
);
4082 WPACKET_cleanup(&wpkt
);
4086 static const struct script_op script_52
[] = {
4087 OP_S_SET_INJECT_PLAIN (script_52_inject_plain
)
4088 OP_C_SET_ALPN ("ossltest")
4089 OP_C_CONNECT_WAIT ()
4091 OP_C_WRITE (DEFAULT
, "apple", 5)
4092 OP_S_BIND_STREAM_ID (a
, C_BIDI_ID(0))
4093 OP_S_READ_EXPECT (a
, "apple", 5)
4095 OP_SET_INJECT_WORD (1, OSSL_QUIC_FRAME_TYPE_DATA_BLOCKED
)
4097 OP_S_WRITE (a
, "orange", 6)
4098 OP_C_READ_EXPECT (DEFAULT
, "orange", 6)
4100 OP_C_WRITE (DEFAULT
, "Strawberry", 10)
4101 OP_S_READ_EXPECT (a
, "Strawberry", 10)
4103 OP_SET_INJECT_WORD (1, OSSL_QUIC_FRAME_TYPE_STREAM_DATA_BLOCKED
)
4105 OP_S_WRITE (a
, "orange", 6)
4106 OP_C_READ_EXPECT (DEFAULT
, "orange", 6)
4108 OP_C_WRITE (DEFAULT
, "Strawberry", 10)
4109 OP_S_READ_EXPECT (a
, "Strawberry", 10)
4111 OP_SET_INJECT_WORD (1, OSSL_QUIC_FRAME_TYPE_STREAMS_BLOCKED_UNI
)
4113 OP_S_WRITE (a
, "orange", 6)
4114 OP_C_READ_EXPECT (DEFAULT
, "orange", 6)
4116 OP_C_WRITE (DEFAULT
, "Strawberry", 10)
4117 OP_S_READ_EXPECT (a
, "Strawberry", 10)
4119 OP_SET_INJECT_WORD (1, OSSL_QUIC_FRAME_TYPE_STREAMS_BLOCKED_BIDI
)
4121 OP_S_WRITE (a
, "orange", 6)
4122 OP_C_READ_EXPECT (DEFAULT
, "orange", 6)
4124 OP_C_WRITE (DEFAULT
, "Strawberry", 10)
4125 OP_S_READ_EXPECT (a
, "Strawberry", 10)
4130 /* 53. Fault injection - excess CRYPTO buffer size */
4131 static int script_53_inject_plain(struct helper
*h
, QUIC_PKT_HDR
*hdr
,
4132 unsigned char *buf
, size_t len
)
4137 uint64_t offset
= 0, data_len
= 100;
4138 unsigned char *frame_buf
= NULL
;
4139 size_t frame_len
, i
;
4141 if (h
->inject_word0
== 0 || hdr
->type
!= QUIC_PKT_TYPE_1RTT
)
4144 h
->inject_word0
= 0;
4146 switch (h
->inject_word1
) {
4149 * Far out offset which will not have been reached during handshake.
4150 * This will not be delivered to the QUIC_TLS instance since it will be
4151 * waiting for in-order delivery of previous bytes. This tests our flow
4152 * control on CRYPTO stream buffering.
4159 frame_len
= 1 + 8 + 8 + (size_t)data_len
;
4160 if (!TEST_ptr(frame_buf
= OPENSSL_malloc(frame_len
)))
4163 if (!TEST_true(WPACKET_init_static_len(&wpkt
, frame_buf
, frame_len
, 0)))
4166 if (!TEST_true(WPACKET_quic_write_vlint(&wpkt
, OSSL_QUIC_FRAME_TYPE_CRYPTO
))
4167 || !TEST_true(WPACKET_quic_write_vlint(&wpkt
, offset
))
4168 || !TEST_true(WPACKET_quic_write_vlint(&wpkt
, data_len
)))
4171 for (i
= 0; i
< data_len
; ++i
)
4172 if (!TEST_true(WPACKET_put_bytes_u8(&wpkt
, 0x42)))
4175 if (!TEST_true(WPACKET_get_total_written(&wpkt
, &written
)))
4178 if (!qtest_fault_prepend_frame(h
->qtf
, frame_buf
, written
))
4184 WPACKET_finish(&wpkt
);
4186 WPACKET_cleanup(&wpkt
);
4187 OPENSSL_free(frame_buf
);
4191 static const struct script_op script_53
[] = {
4192 OP_S_SET_INJECT_PLAIN (script_53_inject_plain
)
4193 OP_C_SET_ALPN ("ossltest")
4194 OP_C_CONNECT_WAIT ()
4196 OP_C_WRITE (DEFAULT
, "apple", 5)
4197 OP_S_BIND_STREAM_ID (a
, C_BIDI_ID(0))
4198 OP_S_READ_EXPECT (a
, "apple", 5)
4200 OP_SET_INJECT_WORD (1, 0)
4201 OP_S_WRITE (a
, "Strawberry", 10)
4203 OP_C_EXPECT_CONN_CLOSE_INFO(QUIC_ERR_CRYPTO_BUFFER_EXCEEDED
,0,0)
4208 /* 54. Fault injection - corrupted crypto stream data */
4209 static int script_54_inject_handshake(struct helper
*h
,
4210 unsigned char *buf
, size_t buf_len
)
4214 for (i
= 0; i
< buf_len
; ++i
)
4220 static const struct script_op script_54
[] = {
4221 OP_S_SET_INJECT_HANDSHAKE(script_54_inject_handshake
)
4222 OP_C_SET_ALPN ("ossltest")
4223 OP_C_CONNECT_WAIT_OR_FAIL()
4225 OP_C_EXPECT_CONN_CLOSE_INFO(QUIC_ERR_CRYPTO_UNEXPECTED_MESSAGE
,0,0)
4230 /* 55. Fault injection - NEW_CONN_ID with >20 byte CID */
4231 static const struct script_op script_55
[] = {
4232 OP_S_SET_INJECT_PLAIN (script_39_inject_plain
)
4233 OP_C_SET_ALPN ("ossltest")
4234 OP_C_CONNECT_WAIT ()
4235 OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE
)
4237 OP_C_NEW_STREAM_BIDI (a
, C_BIDI_ID(0))
4238 OP_C_WRITE (a
, "apple", 5)
4239 OP_S_BIND_STREAM_ID (a
, C_BIDI_ID(0))
4240 OP_S_READ_EXPECT (a
, "apple", 5)
4242 OP_SET_INJECT_WORD (0, 2)
4243 OP_S_WRITE (a
, "orange", 5)
4245 OP_C_EXPECT_CONN_CLOSE_INFO(QUIC_ERR_FRAME_ENCODING_ERROR
,0,0)
4250 /* 56. Fault injection - NEW_CONN_ID with seq no < retire prior to */
4251 static const struct script_op script_56
[] = {
4252 OP_S_SET_INJECT_PLAIN (script_39_inject_plain
)
4253 OP_C_SET_ALPN ("ossltest")
4254 OP_C_CONNECT_WAIT ()
4255 OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE
)
4257 OP_C_NEW_STREAM_BIDI (a
, C_BIDI_ID(0))
4258 OP_C_WRITE (a
, "apple", 5)
4259 OP_S_BIND_STREAM_ID (a
, C_BIDI_ID(0))
4260 OP_S_READ_EXPECT (a
, "apple", 5)
4262 OP_SET_INJECT_WORD (0, 3)
4263 OP_S_WRITE (a
, "orange", 5)
4265 OP_C_EXPECT_CONN_CLOSE_INFO(QUIC_ERR_FRAME_ENCODING_ERROR
,0,0)
4270 /* 57. Fault injection - NEW_CONN_ID with lower seq so ignored */
4271 static const struct script_op script_57
[] = {
4272 OP_S_SET_INJECT_PLAIN (script_39_inject_plain
)
4273 OP_C_SET_ALPN ("ossltest")
4274 OP_C_CONNECT_WAIT ()
4275 OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE
)
4277 OP_C_NEW_STREAM_BIDI (a
, C_BIDI_ID(0))
4278 OP_C_WRITE (a
, "apple", 5)
4279 OP_S_BIND_STREAM_ID (a
, C_BIDI_ID(0))
4280 OP_S_READ_EXPECT (a
, "apple", 5)
4282 OP_SET_INJECT_WORD (0, 4)
4283 OP_S_WRITE (a
, "orange", 5)
4284 OP_C_READ_EXPECT (a
, "orange", 5)
4286 OP_C_WRITE (a
, "Strawberry", 10)
4287 OP_S_READ_EXPECT (a
, "Strawberry", 10)
4290 * Now we send a NEW_CONN_ID with a bogus CID. However the sequence number
4291 * is old so it should be ignored and we should still be able to
4294 OP_SET_INJECT_WORD (0, 5)
4295 OP_S_WRITE (a
, "raspberry", 9)
4296 OP_C_READ_EXPECT (a
, "raspberry", 9)
4298 OP_C_WRITE (a
, "peach", 5)
4299 OP_S_READ_EXPECT (a
, "peach", 5)
4304 /* 58. Fault injection - repeated HANDSHAKE_DONE */
4305 static int script_58_inject_plain(struct helper
*h
, QUIC_PKT_HDR
*hdr
,
4306 unsigned char *buf
, size_t len
)
4309 unsigned char frame_buf
[64];
4313 if (h
->inject_word0
== 0 || hdr
->type
!= QUIC_PKT_TYPE_1RTT
)
4316 if (!TEST_true(WPACKET_init_static_len(&wpkt
, frame_buf
,
4317 sizeof(frame_buf
), 0)))
4320 if (h
->inject_word0
== 1) {
4321 if (!TEST_true(WPACKET_quic_write_vlint(&wpkt
, OSSL_QUIC_FRAME_TYPE_HANDSHAKE_DONE
)))
4324 /* Needless multi-byte encoding */
4325 if (!TEST_true(WPACKET_put_bytes_u8(&wpkt
, 0x40))
4326 || !TEST_true(WPACKET_put_bytes_u8(&wpkt
, 0x1E)))
4330 if (!TEST_true(WPACKET_get_total_written(&wpkt
, &written
)))
4333 if (!qtest_fault_prepend_frame(h
->qtf
, frame_buf
, written
))
4339 WPACKET_finish(&wpkt
);
4341 WPACKET_cleanup(&wpkt
);
4345 static const struct script_op script_58
[] = {
4346 OP_S_SET_INJECT_PLAIN (script_58_inject_plain
)
4347 OP_C_SET_ALPN ("ossltest")
4348 OP_C_CONNECT_WAIT ()
4350 OP_C_WRITE (DEFAULT
, "apple", 5)
4351 OP_S_BIND_STREAM_ID (a
, C_BIDI_ID(0))
4352 OP_S_READ_EXPECT (a
, "apple", 5)
4354 OP_SET_INJECT_WORD (1, 0)
4356 OP_S_WRITE (a
, "orange", 6)
4357 OP_C_READ_EXPECT (DEFAULT
, "orange", 6)
4359 OP_C_WRITE (DEFAULT
, "Strawberry", 10)
4360 OP_S_READ_EXPECT (a
, "Strawberry", 10)
4365 /* 59. Fault injection - multi-byte frame encoding */
4366 static const struct script_op script_59
[] = {
4367 OP_S_SET_INJECT_PLAIN (script_58_inject_plain
)
4368 OP_C_SET_ALPN ("ossltest")
4369 OP_C_CONNECT_WAIT ()
4371 OP_C_WRITE (DEFAULT
, "apple", 5)
4372 OP_S_BIND_STREAM_ID (a
, C_BIDI_ID(0))
4373 OP_S_READ_EXPECT (a
, "apple", 5)
4375 OP_SET_INJECT_WORD (2, 0)
4377 OP_S_WRITE (a
, "orange", 6)
4379 OP_C_EXPECT_CONN_CLOSE_INFO(QUIC_ERR_PROTOCOL_VIOLATION
,0,0)
4384 /* 60. Connection close reason truncation */
4385 static char long_reason
[2048];
4387 static int init_reason(struct helper
*h
, struct helper_local
*hl
)
4389 memset(long_reason
, '~', sizeof(long_reason
));
4390 memcpy(long_reason
, "This is a long reason string.", 29);
4391 long_reason
[OSSL_NELEM(long_reason
) - 1] = '\0';
4395 static int check_shutdown_reason(struct helper
*h
, struct helper_local
*hl
)
4397 const QUIC_TERMINATE_CAUSE
*tc
= ossl_quic_tserver_get_terminate_cause(ACQUIRE_S());
4400 h
->check_spin_again
= 1;
4404 if (!TEST_size_t_ge(tc
->reason_len
, 50)
4405 || !TEST_mem_eq(long_reason
, tc
->reason_len
,
4406 tc
->reason
, tc
->reason_len
))
4412 static const struct script_op script_60
[] = {
4413 OP_C_SET_ALPN ("ossltest")
4414 OP_C_CONNECT_WAIT ()
4416 OP_C_WRITE (DEFAULT
, "apple", 5)
4417 OP_S_BIND_STREAM_ID (a
, C_BIDI_ID(0))
4418 OP_S_READ_EXPECT (a
, "apple", 5)
4420 OP_CHECK (init_reason
, 0)
4421 OP_C_SHUTDOWN_WAIT (long_reason
, 0)
4422 OP_CHECK (check_shutdown_reason
, 0)
4427 /* 61. Fault injection - RESET_STREAM exceeding stream count FC */
4428 static int script_61_inject_plain(struct helper
*h
, QUIC_PKT_HDR
*hdr
,
4429 unsigned char *buf
, size_t len
)
4433 unsigned char frame_buf
[32];
4436 if (h
->inject_word0
== 0 || hdr
->type
!= QUIC_PKT_TYPE_1RTT
)
4439 if (!TEST_true(WPACKET_init_static_len(&wpkt
, frame_buf
,
4440 sizeof(frame_buf
), 0)))
4443 if (!TEST_true(WPACKET_quic_write_vlint(&wpkt
, h
->inject_word0
))
4444 || !TEST_true(WPACKET_quic_write_vlint(&wpkt
, /* stream ID */
4446 || !TEST_true(WPACKET_quic_write_vlint(&wpkt
, 123))
4447 || (h
->inject_word0
== OSSL_QUIC_FRAME_TYPE_RESET_STREAM
4448 && !TEST_true(WPACKET_quic_write_vlint(&wpkt
, 0)))) /* final size */
4451 if (!TEST_true(WPACKET_get_total_written(&wpkt
, &written
)))
4454 if (!qtest_fault_prepend_frame(h
->qtf
, frame_buf
, written
))
4460 WPACKET_finish(&wpkt
);
4462 WPACKET_cleanup(&wpkt
);
4466 static const struct script_op script_61
[] = {
4467 OP_S_SET_INJECT_PLAIN (script_61_inject_plain
)
4468 OP_C_SET_ALPN ("ossltest")
4469 OP_C_CONNECT_WAIT ()
4470 OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE
)
4472 OP_C_NEW_STREAM_BIDI (a
, C_BIDI_ID(0))
4473 OP_C_WRITE (a
, "orange", 6)
4475 OP_S_BIND_STREAM_ID (a
, C_BIDI_ID(0))
4476 OP_S_READ_EXPECT (a
, "orange", 6)
4478 OP_SET_INJECT_WORD (OSSL_QUIC_FRAME_TYPE_RESET_STREAM
,
4479 S_BIDI_ID(OSSL_QUIC_VLINT_MAX
/ 4))
4480 OP_S_WRITE (a
, "fruit", 5)
4482 OP_C_EXPECT_CONN_CLOSE_INFO(QUIC_ERR_STREAM_LIMIT_ERROR
,0,0)
4487 /* 62. Fault injection - STOP_SENDING with high ID */
4488 static const struct script_op script_62
[] = {
4489 OP_S_SET_INJECT_PLAIN (script_61_inject_plain
)
4490 OP_C_SET_ALPN ("ossltest")
4491 OP_C_CONNECT_WAIT ()
4492 OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE
)
4494 OP_C_NEW_STREAM_BIDI (a
, C_BIDI_ID(0))
4495 OP_C_WRITE (a
, "orange", 6)
4497 OP_S_BIND_STREAM_ID (a
, C_BIDI_ID(0))
4498 OP_S_READ_EXPECT (a
, "orange", 6)
4500 OP_SET_INJECT_WORD (OSSL_QUIC_FRAME_TYPE_STOP_SENDING
,
4501 C_BIDI_ID(OSSL_QUIC_VLINT_MAX
/ 4))
4502 OP_S_WRITE (a
, "fruit", 5)
4504 OP_C_EXPECT_CONN_CLOSE_INFO(QUIC_ERR_STREAM_STATE_ERROR
,0,0)
4509 /* 63. Fault injection - STREAM frame exceeding stream limit */
4510 static const struct script_op script_63
[] = {
4511 OP_S_SET_INJECT_PLAIN (script_32_inject_plain
)
4512 OP_C_SET_ALPN ("ossltest")
4513 OP_C_CONNECT_WAIT ()
4514 OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE
)
4516 OP_C_NEW_STREAM_BIDI (a
, C_BIDI_ID(0))
4517 OP_C_WRITE (a
, "apple", 5)
4519 OP_S_BIND_STREAM_ID (a
, C_BIDI_ID(0))
4520 OP_S_READ_EXPECT (a
, "apple", 5)
4522 OP_SET_INJECT_WORD (S_BIDI_ID(5000) + 1, 4)
4523 OP_S_WRITE (a
, "orange", 6)
4525 OP_C_EXPECT_CONN_CLOSE_INFO(QUIC_ERR_STREAM_LIMIT_ERROR
,0,0)
4530 /* 64. Fault injection - STREAM - zero-length no-FIN is accepted */
4531 static const struct script_op script_64
[] = {
4532 OP_S_SET_INJECT_PLAIN (script_32_inject_plain
)
4533 OP_C_SET_ALPN ("ossltest")
4534 OP_C_CONNECT_WAIT ()
4535 OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE
)
4537 OP_S_NEW_STREAM_UNI (a
, S_UNI_ID(0))
4538 OP_S_WRITE (a
, "apple", 5)
4540 OP_C_ACCEPT_STREAM_WAIT (a
)
4541 OP_C_READ_EXPECT (a
, "apple", 5)
4543 OP_SET_INJECT_WORD (S_BIDI_ID(20) + 1, 1)
4544 OP_S_WRITE (a
, "orange", 6)
4545 OP_C_READ_EXPECT (a
, "orange", 6)
4550 /* 65. Fault injection - CRYPTO - zero-length is accepted */
4551 static int script_65_inject_plain(struct helper
*h
, QUIC_PKT_HDR
*hdr
,
4552 unsigned char *buf
, size_t len
)
4555 unsigned char frame_buf
[64];
4559 if (h
->inject_word0
== 0)
4564 if (!TEST_true(WPACKET_init_static_len(&wpkt
, frame_buf
,
4565 sizeof(frame_buf
), 0)))
4568 if (!TEST_true(WPACKET_quic_write_vlint(&wpkt
, OSSL_QUIC_FRAME_TYPE_CRYPTO
))
4569 || !TEST_true(WPACKET_quic_write_vlint(&wpkt
, 0))
4570 || !TEST_true(WPACKET_quic_write_vlint(&wpkt
, 0)))
4573 if (!TEST_true(WPACKET_get_total_written(&wpkt
, &written
)))
4576 if (!qtest_fault_prepend_frame(h
->qtf
, frame_buf
, written
))
4582 WPACKET_finish(&wpkt
);
4584 WPACKET_cleanup(&wpkt
);
4588 static const struct script_op script_65
[] = {
4589 OP_S_SET_INJECT_PLAIN (script_65_inject_plain
)
4590 OP_C_SET_ALPN ("ossltest")
4591 OP_C_CONNECT_WAIT ()
4592 OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE
)
4594 OP_C_NEW_STREAM_BIDI (a
, C_BIDI_ID(0))
4595 OP_C_WRITE (a
, "apple", 5)
4597 OP_S_BIND_STREAM_ID (a
, C_BIDI_ID(0))
4598 OP_S_READ_EXPECT (a
, "apple", 5)
4600 OP_SET_INJECT_WORD (1, 0)
4601 OP_S_WRITE (a
, "orange", 6)
4602 OP_C_READ_EXPECT (a
, "orange", 6)
4607 /* 66. Fault injection - large MAX_STREAM_DATA */
4608 static int script_66_inject_plain(struct helper
*h
, QUIC_PKT_HDR
*hdr
,
4609 unsigned char *buf
, size_t len
)
4613 unsigned char frame_buf
[64];
4616 if (h
->inject_word0
== 0 || hdr
->type
!= QUIC_PKT_TYPE_1RTT
)
4619 if (!TEST_true(WPACKET_init_static_len(&wpkt
, frame_buf
,
4620 sizeof(frame_buf
), 0)))
4623 if (!TEST_true(WPACKET_quic_write_vlint(&wpkt
, h
->inject_word1
)))
4626 if (h
->inject_word1
== OSSL_QUIC_FRAME_TYPE_MAX_STREAM_DATA
)
4627 if (!TEST_true(WPACKET_quic_write_vlint(&wpkt
, /* stream ID */
4628 h
->inject_word0
- 1)))
4631 if (!TEST_true(WPACKET_quic_write_vlint(&wpkt
, OSSL_QUIC_VLINT_MAX
)))
4634 if (!TEST_true(WPACKET_get_total_written(&wpkt
, &written
)))
4637 if (!qtest_fault_prepend_frame(h
->qtf
, frame_buf
, written
))
4643 WPACKET_finish(&wpkt
);
4645 WPACKET_cleanup(&wpkt
);
4649 static const struct script_op script_66
[] = {
4650 OP_S_SET_INJECT_PLAIN (script_66_inject_plain
)
4651 OP_C_SET_ALPN ("ossltest")
4652 OP_C_CONNECT_WAIT ()
4653 OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE
)
4655 OP_S_NEW_STREAM_BIDI (a
, S_BIDI_ID(0))
4656 OP_S_WRITE (a
, "apple", 5)
4658 OP_C_ACCEPT_STREAM_WAIT (a
)
4659 OP_C_READ_EXPECT (a
, "apple", 5)
4661 OP_SET_INJECT_WORD (S_BIDI_ID(0) + 1, OSSL_QUIC_FRAME_TYPE_MAX_STREAM_DATA
)
4662 OP_S_WRITE (a
, "orange", 6)
4663 OP_C_READ_EXPECT (a
, "orange", 6)
4664 OP_C_WRITE (a
, "Strawberry", 10)
4665 OP_S_READ_EXPECT (a
, "Strawberry", 10)
4670 /* 67. Fault injection - large MAX_DATA */
4671 static const struct script_op script_67
[] = {
4672 OP_S_SET_INJECT_PLAIN (script_66_inject_plain
)
4673 OP_C_SET_ALPN ("ossltest")
4674 OP_C_CONNECT_WAIT ()
4675 OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE
)
4677 OP_S_NEW_STREAM_BIDI (a
, S_BIDI_ID(0))
4678 OP_S_WRITE (a
, "apple", 5)
4680 OP_C_ACCEPT_STREAM_WAIT (a
)
4681 OP_C_READ_EXPECT (a
, "apple", 5)
4683 OP_SET_INJECT_WORD (1, OSSL_QUIC_FRAME_TYPE_MAX_DATA
)
4684 OP_S_WRITE (a
, "orange", 6)
4685 OP_C_READ_EXPECT (a
, "orange", 6)
4686 OP_C_WRITE (a
, "Strawberry", 10)
4687 OP_S_READ_EXPECT (a
, "Strawberry", 10)
4692 /* 68. Fault injection - Unexpected TLS messages */
4693 static int script_68_inject_handshake(struct helper
*h
, unsigned char *msg
,
4696 const unsigned char *data
;
4698 const unsigned char certreq
[] = {
4699 SSL3_MT_CERTIFICATE_REQUEST
, /* CertificateRequest message */
4700 0, 0, 12, /* Length of message */
4701 1, 1, /* certificate_request_context */
4702 0, 8, /* Extensions block length */
4703 0, TLSEXT_TYPE_signature_algorithms
, /* sig_algs extension*/
4704 0, 4, /* 4 bytes of sig algs extension*/
4705 0, 2, /* sigalgs list is 2 bytes long */
4706 8, 4 /* rsa_pss_rsae_sha256 */
4708 const unsigned char keyupdate
[] = {
4709 SSL3_MT_KEY_UPDATE
, /* KeyUpdate message */
4710 0, 0, 1, /* Length of message */
4711 SSL_KEY_UPDATE_NOT_REQUESTED
/* update_not_requested */
4714 /* We transform the NewSessionTicket message into something else */
4715 switch(h
->inject_word0
) {
4720 /* CertificateRequest message */
4722 datalen
= sizeof(certreq
);
4726 /* KeyUpdate message */
4728 datalen
= sizeof(keyupdate
);
4735 if (!TEST_true(qtest_fault_resize_message(h
->qtf
,
4736 datalen
- SSL3_HM_HEADER_LENGTH
)))
4739 memcpy(msg
, data
, datalen
);
4744 /* Send a CerticateRequest message post-handshake */
4745 static const struct script_op script_68
[] = {
4746 OP_S_SET_INJECT_HANDSHAKE(script_68_inject_handshake
)
4747 OP_C_SET_ALPN ("ossltest")
4748 OP_C_CONNECT_WAIT ()
4749 OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE
)
4751 OP_C_NEW_STREAM_BIDI (a
, C_BIDI_ID(0))
4752 OP_C_WRITE (a
, "apple", 5)
4753 OP_S_BIND_STREAM_ID (a
, C_BIDI_ID(0))
4754 OP_S_READ_EXPECT (a
, "apple", 5)
4756 OP_SET_INJECT_WORD (1, 0)
4758 OP_S_WRITE (a
, "orange", 6)
4760 OP_C_EXPECT_CONN_CLOSE_INFO(QUIC_ERR_PROTOCOL_VIOLATION
, 0, 0)
4765 /* 69. Send a TLS KeyUpdate message post-handshake */
4766 static const struct script_op script_69
[] = {
4767 OP_S_SET_INJECT_HANDSHAKE(script_68_inject_handshake
)
4768 OP_C_SET_ALPN ("ossltest")
4769 OP_C_CONNECT_WAIT ()
4770 OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE
)
4772 OP_C_NEW_STREAM_BIDI (a
, C_BIDI_ID(0))
4773 OP_C_WRITE (a
, "apple", 5)
4774 OP_S_BIND_STREAM_ID (a
, C_BIDI_ID(0))
4775 OP_S_READ_EXPECT (a
, "apple", 5)
4777 OP_SET_INJECT_WORD (2, 0)
4779 OP_S_WRITE (a
, "orange", 6)
4781 OP_C_EXPECT_CONN_CLOSE_INFO(QUIC_ERR_CRYPTO_ERR_BEGIN
4782 + SSL_AD_UNEXPECTED_MESSAGE
, 0, 0)
4787 static int set_max_early_data(struct helper
*h
, struct helper_local
*hl
)
4790 if (!TEST_true(ossl_quic_tserver_set_max_early_data(ACQUIRE_S(),
4791 (uint32_t)hl
->check_op
->arg2
)))
4797 /* 70. Send a TLS NewSessionTicket message with invalid max_early_data */
4798 static const struct script_op script_70
[] = {
4799 OP_C_SET_ALPN ("ossltest")
4800 OP_C_CONNECT_WAIT ()
4801 OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE
)
4803 OP_C_NEW_STREAM_BIDI (a
, C_BIDI_ID(0))
4804 OP_C_WRITE (a
, "apple", 5)
4805 OP_S_BIND_STREAM_ID (a
, C_BIDI_ID(0))
4806 OP_S_READ_EXPECT (a
, "apple", 5)
4808 OP_CHECK (set_max_early_data
, 0xfffffffe)
4810 OP_S_WRITE (a
, "orange", 6)
4812 OP_C_EXPECT_CONN_CLOSE_INFO(QUIC_ERR_PROTOCOL_VIOLATION
, 0, 0)
4817 /* 71. Send a TLS NewSessionTicket message with valid max_early_data */
4818 static const struct script_op script_71
[] = {
4819 OP_C_SET_ALPN ("ossltest")
4820 OP_C_CONNECT_WAIT ()
4821 OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE
)
4823 OP_C_NEW_STREAM_BIDI (a
, C_BIDI_ID(0))
4824 OP_C_WRITE (a
, "apple", 5)
4825 OP_S_BIND_STREAM_ID (a
, C_BIDI_ID(0))
4826 OP_S_READ_EXPECT (a
, "apple", 5)
4828 OP_CHECK (set_max_early_data
, 0xffffffff)
4830 OP_S_WRITE (a
, "orange", 6)
4831 OP_C_READ_EXPECT (a
, "orange", 6)
4836 /* 72. Test that APL stops handing out streams after limit reached (bidi) */
4837 static int script_72_check(struct helper
*h
, struct helper_local
*hl
)
4839 if (!TEST_uint64_t_ge(h
->fail_count
, 50))
4845 static const struct script_op script_72
[] = {
4846 OP_C_SET_ALPN ("ossltest")
4847 OP_C_CONNECT_WAIT ()
4848 OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE
)
4851 * Request more streams than a server will initially hand out and test that
4852 * they fail properly.
4854 OP_BEGIN_REPEAT (200)
4856 OP_C_NEW_STREAM_BIDI_EX (a
, ANY_ID
, ALLOW_FAIL
| SSL_STREAM_FLAG_NO_BLOCK
)
4857 OP_C_SKIP_IF_UNBOUND (a
, 2)
4858 OP_C_WRITE (a
, "apple", 5)
4859 OP_C_FREE_STREAM (a
)
4863 OP_CHECK (script_72_check
, 0)
4868 /* 73. Test that APL stops handing out streams after limit reached (uni) */
4869 static const struct script_op script_73
[] = {
4870 OP_C_SET_ALPN ("ossltest")
4871 OP_C_CONNECT_WAIT ()
4872 OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE
)
4875 * Request more streams than a server will initially hand out and test that
4876 * they fail properly.
4878 OP_BEGIN_REPEAT (200)
4880 OP_C_NEW_STREAM_UNI_EX (a
, ANY_ID
, ALLOW_FAIL
| SSL_STREAM_FLAG_NO_BLOCK
)
4881 OP_C_SKIP_IF_UNBOUND (a
, 2)
4882 OP_C_WRITE (a
, "apple", 5)
4883 OP_C_FREE_STREAM (a
)
4887 OP_CHECK (script_72_check
, 0)
4892 /* 74. Version negotiation: QUIC_VERSION_1 ignored */
4893 static int generate_version_neg(WPACKET
*wpkt
, uint32_t version
)
4895 QUIC_PKT_HDR hdr
= {0};
4897 hdr
.type
= QUIC_PKT_TYPE_VERSION_NEG
;
4899 hdr
.dst_conn_id
.id_len
= 0;
4900 hdr
.src_conn_id
.id_len
= 8;
4901 memset(hdr
.src_conn_id
.id
, 0x55, 8);
4903 if (!TEST_true(ossl_quic_wire_encode_pkt_hdr(wpkt
, 0, &hdr
, NULL
)))
4906 if (!TEST_true(WPACKET_put_bytes_u32(wpkt
, version
)))
4912 static int server_gen_version_neg(struct helper
*h
, BIO_MSG
*msg
, size_t stride
)
4914 int rc
= 0, have_wpkt
= 0;
4917 BUF_MEM
*buf
= NULL
;
4920 switch (h
->inject_word0
) {
4924 version
= QUIC_VERSION_1
;
4927 version
= 0x5432abcd;
4931 if (!TEST_ptr(buf
= BUF_MEM_new()))
4934 if (!TEST_true(WPACKET_init(&wpkt
, buf
)))
4939 generate_version_neg(&wpkt
, version
);
4941 if (!TEST_true(WPACKET_get_total_written(&wpkt
, &l
)))
4944 if (!TEST_true(qtest_fault_resize_datagram(h
->qtf
, l
)))
4947 memcpy(msg
->data
, buf
->data
, l
);
4948 h
->inject_word0
= 0;
4953 WPACKET_finish(&wpkt
);
4959 static const struct script_op script_74
[] = {
4960 OP_S_SET_INJECT_DATAGRAM (server_gen_version_neg
)
4961 OP_SET_INJECT_WORD (1, 0)
4963 OP_C_SET_ALPN ("ossltest")
4964 OP_C_CONNECT_WAIT ()
4966 OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE
)
4968 OP_C_NEW_STREAM_BIDI (a
, C_BIDI_ID(0))
4969 OP_C_WRITE (a
, "apple", 5)
4970 OP_S_BIND_STREAM_ID (a
, C_BIDI_ID(0))
4971 OP_S_READ_EXPECT (a
, "apple", 5)
4976 /* 75. Version negotiation: Unknown version causes connection abort */
4977 static const struct script_op script_75
[] = {
4978 OP_S_SET_INJECT_DATAGRAM (server_gen_version_neg
)
4979 OP_SET_INJECT_WORD (2, 0)
4981 OP_C_SET_ALPN ("ossltest")
4982 OP_C_CONNECT_WAIT_OR_FAIL()
4984 OP_C_EXPECT_CONN_CLOSE_INFO(QUIC_ERR_CONNECTION_REFUSED
,0,0)
4989 /* 76. Test peer-initiated shutdown wait */
4990 static int script_76_check(struct helper
*h
, struct helper_local
*hl
)
4992 if (!TEST_false(SSL_shutdown_ex(h
->c_conn
,
4993 SSL_SHUTDOWN_FLAG_WAIT_PEER
4994 | SSL_SHUTDOWN_FLAG_NO_BLOCK
,
5001 static const struct script_op script_76
[] = {
5002 OP_C_SET_ALPN ("ossltest")
5003 OP_C_CONNECT_WAIT ()
5004 OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE
)
5006 OP_C_NEW_STREAM_BIDI (a
, C_BIDI_ID(0))
5007 OP_C_WRITE (a
, "apple", 5)
5009 OP_S_BIND_STREAM_ID (a
, C_BIDI_ID(0))
5010 OP_S_READ_EXPECT (a
, "apple", 5)
5012 /* Check a WAIT_PEER call doesn't succeed yet. */
5013 OP_CHECK (script_76_check
, 0)
5016 OP_C_SHUTDOWN_WAIT (NULL
, SSL_SHUTDOWN_FLAG_WAIT_PEER
)
5017 OP_C_EXPECT_CONN_CLOSE_INFO(42, 1, 1)
5022 /* 77. Ensure default stream popping operates correctly */
5023 static const struct script_op script_77
[] = {
5024 OP_C_SET_ALPN ("ossltest")
5025 OP_C_CONNECT_WAIT ()
5027 OP_C_SET_INCOMING_STREAM_POLICY(SSL_INCOMING_STREAM_POLICY_ACCEPT
)
5029 OP_S_NEW_STREAM_BIDI (a
, S_BIDI_ID(0))
5030 OP_S_WRITE (a
, "Strawberry", 10)
5032 OP_C_READ_EXPECT (DEFAULT
, "Strawberry", 10)
5034 OP_S_NEW_STREAM_BIDI (b
, S_BIDI_ID(1))
5035 OP_S_WRITE (b
, "xyz", 3)
5037 OP_C_ACCEPT_STREAM_WAIT (b
)
5038 OP_C_READ_EXPECT (b
, "xyz", 3)
5043 /* 78. Post-connection session ticket handling */
5044 static size_t new_session_count
;
5046 static int on_new_session(SSL
*s
, SSL_SESSION
*sess
)
5048 ++new_session_count
;
5049 return 0; /* do not ref session, we aren't keeping it */
5052 static int setup_session(struct helper
*h
, struct helper_local
*hl
)
5054 SSL_CTX_set_session_cache_mode(h
->c_ctx
, SSL_SESS_CACHE_BOTH
);
5055 SSL_CTX_sess_set_new_cb(h
->c_ctx
, on_new_session
);
5059 static int trigger_late_session_ticket(struct helper
*h
, struct helper_local
*hl
)
5061 new_session_count
= 0;
5063 if (!TEST_true(ossl_quic_tserver_new_ticket(ACQUIRE_S())))
5069 static int check_got_session_ticket(struct helper
*h
, struct helper_local
*hl
)
5071 if (!TEST_size_t_gt(new_session_count
, 0))
5077 static int check_idle_timeout(struct helper
*h
, struct helper_local
*hl
);
5079 static const struct script_op script_78
[] = {
5080 OP_C_SET_ALPN ("ossltest")
5081 OP_CHECK (setup_session
, 0)
5082 OP_C_CONNECT_WAIT ()
5084 OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE
)
5086 OP_C_NEW_STREAM_BIDI (a
, C_BIDI_ID(0))
5087 OP_C_WRITE (a
, "apple", 5)
5089 OP_S_BIND_STREAM_ID (a
, C_BIDI_ID(0))
5090 OP_S_READ_EXPECT (a
, "apple", 5)
5092 OP_S_WRITE (a
, "orange", 6)
5093 OP_C_READ_EXPECT (a
, "orange", 6)
5095 OP_CHECK (trigger_late_session_ticket
, 0)
5097 OP_S_WRITE (a
, "Strawberry", 10)
5098 OP_C_READ_EXPECT (a
, "Strawberry", 10)
5100 OP_CHECK (check_got_session_ticket
, 0)
5101 OP_CHECK2 (check_idle_timeout
,
5102 SSL_VALUE_CLASS_FEATURE_NEGOTIATED
, 30000)
5107 /* 79. Optimised FIN test */
5108 static const struct script_op script_79
[] = {
5109 OP_C_SET_ALPN ("ossltest")
5110 OP_C_CONNECT_WAIT ()
5111 OP_C_WRITE_EX2 (DEFAULT
, "apple", 5, SSL_WRITE_FLAG_CONCLUDE
)
5112 OP_S_BIND_STREAM_ID (a
, C_BIDI_ID(0))
5113 OP_S_READ_EXPECT (a
, "apple", 5)
5115 OP_S_WRITE (a
, "orange", 6)
5117 OP_C_READ_EXPECT (DEFAULT
, "orange", 6)
5118 OP_C_EXPECT_FIN (DEFAULT
)
5122 /* 80. Stateless reset detection test */
5123 static QUIC_STATELESS_RESET_TOKEN test_reset_token
= {
5124 { 0xde, 0xad, 0xbe, 0xef, 0xde, 0xad, 0xbe, 0xef, 0xde, 0xad, 0xbe, 0xef,
5125 0xde, 0xad, 0xbe, 0xef }};
5128 * Generate a packet in the following format:
5129 * https://www.rfc-editor.org/rfc/rfc9000.html#name-stateless-reset
5132 * Unpredictable bits (38..)
5133 * Stateless reset token (128)
5136 static int script_80_send_stateless_reset(struct helper
*h
, QUIC_PKT_HDR
*hdr
,
5137 unsigned char *buf
, size_t len
)
5139 unsigned char databuf
[64];
5141 if (h
->inject_word1
== 0)
5144 h
->inject_word1
= 0;
5146 fprintf(stderr
, "Sending stateless reset\n");
5148 RAND_bytes(databuf
, 64);
5150 memcpy(&databuf
[48], test_reset_token
.token
,
5151 sizeof(test_reset_token
.token
));
5153 if (!TEST_int_eq(SSL_inject_net_dgram(h
->c_conn
, databuf
, sizeof(databuf
),
5154 NULL
, h
->s_net_bio_addr
), 1))
5160 static int script_80_gen_new_conn_id(struct helper
*h
, QUIC_PKT_HDR
*hdr
,
5161 unsigned char *buf
, size_t len
)
5165 unsigned char frame_buf
[64];
5167 QUIC_CONN_ID new_cid
= {0};
5168 OSSL_QUIC_FRAME_NEW_CONN_ID ncid
= {0};
5169 QUIC_CHANNEL
*ch
= ossl_quic_tserver_get_channel(ACQUIRE_S_NOHL());
5171 if (h
->inject_word0
== 0)
5174 h
->inject_word0
= 0;
5176 fprintf(stderr
, "sending new conn id\n");
5177 if (!TEST_true(WPACKET_init_static_len(&wpkt
, frame_buf
,
5178 sizeof(frame_buf
), 0)))
5181 ossl_quic_channel_get_diag_local_cid(ch
, &new_cid
);
5184 ncid
.retire_prior_to
= 2;
5185 ncid
.conn_id
= new_cid
;
5186 memcpy(ncid
.stateless_reset
.token
, test_reset_token
.token
,
5187 sizeof(test_reset_token
.token
));
5189 if (!TEST_true(ossl_quic_wire_encode_frame_new_conn_id(&wpkt
, &ncid
)))
5192 if (!TEST_true(WPACKET_get_total_written(&wpkt
, &l
)))
5195 if (!qtest_fault_prepend_frame(h
->qtf
, frame_buf
, l
))
5201 WPACKET_finish(&wpkt
);
5203 WPACKET_cleanup(&wpkt
);
5208 static int script_80_inject_pkt(struct helper
*h
, QUIC_PKT_HDR
*hdr
,
5209 unsigned char *buf
, size_t len
)
5211 if (h
->inject_word1
== 1)
5212 return script_80_send_stateless_reset(h
, hdr
, buf
, len
);
5213 else if (h
->inject_word0
== 1)
5214 return script_80_gen_new_conn_id(h
, hdr
, buf
, len
);
5219 static const struct script_op script_80
[] = {
5220 OP_S_SET_INJECT_PLAIN (script_80_inject_pkt
)
5221 OP_C_SET_ALPN ("ossltest")
5222 OP_C_CONNECT_WAIT ()
5223 OP_C_WRITE (DEFAULT
, "apple", 5)
5224 OP_C_CONCLUDE (DEFAULT
)
5225 OP_S_BIND_STREAM_ID (a
, C_BIDI_ID(0))
5226 OP_S_READ_EXPECT (a
, "apple", 5)
5227 OP_SET_INJECT_WORD (1, 0)
5228 OP_S_WRITE (a
, "apple", 5)
5229 OP_C_READ_EXPECT (DEFAULT
, "apple", 5)
5230 OP_SET_INJECT_WORD (0, 1)
5231 OP_S_WRITE (a
, "apple", 5)
5232 OP_C_EXPECT_CONN_CLOSE_INFO (0, 0, 1)
5236 /* 81. Idle timeout configuration */
5237 static int modify_idle_timeout(struct helper
*h
, struct helper_local
*hl
)
5241 /* Test bad value is rejected. */
5242 if (!TEST_false(SSL_set_feature_request_uint(h
->c_conn
,
5243 SSL_VALUE_QUIC_IDLE_TIMEOUT
,
5248 if (!TEST_true(SSL_set_feature_request_uint(h
->c_conn
,
5249 SSL_VALUE_QUIC_IDLE_TIMEOUT
,
5250 hl
->check_op
->arg2
)))
5253 if (!TEST_true(SSL_get_feature_request_uint(h
->c_conn
,
5254 SSL_VALUE_QUIC_IDLE_TIMEOUT
,
5258 if (!TEST_uint64_t_eq(v
, hl
->check_op
->arg2
))
5264 static int check_idle_timeout(struct helper
*h
, struct helper_local
*hl
)
5268 if (!TEST_true(SSL_get_value_uint(h
->c_conn
, hl
->check_op
->arg1
,
5269 SSL_VALUE_QUIC_IDLE_TIMEOUT
,
5273 if (!TEST_uint64_t_eq(v
, hl
->check_op
->arg2
))
5279 static const struct script_op script_81
[] = {
5280 OP_C_SET_ALPN ("ossltest")
5281 OP_CHECK (modify_idle_timeout
, 25000)
5282 OP_C_CONNECT_WAIT ()
5284 OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE
)
5286 OP_CHECK2 (check_idle_timeout
,
5287 SSL_VALUE_CLASS_FEATURE_PEER_REQUEST
, 30000)
5288 OP_CHECK2 (check_idle_timeout
,
5289 SSL_VALUE_CLASS_FEATURE_NEGOTIATED
, 25000)
5294 /* 82. Negotiated default idle timeout if not configured */
5295 static const struct script_op script_82
[] = {
5296 OP_C_SET_ALPN ("ossltest")
5297 OP_C_CONNECT_WAIT ()
5299 OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE
)
5301 OP_CHECK2 (check_idle_timeout
,
5302 SSL_VALUE_CLASS_FEATURE_PEER_REQUEST
, 30000)
5303 OP_CHECK2 (check_idle_timeout
,
5304 SSL_VALUE_CLASS_FEATURE_NEGOTIATED
, 30000)
5309 /* 83. No late changes to idle timeout */
5310 static int cannot_change_idle_timeout(struct helper
*h
, struct helper_local
*hl
)
5314 if (!TEST_true(SSL_get_feature_request_uint(h
->c_conn
,
5315 SSL_VALUE_QUIC_IDLE_TIMEOUT
,
5319 if (!TEST_uint64_t_eq(v
, 30000))
5322 if (!TEST_false(SSL_set_feature_request_uint(h
->c_conn
,
5323 SSL_VALUE_QUIC_IDLE_TIMEOUT
,
5330 static const struct script_op script_83
[] = {
5331 OP_C_SET_ALPN ("ossltest")
5332 OP_C_CONNECT_WAIT ()
5334 OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE
)
5336 OP_CHECK (cannot_change_idle_timeout
, 0)
5337 OP_CHECK2 (check_idle_timeout
,
5338 SSL_VALUE_CLASS_FEATURE_PEER_REQUEST
, 30000)
5339 OP_CHECK2 (check_idle_timeout
,
5340 SSL_VALUE_CLASS_FEATURE_NEGOTIATED
, 30000)
5345 /* 82. Test query of available streams */
5346 static int check_avail_streams(struct helper
*h
, struct helper_local
*hl
)
5350 switch (hl
->check_op
->arg1
) {
5352 if (!TEST_true(SSL_get_quic_stream_bidi_local_avail(h
->c_conn
, &v
)))
5356 if (!TEST_true(SSL_get_quic_stream_bidi_remote_avail(h
->c_conn
, &v
)))
5360 if (!TEST_true(SSL_get_quic_stream_uni_local_avail(h
->c_conn
, &v
)))
5364 if (!TEST_true(SSL_get_quic_stream_uni_remote_avail(h
->c_conn
, &v
)))
5371 if (!TEST_uint64_t_eq(v
, hl
->check_op
->arg2
))
5377 static const struct script_op script_82
[] = {
5378 OP_C_SET_ALPN ("ossltest")
5379 OP_C_CONNECT_WAIT ()
5381 OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE
)
5383 OP_CHECK2 (check_avail_streams
, 0, 100)
5384 OP_CHECK2 (check_avail_streams
, 1, 100)
5385 OP_CHECK2 (check_avail_streams
, 2, 100)
5386 OP_CHECK2 (check_avail_streams
, 3, 100)
5388 OP_C_NEW_STREAM_BIDI (a
, C_BIDI_ID(0))
5390 OP_CHECK2 (check_avail_streams
, 0, 99)
5391 OP_CHECK2 (check_avail_streams
, 1, 100)
5392 OP_CHECK2 (check_avail_streams
, 2, 100)
5393 OP_CHECK2 (check_avail_streams
, 3, 100)
5395 OP_C_NEW_STREAM_UNI (b
, C_UNI_ID(0))
5397 OP_CHECK2 (check_avail_streams
, 0, 99)
5398 OP_CHECK2 (check_avail_streams
, 1, 100)
5399 OP_CHECK2 (check_avail_streams
, 2, 99)
5400 OP_CHECK2 (check_avail_streams
, 3, 100)
5402 OP_S_NEW_STREAM_BIDI (a
, S_BIDI_ID(0))
5403 OP_S_WRITE (a
, "x", 1)
5405 OP_CHECK2 (check_avail_streams
, 0, 99)
5406 OP_CHECK2 (check_avail_streams
, 1, 99)
5407 OP_CHECK2 (check_avail_streams
, 2, 99)
5408 OP_CHECK2 (check_avail_streams
, 3, 100)
5410 OP_S_NEW_STREAM_UNI (b
, S_UNI_ID(0))
5411 OP_S_WRITE (b
, "x", 1)
5413 OP_CHECK2 (check_avail_streams
, 0, 99)
5414 OP_CHECK2 (check_avail_streams
, 1, 99)
5415 OP_CHECK2 (check_avail_streams
, 2, 99)
5416 OP_CHECK2 (check_avail_streams
, 3, 99)
5422 static const struct script_op
*const scripts
[] = {
5508 static int test_script(int idx
)
5510 int script_idx
, free_order
, blocking
;
5511 char script_name
[64];
5513 free_order
= idx
% 2;
5521 if (blocking
&& free_order
)
5522 return 1; /* don't need to test free_order twice */
5524 #if !defined(OPENSSL_THREADS)
5526 TEST_skip("cannot test in blocking mode without threads");
5531 snprintf(script_name
, sizeof(script_name
), "script %d", script_idx
+ 1);
5533 TEST_info("Running script %d (order=%d, blocking=%d)", script_idx
+ 1,
5534 free_order
, blocking
);
5535 return run_script(scripts
[script_idx
], script_name
, free_order
, blocking
);
5538 /* Dynamically generated tests. */
5539 static struct script_op dyn_frame_types_script
[] = {
5540 OP_S_SET_INJECT_PLAIN (script_21_inject_plain
)
5541 OP_SET_INJECT_WORD (0, 0) /* dynamic */
5543 OP_C_SET_ALPN ("ossltest")
5544 OP_C_CONNECT_WAIT_OR_FAIL()
5546 OP_C_EXPECT_CONN_CLOSE_INFO(QUIC_ERR_FRAME_ENCODING_ERROR
,0,0)
5551 struct forbidden_frame_type
{
5552 uint64_t pkt_type
, frame_type
, expected_err
;
5555 static const struct forbidden_frame_type forbidden_frame_types
[] = {
5556 { QUIC_PKT_TYPE_INITIAL
, OSSL_QUIC_VLINT_MAX
, QUIC_ERR_FRAME_ENCODING_ERROR
},
5557 { QUIC_PKT_TYPE_HANDSHAKE
, OSSL_QUIC_VLINT_MAX
, QUIC_ERR_FRAME_ENCODING_ERROR
},
5558 { QUIC_PKT_TYPE_1RTT
, OSSL_QUIC_VLINT_MAX
, QUIC_ERR_FRAME_ENCODING_ERROR
},
5560 { QUIC_PKT_TYPE_INITIAL
, OSSL_QUIC_FRAME_TYPE_STREAM
, QUIC_ERR_PROTOCOL_VIOLATION
},
5561 { QUIC_PKT_TYPE_INITIAL
, OSSL_QUIC_FRAME_TYPE_RESET_STREAM
, QUIC_ERR_PROTOCOL_VIOLATION
},
5562 { QUIC_PKT_TYPE_INITIAL
, OSSL_QUIC_FRAME_TYPE_STOP_SENDING
, QUIC_ERR_PROTOCOL_VIOLATION
},
5563 { QUIC_PKT_TYPE_INITIAL
, OSSL_QUIC_FRAME_TYPE_NEW_TOKEN
, QUIC_ERR_PROTOCOL_VIOLATION
},
5564 { QUIC_PKT_TYPE_INITIAL
, OSSL_QUIC_FRAME_TYPE_MAX_DATA
, QUIC_ERR_PROTOCOL_VIOLATION
},
5565 { QUIC_PKT_TYPE_INITIAL
, OSSL_QUIC_FRAME_TYPE_MAX_STREAM_DATA
, QUIC_ERR_PROTOCOL_VIOLATION
},
5566 { QUIC_PKT_TYPE_INITIAL
, OSSL_QUIC_FRAME_TYPE_MAX_STREAMS_BIDI
, QUIC_ERR_PROTOCOL_VIOLATION
},
5567 { QUIC_PKT_TYPE_INITIAL
, OSSL_QUIC_FRAME_TYPE_MAX_STREAMS_UNI
, QUIC_ERR_PROTOCOL_VIOLATION
},
5568 { QUIC_PKT_TYPE_INITIAL
, OSSL_QUIC_FRAME_TYPE_DATA_BLOCKED
, QUIC_ERR_PROTOCOL_VIOLATION
},
5569 { QUIC_PKT_TYPE_INITIAL
, OSSL_QUIC_FRAME_TYPE_STREAM_DATA_BLOCKED
, QUIC_ERR_PROTOCOL_VIOLATION
},
5570 { QUIC_PKT_TYPE_INITIAL
, OSSL_QUIC_FRAME_TYPE_STREAMS_BLOCKED_BIDI
, QUIC_ERR_PROTOCOL_VIOLATION
},
5571 { QUIC_PKT_TYPE_INITIAL
, OSSL_QUIC_FRAME_TYPE_STREAMS_BLOCKED_UNI
, QUIC_ERR_PROTOCOL_VIOLATION
},
5572 { QUIC_PKT_TYPE_INITIAL
, OSSL_QUIC_FRAME_TYPE_NEW_CONN_ID
, QUIC_ERR_PROTOCOL_VIOLATION
},
5573 { QUIC_PKT_TYPE_INITIAL
, OSSL_QUIC_FRAME_TYPE_RETIRE_CONN_ID
, QUIC_ERR_PROTOCOL_VIOLATION
},
5574 { QUIC_PKT_TYPE_INITIAL
, OSSL_QUIC_FRAME_TYPE_PATH_CHALLENGE
, QUIC_ERR_PROTOCOL_VIOLATION
},
5575 { QUIC_PKT_TYPE_INITIAL
, OSSL_QUIC_FRAME_TYPE_PATH_RESPONSE
, QUIC_ERR_PROTOCOL_VIOLATION
},
5576 { QUIC_PKT_TYPE_INITIAL
, OSSL_QUIC_FRAME_TYPE_CONN_CLOSE_APP
, QUIC_ERR_PROTOCOL_VIOLATION
},
5577 { QUIC_PKT_TYPE_INITIAL
, OSSL_QUIC_FRAME_TYPE_HANDSHAKE_DONE
, QUIC_ERR_PROTOCOL_VIOLATION
},
5579 { QUIC_PKT_TYPE_HANDSHAKE
, OSSL_QUIC_FRAME_TYPE_STREAM
, QUIC_ERR_PROTOCOL_VIOLATION
},
5580 { QUIC_PKT_TYPE_HANDSHAKE
, OSSL_QUIC_FRAME_TYPE_RESET_STREAM
, QUIC_ERR_PROTOCOL_VIOLATION
},
5581 { QUIC_PKT_TYPE_HANDSHAKE
, OSSL_QUIC_FRAME_TYPE_STOP_SENDING
, QUIC_ERR_PROTOCOL_VIOLATION
},
5582 { QUIC_PKT_TYPE_HANDSHAKE
, OSSL_QUIC_FRAME_TYPE_NEW_TOKEN
, QUIC_ERR_PROTOCOL_VIOLATION
},
5583 { QUIC_PKT_TYPE_HANDSHAKE
, OSSL_QUIC_FRAME_TYPE_MAX_DATA
, QUIC_ERR_PROTOCOL_VIOLATION
},
5584 { QUIC_PKT_TYPE_HANDSHAKE
, OSSL_QUIC_FRAME_TYPE_MAX_STREAM_DATA
, QUIC_ERR_PROTOCOL_VIOLATION
},
5585 { QUIC_PKT_TYPE_HANDSHAKE
, OSSL_QUIC_FRAME_TYPE_MAX_STREAMS_BIDI
, QUIC_ERR_PROTOCOL_VIOLATION
},
5586 { QUIC_PKT_TYPE_HANDSHAKE
, OSSL_QUIC_FRAME_TYPE_MAX_STREAMS_UNI
, QUIC_ERR_PROTOCOL_VIOLATION
},
5587 { QUIC_PKT_TYPE_HANDSHAKE
, OSSL_QUIC_FRAME_TYPE_DATA_BLOCKED
, QUIC_ERR_PROTOCOL_VIOLATION
},
5588 { QUIC_PKT_TYPE_HANDSHAKE
, OSSL_QUIC_FRAME_TYPE_STREAM_DATA_BLOCKED
, QUIC_ERR_PROTOCOL_VIOLATION
},
5589 { QUIC_PKT_TYPE_HANDSHAKE
, OSSL_QUIC_FRAME_TYPE_STREAMS_BLOCKED_BIDI
, QUIC_ERR_PROTOCOL_VIOLATION
},
5590 { QUIC_PKT_TYPE_HANDSHAKE
, OSSL_QUIC_FRAME_TYPE_STREAMS_BLOCKED_UNI
, QUIC_ERR_PROTOCOL_VIOLATION
},
5591 { QUIC_PKT_TYPE_HANDSHAKE
, OSSL_QUIC_FRAME_TYPE_NEW_CONN_ID
, QUIC_ERR_PROTOCOL_VIOLATION
},
5592 { QUIC_PKT_TYPE_HANDSHAKE
, OSSL_QUIC_FRAME_TYPE_RETIRE_CONN_ID
, QUIC_ERR_PROTOCOL_VIOLATION
},
5593 { QUIC_PKT_TYPE_HANDSHAKE
, OSSL_QUIC_FRAME_TYPE_PATH_CHALLENGE
, QUIC_ERR_PROTOCOL_VIOLATION
},
5594 { QUIC_PKT_TYPE_HANDSHAKE
, OSSL_QUIC_FRAME_TYPE_PATH_RESPONSE
, QUIC_ERR_PROTOCOL_VIOLATION
},
5595 { QUIC_PKT_TYPE_HANDSHAKE
, OSSL_QUIC_FRAME_TYPE_CONN_CLOSE_APP
, QUIC_ERR_PROTOCOL_VIOLATION
},
5596 { QUIC_PKT_TYPE_HANDSHAKE
, OSSL_QUIC_FRAME_TYPE_HANDSHAKE_DONE
, QUIC_ERR_PROTOCOL_VIOLATION
},
5598 /* Client uses a zero-length CID so this is not allowed. */
5599 { QUIC_PKT_TYPE_1RTT
, OSSL_QUIC_FRAME_TYPE_RETIRE_CONN_ID
, QUIC_ERR_PROTOCOL_VIOLATION
},
5602 static ossl_unused
int test_dyn_frame_types(int idx
)
5605 char script_name
[64];
5606 struct script_op
*s
= dyn_frame_types_script
;
5608 for (i
= 0; i
< OSSL_NELEM(dyn_frame_types_script
); ++i
)
5609 if (s
[i
].op
== OPK_SET_INJECT_WORD
) {
5610 s
[i
].arg1
= (size_t)forbidden_frame_types
[idx
].pkt_type
;
5611 s
[i
].arg2
= forbidden_frame_types
[idx
].frame_type
;
5612 } else if (s
[i
].op
== OPK_C_EXPECT_CONN_CLOSE_INFO
) {
5613 s
[i
].arg2
= forbidden_frame_types
[idx
].expected_err
;
5616 snprintf(script_name
, sizeof(script_name
),
5617 "dyn script %d", idx
);
5619 return run_script(dyn_frame_types_script
, script_name
, 0, 0);
5622 OPT_TEST_DECLARE_USAGE("certfile privkeyfile\n")
5624 int setup_tests(void)
5626 if (!test_skip_common_options()) {
5627 TEST_error("Error parsing test options\n");
5631 if (!TEST_ptr(certfile
= test_get_argument(0))
5632 || !TEST_ptr(keyfile
= test_get_argument(1)))
5635 ADD_ALL_TESTS(test_dyn_frame_types
, OSSL_NELEM(forbidden_frame_types
));
5636 ADD_ALL_TESTS(test_script
, OSSL_NELEM(scripts
) * 2 * 2);