]>
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 | |
09a4b4b7 | 21 | #include "internal/numbers.h" /* UINT64_C */ |
ed835673 HL |
22 | |
23 | static const char *certfile, *keyfile; | |
24 | ||
a350db73 HL |
25 | #if defined(OPENSSL_THREADS) |
26 | struct child_thread_args { | |
27 | struct helper *h; | |
28 | const struct script_op *script; | |
0786483a | 29 | const char *script_name; |
a350db73 HL |
30 | int thread_idx; |
31 | ||
32 | CRYPTO_THREAD *t; | |
33 | CRYPTO_MUTEX *m; | |
34 | int testresult; | |
35 | int done; | |
5881dd2c | 36 | int s_checked_out; |
a350db73 HL |
37 | }; |
38 | #endif | |
39 | ||
ed835673 HL |
40 | typedef struct stream_info { |
41 | const char *name; | |
42 | SSL *c_stream; | |
43 | uint64_t s_stream_id; | |
44 | } STREAM_INFO; | |
45 | ||
46 | DEFINE_LHASH_OF_EX(STREAM_INFO); | |
47 | ||
48 | struct helper { | |
49 | int s_fd; | |
e26dc8e3 | 50 | BIO *s_net_bio, *s_net_bio_own, *s_qtf_wbio, *s_qtf_wbio_own; |
84f371a1 RL |
51 | /* The BIO_ADDR used for BIO_bind() */ |
52 | BIO_ADDR *s_net_bio_orig_addr; | |
53 | /* The resulting address, which is the one to connect to */ | |
ed835673 | 54 | BIO_ADDR *s_net_bio_addr; |
84f371a1 | 55 | |
5881dd2c HL |
56 | /* |
57 | * When doing a blocking mode test run, s_priv always points to the TSERVER | |
58 | * and s is NULL when the main thread should not be touching s_priv. | |
59 | */ | |
60 | QUIC_TSERVER *s, *s_priv; | |
ed835673 HL |
61 | LHASH_OF(STREAM_INFO) *s_streams; |
62 | ||
63 | int c_fd; | |
64 | BIO *c_net_bio, *c_net_bio_own; | |
65 | SSL_CTX *c_ctx; | |
66 | SSL *c_conn; | |
67 | LHASH_OF(STREAM_INFO) *c_streams; | |
68 | ||
a350db73 HL |
69 | #if defined(OPENSSL_THREADS) |
70 | struct child_thread_args *threads; | |
71 | size_t num_threads; | |
99d6b9f9 HL |
72 | CRYPTO_MUTEX *misc_m; |
73 | CRYPTO_CONDVAR *misc_cv; | |
a350db73 HL |
74 | #endif |
75 | ||
ed835673 | 76 | OSSL_TIME start_time; |
693b23e3 HL |
77 | |
78 | /* | |
79 | * This is a duration recording the amount of time we have skipped forwards | |
80 | * for testing purposes relative to the real ossl_time_now() clock. We add | |
81 | * a quantity of time to this every time we skip some time. | |
82 | */ | |
83 | CRYPTO_RWLOCK *time_lock; | |
84 | OSSL_TIME time_slip; /* protected by time_lock */ | |
85 | ||
e26dc8e3 HL |
86 | QTEST_FAULT *qtf; |
87 | ||
9715e3aa | 88 | int init, blocking, check_spin_again; |
e26dc8e3 HL |
89 | int free_order, need_injector; |
90 | ||
91 | int (*qtf_packet_plain_cb)(struct helper *h, QUIC_PKT_HDR *hdr, | |
92 | unsigned char *buf, size_t buf_len); | |
de56eebd HL |
93 | int (*qtf_handshake_cb)(struct helper *h, |
94 | unsigned char *buf, size_t buf_len); | |
69169cd9 HL |
95 | int (*qtf_datagram_cb)(struct helper *h, |
96 | BIO_MSG *m, size_t stride); | |
e26dc8e3 | 97 | uint64_t inject_word0, inject_word1; |
14551f1e | 98 | uint64_t scratch0, scratch1, fail_count; |
5881dd2c HL |
99 | #if defined(OPENSSL_THREADS) |
100 | struct { | |
101 | CRYPTO_THREAD *t; | |
102 | CRYPTO_MUTEX *m; | |
103 | CRYPTO_CONDVAR *c; | |
104 | int ready, stop; | |
105 | } server_thread; | |
106 | int s_checked_out; | |
107 | #endif | |
ed835673 HL |
108 | }; |
109 | ||
a350db73 HL |
110 | struct helper_local { |
111 | struct helper *h; | |
112 | LHASH_OF(STREAM_INFO) *c_streams; | |
113 | int thread_idx; | |
5881dd2c | 114 | const struct script_op *check_op; |
a350db73 HL |
115 | }; |
116 | ||
ed835673 HL |
117 | struct script_op { |
118 | uint32_t op; | |
119 | const void *arg0; | |
120 | size_t arg1; | |
5881dd2c | 121 | int (*check_func)(struct helper *h, struct helper_local *hl); |
ed835673 HL |
122 | const char *stream_name; |
123 | uint64_t arg2; | |
e26dc8e3 HL |
124 | int (*qtf_packet_plain_cb)(struct helper *h, QUIC_PKT_HDR *hdr, |
125 | unsigned char *buf, size_t buf_len); | |
de56eebd HL |
126 | int (*qtf_handshake_cb)(struct helper *h, |
127 | unsigned char *buf, size_t buf_len); | |
69169cd9 HL |
128 | int (*qtf_datagram_cb)(struct helper *h, |
129 | BIO_MSG *m, size_t stride); | |
ed835673 HL |
130 | }; |
131 | ||
132 | #define OPK_END 0 | |
133 | #define OPK_CHECK 1 | |
134 | #define OPK_C_SET_ALPN 2 | |
135 | #define OPK_C_CONNECT_WAIT 3 | |
136 | #define OPK_C_WRITE 4 | |
137 | #define OPK_S_WRITE 5 | |
138 | #define OPK_C_READ_EXPECT 6 | |
139 | #define OPK_S_READ_EXPECT 7 | |
140 | #define OPK_C_EXPECT_FIN 8 | |
141 | #define OPK_S_EXPECT_FIN 9 | |
142 | #define OPK_C_CONCLUDE 10 | |
143 | #define OPK_S_CONCLUDE 11 | |
144 | #define OPK_C_DETACH 12 | |
145 | #define OPK_C_ATTACH 13 | |
146 | #define OPK_C_NEW_STREAM 14 | |
147 | #define OPK_S_NEW_STREAM 15 | |
a350db73 | 148 | #define OPK_C_ACCEPT_STREAM_WAIT 16 |
ed835673 HL |
149 | #define OPK_C_ACCEPT_STREAM_NONE 17 |
150 | #define OPK_C_FREE_STREAM 18 | |
151 | #define OPK_C_SET_DEFAULT_STREAM_MODE 19 | |
83df44ae | 152 | #define OPK_C_SET_INCOMING_STREAM_POLICY 20 |
cd5e4380 | 153 | #define OPK_C_SHUTDOWN_WAIT 21 |
ed835673 HL |
154 | #define OPK_C_EXPECT_CONN_CLOSE_INFO 22 |
155 | #define OPK_S_EXPECT_CONN_CLOSE_INFO 23 | |
156 | #define OPK_S_BIND_STREAM_ID 24 | |
157 | #define OPK_C_WAIT_FOR_DATA 25 | |
158 | #define OPK_C_WRITE_FAIL 26 | |
159 | #define OPK_S_WRITE_FAIL 27 | |
160 | #define OPK_C_READ_FAIL 28 | |
161 | #define OPK_C_STREAM_RESET 29 | |
a350db73 HL |
162 | #define OPK_S_ACCEPT_STREAM_WAIT 30 |
163 | #define OPK_NEW_THREAD 31 | |
fca44cfc HL |
164 | #define OPK_BEGIN_REPEAT 32 |
165 | #define OPK_END_REPEAT 33 | |
166 | #define OPK_S_UNBIND_STREAM_ID 34 | |
0345cac6 TM |
167 | #define OPK_C_READ_FAIL_WAIT 35 |
168 | #define OPK_C_CLOSE_SOCKET 36 | |
169 | #define OPK_C_EXPECT_SSL_ERR 37 | |
170 | #define OPK_EXPECT_ERR_REASON 38 | |
171 | #define OPK_EXPECT_ERR_LIB 39 | |
172 | #define OPK_SLEEP 40 | |
2f018d14 | 173 | #define OPK_S_READ_FAIL 41 |
e26dc8e3 HL |
174 | #define OPK_S_SET_INJECT_PLAIN 42 |
175 | #define OPK_SET_INJECT_WORD 43 | |
cd5e4380 HL |
176 | #define OPK_C_INHIBIT_TICK 44 |
177 | #define OPK_C_SET_WRITE_BUF_SIZE 45 | |
de56eebd | 178 | #define OPK_S_SET_INJECT_HANDSHAKE 46 |
614c08c2 | 179 | #define OPK_S_NEW_TICKET 47 |
14551f1e | 180 | #define OPK_C_SKIP_IF_UNBOUND 48 |
69169cd9 | 181 | #define OPK_S_SET_INJECT_DATAGRAM 49 |
3bc38ba0 | 182 | #define OPK_S_SHUTDOWN 50 |
ed835673 HL |
183 | |
184 | #define EXPECT_CONN_CLOSE_APP (1U << 0) | |
185 | #define EXPECT_CONN_CLOSE_REMOTE (1U << 1) | |
186 | ||
14551f1e HL |
187 | /* OPK_C_NEW_STREAM */ |
188 | #define ALLOW_FAIL (1U << 16) | |
189 | ||
ed835673 HL |
190 | #define C_BIDI_ID(ordinal) \ |
191 | (((ordinal) << 2) | QUIC_STREAM_INITIATOR_CLIENT | QUIC_STREAM_DIR_BIDI) | |
192 | #define S_BIDI_ID(ordinal) \ | |
193 | (((ordinal) << 2) | QUIC_STREAM_INITIATOR_SERVER | QUIC_STREAM_DIR_BIDI) | |
194 | #define C_UNI_ID(ordinal) \ | |
195 | (((ordinal) << 2) | QUIC_STREAM_INITIATOR_CLIENT | QUIC_STREAM_DIR_UNI) | |
196 | #define S_UNI_ID(ordinal) \ | |
197 | (((ordinal) << 2) | QUIC_STREAM_INITIATOR_SERVER | QUIC_STREAM_DIR_UNI) | |
198 | ||
a350db73 HL |
199 | #define ANY_ID UINT64_MAX |
200 | ||
ed835673 HL |
201 | #define OP_END \ |
202 | {OPK_END} | |
203 | #define OP_CHECK(func, arg2) \ | |
204 | {OPK_CHECK, NULL, 0, (func), NULL, (arg2)}, | |
205 | #define OP_C_SET_ALPN(alpn) \ | |
206 | {OPK_C_SET_ALPN, (alpn), 0, NULL, NULL}, | |
207 | #define OP_C_CONNECT_WAIT() \ | |
208 | {OPK_C_CONNECT_WAIT, NULL, 0, NULL, NULL}, | |
e26dc8e3 HL |
209 | #define OP_C_CONNECT_WAIT_OR_FAIL() \ |
210 | {OPK_C_CONNECT_WAIT, NULL, 1, NULL, NULL}, | |
ed835673 HL |
211 | #define OP_C_WRITE(stream_name, buf, buf_len) \ |
212 | {OPK_C_WRITE, (buf), (buf_len), NULL, #stream_name}, | |
213 | #define OP_S_WRITE(stream_name, buf, buf_len) \ | |
214 | {OPK_S_WRITE, (buf), (buf_len), NULL, #stream_name}, | |
215 | #define OP_C_READ_EXPECT(stream_name, buf, buf_len) \ | |
216 | {OPK_C_READ_EXPECT, (buf), (buf_len), NULL, #stream_name}, | |
217 | #define OP_S_READ_EXPECT(stream_name, buf, buf_len) \ | |
218 | {OPK_S_READ_EXPECT, (buf), (buf_len), NULL, #stream_name}, | |
219 | #define OP_C_EXPECT_FIN(stream_name) \ | |
220 | {OPK_C_EXPECT_FIN, NULL, 0, NULL, #stream_name}, | |
221 | #define OP_S_EXPECT_FIN(stream_name) \ | |
222 | {OPK_S_EXPECT_FIN, NULL, 0, NULL, #stream_name}, | |
223 | #define OP_C_CONCLUDE(stream_name) \ | |
224 | {OPK_C_CONCLUDE, NULL, 0, NULL, #stream_name}, | |
225 | #define OP_S_CONCLUDE(stream_name) \ | |
226 | {OPK_S_CONCLUDE, NULL, 0, NULL, #stream_name}, | |
227 | #define OP_C_DETACH(stream_name) \ | |
228 | {OPK_C_DETACH, NULL, 0, NULL, #stream_name}, | |
229 | #define OP_C_ATTACH(stream_name) \ | |
230 | {OPK_C_ATTACH, NULL, 0, NULL, #stream_name}, | |
231 | #define OP_C_NEW_STREAM_BIDI(stream_name, expect_id) \ | |
232 | {OPK_C_NEW_STREAM, NULL, 0, NULL, #stream_name, (expect_id)}, | |
14551f1e HL |
233 | #define OP_C_NEW_STREAM_BIDI_EX(stream_name, expect_id, flags) \ |
234 | {OPK_C_NEW_STREAM, NULL, (flags), NULL, #stream_name, (expect_id)}, | |
ed835673 | 235 | #define OP_C_NEW_STREAM_UNI(stream_name, expect_id) \ |
14551f1e HL |
236 | {OPK_C_NEW_STREAM, NULL, SSL_STREAM_FLAG_UNI, \ |
237 | NULL, #stream_name, (expect_id)}, | |
238 | #define OP_C_NEW_STREAM_UNI_EX(stream_name, expect_id, flags) \ | |
239 | {OPK_C_NEW_STREAM, NULL, (flags) | SSL_STREAM_FLAG_UNI, \ | |
240 | NULL, #stream_name, (expect_id)}, | |
ed835673 HL |
241 | #define OP_S_NEW_STREAM_BIDI(stream_name, expect_id) \ |
242 | {OPK_S_NEW_STREAM, NULL, 0, NULL, #stream_name, (expect_id)}, | |
243 | #define OP_S_NEW_STREAM_UNI(stream_name, expect_id) \ | |
244 | {OPK_S_NEW_STREAM, NULL, 1, NULL, #stream_name, (expect_id)}, | |
a350db73 HL |
245 | #define OP_C_ACCEPT_STREAM_WAIT(stream_name) \ |
246 | {OPK_C_ACCEPT_STREAM_WAIT, NULL, 0, NULL, #stream_name}, | |
ed835673 HL |
247 | #define OP_C_ACCEPT_STREAM_NONE() \ |
248 | {OPK_C_ACCEPT_STREAM_NONE, NULL, 0, NULL, NULL}, | |
249 | #define OP_C_FREE_STREAM(stream_name) \ | |
250 | {OPK_C_FREE_STREAM, NULL, 0, NULL, #stream_name}, | |
251 | #define OP_C_SET_DEFAULT_STREAM_MODE(mode) \ | |
252 | {OPK_C_SET_DEFAULT_STREAM_MODE, NULL, (mode), NULL, NULL}, | |
83df44ae HL |
253 | #define OP_C_SET_INCOMING_STREAM_POLICY(policy) \ |
254 | {OPK_C_SET_INCOMING_STREAM_POLICY, NULL, (policy), NULL, NULL}, | |
3bc38ba0 HL |
255 | #define OP_C_SHUTDOWN_WAIT(reason, flags) \ |
256 | {OPK_C_SHUTDOWN_WAIT, (reason), (flags), NULL, NULL}, | |
ed835673 HL |
257 | #define OP_C_EXPECT_CONN_CLOSE_INFO(ec, app, remote) \ |
258 | {OPK_C_EXPECT_CONN_CLOSE_INFO, NULL, \ | |
259 | ((app) ? EXPECT_CONN_CLOSE_APP : 0) | \ | |
260 | ((remote) ? EXPECT_CONN_CLOSE_REMOTE : 0), \ | |
261 | NULL, NULL, (ec)}, | |
262 | #define OP_S_EXPECT_CONN_CLOSE_INFO(ec, app, remote) \ | |
263 | {OPK_S_EXPECT_CONN_CLOSE_INFO, NULL, \ | |
264 | ((app) ? EXPECT_CONN_CLOSE_APP : 0) | \ | |
265 | ((remote) ? EXPECT_CONN_CLOSE_REMOTE : 0), \ | |
266 | NULL, NULL, (ec)}, | |
267 | #define OP_S_BIND_STREAM_ID(stream_name, stream_id) \ | |
268 | {OPK_S_BIND_STREAM_ID, NULL, 0, NULL, #stream_name, (stream_id)}, | |
269 | #define OP_C_WAIT_FOR_DATA(stream_name) \ | |
270 | {OPK_C_WAIT_FOR_DATA, NULL, 0, NULL, #stream_name}, | |
271 | #define OP_C_WRITE_FAIL(stream_name) \ | |
272 | {OPK_C_WRITE_FAIL, NULL, 0, NULL, #stream_name}, | |
273 | #define OP_S_WRITE_FAIL(stream_name) \ | |
274 | {OPK_S_WRITE_FAIL, NULL, 0, NULL, #stream_name}, | |
275 | #define OP_C_READ_FAIL(stream_name) \ | |
276 | {OPK_C_READ_FAIL, NULL, 0, NULL, #stream_name}, | |
2f018d14 HL |
277 | #define OP_S_READ_FAIL(stream_name) \ |
278 | {OPK_S_READ_FAIL, NULL, 0, NULL, #stream_name}, | |
ed835673 HL |
279 | #define OP_C_STREAM_RESET(stream_name, aec) \ |
280 | {OPK_C_STREAM_RESET, NULL, 0, NULL, #stream_name, (aec)}, | |
a350db73 HL |
281 | #define OP_S_ACCEPT_STREAM_WAIT(stream_name) \ |
282 | {OPK_S_ACCEPT_STREAM_WAIT, NULL, 0, NULL, #stream_name}, | |
283 | #define OP_NEW_THREAD(num_threads, script) \ | |
fca44cfc HL |
284 | {OPK_NEW_THREAD, (script), (num_threads), NULL, NULL, 0 }, |
285 | #define OP_BEGIN_REPEAT(n) \ | |
286 | {OPK_BEGIN_REPEAT, NULL, (n)}, | |
287 | #define OP_END_REPEAT() \ | |
288 | {OPK_END_REPEAT}, | |
289 | #define OP_S_UNBIND_STREAM_ID(stream_name) \ | |
290 | {OPK_S_UNBIND_STREAM_ID, NULL, 0, NULL, #stream_name}, | |
0345cac6 TM |
291 | #define OP_C_READ_FAIL_WAIT(stream_name) \ |
292 | {OPK_C_READ_FAIL_WAIT, NULL, 0, NULL, #stream_name}, | |
293 | #define OP_C_CLOSE_SOCKET() \ | |
294 | {OPK_C_CLOSE_SOCKET}, | |
295 | #define OP_C_EXPECT_SSL_ERR(stream_name, err) \ | |
296 | {OPK_C_EXPECT_SSL_ERR, NULL, (err), NULL, #stream_name}, | |
297 | #define OP_EXPECT_ERR_REASON(err) \ | |
298 | {OPK_EXPECT_ERR_REASON, NULL, (err)}, | |
299 | #define OP_EXPECT_ERR_LIB(lib) \ | |
300 | {OPK_EXPECT_ERR_LIB, NULL, (lib)}, | |
301 | #define OP_SLEEP(ms) \ | |
302 | {OPK_SLEEP, NULL, 0, NULL, NULL, (ms)}, | |
e26dc8e3 HL |
303 | #define OP_S_SET_INJECT_PLAIN(f) \ |
304 | {OPK_S_SET_INJECT_PLAIN, NULL, 0, NULL, NULL, 0, (f)}, | |
305 | #define OP_SET_INJECT_WORD(w0, w1) \ | |
306 | {OPK_SET_INJECT_WORD, NULL, (w0), NULL, NULL, (w1), NULL}, | |
cd5e4380 HL |
307 | #define OP_C_INHIBIT_TICK(inhibit) \ |
308 | {OPK_C_INHIBIT_TICK, NULL, (inhibit), NULL, NULL, 0, NULL}, | |
309 | #define OP_C_SET_WRITE_BUF_SIZE(stream_name, size) \ | |
310 | {OPK_C_SET_WRITE_BUF_SIZE, NULL, (size), NULL, #stream_name}, | |
de56eebd HL |
311 | #define OP_S_SET_INJECT_HANDSHAKE(f) \ |
312 | {OPK_S_SET_INJECT_HANDSHAKE, NULL, 0, NULL, NULL, 0, NULL, (f)}, | |
614c08c2 MC |
313 | #define OP_S_NEW_TICKET() \ |
314 | {OPK_S_NEW_TICKET}, | |
14551f1e HL |
315 | #define OP_C_SKIP_IF_UNBOUND(stream_name, n) \ |
316 | {OPK_C_SKIP_IF_UNBOUND, NULL, (n), NULL, #stream_name}, | |
69169cd9 HL |
317 | #define OP_S_SET_INJECT_DATAGRAM(f) \ |
318 | {OPK_S_SET_INJECT_DATAGRAM, NULL, 0, NULL, NULL, 0, NULL, NULL, (f)}, | |
3bc38ba0 HL |
319 | #define OP_S_SHUTDOWN(error_code) \ |
320 | {OPK_S_SHUTDOWN, NULL, (error_code)}, | |
ed835673 | 321 | |
693b23e3 HL |
322 | static OSSL_TIME get_time(void *arg) |
323 | { | |
324 | struct helper *h = arg; | |
325 | OSSL_TIME t; | |
326 | ||
327 | if (!TEST_true(CRYPTO_THREAD_read_lock(h->time_lock))) | |
328 | return ossl_time_zero(); | |
329 | ||
330 | t = ossl_time_add(ossl_time_now(), h->time_slip); | |
331 | ||
332 | CRYPTO_THREAD_unlock(h->time_lock); | |
333 | return t; | |
334 | } | |
335 | ||
5881dd2c | 336 | static int skip_time_ms(struct helper *h, struct helper_local *hl) |
693b23e3 HL |
337 | { |
338 | if (!TEST_true(CRYPTO_THREAD_write_lock(h->time_lock))) | |
339 | return 0; | |
340 | ||
5881dd2c | 341 | h->time_slip = ossl_time_add(h->time_slip, ossl_ms2time(hl->check_op->arg2)); |
693b23e3 HL |
342 | |
343 | CRYPTO_THREAD_unlock(h->time_lock); | |
344 | return 1; | |
345 | } | |
346 | ||
5881dd2c HL |
347 | static QUIC_TSERVER *s_lock(struct helper *h, struct helper_local *hl); |
348 | static void s_unlock(struct helper *h, struct helper_local *hl); | |
349 | ||
350 | #define ACQUIRE_S() s_lock(h, hl) | |
351 | ||
352 | static int check_rejected(struct helper *h, struct helper_local *hl) | |
ed835673 | 353 | { |
5881dd2c | 354 | uint64_t stream_id = hl->check_op->arg2; |
ed835673 | 355 | |
5881dd2c HL |
356 | if (!ossl_quic_tserver_stream_has_peer_stop_sending(ACQUIRE_S(), stream_id, NULL) |
357 | || !ossl_quic_tserver_stream_has_peer_reset_stream(ACQUIRE_S(), stream_id, NULL)) { | |
9715e3aa | 358 | h->check_spin_again = 1; |
ed835673 | 359 | return 0; |
9715e3aa | 360 | } |
ed835673 HL |
361 | |
362 | return 1; | |
363 | } | |
364 | ||
5881dd2c | 365 | static int check_stream_reset(struct helper *h, struct helper_local *hl) |
ed835673 | 366 | { |
5881dd2c | 367 | uint64_t stream_id = hl->check_op->arg2, aec = 0; |
ed835673 | 368 | |
5881dd2c | 369 | if (!ossl_quic_tserver_stream_has_peer_reset_stream(ACQUIRE_S(), stream_id, &aec)) { |
9715e3aa HL |
370 | h->check_spin_again = 1; |
371 | return 0; | |
372 | } | |
373 | ||
374 | return TEST_uint64_t_eq(aec, 42); | |
ed835673 HL |
375 | } |
376 | ||
5881dd2c | 377 | static int check_stream_stopped(struct helper *h, struct helper_local *hl) |
ed835673 | 378 | { |
5881dd2c | 379 | uint64_t stream_id = hl->check_op->arg2; |
ed835673 | 380 | |
5881dd2c | 381 | if (!ossl_quic_tserver_stream_has_peer_stop_sending(ACQUIRE_S(), stream_id, NULL)) { |
9715e3aa HL |
382 | h->check_spin_again = 1; |
383 | return 0; | |
384 | } | |
385 | ||
386 | return 1; | |
ed835673 HL |
387 | } |
388 | ||
5881dd2c | 389 | static int override_key_update(struct helper *h, struct helper_local *hl) |
693b23e3 HL |
390 | { |
391 | QUIC_CHANNEL *ch = ossl_quic_conn_get_channel(h->c_conn); | |
392 | ||
5881dd2c | 393 | ossl_quic_channel_set_txku_threshold_override(ch, hl->check_op->arg2); |
693b23e3 HL |
394 | return 1; |
395 | } | |
396 | ||
5881dd2c | 397 | static int trigger_key_update(struct helper *h, struct helper_local *hl) |
2525109f HL |
398 | { |
399 | if (!TEST_true(SSL_key_update(h->c_conn, SSL_KEY_UPDATE_REQUESTED))) | |
400 | return 0; | |
401 | ||
402 | return 1; | |
403 | } | |
404 | ||
5881dd2c | 405 | static int check_key_update_ge(struct helper *h, struct helper_local *hl) |
693b23e3 HL |
406 | { |
407 | QUIC_CHANNEL *ch = ossl_quic_conn_get_channel(h->c_conn); | |
408 | int64_t txke = (int64_t)ossl_quic_channel_get_tx_key_epoch(ch); | |
409 | int64_t rxke = (int64_t)ossl_quic_channel_get_rx_key_epoch(ch); | |
410 | int64_t diff = txke - rxke; | |
411 | ||
412 | /* | |
413 | * TXKE must always be equal to or ahead of RXKE. | |
414 | * It can be ahead of RXKE by at most 1. | |
415 | */ | |
416 | if (!TEST_int64_t_ge(diff, 0) || !TEST_int64_t_le(diff, 1)) | |
417 | return 0; | |
418 | ||
419 | /* Caller specifies a minimum number of RXKEs which must have happened. */ | |
5881dd2c | 420 | if (!TEST_uint64_t_ge((uint64_t)rxke, hl->check_op->arg2)) |
693b23e3 HL |
421 | return 0; |
422 | ||
423 | return 1; | |
424 | } | |
425 | ||
5881dd2c | 426 | static int check_key_update_lt(struct helper *h, struct helper_local *hl) |
693b23e3 HL |
427 | { |
428 | QUIC_CHANNEL *ch = ossl_quic_conn_get_channel(h->c_conn); | |
429 | uint64_t txke = ossl_quic_channel_get_tx_key_epoch(ch); | |
430 | ||
431 | /* Caller specifies a maximum number of TXKEs which must have happened. */ | |
5881dd2c | 432 | if (!TEST_uint64_t_lt(txke, hl->check_op->arg2)) |
693b23e3 HL |
433 | return 0; |
434 | ||
435 | return 1; | |
436 | } | |
437 | ||
ed835673 HL |
438 | static unsigned long stream_info_hash(const STREAM_INFO *info) |
439 | { | |
440 | return OPENSSL_LH_strhash(info->name); | |
441 | } | |
442 | ||
443 | static int stream_info_cmp(const STREAM_INFO *a, const STREAM_INFO *b) | |
444 | { | |
445 | return strcmp(a->name, b->name); | |
446 | } | |
447 | ||
448 | static void cleanup_stream(STREAM_INFO *info) | |
449 | { | |
450 | SSL_free(info->c_stream); | |
451 | OPENSSL_free(info); | |
452 | } | |
453 | ||
454 | static void helper_cleanup_streams(LHASH_OF(STREAM_INFO) **lh) | |
455 | { | |
456 | if (*lh == NULL) | |
457 | return; | |
458 | ||
459 | lh_STREAM_INFO_doall(*lh, cleanup_stream); | |
460 | lh_STREAM_INFO_free(*lh); | |
461 | *lh = NULL; | |
462 | } | |
463 | ||
a350db73 HL |
464 | #if defined(OPENSSL_THREADS) |
465 | static CRYPTO_THREAD_RETVAL run_script_child_thread(void *arg); | |
466 | ||
467 | static int join_threads(struct child_thread_args *threads, size_t num_threads) | |
468 | { | |
469 | int ok = 1; | |
470 | size_t i; | |
471 | CRYPTO_THREAD_RETVAL rv; | |
472 | ||
473 | for (i = 0; i < num_threads; ++i) { | |
474 | if (threads[i].t != NULL) { | |
475 | ossl_crypto_thread_native_join(threads[i].t, &rv); | |
476 | ||
477 | if (!threads[i].testresult) | |
478 | /* Do not log failure here, worker will do it. */ | |
479 | ok = 0; | |
480 | ||
481 | ossl_crypto_thread_native_clean(threads[i].t); | |
482 | threads[i].t = NULL; | |
483 | } | |
484 | ||
485 | ossl_crypto_mutex_free(&threads[i].m); | |
486 | } | |
487 | ||
488 | return ok; | |
489 | } | |
5881dd2c HL |
490 | |
491 | static int join_server_thread(struct helper *h) | |
492 | { | |
493 | CRYPTO_THREAD_RETVAL rv; | |
494 | ||
495 | if (h->server_thread.t == NULL) | |
496 | return 1; | |
497 | ||
498 | ossl_crypto_mutex_lock(h->server_thread.m); | |
499 | h->server_thread.stop = 1; | |
500 | ossl_crypto_mutex_unlock(h->server_thread.m); | |
501 | ossl_crypto_condvar_signal(h->server_thread.c); | |
502 | ||
503 | ossl_crypto_thread_native_join(h->server_thread.t, &rv); | |
504 | ossl_crypto_thread_native_clean(h->server_thread.t); | |
505 | h->server_thread.t = NULL; | |
506 | return 1; | |
507 | } | |
508 | ||
509 | /* Ensure the server-state lock is currently held. Idempotent. */ | |
510 | static int *s_checked_out_p(struct helper *h, int thread_idx) | |
511 | { | |
512 | return (thread_idx < 0) ? &h->s_checked_out | |
513 | : &h->threads[thread_idx].s_checked_out; | |
514 | } | |
515 | ||
516 | static QUIC_TSERVER *s_lock(struct helper *h, struct helper_local *hl) | |
517 | { | |
518 | int *p_checked_out = s_checked_out_p(h, hl->thread_idx); | |
519 | ||
520 | if (h->server_thread.m == NULL || *p_checked_out) | |
521 | return h->s; | |
522 | ||
523 | ossl_crypto_mutex_lock(h->server_thread.m); | |
524 | h->s = h->s_priv; | |
525 | *p_checked_out = 1; | |
526 | return h->s; | |
527 | } | |
528 | ||
529 | /* Ensure the server-state lock is currently not held. Idempotent. */ | |
530 | static void s_unlock(struct helper *h, struct helper_local *hl) | |
531 | { | |
532 | int *p_checked_out = s_checked_out_p(h, hl->thread_idx); | |
533 | ||
534 | if (h->server_thread.m == NULL || !*p_checked_out) | |
535 | return; | |
536 | ||
537 | *p_checked_out = 0; | |
538 | h->s = NULL; | |
539 | ossl_crypto_mutex_unlock(h->server_thread.m); | |
540 | } | |
541 | ||
542 | static unsigned int server_helper_thread(void *arg) | |
543 | { | |
544 | struct helper *h = arg; | |
545 | ||
546 | ossl_crypto_mutex_lock(h->server_thread.m); | |
547 | ||
548 | for (;;) { | |
549 | int ready, stop; | |
550 | ||
551 | ready = h->server_thread.ready; | |
552 | stop = h->server_thread.stop; | |
553 | ||
554 | if (stop) | |
555 | break; | |
556 | ||
557 | if (!ready) { | |
558 | ossl_crypto_condvar_wait(h->server_thread.c, h->server_thread.m); | |
559 | continue; | |
560 | } | |
561 | ||
562 | ossl_quic_tserver_tick(h->s_priv); | |
563 | ossl_crypto_mutex_unlock(h->server_thread.m); | |
025535ec HL |
564 | /* |
565 | * Give the main thread an opportunity to get the mutex, which is | |
566 | * sometimes necessary in some script operations. | |
567 | */ | |
5881dd2c HL |
568 | OSSL_sleep(1); |
569 | ossl_crypto_mutex_lock(h->server_thread.m); | |
570 | } | |
571 | ||
572 | ossl_crypto_mutex_unlock(h->server_thread.m); | |
573 | return 1; | |
574 | } | |
575 | ||
576 | #else | |
577 | ||
578 | static QUIC_TSERVER *s_lock(struct helper *h, struct helper_local *hl) | |
579 | { | |
580 | return h->s; | |
581 | } | |
582 | ||
583 | static void s_unlock(struct helper *h, struct helper_local *hl) | |
584 | {} | |
585 | ||
a350db73 HL |
586 | #endif |
587 | ||
ed835673 HL |
588 | static void helper_cleanup(struct helper *h) |
589 | { | |
a350db73 HL |
590 | #if defined(OPENSSL_THREADS) |
591 | join_threads(h->threads, h->num_threads); | |
5881dd2c | 592 | join_server_thread(h); |
a350db73 HL |
593 | OPENSSL_free(h->threads); |
594 | h->threads = NULL; | |
595 | h->num_threads = 0; | |
596 | #endif | |
597 | ||
97f30fd5 HL |
598 | if (h->free_order == 0) { |
599 | /* order 0: streams, then conn */ | |
600 | helper_cleanup_streams(&h->c_streams); | |
601 | ||
602 | SSL_free(h->c_conn); | |
603 | h->c_conn = NULL; | |
604 | } else { | |
605 | /* order 1: conn, then streams */ | |
606 | SSL_free(h->c_conn); | |
607 | h->c_conn = NULL; | |
608 | ||
609 | helper_cleanup_streams(&h->c_streams); | |
610 | } | |
ed835673 | 611 | |
97f30fd5 | 612 | helper_cleanup_streams(&h->s_streams); |
5881dd2c HL |
613 | ossl_quic_tserver_free(h->s_priv); |
614 | h->s_priv = h->s = NULL; | |
ed835673 HL |
615 | |
616 | BIO_free(h->s_net_bio_own); | |
617 | h->s_net_bio_own = NULL; | |
618 | ||
619 | BIO_free(h->c_net_bio_own); | |
620 | h->c_net_bio_own = NULL; | |
621 | ||
e26dc8e3 HL |
622 | BIO_free(h->s_qtf_wbio_own); |
623 | h->s_qtf_wbio_own = NULL; | |
624 | ||
1d547f8f HL |
625 | qtest_fault_free(h->qtf); |
626 | h->qtf = NULL; | |
7eebc354 | 627 | |
ed835673 HL |
628 | if (h->s_fd >= 0) { |
629 | BIO_closesocket(h->s_fd); | |
630 | h->s_fd = -1; | |
631 | } | |
632 | ||
633 | if (h->c_fd >= 0) { | |
634 | BIO_closesocket(h->c_fd); | |
635 | h->c_fd = -1; | |
636 | } | |
637 | ||
638 | BIO_ADDR_free(h->s_net_bio_addr); | |
639 | h->s_net_bio_addr = NULL; | |
84f371a1 RL |
640 | BIO_ADDR_free(h->s_net_bio_orig_addr); |
641 | h->s_net_bio_orig_addr = NULL; | |
ed835673 HL |
642 | |
643 | SSL_CTX_free(h->c_ctx); | |
644 | h->c_ctx = NULL; | |
693b23e3 HL |
645 | |
646 | CRYPTO_THREAD_lock_free(h->time_lock); | |
647 | h->time_lock = NULL; | |
5881dd2c HL |
648 | |
649 | #if defined(OPENSSL_THREADS) | |
99d6b9f9 HL |
650 | ossl_crypto_mutex_free(&h->misc_m); |
651 | ossl_crypto_condvar_free(&h->misc_cv); | |
5881dd2c HL |
652 | ossl_crypto_mutex_free(&h->server_thread.m); |
653 | ossl_crypto_condvar_free(&h->server_thread.c); | |
654 | #endif | |
ed835673 HL |
655 | } |
656 | ||
5881dd2c HL |
657 | static int helper_init(struct helper *h, int free_order, int blocking, |
658 | int need_injector) | |
ed835673 | 659 | { |
ed835673 HL |
660 | struct in_addr ina = {0}; |
661 | QUIC_TSERVER_ARGS s_args = {0}; | |
84f371a1 | 662 | union BIO_sock_info_u info; |
ed835673 HL |
663 | |
664 | memset(h, 0, sizeof(*h)); | |
665 | h->c_fd = -1; | |
666 | h->s_fd = -1; | |
97f30fd5 | 667 | h->free_order = free_order; |
5881dd2c | 668 | h->blocking = blocking; |
e26dc8e3 | 669 | h->need_injector = need_injector; |
693b23e3 HL |
670 | h->time_slip = ossl_time_zero(); |
671 | ||
672 | if (!TEST_ptr(h->time_lock = CRYPTO_THREAD_lock_new())) | |
673 | goto err; | |
ed835673 HL |
674 | |
675 | if (!TEST_ptr(h->s_streams = lh_STREAM_INFO_new(stream_info_hash, | |
676 | stream_info_cmp))) | |
677 | goto err; | |
678 | ||
679 | if (!TEST_ptr(h->c_streams = lh_STREAM_INFO_new(stream_info_hash, | |
680 | stream_info_cmp))) | |
681 | goto err; | |
682 | ||
683 | ina.s_addr = htonl(0x7f000001UL); | |
684 | ||
685 | h->s_fd = BIO_socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP, 0); | |
686 | if (!TEST_int_ge(h->s_fd, 0)) | |
687 | goto err; | |
688 | ||
689 | if (!TEST_true(BIO_socket_nbio(h->s_fd, 1))) | |
690 | goto err; | |
691 | ||
84f371a1 RL |
692 | if (!TEST_ptr(h->s_net_bio_orig_addr = BIO_ADDR_new()) |
693 | || !TEST_ptr(h->s_net_bio_addr = BIO_ADDR_new())) | |
694 | goto err; | |
695 | ||
696 | if (!TEST_true(BIO_ADDR_rawmake(h->s_net_bio_orig_addr, AF_INET, | |
697 | &ina, sizeof(ina), 0))) | |
ed835673 HL |
698 | goto err; |
699 | ||
84f371a1 | 700 | if (!TEST_true(BIO_bind(h->s_fd, h->s_net_bio_orig_addr, 0))) |
ed835673 HL |
701 | goto err; |
702 | ||
84f371a1 RL |
703 | info.addr = h->s_net_bio_addr; |
704 | if (!TEST_true(BIO_sock_info(h->s_fd, BIO_SOCK_INFO_ADDRESS, &info))) | |
ed835673 HL |
705 | goto err; |
706 | ||
707 | if (!TEST_int_gt(BIO_ADDR_rawport(h->s_net_bio_addr), 0)) | |
708 | goto err; | |
709 | ||
710 | if (!TEST_ptr(h->s_net_bio = h->s_net_bio_own = BIO_new_dgram(h->s_fd, 0))) | |
711 | goto err; | |
712 | ||
713 | if (!BIO_up_ref(h->s_net_bio)) | |
714 | goto err; | |
715 | ||
e26dc8e3 HL |
716 | if (need_injector) { |
717 | h->s_qtf_wbio = h->s_qtf_wbio_own = BIO_new(qtest_get_bio_method()); | |
718 | if (!TEST_ptr(h->s_qtf_wbio)) | |
719 | goto err; | |
720 | ||
721 | if (!TEST_ptr(BIO_push(h->s_qtf_wbio, h->s_net_bio))) | |
722 | goto err; | |
723 | ||
724 | s_args.net_wbio = h->s_qtf_wbio; | |
725 | } else { | |
726 | s_args.net_wbio = h->s_net_bio; | |
727 | } | |
728 | ||
693b23e3 | 729 | s_args.net_rbio = h->s_net_bio; |
37f27b91 | 730 | s_args.alpn = NULL; |
693b23e3 HL |
731 | s_args.now_cb = get_time; |
732 | s_args.now_cb_arg = h; | |
829eec9f | 733 | s_args.ctx = NULL; |
ed835673 | 734 | |
5881dd2c | 735 | if (!TEST_ptr(h->s_priv = ossl_quic_tserver_new(&s_args, certfile, keyfile))) |
ed835673 HL |
736 | goto err; |
737 | ||
5881dd2c HL |
738 | if (!blocking) |
739 | h->s = h->s_priv; | |
740 | ||
e26dc8e3 | 741 | if (need_injector) { |
5881dd2c | 742 | h->qtf = qtest_create_injector(h->s_priv); |
e26dc8e3 HL |
743 | if (!TEST_ptr(h->qtf)) |
744 | goto err; | |
745 | ||
746 | BIO_set_data(h->s_qtf_wbio, h->qtf); | |
747 | } | |
748 | ||
7eebc354 HL |
749 | if (!need_injector) |
750 | h->s_net_bio_own = NULL; | |
751 | ||
e26dc8e3 | 752 | h->s_qtf_wbio_own = NULL; |
ed835673 HL |
753 | |
754 | h->c_fd = BIO_socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP, 0); | |
755 | if (!TEST_int_ge(h->c_fd, 0)) | |
756 | goto err; | |
757 | ||
758 | if (!TEST_true(BIO_socket_nbio(h->c_fd, 1))) | |
759 | goto err; | |
760 | ||
761 | if (!TEST_ptr(h->c_net_bio = h->c_net_bio_own = BIO_new_dgram(h->c_fd, 0))) | |
762 | goto err; | |
763 | ||
764 | if (!TEST_true(BIO_dgram_set_peer(h->c_net_bio, h->s_net_bio_addr))) | |
765 | goto err; | |
766 | ||
ed835673 HL |
767 | if (!TEST_ptr(h->c_ctx = SSL_CTX_new(OSSL_QUIC_client_method()))) |
768 | goto err; | |
769 | ||
770 | if (!TEST_ptr(h->c_conn = SSL_new(h->c_ctx))) | |
771 | goto err; | |
772 | ||
693b23e3 HL |
773 | /* Use custom time function for virtual time skip. */ |
774 | if (!TEST_true(ossl_quic_conn_set_override_now_cb(h->c_conn, get_time, h))) | |
775 | goto err; | |
776 | ||
ed835673 HL |
777 | /* Takes ownership of our reference to the BIO. */ |
778 | SSL_set0_rbio(h->c_conn, h->c_net_bio); | |
779 | h->c_net_bio_own = NULL; | |
780 | ||
781 | if (!TEST_true(BIO_up_ref(h->c_net_bio))) | |
782 | goto err; | |
783 | ||
784 | SSL_set0_wbio(h->c_conn, h->c_net_bio); | |
785 | ||
5881dd2c HL |
786 | if (!TEST_true(SSL_set_blocking_mode(h->c_conn, h->blocking))) |
787 | goto err; | |
788 | ||
99d6b9f9 HL |
789 | #if defined(OPENSSL_THREADS) |
790 | if (!TEST_ptr(h->misc_m = ossl_crypto_mutex_new())) | |
791 | goto err; | |
792 | if (!TEST_ptr(h->misc_cv = ossl_crypto_condvar_new())) | |
793 | goto err; | |
794 | #endif | |
795 | ||
5881dd2c HL |
796 | if (h->blocking) { |
797 | #if defined(OPENSSL_THREADS) | |
798 | if (!TEST_ptr(h->server_thread.m = ossl_crypto_mutex_new())) | |
799 | goto err; | |
800 | ||
801 | if (!TEST_ptr(h->server_thread.c = ossl_crypto_condvar_new())) | |
802 | goto err; | |
803 | ||
804 | h->server_thread.t | |
805 | = ossl_crypto_thread_native_start(server_helper_thread, h, 1); | |
806 | if (!TEST_ptr(h->server_thread.t)) | |
807 | goto err; | |
808 | #else | |
809 | TEST_error("cannot support blocking mode without threads"); | |
ed835673 | 810 | goto err; |
5881dd2c HL |
811 | #endif |
812 | } | |
ed835673 HL |
813 | |
814 | h->start_time = ossl_time_now(); | |
815 | h->init = 1; | |
816 | return 1; | |
817 | ||
818 | err: | |
819 | helper_cleanup(h); | |
820 | return 0; | |
821 | } | |
822 | ||
a350db73 HL |
823 | static int helper_local_init(struct helper_local *hl, struct helper *h, |
824 | int thread_idx) | |
825 | { | |
826 | hl->h = h; | |
827 | hl->c_streams = NULL; | |
828 | hl->thread_idx = thread_idx; | |
829 | ||
830 | if (!TEST_ptr(h)) | |
831 | return 0; | |
832 | ||
833 | if (thread_idx < 0) { | |
834 | hl->c_streams = h->c_streams; | |
835 | } else { | |
836 | if (!TEST_ptr(hl->c_streams = lh_STREAM_INFO_new(stream_info_hash, | |
837 | stream_info_cmp))) | |
838 | return 0; | |
839 | } | |
840 | ||
841 | return 1; | |
842 | } | |
843 | ||
844 | static void helper_local_cleanup(struct helper_local *hl) | |
845 | { | |
846 | if (hl->h == NULL) | |
847 | return; | |
848 | ||
849 | if (hl->thread_idx >= 0) | |
850 | helper_cleanup_streams(&hl->c_streams); | |
851 | ||
852 | hl->h = NULL; | |
853 | } | |
854 | ||
ed835673 HL |
855 | static STREAM_INFO *get_stream_info(LHASH_OF(STREAM_INFO) *lh, |
856 | const char *stream_name) | |
857 | { | |
858 | STREAM_INFO key, *info; | |
859 | ||
860 | if (!TEST_ptr(stream_name)) | |
861 | return NULL; | |
862 | ||
863 | if (!strcmp(stream_name, "DEFAULT")) | |
864 | return NULL; | |
865 | ||
866 | key.name = stream_name; | |
867 | info = lh_STREAM_INFO_retrieve(lh, &key); | |
868 | if (info == NULL) { | |
869 | info = OPENSSL_zalloc(sizeof(*info)); | |
870 | if (info == NULL) | |
871 | return NULL; | |
872 | ||
873 | info->name = stream_name; | |
874 | info->s_stream_id = UINT64_MAX; | |
875 | lh_STREAM_INFO_insert(lh, info); | |
876 | } | |
877 | ||
878 | return info; | |
879 | } | |
880 | ||
a350db73 HL |
881 | static int helper_local_set_c_stream(struct helper_local *hl, |
882 | const char *stream_name, | |
883 | SSL *c_stream) | |
ed835673 | 884 | { |
a350db73 | 885 | STREAM_INFO *info = get_stream_info(hl->c_streams, stream_name); |
ed835673 HL |
886 | |
887 | if (info == NULL) | |
888 | return 0; | |
889 | ||
890 | info->c_stream = c_stream; | |
891 | info->s_stream_id = UINT64_MAX; | |
892 | return 1; | |
893 | } | |
894 | ||
a350db73 HL |
895 | static SSL *helper_local_get_c_stream(struct helper_local *hl, |
896 | const char *stream_name) | |
ed835673 HL |
897 | { |
898 | STREAM_INFO *info; | |
899 | ||
900 | if (!strcmp(stream_name, "DEFAULT")) | |
a350db73 | 901 | return hl->h->c_conn; |
ed835673 | 902 | |
a350db73 | 903 | info = get_stream_info(hl->c_streams, stream_name); |
ed835673 HL |
904 | if (info == NULL) |
905 | return NULL; | |
906 | ||
907 | return info->c_stream; | |
908 | } | |
909 | ||
910 | static int | |
911 | helper_set_s_stream(struct helper *h, const char *stream_name, | |
912 | uint64_t s_stream_id) | |
913 | { | |
914 | STREAM_INFO *info; | |
915 | ||
916 | if (!strcmp(stream_name, "DEFAULT")) | |
917 | return 0; | |
918 | ||
919 | info = get_stream_info(h->s_streams, stream_name); | |
920 | if (info == NULL) | |
921 | return 0; | |
922 | ||
923 | info->c_stream = NULL; | |
924 | info->s_stream_id = s_stream_id; | |
925 | return 1; | |
926 | } | |
927 | ||
928 | static uint64_t helper_get_s_stream(struct helper *h, const char *stream_name) | |
929 | { | |
930 | STREAM_INFO *info; | |
931 | ||
932 | if (!strcmp(stream_name, "DEFAULT")) | |
933 | return UINT64_MAX; | |
934 | ||
935 | info = get_stream_info(h->s_streams, stream_name); | |
936 | if (info == NULL) | |
937 | return UINT64_MAX; | |
938 | ||
939 | return info->s_stream_id; | |
940 | } | |
941 | ||
e26dc8e3 HL |
942 | static int helper_packet_plain_listener(QTEST_FAULT *qtf, QUIC_PKT_HDR *hdr, |
943 | unsigned char *buf, size_t buf_len, | |
944 | void *arg) | |
945 | { | |
946 | struct helper *h = arg; | |
947 | ||
948 | return h->qtf_packet_plain_cb(h, hdr, buf, buf_len); | |
949 | } | |
950 | ||
de56eebd HL |
951 | static int helper_handshake_listener(QTEST_FAULT *fault, |
952 | unsigned char *buf, size_t buf_len, | |
953 | void *arg) | |
954 | { | |
955 | struct helper *h = arg; | |
956 | ||
957 | return h->qtf_handshake_cb(h, buf, buf_len); | |
958 | } | |
959 | ||
69169cd9 HL |
960 | static int helper_datagram_listener(QTEST_FAULT *fault, |
961 | BIO_MSG *msg, size_t stride, | |
962 | void *arg) | |
963 | { | |
964 | struct helper *h = arg; | |
965 | ||
966 | return h->qtf_datagram_cb(h, msg, stride); | |
967 | } | |
968 | ||
ed835673 HL |
969 | static int is_want(SSL *s, int ret) |
970 | { | |
971 | int ec = SSL_get_error(s, ret); | |
972 | ||
973 | return ec == SSL_ERROR_WANT_READ || ec == SSL_ERROR_WANT_WRITE; | |
974 | } | |
975 | ||
9ff81610 HL |
976 | static int check_consistent_want(SSL *s, int ret) |
977 | { | |
978 | int ec = SSL_get_error(s, ret); | |
979 | int w = SSL_want(s); | |
980 | ||
981 | int ok = TEST_true( | |
982 | (ec == SSL_ERROR_NONE && w == SSL_NOTHING) | |
983 | || (ec == SSL_ERROR_ZERO_RETURN && w == SSL_NOTHING) | |
984 | || (ec == SSL_ERROR_SSL && w == SSL_NOTHING) | |
985 | || (ec == SSL_ERROR_SYSCALL && w == SSL_NOTHING) | |
986 | || (ec == SSL_ERROR_WANT_READ && w == SSL_READING) | |
987 | || (ec == SSL_ERROR_WANT_WRITE && w == SSL_WRITING) | |
988 | || (ec == SSL_ERROR_WANT_CLIENT_HELLO_CB && w == SSL_CLIENT_HELLO_CB) | |
989 | || (ec == SSL_ERROR_WANT_X509_LOOKUP && w == SSL_X509_LOOKUP) | |
990 | || (ec == SSL_ERROR_WANT_RETRY_VERIFY && w == SSL_RETRY_VERIFY) | |
991 | ); | |
992 | ||
993 | if (!ok) | |
994 | TEST_error("got error=%d, want=%d", ec, w); | |
995 | ||
996 | return ok; | |
997 | } | |
998 | ||
a350db73 | 999 | static int run_script_worker(struct helper *h, const struct script_op *script, |
0786483a | 1000 | const char *script_name, |
a350db73 | 1001 | int thread_idx) |
ed835673 | 1002 | { |
ed835673 | 1003 | int testresult = 0; |
ed835673 HL |
1004 | unsigned char *tmp_buf = NULL; |
1005 | int connect_started = 0; | |
9715e3aa | 1006 | size_t offset = 0; |
a350db73 HL |
1007 | size_t op_idx = 0; |
1008 | const struct script_op *op = NULL; | |
629b408c HL |
1009 | int no_advance = 0, first = 1; |
1010 | #if defined(OPENSSL_THREADS) | |
1011 | int end_wait_warning = 0; | |
1012 | #endif | |
a350db73 | 1013 | OSSL_TIME op_start_time = ossl_time_zero(), op_deadline = ossl_time_zero(); |
5881dd2c | 1014 | struct helper_local hl_, *hl = &hl_; |
fca44cfc HL |
1015 | #define REPEAT_SLOTS 8 |
1016 | size_t repeat_stack_idx[REPEAT_SLOTS], repeat_stack_done[REPEAT_SLOTS]; | |
1017 | size_t repeat_stack_limit[REPEAT_SLOTS]; | |
1018 | size_t repeat_stack_len = 0; | |
ed835673 | 1019 | |
5881dd2c | 1020 | if (!TEST_true(helper_local_init(hl, h, thread_idx))) |
ed835673 HL |
1021 | goto out; |
1022 | ||
769c9b1a HL |
1023 | #define COMMON_SPIN_AGAIN() \ |
1024 | { \ | |
1025 | no_advance = 1; \ | |
1026 | continue; \ | |
1027 | } | |
1028 | #define S_SPIN_AGAIN() \ | |
1029 | { \ | |
1030 | s_lock(h, hl); \ | |
1031 | ossl_quic_tserver_tick(h->s); \ | |
1032 | COMMON_SPIN_AGAIN(); \ | |
1033 | } | |
5881dd2c HL |
1034 | #define C_SPIN_AGAIN() \ |
1035 | { \ | |
1036 | if (h->blocking) { \ | |
1037 | TEST_error("spin again in blocking mode"); \ | |
1038 | goto out; \ | |
1039 | } \ | |
769c9b1a | 1040 | COMMON_SPIN_AGAIN(); \ |
5881dd2c | 1041 | } |
ed835673 | 1042 | |
9715e3aa | 1043 | for (;;) { |
a350db73 | 1044 | SSL *c_tgt = h->c_conn; |
ed835673 HL |
1045 | uint64_t s_stream_id = UINT64_MAX; |
1046 | ||
5881dd2c HL |
1047 | s_unlock(h, hl); |
1048 | ||
9715e3aa HL |
1049 | if (no_advance) { |
1050 | no_advance = 0; | |
1051 | } else { | |
1052 | if (!first) | |
1053 | ++op_idx; | |
1054 | ||
1055 | first = 0; | |
4f2d32d6 | 1056 | offset = 0; |
9715e3aa | 1057 | op_start_time = ossl_time_now(); |
cd5e4380 | 1058 | op_deadline = ossl_time_add(op_start_time, ossl_ms2time(8000)); |
9715e3aa HL |
1059 | } |
1060 | ||
1061 | if (!TEST_int_le(ossl_time_compare(ossl_time_now(), op_deadline), 0)) { | |
a350db73 | 1062 | TEST_error("op %zu timed out on thread %d", op_idx + 1, thread_idx); |
9715e3aa HL |
1063 | goto out; |
1064 | } | |
1065 | ||
ed835673 HL |
1066 | op = &script[op_idx]; |
1067 | ||
1068 | if (op->stream_name != NULL) { | |
5881dd2c | 1069 | c_tgt = helper_local_get_c_stream(hl, op->stream_name); |
a350db73 HL |
1070 | if (thread_idx < 0) |
1071 | s_stream_id = helper_get_s_stream(h, op->stream_name); | |
1072 | else | |
1073 | s_stream_id = UINT64_MAX; | |
1074 | } | |
1075 | ||
5881dd2c HL |
1076 | if (thread_idx < 0) { |
1077 | if (!h->blocking) { | |
1078 | ossl_quic_tserver_tick(h->s); | |
1079 | } | |
1080 | #if defined(OPENSSL_THREADS) | |
1081 | else if (h->blocking && !h->server_thread.ready) { | |
1082 | ossl_crypto_mutex_lock(h->server_thread.m); | |
1083 | h->server_thread.ready = 1; | |
1084 | ossl_crypto_mutex_unlock(h->server_thread.m); | |
1085 | ossl_crypto_condvar_signal(h->server_thread.c); | |
1086 | } | |
1087 | if (h->blocking) | |
1088 | assert(h->s == NULL); | |
1089 | #endif | |
1090 | } | |
7ba8f79a HL |
1091 | |
1092 | if (thread_idx >= 0 || connect_started) | |
6084e04b | 1093 | SSL_handle_events(h->c_conn); |
ed835673 | 1094 | |
a350db73 HL |
1095 | if (thread_idx >= 0) { |
1096 | /* Only allow certain opcodes on child threads. */ | |
1097 | switch (op->op) { | |
1098 | case OPK_END: | |
99d6b9f9 | 1099 | case OPK_CHECK: |
a350db73 HL |
1100 | case OPK_C_ACCEPT_STREAM_WAIT: |
1101 | case OPK_C_NEW_STREAM: | |
1102 | case OPK_C_READ_EXPECT: | |
1103 | case OPK_C_EXPECT_FIN: | |
1104 | case OPK_C_WRITE: | |
1105 | case OPK_C_CONCLUDE: | |
1106 | case OPK_C_FREE_STREAM: | |
fca44cfc HL |
1107 | case OPK_BEGIN_REPEAT: |
1108 | case OPK_END_REPEAT: | |
0345cac6 TM |
1109 | case OPK_C_READ_FAIL_WAIT: |
1110 | case OPK_C_EXPECT_SSL_ERR: | |
1111 | case OPK_EXPECT_ERR_REASON: | |
1112 | case OPK_EXPECT_ERR_LIB: | |
1113 | case OPK_SLEEP: | |
a350db73 HL |
1114 | break; |
1115 | ||
1116 | default: | |
0cea6df2 MC |
1117 | TEST_error("opcode %lu not allowed on child thread", |
1118 | (unsigned long)op->op); | |
a350db73 HL |
1119 | goto out; |
1120 | } | |
1121 | } | |
ed835673 HL |
1122 | |
1123 | switch (op->op) { | |
1124 | case OPK_END: | |
fca44cfc HL |
1125 | if (!TEST_size_t_eq(repeat_stack_len, 0)) |
1126 | goto out; | |
1127 | ||
629b408c | 1128 | #if defined(OPENSSL_THREADS) |
a350db73 HL |
1129 | if (thread_idx < 0) { |
1130 | int done; | |
1131 | size_t i; | |
1132 | ||
1133 | for (i = 0; i < h->num_threads; ++i) { | |
1134 | if (h->threads[i].m == NULL) | |
1135 | continue; | |
1136 | ||
1137 | ossl_crypto_mutex_lock(h->threads[i].m); | |
1138 | done = h->threads[i].done; | |
1139 | ossl_crypto_mutex_unlock(h->threads[i].m); | |
1140 | ||
1141 | if (!done) { | |
1142 | if (!end_wait_warning) { | |
1143 | TEST_info("still waiting for other threads to finish (%zu)", i); | |
1144 | end_wait_warning = 1; | |
1145 | } | |
1146 | ||
5881dd2c | 1147 | S_SPIN_AGAIN(); |
a350db73 HL |
1148 | } |
1149 | } | |
1150 | } | |
629b408c | 1151 | #endif |
a350db73 | 1152 | |
0786483a | 1153 | TEST_info("script \"%s\" finished on thread %d", script_name, thread_idx); |
ed835673 HL |
1154 | testresult = 1; |
1155 | goto out; | |
1156 | ||
fca44cfc HL |
1157 | case OPK_BEGIN_REPEAT: |
1158 | if (!TEST_size_t_lt(repeat_stack_len, OSSL_NELEM(repeat_stack_idx))) | |
1159 | goto out; | |
1160 | ||
1161 | if (!TEST_size_t_gt(op->arg1, 0)) | |
1162 | goto out; | |
1163 | ||
1164 | repeat_stack_idx[repeat_stack_len] = op_idx + 1; | |
1165 | repeat_stack_done[repeat_stack_len] = 0; | |
1166 | repeat_stack_limit[repeat_stack_len] = op->arg1; | |
1167 | ++repeat_stack_len; | |
1168 | break; | |
1169 | ||
14551f1e HL |
1170 | case OPK_C_SKIP_IF_UNBOUND: |
1171 | if (c_tgt != NULL) | |
1172 | break; | |
1173 | ||
1174 | op_idx += op->arg1; | |
1175 | break; | |
1176 | ||
fca44cfc HL |
1177 | case OPK_END_REPEAT: |
1178 | if (!TEST_size_t_gt(repeat_stack_len, 0)) | |
1179 | goto out; | |
1180 | ||
1181 | if (++repeat_stack_done[repeat_stack_len - 1] | |
1182 | == repeat_stack_limit[repeat_stack_len - 1]) { | |
1183 | --repeat_stack_len; | |
1184 | } else { | |
1185 | op_idx = repeat_stack_idx[repeat_stack_len - 1]; | |
1186 | no_advance = 1; | |
1187 | continue; | |
1188 | } | |
1189 | ||
1190 | break; | |
1191 | ||
ed835673 | 1192 | case OPK_CHECK: |
9715e3aa | 1193 | { |
5881dd2c HL |
1194 | int ok; |
1195 | ||
1196 | hl->check_op = op; | |
1197 | ok = op->check_func(h, hl); | |
1198 | hl->check_op = NULL; | |
1199 | ||
99d6b9f9 | 1200 | if (thread_idx < 0 && h->check_spin_again) { |
a350db73 | 1201 | h->check_spin_again = 0; |
5881dd2c | 1202 | S_SPIN_AGAIN(); |
9715e3aa | 1203 | } |
ed835673 | 1204 | |
9715e3aa HL |
1205 | if (!TEST_true(ok)) |
1206 | goto out; | |
1207 | } | |
ed835673 HL |
1208 | break; |
1209 | ||
1210 | case OPK_C_SET_ALPN: | |
1211 | { | |
1212 | const char *alpn = op->arg0; | |
1213 | size_t alpn_len = strlen(alpn); | |
1214 | ||
1215 | if (!TEST_size_t_le(alpn_len, UINT8_MAX) | |
1216 | || !TEST_ptr(tmp_buf = (unsigned char *)OPENSSL_malloc(alpn_len + 1))) | |
1217 | goto out; | |
1218 | ||
1219 | memcpy(tmp_buf + 1, alpn, alpn_len); | |
1220 | tmp_buf[0] = (unsigned char)alpn_len; | |
1221 | ||
1222 | /* 0 is the success case for SSL_set_alpn_protos(). */ | |
a350db73 | 1223 | if (!TEST_false(SSL_set_alpn_protos(h->c_conn, tmp_buf, |
ed835673 HL |
1224 | alpn_len + 1))) |
1225 | goto out; | |
1226 | ||
1227 | OPENSSL_free(tmp_buf); | |
1228 | tmp_buf = NULL; | |
1229 | } | |
1230 | break; | |
1231 | ||
1232 | case OPK_C_CONNECT_WAIT: | |
1233 | { | |
1234 | int ret; | |
1235 | ||
1236 | connect_started = 1; | |
1237 | ||
a350db73 | 1238 | ret = SSL_connect(h->c_conn); |
9ff81610 HL |
1239 | if (!check_consistent_want(c_tgt, ret)) |
1240 | goto out; | |
a1d2a9d1 HL |
1241 | if (ret != 1) { |
1242 | if (!h->blocking && is_want(h->c_conn, ret)) | |
5881dd2c | 1243 | C_SPIN_AGAIN(); |
ed835673 | 1244 | |
a1d2a9d1 HL |
1245 | if (op->arg1 == 0 && !TEST_int_eq(ret, 1)) |
1246 | goto out; | |
1247 | } | |
ed835673 HL |
1248 | } |
1249 | break; | |
1250 | ||
1251 | case OPK_C_WRITE: | |
1252 | { | |
1253 | size_t bytes_written = 0; | |
9ff81610 | 1254 | int r; |
ed835673 HL |
1255 | |
1256 | if (!TEST_ptr(c_tgt)) | |
1257 | goto out; | |
1258 | ||
9ff81610 HL |
1259 | r = SSL_write_ex(c_tgt, op->arg0, op->arg1, &bytes_written); |
1260 | if (!TEST_true(r) | |
1261 | || !check_consistent_want(c_tgt, r) | |
ed835673 HL |
1262 | || !TEST_size_t_eq(bytes_written, op->arg1)) |
1263 | goto out; | |
1264 | } | |
1265 | break; | |
1266 | ||
1267 | case OPK_S_WRITE: | |
1268 | { | |
1269 | size_t bytes_written = 0; | |
1270 | ||
1271 | if (!TEST_uint64_t_ne(s_stream_id, UINT64_MAX)) | |
1272 | goto out; | |
1273 | ||
5881dd2c | 1274 | if (!TEST_true(ossl_quic_tserver_write(ACQUIRE_S(), s_stream_id, |
ed835673 HL |
1275 | op->arg0, op->arg1, |
1276 | &bytes_written)) | |
1277 | || !TEST_size_t_eq(bytes_written, op->arg1)) | |
1278 | goto out; | |
1279 | } | |
1280 | break; | |
1281 | ||
1282 | case OPK_C_CONCLUDE: | |
1283 | { | |
1284 | if (!TEST_true(SSL_stream_conclude(c_tgt, 0))) | |
1285 | goto out; | |
1286 | } | |
1287 | break; | |
1288 | ||
1289 | case OPK_S_CONCLUDE: | |
1290 | { | |
1291 | if (!TEST_uint64_t_ne(s_stream_id, UINT64_MAX)) | |
1292 | goto out; | |
1293 | ||
5881dd2c | 1294 | ossl_quic_tserver_conclude(ACQUIRE_S(), s_stream_id); |
ed835673 HL |
1295 | } |
1296 | break; | |
1297 | ||
1298 | case OPK_C_WAIT_FOR_DATA: | |
1299 | { | |
1300 | char buf[1]; | |
1301 | size_t bytes_read = 0; | |
1302 | ||
1303 | if (!TEST_ptr(c_tgt)) | |
1304 | goto out; | |
1305 | ||
1306 | if (!SSL_peek_ex(c_tgt, buf, sizeof(buf), &bytes_read) | |
1307 | || bytes_read == 0) | |
5881dd2c | 1308 | C_SPIN_AGAIN(); |
ed835673 HL |
1309 | } |
1310 | break; | |
1311 | ||
1312 | case OPK_C_READ_EXPECT: | |
1313 | { | |
1314 | size_t bytes_read = 0; | |
9ff81610 | 1315 | int r; |
ed835673 | 1316 | |
9715e3aa HL |
1317 | if (op->arg1 > 0 && tmp_buf == NULL |
1318 | && !TEST_ptr(tmp_buf = OPENSSL_malloc(op->arg1))) | |
ed835673 HL |
1319 | goto out; |
1320 | ||
9ff81610 HL |
1321 | r = SSL_read_ex(c_tgt, tmp_buf + offset, op->arg1 - offset, |
1322 | &bytes_read); | |
1323 | if (!check_consistent_want(c_tgt, r)) | |
1324 | goto out; | |
1325 | ||
1326 | if (!r) | |
5881dd2c | 1327 | C_SPIN_AGAIN(); |
ed835673 | 1328 | |
9715e3aa HL |
1329 | if (bytes_read + offset != op->arg1) { |
1330 | offset += bytes_read; | |
5881dd2c | 1331 | C_SPIN_AGAIN(); |
9715e3aa HL |
1332 | } |
1333 | ||
1334 | if (op->arg1 > 0 | |
1335 | && !TEST_mem_eq(tmp_buf, op->arg1, op->arg0, op->arg1)) | |
ed835673 HL |
1336 | goto out; |
1337 | ||
1338 | OPENSSL_free(tmp_buf); | |
1339 | tmp_buf = NULL; | |
1340 | } | |
1341 | break; | |
1342 | ||
1343 | case OPK_S_READ_EXPECT: | |
1344 | { | |
1345 | size_t bytes_read = 0; | |
1346 | ||
1347 | if (!TEST_uint64_t_ne(s_stream_id, UINT64_MAX)) | |
1348 | goto out; | |
1349 | ||
9715e3aa | 1350 | if (op->arg1 > 0 && tmp_buf == NULL |
ed835673 HL |
1351 | && !TEST_ptr(tmp_buf = OPENSSL_malloc(op->arg1))) |
1352 | goto out; | |
1353 | ||
5881dd2c | 1354 | if (!TEST_true(ossl_quic_tserver_read(ACQUIRE_S(), s_stream_id, |
9715e3aa HL |
1355 | tmp_buf + offset, |
1356 | op->arg1 - offset, | |
1357 | &bytes_read))) | |
ed835673 HL |
1358 | goto out; |
1359 | ||
9715e3aa HL |
1360 | if (bytes_read + offset != op->arg1) { |
1361 | offset += bytes_read; | |
5881dd2c | 1362 | S_SPIN_AGAIN(); |
9715e3aa HL |
1363 | } |
1364 | ||
ed835673 HL |
1365 | if (op->arg1 > 0 |
1366 | && !TEST_mem_eq(tmp_buf, op->arg1, op->arg0, op->arg1)) | |
1367 | goto out; | |
1368 | ||
1369 | OPENSSL_free(tmp_buf); | |
1370 | tmp_buf = NULL; | |
1371 | } | |
1372 | break; | |
1373 | ||
1374 | case OPK_C_EXPECT_FIN: | |
1375 | { | |
1376 | char buf[1]; | |
1377 | size_t bytes_read = 0; | |
9ff81610 | 1378 | int r; |
ed835673 | 1379 | |
9ff81610 HL |
1380 | r = SSL_read_ex(c_tgt, buf, sizeof(buf), &bytes_read); |
1381 | if (!check_consistent_want(c_tgt, r) | |
1382 | || !TEST_false(r) | |
9715e3aa HL |
1383 | || !TEST_size_t_eq(bytes_read, 0)) |
1384 | goto out; | |
1385 | ||
1386 | if (is_want(c_tgt, 0)) | |
5881dd2c | 1387 | C_SPIN_AGAIN(); |
9715e3aa HL |
1388 | |
1389 | if (!TEST_int_eq(SSL_get_error(c_tgt, 0), | |
1390 | SSL_ERROR_ZERO_RETURN)) | |
1391 | goto out; | |
9ff81610 HL |
1392 | |
1393 | if (!TEST_int_eq(SSL_want(c_tgt), SSL_NOTHING)) | |
1394 | goto out; | |
ed835673 HL |
1395 | } |
1396 | break; | |
1397 | ||
1398 | case OPK_S_EXPECT_FIN: | |
1399 | { | |
9715e3aa | 1400 | if (!TEST_uint64_t_ne(s_stream_id, UINT64_MAX)) |
ed835673 | 1401 | goto out; |
9715e3aa | 1402 | |
5881dd2c HL |
1403 | if (!ossl_quic_tserver_has_read_ended(ACQUIRE_S(), s_stream_id)) |
1404 | S_SPIN_AGAIN(); | |
ed835673 HL |
1405 | } |
1406 | break; | |
1407 | ||
1408 | case OPK_C_DETACH: | |
1409 | { | |
1410 | SSL *c_stream; | |
1411 | ||
1412 | if (!TEST_ptr_null(c_tgt)) | |
1413 | goto out; /* don't overwrite existing stream with same name */ | |
1414 | ||
dbf247ad HL |
1415 | if (!TEST_ptr(op->stream_name)) |
1416 | goto out; | |
1417 | ||
a350db73 | 1418 | if (!TEST_ptr(c_stream = ossl_quic_detach_stream(h->c_conn))) |
ed835673 HL |
1419 | goto out; |
1420 | ||
5881dd2c | 1421 | if (!TEST_true(helper_local_set_c_stream(hl, op->stream_name, c_stream))) |
ed835673 HL |
1422 | goto out; |
1423 | } | |
1424 | break; | |
1425 | ||
1426 | case OPK_C_ATTACH: | |
1427 | { | |
1428 | if (!TEST_ptr(c_tgt)) | |
1429 | goto out; | |
1430 | ||
dbf247ad HL |
1431 | if (!TEST_ptr(op->stream_name)) |
1432 | goto out; | |
1433 | ||
a350db73 | 1434 | if (!TEST_true(ossl_quic_attach_stream(h->c_conn, c_tgt))) |
ed835673 HL |
1435 | goto out; |
1436 | ||
5881dd2c | 1437 | if (!TEST_true(helper_local_set_c_stream(hl, op->stream_name, NULL))) |
ed835673 HL |
1438 | goto out; |
1439 | } | |
1440 | break; | |
1441 | ||
1442 | case OPK_C_NEW_STREAM: | |
1443 | { | |
1444 | SSL *c_stream; | |
14551f1e HL |
1445 | uint64_t flags = op->arg1; |
1446 | int allow_fail = ((flags & ALLOW_FAIL) != 0); | |
1447 | ||
1448 | flags &= ~(uint64_t)ALLOW_FAIL; | |
ed835673 HL |
1449 | |
1450 | if (!TEST_ptr_null(c_tgt)) | |
1451 | goto out; /* don't overwrite existing stream with same name */ | |
1452 | ||
dbf247ad HL |
1453 | if (!TEST_ptr(op->stream_name)) |
1454 | goto out; | |
1455 | ||
14551f1e HL |
1456 | c_stream = SSL_new_stream(h->c_conn, flags); |
1457 | if (!allow_fail && !TEST_ptr(c_stream)) | |
ed835673 HL |
1458 | goto out; |
1459 | ||
14551f1e HL |
1460 | if (allow_fail && c_stream == NULL) { |
1461 | if (!TEST_size_t_eq(ERR_GET_REASON(ERR_get_error()), | |
1462 | SSL_R_STREAM_COUNT_LIMITED)) | |
1463 | goto out; | |
1464 | ||
1465 | ++h->fail_count; | |
1466 | break; | |
1467 | } | |
1468 | ||
ed835673 HL |
1469 | if (op->arg2 != UINT64_MAX |
1470 | && !TEST_uint64_t_eq(SSL_get_stream_id(c_stream), | |
1471 | op->arg2)) | |
1472 | goto out; | |
1473 | ||
5881dd2c | 1474 | if (!TEST_true(helper_local_set_c_stream(hl, op->stream_name, c_stream))) |
ed835673 HL |
1475 | goto out; |
1476 | } | |
1477 | break; | |
1478 | ||
1479 | case OPK_S_NEW_STREAM: | |
1480 | { | |
1481 | uint64_t stream_id = UINT64_MAX; | |
1482 | ||
1483 | if (!TEST_uint64_t_eq(s_stream_id, UINT64_MAX)) | |
1484 | goto out; /* don't overwrite existing stream with same name */ | |
1485 | ||
dbf247ad HL |
1486 | if (!TEST_ptr(op->stream_name)) |
1487 | goto out; | |
1488 | ||
5881dd2c | 1489 | if (!TEST_true(ossl_quic_tserver_stream_new(ACQUIRE_S(), |
ed835673 HL |
1490 | op->arg1 > 0, |
1491 | &stream_id))) | |
1492 | goto out; | |
1493 | ||
1494 | if (op->arg2 != UINT64_MAX | |
1495 | && !TEST_uint64_t_eq(stream_id, op->arg2)) | |
1496 | goto out; | |
1497 | ||
a350db73 | 1498 | if (!TEST_true(helper_set_s_stream(h, op->stream_name, |
ed835673 HL |
1499 | stream_id))) |
1500 | goto out; | |
1501 | } | |
1502 | break; | |
1503 | ||
a350db73 | 1504 | case OPK_C_ACCEPT_STREAM_WAIT: |
ed835673 HL |
1505 | { |
1506 | SSL *c_stream; | |
1507 | ||
1508 | if (!TEST_ptr_null(c_tgt)) | |
1509 | goto out; /* don't overwrite existing stream with same name */ | |
1510 | ||
dbf247ad HL |
1511 | if (!TEST_ptr(op->stream_name)) |
1512 | goto out; | |
1513 | ||
a350db73 | 1514 | if ((c_stream = SSL_accept_stream(h->c_conn, 0)) == NULL) |
5881dd2c | 1515 | C_SPIN_AGAIN(); |
ed835673 | 1516 | |
5881dd2c | 1517 | if (!TEST_true(helper_local_set_c_stream(hl, op->stream_name, |
a350db73 HL |
1518 | c_stream))) |
1519 | goto out; | |
1520 | } | |
1521 | break; | |
1522 | ||
1523 | case OPK_S_ACCEPT_STREAM_WAIT: | |
1524 | { | |
1525 | uint64_t new_stream_id; | |
1526 | ||
1527 | if (!TEST_uint64_t_eq(s_stream_id, UINT64_MAX)) | |
1528 | goto out; | |
1529 | ||
dbf247ad HL |
1530 | if (!TEST_ptr(op->stream_name)) |
1531 | goto out; | |
1532 | ||
5881dd2c | 1533 | new_stream_id = ossl_quic_tserver_pop_incoming_stream(ACQUIRE_S()); |
a350db73 | 1534 | if (new_stream_id == UINT64_MAX) |
5881dd2c | 1535 | S_SPIN_AGAIN(); |
a350db73 HL |
1536 | |
1537 | if (!TEST_true(helper_set_s_stream(h, op->stream_name, new_stream_id))) | |
ed835673 HL |
1538 | goto out; |
1539 | } | |
1540 | break; | |
1541 | ||
1542 | case OPK_C_ACCEPT_STREAM_NONE: | |
1543 | { | |
1544 | SSL *c_stream; | |
1545 | ||
5881dd2c HL |
1546 | if (!TEST_ptr_null(c_stream = SSL_accept_stream(h->c_conn, |
1547 | SSL_ACCEPT_STREAM_NO_BLOCK))) { | |
ed835673 HL |
1548 | SSL_free(c_stream); |
1549 | goto out; | |
1550 | } | |
1551 | } | |
1552 | break; | |
1553 | ||
1554 | case OPK_C_FREE_STREAM: | |
1555 | { | |
1556 | if (!TEST_ptr(c_tgt) | |
1557 | || !TEST_true(!SSL_is_connection(c_tgt))) | |
1558 | goto out; | |
1559 | ||
dbf247ad HL |
1560 | if (!TEST_ptr(op->stream_name)) |
1561 | goto out; | |
1562 | ||
5881dd2c | 1563 | if (!TEST_true(helper_local_set_c_stream(hl, op->stream_name, NULL))) |
ed835673 HL |
1564 | goto out; |
1565 | ||
1566 | SSL_free(c_tgt); | |
1567 | c_tgt = NULL; | |
1568 | } | |
1569 | break; | |
1570 | ||
1571 | case OPK_C_SET_DEFAULT_STREAM_MODE: | |
1572 | { | |
1573 | if (!TEST_ptr(c_tgt)) | |
1574 | goto out; | |
1575 | ||
1576 | if (!TEST_true(SSL_set_default_stream_mode(c_tgt, op->arg1))) | |
1577 | goto out; | |
1578 | } | |
1579 | break; | |
1580 | ||
83df44ae | 1581 | case OPK_C_SET_INCOMING_STREAM_POLICY: |
ed835673 HL |
1582 | { |
1583 | if (!TEST_ptr(c_tgt)) | |
1584 | goto out; | |
1585 | ||
83df44ae HL |
1586 | if (!TEST_true(SSL_set_incoming_stream_policy(c_tgt, |
1587 | op->arg1, 0))) | |
ed835673 HL |
1588 | goto out; |
1589 | } | |
1590 | break; | |
1591 | ||
cd5e4380 | 1592 | case OPK_C_SHUTDOWN_WAIT: |
ed835673 HL |
1593 | { |
1594 | int ret; | |
cd5e4380 | 1595 | QUIC_CHANNEL *ch = ossl_quic_conn_get_channel(h->c_conn); |
d49a1634 | 1596 | SSL_SHUTDOWN_EX_ARGS args = {0}; |
cd5e4380 HL |
1597 | |
1598 | ossl_quic_channel_set_inhibit_tick(ch, 0); | |
ed835673 HL |
1599 | |
1600 | if (!TEST_ptr(c_tgt)) | |
1601 | goto out; | |
1602 | ||
d49a1634 HL |
1603 | args.quic_reason = (const char *)op->arg0; |
1604 | ||
3bc38ba0 | 1605 | ret = SSL_shutdown_ex(c_tgt, op->arg1, &args, sizeof(args)); |
ed835673 HL |
1606 | if (!TEST_int_ge(ret, 0)) |
1607 | goto out; | |
1608 | ||
cd5e4380 | 1609 | if (ret == 0) |
5881dd2c | 1610 | C_SPIN_AGAIN(); |
ed835673 HL |
1611 | } |
1612 | break; | |
1613 | ||
3bc38ba0 HL |
1614 | case OPK_S_SHUTDOWN: |
1615 | { | |
5881dd2c | 1616 | ossl_quic_tserver_shutdown(ACQUIRE_S(), op->arg1); |
3bc38ba0 HL |
1617 | } |
1618 | break; | |
1619 | ||
ed835673 HL |
1620 | case OPK_C_EXPECT_CONN_CLOSE_INFO: |
1621 | { | |
1622 | SSL_CONN_CLOSE_INFO cc_info = {0}; | |
1623 | int expect_app = (op->arg1 & EXPECT_CONN_CLOSE_APP) != 0; | |
1624 | int expect_remote = (op->arg1 & EXPECT_CONN_CLOSE_REMOTE) != 0; | |
1625 | uint64_t error_code = op->arg2; | |
1626 | ||
1627 | if (!TEST_ptr(c_tgt)) | |
1628 | goto out; | |
1629 | ||
5881dd2c HL |
1630 | if (h->blocking |
1631 | && !TEST_true(SSL_shutdown_ex(c_tgt, | |
1632 | SSL_SHUTDOWN_FLAG_WAIT_PEER, | |
1633 | NULL, 0))) | |
1634 | goto out; | |
1635 | ||
9715e3aa | 1636 | if (!SSL_get_conn_close_info(c_tgt, &cc_info, sizeof(cc_info))) |
5881dd2c | 1637 | C_SPIN_AGAIN(); |
ed835673 | 1638 | |
7d9e447a HL |
1639 | if (!TEST_int_eq(expect_app, |
1640 | (cc_info.flags | |
1641 | & SSL_CONN_CLOSE_FLAG_TRANSPORT) == 0) | |
1642 | || !TEST_int_eq(expect_remote, | |
1643 | (cc_info.flags | |
1644 | & SSL_CONN_CLOSE_FLAG_LOCAL) == 0) | |
ed835673 HL |
1645 | || !TEST_uint64_t_eq(error_code, cc_info.error_code)) |
1646 | goto out; | |
1647 | } | |
1648 | break; | |
1649 | ||
1650 | case OPK_S_EXPECT_CONN_CLOSE_INFO: | |
1651 | { | |
1652 | const QUIC_TERMINATE_CAUSE *tc; | |
1653 | int expect_app = (op->arg1 & EXPECT_CONN_CLOSE_APP) != 0; | |
1654 | int expect_remote = (op->arg1 & EXPECT_CONN_CLOSE_REMOTE) != 0; | |
1655 | uint64_t error_code = op->arg2; | |
1656 | ||
5881dd2c HL |
1657 | if (!ossl_quic_tserver_is_term_any(ACQUIRE_S())) { |
1658 | ossl_quic_tserver_ping(ACQUIRE_S()); | |
1659 | S_SPIN_AGAIN(); | |
9ff3a99e | 1660 | } |
ed835673 | 1661 | |
5881dd2c | 1662 | if (!TEST_ptr(tc = ossl_quic_tserver_get_terminate_cause(ACQUIRE_S()))) |
ed835673 HL |
1663 | goto out; |
1664 | ||
1665 | if (!TEST_uint64_t_eq(error_code, tc->error_code) | |
1666 | || !TEST_int_eq(expect_app, tc->app) | |
1667 | || !TEST_int_eq(expect_remote, tc->remote)) | |
1668 | goto out; | |
1669 | } | |
1670 | break; | |
1671 | ||
1672 | case OPK_S_BIND_STREAM_ID: | |
1673 | { | |
1674 | if (!TEST_uint64_t_eq(s_stream_id, UINT64_MAX)) | |
1675 | goto out; | |
1676 | ||
dbf247ad HL |
1677 | if (!TEST_ptr(op->stream_name)) |
1678 | goto out; | |
1679 | ||
a350db73 | 1680 | if (!TEST_true(helper_set_s_stream(h, op->stream_name, op->arg2))) |
ed835673 HL |
1681 | goto out; |
1682 | } | |
1683 | break; | |
1684 | ||
fca44cfc HL |
1685 | case OPK_S_UNBIND_STREAM_ID: |
1686 | { | |
1687 | if (!TEST_uint64_t_ne(s_stream_id, UINT64_MAX)) | |
1688 | goto out; | |
1689 | ||
dbf247ad HL |
1690 | if (!TEST_ptr(op->stream_name)) |
1691 | goto out; | |
1692 | ||
fca44cfc HL |
1693 | if (!TEST_true(helper_set_s_stream(h, op->stream_name, UINT64_MAX))) |
1694 | goto out; | |
1695 | } | |
1696 | break; | |
1697 | ||
ed835673 HL |
1698 | case OPK_C_WRITE_FAIL: |
1699 | { | |
571aff4b | 1700 | size_t bytes_written = 0; |
9ff81610 | 1701 | int r; |
ed835673 HL |
1702 | |
1703 | if (!TEST_ptr(c_tgt)) | |
1704 | goto out; | |
1705 | ||
9ff81610 HL |
1706 | r = SSL_write_ex(c_tgt, "apple", 5, &bytes_written); |
1707 | if (!TEST_false(r) | |
1708 | || !check_consistent_want(c_tgt, r)) | |
ed835673 HL |
1709 | goto out; |
1710 | } | |
1711 | break; | |
1712 | ||
1713 | case OPK_S_WRITE_FAIL: | |
1714 | { | |
1715 | size_t bytes_written = 0; | |
1716 | ||
1717 | if (!TEST_uint64_t_ne(s_stream_id, UINT64_MAX)) | |
1718 | goto out; | |
1719 | ||
5881dd2c | 1720 | if (!TEST_false(ossl_quic_tserver_write(ACQUIRE_S(), s_stream_id, |
ed835673 HL |
1721 | (const unsigned char *)"apple", 5, |
1722 | &bytes_written))) | |
1723 | goto out; | |
1724 | } | |
1725 | break; | |
1726 | ||
1727 | case OPK_C_READ_FAIL: | |
1728 | { | |
571aff4b | 1729 | size_t bytes_read = 0; |
ed835673 | 1730 | char buf[1]; |
9ff81610 | 1731 | int r; |
ed835673 HL |
1732 | |
1733 | if (!TEST_ptr(c_tgt)) | |
1734 | goto out; | |
1735 | ||
9ff81610 HL |
1736 | r = SSL_read_ex(c_tgt, buf, sizeof(buf), &bytes_read); |
1737 | if (!TEST_false(r)) | |
1738 | goto out; | |
1739 | if (!check_consistent_want(c_tgt, r)) | |
ed835673 HL |
1740 | goto out; |
1741 | } | |
1742 | break; | |
1743 | ||
0345cac6 TM |
1744 | case OPK_C_READ_FAIL_WAIT: |
1745 | { | |
1746 | size_t bytes_read = 0; | |
1747 | char buf[1]; | |
9ff81610 | 1748 | int r; |
0345cac6 TM |
1749 | |
1750 | if (!TEST_ptr(c_tgt)) | |
1751 | goto out; | |
1752 | ||
9ff81610 HL |
1753 | r = SSL_read_ex(c_tgt, buf, sizeof(buf), &bytes_read); |
1754 | if (!TEST_false(r)) | |
1755 | goto out; | |
1756 | if (!check_consistent_want(c_tgt, r)) | |
0345cac6 TM |
1757 | goto out; |
1758 | ||
1759 | if (is_want(c_tgt, 0)) | |
5881dd2c | 1760 | C_SPIN_AGAIN(); |
0345cac6 TM |
1761 | } |
1762 | break; | |
1763 | ||
2f018d14 HL |
1764 | case OPK_S_READ_FAIL: |
1765 | { | |
1766 | size_t bytes_read = 0; | |
1767 | unsigned char buf[1]; | |
1768 | ||
1769 | if (!TEST_uint64_t_ne(s_stream_id, UINT64_MAX)) | |
1770 | goto out; | |
1771 | ||
5881dd2c | 1772 | if (!TEST_false(ossl_quic_tserver_read(ACQUIRE_S(), s_stream_id, |
2f018d14 HL |
1773 | buf, sizeof(buf), |
1774 | &bytes_read))) | |
1775 | goto out; | |
1776 | } | |
1777 | break; | |
1778 | ||
ed835673 HL |
1779 | case OPK_C_STREAM_RESET: |
1780 | { | |
1781 | SSL_STREAM_RESET_ARGS args = {0}; | |
1782 | ||
1783 | if (!TEST_ptr(c_tgt)) | |
1784 | goto out; | |
1785 | ||
1786 | args.quic_error_code = op->arg2; | |
1787 | ||
1788 | if (!TEST_true(SSL_stream_reset(c_tgt, &args, sizeof(args)))) | |
1789 | goto out; | |
1790 | } | |
1791 | break; | |
1792 | ||
a350db73 HL |
1793 | case OPK_NEW_THREAD: |
1794 | { | |
1795 | #if !defined(OPENSSL_THREADS) | |
629b408c HL |
1796 | /* |
1797 | * If this test script requires threading and we do not have | |
1798 | * support for it, skip the rest of it. | |
1799 | */ | |
1800 | TEST_skip("threading not supported, skipping"); | |
1801 | testresult = 1; | |
a350db73 HL |
1802 | goto out; |
1803 | #else | |
1804 | size_t i; | |
1805 | ||
1806 | if (!TEST_ptr_null(h->threads)) { | |
1807 | TEST_error("max one NEW_THREAD operation per script"); | |
1808 | goto out; | |
1809 | } | |
1810 | ||
1811 | h->threads = OPENSSL_zalloc(op->arg1 * sizeof(struct child_thread_args)); | |
1812 | if (!TEST_ptr(h->threads)) | |
1813 | goto out; | |
1814 | ||
1815 | h->num_threads = op->arg1; | |
1816 | ||
1817 | for (i = 0; i < op->arg1; ++i) { | |
1818 | h->threads[i].h = h; | |
1819 | h->threads[i].script = op->arg0; | |
0786483a | 1820 | h->threads[i].script_name = script_name; |
a350db73 HL |
1821 | h->threads[i].thread_idx = i; |
1822 | ||
1823 | h->threads[i].m = ossl_crypto_mutex_new(); | |
1824 | if (!TEST_ptr(h->threads[i].m)) | |
1825 | goto out; | |
1826 | ||
1827 | h->threads[i].t | |
1828 | = ossl_crypto_thread_native_start(run_script_child_thread, | |
1829 | &h->threads[i], 1); | |
1830 | if (!TEST_ptr(h->threads[i].t)) | |
1831 | goto out; | |
1832 | } | |
1833 | #endif | |
1834 | } | |
1835 | break; | |
1836 | ||
0345cac6 TM |
1837 | case OPK_C_CLOSE_SOCKET: |
1838 | { | |
1839 | BIO_closesocket(h->c_fd); | |
410a90f5 | 1840 | h->c_fd = -1; |
0345cac6 TM |
1841 | } |
1842 | break; | |
1843 | ||
1844 | case OPK_C_EXPECT_SSL_ERR: | |
1845 | { | |
1846 | if (!TEST_size_t_eq((size_t)SSL_get_error(c_tgt, 0), op->arg1)) | |
1847 | goto out; | |
9ff81610 HL |
1848 | if (!TEST_int_eq(SSL_want(c_tgt), SSL_NOTHING)) |
1849 | goto out; | |
0345cac6 TM |
1850 | } |
1851 | break; | |
1852 | ||
1853 | case OPK_EXPECT_ERR_REASON: | |
1854 | { | |
1855 | if (!TEST_size_t_eq((size_t)ERR_GET_REASON(ERR_get_error()), op->arg1)) | |
1856 | goto out; | |
1857 | } | |
1858 | break; | |
1859 | ||
1860 | case OPK_EXPECT_ERR_LIB: | |
1861 | { | |
1862 | if (!TEST_size_t_eq((size_t)ERR_GET_LIB(ERR_get_error()), op->arg1)) | |
1863 | goto out; | |
1864 | } | |
1865 | break; | |
1866 | ||
1867 | case OPK_SLEEP: | |
1868 | { | |
1869 | OSSL_sleep(op->arg2); | |
1870 | } | |
1871 | break; | |
1872 | ||
e26dc8e3 HL |
1873 | case OPK_S_SET_INJECT_PLAIN: |
1874 | h->qtf_packet_plain_cb = op->qtf_packet_plain_cb; | |
1875 | ||
1876 | if (!TEST_true(qtest_fault_set_packet_plain_listener(h->qtf, | |
1877 | h->qtf_packet_plain_cb != NULL ? | |
1878 | helper_packet_plain_listener : NULL, | |
1879 | h))) | |
1880 | goto out; | |
1881 | ||
1882 | break; | |
1883 | ||
de56eebd HL |
1884 | case OPK_S_SET_INJECT_HANDSHAKE: |
1885 | h->qtf_handshake_cb = op->qtf_handshake_cb; | |
1886 | ||
1887 | if (!TEST_true(qtest_fault_set_handshake_listener(h->qtf, | |
1888 | h->qtf_handshake_cb != NULL ? | |
1889 | helper_handshake_listener : NULL, | |
1890 | h))) | |
1891 | goto out; | |
1892 | ||
1893 | break; | |
1894 | ||
69169cd9 HL |
1895 | case OPK_S_SET_INJECT_DATAGRAM: |
1896 | h->qtf_datagram_cb = op->qtf_datagram_cb; | |
1897 | ||
1898 | if (!TEST_true(qtest_fault_set_datagram_listener(h->qtf, | |
1899 | h->qtf_datagram_cb != NULL ? | |
1900 | helper_datagram_listener : NULL, | |
1901 | h))) | |
1902 | goto out; | |
1903 | ||
1904 | break; | |
1905 | ||
e26dc8e3 | 1906 | case OPK_SET_INJECT_WORD: |
5881dd2c HL |
1907 | /* |
1908 | * Must hold server tick lock - callbacks can be called from other | |
1909 | * thread when running test in blocking mode (tsan). | |
1910 | */ | |
1911 | ACQUIRE_S(); | |
e26dc8e3 HL |
1912 | h->inject_word0 = op->arg1; |
1913 | h->inject_word1 = op->arg2; | |
1914 | break; | |
1915 | ||
cd5e4380 HL |
1916 | case OPK_C_INHIBIT_TICK: |
1917 | { | |
1918 | QUIC_CHANNEL *ch = ossl_quic_conn_get_channel(h->c_conn); | |
1919 | ||
1920 | ossl_quic_channel_set_inhibit_tick(ch, op->arg1); | |
1921 | } | |
1922 | break; | |
1923 | ||
1924 | case OPK_C_SET_WRITE_BUF_SIZE: | |
1925 | if (!TEST_ptr(c_tgt)) | |
1926 | goto out; | |
1927 | ||
1928 | if (!TEST_true(ossl_quic_set_write_buffer_size(c_tgt, op->arg1))) | |
1929 | goto out; | |
1930 | ||
1931 | break; | |
1932 | ||
614c08c2 | 1933 | case OPK_S_NEW_TICKET: |
5881dd2c | 1934 | if (!TEST_true(ossl_quic_tserver_new_ticket(ACQUIRE_S()))) |
614c08c2 MC |
1935 | goto out; |
1936 | break; | |
1937 | ||
ed835673 HL |
1938 | default: |
1939 | TEST_error("unknown op"); | |
1940 | goto out; | |
1941 | } | |
1942 | } | |
1943 | ||
1944 | out: | |
5881dd2c | 1945 | s_unlock(h, hl); /* idempotent */ |
fca44cfc HL |
1946 | if (!testresult) { |
1947 | size_t i; | |
1948 | ||
0786483a HL |
1949 | TEST_error("failed in script \"%s\" at op %zu, thread %d\n", |
1950 | script_name, op_idx + 1, thread_idx); | |
ed835673 | 1951 | |
fca44cfc HL |
1952 | for (i = 0; i < repeat_stack_len; ++i) |
1953 | TEST_info("while repeating, iteration %zu of %zu, starting at script op %zu", | |
1954 | repeat_stack_done[i], | |
1955 | repeat_stack_limit[i], | |
1956 | repeat_stack_idx[i]); | |
1957 | } | |
1958 | ||
ed835673 | 1959 | OPENSSL_free(tmp_buf); |
5881dd2c | 1960 | helper_local_cleanup(hl); |
a350db73 HL |
1961 | return testresult; |
1962 | } | |
1963 | ||
0786483a HL |
1964 | static int run_script(const struct script_op *script, |
1965 | const char *script_name, | |
5881dd2c HL |
1966 | int free_order, |
1967 | int blocking) | |
a350db73 HL |
1968 | { |
1969 | int testresult = 0; | |
1970 | struct helper h; | |
1971 | ||
5881dd2c | 1972 | if (!TEST_true(helper_init(&h, free_order, blocking, 1))) |
a350db73 HL |
1973 | goto out; |
1974 | ||
0786483a | 1975 | if (!TEST_true(run_script_worker(&h, script, script_name, -1))) |
a350db73 HL |
1976 | goto out; |
1977 | ||
629b408c | 1978 | #if defined(OPENSSL_THREADS) |
a350db73 HL |
1979 | if (!TEST_true(join_threads(h.threads, h.num_threads))) |
1980 | goto out; | |
629b408c | 1981 | #endif |
a350db73 HL |
1982 | |
1983 | testresult = 1; | |
1984 | out: | |
ed835673 HL |
1985 | helper_cleanup(&h); |
1986 | return testresult; | |
1987 | } | |
1988 | ||
a350db73 HL |
1989 | #if defined(OPENSSL_THREADS) |
1990 | static CRYPTO_THREAD_RETVAL run_script_child_thread(void *arg) | |
1991 | { | |
1992 | int testresult; | |
1993 | struct child_thread_args *args = arg; | |
1994 | ||
1995 | testresult = run_script_worker(args->h, args->script, | |
0786483a | 1996 | args->script_name, |
a350db73 HL |
1997 | args->thread_idx); |
1998 | ||
1999 | ossl_crypto_mutex_lock(args->m); | |
2000 | args->testresult = testresult; | |
2001 | args->done = 1; | |
2002 | ossl_crypto_mutex_unlock(args->m); | |
2003 | return 1; | |
2004 | } | |
2005 | #endif | |
2006 | ||
ed835673 HL |
2007 | /* 1. Simple single-stream test */ |
2008 | static const struct script_op script_1[] = { | |
2009 | OP_C_SET_ALPN ("ossltest") | |
2010 | OP_C_CONNECT_WAIT () | |
2011 | OP_C_WRITE (DEFAULT, "apple", 5) | |
2012 | OP_C_CONCLUDE (DEFAULT) | |
2013 | OP_S_BIND_STREAM_ID (a, C_BIDI_ID(0)) | |
2014 | OP_S_READ_EXPECT (a, "apple", 5) | |
2015 | OP_S_EXPECT_FIN (a) | |
2016 | OP_S_WRITE (a, "orange", 6) | |
2017 | OP_S_CONCLUDE (a) | |
2018 | OP_C_READ_EXPECT (DEFAULT, "orange", 6) | |
2019 | OP_C_EXPECT_FIN (DEFAULT) | |
2020 | OP_END | |
2021 | }; | |
2022 | ||
2023 | /* 2. Multi-stream test */ | |
2024 | static const struct script_op script_2[] = { | |
2025 | OP_C_SET_ALPN ("ossltest") | |
2026 | OP_C_CONNECT_WAIT () | |
83df44ae | 2027 | OP_C_SET_INCOMING_STREAM_POLICY(SSL_INCOMING_STREAM_POLICY_ACCEPT) |
ed835673 HL |
2028 | OP_C_WRITE (DEFAULT, "apple", 5) |
2029 | OP_S_BIND_STREAM_ID (a, C_BIDI_ID(0)) | |
2030 | OP_S_READ_EXPECT (a, "apple", 5) | |
2031 | OP_S_WRITE (a, "orange", 6) | |
2032 | OP_C_READ_EXPECT (DEFAULT, "orange", 6) | |
2033 | ||
2034 | OP_C_NEW_STREAM_BIDI (b, C_BIDI_ID(1)) | |
2035 | OP_C_WRITE (b, "flamingo", 8) | |
2036 | OP_C_CONCLUDE (b) | |
2037 | OP_S_BIND_STREAM_ID (b, C_BIDI_ID(1)) | |
2038 | OP_S_READ_EXPECT (b, "flamingo", 8) | |
2039 | OP_S_EXPECT_FIN (b) | |
2040 | OP_S_WRITE (b, "gargoyle", 8) | |
2041 | OP_S_CONCLUDE (b) | |
2042 | OP_C_READ_EXPECT (b, "gargoyle", 8) | |
2043 | OP_C_EXPECT_FIN (b) | |
2044 | ||
2045 | OP_C_NEW_STREAM_UNI (c, C_UNI_ID(0)) | |
2046 | OP_C_WRITE (c, "elephant", 8) | |
2047 | OP_C_CONCLUDE (c) | |
2048 | OP_S_BIND_STREAM_ID (c, C_UNI_ID(0)) | |
2049 | OP_S_READ_EXPECT (c, "elephant", 8) | |
2050 | OP_S_EXPECT_FIN (c) | |
2051 | OP_S_WRITE_FAIL (c) | |
2052 | ||
2053 | OP_C_ACCEPT_STREAM_NONE () | |
2054 | ||
2055 | OP_S_NEW_STREAM_BIDI (d, S_BIDI_ID(0)) | |
2056 | OP_S_WRITE (d, "frog", 4) | |
2057 | OP_S_CONCLUDE (d) | |
2058 | ||
a350db73 | 2059 | OP_C_ACCEPT_STREAM_WAIT (d) |
ed835673 HL |
2060 | OP_C_ACCEPT_STREAM_NONE () |
2061 | OP_C_READ_EXPECT (d, "frog", 4) | |
2062 | OP_C_EXPECT_FIN (d) | |
2063 | ||
2064 | OP_S_NEW_STREAM_BIDI (e, S_BIDI_ID(1)) | |
2065 | OP_S_WRITE (e, "mixture", 7) | |
2066 | OP_S_CONCLUDE (e) | |
2067 | ||
a350db73 | 2068 | OP_C_ACCEPT_STREAM_WAIT (e) |
ed835673 HL |
2069 | OP_C_READ_EXPECT (e, "mixture", 7) |
2070 | OP_C_EXPECT_FIN (e) | |
2071 | OP_C_WRITE (e, "ramble", 6) | |
2072 | OP_S_READ_EXPECT (e, "ramble", 6) | |
2073 | OP_C_CONCLUDE (e) | |
2074 | OP_S_EXPECT_FIN (e) | |
2075 | ||
2076 | OP_S_NEW_STREAM_UNI (f, S_UNI_ID(0)) | |
2077 | OP_S_WRITE (f, "yonder", 6) | |
2078 | OP_S_CONCLUDE (f) | |
2079 | ||
a350db73 | 2080 | OP_C_ACCEPT_STREAM_WAIT (f) |
ed835673 HL |
2081 | OP_C_ACCEPT_STREAM_NONE () |
2082 | OP_C_READ_EXPECT (f, "yonder", 6) | |
2083 | OP_C_EXPECT_FIN (f) | |
2084 | OP_C_WRITE_FAIL (f) | |
2085 | ||
83df44ae | 2086 | OP_C_SET_INCOMING_STREAM_POLICY(SSL_INCOMING_STREAM_POLICY_REJECT) |
ed835673 HL |
2087 | OP_S_NEW_STREAM_BIDI (g, S_BIDI_ID(2)) |
2088 | OP_S_WRITE (g, "unseen", 6) | |
2089 | OP_S_CONCLUDE (g) | |
2090 | ||
2091 | OP_C_ACCEPT_STREAM_NONE () | |
2092 | ||
83df44ae | 2093 | OP_C_SET_INCOMING_STREAM_POLICY(SSL_INCOMING_STREAM_POLICY_AUTO) |
ed835673 HL |
2094 | OP_S_NEW_STREAM_BIDI (h, S_BIDI_ID(3)) |
2095 | OP_S_WRITE (h, "UNSEEN", 6) | |
2096 | OP_S_CONCLUDE (h) | |
2097 | ||
2098 | OP_C_ACCEPT_STREAM_NONE () | |
2099 | ||
2100 | /* | |
2101 | * Streams g, h should have been rejected, so server should have got | |
2102 | * STOP_SENDING/RESET_STREAM. | |
2103 | */ | |
2104 | OP_CHECK (check_rejected, S_BIDI_ID(2)) | |
2105 | OP_CHECK (check_rejected, S_BIDI_ID(3)) | |
2106 | ||
2107 | OP_END | |
2108 | }; | |
2109 | ||
2110 | /* 3. Default stream detach/reattach test */ | |
2111 | static const struct script_op script_3[] = { | |
2112 | OP_C_SET_ALPN ("ossltest") | |
2113 | OP_C_CONNECT_WAIT () | |
2114 | ||
2115 | OP_C_WRITE (DEFAULT, "apple", 5) | |
2116 | OP_C_DETACH (a) /* DEFAULT becomes stream 'a' */ | |
2117 | OP_C_WRITE_FAIL (DEFAULT) | |
2118 | ||
2119 | OP_C_WRITE (a, "by", 2) | |
2120 | ||
2121 | OP_S_BIND_STREAM_ID (a, C_BIDI_ID(0)) | |
2122 | OP_S_READ_EXPECT (a, "appleby", 7) | |
2123 | ||
2124 | OP_S_WRITE (a, "hello", 5) | |
2125 | OP_C_READ_EXPECT (a, "hello", 5) | |
2126 | ||
2127 | OP_C_WRITE_FAIL (DEFAULT) | |
2128 | OP_C_ATTACH (a) | |
2129 | OP_C_WRITE (DEFAULT, "is here", 7) | |
2130 | OP_S_READ_EXPECT (a, "is here", 7) | |
2131 | ||
2132 | OP_C_DETACH (a) | |
2133 | OP_C_CONCLUDE (a) | |
2134 | OP_S_EXPECT_FIN (a) | |
2135 | ||
2136 | OP_END | |
2137 | }; | |
2138 | ||
2139 | /* 4. Default stream mode test */ | |
2140 | static const struct script_op script_4[] = { | |
2141 | OP_C_SET_ALPN ("ossltest") | |
2142 | OP_C_CONNECT_WAIT () | |
2143 | ||
2144 | OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE) | |
2145 | OP_C_WRITE_FAIL (DEFAULT) | |
2146 | ||
2147 | OP_S_NEW_STREAM_BIDI (a, S_BIDI_ID(0)) | |
2148 | OP_S_WRITE (a, "apple", 5) | |
2149 | ||
2150 | OP_C_READ_FAIL (DEFAULT) | |
2151 | ||
a350db73 | 2152 | OP_C_ACCEPT_STREAM_WAIT (a) |
ed835673 HL |
2153 | OP_C_READ_EXPECT (a, "apple", 5) |
2154 | ||
2155 | OP_C_ATTACH (a) | |
2156 | OP_C_WRITE (DEFAULT, "orange", 6) | |
2157 | OP_S_READ_EXPECT (a, "orange", 6) | |
2158 | ||
2159 | OP_END | |
2160 | }; | |
2161 | ||
2162 | /* 5. Test stream reset functionality */ | |
2163 | static const struct script_op script_5[] = { | |
2164 | OP_C_SET_ALPN ("ossltest") | |
2165 | OP_C_CONNECT_WAIT () | |
2166 | ||
2167 | OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE) | |
2168 | OP_C_NEW_STREAM_BIDI (a, C_BIDI_ID(0)) | |
9ff3a99e | 2169 | OP_C_NEW_STREAM_BIDI (b, C_BIDI_ID(1)) |
ed835673 HL |
2170 | |
2171 | OP_C_WRITE (a, "apple", 5) | |
2172 | OP_C_STREAM_RESET (a, 42) | |
2173 | ||
9ff3a99e HL |
2174 | OP_C_WRITE (b, "strawberry", 10) |
2175 | ||
ed835673 | 2176 | OP_S_BIND_STREAM_ID (a, C_BIDI_ID(0)) |
9ff3a99e HL |
2177 | OP_S_BIND_STREAM_ID (b, C_BIDI_ID(1)) |
2178 | OP_S_READ_EXPECT (b, "strawberry", 10) | |
2f018d14 HL |
2179 | /* Reset disrupts read of already sent data */ |
2180 | OP_S_READ_FAIL (a) | |
ed835673 HL |
2181 | OP_CHECK (check_stream_reset, C_BIDI_ID(0)) |
2182 | ||
2183 | OP_END | |
2184 | }; | |
2185 | ||
2186 | /* 6. Test STOP_SENDING functionality */ | |
2187 | static const struct script_op script_6[] = { | |
2188 | OP_C_SET_ALPN ("ossltest") | |
2189 | OP_C_CONNECT_WAIT () | |
2190 | ||
2191 | OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE) | |
2192 | OP_S_NEW_STREAM_BIDI (a, S_BIDI_ID(0)) | |
2193 | OP_S_WRITE (a, "apple", 5) | |
2194 | ||
a350db73 | 2195 | OP_C_ACCEPT_STREAM_WAIT (a) |
ed835673 HL |
2196 | OP_C_FREE_STREAM (a) |
2197 | OP_C_ACCEPT_STREAM_NONE () | |
2198 | ||
2199 | OP_CHECK (check_stream_stopped, S_BIDI_ID(0)) | |
2200 | ||
2201 | OP_END | |
2202 | }; | |
2203 | ||
2204 | /* 7. Unidirectional default stream mode test (client sends first) */ | |
2205 | static const struct script_op script_7[] = { | |
2206 | OP_C_SET_ALPN ("ossltest") | |
2207 | OP_C_CONNECT_WAIT () | |
2208 | ||
2209 | OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_AUTO_UNI) | |
2210 | OP_C_WRITE (DEFAULT, "apple", 5) | |
2211 | ||
2212 | OP_S_BIND_STREAM_ID (a, C_UNI_ID(0)) | |
2213 | OP_S_READ_EXPECT (a, "apple", 5) | |
2214 | OP_S_WRITE_FAIL (a) | |
2215 | ||
2216 | OP_END | |
2217 | }; | |
2218 | ||
2219 | /* 8. Unidirectional default stream mode test (server sends first) */ | |
2220 | static const struct script_op script_8[] = { | |
2221 | OP_C_SET_ALPN ("ossltest") | |
2222 | OP_C_CONNECT_WAIT () | |
2223 | ||
2224 | OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_AUTO_UNI) | |
2225 | OP_S_NEW_STREAM_UNI (a, S_UNI_ID(0)) | |
2226 | OP_S_WRITE (a, "apple", 5) | |
2227 | OP_C_READ_EXPECT (DEFAULT, "apple", 5) | |
2228 | OP_C_WRITE_FAIL (DEFAULT) | |
2229 | ||
2230 | OP_END | |
2231 | }; | |
2232 | ||
2233 | /* 9. Unidirectional default stream mode test (server sends first on bidi) */ | |
2234 | static const struct script_op script_9[] = { | |
2235 | OP_C_SET_ALPN ("ossltest") | |
2236 | OP_C_CONNECT_WAIT () | |
2237 | ||
2238 | OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_AUTO_UNI) | |
2239 | OP_S_NEW_STREAM_BIDI (a, S_BIDI_ID(0)) | |
2240 | OP_S_WRITE (a, "apple", 5) | |
2241 | OP_C_READ_EXPECT (DEFAULT, "apple", 5) | |
2242 | OP_C_WRITE (DEFAULT, "orange", 6) | |
2243 | OP_S_READ_EXPECT (a, "orange", 6) | |
2244 | ||
2245 | OP_END | |
2246 | }; | |
2247 | ||
2248 | /* 10. Shutdown */ | |
2249 | static const struct script_op script_10[] = { | |
2250 | OP_C_SET_ALPN ("ossltest") | |
2251 | OP_C_CONNECT_WAIT () | |
2252 | ||
2253 | OP_C_WRITE (DEFAULT, "apple", 5) | |
2254 | OP_S_BIND_STREAM_ID (a, C_BIDI_ID(0)) | |
2255 | OP_S_READ_EXPECT (a, "apple", 5) | |
2256 | ||
3bc38ba0 | 2257 | OP_C_SHUTDOWN_WAIT (NULL, 0) |
ed835673 HL |
2258 | OP_C_EXPECT_CONN_CLOSE_INFO(0, 1, 0) |
2259 | OP_S_EXPECT_CONN_CLOSE_INFO(0, 1, 1) | |
2260 | ||
2261 | OP_END | |
2262 | }; | |
2263 | ||
fca44cfc | 2264 | /* 11. Many threads accepted on the same client connection */ |
274bb489 HL |
2265 | static const struct script_op script_11_child[] = { |
2266 | OP_C_ACCEPT_STREAM_WAIT (a) | |
2267 | OP_C_READ_EXPECT (a, "foo", 3) | |
2268 | OP_C_EXPECT_FIN (a) | |
2269 | ||
2270 | OP_END | |
2271 | }; | |
2272 | ||
2273 | static const struct script_op script_11[] = { | |
2274 | OP_C_SET_ALPN ("ossltest") | |
2275 | OP_C_CONNECT_WAIT () | |
2276 | OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE) | |
2277 | ||
fca44cfc HL |
2278 | OP_NEW_THREAD (5, script_11_child) |
2279 | ||
2280 | OP_S_NEW_STREAM_BIDI (a, ANY_ID) | |
274bb489 HL |
2281 | OP_S_WRITE (a, "foo", 3) |
2282 | OP_S_CONCLUDE (a) | |
2283 | ||
fca44cfc | 2284 | OP_S_NEW_STREAM_BIDI (b, ANY_ID) |
274bb489 HL |
2285 | OP_S_WRITE (b, "foo", 3) |
2286 | OP_S_CONCLUDE (b) | |
2287 | ||
fca44cfc | 2288 | OP_S_NEW_STREAM_BIDI (c, ANY_ID) |
274bb489 HL |
2289 | OP_S_WRITE (c, "foo", 3) |
2290 | OP_S_CONCLUDE (c) | |
2291 | ||
fca44cfc | 2292 | OP_S_NEW_STREAM_BIDI (d, ANY_ID) |
274bb489 HL |
2293 | OP_S_WRITE (d, "foo", 3) |
2294 | OP_S_CONCLUDE (d) | |
2295 | ||
fca44cfc | 2296 | OP_S_NEW_STREAM_BIDI (e, ANY_ID) |
274bb489 HL |
2297 | OP_S_WRITE (e, "foo", 3) |
2298 | OP_S_CONCLUDE (e) | |
2299 | ||
274bb489 HL |
2300 | OP_END |
2301 | }; | |
2302 | ||
fca44cfc | 2303 | /* 12. Many threads initiated on the same client connection */ |
274bb489 HL |
2304 | static const struct script_op script_12_child[] = { |
2305 | OP_C_NEW_STREAM_BIDI (a, ANY_ID) | |
2306 | OP_C_WRITE (a, "foo", 3) | |
2307 | OP_C_CONCLUDE (a) | |
2308 | OP_C_FREE_STREAM (a) | |
2309 | ||
2310 | OP_END | |
2311 | }; | |
2312 | ||
2313 | static const struct script_op script_12[] = { | |
2314 | OP_C_SET_ALPN ("ossltest") | |
2315 | OP_C_CONNECT_WAIT () | |
2316 | OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE) | |
2317 | ||
2318 | OP_NEW_THREAD (5, script_12_child) | |
2319 | ||
2320 | OP_S_BIND_STREAM_ID (a, C_BIDI_ID(0)) | |
2321 | OP_S_READ_EXPECT (a, "foo", 3) | |
2322 | OP_S_EXPECT_FIN (a) | |
2323 | OP_S_BIND_STREAM_ID (b, C_BIDI_ID(1)) | |
2324 | OP_S_READ_EXPECT (b, "foo", 3) | |
2325 | OP_S_EXPECT_FIN (b) | |
2326 | OP_S_BIND_STREAM_ID (c, C_BIDI_ID(2)) | |
2327 | OP_S_READ_EXPECT (c, "foo", 3) | |
2328 | OP_S_EXPECT_FIN (c) | |
2329 | OP_S_BIND_STREAM_ID (d, C_BIDI_ID(3)) | |
2330 | OP_S_READ_EXPECT (d, "foo", 3) | |
2331 | OP_S_EXPECT_FIN (d) | |
2332 | OP_S_BIND_STREAM_ID (e, C_BIDI_ID(4)) | |
2333 | OP_S_READ_EXPECT (e, "foo", 3) | |
2334 | OP_S_EXPECT_FIN (e) | |
2335 | ||
2336 | OP_END | |
2337 | }; | |
2338 | ||
fca44cfc HL |
2339 | /* 13. Many threads accepted on the same client connection (stress test) */ |
2340 | static const struct script_op script_13_child[] = { | |
2341 | OP_BEGIN_REPEAT (10) | |
2342 | ||
2343 | OP_C_ACCEPT_STREAM_WAIT (a) | |
2344 | OP_C_READ_EXPECT (a, "foo", 3) | |
2345 | OP_C_EXPECT_FIN (a) | |
2346 | OP_C_FREE_STREAM (a) | |
2347 | ||
2348 | OP_END_REPEAT () | |
2349 | ||
2350 | OP_END | |
2351 | }; | |
2352 | ||
2353 | static const struct script_op script_13[] = { | |
2354 | OP_C_SET_ALPN ("ossltest") | |
2355 | OP_C_CONNECT_WAIT () | |
2356 | OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE) | |
2357 | ||
2358 | OP_NEW_THREAD (5, script_13_child) | |
2359 | ||
2360 | OP_BEGIN_REPEAT (50) | |
2361 | ||
2362 | OP_S_NEW_STREAM_BIDI (a, ANY_ID) | |
2363 | OP_S_WRITE (a, "foo", 3) | |
2364 | OP_S_CONCLUDE (a) | |
2365 | OP_S_UNBIND_STREAM_ID (a) | |
2366 | ||
2367 | OP_END_REPEAT () | |
2368 | ||
2369 | OP_END | |
2370 | }; | |
2371 | ||
2372 | /* 14. Many threads initiating on the same client connection (stress test) */ | |
2373 | static const struct script_op script_14_child[] = { | |
2374 | OP_BEGIN_REPEAT (10) | |
2375 | ||
2376 | OP_C_NEW_STREAM_BIDI (a, ANY_ID) | |
2377 | OP_C_WRITE (a, "foo", 3) | |
2378 | OP_C_CONCLUDE (a) | |
2379 | OP_C_FREE_STREAM (a) | |
2380 | ||
2381 | OP_END_REPEAT () | |
2382 | ||
2383 | OP_END | |
2384 | }; | |
2385 | ||
2386 | static const struct script_op script_14[] = { | |
2387 | OP_C_SET_ALPN ("ossltest") | |
2388 | OP_C_CONNECT_WAIT () | |
2389 | OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE) | |
2390 | ||
2391 | OP_NEW_THREAD (5, script_14_child) | |
2392 | ||
2393 | OP_BEGIN_REPEAT (50) | |
2394 | ||
2395 | OP_S_ACCEPT_STREAM_WAIT (a) | |
2396 | OP_S_READ_EXPECT (a, "foo", 3) | |
2397 | OP_S_EXPECT_FIN (a) | |
2398 | OP_S_UNBIND_STREAM_ID (a) | |
2399 | ||
2400 | OP_END_REPEAT () | |
2401 | ||
2402 | OP_END | |
2403 | }; | |
2404 | ||
0554f723 HL |
2405 | /* 15. Client sending large number of streams, MAX_STREAMS test */ |
2406 | static const struct script_op script_15[] = { | |
2407 | OP_C_SET_ALPN ("ossltest") | |
2408 | OP_C_CONNECT_WAIT () | |
2409 | OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE) | |
2410 | ||
2411 | /* | |
2412 | * This will cause a protocol violation to be raised by the server if we are | |
2413 | * not handling the stream limit correctly on the TX side. | |
2414 | */ | |
2415 | OP_BEGIN_REPEAT (200) | |
2416 | ||
14551f1e | 2417 | OP_C_NEW_STREAM_BIDI_EX (a, ANY_ID, SSL_STREAM_FLAG_ADVANCE) |
0554f723 HL |
2418 | OP_C_WRITE (a, "foo", 3) |
2419 | OP_C_CONCLUDE (a) | |
2420 | OP_C_FREE_STREAM (a) | |
2421 | ||
2422 | OP_END_REPEAT () | |
2423 | ||
2424 | /* Prove the connection is still good. */ | |
2425 | OP_S_NEW_STREAM_BIDI (a, S_BIDI_ID(0)) | |
2426 | OP_S_WRITE (a, "bar", 3) | |
2427 | OP_S_CONCLUDE (a) | |
2428 | ||
2429 | OP_C_ACCEPT_STREAM_WAIT (a) | |
2430 | OP_C_READ_EXPECT (a, "bar", 3) | |
2431 | OP_C_EXPECT_FIN (a) | |
2432 | ||
2433 | /* | |
2434 | * Drain the queue of incoming streams. We should be able to get all 200 | |
2435 | * even though only 100 can be initiated at a time. | |
2436 | */ | |
2437 | OP_BEGIN_REPEAT (200) | |
2438 | ||
2439 | OP_S_ACCEPT_STREAM_WAIT (b) | |
2440 | OP_S_READ_EXPECT (b, "foo", 3) | |
2441 | OP_S_EXPECT_FIN (b) | |
2442 | OP_S_UNBIND_STREAM_ID (b) | |
2443 | ||
2444 | OP_END_REPEAT () | |
2445 | ||
2446 | OP_END | |
2447 | }; | |
2448 | ||
2449 | /* 16. Server sending large number of streams, MAX_STREAMS test */ | |
2450 | static const struct script_op script_16[] = { | |
2451 | OP_C_SET_ALPN ("ossltest") | |
2452 | OP_C_CONNECT_WAIT () | |
2453 | OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE) | |
2454 | ||
2455 | /* | |
2456 | * This will cause a protocol violation to be raised by the client if we are | |
2457 | * not handling the stream limit correctly on the TX side. | |
2458 | */ | |
2459 | OP_BEGIN_REPEAT (200) | |
2460 | ||
2461 | OP_S_NEW_STREAM_BIDI (a, ANY_ID) | |
2462 | OP_S_WRITE (a, "foo", 3) | |
2463 | OP_S_CONCLUDE (a) | |
2464 | OP_S_UNBIND_STREAM_ID (a) | |
2465 | ||
2466 | OP_END_REPEAT () | |
2467 | ||
2468 | /* Prove that the connection is still good. */ | |
2469 | OP_C_NEW_STREAM_BIDI (a, ANY_ID) | |
2470 | OP_C_WRITE (a, "bar", 3) | |
2471 | OP_C_CONCLUDE (a) | |
2472 | ||
2473 | OP_S_ACCEPT_STREAM_WAIT (b) | |
2474 | OP_S_READ_EXPECT (b, "bar", 3) | |
2475 | OP_S_EXPECT_FIN (b) | |
2476 | ||
2477 | /* Drain the queue of incoming streams. */ | |
2478 | OP_BEGIN_REPEAT (200) | |
2479 | ||
2480 | OP_C_ACCEPT_STREAM_WAIT (b) | |
2481 | OP_C_READ_EXPECT (b, "foo", 3) | |
2482 | OP_C_EXPECT_FIN (b) | |
2483 | OP_C_FREE_STREAM (b) | |
2484 | ||
2485 | OP_END_REPEAT () | |
2486 | ||
2487 | OP_END | |
2488 | }; | |
2489 | ||
693b23e3 HL |
2490 | /* 17. Key update test - unlimited */ |
2491 | static const struct script_op script_17[] = { | |
2492 | OP_C_SET_ALPN ("ossltest") | |
2493 | OP_C_CONNECT_WAIT () | |
2494 | ||
2495 | OP_C_WRITE (DEFAULT, "apple", 5) | |
2496 | ||
2497 | OP_S_BIND_STREAM_ID (a, C_BIDI_ID(0)) | |
2498 | OP_S_READ_EXPECT (a, "apple", 5) | |
2499 | ||
2500 | OP_CHECK (override_key_update, 1) | |
2501 | ||
2502 | OP_BEGIN_REPEAT (200) | |
2503 | ||
2504 | OP_C_WRITE (DEFAULT, "apple", 5) | |
2505 | OP_S_READ_EXPECT (a, "apple", 5) | |
2506 | ||
2507 | /* | |
2508 | * TXKU frequency is bounded by RTT because a previous TXKU needs to be | |
2509 | * acknowledged by the peer first before another one can be begin. By | |
2510 | * waiting this long, we eliminate any such concern and ensure as many key | |
2511 | * updates as possible can occur for the purposes of this test. | |
2512 | */ | |
2513 | OP_CHECK (skip_time_ms, 100) | |
2514 | ||
2515 | OP_END_REPEAT () | |
2516 | ||
2517 | /* At least 5 RXKUs detected */ | |
2518 | OP_CHECK (check_key_update_ge, 5) | |
2519 | ||
2520 | /* | |
2521 | * Prove the connection is still healthy by sending something in both | |
2522 | * directions. | |
2523 | */ | |
2524 | OP_C_WRITE (DEFAULT, "xyzzy", 5) | |
2525 | OP_S_READ_EXPECT (a, "xyzzy", 5) | |
2526 | ||
2527 | OP_S_WRITE (a, "plugh", 5) | |
2528 | OP_C_READ_EXPECT (DEFAULT, "plugh", 5) | |
2529 | ||
2530 | OP_END | |
2531 | }; | |
2532 | ||
2533 | /* 18. Key update test - RTT-bounded */ | |
2534 | static const struct script_op script_18[] = { | |
2535 | OP_C_SET_ALPN ("ossltest") | |
2536 | OP_C_CONNECT_WAIT () | |
2537 | ||
2538 | OP_C_WRITE (DEFAULT, "apple", 5) | |
2539 | ||
2540 | OP_S_BIND_STREAM_ID (a, C_BIDI_ID(0)) | |
2541 | OP_S_READ_EXPECT (a, "apple", 5) | |
2542 | ||
2543 | OP_CHECK (override_key_update, 1) | |
2544 | ||
2545 | OP_BEGIN_REPEAT (200) | |
2546 | ||
2547 | OP_C_WRITE (DEFAULT, "apple", 5) | |
2548 | OP_S_READ_EXPECT (a, "apple", 5) | |
de9564bd | 2549 | OP_CHECK (skip_time_ms, 8) |
693b23e3 HL |
2550 | |
2551 | OP_END_REPEAT () | |
2552 | ||
2553 | /* | |
2554 | * This time we simulate far less time passing between writes, so there are | |
2555 | * fewer opportunities to initiate TXKUs. Note that we ask for a TXKU every | |
2556 | * 1 packet above, which is absurd; thus this ensures we only actually | |
2557 | * generate TXKUs when we are allowed to. | |
2558 | */ | |
0e1da9d7 | 2559 | OP_CHECK (check_key_update_lt, 240) |
693b23e3 HL |
2560 | |
2561 | /* | |
2562 | * Prove the connection is still healthy by sending something in both | |
2563 | * directions. | |
2564 | */ | |
2565 | OP_C_WRITE (DEFAULT, "xyzzy", 5) | |
2566 | OP_S_READ_EXPECT (a, "xyzzy", 5) | |
2567 | ||
2568 | OP_S_WRITE (a, "plugh", 5) | |
2569 | OP_C_READ_EXPECT (DEFAULT, "plugh", 5) | |
2570 | ||
2571 | OP_END | |
2572 | }; | |
2573 | ||
2525109f HL |
2574 | /* 19. Key update test - artificially triggered */ |
2575 | static const struct script_op script_19[] = { | |
2576 | OP_C_SET_ALPN ("ossltest") | |
2577 | OP_C_CONNECT_WAIT () | |
2578 | ||
2579 | OP_C_WRITE (DEFAULT, "apple", 5) | |
2580 | ||
2581 | OP_S_BIND_STREAM_ID (a, C_BIDI_ID(0)) | |
2582 | OP_S_READ_EXPECT (a, "apple", 5) | |
2583 | ||
76696a54 HL |
2584 | OP_C_WRITE (DEFAULT, "orange", 6) |
2585 | OP_S_READ_EXPECT (a, "orange", 6) | |
2586 | ||
2587 | OP_S_WRITE (a, "strawberry", 10) | |
2588 | OP_C_READ_EXPECT (DEFAULT, "strawberry", 10) | |
2589 | ||
2525109f HL |
2590 | OP_CHECK (check_key_update_lt, 1) |
2591 | OP_CHECK (trigger_key_update, 0) | |
2592 | ||
2593 | OP_C_WRITE (DEFAULT, "orange", 6) | |
2594 | OP_S_READ_EXPECT (a, "orange", 6) | |
9289e59c | 2595 | OP_S_WRITE (a, "ok", 2) |
2525109f | 2596 | |
9289e59c | 2597 | OP_C_READ_EXPECT (DEFAULT, "ok", 2) |
2525109f HL |
2598 | OP_CHECK (check_key_update_ge, 1) |
2599 | ||
2600 | OP_END | |
2601 | }; | |
2602 | ||
0345cac6 | 2603 | /* 20. Multiple threads accept stream with socket forcibly closed (error test) */ |
99d6b9f9 HL |
2604 | static int script_20_trigger(struct helper *h, volatile uint64_t *counter) |
2605 | { | |
2606 | #if defined(OPENSSL_THREADS) | |
2607 | ossl_crypto_mutex_lock(h->misc_m); | |
2608 | ++*counter; | |
2609 | ossl_crypto_mutex_unlock(h->misc_m); | |
2610 | ossl_crypto_condvar_broadcast(h->misc_cv); | |
2611 | #endif | |
2612 | return 1; | |
2613 | } | |
2614 | ||
2615 | static int script_20_wait(struct helper *h, volatile uint64_t *counter, uint64_t threshold) | |
2616 | { | |
2617 | #if defined(OPENSSL_THREADS) | |
2618 | int stop = 0; | |
2619 | ||
2620 | ossl_crypto_mutex_lock(h->misc_m); | |
2621 | while (!stop) { | |
2622 | stop = (*counter >= threshold); | |
2623 | if (stop) | |
2624 | break; | |
2625 | ||
2626 | ossl_crypto_condvar_wait(h->misc_cv, h->misc_m); | |
2627 | } | |
2628 | ||
2629 | ossl_crypto_mutex_unlock(h->misc_m); | |
2630 | #endif | |
2631 | return 1; | |
2632 | } | |
2633 | ||
2634 | static int script_20_trigger1(struct helper *h, struct helper_local *hl) | |
2635 | { | |
2636 | return script_20_trigger(h, &h->scratch0); | |
2637 | } | |
2638 | ||
2639 | static int script_20_wait1(struct helper *h, struct helper_local *hl) | |
2640 | { | |
2641 | return script_20_wait(h, &h->scratch0, hl->check_op->arg2); | |
2642 | } | |
2643 | ||
2644 | static int script_20_trigger2(struct helper *h, struct helper_local *hl) | |
2645 | { | |
2646 | return script_20_trigger(h, &h->scratch1); | |
2647 | } | |
2648 | ||
2649 | static int script_20_wait2(struct helper *h, struct helper_local *hl) | |
2650 | { | |
2651 | return script_20_wait(h, &h->scratch1, hl->check_op->arg2); | |
2652 | } | |
2653 | ||
0345cac6 TM |
2654 | static const struct script_op script_20_child[] = { |
2655 | OP_C_ACCEPT_STREAM_WAIT (a) | |
2656 | OP_C_READ_EXPECT (a, "foo", 3) | |
2657 | ||
99d6b9f9 HL |
2658 | OP_CHECK (script_20_trigger1, 0) |
2659 | OP_CHECK (script_20_wait2, 1) | |
0345cac6 TM |
2660 | |
2661 | OP_C_READ_FAIL_WAIT (a) | |
2662 | OP_C_EXPECT_SSL_ERR (a, SSL_ERROR_SYSCALL) | |
2663 | OP_EXPECT_ERR_LIB (ERR_LIB_SYS) | |
741170be | 2664 | OP_EXPECT_ERR_REASON (SSL_R_QUIC_NETWORK_ERROR) |
0345cac6 TM |
2665 | OP_C_FREE_STREAM (a) |
2666 | ||
2667 | OP_END | |
2668 | }; | |
2669 | ||
2670 | static const struct script_op script_20[] = { | |
2671 | OP_C_SET_ALPN ("ossltest") | |
2672 | OP_C_CONNECT_WAIT () | |
2673 | OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE) | |
2674 | ||
2675 | OP_NEW_THREAD (5, script_20_child) | |
2676 | ||
2677 | OP_BEGIN_REPEAT (5) | |
2678 | ||
2679 | OP_S_NEW_STREAM_BIDI (a, ANY_ID) | |
2680 | OP_S_WRITE (a, "foo", 3) | |
2681 | OP_S_UNBIND_STREAM_ID (a) | |
2682 | ||
2683 | OP_END_REPEAT () | |
2684 | ||
99d6b9f9 | 2685 | OP_CHECK (script_20_wait1, 5) |
0345cac6 TM |
2686 | |
2687 | OP_C_CLOSE_SOCKET () | |
99d6b9f9 | 2688 | OP_CHECK (script_20_trigger2, 0) |
0345cac6 TM |
2689 | |
2690 | OP_END | |
2691 | }; | |
2692 | ||
e26dc8e3 HL |
2693 | /* 21. Fault injection - unknown frame in 1-RTT packet */ |
2694 | static int script_21_inject_plain(struct helper *h, QUIC_PKT_HDR *hdr, | |
2695 | unsigned char *buf, size_t len) | |
2696 | { | |
7eebc354 | 2697 | int ok = 0; |
e26dc8e3 HL |
2698 | WPACKET wpkt; |
2699 | unsigned char frame_buf[8]; | |
2700 | size_t written; | |
2701 | ||
2702 | if (h->inject_word0 == 0 || hdr->type != h->inject_word0) | |
2703 | return 1; | |
2704 | ||
2705 | if (!TEST_true(WPACKET_init_static_len(&wpkt, frame_buf, | |
2706 | sizeof(frame_buf), 0))) | |
2707 | return 0; | |
2708 | ||
2709 | if (!TEST_true(WPACKET_quic_write_vlint(&wpkt, h->inject_word1))) | |
7eebc354 | 2710 | goto err; |
e26dc8e3 HL |
2711 | |
2712 | if (!TEST_true(WPACKET_get_total_written(&wpkt, &written))) | |
7eebc354 | 2713 | goto err; |
e26dc8e3 HL |
2714 | |
2715 | if (!qtest_fault_prepend_frame(h->qtf, frame_buf, written)) | |
7eebc354 | 2716 | goto err; |
e26dc8e3 | 2717 | |
7eebc354 HL |
2718 | ok = 1; |
2719 | err: | |
96b7df60 HL |
2720 | if (ok) |
2721 | WPACKET_finish(&wpkt); | |
2722 | else | |
2723 | WPACKET_cleanup(&wpkt); | |
7eebc354 | 2724 | return ok; |
e26dc8e3 HL |
2725 | } |
2726 | ||
2727 | static const struct script_op script_21[] = { | |
2728 | OP_S_SET_INJECT_PLAIN (script_21_inject_plain) | |
2729 | OP_C_SET_ALPN ("ossltest") | |
2730 | OP_C_CONNECT_WAIT () | |
2731 | ||
2732 | OP_C_WRITE (DEFAULT, "apple", 5) | |
2733 | OP_S_BIND_STREAM_ID (a, C_BIDI_ID(0)) | |
2734 | OP_S_READ_EXPECT (a, "apple", 5) | |
2735 | ||
2736 | OP_SET_INJECT_WORD (QUIC_PKT_TYPE_1RTT, OSSL_QUIC_VLINT_MAX) | |
2737 | ||
2738 | OP_S_WRITE (a, "orange", 6) | |
2739 | ||
2740 | OP_C_EXPECT_CONN_CLOSE_INFO(QUIC_ERR_FRAME_ENCODING_ERROR,0,0) | |
2741 | ||
2742 | OP_END | |
2743 | }; | |
2744 | ||
2745 | /* 22. Fault injection - non-zero packet header reserved bits */ | |
2746 | static int script_22_inject_plain(struct helper *h, QUIC_PKT_HDR *hdr, | |
2747 | unsigned char *buf, size_t len) | |
2748 | { | |
2749 | if (h->inject_word0 == 0) | |
2750 | return 1; | |
2751 | ||
2752 | hdr->reserved = 1; | |
2753 | return 1; | |
2754 | } | |
2755 | ||
2756 | static const struct script_op script_22[] = { | |
2757 | OP_S_SET_INJECT_PLAIN (script_22_inject_plain) | |
2758 | OP_C_SET_ALPN ("ossltest") | |
2759 | OP_C_CONNECT_WAIT () | |
2760 | ||
2761 | OP_C_WRITE (DEFAULT, "apple", 5) | |
2762 | OP_S_BIND_STREAM_ID (a, C_BIDI_ID(0)) | |
2763 | OP_S_READ_EXPECT (a, "apple", 5) | |
2764 | ||
2765 | OP_SET_INJECT_WORD (1, 0) | |
2766 | ||
2767 | OP_S_WRITE (a, "orange", 6) | |
2768 | ||
2769 | OP_C_EXPECT_CONN_CLOSE_INFO(QUIC_ERR_PROTOCOL_VIOLATION,0,0) | |
2770 | ||
2771 | OP_END | |
2772 | }; | |
2773 | ||
2774 | /* 23. Fault injection - empty NEW_TOKEN */ | |
2775 | static int script_23_inject_plain(struct helper *h, QUIC_PKT_HDR *hdr, | |
2776 | unsigned char *buf, size_t len) | |
2777 | { | |
7eebc354 | 2778 | int ok = 0; |
e26dc8e3 HL |
2779 | WPACKET wpkt; |
2780 | unsigned char frame_buf[16]; | |
2781 | size_t written; | |
2782 | ||
2783 | if (h->inject_word0 == 0) | |
2784 | return 1; | |
2785 | ||
2786 | if (!TEST_true(WPACKET_init_static_len(&wpkt, frame_buf, | |
2787 | sizeof(frame_buf), 0))) | |
2788 | return 0; | |
2789 | ||
2790 | if (!TEST_true(WPACKET_quic_write_vlint(&wpkt, OSSL_QUIC_FRAME_TYPE_NEW_TOKEN)) | |
2791 | || !TEST_true(WPACKET_quic_write_vlint(&wpkt, 0))) | |
7eebc354 | 2792 | goto err; |
e26dc8e3 HL |
2793 | |
2794 | if (!TEST_true(WPACKET_get_total_written(&wpkt, &written))) | |
7eebc354 | 2795 | goto err; |
e26dc8e3 HL |
2796 | |
2797 | if (!qtest_fault_prepend_frame(h->qtf, frame_buf, written)) | |
7eebc354 | 2798 | goto err; |
e26dc8e3 | 2799 | |
7eebc354 HL |
2800 | ok = 1; |
2801 | err: | |
96b7df60 HL |
2802 | if (ok) |
2803 | WPACKET_finish(&wpkt); | |
2804 | else | |
2805 | WPACKET_cleanup(&wpkt); | |
7eebc354 | 2806 | return ok; |
e26dc8e3 HL |
2807 | } |
2808 | ||
2809 | static const struct script_op script_23[] = { | |
2810 | OP_S_SET_INJECT_PLAIN (script_23_inject_plain) | |
2811 | OP_C_SET_ALPN ("ossltest") | |
2812 | OP_C_CONNECT_WAIT () | |
2813 | ||
2814 | OP_C_WRITE (DEFAULT, "apple", 5) | |
2815 | OP_S_BIND_STREAM_ID (a, C_BIDI_ID(0)) | |
2816 | OP_S_READ_EXPECT (a, "apple", 5) | |
2817 | ||
2818 | OP_SET_INJECT_WORD (1, 0) | |
2819 | ||
2820 | OP_S_WRITE (a, "orange", 6) | |
2821 | ||
2822 | OP_C_EXPECT_CONN_CLOSE_INFO(QUIC_ERR_FRAME_ENCODING_ERROR,0,0) | |
2823 | ||
2824 | OP_END | |
2825 | }; | |
2826 | ||
2827 | /* 24. Fault injection - excess value of MAX_STREAMS_BIDI */ | |
2828 | static int script_24_inject_plain(struct helper *h, QUIC_PKT_HDR *hdr, | |
2829 | unsigned char *buf, size_t len) | |
2830 | { | |
7eebc354 | 2831 | int ok = 0; |
e26dc8e3 HL |
2832 | WPACKET wpkt; |
2833 | unsigned char frame_buf[16]; | |
2834 | size_t written; | |
2835 | ||
2836 | if (h->inject_word0 == 0) | |
2837 | return 1; | |
2838 | ||
2839 | if (!TEST_true(WPACKET_init_static_len(&wpkt, frame_buf, | |
2840 | sizeof(frame_buf), 0))) | |
2841 | return 0; | |
2842 | ||
2843 | if (!TEST_true(WPACKET_quic_write_vlint(&wpkt, h->inject_word1)) | |
2844 | || !TEST_true(WPACKET_quic_write_vlint(&wpkt, (((uint64_t)1) << 60) + 1))) | |
7eebc354 | 2845 | goto err; |
e26dc8e3 HL |
2846 | |
2847 | if (!TEST_true(WPACKET_get_total_written(&wpkt, &written))) | |
7eebc354 | 2848 | goto err; |
e26dc8e3 HL |
2849 | |
2850 | if (!qtest_fault_prepend_frame(h->qtf, frame_buf, written)) | |
7eebc354 | 2851 | goto err; |
e26dc8e3 | 2852 | |
7eebc354 HL |
2853 | ok = 1; |
2854 | err: | |
96b7df60 HL |
2855 | if (ok) |
2856 | WPACKET_finish(&wpkt); | |
2857 | else | |
2858 | WPACKET_cleanup(&wpkt); | |
7eebc354 | 2859 | return ok; |
e26dc8e3 HL |
2860 | } |
2861 | ||
2862 | static const struct script_op script_24[] = { | |
2863 | OP_S_SET_INJECT_PLAIN (script_24_inject_plain) | |
2864 | OP_C_SET_ALPN ("ossltest") | |
2865 | OP_C_CONNECT_WAIT () | |
2866 | ||
2867 | OP_C_WRITE (DEFAULT, "apple", 5) | |
2868 | OP_S_BIND_STREAM_ID (a, C_BIDI_ID(0)) | |
2869 | OP_S_READ_EXPECT (a, "apple", 5) | |
2870 | ||
2871 | OP_SET_INJECT_WORD (1, OSSL_QUIC_FRAME_TYPE_MAX_STREAMS_BIDI) | |
2872 | ||
2873 | OP_S_WRITE (a, "orange", 6) | |
2874 | ||
2875 | OP_C_EXPECT_CONN_CLOSE_INFO(QUIC_ERR_FRAME_ENCODING_ERROR,0,0) | |
2876 | ||
2877 | OP_END | |
2878 | }; | |
2879 | ||
2880 | /* 25. Fault injection - excess value of MAX_STREAMS_UNI */ | |
2881 | static const struct script_op script_25[] = { | |
2882 | OP_S_SET_INJECT_PLAIN (script_24_inject_plain) | |
2883 | OP_C_SET_ALPN ("ossltest") | |
2884 | OP_C_CONNECT_WAIT () | |
2885 | ||
2886 | OP_C_WRITE (DEFAULT, "apple", 5) | |
2887 | OP_S_BIND_STREAM_ID (a, C_BIDI_ID(0)) | |
2888 | OP_S_READ_EXPECT (a, "apple", 5) | |
2889 | ||
2890 | OP_SET_INJECT_WORD (1, OSSL_QUIC_FRAME_TYPE_MAX_STREAMS_UNI) | |
2891 | ||
2892 | OP_S_WRITE (a, "orange", 6) | |
2893 | ||
2894 | OP_C_EXPECT_CONN_CLOSE_INFO(QUIC_ERR_FRAME_ENCODING_ERROR,0,0) | |
2895 | ||
2896 | OP_END | |
2897 | }; | |
2898 | ||
2899 | /* 26. Fault injection - excess value of STREAMS_BLOCKED_BIDI */ | |
2900 | static const struct script_op script_26[] = { | |
2901 | OP_S_SET_INJECT_PLAIN (script_24_inject_plain) | |
2902 | OP_C_SET_ALPN ("ossltest") | |
2903 | OP_C_CONNECT_WAIT () | |
2904 | ||
2905 | OP_C_WRITE (DEFAULT, "apple", 5) | |
2906 | OP_S_BIND_STREAM_ID (a, C_BIDI_ID(0)) | |
2907 | OP_S_READ_EXPECT (a, "apple", 5) | |
2908 | ||
2909 | OP_SET_INJECT_WORD (1, OSSL_QUIC_FRAME_TYPE_STREAMS_BLOCKED_BIDI) | |
2910 | ||
2911 | OP_S_WRITE (a, "orange", 6) | |
2912 | ||
2913 | OP_C_EXPECT_CONN_CLOSE_INFO(QUIC_ERR_STREAM_LIMIT_ERROR,0,0) | |
2914 | ||
2915 | OP_END | |
2916 | }; | |
2917 | ||
2918 | /* 27. Fault injection - excess value of STREAMS_BLOCKED_UNI */ | |
2919 | static const struct script_op script_27[] = { | |
2920 | OP_S_SET_INJECT_PLAIN (script_24_inject_plain) | |
2921 | OP_C_SET_ALPN ("ossltest") | |
2922 | OP_C_CONNECT_WAIT () | |
2923 | ||
2924 | OP_C_WRITE (DEFAULT, "apple", 5) | |
2925 | OP_S_BIND_STREAM_ID (a, C_BIDI_ID(0)) | |
2926 | OP_S_READ_EXPECT (a, "apple", 5) | |
2927 | ||
2928 | OP_SET_INJECT_WORD (1, OSSL_QUIC_FRAME_TYPE_STREAMS_BLOCKED_UNI) | |
2929 | ||
2930 | OP_S_WRITE (a, "orange", 6) | |
2931 | ||
2932 | OP_C_EXPECT_CONN_CLOSE_INFO(QUIC_ERR_STREAM_LIMIT_ERROR,0,0) | |
2933 | ||
2934 | OP_END | |
2935 | }; | |
2936 | ||
2937 | /* 28. Fault injection - received RESET_STREAM for send-only stream */ | |
2938 | static int script_28_inject_plain(struct helper *h, QUIC_PKT_HDR *hdr, | |
2939 | unsigned char *buf, size_t len) | |
2940 | { | |
7eebc354 | 2941 | int ok = 0; |
e26dc8e3 HL |
2942 | WPACKET wpkt; |
2943 | unsigned char frame_buf[32]; | |
2944 | size_t written; | |
2945 | ||
2946 | if (h->inject_word0 == 0) | |
2947 | return 1; | |
2948 | ||
2949 | if (!TEST_true(WPACKET_init_static_len(&wpkt, frame_buf, | |
2950 | sizeof(frame_buf), 0))) | |
2951 | return 0; | |
2952 | ||
2953 | if (!TEST_true(WPACKET_quic_write_vlint(&wpkt, h->inject_word1)) | |
2954 | || !TEST_true(WPACKET_quic_write_vlint(&wpkt, /* stream ID */ | |
2955 | h->inject_word0 - 1)) | |
2956 | || !TEST_true(WPACKET_quic_write_vlint(&wpkt, 123)) | |
2957 | || (h->inject_word1 == OSSL_QUIC_FRAME_TYPE_RESET_STREAM | |
2958 | && !TEST_true(WPACKET_quic_write_vlint(&wpkt, 5)))) /* final size */ | |
7eebc354 | 2959 | goto err; |
e26dc8e3 HL |
2960 | |
2961 | if (!TEST_true(WPACKET_get_total_written(&wpkt, &written))) | |
7eebc354 | 2962 | goto err; |
e26dc8e3 HL |
2963 | |
2964 | if (!qtest_fault_prepend_frame(h->qtf, frame_buf, written)) | |
7eebc354 | 2965 | goto err; |
e26dc8e3 | 2966 | |
7eebc354 HL |
2967 | ok = 1; |
2968 | err: | |
96b7df60 HL |
2969 | if (ok) |
2970 | WPACKET_finish(&wpkt); | |
2971 | else | |
2972 | WPACKET_cleanup(&wpkt); | |
7eebc354 | 2973 | return ok; |
e26dc8e3 HL |
2974 | } |
2975 | ||
2976 | static const struct script_op script_28[] = { | |
2977 | OP_S_SET_INJECT_PLAIN (script_28_inject_plain) | |
2978 | OP_C_SET_ALPN ("ossltest") | |
2979 | OP_C_CONNECT_WAIT () | |
2980 | OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE) | |
2981 | ||
70cafc44 HL |
2982 | OP_C_NEW_STREAM_BIDI (a, C_BIDI_ID(0)) |
2983 | OP_C_WRITE (a, "orange", 6) | |
e26dc8e3 | 2984 | |
70cafc44 HL |
2985 | OP_S_BIND_STREAM_ID (a, C_BIDI_ID(0)) |
2986 | OP_S_READ_EXPECT (a, "orange", 6) | |
2987 | ||
2988 | OP_C_NEW_STREAM_UNI (b, C_UNI_ID(0)) | |
2989 | OP_C_WRITE (b, "apple", 5) | |
2990 | ||
2991 | OP_S_BIND_STREAM_ID (b, C_UNI_ID(0)) | |
2992 | OP_S_READ_EXPECT (b, "apple", 5) | |
e26dc8e3 HL |
2993 | |
2994 | OP_SET_INJECT_WORD (C_UNI_ID(0) + 1, OSSL_QUIC_FRAME_TYPE_RESET_STREAM) | |
70cafc44 | 2995 | OP_S_WRITE (a, "fruit", 5) |
e26dc8e3 HL |
2996 | |
2997 | OP_C_EXPECT_CONN_CLOSE_INFO(QUIC_ERR_STREAM_STATE_ERROR,0,0) | |
2998 | ||
2999 | OP_END | |
3000 | }; | |
3001 | ||
3002 | /* 29. Fault injection - received RESET_STREAM for nonexistent send-only stream */ | |
3003 | static const struct script_op script_29[] = { | |
3004 | OP_S_SET_INJECT_PLAIN (script_28_inject_plain) | |
3005 | OP_C_SET_ALPN ("ossltest") | |
3006 | OP_C_CONNECT_WAIT () | |
3007 | OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE) | |
3008 | ||
70cafc44 HL |
3009 | OP_C_NEW_STREAM_BIDI (a, C_BIDI_ID(0)) |
3010 | OP_C_WRITE (a, "orange", 6) | |
e26dc8e3 | 3011 | |
70cafc44 HL |
3012 | OP_S_BIND_STREAM_ID (a, C_BIDI_ID(0)) |
3013 | OP_S_READ_EXPECT (a, "orange", 6) | |
3014 | ||
3015 | OP_C_NEW_STREAM_UNI (b, C_UNI_ID(0)) | |
3016 | OP_C_WRITE (b, "apple", 5) | |
3017 | ||
3018 | OP_S_BIND_STREAM_ID (b, C_UNI_ID(0)) | |
3019 | OP_S_READ_EXPECT (b, "apple", 5) | |
e26dc8e3 HL |
3020 | |
3021 | OP_SET_INJECT_WORD (C_UNI_ID(1) + 1, OSSL_QUIC_FRAME_TYPE_RESET_STREAM) | |
70cafc44 | 3022 | OP_S_WRITE (a, "fruit", 5) |
e26dc8e3 HL |
3023 | |
3024 | OP_C_EXPECT_CONN_CLOSE_INFO(QUIC_ERR_STREAM_STATE_ERROR,0,0) | |
3025 | ||
3026 | OP_END | |
3027 | }; | |
3028 | ||
3029 | /* 30. Fault injection - received STOP_SENDING for receive-only stream */ | |
3030 | static const struct script_op script_30[] = { | |
3031 | OP_S_SET_INJECT_PLAIN (script_28_inject_plain) | |
3032 | OP_C_SET_ALPN ("ossltest") | |
3033 | OP_C_CONNECT_WAIT () | |
3034 | OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE) | |
3035 | ||
3036 | OP_S_NEW_STREAM_UNI (a, S_UNI_ID(0)) | |
3037 | OP_S_WRITE (a, "apple", 5) | |
3038 | ||
3039 | OP_C_ACCEPT_STREAM_WAIT (a) | |
3040 | OP_C_READ_EXPECT (a, "apple", 5) | |
3041 | ||
3042 | OP_SET_INJECT_WORD (S_UNI_ID(0) + 1, OSSL_QUIC_FRAME_TYPE_STOP_SENDING) | |
3043 | OP_S_WRITE (a, "orange", 6) | |
3044 | ||
3045 | OP_C_EXPECT_CONN_CLOSE_INFO(QUIC_ERR_STREAM_STATE_ERROR,0,0) | |
3046 | ||
3047 | OP_END | |
3048 | }; | |
3049 | ||
3050 | /* 31. Fault injection - received STOP_SENDING for nonexistent receive-only stream */ | |
3051 | static const struct script_op script_31[] = { | |
3052 | OP_S_SET_INJECT_PLAIN (script_28_inject_plain) | |
3053 | OP_C_SET_ALPN ("ossltest") | |
3054 | OP_C_CONNECT_WAIT () | |
3055 | OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE) | |
3056 | ||
3057 | OP_S_NEW_STREAM_UNI (a, S_UNI_ID(0)) | |
3058 | OP_S_WRITE (a, "apple", 5) | |
3059 | ||
3060 | OP_C_ACCEPT_STREAM_WAIT (a) | |
3061 | OP_C_READ_EXPECT (a, "apple", 5) | |
3062 | ||
3063 | OP_SET_INJECT_WORD (C_UNI_ID(0) + 1, OSSL_QUIC_FRAME_TYPE_STOP_SENDING) | |
3064 | OP_S_WRITE (a, "orange", 6) | |
3065 | ||
3066 | OP_C_EXPECT_CONN_CLOSE_INFO(QUIC_ERR_STREAM_STATE_ERROR,0,0) | |
3067 | ||
3068 | OP_END | |
3069 | }; | |
3070 | ||
3071 | /* 32. Fault injection - STREAM frame for nonexistent stream */ | |
3072 | static int script_32_inject_plain(struct helper *h, QUIC_PKT_HDR *hdr, | |
3073 | unsigned char *buf, size_t len) | |
3074 | { | |
7eebc354 | 3075 | int ok = 0; |
e26dc8e3 HL |
3076 | WPACKET wpkt; |
3077 | unsigned char frame_buf[64]; | |
3078 | size_t written; | |
3079 | uint64_t type = OSSL_QUIC_FRAME_TYPE_STREAM_OFF_LEN, offset, flen, i; | |
3080 | ||
3081 | switch (h->inject_word1) { | |
3082 | default: | |
3083 | return 0; | |
3084 | case 0: | |
3085 | return 1; | |
3086 | case 1: | |
3087 | offset = 0; | |
1623bf37 | 3088 | flen = 0; |
e26dc8e3 HL |
3089 | break; |
3090 | case 2: | |
3091 | offset = (((uint64_t)1)<<62) - 1; | |
1623bf37 | 3092 | flen = 5; |
e26dc8e3 HL |
3093 | break; |
3094 | case 3: | |
3095 | offset = 1 * 1024 * 1024 * 1024; /* 1G */ | |
1623bf37 HL |
3096 | flen = 5; |
3097 | break; | |
3098 | case 4: | |
3099 | offset = 0; | |
3100 | flen = 1; | |
e26dc8e3 HL |
3101 | break; |
3102 | } | |
3103 | ||
3104 | if (!TEST_true(WPACKET_init_static_len(&wpkt, frame_buf, | |
3105 | sizeof(frame_buf), 0))) | |
3106 | return 0; | |
3107 | ||
3108 | if (!TEST_true(WPACKET_quic_write_vlint(&wpkt, type)) | |
3109 | || !TEST_true(WPACKET_quic_write_vlint(&wpkt, /* stream ID */ | |
3110 | h->inject_word0 - 1)) | |
3111 | || !TEST_true(WPACKET_quic_write_vlint(&wpkt, offset)) | |
3112 | || !TEST_true(WPACKET_quic_write_vlint(&wpkt, flen))) | |
7eebc354 | 3113 | goto err; |
e26dc8e3 HL |
3114 | |
3115 | for (i = 0; i < flen; ++i) | |
3116 | if (!TEST_true(WPACKET_put_bytes_u8(&wpkt, 0x42))) | |
7eebc354 | 3117 | goto err; |
e26dc8e3 HL |
3118 | |
3119 | if (!TEST_true(WPACKET_get_total_written(&wpkt, &written))) | |
7eebc354 | 3120 | goto err; |
e26dc8e3 HL |
3121 | |
3122 | if (!qtest_fault_prepend_frame(h->qtf, frame_buf, written)) | |
7eebc354 | 3123 | goto err; |
e26dc8e3 | 3124 | |
7eebc354 HL |
3125 | ok = 1; |
3126 | err: | |
96b7df60 HL |
3127 | if (ok) |
3128 | WPACKET_finish(&wpkt); | |
3129 | else | |
3130 | WPACKET_cleanup(&wpkt); | |
7eebc354 | 3131 | return ok; |
e26dc8e3 HL |
3132 | } |
3133 | ||
3134 | static const struct script_op script_32[] = { | |
3135 | OP_S_SET_INJECT_PLAIN (script_32_inject_plain) | |
3136 | OP_C_SET_ALPN ("ossltest") | |
3137 | OP_C_CONNECT_WAIT () | |
3138 | OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE) | |
3139 | ||
3140 | OP_S_NEW_STREAM_UNI (a, S_UNI_ID(0)) | |
3141 | OP_S_WRITE (a, "apple", 5) | |
3142 | ||
3143 | OP_C_ACCEPT_STREAM_WAIT (a) | |
3144 | OP_C_READ_EXPECT (a, "apple", 5) | |
3145 | ||
3146 | OP_SET_INJECT_WORD (C_UNI_ID(0) + 1, 1) | |
3147 | OP_S_WRITE (a, "orange", 6) | |
3148 | ||
3149 | OP_C_EXPECT_CONN_CLOSE_INFO(QUIC_ERR_STREAM_STATE_ERROR,0,0) | |
3150 | ||
3151 | OP_END | |
3152 | }; | |
3153 | ||
3154 | /* 33. Fault injection - STREAM frame with illegal offset */ | |
3155 | static const struct script_op script_33[] = { | |
3156 | OP_S_SET_INJECT_PLAIN (script_32_inject_plain) | |
3157 | OP_C_SET_ALPN ("ossltest") | |
3158 | OP_C_CONNECT_WAIT () | |
3159 | OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE) | |
3160 | ||
3161 | OP_C_NEW_STREAM_BIDI (a, C_BIDI_ID(0)) | |
3162 | OP_C_WRITE (a, "apple", 5) | |
3163 | ||
3164 | OP_S_BIND_STREAM_ID (a, C_BIDI_ID(0)) | |
3165 | OP_S_READ_EXPECT (a, "apple", 5) | |
3166 | ||
3167 | OP_SET_INJECT_WORD (C_BIDI_ID(0) + 1, 2) | |
3168 | OP_S_WRITE (a, "orange", 6) | |
3169 | ||
3170 | OP_C_EXPECT_CONN_CLOSE_INFO(QUIC_ERR_FRAME_ENCODING_ERROR,0,0) | |
3171 | ||
3172 | OP_END | |
3173 | }; | |
3174 | ||
3175 | /* 34. Fault injection - STREAM frame which exceeds FC */ | |
3176 | static const struct script_op script_34[] = { | |
3177 | OP_S_SET_INJECT_PLAIN (script_32_inject_plain) | |
3178 | OP_C_SET_ALPN ("ossltest") | |
3179 | OP_C_CONNECT_WAIT () | |
3180 | OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE) | |
3181 | ||
3182 | OP_C_NEW_STREAM_BIDI (a, C_BIDI_ID(0)) | |
3183 | OP_C_WRITE (a, "apple", 5) | |
3184 | ||
3185 | OP_S_BIND_STREAM_ID (a, C_BIDI_ID(0)) | |
3186 | OP_S_READ_EXPECT (a, "apple", 5) | |
3187 | ||
3188 | OP_SET_INJECT_WORD (C_BIDI_ID(0) + 1, 3) | |
3189 | OP_S_WRITE (a, "orange", 6) | |
3190 | ||
3191 | OP_C_EXPECT_CONN_CLOSE_INFO(QUIC_ERR_FLOW_CONTROL_ERROR,0,0) | |
3192 | ||
3193 | OP_END | |
3194 | }; | |
3195 | ||
3196 | /* 35. Fault injection - MAX_STREAM_DATA for receive-only stream */ | |
3197 | static const struct script_op script_35[] = { | |
3198 | OP_S_SET_INJECT_PLAIN (script_28_inject_plain) | |
3199 | OP_C_SET_ALPN ("ossltest") | |
3200 | OP_C_CONNECT_WAIT () | |
3201 | OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE) | |
3202 | ||
3203 | OP_S_NEW_STREAM_UNI (a, S_UNI_ID(0)) | |
3204 | OP_S_WRITE (a, "apple", 5) | |
3205 | ||
3206 | OP_C_ACCEPT_STREAM_WAIT (a) | |
3207 | OP_C_READ_EXPECT (a, "apple", 5) | |
3208 | ||
3209 | OP_SET_INJECT_WORD (S_UNI_ID(0) + 1, OSSL_QUIC_FRAME_TYPE_MAX_STREAM_DATA) | |
3210 | OP_S_WRITE (a, "orange", 6) | |
3211 | ||
3212 | OP_C_EXPECT_CONN_CLOSE_INFO(QUIC_ERR_STREAM_STATE_ERROR,0,0) | |
3213 | ||
3214 | OP_END | |
3215 | }; | |
3216 | ||
3217 | /* 36. Fault injection - MAX_STREAM_DATA for nonexistent stream */ | |
3218 | static const struct script_op script_36[] = { | |
3219 | OP_S_SET_INJECT_PLAIN (script_28_inject_plain) | |
3220 | OP_C_SET_ALPN ("ossltest") | |
3221 | OP_C_CONNECT_WAIT () | |
3222 | OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE) | |
3223 | ||
3224 | OP_S_NEW_STREAM_UNI (a, S_UNI_ID(0)) | |
3225 | OP_S_WRITE (a, "apple", 5) | |
3226 | ||
3227 | OP_C_ACCEPT_STREAM_WAIT (a) | |
3228 | OP_C_READ_EXPECT (a, "apple", 5) | |
3229 | ||
3230 | OP_SET_INJECT_WORD (C_BIDI_ID(0) + 1, OSSL_QUIC_FRAME_TYPE_MAX_STREAM_DATA) | |
3231 | OP_S_WRITE (a, "orange", 6) | |
3232 | ||
3233 | OP_C_EXPECT_CONN_CLOSE_INFO(QUIC_ERR_STREAM_STATE_ERROR,0,0) | |
3234 | ||
3235 | OP_END | |
3236 | }; | |
3237 | ||
3238 | /* 37. Fault injection - STREAM_DATA_BLOCKED for send-only stream */ | |
3239 | static const struct script_op script_37[] = { | |
3240 | OP_S_SET_INJECT_PLAIN (script_28_inject_plain) | |
3241 | OP_C_SET_ALPN ("ossltest") | |
3242 | OP_C_CONNECT_WAIT () | |
3243 | OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE) | |
3244 | ||
3245 | OP_C_NEW_STREAM_UNI (a, C_UNI_ID(0)) | |
3246 | OP_C_WRITE (a, "apple", 5) | |
3247 | ||
3248 | OP_S_BIND_STREAM_ID (a, C_UNI_ID(0)) | |
3249 | OP_S_READ_EXPECT (a, "apple", 5) | |
3250 | ||
3251 | OP_S_NEW_STREAM_UNI (b, S_UNI_ID(0)) | |
3252 | OP_SET_INJECT_WORD (C_UNI_ID(0) + 1, OSSL_QUIC_FRAME_TYPE_STREAM_DATA_BLOCKED) | |
3253 | OP_S_WRITE (b, "orange", 5) | |
3254 | ||
3255 | OP_C_EXPECT_CONN_CLOSE_INFO(QUIC_ERR_STREAM_STATE_ERROR,0,0) | |
3256 | ||
3257 | OP_END | |
3258 | }; | |
3259 | ||
3260 | /* 38. Fault injection - STREAM_DATA_BLOCKED for non-existent stream */ | |
3261 | static const struct script_op script_38[] = { | |
3262 | OP_S_SET_INJECT_PLAIN (script_28_inject_plain) | |
3263 | OP_C_SET_ALPN ("ossltest") | |
3264 | OP_C_CONNECT_WAIT () | |
3265 | OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE) | |
3266 | ||
3267 | OP_S_NEW_STREAM_UNI (b, S_UNI_ID(0)) | |
3268 | OP_SET_INJECT_WORD (C_BIDI_ID(0) + 1, OSSL_QUIC_FRAME_TYPE_STREAM_DATA_BLOCKED) | |
3269 | OP_S_WRITE (b, "orange", 5) | |
3270 | ||
3271 | OP_C_EXPECT_CONN_CLOSE_INFO(QUIC_ERR_STREAM_STATE_ERROR,0,0) | |
3272 | ||
3273 | OP_END | |
3274 | }; | |
3275 | ||
3276 | /* 39. Fault injection - NEW_CONN_ID with zero-len CID */ | |
3277 | static int script_39_inject_plain(struct helper *h, QUIC_PKT_HDR *hdr, | |
3278 | unsigned char *buf, size_t len) | |
3279 | { | |
7eebc354 | 3280 | int ok = 0; |
e26dc8e3 HL |
3281 | WPACKET wpkt; |
3282 | unsigned char frame_buf[64]; | |
3283 | size_t i, written; | |
ed75eb32 HL |
3284 | uint64_t seq_no = 0, retire_prior_to = 0; |
3285 | QUIC_CONN_ID new_cid = {0}; | |
5881dd2c | 3286 | QUIC_CHANNEL *ch = ossl_quic_tserver_get_channel(h->s_priv); |
e26dc8e3 | 3287 | |
ed75eb32 HL |
3288 | switch (h->inject_word1) { |
3289 | case 0: | |
e26dc8e3 | 3290 | return 1; |
ed75eb32 HL |
3291 | case 1: |
3292 | new_cid.id_len = 0; | |
3293 | break; | |
3294 | case 2: | |
3295 | new_cid.id_len = 21; | |
3296 | break; | |
3297 | case 3: | |
3298 | new_cid.id_len = 1; | |
3299 | new_cid.id[0] = 0x55; | |
3300 | ||
3301 | seq_no = 0; | |
3302 | retire_prior_to = 1; | |
3303 | break; | |
3304 | case 4: | |
f2609004 | 3305 | /* Use our actual CID so we don't break connectivity. */ |
ed75eb32 HL |
3306 | ossl_quic_channel_get_diag_local_cid(ch, &new_cid); |
3307 | ||
3308 | seq_no = 2; | |
3309 | retire_prior_to = 2; | |
3310 | break; | |
3311 | case 5: | |
3312 | /* | |
3313 | * Use a bogus CID which will need to be ignored if connectivity is to | |
3314 | * be continued. | |
3315 | */ | |
3316 | new_cid.id_len = 8; | |
3317 | new_cid.id[0] = 0x55; | |
3318 | ||
3319 | seq_no = 1; | |
3320 | retire_prior_to = 1; | |
3321 | break; | |
3322 | } | |
e26dc8e3 HL |
3323 | |
3324 | if (!TEST_true(WPACKET_init_static_len(&wpkt, frame_buf, | |
3325 | sizeof(frame_buf), 0))) | |
3326 | return 0; | |
3327 | ||
3328 | if (!TEST_true(WPACKET_quic_write_vlint(&wpkt, OSSL_QUIC_FRAME_TYPE_NEW_CONN_ID)) | |
ed75eb32 HL |
3329 | || !TEST_true(WPACKET_quic_write_vlint(&wpkt, seq_no)) /* seq no */ |
3330 | || !TEST_true(WPACKET_quic_write_vlint(&wpkt, retire_prior_to)) /* retire prior to */ | |
3331 | || !TEST_true(WPACKET_put_bytes_u8(&wpkt, new_cid.id_len))) /* len */ | |
7eebc354 | 3332 | goto err; |
e26dc8e3 | 3333 | |
d63b8cbb | 3334 | for (i = 0; i < new_cid.id_len && i < OSSL_NELEM(new_cid.id); ++i) |
ed75eb32 HL |
3335 | if (!TEST_true(WPACKET_put_bytes_u8(&wpkt, new_cid.id[i]))) |
3336 | goto err; | |
3337 | ||
d63b8cbb HL |
3338 | for (; i < new_cid.id_len; ++i) |
3339 | if (!TEST_true(WPACKET_put_bytes_u8(&wpkt, 0x55))) | |
3340 | goto err; | |
3341 | ||
e26dc8e3 HL |
3342 | for (i = 0; i < QUIC_STATELESS_RESET_TOKEN_LEN; ++i) |
3343 | if (!TEST_true(WPACKET_put_bytes_u8(&wpkt, 0x42))) | |
7eebc354 | 3344 | goto err; |
e26dc8e3 HL |
3345 | |
3346 | if (!TEST_true(WPACKET_get_total_written(&wpkt, &written))) | |
7eebc354 | 3347 | goto err; |
e26dc8e3 HL |
3348 | |
3349 | if (!qtest_fault_prepend_frame(h->qtf, frame_buf, written)) | |
7eebc354 | 3350 | goto err; |
e26dc8e3 | 3351 | |
7eebc354 HL |
3352 | ok = 1; |
3353 | err: | |
96b7df60 HL |
3354 | if (ok) |
3355 | WPACKET_finish(&wpkt); | |
3356 | else | |
3357 | WPACKET_cleanup(&wpkt); | |
7eebc354 | 3358 | return ok; |
e26dc8e3 HL |
3359 | } |
3360 | ||
3361 | static const struct script_op script_39[] = { | |
3362 | OP_S_SET_INJECT_PLAIN (script_39_inject_plain) | |
3363 | OP_C_SET_ALPN ("ossltest") | |
3364 | OP_C_CONNECT_WAIT () | |
3365 | OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE) | |
3366 | ||
3367 | OP_C_NEW_STREAM_BIDI (a, C_BIDI_ID(0)) | |
3368 | OP_C_WRITE (a, "apple", 5) | |
3369 | OP_S_BIND_STREAM_ID (a, C_BIDI_ID(0)) | |
3370 | OP_S_READ_EXPECT (a, "apple", 5) | |
3371 | ||
3372 | OP_SET_INJECT_WORD (0, 1) | |
3373 | OP_S_WRITE (a, "orange", 5) | |
3374 | ||
3375 | OP_C_EXPECT_CONN_CLOSE_INFO(QUIC_ERR_FRAME_ENCODING_ERROR,0,0) | |
3376 | ||
3377 | OP_END | |
3378 | }; | |
3379 | ||
cd5e4380 HL |
3380 | /* 40. Shutdown flush test */ |
3381 | static const unsigned char script_40_data[1024] = "strawberry"; | |
3382 | ||
3383 | static const struct script_op script_40[] = { | |
3384 | OP_C_SET_ALPN ("ossltest") | |
3385 | OP_C_CONNECT_WAIT () | |
3386 | OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE) | |
3387 | ||
3388 | OP_C_NEW_STREAM_BIDI (a, C_BIDI_ID(0)) | |
3389 | OP_C_WRITE (a, "apple", 5) | |
3390 | ||
3391 | OP_C_INHIBIT_TICK (1) | |
3392 | OP_C_SET_WRITE_BUF_SIZE (a, 1024 * 100 * 3) | |
3393 | ||
3394 | OP_BEGIN_REPEAT (100) | |
3395 | ||
3396 | OP_C_WRITE (a, script_40_data, sizeof(script_40_data)) | |
3397 | ||
3398 | OP_END_REPEAT () | |
3399 | ||
3400 | OP_C_CONCLUDE (a) | |
3bc38ba0 | 3401 | OP_C_SHUTDOWN_WAIT (NULL, 0) /* disengages tick inhibition */ |
cd5e4380 HL |
3402 | |
3403 | OP_S_BIND_STREAM_ID (a, C_BIDI_ID(0)) | |
3404 | OP_S_READ_EXPECT (a, "apple", 5) | |
3405 | ||
3406 | OP_BEGIN_REPEAT (100) | |
3407 | ||
3408 | OP_S_READ_EXPECT (a, script_40_data, sizeof(script_40_data)) | |
3409 | ||
3410 | OP_END_REPEAT () | |
3411 | ||
3412 | OP_S_EXPECT_FIN (a) | |
3413 | ||
3414 | OP_C_EXPECT_CONN_CLOSE_INFO(0, 1, 0) | |
3415 | OP_S_EXPECT_CONN_CLOSE_INFO(0, 1, 1) | |
3416 | ||
3417 | OP_END | |
3418 | }; | |
3419 | ||
7eb330ff HL |
3420 | /* 41. Fault injection - PATH_CHALLENGE yields PATH_RESPONSE */ |
3421 | static const uint64_t path_challenge = UINT64_C(0xbdeb9451169c83aa); | |
3422 | ||
3423 | static int script_41_inject_plain(struct helper *h, QUIC_PKT_HDR *hdr, | |
3424 | unsigned char *buf, size_t len) | |
3425 | { | |
3426 | int ok = 0; | |
3427 | WPACKET wpkt; | |
3428 | unsigned char frame_buf[16]; | |
3429 | size_t written; | |
3430 | ||
3431 | if (h->inject_word0 == 0) | |
3432 | return 1; | |
3433 | ||
3434 | if (!TEST_true(WPACKET_init_static_len(&wpkt, frame_buf, | |
3435 | sizeof(frame_buf), 0))) | |
3436 | return 0; | |
3437 | ||
a1aff2c6 | 3438 | if (!TEST_true(WPACKET_quic_write_vlint(&wpkt, h->inject_word1)) |
7eb330ff HL |
3439 | || !TEST_true(WPACKET_put_bytes_u64(&wpkt, path_challenge))) |
3440 | goto err; | |
3441 | ||
3442 | if (!TEST_true(WPACKET_get_total_written(&wpkt, &written)) | |
3443 | || !TEST_size_t_eq(written, 9)) | |
3444 | goto err; | |
3445 | ||
3446 | if (!qtest_fault_prepend_frame(h->qtf, frame_buf, written)) | |
3447 | goto err; | |
3448 | ||
3449 | --h->inject_word0; | |
3450 | ok = 1; | |
3451 | err: | |
3452 | if (ok) | |
3453 | WPACKET_finish(&wpkt); | |
3454 | else | |
3455 | WPACKET_cleanup(&wpkt); | |
3456 | return ok; | |
3457 | } | |
3458 | ||
3459 | static void script_41_trace(int write_p, int version, int content_type, | |
3460 | const void *buf, size_t len, SSL *ssl, void *arg) | |
3461 | { | |
3462 | uint64_t frame_type, frame_data; | |
3463 | int was_minimal; | |
3464 | struct helper *h = arg; | |
3465 | PACKET pkt; | |
3466 | ||
3467 | if (version != OSSL_QUIC1_VERSION | |
3468 | || content_type != SSL3_RT_QUIC_FRAME_FULL | |
3469 | || len < 1) | |
3470 | return; | |
3471 | ||
3472 | if (!TEST_true(PACKET_buf_init(&pkt, buf, len))) { | |
3473 | ++h->scratch1; | |
3474 | return; | |
3475 | } | |
3476 | ||
3477 | if (!TEST_true(ossl_quic_wire_peek_frame_header(&pkt, &frame_type, | |
3478 | &was_minimal))) { | |
3479 | ++h->scratch1; | |
3480 | return; | |
3481 | } | |
3482 | ||
3483 | if (frame_type != OSSL_QUIC_FRAME_TYPE_PATH_RESPONSE) | |
3484 | return; | |
3485 | ||
3486 | if (!TEST_true(ossl_quic_wire_decode_frame_path_response(&pkt, &frame_data)) | |
3487 | || !TEST_uint64_t_eq(frame_data, path_challenge)) { | |
3488 | ++h->scratch1; | |
3489 | return; | |
3490 | } | |
3491 | ||
3492 | ++h->scratch0; | |
3493 | } | |
3494 | ||
5881dd2c | 3495 | static int script_41_setup(struct helper *h, struct helper_local *hl) |
7eb330ff | 3496 | { |
5881dd2c | 3497 | ossl_quic_tserver_set_msg_callback(ACQUIRE_S(), script_41_trace, h); |
7eb330ff HL |
3498 | return 1; |
3499 | } | |
3500 | ||
5881dd2c | 3501 | static int script_41_check(struct helper *h, struct helper_local *hl) |
7eb330ff HL |
3502 | { |
3503 | /* At least one valid challenge/response echo? */ | |
3504 | if (!TEST_uint64_t_gt(h->scratch0, 0)) | |
3505 | return 0; | |
3506 | ||
3507 | /* No failed tests? */ | |
3508 | if (!TEST_uint64_t_eq(h->scratch1, 0)) | |
3509 | return 0; | |
3510 | ||
3511 | return 1; | |
3512 | } | |
3513 | ||
3514 | static const struct script_op script_41[] = { | |
3515 | OP_S_SET_INJECT_PLAIN (script_41_inject_plain) | |
3516 | OP_C_SET_ALPN ("ossltest") | |
3517 | OP_C_CONNECT_WAIT () | |
3518 | OP_CHECK (script_41_setup, 0) | |
3519 | ||
3520 | OP_C_WRITE (DEFAULT, "apple", 5) | |
3521 | OP_S_BIND_STREAM_ID (a, C_BIDI_ID(0)) | |
3522 | OP_S_READ_EXPECT (a, "apple", 5) | |
3523 | ||
a1aff2c6 | 3524 | OP_SET_INJECT_WORD (1, OSSL_QUIC_FRAME_TYPE_PATH_CHALLENGE) |
7eb330ff HL |
3525 | |
3526 | OP_S_WRITE (a, "orange", 6) | |
3527 | OP_C_READ_EXPECT (DEFAULT, "orange", 6) | |
3528 | ||
3529 | OP_C_WRITE (DEFAULT, "strawberry", 10) | |
3530 | OP_S_READ_EXPECT (a, "strawberry", 10) | |
3531 | ||
3532 | OP_CHECK (script_41_check, 0) | |
3533 | OP_END | |
3534 | }; | |
3535 | ||
27c2f62f HL |
3536 | /* 42. Fault injection - CRYPTO frame with illegal offset */ |
3537 | static int script_42_inject_plain(struct helper *h, QUIC_PKT_HDR *hdr, | |
3538 | unsigned char *buf, size_t len) | |
3539 | { | |
3540 | int ok = 0; | |
3541 | unsigned char frame_buf[64]; | |
3542 | size_t written; | |
3543 | WPACKET wpkt; | |
3544 | ||
3545 | if (h->inject_word0 == 0) | |
3546 | return 1; | |
3547 | ||
3548 | --h->inject_word0; | |
3549 | ||
3550 | if (!TEST_true(WPACKET_init_static_len(&wpkt, frame_buf, | |
3551 | sizeof(frame_buf), 0))) | |
3552 | return 0; | |
3553 | ||
3554 | if (!TEST_true(WPACKET_quic_write_vlint(&wpkt, OSSL_QUIC_FRAME_TYPE_CRYPTO)) | |
ab6c6345 | 3555 | || !TEST_true(WPACKET_quic_write_vlint(&wpkt, h->inject_word1)) |
27c2f62f HL |
3556 | || !TEST_true(WPACKET_quic_write_vlint(&wpkt, 1)) |
3557 | || !TEST_true(WPACKET_put_bytes_u8(&wpkt, 0x42))) | |
3558 | goto err; | |
3559 | ||
3560 | if (!TEST_true(WPACKET_get_total_written(&wpkt, &written))) | |
3561 | goto err; | |
3562 | ||
3563 | if (!qtest_fault_prepend_frame(h->qtf, frame_buf, written)) | |
3564 | goto err; | |
3565 | ||
3566 | ok = 1; | |
3567 | err: | |
3568 | if (ok) | |
3569 | WPACKET_finish(&wpkt); | |
3570 | else | |
3571 | WPACKET_cleanup(&wpkt); | |
3572 | return ok; | |
3573 | } | |
3574 | ||
3575 | static const struct script_op script_42[] = { | |
3576 | OP_S_SET_INJECT_PLAIN (script_42_inject_plain) | |
3577 | OP_C_SET_ALPN ("ossltest") | |
3578 | OP_C_CONNECT_WAIT () | |
3579 | OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE) | |
3580 | ||
3581 | OP_C_NEW_STREAM_BIDI (a, C_BIDI_ID(0)) | |
3582 | OP_C_WRITE (a, "apple", 5) | |
3583 | ||
3584 | OP_S_BIND_STREAM_ID (a, C_BIDI_ID(0)) | |
3585 | OP_S_READ_EXPECT (a, "apple", 5) | |
3586 | ||
ab6c6345 | 3587 | OP_SET_INJECT_WORD (1, (((uint64_t)1) << 62) - 1) |
27c2f62f HL |
3588 | OP_S_WRITE (a, "orange", 6) |
3589 | ||
3590 | OP_C_EXPECT_CONN_CLOSE_INFO(QUIC_ERR_FRAME_ENCODING_ERROR,0,0) | |
3591 | ||
3592 | OP_END | |
3593 | }; | |
3594 | ||
ab6c6345 HL |
3595 | /* 43. Fault injection - CRYPTO frame exceeding FC */ |
3596 | static const struct script_op script_43[] = { | |
3597 | OP_S_SET_INJECT_PLAIN (script_42_inject_plain) | |
3598 | OP_C_SET_ALPN ("ossltest") | |
3599 | OP_C_CONNECT_WAIT () | |
3600 | OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE) | |
3601 | ||
3602 | OP_C_NEW_STREAM_BIDI (a, C_BIDI_ID(0)) | |
3603 | OP_C_WRITE (a, "apple", 5) | |
3604 | ||
3605 | OP_S_BIND_STREAM_ID (a, C_BIDI_ID(0)) | |
3606 | OP_S_READ_EXPECT (a, "apple", 5) | |
3607 | ||
3608 | OP_SET_INJECT_WORD (1, 0x100000 /* 1 MiB */) | |
3609 | OP_S_WRITE (a, "orange", 6) | |
3610 | ||
3611 | OP_C_EXPECT_CONN_CLOSE_INFO(QUIC_ERR_CRYPTO_BUFFER_EXCEEDED,0,0) | |
3612 | ||
3613 | OP_END | |
3614 | }; | |
3615 | ||
97684a15 HL |
3616 | /* 44. Fault injection - PADDING */ |
3617 | static int script_44_inject_plain(struct helper *h, QUIC_PKT_HDR *hdr, | |
3618 | unsigned char *buf, size_t len) | |
3619 | { | |
3620 | int ok = 0; | |
3621 | WPACKET wpkt; | |
3622 | unsigned char frame_buf[16]; | |
3623 | size_t written; | |
3624 | ||
3625 | if (h->inject_word0 == 0) | |
3626 | return 1; | |
3627 | ||
3628 | if (!TEST_true(WPACKET_init_static_len(&wpkt, frame_buf, | |
3629 | sizeof(frame_buf), 0))) | |
3630 | return 0; | |
3631 | ||
3632 | if (!TEST_true(ossl_quic_wire_encode_padding(&wpkt, 1))) | |
3633 | goto err; | |
3634 | ||
3635 | if (!TEST_true(WPACKET_get_total_written(&wpkt, &written))) | |
3636 | goto err; | |
3637 | ||
3638 | if (!qtest_fault_prepend_frame(h->qtf, frame_buf, written)) | |
3639 | goto err; | |
3640 | ||
3641 | ok = 1; | |
3642 | err: | |
3643 | if (ok) | |
3644 | WPACKET_finish(&wpkt); | |
3645 | else | |
3646 | WPACKET_cleanup(&wpkt); | |
3647 | return ok; | |
3648 | } | |
3649 | ||
3650 | static const struct script_op script_44[] = { | |
3651 | OP_S_SET_INJECT_PLAIN (script_44_inject_plain) | |
3652 | OP_C_SET_ALPN ("ossltest") | |
3653 | OP_C_CONNECT_WAIT () | |
3654 | ||
3655 | OP_C_WRITE (DEFAULT, "apple", 5) | |
3656 | OP_S_BIND_STREAM_ID (a, C_BIDI_ID(0)) | |
3657 | OP_S_READ_EXPECT (a, "apple", 5) | |
3658 | ||
3659 | OP_SET_INJECT_WORD (1, 0) | |
3660 | ||
3661 | OP_S_WRITE (a, "Strawberry", 10) | |
3662 | OP_C_READ_EXPECT (DEFAULT, "Strawberry", 10) | |
3663 | ||
3664 | OP_END | |
3665 | }; | |
3666 | ||
17340e87 | 3667 | /* 45. PING must generate ACK */ |
5881dd2c | 3668 | static int force_ping(struct helper *h, struct helper_local *hl) |
17340e87 | 3669 | { |
5881dd2c | 3670 | QUIC_CHANNEL *ch = ossl_quic_tserver_get_channel(ACQUIRE_S()); |
17340e87 HL |
3671 | |
3672 | h->scratch0 = ossl_quic_channel_get_diag_num_rx_ack(ch); | |
3673 | ||
5881dd2c | 3674 | if (!TEST_true(ossl_quic_tserver_ping(ACQUIRE_S()))) |
17340e87 HL |
3675 | return 0; |
3676 | ||
3677 | return 1; | |
3678 | } | |
3679 | ||
5881dd2c | 3680 | static int wait_incoming_acks_increased(struct helper *h, struct helper_local *hl) |
17340e87 | 3681 | { |
5881dd2c | 3682 | QUIC_CHANNEL *ch = ossl_quic_tserver_get_channel(ACQUIRE_S()); |
17340e87 HL |
3683 | uint16_t count; |
3684 | ||
3685 | count = ossl_quic_channel_get_diag_num_rx_ack(ch); | |
3686 | ||
3687 | if (count == h->scratch0) { | |
3688 | h->check_spin_again = 1; | |
3689 | return 0; | |
3690 | } | |
3691 | ||
3692 | return 1; | |
3693 | } | |
3694 | ||
3695 | static const struct script_op script_45[] = { | |
3696 | OP_C_SET_ALPN ("ossltest") | |
3697 | OP_C_CONNECT_WAIT () | |
3698 | ||
3699 | OP_C_WRITE (DEFAULT, "apple", 5) | |
3700 | OP_S_BIND_STREAM_ID (a, C_BIDI_ID(0)) | |
3701 | OP_S_READ_EXPECT (a, "apple", 5) | |
3702 | ||
3703 | OP_BEGIN_REPEAT (2) | |
3704 | ||
3705 | OP_CHECK (force_ping, 0) | |
3706 | OP_CHECK (wait_incoming_acks_increased, 0) | |
3707 | ||
3708 | OP_END_REPEAT () | |
3709 | ||
3710 | OP_S_WRITE (a, "Strawberry", 10) | |
3711 | OP_C_READ_EXPECT (DEFAULT, "Strawberry", 10) | |
3712 | ||
3713 | OP_END | |
3714 | }; | |
3715 | ||
ed0d6ba4 HL |
3716 | /* 46. Fault injection - ACK - malformed initial range */ |
3717 | static int script_46_inject_plain(struct helper *h, QUIC_PKT_HDR *hdr, | |
3718 | unsigned char *buf, size_t len) | |
3719 | { | |
3720 | int ok = 0; | |
3721 | WPACKET wpkt; | |
3722 | unsigned char frame_buf[16]; | |
3723 | size_t written; | |
d49a1634 HL |
3724 | uint64_t type = 0, largest_acked = 0, first_range = 0, range_count = 0; |
3725 | uint64_t agap = 0, alen = 0; | |
ed0d6ba4 HL |
3726 | uint64_t ect0 = 0, ect1 = 0, ecnce = 0; |
3727 | ||
3728 | if (h->inject_word0 == 0) | |
3729 | return 1; | |
3730 | ||
3731 | if (!TEST_true(WPACKET_init_static_len(&wpkt, frame_buf, | |
3732 | sizeof(frame_buf), 0))) | |
3733 | return 0; | |
3734 | ||
3735 | type = OSSL_QUIC_FRAME_TYPE_ACK_WITHOUT_ECN; | |
3736 | ||
3737 | switch (h->inject_word0) { | |
3738 | case 1: | |
3739 | largest_acked = 100; | |
3740 | first_range = 101; | |
3741 | range_count = 0; | |
3742 | break; | |
3743 | case 2: | |
3744 | largest_acked = 100; | |
3745 | first_range = 80; | |
3746 | /* [20..100]; [0..18] */ | |
3747 | range_count = 1; | |
3748 | agap = 0; | |
3749 | alen = 19; | |
3750 | break; | |
3751 | case 3: | |
3752 | largest_acked = 100; | |
3753 | first_range = 80; | |
3754 | range_count = 1; | |
3755 | agap = 18; | |
3756 | alen = 1; | |
3757 | break; | |
3758 | case 4: | |
3759 | type = OSSL_QUIC_FRAME_TYPE_ACK_WITH_ECN; | |
3760 | largest_acked = 100; | |
3761 | first_range = 1; | |
3762 | range_count = 0; | |
3763 | break; | |
3764 | case 5: | |
3765 | type = OSSL_QUIC_FRAME_TYPE_ACK_WITH_ECN; | |
3766 | largest_acked = 0; | |
3767 | first_range = 0; | |
3768 | range_count = 0; | |
3769 | ect0 = 0; | |
3770 | ect1 = 50; | |
3771 | ecnce = 200; | |
3772 | break; | |
3773 | } | |
3774 | ||
3775 | h->inject_word0 = 0; | |
3776 | ||
3777 | if (!TEST_true(WPACKET_quic_write_vlint(&wpkt, type)) | |
3778 | || !TEST_true(WPACKET_quic_write_vlint(&wpkt, largest_acked)) | |
3779 | || !TEST_true(WPACKET_quic_write_vlint(&wpkt, /*ack_delay=*/0)) | |
3780 | || !TEST_true(WPACKET_quic_write_vlint(&wpkt, /*ack_range_count=*/range_count)) | |
3781 | || !TEST_true(WPACKET_quic_write_vlint(&wpkt, /*first_ack_range=*/first_range))) | |
3782 | goto err; | |
3783 | ||
3784 | if (range_count > 0) | |
3785 | if (!TEST_true(WPACKET_quic_write_vlint(&wpkt, /*range[0].gap=*/agap)) | |
3786 | || !TEST_true(WPACKET_quic_write_vlint(&wpkt, /*range[0].len=*/alen))) | |
3787 | goto err; | |
3788 | ||
3789 | if (type == OSSL_QUIC_FRAME_TYPE_ACK_WITH_ECN) | |
3790 | if (!TEST_true(WPACKET_quic_write_vlint(&wpkt, ect0)) | |
3791 | || !TEST_true(WPACKET_quic_write_vlint(&wpkt, ect1)) | |
3792 | || !TEST_true(WPACKET_quic_write_vlint(&wpkt, ecnce))) | |
3793 | goto err; | |
3794 | ||
3795 | if (!TEST_true(WPACKET_get_total_written(&wpkt, &written))) | |
3796 | goto err; | |
3797 | ||
3798 | if (!qtest_fault_prepend_frame(h->qtf, frame_buf, written)) | |
3799 | goto err; | |
3800 | ||
3801 | ok = 1; | |
3802 | err: | |
3803 | if (ok) | |
3804 | WPACKET_finish(&wpkt); | |
3805 | else | |
3806 | WPACKET_cleanup(&wpkt); | |
3807 | return ok; | |
3808 | } | |
3809 | ||
3810 | static const struct script_op script_46[] = { | |
3811 | OP_S_SET_INJECT_PLAIN (script_46_inject_plain) | |
3812 | OP_C_SET_ALPN ("ossltest") | |
3813 | OP_C_CONNECT_WAIT () | |
3814 | ||
3815 | OP_C_WRITE (DEFAULT, "apple", 5) | |
3816 | OP_S_BIND_STREAM_ID (a, C_BIDI_ID(0)) | |
3817 | OP_S_READ_EXPECT (a, "apple", 5) | |
3818 | ||
3819 | OP_SET_INJECT_WORD (1, 0) | |
3820 | ||
3821 | OP_S_WRITE (a, "Strawberry", 10) | |
3822 | ||
3823 | OP_C_EXPECT_CONN_CLOSE_INFO(QUIC_ERR_FRAME_ENCODING_ERROR,0,0) | |
3824 | ||
3825 | OP_END | |
3826 | }; | |
3827 | ||
3828 | /* 47. Fault injection - ACK - malformed subsequent range */ | |
3829 | static const struct script_op script_47[] = { | |
3830 | OP_S_SET_INJECT_PLAIN (script_46_inject_plain) | |
3831 | OP_C_SET_ALPN ("ossltest") | |
3832 | OP_C_CONNECT_WAIT () | |
3833 | ||
3834 | OP_C_WRITE (DEFAULT, "apple", 5) | |
3835 | OP_S_BIND_STREAM_ID (a, C_BIDI_ID(0)) | |
3836 | OP_S_READ_EXPECT (a, "apple", 5) | |
3837 | ||
3838 | OP_SET_INJECT_WORD (2, 0) | |
3839 | ||
3840 | OP_S_WRITE (a, "Strawberry", 10) | |
3841 | ||
3842 | OP_C_EXPECT_CONN_CLOSE_INFO(QUIC_ERR_FRAME_ENCODING_ERROR,0,0) | |
3843 | ||
3844 | OP_END | |
3845 | }; | |
3846 | ||
3847 | /* 48. Fault injection - ACK - malformed subsequent range */ | |
3848 | static const struct script_op script_48[] = { | |
3849 | OP_S_SET_INJECT_PLAIN (script_46_inject_plain) | |
3850 | OP_C_SET_ALPN ("ossltest") | |
3851 | OP_C_CONNECT_WAIT () | |
3852 | ||
3853 | OP_C_WRITE (DEFAULT, "apple", 5) | |
3854 | OP_S_BIND_STREAM_ID (a, C_BIDI_ID(0)) | |
3855 | OP_S_READ_EXPECT (a, "apple", 5) | |
3856 | ||
3857 | OP_SET_INJECT_WORD (3, 0) | |
3858 | ||
3859 | OP_S_WRITE (a, "Strawberry", 10) | |
3860 | ||
3861 | OP_C_EXPECT_CONN_CLOSE_INFO(QUIC_ERR_FRAME_ENCODING_ERROR,0,0) | |
3862 | ||
3863 | OP_END | |
3864 | }; | |
3865 | ||
3866 | /* 49. Fault injection - ACK - fictional PN */ | |
3867 | static const struct script_op script_49[] = { | |
3868 | OP_S_SET_INJECT_PLAIN (script_46_inject_plain) | |
3869 | OP_C_SET_ALPN ("ossltest") | |
3870 | OP_C_CONNECT_WAIT () | |
3871 | ||
3872 | OP_C_WRITE (DEFAULT, "apple", 5) | |
3873 | OP_S_BIND_STREAM_ID (a, C_BIDI_ID(0)) | |
3874 | OP_S_READ_EXPECT (a, "apple", 5) | |
3875 | ||
3876 | OP_SET_INJECT_WORD (4, 0) | |
3877 | ||
3878 | OP_S_WRITE (a, "Strawberry", 10) | |
3879 | OP_C_READ_EXPECT (DEFAULT, "Strawberry", 10) | |
3880 | ||
3881 | OP_END | |
3882 | }; | |
3883 | ||
3884 | /* 50. Fault injection - ACK - duplicate PN */ | |
3885 | static const struct script_op script_50[] = { | |
3886 | OP_S_SET_INJECT_PLAIN (script_46_inject_plain) | |
3887 | OP_C_SET_ALPN ("ossltest") | |
3888 | OP_C_CONNECT_WAIT () | |
3889 | ||
3890 | OP_C_WRITE (DEFAULT, "apple", 5) | |
3891 | OP_S_BIND_STREAM_ID (a, C_BIDI_ID(0)) | |
3892 | OP_S_READ_EXPECT (a, "apple", 5) | |
3893 | ||
3894 | OP_BEGIN_REPEAT (2) | |
3895 | ||
3896 | OP_SET_INJECT_WORD (5, 0) | |
3897 | ||
3898 | OP_S_WRITE (a, "Strawberry", 10) | |
3899 | OP_C_READ_EXPECT (DEFAULT, "Strawberry", 10) | |
3900 | ||
3901 | OP_END_REPEAT () | |
3902 | ||
3903 | OP_END | |
3904 | }; | |
3905 | ||
f2609004 | 3906 | /* 51. Fault injection - PATH_RESPONSE is ignored */ |
a1aff2c6 HL |
3907 | static const struct script_op script_51[] = { |
3908 | OP_S_SET_INJECT_PLAIN (script_41_inject_plain) | |
3909 | OP_C_SET_ALPN ("ossltest") | |
3910 | OP_C_CONNECT_WAIT () | |
3911 | ||
3912 | OP_C_WRITE (DEFAULT, "apple", 5) | |
3913 | OP_S_BIND_STREAM_ID (a, C_BIDI_ID(0)) | |
3914 | OP_S_READ_EXPECT (a, "apple", 5) | |
3915 | ||
3916 | OP_SET_INJECT_WORD (1, OSSL_QUIC_FRAME_TYPE_PATH_RESPONSE) | |
3917 | ||
3918 | OP_S_WRITE (a, "orange", 6) | |
3919 | OP_C_READ_EXPECT (DEFAULT, "orange", 6) | |
3920 | ||
3921 | OP_C_WRITE (DEFAULT, "Strawberry", 10) | |
3922 | OP_S_READ_EXPECT (a, "Strawberry", 10) | |
3923 | ||
3924 | OP_END | |
3925 | }; | |
3926 | ||
477944b6 HL |
3927 | /* 52. Fault injection - ignore BLOCKED frames with bogus values */ |
3928 | static int script_52_inject_plain(struct helper *h, QUIC_PKT_HDR *hdr, | |
3929 | unsigned char *buf, size_t len) | |
3930 | { | |
3931 | int ok = 0; | |
3932 | unsigned char frame_buf[64]; | |
3933 | size_t written; | |
3934 | WPACKET wpkt; | |
3935 | uint64_t type = h->inject_word1; | |
3936 | ||
3937 | if (h->inject_word0 == 0) | |
3938 | return 1; | |
3939 | ||
3940 | --h->inject_word0; | |
3941 | ||
3942 | if (!TEST_true(WPACKET_init_static_len(&wpkt, frame_buf, | |
3943 | sizeof(frame_buf), 0))) | |
3944 | return 0; | |
3945 | ||
3946 | if (!TEST_true(WPACKET_quic_write_vlint(&wpkt, type))) | |
3947 | goto err; | |
3948 | ||
3949 | if (type == OSSL_QUIC_FRAME_TYPE_STREAM_DATA_BLOCKED) | |
3950 | if (!TEST_true(WPACKET_quic_write_vlint(&wpkt, C_BIDI_ID(0)))) | |
3951 | goto err; | |
3952 | ||
3953 | if (!TEST_true(WPACKET_quic_write_vlint(&wpkt, 0xFFFFFF))) | |
3954 | goto err; | |
3955 | ||
3956 | if (!TEST_true(WPACKET_get_total_written(&wpkt, &written))) | |
3957 | goto err; | |
3958 | ||
3959 | if (!qtest_fault_prepend_frame(h->qtf, frame_buf, written)) | |
3960 | goto err; | |
3961 | ||
3962 | ok = 1; | |
3963 | err: | |
3964 | if (ok) | |
3965 | WPACKET_finish(&wpkt); | |
3966 | else | |
3967 | WPACKET_cleanup(&wpkt); | |
3968 | return ok; | |
3969 | } | |
3970 | ||
3971 | static const struct script_op script_52[] = { | |
3972 | OP_S_SET_INJECT_PLAIN (script_52_inject_plain) | |
3973 | OP_C_SET_ALPN ("ossltest") | |
3974 | OP_C_CONNECT_WAIT () | |
3975 | ||
3976 | OP_C_WRITE (DEFAULT, "apple", 5) | |
3977 | OP_S_BIND_STREAM_ID (a, C_BIDI_ID(0)) | |
3978 | OP_S_READ_EXPECT (a, "apple", 5) | |
3979 | ||
3980 | OP_SET_INJECT_WORD (1, OSSL_QUIC_FRAME_TYPE_DATA_BLOCKED) | |
3981 | ||
3982 | OP_S_WRITE (a, "orange", 6) | |
3983 | OP_C_READ_EXPECT (DEFAULT, "orange", 6) | |
3984 | ||
3985 | OP_C_WRITE (DEFAULT, "Strawberry", 10) | |
3986 | OP_S_READ_EXPECT (a, "Strawberry", 10) | |
3987 | ||
3988 | OP_SET_INJECT_WORD (1, OSSL_QUIC_FRAME_TYPE_STREAM_DATA_BLOCKED) | |
3989 | ||
3990 | OP_S_WRITE (a, "orange", 6) | |
3991 | OP_C_READ_EXPECT (DEFAULT, "orange", 6) | |
3992 | ||
3993 | OP_C_WRITE (DEFAULT, "Strawberry", 10) | |
3994 | OP_S_READ_EXPECT (a, "Strawberry", 10) | |
3995 | ||
3996 | OP_SET_INJECT_WORD (1, OSSL_QUIC_FRAME_TYPE_STREAMS_BLOCKED_UNI) | |
3997 | ||
3998 | OP_S_WRITE (a, "orange", 6) | |
3999 | OP_C_READ_EXPECT (DEFAULT, "orange", 6) | |
4000 | ||
4001 | OP_C_WRITE (DEFAULT, "Strawberry", 10) | |
4002 | OP_S_READ_EXPECT (a, "Strawberry", 10) | |
4003 | ||
4004 | OP_SET_INJECT_WORD (1, OSSL_QUIC_FRAME_TYPE_STREAMS_BLOCKED_BIDI) | |
4005 | ||
4006 | OP_S_WRITE (a, "orange", 6) | |
4007 | OP_C_READ_EXPECT (DEFAULT, "orange", 6) | |
4008 | ||
4009 | OP_C_WRITE (DEFAULT, "Strawberry", 10) | |
4010 | OP_S_READ_EXPECT (a, "Strawberry", 10) | |
4011 | ||
4012 | OP_END | |
4013 | }; | |
a1aff2c6 | 4014 | |
de56eebd HL |
4015 | /* 53. Fault injection - excess CRYPTO buffer size */ |
4016 | static int script_53_inject_plain(struct helper *h, QUIC_PKT_HDR *hdr, | |
4017 | unsigned char *buf, size_t len) | |
4018 | { | |
4019 | int ok = 0; | |
4020 | size_t written; | |
4021 | WPACKET wpkt; | |
4022 | uint64_t offset = 0, data_len = 100; | |
4023 | unsigned char *frame_buf = NULL; | |
4024 | size_t frame_len, i; | |
4025 | ||
4026 | if (h->inject_word0 == 0) | |
4027 | return 1; | |
4028 | ||
4029 | h->inject_word0 = 0; | |
4030 | ||
4031 | switch (h->inject_word1) { | |
4032 | case 0: | |
4033 | /* | |
4034 | * Far out offset which will not have been reached during handshake. | |
4035 | * This will not be delivered to the QUIC_TLS instance since it will be | |
4036 | * waiting for in-order delivery of previous bytes. This tests our flow | |
4037 | * control on CRYPTO stream buffering. | |
4038 | */ | |
4039 | offset = 100000; | |
4040 | data_len = 1; | |
4041 | break; | |
4042 | } | |
4043 | ||
d49a1634 | 4044 | frame_len = 1 + 8 + 8 + (size_t)data_len; |
de56eebd HL |
4045 | if (!TEST_ptr(frame_buf = OPENSSL_malloc(frame_len))) |
4046 | return 0; | |
4047 | ||
4048 | if (!TEST_true(WPACKET_init_static_len(&wpkt, frame_buf, frame_len, 0))) | |
4049 | goto err; | |
4050 | ||
4051 | if (!TEST_true(WPACKET_quic_write_vlint(&wpkt, OSSL_QUIC_FRAME_TYPE_CRYPTO)) | |
4052 | || !TEST_true(WPACKET_quic_write_vlint(&wpkt, offset)) | |
4053 | || !TEST_true(WPACKET_quic_write_vlint(&wpkt, data_len))) | |
4054 | goto err; | |
4055 | ||
4056 | for (i = 0; i < data_len; ++i) | |
4057 | if (!TEST_true(WPACKET_put_bytes_u8(&wpkt, 0x42))) | |
4058 | goto err; | |
4059 | ||
4060 | if (!TEST_true(WPACKET_get_total_written(&wpkt, &written))) | |
4061 | goto err; | |
4062 | ||
4063 | if (!qtest_fault_prepend_frame(h->qtf, frame_buf, written)) | |
4064 | goto err; | |
4065 | ||
4066 | ok = 1; | |
4067 | err: | |
4068 | if (ok) | |
4069 | WPACKET_finish(&wpkt); | |
4070 | else | |
4071 | WPACKET_cleanup(&wpkt); | |
4072 | OPENSSL_free(frame_buf); | |
4073 | return ok; | |
4074 | } | |
4075 | ||
4076 | static const struct script_op script_53[] = { | |
4077 | OP_S_SET_INJECT_PLAIN (script_53_inject_plain) | |
4078 | OP_C_SET_ALPN ("ossltest") | |
4079 | OP_C_CONNECT_WAIT () | |
4080 | ||
4081 | OP_C_WRITE (DEFAULT, "apple", 5) | |
4082 | OP_S_BIND_STREAM_ID (a, C_BIDI_ID(0)) | |
4083 | OP_S_READ_EXPECT (a, "apple", 5) | |
4084 | ||
4085 | OP_SET_INJECT_WORD (1, 0) | |
4086 | OP_S_WRITE (a, "Strawberry", 10) | |
4087 | ||
4088 | OP_C_EXPECT_CONN_CLOSE_INFO(QUIC_ERR_CRYPTO_BUFFER_EXCEEDED,0,0) | |
4089 | ||
4090 | OP_END | |
4091 | }; | |
4092 | ||
4093 | /* 54. Fault injection - corrupted crypto stream data */ | |
4094 | static int script_54_inject_handshake(struct helper *h, | |
4095 | unsigned char *buf, size_t buf_len) | |
4096 | { | |
4097 | size_t i; | |
4098 | ||
4099 | for (i = 0; i < buf_len; ++i) | |
4100 | buf[i] ^= 0xff; | |
4101 | ||
4102 | return 1; | |
4103 | } | |
4104 | ||
4105 | static const struct script_op script_54[] = { | |
4106 | OP_S_SET_INJECT_HANDSHAKE(script_54_inject_handshake) | |
4107 | OP_C_SET_ALPN ("ossltest") | |
4108 | OP_C_CONNECT_WAIT_OR_FAIL() | |
4109 | ||
4110 | OP_C_EXPECT_CONN_CLOSE_INFO(QUIC_ERR_CRYPTO_UNEXPECTED_MESSAGE,0,0) | |
4111 | ||
4112 | OP_END | |
4113 | }; | |
4114 | ||
ed75eb32 HL |
4115 | /* 55. Fault injection - NEW_CONN_ID with >20 byte CID */ |
4116 | static const struct script_op script_55[] = { | |
4117 | OP_S_SET_INJECT_PLAIN (script_39_inject_plain) | |
4118 | OP_C_SET_ALPN ("ossltest") | |
4119 | OP_C_CONNECT_WAIT () | |
4120 | OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE) | |
4121 | ||
4122 | OP_C_NEW_STREAM_BIDI (a, C_BIDI_ID(0)) | |
4123 | OP_C_WRITE (a, "apple", 5) | |
4124 | OP_S_BIND_STREAM_ID (a, C_BIDI_ID(0)) | |
4125 | OP_S_READ_EXPECT (a, "apple", 5) | |
4126 | ||
4127 | OP_SET_INJECT_WORD (0, 2) | |
4128 | OP_S_WRITE (a, "orange", 5) | |
4129 | ||
4130 | OP_C_EXPECT_CONN_CLOSE_INFO(QUIC_ERR_FRAME_ENCODING_ERROR,0,0) | |
4131 | ||
4132 | OP_END | |
4133 | }; | |
4134 | ||
4135 | /* 56. Fault injection - NEW_CONN_ID with seq no < retire prior to */ | |
4136 | static const struct script_op script_56[] = { | |
4137 | OP_S_SET_INJECT_PLAIN (script_39_inject_plain) | |
4138 | OP_C_SET_ALPN ("ossltest") | |
4139 | OP_C_CONNECT_WAIT () | |
4140 | OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE) | |
4141 | ||
4142 | OP_C_NEW_STREAM_BIDI (a, C_BIDI_ID(0)) | |
4143 | OP_C_WRITE (a, "apple", 5) | |
4144 | OP_S_BIND_STREAM_ID (a, C_BIDI_ID(0)) | |
4145 | OP_S_READ_EXPECT (a, "apple", 5) | |
4146 | ||
4147 | OP_SET_INJECT_WORD (0, 3) | |
4148 | OP_S_WRITE (a, "orange", 5) | |
4149 | ||
4150 | OP_C_EXPECT_CONN_CLOSE_INFO(QUIC_ERR_FRAME_ENCODING_ERROR,0,0) | |
4151 | ||
4152 | OP_END | |
4153 | }; | |
4154 | ||
f2609004 | 4155 | /* 57. Fault injection - NEW_CONN_ID with lower seq so ignored */ |
ed75eb32 HL |
4156 | static const struct script_op script_57[] = { |
4157 | OP_S_SET_INJECT_PLAIN (script_39_inject_plain) | |
4158 | OP_C_SET_ALPN ("ossltest") | |
4159 | OP_C_CONNECT_WAIT () | |
4160 | OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE) | |
4161 | ||
4162 | OP_C_NEW_STREAM_BIDI (a, C_BIDI_ID(0)) | |
4163 | OP_C_WRITE (a, "apple", 5) | |
4164 | OP_S_BIND_STREAM_ID (a, C_BIDI_ID(0)) | |
4165 | OP_S_READ_EXPECT (a, "apple", 5) | |
4166 | ||
4167 | OP_SET_INJECT_WORD (0, 4) | |
4168 | OP_S_WRITE (a, "orange", 5) | |
4169 | OP_C_READ_EXPECT (a, "orange", 5) | |
4170 | ||
4171 | OP_C_WRITE (a, "Strawberry", 10) | |
4172 | OP_S_READ_EXPECT (a, "Strawberry", 10) | |
4173 | ||
4174 | /* | |
4175 | * Now we send a NEW_CONN_ID with a bogus CID. However the sequence number | |
4176 | * is old so it should be ignored and we should still be able to | |
4177 | * communicate. | |
4178 | */ | |
4179 | OP_SET_INJECT_WORD (0, 5) | |
4180 | OP_S_WRITE (a, "raspberry", 9) | |
4181 | OP_C_READ_EXPECT (a, "raspberry", 9) | |
4182 | ||
4183 | OP_C_WRITE (a, "peach", 5) | |
4184 | OP_S_READ_EXPECT (a, "peach", 5) | |
4185 | ||
4186 | OP_END | |
4187 | }; | |
4188 | ||
d56b81ac HL |
4189 | /* 58. Fault injection - repeated HANDSHAKE_DONE */ |
4190 | static int script_58_inject_plain(struct helper *h, QUIC_PKT_HDR *hdr, | |
4191 | unsigned char *buf, size_t len) | |
4192 | { | |
4193 | int ok = 0; | |
4194 | unsigned char frame_buf[64]; | |
4195 | size_t written; | |
4196 | WPACKET wpkt; | |
4197 | ||
4198 | if (h->inject_word0 == 0) | |
4199 | return 1; | |
4200 | ||
4201 | if (!TEST_true(WPACKET_init_static_len(&wpkt, frame_buf, | |
4202 | sizeof(frame_buf), 0))) | |
4203 | return 0; | |
4204 | ||
4205 | if (h->inject_word0 == 1) { | |
4206 | if (!TEST_true(WPACKET_quic_write_vlint(&wpkt, OSSL_QUIC_FRAME_TYPE_HANDSHAKE_DONE))) | |
4207 | goto err; | |
4208 | } else { | |
4209 | /* Needless multi-byte encoding */ | |
4210 | if (!TEST_true(WPACKET_put_bytes_u8(&wpkt, 0x40)) | |
4211 | || !TEST_true(WPACKET_put_bytes_u8(&wpkt, 0x1E))) | |
4212 | goto err; | |
4213 | } | |
4214 | ||
4215 | if (!TEST_true(WPACKET_get_total_written(&wpkt, &written))) | |
4216 | goto err; | |
4217 | ||
4218 | if (!qtest_fault_prepend_frame(h->qtf, frame_buf, written)) | |
4219 | goto err; | |
4220 | ||
4221 | ok = 1; | |
4222 | err: | |
4223 | if (ok) | |
4224 | WPACKET_finish(&wpkt); | |
4225 | else | |
4226 | WPACKET_cleanup(&wpkt); | |
4227 | return ok; | |
4228 | } | |
4229 | ||
4230 | static const struct script_op script_58[] = { | |
4231 | OP_S_SET_INJECT_PLAIN (script_58_inject_plain) | |
4232 | OP_C_SET_ALPN ("ossltest") | |
4233 | OP_C_CONNECT_WAIT () | |
4234 | ||
4235 | OP_C_WRITE (DEFAULT, "apple", 5) | |
4236 | OP_S_BIND_STREAM_ID (a, C_BIDI_ID(0)) | |
4237 | OP_S_READ_EXPECT (a, "apple", 5) | |
4238 | ||
4239 | OP_SET_INJECT_WORD (1, 0) | |
4240 | ||
4241 | OP_S_WRITE (a, "orange", 6) | |
4242 | OP_C_READ_EXPECT (DEFAULT, "orange", 6) | |
4243 | ||
4244 | OP_C_WRITE (DEFAULT, "Strawberry", 10) | |
4245 | OP_S_READ_EXPECT (a, "Strawberry", 10) | |
4246 | ||
4247 | OP_END | |
4248 | }; | |
4249 | ||
4250 | /* 59. Fault injection - multi-byte frame encoding */ | |
4251 | static const struct script_op script_59[] = { | |
4252 | OP_S_SET_INJECT_PLAIN (script_58_inject_plain) | |
4253 | OP_C_SET_ALPN ("ossltest") | |
4254 | OP_C_CONNECT_WAIT () | |
4255 | ||
4256 | OP_C_WRITE (DEFAULT, "apple", 5) | |
4257 | OP_S_BIND_STREAM_ID (a, C_BIDI_ID(0)) | |
4258 | OP_S_READ_EXPECT (a, "apple", 5) | |
4259 | ||
4260 | OP_SET_INJECT_WORD (2, 0) | |
4261 | ||
4262 | OP_S_WRITE (a, "orange", 6) | |
4263 | ||
4264 | OP_C_EXPECT_CONN_CLOSE_INFO(QUIC_ERR_PROTOCOL_VIOLATION,0,0) | |
4265 | ||
4266 | OP_END | |
4267 | }; | |
4268 | ||
d49a1634 HL |
4269 | /* 60. Connection close reason truncation */ |
4270 | static char long_reason[2048]; | |
4271 | ||
5881dd2c | 4272 | static int init_reason(struct helper *h, struct helper_local *hl) |
d49a1634 HL |
4273 | { |
4274 | memset(long_reason, '~', sizeof(long_reason)); | |
4275 | memcpy(long_reason, "This is a long reason string.", 29); | |
d63b8cbb | 4276 | long_reason[OSSL_NELEM(long_reason) - 1] = '\0'; |
d49a1634 HL |
4277 | return 1; |
4278 | } | |
4279 | ||
5881dd2c | 4280 | static int check_shutdown_reason(struct helper *h, struct helper_local *hl) |
d49a1634 | 4281 | { |
5881dd2c | 4282 | const QUIC_TERMINATE_CAUSE *tc = ossl_quic_tserver_get_terminate_cause(ACQUIRE_S()); |
d49a1634 HL |
4283 | |
4284 | if (tc == NULL) { | |
4285 | h->check_spin_again = 1; | |
4286 | return 0; | |
4287 | } | |
4288 | ||
4289 | if (!TEST_size_t_ge(tc->reason_len, 50) | |
4290 | || !TEST_mem_eq(long_reason, tc->reason_len, | |
4291 | tc->reason, tc->reason_len)) | |
4292 | return 0; | |
4293 | ||
4294 | return 1; | |
4295 | } | |
4296 | ||
4297 | static const struct script_op script_60[] = { | |
4298 | OP_C_SET_ALPN ("ossltest") | |
4299 | OP_C_CONNECT_WAIT () | |
4300 | ||
4301 | OP_C_WRITE (DEFAULT, "apple", 5) | |
4302 | OP_S_BIND_STREAM_ID (a, C_BIDI_ID(0)) | |
4303 | OP_S_READ_EXPECT (a, "apple", 5) | |
4304 | ||
4305 | OP_CHECK (init_reason, 0) | |
3bc38ba0 | 4306 | OP_C_SHUTDOWN_WAIT (long_reason, 0) |
d49a1634 HL |
4307 | OP_CHECK (check_shutdown_reason, 0) |
4308 | ||
4309 | OP_END | |
4310 | }; | |
4311 | ||
d63b8cbb HL |
4312 | /* 61. Fault injection - RESET_STREAM exceeding stream count FC */ |
4313 | static int script_61_inject_plain(struct helper *h, QUIC_PKT_HDR *hdr, | |
4314 | unsigned char *buf, size_t len) | |
4315 | { | |
4316 | int ok = 0; | |
4317 | WPACKET wpkt; | |
4318 | unsigned char frame_buf[32]; | |
4319 | size_t written; | |
4320 | ||
4321 | if (h->inject_word0 == 0) | |
4322 | return 1; | |
4323 | ||
4324 | if (!TEST_true(WPACKET_init_static_len(&wpkt, frame_buf, | |
4325 | sizeof(frame_buf), 0))) | |
4326 | return 0; | |
4327 | ||
4328 | if (!TEST_true(WPACKET_quic_write_vlint(&wpkt, h->inject_word0)) | |
4329 | || !TEST_true(WPACKET_quic_write_vlint(&wpkt, /* stream ID */ | |
4330 | h->inject_word1)) | |
4331 | || !TEST_true(WPACKET_quic_write_vlint(&wpkt, 123)) | |
4332 | || (h->inject_word1 == OSSL_QUIC_FRAME_TYPE_RESET_STREAM | |
4333 | && !TEST_true(WPACKET_quic_write_vlint(&wpkt, 0)))) /* final size */ | |
4334 | goto err; | |
4335 | ||
4336 | if (!TEST_true(WPACKET_get_total_written(&wpkt, &written))) | |
4337 | goto err; | |
4338 | ||
4339 | if (!qtest_fault_prepend_frame(h->qtf, frame_buf, written)) | |
4340 | goto err; | |
4341 | ||
4342 | ok = 1; | |
4343 | err: | |
4344 | if (ok) | |
4345 | WPACKET_finish(&wpkt); | |
4346 | else | |
4347 | WPACKET_cleanup(&wpkt); | |
4348 | return ok; | |
4349 | } | |
4350 | ||
4351 | static const struct script_op script_61[] = { | |
4352 | OP_S_SET_INJECT_PLAIN (script_61_inject_plain) | |
4353 | OP_C_SET_ALPN ("ossltest") | |
4354 | OP_C_CONNECT_WAIT () | |
4355 | OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE) | |
4356 | ||
4357 | OP_C_NEW_STREAM_BIDI (a, C_BIDI_ID(0)) | |
4358 | OP_C_WRITE (a, "orange", 6) | |
4359 | ||
4360 | OP_S_BIND_STREAM_ID (a, C_BIDI_ID(0)) | |
4361 | OP_S_READ_EXPECT (a, "orange", 6) | |
4362 | ||
4363 | OP_SET_INJECT_WORD (OSSL_QUIC_FRAME_TYPE_RESET_STREAM, | |
4364 | S_BIDI_ID(OSSL_QUIC_VLINT_MAX / 4)) | |
4365 | OP_S_WRITE (a, "fruit", 5) | |
4366 | ||
4367 | OP_C_EXPECT_CONN_CLOSE_INFO(QUIC_ERR_STREAM_LIMIT_ERROR,0,0) | |
4368 | ||
4369 | OP_END | |
4370 | }; | |
4371 | ||
4372 | /* 62. Fault injection - STOP_SENDING with high ID */ | |
4373 | static const struct script_op script_62[] = { | |
4374 | OP_S_SET_INJECT_PLAIN (script_61_inject_plain) | |
4375 | OP_C_SET_ALPN ("ossltest") | |
4376 | OP_C_CONNECT_WAIT () | |
4377 | OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE) | |
4378 | ||
4379 | OP_C_NEW_STREAM_BIDI (a, C_BIDI_ID(0)) | |
4380 | OP_C_WRITE (a, "orange", 6) | |
4381 | ||
4382 | OP_S_BIND_STREAM_ID (a, C_BIDI_ID(0)) | |
4383 | OP_S_READ_EXPECT (a, "orange", 6) | |
4384 | ||
4385 | OP_SET_INJECT_WORD (OSSL_QUIC_FRAME_TYPE_STOP_SENDING, | |
4386 | C_BIDI_ID(OSSL_QUIC_VLINT_MAX / 4)) | |
4387 | OP_S_WRITE (a, "fruit", 5) | |
4388 | ||
4389 | OP_C_EXPECT_CONN_CLOSE_INFO(QUIC_ERR_STREAM_STATE_ERROR,0,0) | |
4390 | ||
4391 | OP_END | |
4392 | }; | |
d49a1634 | 4393 | |
1623bf37 HL |
4394 | /* 63. Fault injection - STREAM frame exceeding stream limit */ |
4395 | static const struct script_op script_63[] = { | |
4396 | OP_S_SET_INJECT_PLAIN (script_32_inject_plain) | |
4397 | OP_C_SET_ALPN ("ossltest") | |
4398 | OP_C_CONNECT_WAIT () | |
4399 | OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE) | |
4400 | ||
4401 | OP_C_NEW_STREAM_BIDI (a, C_BIDI_ID(0)) | |
4402 | OP_C_WRITE (a, "apple", 5) | |
4403 | ||
4404 | OP_S_BIND_STREAM_ID (a, C_BIDI_ID(0)) | |
4405 | OP_S_READ_EXPECT (a, "apple", 5) | |
4406 | ||
4407 | OP_SET_INJECT_WORD (S_BIDI_ID(5000) + 1, 4) | |
4408 | OP_S_WRITE (a, "orange", 6) | |
4409 | ||
4410 | OP_C_EXPECT_CONN_CLOSE_INFO(QUIC_ERR_STREAM_LIMIT_ERROR,0,0) | |
4411 | ||
4412 | OP_END | |
4413 | }; | |
4414 | ||
4415 | /* 64. Fault injection - STREAM - zero-length no-FIN is accepted */ | |
4416 | static const struct script_op script_64[] = { | |
4417 | OP_S_SET_INJECT_PLAIN (script_32_inject_plain) | |
4418 | OP_C_SET_ALPN ("ossltest") | |
4419 | OP_C_CONNECT_WAIT () | |
4420 | OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE) | |
4421 | ||
4422 | OP_S_NEW_STREAM_UNI (a, S_UNI_ID(0)) | |
4423 | OP_S_WRITE (a, "apple", 5) | |
4424 | ||
4425 | OP_C_ACCEPT_STREAM_WAIT (a) | |
4426 | OP_C_READ_EXPECT (a, "apple", 5) | |
4427 | ||
4428 | OP_SET_INJECT_WORD (S_BIDI_ID(20) + 1, 1) | |
4429 | OP_S_WRITE (a, "orange", 6) | |
4430 | OP_C_READ_EXPECT (a, "orange", 6) | |
4431 | ||
4432 | OP_END | |
4433 | }; | |
4434 | ||
4435 | /* 65. Fault injection - CRYPTO - zero-length is accepted */ | |
4436 | static int script_65_inject_plain(struct helper *h, QUIC_PKT_HDR *hdr, | |
4437 | unsigned char *buf, size_t len) | |
4438 | { | |
4439 | int ok = 0; | |
4440 | unsigned char frame_buf[64]; | |
4441 | size_t written; | |
4442 | WPACKET wpkt; | |
4443 | ||
4444 | if (h->inject_word0 == 0) | |
4445 | return 1; | |
4446 | ||
4447 | --h->inject_word0; | |
4448 | ||
4449 | if (!TEST_true(WPACKET_init_static_len(&wpkt, frame_buf, | |
4450 | sizeof(frame_buf), 0))) | |
4451 | return 0; | |
4452 | ||
4453 | if (!TEST_true(WPACKET_quic_write_vlint(&wpkt, OSSL_QUIC_FRAME_TYPE_CRYPTO)) | |
4454 | || !TEST_true(WPACKET_quic_write_vlint(&wpkt, 0)) | |
4455 | || !TEST_true(WPACKET_quic_write_vlint(&wpkt, 0))) | |
4456 | goto err; | |
4457 | ||
4458 | if (!TEST_true(WPACKET_get_total_written(&wpkt, &written))) | |
4459 | goto err; | |
4460 | ||
4461 | if (!qtest_fault_prepend_frame(h->qtf, frame_buf, written)) | |
4462 | goto err; | |
4463 | ||
4464 | ok = 1; | |
4465 | err: | |
4466 | if (ok) | |
4467 | WPACKET_finish(&wpkt); | |
4468 | else | |
4469 | WPACKET_cleanup(&wpkt); | |
4470 | return ok; | |
4471 | } | |
4472 | ||
4473 | static const struct script_op script_65[] = { | |
4474 | OP_S_SET_INJECT_PLAIN (script_65_inject_plain) | |
4475 | OP_C_SET_ALPN ("ossltest") | |
4476 | OP_C_CONNECT_WAIT () | |
4477 | OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE) | |
4478 | ||
4479 | OP_C_NEW_STREAM_BIDI (a, C_BIDI_ID(0)) | |
4480 | OP_C_WRITE (a, "apple", 5) | |
4481 | ||
4482 | OP_S_BIND_STREAM_ID (a, C_BIDI_ID(0)) | |
4483 | OP_S_READ_EXPECT (a, "apple", 5) | |
4484 | ||
4485 | OP_SET_INJECT_WORD (1, 0) | |
4486 | OP_S_WRITE (a, "orange", 6) | |
4487 | OP_C_READ_EXPECT (a, "orange", 6) | |
4488 | ||
4489 | OP_END | |
4490 | }; | |
4491 | ||
4492 | /* 66. Fault injection - large MAX_STREAM_DATA */ | |
4493 | static int script_66_inject_plain(struct helper *h, QUIC_PKT_HDR *hdr, | |
4494 | unsigned char *buf, size_t len) | |
4495 | { | |
4496 | int ok = 0; | |
4497 | WPACKET wpkt; | |
4498 | unsigned char frame_buf[64]; | |
4499 | size_t written; | |
4500 | ||
4501 | if (h->inject_word0 == 0) | |
4502 | return 1; | |
4503 | ||
4504 | if (!TEST_true(WPACKET_init_static_len(&wpkt, frame_buf, | |
4505 | sizeof(frame_buf), 0))) | |
4506 | return 0; | |
4507 | ||
4508 | if (!TEST_true(WPACKET_quic_write_vlint(&wpkt, h->inject_word1))) | |
4509 | goto err; | |
4510 | ||
4511 | if (h->inject_word1 == OSSL_QUIC_FRAME_TYPE_MAX_STREAM_DATA) | |
4512 | if (!TEST_true(WPACKET_quic_write_vlint(&wpkt, /* stream ID */ | |
4513 | h->inject_word0 - 1))) | |
4514 | goto err; | |
4515 | ||
4516 | if (!TEST_true(WPACKET_quic_write_vlint(&wpkt, OSSL_QUIC_VLINT_MAX))) | |
4517 | goto err; | |
4518 | ||
4519 | if (!TEST_true(WPACKET_get_total_written(&wpkt, &written))) | |
4520 | goto err; | |
4521 | ||
4522 | if (!qtest_fault_prepend_frame(h->qtf, frame_buf, written)) | |
4523 | goto err; | |
4524 | ||
4525 | ok = 1; | |
4526 | err: | |
4527 | if (ok) | |
4528 | WPACKET_finish(&wpkt); | |
4529 | else | |
4530 | WPACKET_cleanup(&wpkt); | |
4531 | return ok; | |
4532 | } | |
4533 | ||
4534 | static const struct script_op script_66[] = { | |
4535 | OP_S_SET_INJECT_PLAIN (script_66_inject_plain) | |
4536 | OP_C_SET_ALPN ("ossltest") | |
4537 | OP_C_CONNECT_WAIT () | |
4538 | OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE) | |
4539 | ||
4540 | OP_S_NEW_STREAM_BIDI (a, S_BIDI_ID(0)) | |
4541 | OP_S_WRITE (a, "apple", 5) | |
4542 | ||
4543 | OP_C_ACCEPT_STREAM_WAIT (a) | |
4544 | OP_C_READ_EXPECT (a, "apple", 5) | |
4545 | ||
4546 | OP_SET_INJECT_WORD (S_BIDI_ID(0) + 1, OSSL_QUIC_FRAME_TYPE_MAX_STREAM_DATA) | |
4547 | OP_S_WRITE (a, "orange", 6) | |
4548 | OP_C_READ_EXPECT (a, "orange", 6) | |
4549 | OP_C_WRITE (a, "Strawberry", 10) | |
4550 | OP_S_READ_EXPECT (a, "Strawberry", 10) | |
4551 | ||
4552 | OP_END | |
4553 | }; | |
4554 | ||
4555 | /* 67. Fault injection - large MAX_DATA */ | |
4556 | static const struct script_op script_67[] = { | |
4557 | OP_S_SET_INJECT_PLAIN (script_66_inject_plain) | |
4558 | OP_C_SET_ALPN ("ossltest") | |
4559 | OP_C_CONNECT_WAIT () | |
4560 | OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE) | |
4561 | ||
4562 | OP_S_NEW_STREAM_BIDI (a, S_BIDI_ID(0)) | |
4563 | OP_S_WRITE (a, "apple", 5) | |
4564 | ||
4565 | OP_C_ACCEPT_STREAM_WAIT (a) | |
4566 | OP_C_READ_EXPECT (a, "apple", 5) | |
4567 | ||
4568 | OP_SET_INJECT_WORD (1, OSSL_QUIC_FRAME_TYPE_MAX_DATA) | |
4569 | OP_S_WRITE (a, "orange", 6) | |
4570 | OP_C_READ_EXPECT (a, "orange", 6) | |
4571 | OP_C_WRITE (a, "Strawberry", 10) | |
4572 | OP_S_READ_EXPECT (a, "Strawberry", 10) | |
4573 | ||
4574 | OP_END | |
4575 | }; | |
4576 | ||
644ef0bb MC |
4577 | /* 68. Fault injection - Unexpected TLS messages */ |
4578 | static int script_68_inject_handshake(struct helper *h, unsigned char *msg, | |
4579 | size_t msglen) | |
4580 | { | |
4581 | const unsigned char *data; | |
4582 | size_t datalen; | |
4583 | const unsigned char certreq[] = { | |
4584 | SSL3_MT_CERTIFICATE_REQUEST, /* CertificateRequest message */ | |
4585 | 0, 0, 12, /* Length of message */ | |
4586 | 1, 1, /* certificate_request_context */ | |
4587 | 0, 8, /* Extensions block length */ | |
4588 | 0, TLSEXT_TYPE_signature_algorithms, /* sig_algs extension*/ | |
4589 | 0, 4, /* 4 bytes of sig algs extension*/ | |
4590 | 0, 2, /* sigalgs list is 2 bytes long */ | |
4591 | 8, 4 /* rsa_pss_rsae_sha256 */ | |
4592 | }; | |
4593 | const unsigned char keyupdate[] = { | |
4594 | SSL3_MT_KEY_UPDATE, /* KeyUpdate message */ | |
4595 | 0, 0, 1, /* Length of message */ | |
4596 | SSL_KEY_UPDATE_NOT_REQUESTED /* update_not_requested */ | |
4597 | }; | |
4598 | ||
4599 | /* We transform the NewSessionTicket message into something else */ | |
4600 | switch(h->inject_word0) { | |
4601 | case 0: | |
4602 | return 1; | |
4603 | ||
4604 | case 1: | |
4605 | /* CertificateRequest message */ | |
4606 | data = certreq; | |
4607 | datalen = sizeof(certreq); | |
4608 | break; | |
4609 | ||
4610 | case 2: | |
4611 | /* KeyUpdate message */ | |
4612 | data = keyupdate; | |
4613 | datalen = sizeof(keyupdate); | |
4614 | break; | |
4615 | ||
4616 | default: | |
4617 | return 0; | |
4618 | } | |
4619 | ||
4620 | if (!TEST_true(qtest_fault_resize_message(h->qtf, | |
4621 | datalen - SSL3_HM_HEADER_LENGTH))) | |
4622 | return 0; | |
4623 | ||
4624 | memcpy(msg, data, datalen); | |
4625 | ||
4626 | return 1; | |
4627 | } | |
4628 | ||
4629 | /* Send a CerticateRequest message post-handshake */ | |
4630 | static const struct script_op script_68[] = { | |
4631 | OP_S_SET_INJECT_HANDSHAKE(script_68_inject_handshake) | |
4632 | OP_C_SET_ALPN ("ossltest") | |
4633 | OP_C_CONNECT_WAIT () | |
4634 | OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE) | |
4635 | ||
4636 | OP_C_NEW_STREAM_BIDI (a, C_BIDI_ID(0)) | |
4637 | OP_C_WRITE (a, "apple", 5) | |
4638 | OP_S_BIND_STREAM_ID (a, C_BIDI_ID(0)) | |
4639 | OP_S_READ_EXPECT (a, "apple", 5) | |
4640 | ||
4641 | OP_SET_INJECT_WORD (1, 0) | |
4642 | OP_S_NEW_TICKET () | |
4643 | OP_S_WRITE (a, "orange", 6) | |
4644 | ||
4645 | OP_C_EXPECT_CONN_CLOSE_INFO(QUIC_ERR_PROTOCOL_VIOLATION, 0, 0) | |
4646 | ||
4647 | OP_END | |
4648 | }; | |
4649 | ||
4650 | /* 69. Send a TLS KeyUpdate message post-handshake */ | |
4651 | static const struct script_op script_69[] = { | |
4652 | OP_S_SET_INJECT_HANDSHAKE(script_68_inject_handshake) | |
4653 | OP_C_SET_ALPN ("ossltest") | |
4654 | OP_C_CONNECT_WAIT () | |
4655 | OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE) | |
4656 | ||
4657 | OP_C_NEW_STREAM_BIDI (a, C_BIDI_ID(0)) | |
4658 | OP_C_WRITE (a, "apple", 5) | |
4659 | OP_S_BIND_STREAM_ID (a, C_BIDI_ID(0)) | |
4660 | OP_S_READ_EXPECT (a, "apple", 5) | |
4661 | ||
4662 | OP_SET_INJECT_WORD (2, 0) | |
4663 | OP_S_NEW_TICKET () | |
4664 | OP_S_WRITE (a, "orange", 6) | |
4665 | ||
4666 | OP_C_EXPECT_CONN_CLOSE_INFO(QUIC_ERR_CRYPTO_ERR_BEGIN | |
4667 | + SSL_AD_UNEXPECTED_MESSAGE, 0, 0) | |
4668 | ||
4669 | OP_END | |
4670 | }; | |
4671 | ||
5881dd2c | 4672 | static int set_max_early_data(struct helper *h, struct helper_local *hl) |
644ef0bb MC |
4673 | { |
4674 | ||
5881dd2c HL |
4675 | if (!TEST_true(ossl_quic_tserver_set_max_early_data(ACQUIRE_S(), |
4676 | (uint32_t)hl->check_op->arg2))) | |
644ef0bb MC |
4677 | return 0; |
4678 | ||
4679 | return 1; | |
4680 | } | |
4681 | ||
4682 | /* 70. Send a TLS NewSessionTicket message with invalid max_early_data */ | |
4683 | static const struct script_op script_70[] = { | |
4684 | OP_C_SET_ALPN ("ossltest") | |
4685 | OP_C_CONNECT_WAIT () | |
4686 | OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE) | |
4687 | ||
4688 | OP_C_NEW_STREAM_BIDI (a, C_BIDI_ID(0)) | |
4689 | OP_C_WRITE (a, "apple", 5) | |
4690 | OP_S_BIND_STREAM_ID (a, C_BIDI_ID(0)) | |
4691 | OP_S_READ_EXPECT (a, "apple", 5) | |
4692 | ||
4693 | OP_CHECK (set_max_early_data, 0xfffffffe) | |
4694 | OP_S_NEW_TICKET () | |
4695 | OP_S_WRITE (a, "orange", 6) | |
4696 | ||
4697 | OP_C_EXPECT_CONN_CLOSE_INFO(QUIC_ERR_PROTOCOL_VIOLATION, 0, 0) | |
4698 | ||
4699 | OP_END | |
4700 | }; | |
4701 | ||
4702 | /* 71. Send a TLS NewSessionTicket message with valid max_early_data */ | |
4703 | static const struct script_op script_71[] = { | |
4704 | OP_C_SET_ALPN ("ossltest") | |
4705 | OP_C_CONNECT_WAIT () | |
4706 | OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE) | |
4707 | ||
4708 | OP_C_NEW_STREAM_BIDI (a, C_BIDI_ID(0)) | |
4709 | OP_C_WRITE (a, "apple", 5) | |
4710 | OP_S_BIND_STREAM_ID (a, C_BIDI_ID(0)) | |
4711 | OP_S_READ_EXPECT (a, "apple", 5) | |
4712 | ||
4713 | OP_CHECK (set_max_early_data, 0xffffffff) | |
4714 | OP_S_NEW_TICKET () | |
4715 | OP_S_WRITE (a, "orange", 6) | |
4716 | OP_C_READ_EXPECT (a, "orange", 6) | |
4717 | ||
4718 | OP_END | |
4719 | }; | |
4720 | ||
14551f1e | 4721 | /* 72. Test that APL stops handing out streams after limit reached (bidi) */ |
5881dd2c | 4722 | static int script_72_check(struct helper *h, struct helper_local *hl) |
14551f1e HL |
4723 | { |
4724 | if (!TEST_uint64_t_ge(h->fail_count, 50)) | |
4725 | return 0; | |
4726 | ||
4727 | return 1; | |
4728 | } | |
4729 | ||
4730 | static const struct script_op script_72[] = { | |
4731 | OP_C_SET_ALPN ("ossltest") | |
4732 | OP_C_CONNECT_WAIT () | |
4733 | OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE) | |
4734 | ||
4735 | /* | |
4736 | * Request more streams than a server will initially hand out and test that | |
4737 | * they fail properly. | |
4738 | */ | |
4739 | OP_BEGIN_REPEAT (200) | |
4740 | ||
5881dd2c | 4741 | OP_C_NEW_STREAM_BIDI_EX (a, ANY_ID, ALLOW_FAIL | SSL_STREAM_FLAG_NO_BLOCK) |
14551f1e HL |
4742 | OP_C_SKIP_IF_UNBOUND (a, 2) |
4743 | OP_C_WRITE (a, "apple", 5) | |
4744 | OP_C_FREE_STREAM (a) | |
4745 | ||
4746 | OP_END_REPEAT () | |
4747 | ||
4748 | OP_CHECK (script_72_check, 0) | |
4749 | ||
4750 | OP_END | |
4751 | }; | |
4752 | ||
4753 | /* 73. Test that APL stops handing out streams after limit reached (uni) */ | |
4754 | static const struct script_op script_73[] = { | |
4755 | OP_C_SET_ALPN ("ossltest") | |
4756 | OP_C_CONNECT_WAIT () | |
4757 | OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE) | |
4758 | ||
4759 | /* | |
4760 | * Request more streams than a server will initially hand out and test that | |
4761 | * they fail properly. | |
4762 | */ | |
4763 | OP_BEGIN_REPEAT (200) | |
4764 | ||
5881dd2c | 4765 | OP_C_NEW_STREAM_UNI_EX (a, ANY_ID, ALLOW_FAIL | SSL_STREAM_FLAG_NO_BLOCK) |
14551f1e HL |
4766 | OP_C_SKIP_IF_UNBOUND (a, 2) |
4767 | OP_C_WRITE (a, "apple", 5) | |
4768 | OP_C_FREE_STREAM (a) | |
4769 | ||
4770 | OP_END_REPEAT () | |
4771 | ||
4772 | OP_CHECK (script_72_check, 0) | |
4773 | ||
4774 | OP_END | |
4775 | }; | |
4776 | ||
69169cd9 HL |
4777 | /* 74. Version negotiation: QUIC_VERSION_1 ignored */ |
4778 | static int generate_version_neg(WPACKET *wpkt, uint32_t version) | |
4779 | { | |
4780 | QUIC_PKT_HDR hdr = {0}; | |
4781 | ||
4782 | hdr.type = QUIC_PKT_TYPE_VERSION_NEG; | |
4783 | hdr.fixed = 1; | |
4784 | hdr.dst_conn_id.id_len = 0; | |
4785 | hdr.src_conn_id.id_len = 8; | |
4786 | memset(hdr.src_conn_id.id, 0x55, 8); | |
4787 | ||
4788 | if (!TEST_true(ossl_quic_wire_encode_pkt_hdr(wpkt, 0, &hdr, NULL))) | |
4789 | return 0; | |
4790 | ||
4791 | if (!TEST_true(WPACKET_put_bytes_u32(wpkt, version))) | |
4792 | return 0; | |
4793 | ||
4794 | return 1; | |
4795 | } | |
4796 | ||
4797 | static int server_gen_version_neg(struct helper *h, BIO_MSG *msg, size_t stride) | |
4798 | { | |
4799 | int rc = 0, have_wpkt = 0; | |
4800 | size_t l; | |
4801 | WPACKET wpkt; | |
4802 | BUF_MEM *buf = NULL; | |
4803 | uint32_t version; | |
4804 | ||
4805 | switch (h->inject_word0) { | |
4806 | case 0: | |
4807 | return 1; | |
4808 | case 1: | |
4809 | version = QUIC_VERSION_1; | |
4810 | break; | |
4811 | default: | |
4812 | version = 0x5432abcd; | |
4813 | break; | |
4814 | } | |
4815 | ||
4816 | if (!TEST_ptr(buf = BUF_MEM_new())) | |
4817 | goto err; | |
4818 | ||
4819 | if (!TEST_true(WPACKET_init(&wpkt, buf))) | |
4820 | goto err; | |
4821 | ||
4822 | have_wpkt = 1; | |
4823 | ||
4824 | generate_version_neg(&wpkt, version); | |
4825 | ||
4826 | if (!TEST_true(WPACKET_get_total_written(&wpkt, &l))) | |
4827 | goto err; | |
4828 | ||
4829 | if (!TEST_true(qtest_fault_resize_datagram(h->qtf, l))) | |
4830 | return 0; | |
4831 | ||
4832 | memcpy(msg->data, buf->data, l); | |
4833 | h->inject_word0 = 0; | |
4834 | ||
4835 | rc = 1; | |
4836 | err: | |
4837 | if (have_wpkt) | |
4838 | WPACKET_finish(&wpkt); | |
4839 | ||
4840 | BUF_MEM_free(buf); | |
4841 | return rc; | |
4842 | } | |
4843 | ||
4844 | static const struct script_op script_74[] = { | |
4845 | OP_S_SET_INJECT_DATAGRAM (server_gen_version_neg) | |
4846 | OP_SET_INJECT_WORD (1, 0) | |
4847 | ||
4848 | OP_C_SET_ALPN ("ossltest") | |
4849 | OP_C_CONNECT_WAIT () | |
4850 | ||
4851 | OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE) | |
4852 | ||
4853 | OP_C_NEW_STREAM_BIDI (a, C_BIDI_ID(0)) | |
4854 | OP_C_WRITE (a, "apple", 5) | |
4855 | OP_S_BIND_STREAM_ID (a, C_BIDI_ID(0)) | |
4856 | OP_S_READ_EXPECT (a, "apple", 5) | |
4857 | ||
4858 | OP_END | |
4859 | }; | |
4860 | ||
4861 | /* 75. Version negotiation: Unknown version causes connection abort */ | |
4862 | static const struct script_op script_75[] = { | |
4863 | OP_S_SET_INJECT_DATAGRAM (server_gen_version_neg) | |
4864 | OP_SET_INJECT_WORD (2, 0) | |
4865 | ||
4866 | OP_C_SET_ALPN ("ossltest") | |
4867 | OP_C_CONNECT_WAIT_OR_FAIL() | |
4868 | ||
4869 | OP_C_EXPECT_CONN_CLOSE_INFO(QUIC_ERR_CONNECTION_REFUSED,0,0) | |
4870 | ||
4871 | OP_END | |
4872 | }; | |
4873 | ||
5881dd2c HL |
4874 | /* 76. Test peer-initiated shutdown wait */ |
4875 | static int script_76_check(struct helper *h, struct helper_local *hl) | |
3bc38ba0 | 4876 | { |
5881dd2c HL |
4877 | if (!TEST_false(SSL_shutdown_ex(h->c_conn, |
4878 | SSL_SHUTDOWN_FLAG_WAIT_PEER | |
4879 | | SSL_SHUTDOWN_FLAG_NO_BLOCK, | |
3bc38ba0 HL |
4880 | NULL, 0))) |
4881 | return 0; | |
4882 | ||
4883 | return 1; | |
4884 | } | |
4885 | ||
4886 | static const struct script_op script_76[] = { | |
4887 | OP_C_SET_ALPN ("ossltest") | |
4888 | OP_C_CONNECT_WAIT () | |
4889 | OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE) | |
4890 | ||
4891 | OP_C_NEW_STREAM_BIDI (a, C_BIDI_ID(0)) | |
4892 | OP_C_WRITE (a, "apple", 5) | |
4893 | ||
4894 | OP_S_BIND_STREAM_ID (a, C_BIDI_ID(0)) | |
4895 | OP_S_READ_EXPECT (a, "apple", 5) | |
4896 | ||
4897 | /* Check a WAIT_PEER call doesn't succeed yet. */ | |
4898 | OP_CHECK (script_76_check, 0) | |
4899 | OP_S_SHUTDOWN (42) | |
4900 | ||
4901 | OP_C_SHUTDOWN_WAIT (NULL, SSL_SHUTDOWN_FLAG_WAIT_PEER) | |
4902 | OP_C_EXPECT_CONN_CLOSE_INFO(42, 1, 1) | |
4903 | ||
4904 | OP_END | |
4905 | }; | |
4906 | ||
ed835673 HL |
4907 | static const struct script_op *const scripts[] = { |
4908 | script_1, | |
4909 | script_2, | |
4910 | script_3, | |
4911 | script_4, | |
4912 | script_5, | |
4913 | script_6, | |
4914 | script_7, | |
4915 | script_8, | |
4916 | script_9, | |
4917 | script_10, | |
274bb489 HL |
4918 | script_11, |
4919 | script_12, | |
fca44cfc HL |
4920 | script_13, |
4921 | script_14, | |
0554f723 HL |
4922 | script_15, |
4923 | script_16, | |
693b23e3 HL |
4924 | script_17, |
4925 | script_18, | |
2525109f | 4926 | script_19, |
0345cac6 | 4927 | script_20, |
e26dc8e3 HL |
4928 | script_21, |
4929 | script_22, | |
4930 | script_23, | |
4931 | script_24, | |
4932 | script_25, | |
4933 | script_26, | |
4934 | script_27, | |
4935 | script_28, | |
4936 | script_29, | |
4937 | script_30, | |
4938 | script_31, | |
4939 | script_32, | |
4940 | script_33, | |
4941 | script_34, | |
4942 | script_35, | |
4943 | script_36, | |
4944 | script_37, | |
4945 | script_38, | |
8aa6a436 | 4946 | script_39, |
0786483a | 4947 | script_40, |
7eb330ff | 4948 | script_41, |
27c2f62f | 4949 | script_42, |
ab6c6345 | 4950 | script_43, |
97684a15 | 4951 | script_44, |
17340e87 | 4952 | script_45, |
ed0d6ba4 HL |
4953 | script_46, |
4954 | script_47, | |
4955 | script_48, | |
4956 | script_49, | |
4957 | script_50, | |
a1aff2c6 | 4958 | script_51, |
477944b6 | 4959 | script_52, |
de56eebd HL |
4960 | script_53, |
4961 | script_54, | |
ed75eb32 HL |
4962 | script_55, |
4963 | script_56, | |
4964 | script_57, | |
d56b81ac HL |
4965 | script_58, |
4966 | script_59, | |
d49a1634 | 4967 | script_60, |
d63b8cbb HL |
4968 | script_61, |
4969 | script_62, | |
1623bf37 HL |
4970 | script_63, |
4971 | script_64, | |
4972 | script_65, | |
4973 | script_66, | |
4974 | script_67, | |
644ef0bb MC |
4975 | script_68, |
4976 | script_69, | |
4977 | script_70, | |
14551f1e HL |
4978 | script_71, |
4979 | script_72, | |
69169cd9 HL |
4980 | script_73, |
4981 | script_74, | |
3bc38ba0 HL |
4982 | script_75, |
4983 | script_76 | |
ed835673 HL |
4984 | }; |
4985 | ||
4986 | static int test_script(int idx) | |
4987 | { | |
5881dd2c | 4988 | int script_idx, free_order, blocking; |
0786483a HL |
4989 | char script_name[64]; |
4990 | ||
5881dd2c HL |
4991 | free_order = idx % 2; |
4992 | idx /= 2; | |
4993 | ||
4994 | blocking = idx % 2; | |
4995 | idx /= 2; | |
4996 | ||
4997 | script_idx = idx; | |
4998 | ||
4999 | if (blocking && free_order) | |
5000 | return 1; /* don't need to test free_order twice */ | |
5001 | ||
5002 | #if !defined(OPENSSL_THREADS) | |
5003 | if (blocking) { | |
5004 | TEST_skip("cannot test in blocking mode without threads"); | |
5005 | return 1; | |
5006 | } | |
5007 | #endif | |
5008 | ||
cd5e4380 | 5009 | snprintf(script_name, sizeof(script_name), "script %d", script_idx + 1); |
97f30fd5 | 5010 | |
5881dd2c HL |
5011 | TEST_info("Running script %d (order=%d, blocking=%d)", script_idx + 1, |
5012 | free_order, blocking); | |
5013 | return run_script(scripts[script_idx], script_name, free_order, blocking); | |
ed835673 HL |
5014 | } |
5015 | ||
e26dc8e3 HL |
5016 | /* Dynamically generated tests. */ |
5017 | static struct script_op dyn_frame_types_script[] = { | |
8aa6a436 | 5018 | OP_S_SET_INJECT_PLAIN (script_21_inject_plain) |
e26dc8e3 HL |
5019 | OP_SET_INJECT_WORD (0, 0) /* dynamic */ |
5020 | ||
5021 | OP_C_SET_ALPN ("ossltest") | |
5022 | OP_C_CONNECT_WAIT_OR_FAIL() | |
5023 | ||
5024 | OP_C_EXPECT_CONN_CLOSE_INFO(QUIC_ERR_FRAME_ENCODING_ERROR,0,0) | |
5025 | ||
5026 | OP_END | |
5027 | }; | |
5028 | ||
5029 | struct forbidden_frame_type { | |
5030 | uint64_t pkt_type, frame_type, expected_err; | |
5031 | }; | |
5032 | ||
5033 | static const struct forbidden_frame_type forbidden_frame_types[] = { | |
5034 | { QUIC_PKT_TYPE_INITIAL, OSSL_QUIC_VLINT_MAX, QUIC_ERR_FRAME_ENCODING_ERROR }, | |
5035 | { QUIC_PKT_TYPE_HANDSHAKE, OSSL_QUIC_VLINT_MAX, QUIC_ERR_FRAME_ENCODING_ERROR }, | |
5036 | { QUIC_PKT_TYPE_1RTT, OSSL_QUIC_VLINT_MAX, QUIC_ERR_FRAME_ENCODING_ERROR }, | |
5037 | ||
5038 | { QUIC_PKT_TYPE_INITIAL, OSSL_QUIC_FRAME_TYPE_STREAM, QUIC_ERR_PROTOCOL_VIOLATION }, | |
5039 | { QUIC_PKT_TYPE_INITIAL, OSSL_QUIC_FRAME_TYPE_RESET_STREAM, QUIC_ERR_PROTOCOL_VIOLATION }, | |
5040 | { QUIC_PKT_TYPE_INITIAL, OSSL_QUIC_FRAME_TYPE_STOP_SENDING, QUIC_ERR_PROTOCOL_VIOLATION }, | |
5041 | { QUIC_PKT_TYPE_INITIAL, OSSL_QUIC_FRAME_TYPE_NEW_TOKEN, QUIC_ERR_PROTOCOL_VIOLATION }, | |
5042 | { QUIC_PKT_TYPE_INITIAL, OSSL_QUIC_FRAME_TYPE_MAX_DATA, QUIC_ERR_PROTOCOL_VIOLATION }, | |
5043 | { QUIC_PKT_TYPE_INITIAL, OSSL_QUIC_FRAME_TYPE_MAX_STREAM_DATA, QUIC_ERR_PROTOCOL_VIOLATION }, | |
5044 | { QUIC_PKT_TYPE_INITIAL, OSSL_QUIC_FRAME_TYPE_MAX_STREAMS_BIDI, QUIC_ERR_PROTOCOL_VIOLATION }, | |
5045 | { QUIC_PKT_TYPE_INITIAL, OSSL_QUIC_FRAME_TYPE_MAX_STREAMS_UNI, QUIC_ERR_PROTOCOL_VIOLATION }, | |
5046 | { QUIC_PKT_TYPE_INITIAL, OSSL_QUIC_FRAME_TYPE_DATA_BLOCKED, QUIC_ERR_PROTOCOL_VIOLATION }, | |
5047 | { QUIC_PKT_TYPE_INITIAL, OSSL_QUIC_FRAME_TYPE_STREAM_DATA_BLOCKED, QUIC_ERR_PROTOCOL_VIOLATION }, | |
5048 | { QUIC_PKT_TYPE_INITIAL, OSSL_QUIC_FRAME_TYPE_STREAMS_BLOCKED_BIDI, QUIC_ERR_PROTOCOL_VIOLATION }, | |
5049 | { QUIC_PKT_TYPE_INITIAL, OSSL_QUIC_FRAME_TYPE_STREAMS_BLOCKED_UNI, QUIC_ERR_PROTOCOL_VIOLATION }, | |
5050 | { QUIC_PKT_TYPE_INITIAL, OSSL_QUIC_FRAME_TYPE_NEW_CONN_ID, QUIC_ERR_PROTOCOL_VIOLATION }, | |
5051 | { QUIC_PKT_TYPE_INITIAL, OSSL_QUIC_FRAME_TYPE_RETIRE_CONN_ID, QUIC_ERR_PROTOCOL_VIOLATION }, | |
5052 | { QUIC_PKT_TYPE_INITIAL, OSSL_QUIC_FRAME_TYPE_PATH_CHALLENGE, QUIC_ERR_PROTOCOL_VIOLATION }, | |
5053 | { QUIC_PKT_TYPE_INITIAL, OSSL_QUIC_FRAME_TYPE_PATH_RESPONSE, QUIC_ERR_PROTOCOL_VIOLATION }, | |
5054 | { QUIC_PKT_TYPE_INITIAL, OSSL_QUIC_FRAME_TYPE_CONN_CLOSE_APP, QUIC_ERR_PROTOCOL_VIOLATION }, | |
5055 | { QUIC_PKT_TYPE_INITIAL, OSSL_QUIC_FRAME_TYPE_HANDSHAKE_DONE, QUIC_ERR_PROTOCOL_VIOLATION }, | |
5056 | ||
5057 | { QUIC_PKT_TYPE_HANDSHAKE, OSSL_QUIC_FRAME_TYPE_STREAM, QUIC_ERR_PROTOCOL_VIOLATION }, | |
5058 | { QUIC_PKT_TYPE_HANDSHAKE, OSSL_QUIC_FRAME_TYPE_RESET_STREAM, QUIC_ERR_PROTOCOL_VIOLATION }, | |
5059 | { QUIC_PKT_TYPE_HANDSHAKE, OSSL_QUIC_FRAME_TYPE_STOP_SENDING, QUIC_ERR_PROTOCOL_VIOLATION }, | |
5060 | { QUIC_PKT_TYPE_HANDSHAKE, OSSL_QUIC_FRAME_TYPE_NEW_TOKEN, QUIC_ERR_PROTOCOL_VIOLATION }, | |
5061 | { QUIC_PKT_TYPE_HANDSHAKE, OSSL_QUIC_FRAME_TYPE_MAX_DATA, QUIC_ERR_PROTOCOL_VIOLATION }, | |
5062 | { QUIC_PKT_TYPE_HANDSHAKE, OSSL_QUIC_FRAME_TYPE_MAX_STREAM_DATA, QUIC_ERR_PROTOCOL_VIOLATION }, | |
5063 | { QUIC_PKT_TYPE_HANDSHAKE, OSSL_QUIC_FRAME_TYPE_MAX_STREAMS_BIDI, QUIC_ERR_PROTOCOL_VIOLATION }, | |
5064 | { QUIC_PKT_TYPE_HANDSHAKE, OSSL_QUIC_FRAME_TYPE_MAX_STREAMS_UNI, QUIC_ERR_PROTOCOL_VIOLATION }, | |
5065 | { QUIC_PKT_TYPE_HANDSHAKE, OSSL_QUIC_FRAME_TYPE_DATA_BLOCKED, QUIC_ERR_PROTOCOL_VIOLATION }, | |
5066 | { QUIC_PKT_TYPE_HANDSHAKE, OSSL_QUIC_FRAME_TYPE_STREAM_DATA_BLOCKED, QUIC_ERR_PROTOCOL_VIOLATION }, | |
5067 | { QUIC_PKT_TYPE_HANDSHAKE, OSSL_QUIC_FRAME_TYPE_STREAMS_BLOCKED_BIDI, QUIC_ERR_PROTOCOL_VIOLATION }, | |
5068 | { QUIC_PKT_TYPE_HANDSHAKE, OSSL_QUIC_FRAME_TYPE_STREAMS_BLOCKED_UNI, QUIC_ERR_PROTOCOL_VIOLATION }, | |
5069 | { QUIC_PKT_TYPE_HANDSHAKE, OSSL_QUIC_FRAME_TYPE_NEW_CONN_ID, QUIC_ERR_PROTOCOL_VIOLATION }, | |
5070 | { QUIC_PKT_TYPE_HANDSHAKE, OSSL_QUIC_FRAME_TYPE_RETIRE_CONN_ID, QUIC_ERR_PROTOCOL_VIOLATION }, | |
5071 | { QUIC_PKT_TYPE_HANDSHAKE, OSSL_QUIC_FRAME_TYPE_PATH_CHALLENGE, QUIC_ERR_PROTOCOL_VIOLATION }, | |
5072 | { QUIC_PKT_TYPE_HANDSHAKE, OSSL_QUIC_FRAME_TYPE_PATH_RESPONSE, QUIC_ERR_PROTOCOL_VIOLATION }, | |
5073 | { QUIC_PKT_TYPE_HANDSHAKE, OSSL_QUIC_FRAME_TYPE_CONN_CLOSE_APP, QUIC_ERR_PROTOCOL_VIOLATION }, | |
5074 | { QUIC_PKT_TYPE_HANDSHAKE, OSSL_QUIC_FRAME_TYPE_HANDSHAKE_DONE, QUIC_ERR_PROTOCOL_VIOLATION }, | |
5075 | ||
5076 | /* Client uses a zero-length CID so this is not allowed. */ | |
5077 | { QUIC_PKT_TYPE_1RTT, OSSL_QUIC_FRAME_TYPE_RETIRE_CONN_ID, QUIC_ERR_PROTOCOL_VIOLATION }, | |
5078 | }; | |
5079 | ||
5080 | static ossl_unused int test_dyn_frame_types(int idx) | |
5081 | { | |
5082 | size_t i; | |
0786483a | 5083 | char script_name[64]; |
e26dc8e3 HL |
5084 | struct script_op *s = dyn_frame_types_script; |
5085 | ||
5086 | for (i = 0; i < OSSL_NELEM(dyn_frame_types_script); ++i) | |
5087 | if (s[i].op == OPK_SET_INJECT_WORD) { | |
49a38dee | 5088 | s[i].arg1 = (size_t)forbidden_frame_types[idx].pkt_type; |
e26dc8e3 HL |
5089 | s[i].arg2 = forbidden_frame_types[idx].frame_type; |
5090 | } else if (s[i].op == OPK_C_EXPECT_CONN_CLOSE_INFO) { | |
5091 | s[i].arg2 = forbidden_frame_types[idx].expected_err; | |
5092 | } | |
5093 | ||
0786483a HL |
5094 | snprintf(script_name, sizeof(script_name), |
5095 | "dyn script %d", idx); | |
5096 | ||
5881dd2c | 5097 | return run_script(dyn_frame_types_script, script_name, 0, 0); |
e26dc8e3 HL |
5098 | } |
5099 | ||
ed835673 HL |
5100 | OPT_TEST_DECLARE_USAGE("certfile privkeyfile\n") |
5101 | ||
5102 | int setup_tests(void) | |
5103 | { | |
5104 | if (!test_skip_common_options()) { | |
5105 | TEST_error("Error parsing test options\n"); | |
5106 | return 0; | |
5107 | } | |
5108 | ||
5109 | if (!TEST_ptr(certfile = test_get_argument(0)) | |
5110 | || !TEST_ptr(keyfile = test_get_argument(1))) | |
5111 | return 0; | |
5112 | ||
e26dc8e3 | 5113 | ADD_ALL_TESTS(test_dyn_frame_types, OSSL_NELEM(forbidden_frame_types)); |
5881dd2c | 5114 | ADD_ALL_TESTS(test_script, OSSL_NELEM(scripts) * 2 * 2); |
ed835673 HL |
5115 | return 1; |
5116 | } |