xref: /src/crypto/openssl/test/quic_txp_test.c (revision f25b8c9fb4f58cf61adb47d7570abe7caa6d385d)
1 /*
2  * Copyright 2022-2025 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 "internal/packet.h"
10 #include "internal/quic_txp.h"
11 #include "internal/quic_statm.h"
12 #include "internal/quic_demux.h"
13 #include "internal/quic_record_rx.h"
14 #include "testutil.h"
15 #include "quic_record_test_util.h"
16 
17 static const QUIC_CONN_ID scid_1 = {
18     1, { 0x5f }
19 };
20 
21 static const QUIC_CONN_ID dcid_1 = {
22     8, { 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8 }
23 };
24 
25 static const QUIC_CONN_ID cid_1 = {
26     8, { 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, 0xb8 }
27 };
28 
29 static const unsigned char reset_token_1[16] = {
30     0x99,
31     0x88,
32     0x77,
33     0x66,
34     0x55,
35     0x44,
36     0x33,
37     0x22,
38     0x11,
39     0xaa,
40     0xbb,
41     0xcc,
42     0xdd,
43     0xee,
44     0xff,
45     0x12,
46 };
47 
48 static const unsigned char secret_1[32] = {
49     0x01
50 };
51 
fake_now(void * arg)52 static OSSL_TIME fake_now(void *arg)
53 {
54     return ossl_time_now(); /* TODO */
55 }
56 
57 struct helper {
58     OSSL_QUIC_TX_PACKETISER *txp;
59     OSSL_QUIC_TX_PACKETISER_ARGS args;
60     OSSL_QTX_ARGS qtx_args;
61     BIO *bio1, *bio2;
62     QUIC_TXFC conn_txfc;
63     QUIC_RXFC conn_rxfc, stream_rxfc;
64     QUIC_RXFC max_streams_bidi_rxfc, max_streams_uni_rxfc;
65     OSSL_STATM statm;
66     OSSL_CC_DATA *cc_data;
67     const OSSL_CC_METHOD *cc_method;
68     QUIC_STREAM_MAP qsm;
69     char have_statm, have_qsm;
70     QUIC_DEMUX *demux;
71     OSSL_QRX *qrx;
72     OSSL_QRX_ARGS qrx_args;
73     OSSL_QRX_PKT *qrx_pkt;
74     PACKET pkt;
75     uint64_t frame_type;
76     union {
77         uint64_t max_data;
78         OSSL_QUIC_FRAME_NEW_CONN_ID new_conn_id;
79         OSSL_QUIC_FRAME_ACK ack;
80         struct {
81             const unsigned char *token;
82             size_t token_len;
83         } new_token;
84         OSSL_QUIC_FRAME_CRYPTO crypto;
85         OSSL_QUIC_FRAME_STREAM stream;
86         OSSL_QUIC_FRAME_STOP_SENDING stop_sending;
87         OSSL_QUIC_FRAME_RESET_STREAM reset_stream;
88         OSSL_QUIC_FRAME_CONN_CLOSE conn_close;
89     } frame;
90     OSSL_QUIC_ACK_RANGE ack_ranges[16];
91 };
92 
helper_cleanup(struct helper * h)93 static void helper_cleanup(struct helper *h)
94 {
95     size_t i;
96     uint32_t pn_space;
97 
98     ossl_qrx_pkt_release(h->qrx_pkt);
99     h->qrx_pkt = NULL;
100 
101     for (pn_space = QUIC_PN_SPACE_INITIAL;
102         pn_space < QUIC_PN_SPACE_NUM;
103         ++pn_space)
104         ossl_ackm_on_pkt_space_discarded(h->args.ackm, pn_space);
105 
106     ossl_quic_tx_packetiser_free(h->txp);
107     ossl_qtx_free(h->args.qtx);
108     ossl_quic_txpim_free(h->args.txpim);
109     ossl_quic_cfq_free(h->args.cfq);
110     if (h->cc_data != NULL)
111         h->cc_method->free(h->cc_data);
112     if (h->have_statm)
113         ossl_statm_destroy(&h->statm);
114     if (h->have_qsm)
115         ossl_quic_stream_map_cleanup(&h->qsm);
116     for (i = 0; i < QUIC_PN_SPACE_NUM; ++i)
117         ossl_quic_sstream_free(h->args.crypto[i]);
118     ossl_ackm_free(h->args.ackm);
119     ossl_qrx_free(h->qrx);
120     ossl_quic_demux_free(h->demux);
121     BIO_free(h->bio1);
122     BIO_free(h->bio2);
123 }
124 
demux_default_handler(QUIC_URXE * e,void * arg,const QUIC_CONN_ID * dcid)125 static void demux_default_handler(QUIC_URXE *e, void *arg,
126     const QUIC_CONN_ID *dcid)
127 {
128     struct helper *h = arg;
129 
130     if (dcid == NULL || !ossl_quic_conn_id_eq(dcid, &dcid_1))
131         return;
132 
133     ossl_qrx_inject_urxe(h->qrx, e);
134 }
135 
helper_init(struct helper * h)136 static int helper_init(struct helper *h)
137 {
138     int rc = 0;
139     size_t i;
140 
141     memset(h, 0, sizeof(*h));
142 
143     /* Initialisation */
144     if (!TEST_true(BIO_new_bio_dgram_pair(&h->bio1, 0, &h->bio2, 0)))
145         goto err;
146 
147     h->qtx_args.bio = h->bio1;
148     h->qtx_args.mdpl = 1200;
149 
150     if (!TEST_ptr(h->args.qtx = ossl_qtx_new(&h->qtx_args)))
151         goto err;
152 
153     if (!TEST_ptr(h->args.txpim = ossl_quic_txpim_new()))
154         goto err;
155 
156     if (!TEST_ptr(h->args.cfq = ossl_quic_cfq_new()))
157         goto err;
158 
159     if (!TEST_true(ossl_quic_txfc_init(&h->conn_txfc, NULL)))
160         goto err;
161 
162     if (!TEST_true(ossl_quic_rxfc_init(&h->conn_rxfc, NULL,
163             2 * 1024 * 1024,
164             10 * 1024 * 1024,
165             fake_now,
166             NULL)))
167         goto err;
168 
169     if (!TEST_true(ossl_quic_rxfc_init(&h->stream_rxfc, &h->conn_rxfc,
170             1 * 1024 * 1024,
171             5 * 1024 * 1024,
172             fake_now,
173             NULL)))
174         goto err;
175 
176     if (!TEST_true(ossl_quic_rxfc_init(&h->max_streams_bidi_rxfc, NULL,
177             100, 100,
178             fake_now,
179             NULL)))
180         goto err;
181 
182     if (!TEST_true(ossl_quic_rxfc_init(&h->max_streams_uni_rxfc, NULL,
183             100, 100,
184             fake_now,
185             NULL)))
186 
187         if (!TEST_true(ossl_statm_init(&h->statm)))
188             goto err;
189 
190     h->have_statm = 1;
191 
192     h->cc_method = &ossl_cc_dummy_method;
193     if (!TEST_ptr(h->cc_data = h->cc_method->new(fake_now, NULL)))
194         goto err;
195 
196     if (!TEST_ptr(h->args.ackm = ossl_ackm_new(fake_now, NULL,
197                       &h->statm,
198                       h->cc_method,
199                       h->cc_data,
200                       /* is_server */ 0)))
201         goto err;
202 
203     if (!TEST_true(ossl_quic_stream_map_init(&h->qsm, NULL, NULL,
204             &h->max_streams_bidi_rxfc,
205             &h->max_streams_uni_rxfc,
206             /*is_server=*/0)))
207         goto err;
208 
209     h->have_qsm = 1;
210 
211     for (i = 0; i < QUIC_PN_SPACE_NUM; ++i)
212         if (!TEST_ptr(h->args.crypto[i] = ossl_quic_sstream_new(4096)))
213             goto err;
214 
215     h->args.cur_scid = scid_1;
216     h->args.cur_dcid = dcid_1;
217     h->args.qsm = &h->qsm;
218     h->args.conn_txfc = &h->conn_txfc;
219     h->args.conn_rxfc = &h->conn_rxfc;
220     h->args.max_streams_bidi_rxfc = &h->max_streams_bidi_rxfc;
221     h->args.max_streams_uni_rxfc = &h->max_streams_uni_rxfc;
222     h->args.cc_method = h->cc_method;
223     h->args.cc_data = h->cc_data;
224     h->args.now = fake_now;
225     h->args.protocol_version = QUIC_VERSION_1;
226 
227     if (!TEST_ptr(h->txp = ossl_quic_tx_packetiser_new(&h->args)))
228         goto err;
229 
230     /*
231      * Our helper should always skip validation
232      * as the tests are not written to expect delayed connections
233      */
234     ossl_quic_tx_packetiser_set_validated(h->txp);
235 
236     if (!TEST_ptr(h->demux = ossl_quic_demux_new(h->bio2, 8,
237                       fake_now, NULL)))
238         goto err;
239 
240     ossl_quic_demux_set_default_handler(h->demux, demux_default_handler, h);
241 
242     h->qrx_args.demux = h->demux;
243     h->qrx_args.short_conn_id_len = 8;
244     h->qrx_args.max_deferred = 32;
245 
246     if (!TEST_ptr(h->qrx = ossl_qrx_new(&h->qrx_args)))
247         goto err;
248 
249     ossl_qrx_allow_1rtt_processing(h->qrx);
250 
251     rc = 1;
252 err:
253     if (!rc)
254         helper_cleanup(h);
255 
256     return rc;
257 }
258 
259 #define OPK_END 0 /* End of Script */
260 #define OPK_TXP_GENERATE 1 /* Call generate, expect packet output */
261 #define OPK_TXP_GENERATE_NONE 2 /* Call generate, expect no packet output */
262 #define OPK_RX_PKT 3 /* Receive, expect packet */
263 #define OPK_RX_PKT_NONE 4 /* Receive, expect no packet */
264 #define OPK_EXPECT_DGRAM_LEN 5 /* Expect received datagram length in range */
265 #define OPK_EXPECT_FRAME 6 /* Expect next frame is of type */
266 #define OPK_EXPECT_INITIAL_TOKEN 7 /* Expect initial token buffer match */
267 #define OPK_EXPECT_HDR 8 /* Expect header structure match */
268 #define OPK_CHECK 9 /* Call check function */
269 #define OPK_NEXT_FRAME 10 /* Next frame */
270 #define OPK_EXPECT_NO_FRAME 11 /* Expect no further frames */
271 #define OPK_PROVIDE_SECRET 12 /* Provide secret to QTX and QRX */
272 #define OPK_DISCARD_EL 13 /* Discard QTX EL */
273 #define OPK_CRYPTO_SEND 14 /* Push data into crypto send stream */
274 #define OPK_STREAM_NEW 15 /* Create new application stream */
275 #define OPK_STREAM_SEND 16 /* Push data into application send stream */
276 #define OPK_STREAM_FIN 17 /* Mark stream as finished */
277 #define OPK_STOP_SENDING 18 /* Mark stream for STOP_SENDING */
278 #define OPK_RESET_STREAM 19 /* Mark stream for RESET_STREAM */
279 #define OPK_CONN_TXFC_BUMP 20 /* Bump connection TXFC CWM */
280 #define OPK_STREAM_TXFC_BUMP 21 /* Bump stream TXFC CWM */
281 #define OPK_HANDSHAKE_COMPLETE 22 /* Mark handshake as complete */
282 #define OPK_NOP 23 /* No-op */
283 
284 struct script_op {
285     uint32_t opcode;
286     uint64_t arg0, arg1;
287     const void *buf;
288     size_t buf_len;
289     int (*check_func)(struct helper *h);
290 };
291 
292 #define OP_END \
293     { OPK_END }
294 #define OP_TXP_GENERATE() \
295     { OPK_TXP_GENERATE },
296 #define OP_TXP_GENERATE_NONE() \
297     { OPK_TXP_GENERATE_NONE },
298 #define OP_RX_PKT() \
299     { OPK_RX_PKT },
300 #define OP_RX_PKT_NONE() \
301     { OPK_RX_PKT_NONE },
302 #define OP_EXPECT_DGRAM_LEN(lo, hi) \
303     { OPK_EXPECT_DGRAM_LEN, (lo), (hi) },
304 #define OP_EXPECT_FRAME(frame_type) \
305     { OPK_EXPECT_FRAME, (frame_type) },
306 #define OP_EXPECT_INITIAL_TOKEN(buf) \
307     { OPK_EXPECT_INITIAL_TOKEN, sizeof(buf), 0, buf },
308 #define OP_EXPECT_HDR(hdr) \
309     { OPK_EXPECT_HDR, 0, 0, &(hdr) },
310 #define OP_CHECK(func) \
311     { OPK_CHECK, 0, 0, NULL, 0, (func) },
312 #define OP_NEXT_FRAME() \
313     { OPK_NEXT_FRAME },
314 #define OP_EXPECT_NO_FRAME() \
315     { OPK_EXPECT_NO_FRAME },
316 #define OP_PROVIDE_SECRET(el, suite, secret) \
317     { OPK_PROVIDE_SECRET, (el), (suite), (secret), sizeof(secret) },
318 #define OP_DISCARD_EL(el) \
319     { OPK_DISCARD_EL, (el) },
320 #define OP_CRYPTO_SEND(pn_space, buf) \
321     { OPK_CRYPTO_SEND, (pn_space), 0, (buf), sizeof(buf) },
322 #define OP_STREAM_NEW(id) \
323     { OPK_STREAM_NEW, (id) },
324 #define OP_STREAM_SEND(id, buf) \
325     { OPK_STREAM_SEND, (id), 0, (buf), sizeof(buf) },
326 #define OP_STREAM_FIN(id) \
327     { OPK_STREAM_FIN, (id) },
328 #define OP_STOP_SENDING(id, aec) \
329     { OPK_STOP_SENDING, (id), (aec) },
330 #define OP_RESET_STREAM(id, aec) \
331     { OPK_RESET_STREAM, (id), (aec) },
332 #define OP_CONN_TXFC_BUMP(cwm) \
333     { OPK_CONN_TXFC_BUMP, (cwm) },
334 #define OP_STREAM_TXFC_BUMP(id, cwm) \
335     { OPK_STREAM_TXFC_BUMP, (cwm), (id) },
336 #define OP_HANDSHAKE_COMPLETE() \
337     { OPK_HANDSHAKE_COMPLETE },
338 #define OP_NOP() \
339     { OPK_NOP },
340 
schedule_handshake_done(struct helper * h)341 static int schedule_handshake_done(struct helper *h)
342 {
343     ossl_quic_tx_packetiser_schedule_handshake_done(h->txp);
344     return 1;
345 }
346 
schedule_ack_eliciting_app(struct helper * h)347 static int schedule_ack_eliciting_app(struct helper *h)
348 {
349     ossl_quic_tx_packetiser_schedule_ack_eliciting(h->txp, QUIC_PN_SPACE_APP);
350     return 1;
351 }
352 
353 /* 1. 1-RTT, Single Handshake Done Frame */
354 static const struct script_op script_1[] = {
355     OP_PROVIDE_SECRET(QUIC_ENC_LEVEL_1RTT, QRL_SUITE_AES128GCM, secret_1)
356         OP_TXP_GENERATE_NONE()
357             OP_CHECK(schedule_handshake_done)
358                 OP_TXP_GENERATE()
359                     OP_RX_PKT()
360     /* Should not be long */
361     OP_EXPECT_DGRAM_LEN(21, 32)
362         OP_NEXT_FRAME()
363             OP_EXPECT_FRAME(OSSL_QUIC_FRAME_TYPE_HANDSHAKE_DONE)
364                 OP_EXPECT_NO_FRAME()
365                     OP_RX_PKT_NONE()
366                         OP_TXP_GENERATE_NONE()
367                             OP_END
368 };
369 
370 /* 2. 1-RTT, Forced ACK-Eliciting Frame */
371 static const struct script_op script_2[] = {
372     OP_PROVIDE_SECRET(QUIC_ENC_LEVEL_1RTT, QRL_SUITE_AES128GCM, secret_1)
373         OP_TXP_GENERATE_NONE()
374             OP_CHECK(schedule_ack_eliciting_app)
375                 OP_TXP_GENERATE()
376                     OP_RX_PKT()
377     /* Should not be long */
378     OP_EXPECT_DGRAM_LEN(21, 32)
379     /* A PING frame should have been added */
380     OP_NEXT_FRAME()
381         OP_EXPECT_FRAME(OSSL_QUIC_FRAME_TYPE_PING)
382             OP_EXPECT_NO_FRAME()
383                 OP_RX_PKT_NONE()
384                     OP_TXP_GENERATE_NONE()
385                         OP_END
386 };
387 
388 /* 3. 1-RTT, MAX_DATA */
schedule_max_data(struct helper * h)389 static int schedule_max_data(struct helper *h)
390 {
391     uint64_t cwm;
392 
393     cwm = ossl_quic_rxfc_get_cwm(&h->stream_rxfc);
394 
395     if (!TEST_true(ossl_quic_rxfc_on_rx_stream_frame(&h->stream_rxfc, cwm, 0))
396         || !TEST_true(ossl_quic_rxfc_on_retire(&h->stream_rxfc, cwm,
397             ossl_ticks2time(OSSL_TIME_MS))))
398         return 0;
399 
400     return 1;
401 }
402 
403 static const struct script_op script_3[] = {
404     OP_PROVIDE_SECRET(QUIC_ENC_LEVEL_1RTT, QRL_SUITE_AES128GCM, secret_1)
405         OP_TXP_GENERATE_NONE()
406             OP_CHECK(schedule_max_data)
407                 OP_TXP_GENERATE()
408                     OP_RX_PKT()
409     /* Should not be long */
410     OP_EXPECT_DGRAM_LEN(21, 40)
411     /* A PING frame should have been added */
412     OP_NEXT_FRAME()
413         OP_EXPECT_FRAME(OSSL_QUIC_FRAME_TYPE_MAX_DATA)
414             OP_EXPECT_NO_FRAME()
415                 OP_RX_PKT_NONE()
416                     OP_TXP_GENERATE_NONE()
417                         OP_END
418 };
419 
420 /* 4. 1-RTT, CFQ (NEW_CONN_ID) */
free_buf_mem(unsigned char * buf,size_t buf_len,void * arg)421 static void free_buf_mem(unsigned char *buf, size_t buf_len, void *arg)
422 {
423     BUF_MEM_free((BUF_MEM *)arg);
424 }
425 
schedule_cfq_new_conn_id(struct helper * h)426 static int schedule_cfq_new_conn_id(struct helper *h)
427 {
428     int rc = 0;
429     QUIC_CFQ_ITEM *cfq_item;
430     WPACKET wpkt;
431     BUF_MEM *buf_mem = NULL;
432     size_t l = 0;
433     OSSL_QUIC_FRAME_NEW_CONN_ID ncid = { 0 };
434 
435     ncid.seq_num = 2345;
436     ncid.retire_prior_to = 1234;
437     ncid.conn_id = cid_1;
438     memcpy(ncid.stateless_reset.token, reset_token_1, sizeof(reset_token_1));
439 
440     if (!TEST_ptr(buf_mem = BUF_MEM_new()))
441         goto err;
442 
443     if (!TEST_true(WPACKET_init(&wpkt, buf_mem)))
444         goto err;
445 
446     if (!TEST_true(ossl_quic_wire_encode_frame_new_conn_id(&wpkt, &ncid))) {
447         WPACKET_cleanup(&wpkt);
448         goto err;
449     }
450 
451     WPACKET_finish(&wpkt);
452 
453     if (!TEST_true(WPACKET_get_total_written(&wpkt, &l)))
454         goto err;
455 
456     if (!TEST_ptr(cfq_item = ossl_quic_cfq_add_frame(h->args.cfq, 1,
457                       QUIC_PN_SPACE_APP,
458                       OSSL_QUIC_FRAME_TYPE_NEW_CONN_ID, 0,
459                       (unsigned char *)buf_mem->data, l,
460                       free_buf_mem,
461                       buf_mem)))
462         goto err;
463 
464     rc = 1;
465 err:
466     if (!rc)
467         BUF_MEM_free(buf_mem);
468     return rc;
469 }
470 
check_cfq_new_conn_id(struct helper * h)471 static int check_cfq_new_conn_id(struct helper *h)
472 {
473     if (!TEST_uint64_t_eq(h->frame.new_conn_id.seq_num, 2345)
474         || !TEST_uint64_t_eq(h->frame.new_conn_id.retire_prior_to, 1234)
475         || !TEST_mem_eq(&h->frame.new_conn_id.conn_id, sizeof(cid_1),
476             &cid_1, sizeof(cid_1))
477         || !TEST_mem_eq(&h->frame.new_conn_id.stateless_reset.token,
478             sizeof(reset_token_1),
479             reset_token_1,
480             sizeof(reset_token_1)))
481         return 0;
482 
483     return 1;
484 }
485 
486 static const struct script_op script_4[] = {
487     OP_PROVIDE_SECRET(QUIC_ENC_LEVEL_1RTT, QRL_SUITE_AES128GCM, secret_1)
488         OP_TXP_GENERATE_NONE()
489             OP_CHECK(schedule_cfq_new_conn_id)
490                 OP_TXP_GENERATE()
491                     OP_RX_PKT()
492                         OP_EXPECT_DGRAM_LEN(21, 128)
493                             OP_NEXT_FRAME()
494                                 OP_EXPECT_FRAME(OSSL_QUIC_FRAME_TYPE_NEW_CONN_ID)
495                                     OP_CHECK(check_cfq_new_conn_id)
496                                         OP_EXPECT_NO_FRAME()
497                                             OP_RX_PKT_NONE()
498                                                 OP_TXP_GENERATE_NONE()
499                                                     OP_END
500 };
501 
502 /* 5. 1-RTT, CFQ (NEW_TOKEN) */
503 static const unsigned char token_1[] = {
504     0x10, 0x11, 0x12, 0x13, 0x14, 0x15
505 };
506 
schedule_cfq_new_token(struct helper * h)507 static int schedule_cfq_new_token(struct helper *h)
508 {
509     int rc = 0;
510     QUIC_CFQ_ITEM *cfq_item;
511     WPACKET wpkt;
512     BUF_MEM *buf_mem = NULL;
513     size_t l = 0;
514 
515     if (!TEST_ptr(buf_mem = BUF_MEM_new()))
516         goto err;
517 
518     if (!TEST_true(WPACKET_init(&wpkt, buf_mem)))
519         goto err;
520 
521     if (!TEST_true(ossl_quic_wire_encode_frame_new_token(&wpkt, token_1,
522             sizeof(token_1)))) {
523         WPACKET_cleanup(&wpkt);
524         goto err;
525     }
526 
527     WPACKET_finish(&wpkt);
528 
529     if (!TEST_true(WPACKET_get_total_written(&wpkt, &l)))
530         goto err;
531 
532     if (!TEST_ptr(cfq_item = ossl_quic_cfq_add_frame(h->args.cfq, 1,
533                       QUIC_PN_SPACE_APP,
534                       OSSL_QUIC_FRAME_TYPE_NEW_TOKEN, 0,
535                       (unsigned char *)buf_mem->data, l,
536                       free_buf_mem,
537                       buf_mem)))
538         goto err;
539 
540     rc = 1;
541 err:
542     if (!rc)
543         BUF_MEM_free(buf_mem);
544     return rc;
545 }
546 
check_cfq_new_token(struct helper * h)547 static int check_cfq_new_token(struct helper *h)
548 {
549     if (!TEST_mem_eq(h->frame.new_token.token,
550             h->frame.new_token.token_len,
551             token_1,
552             sizeof(token_1)))
553         return 0;
554 
555     return 1;
556 }
557 
558 static const struct script_op script_5[] = {
559     OP_PROVIDE_SECRET(QUIC_ENC_LEVEL_1RTT, QRL_SUITE_AES128GCM, secret_1)
560         OP_TXP_GENERATE_NONE()
561             OP_CHECK(schedule_cfq_new_token)
562                 OP_TXP_GENERATE()
563                     OP_RX_PKT()
564                         OP_EXPECT_DGRAM_LEN(21, 512)
565                             OP_NEXT_FRAME()
566                                 OP_EXPECT_FRAME(OSSL_QUIC_FRAME_TYPE_NEW_TOKEN)
567                                     OP_CHECK(check_cfq_new_token)
568                                         OP_EXPECT_NO_FRAME()
569                                             OP_RX_PKT_NONE()
570                                                 OP_TXP_GENERATE_NONE()
571                                                     OP_END
572 };
573 
574 /* 6. 1-RTT, ACK */
schedule_ack(struct helper * h)575 static int schedule_ack(struct helper *h)
576 {
577     size_t i;
578     OSSL_ACKM_RX_PKT rx_pkt = { 0 };
579 
580     /* Stimulate ACK emission by simulating a few received packets. */
581     for (i = 0; i < 5; ++i) {
582         rx_pkt.pkt_num = i;
583         rx_pkt.time = fake_now(NULL);
584         rx_pkt.pkt_space = QUIC_PN_SPACE_APP;
585         rx_pkt.is_ack_eliciting = 1;
586 
587         if (!TEST_true(ossl_ackm_on_rx_packet(h->args.ackm, &rx_pkt)))
588             return 0;
589     }
590 
591     return 1;
592 }
593 
594 static const struct script_op script_6[] = {
595     OP_PROVIDE_SECRET(QUIC_ENC_LEVEL_1RTT, QRL_SUITE_AES128GCM, secret_1)
596         OP_TXP_GENERATE_NONE()
597             OP_CHECK(schedule_ack)
598                 OP_TXP_GENERATE()
599                     OP_RX_PKT()
600                         OP_EXPECT_DGRAM_LEN(21, 512)
601                             OP_NEXT_FRAME()
602                                 OP_EXPECT_FRAME(OSSL_QUIC_FRAME_TYPE_ACK_WITHOUT_ECN)
603                                     OP_EXPECT_NO_FRAME()
604                                         OP_RX_PKT_NONE()
605                                             OP_TXP_GENERATE_NONE()
606                                                 OP_END
607 };
608 
609 /* 7. 1-RTT, ACK, NEW_TOKEN */
610 static const struct script_op script_7[] = {
611     OP_PROVIDE_SECRET(QUIC_ENC_LEVEL_1RTT, QRL_SUITE_AES128GCM, secret_1)
612         OP_TXP_GENERATE_NONE()
613             OP_CHECK(schedule_cfq_new_token)
614                 OP_CHECK(schedule_ack)
615                     OP_TXP_GENERATE()
616                         OP_RX_PKT()
617                             OP_EXPECT_DGRAM_LEN(21, 512)
618     /* ACK must come before NEW_TOKEN */
619     OP_NEXT_FRAME()
620         OP_EXPECT_FRAME(OSSL_QUIC_FRAME_TYPE_ACK_WITHOUT_ECN)
621             OP_NEXT_FRAME()
622                 OP_EXPECT_FRAME(OSSL_QUIC_FRAME_TYPE_NEW_TOKEN)
623                     OP_EXPECT_NO_FRAME()
624                         OP_RX_PKT_NONE()
625                             OP_TXP_GENERATE_NONE()
626                                 OP_END
627 };
628 
629 /* 8. 1-RTT, CRYPTO */
630 static const unsigned char crypto_1[] = {
631     0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09
632 };
633 
634 static const struct script_op script_8[] = {
635     OP_PROVIDE_SECRET(QUIC_ENC_LEVEL_1RTT, QRL_SUITE_AES128GCM, secret_1)
636         OP_TXP_GENERATE_NONE()
637             OP_CRYPTO_SEND(QUIC_PN_SPACE_APP, crypto_1)
638                 OP_TXP_GENERATE()
639                     OP_RX_PKT()
640                         OP_EXPECT_DGRAM_LEN(21, 512)
641                             OP_NEXT_FRAME()
642                                 OP_EXPECT_FRAME(OSSL_QUIC_FRAME_TYPE_CRYPTO)
643                                     OP_EXPECT_NO_FRAME()
644                                         OP_RX_PKT_NONE()
645                                             OP_TXP_GENERATE_NONE()
646                                                 OP_END
647 };
648 
649 /* 9. 1-RTT, STREAM */
650 static const unsigned char stream_9[] = {
651     0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f, 0x7a, 0x7b
652 };
653 
check_stream_9(struct helper * h)654 static int check_stream_9(struct helper *h)
655 {
656     if (!TEST_mem_eq(h->frame.stream.data, (size_t)h->frame.stream.len,
657             stream_9, sizeof(stream_9)))
658         return 0;
659 
660     return 1;
661 }
662 
663 static const struct script_op script_9[] = {
664     OP_PROVIDE_SECRET(QUIC_ENC_LEVEL_1RTT, QRL_SUITE_AES128GCM, secret_1)
665         OP_HANDSHAKE_COMPLETE()
666             OP_TXP_GENERATE_NONE()
667                 OP_STREAM_NEW(42)
668                     OP_STREAM_SEND(42, stream_9)
669     /* Still no output because of TXFC */
670     OP_TXP_GENERATE_NONE()
671     /* Now grant a TXFC budget */
672     OP_CONN_TXFC_BUMP(1000)
673         OP_STREAM_TXFC_BUMP(42, 1000)
674             OP_TXP_GENERATE()
675                 OP_RX_PKT()
676                     OP_EXPECT_DGRAM_LEN(21, 512)
677                         OP_NEXT_FRAME()
678                             OP_EXPECT_FRAME(OSSL_QUIC_FRAME_TYPE_STREAM)
679                                 OP_CHECK(check_stream_9)
680                                     OP_EXPECT_NO_FRAME()
681                                         OP_RX_PKT_NONE()
682                                             OP_TXP_GENERATE_NONE()
683                                                 OP_END
684 };
685 
686 /* 10. 1-RTT, STREAM, round robin */
687 /* The data below is randomly generated data. */
688 static const unsigned char stream_10a[1300] = {
689     0x40, 0x0d, 0xb6, 0x0d, 0x25, 0x5f, 0xdd, 0xb9, 0x05, 0x79, 0xa8, 0xe3,
690     0x79, 0x32, 0xb2, 0xa7, 0x30, 0x6d, 0x29, 0xf6, 0xba, 0x50, 0xbe, 0x83,
691     0xcb, 0x56, 0xec, 0xd6, 0xc7, 0x80, 0x84, 0xa2, 0x2f, 0xeb, 0xc4, 0x37,
692     0x40, 0x44, 0xef, 0xd8, 0x78, 0xbb, 0x92, 0x80, 0x22, 0x33, 0xc0, 0xce,
693     0x33, 0x5b, 0x75, 0x8c, 0xa5, 0x1a, 0x7a, 0x2a, 0xa9, 0x88, 0xaf, 0xf6,
694     0x3a, 0xe2, 0x5e, 0x60, 0x52, 0x6d, 0xef, 0x7f, 0x2a, 0x9a, 0xaa, 0x17,
695     0x0e, 0x12, 0x51, 0x82, 0x08, 0x2f, 0x0f, 0x5b, 0xff, 0xf5, 0x7c, 0x7c,
696     0x89, 0x04, 0xfb, 0xa7, 0x80, 0x4e, 0xda, 0x12, 0x89, 0x01, 0x4a, 0x81,
697     0x84, 0x78, 0x15, 0xa9, 0x12, 0x28, 0x69, 0x4a, 0x25, 0xe5, 0x8b, 0x69,
698     0xc2, 0x9f, 0xb6, 0x59, 0x49, 0xe3, 0x53, 0x90, 0xef, 0xc9, 0xb8, 0x40,
699     0xdd, 0x62, 0x5f, 0x99, 0x68, 0xd2, 0x0a, 0x77, 0xde, 0xf3, 0x11, 0x39,
700     0x7f, 0x93, 0x8b, 0x81, 0x69, 0x36, 0xa7, 0x76, 0xa4, 0x10, 0x56, 0x51,
701     0xe5, 0x45, 0x3a, 0x42, 0x49, 0x6c, 0xc6, 0xa0, 0xb4, 0x13, 0x46, 0x59,
702     0x0e, 0x48, 0x60, 0xc9, 0xff, 0x70, 0x10, 0x8d, 0x6a, 0xf9, 0x5b, 0x94,
703     0xc2, 0x9e, 0x49, 0x19, 0x56, 0xf2, 0xc1, 0xff, 0x08, 0x3f, 0x9e, 0x26,
704     0x8e, 0x99, 0x71, 0xc4, 0x25, 0xb1, 0x4e, 0xcc, 0x7e, 0x5f, 0xf0, 0x4e,
705     0x25, 0xa2, 0x2f, 0x3f, 0x68, 0xaa, 0xcf, 0xbd, 0x19, 0x19, 0x1c, 0x92,
706     0xa0, 0xb6, 0xb8, 0x32, 0xb1, 0x0b, 0x91, 0x05, 0xa9, 0xf8, 0x1a, 0x4b,
707     0x74, 0x09, 0xf9, 0x57, 0xd0, 0x1c, 0x38, 0x10, 0x05, 0x54, 0xd8, 0x4e,
708     0x12, 0x67, 0xcc, 0x43, 0xa3, 0x81, 0xa9, 0x3a, 0x12, 0x57, 0xe7, 0x4b,
709     0x0e, 0xe5, 0x51, 0xf9, 0x5f, 0xd4, 0x46, 0x73, 0xa2, 0x78, 0xb7, 0x00,
710     0x24, 0x69, 0x35, 0x10, 0x1e, 0xb8, 0xa7, 0x4a, 0x9b, 0xbc, 0xfc, 0x04,
711     0x6f, 0x1a, 0xb0, 0x4f, 0x12, 0xc9, 0x2b, 0x3b, 0x94, 0x85, 0x1b, 0x8e,
712     0xba, 0xac, 0xfd, 0x10, 0x22, 0x68, 0x90, 0x17, 0x13, 0x44, 0x18, 0x2f,
713     0x33, 0x37, 0x1a, 0x89, 0xc0, 0x2c, 0x14, 0x59, 0xb2, 0xaf, 0xc0, 0x6b,
714     0xdc, 0x28, 0xe1, 0xe9, 0xc1, 0x0c, 0xb4, 0x80, 0x90, 0xb9, 0x1f, 0x45,
715     0xb4, 0x63, 0x9a, 0x0e, 0xfa, 0x33, 0xf5, 0x75, 0x3a, 0x4f, 0xc3, 0x8c,
716     0x70, 0xdb, 0xd7, 0xbf, 0xf6, 0xb8, 0x7f, 0xcc, 0xe5, 0x85, 0xb6, 0xae,
717     0x25, 0x60, 0x18, 0x5b, 0xf1, 0x51, 0x1a, 0x85, 0xc1, 0x7f, 0xf3, 0xbe,
718     0xb6, 0x82, 0x38, 0xe3, 0xd2, 0xff, 0x8a, 0xc4, 0xdb, 0x08, 0xe6, 0x96,
719     0xd5, 0x3d, 0x1f, 0xc5, 0x12, 0x35, 0x45, 0x75, 0x5d, 0x17, 0x4e, 0xe1,
720     0xb8, 0xc9, 0xf0, 0x45, 0x95, 0x0b, 0x03, 0xcb, 0x85, 0x47, 0xaf, 0xc7,
721     0x88, 0xb6, 0xc1, 0x2c, 0xb8, 0x9b, 0xe6, 0x8b, 0x51, 0xd5, 0x2e, 0x71,
722     0xba, 0xc9, 0xa9, 0x37, 0x5e, 0x1c, 0x2c, 0x03, 0xf0, 0xc7, 0xc1, 0xd3,
723     0x72, 0xaa, 0x4d, 0x19, 0xd6, 0x51, 0x64, 0x12, 0xeb, 0x39, 0xeb, 0x45,
724     0xe9, 0xb4, 0x84, 0x08, 0xb6, 0x6c, 0xc7, 0x3e, 0xf0, 0x88, 0x64, 0xc2,
725     0x91, 0xb7, 0xa5, 0x86, 0x66, 0x83, 0xd5, 0xd3, 0x41, 0x24, 0xb2, 0x1c,
726     0x9a, 0x18, 0x10, 0x0e, 0xa5, 0xc9, 0xef, 0xcd, 0x06, 0xce, 0xa8, 0xaf,
727     0x22, 0x52, 0x25, 0x0b, 0x99, 0x3d, 0xe9, 0x26, 0xda, 0xa9, 0x47, 0xd1,
728     0x4b, 0xa6, 0x4c, 0xfc, 0x80, 0xaf, 0x6a, 0x59, 0x4b, 0x35, 0xa4, 0x93,
729     0x39, 0x5b, 0xfa, 0x91, 0x9d, 0xdf, 0x9d, 0x3c, 0xfb, 0x53, 0xca, 0x18,
730     0x19, 0xe4, 0xda, 0x95, 0x47, 0x5a, 0x37, 0x59, 0xd7, 0xd2, 0xe4, 0x75,
731     0x45, 0x0d, 0x03, 0x7f, 0xa0, 0xa9, 0xa0, 0x71, 0x06, 0xb1, 0x9d, 0x46,
732     0xbd, 0xcf, 0x4a, 0x8b, 0x73, 0xc1, 0x45, 0x5c, 0x00, 0x61, 0xfd, 0xd1,
733     0xa4, 0xa2, 0x3e, 0xaa, 0xbe, 0x72, 0xf1, 0x7a, 0x1a, 0x76, 0x88, 0x5c,
734     0x9e, 0x74, 0x6d, 0x2a, 0x34, 0xfc, 0xf7, 0x41, 0x28, 0xe8, 0xa3, 0x43,
735     0x4d, 0x43, 0x1d, 0x6c, 0x36, 0xb1, 0x45, 0x71, 0x5a, 0x3c, 0xd3, 0x28,
736     0x44, 0xe4, 0x9b, 0xbf, 0x54, 0x16, 0xc3, 0x99, 0x6c, 0x42, 0xd8, 0x20,
737     0xb6, 0x20, 0x5f, 0x6e, 0xbc, 0xba, 0x88, 0x5e, 0x2f, 0xa5, 0xd1, 0x82,
738     0x5c, 0x92, 0xd0, 0x79, 0xfd, 0xcc, 0x61, 0x49, 0xd0, 0x73, 0x92, 0xe6,
739     0x98, 0xe3, 0x80, 0x7a, 0xf9, 0x56, 0x63, 0x33, 0x19, 0xda, 0x54, 0x13,
740     0xf0, 0x21, 0xa8, 0x15, 0xf6, 0xb7, 0x43, 0x7c, 0x1c, 0x1e, 0xb1, 0x89,
741     0x8d, 0xce, 0x20, 0x54, 0x81, 0x80, 0xb5, 0x8f, 0x9b, 0xb1, 0x09, 0x92,
742     0xdb, 0x25, 0x6f, 0x30, 0x29, 0x08, 0x1a, 0x05, 0x08, 0xf4, 0x83, 0x8b,
743     0x1e, 0x2d, 0xfd, 0xe4, 0xb2, 0x76, 0xc8, 0x4d, 0xf3, 0xa6, 0x49, 0x5f,
744     0x2c, 0x99, 0x78, 0xbd, 0x07, 0xef, 0xc8, 0xd9, 0xb5, 0x70, 0x3b, 0x0a,
745     0xcb, 0xbd, 0xa0, 0xea, 0x15, 0xfb, 0xd1, 0x6e, 0x61, 0x83, 0xcb, 0x90,
746     0xd0, 0xa3, 0x81, 0x28, 0xdc, 0xd5, 0x84, 0xae, 0x55, 0x28, 0x13, 0x9e,
747     0xc6, 0xd8, 0xf4, 0x67, 0xd6, 0x0d, 0xd4, 0x69, 0xac, 0xf6, 0x35, 0x95,
748     0x99, 0x44, 0x26, 0x72, 0x36, 0x55, 0xf9, 0x42, 0xa6, 0x1b, 0x00, 0x93,
749     0x00, 0x19, 0x2f, 0x70, 0xd3, 0x16, 0x66, 0x4e, 0x80, 0xbb, 0xb6, 0x84,
750     0xa1, 0x2c, 0x09, 0xfb, 0x41, 0xdf, 0x63, 0xde, 0x62, 0x3e, 0xd0, 0xa8,
751     0xd8, 0x0c, 0x03, 0x06, 0xa9, 0x82, 0x17, 0x9c, 0xd2, 0xa9, 0xd5, 0x6f,
752     0xcc, 0xc0, 0xf2, 0x5d, 0xb1, 0xba, 0xf8, 0x2e, 0x37, 0x8b, 0xe6, 0x5d,
753     0x9f, 0x1b, 0xfb, 0x53, 0x0a, 0x96, 0xbe, 0x69, 0x31, 0x19, 0x8f, 0x44,
754     0x1b, 0xc2, 0x42, 0x7e, 0x65, 0x12, 0x1d, 0x52, 0x1e, 0xe2, 0xc0, 0x86,
755     0x70, 0x88, 0xe5, 0xf6, 0x87, 0x5d, 0x03, 0x4b, 0x12, 0x3c, 0x2d, 0xaf,
756     0x09, 0xf5, 0x4f, 0x82, 0x2e, 0x2e, 0xbe, 0x07, 0xe8, 0x8d, 0x57, 0x6e,
757     0xc0, 0xeb, 0xf9, 0x37, 0xac, 0x89, 0x01, 0xb7, 0xc6, 0x52, 0x1c, 0x86,
758     0xe5, 0xbc, 0x1f, 0xbd, 0xde, 0xa2, 0x42, 0xb6, 0x73, 0x85, 0x6f, 0x06,
759     0x36, 0x56, 0x40, 0x2b, 0xea, 0x16, 0x8c, 0xf4, 0x7b, 0x65, 0x6a, 0xca,
760     0x3c, 0x56, 0x68, 0x01, 0xe3, 0x9c, 0xbb, 0xb9, 0x45, 0x54, 0xcd, 0x13,
761     0x74, 0xad, 0x80, 0x40, 0xbc, 0xd0, 0x74, 0xb4, 0x31, 0xe4, 0xca, 0xd5,
762     0xf8, 0x4f, 0x08, 0x5b, 0xc4, 0x15, 0x1a, 0x51, 0x3b, 0xc6, 0x40, 0xc8,
763     0xea, 0x76, 0x30, 0x95, 0xb7, 0x76, 0xa4, 0xda, 0x20, 0xdb, 0x75, 0x1c,
764     0xf4, 0x87, 0x24, 0x29, 0x54, 0xc6, 0x59, 0x0c, 0xf0, 0xed, 0xf5, 0x3d,
765     0xce, 0x95, 0x23, 0x30, 0x49, 0x91, 0xa7, 0x7b, 0x22, 0xb5, 0xd7, 0x71,
766     0xb0, 0x60, 0xe1, 0xf0, 0x84, 0x74, 0x0e, 0x2f, 0xa8, 0x79, 0x35, 0xb9,
767     0x03, 0xb5, 0x2c, 0xdc, 0x60, 0x48, 0x12, 0xd9, 0x14, 0x5a, 0x58, 0x5d,
768     0x95, 0xc6, 0x47, 0xfd, 0xaf, 0x09, 0xc2, 0x67, 0xa5, 0x09, 0xae, 0xff,
769     0x4b, 0xd5, 0x6c, 0x2f, 0x1d, 0x33, 0x31, 0xcb, 0xdb, 0xcf, 0xf5, 0xf6,
770     0xbc, 0x90, 0xb2, 0x15, 0xd4, 0x34, 0xeb, 0xde, 0x0e, 0x8f, 0x3d, 0xea,
771     0xa4, 0x9b, 0x29, 0x8a, 0xf9, 0x4a, 0xac, 0x38, 0x1e, 0x46, 0xb2, 0x2d,
772     0xa2, 0x61, 0xc5, 0x99, 0x5e, 0x85, 0x36, 0x85, 0xb0, 0xb1, 0x6b, 0xc4,
773     0x06, 0x68, 0xc7, 0x9b, 0x54, 0xb9, 0xc8, 0x9d, 0xf3, 0x1a, 0xe0, 0x67,
774     0x0e, 0x4d, 0x5c, 0x13, 0x54, 0xa4, 0x62, 0x62, 0x6f, 0xae, 0x0e, 0x86,
775     0xa2, 0xe0, 0x31, 0xc7, 0x72, 0xa1, 0xbb, 0x87, 0x3e, 0x61, 0x96, 0xb7,
776     0x53, 0xf9, 0x34, 0xcb, 0xfd, 0x6c, 0x67, 0x25, 0x73, 0x61, 0x75, 0x4f,
777     0xab, 0x37, 0x08, 0xef, 0x35, 0x5a, 0x03, 0xe5, 0x08, 0x43, 0xec, 0xdc,
778     0xb5, 0x2c, 0x1f, 0xe6, 0xeb, 0xc6, 0x06, 0x0b, 0xed, 0xad, 0x74, 0xf4,
779     0x55, 0xef, 0xe0, 0x2e, 0x83, 0x00, 0xdb, 0x32, 0xde, 0xe9, 0xe4, 0x2f,
780     0xf5, 0x20, 0x6d, 0x72, 0x47, 0xf4, 0x68, 0xa6, 0x7f, 0x3e, 0x6a, 0x5a,
781     0x21, 0x76, 0x31, 0x97, 0xa0, 0xc6, 0x7d, 0x03, 0xf7, 0x27, 0x45, 0x5a,
782     0x75, 0x03, 0xc1, 0x5c, 0x94, 0x2b, 0x37, 0x9f, 0x46, 0x8f, 0xc3, 0xa7,
783     0x50, 0xe4, 0xe7, 0x23, 0xf7, 0x20, 0xa2, 0x8e, 0x4b, 0xfd, 0x7a, 0xa7,
784     0x8a, 0x54, 0x7b, 0x32, 0xef, 0x0e, 0x82, 0xb9, 0xf9, 0x14, 0x62, 0x68,
785     0x32, 0x9e, 0x55, 0xc0, 0xd8, 0xc7, 0x41, 0x9c, 0x67, 0x95, 0xbf, 0xc3,
786     0x86, 0x74, 0x70, 0x64, 0x44, 0x23, 0x77, 0x79, 0x82, 0x23, 0x1c, 0xf4,
787     0xa1, 0x05, 0xd3, 0x98, 0x89, 0xde, 0x7d, 0xb3, 0x5b, 0xef, 0x38, 0xd2,
788     0x07, 0xbc, 0x5a, 0x69, 0xa3, 0xe4, 0x37, 0x9b, 0x53, 0xff, 0x04, 0x6b,
789     0xd9, 0xd8, 0x32, 0x89, 0xf7, 0x82, 0x77, 0xcf, 0xe6, 0xff, 0xf4, 0x15,
790     0x54, 0x91, 0x65, 0x96, 0x49, 0xd7, 0x0a, 0xa4, 0xf3, 0x55, 0x2b, 0xc1,
791     0x48, 0xc1, 0x7e, 0x56, 0x69, 0x27, 0xf4, 0xd1, 0x47, 0x1f, 0xde, 0x86,
792     0x15, 0x67, 0x04, 0x9d, 0x41, 0x1f, 0xe8, 0xe1, 0x23, 0xe4, 0x56, 0xb9,
793     0xdb, 0x4e, 0xe4, 0x84, 0x6c, 0x63, 0x39, 0xad, 0x44, 0x6d, 0x4e, 0x28,
794     0xcd, 0xf6, 0xac, 0xec, 0xc2, 0xad, 0xcd, 0xc3, 0xed, 0x03, 0x63, 0x5d,
795     0xef, 0x1d, 0x40, 0x8d, 0x9a, 0x02, 0x67, 0x4b, 0x55, 0xb5, 0xfe, 0x75,
796     0xb6, 0x53, 0x34, 0x1d, 0x7b, 0x26, 0x23, 0xfe, 0xb9, 0x21, 0xd3, 0xe0,
797     0xa0, 0x1a, 0x85, 0xe5
798 };
799 
800 static const unsigned char stream_10b[1300] = {
801     0x18, 0x00, 0xd7, 0xfb, 0x12, 0xda, 0xdb, 0x68, 0xeb, 0x38, 0x4d, 0xf6,
802     0xb2, 0x45, 0x74, 0x4c, 0xcc, 0xe7, 0xa7, 0xc1, 0x26, 0x84, 0x3d, 0xdf,
803     0x7d, 0xc5, 0xe9, 0xd4, 0x31, 0xa2, 0x51, 0x38, 0x95, 0xe2, 0x68, 0x11,
804     0x9d, 0xd1, 0x52, 0xb5, 0xef, 0x76, 0xe0, 0x3d, 0x11, 0x50, 0xd7, 0xb2,
805     0xc1, 0x7d, 0x12, 0xaf, 0x02, 0x52, 0x97, 0x03, 0xf3, 0x2e, 0x54, 0xdf,
806     0xa0, 0x40, 0x76, 0x52, 0x82, 0x23, 0x3c, 0xbd, 0x20, 0x6d, 0x0a, 0x6f,
807     0x81, 0xfc, 0x41, 0x9d, 0x2e, 0xa7, 0x2c, 0x78, 0x9c, 0xd8, 0x56, 0xb0,
808     0x31, 0x35, 0xc8, 0x53, 0xef, 0xf9, 0x43, 0x17, 0xc0, 0x8c, 0x2c, 0x8f,
809     0x4a, 0x68, 0xe8, 0x9f, 0xbd, 0x3f, 0xf2, 0x18, 0xb8, 0xe6, 0x55, 0xea,
810     0x2a, 0x37, 0x3e, 0xac, 0xb0, 0x75, 0xd4, 0x75, 0x12, 0x82, 0xec, 0x21,
811     0xb9, 0xce, 0xe5, 0xc1, 0x62, 0x49, 0xd5, 0xf1, 0xca, 0xd4, 0x32, 0x76,
812     0x34, 0x5f, 0x3e, 0xc9, 0xb3, 0x54, 0xe4, 0xd0, 0xa9, 0x7d, 0x0c, 0x64,
813     0x48, 0x0a, 0x74, 0x38, 0x03, 0xd0, 0x20, 0xac, 0xe3, 0x58, 0x3d, 0x4b,
814     0xa7, 0x46, 0xac, 0x57, 0x63, 0x12, 0x17, 0xcb, 0x96, 0xed, 0xc9, 0x39,
815     0x64, 0xde, 0xff, 0xc6, 0xb2, 0x40, 0x2c, 0xf9, 0x1d, 0xa6, 0x94, 0x2a,
816     0x16, 0x4d, 0x7f, 0x22, 0x91, 0x8b, 0xfe, 0x83, 0x77, 0x02, 0x68, 0x62,
817     0x27, 0x77, 0x2e, 0xe9, 0xce, 0xbc, 0x20, 0xe8, 0xfb, 0xf8, 0x4e, 0x17,
818     0x07, 0xe1, 0xaa, 0x29, 0xb7, 0x50, 0xcf, 0xb0, 0x6a, 0xcf, 0x01, 0xec,
819     0xbf, 0xff, 0xb5, 0x9f, 0x00, 0x64, 0x80, 0xbb, 0xa6, 0xe4, 0xa2, 0x1e,
820     0xe4, 0xf8, 0xa3, 0x0d, 0xc7, 0x65, 0x45, 0xb7, 0x01, 0x33, 0x80, 0x37,
821     0x11, 0x16, 0x34, 0xc1, 0x06, 0xc5, 0xd3, 0xc4, 0x70, 0x62, 0x75, 0xd8,
822     0xa3, 0xba, 0x84, 0x9f, 0x81, 0x9f, 0xda, 0x01, 0x83, 0x42, 0x84, 0x05,
823     0x69, 0x68, 0xb0, 0x74, 0x73, 0x0f, 0x68, 0x39, 0xd3, 0x11, 0xc5, 0x55,
824     0x3e, 0xf2, 0xb7, 0xf4, 0xa6, 0xed, 0x0b, 0x50, 0xbe, 0x44, 0xf8, 0x67,
825     0x48, 0x46, 0x5e, 0x71, 0x07, 0xcf, 0xca, 0x8a, 0xbc, 0xa4, 0x3c, 0xd2,
826     0x4a, 0x80, 0x2e, 0x4f, 0xc5, 0x3b, 0x61, 0xc1, 0x7e, 0x93, 0x9e, 0xe0,
827     0x05, 0xfb, 0x10, 0xe8, 0x53, 0xff, 0x16, 0x5e, 0x18, 0xe0, 0x9f, 0x39,
828     0xbf, 0xaa, 0x80, 0x6d, 0xb7, 0x9f, 0x51, 0x91, 0xa0, 0xf6, 0xce, 0xad,
829     0xed, 0x56, 0x15, 0xb9, 0x12, 0x57, 0x60, 0xa6, 0xae, 0x54, 0x6e, 0x36,
830     0xf3, 0xe0, 0x05, 0xd8, 0x3e, 0x6d, 0x08, 0x36, 0xc9, 0x79, 0x64, 0x51,
831     0x63, 0x92, 0xa8, 0xa1, 0xbf, 0x55, 0x26, 0x80, 0x75, 0x44, 0x33, 0x33,
832     0xfb, 0xb7, 0xec, 0xf9, 0xc6, 0x01, 0xf9, 0xd5, 0x93, 0xfc, 0xb7, 0x43,
833     0xa2, 0x38, 0x0d, 0x17, 0x75, 0x67, 0xec, 0xc9, 0x98, 0xd6, 0x25, 0xe6,
834     0xb9, 0xed, 0x61, 0xa4, 0xee, 0x2c, 0xda, 0x27, 0xbd, 0xff, 0x86, 0x1e,
835     0x45, 0x64, 0xfe, 0xcf, 0x0c, 0x9b, 0x7b, 0x75, 0x5f, 0xf1, 0xe0, 0xba,
836     0x77, 0x8c, 0x03, 0x8f, 0xb4, 0x3a, 0xb6, 0x9c, 0xda, 0x9a, 0x83, 0xcb,
837     0xe9, 0xcb, 0x3f, 0xf4, 0x10, 0x99, 0x5b, 0xe1, 0x19, 0x8f, 0x6b, 0x95,
838     0x50, 0xe6, 0x78, 0xc9, 0x35, 0xb6, 0x87, 0xd8, 0x9e, 0x17, 0x30, 0x96,
839     0x70, 0xa3, 0x04, 0x69, 0x1c, 0xa2, 0x6c, 0xd4, 0x88, 0x48, 0x44, 0x14,
840     0x94, 0xd4, 0xc9, 0x4d, 0xe3, 0x82, 0x7e, 0x62, 0xf0, 0x0a, 0x18, 0x4d,
841     0xd0, 0xd6, 0x63, 0xa3, 0xdf, 0xea, 0x28, 0xf4, 0x00, 0x75, 0x70, 0x78,
842     0x08, 0x70, 0x3f, 0xff, 0x84, 0x86, 0x72, 0xea, 0x4f, 0x15, 0x8c, 0x17,
843     0x60, 0x5f, 0xa1, 0x50, 0xa0, 0xfc, 0x6f, 0x8a, 0x46, 0xfc, 0x01, 0x8d,
844     0x7c, 0xdc, 0x69, 0x6a, 0xd3, 0x74, 0x69, 0x76, 0x77, 0xdd, 0xe4, 0x9c,
845     0x49, 0x1e, 0x6f, 0x7d, 0x31, 0x14, 0xd9, 0xe9, 0xe7, 0x17, 0x66, 0x82,
846     0x1b, 0xf1, 0x0f, 0xe2, 0xba, 0xd2, 0x28, 0xd1, 0x6f, 0x48, 0xc7, 0xac,
847     0x08, 0x4e, 0xee, 0x94, 0x66, 0x99, 0x34, 0x16, 0x5d, 0x95, 0xae, 0xe3,
848     0x59, 0x79, 0x7f, 0x8e, 0x9f, 0xe3, 0xdb, 0xff, 0xdc, 0x4d, 0xb0, 0xbf,
849     0xf9, 0xf3, 0x3e, 0xec, 0xcf, 0x50, 0x3d, 0x2d, 0xba, 0x94, 0x1f, 0x1a,
850     0xab, 0xa4, 0xf4, 0x67, 0x43, 0x7e, 0xb9, 0x65, 0x20, 0x13, 0xb1, 0xd9,
851     0x88, 0x4a, 0x24, 0x13, 0x84, 0x86, 0xae, 0x2b, 0x0c, 0x6c, 0x7e, 0xd4,
852     0x25, 0x6e, 0xaa, 0x8d, 0x0c, 0x54, 0x99, 0xde, 0x1d, 0xac, 0x8c, 0x5c,
853     0x73, 0x94, 0xd9, 0x75, 0xcb, 0x5a, 0x54, 0x3d, 0xeb, 0xff, 0xc1, 0x95,
854     0x53, 0xb5, 0x39, 0xf7, 0xe5, 0xf1, 0x77, 0xd1, 0x42, 0x82, 0x4b, 0xb0,
855     0xab, 0x19, 0x28, 0xff, 0x53, 0x28, 0x87, 0x46, 0xc6, 0x6f, 0x05, 0x06,
856     0xa6, 0x0c, 0x97, 0x93, 0x68, 0x38, 0xe1, 0x61, 0xed, 0xf8, 0x90, 0x13,
857     0xa3, 0x6f, 0xf2, 0x08, 0x37, 0xd7, 0x05, 0x25, 0x34, 0x43, 0x57, 0x72,
858     0xfd, 0x6c, 0xc2, 0x19, 0x26, 0xe7, 0x50, 0x30, 0xb8, 0x6d, 0x09, 0x71,
859     0x83, 0x75, 0xd4, 0x11, 0x25, 0x29, 0xc6, 0xee, 0xb2, 0x51, 0x1c, 0x1c,
860     0x9e, 0x2d, 0x09, 0xb9, 0x73, 0x2b, 0xbf, 0xda, 0xc8, 0x1e, 0x2b, 0xe5,
861     0x3f, 0x1e, 0x63, 0xe9, 0xc0, 0x6d, 0x04, 0x3a, 0x48, 0x61, 0xa8, 0xc6,
862     0x16, 0x8d, 0x69, 0xc0, 0x67, 0x0c, 0x3b, 0xc4, 0x05, 0x36, 0xa1, 0x30,
863     0x62, 0x92, 0x4d, 0x44, 0x31, 0x66, 0x46, 0xda, 0xef, 0x0f, 0x4e, 0xfb,
864     0x78, 0x6a, 0xa9, 0x5b, 0xf8, 0x56, 0x26, 0x74, 0x16, 0xab, 0x17, 0x93,
865     0x3c, 0x36, 0xbb, 0xa2, 0xbf, 0xad, 0xba, 0xb1, 0xfe, 0xc4, 0x9f, 0x75,
866     0x47, 0x1e, 0x99, 0x7e, 0x32, 0xe8, 0xd4, 0x6c, 0xa4, 0xf8, 0xd2, 0xe4,
867     0xb2, 0x51, 0xbb, 0xb2, 0xd7, 0xce, 0x94, 0xaf, 0x7f, 0xe6, 0x2c, 0x13,
868     0xae, 0xd2, 0x29, 0x30, 0x7b, 0xfd, 0x25, 0x61, 0xf9, 0xe8, 0x35, 0x2d,
869     0x1a, 0xc9, 0x81, 0xa5, 0xfe, 0xce, 0xf6, 0x17, 0xc5, 0xfb, 0x8c, 0x79,
870     0x67, 0xa8, 0x5f, 0x5c, 0x31, 0xbc, 0xfc, 0xf3, 0x6b, 0xd3, 0x0d, 0xe0,
871     0x62, 0xab, 0x86, 0xc3, 0x17, 0x5a, 0xba, 0x97, 0x86, 0x8f, 0x65, 0xd6,
872     0xbd, 0x0c, 0xa1, 0xfb, 0x7f, 0x7c, 0xdc, 0xcb, 0x94, 0x30, 0x0b, 0x04,
873     0x54, 0xc4, 0x31, 0xa1, 0xca, 0x1e, 0xc5, 0xf0, 0xb6, 0x08, 0xd7, 0x2e,
874     0xa1, 0x90, 0x41, 0xce, 0xd9, 0xef, 0x3a, 0x58, 0x01, 0x1a, 0x73, 0x18,
875     0xad, 0xdc, 0x20, 0x25, 0x95, 0x1a, 0xfe, 0x61, 0xf1, 0x58, 0x32, 0x8b,
876     0x43, 0x59, 0xd6, 0x21, 0xdb, 0xa9, 0x8e, 0x54, 0xe6, 0x21, 0xcf, 0xd3,
877     0x6b, 0x59, 0x29, 0x9b, 0x3e, 0x6c, 0x7f, 0xe2, 0x29, 0x72, 0x8c, 0xd1,
878     0x3e, 0x9a, 0x84, 0x98, 0xb0, 0xf3, 0x20, 0x30, 0x34, 0x71, 0xa7, 0x5b,
879     0xf0, 0x26, 0xe1, 0xf4, 0x76, 0x65, 0xc9, 0xd7, 0xe4, 0xb9, 0x25, 0x48,
880     0xc2, 0x7e, 0xa6, 0x0b, 0x0d, 0x05, 0x68, 0xa1, 0x96, 0x61, 0x0b, 0x4c,
881     0x2f, 0x1a, 0xe3, 0x56, 0x71, 0x89, 0x48, 0x66, 0xd8, 0xd0, 0x69, 0x37,
882     0x7a, 0xdf, 0xdb, 0xed, 0xad, 0x82, 0xaa, 0x40, 0x25, 0x47, 0x3e, 0x75,
883     0xa6, 0x0e, 0xf5, 0x2f, 0xa7, 0x4e, 0x97, 0xa2, 0x5f, 0x01, 0x99, 0x48,
884     0x3a, 0x63, 0x18, 0x20, 0x61, 0x72, 0xe4, 0xcf, 0x4b, 0x3b, 0x99, 0x36,
885     0xe1, 0xf3, 0xbf, 0xae, 0x2b, 0x6b, 0xa1, 0x94, 0xa0, 0x15, 0x94, 0xd6,
886     0xe0, 0xba, 0x71, 0xa2, 0x85, 0xa0, 0x8c, 0x5e, 0x58, 0xe2, 0xde, 0x6b,
887     0x08, 0x68, 0x90, 0x82, 0x71, 0x8d, 0xfd, 0x12, 0xa2, 0x49, 0x87, 0x70,
888     0xee, 0x2a, 0x08, 0xe2, 0x26, 0xaf, 0xeb, 0x85, 0x35, 0xd2, 0x0e, 0xfd,
889     0x2b, 0x6f, 0xc0, 0xfe, 0x41, 0xbb, 0xd7, 0x0a, 0xa3, 0x8d, 0x8b, 0xec,
890     0x44, 0x9f, 0x46, 0x59, 0x4d, 0xac, 0x04, 0x1e, 0xde, 0x10, 0x7b, 0x17,
891     0x0a, 0xb0, 0xcc, 0x26, 0x0c, 0xa9, 0x3c, 0x5f, 0xd8, 0xe6, 0x52, 0xd3,
892     0xfd, 0x0b, 0x66, 0x75, 0x06, 0x84, 0x23, 0x64, 0x2b, 0x80, 0x68, 0xf9,
893     0xcb, 0xcd, 0x04, 0x07, 0xf7, 0xe0, 0x07, 0xb4, 0xc6, 0xa0, 0x08, 0xd0,
894     0x76, 0x16, 0x77, 0xd8, 0x48, 0xf0, 0x45, 0x4e, 0xe2, 0xf2, 0x88, 0xcd,
895     0x0f, 0xbd, 0x7d, 0xb6, 0xbe, 0x4e, 0x9e, 0x5d, 0x6c, 0x47, 0x26, 0x34,
896     0x94, 0xfb, 0xc5, 0x4f, 0x5c, 0xb5, 0xb5, 0xfc, 0x99, 0x34, 0x71, 0xe5,
897     0xe1, 0x36, 0x0c, 0xd2, 0x95, 0xb8, 0x93, 0x3c, 0x5d, 0x2d, 0x71, 0x55,
898     0x0b, 0x96, 0x4e, 0x9f, 0x07, 0x9a, 0x38, 0x9a, 0xcc, 0x24, 0xb5, 0xac,
899     0x05, 0x8b, 0x1c, 0x61, 0xd4, 0xf2, 0xdf, 0x9e, 0x11, 0xe3, 0x7d, 0x64,
900     0x2f, 0xe5, 0x13, 0xd4, 0x0a, 0xe9, 0x32, 0x26, 0xa8, 0x93, 0x21, 0x59,
901     0xf3, 0x41, 0x48, 0x0a, 0xbd, 0x59, 0x8f, 0xf8, 0x72, 0xab, 0xd3, 0x65,
902     0x8e, 0xdc, 0xaa, 0x0c, 0xc0, 0x01, 0x36, 0xb7, 0xf5, 0x84, 0x27, 0x9a,
903     0x98, 0x89, 0x73, 0x3a, 0xeb, 0x55, 0x15, 0xc9, 0x3d, 0xe1, 0xf8, 0xea,
904     0xf6, 0x11, 0x28, 0xe0, 0x80, 0x93, 0xcc, 0xba, 0xe1, 0xf1, 0x81, 0xbc,
905     0xa4, 0x30, 0xbc, 0x98, 0xe8, 0x9e, 0x8d, 0x17, 0x7e, 0xb7, 0xb1, 0x27,
906     0x6f, 0xcf, 0x9c, 0x0d, 0x1d, 0x01, 0xea, 0x45, 0xc0, 0x90, 0xda, 0x53,
907     0xf6, 0xde, 0xdf, 0x12, 0xa1, 0x23, 0x3d, 0x92, 0x89, 0x77, 0xa7, 0x2a,
908     0xe7, 0x45, 0x24, 0xdd, 0xf2, 0x17, 0x10, 0xca, 0x6e, 0x14, 0xb2, 0x77,
909     0x08, 0xc4, 0x18, 0xcd
910 };
911 
912 static uint64_t stream_10a_off, stream_10b_off;
913 
check_stream_10a(struct helper * h)914 static int check_stream_10a(struct helper *h)
915 {
916     /*
917      * Must have filled or almost filled the packet (using default MDPL of
918      * 1200).
919      */
920     if (!TEST_uint64_t_ge(h->frame.stream.len, 1150)
921         || !TEST_uint64_t_le(h->frame.stream.len, 1200))
922         return 0;
923 
924     if (!TEST_mem_eq(h->frame.stream.data, (size_t)h->frame.stream.len,
925             stream_10a, (size_t)h->frame.stream.len))
926         return 0;
927 
928     stream_10a_off = h->frame.stream.offset + h->frame.stream.len;
929     return 1;
930 }
931 
check_stream_10b(struct helper * h)932 static int check_stream_10b(struct helper *h)
933 {
934     if (!TEST_uint64_t_ge(h->frame.stream.len, 1150)
935         || !TEST_uint64_t_le(h->frame.stream.len, 1200))
936         return 0;
937 
938     if (!TEST_mem_eq(h->frame.stream.data, (size_t)h->frame.stream.len,
939             stream_10b, (size_t)h->frame.stream.len))
940         return 0;
941 
942     stream_10b_off = h->frame.stream.offset + h->frame.stream.len;
943     return 1;
944 }
945 
check_stream_10c(struct helper * h)946 static int check_stream_10c(struct helper *h)
947 {
948     if (!TEST_uint64_t_ge(h->frame.stream.len, 5)
949         || !TEST_uint64_t_le(h->frame.stream.len, 200))
950         return 0;
951 
952     if (!TEST_mem_eq(h->frame.stream.data, (size_t)h->frame.stream.len,
953             stream_10a + stream_10a_off, (size_t)h->frame.stream.len))
954         return 0;
955 
956     return 1;
957 }
958 
check_stream_10d(struct helper * h)959 static int check_stream_10d(struct helper *h)
960 {
961     if (!TEST_uint64_t_ge(h->frame.stream.len, 5)
962         || !TEST_uint64_t_le(h->frame.stream.len, 200))
963         return 0;
964 
965     if (!TEST_mem_eq(h->frame.stream.data, (size_t)h->frame.stream.len,
966             stream_10b + stream_10b_off, (size_t)h->frame.stream.len))
967         return 0;
968 
969     return 1;
970 }
971 
972 static const struct script_op script_10[] = {
973     OP_PROVIDE_SECRET(QUIC_ENC_LEVEL_1RTT, QRL_SUITE_AES128GCM, secret_1)
974         OP_HANDSHAKE_COMPLETE()
975             OP_TXP_GENERATE_NONE()
976                 OP_STREAM_NEW(42)
977                     OP_STREAM_NEW(43)
978                         OP_CONN_TXFC_BUMP(10000)
979                             OP_STREAM_TXFC_BUMP(42, 5000)
980                                 OP_STREAM_TXFC_BUMP(43, 5000)
981                                     OP_STREAM_SEND(42, stream_10a)
982                                         OP_STREAM_SEND(43, stream_10b)
983 
984     /* First packet containing data from stream 42 */
985     OP_TXP_GENERATE()
986         OP_RX_PKT()
987             OP_EXPECT_DGRAM_LEN(1100, 1200)
988                 OP_NEXT_FRAME()
989                     OP_EXPECT_FRAME(OSSL_QUIC_FRAME_TYPE_STREAM)
990                         OP_CHECK(check_stream_10a)
991                             OP_EXPECT_NO_FRAME()
992 
993     /* Second packet containing data from stream 43 */
994     OP_TXP_GENERATE()
995         OP_RX_PKT()
996             OP_EXPECT_DGRAM_LEN(1100, 1200)
997                 OP_NEXT_FRAME()
998                     OP_EXPECT_FRAME(OSSL_QUIC_FRAME_TYPE_STREAM)
999                         OP_CHECK(check_stream_10b)
1000                             OP_EXPECT_NO_FRAME()
1001 
1002     /* Third packet containing data from stream 42 */
1003     OP_TXP_GENERATE()
1004         OP_RX_PKT()
1005             OP_EXPECT_DGRAM_LEN(200, 500)
1006                 OP_NEXT_FRAME()
1007                     OP_EXPECT_FRAME(OSSL_QUIC_FRAME_TYPE_STREAM_OFF_LEN)
1008                         OP_CHECK(check_stream_10c)
1009                             OP_NEXT_FRAME()
1010                                 OP_EXPECT_FRAME(OSSL_QUIC_FRAME_TYPE_STREAM_OFF)
1011                                     OP_CHECK(check_stream_10d)
1012                                         OP_EXPECT_NO_FRAME()
1013 
1014                                             OP_RX_PKT_NONE()
1015                                                 OP_TXP_GENERATE_NONE()
1016 
1017                                                     OP_END
1018 };
1019 
1020 /* 11. Initial, CRYPTO */
1021 static const struct script_op script_11[] = {
1022     OP_PROVIDE_SECRET(QUIC_ENC_LEVEL_INITIAL, QRL_SUITE_AES128GCM, secret_1)
1023         OP_TXP_GENERATE_NONE()
1024             OP_CRYPTO_SEND(QUIC_PN_SPACE_INITIAL, crypto_1)
1025                 OP_TXP_GENERATE()
1026                     OP_RX_PKT()
1027                         OP_EXPECT_DGRAM_LEN(1200, 1200)
1028                             OP_NEXT_FRAME()
1029                                 OP_EXPECT_FRAME(OSSL_QUIC_FRAME_TYPE_CRYPTO)
1030                                     OP_EXPECT_NO_FRAME()
1031                                         OP_RX_PKT_NONE()
1032                                             OP_TXP_GENERATE_NONE()
1033                                                 OP_END
1034 };
1035 
1036 /* 12. 1-RTT, STOP_SENDING */
check_stream_12(struct helper * h)1037 static int check_stream_12(struct helper *h)
1038 {
1039     if (!TEST_uint64_t_eq(h->frame.stop_sending.stream_id, 42)
1040         || !TEST_uint64_t_eq(h->frame.stop_sending.app_error_code, 4568))
1041         return 0;
1042 
1043     return 1;
1044 }
1045 
1046 static const struct script_op script_12[] = {
1047     OP_PROVIDE_SECRET(QUIC_ENC_LEVEL_1RTT, QRL_SUITE_AES128GCM, secret_1)
1048         OP_HANDSHAKE_COMPLETE()
1049             OP_TXP_GENERATE_NONE()
1050                 OP_STREAM_NEW(42)
1051                     OP_STOP_SENDING(42, 4568)
1052                         OP_TXP_GENERATE()
1053                             OP_RX_PKT()
1054                                 OP_EXPECT_DGRAM_LEN(21, 128)
1055                                     OP_NEXT_FRAME()
1056                                         OP_EXPECT_FRAME(OSSL_QUIC_FRAME_TYPE_STOP_SENDING)
1057                                             OP_CHECK(check_stream_12)
1058                                                 OP_EXPECT_NO_FRAME()
1059                                                     OP_RX_PKT_NONE()
1060                                                         OP_TXP_GENERATE_NONE()
1061                                                             OP_END
1062 };
1063 
1064 /* 13. 1-RTT, RESET_STREAM */
1065 static const unsigned char stream_13[] = {
1066     0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f, 0x7a, 0x7b
1067 };
1068 
check_stream_13(struct helper * h)1069 static ossl_unused int check_stream_13(struct helper *h)
1070 {
1071     if (!TEST_uint64_t_eq(h->frame.reset_stream.stream_id, 42)
1072         || !TEST_uint64_t_eq(h->frame.reset_stream.app_error_code, 4568)
1073         || !TEST_uint64_t_eq(h->frame.reset_stream.final_size, 0))
1074         return 0;
1075 
1076     return 1;
1077 }
1078 
1079 static const struct script_op script_13[] = {
1080     OP_PROVIDE_SECRET(QUIC_ENC_LEVEL_1RTT, QRL_SUITE_AES128GCM, secret_1)
1081         OP_HANDSHAKE_COMPLETE()
1082             OP_TXP_GENERATE_NONE()
1083                 OP_STREAM_NEW(42)
1084                     OP_CONN_TXFC_BUMP(8)
1085                         OP_STREAM_TXFC_BUMP(42, 8)
1086                             OP_STREAM_SEND(42, stream_13)
1087                                 OP_RESET_STREAM(42, 4568)
1088                                     OP_TXP_GENERATE()
1089                                         OP_RX_PKT()
1090                                             OP_EXPECT_DGRAM_LEN(21, 128)
1091                                                 OP_NEXT_FRAME()
1092                                                     OP_EXPECT_FRAME(OSSL_QUIC_FRAME_TYPE_RESET_STREAM)
1093                                                         OP_CHECK(check_stream_13)
1094                                                             OP_NEXT_FRAME()
1095                                                                 OP_EXPECT_NO_FRAME()
1096                                                                     OP_RX_PKT_NONE()
1097                                                                         OP_TXP_GENERATE_NONE()
1098                                                                             OP_END
1099 };
1100 
1101 /* 14. 1-RTT, CONNECTION_CLOSE */
gen_conn_close(struct helper * h)1102 static int gen_conn_close(struct helper *h)
1103 {
1104     OSSL_QUIC_FRAME_CONN_CLOSE f = { 0 };
1105 
1106     f.error_code = 2345;
1107     f.frame_type = OSSL_QUIC_FRAME_TYPE_HANDSHAKE_DONE;
1108     f.reason = "Reason string";
1109     f.reason_len = strlen(f.reason);
1110 
1111     if (!TEST_true(ossl_quic_tx_packetiser_schedule_conn_close(h->txp, &f)))
1112         return 0;
1113 
1114     return 1;
1115 }
1116 
check_14(struct helper * h)1117 static int check_14(struct helper *h)
1118 {
1119     if (!TEST_int_eq(h->frame.conn_close.is_app, 0)
1120         || !TEST_uint64_t_eq(h->frame.conn_close.frame_type,
1121             OSSL_QUIC_FRAME_TYPE_HANDSHAKE_DONE)
1122         || !TEST_uint64_t_eq(h->frame.conn_close.error_code, 2345)
1123         || !TEST_mem_eq(h->frame.conn_close.reason, h->frame.conn_close.reason_len,
1124             "Reason string", 13))
1125         return 0;
1126 
1127     return 1;
1128 }
1129 
1130 static const struct script_op script_14[] = {
1131     OP_PROVIDE_SECRET(QUIC_ENC_LEVEL_1RTT, QRL_SUITE_AES128GCM, secret_1)
1132         OP_HANDSHAKE_COMPLETE()
1133             OP_TXP_GENERATE_NONE()
1134                 OP_CHECK(gen_conn_close)
1135                     OP_TXP_GENERATE()
1136                         OP_RX_PKT()
1137                             OP_EXPECT_DGRAM_LEN(21, 512)
1138                                 OP_NEXT_FRAME()
1139                                     OP_EXPECT_FRAME(OSSL_QUIC_FRAME_TYPE_CONN_CLOSE_TRANSPORT)
1140                                         OP_CHECK(check_14)
1141                                             OP_EXPECT_NO_FRAME()
1142                                                 OP_RX_PKT_NONE()
1143                                                     OP_END
1144 };
1145 
1146 /* 15. INITIAL, Anti-Deadlock Probe Simulation */
gen_probe_initial(struct helper * h)1147 static int gen_probe_initial(struct helper *h)
1148 {
1149     OSSL_ACKM_PROBE_INFO *probe = ossl_ackm_get0_probe_request(h->args.ackm);
1150 
1151     /*
1152      * Pretend the ACKM asked for an anti-deadlock Initial probe.
1153      * We test output of this in the ACKM unit tests.
1154      */
1155     ++probe->anti_deadlock_initial;
1156     return 1;
1157 }
1158 
1159 static const struct script_op script_15[] = {
1160     OP_PROVIDE_SECRET(QUIC_ENC_LEVEL_INITIAL, QRL_SUITE_AES128GCM, secret_1)
1161         OP_TXP_GENERATE_NONE()
1162             OP_CHECK(gen_probe_initial)
1163                 OP_TXP_GENERATE()
1164                     OP_RX_PKT()
1165                         OP_EXPECT_DGRAM_LEN(1200, 1200)
1166                             OP_NEXT_FRAME()
1167                                 OP_EXPECT_FRAME(OSSL_QUIC_FRAME_TYPE_PING)
1168                                     OP_EXPECT_NO_FRAME()
1169                                         OP_RX_PKT_NONE()
1170                                             OP_TXP_GENERATE_NONE()
1171                                                 OP_END
1172 };
1173 
1174 /* 16. HANDSHAKE, Anti-Deadlock Probe Simulation */
gen_probe_handshake(struct helper * h)1175 static int gen_probe_handshake(struct helper *h)
1176 {
1177     OSSL_ACKM_PROBE_INFO *probe = ossl_ackm_get0_probe_request(h->args.ackm);
1178 
1179     /*
1180      * Pretend the ACKM asked for an anti-deadlock Handshake probe.
1181      * We test output of this in the ACKM unit tests.
1182      */
1183     ++probe->anti_deadlock_handshake;
1184     return 1;
1185 }
1186 
1187 static const struct script_op script_16[] = {
1188     OP_DISCARD_EL(QUIC_ENC_LEVEL_INITIAL)
1189         OP_PROVIDE_SECRET(QUIC_ENC_LEVEL_HANDSHAKE, QRL_SUITE_AES128GCM, secret_1)
1190             OP_TXP_GENERATE_NONE()
1191                 OP_CHECK(gen_probe_handshake)
1192                     OP_TXP_GENERATE()
1193                         OP_RX_PKT()
1194                             OP_EXPECT_DGRAM_LEN(21, 512)
1195                                 OP_NEXT_FRAME()
1196                                     OP_EXPECT_FRAME(OSSL_QUIC_FRAME_TYPE_PING)
1197                                         OP_EXPECT_NO_FRAME()
1198                                             OP_RX_PKT_NONE()
1199                                                 OP_TXP_GENERATE_NONE()
1200                                                     OP_END
1201 };
1202 
1203 /* 17. 1-RTT, Probe Simulation */
gen_probe_1rtt(struct helper * h)1204 static int gen_probe_1rtt(struct helper *h)
1205 {
1206     OSSL_ACKM_PROBE_INFO *probe = ossl_ackm_get0_probe_request(h->args.ackm);
1207 
1208     /*
1209      * Pretend the ACKM asked for a 1-RTT PTO probe.
1210      * We test output of this in the ACKM unit tests.
1211      */
1212     ++probe->pto[QUIC_PN_SPACE_APP];
1213     return 1;
1214 }
1215 
1216 static const struct script_op script_17[] = {
1217     OP_DISCARD_EL(QUIC_ENC_LEVEL_INITIAL)
1218         OP_DISCARD_EL(QUIC_ENC_LEVEL_HANDSHAKE)
1219             OP_PROVIDE_SECRET(QUIC_ENC_LEVEL_1RTT, QRL_SUITE_AES128GCM, secret_1)
1220                 OP_TXP_GENERATE_NONE()
1221                     OP_CHECK(gen_probe_1rtt)
1222                         OP_TXP_GENERATE()
1223                             OP_RX_PKT()
1224                                 OP_EXPECT_DGRAM_LEN(21, 512)
1225                                     OP_NEXT_FRAME()
1226                                         OP_EXPECT_FRAME(OSSL_QUIC_FRAME_TYPE_PING)
1227                                             OP_EXPECT_NO_FRAME()
1228                                                 OP_RX_PKT_NONE()
1229                                                     OP_TXP_GENERATE_NONE()
1230                                                         OP_END
1231 };
1232 
1233 /* 18. Big Token Rejection */
1234 static const unsigned char big_token[1950];
1235 
try_big_token(struct helper * h)1236 static int try_big_token(struct helper *h)
1237 {
1238     size_t i;
1239 
1240     /* Ensure big token is rejected */
1241     if (!TEST_false(ossl_quic_tx_packetiser_set_initial_token(h->txp,
1242             big_token,
1243             sizeof(big_token),
1244             NULL,
1245             NULL)))
1246         return 0;
1247 
1248     /*
1249      * Keep trying until we find an acceptable size, then make sure
1250      * that works for generation
1251      */
1252     for (i = sizeof(big_token) - 1;; --i) {
1253         if (!TEST_size_t_gt(i, 0))
1254             return 0;
1255 
1256         if (ossl_quic_tx_packetiser_set_initial_token(h->txp, big_token, i,
1257                 NULL, NULL))
1258             break;
1259     }
1260 
1261     return 1;
1262 }
1263 
1264 static const struct script_op script_18[] = {
1265     OP_PROVIDE_SECRET(QUIC_ENC_LEVEL_INITIAL, QRL_SUITE_AES128GCM, secret_1)
1266         OP_TXP_GENERATE_NONE()
1267             OP_CHECK(try_big_token)
1268                 OP_TXP_GENERATE_NONE()
1269                     OP_CRYPTO_SEND(QUIC_PN_SPACE_INITIAL, crypto_1)
1270                         OP_TXP_GENERATE()
1271                             OP_RX_PKT()
1272                                 OP_EXPECT_DGRAM_LEN(1200, 1200)
1273                                     OP_NEXT_FRAME()
1274                                         OP_EXPECT_FRAME(OSSL_QUIC_FRAME_TYPE_CRYPTO)
1275                                             OP_EXPECT_NO_FRAME()
1276                                                 OP_RX_PKT_NONE()
1277                                                     OP_TXP_GENERATE_NONE()
1278                                                         OP_END
1279 };
1280 
1281 static const struct script_op *const scripts[] = {
1282     script_1,
1283     script_2,
1284     script_3,
1285     script_4,
1286     script_5,
1287     script_6,
1288     script_7,
1289     script_8,
1290     script_9,
1291     script_10,
1292     script_11,
1293     script_12,
1294     script_13,
1295     script_14,
1296     script_15,
1297     script_16,
1298     script_17,
1299     script_18
1300 };
1301 
skip_padding(struct helper * h)1302 static void skip_padding(struct helper *h)
1303 {
1304     uint64_t frame_type;
1305 
1306     if (!ossl_quic_wire_peek_frame_header(&h->pkt, &frame_type, NULL))
1307         return; /* EOF */
1308 
1309     if (frame_type == OSSL_QUIC_FRAME_TYPE_PADDING)
1310         ossl_quic_wire_decode_padding(&h->pkt);
1311 }
1312 
run_script(int script_idx,const struct script_op * script)1313 static int run_script(int script_idx, const struct script_op *script)
1314 {
1315     int testresult = 0, have_helper = 0;
1316     QUIC_TXP_STATUS status;
1317     struct helper h;
1318     const struct script_op *op;
1319     size_t opn = 0;
1320 
1321     if (!helper_init(&h))
1322         goto err;
1323 
1324     have_helper = 1;
1325     for (op = script, opn = 0; op->opcode != OPK_END; ++op, ++opn) {
1326         switch (op->opcode) {
1327         case OPK_TXP_GENERATE:
1328             if (!TEST_true(ossl_quic_tx_packetiser_generate(h.txp, &status))
1329                 && !TEST_size_t_gt(status.sent_pkt, 0))
1330                 goto err;
1331 
1332             ossl_qtx_finish_dgram(h.args.qtx);
1333             ossl_qtx_flush_net(h.args.qtx);
1334             break;
1335         case OPK_TXP_GENERATE_NONE:
1336             if (!TEST_true(ossl_quic_tx_packetiser_generate(h.txp, &status))
1337                 && !TEST_size_t_eq(status.sent_pkt, 0))
1338                 goto err;
1339 
1340             break;
1341         case OPK_RX_PKT:
1342             ossl_quic_demux_pump(h.demux);
1343             ossl_qrx_pkt_release(h.qrx_pkt);
1344             h.qrx_pkt = NULL;
1345             if (!TEST_true(ossl_qrx_read_pkt(h.qrx, &h.qrx_pkt)))
1346                 goto err;
1347             if (!TEST_true(PACKET_buf_init(&h.pkt,
1348                     h.qrx_pkt->hdr->data,
1349                     h.qrx_pkt->hdr->len)))
1350                 goto err;
1351             h.frame_type = UINT64_MAX;
1352             break;
1353         case OPK_RX_PKT_NONE:
1354             ossl_quic_demux_pump(h.demux);
1355             if (!TEST_false(ossl_qrx_read_pkt(h.qrx, &h.qrx_pkt)))
1356                 goto err;
1357             h.frame_type = UINT64_MAX;
1358             break;
1359         case OPK_EXPECT_DGRAM_LEN:
1360             if (!TEST_size_t_ge(h.qrx_pkt->datagram_len, (size_t)op->arg0)
1361                 || !TEST_size_t_le(h.qrx_pkt->datagram_len, (size_t)op->arg1))
1362                 goto err;
1363             break;
1364         case OPK_EXPECT_FRAME:
1365             if (!TEST_uint64_t_eq(h.frame_type, op->arg0))
1366                 goto err;
1367             break;
1368         case OPK_EXPECT_INITIAL_TOKEN:
1369             if (!TEST_mem_eq(h.qrx_pkt->hdr->token, h.qrx_pkt->hdr->token_len,
1370                     op->buf, (size_t)op->arg0))
1371                 goto err;
1372             break;
1373         case OPK_EXPECT_HDR:
1374             if (!TEST_true(cmp_pkt_hdr(h.qrx_pkt->hdr, op->buf,
1375                     NULL, 0, 0)))
1376                 goto err;
1377             break;
1378         case OPK_CHECK:
1379             if (!TEST_true(op->check_func(&h)))
1380                 goto err;
1381             break;
1382         case OPK_NEXT_FRAME:
1383             skip_padding(&h);
1384             if (!ossl_quic_wire_peek_frame_header(&h.pkt, &h.frame_type, NULL)) {
1385                 h.frame_type = UINT64_MAX;
1386                 break;
1387             }
1388 
1389             switch (h.frame_type) {
1390             case OSSL_QUIC_FRAME_TYPE_HANDSHAKE_DONE:
1391                 if (!TEST_true(ossl_quic_wire_decode_frame_handshake_done(&h.pkt)))
1392                     goto err;
1393                 break;
1394             case OSSL_QUIC_FRAME_TYPE_PING:
1395                 if (!TEST_true(ossl_quic_wire_decode_frame_ping(&h.pkt)))
1396                     goto err;
1397                 break;
1398             case OSSL_QUIC_FRAME_TYPE_MAX_DATA:
1399                 if (!TEST_true(ossl_quic_wire_decode_frame_max_data(&h.pkt,
1400                         &h.frame.max_data)))
1401                     goto err;
1402                 break;
1403             case OSSL_QUIC_FRAME_TYPE_NEW_CONN_ID:
1404                 if (!TEST_true(ossl_quic_wire_decode_frame_new_conn_id(&h.pkt,
1405                         &h.frame.new_conn_id)))
1406                     goto err;
1407                 break;
1408             case OSSL_QUIC_FRAME_TYPE_NEW_TOKEN:
1409                 if (!TEST_true(ossl_quic_wire_decode_frame_new_token(&h.pkt,
1410                         &h.frame.new_token.token,
1411                         &h.frame.new_token.token_len)))
1412                     goto err;
1413                 break;
1414             case OSSL_QUIC_FRAME_TYPE_ACK_WITH_ECN:
1415             case OSSL_QUIC_FRAME_TYPE_ACK_WITHOUT_ECN:
1416                 h.frame.ack.ack_ranges = h.ack_ranges;
1417                 h.frame.ack.num_ack_ranges = OSSL_NELEM(h.ack_ranges);
1418                 if (!TEST_true(ossl_quic_wire_decode_frame_ack(&h.pkt,
1419                         h.args.ack_delay_exponent,
1420                         &h.frame.ack,
1421                         NULL)))
1422                     goto err;
1423                 break;
1424             case OSSL_QUIC_FRAME_TYPE_CRYPTO:
1425                 if (!TEST_true(ossl_quic_wire_decode_frame_crypto(&h.pkt, 0, &h.frame.crypto)))
1426                     goto err;
1427                 break;
1428 
1429             case OSSL_QUIC_FRAME_TYPE_STREAM:
1430             case OSSL_QUIC_FRAME_TYPE_STREAM_FIN:
1431             case OSSL_QUIC_FRAME_TYPE_STREAM_LEN:
1432             case OSSL_QUIC_FRAME_TYPE_STREAM_LEN_FIN:
1433             case OSSL_QUIC_FRAME_TYPE_STREAM_OFF:
1434             case OSSL_QUIC_FRAME_TYPE_STREAM_OFF_FIN:
1435             case OSSL_QUIC_FRAME_TYPE_STREAM_OFF_LEN:
1436             case OSSL_QUIC_FRAME_TYPE_STREAM_OFF_LEN_FIN:
1437                 if (!TEST_true(ossl_quic_wire_decode_frame_stream(&h.pkt, 0, &h.frame.stream)))
1438                     goto err;
1439                 break;
1440 
1441             case OSSL_QUIC_FRAME_TYPE_STOP_SENDING:
1442                 if (!TEST_true(ossl_quic_wire_decode_frame_stop_sending(&h.pkt,
1443                         &h.frame.stop_sending)))
1444                     goto err;
1445                 break;
1446 
1447             case OSSL_QUIC_FRAME_TYPE_RESET_STREAM:
1448                 if (!TEST_true(ossl_quic_wire_decode_frame_reset_stream(&h.pkt,
1449                         &h.frame.reset_stream)))
1450                     goto err;
1451                 break;
1452 
1453             case OSSL_QUIC_FRAME_TYPE_CONN_CLOSE_TRANSPORT:
1454             case OSSL_QUIC_FRAME_TYPE_CONN_CLOSE_APP:
1455                 if (!TEST_true(ossl_quic_wire_decode_frame_conn_close(&h.pkt,
1456                         &h.frame.conn_close)))
1457                     goto err;
1458                 break;
1459 
1460             default:
1461                 TEST_error("unknown frame type");
1462                 goto err;
1463             }
1464             break;
1465         case OPK_EXPECT_NO_FRAME:
1466             skip_padding(&h);
1467             if (!TEST_size_t_eq(PACKET_remaining(&h.pkt), 0))
1468                 goto err;
1469             break;
1470         case OPK_PROVIDE_SECRET:
1471             if (!TEST_true(ossl_qtx_provide_secret(h.args.qtx,
1472                     (uint32_t)op->arg0,
1473                     (uint32_t)op->arg1,
1474                     NULL, op->buf, op->buf_len)))
1475                 goto err;
1476             if (!TEST_true(ossl_qrx_provide_secret(h.qrx,
1477                     (uint32_t)op->arg0,
1478                     (uint32_t)op->arg1,
1479                     NULL, op->buf, op->buf_len)))
1480                 goto err;
1481             break;
1482         case OPK_DISCARD_EL:
1483             if (!TEST_true(ossl_quic_tx_packetiser_discard_enc_level(h.txp,
1484                     (uint32_t)op->arg0)))
1485                 goto err;
1486             /*
1487              * We do not discard on the QRX here, the object is to test the
1488              * TXP so if the TXP does erroneously send at a discarded EL we
1489              * want to know about it.
1490              */
1491             break;
1492         case OPK_CRYPTO_SEND: {
1493             size_t consumed = 0;
1494 
1495             if (!TEST_true(ossl_quic_sstream_append(h.args.crypto[op->arg0],
1496                     op->buf, op->buf_len,
1497                     &consumed)))
1498                 goto err;
1499 
1500             if (!TEST_size_t_eq(consumed, op->buf_len))
1501                 goto err;
1502         } break;
1503         case OPK_STREAM_NEW: {
1504             QUIC_STREAM *s;
1505 
1506             if (!TEST_ptr(s = ossl_quic_stream_map_alloc(h.args.qsm, op->arg0,
1507                               QUIC_STREAM_DIR_BIDI)))
1508                 goto err;
1509 
1510             if (!TEST_ptr(s->sstream = ossl_quic_sstream_new(512 * 1024))
1511                 || !TEST_true(ossl_quic_txfc_init(&s->txfc, &h.conn_txfc))
1512                 || !TEST_true(ossl_quic_rxfc_init(&s->rxfc, &h.conn_rxfc,
1513                     1 * 1024 * 1024,
1514                     16 * 1024 * 1024,
1515                     fake_now, NULL))
1516                 || !TEST_ptr(s->rstream = ossl_quic_rstream_new(&s->rxfc,
1517                                  NULL, 1024))) {
1518                 ossl_quic_sstream_free(s->sstream);
1519                 ossl_quic_stream_map_release(h.args.qsm, s);
1520                 goto err;
1521             }
1522         } break;
1523         case OPK_STREAM_SEND: {
1524             QUIC_STREAM *s;
1525             size_t consumed = 0;
1526 
1527             if (!TEST_ptr(s = ossl_quic_stream_map_get_by_id(h.args.qsm,
1528                               op->arg0)))
1529                 goto err;
1530 
1531             if (!TEST_true(ossl_quic_sstream_append(s->sstream, op->buf,
1532                     op->buf_len, &consumed)))
1533                 goto err;
1534 
1535             if (!TEST_size_t_eq(consumed, op->buf_len))
1536                 goto err;
1537 
1538             ossl_quic_stream_map_update_state(h.args.qsm, s);
1539         } break;
1540         case OPK_STREAM_FIN: {
1541             QUIC_STREAM *s;
1542 
1543             if (!TEST_ptr(s = ossl_quic_stream_map_get_by_id(h.args.qsm,
1544                               op->arg0)))
1545                 goto err;
1546 
1547             ossl_quic_sstream_fin(s->sstream);
1548         } break;
1549         case OPK_STOP_SENDING: {
1550             QUIC_STREAM *s;
1551 
1552             if (!TEST_ptr(s = ossl_quic_stream_map_get_by_id(h.args.qsm,
1553                               op->arg0)))
1554                 goto err;
1555 
1556             if (!TEST_true(ossl_quic_stream_map_stop_sending_recv_part(h.args.qsm,
1557                     s, op->arg1)))
1558                 goto err;
1559 
1560             ossl_quic_stream_map_update_state(h.args.qsm, s);
1561 
1562             if (!TEST_true(s->active))
1563                 goto err;
1564         } break;
1565         case OPK_RESET_STREAM: {
1566             QUIC_STREAM *s;
1567 
1568             if (!TEST_ptr(s = ossl_quic_stream_map_get_by_id(h.args.qsm,
1569                               op->arg0)))
1570                 goto err;
1571 
1572             if (!TEST_true(ossl_quic_stream_map_reset_stream_send_part(h.args.qsm,
1573                     s, op->arg1)))
1574                 goto err;
1575 
1576             ossl_quic_stream_map_update_state(h.args.qsm, s);
1577 
1578             if (!TEST_true(s->active))
1579                 goto err;
1580         } break;
1581         case OPK_CONN_TXFC_BUMP:
1582             if (!TEST_true(ossl_quic_txfc_bump_cwm(h.args.conn_txfc, op->arg0)))
1583                 goto err;
1584 
1585             break;
1586         case OPK_STREAM_TXFC_BUMP: {
1587             QUIC_STREAM *s;
1588 
1589             if (!TEST_ptr(s = ossl_quic_stream_map_get_by_id(h.args.qsm,
1590                               op->arg1)))
1591                 goto err;
1592 
1593             if (!TEST_true(ossl_quic_txfc_bump_cwm(&s->txfc, op->arg0)))
1594                 goto err;
1595 
1596             ossl_quic_stream_map_update_state(h.args.qsm, s);
1597         } break;
1598         case OPK_HANDSHAKE_COMPLETE:
1599             ossl_quic_tx_packetiser_notify_handshake_complete(h.txp);
1600             break;
1601         case OPK_NOP:
1602             break;
1603         default:
1604             TEST_error("bad opcode");
1605             goto err;
1606         }
1607     }
1608 
1609     testresult = 1;
1610 err:
1611     if (!testresult)
1612         TEST_error("script %d failed at op %zu", script_idx + 1, opn + 1);
1613     if (have_helper)
1614         helper_cleanup(&h);
1615     return testresult;
1616 }
1617 
test_script(int idx)1618 static int test_script(int idx)
1619 {
1620     return run_script(idx, scripts[idx]);
1621 }
1622 
1623 /*
1624  * Dynamic Script 1.
1625  *
1626  * This script exists to test the interactions between multiple packets (ELs) in
1627  * the same datagram when there is a padding requirement (due to the datagram
1628  * containing an Initial packet). There are boundary cases which are difficult
1629  * to get right so it is important to test this entire space. Examples of such
1630  * edge cases include:
1631  *
1632  * - If we are planning on generating both an Initial and Handshake packet in a
1633  *   datagram ordinarily we would plan on adding the padding frames to meet the
1634  *   mandatory minimum size to the last packet in the datagram (i.e., the
1635  *   Handshake packet). But if the amount of room remaining in a datagram is
1636  *   e.g. only 3 bytes after generating the Initial packet, this is not
1637  *   enough room for another packet and we have a problem as having finished
1638  *   the Initial packet we have no way to add the necessary padding.
1639  *
1640  * - If we do have room for another packet but it is not enough room to encode
1641  *   any desired frame.
1642  *
1643  * This test confirms we handle these cases correctly for multi-packet datagrams
1644  * by placing two packets in a datagram and varying the size of the first
1645  * datagram.
1646  */
1647 static const unsigned char dyn_script_1_crypto_1a[1200];
1648 static const unsigned char dyn_script_1_crypto_1b[1];
1649 
check_is_initial(struct helper * h)1650 static int check_is_initial(struct helper *h)
1651 {
1652     return h->qrx_pkt->hdr->type == QUIC_PKT_TYPE_INITIAL;
1653 }
1654 
check_is_handshake(struct helper * h)1655 static int check_is_handshake(struct helper *h)
1656 {
1657     return h->qrx_pkt->hdr->type == QUIC_PKT_TYPE_HANDSHAKE;
1658 }
1659 
1660 static struct script_op dyn_script_1[] = {
1661     OP_PROVIDE_SECRET(QUIC_ENC_LEVEL_INITIAL, QRL_SUITE_AES128GCM, secret_1)
1662         OP_PROVIDE_SECRET(QUIC_ENC_LEVEL_HANDSHAKE, QRL_SUITE_AES128GCM, secret_1)
1663             OP_TXP_GENERATE_NONE()
1664                 OP_CRYPTO_SEND(QUIC_PN_SPACE_INITIAL, dyn_script_1_crypto_1a) /* [crypto_idx] */
1665     OP_CRYPTO_SEND(QUIC_PN_SPACE_HANDSHAKE, dyn_script_1_crypto_1b)
1666         OP_TXP_GENERATE()
1667             OP_RX_PKT()
1668                 OP_EXPECT_DGRAM_LEN(1200, 1200)
1669                     OP_CHECK(check_is_initial)
1670                         OP_NOP() /* [pkt_idx] */
1671     OP_NOP() /* [check_idx] */
1672     OP_END
1673 };
1674 
1675 static const size_t dyn_script_1_crypto_idx = 3;
1676 static const size_t dyn_script_1_pkt_idx = 9;
1677 static const size_t dyn_script_1_check_idx = 10;
1678 static const size_t dyn_script_1_start_from = 1000;
1679 
test_dyn_script_1(int idx)1680 static int test_dyn_script_1(int idx)
1681 {
1682     size_t target_size = dyn_script_1_start_from + (size_t)idx;
1683     int expect_handshake_pkt_in_same_dgram = (target_size <= 1115);
1684 
1685     dyn_script_1[dyn_script_1_crypto_idx].buf_len = target_size;
1686 
1687     if (expect_handshake_pkt_in_same_dgram) {
1688         dyn_script_1[dyn_script_1_pkt_idx].opcode = OPK_RX_PKT;
1689         dyn_script_1[dyn_script_1_check_idx].opcode = OPK_CHECK;
1690         dyn_script_1[dyn_script_1_check_idx].check_func = check_is_handshake;
1691     } else {
1692         dyn_script_1[dyn_script_1_pkt_idx].opcode = OPK_RX_PKT_NONE;
1693         dyn_script_1[dyn_script_1_check_idx].opcode = OPK_NOP;
1694     }
1695 
1696     if (!run_script(idx, dyn_script_1)) {
1697         TEST_error("failed dyn script 1 with target size %zu", target_size);
1698         return 0;
1699     }
1700 
1701     return 1;
1702 }
1703 
setup_tests(void)1704 int setup_tests(void)
1705 {
1706     ADD_ALL_TESTS(test_script, OSSL_NELEM(scripts));
1707     ADD_ALL_TESTS(test_dyn_script_1,
1708         OSSL_NELEM(dyn_script_1_crypto_1a)
1709             - dyn_script_1_start_from + 1);
1710     return 1;
1711 }
1712