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