]> git.ipfire.org Git - thirdparty/openssl.git/blob - test/quic_multistream_test.c
QUIC: Allow application to trigger TXKU
[thirdparty/openssl.git] / test / quic_multistream_test.c
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"
14 #include "internal/quic_ssl.h"
15 #include "testutil.h"
16 #if defined(OPENSSL_THREADS)
17 # include "internal/thread_arch.h"
18 #endif
19
20 static const char *certfile, *keyfile;
21
22 #if defined(OPENSSL_THREADS)
23 struct child_thread_args {
24 struct helper *h;
25 const struct script_op *script;
26 int thread_idx;
27
28 CRYPTO_THREAD *t;
29 CRYPTO_MUTEX *m;
30 int testresult;
31 int done;
32 };
33 #endif
34
35 typedef struct stream_info {
36 const char *name;
37 SSL *c_stream;
38 uint64_t s_stream_id;
39 } STREAM_INFO;
40
41 DEFINE_LHASH_OF_EX(STREAM_INFO);
42
43 struct helper {
44 int s_fd;
45 BIO *s_net_bio, *s_net_bio_own;
46 BIO_ADDR *s_net_bio_addr;
47 QUIC_TSERVER *s;
48 LHASH_OF(STREAM_INFO) *s_streams;
49
50 int c_fd;
51 BIO *c_net_bio, *c_net_bio_own;
52 SSL_CTX *c_ctx;
53 SSL *c_conn;
54 LHASH_OF(STREAM_INFO) *c_streams;
55
56 #if defined(OPENSSL_THREADS)
57 struct child_thread_args *threads;
58 size_t num_threads;
59 #endif
60
61 OSSL_TIME start_time;
62
63 /*
64 * This is a duration recording the amount of time we have skipped forwards
65 * for testing purposes relative to the real ossl_time_now() clock. We add
66 * a quantity of time to this every time we skip some time.
67 */
68 CRYPTO_RWLOCK *time_lock;
69 OSSL_TIME time_slip; /* protected by time_lock */
70
71 int init, blocking, check_spin_again;
72 int free_order;
73 };
74
75 struct helper_local {
76 struct helper *h;
77 LHASH_OF(STREAM_INFO) *c_streams;
78 int thread_idx;
79 };
80
81 struct script_op {
82 uint32_t op;
83 const void *arg0;
84 size_t arg1;
85 int (*check_func)(struct helper *h, const struct script_op *op);
86 const char *stream_name;
87 uint64_t arg2;
88 };
89
90 #define OPK_END 0
91 #define OPK_CHECK 1
92 #define OPK_C_SET_ALPN 2
93 #define OPK_C_CONNECT_WAIT 3
94 #define OPK_C_WRITE 4
95 #define OPK_S_WRITE 5
96 #define OPK_C_READ_EXPECT 6
97 #define OPK_S_READ_EXPECT 7
98 #define OPK_C_EXPECT_FIN 8
99 #define OPK_S_EXPECT_FIN 9
100 #define OPK_C_CONCLUDE 10
101 #define OPK_S_CONCLUDE 11
102 #define OPK_C_DETACH 12
103 #define OPK_C_ATTACH 13
104 #define OPK_C_NEW_STREAM 14
105 #define OPK_S_NEW_STREAM 15
106 #define OPK_C_ACCEPT_STREAM_WAIT 16
107 #define OPK_C_ACCEPT_STREAM_NONE 17
108 #define OPK_C_FREE_STREAM 18
109 #define OPK_C_SET_DEFAULT_STREAM_MODE 19
110 #define OPK_C_SET_INCOMING_STREAM_POLICY 20
111 #define OPK_C_SHUTDOWN 21
112 #define OPK_C_EXPECT_CONN_CLOSE_INFO 22
113 #define OPK_S_EXPECT_CONN_CLOSE_INFO 23
114 #define OPK_S_BIND_STREAM_ID 24
115 #define OPK_C_WAIT_FOR_DATA 25
116 #define OPK_C_WRITE_FAIL 26
117 #define OPK_S_WRITE_FAIL 27
118 #define OPK_C_READ_FAIL 28
119 #define OPK_C_STREAM_RESET 29
120 #define OPK_S_ACCEPT_STREAM_WAIT 30
121 #define OPK_NEW_THREAD 31
122 #define OPK_BEGIN_REPEAT 32
123 #define OPK_END_REPEAT 33
124 #define OPK_S_UNBIND_STREAM_ID 34
125
126 #define EXPECT_CONN_CLOSE_APP (1U << 0)
127 #define EXPECT_CONN_CLOSE_REMOTE (1U << 1)
128
129 #define C_BIDI_ID(ordinal) \
130 (((ordinal) << 2) | QUIC_STREAM_INITIATOR_CLIENT | QUIC_STREAM_DIR_BIDI)
131 #define S_BIDI_ID(ordinal) \
132 (((ordinal) << 2) | QUIC_STREAM_INITIATOR_SERVER | QUIC_STREAM_DIR_BIDI)
133 #define C_UNI_ID(ordinal) \
134 (((ordinal) << 2) | QUIC_STREAM_INITIATOR_CLIENT | QUIC_STREAM_DIR_UNI)
135 #define S_UNI_ID(ordinal) \
136 (((ordinal) << 2) | QUIC_STREAM_INITIATOR_SERVER | QUIC_STREAM_DIR_UNI)
137
138 #define ANY_ID UINT64_MAX
139
140 #define OP_END \
141 {OPK_END}
142 #define OP_CHECK(func, arg2) \
143 {OPK_CHECK, NULL, 0, (func), NULL, (arg2)},
144 #define OP_C_SET_ALPN(alpn) \
145 {OPK_C_SET_ALPN, (alpn), 0, NULL, NULL},
146 #define OP_C_CONNECT_WAIT() \
147 {OPK_C_CONNECT_WAIT, NULL, 0, NULL, NULL},
148 #define OP_C_WRITE(stream_name, buf, buf_len) \
149 {OPK_C_WRITE, (buf), (buf_len), NULL, #stream_name},
150 #define OP_S_WRITE(stream_name, buf, buf_len) \
151 {OPK_S_WRITE, (buf), (buf_len), NULL, #stream_name},
152 #define OP_C_READ_EXPECT(stream_name, buf, buf_len) \
153 {OPK_C_READ_EXPECT, (buf), (buf_len), NULL, #stream_name},
154 #define OP_S_READ_EXPECT(stream_name, buf, buf_len) \
155 {OPK_S_READ_EXPECT, (buf), (buf_len), NULL, #stream_name},
156 #define OP_C_EXPECT_FIN(stream_name) \
157 {OPK_C_EXPECT_FIN, NULL, 0, NULL, #stream_name},
158 #define OP_S_EXPECT_FIN(stream_name) \
159 {OPK_S_EXPECT_FIN, NULL, 0, NULL, #stream_name},
160 #define OP_C_CONCLUDE(stream_name) \
161 {OPK_C_CONCLUDE, NULL, 0, NULL, #stream_name},
162 #define OP_S_CONCLUDE(stream_name) \
163 {OPK_S_CONCLUDE, NULL, 0, NULL, #stream_name},
164 #define OP_C_DETACH(stream_name) \
165 {OPK_C_DETACH, NULL, 0, NULL, #stream_name},
166 #define OP_C_ATTACH(stream_name) \
167 {OPK_C_ATTACH, NULL, 0, NULL, #stream_name},
168 #define OP_C_NEW_STREAM_BIDI(stream_name, expect_id) \
169 {OPK_C_NEW_STREAM, NULL, 0, NULL, #stream_name, (expect_id)},
170 #define OP_C_NEW_STREAM_UNI(stream_name, expect_id) \
171 {OPK_C_NEW_STREAM, NULL, 1, NULL, #stream_name, (expect_id)},
172 #define OP_S_NEW_STREAM_BIDI(stream_name, expect_id) \
173 {OPK_S_NEW_STREAM, NULL, 0, NULL, #stream_name, (expect_id)},
174 #define OP_S_NEW_STREAM_UNI(stream_name, expect_id) \
175 {OPK_S_NEW_STREAM, NULL, 1, NULL, #stream_name, (expect_id)},
176 #define OP_C_ACCEPT_STREAM_WAIT(stream_name) \
177 {OPK_C_ACCEPT_STREAM_WAIT, NULL, 0, NULL, #stream_name},
178 #define OP_C_ACCEPT_STREAM_NONE() \
179 {OPK_C_ACCEPT_STREAM_NONE, NULL, 0, NULL, NULL},
180 #define OP_C_FREE_STREAM(stream_name) \
181 {OPK_C_FREE_STREAM, NULL, 0, NULL, #stream_name},
182 #define OP_C_SET_DEFAULT_STREAM_MODE(mode) \
183 {OPK_C_SET_DEFAULT_STREAM_MODE, NULL, (mode), NULL, NULL},
184 #define OP_C_SET_INCOMING_STREAM_POLICY(policy) \
185 {OPK_C_SET_INCOMING_STREAM_POLICY, NULL, (policy), NULL, NULL},
186 #define OP_C_SHUTDOWN() \
187 {OPK_C_SHUTDOWN, NULL, 0, NULL, NULL},
188 #define OP_C_EXPECT_CONN_CLOSE_INFO(ec, app, remote) \
189 {OPK_C_EXPECT_CONN_CLOSE_INFO, NULL, \
190 ((app) ? EXPECT_CONN_CLOSE_APP : 0) | \
191 ((remote) ? EXPECT_CONN_CLOSE_REMOTE : 0), \
192 NULL, NULL, (ec)},
193 #define OP_S_EXPECT_CONN_CLOSE_INFO(ec, app, remote) \
194 {OPK_S_EXPECT_CONN_CLOSE_INFO, NULL, \
195 ((app) ? EXPECT_CONN_CLOSE_APP : 0) | \
196 ((remote) ? EXPECT_CONN_CLOSE_REMOTE : 0), \
197 NULL, NULL, (ec)},
198 #define OP_S_BIND_STREAM_ID(stream_name, stream_id) \
199 {OPK_S_BIND_STREAM_ID, NULL, 0, NULL, #stream_name, (stream_id)},
200 #define OP_C_WAIT_FOR_DATA(stream_name) \
201 {OPK_C_WAIT_FOR_DATA, NULL, 0, NULL, #stream_name},
202 #define OP_C_WRITE_FAIL(stream_name) \
203 {OPK_C_WRITE_FAIL, NULL, 0, NULL, #stream_name},
204 #define OP_S_WRITE_FAIL(stream_name) \
205 {OPK_S_WRITE_FAIL, NULL, 0, NULL, #stream_name},
206 #define OP_C_READ_FAIL(stream_name) \
207 {OPK_C_READ_FAIL, NULL, 0, NULL, #stream_name},
208 #define OP_C_STREAM_RESET(stream_name, aec) \
209 {OPK_C_STREAM_RESET, NULL, 0, NULL, #stream_name, (aec)},
210 #define OP_S_ACCEPT_STREAM_WAIT(stream_name) \
211 {OPK_S_ACCEPT_STREAM_WAIT, NULL, 0, NULL, #stream_name},
212 #define OP_NEW_THREAD(num_threads, script) \
213 {OPK_NEW_THREAD, (script), (num_threads), NULL, NULL, 0 },
214 #define OP_BEGIN_REPEAT(n) \
215 {OPK_BEGIN_REPEAT, NULL, (n)},
216 #define OP_END_REPEAT() \
217 {OPK_END_REPEAT},
218 #define OP_S_UNBIND_STREAM_ID(stream_name) \
219 {OPK_S_UNBIND_STREAM_ID, NULL, 0, NULL, #stream_name},
220
221 static OSSL_TIME get_time(void *arg)
222 {
223 struct helper *h = arg;
224 OSSL_TIME t;
225
226 if (!TEST_true(CRYPTO_THREAD_read_lock(h->time_lock)))
227 return ossl_time_zero();
228
229 t = ossl_time_add(ossl_time_now(), h->time_slip);
230
231 CRYPTO_THREAD_unlock(h->time_lock);
232 return t;
233 }
234
235 static int skip_time_ms(struct helper *h, const struct script_op *op)
236 {
237 if (!TEST_true(CRYPTO_THREAD_write_lock(h->time_lock)))
238 return 0;
239
240 h->time_slip = ossl_time_add(h->time_slip, ossl_ms2time(op->arg2));
241
242 CRYPTO_THREAD_unlock(h->time_lock);
243 return 1;
244 }
245
246 static int check_rejected(struct helper *h, const struct script_op *op)
247 {
248 uint64_t stream_id = op->arg2;
249
250 if (!ossl_quic_tserver_stream_has_peer_stop_sending(h->s, stream_id, NULL)
251 || !ossl_quic_tserver_stream_has_peer_reset_stream(h->s, stream_id, NULL)) {
252 h->check_spin_again = 1;
253 return 0;
254 }
255
256 return 1;
257 }
258
259 static int check_stream_reset(struct helper *h, const struct script_op *op)
260 {
261 uint64_t stream_id = op->arg2, aec = 0;
262
263 if (!ossl_quic_tserver_stream_has_peer_reset_stream(h->s, stream_id, &aec)) {
264 h->check_spin_again = 1;
265 return 0;
266 }
267
268 return TEST_uint64_t_eq(aec, 42);
269 }
270
271 static int check_stream_stopped(struct helper *h, const struct script_op *op)
272 {
273 uint64_t stream_id = op->arg2;
274
275 if (!ossl_quic_tserver_stream_has_peer_stop_sending(h->s, stream_id, NULL)) {
276 h->check_spin_again = 1;
277 return 0;
278 }
279
280 return 1;
281 }
282
283 static int override_key_update(struct helper *h, const struct script_op *op)
284 {
285 QUIC_CHANNEL *ch = ossl_quic_conn_get_channel(h->c_conn);
286
287 ossl_quic_channel_set_txku_threshold_override(ch, op->arg2);
288 return 1;
289 }
290
291 static int trigger_key_update(struct helper *h, const struct script_op *op)
292 {
293 if (!TEST_true(SSL_key_update(h->c_conn, SSL_KEY_UPDATE_REQUESTED)))
294 return 0;
295
296 return 1;
297 }
298
299 static int check_key_update_ge(struct helper *h, const struct script_op *op)
300 {
301 QUIC_CHANNEL *ch = ossl_quic_conn_get_channel(h->c_conn);
302 int64_t txke = (int64_t)ossl_quic_channel_get_tx_key_epoch(ch);
303 int64_t rxke = (int64_t)ossl_quic_channel_get_rx_key_epoch(ch);
304 int64_t diff = txke - rxke;
305
306 /*
307 * TXKE must always be equal to or ahead of RXKE.
308 * It can be ahead of RXKE by at most 1.
309 */
310 if (!TEST_int64_t_ge(diff, 0) || !TEST_int64_t_le(diff, 1))
311 return 0;
312
313 /* Caller specifies a minimum number of RXKEs which must have happened. */
314 if (!TEST_uint64_t_ge((uint64_t)rxke, op->arg2))
315 return 0;
316
317 return 1;
318 }
319
320 static int check_key_update_lt(struct helper *h, const struct script_op *op)
321 {
322 QUIC_CHANNEL *ch = ossl_quic_conn_get_channel(h->c_conn);
323 uint64_t txke = ossl_quic_channel_get_tx_key_epoch(ch);
324
325 /* Caller specifies a maximum number of TXKEs which must have happened. */
326 if (!TEST_uint64_t_lt(txke, op->arg2))
327 return 0;
328
329 return 1;
330 }
331
332 static unsigned long stream_info_hash(const STREAM_INFO *info)
333 {
334 return OPENSSL_LH_strhash(info->name);
335 }
336
337 static int stream_info_cmp(const STREAM_INFO *a, const STREAM_INFO *b)
338 {
339 return strcmp(a->name, b->name);
340 }
341
342 static void cleanup_stream(STREAM_INFO *info)
343 {
344 SSL_free(info->c_stream);
345 OPENSSL_free(info);
346 }
347
348 static void helper_cleanup_streams(LHASH_OF(STREAM_INFO) **lh)
349 {
350 if (*lh == NULL)
351 return;
352
353 lh_STREAM_INFO_doall(*lh, cleanup_stream);
354 lh_STREAM_INFO_free(*lh);
355 *lh = NULL;
356 }
357
358 #if defined(OPENSSL_THREADS)
359 static CRYPTO_THREAD_RETVAL run_script_child_thread(void *arg);
360
361 static int join_threads(struct child_thread_args *threads, size_t num_threads)
362 {
363 int ok = 1;
364 size_t i;
365 CRYPTO_THREAD_RETVAL rv;
366
367 for (i = 0; i < num_threads; ++i) {
368 if (threads[i].t != NULL) {
369 ossl_crypto_thread_native_join(threads[i].t, &rv);
370
371 if (!threads[i].testresult)
372 /* Do not log failure here, worker will do it. */
373 ok = 0;
374
375 ossl_crypto_thread_native_clean(threads[i].t);
376 threads[i].t = NULL;
377 }
378
379 ossl_crypto_mutex_free(&threads[i].m);
380 }
381
382 return ok;
383 }
384 #endif
385
386 static void helper_cleanup(struct helper *h)
387 {
388 #if defined(OPENSSL_THREADS)
389 join_threads(h->threads, h->num_threads);
390 OPENSSL_free(h->threads);
391 h->threads = NULL;
392 h->num_threads = 0;
393 #endif
394
395 if (h->free_order == 0) {
396 /* order 0: streams, then conn */
397 helper_cleanup_streams(&h->c_streams);
398
399 SSL_free(h->c_conn);
400 h->c_conn = NULL;
401 } else {
402 /* order 1: conn, then streams */
403 SSL_free(h->c_conn);
404 h->c_conn = NULL;
405
406 helper_cleanup_streams(&h->c_streams);
407 }
408
409 helper_cleanup_streams(&h->s_streams);
410 ossl_quic_tserver_free(h->s);
411 h->s = NULL;
412
413 BIO_free(h->s_net_bio_own);
414 h->s_net_bio_own = NULL;
415
416 BIO_free(h->c_net_bio_own);
417 h->c_net_bio_own = NULL;
418
419 if (h->s_fd >= 0) {
420 BIO_closesocket(h->s_fd);
421 h->s_fd = -1;
422 }
423
424 if (h->c_fd >= 0) {
425 BIO_closesocket(h->c_fd);
426 h->c_fd = -1;
427 }
428
429 BIO_ADDR_free(h->s_net_bio_addr);
430 h->s_net_bio_addr = NULL;
431
432 SSL_CTX_free(h->c_ctx);
433 h->c_ctx = NULL;
434
435 CRYPTO_THREAD_lock_free(h->time_lock);
436 h->time_lock = NULL;
437 }
438
439 static int helper_init(struct helper *h, int free_order)
440 {
441 short port = 8186;
442 struct in_addr ina = {0};
443 QUIC_TSERVER_ARGS s_args = {0};
444
445 memset(h, 0, sizeof(*h));
446 h->c_fd = -1;
447 h->s_fd = -1;
448 h->free_order = free_order;
449 h->time_slip = ossl_time_zero();
450
451 if (!TEST_ptr(h->time_lock = CRYPTO_THREAD_lock_new()))
452 goto err;
453
454 if (!TEST_ptr(h->s_streams = lh_STREAM_INFO_new(stream_info_hash,
455 stream_info_cmp)))
456 goto err;
457
458 if (!TEST_ptr(h->c_streams = lh_STREAM_INFO_new(stream_info_hash,
459 stream_info_cmp)))
460 goto err;
461
462 ina.s_addr = htonl(0x7f000001UL);
463
464 h->s_fd = BIO_socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP, 0);
465 if (!TEST_int_ge(h->s_fd, 0))
466 goto err;
467
468 if (!TEST_true(BIO_socket_nbio(h->s_fd, 1)))
469 goto err;
470
471 if (!TEST_ptr(h->s_net_bio_addr = BIO_ADDR_new()))
472 goto err;
473
474 if (!TEST_true(BIO_ADDR_rawmake(h->s_net_bio_addr, AF_INET, &ina, sizeof(ina),
475 htons(port))))
476 goto err;
477
478 if (!TEST_true(BIO_bind(h->s_fd, h->s_net_bio_addr, 0)))
479 goto err;
480
481 if (!TEST_int_gt(BIO_ADDR_rawport(h->s_net_bio_addr), 0))
482 goto err;
483
484 if (!TEST_ptr(h->s_net_bio = h->s_net_bio_own = BIO_new_dgram(h->s_fd, 0)))
485 goto err;
486
487 if (!BIO_up_ref(h->s_net_bio))
488 goto err;
489
490 s_args.net_rbio = h->s_net_bio;
491 s_args.net_wbio = h->s_net_bio;
492 s_args.now_cb = get_time;
493 s_args.now_cb_arg = h;
494
495 if (!TEST_ptr(h->s = ossl_quic_tserver_new(&s_args, certfile, keyfile)))
496 goto err;
497
498 h->s_net_bio_own = NULL;
499
500 h->c_fd = BIO_socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP, 0);
501 if (!TEST_int_ge(h->c_fd, 0))
502 goto err;
503
504 if (!TEST_true(BIO_socket_nbio(h->c_fd, 1)))
505 goto err;
506
507 if (!TEST_ptr(h->c_net_bio = h->c_net_bio_own = BIO_new_dgram(h->c_fd, 0)))
508 goto err;
509
510 if (!TEST_true(BIO_dgram_set_peer(h->c_net_bio, h->s_net_bio_addr)))
511 goto err;
512
513
514 if (!TEST_ptr(h->c_ctx = SSL_CTX_new(OSSL_QUIC_client_method())))
515 goto err;
516
517 if (!TEST_ptr(h->c_conn = SSL_new(h->c_ctx)))
518 goto err;
519
520 /* Use custom time function for virtual time skip. */
521 if (!TEST_true(ossl_quic_conn_set_override_now_cb(h->c_conn, get_time, h)))
522 goto err;
523
524 /* Takes ownership of our reference to the BIO. */
525 SSL_set0_rbio(h->c_conn, h->c_net_bio);
526 h->c_net_bio_own = NULL;
527
528 if (!TEST_true(BIO_up_ref(h->c_net_bio)))
529 goto err;
530
531 SSL_set0_wbio(h->c_conn, h->c_net_bio);
532
533 if (!TEST_true(SSL_set_blocking_mode(h->c_conn, 0)))
534 goto err;
535
536 h->start_time = ossl_time_now();
537 h->init = 1;
538 return 1;
539
540 err:
541 helper_cleanup(h);
542 return 0;
543 }
544
545 static int helper_local_init(struct helper_local *hl, struct helper *h,
546 int thread_idx)
547 {
548 hl->h = h;
549 hl->c_streams = NULL;
550 hl->thread_idx = thread_idx;
551
552 if (!TEST_ptr(h))
553 return 0;
554
555 if (thread_idx < 0) {
556 hl->c_streams = h->c_streams;
557 } else {
558 if (!TEST_ptr(hl->c_streams = lh_STREAM_INFO_new(stream_info_hash,
559 stream_info_cmp)))
560 return 0;
561 }
562
563 return 1;
564 }
565
566 static void helper_local_cleanup(struct helper_local *hl)
567 {
568 if (hl->h == NULL)
569 return;
570
571 if (hl->thread_idx >= 0)
572 helper_cleanup_streams(&hl->c_streams);
573
574 hl->h = NULL;
575 }
576
577 static STREAM_INFO *get_stream_info(LHASH_OF(STREAM_INFO) *lh,
578 const char *stream_name)
579 {
580 STREAM_INFO key, *info;
581
582 if (!TEST_ptr(stream_name))
583 return NULL;
584
585 if (!strcmp(stream_name, "DEFAULT"))
586 return NULL;
587
588 key.name = stream_name;
589 info = lh_STREAM_INFO_retrieve(lh, &key);
590 if (info == NULL) {
591 info = OPENSSL_zalloc(sizeof(*info));
592 if (info == NULL)
593 return NULL;
594
595 info->name = stream_name;
596 info->s_stream_id = UINT64_MAX;
597 lh_STREAM_INFO_insert(lh, info);
598 }
599
600 return info;
601 }
602
603 static int helper_local_set_c_stream(struct helper_local *hl,
604 const char *stream_name,
605 SSL *c_stream)
606 {
607 STREAM_INFO *info = get_stream_info(hl->c_streams, stream_name);
608
609 if (info == NULL)
610 return 0;
611
612 info->c_stream = c_stream;
613 info->s_stream_id = UINT64_MAX;
614 return 1;
615 }
616
617 static SSL *helper_local_get_c_stream(struct helper_local *hl,
618 const char *stream_name)
619 {
620 STREAM_INFO *info;
621
622 if (!strcmp(stream_name, "DEFAULT"))
623 return hl->h->c_conn;
624
625 info = get_stream_info(hl->c_streams, stream_name);
626 if (info == NULL)
627 return NULL;
628
629 return info->c_stream;
630 }
631
632 static int
633 helper_set_s_stream(struct helper *h, const char *stream_name,
634 uint64_t s_stream_id)
635 {
636 STREAM_INFO *info;
637
638 if (!strcmp(stream_name, "DEFAULT"))
639 return 0;
640
641 info = get_stream_info(h->s_streams, stream_name);
642 if (info == NULL)
643 return 0;
644
645 info->c_stream = NULL;
646 info->s_stream_id = s_stream_id;
647 return 1;
648 }
649
650 static uint64_t helper_get_s_stream(struct helper *h, const char *stream_name)
651 {
652 STREAM_INFO *info;
653
654 if (!strcmp(stream_name, "DEFAULT"))
655 return UINT64_MAX;
656
657 info = get_stream_info(h->s_streams, stream_name);
658 if (info == NULL)
659 return UINT64_MAX;
660
661 return info->s_stream_id;
662 }
663
664 static int is_want(SSL *s, int ret)
665 {
666 int ec = SSL_get_error(s, ret);
667
668 return ec == SSL_ERROR_WANT_READ || ec == SSL_ERROR_WANT_WRITE;
669 }
670
671 static int run_script_worker(struct helper *h, const struct script_op *script,
672 int thread_idx)
673 {
674 int testresult = 0;
675 unsigned char *tmp_buf = NULL;
676 int connect_started = 0;
677 size_t offset = 0;
678 size_t op_idx = 0;
679 const struct script_op *op = NULL;
680 int no_advance = 0, first = 1;
681 #if defined(OPENSSL_THREADS)
682 int end_wait_warning = 0;
683 #endif
684 OSSL_TIME op_start_time = ossl_time_zero(), op_deadline = ossl_time_zero();
685 struct helper_local hl;
686 #define REPEAT_SLOTS 8
687 size_t repeat_stack_idx[REPEAT_SLOTS], repeat_stack_done[REPEAT_SLOTS];
688 size_t repeat_stack_limit[REPEAT_SLOTS];
689 size_t repeat_stack_len = 0;
690
691 if (!TEST_true(helper_local_init(&hl, h, thread_idx)))
692 goto out;
693
694 #define SPIN_AGAIN() { OSSL_sleep(1); no_advance = 1; continue; }
695
696 for (;;) {
697 SSL *c_tgt = h->c_conn;
698 uint64_t s_stream_id = UINT64_MAX;
699
700 if (no_advance) {
701 no_advance = 0;
702 } else {
703 if (!first)
704 ++op_idx;
705
706 first = 0;
707 offset = 0;
708 op_start_time = ossl_time_now();
709 op_deadline = ossl_time_add(op_start_time, ossl_ms2time(2000));
710 }
711
712 if (!TEST_int_le(ossl_time_compare(ossl_time_now(), op_deadline), 0)) {
713 TEST_error("op %zu timed out on thread %d", op_idx + 1, thread_idx);
714 goto out;
715 }
716
717 op = &script[op_idx];
718
719 if (op->stream_name != NULL) {
720 c_tgt = helper_local_get_c_stream(&hl, op->stream_name);
721 if (thread_idx < 0)
722 s_stream_id = helper_get_s_stream(h, op->stream_name);
723 else
724 s_stream_id = UINT64_MAX;
725 }
726
727 if (thread_idx < 0)
728 ossl_quic_tserver_tick(h->s);
729
730 if (thread_idx >= 0 || connect_started)
731 SSL_handle_events(h->c_conn);
732
733 if (thread_idx >= 0) {
734 /* Only allow certain opcodes on child threads. */
735 switch (op->op) {
736 case OPK_END:
737 case OPK_C_ACCEPT_STREAM_WAIT:
738 case OPK_C_NEW_STREAM:
739 case OPK_C_READ_EXPECT:
740 case OPK_C_EXPECT_FIN:
741 case OPK_C_WRITE:
742 case OPK_C_CONCLUDE:
743 case OPK_C_FREE_STREAM:
744 case OPK_BEGIN_REPEAT:
745 case OPK_END_REPEAT:
746 break;
747
748 default:
749 TEST_error("opcode %d not allowed on child thread", op->op);
750 goto out;
751 }
752 }
753
754 switch (op->op) {
755 case OPK_END:
756 if (!TEST_size_t_eq(repeat_stack_len, 0))
757 goto out;
758
759 #if defined(OPENSSL_THREADS)
760 if (thread_idx < 0) {
761 int done;
762 size_t i;
763
764 for (i = 0; i < h->num_threads; ++i) {
765 if (h->threads[i].m == NULL)
766 continue;
767
768 ossl_crypto_mutex_lock(h->threads[i].m);
769 done = h->threads[i].done;
770 ossl_crypto_mutex_unlock(h->threads[i].m);
771
772 if (!done) {
773 if (!end_wait_warning) {
774 TEST_info("still waiting for other threads to finish (%zu)", i);
775 end_wait_warning = 1;
776 }
777
778 SPIN_AGAIN();
779 }
780 }
781 }
782 #endif
783
784 TEST_info("script finished on thread %d", thread_idx);
785 testresult = 1;
786 goto out;
787
788 case OPK_BEGIN_REPEAT:
789 if (!TEST_size_t_lt(repeat_stack_len, OSSL_NELEM(repeat_stack_idx)))
790 goto out;
791
792 if (!TEST_size_t_gt(op->arg1, 0))
793 goto out;
794
795 repeat_stack_idx[repeat_stack_len] = op_idx + 1;
796 repeat_stack_done[repeat_stack_len] = 0;
797 repeat_stack_limit[repeat_stack_len] = op->arg1;
798 ++repeat_stack_len;
799 break;
800
801 case OPK_END_REPEAT:
802 if (!TEST_size_t_gt(repeat_stack_len, 0))
803 goto out;
804
805 if (++repeat_stack_done[repeat_stack_len - 1]
806 == repeat_stack_limit[repeat_stack_len - 1]) {
807 --repeat_stack_len;
808 } else {
809 op_idx = repeat_stack_idx[repeat_stack_len - 1];
810 no_advance = 1;
811 continue;
812 }
813
814 break;
815
816 case OPK_CHECK:
817 {
818 int ok = op->check_func(h, op);
819 if (h->check_spin_again) {
820 h->check_spin_again = 0;
821 SPIN_AGAIN();
822 }
823
824 if (!TEST_true(ok))
825 goto out;
826 }
827 break;
828
829 case OPK_C_SET_ALPN:
830 {
831 const char *alpn = op->arg0;
832 size_t alpn_len = strlen(alpn);
833
834 if (!TEST_size_t_le(alpn_len, UINT8_MAX)
835 || !TEST_ptr(tmp_buf = (unsigned char *)OPENSSL_malloc(alpn_len + 1)))
836 goto out;
837
838 memcpy(tmp_buf + 1, alpn, alpn_len);
839 tmp_buf[0] = (unsigned char)alpn_len;
840
841 /* 0 is the success case for SSL_set_alpn_protos(). */
842 if (!TEST_false(SSL_set_alpn_protos(h->c_conn, tmp_buf,
843 alpn_len + 1)))
844 goto out;
845
846 OPENSSL_free(tmp_buf);
847 tmp_buf = NULL;
848 }
849 break;
850
851 case OPK_C_CONNECT_WAIT:
852 {
853 int ret;
854
855 connect_started = 1;
856
857 ret = SSL_connect(h->c_conn);
858 if (!TEST_true(ret == 1
859 || (!h->blocking && is_want(h->c_conn, ret))))
860 goto out;
861
862 if (!h->blocking && ret != 1)
863 SPIN_AGAIN();
864 }
865 break;
866
867 case OPK_C_WRITE:
868 {
869 size_t bytes_written = 0;
870
871 if (!TEST_ptr(c_tgt))
872 goto out;
873
874 if (!TEST_true(SSL_write_ex(c_tgt, op->arg0, op->arg1,
875 &bytes_written))
876 || !TEST_size_t_eq(bytes_written, op->arg1))
877 goto out;
878 }
879 break;
880
881 case OPK_S_WRITE:
882 {
883 size_t bytes_written = 0;
884
885 if (!TEST_uint64_t_ne(s_stream_id, UINT64_MAX))
886 goto out;
887
888 if (!TEST_true(ossl_quic_tserver_write(h->s, s_stream_id,
889 op->arg0, op->arg1,
890 &bytes_written))
891 || !TEST_size_t_eq(bytes_written, op->arg1))
892 goto out;
893 }
894 break;
895
896 case OPK_C_CONCLUDE:
897 {
898 if (!TEST_true(SSL_stream_conclude(c_tgt, 0)))
899 goto out;
900 }
901 break;
902
903 case OPK_S_CONCLUDE:
904 {
905 if (!TEST_uint64_t_ne(s_stream_id, UINT64_MAX))
906 goto out;
907
908 ossl_quic_tserver_conclude(h->s, s_stream_id);
909 }
910 break;
911
912 case OPK_C_WAIT_FOR_DATA:
913 {
914 char buf[1];
915 size_t bytes_read = 0;
916
917 if (!TEST_ptr(c_tgt))
918 goto out;
919
920 if (!SSL_peek_ex(c_tgt, buf, sizeof(buf), &bytes_read)
921 || bytes_read == 0)
922 SPIN_AGAIN();
923 }
924 break;
925
926 case OPK_C_READ_EXPECT:
927 {
928 size_t bytes_read = 0;
929
930 if (op->arg1 > 0 && tmp_buf == NULL
931 && !TEST_ptr(tmp_buf = OPENSSL_malloc(op->arg1)))
932 goto out;
933
934 if (!SSL_read_ex(c_tgt, tmp_buf + offset, op->arg1 - offset,
935 &bytes_read))
936 SPIN_AGAIN();
937
938 if (bytes_read + offset != op->arg1) {
939 offset += bytes_read;
940 SPIN_AGAIN();
941 }
942
943 if (op->arg1 > 0
944 && !TEST_mem_eq(tmp_buf, op->arg1, op->arg0, op->arg1))
945 goto out;
946
947 OPENSSL_free(tmp_buf);
948 tmp_buf = NULL;
949 }
950 break;
951
952 case OPK_S_READ_EXPECT:
953 {
954 size_t bytes_read = 0;
955
956 if (!TEST_uint64_t_ne(s_stream_id, UINT64_MAX))
957 goto out;
958
959 if (op->arg1 > 0 && tmp_buf == NULL
960 && !TEST_ptr(tmp_buf = OPENSSL_malloc(op->arg1)))
961 goto out;
962
963 if (!TEST_true(ossl_quic_tserver_read(h->s, s_stream_id,
964 tmp_buf + offset,
965 op->arg1 - offset,
966 &bytes_read)))
967 goto out;
968
969 if (bytes_read + offset != op->arg1) {
970 offset += bytes_read;
971 SPIN_AGAIN();
972 }
973
974 if (op->arg1 > 0
975 && !TEST_mem_eq(tmp_buf, op->arg1, op->arg0, op->arg1))
976 goto out;
977
978 OPENSSL_free(tmp_buf);
979 tmp_buf = NULL;
980 }
981 break;
982
983 case OPK_C_EXPECT_FIN:
984 {
985 char buf[1];
986 size_t bytes_read = 0;
987
988 if (!TEST_false(SSL_read_ex(c_tgt, buf, sizeof(buf),
989 &bytes_read))
990 || !TEST_size_t_eq(bytes_read, 0))
991 goto out;
992
993 if (is_want(c_tgt, 0))
994 SPIN_AGAIN();
995
996 if (!TEST_int_eq(SSL_get_error(c_tgt, 0),
997 SSL_ERROR_ZERO_RETURN))
998 goto out;
999 }
1000 break;
1001
1002 case OPK_S_EXPECT_FIN:
1003 {
1004 if (!TEST_uint64_t_ne(s_stream_id, UINT64_MAX))
1005 goto out;
1006
1007 if (!ossl_quic_tserver_has_read_ended(h->s, s_stream_id))
1008 SPIN_AGAIN();
1009 }
1010 break;
1011
1012 case OPK_C_DETACH:
1013 {
1014 SSL *c_stream;
1015
1016 if (!TEST_ptr_null(c_tgt))
1017 goto out; /* don't overwrite existing stream with same name */
1018
1019 if (!TEST_ptr(c_stream = ossl_quic_detach_stream(h->c_conn)))
1020 goto out;
1021
1022 if (!TEST_true(helper_local_set_c_stream(&hl, op->stream_name, c_stream)))
1023 goto out;
1024 }
1025 break;
1026
1027 case OPK_C_ATTACH:
1028 {
1029 if (!TEST_ptr(c_tgt))
1030 goto out;
1031
1032 if (!TEST_true(ossl_quic_attach_stream(h->c_conn, c_tgt)))
1033 goto out;
1034
1035 if (!TEST_true(helper_local_set_c_stream(&hl, op->stream_name, NULL)))
1036 goto out;
1037 }
1038 break;
1039
1040 case OPK_C_NEW_STREAM:
1041 {
1042 SSL *c_stream;
1043 uint64_t flags = 0;
1044
1045 if (!TEST_ptr_null(c_tgt))
1046 goto out; /* don't overwrite existing stream with same name */
1047
1048 if (op->arg1 != 0)
1049 flags |= SSL_STREAM_FLAG_UNI;
1050
1051 if (!TEST_ptr(c_stream = SSL_new_stream(h->c_conn, flags)))
1052 goto out;
1053
1054 if (op->arg2 != UINT64_MAX
1055 && !TEST_uint64_t_eq(SSL_get_stream_id(c_stream),
1056 op->arg2))
1057 goto out;
1058
1059 if (!TEST_true(helper_local_set_c_stream(&hl, op->stream_name, c_stream)))
1060 goto out;
1061 }
1062 break;
1063
1064 case OPK_S_NEW_STREAM:
1065 {
1066 uint64_t stream_id = UINT64_MAX;
1067
1068 if (!TEST_uint64_t_eq(s_stream_id, UINT64_MAX))
1069 goto out; /* don't overwrite existing stream with same name */
1070
1071 if (!TEST_true(ossl_quic_tserver_stream_new(h->s,
1072 op->arg1 > 0,
1073 &stream_id)))
1074 goto out;
1075
1076 if (op->arg2 != UINT64_MAX
1077 && !TEST_uint64_t_eq(stream_id, op->arg2))
1078 goto out;
1079
1080 if (!TEST_true(helper_set_s_stream(h, op->stream_name,
1081 stream_id)))
1082 goto out;
1083 }
1084 break;
1085
1086 case OPK_C_ACCEPT_STREAM_WAIT:
1087 {
1088 SSL *c_stream;
1089
1090 if (!TEST_ptr_null(c_tgt))
1091 goto out; /* don't overwrite existing stream with same name */
1092
1093 if ((c_stream = SSL_accept_stream(h->c_conn, 0)) == NULL)
1094 SPIN_AGAIN();
1095
1096 if (!TEST_true(helper_local_set_c_stream(&hl, op->stream_name,
1097 c_stream)))
1098 goto out;
1099 }
1100 break;
1101
1102 case OPK_S_ACCEPT_STREAM_WAIT:
1103 {
1104 uint64_t new_stream_id;
1105
1106 if (!TEST_uint64_t_eq(s_stream_id, UINT64_MAX))
1107 goto out;
1108
1109 new_stream_id = ossl_quic_tserver_pop_incoming_stream(h->s);
1110 if (new_stream_id == UINT64_MAX)
1111 SPIN_AGAIN();
1112
1113 if (!TEST_true(helper_set_s_stream(h, op->stream_name, new_stream_id)))
1114 goto out;
1115 }
1116 break;
1117
1118 case OPK_C_ACCEPT_STREAM_NONE:
1119 {
1120 SSL *c_stream;
1121
1122 if (!TEST_ptr_null(c_stream = SSL_accept_stream(h->c_conn, 0))) {
1123 SSL_free(c_stream);
1124 goto out;
1125 }
1126 }
1127 break;
1128
1129 case OPK_C_FREE_STREAM:
1130 {
1131 if (!TEST_ptr(c_tgt)
1132 || !TEST_true(!SSL_is_connection(c_tgt)))
1133 goto out;
1134
1135 if (!TEST_true(helper_local_set_c_stream(&hl, op->stream_name, NULL)))
1136 goto out;
1137
1138 SSL_free(c_tgt);
1139 c_tgt = NULL;
1140 }
1141 break;
1142
1143 case OPK_C_SET_DEFAULT_STREAM_MODE:
1144 {
1145 if (!TEST_ptr(c_tgt))
1146 goto out;
1147
1148 if (!TEST_true(SSL_set_default_stream_mode(c_tgt, op->arg1)))
1149 goto out;
1150 }
1151 break;
1152
1153 case OPK_C_SET_INCOMING_STREAM_POLICY:
1154 {
1155 if (!TEST_ptr(c_tgt))
1156 goto out;
1157
1158 if (!TEST_true(SSL_set_incoming_stream_policy(c_tgt,
1159 op->arg1, 0)))
1160 goto out;
1161 }
1162 break;
1163
1164 case OPK_C_SHUTDOWN:
1165 {
1166 int ret;
1167
1168 if (!TEST_ptr(c_tgt))
1169 goto out;
1170
1171 ret = SSL_shutdown_ex(c_tgt, 0, NULL, 0);
1172 if (!TEST_int_ge(ret, 0))
1173 goto out;
1174
1175 }
1176 break;
1177
1178 case OPK_C_EXPECT_CONN_CLOSE_INFO:
1179 {
1180 SSL_CONN_CLOSE_INFO cc_info = {0};
1181 int expect_app = (op->arg1 & EXPECT_CONN_CLOSE_APP) != 0;
1182 int expect_remote = (op->arg1 & EXPECT_CONN_CLOSE_REMOTE) != 0;
1183 uint64_t error_code = op->arg2;
1184
1185 if (!TEST_ptr(c_tgt))
1186 goto out;
1187
1188 if (!SSL_get_conn_close_info(c_tgt, &cc_info, sizeof(cc_info)))
1189 SPIN_AGAIN();
1190
1191 if (!TEST_int_eq(expect_app, !cc_info.is_transport)
1192 || !TEST_int_eq(expect_remote, !cc_info.is_local)
1193 || !TEST_uint64_t_eq(error_code, cc_info.error_code))
1194 goto out;
1195 }
1196 break;
1197
1198 case OPK_S_EXPECT_CONN_CLOSE_INFO:
1199 {
1200 const QUIC_TERMINATE_CAUSE *tc;
1201 int expect_app = (op->arg1 & EXPECT_CONN_CLOSE_APP) != 0;
1202 int expect_remote = (op->arg1 & EXPECT_CONN_CLOSE_REMOTE) != 0;
1203 uint64_t error_code = op->arg2;
1204
1205 if (!ossl_quic_tserver_is_term_any(h->s))
1206 SPIN_AGAIN();
1207
1208 if (!TEST_ptr(tc = ossl_quic_tserver_get_terminate_cause(h->s)))
1209 goto out;
1210
1211 if (!TEST_uint64_t_eq(error_code, tc->error_code)
1212 || !TEST_int_eq(expect_app, tc->app)
1213 || !TEST_int_eq(expect_remote, tc->remote))
1214 goto out;
1215 }
1216 break;
1217
1218 case OPK_S_BIND_STREAM_ID:
1219 {
1220 if (!TEST_uint64_t_eq(s_stream_id, UINT64_MAX))
1221 goto out;
1222
1223 if (!TEST_true(helper_set_s_stream(h, op->stream_name, op->arg2)))
1224 goto out;
1225 }
1226 break;
1227
1228 case OPK_S_UNBIND_STREAM_ID:
1229 {
1230 if (!TEST_uint64_t_ne(s_stream_id, UINT64_MAX))
1231 goto out;
1232
1233 if (!TEST_true(helper_set_s_stream(h, op->stream_name, UINT64_MAX)))
1234 goto out;
1235 }
1236 break;
1237
1238 case OPK_C_WRITE_FAIL:
1239 {
1240 size_t bytes_written = 0;
1241
1242 if (!TEST_ptr(c_tgt))
1243 goto out;
1244
1245 if (!TEST_false(SSL_write_ex(c_tgt, "apple", 5, &bytes_written)))
1246 goto out;
1247 }
1248 break;
1249
1250 case OPK_S_WRITE_FAIL:
1251 {
1252 size_t bytes_written = 0;
1253
1254 if (!TEST_uint64_t_ne(s_stream_id, UINT64_MAX))
1255 goto out;
1256
1257 if (!TEST_false(ossl_quic_tserver_write(h->s, s_stream_id,
1258 (const unsigned char *)"apple", 5,
1259 &bytes_written)))
1260 goto out;
1261 }
1262 break;
1263
1264 case OPK_C_READ_FAIL:
1265 {
1266 size_t bytes_read = 0;
1267 char buf[1];
1268
1269 if (!TEST_ptr(c_tgt))
1270 goto out;
1271
1272 if (!TEST_false(SSL_read_ex(c_tgt, buf, sizeof(buf), &bytes_read)))
1273 goto out;
1274 }
1275 break;
1276
1277 case OPK_C_STREAM_RESET:
1278 {
1279 SSL_STREAM_RESET_ARGS args = {0};
1280
1281 if (!TEST_ptr(c_tgt))
1282 goto out;
1283
1284 args.quic_error_code = op->arg2;
1285
1286 if (!TEST_true(SSL_stream_reset(c_tgt, &args, sizeof(args))))
1287 goto out;
1288 }
1289 break;
1290
1291 case OPK_NEW_THREAD:
1292 {
1293 #if !defined(OPENSSL_THREADS)
1294 /*
1295 * If this test script requires threading and we do not have
1296 * support for it, skip the rest of it.
1297 */
1298 TEST_skip("threading not supported, skipping");
1299 testresult = 1;
1300 goto out;
1301 #else
1302 size_t i;
1303
1304 if (!TEST_ptr_null(h->threads)) {
1305 TEST_error("max one NEW_THREAD operation per script");
1306 goto out;
1307 }
1308
1309 h->threads = OPENSSL_zalloc(op->arg1 * sizeof(struct child_thread_args));
1310 if (!TEST_ptr(h->threads))
1311 goto out;
1312
1313 h->num_threads = op->arg1;
1314
1315 for (i = 0; i < op->arg1; ++i) {
1316 h->threads[i].h = h;
1317 h->threads[i].script = op->arg0;
1318 h->threads[i].thread_idx = i;
1319
1320 h->threads[i].m = ossl_crypto_mutex_new();
1321 if (!TEST_ptr(h->threads[i].m))
1322 goto out;
1323
1324 h->threads[i].t
1325 = ossl_crypto_thread_native_start(run_script_child_thread,
1326 &h->threads[i], 1);
1327 if (!TEST_ptr(h->threads[i].t))
1328 goto out;
1329 }
1330 #endif
1331 }
1332 break;
1333
1334 default:
1335 TEST_error("unknown op");
1336 goto out;
1337 }
1338 }
1339
1340 out:
1341 if (!testresult) {
1342 size_t i;
1343
1344 TEST_error("failed at script op %zu, thread %d\n",
1345 op_idx + 1, thread_idx);
1346
1347 for (i = 0; i < repeat_stack_len; ++i)
1348 TEST_info("while repeating, iteration %zu of %zu, starting at script op %zu",
1349 repeat_stack_done[i],
1350 repeat_stack_limit[i],
1351 repeat_stack_idx[i]);
1352 }
1353
1354 OPENSSL_free(tmp_buf);
1355 helper_local_cleanup(&hl);
1356 return testresult;
1357 }
1358
1359 static int run_script(const struct script_op *script, int free_order)
1360 {
1361 int testresult = 0;
1362 struct helper h;
1363
1364 if (!TEST_true(helper_init(&h, free_order)))
1365 goto out;
1366
1367 if (!TEST_true(run_script_worker(&h, script, -1)))
1368 goto out;
1369
1370 #if defined(OPENSSL_THREADS)
1371 if (!TEST_true(join_threads(h.threads, h.num_threads)))
1372 goto out;
1373 #endif
1374
1375 testresult = 1;
1376 out:
1377 helper_cleanup(&h);
1378 return testresult;
1379 }
1380
1381 #if defined(OPENSSL_THREADS)
1382 static CRYPTO_THREAD_RETVAL run_script_child_thread(void *arg)
1383 {
1384 int testresult;
1385 struct child_thread_args *args = arg;
1386
1387 testresult = run_script_worker(args->h, args->script,
1388 args->thread_idx);
1389
1390 ossl_crypto_mutex_lock(args->m);
1391 args->testresult = testresult;
1392 args->done = 1;
1393 ossl_crypto_mutex_unlock(args->m);
1394 return 1;
1395 }
1396 #endif
1397
1398 /* 1. Simple single-stream test */
1399 static const struct script_op script_1[] = {
1400 OP_C_SET_ALPN ("ossltest")
1401 OP_C_CONNECT_WAIT ()
1402 OP_C_WRITE (DEFAULT, "apple", 5)
1403 OP_C_CONCLUDE (DEFAULT)
1404 OP_S_BIND_STREAM_ID (a, C_BIDI_ID(0))
1405 OP_S_READ_EXPECT (a, "apple", 5)
1406 OP_S_EXPECT_FIN (a)
1407 OP_S_WRITE (a, "orange", 6)
1408 OP_S_CONCLUDE (a)
1409 OP_C_READ_EXPECT (DEFAULT, "orange", 6)
1410 OP_C_EXPECT_FIN (DEFAULT)
1411 OP_END
1412 };
1413
1414 /* 2. Multi-stream test */
1415 static const struct script_op script_2[] = {
1416 OP_C_SET_ALPN ("ossltest")
1417 OP_C_CONNECT_WAIT ()
1418 OP_C_SET_INCOMING_STREAM_POLICY(SSL_INCOMING_STREAM_POLICY_ACCEPT)
1419 OP_C_WRITE (DEFAULT, "apple", 5)
1420 OP_S_BIND_STREAM_ID (a, C_BIDI_ID(0))
1421 OP_S_READ_EXPECT (a, "apple", 5)
1422 OP_S_WRITE (a, "orange", 6)
1423 OP_C_READ_EXPECT (DEFAULT, "orange", 6)
1424
1425 OP_C_NEW_STREAM_BIDI (b, C_BIDI_ID(1))
1426 OP_C_WRITE (b, "flamingo", 8)
1427 OP_C_CONCLUDE (b)
1428 OP_S_BIND_STREAM_ID (b, C_BIDI_ID(1))
1429 OP_S_READ_EXPECT (b, "flamingo", 8)
1430 OP_S_EXPECT_FIN (b)
1431 OP_S_WRITE (b, "gargoyle", 8)
1432 OP_S_CONCLUDE (b)
1433 OP_C_READ_EXPECT (b, "gargoyle", 8)
1434 OP_C_EXPECT_FIN (b)
1435
1436 OP_C_NEW_STREAM_UNI (c, C_UNI_ID(0))
1437 OP_C_WRITE (c, "elephant", 8)
1438 OP_C_CONCLUDE (c)
1439 OP_S_BIND_STREAM_ID (c, C_UNI_ID(0))
1440 OP_S_READ_EXPECT (c, "elephant", 8)
1441 OP_S_EXPECT_FIN (c)
1442 OP_S_WRITE_FAIL (c)
1443
1444 OP_C_ACCEPT_STREAM_NONE ()
1445
1446 OP_S_NEW_STREAM_BIDI (d, S_BIDI_ID(0))
1447 OP_S_WRITE (d, "frog", 4)
1448 OP_S_CONCLUDE (d)
1449
1450 OP_C_ACCEPT_STREAM_WAIT (d)
1451 OP_C_ACCEPT_STREAM_NONE ()
1452 OP_C_READ_EXPECT (d, "frog", 4)
1453 OP_C_EXPECT_FIN (d)
1454
1455 OP_S_NEW_STREAM_BIDI (e, S_BIDI_ID(1))
1456 OP_S_WRITE (e, "mixture", 7)
1457 OP_S_CONCLUDE (e)
1458
1459 OP_C_ACCEPT_STREAM_WAIT (e)
1460 OP_C_READ_EXPECT (e, "mixture", 7)
1461 OP_C_EXPECT_FIN (e)
1462 OP_C_WRITE (e, "ramble", 6)
1463 OP_S_READ_EXPECT (e, "ramble", 6)
1464 OP_C_CONCLUDE (e)
1465 OP_S_EXPECT_FIN (e)
1466
1467 OP_S_NEW_STREAM_UNI (f, S_UNI_ID(0))
1468 OP_S_WRITE (f, "yonder", 6)
1469 OP_S_CONCLUDE (f)
1470
1471 OP_C_ACCEPT_STREAM_WAIT (f)
1472 OP_C_ACCEPT_STREAM_NONE ()
1473 OP_C_READ_EXPECT (f, "yonder", 6)
1474 OP_C_EXPECT_FIN (f)
1475 OP_C_WRITE_FAIL (f)
1476
1477 OP_C_SET_INCOMING_STREAM_POLICY(SSL_INCOMING_STREAM_POLICY_REJECT)
1478 OP_S_NEW_STREAM_BIDI (g, S_BIDI_ID(2))
1479 OP_S_WRITE (g, "unseen", 6)
1480 OP_S_CONCLUDE (g)
1481
1482 OP_C_ACCEPT_STREAM_NONE ()
1483
1484 OP_C_SET_INCOMING_STREAM_POLICY(SSL_INCOMING_STREAM_POLICY_AUTO)
1485 OP_S_NEW_STREAM_BIDI (h, S_BIDI_ID(3))
1486 OP_S_WRITE (h, "UNSEEN", 6)
1487 OP_S_CONCLUDE (h)
1488
1489 OP_C_ACCEPT_STREAM_NONE ()
1490
1491 /*
1492 * Streams g, h should have been rejected, so server should have got
1493 * STOP_SENDING/RESET_STREAM.
1494 */
1495 OP_CHECK (check_rejected, S_BIDI_ID(2))
1496 OP_CHECK (check_rejected, S_BIDI_ID(3))
1497
1498 OP_END
1499 };
1500
1501 /* 3. Default stream detach/reattach test */
1502 static const struct script_op script_3[] = {
1503 OP_C_SET_ALPN ("ossltest")
1504 OP_C_CONNECT_WAIT ()
1505
1506 OP_C_WRITE (DEFAULT, "apple", 5)
1507 OP_C_DETACH (a) /* DEFAULT becomes stream 'a' */
1508 OP_C_WRITE_FAIL (DEFAULT)
1509
1510 OP_C_WRITE (a, "by", 2)
1511
1512 OP_S_BIND_STREAM_ID (a, C_BIDI_ID(0))
1513 OP_S_READ_EXPECT (a, "appleby", 7)
1514
1515 OP_S_WRITE (a, "hello", 5)
1516 OP_C_READ_EXPECT (a, "hello", 5)
1517
1518 OP_C_WRITE_FAIL (DEFAULT)
1519 OP_C_ATTACH (a)
1520 OP_C_WRITE (DEFAULT, "is here", 7)
1521 OP_S_READ_EXPECT (a, "is here", 7)
1522
1523 OP_C_DETACH (a)
1524 OP_C_CONCLUDE (a)
1525 OP_S_EXPECT_FIN (a)
1526
1527 OP_END
1528 };
1529
1530 /* 4. Default stream mode test */
1531 static const struct script_op script_4[] = {
1532 OP_C_SET_ALPN ("ossltest")
1533 OP_C_CONNECT_WAIT ()
1534
1535 OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE)
1536 OP_C_WRITE_FAIL (DEFAULT)
1537
1538 OP_S_NEW_STREAM_BIDI (a, S_BIDI_ID(0))
1539 OP_S_WRITE (a, "apple", 5)
1540
1541 OP_C_READ_FAIL (DEFAULT)
1542
1543 OP_C_ACCEPT_STREAM_WAIT (a)
1544 OP_C_READ_EXPECT (a, "apple", 5)
1545
1546 OP_C_ATTACH (a)
1547 OP_C_WRITE (DEFAULT, "orange", 6)
1548 OP_S_READ_EXPECT (a, "orange", 6)
1549
1550 OP_END
1551 };
1552
1553 /* 5. Test stream reset functionality */
1554 static const struct script_op script_5[] = {
1555 OP_C_SET_ALPN ("ossltest")
1556 OP_C_CONNECT_WAIT ()
1557
1558 OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE)
1559 OP_C_NEW_STREAM_BIDI (a, C_BIDI_ID(0))
1560
1561 OP_C_WRITE (a, "apple", 5)
1562 OP_C_STREAM_RESET (a, 42)
1563
1564 OP_S_BIND_STREAM_ID (a, C_BIDI_ID(0))
1565 OP_S_READ_EXPECT (a, "apple", 5)
1566 OP_CHECK (check_stream_reset, C_BIDI_ID(0))
1567
1568 OP_END
1569 };
1570
1571 /* 6. Test STOP_SENDING functionality */
1572 static const struct script_op script_6[] = {
1573 OP_C_SET_ALPN ("ossltest")
1574 OP_C_CONNECT_WAIT ()
1575
1576 OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE)
1577 OP_S_NEW_STREAM_BIDI (a, S_BIDI_ID(0))
1578 OP_S_WRITE (a, "apple", 5)
1579
1580 OP_C_ACCEPT_STREAM_WAIT (a)
1581 OP_C_FREE_STREAM (a)
1582 OP_C_ACCEPT_STREAM_NONE ()
1583
1584 OP_CHECK (check_stream_stopped, S_BIDI_ID(0))
1585
1586 OP_END
1587 };
1588
1589 /* 7. Unidirectional default stream mode test (client sends first) */
1590 static const struct script_op script_7[] = {
1591 OP_C_SET_ALPN ("ossltest")
1592 OP_C_CONNECT_WAIT ()
1593
1594 OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_AUTO_UNI)
1595 OP_C_WRITE (DEFAULT, "apple", 5)
1596
1597 OP_S_BIND_STREAM_ID (a, C_UNI_ID(0))
1598 OP_S_READ_EXPECT (a, "apple", 5)
1599 OP_S_WRITE_FAIL (a)
1600
1601 OP_END
1602 };
1603
1604 /* 8. Unidirectional default stream mode test (server sends first) */
1605 static const struct script_op script_8[] = {
1606 OP_C_SET_ALPN ("ossltest")
1607 OP_C_CONNECT_WAIT ()
1608
1609 OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_AUTO_UNI)
1610 OP_S_NEW_STREAM_UNI (a, S_UNI_ID(0))
1611 OP_S_WRITE (a, "apple", 5)
1612 OP_C_READ_EXPECT (DEFAULT, "apple", 5)
1613 OP_C_WRITE_FAIL (DEFAULT)
1614
1615 OP_END
1616 };
1617
1618 /* 9. Unidirectional default stream mode test (server sends first on bidi) */
1619 static const struct script_op script_9[] = {
1620 OP_C_SET_ALPN ("ossltest")
1621 OP_C_CONNECT_WAIT ()
1622
1623 OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_AUTO_UNI)
1624 OP_S_NEW_STREAM_BIDI (a, S_BIDI_ID(0))
1625 OP_S_WRITE (a, "apple", 5)
1626 OP_C_READ_EXPECT (DEFAULT, "apple", 5)
1627 OP_C_WRITE (DEFAULT, "orange", 6)
1628 OP_S_READ_EXPECT (a, "orange", 6)
1629
1630 OP_END
1631 };
1632
1633 /* 10. Shutdown */
1634 static const struct script_op script_10[] = {
1635 OP_C_SET_ALPN ("ossltest")
1636 OP_C_CONNECT_WAIT ()
1637
1638 OP_C_WRITE (DEFAULT, "apple", 5)
1639 OP_S_BIND_STREAM_ID (a, C_BIDI_ID(0))
1640 OP_S_READ_EXPECT (a, "apple", 5)
1641
1642 OP_C_SHUTDOWN ()
1643 OP_C_EXPECT_CONN_CLOSE_INFO(0, 1, 0)
1644 OP_S_EXPECT_CONN_CLOSE_INFO(0, 1, 1)
1645
1646 OP_END
1647 };
1648
1649 /* 11. Many threads accepted on the same client connection */
1650 static const struct script_op script_11_child[] = {
1651 OP_C_ACCEPT_STREAM_WAIT (a)
1652 OP_C_READ_EXPECT (a, "foo", 3)
1653 OP_C_EXPECT_FIN (a)
1654
1655 OP_END
1656 };
1657
1658 static const struct script_op script_11[] = {
1659 OP_C_SET_ALPN ("ossltest")
1660 OP_C_CONNECT_WAIT ()
1661 OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE)
1662
1663 OP_NEW_THREAD (5, script_11_child)
1664
1665 OP_S_NEW_STREAM_BIDI (a, ANY_ID)
1666 OP_S_WRITE (a, "foo", 3)
1667 OP_S_CONCLUDE (a)
1668
1669 OP_S_NEW_STREAM_BIDI (b, ANY_ID)
1670 OP_S_WRITE (b, "foo", 3)
1671 OP_S_CONCLUDE (b)
1672
1673 OP_S_NEW_STREAM_BIDI (c, ANY_ID)
1674 OP_S_WRITE (c, "foo", 3)
1675 OP_S_CONCLUDE (c)
1676
1677 OP_S_NEW_STREAM_BIDI (d, ANY_ID)
1678 OP_S_WRITE (d, "foo", 3)
1679 OP_S_CONCLUDE (d)
1680
1681 OP_S_NEW_STREAM_BIDI (e, ANY_ID)
1682 OP_S_WRITE (e, "foo", 3)
1683 OP_S_CONCLUDE (e)
1684
1685 OP_END
1686 };
1687
1688 /* 12. Many threads initiated on the same client connection */
1689 static const struct script_op script_12_child[] = {
1690 OP_C_NEW_STREAM_BIDI (a, ANY_ID)
1691 OP_C_WRITE (a, "foo", 3)
1692 OP_C_CONCLUDE (a)
1693 OP_C_FREE_STREAM (a)
1694
1695 OP_END
1696 };
1697
1698 static const struct script_op script_12[] = {
1699 OP_C_SET_ALPN ("ossltest")
1700 OP_C_CONNECT_WAIT ()
1701 OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE)
1702
1703 OP_NEW_THREAD (5, script_12_child)
1704
1705 OP_S_BIND_STREAM_ID (a, C_BIDI_ID(0))
1706 OP_S_READ_EXPECT (a, "foo", 3)
1707 OP_S_EXPECT_FIN (a)
1708 OP_S_BIND_STREAM_ID (b, C_BIDI_ID(1))
1709 OP_S_READ_EXPECT (b, "foo", 3)
1710 OP_S_EXPECT_FIN (b)
1711 OP_S_BIND_STREAM_ID (c, C_BIDI_ID(2))
1712 OP_S_READ_EXPECT (c, "foo", 3)
1713 OP_S_EXPECT_FIN (c)
1714 OP_S_BIND_STREAM_ID (d, C_BIDI_ID(3))
1715 OP_S_READ_EXPECT (d, "foo", 3)
1716 OP_S_EXPECT_FIN (d)
1717 OP_S_BIND_STREAM_ID (e, C_BIDI_ID(4))
1718 OP_S_READ_EXPECT (e, "foo", 3)
1719 OP_S_EXPECT_FIN (e)
1720
1721 OP_END
1722 };
1723
1724 /* 13. Many threads accepted on the same client connection (stress test) */
1725 static const struct script_op script_13_child[] = {
1726 OP_BEGIN_REPEAT (10)
1727
1728 OP_C_ACCEPT_STREAM_WAIT (a)
1729 OP_C_READ_EXPECT (a, "foo", 3)
1730 OP_C_EXPECT_FIN (a)
1731 OP_C_FREE_STREAM (a)
1732
1733 OP_END_REPEAT ()
1734
1735 OP_END
1736 };
1737
1738 static const struct script_op script_13[] = {
1739 OP_C_SET_ALPN ("ossltest")
1740 OP_C_CONNECT_WAIT ()
1741 OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE)
1742
1743 OP_NEW_THREAD (5, script_13_child)
1744
1745 OP_BEGIN_REPEAT (50)
1746
1747 OP_S_NEW_STREAM_BIDI (a, ANY_ID)
1748 OP_S_WRITE (a, "foo", 3)
1749 OP_S_CONCLUDE (a)
1750 OP_S_UNBIND_STREAM_ID (a)
1751
1752 OP_END_REPEAT ()
1753
1754 OP_END
1755 };
1756
1757 /* 14. Many threads initiating on the same client connection (stress test) */
1758 static const struct script_op script_14_child[] = {
1759 OP_BEGIN_REPEAT (10)
1760
1761 OP_C_NEW_STREAM_BIDI (a, ANY_ID)
1762 OP_C_WRITE (a, "foo", 3)
1763 OP_C_CONCLUDE (a)
1764 OP_C_FREE_STREAM (a)
1765
1766 OP_END_REPEAT ()
1767
1768 OP_END
1769 };
1770
1771 static const struct script_op script_14[] = {
1772 OP_C_SET_ALPN ("ossltest")
1773 OP_C_CONNECT_WAIT ()
1774 OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE)
1775
1776 OP_NEW_THREAD (5, script_14_child)
1777
1778 OP_BEGIN_REPEAT (50)
1779
1780 OP_S_ACCEPT_STREAM_WAIT (a)
1781 OP_S_READ_EXPECT (a, "foo", 3)
1782 OP_S_EXPECT_FIN (a)
1783 OP_S_UNBIND_STREAM_ID (a)
1784
1785 OP_END_REPEAT ()
1786
1787 OP_END
1788 };
1789
1790 /* 15. Client sending large number of streams, MAX_STREAMS test */
1791 static const struct script_op script_15[] = {
1792 OP_C_SET_ALPN ("ossltest")
1793 OP_C_CONNECT_WAIT ()
1794 OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE)
1795
1796 /*
1797 * This will cause a protocol violation to be raised by the server if we are
1798 * not handling the stream limit correctly on the TX side.
1799 */
1800 OP_BEGIN_REPEAT (200)
1801
1802 OP_C_NEW_STREAM_BIDI (a, ANY_ID)
1803 OP_C_WRITE (a, "foo", 3)
1804 OP_C_CONCLUDE (a)
1805 OP_C_FREE_STREAM (a)
1806
1807 OP_END_REPEAT ()
1808
1809 /* Prove the connection is still good. */
1810 OP_S_NEW_STREAM_BIDI (a, S_BIDI_ID(0))
1811 OP_S_WRITE (a, "bar", 3)
1812 OP_S_CONCLUDE (a)
1813
1814 OP_C_ACCEPT_STREAM_WAIT (a)
1815 OP_C_READ_EXPECT (a, "bar", 3)
1816 OP_C_EXPECT_FIN (a)
1817
1818 /*
1819 * Drain the queue of incoming streams. We should be able to get all 200
1820 * even though only 100 can be initiated at a time.
1821 */
1822 OP_BEGIN_REPEAT (200)
1823
1824 OP_S_ACCEPT_STREAM_WAIT (b)
1825 OP_S_READ_EXPECT (b, "foo", 3)
1826 OP_S_EXPECT_FIN (b)
1827 OP_S_UNBIND_STREAM_ID (b)
1828
1829 OP_END_REPEAT ()
1830
1831 OP_END
1832 };
1833
1834 /* 16. Server sending large number of streams, MAX_STREAMS test */
1835 static const struct script_op script_16[] = {
1836 OP_C_SET_ALPN ("ossltest")
1837 OP_C_CONNECT_WAIT ()
1838 OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE)
1839
1840 /*
1841 * This will cause a protocol violation to be raised by the client if we are
1842 * not handling the stream limit correctly on the TX side.
1843 */
1844 OP_BEGIN_REPEAT (200)
1845
1846 OP_S_NEW_STREAM_BIDI (a, ANY_ID)
1847 OP_S_WRITE (a, "foo", 3)
1848 OP_S_CONCLUDE (a)
1849 OP_S_UNBIND_STREAM_ID (a)
1850
1851 OP_END_REPEAT ()
1852
1853 /* Prove that the connection is still good. */
1854 OP_C_NEW_STREAM_BIDI (a, ANY_ID)
1855 OP_C_WRITE (a, "bar", 3)
1856 OP_C_CONCLUDE (a)
1857
1858 OP_S_ACCEPT_STREAM_WAIT (b)
1859 OP_S_READ_EXPECT (b, "bar", 3)
1860 OP_S_EXPECT_FIN (b)
1861
1862 /* Drain the queue of incoming streams. */
1863 OP_BEGIN_REPEAT (200)
1864
1865 OP_C_ACCEPT_STREAM_WAIT (b)
1866 OP_C_READ_EXPECT (b, "foo", 3)
1867 OP_C_EXPECT_FIN (b)
1868 OP_C_FREE_STREAM (b)
1869
1870 OP_END_REPEAT ()
1871
1872 OP_END
1873 };
1874
1875 /* 17. Key update test - unlimited */
1876 static const struct script_op script_17[] = {
1877 OP_C_SET_ALPN ("ossltest")
1878 OP_C_CONNECT_WAIT ()
1879
1880 OP_C_WRITE (DEFAULT, "apple", 5)
1881
1882 OP_S_BIND_STREAM_ID (a, C_BIDI_ID(0))
1883 OP_S_READ_EXPECT (a, "apple", 5)
1884
1885 OP_CHECK (override_key_update, 1)
1886
1887 OP_BEGIN_REPEAT (200)
1888
1889 OP_C_WRITE (DEFAULT, "apple", 5)
1890 OP_S_READ_EXPECT (a, "apple", 5)
1891
1892 /*
1893 * TXKU frequency is bounded by RTT because a previous TXKU needs to be
1894 * acknowledged by the peer first before another one can be begin. By
1895 * waiting this long, we eliminate any such concern and ensure as many key
1896 * updates as possible can occur for the purposes of this test.
1897 */
1898 OP_CHECK (skip_time_ms, 100)
1899
1900 OP_END_REPEAT ()
1901
1902 /* At least 5 RXKUs detected */
1903 OP_CHECK (check_key_update_ge, 5)
1904
1905 /*
1906 * Prove the connection is still healthy by sending something in both
1907 * directions.
1908 */
1909 OP_C_WRITE (DEFAULT, "xyzzy", 5)
1910 OP_S_READ_EXPECT (a, "xyzzy", 5)
1911
1912 OP_S_WRITE (a, "plugh", 5)
1913 OP_C_READ_EXPECT (DEFAULT, "plugh", 5)
1914
1915 OP_END
1916 };
1917
1918 /* 18. Key update test - RTT-bounded */
1919 static const struct script_op script_18[] = {
1920 OP_C_SET_ALPN ("ossltest")
1921 OP_C_CONNECT_WAIT ()
1922
1923 OP_C_WRITE (DEFAULT, "apple", 5)
1924
1925 OP_S_BIND_STREAM_ID (a, C_BIDI_ID(0))
1926 OP_S_READ_EXPECT (a, "apple", 5)
1927
1928 OP_CHECK (override_key_update, 1)
1929
1930 OP_BEGIN_REPEAT (200)
1931
1932 OP_C_WRITE (DEFAULT, "apple", 5)
1933 OP_S_READ_EXPECT (a, "apple", 5)
1934 OP_CHECK (skip_time_ms, 2)
1935
1936 OP_END_REPEAT ()
1937
1938 /*
1939 * This time we simulate far less time passing between writes, so there are
1940 * fewer opportunities to initiate TXKUs. Note that we ask for a TXKU every
1941 * 1 packet above, which is absurd; thus this ensures we only actually
1942 * generate TXKUs when we are allowed to.
1943 */
1944 OP_CHECK (check_key_update_ge, 4)
1945 OP_CHECK (check_key_update_lt, 120)
1946
1947 /*
1948 * Prove the connection is still healthy by sending something in both
1949 * directions.
1950 */
1951 OP_C_WRITE (DEFAULT, "xyzzy", 5)
1952 OP_S_READ_EXPECT (a, "xyzzy", 5)
1953
1954 OP_S_WRITE (a, "plugh", 5)
1955 OP_C_READ_EXPECT (DEFAULT, "plugh", 5)
1956
1957 OP_END
1958 };
1959
1960 /* 19. Key update test - artificially triggered */
1961 static const struct script_op script_19[] = {
1962 OP_C_SET_ALPN ("ossltest")
1963 OP_C_CONNECT_WAIT ()
1964
1965 OP_C_WRITE (DEFAULT, "apple", 5)
1966
1967 OP_S_BIND_STREAM_ID (a, C_BIDI_ID(0))
1968 OP_S_READ_EXPECT (a, "apple", 5)
1969
1970 OP_CHECK (check_key_update_lt, 1)
1971 OP_CHECK (trigger_key_update, 0)
1972
1973 OP_C_WRITE (DEFAULT, "orange", 6)
1974 OP_S_READ_EXPECT (a, "orange", 6)
1975
1976 OP_CHECK (check_key_update_ge, 1)
1977
1978 OP_END
1979 };
1980
1981 static const struct script_op *const scripts[] = {
1982 script_1,
1983 script_2,
1984 script_3,
1985 script_4,
1986 script_5,
1987 script_6,
1988 script_7,
1989 script_8,
1990 script_9,
1991 script_10,
1992 script_11,
1993 script_12,
1994 script_13,
1995 script_14,
1996 script_15,
1997 script_16,
1998 script_17,
1999 script_18,
2000 script_19,
2001 };
2002
2003 static int test_script(int idx)
2004 {
2005 int script_idx = idx >> 1;
2006 int free_order = idx & 1;
2007
2008 TEST_info("Running script %d (order=%d)", script_idx + 1, free_order);
2009 return run_script(scripts[script_idx], free_order);
2010 }
2011
2012 OPT_TEST_DECLARE_USAGE("certfile privkeyfile\n")
2013
2014 int setup_tests(void)
2015 {
2016 if (!test_skip_common_options()) {
2017 TEST_error("Error parsing test options\n");
2018 return 0;
2019 }
2020
2021 if (!TEST_ptr(certfile = test_get_argument(0))
2022 || !TEST_ptr(keyfile = test_get_argument(1)))
2023 return 0;
2024
2025 ADD_ALL_TESTS(test_script, OSSL_NELEM(scripts) * 2);
2026 return 1;
2027 }