]>
Commit | Line | Data |
---|---|---|
ed835673 HL |
1 | /* |
2 | * Copyright 2023 The OpenSSL Project Authors. All Rights Reserved. | |
3 | * | |
4 | * Licensed under the Apache License 2.0 (the "License"). You may not use | |
5 | * this file except in compliance with the License. You can obtain a copy | |
6 | * in the file LICENSE in the source distribution or at | |
7 | * https://www.openssl.org/source/license.html | |
8 | */ | |
9 | #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" | |
de521629 | 14 | #include "internal/quic_ssl.h" |
e26dc8e3 | 15 | #include "internal/quic_error.h" |
ed835673 | 16 | #include "testutil.h" |
e26dc8e3 | 17 | #include "helpers/quictestlib.h" |
a350db73 HL |
18 | #if defined(OPENSSL_THREADS) |
19 | # include "internal/thread_arch.h" | |
20 | #endif | |
ed835673 HL |
21 | |
22 | static const char *certfile, *keyfile; | |
23 | ||
a350db73 HL |
24 | #if defined(OPENSSL_THREADS) |
25 | struct child_thread_args { | |
26 | struct helper *h; | |
27 | const struct script_op *script; | |
0786483a | 28 | const char *script_name; |
a350db73 HL |
29 | int thread_idx; |
30 | ||
31 | CRYPTO_THREAD *t; | |
32 | CRYPTO_MUTEX *m; | |
33 | int testresult; | |
34 | int done; | |
35 | }; | |
36 | #endif | |
37 | ||
ed835673 HL |
38 | typedef struct stream_info { |
39 | const char *name; | |
40 | SSL *c_stream; | |
41 | uint64_t s_stream_id; | |
42 | } STREAM_INFO; | |
43 | ||
44 | DEFINE_LHASH_OF_EX(STREAM_INFO); | |
45 | ||
46 | struct helper { | |
47 | int s_fd; | |
e26dc8e3 | 48 | BIO *s_net_bio, *s_net_bio_own, *s_qtf_wbio, *s_qtf_wbio_own; |
ed835673 HL |
49 | BIO_ADDR *s_net_bio_addr; |
50 | QUIC_TSERVER *s; | |
51 | LHASH_OF(STREAM_INFO) *s_streams; | |
52 | ||
53 | int c_fd; | |
54 | BIO *c_net_bio, *c_net_bio_own; | |
55 | SSL_CTX *c_ctx; | |
56 | SSL *c_conn; | |
57 | LHASH_OF(STREAM_INFO) *c_streams; | |
58 | ||
a350db73 HL |
59 | #if defined(OPENSSL_THREADS) |
60 | struct child_thread_args *threads; | |
61 | size_t num_threads; | |
62 | #endif | |
63 | ||
ed835673 | 64 | OSSL_TIME start_time; |
693b23e3 HL |
65 | |
66 | /* | |
67 | * This is a duration recording the amount of time we have skipped forwards | |
68 | * for testing purposes relative to the real ossl_time_now() clock. We add | |
69 | * a quantity of time to this every time we skip some time. | |
70 | */ | |
71 | CRYPTO_RWLOCK *time_lock; | |
72 | OSSL_TIME time_slip; /* protected by time_lock */ | |
73 | ||
e26dc8e3 HL |
74 | QTEST_FAULT *qtf; |
75 | ||
9715e3aa | 76 | int init, blocking, check_spin_again; |
e26dc8e3 HL |
77 | int free_order, need_injector; |
78 | ||
79 | int (*qtf_packet_plain_cb)(struct helper *h, QUIC_PKT_HDR *hdr, | |
80 | unsigned char *buf, size_t buf_len); | |
81 | uint64_t inject_word0, inject_word1; | |
ed835673 HL |
82 | }; |
83 | ||
a350db73 HL |
84 | struct helper_local { |
85 | struct helper *h; | |
86 | LHASH_OF(STREAM_INFO) *c_streams; | |
87 | int thread_idx; | |
88 | }; | |
89 | ||
ed835673 HL |
90 | struct script_op { |
91 | uint32_t op; | |
92 | const void *arg0; | |
93 | size_t arg1; | |
94 | int (*check_func)(struct helper *h, const struct script_op *op); | |
95 | const char *stream_name; | |
96 | uint64_t arg2; | |
e26dc8e3 HL |
97 | int (*qtf_packet_plain_cb)(struct helper *h, QUIC_PKT_HDR *hdr, |
98 | unsigned char *buf, size_t buf_len); | |
ed835673 HL |
99 | }; |
100 | ||
101 | #define OPK_END 0 | |
102 | #define OPK_CHECK 1 | |
103 | #define OPK_C_SET_ALPN 2 | |
104 | #define OPK_C_CONNECT_WAIT 3 | |
105 | #define OPK_C_WRITE 4 | |
106 | #define OPK_S_WRITE 5 | |
107 | #define OPK_C_READ_EXPECT 6 | |
108 | #define OPK_S_READ_EXPECT 7 | |
109 | #define OPK_C_EXPECT_FIN 8 | |
110 | #define OPK_S_EXPECT_FIN 9 | |
111 | #define OPK_C_CONCLUDE 10 | |
112 | #define OPK_S_CONCLUDE 11 | |
113 | #define OPK_C_DETACH 12 | |
114 | #define OPK_C_ATTACH 13 | |
115 | #define OPK_C_NEW_STREAM 14 | |
116 | #define OPK_S_NEW_STREAM 15 | |
a350db73 | 117 | #define OPK_C_ACCEPT_STREAM_WAIT 16 |
ed835673 HL |
118 | #define OPK_C_ACCEPT_STREAM_NONE 17 |
119 | #define OPK_C_FREE_STREAM 18 | |
120 | #define OPK_C_SET_DEFAULT_STREAM_MODE 19 | |
83df44ae | 121 | #define OPK_C_SET_INCOMING_STREAM_POLICY 20 |
cd5e4380 | 122 | #define OPK_C_SHUTDOWN_WAIT 21 |
ed835673 HL |
123 | #define OPK_C_EXPECT_CONN_CLOSE_INFO 22 |
124 | #define OPK_S_EXPECT_CONN_CLOSE_INFO 23 | |
125 | #define OPK_S_BIND_STREAM_ID 24 | |
126 | #define OPK_C_WAIT_FOR_DATA 25 | |
127 | #define OPK_C_WRITE_FAIL 26 | |
128 | #define OPK_S_WRITE_FAIL 27 | |
129 | #define OPK_C_READ_FAIL 28 | |
130 | #define OPK_C_STREAM_RESET 29 | |
a350db73 HL |
131 | #define OPK_S_ACCEPT_STREAM_WAIT 30 |
132 | #define OPK_NEW_THREAD 31 | |
fca44cfc HL |
133 | #define OPK_BEGIN_REPEAT 32 |
134 | #define OPK_END_REPEAT 33 | |
135 | #define OPK_S_UNBIND_STREAM_ID 34 | |
0345cac6 TM |
136 | #define OPK_C_READ_FAIL_WAIT 35 |
137 | #define OPK_C_CLOSE_SOCKET 36 | |
138 | #define OPK_C_EXPECT_SSL_ERR 37 | |
139 | #define OPK_EXPECT_ERR_REASON 38 | |
140 | #define OPK_EXPECT_ERR_LIB 39 | |
141 | #define OPK_SLEEP 40 | |
2f018d14 | 142 | #define OPK_S_READ_FAIL 41 |
e26dc8e3 HL |
143 | #define OPK_S_SET_INJECT_PLAIN 42 |
144 | #define OPK_SET_INJECT_WORD 43 | |
cd5e4380 HL |
145 | #define OPK_C_INHIBIT_TICK 44 |
146 | #define OPK_C_SET_WRITE_BUF_SIZE 45 | |
ed835673 HL |
147 | |
148 | #define EXPECT_CONN_CLOSE_APP (1U << 0) | |
149 | #define EXPECT_CONN_CLOSE_REMOTE (1U << 1) | |
150 | ||
151 | #define C_BIDI_ID(ordinal) \ | |
152 | (((ordinal) << 2) | QUIC_STREAM_INITIATOR_CLIENT | QUIC_STREAM_DIR_BIDI) | |
153 | #define S_BIDI_ID(ordinal) \ | |
154 | (((ordinal) << 2) | QUIC_STREAM_INITIATOR_SERVER | QUIC_STREAM_DIR_BIDI) | |
155 | #define C_UNI_ID(ordinal) \ | |
156 | (((ordinal) << 2) | QUIC_STREAM_INITIATOR_CLIENT | QUIC_STREAM_DIR_UNI) | |
157 | #define S_UNI_ID(ordinal) \ | |
158 | (((ordinal) << 2) | QUIC_STREAM_INITIATOR_SERVER | QUIC_STREAM_DIR_UNI) | |
159 | ||
a350db73 HL |
160 | #define ANY_ID UINT64_MAX |
161 | ||
ed835673 HL |
162 | #define OP_END \ |
163 | {OPK_END} | |
164 | #define OP_CHECK(func, arg2) \ | |
165 | {OPK_CHECK, NULL, 0, (func), NULL, (arg2)}, | |
166 | #define OP_C_SET_ALPN(alpn) \ | |
167 | {OPK_C_SET_ALPN, (alpn), 0, NULL, NULL}, | |
168 | #define OP_C_CONNECT_WAIT() \ | |
169 | {OPK_C_CONNECT_WAIT, NULL, 0, NULL, NULL}, | |
e26dc8e3 HL |
170 | #define OP_C_CONNECT_WAIT_OR_FAIL() \ |
171 | {OPK_C_CONNECT_WAIT, NULL, 1, NULL, NULL}, | |
ed835673 HL |
172 | #define OP_C_WRITE(stream_name, buf, buf_len) \ |
173 | {OPK_C_WRITE, (buf), (buf_len), NULL, #stream_name}, | |
174 | #define OP_S_WRITE(stream_name, buf, buf_len) \ | |
175 | {OPK_S_WRITE, (buf), (buf_len), NULL, #stream_name}, | |
176 | #define OP_C_READ_EXPECT(stream_name, buf, buf_len) \ | |
177 | {OPK_C_READ_EXPECT, (buf), (buf_len), NULL, #stream_name}, | |
178 | #define OP_S_READ_EXPECT(stream_name, buf, buf_len) \ | |
179 | {OPK_S_READ_EXPECT, (buf), (buf_len), NULL, #stream_name}, | |
180 | #define OP_C_EXPECT_FIN(stream_name) \ | |
181 | {OPK_C_EXPECT_FIN, NULL, 0, NULL, #stream_name}, | |
182 | #define OP_S_EXPECT_FIN(stream_name) \ | |
183 | {OPK_S_EXPECT_FIN, NULL, 0, NULL, #stream_name}, | |
184 | #define OP_C_CONCLUDE(stream_name) \ | |
185 | {OPK_C_CONCLUDE, NULL, 0, NULL, #stream_name}, | |
186 | #define OP_S_CONCLUDE(stream_name) \ | |
187 | {OPK_S_CONCLUDE, NULL, 0, NULL, #stream_name}, | |
188 | #define OP_C_DETACH(stream_name) \ | |
189 | {OPK_C_DETACH, NULL, 0, NULL, #stream_name}, | |
190 | #define OP_C_ATTACH(stream_name) \ | |
191 | {OPK_C_ATTACH, NULL, 0, NULL, #stream_name}, | |
192 | #define OP_C_NEW_STREAM_BIDI(stream_name, expect_id) \ | |
193 | {OPK_C_NEW_STREAM, NULL, 0, NULL, #stream_name, (expect_id)}, | |
194 | #define OP_C_NEW_STREAM_UNI(stream_name, expect_id) \ | |
195 | {OPK_C_NEW_STREAM, NULL, 1, NULL, #stream_name, (expect_id)}, | |
196 | #define OP_S_NEW_STREAM_BIDI(stream_name, expect_id) \ | |
197 | {OPK_S_NEW_STREAM, NULL, 0, NULL, #stream_name, (expect_id)}, | |
198 | #define OP_S_NEW_STREAM_UNI(stream_name, expect_id) \ | |
199 | {OPK_S_NEW_STREAM, NULL, 1, NULL, #stream_name, (expect_id)}, | |
a350db73 HL |
200 | #define OP_C_ACCEPT_STREAM_WAIT(stream_name) \ |
201 | {OPK_C_ACCEPT_STREAM_WAIT, NULL, 0, NULL, #stream_name}, | |
ed835673 HL |
202 | #define OP_C_ACCEPT_STREAM_NONE() \ |
203 | {OPK_C_ACCEPT_STREAM_NONE, NULL, 0, NULL, NULL}, | |
204 | #define OP_C_FREE_STREAM(stream_name) \ | |
205 | {OPK_C_FREE_STREAM, NULL, 0, NULL, #stream_name}, | |
206 | #define OP_C_SET_DEFAULT_STREAM_MODE(mode) \ | |
207 | {OPK_C_SET_DEFAULT_STREAM_MODE, NULL, (mode), NULL, NULL}, | |
83df44ae HL |
208 | #define OP_C_SET_INCOMING_STREAM_POLICY(policy) \ |
209 | {OPK_C_SET_INCOMING_STREAM_POLICY, NULL, (policy), NULL, NULL}, | |
cd5e4380 HL |
210 | #define OP_C_SHUTDOWN_WAIT() \ |
211 | {OPK_C_SHUTDOWN_WAIT, NULL, 0, NULL, NULL}, | |
ed835673 HL |
212 | #define OP_C_EXPECT_CONN_CLOSE_INFO(ec, app, remote) \ |
213 | {OPK_C_EXPECT_CONN_CLOSE_INFO, NULL, \ | |
214 | ((app) ? EXPECT_CONN_CLOSE_APP : 0) | \ | |
215 | ((remote) ? EXPECT_CONN_CLOSE_REMOTE : 0), \ | |
216 | NULL, NULL, (ec)}, | |
217 | #define OP_S_EXPECT_CONN_CLOSE_INFO(ec, app, remote) \ | |
218 | {OPK_S_EXPECT_CONN_CLOSE_INFO, NULL, \ | |
219 | ((app) ? EXPECT_CONN_CLOSE_APP : 0) | \ | |
220 | ((remote) ? EXPECT_CONN_CLOSE_REMOTE : 0), \ | |
221 | NULL, NULL, (ec)}, | |
222 | #define OP_S_BIND_STREAM_ID(stream_name, stream_id) \ | |
223 | {OPK_S_BIND_STREAM_ID, NULL, 0, NULL, #stream_name, (stream_id)}, | |
224 | #define OP_C_WAIT_FOR_DATA(stream_name) \ | |
225 | {OPK_C_WAIT_FOR_DATA, NULL, 0, NULL, #stream_name}, | |
226 | #define OP_C_WRITE_FAIL(stream_name) \ | |
227 | {OPK_C_WRITE_FAIL, NULL, 0, NULL, #stream_name}, | |
228 | #define OP_S_WRITE_FAIL(stream_name) \ | |
229 | {OPK_S_WRITE_FAIL, NULL, 0, NULL, #stream_name}, | |
230 | #define OP_C_READ_FAIL(stream_name) \ | |
231 | {OPK_C_READ_FAIL, NULL, 0, NULL, #stream_name}, | |
2f018d14 HL |
232 | #define OP_S_READ_FAIL(stream_name) \ |
233 | {OPK_S_READ_FAIL, NULL, 0, NULL, #stream_name}, | |
ed835673 HL |
234 | #define OP_C_STREAM_RESET(stream_name, aec) \ |
235 | {OPK_C_STREAM_RESET, NULL, 0, NULL, #stream_name, (aec)}, | |
a350db73 HL |
236 | #define OP_S_ACCEPT_STREAM_WAIT(stream_name) \ |
237 | {OPK_S_ACCEPT_STREAM_WAIT, NULL, 0, NULL, #stream_name}, | |
238 | #define OP_NEW_THREAD(num_threads, script) \ | |
fca44cfc HL |
239 | {OPK_NEW_THREAD, (script), (num_threads), NULL, NULL, 0 }, |
240 | #define OP_BEGIN_REPEAT(n) \ | |
241 | {OPK_BEGIN_REPEAT, NULL, (n)}, | |
242 | #define OP_END_REPEAT() \ | |
243 | {OPK_END_REPEAT}, | |
244 | #define OP_S_UNBIND_STREAM_ID(stream_name) \ | |
245 | {OPK_S_UNBIND_STREAM_ID, NULL, 0, NULL, #stream_name}, | |
0345cac6 TM |
246 | #define OP_C_READ_FAIL_WAIT(stream_name) \ |
247 | {OPK_C_READ_FAIL_WAIT, NULL, 0, NULL, #stream_name}, | |
248 | #define OP_C_CLOSE_SOCKET() \ | |
249 | {OPK_C_CLOSE_SOCKET}, | |
250 | #define OP_C_EXPECT_SSL_ERR(stream_name, err) \ | |
251 | {OPK_C_EXPECT_SSL_ERR, NULL, (err), NULL, #stream_name}, | |
252 | #define OP_EXPECT_ERR_REASON(err) \ | |
253 | {OPK_EXPECT_ERR_REASON, NULL, (err)}, | |
254 | #define OP_EXPECT_ERR_LIB(lib) \ | |
255 | {OPK_EXPECT_ERR_LIB, NULL, (lib)}, | |
256 | #define OP_SLEEP(ms) \ | |
257 | {OPK_SLEEP, NULL, 0, NULL, NULL, (ms)}, | |
e26dc8e3 HL |
258 | #define OP_S_SET_INJECT_PLAIN(f) \ |
259 | {OPK_S_SET_INJECT_PLAIN, NULL, 0, NULL, NULL, 0, (f)}, | |
260 | #define OP_SET_INJECT_WORD(w0, w1) \ | |
261 | {OPK_SET_INJECT_WORD, NULL, (w0), NULL, NULL, (w1), NULL}, | |
cd5e4380 HL |
262 | #define OP_C_INHIBIT_TICK(inhibit) \ |
263 | {OPK_C_INHIBIT_TICK, NULL, (inhibit), NULL, NULL, 0, NULL}, | |
264 | #define OP_C_SET_WRITE_BUF_SIZE(stream_name, size) \ | |
265 | {OPK_C_SET_WRITE_BUF_SIZE, NULL, (size), NULL, #stream_name}, | |
ed835673 | 266 | |
693b23e3 HL |
267 | static OSSL_TIME get_time(void *arg) |
268 | { | |
269 | struct helper *h = arg; | |
270 | OSSL_TIME t; | |
271 | ||
272 | if (!TEST_true(CRYPTO_THREAD_read_lock(h->time_lock))) | |
273 | return ossl_time_zero(); | |
274 | ||
275 | t = ossl_time_add(ossl_time_now(), h->time_slip); | |
276 | ||
277 | CRYPTO_THREAD_unlock(h->time_lock); | |
278 | return t; | |
279 | } | |
280 | ||
281 | static int skip_time_ms(struct helper *h, const struct script_op *op) | |
282 | { | |
283 | if (!TEST_true(CRYPTO_THREAD_write_lock(h->time_lock))) | |
284 | return 0; | |
285 | ||
286 | h->time_slip = ossl_time_add(h->time_slip, ossl_ms2time(op->arg2)); | |
287 | ||
288 | CRYPTO_THREAD_unlock(h->time_lock); | |
289 | return 1; | |
290 | } | |
291 | ||
ed835673 HL |
292 | static int check_rejected(struct helper *h, const struct script_op *op) |
293 | { | |
294 | uint64_t stream_id = op->arg2; | |
295 | ||
9715e3aa HL |
296 | if (!ossl_quic_tserver_stream_has_peer_stop_sending(h->s, stream_id, NULL) |
297 | || !ossl_quic_tserver_stream_has_peer_reset_stream(h->s, stream_id, NULL)) { | |
298 | h->check_spin_again = 1; | |
ed835673 | 299 | return 0; |
9715e3aa | 300 | } |
ed835673 HL |
301 | |
302 | return 1; | |
303 | } | |
304 | ||
305 | static int check_stream_reset(struct helper *h, const struct script_op *op) | |
306 | { | |
307 | uint64_t stream_id = op->arg2, aec = 0; | |
308 | ||
9715e3aa HL |
309 | if (!ossl_quic_tserver_stream_has_peer_reset_stream(h->s, stream_id, &aec)) { |
310 | h->check_spin_again = 1; | |
311 | return 0; | |
312 | } | |
313 | ||
314 | return TEST_uint64_t_eq(aec, 42); | |
ed835673 HL |
315 | } |
316 | ||
317 | static int check_stream_stopped(struct helper *h, const struct script_op *op) | |
318 | { | |
319 | uint64_t stream_id = op->arg2; | |
320 | ||
9715e3aa HL |
321 | if (!ossl_quic_tserver_stream_has_peer_stop_sending(h->s, stream_id, NULL)) { |
322 | h->check_spin_again = 1; | |
323 | return 0; | |
324 | } | |
325 | ||
326 | return 1; | |
ed835673 HL |
327 | } |
328 | ||
693b23e3 HL |
329 | static int override_key_update(struct helper *h, const struct script_op *op) |
330 | { | |
331 | QUIC_CHANNEL *ch = ossl_quic_conn_get_channel(h->c_conn); | |
332 | ||
333 | ossl_quic_channel_set_txku_threshold_override(ch, op->arg2); | |
334 | return 1; | |
335 | } | |
336 | ||
2525109f HL |
337 | static int trigger_key_update(struct helper *h, const struct script_op *op) |
338 | { | |
339 | if (!TEST_true(SSL_key_update(h->c_conn, SSL_KEY_UPDATE_REQUESTED))) | |
340 | return 0; | |
341 | ||
342 | return 1; | |
343 | } | |
344 | ||
693b23e3 HL |
345 | static int check_key_update_ge(struct helper *h, const struct script_op *op) |
346 | { | |
347 | QUIC_CHANNEL *ch = ossl_quic_conn_get_channel(h->c_conn); | |
348 | int64_t txke = (int64_t)ossl_quic_channel_get_tx_key_epoch(ch); | |
349 | int64_t rxke = (int64_t)ossl_quic_channel_get_rx_key_epoch(ch); | |
350 | int64_t diff = txke - rxke; | |
351 | ||
352 | /* | |
353 | * TXKE must always be equal to or ahead of RXKE. | |
354 | * It can be ahead of RXKE by at most 1. | |
355 | */ | |
356 | if (!TEST_int64_t_ge(diff, 0) || !TEST_int64_t_le(diff, 1)) | |
357 | return 0; | |
358 | ||
359 | /* Caller specifies a minimum number of RXKEs which must have happened. */ | |
360 | if (!TEST_uint64_t_ge((uint64_t)rxke, op->arg2)) | |
361 | return 0; | |
362 | ||
363 | return 1; | |
364 | } | |
365 | ||
366 | static int check_key_update_lt(struct helper *h, const struct script_op *op) | |
367 | { | |
368 | QUIC_CHANNEL *ch = ossl_quic_conn_get_channel(h->c_conn); | |
369 | uint64_t txke = ossl_quic_channel_get_tx_key_epoch(ch); | |
370 | ||
371 | /* Caller specifies a maximum number of TXKEs which must have happened. */ | |
372 | if (!TEST_uint64_t_lt(txke, op->arg2)) | |
373 | return 0; | |
374 | ||
375 | return 1; | |
376 | } | |
377 | ||
ed835673 HL |
378 | static unsigned long stream_info_hash(const STREAM_INFO *info) |
379 | { | |
380 | return OPENSSL_LH_strhash(info->name); | |
381 | } | |
382 | ||
383 | static int stream_info_cmp(const STREAM_INFO *a, const STREAM_INFO *b) | |
384 | { | |
385 | return strcmp(a->name, b->name); | |
386 | } | |
387 | ||
388 | static void cleanup_stream(STREAM_INFO *info) | |
389 | { | |
390 | SSL_free(info->c_stream); | |
391 | OPENSSL_free(info); | |
392 | } | |
393 | ||
394 | static void helper_cleanup_streams(LHASH_OF(STREAM_INFO) **lh) | |
395 | { | |
396 | if (*lh == NULL) | |
397 | return; | |
398 | ||
399 | lh_STREAM_INFO_doall(*lh, cleanup_stream); | |
400 | lh_STREAM_INFO_free(*lh); | |
401 | *lh = NULL; | |
402 | } | |
403 | ||
a350db73 HL |
404 | #if defined(OPENSSL_THREADS) |
405 | static CRYPTO_THREAD_RETVAL run_script_child_thread(void *arg); | |
406 | ||
407 | static int join_threads(struct child_thread_args *threads, size_t num_threads) | |
408 | { | |
409 | int ok = 1; | |
410 | size_t i; | |
411 | CRYPTO_THREAD_RETVAL rv; | |
412 | ||
413 | for (i = 0; i < num_threads; ++i) { | |
414 | if (threads[i].t != NULL) { | |
415 | ossl_crypto_thread_native_join(threads[i].t, &rv); | |
416 | ||
417 | if (!threads[i].testresult) | |
418 | /* Do not log failure here, worker will do it. */ | |
419 | ok = 0; | |
420 | ||
421 | ossl_crypto_thread_native_clean(threads[i].t); | |
422 | threads[i].t = NULL; | |
423 | } | |
424 | ||
425 | ossl_crypto_mutex_free(&threads[i].m); | |
426 | } | |
427 | ||
428 | return ok; | |
429 | } | |
430 | #endif | |
431 | ||
ed835673 HL |
432 | static void helper_cleanup(struct helper *h) |
433 | { | |
a350db73 HL |
434 | #if defined(OPENSSL_THREADS) |
435 | join_threads(h->threads, h->num_threads); | |
436 | OPENSSL_free(h->threads); | |
437 | h->threads = NULL; | |
438 | h->num_threads = 0; | |
439 | #endif | |
440 | ||
97f30fd5 HL |
441 | if (h->free_order == 0) { |
442 | /* order 0: streams, then conn */ | |
443 | helper_cleanup_streams(&h->c_streams); | |
444 | ||
445 | SSL_free(h->c_conn); | |
446 | h->c_conn = NULL; | |
447 | } else { | |
448 | /* order 1: conn, then streams */ | |
449 | SSL_free(h->c_conn); | |
450 | h->c_conn = NULL; | |
451 | ||
452 | helper_cleanup_streams(&h->c_streams); | |
453 | } | |
ed835673 | 454 | |
97f30fd5 | 455 | helper_cleanup_streams(&h->s_streams); |
ed835673 HL |
456 | ossl_quic_tserver_free(h->s); |
457 | h->s = NULL; | |
458 | ||
459 | BIO_free(h->s_net_bio_own); | |
460 | h->s_net_bio_own = NULL; | |
461 | ||
462 | BIO_free(h->c_net_bio_own); | |
463 | h->c_net_bio_own = NULL; | |
464 | ||
e26dc8e3 HL |
465 | BIO_free(h->s_qtf_wbio_own); |
466 | h->s_qtf_wbio_own = NULL; | |
467 | ||
1d547f8f HL |
468 | qtest_fault_free(h->qtf); |
469 | h->qtf = NULL; | |
7eebc354 | 470 | |
ed835673 HL |
471 | if (h->s_fd >= 0) { |
472 | BIO_closesocket(h->s_fd); | |
473 | h->s_fd = -1; | |
474 | } | |
475 | ||
476 | if (h->c_fd >= 0) { | |
477 | BIO_closesocket(h->c_fd); | |
478 | h->c_fd = -1; | |
479 | } | |
480 | ||
481 | BIO_ADDR_free(h->s_net_bio_addr); | |
482 | h->s_net_bio_addr = NULL; | |
483 | ||
484 | SSL_CTX_free(h->c_ctx); | |
485 | h->c_ctx = NULL; | |
693b23e3 HL |
486 | |
487 | CRYPTO_THREAD_lock_free(h->time_lock); | |
488 | h->time_lock = NULL; | |
ed835673 HL |
489 | } |
490 | ||
e26dc8e3 | 491 | static int helper_init(struct helper *h, int free_order, int need_injector) |
ed835673 HL |
492 | { |
493 | short port = 8186; | |
494 | struct in_addr ina = {0}; | |
495 | QUIC_TSERVER_ARGS s_args = {0}; | |
496 | ||
497 | memset(h, 0, sizeof(*h)); | |
498 | h->c_fd = -1; | |
499 | h->s_fd = -1; | |
97f30fd5 | 500 | h->free_order = free_order; |
e26dc8e3 | 501 | h->need_injector = need_injector; |
693b23e3 HL |
502 | h->time_slip = ossl_time_zero(); |
503 | ||
504 | if (!TEST_ptr(h->time_lock = CRYPTO_THREAD_lock_new())) | |
505 | goto err; | |
ed835673 HL |
506 | |
507 | if (!TEST_ptr(h->s_streams = lh_STREAM_INFO_new(stream_info_hash, | |
508 | stream_info_cmp))) | |
509 | goto err; | |
510 | ||
511 | if (!TEST_ptr(h->c_streams = lh_STREAM_INFO_new(stream_info_hash, | |
512 | stream_info_cmp))) | |
513 | goto err; | |
514 | ||
515 | ina.s_addr = htonl(0x7f000001UL); | |
516 | ||
517 | h->s_fd = BIO_socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP, 0); | |
518 | if (!TEST_int_ge(h->s_fd, 0)) | |
519 | goto err; | |
520 | ||
521 | if (!TEST_true(BIO_socket_nbio(h->s_fd, 1))) | |
522 | goto err; | |
523 | ||
524 | if (!TEST_ptr(h->s_net_bio_addr = BIO_ADDR_new())) | |
525 | goto err; | |
526 | ||
527 | if (!TEST_true(BIO_ADDR_rawmake(h->s_net_bio_addr, AF_INET, &ina, sizeof(ina), | |
528 | htons(port)))) | |
529 | goto err; | |
530 | ||
531 | if (!TEST_true(BIO_bind(h->s_fd, h->s_net_bio_addr, 0))) | |
532 | goto err; | |
533 | ||
534 | if (!TEST_int_gt(BIO_ADDR_rawport(h->s_net_bio_addr), 0)) | |
535 | goto err; | |
536 | ||
537 | if (!TEST_ptr(h->s_net_bio = h->s_net_bio_own = BIO_new_dgram(h->s_fd, 0))) | |
538 | goto err; | |
539 | ||
540 | if (!BIO_up_ref(h->s_net_bio)) | |
541 | goto err; | |
542 | ||
e26dc8e3 HL |
543 | if (need_injector) { |
544 | h->s_qtf_wbio = h->s_qtf_wbio_own = BIO_new(qtest_get_bio_method()); | |
545 | if (!TEST_ptr(h->s_qtf_wbio)) | |
546 | goto err; | |
547 | ||
548 | if (!TEST_ptr(BIO_push(h->s_qtf_wbio, h->s_net_bio))) | |
549 | goto err; | |
550 | ||
551 | s_args.net_wbio = h->s_qtf_wbio; | |
552 | } else { | |
553 | s_args.net_wbio = h->s_net_bio; | |
554 | } | |
555 | ||
693b23e3 | 556 | s_args.net_rbio = h->s_net_bio; |
37f27b91 | 557 | s_args.alpn = NULL; |
693b23e3 HL |
558 | s_args.now_cb = get_time; |
559 | s_args.now_cb_arg = h; | |
829eec9f | 560 | s_args.ctx = NULL; |
ed835673 HL |
561 | |
562 | if (!TEST_ptr(h->s = ossl_quic_tserver_new(&s_args, certfile, keyfile))) | |
563 | goto err; | |
564 | ||
e26dc8e3 HL |
565 | if (need_injector) { |
566 | h->qtf = qtest_create_injector(h->s); | |
567 | if (!TEST_ptr(h->qtf)) | |
568 | goto err; | |
569 | ||
570 | BIO_set_data(h->s_qtf_wbio, h->qtf); | |
571 | } | |
572 | ||
7eebc354 HL |
573 | if (!need_injector) |
574 | h->s_net_bio_own = NULL; | |
575 | ||
e26dc8e3 | 576 | h->s_qtf_wbio_own = NULL; |
ed835673 HL |
577 | |
578 | h->c_fd = BIO_socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP, 0); | |
579 | if (!TEST_int_ge(h->c_fd, 0)) | |
580 | goto err; | |
581 | ||
582 | if (!TEST_true(BIO_socket_nbio(h->c_fd, 1))) | |
583 | goto err; | |
584 | ||
585 | if (!TEST_ptr(h->c_net_bio = h->c_net_bio_own = BIO_new_dgram(h->c_fd, 0))) | |
586 | goto err; | |
587 | ||
588 | if (!TEST_true(BIO_dgram_set_peer(h->c_net_bio, h->s_net_bio_addr))) | |
589 | goto err; | |
590 | ||
ed835673 HL |
591 | if (!TEST_ptr(h->c_ctx = SSL_CTX_new(OSSL_QUIC_client_method()))) |
592 | goto err; | |
593 | ||
594 | if (!TEST_ptr(h->c_conn = SSL_new(h->c_ctx))) | |
595 | goto err; | |
596 | ||
693b23e3 HL |
597 | /* Use custom time function for virtual time skip. */ |
598 | if (!TEST_true(ossl_quic_conn_set_override_now_cb(h->c_conn, get_time, h))) | |
599 | goto err; | |
600 | ||
ed835673 HL |
601 | /* Takes ownership of our reference to the BIO. */ |
602 | SSL_set0_rbio(h->c_conn, h->c_net_bio); | |
603 | h->c_net_bio_own = NULL; | |
604 | ||
605 | if (!TEST_true(BIO_up_ref(h->c_net_bio))) | |
606 | goto err; | |
607 | ||
608 | SSL_set0_wbio(h->c_conn, h->c_net_bio); | |
609 | ||
610 | if (!TEST_true(SSL_set_blocking_mode(h->c_conn, 0))) | |
611 | goto err; | |
612 | ||
613 | h->start_time = ossl_time_now(); | |
614 | h->init = 1; | |
615 | return 1; | |
616 | ||
617 | err: | |
618 | helper_cleanup(h); | |
619 | return 0; | |
620 | } | |
621 | ||
a350db73 HL |
622 | static int helper_local_init(struct helper_local *hl, struct helper *h, |
623 | int thread_idx) | |
624 | { | |
625 | hl->h = h; | |
626 | hl->c_streams = NULL; | |
627 | hl->thread_idx = thread_idx; | |
628 | ||
629 | if (!TEST_ptr(h)) | |
630 | return 0; | |
631 | ||
632 | if (thread_idx < 0) { | |
633 | hl->c_streams = h->c_streams; | |
634 | } else { | |
635 | if (!TEST_ptr(hl->c_streams = lh_STREAM_INFO_new(stream_info_hash, | |
636 | stream_info_cmp))) | |
637 | return 0; | |
638 | } | |
639 | ||
640 | return 1; | |
641 | } | |
642 | ||
643 | static void helper_local_cleanup(struct helper_local *hl) | |
644 | { | |
645 | if (hl->h == NULL) | |
646 | return; | |
647 | ||
648 | if (hl->thread_idx >= 0) | |
649 | helper_cleanup_streams(&hl->c_streams); | |
650 | ||
651 | hl->h = NULL; | |
652 | } | |
653 | ||
ed835673 HL |
654 | static STREAM_INFO *get_stream_info(LHASH_OF(STREAM_INFO) *lh, |
655 | const char *stream_name) | |
656 | { | |
657 | STREAM_INFO key, *info; | |
658 | ||
659 | if (!TEST_ptr(stream_name)) | |
660 | return NULL; | |
661 | ||
662 | if (!strcmp(stream_name, "DEFAULT")) | |
663 | return NULL; | |
664 | ||
665 | key.name = stream_name; | |
666 | info = lh_STREAM_INFO_retrieve(lh, &key); | |
667 | if (info == NULL) { | |
668 | info = OPENSSL_zalloc(sizeof(*info)); | |
669 | if (info == NULL) | |
670 | return NULL; | |
671 | ||
672 | info->name = stream_name; | |
673 | info->s_stream_id = UINT64_MAX; | |
674 | lh_STREAM_INFO_insert(lh, info); | |
675 | } | |
676 | ||
677 | return info; | |
678 | } | |
679 | ||
a350db73 HL |
680 | static int helper_local_set_c_stream(struct helper_local *hl, |
681 | const char *stream_name, | |
682 | SSL *c_stream) | |
ed835673 | 683 | { |
a350db73 | 684 | STREAM_INFO *info = get_stream_info(hl->c_streams, stream_name); |
ed835673 HL |
685 | |
686 | if (info == NULL) | |
687 | return 0; | |
688 | ||
689 | info->c_stream = c_stream; | |
690 | info->s_stream_id = UINT64_MAX; | |
691 | return 1; | |
692 | } | |
693 | ||
a350db73 HL |
694 | static SSL *helper_local_get_c_stream(struct helper_local *hl, |
695 | const char *stream_name) | |
ed835673 HL |
696 | { |
697 | STREAM_INFO *info; | |
698 | ||
699 | if (!strcmp(stream_name, "DEFAULT")) | |
a350db73 | 700 | return hl->h->c_conn; |
ed835673 | 701 | |
a350db73 | 702 | info = get_stream_info(hl->c_streams, stream_name); |
ed835673 HL |
703 | if (info == NULL) |
704 | return NULL; | |
705 | ||
706 | return info->c_stream; | |
707 | } | |
708 | ||
709 | static int | |
710 | helper_set_s_stream(struct helper *h, const char *stream_name, | |
711 | uint64_t s_stream_id) | |
712 | { | |
713 | STREAM_INFO *info; | |
714 | ||
715 | if (!strcmp(stream_name, "DEFAULT")) | |
716 | return 0; | |
717 | ||
718 | info = get_stream_info(h->s_streams, stream_name); | |
719 | if (info == NULL) | |
720 | return 0; | |
721 | ||
722 | info->c_stream = NULL; | |
723 | info->s_stream_id = s_stream_id; | |
724 | return 1; | |
725 | } | |
726 | ||
727 | static uint64_t helper_get_s_stream(struct helper *h, const char *stream_name) | |
728 | { | |
729 | STREAM_INFO *info; | |
730 | ||
731 | if (!strcmp(stream_name, "DEFAULT")) | |
732 | return UINT64_MAX; | |
733 | ||
734 | info = get_stream_info(h->s_streams, stream_name); | |
735 | if (info == NULL) | |
736 | return UINT64_MAX; | |
737 | ||
738 | return info->s_stream_id; | |
739 | } | |
740 | ||
e26dc8e3 HL |
741 | static int helper_packet_plain_listener(QTEST_FAULT *qtf, QUIC_PKT_HDR *hdr, |
742 | unsigned char *buf, size_t buf_len, | |
743 | void *arg) | |
744 | { | |
745 | struct helper *h = arg; | |
746 | ||
747 | return h->qtf_packet_plain_cb(h, hdr, buf, buf_len); | |
748 | } | |
749 | ||
ed835673 HL |
750 | static int is_want(SSL *s, int ret) |
751 | { | |
752 | int ec = SSL_get_error(s, ret); | |
753 | ||
754 | return ec == SSL_ERROR_WANT_READ || ec == SSL_ERROR_WANT_WRITE; | |
755 | } | |
756 | ||
a350db73 | 757 | static int run_script_worker(struct helper *h, const struct script_op *script, |
0786483a | 758 | const char *script_name, |
a350db73 | 759 | int thread_idx) |
ed835673 | 760 | { |
ed835673 | 761 | int testresult = 0; |
ed835673 HL |
762 | unsigned char *tmp_buf = NULL; |
763 | int connect_started = 0; | |
9715e3aa | 764 | size_t offset = 0; |
a350db73 HL |
765 | size_t op_idx = 0; |
766 | const struct script_op *op = NULL; | |
629b408c HL |
767 | int no_advance = 0, first = 1; |
768 | #if defined(OPENSSL_THREADS) | |
769 | int end_wait_warning = 0; | |
770 | #endif | |
a350db73 HL |
771 | OSSL_TIME op_start_time = ossl_time_zero(), op_deadline = ossl_time_zero(); |
772 | struct helper_local hl; | |
fca44cfc HL |
773 | #define REPEAT_SLOTS 8 |
774 | size_t repeat_stack_idx[REPEAT_SLOTS], repeat_stack_done[REPEAT_SLOTS]; | |
775 | size_t repeat_stack_limit[REPEAT_SLOTS]; | |
776 | size_t repeat_stack_len = 0; | |
ed835673 | 777 | |
a350db73 | 778 | if (!TEST_true(helper_local_init(&hl, h, thread_idx))) |
ed835673 HL |
779 | goto out; |
780 | ||
2525109f | 781 | #define SPIN_AGAIN() { OSSL_sleep(1); no_advance = 1; continue; } |
ed835673 | 782 | |
9715e3aa | 783 | for (;;) { |
a350db73 | 784 | SSL *c_tgt = h->c_conn; |
ed835673 HL |
785 | uint64_t s_stream_id = UINT64_MAX; |
786 | ||
9715e3aa HL |
787 | if (no_advance) { |
788 | no_advance = 0; | |
789 | } else { | |
790 | if (!first) | |
791 | ++op_idx; | |
792 | ||
793 | first = 0; | |
4f2d32d6 | 794 | offset = 0; |
9715e3aa | 795 | op_start_time = ossl_time_now(); |
cd5e4380 | 796 | op_deadline = ossl_time_add(op_start_time, ossl_ms2time(8000)); |
9715e3aa HL |
797 | } |
798 | ||
799 | if (!TEST_int_le(ossl_time_compare(ossl_time_now(), op_deadline), 0)) { | |
a350db73 | 800 | TEST_error("op %zu timed out on thread %d", op_idx + 1, thread_idx); |
9715e3aa HL |
801 | goto out; |
802 | } | |
803 | ||
ed835673 HL |
804 | op = &script[op_idx]; |
805 | ||
806 | if (op->stream_name != NULL) { | |
a350db73 HL |
807 | c_tgt = helper_local_get_c_stream(&hl, op->stream_name); |
808 | if (thread_idx < 0) | |
809 | s_stream_id = helper_get_s_stream(h, op->stream_name); | |
810 | else | |
811 | s_stream_id = UINT64_MAX; | |
812 | } | |
813 | ||
7ba8f79a | 814 | if (thread_idx < 0) |
a350db73 | 815 | ossl_quic_tserver_tick(h->s); |
7ba8f79a HL |
816 | |
817 | if (thread_idx >= 0 || connect_started) | |
6084e04b | 818 | SSL_handle_events(h->c_conn); |
ed835673 | 819 | |
a350db73 HL |
820 | if (thread_idx >= 0) { |
821 | /* Only allow certain opcodes on child threads. */ | |
822 | switch (op->op) { | |
823 | case OPK_END: | |
824 | case OPK_C_ACCEPT_STREAM_WAIT: | |
825 | case OPK_C_NEW_STREAM: | |
826 | case OPK_C_READ_EXPECT: | |
827 | case OPK_C_EXPECT_FIN: | |
828 | case OPK_C_WRITE: | |
829 | case OPK_C_CONCLUDE: | |
830 | case OPK_C_FREE_STREAM: | |
fca44cfc HL |
831 | case OPK_BEGIN_REPEAT: |
832 | case OPK_END_REPEAT: | |
0345cac6 TM |
833 | case OPK_C_READ_FAIL_WAIT: |
834 | case OPK_C_EXPECT_SSL_ERR: | |
835 | case OPK_EXPECT_ERR_REASON: | |
836 | case OPK_EXPECT_ERR_LIB: | |
837 | case OPK_SLEEP: | |
a350db73 HL |
838 | break; |
839 | ||
840 | default: | |
0cea6df2 MC |
841 | TEST_error("opcode %lu not allowed on child thread", |
842 | (unsigned long)op->op); | |
a350db73 HL |
843 | goto out; |
844 | } | |
845 | } | |
ed835673 HL |
846 | |
847 | switch (op->op) { | |
848 | case OPK_END: | |
fca44cfc HL |
849 | if (!TEST_size_t_eq(repeat_stack_len, 0)) |
850 | goto out; | |
851 | ||
629b408c | 852 | #if defined(OPENSSL_THREADS) |
a350db73 HL |
853 | if (thread_idx < 0) { |
854 | int done; | |
855 | size_t i; | |
856 | ||
857 | for (i = 0; i < h->num_threads; ++i) { | |
858 | if (h->threads[i].m == NULL) | |
859 | continue; | |
860 | ||
861 | ossl_crypto_mutex_lock(h->threads[i].m); | |
862 | done = h->threads[i].done; | |
863 | ossl_crypto_mutex_unlock(h->threads[i].m); | |
864 | ||
865 | if (!done) { | |
866 | if (!end_wait_warning) { | |
867 | TEST_info("still waiting for other threads to finish (%zu)", i); | |
868 | end_wait_warning = 1; | |
869 | } | |
870 | ||
871 | SPIN_AGAIN(); | |
872 | } | |
873 | } | |
874 | } | |
629b408c | 875 | #endif |
a350db73 | 876 | |
0786483a | 877 | TEST_info("script \"%s\" finished on thread %d", script_name, thread_idx); |
ed835673 HL |
878 | testresult = 1; |
879 | goto out; | |
880 | ||
fca44cfc HL |
881 | case OPK_BEGIN_REPEAT: |
882 | if (!TEST_size_t_lt(repeat_stack_len, OSSL_NELEM(repeat_stack_idx))) | |
883 | goto out; | |
884 | ||
885 | if (!TEST_size_t_gt(op->arg1, 0)) | |
886 | goto out; | |
887 | ||
888 | repeat_stack_idx[repeat_stack_len] = op_idx + 1; | |
889 | repeat_stack_done[repeat_stack_len] = 0; | |
890 | repeat_stack_limit[repeat_stack_len] = op->arg1; | |
891 | ++repeat_stack_len; | |
892 | break; | |
893 | ||
894 | case OPK_END_REPEAT: | |
895 | if (!TEST_size_t_gt(repeat_stack_len, 0)) | |
896 | goto out; | |
897 | ||
898 | if (++repeat_stack_done[repeat_stack_len - 1] | |
899 | == repeat_stack_limit[repeat_stack_len - 1]) { | |
900 | --repeat_stack_len; | |
901 | } else { | |
902 | op_idx = repeat_stack_idx[repeat_stack_len - 1]; | |
903 | no_advance = 1; | |
904 | continue; | |
905 | } | |
906 | ||
907 | break; | |
908 | ||
ed835673 | 909 | case OPK_CHECK: |
9715e3aa | 910 | { |
a350db73 HL |
911 | int ok = op->check_func(h, op); |
912 | if (h->check_spin_again) { | |
913 | h->check_spin_again = 0; | |
9715e3aa HL |
914 | SPIN_AGAIN(); |
915 | } | |
ed835673 | 916 | |
9715e3aa HL |
917 | if (!TEST_true(ok)) |
918 | goto out; | |
919 | } | |
ed835673 HL |
920 | break; |
921 | ||
922 | case OPK_C_SET_ALPN: | |
923 | { | |
924 | const char *alpn = op->arg0; | |
925 | size_t alpn_len = strlen(alpn); | |
926 | ||
927 | if (!TEST_size_t_le(alpn_len, UINT8_MAX) | |
928 | || !TEST_ptr(tmp_buf = (unsigned char *)OPENSSL_malloc(alpn_len + 1))) | |
929 | goto out; | |
930 | ||
931 | memcpy(tmp_buf + 1, alpn, alpn_len); | |
932 | tmp_buf[0] = (unsigned char)alpn_len; | |
933 | ||
934 | /* 0 is the success case for SSL_set_alpn_protos(). */ | |
a350db73 | 935 | if (!TEST_false(SSL_set_alpn_protos(h->c_conn, tmp_buf, |
ed835673 HL |
936 | alpn_len + 1))) |
937 | goto out; | |
938 | ||
939 | OPENSSL_free(tmp_buf); | |
940 | tmp_buf = NULL; | |
941 | } | |
942 | break; | |
943 | ||
944 | case OPK_C_CONNECT_WAIT: | |
945 | { | |
946 | int ret; | |
947 | ||
948 | connect_started = 1; | |
949 | ||
a350db73 | 950 | ret = SSL_connect(h->c_conn); |
e26dc8e3 | 951 | if (!TEST_true((ret == 1 || op->arg1 > 0) |
a350db73 | 952 | || (!h->blocking && is_want(h->c_conn, ret)))) |
ed835673 HL |
953 | goto out; |
954 | ||
e26dc8e3 | 955 | if (!h->blocking && ret < 0) |
ed835673 HL |
956 | SPIN_AGAIN(); |
957 | } | |
958 | break; | |
959 | ||
960 | case OPK_C_WRITE: | |
961 | { | |
962 | size_t bytes_written = 0; | |
963 | ||
964 | if (!TEST_ptr(c_tgt)) | |
965 | goto out; | |
966 | ||
967 | if (!TEST_true(SSL_write_ex(c_tgt, op->arg0, op->arg1, | |
968 | &bytes_written)) | |
969 | || !TEST_size_t_eq(bytes_written, op->arg1)) | |
970 | goto out; | |
971 | } | |
972 | break; | |
973 | ||
974 | case OPK_S_WRITE: | |
975 | { | |
976 | size_t bytes_written = 0; | |
977 | ||
978 | if (!TEST_uint64_t_ne(s_stream_id, UINT64_MAX)) | |
979 | goto out; | |
980 | ||
a350db73 | 981 | if (!TEST_true(ossl_quic_tserver_write(h->s, s_stream_id, |
ed835673 HL |
982 | op->arg0, op->arg1, |
983 | &bytes_written)) | |
984 | || !TEST_size_t_eq(bytes_written, op->arg1)) | |
985 | goto out; | |
986 | } | |
987 | break; | |
988 | ||
989 | case OPK_C_CONCLUDE: | |
990 | { | |
991 | if (!TEST_true(SSL_stream_conclude(c_tgt, 0))) | |
992 | goto out; | |
993 | } | |
994 | break; | |
995 | ||
996 | case OPK_S_CONCLUDE: | |
997 | { | |
998 | if (!TEST_uint64_t_ne(s_stream_id, UINT64_MAX)) | |
999 | goto out; | |
1000 | ||
a350db73 | 1001 | ossl_quic_tserver_conclude(h->s, s_stream_id); |
ed835673 HL |
1002 | } |
1003 | break; | |
1004 | ||
1005 | case OPK_C_WAIT_FOR_DATA: | |
1006 | { | |
1007 | char buf[1]; | |
1008 | size_t bytes_read = 0; | |
1009 | ||
1010 | if (!TEST_ptr(c_tgt)) | |
1011 | goto out; | |
1012 | ||
1013 | if (!SSL_peek_ex(c_tgt, buf, sizeof(buf), &bytes_read) | |
1014 | || bytes_read == 0) | |
1015 | SPIN_AGAIN(); | |
1016 | } | |
1017 | break; | |
1018 | ||
1019 | case OPK_C_READ_EXPECT: | |
1020 | { | |
1021 | size_t bytes_read = 0; | |
1022 | ||
9715e3aa HL |
1023 | if (op->arg1 > 0 && tmp_buf == NULL |
1024 | && !TEST_ptr(tmp_buf = OPENSSL_malloc(op->arg1))) | |
ed835673 HL |
1025 | goto out; |
1026 | ||
9715e3aa HL |
1027 | if (!SSL_read_ex(c_tgt, tmp_buf + offset, op->arg1 - offset, |
1028 | &bytes_read)) | |
1029 | SPIN_AGAIN(); | |
ed835673 | 1030 | |
9715e3aa HL |
1031 | if (bytes_read + offset != op->arg1) { |
1032 | offset += bytes_read; | |
1033 | SPIN_AGAIN(); | |
1034 | } | |
1035 | ||
1036 | if (op->arg1 > 0 | |
1037 | && !TEST_mem_eq(tmp_buf, op->arg1, op->arg0, op->arg1)) | |
ed835673 HL |
1038 | goto out; |
1039 | ||
1040 | OPENSSL_free(tmp_buf); | |
1041 | tmp_buf = NULL; | |
1042 | } | |
1043 | break; | |
1044 | ||
1045 | case OPK_S_READ_EXPECT: | |
1046 | { | |
1047 | size_t bytes_read = 0; | |
1048 | ||
1049 | if (!TEST_uint64_t_ne(s_stream_id, UINT64_MAX)) | |
1050 | goto out; | |
1051 | ||
9715e3aa | 1052 | if (op->arg1 > 0 && tmp_buf == NULL |
ed835673 HL |
1053 | && !TEST_ptr(tmp_buf = OPENSSL_malloc(op->arg1))) |
1054 | goto out; | |
1055 | ||
a350db73 | 1056 | if (!TEST_true(ossl_quic_tserver_read(h->s, s_stream_id, |
9715e3aa HL |
1057 | tmp_buf + offset, |
1058 | op->arg1 - offset, | |
1059 | &bytes_read))) | |
ed835673 HL |
1060 | goto out; |
1061 | ||
9715e3aa HL |
1062 | if (bytes_read + offset != op->arg1) { |
1063 | offset += bytes_read; | |
1064 | SPIN_AGAIN(); | |
1065 | } | |
1066 | ||
ed835673 HL |
1067 | if (op->arg1 > 0 |
1068 | && !TEST_mem_eq(tmp_buf, op->arg1, op->arg0, op->arg1)) | |
1069 | goto out; | |
1070 | ||
1071 | OPENSSL_free(tmp_buf); | |
1072 | tmp_buf = NULL; | |
1073 | } | |
1074 | break; | |
1075 | ||
1076 | case OPK_C_EXPECT_FIN: | |
1077 | { | |
1078 | char buf[1]; | |
1079 | size_t bytes_read = 0; | |
1080 | ||
1081 | if (!TEST_false(SSL_read_ex(c_tgt, buf, sizeof(buf), | |
1082 | &bytes_read)) | |
9715e3aa HL |
1083 | || !TEST_size_t_eq(bytes_read, 0)) |
1084 | goto out; | |
1085 | ||
1086 | if (is_want(c_tgt, 0)) | |
1087 | SPIN_AGAIN(); | |
1088 | ||
1089 | if (!TEST_int_eq(SSL_get_error(c_tgt, 0), | |
1090 | SSL_ERROR_ZERO_RETURN)) | |
1091 | goto out; | |
ed835673 HL |
1092 | } |
1093 | break; | |
1094 | ||
1095 | case OPK_S_EXPECT_FIN: | |
1096 | { | |
9715e3aa | 1097 | if (!TEST_uint64_t_ne(s_stream_id, UINT64_MAX)) |
ed835673 | 1098 | goto out; |
9715e3aa | 1099 | |
a350db73 | 1100 | if (!ossl_quic_tserver_has_read_ended(h->s, s_stream_id)) |
9715e3aa | 1101 | SPIN_AGAIN(); |
ed835673 HL |
1102 | } |
1103 | break; | |
1104 | ||
1105 | case OPK_C_DETACH: | |
1106 | { | |
1107 | SSL *c_stream; | |
1108 | ||
1109 | if (!TEST_ptr_null(c_tgt)) | |
1110 | goto out; /* don't overwrite existing stream with same name */ | |
1111 | ||
a350db73 | 1112 | if (!TEST_ptr(c_stream = ossl_quic_detach_stream(h->c_conn))) |
ed835673 HL |
1113 | goto out; |
1114 | ||
a350db73 | 1115 | if (!TEST_true(helper_local_set_c_stream(&hl, op->stream_name, c_stream))) |
ed835673 HL |
1116 | goto out; |
1117 | } | |
1118 | break; | |
1119 | ||
1120 | case OPK_C_ATTACH: | |
1121 | { | |
1122 | if (!TEST_ptr(c_tgt)) | |
1123 | goto out; | |
1124 | ||
a350db73 | 1125 | if (!TEST_true(ossl_quic_attach_stream(h->c_conn, c_tgt))) |
ed835673 HL |
1126 | goto out; |
1127 | ||
a350db73 | 1128 | if (!TEST_true(helper_local_set_c_stream(&hl, op->stream_name, NULL))) |
ed835673 HL |
1129 | goto out; |
1130 | } | |
1131 | break; | |
1132 | ||
1133 | case OPK_C_NEW_STREAM: | |
1134 | { | |
1135 | SSL *c_stream; | |
1136 | uint64_t flags = 0; | |
1137 | ||
1138 | if (!TEST_ptr_null(c_tgt)) | |
1139 | goto out; /* don't overwrite existing stream with same name */ | |
1140 | ||
1141 | if (op->arg1 != 0) | |
1142 | flags |= SSL_STREAM_FLAG_UNI; | |
1143 | ||
a350db73 | 1144 | if (!TEST_ptr(c_stream = SSL_new_stream(h->c_conn, flags))) |
ed835673 HL |
1145 | goto out; |
1146 | ||
1147 | if (op->arg2 != UINT64_MAX | |
1148 | && !TEST_uint64_t_eq(SSL_get_stream_id(c_stream), | |
1149 | op->arg2)) | |
1150 | goto out; | |
1151 | ||
a350db73 | 1152 | if (!TEST_true(helper_local_set_c_stream(&hl, op->stream_name, c_stream))) |
ed835673 HL |
1153 | goto out; |
1154 | } | |
1155 | break; | |
1156 | ||
1157 | case OPK_S_NEW_STREAM: | |
1158 | { | |
1159 | uint64_t stream_id = UINT64_MAX; | |
1160 | ||
1161 | if (!TEST_uint64_t_eq(s_stream_id, UINT64_MAX)) | |
1162 | goto out; /* don't overwrite existing stream with same name */ | |
1163 | ||
a350db73 | 1164 | if (!TEST_true(ossl_quic_tserver_stream_new(h->s, |
ed835673 HL |
1165 | op->arg1 > 0, |
1166 | &stream_id))) | |
1167 | goto out; | |
1168 | ||
1169 | if (op->arg2 != UINT64_MAX | |
1170 | && !TEST_uint64_t_eq(stream_id, op->arg2)) | |
1171 | goto out; | |
1172 | ||
a350db73 | 1173 | if (!TEST_true(helper_set_s_stream(h, op->stream_name, |
ed835673 HL |
1174 | stream_id))) |
1175 | goto out; | |
1176 | } | |
1177 | break; | |
1178 | ||
a350db73 | 1179 | case OPK_C_ACCEPT_STREAM_WAIT: |
ed835673 HL |
1180 | { |
1181 | SSL *c_stream; | |
1182 | ||
1183 | if (!TEST_ptr_null(c_tgt)) | |
1184 | goto out; /* don't overwrite existing stream with same name */ | |
1185 | ||
a350db73 | 1186 | if ((c_stream = SSL_accept_stream(h->c_conn, 0)) == NULL) |
9715e3aa | 1187 | SPIN_AGAIN(); |
ed835673 | 1188 | |
a350db73 HL |
1189 | if (!TEST_true(helper_local_set_c_stream(&hl, op->stream_name, |
1190 | c_stream))) | |
1191 | goto out; | |
1192 | } | |
1193 | break; | |
1194 | ||
1195 | case OPK_S_ACCEPT_STREAM_WAIT: | |
1196 | { | |
1197 | uint64_t new_stream_id; | |
1198 | ||
1199 | if (!TEST_uint64_t_eq(s_stream_id, UINT64_MAX)) | |
1200 | goto out; | |
1201 | ||
1202 | new_stream_id = ossl_quic_tserver_pop_incoming_stream(h->s); | |
1203 | if (new_stream_id == UINT64_MAX) | |
1204 | SPIN_AGAIN(); | |
1205 | ||
1206 | if (!TEST_true(helper_set_s_stream(h, op->stream_name, new_stream_id))) | |
ed835673 HL |
1207 | goto out; |
1208 | } | |
1209 | break; | |
1210 | ||
1211 | case OPK_C_ACCEPT_STREAM_NONE: | |
1212 | { | |
1213 | SSL *c_stream; | |
1214 | ||
a350db73 | 1215 | if (!TEST_ptr_null(c_stream = SSL_accept_stream(h->c_conn, 0))) { |
ed835673 HL |
1216 | SSL_free(c_stream); |
1217 | goto out; | |
1218 | } | |
1219 | } | |
1220 | break; | |
1221 | ||
1222 | case OPK_C_FREE_STREAM: | |
1223 | { | |
1224 | if (!TEST_ptr(c_tgt) | |
1225 | || !TEST_true(!SSL_is_connection(c_tgt))) | |
1226 | goto out; | |
1227 | ||
a350db73 | 1228 | if (!TEST_true(helper_local_set_c_stream(&hl, op->stream_name, NULL))) |
ed835673 HL |
1229 | goto out; |
1230 | ||
1231 | SSL_free(c_tgt); | |
1232 | c_tgt = NULL; | |
1233 | } | |
1234 | break; | |
1235 | ||
1236 | case OPK_C_SET_DEFAULT_STREAM_MODE: | |
1237 | { | |
1238 | if (!TEST_ptr(c_tgt)) | |
1239 | goto out; | |
1240 | ||
1241 | if (!TEST_true(SSL_set_default_stream_mode(c_tgt, op->arg1))) | |
1242 | goto out; | |
1243 | } | |
1244 | break; | |
1245 | ||
83df44ae | 1246 | case OPK_C_SET_INCOMING_STREAM_POLICY: |
ed835673 HL |
1247 | { |
1248 | if (!TEST_ptr(c_tgt)) | |
1249 | goto out; | |
1250 | ||
83df44ae HL |
1251 | if (!TEST_true(SSL_set_incoming_stream_policy(c_tgt, |
1252 | op->arg1, 0))) | |
ed835673 HL |
1253 | goto out; |
1254 | } | |
1255 | break; | |
1256 | ||
cd5e4380 | 1257 | case OPK_C_SHUTDOWN_WAIT: |
ed835673 HL |
1258 | { |
1259 | int ret; | |
cd5e4380 HL |
1260 | QUIC_CHANNEL *ch = ossl_quic_conn_get_channel(h->c_conn); |
1261 | ||
1262 | ossl_quic_channel_set_inhibit_tick(ch, 0); | |
ed835673 HL |
1263 | |
1264 | if (!TEST_ptr(c_tgt)) | |
1265 | goto out; | |
1266 | ||
1267 | ret = SSL_shutdown_ex(c_tgt, 0, NULL, 0); | |
1268 | if (!TEST_int_ge(ret, 0)) | |
1269 | goto out; | |
1270 | ||
cd5e4380 HL |
1271 | if (ret == 0) |
1272 | SPIN_AGAIN(); | |
ed835673 HL |
1273 | } |
1274 | break; | |
1275 | ||
1276 | case OPK_C_EXPECT_CONN_CLOSE_INFO: | |
1277 | { | |
1278 | SSL_CONN_CLOSE_INFO cc_info = {0}; | |
1279 | int expect_app = (op->arg1 & EXPECT_CONN_CLOSE_APP) != 0; | |
1280 | int expect_remote = (op->arg1 & EXPECT_CONN_CLOSE_REMOTE) != 0; | |
1281 | uint64_t error_code = op->arg2; | |
1282 | ||
1283 | if (!TEST_ptr(c_tgt)) | |
1284 | goto out; | |
1285 | ||
9715e3aa HL |
1286 | if (!SSL_get_conn_close_info(c_tgt, &cc_info, sizeof(cc_info))) |
1287 | SPIN_AGAIN(); | |
ed835673 HL |
1288 | |
1289 | if (!TEST_int_eq(expect_app, !cc_info.is_transport) | |
1290 | || !TEST_int_eq(expect_remote, !cc_info.is_local) | |
1291 | || !TEST_uint64_t_eq(error_code, cc_info.error_code)) | |
1292 | goto out; | |
1293 | } | |
1294 | break; | |
1295 | ||
1296 | case OPK_S_EXPECT_CONN_CLOSE_INFO: | |
1297 | { | |
1298 | const QUIC_TERMINATE_CAUSE *tc; | |
1299 | int expect_app = (op->arg1 & EXPECT_CONN_CLOSE_APP) != 0; | |
1300 | int expect_remote = (op->arg1 & EXPECT_CONN_CLOSE_REMOTE) != 0; | |
1301 | uint64_t error_code = op->arg2; | |
1302 | ||
9ff3a99e HL |
1303 | if (!ossl_quic_tserver_is_term_any(h->s)) { |
1304 | ossl_quic_tserver_ping(h->s); | |
9715e3aa | 1305 | SPIN_AGAIN(); |
9ff3a99e | 1306 | } |
ed835673 | 1307 | |
a350db73 | 1308 | if (!TEST_ptr(tc = ossl_quic_tserver_get_terminate_cause(h->s))) |
ed835673 HL |
1309 | goto out; |
1310 | ||
1311 | if (!TEST_uint64_t_eq(error_code, tc->error_code) | |
1312 | || !TEST_int_eq(expect_app, tc->app) | |
1313 | || !TEST_int_eq(expect_remote, tc->remote)) | |
1314 | goto out; | |
1315 | } | |
1316 | break; | |
1317 | ||
1318 | case OPK_S_BIND_STREAM_ID: | |
1319 | { | |
1320 | if (!TEST_uint64_t_eq(s_stream_id, UINT64_MAX)) | |
1321 | goto out; | |
1322 | ||
a350db73 | 1323 | if (!TEST_true(helper_set_s_stream(h, op->stream_name, op->arg2))) |
ed835673 HL |
1324 | goto out; |
1325 | } | |
1326 | break; | |
1327 | ||
fca44cfc HL |
1328 | case OPK_S_UNBIND_STREAM_ID: |
1329 | { | |
1330 | if (!TEST_uint64_t_ne(s_stream_id, UINT64_MAX)) | |
1331 | goto out; | |
1332 | ||
1333 | if (!TEST_true(helper_set_s_stream(h, op->stream_name, UINT64_MAX))) | |
1334 | goto out; | |
1335 | } | |
1336 | break; | |
1337 | ||
ed835673 HL |
1338 | case OPK_C_WRITE_FAIL: |
1339 | { | |
571aff4b | 1340 | size_t bytes_written = 0; |
ed835673 HL |
1341 | |
1342 | if (!TEST_ptr(c_tgt)) | |
1343 | goto out; | |
1344 | ||
1345 | if (!TEST_false(SSL_write_ex(c_tgt, "apple", 5, &bytes_written))) | |
1346 | goto out; | |
1347 | } | |
1348 | break; | |
1349 | ||
1350 | case OPK_S_WRITE_FAIL: | |
1351 | { | |
1352 | size_t bytes_written = 0; | |
1353 | ||
1354 | if (!TEST_uint64_t_ne(s_stream_id, UINT64_MAX)) | |
1355 | goto out; | |
1356 | ||
a350db73 | 1357 | if (!TEST_false(ossl_quic_tserver_write(h->s, s_stream_id, |
ed835673 HL |
1358 | (const unsigned char *)"apple", 5, |
1359 | &bytes_written))) | |
1360 | goto out; | |
1361 | } | |
1362 | break; | |
1363 | ||
1364 | case OPK_C_READ_FAIL: | |
1365 | { | |
571aff4b | 1366 | size_t bytes_read = 0; |
ed835673 HL |
1367 | char buf[1]; |
1368 | ||
1369 | if (!TEST_ptr(c_tgt)) | |
1370 | goto out; | |
1371 | ||
1372 | if (!TEST_false(SSL_read_ex(c_tgt, buf, sizeof(buf), &bytes_read))) | |
1373 | goto out; | |
1374 | } | |
1375 | break; | |
1376 | ||
0345cac6 TM |
1377 | case OPK_C_READ_FAIL_WAIT: |
1378 | { | |
1379 | size_t bytes_read = 0; | |
1380 | char buf[1]; | |
1381 | ||
1382 | if (!TEST_ptr(c_tgt)) | |
1383 | goto out; | |
1384 | ||
1385 | if (!TEST_false(SSL_read_ex(c_tgt, buf, sizeof(buf), &bytes_read))) | |
1386 | goto out; | |
1387 | ||
1388 | if (is_want(c_tgt, 0)) | |
1389 | SPIN_AGAIN(); | |
1390 | } | |
1391 | break; | |
1392 | ||
2f018d14 HL |
1393 | case OPK_S_READ_FAIL: |
1394 | { | |
1395 | size_t bytes_read = 0; | |
1396 | unsigned char buf[1]; | |
1397 | ||
1398 | if (!TEST_uint64_t_ne(s_stream_id, UINT64_MAX)) | |
1399 | goto out; | |
1400 | ||
1401 | if (!TEST_false(ossl_quic_tserver_read(h->s, s_stream_id, | |
1402 | buf, sizeof(buf), | |
1403 | &bytes_read))) | |
1404 | goto out; | |
1405 | } | |
1406 | break; | |
1407 | ||
ed835673 HL |
1408 | case OPK_C_STREAM_RESET: |
1409 | { | |
1410 | SSL_STREAM_RESET_ARGS args = {0}; | |
1411 | ||
1412 | if (!TEST_ptr(c_tgt)) | |
1413 | goto out; | |
1414 | ||
1415 | args.quic_error_code = op->arg2; | |
1416 | ||
1417 | if (!TEST_true(SSL_stream_reset(c_tgt, &args, sizeof(args)))) | |
1418 | goto out; | |
1419 | } | |
1420 | break; | |
1421 | ||
a350db73 HL |
1422 | case OPK_NEW_THREAD: |
1423 | { | |
1424 | #if !defined(OPENSSL_THREADS) | |
629b408c HL |
1425 | /* |
1426 | * If this test script requires threading and we do not have | |
1427 | * support for it, skip the rest of it. | |
1428 | */ | |
1429 | TEST_skip("threading not supported, skipping"); | |
1430 | testresult = 1; | |
a350db73 HL |
1431 | goto out; |
1432 | #else | |
1433 | size_t i; | |
1434 | ||
1435 | if (!TEST_ptr_null(h->threads)) { | |
1436 | TEST_error("max one NEW_THREAD operation per script"); | |
1437 | goto out; | |
1438 | } | |
1439 | ||
1440 | h->threads = OPENSSL_zalloc(op->arg1 * sizeof(struct child_thread_args)); | |
1441 | if (!TEST_ptr(h->threads)) | |
1442 | goto out; | |
1443 | ||
1444 | h->num_threads = op->arg1; | |
1445 | ||
1446 | for (i = 0; i < op->arg1; ++i) { | |
1447 | h->threads[i].h = h; | |
1448 | h->threads[i].script = op->arg0; | |
0786483a | 1449 | h->threads[i].script_name = script_name; |
a350db73 HL |
1450 | h->threads[i].thread_idx = i; |
1451 | ||
1452 | h->threads[i].m = ossl_crypto_mutex_new(); | |
1453 | if (!TEST_ptr(h->threads[i].m)) | |
1454 | goto out; | |
1455 | ||
1456 | h->threads[i].t | |
1457 | = ossl_crypto_thread_native_start(run_script_child_thread, | |
1458 | &h->threads[i], 1); | |
1459 | if (!TEST_ptr(h->threads[i].t)) | |
1460 | goto out; | |
1461 | } | |
1462 | #endif | |
1463 | } | |
1464 | break; | |
1465 | ||
0345cac6 TM |
1466 | case OPK_C_CLOSE_SOCKET: |
1467 | { | |
1468 | BIO_closesocket(h->c_fd); | |
1469 | } | |
1470 | break; | |
1471 | ||
1472 | case OPK_C_EXPECT_SSL_ERR: | |
1473 | { | |
1474 | if (!TEST_size_t_eq((size_t)SSL_get_error(c_tgt, 0), op->arg1)) | |
1475 | goto out; | |
1476 | } | |
1477 | break; | |
1478 | ||
1479 | case OPK_EXPECT_ERR_REASON: | |
1480 | { | |
1481 | if (!TEST_size_t_eq((size_t)ERR_GET_REASON(ERR_get_error()), op->arg1)) | |
1482 | goto out; | |
1483 | } | |
1484 | break; | |
1485 | ||
1486 | case OPK_EXPECT_ERR_LIB: | |
1487 | { | |
1488 | if (!TEST_size_t_eq((size_t)ERR_GET_LIB(ERR_get_error()), op->arg1)) | |
1489 | goto out; | |
1490 | } | |
1491 | break; | |
1492 | ||
1493 | case OPK_SLEEP: | |
1494 | { | |
1495 | OSSL_sleep(op->arg2); | |
1496 | } | |
1497 | break; | |
1498 | ||
e26dc8e3 HL |
1499 | case OPK_S_SET_INJECT_PLAIN: |
1500 | h->qtf_packet_plain_cb = op->qtf_packet_plain_cb; | |
1501 | ||
1502 | if (!TEST_true(qtest_fault_set_packet_plain_listener(h->qtf, | |
1503 | h->qtf_packet_plain_cb != NULL ? | |
1504 | helper_packet_plain_listener : NULL, | |
1505 | h))) | |
1506 | goto out; | |
1507 | ||
1508 | break; | |
1509 | ||
1510 | case OPK_SET_INJECT_WORD: | |
1511 | h->inject_word0 = op->arg1; | |
1512 | h->inject_word1 = op->arg2; | |
1513 | break; | |
1514 | ||
cd5e4380 HL |
1515 | case OPK_C_INHIBIT_TICK: |
1516 | { | |
1517 | QUIC_CHANNEL *ch = ossl_quic_conn_get_channel(h->c_conn); | |
1518 | ||
1519 | ossl_quic_channel_set_inhibit_tick(ch, op->arg1); | |
1520 | } | |
1521 | break; | |
1522 | ||
1523 | case OPK_C_SET_WRITE_BUF_SIZE: | |
1524 | if (!TEST_ptr(c_tgt)) | |
1525 | goto out; | |
1526 | ||
1527 | if (!TEST_true(ossl_quic_set_write_buffer_size(c_tgt, op->arg1))) | |
1528 | goto out; | |
1529 | ||
1530 | break; | |
1531 | ||
ed835673 HL |
1532 | default: |
1533 | TEST_error("unknown op"); | |
1534 | goto out; | |
1535 | } | |
1536 | } | |
1537 | ||
1538 | out: | |
fca44cfc HL |
1539 | if (!testresult) { |
1540 | size_t i; | |
1541 | ||
0786483a HL |
1542 | TEST_error("failed in script \"%s\" at op %zu, thread %d\n", |
1543 | script_name, op_idx + 1, thread_idx); | |
ed835673 | 1544 | |
fca44cfc HL |
1545 | for (i = 0; i < repeat_stack_len; ++i) |
1546 | TEST_info("while repeating, iteration %zu of %zu, starting at script op %zu", | |
1547 | repeat_stack_done[i], | |
1548 | repeat_stack_limit[i], | |
1549 | repeat_stack_idx[i]); | |
1550 | } | |
1551 | ||
ed835673 | 1552 | OPENSSL_free(tmp_buf); |
a350db73 HL |
1553 | helper_local_cleanup(&hl); |
1554 | return testresult; | |
1555 | } | |
1556 | ||
0786483a HL |
1557 | static int run_script(const struct script_op *script, |
1558 | const char *script_name, | |
1559 | int free_order) | |
a350db73 HL |
1560 | { |
1561 | int testresult = 0; | |
1562 | struct helper h; | |
1563 | ||
e26dc8e3 | 1564 | if (!TEST_true(helper_init(&h, free_order, 1))) |
a350db73 HL |
1565 | goto out; |
1566 | ||
0786483a | 1567 | if (!TEST_true(run_script_worker(&h, script, script_name, -1))) |
a350db73 HL |
1568 | goto out; |
1569 | ||
629b408c | 1570 | #if defined(OPENSSL_THREADS) |
a350db73 HL |
1571 | if (!TEST_true(join_threads(h.threads, h.num_threads))) |
1572 | goto out; | |
629b408c | 1573 | #endif |
a350db73 HL |
1574 | |
1575 | testresult = 1; | |
1576 | out: | |
ed835673 HL |
1577 | helper_cleanup(&h); |
1578 | return testresult; | |
1579 | } | |
1580 | ||
a350db73 HL |
1581 | #if defined(OPENSSL_THREADS) |
1582 | static CRYPTO_THREAD_RETVAL run_script_child_thread(void *arg) | |
1583 | { | |
1584 | int testresult; | |
1585 | struct child_thread_args *args = arg; | |
1586 | ||
1587 | testresult = run_script_worker(args->h, args->script, | |
0786483a | 1588 | args->script_name, |
a350db73 HL |
1589 | args->thread_idx); |
1590 | ||
1591 | ossl_crypto_mutex_lock(args->m); | |
1592 | args->testresult = testresult; | |
1593 | args->done = 1; | |
1594 | ossl_crypto_mutex_unlock(args->m); | |
1595 | return 1; | |
1596 | } | |
1597 | #endif | |
1598 | ||
ed835673 HL |
1599 | /* 1. Simple single-stream test */ |
1600 | static const struct script_op script_1[] = { | |
1601 | OP_C_SET_ALPN ("ossltest") | |
1602 | OP_C_CONNECT_WAIT () | |
1603 | OP_C_WRITE (DEFAULT, "apple", 5) | |
1604 | OP_C_CONCLUDE (DEFAULT) | |
1605 | OP_S_BIND_STREAM_ID (a, C_BIDI_ID(0)) | |
1606 | OP_S_READ_EXPECT (a, "apple", 5) | |
1607 | OP_S_EXPECT_FIN (a) | |
1608 | OP_S_WRITE (a, "orange", 6) | |
1609 | OP_S_CONCLUDE (a) | |
1610 | OP_C_READ_EXPECT (DEFAULT, "orange", 6) | |
1611 | OP_C_EXPECT_FIN (DEFAULT) | |
1612 | OP_END | |
1613 | }; | |
1614 | ||
1615 | /* 2. Multi-stream test */ | |
1616 | static const struct script_op script_2[] = { | |
1617 | OP_C_SET_ALPN ("ossltest") | |
1618 | OP_C_CONNECT_WAIT () | |
83df44ae | 1619 | OP_C_SET_INCOMING_STREAM_POLICY(SSL_INCOMING_STREAM_POLICY_ACCEPT) |
ed835673 HL |
1620 | OP_C_WRITE (DEFAULT, "apple", 5) |
1621 | OP_S_BIND_STREAM_ID (a, C_BIDI_ID(0)) | |
1622 | OP_S_READ_EXPECT (a, "apple", 5) | |
1623 | OP_S_WRITE (a, "orange", 6) | |
1624 | OP_C_READ_EXPECT (DEFAULT, "orange", 6) | |
1625 | ||
1626 | OP_C_NEW_STREAM_BIDI (b, C_BIDI_ID(1)) | |
1627 | OP_C_WRITE (b, "flamingo", 8) | |
1628 | OP_C_CONCLUDE (b) | |
1629 | OP_S_BIND_STREAM_ID (b, C_BIDI_ID(1)) | |
1630 | OP_S_READ_EXPECT (b, "flamingo", 8) | |
1631 | OP_S_EXPECT_FIN (b) | |
1632 | OP_S_WRITE (b, "gargoyle", 8) | |
1633 | OP_S_CONCLUDE (b) | |
1634 | OP_C_READ_EXPECT (b, "gargoyle", 8) | |
1635 | OP_C_EXPECT_FIN (b) | |
1636 | ||
1637 | OP_C_NEW_STREAM_UNI (c, C_UNI_ID(0)) | |
1638 | OP_C_WRITE (c, "elephant", 8) | |
1639 | OP_C_CONCLUDE (c) | |
1640 | OP_S_BIND_STREAM_ID (c, C_UNI_ID(0)) | |
1641 | OP_S_READ_EXPECT (c, "elephant", 8) | |
1642 | OP_S_EXPECT_FIN (c) | |
1643 | OP_S_WRITE_FAIL (c) | |
1644 | ||
1645 | OP_C_ACCEPT_STREAM_NONE () | |
1646 | ||
1647 | OP_S_NEW_STREAM_BIDI (d, S_BIDI_ID(0)) | |
1648 | OP_S_WRITE (d, "frog", 4) | |
1649 | OP_S_CONCLUDE (d) | |
1650 | ||
a350db73 | 1651 | OP_C_ACCEPT_STREAM_WAIT (d) |
ed835673 HL |
1652 | OP_C_ACCEPT_STREAM_NONE () |
1653 | OP_C_READ_EXPECT (d, "frog", 4) | |
1654 | OP_C_EXPECT_FIN (d) | |
1655 | ||
1656 | OP_S_NEW_STREAM_BIDI (e, S_BIDI_ID(1)) | |
1657 | OP_S_WRITE (e, "mixture", 7) | |
1658 | OP_S_CONCLUDE (e) | |
1659 | ||
a350db73 | 1660 | OP_C_ACCEPT_STREAM_WAIT (e) |
ed835673 HL |
1661 | OP_C_READ_EXPECT (e, "mixture", 7) |
1662 | OP_C_EXPECT_FIN (e) | |
1663 | OP_C_WRITE (e, "ramble", 6) | |
1664 | OP_S_READ_EXPECT (e, "ramble", 6) | |
1665 | OP_C_CONCLUDE (e) | |
1666 | OP_S_EXPECT_FIN (e) | |
1667 | ||
1668 | OP_S_NEW_STREAM_UNI (f, S_UNI_ID(0)) | |
1669 | OP_S_WRITE (f, "yonder", 6) | |
1670 | OP_S_CONCLUDE (f) | |
1671 | ||
a350db73 | 1672 | OP_C_ACCEPT_STREAM_WAIT (f) |
ed835673 HL |
1673 | OP_C_ACCEPT_STREAM_NONE () |
1674 | OP_C_READ_EXPECT (f, "yonder", 6) | |
1675 | OP_C_EXPECT_FIN (f) | |
1676 | OP_C_WRITE_FAIL (f) | |
1677 | ||
83df44ae | 1678 | OP_C_SET_INCOMING_STREAM_POLICY(SSL_INCOMING_STREAM_POLICY_REJECT) |
ed835673 HL |
1679 | OP_S_NEW_STREAM_BIDI (g, S_BIDI_ID(2)) |
1680 | OP_S_WRITE (g, "unseen", 6) | |
1681 | OP_S_CONCLUDE (g) | |
1682 | ||
1683 | OP_C_ACCEPT_STREAM_NONE () | |
1684 | ||
83df44ae | 1685 | OP_C_SET_INCOMING_STREAM_POLICY(SSL_INCOMING_STREAM_POLICY_AUTO) |
ed835673 HL |
1686 | OP_S_NEW_STREAM_BIDI (h, S_BIDI_ID(3)) |
1687 | OP_S_WRITE (h, "UNSEEN", 6) | |
1688 | OP_S_CONCLUDE (h) | |
1689 | ||
1690 | OP_C_ACCEPT_STREAM_NONE () | |
1691 | ||
1692 | /* | |
1693 | * Streams g, h should have been rejected, so server should have got | |
1694 | * STOP_SENDING/RESET_STREAM. | |
1695 | */ | |
1696 | OP_CHECK (check_rejected, S_BIDI_ID(2)) | |
1697 | OP_CHECK (check_rejected, S_BIDI_ID(3)) | |
1698 | ||
1699 | OP_END | |
1700 | }; | |
1701 | ||
1702 | /* 3. Default stream detach/reattach test */ | |
1703 | static const struct script_op script_3[] = { | |
1704 | OP_C_SET_ALPN ("ossltest") | |
1705 | OP_C_CONNECT_WAIT () | |
1706 | ||
1707 | OP_C_WRITE (DEFAULT, "apple", 5) | |
1708 | OP_C_DETACH (a) /* DEFAULT becomes stream 'a' */ | |
1709 | OP_C_WRITE_FAIL (DEFAULT) | |
1710 | ||
1711 | OP_C_WRITE (a, "by", 2) | |
1712 | ||
1713 | OP_S_BIND_STREAM_ID (a, C_BIDI_ID(0)) | |
1714 | OP_S_READ_EXPECT (a, "appleby", 7) | |
1715 | ||
1716 | OP_S_WRITE (a, "hello", 5) | |
1717 | OP_C_READ_EXPECT (a, "hello", 5) | |
1718 | ||
1719 | OP_C_WRITE_FAIL (DEFAULT) | |
1720 | OP_C_ATTACH (a) | |
1721 | OP_C_WRITE (DEFAULT, "is here", 7) | |
1722 | OP_S_READ_EXPECT (a, "is here", 7) | |
1723 | ||
1724 | OP_C_DETACH (a) | |
1725 | OP_C_CONCLUDE (a) | |
1726 | OP_S_EXPECT_FIN (a) | |
1727 | ||
1728 | OP_END | |
1729 | }; | |
1730 | ||
1731 | /* 4. Default stream mode test */ | |
1732 | static const struct script_op script_4[] = { | |
1733 | OP_C_SET_ALPN ("ossltest") | |
1734 | OP_C_CONNECT_WAIT () | |
1735 | ||
1736 | OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE) | |
1737 | OP_C_WRITE_FAIL (DEFAULT) | |
1738 | ||
1739 | OP_S_NEW_STREAM_BIDI (a, S_BIDI_ID(0)) | |
1740 | OP_S_WRITE (a, "apple", 5) | |
1741 | ||
1742 | OP_C_READ_FAIL (DEFAULT) | |
1743 | ||
a350db73 | 1744 | OP_C_ACCEPT_STREAM_WAIT (a) |
ed835673 HL |
1745 | OP_C_READ_EXPECT (a, "apple", 5) |
1746 | ||
1747 | OP_C_ATTACH (a) | |
1748 | OP_C_WRITE (DEFAULT, "orange", 6) | |
1749 | OP_S_READ_EXPECT (a, "orange", 6) | |
1750 | ||
1751 | OP_END | |
1752 | }; | |
1753 | ||
1754 | /* 5. Test stream reset functionality */ | |
1755 | static const struct script_op script_5[] = { | |
1756 | OP_C_SET_ALPN ("ossltest") | |
1757 | OP_C_CONNECT_WAIT () | |
1758 | ||
1759 | OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE) | |
1760 | OP_C_NEW_STREAM_BIDI (a, C_BIDI_ID(0)) | |
9ff3a99e | 1761 | OP_C_NEW_STREAM_BIDI (b, C_BIDI_ID(1)) |
ed835673 HL |
1762 | |
1763 | OP_C_WRITE (a, "apple", 5) | |
1764 | OP_C_STREAM_RESET (a, 42) | |
1765 | ||
9ff3a99e HL |
1766 | OP_C_WRITE (b, "strawberry", 10) |
1767 | ||
ed835673 | 1768 | OP_S_BIND_STREAM_ID (a, C_BIDI_ID(0)) |
9ff3a99e HL |
1769 | OP_S_BIND_STREAM_ID (b, C_BIDI_ID(1)) |
1770 | OP_S_READ_EXPECT (b, "strawberry", 10) | |
2f018d14 HL |
1771 | /* Reset disrupts read of already sent data */ |
1772 | OP_S_READ_FAIL (a) | |
ed835673 HL |
1773 | OP_CHECK (check_stream_reset, C_BIDI_ID(0)) |
1774 | ||
1775 | OP_END | |
1776 | }; | |
1777 | ||
1778 | /* 6. Test STOP_SENDING functionality */ | |
1779 | static const struct script_op script_6[] = { | |
1780 | OP_C_SET_ALPN ("ossltest") | |
1781 | OP_C_CONNECT_WAIT () | |
1782 | ||
1783 | OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE) | |
1784 | OP_S_NEW_STREAM_BIDI (a, S_BIDI_ID(0)) | |
1785 | OP_S_WRITE (a, "apple", 5) | |
1786 | ||
a350db73 | 1787 | OP_C_ACCEPT_STREAM_WAIT (a) |
ed835673 HL |
1788 | OP_C_FREE_STREAM (a) |
1789 | OP_C_ACCEPT_STREAM_NONE () | |
1790 | ||
1791 | OP_CHECK (check_stream_stopped, S_BIDI_ID(0)) | |
1792 | ||
1793 | OP_END | |
1794 | }; | |
1795 | ||
1796 | /* 7. Unidirectional default stream mode test (client sends first) */ | |
1797 | static const struct script_op script_7[] = { | |
1798 | OP_C_SET_ALPN ("ossltest") | |
1799 | OP_C_CONNECT_WAIT () | |
1800 | ||
1801 | OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_AUTO_UNI) | |
1802 | OP_C_WRITE (DEFAULT, "apple", 5) | |
1803 | ||
1804 | OP_S_BIND_STREAM_ID (a, C_UNI_ID(0)) | |
1805 | OP_S_READ_EXPECT (a, "apple", 5) | |
1806 | OP_S_WRITE_FAIL (a) | |
1807 | ||
1808 | OP_END | |
1809 | }; | |
1810 | ||
1811 | /* 8. Unidirectional default stream mode test (server sends first) */ | |
1812 | static const struct script_op script_8[] = { | |
1813 | OP_C_SET_ALPN ("ossltest") | |
1814 | OP_C_CONNECT_WAIT () | |
1815 | ||
1816 | OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_AUTO_UNI) | |
1817 | OP_S_NEW_STREAM_UNI (a, S_UNI_ID(0)) | |
1818 | OP_S_WRITE (a, "apple", 5) | |
1819 | OP_C_READ_EXPECT (DEFAULT, "apple", 5) | |
1820 | OP_C_WRITE_FAIL (DEFAULT) | |
1821 | ||
1822 | OP_END | |
1823 | }; | |
1824 | ||
1825 | /* 9. Unidirectional default stream mode test (server sends first on bidi) */ | |
1826 | static const struct script_op script_9[] = { | |
1827 | OP_C_SET_ALPN ("ossltest") | |
1828 | OP_C_CONNECT_WAIT () | |
1829 | ||
1830 | OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_AUTO_UNI) | |
1831 | OP_S_NEW_STREAM_BIDI (a, S_BIDI_ID(0)) | |
1832 | OP_S_WRITE (a, "apple", 5) | |
1833 | OP_C_READ_EXPECT (DEFAULT, "apple", 5) | |
1834 | OP_C_WRITE (DEFAULT, "orange", 6) | |
1835 | OP_S_READ_EXPECT (a, "orange", 6) | |
1836 | ||
1837 | OP_END | |
1838 | }; | |
1839 | ||
1840 | /* 10. Shutdown */ | |
1841 | static const struct script_op script_10[] = { | |
1842 | OP_C_SET_ALPN ("ossltest") | |
1843 | OP_C_CONNECT_WAIT () | |
1844 | ||
1845 | OP_C_WRITE (DEFAULT, "apple", 5) | |
1846 | OP_S_BIND_STREAM_ID (a, C_BIDI_ID(0)) | |
1847 | OP_S_READ_EXPECT (a, "apple", 5) | |
1848 | ||
cd5e4380 | 1849 | OP_C_SHUTDOWN_WAIT () |
ed835673 HL |
1850 | OP_C_EXPECT_CONN_CLOSE_INFO(0, 1, 0) |
1851 | OP_S_EXPECT_CONN_CLOSE_INFO(0, 1, 1) | |
1852 | ||
1853 | OP_END | |
1854 | }; | |
1855 | ||
fca44cfc | 1856 | /* 11. Many threads accepted on the same client connection */ |
274bb489 HL |
1857 | static const struct script_op script_11_child[] = { |
1858 | OP_C_ACCEPT_STREAM_WAIT (a) | |
1859 | OP_C_READ_EXPECT (a, "foo", 3) | |
1860 | OP_C_EXPECT_FIN (a) | |
1861 | ||
1862 | OP_END | |
1863 | }; | |
1864 | ||
1865 | static const struct script_op script_11[] = { | |
1866 | OP_C_SET_ALPN ("ossltest") | |
1867 | OP_C_CONNECT_WAIT () | |
1868 | OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE) | |
1869 | ||
fca44cfc HL |
1870 | OP_NEW_THREAD (5, script_11_child) |
1871 | ||
1872 | OP_S_NEW_STREAM_BIDI (a, ANY_ID) | |
274bb489 HL |
1873 | OP_S_WRITE (a, "foo", 3) |
1874 | OP_S_CONCLUDE (a) | |
1875 | ||
fca44cfc | 1876 | OP_S_NEW_STREAM_BIDI (b, ANY_ID) |
274bb489 HL |
1877 | OP_S_WRITE (b, "foo", 3) |
1878 | OP_S_CONCLUDE (b) | |
1879 | ||
fca44cfc | 1880 | OP_S_NEW_STREAM_BIDI (c, ANY_ID) |
274bb489 HL |
1881 | OP_S_WRITE (c, "foo", 3) |
1882 | OP_S_CONCLUDE (c) | |
1883 | ||
fca44cfc | 1884 | OP_S_NEW_STREAM_BIDI (d, ANY_ID) |
274bb489 HL |
1885 | OP_S_WRITE (d, "foo", 3) |
1886 | OP_S_CONCLUDE (d) | |
1887 | ||
fca44cfc | 1888 | OP_S_NEW_STREAM_BIDI (e, ANY_ID) |
274bb489 HL |
1889 | OP_S_WRITE (e, "foo", 3) |
1890 | OP_S_CONCLUDE (e) | |
1891 | ||
274bb489 HL |
1892 | OP_END |
1893 | }; | |
1894 | ||
fca44cfc | 1895 | /* 12. Many threads initiated on the same client connection */ |
274bb489 HL |
1896 | static const struct script_op script_12_child[] = { |
1897 | OP_C_NEW_STREAM_BIDI (a, ANY_ID) | |
1898 | OP_C_WRITE (a, "foo", 3) | |
1899 | OP_C_CONCLUDE (a) | |
1900 | OP_C_FREE_STREAM (a) | |
1901 | ||
1902 | OP_END | |
1903 | }; | |
1904 | ||
1905 | static const struct script_op script_12[] = { | |
1906 | OP_C_SET_ALPN ("ossltest") | |
1907 | OP_C_CONNECT_WAIT () | |
1908 | OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE) | |
1909 | ||
1910 | OP_NEW_THREAD (5, script_12_child) | |
1911 | ||
1912 | OP_S_BIND_STREAM_ID (a, C_BIDI_ID(0)) | |
1913 | OP_S_READ_EXPECT (a, "foo", 3) | |
1914 | OP_S_EXPECT_FIN (a) | |
1915 | OP_S_BIND_STREAM_ID (b, C_BIDI_ID(1)) | |
1916 | OP_S_READ_EXPECT (b, "foo", 3) | |
1917 | OP_S_EXPECT_FIN (b) | |
1918 | OP_S_BIND_STREAM_ID (c, C_BIDI_ID(2)) | |
1919 | OP_S_READ_EXPECT (c, "foo", 3) | |
1920 | OP_S_EXPECT_FIN (c) | |
1921 | OP_S_BIND_STREAM_ID (d, C_BIDI_ID(3)) | |
1922 | OP_S_READ_EXPECT (d, "foo", 3) | |
1923 | OP_S_EXPECT_FIN (d) | |
1924 | OP_S_BIND_STREAM_ID (e, C_BIDI_ID(4)) | |
1925 | OP_S_READ_EXPECT (e, "foo", 3) | |
1926 | OP_S_EXPECT_FIN (e) | |
1927 | ||
1928 | OP_END | |
1929 | }; | |
1930 | ||
fca44cfc HL |
1931 | /* 13. Many threads accepted on the same client connection (stress test) */ |
1932 | static const struct script_op script_13_child[] = { | |
1933 | OP_BEGIN_REPEAT (10) | |
1934 | ||
1935 | OP_C_ACCEPT_STREAM_WAIT (a) | |
1936 | OP_C_READ_EXPECT (a, "foo", 3) | |
1937 | OP_C_EXPECT_FIN (a) | |
1938 | OP_C_FREE_STREAM (a) | |
1939 | ||
1940 | OP_END_REPEAT () | |
1941 | ||
1942 | OP_END | |
1943 | }; | |
1944 | ||
1945 | static const struct script_op script_13[] = { | |
1946 | OP_C_SET_ALPN ("ossltest") | |
1947 | OP_C_CONNECT_WAIT () | |
1948 | OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE) | |
1949 | ||
1950 | OP_NEW_THREAD (5, script_13_child) | |
1951 | ||
1952 | OP_BEGIN_REPEAT (50) | |
1953 | ||
1954 | OP_S_NEW_STREAM_BIDI (a, ANY_ID) | |
1955 | OP_S_WRITE (a, "foo", 3) | |
1956 | OP_S_CONCLUDE (a) | |
1957 | OP_S_UNBIND_STREAM_ID (a) | |
1958 | ||
1959 | OP_END_REPEAT () | |
1960 | ||
1961 | OP_END | |
1962 | }; | |
1963 | ||
1964 | /* 14. Many threads initiating on the same client connection (stress test) */ | |
1965 | static const struct script_op script_14_child[] = { | |
1966 | OP_BEGIN_REPEAT (10) | |
1967 | ||
1968 | OP_C_NEW_STREAM_BIDI (a, ANY_ID) | |
1969 | OP_C_WRITE (a, "foo", 3) | |
1970 | OP_C_CONCLUDE (a) | |
1971 | OP_C_FREE_STREAM (a) | |
1972 | ||
1973 | OP_END_REPEAT () | |
1974 | ||
1975 | OP_END | |
1976 | }; | |
1977 | ||
1978 | static const struct script_op script_14[] = { | |
1979 | OP_C_SET_ALPN ("ossltest") | |
1980 | OP_C_CONNECT_WAIT () | |
1981 | OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE) | |
1982 | ||
1983 | OP_NEW_THREAD (5, script_14_child) | |
1984 | ||
1985 | OP_BEGIN_REPEAT (50) | |
1986 | ||
1987 | OP_S_ACCEPT_STREAM_WAIT (a) | |
1988 | OP_S_READ_EXPECT (a, "foo", 3) | |
1989 | OP_S_EXPECT_FIN (a) | |
1990 | OP_S_UNBIND_STREAM_ID (a) | |
1991 | ||
1992 | OP_END_REPEAT () | |
1993 | ||
1994 | OP_END | |
1995 | }; | |
1996 | ||
0554f723 HL |
1997 | /* 15. Client sending large number of streams, MAX_STREAMS test */ |
1998 | static const struct script_op script_15[] = { | |
1999 | OP_C_SET_ALPN ("ossltest") | |
2000 | OP_C_CONNECT_WAIT () | |
2001 | OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE) | |
2002 | ||
2003 | /* | |
2004 | * This will cause a protocol violation to be raised by the server if we are | |
2005 | * not handling the stream limit correctly on the TX side. | |
2006 | */ | |
2007 | OP_BEGIN_REPEAT (200) | |
2008 | ||
2009 | OP_C_NEW_STREAM_BIDI (a, ANY_ID) | |
2010 | OP_C_WRITE (a, "foo", 3) | |
2011 | OP_C_CONCLUDE (a) | |
2012 | OP_C_FREE_STREAM (a) | |
2013 | ||
2014 | OP_END_REPEAT () | |
2015 | ||
2016 | /* Prove the connection is still good. */ | |
2017 | OP_S_NEW_STREAM_BIDI (a, S_BIDI_ID(0)) | |
2018 | OP_S_WRITE (a, "bar", 3) | |
2019 | OP_S_CONCLUDE (a) | |
2020 | ||
2021 | OP_C_ACCEPT_STREAM_WAIT (a) | |
2022 | OP_C_READ_EXPECT (a, "bar", 3) | |
2023 | OP_C_EXPECT_FIN (a) | |
2024 | ||
2025 | /* | |
2026 | * Drain the queue of incoming streams. We should be able to get all 200 | |
2027 | * even though only 100 can be initiated at a time. | |
2028 | */ | |
2029 | OP_BEGIN_REPEAT (200) | |
2030 | ||
2031 | OP_S_ACCEPT_STREAM_WAIT (b) | |
2032 | OP_S_READ_EXPECT (b, "foo", 3) | |
2033 | OP_S_EXPECT_FIN (b) | |
2034 | OP_S_UNBIND_STREAM_ID (b) | |
2035 | ||
2036 | OP_END_REPEAT () | |
2037 | ||
2038 | OP_END | |
2039 | }; | |
2040 | ||
2041 | /* 16. Server sending large number of streams, MAX_STREAMS test */ | |
2042 | static const struct script_op script_16[] = { | |
2043 | OP_C_SET_ALPN ("ossltest") | |
2044 | OP_C_CONNECT_WAIT () | |
2045 | OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE) | |
2046 | ||
2047 | /* | |
2048 | * This will cause a protocol violation to be raised by the client if we are | |
2049 | * not handling the stream limit correctly on the TX side. | |
2050 | */ | |
2051 | OP_BEGIN_REPEAT (200) | |
2052 | ||
2053 | OP_S_NEW_STREAM_BIDI (a, ANY_ID) | |
2054 | OP_S_WRITE (a, "foo", 3) | |
2055 | OP_S_CONCLUDE (a) | |
2056 | OP_S_UNBIND_STREAM_ID (a) | |
2057 | ||
2058 | OP_END_REPEAT () | |
2059 | ||
2060 | /* Prove that the connection is still good. */ | |
2061 | OP_C_NEW_STREAM_BIDI (a, ANY_ID) | |
2062 | OP_C_WRITE (a, "bar", 3) | |
2063 | OP_C_CONCLUDE (a) | |
2064 | ||
2065 | OP_S_ACCEPT_STREAM_WAIT (b) | |
2066 | OP_S_READ_EXPECT (b, "bar", 3) | |
2067 | OP_S_EXPECT_FIN (b) | |
2068 | ||
2069 | /* Drain the queue of incoming streams. */ | |
2070 | OP_BEGIN_REPEAT (200) | |
2071 | ||
2072 | OP_C_ACCEPT_STREAM_WAIT (b) | |
2073 | OP_C_READ_EXPECT (b, "foo", 3) | |
2074 | OP_C_EXPECT_FIN (b) | |
2075 | OP_C_FREE_STREAM (b) | |
2076 | ||
2077 | OP_END_REPEAT () | |
2078 | ||
2079 | OP_END | |
2080 | }; | |
2081 | ||
693b23e3 HL |
2082 | /* 17. Key update test - unlimited */ |
2083 | static const struct script_op script_17[] = { | |
2084 | OP_C_SET_ALPN ("ossltest") | |
2085 | OP_C_CONNECT_WAIT () | |
2086 | ||
2087 | OP_C_WRITE (DEFAULT, "apple", 5) | |
2088 | ||
2089 | OP_S_BIND_STREAM_ID (a, C_BIDI_ID(0)) | |
2090 | OP_S_READ_EXPECT (a, "apple", 5) | |
2091 | ||
2092 | OP_CHECK (override_key_update, 1) | |
2093 | ||
2094 | OP_BEGIN_REPEAT (200) | |
2095 | ||
2096 | OP_C_WRITE (DEFAULT, "apple", 5) | |
2097 | OP_S_READ_EXPECT (a, "apple", 5) | |
2098 | ||
2099 | /* | |
2100 | * TXKU frequency is bounded by RTT because a previous TXKU needs to be | |
2101 | * acknowledged by the peer first before another one can be begin. By | |
2102 | * waiting this long, we eliminate any such concern and ensure as many key | |
2103 | * updates as possible can occur for the purposes of this test. | |
2104 | */ | |
2105 | OP_CHECK (skip_time_ms, 100) | |
2106 | ||
2107 | OP_END_REPEAT () | |
2108 | ||
2109 | /* At least 5 RXKUs detected */ | |
2110 | OP_CHECK (check_key_update_ge, 5) | |
2111 | ||
2112 | /* | |
2113 | * Prove the connection is still healthy by sending something in both | |
2114 | * directions. | |
2115 | */ | |
2116 | OP_C_WRITE (DEFAULT, "xyzzy", 5) | |
2117 | OP_S_READ_EXPECT (a, "xyzzy", 5) | |
2118 | ||
2119 | OP_S_WRITE (a, "plugh", 5) | |
2120 | OP_C_READ_EXPECT (DEFAULT, "plugh", 5) | |
2121 | ||
2122 | OP_END | |
2123 | }; | |
2124 | ||
2125 | /* 18. Key update test - RTT-bounded */ | |
2126 | static const struct script_op script_18[] = { | |
2127 | OP_C_SET_ALPN ("ossltest") | |
2128 | OP_C_CONNECT_WAIT () | |
2129 | ||
2130 | OP_C_WRITE (DEFAULT, "apple", 5) | |
2131 | ||
2132 | OP_S_BIND_STREAM_ID (a, C_BIDI_ID(0)) | |
2133 | OP_S_READ_EXPECT (a, "apple", 5) | |
2134 | ||
2135 | OP_CHECK (override_key_update, 1) | |
2136 | ||
2137 | OP_BEGIN_REPEAT (200) | |
2138 | ||
2139 | OP_C_WRITE (DEFAULT, "apple", 5) | |
2140 | OP_S_READ_EXPECT (a, "apple", 5) | |
de9564bd | 2141 | OP_CHECK (skip_time_ms, 8) |
693b23e3 HL |
2142 | |
2143 | OP_END_REPEAT () | |
2144 | ||
2145 | /* | |
2146 | * This time we simulate far less time passing between writes, so there are | |
2147 | * fewer opportunities to initiate TXKUs. Note that we ask for a TXKU every | |
2148 | * 1 packet above, which is absurd; thus this ensures we only actually | |
2149 | * generate TXKUs when we are allowed to. | |
2150 | */ | |
0e1da9d7 | 2151 | OP_CHECK (check_key_update_lt, 240) |
693b23e3 HL |
2152 | |
2153 | /* | |
2154 | * Prove the connection is still healthy by sending something in both | |
2155 | * directions. | |
2156 | */ | |
2157 | OP_C_WRITE (DEFAULT, "xyzzy", 5) | |
2158 | OP_S_READ_EXPECT (a, "xyzzy", 5) | |
2159 | ||
2160 | OP_S_WRITE (a, "plugh", 5) | |
2161 | OP_C_READ_EXPECT (DEFAULT, "plugh", 5) | |
2162 | ||
2163 | OP_END | |
2164 | }; | |
2165 | ||
2525109f HL |
2166 | /* 19. Key update test - artificially triggered */ |
2167 | static const struct script_op script_19[] = { | |
2168 | OP_C_SET_ALPN ("ossltest") | |
2169 | OP_C_CONNECT_WAIT () | |
2170 | ||
2171 | OP_C_WRITE (DEFAULT, "apple", 5) | |
2172 | ||
2173 | OP_S_BIND_STREAM_ID (a, C_BIDI_ID(0)) | |
2174 | OP_S_READ_EXPECT (a, "apple", 5) | |
2175 | ||
76696a54 HL |
2176 | OP_C_WRITE (DEFAULT, "orange", 6) |
2177 | OP_S_READ_EXPECT (a, "orange", 6) | |
2178 | ||
2179 | OP_S_WRITE (a, "strawberry", 10) | |
2180 | OP_C_READ_EXPECT (DEFAULT, "strawberry", 10) | |
2181 | ||
2525109f HL |
2182 | OP_CHECK (check_key_update_lt, 1) |
2183 | OP_CHECK (trigger_key_update, 0) | |
2184 | ||
2185 | OP_C_WRITE (DEFAULT, "orange", 6) | |
2186 | OP_S_READ_EXPECT (a, "orange", 6) | |
9289e59c | 2187 | OP_S_WRITE (a, "ok", 2) |
2525109f | 2188 | |
9289e59c | 2189 | OP_C_READ_EXPECT (DEFAULT, "ok", 2) |
2525109f HL |
2190 | OP_CHECK (check_key_update_ge, 1) |
2191 | ||
2192 | OP_END | |
2193 | }; | |
2194 | ||
0345cac6 TM |
2195 | /* 20. Multiple threads accept stream with socket forcibly closed (error test) */ |
2196 | static const struct script_op script_20_child[] = { | |
2197 | OP_C_ACCEPT_STREAM_WAIT (a) | |
2198 | OP_C_READ_EXPECT (a, "foo", 3) | |
2199 | ||
2200 | OP_SLEEP (500) | |
2201 | ||
2202 | OP_C_READ_FAIL_WAIT (a) | |
2203 | OP_C_EXPECT_SSL_ERR (a, SSL_ERROR_SYSCALL) | |
2204 | OP_EXPECT_ERR_LIB (ERR_LIB_SYS) | |
2205 | OP_EXPECT_ERR_REASON (SSL_R_PROTOCOL_IS_SHUTDOWN) | |
2206 | OP_C_FREE_STREAM (a) | |
2207 | ||
2208 | OP_END | |
2209 | }; | |
2210 | ||
2211 | static const struct script_op script_20[] = { | |
2212 | OP_C_SET_ALPN ("ossltest") | |
2213 | OP_C_CONNECT_WAIT () | |
2214 | OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE) | |
2215 | ||
2216 | OP_NEW_THREAD (5, script_20_child) | |
2217 | ||
2218 | OP_BEGIN_REPEAT (5) | |
2219 | ||
2220 | OP_S_NEW_STREAM_BIDI (a, ANY_ID) | |
2221 | OP_S_WRITE (a, "foo", 3) | |
2222 | OP_S_UNBIND_STREAM_ID (a) | |
2223 | ||
2224 | OP_END_REPEAT () | |
2225 | ||
2226 | OP_SLEEP (100) | |
2227 | ||
2228 | OP_C_CLOSE_SOCKET () | |
2229 | ||
2230 | OP_END | |
2231 | }; | |
2232 | ||
e26dc8e3 HL |
2233 | /* 21. Fault injection - unknown frame in 1-RTT packet */ |
2234 | static int script_21_inject_plain(struct helper *h, QUIC_PKT_HDR *hdr, | |
2235 | unsigned char *buf, size_t len) | |
2236 | { | |
7eebc354 | 2237 | int ok = 0; |
e26dc8e3 HL |
2238 | WPACKET wpkt; |
2239 | unsigned char frame_buf[8]; | |
2240 | size_t written; | |
2241 | ||
2242 | if (h->inject_word0 == 0 || hdr->type != h->inject_word0) | |
2243 | return 1; | |
2244 | ||
2245 | if (!TEST_true(WPACKET_init_static_len(&wpkt, frame_buf, | |
2246 | sizeof(frame_buf), 0))) | |
2247 | return 0; | |
2248 | ||
2249 | if (!TEST_true(WPACKET_quic_write_vlint(&wpkt, h->inject_word1))) | |
7eebc354 | 2250 | goto err; |
e26dc8e3 HL |
2251 | |
2252 | if (!TEST_true(WPACKET_get_total_written(&wpkt, &written))) | |
7eebc354 | 2253 | goto err; |
e26dc8e3 HL |
2254 | |
2255 | if (!qtest_fault_prepend_frame(h->qtf, frame_buf, written)) | |
7eebc354 | 2256 | goto err; |
e26dc8e3 | 2257 | |
7eebc354 HL |
2258 | ok = 1; |
2259 | err: | |
96b7df60 HL |
2260 | if (ok) |
2261 | WPACKET_finish(&wpkt); | |
2262 | else | |
2263 | WPACKET_cleanup(&wpkt); | |
7eebc354 | 2264 | return ok; |
e26dc8e3 HL |
2265 | } |
2266 | ||
2267 | static const struct script_op script_21[] = { | |
2268 | OP_S_SET_INJECT_PLAIN (script_21_inject_plain) | |
2269 | OP_C_SET_ALPN ("ossltest") | |
2270 | OP_C_CONNECT_WAIT () | |
2271 | ||
2272 | OP_C_WRITE (DEFAULT, "apple", 5) | |
2273 | OP_S_BIND_STREAM_ID (a, C_BIDI_ID(0)) | |
2274 | OP_S_READ_EXPECT (a, "apple", 5) | |
2275 | ||
2276 | OP_SET_INJECT_WORD (QUIC_PKT_TYPE_1RTT, OSSL_QUIC_VLINT_MAX) | |
2277 | ||
2278 | OP_S_WRITE (a, "orange", 6) | |
2279 | ||
2280 | OP_C_EXPECT_CONN_CLOSE_INFO(QUIC_ERR_FRAME_ENCODING_ERROR,0,0) | |
2281 | ||
2282 | OP_END | |
2283 | }; | |
2284 | ||
2285 | /* 22. Fault injection - non-zero packet header reserved bits */ | |
2286 | static int script_22_inject_plain(struct helper *h, QUIC_PKT_HDR *hdr, | |
2287 | unsigned char *buf, size_t len) | |
2288 | { | |
2289 | if (h->inject_word0 == 0) | |
2290 | return 1; | |
2291 | ||
2292 | hdr->reserved = 1; | |
2293 | return 1; | |
2294 | } | |
2295 | ||
2296 | static const struct script_op script_22[] = { | |
2297 | OP_S_SET_INJECT_PLAIN (script_22_inject_plain) | |
2298 | OP_C_SET_ALPN ("ossltest") | |
2299 | OP_C_CONNECT_WAIT () | |
2300 | ||
2301 | OP_C_WRITE (DEFAULT, "apple", 5) | |
2302 | OP_S_BIND_STREAM_ID (a, C_BIDI_ID(0)) | |
2303 | OP_S_READ_EXPECT (a, "apple", 5) | |
2304 | ||
2305 | OP_SET_INJECT_WORD (1, 0) | |
2306 | ||
2307 | OP_S_WRITE (a, "orange", 6) | |
2308 | ||
2309 | OP_C_EXPECT_CONN_CLOSE_INFO(QUIC_ERR_PROTOCOL_VIOLATION,0,0) | |
2310 | ||
2311 | OP_END | |
2312 | }; | |
2313 | ||
2314 | /* 23. Fault injection - empty NEW_TOKEN */ | |
2315 | static int script_23_inject_plain(struct helper *h, QUIC_PKT_HDR *hdr, | |
2316 | unsigned char *buf, size_t len) | |
2317 | { | |
7eebc354 | 2318 | int ok = 0; |
e26dc8e3 HL |
2319 | WPACKET wpkt; |
2320 | unsigned char frame_buf[16]; | |
2321 | size_t written; | |
2322 | ||
2323 | if (h->inject_word0 == 0) | |
2324 | return 1; | |
2325 | ||
2326 | if (!TEST_true(WPACKET_init_static_len(&wpkt, frame_buf, | |
2327 | sizeof(frame_buf), 0))) | |
2328 | return 0; | |
2329 | ||
2330 | if (!TEST_true(WPACKET_quic_write_vlint(&wpkt, OSSL_QUIC_FRAME_TYPE_NEW_TOKEN)) | |
2331 | || !TEST_true(WPACKET_quic_write_vlint(&wpkt, 0))) | |
7eebc354 | 2332 | goto err; |
e26dc8e3 HL |
2333 | |
2334 | if (!TEST_true(WPACKET_get_total_written(&wpkt, &written))) | |
7eebc354 | 2335 | goto err; |
e26dc8e3 HL |
2336 | |
2337 | if (!qtest_fault_prepend_frame(h->qtf, frame_buf, written)) | |
7eebc354 | 2338 | goto err; |
e26dc8e3 | 2339 | |
7eebc354 HL |
2340 | ok = 1; |
2341 | err: | |
96b7df60 HL |
2342 | if (ok) |
2343 | WPACKET_finish(&wpkt); | |
2344 | else | |
2345 | WPACKET_cleanup(&wpkt); | |
7eebc354 | 2346 | return ok; |
e26dc8e3 HL |
2347 | } |
2348 | ||
2349 | static const struct script_op script_23[] = { | |
2350 | OP_S_SET_INJECT_PLAIN (script_23_inject_plain) | |
2351 | OP_C_SET_ALPN ("ossltest") | |
2352 | OP_C_CONNECT_WAIT () | |
2353 | ||
2354 | OP_C_WRITE (DEFAULT, "apple", 5) | |
2355 | OP_S_BIND_STREAM_ID (a, C_BIDI_ID(0)) | |
2356 | OP_S_READ_EXPECT (a, "apple", 5) | |
2357 | ||
2358 | OP_SET_INJECT_WORD (1, 0) | |
2359 | ||
2360 | OP_S_WRITE (a, "orange", 6) | |
2361 | ||
2362 | OP_C_EXPECT_CONN_CLOSE_INFO(QUIC_ERR_FRAME_ENCODING_ERROR,0,0) | |
2363 | ||
2364 | OP_END | |
2365 | }; | |
2366 | ||
2367 | /* 24. Fault injection - excess value of MAX_STREAMS_BIDI */ | |
2368 | static int script_24_inject_plain(struct helper *h, QUIC_PKT_HDR *hdr, | |
2369 | unsigned char *buf, size_t len) | |
2370 | { | |
7eebc354 | 2371 | int ok = 0; |
e26dc8e3 HL |
2372 | WPACKET wpkt; |
2373 | unsigned char frame_buf[16]; | |
2374 | size_t written; | |
2375 | ||
2376 | if (h->inject_word0 == 0) | |
2377 | return 1; | |
2378 | ||
2379 | if (!TEST_true(WPACKET_init_static_len(&wpkt, frame_buf, | |
2380 | sizeof(frame_buf), 0))) | |
2381 | return 0; | |
2382 | ||
2383 | if (!TEST_true(WPACKET_quic_write_vlint(&wpkt, h->inject_word1)) | |
2384 | || !TEST_true(WPACKET_quic_write_vlint(&wpkt, (((uint64_t)1) << 60) + 1))) | |
7eebc354 | 2385 | goto err; |
e26dc8e3 HL |
2386 | |
2387 | if (!TEST_true(WPACKET_get_total_written(&wpkt, &written))) | |
7eebc354 | 2388 | goto err; |
e26dc8e3 HL |
2389 | |
2390 | if (!qtest_fault_prepend_frame(h->qtf, frame_buf, written)) | |
7eebc354 | 2391 | goto err; |
e26dc8e3 | 2392 | |
7eebc354 HL |
2393 | ok = 1; |
2394 | err: | |
96b7df60 HL |
2395 | if (ok) |
2396 | WPACKET_finish(&wpkt); | |
2397 | else | |
2398 | WPACKET_cleanup(&wpkt); | |
7eebc354 | 2399 | return ok; |
e26dc8e3 HL |
2400 | } |
2401 | ||
2402 | static const struct script_op script_24[] = { | |
2403 | OP_S_SET_INJECT_PLAIN (script_24_inject_plain) | |
2404 | OP_C_SET_ALPN ("ossltest") | |
2405 | OP_C_CONNECT_WAIT () | |
2406 | ||
2407 | OP_C_WRITE (DEFAULT, "apple", 5) | |
2408 | OP_S_BIND_STREAM_ID (a, C_BIDI_ID(0)) | |
2409 | OP_S_READ_EXPECT (a, "apple", 5) | |
2410 | ||
2411 | OP_SET_INJECT_WORD (1, OSSL_QUIC_FRAME_TYPE_MAX_STREAMS_BIDI) | |
2412 | ||
2413 | OP_S_WRITE (a, "orange", 6) | |
2414 | ||
2415 | OP_C_EXPECT_CONN_CLOSE_INFO(QUIC_ERR_FRAME_ENCODING_ERROR,0,0) | |
2416 | ||
2417 | OP_END | |
2418 | }; | |
2419 | ||
2420 | /* 25. Fault injection - excess value of MAX_STREAMS_UNI */ | |
2421 | static const struct script_op script_25[] = { | |
2422 | OP_S_SET_INJECT_PLAIN (script_24_inject_plain) | |
2423 | OP_C_SET_ALPN ("ossltest") | |
2424 | OP_C_CONNECT_WAIT () | |
2425 | ||
2426 | OP_C_WRITE (DEFAULT, "apple", 5) | |
2427 | OP_S_BIND_STREAM_ID (a, C_BIDI_ID(0)) | |
2428 | OP_S_READ_EXPECT (a, "apple", 5) | |
2429 | ||
2430 | OP_SET_INJECT_WORD (1, OSSL_QUIC_FRAME_TYPE_MAX_STREAMS_UNI) | |
2431 | ||
2432 | OP_S_WRITE (a, "orange", 6) | |
2433 | ||
2434 | OP_C_EXPECT_CONN_CLOSE_INFO(QUIC_ERR_FRAME_ENCODING_ERROR,0,0) | |
2435 | ||
2436 | OP_END | |
2437 | }; | |
2438 | ||
2439 | /* 26. Fault injection - excess value of STREAMS_BLOCKED_BIDI */ | |
2440 | static const struct script_op script_26[] = { | |
2441 | OP_S_SET_INJECT_PLAIN (script_24_inject_plain) | |
2442 | OP_C_SET_ALPN ("ossltest") | |
2443 | OP_C_CONNECT_WAIT () | |
2444 | ||
2445 | OP_C_WRITE (DEFAULT, "apple", 5) | |
2446 | OP_S_BIND_STREAM_ID (a, C_BIDI_ID(0)) | |
2447 | OP_S_READ_EXPECT (a, "apple", 5) | |
2448 | ||
2449 | OP_SET_INJECT_WORD (1, OSSL_QUIC_FRAME_TYPE_STREAMS_BLOCKED_BIDI) | |
2450 | ||
2451 | OP_S_WRITE (a, "orange", 6) | |
2452 | ||
2453 | OP_C_EXPECT_CONN_CLOSE_INFO(QUIC_ERR_STREAM_LIMIT_ERROR,0,0) | |
2454 | ||
2455 | OP_END | |
2456 | }; | |
2457 | ||
2458 | /* 27. Fault injection - excess value of STREAMS_BLOCKED_UNI */ | |
2459 | static const struct script_op script_27[] = { | |
2460 | OP_S_SET_INJECT_PLAIN (script_24_inject_plain) | |
2461 | OP_C_SET_ALPN ("ossltest") | |
2462 | OP_C_CONNECT_WAIT () | |
2463 | ||
2464 | OP_C_WRITE (DEFAULT, "apple", 5) | |
2465 | OP_S_BIND_STREAM_ID (a, C_BIDI_ID(0)) | |
2466 | OP_S_READ_EXPECT (a, "apple", 5) | |
2467 | ||
2468 | OP_SET_INJECT_WORD (1, OSSL_QUIC_FRAME_TYPE_STREAMS_BLOCKED_UNI) | |
2469 | ||
2470 | OP_S_WRITE (a, "orange", 6) | |
2471 | ||
2472 | OP_C_EXPECT_CONN_CLOSE_INFO(QUIC_ERR_STREAM_LIMIT_ERROR,0,0) | |
2473 | ||
2474 | OP_END | |
2475 | }; | |
2476 | ||
2477 | /* 28. Fault injection - received RESET_STREAM for send-only stream */ | |
2478 | static int script_28_inject_plain(struct helper *h, QUIC_PKT_HDR *hdr, | |
2479 | unsigned char *buf, size_t len) | |
2480 | { | |
7eebc354 | 2481 | int ok = 0; |
e26dc8e3 HL |
2482 | WPACKET wpkt; |
2483 | unsigned char frame_buf[32]; | |
2484 | size_t written; | |
2485 | ||
2486 | if (h->inject_word0 == 0) | |
2487 | return 1; | |
2488 | ||
2489 | if (!TEST_true(WPACKET_init_static_len(&wpkt, frame_buf, | |
2490 | sizeof(frame_buf), 0))) | |
2491 | return 0; | |
2492 | ||
2493 | if (!TEST_true(WPACKET_quic_write_vlint(&wpkt, h->inject_word1)) | |
2494 | || !TEST_true(WPACKET_quic_write_vlint(&wpkt, /* stream ID */ | |
2495 | h->inject_word0 - 1)) | |
2496 | || !TEST_true(WPACKET_quic_write_vlint(&wpkt, 123)) | |
2497 | || (h->inject_word1 == OSSL_QUIC_FRAME_TYPE_RESET_STREAM | |
2498 | && !TEST_true(WPACKET_quic_write_vlint(&wpkt, 5)))) /* final size */ | |
7eebc354 | 2499 | goto err; |
e26dc8e3 HL |
2500 | |
2501 | if (!TEST_true(WPACKET_get_total_written(&wpkt, &written))) | |
7eebc354 | 2502 | goto err; |
e26dc8e3 HL |
2503 | |
2504 | if (!qtest_fault_prepend_frame(h->qtf, frame_buf, written)) | |
7eebc354 | 2505 | goto err; |
e26dc8e3 | 2506 | |
7eebc354 HL |
2507 | ok = 1; |
2508 | err: | |
96b7df60 HL |
2509 | if (ok) |
2510 | WPACKET_finish(&wpkt); | |
2511 | else | |
2512 | WPACKET_cleanup(&wpkt); | |
7eebc354 | 2513 | return ok; |
e26dc8e3 HL |
2514 | } |
2515 | ||
2516 | static const struct script_op script_28[] = { | |
2517 | OP_S_SET_INJECT_PLAIN (script_28_inject_plain) | |
2518 | OP_C_SET_ALPN ("ossltest") | |
2519 | OP_C_CONNECT_WAIT () | |
2520 | OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE) | |
2521 | ||
70cafc44 HL |
2522 | OP_C_NEW_STREAM_BIDI (a, C_BIDI_ID(0)) |
2523 | OP_C_WRITE (a, "orange", 6) | |
e26dc8e3 | 2524 | |
70cafc44 HL |
2525 | OP_S_BIND_STREAM_ID (a, C_BIDI_ID(0)) |
2526 | OP_S_READ_EXPECT (a, "orange", 6) | |
2527 | ||
2528 | OP_C_NEW_STREAM_UNI (b, C_UNI_ID(0)) | |
2529 | OP_C_WRITE (b, "apple", 5) | |
2530 | ||
2531 | OP_S_BIND_STREAM_ID (b, C_UNI_ID(0)) | |
2532 | OP_S_READ_EXPECT (b, "apple", 5) | |
e26dc8e3 HL |
2533 | |
2534 | OP_SET_INJECT_WORD (C_UNI_ID(0) + 1, OSSL_QUIC_FRAME_TYPE_RESET_STREAM) | |
70cafc44 | 2535 | OP_S_WRITE (a, "fruit", 5) |
e26dc8e3 HL |
2536 | |
2537 | OP_C_EXPECT_CONN_CLOSE_INFO(QUIC_ERR_STREAM_STATE_ERROR,0,0) | |
2538 | ||
2539 | OP_END | |
2540 | }; | |
2541 | ||
2542 | /* 29. Fault injection - received RESET_STREAM for nonexistent send-only stream */ | |
2543 | static const struct script_op script_29[] = { | |
2544 | OP_S_SET_INJECT_PLAIN (script_28_inject_plain) | |
2545 | OP_C_SET_ALPN ("ossltest") | |
2546 | OP_C_CONNECT_WAIT () | |
2547 | OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE) | |
2548 | ||
70cafc44 HL |
2549 | OP_C_NEW_STREAM_BIDI (a, C_BIDI_ID(0)) |
2550 | OP_C_WRITE (a, "orange", 6) | |
e26dc8e3 | 2551 | |
70cafc44 HL |
2552 | OP_S_BIND_STREAM_ID (a, C_BIDI_ID(0)) |
2553 | OP_S_READ_EXPECT (a, "orange", 6) | |
2554 | ||
2555 | OP_C_NEW_STREAM_UNI (b, C_UNI_ID(0)) | |
2556 | OP_C_WRITE (b, "apple", 5) | |
2557 | ||
2558 | OP_S_BIND_STREAM_ID (b, C_UNI_ID(0)) | |
2559 | OP_S_READ_EXPECT (b, "apple", 5) | |
e26dc8e3 HL |
2560 | |
2561 | OP_SET_INJECT_WORD (C_UNI_ID(1) + 1, OSSL_QUIC_FRAME_TYPE_RESET_STREAM) | |
70cafc44 | 2562 | OP_S_WRITE (a, "fruit", 5) |
e26dc8e3 HL |
2563 | |
2564 | OP_C_EXPECT_CONN_CLOSE_INFO(QUIC_ERR_STREAM_STATE_ERROR,0,0) | |
2565 | ||
2566 | OP_END | |
2567 | }; | |
2568 | ||
2569 | /* 30. Fault injection - received STOP_SENDING for receive-only stream */ | |
2570 | static const struct script_op script_30[] = { | |
2571 | OP_S_SET_INJECT_PLAIN (script_28_inject_plain) | |
2572 | OP_C_SET_ALPN ("ossltest") | |
2573 | OP_C_CONNECT_WAIT () | |
2574 | OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE) | |
2575 | ||
2576 | OP_S_NEW_STREAM_UNI (a, S_UNI_ID(0)) | |
2577 | OP_S_WRITE (a, "apple", 5) | |
2578 | ||
2579 | OP_C_ACCEPT_STREAM_WAIT (a) | |
2580 | OP_C_READ_EXPECT (a, "apple", 5) | |
2581 | ||
2582 | OP_SET_INJECT_WORD (S_UNI_ID(0) + 1, OSSL_QUIC_FRAME_TYPE_STOP_SENDING) | |
2583 | OP_S_WRITE (a, "orange", 6) | |
2584 | ||
2585 | OP_C_EXPECT_CONN_CLOSE_INFO(QUIC_ERR_STREAM_STATE_ERROR,0,0) | |
2586 | ||
2587 | OP_END | |
2588 | }; | |
2589 | ||
2590 | /* 31. Fault injection - received STOP_SENDING for nonexistent receive-only stream */ | |
2591 | static const struct script_op script_31[] = { | |
2592 | OP_S_SET_INJECT_PLAIN (script_28_inject_plain) | |
2593 | OP_C_SET_ALPN ("ossltest") | |
2594 | OP_C_CONNECT_WAIT () | |
2595 | OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE) | |
2596 | ||
2597 | OP_S_NEW_STREAM_UNI (a, S_UNI_ID(0)) | |
2598 | OP_S_WRITE (a, "apple", 5) | |
2599 | ||
2600 | OP_C_ACCEPT_STREAM_WAIT (a) | |
2601 | OP_C_READ_EXPECT (a, "apple", 5) | |
2602 | ||
2603 | OP_SET_INJECT_WORD (C_UNI_ID(0) + 1, OSSL_QUIC_FRAME_TYPE_STOP_SENDING) | |
2604 | OP_S_WRITE (a, "orange", 6) | |
2605 | ||
2606 | OP_C_EXPECT_CONN_CLOSE_INFO(QUIC_ERR_STREAM_STATE_ERROR,0,0) | |
2607 | ||
2608 | OP_END | |
2609 | }; | |
2610 | ||
2611 | /* 32. Fault injection - STREAM frame for nonexistent stream */ | |
2612 | static int script_32_inject_plain(struct helper *h, QUIC_PKT_HDR *hdr, | |
2613 | unsigned char *buf, size_t len) | |
2614 | { | |
7eebc354 | 2615 | int ok = 0; |
e26dc8e3 HL |
2616 | WPACKET wpkt; |
2617 | unsigned char frame_buf[64]; | |
2618 | size_t written; | |
2619 | uint64_t type = OSSL_QUIC_FRAME_TYPE_STREAM_OFF_LEN, offset, flen, i; | |
2620 | ||
2621 | switch (h->inject_word1) { | |
2622 | default: | |
2623 | return 0; | |
2624 | case 0: | |
2625 | return 1; | |
2626 | case 1: | |
2627 | offset = 0; | |
2628 | flen = 0; | |
2629 | break; | |
2630 | case 2: | |
2631 | offset = (((uint64_t)1)<<62) - 1; | |
2632 | flen = 5; | |
2633 | break; | |
2634 | case 3: | |
2635 | offset = 1 * 1024 * 1024 * 1024; /* 1G */ | |
2636 | flen = 5; | |
2637 | break; | |
2638 | } | |
2639 | ||
2640 | if (!TEST_true(WPACKET_init_static_len(&wpkt, frame_buf, | |
2641 | sizeof(frame_buf), 0))) | |
2642 | return 0; | |
2643 | ||
2644 | if (!TEST_true(WPACKET_quic_write_vlint(&wpkt, type)) | |
2645 | || !TEST_true(WPACKET_quic_write_vlint(&wpkt, /* stream ID */ | |
2646 | h->inject_word0 - 1)) | |
2647 | || !TEST_true(WPACKET_quic_write_vlint(&wpkt, offset)) | |
2648 | || !TEST_true(WPACKET_quic_write_vlint(&wpkt, flen))) | |
7eebc354 | 2649 | goto err; |
e26dc8e3 HL |
2650 | |
2651 | for (i = 0; i < flen; ++i) | |
2652 | if (!TEST_true(WPACKET_put_bytes_u8(&wpkt, 0x42))) | |
7eebc354 | 2653 | goto err; |
e26dc8e3 HL |
2654 | |
2655 | if (!TEST_true(WPACKET_get_total_written(&wpkt, &written))) | |
7eebc354 | 2656 | goto err; |
e26dc8e3 HL |
2657 | |
2658 | if (!qtest_fault_prepend_frame(h->qtf, frame_buf, written)) | |
7eebc354 | 2659 | goto err; |
e26dc8e3 | 2660 | |
7eebc354 HL |
2661 | ok = 1; |
2662 | err: | |
96b7df60 HL |
2663 | if (ok) |
2664 | WPACKET_finish(&wpkt); | |
2665 | else | |
2666 | WPACKET_cleanup(&wpkt); | |
7eebc354 | 2667 | return ok; |
e26dc8e3 HL |
2668 | } |
2669 | ||
2670 | static const struct script_op script_32[] = { | |
2671 | OP_S_SET_INJECT_PLAIN (script_32_inject_plain) | |
2672 | OP_C_SET_ALPN ("ossltest") | |
2673 | OP_C_CONNECT_WAIT () | |
2674 | OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE) | |
2675 | ||
2676 | OP_S_NEW_STREAM_UNI (a, S_UNI_ID(0)) | |
2677 | OP_S_WRITE (a, "apple", 5) | |
2678 | ||
2679 | OP_C_ACCEPT_STREAM_WAIT (a) | |
2680 | OP_C_READ_EXPECT (a, "apple", 5) | |
2681 | ||
2682 | OP_SET_INJECT_WORD (C_UNI_ID(0) + 1, 1) | |
2683 | OP_S_WRITE (a, "orange", 6) | |
2684 | ||
2685 | OP_C_EXPECT_CONN_CLOSE_INFO(QUIC_ERR_STREAM_STATE_ERROR,0,0) | |
2686 | ||
2687 | OP_END | |
2688 | }; | |
2689 | ||
2690 | /* 33. Fault injection - STREAM frame with illegal offset */ | |
2691 | static const struct script_op script_33[] = { | |
2692 | OP_S_SET_INJECT_PLAIN (script_32_inject_plain) | |
2693 | OP_C_SET_ALPN ("ossltest") | |
2694 | OP_C_CONNECT_WAIT () | |
2695 | OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE) | |
2696 | ||
2697 | OP_C_NEW_STREAM_BIDI (a, C_BIDI_ID(0)) | |
2698 | OP_C_WRITE (a, "apple", 5) | |
2699 | ||
2700 | OP_S_BIND_STREAM_ID (a, C_BIDI_ID(0)) | |
2701 | OP_S_READ_EXPECT (a, "apple", 5) | |
2702 | ||
2703 | OP_SET_INJECT_WORD (C_BIDI_ID(0) + 1, 2) | |
2704 | OP_S_WRITE (a, "orange", 6) | |
2705 | ||
2706 | OP_C_EXPECT_CONN_CLOSE_INFO(QUIC_ERR_FRAME_ENCODING_ERROR,0,0) | |
2707 | ||
2708 | OP_END | |
2709 | }; | |
2710 | ||
2711 | /* 34. Fault injection - STREAM frame which exceeds FC */ | |
2712 | static const struct script_op script_34[] = { | |
2713 | OP_S_SET_INJECT_PLAIN (script_32_inject_plain) | |
2714 | OP_C_SET_ALPN ("ossltest") | |
2715 | OP_C_CONNECT_WAIT () | |
2716 | OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE) | |
2717 | ||
2718 | OP_C_NEW_STREAM_BIDI (a, C_BIDI_ID(0)) | |
2719 | OP_C_WRITE (a, "apple", 5) | |
2720 | ||
2721 | OP_S_BIND_STREAM_ID (a, C_BIDI_ID(0)) | |
2722 | OP_S_READ_EXPECT (a, "apple", 5) | |
2723 | ||
2724 | OP_SET_INJECT_WORD (C_BIDI_ID(0) + 1, 3) | |
2725 | OP_S_WRITE (a, "orange", 6) | |
2726 | ||
2727 | OP_C_EXPECT_CONN_CLOSE_INFO(QUIC_ERR_FLOW_CONTROL_ERROR,0,0) | |
2728 | ||
2729 | OP_END | |
2730 | }; | |
2731 | ||
2732 | /* 35. Fault injection - MAX_STREAM_DATA for receive-only stream */ | |
2733 | static const struct script_op script_35[] = { | |
2734 | OP_S_SET_INJECT_PLAIN (script_28_inject_plain) | |
2735 | OP_C_SET_ALPN ("ossltest") | |
2736 | OP_C_CONNECT_WAIT () | |
2737 | OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE) | |
2738 | ||
2739 | OP_S_NEW_STREAM_UNI (a, S_UNI_ID(0)) | |
2740 | OP_S_WRITE (a, "apple", 5) | |
2741 | ||
2742 | OP_C_ACCEPT_STREAM_WAIT (a) | |
2743 | OP_C_READ_EXPECT (a, "apple", 5) | |
2744 | ||
2745 | OP_SET_INJECT_WORD (S_UNI_ID(0) + 1, OSSL_QUIC_FRAME_TYPE_MAX_STREAM_DATA) | |
2746 | OP_S_WRITE (a, "orange", 6) | |
2747 | ||
2748 | OP_C_EXPECT_CONN_CLOSE_INFO(QUIC_ERR_STREAM_STATE_ERROR,0,0) | |
2749 | ||
2750 | OP_END | |
2751 | }; | |
2752 | ||
2753 | /* 36. Fault injection - MAX_STREAM_DATA for nonexistent stream */ | |
2754 | static const struct script_op script_36[] = { | |
2755 | OP_S_SET_INJECT_PLAIN (script_28_inject_plain) | |
2756 | OP_C_SET_ALPN ("ossltest") | |
2757 | OP_C_CONNECT_WAIT () | |
2758 | OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE) | |
2759 | ||
2760 | OP_S_NEW_STREAM_UNI (a, S_UNI_ID(0)) | |
2761 | OP_S_WRITE (a, "apple", 5) | |
2762 | ||
2763 | OP_C_ACCEPT_STREAM_WAIT (a) | |
2764 | OP_C_READ_EXPECT (a, "apple", 5) | |
2765 | ||
2766 | OP_SET_INJECT_WORD (C_BIDI_ID(0) + 1, OSSL_QUIC_FRAME_TYPE_MAX_STREAM_DATA) | |
2767 | OP_S_WRITE (a, "orange", 6) | |
2768 | ||
2769 | OP_C_EXPECT_CONN_CLOSE_INFO(QUIC_ERR_STREAM_STATE_ERROR,0,0) | |
2770 | ||
2771 | OP_END | |
2772 | }; | |
2773 | ||
2774 | /* 37. Fault injection - STREAM_DATA_BLOCKED for send-only stream */ | |
2775 | static const struct script_op script_37[] = { | |
2776 | OP_S_SET_INJECT_PLAIN (script_28_inject_plain) | |
2777 | OP_C_SET_ALPN ("ossltest") | |
2778 | OP_C_CONNECT_WAIT () | |
2779 | OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE) | |
2780 | ||
2781 | OP_C_NEW_STREAM_UNI (a, C_UNI_ID(0)) | |
2782 | OP_C_WRITE (a, "apple", 5) | |
2783 | ||
2784 | OP_S_BIND_STREAM_ID (a, C_UNI_ID(0)) | |
2785 | OP_S_READ_EXPECT (a, "apple", 5) | |
2786 | ||
2787 | OP_S_NEW_STREAM_UNI (b, S_UNI_ID(0)) | |
2788 | OP_SET_INJECT_WORD (C_UNI_ID(0) + 1, OSSL_QUIC_FRAME_TYPE_STREAM_DATA_BLOCKED) | |
2789 | OP_S_WRITE (b, "orange", 5) | |
2790 | ||
2791 | OP_C_EXPECT_CONN_CLOSE_INFO(QUIC_ERR_STREAM_STATE_ERROR,0,0) | |
2792 | ||
2793 | OP_END | |
2794 | }; | |
2795 | ||
2796 | /* 38. Fault injection - STREAM_DATA_BLOCKED for non-existent stream */ | |
2797 | static const struct script_op script_38[] = { | |
2798 | OP_S_SET_INJECT_PLAIN (script_28_inject_plain) | |
2799 | OP_C_SET_ALPN ("ossltest") | |
2800 | OP_C_CONNECT_WAIT () | |
2801 | OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE) | |
2802 | ||
2803 | OP_S_NEW_STREAM_UNI (b, S_UNI_ID(0)) | |
2804 | OP_SET_INJECT_WORD (C_BIDI_ID(0) + 1, OSSL_QUIC_FRAME_TYPE_STREAM_DATA_BLOCKED) | |
2805 | OP_S_WRITE (b, "orange", 5) | |
2806 | ||
2807 | OP_C_EXPECT_CONN_CLOSE_INFO(QUIC_ERR_STREAM_STATE_ERROR,0,0) | |
2808 | ||
2809 | OP_END | |
2810 | }; | |
2811 | ||
2812 | /* 39. Fault injection - NEW_CONN_ID with zero-len CID */ | |
2813 | static int script_39_inject_plain(struct helper *h, QUIC_PKT_HDR *hdr, | |
2814 | unsigned char *buf, size_t len) | |
2815 | { | |
7eebc354 | 2816 | int ok = 0; |
e26dc8e3 HL |
2817 | WPACKET wpkt; |
2818 | unsigned char frame_buf[64]; | |
2819 | size_t i, written; | |
2820 | ||
2821 | if (h->inject_word1 == 0) | |
2822 | return 1; | |
2823 | ||
2824 | if (!TEST_true(WPACKET_init_static_len(&wpkt, frame_buf, | |
2825 | sizeof(frame_buf), 0))) | |
2826 | return 0; | |
2827 | ||
2828 | if (!TEST_true(WPACKET_quic_write_vlint(&wpkt, OSSL_QUIC_FRAME_TYPE_NEW_CONN_ID)) | |
2829 | || !TEST_true(WPACKET_quic_write_vlint(&wpkt, 0)) /* seq no */ | |
2830 | || !TEST_true(WPACKET_quic_write_vlint(&wpkt, 0)) /* retire prior to */ | |
2831 | || !TEST_true(WPACKET_put_bytes_u8(&wpkt, 0))) /* len */ | |
7eebc354 | 2832 | goto err; |
e26dc8e3 HL |
2833 | |
2834 | for (i = 0; i < QUIC_STATELESS_RESET_TOKEN_LEN; ++i) | |
2835 | if (!TEST_true(WPACKET_put_bytes_u8(&wpkt, 0x42))) | |
7eebc354 | 2836 | goto err; |
e26dc8e3 HL |
2837 | |
2838 | if (!TEST_true(WPACKET_get_total_written(&wpkt, &written))) | |
7eebc354 | 2839 | goto err; |
e26dc8e3 HL |
2840 | |
2841 | if (!qtest_fault_prepend_frame(h->qtf, frame_buf, written)) | |
7eebc354 | 2842 | goto err; |
e26dc8e3 | 2843 | |
7eebc354 HL |
2844 | ok = 1; |
2845 | err: | |
96b7df60 HL |
2846 | if (ok) |
2847 | WPACKET_finish(&wpkt); | |
2848 | else | |
2849 | WPACKET_cleanup(&wpkt); | |
7eebc354 | 2850 | return ok; |
e26dc8e3 HL |
2851 | } |
2852 | ||
2853 | static const struct script_op script_39[] = { | |
2854 | OP_S_SET_INJECT_PLAIN (script_39_inject_plain) | |
2855 | OP_C_SET_ALPN ("ossltest") | |
2856 | OP_C_CONNECT_WAIT () | |
2857 | OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE) | |
2858 | ||
2859 | OP_C_NEW_STREAM_BIDI (a, C_BIDI_ID(0)) | |
2860 | OP_C_WRITE (a, "apple", 5) | |
2861 | OP_S_BIND_STREAM_ID (a, C_BIDI_ID(0)) | |
2862 | OP_S_READ_EXPECT (a, "apple", 5) | |
2863 | ||
2864 | OP_SET_INJECT_WORD (0, 1) | |
2865 | OP_S_WRITE (a, "orange", 5) | |
2866 | ||
2867 | OP_C_EXPECT_CONN_CLOSE_INFO(QUIC_ERR_FRAME_ENCODING_ERROR,0,0) | |
2868 | ||
2869 | OP_END | |
2870 | }; | |
2871 | ||
cd5e4380 HL |
2872 | /* 40. Shutdown flush test */ |
2873 | static const unsigned char script_40_data[1024] = "strawberry"; | |
2874 | ||
2875 | static const struct script_op script_40[] = { | |
2876 | OP_C_SET_ALPN ("ossltest") | |
2877 | OP_C_CONNECT_WAIT () | |
2878 | OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE) | |
2879 | ||
2880 | OP_C_NEW_STREAM_BIDI (a, C_BIDI_ID(0)) | |
2881 | OP_C_WRITE (a, "apple", 5) | |
2882 | ||
2883 | OP_C_INHIBIT_TICK (1) | |
2884 | OP_C_SET_WRITE_BUF_SIZE (a, 1024 * 100 * 3) | |
2885 | ||
2886 | OP_BEGIN_REPEAT (100) | |
2887 | ||
2888 | OP_C_WRITE (a, script_40_data, sizeof(script_40_data)) | |
2889 | ||
2890 | OP_END_REPEAT () | |
2891 | ||
2892 | OP_C_CONCLUDE (a) | |
2893 | OP_C_SHUTDOWN_WAIT () /* disengages tick inhibition */ | |
2894 | ||
2895 | OP_S_BIND_STREAM_ID (a, C_BIDI_ID(0)) | |
2896 | OP_S_READ_EXPECT (a, "apple", 5) | |
2897 | ||
2898 | OP_BEGIN_REPEAT (100) | |
2899 | ||
2900 | OP_S_READ_EXPECT (a, script_40_data, sizeof(script_40_data)) | |
2901 | ||
2902 | OP_END_REPEAT () | |
2903 | ||
2904 | OP_S_EXPECT_FIN (a) | |
2905 | ||
2906 | OP_C_EXPECT_CONN_CLOSE_INFO(0, 1, 0) | |
2907 | OP_S_EXPECT_CONN_CLOSE_INFO(0, 1, 1) | |
2908 | ||
2909 | OP_END | |
2910 | }; | |
2911 | ||
ed835673 HL |
2912 | static const struct script_op *const scripts[] = { |
2913 | script_1, | |
2914 | script_2, | |
2915 | script_3, | |
2916 | script_4, | |
2917 | script_5, | |
2918 | script_6, | |
2919 | script_7, | |
2920 | script_8, | |
2921 | script_9, | |
2922 | script_10, | |
274bb489 HL |
2923 | script_11, |
2924 | script_12, | |
fca44cfc HL |
2925 | script_13, |
2926 | script_14, | |
0554f723 HL |
2927 | script_15, |
2928 | script_16, | |
693b23e3 HL |
2929 | script_17, |
2930 | script_18, | |
2525109f | 2931 | script_19, |
0345cac6 | 2932 | script_20, |
e26dc8e3 HL |
2933 | script_21, |
2934 | script_22, | |
2935 | script_23, | |
2936 | script_24, | |
2937 | script_25, | |
2938 | script_26, | |
2939 | script_27, | |
2940 | script_28, | |
2941 | script_29, | |
2942 | script_30, | |
2943 | script_31, | |
2944 | script_32, | |
2945 | script_33, | |
2946 | script_34, | |
2947 | script_35, | |
2948 | script_36, | |
2949 | script_37, | |
2950 | script_38, | |
8aa6a436 | 2951 | script_39, |
0786483a | 2952 | script_40, |
ed835673 HL |
2953 | }; |
2954 | ||
2955 | static int test_script(int idx) | |
2956 | { | |
97f30fd5 HL |
2957 | int script_idx = idx >> 1; |
2958 | int free_order = idx & 1; | |
0786483a HL |
2959 | char script_name[64]; |
2960 | ||
cd5e4380 | 2961 | snprintf(script_name, sizeof(script_name), "script %d", script_idx + 1); |
97f30fd5 HL |
2962 | |
2963 | TEST_info("Running script %d (order=%d)", script_idx + 1, free_order); | |
0786483a | 2964 | return run_script(scripts[script_idx], script_name, free_order); |
ed835673 HL |
2965 | } |
2966 | ||
e26dc8e3 HL |
2967 | /* Dynamically generated tests. */ |
2968 | static struct script_op dyn_frame_types_script[] = { | |
8aa6a436 | 2969 | OP_S_SET_INJECT_PLAIN (script_21_inject_plain) |
e26dc8e3 HL |
2970 | OP_SET_INJECT_WORD (0, 0) /* dynamic */ |
2971 | ||
2972 | OP_C_SET_ALPN ("ossltest") | |
2973 | OP_C_CONNECT_WAIT_OR_FAIL() | |
2974 | ||
2975 | OP_C_EXPECT_CONN_CLOSE_INFO(QUIC_ERR_FRAME_ENCODING_ERROR,0,0) | |
2976 | ||
2977 | OP_END | |
2978 | }; | |
2979 | ||
2980 | struct forbidden_frame_type { | |
2981 | uint64_t pkt_type, frame_type, expected_err; | |
2982 | }; | |
2983 | ||
2984 | static const struct forbidden_frame_type forbidden_frame_types[] = { | |
2985 | { QUIC_PKT_TYPE_INITIAL, OSSL_QUIC_VLINT_MAX, QUIC_ERR_FRAME_ENCODING_ERROR }, | |
2986 | { QUIC_PKT_TYPE_HANDSHAKE, OSSL_QUIC_VLINT_MAX, QUIC_ERR_FRAME_ENCODING_ERROR }, | |
2987 | { QUIC_PKT_TYPE_1RTT, OSSL_QUIC_VLINT_MAX, QUIC_ERR_FRAME_ENCODING_ERROR }, | |
2988 | ||
2989 | { QUIC_PKT_TYPE_INITIAL, OSSL_QUIC_FRAME_TYPE_STREAM, QUIC_ERR_PROTOCOL_VIOLATION }, | |
2990 | { QUIC_PKT_TYPE_INITIAL, OSSL_QUIC_FRAME_TYPE_RESET_STREAM, QUIC_ERR_PROTOCOL_VIOLATION }, | |
2991 | { QUIC_PKT_TYPE_INITIAL, OSSL_QUIC_FRAME_TYPE_STOP_SENDING, QUIC_ERR_PROTOCOL_VIOLATION }, | |
2992 | { QUIC_PKT_TYPE_INITIAL, OSSL_QUIC_FRAME_TYPE_NEW_TOKEN, QUIC_ERR_PROTOCOL_VIOLATION }, | |
2993 | { QUIC_PKT_TYPE_INITIAL, OSSL_QUIC_FRAME_TYPE_MAX_DATA, QUIC_ERR_PROTOCOL_VIOLATION }, | |
2994 | { QUIC_PKT_TYPE_INITIAL, OSSL_QUIC_FRAME_TYPE_MAX_STREAM_DATA, QUIC_ERR_PROTOCOL_VIOLATION }, | |
2995 | { QUIC_PKT_TYPE_INITIAL, OSSL_QUIC_FRAME_TYPE_MAX_STREAMS_BIDI, QUIC_ERR_PROTOCOL_VIOLATION }, | |
2996 | { QUIC_PKT_TYPE_INITIAL, OSSL_QUIC_FRAME_TYPE_MAX_STREAMS_UNI, QUIC_ERR_PROTOCOL_VIOLATION }, | |
2997 | { QUIC_PKT_TYPE_INITIAL, OSSL_QUIC_FRAME_TYPE_DATA_BLOCKED, QUIC_ERR_PROTOCOL_VIOLATION }, | |
2998 | { QUIC_PKT_TYPE_INITIAL, OSSL_QUIC_FRAME_TYPE_STREAM_DATA_BLOCKED, QUIC_ERR_PROTOCOL_VIOLATION }, | |
2999 | { QUIC_PKT_TYPE_INITIAL, OSSL_QUIC_FRAME_TYPE_STREAMS_BLOCKED_BIDI, QUIC_ERR_PROTOCOL_VIOLATION }, | |
3000 | { QUIC_PKT_TYPE_INITIAL, OSSL_QUIC_FRAME_TYPE_STREAMS_BLOCKED_UNI, QUIC_ERR_PROTOCOL_VIOLATION }, | |
3001 | { QUIC_PKT_TYPE_INITIAL, OSSL_QUIC_FRAME_TYPE_NEW_CONN_ID, QUIC_ERR_PROTOCOL_VIOLATION }, | |
3002 | { QUIC_PKT_TYPE_INITIAL, OSSL_QUIC_FRAME_TYPE_RETIRE_CONN_ID, QUIC_ERR_PROTOCOL_VIOLATION }, | |
3003 | { QUIC_PKT_TYPE_INITIAL, OSSL_QUIC_FRAME_TYPE_PATH_CHALLENGE, QUIC_ERR_PROTOCOL_VIOLATION }, | |
3004 | { QUIC_PKT_TYPE_INITIAL, OSSL_QUIC_FRAME_TYPE_PATH_RESPONSE, QUIC_ERR_PROTOCOL_VIOLATION }, | |
3005 | { QUIC_PKT_TYPE_INITIAL, OSSL_QUIC_FRAME_TYPE_CONN_CLOSE_APP, QUIC_ERR_PROTOCOL_VIOLATION }, | |
3006 | { QUIC_PKT_TYPE_INITIAL, OSSL_QUIC_FRAME_TYPE_HANDSHAKE_DONE, QUIC_ERR_PROTOCOL_VIOLATION }, | |
3007 | ||
3008 | { QUIC_PKT_TYPE_HANDSHAKE, OSSL_QUIC_FRAME_TYPE_STREAM, QUIC_ERR_PROTOCOL_VIOLATION }, | |
3009 | { QUIC_PKT_TYPE_HANDSHAKE, OSSL_QUIC_FRAME_TYPE_RESET_STREAM, QUIC_ERR_PROTOCOL_VIOLATION }, | |
3010 | { QUIC_PKT_TYPE_HANDSHAKE, OSSL_QUIC_FRAME_TYPE_STOP_SENDING, QUIC_ERR_PROTOCOL_VIOLATION }, | |
3011 | { QUIC_PKT_TYPE_HANDSHAKE, OSSL_QUIC_FRAME_TYPE_NEW_TOKEN, QUIC_ERR_PROTOCOL_VIOLATION }, | |
3012 | { QUIC_PKT_TYPE_HANDSHAKE, OSSL_QUIC_FRAME_TYPE_MAX_DATA, QUIC_ERR_PROTOCOL_VIOLATION }, | |
3013 | { QUIC_PKT_TYPE_HANDSHAKE, OSSL_QUIC_FRAME_TYPE_MAX_STREAM_DATA, QUIC_ERR_PROTOCOL_VIOLATION }, | |
3014 | { QUIC_PKT_TYPE_HANDSHAKE, OSSL_QUIC_FRAME_TYPE_MAX_STREAMS_BIDI, QUIC_ERR_PROTOCOL_VIOLATION }, | |
3015 | { QUIC_PKT_TYPE_HANDSHAKE, OSSL_QUIC_FRAME_TYPE_MAX_STREAMS_UNI, QUIC_ERR_PROTOCOL_VIOLATION }, | |
3016 | { QUIC_PKT_TYPE_HANDSHAKE, OSSL_QUIC_FRAME_TYPE_DATA_BLOCKED, QUIC_ERR_PROTOCOL_VIOLATION }, | |
3017 | { QUIC_PKT_TYPE_HANDSHAKE, OSSL_QUIC_FRAME_TYPE_STREAM_DATA_BLOCKED, QUIC_ERR_PROTOCOL_VIOLATION }, | |
3018 | { QUIC_PKT_TYPE_HANDSHAKE, OSSL_QUIC_FRAME_TYPE_STREAMS_BLOCKED_BIDI, QUIC_ERR_PROTOCOL_VIOLATION }, | |
3019 | { QUIC_PKT_TYPE_HANDSHAKE, OSSL_QUIC_FRAME_TYPE_STREAMS_BLOCKED_UNI, QUIC_ERR_PROTOCOL_VIOLATION }, | |
3020 | { QUIC_PKT_TYPE_HANDSHAKE, OSSL_QUIC_FRAME_TYPE_NEW_CONN_ID, QUIC_ERR_PROTOCOL_VIOLATION }, | |
3021 | { QUIC_PKT_TYPE_HANDSHAKE, OSSL_QUIC_FRAME_TYPE_RETIRE_CONN_ID, QUIC_ERR_PROTOCOL_VIOLATION }, | |
3022 | { QUIC_PKT_TYPE_HANDSHAKE, OSSL_QUIC_FRAME_TYPE_PATH_CHALLENGE, QUIC_ERR_PROTOCOL_VIOLATION }, | |
3023 | { QUIC_PKT_TYPE_HANDSHAKE, OSSL_QUIC_FRAME_TYPE_PATH_RESPONSE, QUIC_ERR_PROTOCOL_VIOLATION }, | |
3024 | { QUIC_PKT_TYPE_HANDSHAKE, OSSL_QUIC_FRAME_TYPE_CONN_CLOSE_APP, QUIC_ERR_PROTOCOL_VIOLATION }, | |
3025 | { QUIC_PKT_TYPE_HANDSHAKE, OSSL_QUIC_FRAME_TYPE_HANDSHAKE_DONE, QUIC_ERR_PROTOCOL_VIOLATION }, | |
3026 | ||
3027 | /* Client uses a zero-length CID so this is not allowed. */ | |
3028 | { QUIC_PKT_TYPE_1RTT, OSSL_QUIC_FRAME_TYPE_RETIRE_CONN_ID, QUIC_ERR_PROTOCOL_VIOLATION }, | |
3029 | }; | |
3030 | ||
3031 | static ossl_unused int test_dyn_frame_types(int idx) | |
3032 | { | |
3033 | size_t i; | |
0786483a | 3034 | char script_name[64]; |
e26dc8e3 HL |
3035 | struct script_op *s = dyn_frame_types_script; |
3036 | ||
3037 | for (i = 0; i < OSSL_NELEM(dyn_frame_types_script); ++i) | |
3038 | if (s[i].op == OPK_SET_INJECT_WORD) { | |
49a38dee | 3039 | s[i].arg1 = (size_t)forbidden_frame_types[idx].pkt_type; |
e26dc8e3 HL |
3040 | s[i].arg2 = forbidden_frame_types[idx].frame_type; |
3041 | } else if (s[i].op == OPK_C_EXPECT_CONN_CLOSE_INFO) { | |
3042 | s[i].arg2 = forbidden_frame_types[idx].expected_err; | |
3043 | } | |
3044 | ||
0786483a HL |
3045 | snprintf(script_name, sizeof(script_name), |
3046 | "dyn script %d", idx); | |
3047 | ||
3048 | return run_script(dyn_frame_types_script, script_name, 0); | |
e26dc8e3 HL |
3049 | } |
3050 | ||
ed835673 HL |
3051 | OPT_TEST_DECLARE_USAGE("certfile privkeyfile\n") |
3052 | ||
3053 | int setup_tests(void) | |
3054 | { | |
3055 | if (!test_skip_common_options()) { | |
3056 | TEST_error("Error parsing test options\n"); | |
3057 | return 0; | |
3058 | } | |
3059 | ||
3060 | if (!TEST_ptr(certfile = test_get_argument(0)) | |
3061 | || !TEST_ptr(keyfile = test_get_argument(1))) | |
3062 | return 0; | |
3063 | ||
e26dc8e3 | 3064 | ADD_ALL_TESTS(test_dyn_frame_types, OSSL_NELEM(forbidden_frame_types)); |
97f30fd5 | 3065 | ADD_ALL_TESTS(test_script, OSSL_NELEM(scripts) * 2); |
ed835673 HL |
3066 | return 1; |
3067 | } |