quic_txp_test.c 55 KB

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