quic_txp_test.c 63 KB

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