quic_txp_test.c 63 KB

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