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