2 * Copyright 2023 The OpenSSL Project Authors. All Rights Reserved.
4 * Licensed under the Apache License 2.0 (the "License"). You may not use
5 * this file except in compliance with the License. You can obtain a copy
6 * in the file LICENSE in the source distribution or at
7 * https://www.openssl.org/source/license.html
9 #include <openssl/ssl.h>
10 #include <openssl/quic.h>
11 #include <openssl/bio.h>
12 #include <openssl/lhash.h>
13 #include "internal/quic_tserver.h"
14 #include "internal/quic_ssl.h"
16 #if defined(OPENSSL_THREADS)
17 # include "internal/thread_arch.h"
20 static const char *certfile
, *keyfile
;
22 #if defined(OPENSSL_THREADS)
23 struct child_thread_args
{
25 const struct script_op
*script
;
35 typedef struct stream_info
{
41 DEFINE_LHASH_OF_EX(STREAM_INFO
);
45 BIO
*s_net_bio
, *s_net_bio_own
;
46 BIO_ADDR
*s_net_bio_addr
;
48 LHASH_OF(STREAM_INFO
) *s_streams
;
51 BIO
*c_net_bio
, *c_net_bio_own
;
54 LHASH_OF(STREAM_INFO
) *c_streams
;
56 #if defined(OPENSSL_THREADS)
57 struct child_thread_args
*threads
;
64 * This is a duration recording the amount of time we have skipped forwards
65 * for testing purposes relative to the real ossl_time_now() clock. We add
66 * a quantity of time to this every time we skip some time.
68 CRYPTO_RWLOCK
*time_lock
;
69 OSSL_TIME time_slip
; /* protected by time_lock */
71 int init
, blocking
, check_spin_again
;
77 LHASH_OF(STREAM_INFO
) *c_streams
;
85 int (*check_func
)(struct helper
*h
, const struct script_op
*op
);
86 const char *stream_name
;
92 #define OPK_C_SET_ALPN 2
93 #define OPK_C_CONNECT_WAIT 3
96 #define OPK_C_READ_EXPECT 6
97 #define OPK_S_READ_EXPECT 7
98 #define OPK_C_EXPECT_FIN 8
99 #define OPK_S_EXPECT_FIN 9
100 #define OPK_C_CONCLUDE 10
101 #define OPK_S_CONCLUDE 11
102 #define OPK_C_DETACH 12
103 #define OPK_C_ATTACH 13
104 #define OPK_C_NEW_STREAM 14
105 #define OPK_S_NEW_STREAM 15
106 #define OPK_C_ACCEPT_STREAM_WAIT 16
107 #define OPK_C_ACCEPT_STREAM_NONE 17
108 #define OPK_C_FREE_STREAM 18
109 #define OPK_C_SET_DEFAULT_STREAM_MODE 19
110 #define OPK_C_SET_INCOMING_STREAM_POLICY 20
111 #define OPK_C_SHUTDOWN 21
112 #define OPK_C_EXPECT_CONN_CLOSE_INFO 22
113 #define OPK_S_EXPECT_CONN_CLOSE_INFO 23
114 #define OPK_S_BIND_STREAM_ID 24
115 #define OPK_C_WAIT_FOR_DATA 25
116 #define OPK_C_WRITE_FAIL 26
117 #define OPK_S_WRITE_FAIL 27
118 #define OPK_C_READ_FAIL 28
119 #define OPK_C_STREAM_RESET 29
120 #define OPK_S_ACCEPT_STREAM_WAIT 30
121 #define OPK_NEW_THREAD 31
122 #define OPK_BEGIN_REPEAT 32
123 #define OPK_END_REPEAT 33
124 #define OPK_S_UNBIND_STREAM_ID 34
126 #define EXPECT_CONN_CLOSE_APP (1U << 0)
127 #define EXPECT_CONN_CLOSE_REMOTE (1U << 1)
129 #define C_BIDI_ID(ordinal) \
130 (((ordinal) << 2) | QUIC_STREAM_INITIATOR_CLIENT | QUIC_STREAM_DIR_BIDI)
131 #define S_BIDI_ID(ordinal) \
132 (((ordinal) << 2) | QUIC_STREAM_INITIATOR_SERVER | QUIC_STREAM_DIR_BIDI)
133 #define C_UNI_ID(ordinal) \
134 (((ordinal) << 2) | QUIC_STREAM_INITIATOR_CLIENT | QUIC_STREAM_DIR_UNI)
135 #define S_UNI_ID(ordinal) \
136 (((ordinal) << 2) | QUIC_STREAM_INITIATOR_SERVER | QUIC_STREAM_DIR_UNI)
138 #define ANY_ID UINT64_MAX
142 #define OP_CHECK(func, arg2) \
143 {OPK_CHECK, NULL, 0, (func), NULL, (arg2)},
144 #define OP_C_SET_ALPN(alpn) \
145 {OPK_C_SET_ALPN, (alpn), 0, NULL, NULL},
146 #define OP_C_CONNECT_WAIT() \
147 {OPK_C_CONNECT_WAIT, NULL, 0, NULL, NULL},
148 #define OP_C_WRITE(stream_name, buf, buf_len) \
149 {OPK_C_WRITE, (buf), (buf_len), NULL, #stream_name},
150 #define OP_S_WRITE(stream_name, buf, buf_len) \
151 {OPK_S_WRITE, (buf), (buf_len), NULL, #stream_name},
152 #define OP_C_READ_EXPECT(stream_name, buf, buf_len) \
153 {OPK_C_READ_EXPECT, (buf), (buf_len), NULL, #stream_name},
154 #define OP_S_READ_EXPECT(stream_name, buf, buf_len) \
155 {OPK_S_READ_EXPECT, (buf), (buf_len), NULL, #stream_name},
156 #define OP_C_EXPECT_FIN(stream_name) \
157 {OPK_C_EXPECT_FIN, NULL, 0, NULL, #stream_name},
158 #define OP_S_EXPECT_FIN(stream_name) \
159 {OPK_S_EXPECT_FIN, NULL, 0, NULL, #stream_name},
160 #define OP_C_CONCLUDE(stream_name) \
161 {OPK_C_CONCLUDE, NULL, 0, NULL, #stream_name},
162 #define OP_S_CONCLUDE(stream_name) \
163 {OPK_S_CONCLUDE, NULL, 0, NULL, #stream_name},
164 #define OP_C_DETACH(stream_name) \
165 {OPK_C_DETACH, NULL, 0, NULL, #stream_name},
166 #define OP_C_ATTACH(stream_name) \
167 {OPK_C_ATTACH, NULL, 0, NULL, #stream_name},
168 #define OP_C_NEW_STREAM_BIDI(stream_name, expect_id) \
169 {OPK_C_NEW_STREAM, NULL, 0, NULL, #stream_name, (expect_id)},
170 #define OP_C_NEW_STREAM_UNI(stream_name, expect_id) \
171 {OPK_C_NEW_STREAM, NULL, 1, NULL, #stream_name, (expect_id)},
172 #define OP_S_NEW_STREAM_BIDI(stream_name, expect_id) \
173 {OPK_S_NEW_STREAM, NULL, 0, NULL, #stream_name, (expect_id)},
174 #define OP_S_NEW_STREAM_UNI(stream_name, expect_id) \
175 {OPK_S_NEW_STREAM, NULL, 1, NULL, #stream_name, (expect_id)},
176 #define OP_C_ACCEPT_STREAM_WAIT(stream_name) \
177 {OPK_C_ACCEPT_STREAM_WAIT, NULL, 0, NULL, #stream_name},
178 #define OP_C_ACCEPT_STREAM_NONE() \
179 {OPK_C_ACCEPT_STREAM_NONE, NULL, 0, NULL, NULL},
180 #define OP_C_FREE_STREAM(stream_name) \
181 {OPK_C_FREE_STREAM, NULL, 0, NULL, #stream_name},
182 #define OP_C_SET_DEFAULT_STREAM_MODE(mode) \
183 {OPK_C_SET_DEFAULT_STREAM_MODE, NULL, (mode), NULL, NULL},
184 #define OP_C_SET_INCOMING_STREAM_POLICY(policy) \
185 {OPK_C_SET_INCOMING_STREAM_POLICY, NULL, (policy), NULL, NULL},
186 #define OP_C_SHUTDOWN() \
187 {OPK_C_SHUTDOWN, NULL, 0, NULL, NULL},
188 #define OP_C_EXPECT_CONN_CLOSE_INFO(ec, app, remote) \
189 {OPK_C_EXPECT_CONN_CLOSE_INFO, NULL, \
190 ((app) ? EXPECT_CONN_CLOSE_APP : 0) | \
191 ((remote) ? EXPECT_CONN_CLOSE_REMOTE : 0), \
193 #define OP_S_EXPECT_CONN_CLOSE_INFO(ec, app, remote) \
194 {OPK_S_EXPECT_CONN_CLOSE_INFO, NULL, \
195 ((app) ? EXPECT_CONN_CLOSE_APP : 0) | \
196 ((remote) ? EXPECT_CONN_CLOSE_REMOTE : 0), \
198 #define OP_S_BIND_STREAM_ID(stream_name, stream_id) \
199 {OPK_S_BIND_STREAM_ID, NULL, 0, NULL, #stream_name, (stream_id)},
200 #define OP_C_WAIT_FOR_DATA(stream_name) \
201 {OPK_C_WAIT_FOR_DATA, NULL, 0, NULL, #stream_name},
202 #define OP_C_WRITE_FAIL(stream_name) \
203 {OPK_C_WRITE_FAIL, NULL, 0, NULL, #stream_name},
204 #define OP_S_WRITE_FAIL(stream_name) \
205 {OPK_S_WRITE_FAIL, NULL, 0, NULL, #stream_name},
206 #define OP_C_READ_FAIL(stream_name) \
207 {OPK_C_READ_FAIL, NULL, 0, NULL, #stream_name},
208 #define OP_C_STREAM_RESET(stream_name, aec) \
209 {OPK_C_STREAM_RESET, NULL, 0, NULL, #stream_name, (aec)},
210 #define OP_S_ACCEPT_STREAM_WAIT(stream_name) \
211 {OPK_S_ACCEPT_STREAM_WAIT, NULL, 0, NULL, #stream_name},
212 #define OP_NEW_THREAD(num_threads, script) \
213 {OPK_NEW_THREAD, (script), (num_threads), NULL, NULL, 0 },
214 #define OP_BEGIN_REPEAT(n) \
215 {OPK_BEGIN_REPEAT, NULL, (n)},
216 #define OP_END_REPEAT() \
218 #define OP_S_UNBIND_STREAM_ID(stream_name) \
219 {OPK_S_UNBIND_STREAM_ID, NULL, 0, NULL, #stream_name},
221 static OSSL_TIME
get_time(void *arg
)
223 struct helper
*h
= arg
;
226 if (!TEST_true(CRYPTO_THREAD_read_lock(h
->time_lock
)))
227 return ossl_time_zero();
229 t
= ossl_time_add(ossl_time_now(), h
->time_slip
);
231 CRYPTO_THREAD_unlock(h
->time_lock
);
235 static int skip_time_ms(struct helper
*h
, const struct script_op
*op
)
237 if (!TEST_true(CRYPTO_THREAD_write_lock(h
->time_lock
)))
240 h
->time_slip
= ossl_time_add(h
->time_slip
, ossl_ms2time(op
->arg2
));
242 CRYPTO_THREAD_unlock(h
->time_lock
);
246 static int check_rejected(struct helper
*h
, const struct script_op
*op
)
248 uint64_t stream_id
= op
->arg2
;
250 if (!ossl_quic_tserver_stream_has_peer_stop_sending(h
->s
, stream_id
, NULL
)
251 || !ossl_quic_tserver_stream_has_peer_reset_stream(h
->s
, stream_id
, NULL
)) {
252 h
->check_spin_again
= 1;
259 static int check_stream_reset(struct helper
*h
, const struct script_op
*op
)
261 uint64_t stream_id
= op
->arg2
, aec
= 0;
263 if (!ossl_quic_tserver_stream_has_peer_reset_stream(h
->s
, stream_id
, &aec
)) {
264 h
->check_spin_again
= 1;
268 return TEST_uint64_t_eq(aec
, 42);
271 static int check_stream_stopped(struct helper
*h
, const struct script_op
*op
)
273 uint64_t stream_id
= op
->arg2
;
275 if (!ossl_quic_tserver_stream_has_peer_stop_sending(h
->s
, stream_id
, NULL
)) {
276 h
->check_spin_again
= 1;
283 static int override_key_update(struct helper
*h
, const struct script_op
*op
)
285 QUIC_CHANNEL
*ch
= ossl_quic_conn_get_channel(h
->c_conn
);
287 ossl_quic_channel_set_txku_threshold_override(ch
, op
->arg2
);
291 static int trigger_key_update(struct helper
*h
, const struct script_op
*op
)
293 if (!TEST_true(SSL_key_update(h
->c_conn
, SSL_KEY_UPDATE_REQUESTED
)))
299 static int check_key_update_ge(struct helper
*h
, const struct script_op
*op
)
301 QUIC_CHANNEL
*ch
= ossl_quic_conn_get_channel(h
->c_conn
);
302 int64_t txke
= (int64_t)ossl_quic_channel_get_tx_key_epoch(ch
);
303 int64_t rxke
= (int64_t)ossl_quic_channel_get_rx_key_epoch(ch
);
304 int64_t diff
= txke
- rxke
;
307 * TXKE must always be equal to or ahead of RXKE.
308 * It can be ahead of RXKE by at most 1.
310 if (!TEST_int64_t_ge(diff
, 0) || !TEST_int64_t_le(diff
, 1))
313 /* Caller specifies a minimum number of RXKEs which must have happened. */
314 if (!TEST_uint64_t_ge((uint64_t)rxke
, op
->arg2
))
320 static int check_key_update_lt(struct helper
*h
, const struct script_op
*op
)
322 QUIC_CHANNEL
*ch
= ossl_quic_conn_get_channel(h
->c_conn
);
323 uint64_t txke
= ossl_quic_channel_get_tx_key_epoch(ch
);
325 /* Caller specifies a maximum number of TXKEs which must have happened. */
326 if (!TEST_uint64_t_lt(txke
, op
->arg2
))
332 static unsigned long stream_info_hash(const STREAM_INFO
*info
)
334 return OPENSSL_LH_strhash(info
->name
);
337 static int stream_info_cmp(const STREAM_INFO
*a
, const STREAM_INFO
*b
)
339 return strcmp(a
->name
, b
->name
);
342 static void cleanup_stream(STREAM_INFO
*info
)
344 SSL_free(info
->c_stream
);
348 static void helper_cleanup_streams(LHASH_OF(STREAM_INFO
) **lh
)
353 lh_STREAM_INFO_doall(*lh
, cleanup_stream
);
354 lh_STREAM_INFO_free(*lh
);
358 #if defined(OPENSSL_THREADS)
359 static CRYPTO_THREAD_RETVAL
run_script_child_thread(void *arg
);
361 static int join_threads(struct child_thread_args
*threads
, size_t num_threads
)
365 CRYPTO_THREAD_RETVAL rv
;
367 for (i
= 0; i
< num_threads
; ++i
) {
368 if (threads
[i
].t
!= NULL
) {
369 ossl_crypto_thread_native_join(threads
[i
].t
, &rv
);
371 if (!threads
[i
].testresult
)
372 /* Do not log failure here, worker will do it. */
375 ossl_crypto_thread_native_clean(threads
[i
].t
);
379 ossl_crypto_mutex_free(&threads
[i
].m
);
386 static void helper_cleanup(struct helper
*h
)
388 #if defined(OPENSSL_THREADS)
389 join_threads(h
->threads
, h
->num_threads
);
390 OPENSSL_free(h
->threads
);
395 if (h
->free_order
== 0) {
396 /* order 0: streams, then conn */
397 helper_cleanup_streams(&h
->c_streams
);
402 /* order 1: conn, then streams */
406 helper_cleanup_streams(&h
->c_streams
);
409 helper_cleanup_streams(&h
->s_streams
);
410 ossl_quic_tserver_free(h
->s
);
413 BIO_free(h
->s_net_bio_own
);
414 h
->s_net_bio_own
= NULL
;
416 BIO_free(h
->c_net_bio_own
);
417 h
->c_net_bio_own
= NULL
;
420 BIO_closesocket(h
->s_fd
);
425 BIO_closesocket(h
->c_fd
);
429 BIO_ADDR_free(h
->s_net_bio_addr
);
430 h
->s_net_bio_addr
= NULL
;
432 SSL_CTX_free(h
->c_ctx
);
435 CRYPTO_THREAD_lock_free(h
->time_lock
);
439 static int helper_init(struct helper
*h
, int free_order
)
442 struct in_addr ina
= {0};
443 QUIC_TSERVER_ARGS s_args
= {0};
445 memset(h
, 0, sizeof(*h
));
448 h
->free_order
= free_order
;
449 h
->time_slip
= ossl_time_zero();
451 if (!TEST_ptr(h
->time_lock
= CRYPTO_THREAD_lock_new()))
454 if (!TEST_ptr(h
->s_streams
= lh_STREAM_INFO_new(stream_info_hash
,
458 if (!TEST_ptr(h
->c_streams
= lh_STREAM_INFO_new(stream_info_hash
,
462 ina
.s_addr
= htonl(0x7f000001UL
);
464 h
->s_fd
= BIO_socket(AF_INET
, SOCK_DGRAM
, IPPROTO_UDP
, 0);
465 if (!TEST_int_ge(h
->s_fd
, 0))
468 if (!TEST_true(BIO_socket_nbio(h
->s_fd
, 1)))
471 if (!TEST_ptr(h
->s_net_bio_addr
= BIO_ADDR_new()))
474 if (!TEST_true(BIO_ADDR_rawmake(h
->s_net_bio_addr
, AF_INET
, &ina
, sizeof(ina
),
478 if (!TEST_true(BIO_bind(h
->s_fd
, h
->s_net_bio_addr
, 0)))
481 if (!TEST_int_gt(BIO_ADDR_rawport(h
->s_net_bio_addr
), 0))
484 if (!TEST_ptr(h
->s_net_bio
= h
->s_net_bio_own
= BIO_new_dgram(h
->s_fd
, 0)))
487 if (!BIO_up_ref(h
->s_net_bio
))
490 s_args
.net_rbio
= h
->s_net_bio
;
491 s_args
.net_wbio
= h
->s_net_bio
;
492 s_args
.now_cb
= get_time
;
493 s_args
.now_cb_arg
= h
;
495 if (!TEST_ptr(h
->s
= ossl_quic_tserver_new(&s_args
, certfile
, keyfile
)))
498 h
->s_net_bio_own
= NULL
;
500 h
->c_fd
= BIO_socket(AF_INET
, SOCK_DGRAM
, IPPROTO_UDP
, 0);
501 if (!TEST_int_ge(h
->c_fd
, 0))
504 if (!TEST_true(BIO_socket_nbio(h
->c_fd
, 1)))
507 if (!TEST_ptr(h
->c_net_bio
= h
->c_net_bio_own
= BIO_new_dgram(h
->c_fd
, 0)))
510 if (!TEST_true(BIO_dgram_set_peer(h
->c_net_bio
, h
->s_net_bio_addr
)))
514 if (!TEST_ptr(h
->c_ctx
= SSL_CTX_new(OSSL_QUIC_client_method())))
517 if (!TEST_ptr(h
->c_conn
= SSL_new(h
->c_ctx
)))
520 /* Use custom time function for virtual time skip. */
521 if (!TEST_true(ossl_quic_conn_set_override_now_cb(h
->c_conn
, get_time
, h
)))
524 /* Takes ownership of our reference to the BIO. */
525 SSL_set0_rbio(h
->c_conn
, h
->c_net_bio
);
526 h
->c_net_bio_own
= NULL
;
528 if (!TEST_true(BIO_up_ref(h
->c_net_bio
)))
531 SSL_set0_wbio(h
->c_conn
, h
->c_net_bio
);
533 if (!TEST_true(SSL_set_blocking_mode(h
->c_conn
, 0)))
536 h
->start_time
= ossl_time_now();
545 static int helper_local_init(struct helper_local
*hl
, struct helper
*h
,
549 hl
->c_streams
= NULL
;
550 hl
->thread_idx
= thread_idx
;
555 if (thread_idx
< 0) {
556 hl
->c_streams
= h
->c_streams
;
558 if (!TEST_ptr(hl
->c_streams
= lh_STREAM_INFO_new(stream_info_hash
,
566 static void helper_local_cleanup(struct helper_local
*hl
)
571 if (hl
->thread_idx
>= 0)
572 helper_cleanup_streams(&hl
->c_streams
);
577 static STREAM_INFO
*get_stream_info(LHASH_OF(STREAM_INFO
) *lh
,
578 const char *stream_name
)
580 STREAM_INFO key
, *info
;
582 if (!TEST_ptr(stream_name
))
585 if (!strcmp(stream_name
, "DEFAULT"))
588 key
.name
= stream_name
;
589 info
= lh_STREAM_INFO_retrieve(lh
, &key
);
591 info
= OPENSSL_zalloc(sizeof(*info
));
595 info
->name
= stream_name
;
596 info
->s_stream_id
= UINT64_MAX
;
597 lh_STREAM_INFO_insert(lh
, info
);
603 static int helper_local_set_c_stream(struct helper_local
*hl
,
604 const char *stream_name
,
607 STREAM_INFO
*info
= get_stream_info(hl
->c_streams
, stream_name
);
612 info
->c_stream
= c_stream
;
613 info
->s_stream_id
= UINT64_MAX
;
617 static SSL
*helper_local_get_c_stream(struct helper_local
*hl
,
618 const char *stream_name
)
622 if (!strcmp(stream_name
, "DEFAULT"))
623 return hl
->h
->c_conn
;
625 info
= get_stream_info(hl
->c_streams
, stream_name
);
629 return info
->c_stream
;
633 helper_set_s_stream(struct helper
*h
, const char *stream_name
,
634 uint64_t s_stream_id
)
638 if (!strcmp(stream_name
, "DEFAULT"))
641 info
= get_stream_info(h
->s_streams
, stream_name
);
645 info
->c_stream
= NULL
;
646 info
->s_stream_id
= s_stream_id
;
650 static uint64_t helper_get_s_stream(struct helper
*h
, const char *stream_name
)
654 if (!strcmp(stream_name
, "DEFAULT"))
657 info
= get_stream_info(h
->s_streams
, stream_name
);
661 return info
->s_stream_id
;
664 static int is_want(SSL
*s
, int ret
)
666 int ec
= SSL_get_error(s
, ret
);
668 return ec
== SSL_ERROR_WANT_READ
|| ec
== SSL_ERROR_WANT_WRITE
;
671 static int run_script_worker(struct helper
*h
, const struct script_op
*script
,
675 unsigned char *tmp_buf
= NULL
;
676 int connect_started
= 0;
679 const struct script_op
*op
= NULL
;
680 int no_advance
= 0, first
= 1;
681 #if defined(OPENSSL_THREADS)
682 int end_wait_warning
= 0;
684 OSSL_TIME op_start_time
= ossl_time_zero(), op_deadline
= ossl_time_zero();
685 struct helper_local hl
;
686 #define REPEAT_SLOTS 8
687 size_t repeat_stack_idx
[REPEAT_SLOTS
], repeat_stack_done
[REPEAT_SLOTS
];
688 size_t repeat_stack_limit
[REPEAT_SLOTS
];
689 size_t repeat_stack_len
= 0;
691 if (!TEST_true(helper_local_init(&hl
, h
, thread_idx
)))
694 #define SPIN_AGAIN() { OSSL_sleep(1); no_advance = 1; continue; }
697 SSL
*c_tgt
= h
->c_conn
;
698 uint64_t s_stream_id
= UINT64_MAX
;
708 op_start_time
= ossl_time_now();
709 op_deadline
= ossl_time_add(op_start_time
, ossl_ms2time(2000));
712 if (!TEST_int_le(ossl_time_compare(ossl_time_now(), op_deadline
), 0)) {
713 TEST_error("op %zu timed out on thread %d", op_idx
+ 1, thread_idx
);
717 op
= &script
[op_idx
];
719 if (op
->stream_name
!= NULL
) {
720 c_tgt
= helper_local_get_c_stream(&hl
, op
->stream_name
);
722 s_stream_id
= helper_get_s_stream(h
, op
->stream_name
);
724 s_stream_id
= UINT64_MAX
;
728 ossl_quic_tserver_tick(h
->s
);
730 if (thread_idx
>= 0 || connect_started
)
731 SSL_handle_events(h
->c_conn
);
733 if (thread_idx
>= 0) {
734 /* Only allow certain opcodes on child threads. */
737 case OPK_C_ACCEPT_STREAM_WAIT
:
738 case OPK_C_NEW_STREAM
:
739 case OPK_C_READ_EXPECT
:
740 case OPK_C_EXPECT_FIN
:
743 case OPK_C_FREE_STREAM
:
744 case OPK_BEGIN_REPEAT
:
749 TEST_error("opcode %d not allowed on child thread", op
->op
);
756 if (!TEST_size_t_eq(repeat_stack_len
, 0))
759 #if defined(OPENSSL_THREADS)
760 if (thread_idx
< 0) {
764 for (i
= 0; i
< h
->num_threads
; ++i
) {
765 if (h
->threads
[i
].m
== NULL
)
768 ossl_crypto_mutex_lock(h
->threads
[i
].m
);
769 done
= h
->threads
[i
].done
;
770 ossl_crypto_mutex_unlock(h
->threads
[i
].m
);
773 if (!end_wait_warning
) {
774 TEST_info("still waiting for other threads to finish (%zu)", i
);
775 end_wait_warning
= 1;
784 TEST_info("script finished on thread %d", thread_idx
);
788 case OPK_BEGIN_REPEAT
:
789 if (!TEST_size_t_lt(repeat_stack_len
, OSSL_NELEM(repeat_stack_idx
)))
792 if (!TEST_size_t_gt(op
->arg1
, 0))
795 repeat_stack_idx
[repeat_stack_len
] = op_idx
+ 1;
796 repeat_stack_done
[repeat_stack_len
] = 0;
797 repeat_stack_limit
[repeat_stack_len
] = op
->arg1
;
802 if (!TEST_size_t_gt(repeat_stack_len
, 0))
805 if (++repeat_stack_done
[repeat_stack_len
- 1]
806 == repeat_stack_limit
[repeat_stack_len
- 1]) {
809 op_idx
= repeat_stack_idx
[repeat_stack_len
- 1];
818 int ok
= op
->check_func(h
, op
);
819 if (h
->check_spin_again
) {
820 h
->check_spin_again
= 0;
831 const char *alpn
= op
->arg0
;
832 size_t alpn_len
= strlen(alpn
);
834 if (!TEST_size_t_le(alpn_len
, UINT8_MAX
)
835 || !TEST_ptr(tmp_buf
= (unsigned char *)OPENSSL_malloc(alpn_len
+ 1)))
838 memcpy(tmp_buf
+ 1, alpn
, alpn_len
);
839 tmp_buf
[0] = (unsigned char)alpn_len
;
841 /* 0 is the success case for SSL_set_alpn_protos(). */
842 if (!TEST_false(SSL_set_alpn_protos(h
->c_conn
, tmp_buf
,
846 OPENSSL_free(tmp_buf
);
851 case OPK_C_CONNECT_WAIT
:
857 ret
= SSL_connect(h
->c_conn
);
858 if (!TEST_true(ret
== 1
859 || (!h
->blocking
&& is_want(h
->c_conn
, ret
))))
862 if (!h
->blocking
&& ret
!= 1)
869 size_t bytes_written
= 0;
871 if (!TEST_ptr(c_tgt
))
874 if (!TEST_true(SSL_write_ex(c_tgt
, op
->arg0
, op
->arg1
,
876 || !TEST_size_t_eq(bytes_written
, op
->arg1
))
883 size_t bytes_written
= 0;
885 if (!TEST_uint64_t_ne(s_stream_id
, UINT64_MAX
))
888 if (!TEST_true(ossl_quic_tserver_write(h
->s
, s_stream_id
,
891 || !TEST_size_t_eq(bytes_written
, op
->arg1
))
898 if (!TEST_true(SSL_stream_conclude(c_tgt
, 0)))
905 if (!TEST_uint64_t_ne(s_stream_id
, UINT64_MAX
))
908 ossl_quic_tserver_conclude(h
->s
, s_stream_id
);
912 case OPK_C_WAIT_FOR_DATA
:
915 size_t bytes_read
= 0;
917 if (!TEST_ptr(c_tgt
))
920 if (!SSL_peek_ex(c_tgt
, buf
, sizeof(buf
), &bytes_read
)
926 case OPK_C_READ_EXPECT
:
928 size_t bytes_read
= 0;
930 if (op
->arg1
> 0 && tmp_buf
== NULL
931 && !TEST_ptr(tmp_buf
= OPENSSL_malloc(op
->arg1
)))
934 if (!SSL_read_ex(c_tgt
, tmp_buf
+ offset
, op
->arg1
- offset
,
938 if (bytes_read
+ offset
!= op
->arg1
) {
939 offset
+= bytes_read
;
944 && !TEST_mem_eq(tmp_buf
, op
->arg1
, op
->arg0
, op
->arg1
))
947 OPENSSL_free(tmp_buf
);
952 case OPK_S_READ_EXPECT
:
954 size_t bytes_read
= 0;
956 if (!TEST_uint64_t_ne(s_stream_id
, UINT64_MAX
))
959 if (op
->arg1
> 0 && tmp_buf
== NULL
960 && !TEST_ptr(tmp_buf
= OPENSSL_malloc(op
->arg1
)))
963 if (!TEST_true(ossl_quic_tserver_read(h
->s
, s_stream_id
,
969 if (bytes_read
+ offset
!= op
->arg1
) {
970 offset
+= bytes_read
;
975 && !TEST_mem_eq(tmp_buf
, op
->arg1
, op
->arg0
, op
->arg1
))
978 OPENSSL_free(tmp_buf
);
983 case OPK_C_EXPECT_FIN
:
986 size_t bytes_read
= 0;
988 if (!TEST_false(SSL_read_ex(c_tgt
, buf
, sizeof(buf
),
990 || !TEST_size_t_eq(bytes_read
, 0))
993 if (is_want(c_tgt
, 0))
996 if (!TEST_int_eq(SSL_get_error(c_tgt
, 0),
997 SSL_ERROR_ZERO_RETURN
))
1002 case OPK_S_EXPECT_FIN
:
1004 if (!TEST_uint64_t_ne(s_stream_id
, UINT64_MAX
))
1007 if (!ossl_quic_tserver_has_read_ended(h
->s
, s_stream_id
))
1016 if (!TEST_ptr_null(c_tgt
))
1017 goto out
; /* don't overwrite existing stream with same name */
1019 if (!TEST_ptr(c_stream
= ossl_quic_detach_stream(h
->c_conn
)))
1022 if (!TEST_true(helper_local_set_c_stream(&hl
, op
->stream_name
, c_stream
)))
1029 if (!TEST_ptr(c_tgt
))
1032 if (!TEST_true(ossl_quic_attach_stream(h
->c_conn
, c_tgt
)))
1035 if (!TEST_true(helper_local_set_c_stream(&hl
, op
->stream_name
, NULL
)))
1040 case OPK_C_NEW_STREAM
:
1045 if (!TEST_ptr_null(c_tgt
))
1046 goto out
; /* don't overwrite existing stream with same name */
1049 flags
|= SSL_STREAM_FLAG_UNI
;
1051 if (!TEST_ptr(c_stream
= SSL_new_stream(h
->c_conn
, flags
)))
1054 if (op
->arg2
!= UINT64_MAX
1055 && !TEST_uint64_t_eq(SSL_get_stream_id(c_stream
),
1059 if (!TEST_true(helper_local_set_c_stream(&hl
, op
->stream_name
, c_stream
)))
1064 case OPK_S_NEW_STREAM
:
1066 uint64_t stream_id
= UINT64_MAX
;
1068 if (!TEST_uint64_t_eq(s_stream_id
, UINT64_MAX
))
1069 goto out
; /* don't overwrite existing stream with same name */
1071 if (!TEST_true(ossl_quic_tserver_stream_new(h
->s
,
1076 if (op
->arg2
!= UINT64_MAX
1077 && !TEST_uint64_t_eq(stream_id
, op
->arg2
))
1080 if (!TEST_true(helper_set_s_stream(h
, op
->stream_name
,
1086 case OPK_C_ACCEPT_STREAM_WAIT
:
1090 if (!TEST_ptr_null(c_tgt
))
1091 goto out
; /* don't overwrite existing stream with same name */
1093 if ((c_stream
= SSL_accept_stream(h
->c_conn
, 0)) == NULL
)
1096 if (!TEST_true(helper_local_set_c_stream(&hl
, op
->stream_name
,
1102 case OPK_S_ACCEPT_STREAM_WAIT
:
1104 uint64_t new_stream_id
;
1106 if (!TEST_uint64_t_eq(s_stream_id
, UINT64_MAX
))
1109 new_stream_id
= ossl_quic_tserver_pop_incoming_stream(h
->s
);
1110 if (new_stream_id
== UINT64_MAX
)
1113 if (!TEST_true(helper_set_s_stream(h
, op
->stream_name
, new_stream_id
)))
1118 case OPK_C_ACCEPT_STREAM_NONE
:
1122 if (!TEST_ptr_null(c_stream
= SSL_accept_stream(h
->c_conn
, 0))) {
1129 case OPK_C_FREE_STREAM
:
1131 if (!TEST_ptr(c_tgt
)
1132 || !TEST_true(!SSL_is_connection(c_tgt
)))
1135 if (!TEST_true(helper_local_set_c_stream(&hl
, op
->stream_name
, NULL
)))
1143 case OPK_C_SET_DEFAULT_STREAM_MODE
:
1145 if (!TEST_ptr(c_tgt
))
1148 if (!TEST_true(SSL_set_default_stream_mode(c_tgt
, op
->arg1
)))
1153 case OPK_C_SET_INCOMING_STREAM_POLICY
:
1155 if (!TEST_ptr(c_tgt
))
1158 if (!TEST_true(SSL_set_incoming_stream_policy(c_tgt
,
1164 case OPK_C_SHUTDOWN
:
1168 if (!TEST_ptr(c_tgt
))
1171 ret
= SSL_shutdown_ex(c_tgt
, 0, NULL
, 0);
1172 if (!TEST_int_ge(ret
, 0))
1178 case OPK_C_EXPECT_CONN_CLOSE_INFO
:
1180 SSL_CONN_CLOSE_INFO cc_info
= {0};
1181 int expect_app
= (op
->arg1
& EXPECT_CONN_CLOSE_APP
) != 0;
1182 int expect_remote
= (op
->arg1
& EXPECT_CONN_CLOSE_REMOTE
) != 0;
1183 uint64_t error_code
= op
->arg2
;
1185 if (!TEST_ptr(c_tgt
))
1188 if (!SSL_get_conn_close_info(c_tgt
, &cc_info
, sizeof(cc_info
)))
1191 if (!TEST_int_eq(expect_app
, !cc_info
.is_transport
)
1192 || !TEST_int_eq(expect_remote
, !cc_info
.is_local
)
1193 || !TEST_uint64_t_eq(error_code
, cc_info
.error_code
))
1198 case OPK_S_EXPECT_CONN_CLOSE_INFO
:
1200 const QUIC_TERMINATE_CAUSE
*tc
;
1201 int expect_app
= (op
->arg1
& EXPECT_CONN_CLOSE_APP
) != 0;
1202 int expect_remote
= (op
->arg1
& EXPECT_CONN_CLOSE_REMOTE
) != 0;
1203 uint64_t error_code
= op
->arg2
;
1205 if (!ossl_quic_tserver_is_term_any(h
->s
))
1208 if (!TEST_ptr(tc
= ossl_quic_tserver_get_terminate_cause(h
->s
)))
1211 if (!TEST_uint64_t_eq(error_code
, tc
->error_code
)
1212 || !TEST_int_eq(expect_app
, tc
->app
)
1213 || !TEST_int_eq(expect_remote
, tc
->remote
))
1218 case OPK_S_BIND_STREAM_ID
:
1220 if (!TEST_uint64_t_eq(s_stream_id
, UINT64_MAX
))
1223 if (!TEST_true(helper_set_s_stream(h
, op
->stream_name
, op
->arg2
)))
1228 case OPK_S_UNBIND_STREAM_ID
:
1230 if (!TEST_uint64_t_ne(s_stream_id
, UINT64_MAX
))
1233 if (!TEST_true(helper_set_s_stream(h
, op
->stream_name
, UINT64_MAX
)))
1238 case OPK_C_WRITE_FAIL
:
1240 size_t bytes_written
= 0;
1242 if (!TEST_ptr(c_tgt
))
1245 if (!TEST_false(SSL_write_ex(c_tgt
, "apple", 5, &bytes_written
)))
1250 case OPK_S_WRITE_FAIL
:
1252 size_t bytes_written
= 0;
1254 if (!TEST_uint64_t_ne(s_stream_id
, UINT64_MAX
))
1257 if (!TEST_false(ossl_quic_tserver_write(h
->s
, s_stream_id
,
1258 (const unsigned char *)"apple", 5,
1264 case OPK_C_READ_FAIL
:
1266 size_t bytes_read
= 0;
1269 if (!TEST_ptr(c_tgt
))
1272 if (!TEST_false(SSL_read_ex(c_tgt
, buf
, sizeof(buf
), &bytes_read
)))
1277 case OPK_C_STREAM_RESET
:
1279 SSL_STREAM_RESET_ARGS args
= {0};
1281 if (!TEST_ptr(c_tgt
))
1284 args
.quic_error_code
= op
->arg2
;
1286 if (!TEST_true(SSL_stream_reset(c_tgt
, &args
, sizeof(args
))))
1291 case OPK_NEW_THREAD
:
1293 #if !defined(OPENSSL_THREADS)
1295 * If this test script requires threading and we do not have
1296 * support for it, skip the rest of it.
1298 TEST_skip("threading not supported, skipping");
1304 if (!TEST_ptr_null(h
->threads
)) {
1305 TEST_error("max one NEW_THREAD operation per script");
1309 h
->threads
= OPENSSL_zalloc(op
->arg1
* sizeof(struct child_thread_args
));
1310 if (!TEST_ptr(h
->threads
))
1313 h
->num_threads
= op
->arg1
;
1315 for (i
= 0; i
< op
->arg1
; ++i
) {
1316 h
->threads
[i
].h
= h
;
1317 h
->threads
[i
].script
= op
->arg0
;
1318 h
->threads
[i
].thread_idx
= i
;
1320 h
->threads
[i
].m
= ossl_crypto_mutex_new();
1321 if (!TEST_ptr(h
->threads
[i
].m
))
1325 = ossl_crypto_thread_native_start(run_script_child_thread
,
1327 if (!TEST_ptr(h
->threads
[i
].t
))
1335 TEST_error("unknown op");
1344 TEST_error("failed at script op %zu, thread %d\n",
1345 op_idx
+ 1, thread_idx
);
1347 for (i
= 0; i
< repeat_stack_len
; ++i
)
1348 TEST_info("while repeating, iteration %zu of %zu, starting at script op %zu",
1349 repeat_stack_done
[i
],
1350 repeat_stack_limit
[i
],
1351 repeat_stack_idx
[i
]);
1354 OPENSSL_free(tmp_buf
);
1355 helper_local_cleanup(&hl
);
1359 static int run_script(const struct script_op
*script
, int free_order
)
1364 if (!TEST_true(helper_init(&h
, free_order
)))
1367 if (!TEST_true(run_script_worker(&h
, script
, -1)))
1370 #if defined(OPENSSL_THREADS)
1371 if (!TEST_true(join_threads(h
.threads
, h
.num_threads
)))
1381 #if defined(OPENSSL_THREADS)
1382 static CRYPTO_THREAD_RETVAL
run_script_child_thread(void *arg
)
1385 struct child_thread_args
*args
= arg
;
1387 testresult
= run_script_worker(args
->h
, args
->script
,
1390 ossl_crypto_mutex_lock(args
->m
);
1391 args
->testresult
= testresult
;
1393 ossl_crypto_mutex_unlock(args
->m
);
1398 /* 1. Simple single-stream test */
1399 static const struct script_op script_1
[] = {
1400 OP_C_SET_ALPN ("ossltest")
1401 OP_C_CONNECT_WAIT ()
1402 OP_C_WRITE (DEFAULT
, "apple", 5)
1403 OP_C_CONCLUDE (DEFAULT
)
1404 OP_S_BIND_STREAM_ID (a
, C_BIDI_ID(0))
1405 OP_S_READ_EXPECT (a
, "apple", 5)
1407 OP_S_WRITE (a
, "orange", 6)
1409 OP_C_READ_EXPECT (DEFAULT
, "orange", 6)
1410 OP_C_EXPECT_FIN (DEFAULT
)
1414 /* 2. Multi-stream test */
1415 static const struct script_op script_2
[] = {
1416 OP_C_SET_ALPN ("ossltest")
1417 OP_C_CONNECT_WAIT ()
1418 OP_C_SET_INCOMING_STREAM_POLICY(SSL_INCOMING_STREAM_POLICY_ACCEPT
)
1419 OP_C_WRITE (DEFAULT
, "apple", 5)
1420 OP_S_BIND_STREAM_ID (a
, C_BIDI_ID(0))
1421 OP_S_READ_EXPECT (a
, "apple", 5)
1422 OP_S_WRITE (a
, "orange", 6)
1423 OP_C_READ_EXPECT (DEFAULT
, "orange", 6)
1425 OP_C_NEW_STREAM_BIDI (b
, C_BIDI_ID(1))
1426 OP_C_WRITE (b
, "flamingo", 8)
1428 OP_S_BIND_STREAM_ID (b
, C_BIDI_ID(1))
1429 OP_S_READ_EXPECT (b
, "flamingo", 8)
1431 OP_S_WRITE (b
, "gargoyle", 8)
1433 OP_C_READ_EXPECT (b
, "gargoyle", 8)
1436 OP_C_NEW_STREAM_UNI (c
, C_UNI_ID(0))
1437 OP_C_WRITE (c
, "elephant", 8)
1439 OP_S_BIND_STREAM_ID (c
, C_UNI_ID(0))
1440 OP_S_READ_EXPECT (c
, "elephant", 8)
1444 OP_C_ACCEPT_STREAM_NONE ()
1446 OP_S_NEW_STREAM_BIDI (d
, S_BIDI_ID(0))
1447 OP_S_WRITE (d
, "frog", 4)
1450 OP_C_ACCEPT_STREAM_WAIT (d
)
1451 OP_C_ACCEPT_STREAM_NONE ()
1452 OP_C_READ_EXPECT (d
, "frog", 4)
1455 OP_S_NEW_STREAM_BIDI (e
, S_BIDI_ID(1))
1456 OP_S_WRITE (e
, "mixture", 7)
1459 OP_C_ACCEPT_STREAM_WAIT (e
)
1460 OP_C_READ_EXPECT (e
, "mixture", 7)
1462 OP_C_WRITE (e
, "ramble", 6)
1463 OP_S_READ_EXPECT (e
, "ramble", 6)
1467 OP_S_NEW_STREAM_UNI (f
, S_UNI_ID(0))
1468 OP_S_WRITE (f
, "yonder", 6)
1471 OP_C_ACCEPT_STREAM_WAIT (f
)
1472 OP_C_ACCEPT_STREAM_NONE ()
1473 OP_C_READ_EXPECT (f
, "yonder", 6)
1477 OP_C_SET_INCOMING_STREAM_POLICY(SSL_INCOMING_STREAM_POLICY_REJECT
)
1478 OP_S_NEW_STREAM_BIDI (g
, S_BIDI_ID(2))
1479 OP_S_WRITE (g
, "unseen", 6)
1482 OP_C_ACCEPT_STREAM_NONE ()
1484 OP_C_SET_INCOMING_STREAM_POLICY(SSL_INCOMING_STREAM_POLICY_AUTO
)
1485 OP_S_NEW_STREAM_BIDI (h
, S_BIDI_ID(3))
1486 OP_S_WRITE (h
, "UNSEEN", 6)
1489 OP_C_ACCEPT_STREAM_NONE ()
1492 * Streams g, h should have been rejected, so server should have got
1493 * STOP_SENDING/RESET_STREAM.
1495 OP_CHECK (check_rejected
, S_BIDI_ID(2))
1496 OP_CHECK (check_rejected
, S_BIDI_ID(3))
1501 /* 3. Default stream detach/reattach test */
1502 static const struct script_op script_3
[] = {
1503 OP_C_SET_ALPN ("ossltest")
1504 OP_C_CONNECT_WAIT ()
1506 OP_C_WRITE (DEFAULT
, "apple", 5)
1507 OP_C_DETACH (a
) /* DEFAULT becomes stream 'a' */
1508 OP_C_WRITE_FAIL (DEFAULT
)
1510 OP_C_WRITE (a
, "by", 2)
1512 OP_S_BIND_STREAM_ID (a
, C_BIDI_ID(0))
1513 OP_S_READ_EXPECT (a
, "appleby", 7)
1515 OP_S_WRITE (a
, "hello", 5)
1516 OP_C_READ_EXPECT (a
, "hello", 5)
1518 OP_C_WRITE_FAIL (DEFAULT
)
1520 OP_C_WRITE (DEFAULT
, "is here", 7)
1521 OP_S_READ_EXPECT (a
, "is here", 7)
1530 /* 4. Default stream mode test */
1531 static const struct script_op script_4
[] = {
1532 OP_C_SET_ALPN ("ossltest")
1533 OP_C_CONNECT_WAIT ()
1535 OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE
)
1536 OP_C_WRITE_FAIL (DEFAULT
)
1538 OP_S_NEW_STREAM_BIDI (a
, S_BIDI_ID(0))
1539 OP_S_WRITE (a
, "apple", 5)
1541 OP_C_READ_FAIL (DEFAULT
)
1543 OP_C_ACCEPT_STREAM_WAIT (a
)
1544 OP_C_READ_EXPECT (a
, "apple", 5)
1547 OP_C_WRITE (DEFAULT
, "orange", 6)
1548 OP_S_READ_EXPECT (a
, "orange", 6)
1553 /* 5. Test stream reset functionality */
1554 static const struct script_op script_5
[] = {
1555 OP_C_SET_ALPN ("ossltest")
1556 OP_C_CONNECT_WAIT ()
1558 OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE
)
1559 OP_C_NEW_STREAM_BIDI (a
, C_BIDI_ID(0))
1561 OP_C_WRITE (a
, "apple", 5)
1562 OP_C_STREAM_RESET (a
, 42)
1564 OP_S_BIND_STREAM_ID (a
, C_BIDI_ID(0))
1565 OP_S_READ_EXPECT (a
, "apple", 5)
1566 OP_CHECK (check_stream_reset
, C_BIDI_ID(0))
1571 /* 6. Test STOP_SENDING functionality */
1572 static const struct script_op script_6
[] = {
1573 OP_C_SET_ALPN ("ossltest")
1574 OP_C_CONNECT_WAIT ()
1576 OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE
)
1577 OP_S_NEW_STREAM_BIDI (a
, S_BIDI_ID(0))
1578 OP_S_WRITE (a
, "apple", 5)
1580 OP_C_ACCEPT_STREAM_WAIT (a
)
1581 OP_C_FREE_STREAM (a
)
1582 OP_C_ACCEPT_STREAM_NONE ()
1584 OP_CHECK (check_stream_stopped
, S_BIDI_ID(0))
1589 /* 7. Unidirectional default stream mode test (client sends first) */
1590 static const struct script_op script_7
[] = {
1591 OP_C_SET_ALPN ("ossltest")
1592 OP_C_CONNECT_WAIT ()
1594 OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_AUTO_UNI
)
1595 OP_C_WRITE (DEFAULT
, "apple", 5)
1597 OP_S_BIND_STREAM_ID (a
, C_UNI_ID(0))
1598 OP_S_READ_EXPECT (a
, "apple", 5)
1604 /* 8. Unidirectional default stream mode test (server sends first) */
1605 static const struct script_op script_8
[] = {
1606 OP_C_SET_ALPN ("ossltest")
1607 OP_C_CONNECT_WAIT ()
1609 OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_AUTO_UNI
)
1610 OP_S_NEW_STREAM_UNI (a
, S_UNI_ID(0))
1611 OP_S_WRITE (a
, "apple", 5)
1612 OP_C_READ_EXPECT (DEFAULT
, "apple", 5)
1613 OP_C_WRITE_FAIL (DEFAULT
)
1618 /* 9. Unidirectional default stream mode test (server sends first on bidi) */
1619 static const struct script_op script_9
[] = {
1620 OP_C_SET_ALPN ("ossltest")
1621 OP_C_CONNECT_WAIT ()
1623 OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_AUTO_UNI
)
1624 OP_S_NEW_STREAM_BIDI (a
, S_BIDI_ID(0))
1625 OP_S_WRITE (a
, "apple", 5)
1626 OP_C_READ_EXPECT (DEFAULT
, "apple", 5)
1627 OP_C_WRITE (DEFAULT
, "orange", 6)
1628 OP_S_READ_EXPECT (a
, "orange", 6)
1634 static const struct script_op script_10
[] = {
1635 OP_C_SET_ALPN ("ossltest")
1636 OP_C_CONNECT_WAIT ()
1638 OP_C_WRITE (DEFAULT
, "apple", 5)
1639 OP_S_BIND_STREAM_ID (a
, C_BIDI_ID(0))
1640 OP_S_READ_EXPECT (a
, "apple", 5)
1643 OP_C_EXPECT_CONN_CLOSE_INFO(0, 1, 0)
1644 OP_S_EXPECT_CONN_CLOSE_INFO(0, 1, 1)
1649 /* 11. Many threads accepted on the same client connection */
1650 static const struct script_op script_11_child
[] = {
1651 OP_C_ACCEPT_STREAM_WAIT (a
)
1652 OP_C_READ_EXPECT (a
, "foo", 3)
1658 static const struct script_op script_11
[] = {
1659 OP_C_SET_ALPN ("ossltest")
1660 OP_C_CONNECT_WAIT ()
1661 OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE
)
1663 OP_NEW_THREAD (5, script_11_child
)
1665 OP_S_NEW_STREAM_BIDI (a
, ANY_ID
)
1666 OP_S_WRITE (a
, "foo", 3)
1669 OP_S_NEW_STREAM_BIDI (b
, ANY_ID
)
1670 OP_S_WRITE (b
, "foo", 3)
1673 OP_S_NEW_STREAM_BIDI (c
, ANY_ID
)
1674 OP_S_WRITE (c
, "foo", 3)
1677 OP_S_NEW_STREAM_BIDI (d
, ANY_ID
)
1678 OP_S_WRITE (d
, "foo", 3)
1681 OP_S_NEW_STREAM_BIDI (e
, ANY_ID
)
1682 OP_S_WRITE (e
, "foo", 3)
1688 /* 12. Many threads initiated on the same client connection */
1689 static const struct script_op script_12_child
[] = {
1690 OP_C_NEW_STREAM_BIDI (a
, ANY_ID
)
1691 OP_C_WRITE (a
, "foo", 3)
1693 OP_C_FREE_STREAM (a
)
1698 static const struct script_op script_12
[] = {
1699 OP_C_SET_ALPN ("ossltest")
1700 OP_C_CONNECT_WAIT ()
1701 OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE
)
1703 OP_NEW_THREAD (5, script_12_child
)
1705 OP_S_BIND_STREAM_ID (a
, C_BIDI_ID(0))
1706 OP_S_READ_EXPECT (a
, "foo", 3)
1708 OP_S_BIND_STREAM_ID (b
, C_BIDI_ID(1))
1709 OP_S_READ_EXPECT (b
, "foo", 3)
1711 OP_S_BIND_STREAM_ID (c
, C_BIDI_ID(2))
1712 OP_S_READ_EXPECT (c
, "foo", 3)
1714 OP_S_BIND_STREAM_ID (d
, C_BIDI_ID(3))
1715 OP_S_READ_EXPECT (d
, "foo", 3)
1717 OP_S_BIND_STREAM_ID (e
, C_BIDI_ID(4))
1718 OP_S_READ_EXPECT (e
, "foo", 3)
1724 /* 13. Many threads accepted on the same client connection (stress test) */
1725 static const struct script_op script_13_child
[] = {
1726 OP_BEGIN_REPEAT (10)
1728 OP_C_ACCEPT_STREAM_WAIT (a
)
1729 OP_C_READ_EXPECT (a
, "foo", 3)
1731 OP_C_FREE_STREAM (a
)
1738 static const struct script_op script_13
[] = {
1739 OP_C_SET_ALPN ("ossltest")
1740 OP_C_CONNECT_WAIT ()
1741 OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE
)
1743 OP_NEW_THREAD (5, script_13_child
)
1745 OP_BEGIN_REPEAT (50)
1747 OP_S_NEW_STREAM_BIDI (a
, ANY_ID
)
1748 OP_S_WRITE (a
, "foo", 3)
1750 OP_S_UNBIND_STREAM_ID (a
)
1757 /* 14. Many threads initiating on the same client connection (stress test) */
1758 static const struct script_op script_14_child
[] = {
1759 OP_BEGIN_REPEAT (10)
1761 OP_C_NEW_STREAM_BIDI (a
, ANY_ID
)
1762 OP_C_WRITE (a
, "foo", 3)
1764 OP_C_FREE_STREAM (a
)
1771 static const struct script_op script_14
[] = {
1772 OP_C_SET_ALPN ("ossltest")
1773 OP_C_CONNECT_WAIT ()
1774 OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE
)
1776 OP_NEW_THREAD (5, script_14_child
)
1778 OP_BEGIN_REPEAT (50)
1780 OP_S_ACCEPT_STREAM_WAIT (a
)
1781 OP_S_READ_EXPECT (a
, "foo", 3)
1783 OP_S_UNBIND_STREAM_ID (a
)
1790 /* 15. Client sending large number of streams, MAX_STREAMS test */
1791 static const struct script_op script_15
[] = {
1792 OP_C_SET_ALPN ("ossltest")
1793 OP_C_CONNECT_WAIT ()
1794 OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE
)
1797 * This will cause a protocol violation to be raised by the server if we are
1798 * not handling the stream limit correctly on the TX side.
1800 OP_BEGIN_REPEAT (200)
1802 OP_C_NEW_STREAM_BIDI (a
, ANY_ID
)
1803 OP_C_WRITE (a
, "foo", 3)
1805 OP_C_FREE_STREAM (a
)
1809 /* Prove the connection is still good. */
1810 OP_S_NEW_STREAM_BIDI (a
, S_BIDI_ID(0))
1811 OP_S_WRITE (a
, "bar", 3)
1814 OP_C_ACCEPT_STREAM_WAIT (a
)
1815 OP_C_READ_EXPECT (a
, "bar", 3)
1819 * Drain the queue of incoming streams. We should be able to get all 200
1820 * even though only 100 can be initiated at a time.
1822 OP_BEGIN_REPEAT (200)
1824 OP_S_ACCEPT_STREAM_WAIT (b
)
1825 OP_S_READ_EXPECT (b
, "foo", 3)
1827 OP_S_UNBIND_STREAM_ID (b
)
1834 /* 16. Server sending large number of streams, MAX_STREAMS test */
1835 static const struct script_op script_16
[] = {
1836 OP_C_SET_ALPN ("ossltest")
1837 OP_C_CONNECT_WAIT ()
1838 OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE
)
1841 * This will cause a protocol violation to be raised by the client if we are
1842 * not handling the stream limit correctly on the TX side.
1844 OP_BEGIN_REPEAT (200)
1846 OP_S_NEW_STREAM_BIDI (a
, ANY_ID
)
1847 OP_S_WRITE (a
, "foo", 3)
1849 OP_S_UNBIND_STREAM_ID (a
)
1853 /* Prove that the connection is still good. */
1854 OP_C_NEW_STREAM_BIDI (a
, ANY_ID
)
1855 OP_C_WRITE (a
, "bar", 3)
1858 OP_S_ACCEPT_STREAM_WAIT (b
)
1859 OP_S_READ_EXPECT (b
, "bar", 3)
1862 /* Drain the queue of incoming streams. */
1863 OP_BEGIN_REPEAT (200)
1865 OP_C_ACCEPT_STREAM_WAIT (b
)
1866 OP_C_READ_EXPECT (b
, "foo", 3)
1868 OP_C_FREE_STREAM (b
)
1875 /* 17. Key update test - unlimited */
1876 static const struct script_op script_17
[] = {
1877 OP_C_SET_ALPN ("ossltest")
1878 OP_C_CONNECT_WAIT ()
1880 OP_C_WRITE (DEFAULT
, "apple", 5)
1882 OP_S_BIND_STREAM_ID (a
, C_BIDI_ID(0))
1883 OP_S_READ_EXPECT (a
, "apple", 5)
1885 OP_CHECK (override_key_update
, 1)
1887 OP_BEGIN_REPEAT (200)
1889 OP_C_WRITE (DEFAULT
, "apple", 5)
1890 OP_S_READ_EXPECT (a
, "apple", 5)
1893 * TXKU frequency is bounded by RTT because a previous TXKU needs to be
1894 * acknowledged by the peer first before another one can be begin. By
1895 * waiting this long, we eliminate any such concern and ensure as many key
1896 * updates as possible can occur for the purposes of this test.
1898 OP_CHECK (skip_time_ms
, 100)
1902 /* At least 5 RXKUs detected */
1903 OP_CHECK (check_key_update_ge
, 5)
1906 * Prove the connection is still healthy by sending something in both
1909 OP_C_WRITE (DEFAULT
, "xyzzy", 5)
1910 OP_S_READ_EXPECT (a
, "xyzzy", 5)
1912 OP_S_WRITE (a
, "plugh", 5)
1913 OP_C_READ_EXPECT (DEFAULT
, "plugh", 5)
1918 /* 18. Key update test - RTT-bounded */
1919 static const struct script_op script_18
[] = {
1920 OP_C_SET_ALPN ("ossltest")
1921 OP_C_CONNECT_WAIT ()
1923 OP_C_WRITE (DEFAULT
, "apple", 5)
1925 OP_S_BIND_STREAM_ID (a
, C_BIDI_ID(0))
1926 OP_S_READ_EXPECT (a
, "apple", 5)
1928 OP_CHECK (override_key_update
, 1)
1930 OP_BEGIN_REPEAT (200)
1932 OP_C_WRITE (DEFAULT
, "apple", 5)
1933 OP_S_READ_EXPECT (a
, "apple", 5)
1934 OP_CHECK (skip_time_ms
, 2)
1939 * This time we simulate far less time passing between writes, so there are
1940 * fewer opportunities to initiate TXKUs. Note that we ask for a TXKU every
1941 * 1 packet above, which is absurd; thus this ensures we only actually
1942 * generate TXKUs when we are allowed to.
1944 OP_CHECK (check_key_update_ge
, 4)
1945 OP_CHECK (check_key_update_lt
, 120)
1948 * Prove the connection is still healthy by sending something in both
1951 OP_C_WRITE (DEFAULT
, "xyzzy", 5)
1952 OP_S_READ_EXPECT (a
, "xyzzy", 5)
1954 OP_S_WRITE (a
, "plugh", 5)
1955 OP_C_READ_EXPECT (DEFAULT
, "plugh", 5)
1960 /* 19. Key update test - artificially triggered */
1961 static const struct script_op script_19
[] = {
1962 OP_C_SET_ALPN ("ossltest")
1963 OP_C_CONNECT_WAIT ()
1965 OP_C_WRITE (DEFAULT
, "apple", 5)
1967 OP_S_BIND_STREAM_ID (a
, C_BIDI_ID(0))
1968 OP_S_READ_EXPECT (a
, "apple", 5)
1970 OP_CHECK (check_key_update_lt
, 1)
1971 OP_CHECK (trigger_key_update
, 0)
1973 OP_C_WRITE (DEFAULT
, "orange", 6)
1974 OP_S_READ_EXPECT (a
, "orange", 6)
1976 OP_CHECK (check_key_update_ge
, 1)
1981 static const struct script_op
*const scripts
[] = {
2003 static int test_script(int idx
)
2005 int script_idx
= idx
>> 1;
2006 int free_order
= idx
& 1;
2008 TEST_info("Running script %d (order=%d)", script_idx
+ 1, free_order
);
2009 return run_script(scripts
[script_idx
], free_order
);
2012 OPT_TEST_DECLARE_USAGE("certfile privkeyfile\n")
2014 int setup_tests(void)
2016 if (!test_skip_common_options()) {
2017 TEST_error("Error parsing test options\n");
2021 if (!TEST_ptr(certfile
= test_get_argument(0))
2022 || !TEST_ptr(keyfile
= test_get_argument(1)))
2025 ADD_ALL_TESTS(test_script
, OSSL_NELEM(scripts
) * 2);