quic_txp_test.c 63 KB

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