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