quicapitest.c 73 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282
  1. /*
  2. * Copyright 2022-2024 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 <stdio.h>
  10. #include <string.h>
  11. #include <openssl/opensslconf.h>
  12. #include <openssl/quic.h>
  13. #include <openssl/rand.h>
  14. #include "helpers/ssltestlib.h"
  15. #include "helpers/quictestlib.h"
  16. #include "testutil.h"
  17. #include "testutil/output.h"
  18. #include "../ssl/ssl_local.h"
  19. #include "internal/quic_error.h"
  20. static OSSL_LIB_CTX *libctx = NULL;
  21. static OSSL_PROVIDER *defctxnull = NULL;
  22. static char *certsdir = NULL;
  23. static char *cert = NULL;
  24. static char *ccert = NULL;
  25. static char *cauthca = NULL;
  26. static char *privkey = NULL;
  27. static char *cprivkey = NULL;
  28. static char *datadir = NULL;
  29. static int is_fips = 0;
  30. /* The ssltrace test assumes some options are switched on/off */
  31. #if !defined(OPENSSL_NO_SSL_TRACE) \
  32. && defined(OPENSSL_NO_BROTLI) && defined(OPENSSL_NO_ZSTD) \
  33. && !defined(OPENSSL_NO_ECX) && !defined(OPENSSL_NO_DH)
  34. # define DO_SSL_TRACE_TEST
  35. #endif
  36. /*
  37. * Test that we read what we've written.
  38. * Test 0: Non-blocking
  39. * Test 1: Blocking
  40. * Test 2: Blocking, introduce socket error, test error handling.
  41. */
  42. static int test_quic_write_read(int idx)
  43. {
  44. SSL_CTX *cctx = SSL_CTX_new_ex(libctx, NULL, OSSL_QUIC_client_method());
  45. SSL_CTX *sctx = NULL;
  46. SSL *clientquic = NULL;
  47. QUIC_TSERVER *qtserv = NULL;
  48. int j, k, ret = 0;
  49. unsigned char buf[20], scratch[64];
  50. static char *msg = "A test message";
  51. size_t msglen = strlen(msg);
  52. size_t numbytes = 0;
  53. int ssock = 0, csock = 0;
  54. uint64_t sid = UINT64_MAX;
  55. SSL_SESSION *sess = NULL;
  56. if (idx >= 1 && !qtest_supports_blocking())
  57. return TEST_skip("Blocking tests not supported in this build");
  58. for (k = 0; k < 2; k++) {
  59. if (!TEST_ptr(cctx)
  60. || !TEST_true(qtest_create_quic_objects(libctx, cctx, sctx,
  61. cert, privkey,
  62. idx >= 1
  63. ? QTEST_FLAG_BLOCK
  64. : 0,
  65. &qtserv, &clientquic,
  66. NULL, NULL))
  67. || !TEST_true(SSL_set_tlsext_host_name(clientquic, "localhost")))
  68. goto end;
  69. if (sess != NULL && !TEST_true(SSL_set_session(clientquic, sess)))
  70. goto end;
  71. if (!TEST_true(qtest_create_quic_connection(qtserv, clientquic)))
  72. goto end;
  73. if (idx >= 1) {
  74. if (!TEST_true(BIO_get_fd(ossl_quic_tserver_get0_rbio(qtserv),
  75. &ssock)))
  76. goto end;
  77. if (!TEST_int_gt(csock = SSL_get_rfd(clientquic), 0))
  78. goto end;
  79. }
  80. sid = 0; /* client-initiated bidirectional stream */
  81. for (j = 0; j < 2; j++) {
  82. /* Check that sending and receiving app data is ok */
  83. if (!TEST_true(SSL_write_ex(clientquic, msg, msglen, &numbytes))
  84. || !TEST_size_t_eq(numbytes, msglen))
  85. goto end;
  86. if (idx >= 1) {
  87. do {
  88. if (!TEST_true(wait_until_sock_readable(ssock)))
  89. goto end;
  90. ossl_quic_tserver_tick(qtserv);
  91. if (!TEST_true(ossl_quic_tserver_read(qtserv, sid, buf,
  92. sizeof(buf),
  93. &numbytes)))
  94. goto end;
  95. } while (numbytes == 0);
  96. if (!TEST_mem_eq(buf, numbytes, msg, msglen))
  97. goto end;
  98. }
  99. if (idx >= 2 && j > 0)
  100. /* Introduce permanent socket error */
  101. BIO_closesocket(csock);
  102. ossl_quic_tserver_tick(qtserv);
  103. if (!TEST_true(ossl_quic_tserver_write(qtserv, sid,
  104. (unsigned char *)msg,
  105. msglen, &numbytes)))
  106. goto end;
  107. ossl_quic_tserver_tick(qtserv);
  108. SSL_handle_events(clientquic);
  109. if (idx >= 2 && j > 0) {
  110. if (!TEST_false(SSL_read_ex(clientquic, buf, 1, &numbytes))
  111. || !TEST_int_eq(SSL_get_error(clientquic, 0),
  112. SSL_ERROR_SYSCALL)
  113. || !TEST_false(SSL_write_ex(clientquic, msg, msglen,
  114. &numbytes))
  115. || !TEST_int_eq(SSL_get_error(clientquic, 0),
  116. SSL_ERROR_SYSCALL))
  117. goto end;
  118. break;
  119. }
  120. /*
  121. * In blocking mode the SSL_read_ex call will block until the socket
  122. * is readable and has our data. In non-blocking mode we're doing
  123. * everything in memory, so it should be immediately available
  124. */
  125. if (!TEST_true(SSL_read_ex(clientquic, buf, 1, &numbytes))
  126. || !TEST_size_t_eq(numbytes, 1)
  127. || !TEST_true(SSL_has_pending(clientquic))
  128. || !TEST_int_eq(SSL_pending(clientquic), msglen - 1)
  129. || !TEST_true(SSL_read_ex(clientquic, buf + 1,
  130. sizeof(buf) - 1, &numbytes))
  131. || !TEST_mem_eq(buf, numbytes + 1, msg, msglen))
  132. goto end;
  133. }
  134. /* Test that exporters work. */
  135. if (!TEST_true(SSL_export_keying_material(clientquic, scratch,
  136. sizeof(scratch), "test", 4, (unsigned char *)"ctx", 3,
  137. 1)))
  138. goto end;
  139. if (sess == NULL) {
  140. /* We didn't supply a session so we're not expecting resumption */
  141. if (!TEST_false(SSL_session_reused(clientquic)))
  142. goto end;
  143. /* We should have a session ticket by now */
  144. sess = SSL_get1_session(clientquic);
  145. if (!TEST_ptr(sess))
  146. goto end;
  147. } else {
  148. /* We supplied a session so we should have resumed */
  149. if (!TEST_true(SSL_session_reused(clientquic)))
  150. goto end;
  151. }
  152. if (!TEST_true(qtest_shutdown(qtserv, clientquic)))
  153. goto end;
  154. if (sctx == NULL) {
  155. sctx = ossl_quic_tserver_get0_ssl_ctx(qtserv);
  156. if (!TEST_true(SSL_CTX_up_ref(sctx))) {
  157. sctx = NULL;
  158. goto end;
  159. }
  160. }
  161. ossl_quic_tserver_free(qtserv);
  162. qtserv = NULL;
  163. SSL_free(clientquic);
  164. clientquic = NULL;
  165. if (idx >= 2)
  166. break;
  167. }
  168. ret = 1;
  169. end:
  170. SSL_SESSION_free(sess);
  171. ossl_quic_tserver_free(qtserv);
  172. SSL_free(clientquic);
  173. SSL_CTX_free(cctx);
  174. SSL_CTX_free(sctx);
  175. return ret;
  176. }
  177. /*
  178. * Test that sending FIN with no data to a client blocking in SSL_read_ex() will
  179. * wake up the client.
  180. */
  181. static int test_fin_only_blocking(void)
  182. {
  183. SSL_CTX *cctx = SSL_CTX_new_ex(libctx, NULL, OSSL_QUIC_client_method());
  184. SSL_CTX *sctx = NULL;
  185. SSL *clientquic = NULL;
  186. QUIC_TSERVER *qtserv = NULL;
  187. const char *msg = "Hello World";
  188. uint64_t sid;
  189. size_t numbytes;
  190. unsigned char buf[32];
  191. int ret = 0;
  192. OSSL_TIME timer, timediff;
  193. if (!qtest_supports_blocking())
  194. return TEST_skip("Blocking tests not supported in this build");
  195. if (!TEST_ptr(cctx)
  196. || !TEST_true(qtest_create_quic_objects(libctx, cctx, sctx,
  197. cert, privkey,
  198. QTEST_FLAG_BLOCK,
  199. &qtserv, &clientquic,
  200. NULL, NULL))
  201. || !TEST_true(SSL_set_tlsext_host_name(clientquic, "localhost")))
  202. goto end;
  203. if (!TEST_true(qtest_create_quic_connection(qtserv, clientquic)))
  204. goto end;
  205. if (!TEST_true(ossl_quic_tserver_stream_new(qtserv, 0, &sid))
  206. || !TEST_true(ossl_quic_tserver_write(qtserv, sid,
  207. (unsigned char *)msg,
  208. strlen(msg), &numbytes))
  209. || !TEST_size_t_eq(strlen(msg), numbytes))
  210. goto end;
  211. ossl_quic_tserver_tick(qtserv);
  212. if (!TEST_true(SSL_read_ex(clientquic, buf, sizeof(buf), &numbytes))
  213. || !TEST_mem_eq(msg, strlen(msg), buf, numbytes))
  214. goto end;
  215. if (!TEST_true(ossl_quic_tserver_conclude(qtserv, sid)))
  216. goto end;
  217. timer = ossl_time_now();
  218. if (!TEST_false(SSL_read_ex(clientquic, buf, sizeof(buf), &numbytes)))
  219. goto end;
  220. timediff = ossl_time_subtract(ossl_time_now(), timer);
  221. if (!TEST_int_eq(SSL_get_error(clientquic, 0), SSL_ERROR_ZERO_RETURN)
  222. /*
  223. * We expect the SSL_read_ex to not have blocked so this should
  224. * be very fast. 20ms should be plenty.
  225. */
  226. || !TEST_uint64_t_le(ossl_time2ms(timediff), 20))
  227. goto end;
  228. if (!TEST_true(qtest_shutdown(qtserv, clientquic)))
  229. goto end;
  230. ret = 1;
  231. end:
  232. ossl_quic_tserver_free(qtserv);
  233. SSL_free(clientquic);
  234. SSL_CTX_free(cctx);
  235. SSL_CTX_free(sctx);
  236. return ret;
  237. }
  238. /* Test that a vanilla QUIC SSL object has the expected ciphersuites available */
  239. static int test_ciphersuites(void)
  240. {
  241. SSL_CTX *ctx = SSL_CTX_new_ex(libctx, NULL, OSSL_QUIC_client_method());
  242. SSL *ssl;
  243. int testresult = 0;
  244. const STACK_OF(SSL_CIPHER) *ciphers = NULL;
  245. const SSL_CIPHER *cipher;
  246. /* We expect this exact list of ciphersuites by default */
  247. int cipherids[] = {
  248. TLS1_3_CK_AES_256_GCM_SHA384,
  249. #if !defined(OPENSSL_NO_CHACHA) && !defined(OPENSSL_NO_POLY1305)
  250. TLS1_3_CK_CHACHA20_POLY1305_SHA256,
  251. #endif
  252. TLS1_3_CK_AES_128_GCM_SHA256
  253. };
  254. size_t i, j;
  255. if (!TEST_ptr(ctx))
  256. return 0;
  257. ssl = SSL_new(ctx);
  258. if (!TEST_ptr(ssl))
  259. goto err;
  260. ciphers = SSL_get_ciphers(ssl);
  261. for (i = 0, j = 0; i < OSSL_NELEM(cipherids); i++) {
  262. if (cipherids[i] == TLS1_3_CK_CHACHA20_POLY1305_SHA256 && is_fips)
  263. continue;
  264. cipher = sk_SSL_CIPHER_value(ciphers, j++);
  265. if (!TEST_ptr(cipher))
  266. goto err;
  267. if (!TEST_uint_eq(SSL_CIPHER_get_id(cipher), cipherids[i]))
  268. goto err;
  269. }
  270. /* We should have checked all the ciphers in the stack */
  271. if (!TEST_int_eq(sk_SSL_CIPHER_num(ciphers), j))
  272. goto err;
  273. testresult = 1;
  274. err:
  275. SSL_free(ssl);
  276. SSL_CTX_free(ctx);
  277. return testresult;
  278. }
  279. static int test_cipher_find(void)
  280. {
  281. SSL_CTX *cctx = SSL_CTX_new_ex(libctx, NULL, OSSL_QUIC_client_method());
  282. SSL *clientquic = NULL;
  283. struct {
  284. const unsigned char *cipherbytes;
  285. int ok;
  286. } testciphers[] = {
  287. { TLS13_AES_128_GCM_SHA256_BYTES, 1 },
  288. { TLS13_AES_256_GCM_SHA384_BYTES, 1 },
  289. { TLS13_CHACHA20_POLY1305_SHA256_BYTES, 1 },
  290. { TLS13_AES_128_CCM_SHA256_BYTES, 0 },
  291. { TLS13_AES_128_CCM_8_SHA256_BYTES, 0 }
  292. };
  293. size_t i;
  294. int testresult = 0;
  295. if (!TEST_ptr(cctx))
  296. goto err;
  297. clientquic = SSL_new(cctx);
  298. if (!TEST_ptr(clientquic))
  299. goto err;
  300. for (i = 0; i < OSSL_NELEM(testciphers); i++)
  301. if (testciphers[i].ok) {
  302. if (!TEST_ptr(SSL_CIPHER_find(clientquic,
  303. testciphers[i].cipherbytes)))
  304. goto err;
  305. } else {
  306. if (!TEST_ptr_null(SSL_CIPHER_find(clientquic,
  307. testciphers[i].cipherbytes)))
  308. goto err;
  309. }
  310. testresult = 1;
  311. err:
  312. SSL_free(clientquic);
  313. SSL_CTX_free(cctx);
  314. return testresult;
  315. }
  316. /*
  317. * Test that SSL_version, SSL_get_version, SSL_is_quic, SSL_is_tls and
  318. * SSL_is_dtls return the expected results for a QUIC connection. Compare with
  319. * test_version() in sslapitest.c which does the same thing for TLS/DTLS
  320. * connections.
  321. */
  322. static int test_version(void)
  323. {
  324. SSL_CTX *cctx = SSL_CTX_new_ex(libctx, NULL, OSSL_QUIC_client_method());
  325. SSL *clientquic = NULL;
  326. QUIC_TSERVER *qtserv = NULL;
  327. int testresult = 0;
  328. if (!TEST_ptr(cctx)
  329. || !TEST_true(qtest_create_quic_objects(libctx, cctx, NULL, cert,
  330. privkey, 0, &qtserv,
  331. &clientquic, NULL, NULL))
  332. || !TEST_true(qtest_create_quic_connection(qtserv, clientquic)))
  333. goto err;
  334. if (!TEST_int_eq(SSL_version(clientquic), OSSL_QUIC1_VERSION)
  335. || !TEST_str_eq(SSL_get_version(clientquic), "QUICv1"))
  336. goto err;
  337. if (!TEST_true(SSL_is_quic(clientquic))
  338. || !TEST_false(SSL_is_tls(clientquic))
  339. || !TEST_false(SSL_is_dtls(clientquic)))
  340. goto err;
  341. testresult = 1;
  342. err:
  343. ossl_quic_tserver_free(qtserv);
  344. SSL_free(clientquic);
  345. SSL_CTX_free(cctx);
  346. return testresult;
  347. }
  348. #if defined(DO_SSL_TRACE_TEST)
  349. static void strip_line_ends(char *str)
  350. {
  351. size_t i;
  352. for (i = strlen(str);
  353. i > 0 && (str[i - 1] == '\n' || str[i - 1] == '\r');
  354. i--);
  355. str[i] = '\0';
  356. }
  357. static int compare_with_file(BIO *membio)
  358. {
  359. BIO *file = NULL, *newfile = NULL;
  360. char buf1[512], buf2[512];
  361. char *reffile;
  362. int ret = 0;
  363. size_t i;
  364. #ifdef OPENSSL_NO_ZLIB
  365. reffile = test_mk_file_path(datadir, "ssltraceref.txt");
  366. #else
  367. reffile = test_mk_file_path(datadir, "ssltraceref-zlib.txt");
  368. #endif
  369. if (!TEST_ptr(reffile))
  370. goto err;
  371. file = BIO_new_file(reffile, "rb");
  372. if (!TEST_ptr(file))
  373. goto err;
  374. newfile = BIO_new_file("ssltraceref-new.txt", "wb");
  375. if (!TEST_ptr(newfile))
  376. goto err;
  377. while (BIO_gets(membio, buf2, sizeof(buf2)) > 0)
  378. if (BIO_puts(newfile, buf2) <= 0) {
  379. TEST_error("Failed writing new file data");
  380. goto err;
  381. }
  382. if (!TEST_int_ge(BIO_seek(membio, 0), 0))
  383. goto err;
  384. while (BIO_gets(file, buf1, sizeof(buf1)) > 0) {
  385. if (BIO_gets(membio, buf2, sizeof(buf2)) <= 0) {
  386. TEST_error("Failed reading mem data");
  387. goto err;
  388. }
  389. strip_line_ends(buf1);
  390. strip_line_ends(buf2);
  391. if (strlen(buf1) != strlen(buf2)) {
  392. TEST_error("Actual and ref line data length mismatch");
  393. TEST_info("%s", buf1);
  394. TEST_info("%s", buf2);
  395. goto err;
  396. }
  397. for (i = 0; i < strlen(buf1); i++) {
  398. /* '?' is a wild card character in the reference text */
  399. if (buf1[i] == '?')
  400. buf2[i] = '?';
  401. }
  402. if (!TEST_str_eq(buf1, buf2))
  403. goto err;
  404. }
  405. if (!TEST_true(BIO_eof(file))
  406. || !TEST_true(BIO_eof(membio)))
  407. goto err;
  408. ret = 1;
  409. err:
  410. OPENSSL_free(reffile);
  411. BIO_free(file);
  412. BIO_free(newfile);
  413. return ret;
  414. }
  415. /*
  416. * Tests that the SSL_trace() msg_callback works as expected with a QUIC
  417. * connection. This also provides testing of the msg_callback at the same time.
  418. */
  419. static int test_ssl_trace(void)
  420. {
  421. SSL_CTX *cctx = NULL;
  422. SSL *clientquic = NULL;
  423. QUIC_TSERVER *qtserv = NULL;
  424. int testresult = 0;
  425. BIO *bio = NULL;
  426. if (!TEST_ptr(cctx = SSL_CTX_new_ex(libctx, NULL, OSSL_QUIC_client_method()))
  427. || !TEST_ptr(bio = BIO_new(BIO_s_mem()))
  428. || !TEST_true(SSL_CTX_set_ciphersuites(cctx, "TLS_AES_128_GCM_SHA256"))
  429. || !TEST_true(qtest_create_quic_objects(libctx, cctx, NULL, cert,
  430. privkey,
  431. QTEST_FLAG_FAKE_TIME,
  432. &qtserv,
  433. &clientquic, NULL, NULL)))
  434. goto err;
  435. SSL_set_msg_callback(clientquic, SSL_trace);
  436. SSL_set_msg_callback_arg(clientquic, bio);
  437. if (!TEST_true(qtest_create_quic_connection(qtserv, clientquic)))
  438. goto err;
  439. /* Skip the comparison of the trace when the fips provider is used. */
  440. if (is_fips) {
  441. /* Check whether there was something written. */
  442. if (!TEST_int_gt(BIO_pending(bio), 0))
  443. goto err;
  444. } else {
  445. if (!TEST_true(compare_with_file(bio)))
  446. goto err;
  447. }
  448. testresult = 1;
  449. err:
  450. ossl_quic_tserver_free(qtserv);
  451. SSL_free(clientquic);
  452. SSL_CTX_free(cctx);
  453. BIO_free(bio);
  454. return testresult;
  455. }
  456. #endif
  457. static int ensure_valid_ciphers(const STACK_OF(SSL_CIPHER) *ciphers)
  458. {
  459. size_t i;
  460. /* Ensure ciphersuite list is suitably subsetted. */
  461. for (i = 0; i < (size_t)sk_SSL_CIPHER_num(ciphers); ++i) {
  462. const SSL_CIPHER *cipher = sk_SSL_CIPHER_value(ciphers, i);
  463. switch (SSL_CIPHER_get_id(cipher)) {
  464. case TLS1_3_CK_AES_128_GCM_SHA256:
  465. case TLS1_3_CK_AES_256_GCM_SHA384:
  466. case TLS1_3_CK_CHACHA20_POLY1305_SHA256:
  467. break;
  468. default:
  469. TEST_error("forbidden cipher: %s", SSL_CIPHER_get_name(cipher));
  470. return 0;
  471. }
  472. }
  473. return 1;
  474. }
  475. /*
  476. * Test that handshake-layer APIs which shouldn't work don't work with QUIC.
  477. */
  478. static int test_quic_forbidden_apis_ctx(void)
  479. {
  480. int testresult = 0;
  481. SSL_CTX *ctx = NULL;
  482. if (!TEST_ptr(ctx = SSL_CTX_new_ex(libctx, NULL, OSSL_QUIC_client_method())))
  483. goto err;
  484. #ifndef OPENSSL_NO_SRTP
  485. /* This function returns 0 on success and 1 on error, and should fail. */
  486. if (!TEST_true(SSL_CTX_set_tlsext_use_srtp(ctx, "SRTP_AEAD_AES_128_GCM")))
  487. goto err;
  488. #endif
  489. /*
  490. * List of ciphersuites we do and don't allow in QUIC.
  491. */
  492. #define QUIC_CIPHERSUITES \
  493. "TLS_AES_128_GCM_SHA256:" \
  494. "TLS_AES_256_GCM_SHA384:" \
  495. "TLS_CHACHA20_POLY1305_SHA256"
  496. #define NON_QUIC_CIPHERSUITES \
  497. "TLS_AES_128_CCM_SHA256:" \
  498. "TLS_AES_256_CCM_SHA384:" \
  499. "TLS_AES_128_CCM_8_SHA256"
  500. /* Set TLSv1.3 ciphersuite list for the SSL_CTX. */
  501. if (!TEST_true(SSL_CTX_set_ciphersuites(ctx,
  502. QUIC_CIPHERSUITES ":"
  503. NON_QUIC_CIPHERSUITES)))
  504. goto err;
  505. /*
  506. * Forbidden ciphersuites should show up in SSL_CTX accessors, they are only
  507. * filtered in SSL_get1_supported_ciphers, so we don't check for
  508. * non-inclusion here.
  509. */
  510. testresult = 1;
  511. err:
  512. SSL_CTX_free(ctx);
  513. return testresult;
  514. }
  515. static int test_quic_forbidden_apis(void)
  516. {
  517. int testresult = 0;
  518. SSL_CTX *ctx = NULL;
  519. SSL *ssl = NULL;
  520. STACK_OF(SSL_CIPHER) *ciphers = NULL;
  521. if (!TEST_ptr(ctx = SSL_CTX_new_ex(libctx, NULL, OSSL_QUIC_client_method())))
  522. goto err;
  523. if (!TEST_ptr(ssl = SSL_new(ctx)))
  524. goto err;
  525. #ifndef OPENSSL_NO_SRTP
  526. /* This function returns 0 on success and 1 on error, and should fail. */
  527. if (!TEST_true(SSL_set_tlsext_use_srtp(ssl, "SRTP_AEAD_AES_128_GCM")))
  528. goto err;
  529. #endif
  530. /* Set TLSv1.3 ciphersuite list for the SSL_CTX. */
  531. if (!TEST_true(SSL_set_ciphersuites(ssl,
  532. QUIC_CIPHERSUITES ":"
  533. NON_QUIC_CIPHERSUITES)))
  534. goto err;
  535. /* Non-QUIC ciphersuites must not appear in supported ciphers list. */
  536. if (!TEST_ptr(ciphers = SSL_get1_supported_ciphers(ssl))
  537. || !TEST_true(ensure_valid_ciphers(ciphers)))
  538. goto err;
  539. testresult = 1;
  540. err:
  541. sk_SSL_CIPHER_free(ciphers);
  542. SSL_free(ssl);
  543. SSL_CTX_free(ctx);
  544. return testresult;
  545. }
  546. static int test_quic_forbidden_options(void)
  547. {
  548. int testresult = 0;
  549. SSL_CTX *ctx = NULL;
  550. SSL *ssl = NULL;
  551. char buf[16];
  552. size_t len;
  553. if (!TEST_ptr(ctx = SSL_CTX_new_ex(libctx, NULL, OSSL_QUIC_client_method())))
  554. goto err;
  555. /* QUIC options restrictions do not affect SSL_CTX */
  556. SSL_CTX_set_options(ctx, UINT64_MAX);
  557. if (!TEST_uint64_t_eq(SSL_CTX_get_options(ctx), UINT64_MAX))
  558. goto err;
  559. /* Set options on CTX which should not be inherited (tested below). */
  560. SSL_CTX_set_read_ahead(ctx, 1);
  561. SSL_CTX_set_max_early_data(ctx, 1);
  562. SSL_CTX_set_recv_max_early_data(ctx, 1);
  563. SSL_CTX_set_quiet_shutdown(ctx, 1);
  564. if (!TEST_ptr(ssl = SSL_new(ctx)))
  565. goto err;
  566. /* Only permitted options get transferred to SSL object */
  567. if (!TEST_uint64_t_eq(SSL_get_options(ssl), OSSL_QUIC_PERMITTED_OPTIONS))
  568. goto err;
  569. /* Try again using SSL_set_options */
  570. SSL_set_options(ssl, UINT64_MAX);
  571. if (!TEST_uint64_t_eq(SSL_get_options(ssl), OSSL_QUIC_PERMITTED_OPTIONS))
  572. goto err;
  573. /* Clear everything */
  574. SSL_clear_options(ssl, UINT64_MAX);
  575. if (!TEST_uint64_t_eq(SSL_get_options(ssl), 0))
  576. goto err;
  577. /* Readahead */
  578. if (!TEST_false(SSL_get_read_ahead(ssl)))
  579. goto err;
  580. SSL_set_read_ahead(ssl, 1);
  581. if (!TEST_false(SSL_get_read_ahead(ssl)))
  582. goto err;
  583. /* Block padding */
  584. if (!TEST_true(SSL_set_block_padding(ssl, 0))
  585. || !TEST_true(SSL_set_block_padding(ssl, 1))
  586. || !TEST_false(SSL_set_block_padding(ssl, 2)))
  587. goto err;
  588. /* Max fragment length */
  589. if (!TEST_true(SSL_set_tlsext_max_fragment_length(ssl, TLSEXT_max_fragment_length_DISABLED))
  590. || !TEST_false(SSL_set_tlsext_max_fragment_length(ssl, TLSEXT_max_fragment_length_512)))
  591. goto err;
  592. /* Max early data */
  593. if (!TEST_false(SSL_set_recv_max_early_data(ssl, 1))
  594. || !TEST_false(SSL_set_max_early_data(ssl, 1)))
  595. goto err;
  596. /* Read/Write */
  597. if (!TEST_false(SSL_read_early_data(ssl, buf, sizeof(buf), &len))
  598. || !TEST_false(SSL_write_early_data(ssl, buf, sizeof(buf), &len)))
  599. goto err;
  600. /* Buffer Management */
  601. if (!TEST_true(SSL_alloc_buffers(ssl))
  602. || !TEST_false(SSL_free_buffers(ssl)))
  603. goto err;
  604. /* Pipelining */
  605. if (!TEST_false(SSL_set_max_send_fragment(ssl, 2))
  606. || !TEST_false(SSL_set_split_send_fragment(ssl, 2))
  607. || !TEST_false(SSL_set_max_pipelines(ssl, 2)))
  608. goto err;
  609. /* HRR */
  610. if (!TEST_false(SSL_stateless(ssl)))
  611. goto err;
  612. /* Quiet Shutdown */
  613. if (!TEST_false(SSL_get_quiet_shutdown(ssl)))
  614. goto err;
  615. /* No duplication */
  616. if (!TEST_ptr_null(SSL_dup(ssl)))
  617. goto err;
  618. /* No clear */
  619. if (!TEST_false(SSL_clear(ssl)))
  620. goto err;
  621. testresult = 1;
  622. err:
  623. SSL_free(ssl);
  624. SSL_CTX_free(ctx);
  625. return testresult;
  626. }
  627. static int test_quic_set_fd(int idx)
  628. {
  629. int testresult = 0;
  630. SSL_CTX *ctx = NULL;
  631. SSL *ssl = NULL;
  632. int fd = -1, resfd = -1;
  633. BIO *bio = NULL;
  634. if (!TEST_ptr(ctx = SSL_CTX_new_ex(libctx, NULL, OSSL_QUIC_client_method())))
  635. goto err;
  636. if (!TEST_ptr(ssl = SSL_new(ctx)))
  637. goto err;
  638. if (!TEST_int_ge(fd = BIO_socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP, 0), 0))
  639. goto err;
  640. if (idx == 0) {
  641. if (!TEST_true(SSL_set_fd(ssl, fd)))
  642. goto err;
  643. if (!TEST_ptr(bio = SSL_get_rbio(ssl)))
  644. goto err;
  645. if (!TEST_ptr_eq(bio, SSL_get_wbio(ssl)))
  646. goto err;
  647. } else if (idx == 1) {
  648. if (!TEST_true(SSL_set_rfd(ssl, fd)))
  649. goto err;
  650. if (!TEST_ptr(bio = SSL_get_rbio(ssl)))
  651. goto err;
  652. if (!TEST_ptr_null(SSL_get_wbio(ssl)))
  653. goto err;
  654. } else {
  655. if (!TEST_true(SSL_set_wfd(ssl, fd)))
  656. goto err;
  657. if (!TEST_ptr(bio = SSL_get_wbio(ssl)))
  658. goto err;
  659. if (!TEST_ptr_null(SSL_get_rbio(ssl)))
  660. goto err;
  661. }
  662. if (!TEST_int_eq(BIO_method_type(bio), BIO_TYPE_DGRAM))
  663. goto err;
  664. if (!TEST_true(BIO_get_fd(bio, &resfd))
  665. || !TEST_int_eq(resfd, fd))
  666. goto err;
  667. testresult = 1;
  668. err:
  669. SSL_free(ssl);
  670. SSL_CTX_free(ctx);
  671. if (fd >= 0)
  672. BIO_closesocket(fd);
  673. return testresult;
  674. }
  675. #define MAXLOOPS 1000
  676. static int test_bio_ssl(void)
  677. {
  678. /*
  679. * We just use OSSL_QUIC_client_method() rather than
  680. * OSSL_QUIC_client_thread_method(). We will never leave the connection idle
  681. * so we will always be implicitly handling time events anyway via other
  682. * IO calls.
  683. */
  684. SSL_CTX *cctx = SSL_CTX_new_ex(libctx, NULL, OSSL_QUIC_client_method());
  685. SSL *clientquic = NULL, *stream = NULL;
  686. QUIC_TSERVER *qtserv = NULL;
  687. int testresult = 0;
  688. BIO *cbio = NULL, *strbio = NULL, *thisbio;
  689. const char *msg = "Hello world";
  690. int abortctr = 0, err, clienterr = 0, servererr = 0, retc = 0, rets = 0;
  691. size_t written, readbytes, msglen;
  692. int sid = 0, i;
  693. unsigned char buf[80];
  694. if (!TEST_ptr(cctx))
  695. goto err;
  696. cbio = BIO_new_ssl(cctx, 1);
  697. if (!TEST_ptr(cbio))
  698. goto err;
  699. /*
  700. * We must configure the ALPN/peer address etc so we get the SSL object in
  701. * order to pass it to qtest_create_quic_objects for configuration.
  702. */
  703. if (!TEST_int_eq(BIO_get_ssl(cbio, &clientquic), 1))
  704. goto err;
  705. if (!TEST_true(qtest_create_quic_objects(libctx, NULL, NULL, cert, privkey,
  706. 0, &qtserv, &clientquic, NULL,
  707. NULL)))
  708. goto err;
  709. msglen = strlen(msg);
  710. do {
  711. err = BIO_FLAGS_WRITE;
  712. while (!clienterr && !retc && err == BIO_FLAGS_WRITE) {
  713. retc = BIO_write_ex(cbio, msg, msglen, &written);
  714. if (!retc) {
  715. if (BIO_should_retry(cbio))
  716. err = BIO_retry_type(cbio);
  717. else
  718. err = 0;
  719. }
  720. }
  721. if (!clienterr && retc <= 0 && err != BIO_FLAGS_READ) {
  722. TEST_info("BIO_write_ex() failed %d, %d", retc, err);
  723. TEST_openssl_errors();
  724. clienterr = 1;
  725. }
  726. if (!servererr && rets <= 0) {
  727. ossl_quic_tserver_tick(qtserv);
  728. servererr = ossl_quic_tserver_is_term_any(qtserv);
  729. if (!servererr)
  730. rets = ossl_quic_tserver_is_handshake_confirmed(qtserv);
  731. }
  732. if (clienterr && servererr)
  733. goto err;
  734. if (++abortctr == MAXLOOPS) {
  735. TEST_info("No progress made");
  736. goto err;
  737. }
  738. } while ((!retc && !clienterr) || (rets <= 0 && !servererr));
  739. /*
  740. * 2 loops: The first using the default stream, and the second using a new
  741. * client initiated bidi stream.
  742. */
  743. for (i = 0, thisbio = cbio; i < 2; i++) {
  744. if (!TEST_true(ossl_quic_tserver_read(qtserv, sid, buf, sizeof(buf),
  745. &readbytes))
  746. || !TEST_mem_eq(msg, msglen, buf, readbytes))
  747. goto err;
  748. if (!TEST_true(ossl_quic_tserver_write(qtserv, sid, (unsigned char *)msg,
  749. msglen, &written)))
  750. goto err;
  751. ossl_quic_tserver_tick(qtserv);
  752. if (!TEST_true(BIO_read_ex(thisbio, buf, sizeof(buf), &readbytes))
  753. || !TEST_mem_eq(msg, msglen, buf, readbytes))
  754. goto err;
  755. if (i == 1)
  756. break;
  757. if (!TEST_true(SSL_set_mode(clientquic, 0)))
  758. goto err;
  759. /*
  760. * Now create a new stream and repeat. The bottom two bits of the stream
  761. * id represents whether the stream is bidi and whether it is client
  762. * initiated or not. For client initiated bidi they are both 0. So the
  763. * first client initiated bidi stream is 0 and the next one is 4.
  764. */
  765. sid = 4;
  766. stream = SSL_new_stream(clientquic, 0);
  767. if (!TEST_ptr(stream))
  768. goto err;
  769. if (!TEST_true(SSL_set_mode(stream, 0)))
  770. goto err;
  771. thisbio = strbio = BIO_new(BIO_f_ssl());
  772. if (!TEST_ptr(strbio))
  773. goto err;
  774. if (!TEST_int_eq(BIO_set_ssl(thisbio, stream, BIO_CLOSE), 1))
  775. goto err;
  776. stream = NULL;
  777. if (!TEST_true(BIO_write_ex(thisbio, msg, msglen, &written)))
  778. goto err;
  779. ossl_quic_tserver_tick(qtserv);
  780. }
  781. testresult = 1;
  782. err:
  783. BIO_free_all(cbio);
  784. BIO_free_all(strbio);
  785. SSL_free(stream);
  786. ossl_quic_tserver_free(qtserv);
  787. SSL_CTX_free(cctx);
  788. return testresult;
  789. }
  790. #define BACK_PRESSURE_NUM_LOOPS 10000
  791. /*
  792. * Test that sending data from the client to the server faster than the server
  793. * can process it eventually results in back pressure on the client.
  794. */
  795. static int test_back_pressure(void)
  796. {
  797. SSL_CTX *cctx = SSL_CTX_new_ex(libctx, NULL, OSSL_QUIC_client_method());
  798. SSL *clientquic = NULL;
  799. QUIC_TSERVER *qtserv = NULL;
  800. int testresult = 0;
  801. unsigned char *msg = NULL;
  802. const size_t msglen = 1024;
  803. unsigned char buf[64];
  804. size_t readbytes, written;
  805. int i;
  806. if (!TEST_ptr(cctx)
  807. || !TEST_true(qtest_create_quic_objects(libctx, cctx, NULL, cert,
  808. privkey, 0, &qtserv,
  809. &clientquic, NULL, NULL))
  810. || !TEST_true(qtest_create_quic_connection(qtserv, clientquic)))
  811. goto err;
  812. msg = OPENSSL_malloc(msglen);
  813. if (!TEST_ptr(msg))
  814. goto err;
  815. if (!TEST_int_eq(RAND_bytes_ex(libctx, msg, msglen, 0), 1))
  816. goto err;
  817. /*
  818. * Limit to 10000 loops. If we've not seen any back pressure after that
  819. * we're going to run out of memory, so abort.
  820. */
  821. for (i = 0; i < BACK_PRESSURE_NUM_LOOPS; i++) {
  822. /* Send data from the client */
  823. if (!SSL_write_ex(clientquic, msg, msglen, &written)) {
  824. /* Check if we are seeing back pressure */
  825. if (SSL_get_error(clientquic, 0) == SSL_ERROR_WANT_WRITE)
  826. break;
  827. TEST_error("Unexpected client failure");
  828. goto err;
  829. }
  830. /* Receive data at the server */
  831. ossl_quic_tserver_tick(qtserv);
  832. if (!TEST_true(ossl_quic_tserver_read(qtserv, 0, buf, sizeof(buf),
  833. &readbytes)))
  834. goto err;
  835. }
  836. if (i == BACK_PRESSURE_NUM_LOOPS) {
  837. TEST_error("No back pressure seen");
  838. goto err;
  839. }
  840. testresult = 1;
  841. err:
  842. SSL_free(clientquic);
  843. ossl_quic_tserver_free(qtserv);
  844. SSL_CTX_free(cctx);
  845. OPENSSL_free(msg);
  846. return testresult;
  847. }
  848. static int dgram_ctr = 0;
  849. static void dgram_cb(int write_p, int version, int content_type,
  850. const void *buf, size_t msglen, SSL *ssl, void *arg)
  851. {
  852. if (!write_p)
  853. return;
  854. if (content_type != SSL3_RT_QUIC_DATAGRAM)
  855. return;
  856. dgram_ctr++;
  857. }
  858. /* Test that we send multiple datagrams in one go when appropriate */
  859. static int test_multiple_dgrams(void)
  860. {
  861. SSL_CTX *cctx = SSL_CTX_new_ex(libctx, NULL, OSSL_QUIC_client_method());
  862. SSL *clientquic = NULL;
  863. QUIC_TSERVER *qtserv = NULL;
  864. int testresult = 0;
  865. unsigned char *buf;
  866. const size_t buflen = 1400;
  867. size_t written;
  868. buf = OPENSSL_zalloc(buflen);
  869. if (!TEST_ptr(cctx)
  870. || !TEST_ptr(buf)
  871. || !TEST_true(qtest_create_quic_objects(libctx, cctx, NULL, cert,
  872. privkey, 0, &qtserv,
  873. &clientquic, NULL, NULL))
  874. || !TEST_true(qtest_create_quic_connection(qtserv, clientquic)))
  875. goto err;
  876. dgram_ctr = 0;
  877. SSL_set_msg_callback(clientquic, dgram_cb);
  878. if (!TEST_true(SSL_write_ex(clientquic, buf, buflen, &written))
  879. || !TEST_size_t_eq(written, buflen)
  880. /* We wrote enough data for 2 datagrams */
  881. || !TEST_int_eq(dgram_ctr, 2))
  882. goto err;
  883. testresult = 1;
  884. err:
  885. OPENSSL_free(buf);
  886. SSL_free(clientquic);
  887. ossl_quic_tserver_free(qtserv);
  888. SSL_CTX_free(cctx);
  889. return testresult;
  890. }
  891. static int non_io_retry_cert_verify_cb(X509_STORE_CTX *ctx, void *arg)
  892. {
  893. int idx = SSL_get_ex_data_X509_STORE_CTX_idx();
  894. SSL *ssl;
  895. const int *allow = (int *)arg;
  896. /* this should not happen but check anyway */
  897. if (idx < 0
  898. || (ssl = X509_STORE_CTX_get_ex_data(ctx, idx)) == NULL)
  899. return 0;
  900. /* If this is our first attempt then retry */
  901. if (*allow == 0)
  902. return SSL_set_retry_verify(ssl);
  903. /* Otherwise do nothing - verification succeeds. Continue as normal */
  904. return 1;
  905. }
  906. /* Test that we can handle a non-io related retry error
  907. * Test 0: Non-blocking
  908. * Test 1: Blocking
  909. */
  910. static int test_non_io_retry(int idx)
  911. {
  912. SSL_CTX *cctx;
  913. SSL *clientquic = NULL;
  914. QUIC_TSERVER *qtserv = NULL;
  915. int testresult = 0;
  916. int flags = 0, allow = 0;
  917. if (idx >= 1 && !qtest_supports_blocking())
  918. return TEST_skip("Blocking tests not supported in this build");
  919. cctx = SSL_CTX_new_ex(libctx, NULL, OSSL_QUIC_client_method());
  920. if (!TEST_ptr(cctx))
  921. goto err;
  922. SSL_CTX_set_cert_verify_callback(cctx, non_io_retry_cert_verify_cb, &allow);
  923. flags = (idx >= 1) ? QTEST_FLAG_BLOCK : 0;
  924. if (!TEST_true(qtest_create_quic_objects(libctx, cctx, NULL, cert, privkey,
  925. flags, &qtserv, &clientquic, NULL,
  926. NULL))
  927. || !TEST_true(qtest_create_quic_connection_ex(qtserv, clientquic,
  928. SSL_ERROR_WANT_RETRY_VERIFY))
  929. || !TEST_int_eq(SSL_want(clientquic), SSL_RETRY_VERIFY))
  930. goto err;
  931. allow = 1;
  932. if (!TEST_true(qtest_create_quic_connection(qtserv, clientquic)))
  933. goto err;
  934. testresult = 1;
  935. err:
  936. SSL_free(clientquic);
  937. ossl_quic_tserver_free(qtserv);
  938. SSL_CTX_free(cctx);
  939. return testresult;
  940. }
  941. static int use_session_cb_cnt = 0;
  942. static int find_session_cb_cnt = 0;
  943. static const char *pskid = "Identity";
  944. static SSL_SESSION *serverpsk = NULL, *clientpsk = NULL;
  945. static int use_session_cb(SSL *ssl, const EVP_MD *md, const unsigned char **id,
  946. size_t *idlen, SSL_SESSION **sess)
  947. {
  948. use_session_cb_cnt++;
  949. if (clientpsk == NULL)
  950. return 0;
  951. SSL_SESSION_up_ref(clientpsk);
  952. *sess = clientpsk;
  953. *id = (const unsigned char *)pskid;
  954. *idlen = strlen(pskid);
  955. return 1;
  956. }
  957. static int find_session_cb(SSL *ssl, const unsigned char *identity,
  958. size_t identity_len, SSL_SESSION **sess)
  959. {
  960. find_session_cb_cnt++;
  961. if (serverpsk == NULL)
  962. return 0;
  963. /* Identity should match that set by the client */
  964. if (strlen(pskid) != identity_len
  965. || strncmp(pskid, (const char *)identity, identity_len) != 0)
  966. return 0;
  967. SSL_SESSION_up_ref(serverpsk);
  968. *sess = serverpsk;
  969. return 1;
  970. }
  971. static int test_quic_psk(void)
  972. {
  973. SSL_CTX *cctx = SSL_CTX_new_ex(libctx, NULL, OSSL_QUIC_client_method());
  974. SSL *clientquic = NULL;
  975. QUIC_TSERVER *qtserv = NULL;
  976. int testresult = 0;
  977. if (!TEST_ptr(cctx)
  978. /* No cert or private key for the server, i.e. PSK only */
  979. || !TEST_true(qtest_create_quic_objects(libctx, cctx, NULL, NULL,
  980. NULL, 0, &qtserv,
  981. &clientquic, NULL, NULL)))
  982. goto end;
  983. SSL_set_psk_use_session_callback(clientquic, use_session_cb);
  984. ossl_quic_tserver_set_psk_find_session_cb(qtserv, find_session_cb);
  985. use_session_cb_cnt = 0;
  986. find_session_cb_cnt = 0;
  987. clientpsk = serverpsk = create_a_psk(clientquic, SHA384_DIGEST_LENGTH);
  988. if (!TEST_ptr(clientpsk))
  989. goto end;
  990. /* We already had one ref. Add another one */
  991. SSL_SESSION_up_ref(clientpsk);
  992. if (!TEST_true(qtest_create_quic_connection(qtserv, clientquic))
  993. || !TEST_int_eq(1, find_session_cb_cnt)
  994. || !TEST_int_eq(1, use_session_cb_cnt)
  995. /* Check that we actually used the PSK */
  996. || !TEST_true(SSL_session_reused(clientquic)))
  997. goto end;
  998. testresult = 1;
  999. end:
  1000. SSL_free(clientquic);
  1001. ossl_quic_tserver_free(qtserv);
  1002. SSL_CTX_free(cctx);
  1003. SSL_SESSION_free(clientpsk);
  1004. SSL_SESSION_free(serverpsk);
  1005. clientpsk = serverpsk = NULL;
  1006. return testresult;
  1007. }
  1008. static int test_client_auth(int idx)
  1009. {
  1010. SSL_CTX *cctx = SSL_CTX_new_ex(libctx, NULL, OSSL_QUIC_client_method());
  1011. SSL_CTX *sctx = SSL_CTX_new_ex(libctx, NULL, TLS_method());
  1012. SSL *clientquic = NULL;
  1013. QUIC_TSERVER *qtserv = NULL;
  1014. int testresult = 0;
  1015. unsigned char buf[20];
  1016. static char *msg = "A test message";
  1017. size_t msglen = strlen(msg);
  1018. size_t numbytes = 0;
  1019. if (!TEST_ptr(cctx) || !TEST_ptr(sctx))
  1020. goto err;
  1021. SSL_CTX_set_verify(sctx, SSL_VERIFY_PEER | SSL_VERIFY_FAIL_IF_NO_PEER_CERT
  1022. | SSL_VERIFY_CLIENT_ONCE, NULL);
  1023. if (!TEST_true(SSL_CTX_load_verify_file(sctx, cauthca)))
  1024. goto err;
  1025. if (idx > 0
  1026. && (!TEST_true(SSL_CTX_use_certificate_chain_file(cctx, ccert))
  1027. || !TEST_true(SSL_CTX_use_PrivateKey_file(cctx, cprivkey,
  1028. SSL_FILETYPE_PEM))))
  1029. goto err;
  1030. if (!TEST_true(qtest_create_quic_objects(libctx, cctx, sctx, cert,
  1031. privkey, 0, &qtserv,
  1032. &clientquic, NULL, NULL)))
  1033. goto err;
  1034. if (idx > 1) {
  1035. if (!TEST_true(ssl_ctx_add_large_cert_chain(libctx, cctx, ccert))
  1036. || !TEST_true(ssl_ctx_add_large_cert_chain(libctx, sctx, cert)))
  1037. goto err;
  1038. }
  1039. if (idx == 0) {
  1040. if (!TEST_false(qtest_create_quic_connection(qtserv, clientquic)))
  1041. goto err;
  1042. /* negative test passed */
  1043. testresult = 1;
  1044. goto err;
  1045. }
  1046. if (!TEST_true(qtest_create_quic_connection(qtserv, clientquic)))
  1047. goto err;
  1048. /* Check that sending and receiving app data is ok */
  1049. if (!TEST_true(SSL_write_ex(clientquic, msg, msglen, &numbytes))
  1050. || !TEST_size_t_eq(numbytes, msglen))
  1051. goto err;
  1052. ossl_quic_tserver_tick(qtserv);
  1053. if (!TEST_true(ossl_quic_tserver_write(qtserv, 0,
  1054. (unsigned char *)msg,
  1055. msglen, &numbytes)))
  1056. goto err;
  1057. ossl_quic_tserver_tick(qtserv);
  1058. SSL_handle_events(clientquic);
  1059. if (!TEST_true(SSL_read_ex(clientquic, buf, sizeof(buf), &numbytes))
  1060. || !TEST_size_t_eq(numbytes, msglen)
  1061. || !TEST_mem_eq(buf, numbytes, msg, msglen))
  1062. goto err;
  1063. if (!TEST_true(qtest_shutdown(qtserv, clientquic)))
  1064. goto err;
  1065. testresult = 1;
  1066. err:
  1067. SSL_free(clientquic);
  1068. ossl_quic_tserver_free(qtserv);
  1069. SSL_CTX_free(sctx);
  1070. SSL_CTX_free(cctx);
  1071. return testresult;
  1072. }
  1073. /*
  1074. * Test that we correctly handle ALPN supplied by the application
  1075. * Test 0: ALPN is provided
  1076. * Test 1: No ALPN is provided
  1077. */
  1078. static int test_alpn(int idx)
  1079. {
  1080. SSL_CTX *cctx = SSL_CTX_new_ex(libctx, NULL, OSSL_QUIC_client_method());
  1081. SSL *clientquic = NULL;
  1082. QUIC_TSERVER *qtserv = NULL;
  1083. int testresult = 0;
  1084. int ret;
  1085. /*
  1086. * Ensure we only configure ciphersuites that are available with both the
  1087. * default and fips providers to get the same output in both cases
  1088. */
  1089. if (!TEST_true(SSL_CTX_set_ciphersuites(cctx, "TLS_AES_128_GCM_SHA256")))
  1090. goto err;
  1091. if (!TEST_ptr(cctx)
  1092. || !TEST_true(qtest_create_quic_objects(libctx, cctx, NULL, cert,
  1093. privkey,
  1094. QTEST_FLAG_FAKE_TIME,
  1095. &qtserv,
  1096. &clientquic, NULL, NULL)))
  1097. goto err;
  1098. if (idx == 0) {
  1099. /*
  1100. * Clear the ALPN we set in qtest_create_quic_objects. We use TEST_false
  1101. * because SSL_set_alpn_protos returns 0 for success.
  1102. */
  1103. if (!TEST_false(SSL_set_alpn_protos(clientquic, NULL, 0)))
  1104. goto err;
  1105. }
  1106. ret = SSL_connect(clientquic);
  1107. if (!TEST_int_le(ret, 0))
  1108. goto err;
  1109. if (idx == 0) {
  1110. /* We expect an immediate error due to lack of ALPN */
  1111. if (!TEST_int_eq(SSL_get_error(clientquic, ret), SSL_ERROR_SSL))
  1112. goto err;
  1113. } else {
  1114. /* ALPN was provided so we expect the connection to succeed */
  1115. if (!TEST_int_eq(SSL_get_error(clientquic, ret), SSL_ERROR_WANT_READ)
  1116. || !TEST_true(qtest_create_quic_connection(qtserv, clientquic)))
  1117. goto err;
  1118. }
  1119. testresult = 1;
  1120. err:
  1121. ossl_quic_tserver_free(qtserv);
  1122. SSL_free(clientquic);
  1123. SSL_CTX_free(cctx);
  1124. return testresult;
  1125. }
  1126. /*
  1127. * Test SSL_get_shutdown() behavior.
  1128. */
  1129. static int test_get_shutdown(void)
  1130. {
  1131. SSL_CTX *cctx = SSL_CTX_new_ex(libctx, NULL, OSSL_QUIC_client_method());
  1132. SSL *clientquic = NULL;
  1133. QUIC_TSERVER *qtserv = NULL;
  1134. int testresult = 0;
  1135. if (!TEST_ptr(cctx)
  1136. || !TEST_true(qtest_create_quic_objects(libctx, cctx, NULL, cert,
  1137. privkey,
  1138. QTEST_FLAG_FAKE_TIME,
  1139. &qtserv, &clientquic,
  1140. NULL, NULL))
  1141. || !TEST_true(qtest_create_quic_connection(qtserv, clientquic)))
  1142. goto err;
  1143. if (!TEST_int_eq(SSL_get_shutdown(clientquic), 0))
  1144. goto err;
  1145. if (!TEST_int_eq(SSL_shutdown(clientquic), 0))
  1146. goto err;
  1147. if (!TEST_int_eq(SSL_get_shutdown(clientquic), SSL_SENT_SHUTDOWN))
  1148. goto err;
  1149. do {
  1150. ossl_quic_tserver_tick(qtserv);
  1151. qtest_add_time(100);
  1152. } while (SSL_shutdown(clientquic) == 0);
  1153. if (!TEST_int_eq(SSL_get_shutdown(clientquic),
  1154. SSL_SENT_SHUTDOWN | SSL_RECEIVED_SHUTDOWN))
  1155. goto err;
  1156. testresult = 1;
  1157. err:
  1158. ossl_quic_tserver_free(qtserv);
  1159. SSL_free(clientquic);
  1160. SSL_CTX_free(cctx);
  1161. return testresult;
  1162. }
  1163. #define MAX_LOOPS 2000
  1164. /*
  1165. * Keep retrying SSL_read_ex until it succeeds or we give up. Accept a stream
  1166. * if we don't already have one
  1167. */
  1168. static int unreliable_client_read(SSL *clientquic, SSL **stream, void *buf,
  1169. size_t buflen, size_t *readbytes,
  1170. QUIC_TSERVER *qtserv)
  1171. {
  1172. int abortctr;
  1173. /* We just do this in a loop with a sleep for simplicity */
  1174. for (abortctr = 0; abortctr < MAX_LOOPS; abortctr++) {
  1175. if (*stream == NULL) {
  1176. SSL_handle_events(clientquic);
  1177. *stream = SSL_accept_stream(clientquic, 0);
  1178. }
  1179. if (*stream != NULL) {
  1180. if (SSL_read_ex(*stream, buf, buflen, readbytes))
  1181. return 1;
  1182. if (!TEST_int_eq(SSL_get_error(*stream, 0), SSL_ERROR_WANT_READ))
  1183. return 0;
  1184. }
  1185. ossl_quic_tserver_tick(qtserv);
  1186. qtest_add_time(1);
  1187. qtest_wait_for_timeout(clientquic, qtserv);
  1188. }
  1189. TEST_error("No progress made");
  1190. return 0;
  1191. }
  1192. /* Keep retrying ossl_quic_tserver_read until it succeeds or we give up */
  1193. static int unreliable_server_read(QUIC_TSERVER *qtserv, uint64_t sid,
  1194. void *buf, size_t buflen, size_t *readbytes,
  1195. SSL *clientquic)
  1196. {
  1197. int abortctr;
  1198. /* We just do this in a loop with a sleep for simplicity */
  1199. for (abortctr = 0; abortctr < MAX_LOOPS; abortctr++) {
  1200. if (ossl_quic_tserver_read(qtserv, sid, buf, buflen, readbytes)
  1201. && *readbytes > 1)
  1202. return 1;
  1203. ossl_quic_tserver_tick(qtserv);
  1204. SSL_handle_events(clientquic);
  1205. qtest_add_time(1);
  1206. qtest_wait_for_timeout(clientquic, qtserv);
  1207. }
  1208. TEST_error("No progress made");
  1209. return 0;
  1210. }
  1211. /*
  1212. * Create a connection and send data using an unreliable transport. We introduce
  1213. * random noise to drop, delay and duplicate datagrams.
  1214. * Test 0: Introduce random noise to datagrams
  1215. * Test 1: As with test 0 but also split datagrams containing multiple packets
  1216. * into individual datagrams so that individual packets can be affected
  1217. * by noise - not just a whole datagram.
  1218. */
  1219. static int test_noisy_dgram(int idx)
  1220. {
  1221. SSL_CTX *cctx = SSL_CTX_new_ex(libctx, NULL, OSSL_QUIC_client_method());
  1222. SSL *clientquic = NULL, *stream[2] = { NULL, NULL };
  1223. QUIC_TSERVER *qtserv = NULL;
  1224. int testresult = 0;
  1225. uint64_t sid = 0;
  1226. char *msg = "Hello world!";
  1227. size_t msglen = strlen(msg), written, readbytes, i, j;
  1228. unsigned char buf[80];
  1229. int flags = QTEST_FLAG_NOISE | QTEST_FLAG_FAKE_TIME;
  1230. QTEST_FAULT *fault = NULL;
  1231. if (idx == 1)
  1232. flags |= QTEST_FLAG_PACKET_SPLIT;
  1233. if (!TEST_ptr(cctx)
  1234. || !TEST_true(qtest_create_quic_objects(libctx, cctx, NULL, cert,
  1235. privkey, flags,
  1236. &qtserv,
  1237. &clientquic, &fault, NULL)))
  1238. goto err;
  1239. if (!TEST_true(qtest_create_quic_connection(qtserv, clientquic)))
  1240. goto err;
  1241. if (!TEST_true(SSL_set_incoming_stream_policy(clientquic,
  1242. SSL_INCOMING_STREAM_POLICY_ACCEPT,
  1243. 0))
  1244. || !TEST_true(SSL_set_default_stream_mode(clientquic,
  1245. SSL_DEFAULT_STREAM_MODE_NONE)))
  1246. goto err;
  1247. for (j = 0; j < 2; j++) {
  1248. if (!TEST_true(ossl_quic_tserver_stream_new(qtserv, 0, &sid)))
  1249. goto err;
  1250. ossl_quic_tserver_tick(qtserv);
  1251. qtest_add_time(1);
  1252. /*
  1253. * Send data from the server to the client. Some datagrams may get
  1254. * lost, modified, dropped or re-ordered. We repeat 20 times to ensure
  1255. * we are sending enough datagrams for problems to be noticed.
  1256. */
  1257. for (i = 0; i < 20; i++) {
  1258. if (!TEST_true(ossl_quic_tserver_write(qtserv, sid,
  1259. (unsigned char *)msg, msglen,
  1260. &written))
  1261. || !TEST_size_t_eq(msglen, written))
  1262. goto err;
  1263. ossl_quic_tserver_tick(qtserv);
  1264. qtest_add_time(1);
  1265. /*
  1266. * Since the underlying BIO is now noisy we may get failures that
  1267. * need to be retried - so we use unreliable_client_read() to
  1268. * handle that
  1269. */
  1270. if (!TEST_true(unreliable_client_read(clientquic, &stream[j], buf,
  1271. sizeof(buf), &readbytes,
  1272. qtserv))
  1273. || !TEST_mem_eq(msg, msglen, buf, readbytes))
  1274. goto err;
  1275. }
  1276. /* Send data from the client to the server */
  1277. for (i = 0; i < 20; i++) {
  1278. if (!TEST_true(SSL_write_ex(stream[j], (unsigned char *)msg,
  1279. msglen, &written))
  1280. || !TEST_size_t_eq(msglen, written))
  1281. goto err;
  1282. ossl_quic_tserver_tick(qtserv);
  1283. qtest_add_time(1);
  1284. /*
  1285. * Since the underlying BIO is now noisy we may get failures that
  1286. * need to be retried - so we use unreliable_server_read() to
  1287. * handle that
  1288. */
  1289. if (!TEST_true(unreliable_server_read(qtserv, sid, buf, sizeof(buf),
  1290. &readbytes, clientquic))
  1291. || !TEST_mem_eq(msg, msglen, buf, readbytes))
  1292. goto err;
  1293. }
  1294. }
  1295. testresult = 1;
  1296. err:
  1297. ossl_quic_tserver_free(qtserv);
  1298. SSL_free(stream[0]);
  1299. SSL_free(stream[1]);
  1300. SSL_free(clientquic);
  1301. SSL_CTX_free(cctx);
  1302. qtest_fault_free(fault);
  1303. return testresult;
  1304. }
  1305. /*
  1306. * Create a connection and send some big data using a transport with limited bandwidth.
  1307. */
  1308. #define TEST_TRANSFER_DATA_SIZE (2*1024*1024) /* 2 MBytes */
  1309. #define TEST_SINGLE_WRITE_SIZE (16*1024) /* 16 kBytes */
  1310. #define TEST_BW_LIMIT 1000 /* 1000 Bytes/ms */
  1311. static int test_bw_limit(void)
  1312. {
  1313. SSL_CTX *cctx = SSL_CTX_new_ex(libctx, NULL, OSSL_QUIC_client_method());
  1314. SSL *clientquic = NULL;
  1315. QUIC_TSERVER *qtserv = NULL;
  1316. int testresult = 0;
  1317. unsigned char *msg = NULL, *recvbuf = NULL;
  1318. size_t sendlen = TEST_TRANSFER_DATA_SIZE;
  1319. size_t recvlen = TEST_TRANSFER_DATA_SIZE;
  1320. size_t written, readbytes;
  1321. int flags = QTEST_FLAG_NOISE | QTEST_FLAG_FAKE_TIME;
  1322. QTEST_FAULT *fault = NULL;
  1323. uint64_t real_bw;
  1324. if (!TEST_ptr(cctx)
  1325. || !TEST_true(qtest_create_quic_objects(libctx, cctx, NULL, cert,
  1326. privkey, flags,
  1327. &qtserv,
  1328. &clientquic, &fault, NULL)))
  1329. goto err;
  1330. if (!TEST_ptr(msg = OPENSSL_zalloc(TEST_SINGLE_WRITE_SIZE))
  1331. || !TEST_ptr(recvbuf = OPENSSL_zalloc(TEST_SINGLE_WRITE_SIZE)))
  1332. goto err;
  1333. /* Set BW to 1000 Bytes/ms -> 1MByte/s both ways */
  1334. if (!TEST_true(qtest_fault_set_bw_limit(fault, 1000, 1000, 0)))
  1335. goto err;
  1336. if (!TEST_true(qtest_create_quic_connection(qtserv, clientquic)))
  1337. goto err;
  1338. qtest_start_stopwatch();
  1339. while (recvlen > 0) {
  1340. qtest_add_time(1);
  1341. if (sendlen > 0) {
  1342. if (!SSL_write_ex(clientquic, msg,
  1343. sendlen > TEST_SINGLE_WRITE_SIZE ? TEST_SINGLE_WRITE_SIZE
  1344. : sendlen,
  1345. &written)) {
  1346. TEST_info("Retrying to send: %llu", (unsigned long long) sendlen);
  1347. if (!TEST_int_eq(SSL_get_error(clientquic, 0), SSL_ERROR_WANT_WRITE))
  1348. goto err;
  1349. } else {
  1350. sendlen -= written;
  1351. TEST_info("Remaining to send: %llu", (unsigned long long) sendlen);
  1352. }
  1353. } else {
  1354. SSL_handle_events(clientquic);
  1355. }
  1356. if (ossl_quic_tserver_read(qtserv, 0, recvbuf,
  1357. recvlen > TEST_SINGLE_WRITE_SIZE ? TEST_SINGLE_WRITE_SIZE
  1358. : recvlen,
  1359. &readbytes)
  1360. && readbytes > 1) {
  1361. recvlen -= readbytes;
  1362. TEST_info("Remaining to recv: %llu", (unsigned long long) recvlen);
  1363. } else {
  1364. TEST_info("No progress on recv: %llu", (unsigned long long) recvlen);
  1365. }
  1366. ossl_quic_tserver_tick(qtserv);
  1367. }
  1368. real_bw = TEST_TRANSFER_DATA_SIZE / qtest_get_stopwatch_time();
  1369. TEST_info("BW limit: %d Bytes/ms Real bandwidth reached: %llu Bytes/ms",
  1370. TEST_BW_LIMIT, (unsigned long long)real_bw);
  1371. if (!TEST_uint64_t_lt(real_bw, TEST_BW_LIMIT))
  1372. goto err;
  1373. testresult = 1;
  1374. err:
  1375. OPENSSL_free(msg);
  1376. OPENSSL_free(recvbuf);
  1377. ossl_quic_tserver_free(qtserv);
  1378. SSL_free(clientquic);
  1379. SSL_CTX_free(cctx);
  1380. qtest_fault_free(fault);
  1381. return testresult;
  1382. }
  1383. enum {
  1384. TPARAM_OP_DUP,
  1385. TPARAM_OP_DROP,
  1386. TPARAM_OP_INJECT,
  1387. TPARAM_OP_INJECT_TWICE,
  1388. TPARAM_OP_INJECT_RAW,
  1389. TPARAM_OP_DROP_INJECT,
  1390. TPARAM_OP_MUTATE
  1391. };
  1392. #define TPARAM_CHECK_DUP(name, reason) \
  1393. { QUIC_TPARAM_##name, TPARAM_OP_DUP, (reason) },
  1394. #define TPARAM_CHECK_DROP(name, reason) \
  1395. { QUIC_TPARAM_##name, TPARAM_OP_DROP, (reason) },
  1396. #define TPARAM_CHECK_INJECT(name, buf, buf_len, reason) \
  1397. { QUIC_TPARAM_##name, TPARAM_OP_INJECT, (reason), \
  1398. (buf), (buf_len) },
  1399. #define TPARAM_CHECK_INJECT_A(name, buf, reason) \
  1400. TPARAM_CHECK_INJECT(name, buf, sizeof(buf), reason)
  1401. #define TPARAM_CHECK_DROP_INJECT(name, buf, buf_len, reason) \
  1402. { QUIC_TPARAM_##name, TPARAM_OP_DROP_INJECT, (reason), \
  1403. (buf), (buf_len) },
  1404. #define TPARAM_CHECK_DROP_INJECT_A(name, buf, reason) \
  1405. TPARAM_CHECK_DROP_INJECT(name, buf, sizeof(buf), reason)
  1406. #define TPARAM_CHECK_INJECT_TWICE(name, buf, buf_len, reason) \
  1407. { QUIC_TPARAM_##name, TPARAM_OP_INJECT_TWICE, (reason), \
  1408. (buf), (buf_len) },
  1409. #define TPARAM_CHECK_INJECT_TWICE_A(name, buf, reason) \
  1410. TPARAM_CHECK_INJECT_TWICE(name, buf, sizeof(buf), reason)
  1411. #define TPARAM_CHECK_INJECT_RAW(buf, buf_len, reason) \
  1412. { 0, TPARAM_OP_INJECT_RAW, (reason), \
  1413. (buf), (buf_len) },
  1414. #define TPARAM_CHECK_INJECT_RAW_A(buf, reason) \
  1415. TPARAM_CHECK_INJECT_RAW(buf, sizeof(buf), reason)
  1416. #define TPARAM_CHECK_MUTATE(name, reason) \
  1417. { QUIC_TPARAM_##name, TPARAM_OP_MUTATE, (reason) },
  1418. #define TPARAM_CHECK_INT(name, reason) \
  1419. TPARAM_CHECK_DROP_INJECT(name, NULL, 0, reason) \
  1420. TPARAM_CHECK_DROP_INJECT_A(name, bogus_int, reason) \
  1421. TPARAM_CHECK_DROP_INJECT_A(name, int_with_trailer, reason)
  1422. struct tparam_test {
  1423. uint64_t id;
  1424. int op;
  1425. const char *expect_fail; /* substring to expect in reason */
  1426. const void *buf;
  1427. size_t buf_len;
  1428. };
  1429. static const unsigned char retry_scid_1[8] = { 0 };
  1430. static const unsigned char disable_active_migration_1[] = {
  1431. 0x00
  1432. };
  1433. static const unsigned char malformed_stateless_reset_token_1[] = {
  1434. 0x02, 0xff
  1435. };
  1436. static const unsigned char malformed_stateless_reset_token_2[] = {
  1437. 0x01
  1438. };
  1439. static const unsigned char malformed_stateless_reset_token_3[15] = { 0 };
  1440. static const unsigned char malformed_stateless_reset_token_4[17] = { 0 };
  1441. static const unsigned char malformed_preferred_addr_1[] = {
  1442. 0x0d, 0xff
  1443. };
  1444. static const unsigned char malformed_preferred_addr_2[42] = {
  1445. 0x0d, 0x28, /* too short */
  1446. };
  1447. static const unsigned char malformed_preferred_addr_3[64] = {
  1448. 0x0d, 0x3e, /* too long */
  1449. };
  1450. static const unsigned char malformed_preferred_addr_4[] = {
  1451. /* TPARAM too short for CID length indicated */
  1452. 0x0d, 0x29, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  1453. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  1454. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  1455. 0x00, 0x00, 0x01, 0x55,
  1456. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  1457. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  1458. };
  1459. static const unsigned char malformed_unknown_1[] = {
  1460. 0xff
  1461. };
  1462. static const unsigned char malformed_unknown_2[] = {
  1463. 0x55, 0x55,
  1464. };
  1465. static const unsigned char malformed_unknown_3[] = {
  1466. 0x55, 0x55, 0x01,
  1467. };
  1468. static const unsigned char ack_delay_exp[] = {
  1469. 0x03
  1470. };
  1471. static const unsigned char stateless_reset_token[16] = { 0x42 };
  1472. static const unsigned char preferred_addr[] = {
  1473. 0x44, 0x44, 0x44, 0x44,
  1474. 0x55, 0x55,
  1475. 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66,
  1476. 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66,
  1477. 0x77, 0x77,
  1478. 0x02, 0xAA, 0xBB,
  1479. 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99,
  1480. 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99,
  1481. };
  1482. static const unsigned char long_cid[21] = { 0x42 };
  1483. static const unsigned char excess_ack_delay_exp[] = {
  1484. 0x15,
  1485. };
  1486. static const unsigned char excess_max_ack_delay[] = {
  1487. 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00,
  1488. };
  1489. static const unsigned char excess_initial_max_streams[] = {
  1490. 0xD0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
  1491. };
  1492. static const unsigned char undersize_udp_payload_size[] = {
  1493. 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0xaf,
  1494. };
  1495. static const unsigned char undersize_active_conn_id_limit[] = {
  1496. 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
  1497. };
  1498. static const unsigned char bogus_int[9] = { 0 };
  1499. static const unsigned char int_with_trailer[2] = { 0x01 };
  1500. #define QUIC_TPARAM_UNKNOWN_1 0xf1f1
  1501. static const struct tparam_test tparam_tests[] = {
  1502. TPARAM_CHECK_DUP(ORIG_DCID,
  1503. "ORIG_DCID appears multiple times")
  1504. TPARAM_CHECK_DUP(INITIAL_SCID,
  1505. "INITIAL_SCID appears multiple times")
  1506. TPARAM_CHECK_DUP(INITIAL_MAX_DATA,
  1507. "INITIAL_MAX_DATA appears multiple times")
  1508. TPARAM_CHECK_DUP(INITIAL_MAX_STREAM_DATA_BIDI_LOCAL,
  1509. "INITIAL_MAX_STREAM_DATA_BIDI_LOCAL appears multiple times")
  1510. TPARAM_CHECK_DUP(INITIAL_MAX_STREAM_DATA_BIDI_REMOTE,
  1511. "INITIAL_MAX_STREAM_DATA_BIDI_REMOTE appears multiple times")
  1512. TPARAM_CHECK_DUP(INITIAL_MAX_STREAM_DATA_UNI,
  1513. "INITIAL_MAX_STREAM_DATA_UNI appears multiple times")
  1514. TPARAM_CHECK_DUP(INITIAL_MAX_STREAMS_BIDI,
  1515. "INITIAL_MAX_STREAMS_BIDI appears multiple times")
  1516. TPARAM_CHECK_DUP(INITIAL_MAX_STREAMS_UNI,
  1517. "INITIAL_MAX_STREAMS_UNI appears multiple times")
  1518. TPARAM_CHECK_DUP(MAX_IDLE_TIMEOUT,
  1519. "MAX_IDLE_TIMEOUT appears multiple times")
  1520. TPARAM_CHECK_DUP(MAX_UDP_PAYLOAD_SIZE,
  1521. "MAX_UDP_PAYLOAD_SIZE appears multiple times")
  1522. TPARAM_CHECK_DUP(ACTIVE_CONN_ID_LIMIT,
  1523. "ACTIVE_CONN_ID_LIMIT appears multiple times")
  1524. TPARAM_CHECK_DUP(DISABLE_ACTIVE_MIGRATION,
  1525. "DISABLE_ACTIVE_MIGRATION appears multiple times")
  1526. TPARAM_CHECK_DROP(INITIAL_SCID,
  1527. "INITIAL_SCID was not sent but is required")
  1528. TPARAM_CHECK_DROP(ORIG_DCID,
  1529. "ORIG_DCID was not sent but is required")
  1530. TPARAM_CHECK_INJECT_A(RETRY_SCID, retry_scid_1,
  1531. "RETRY_SCID sent when not performing a retry")
  1532. TPARAM_CHECK_DROP_INJECT_A(DISABLE_ACTIVE_MIGRATION, disable_active_migration_1,
  1533. "DISABLE_ACTIVE_MIGRATION is malformed")
  1534. TPARAM_CHECK_INJECT(UNKNOWN_1, NULL, 0,
  1535. NULL)
  1536. TPARAM_CHECK_INJECT_RAW_A(malformed_stateless_reset_token_1,
  1537. "STATELESS_RESET_TOKEN is malformed")
  1538. TPARAM_CHECK_INJECT_A(STATELESS_RESET_TOKEN,
  1539. malformed_stateless_reset_token_2,
  1540. "STATELESS_RESET_TOKEN is malformed")
  1541. TPARAM_CHECK_INJECT_A(STATELESS_RESET_TOKEN,
  1542. malformed_stateless_reset_token_3,
  1543. "STATELESS_RESET_TOKEN is malformed")
  1544. TPARAM_CHECK_INJECT_A(STATELESS_RESET_TOKEN,
  1545. malformed_stateless_reset_token_4,
  1546. "STATELESS_RESET_TOKEN is malformed")
  1547. TPARAM_CHECK_INJECT(STATELESS_RESET_TOKEN,
  1548. NULL, 0,
  1549. "STATELESS_RESET_TOKEN is malformed")
  1550. TPARAM_CHECK_INJECT_RAW_A(malformed_preferred_addr_1,
  1551. "PREFERRED_ADDR is malformed")
  1552. TPARAM_CHECK_INJECT_RAW_A(malformed_preferred_addr_2,
  1553. "PREFERRED_ADDR is malformed")
  1554. TPARAM_CHECK_INJECT_RAW_A(malformed_preferred_addr_3,
  1555. "PREFERRED_ADDR is malformed")
  1556. TPARAM_CHECK_INJECT_RAW_A(malformed_preferred_addr_4,
  1557. "PREFERRED_ADDR is malformed")
  1558. TPARAM_CHECK_INJECT_RAW_A(malformed_unknown_1,
  1559. "bad transport parameter")
  1560. TPARAM_CHECK_INJECT_RAW_A(malformed_unknown_2,
  1561. "bad transport parameter")
  1562. TPARAM_CHECK_INJECT_RAW_A(malformed_unknown_3,
  1563. "bad transport parameter")
  1564. TPARAM_CHECK_INJECT_A(ACK_DELAY_EXP, excess_ack_delay_exp,
  1565. "ACK_DELAY_EXP is malformed")
  1566. TPARAM_CHECK_INJECT_A(MAX_ACK_DELAY, excess_max_ack_delay,
  1567. "MAX_ACK_DELAY is malformed")
  1568. TPARAM_CHECK_DROP_INJECT_A(INITIAL_MAX_STREAMS_BIDI, excess_initial_max_streams,
  1569. "INITIAL_MAX_STREAMS_BIDI is malformed")
  1570. TPARAM_CHECK_DROP_INJECT_A(INITIAL_MAX_STREAMS_UNI, excess_initial_max_streams,
  1571. "INITIAL_MAX_STREAMS_UNI is malformed")
  1572. TPARAM_CHECK_DROP_INJECT_A(MAX_UDP_PAYLOAD_SIZE, undersize_udp_payload_size,
  1573. "MAX_UDP_PAYLOAD_SIZE is malformed")
  1574. TPARAM_CHECK_DROP_INJECT_A(ACTIVE_CONN_ID_LIMIT, undersize_active_conn_id_limit,
  1575. "ACTIVE_CONN_ID_LIMIT is malformed")
  1576. TPARAM_CHECK_INJECT_TWICE_A(ACK_DELAY_EXP, ack_delay_exp,
  1577. "ACK_DELAY_EXP appears multiple times")
  1578. TPARAM_CHECK_INJECT_TWICE_A(MAX_ACK_DELAY, ack_delay_exp,
  1579. "MAX_ACK_DELAY appears multiple times")
  1580. TPARAM_CHECK_INJECT_TWICE_A(STATELESS_RESET_TOKEN, stateless_reset_token,
  1581. "STATELESS_RESET_TOKEN appears multiple times")
  1582. TPARAM_CHECK_INJECT_TWICE_A(PREFERRED_ADDR, preferred_addr,
  1583. "PREFERRED_ADDR appears multiple times")
  1584. TPARAM_CHECK_MUTATE(ORIG_DCID,
  1585. "ORIG_DCID does not match expected value")
  1586. TPARAM_CHECK_MUTATE(INITIAL_SCID,
  1587. "INITIAL_SCID does not match expected value")
  1588. TPARAM_CHECK_DROP_INJECT_A(ORIG_DCID, long_cid,
  1589. "ORIG_DCID is malformed")
  1590. TPARAM_CHECK_DROP_INJECT_A(INITIAL_SCID, long_cid,
  1591. "INITIAL_SCID is malformed")
  1592. TPARAM_CHECK_INT(INITIAL_MAX_DATA,
  1593. "INITIAL_MAX_DATA is malformed")
  1594. TPARAM_CHECK_INT(INITIAL_MAX_STREAM_DATA_BIDI_LOCAL,
  1595. "INITIAL_MAX_STREAM_DATA_BIDI_LOCAL is malformed")
  1596. TPARAM_CHECK_INT(INITIAL_MAX_STREAM_DATA_BIDI_REMOTE,
  1597. "INITIAL_MAX_STREAM_DATA_BIDI_REMOTE is malformed")
  1598. TPARAM_CHECK_INT(INITIAL_MAX_STREAM_DATA_UNI,
  1599. "INITIAL_MAX_STREAM_DATA_UNI is malformed")
  1600. TPARAM_CHECK_INT(ACK_DELAY_EXP,
  1601. "ACK_DELAY_EXP is malformed")
  1602. TPARAM_CHECK_INT(MAX_ACK_DELAY,
  1603. "MAX_ACK_DELAY is malformed")
  1604. TPARAM_CHECK_INT(INITIAL_MAX_STREAMS_BIDI,
  1605. "INITIAL_MAX_STREAMS_BIDI is malformed")
  1606. TPARAM_CHECK_INT(INITIAL_MAX_STREAMS_UNI,
  1607. "INITIAL_MAX_STREAMS_UNI is malformed")
  1608. TPARAM_CHECK_INT(MAX_IDLE_TIMEOUT,
  1609. "MAX_IDLE_TIMEOUT is malformed")
  1610. TPARAM_CHECK_INT(MAX_UDP_PAYLOAD_SIZE,
  1611. "MAX_UDP_PAYLOAD_SIZE is malformed")
  1612. TPARAM_CHECK_INT(ACTIVE_CONN_ID_LIMIT,
  1613. "ACTIVE_CONN_ID_LIMIT is malformed")
  1614. };
  1615. struct tparam_ctx {
  1616. const struct tparam_test *t;
  1617. };
  1618. static int tparam_handle(struct tparam_ctx *ctx,
  1619. uint64_t id, unsigned char *data,
  1620. size_t data_len,
  1621. WPACKET *wpkt)
  1622. {
  1623. const struct tparam_test *t = ctx->t;
  1624. switch (t->op) {
  1625. case TPARAM_OP_DUP:
  1626. if (!TEST_ptr(ossl_quic_wire_encode_transport_param_bytes(wpkt, id,
  1627. data, data_len)))
  1628. return 0;
  1629. /*
  1630. * If this is the matching ID, write it again, duplicating the TPARAM.
  1631. */
  1632. if (id == t->id
  1633. && !TEST_ptr(ossl_quic_wire_encode_transport_param_bytes(wpkt, id,
  1634. data, data_len)))
  1635. return 0;
  1636. return 1;
  1637. case TPARAM_OP_DROP:
  1638. case TPARAM_OP_DROP_INJECT:
  1639. /* Pass through unless ID matches. */
  1640. if (id != t->id
  1641. && !TEST_ptr(ossl_quic_wire_encode_transport_param_bytes(wpkt, id,
  1642. data, data_len)))
  1643. return 0;
  1644. return 1;
  1645. case TPARAM_OP_INJECT:
  1646. case TPARAM_OP_INJECT_TWICE:
  1647. case TPARAM_OP_INJECT_RAW:
  1648. /* Always pass through. */
  1649. if (!TEST_ptr(ossl_quic_wire_encode_transport_param_bytes(wpkt, id,
  1650. data, data_len)))
  1651. return 0;
  1652. return 1;
  1653. case TPARAM_OP_MUTATE:
  1654. if (id == t->id) {
  1655. if (!TEST_size_t_gt(data_len, 0))
  1656. return 0;
  1657. data[0] ^= 1;
  1658. }
  1659. if (!TEST_ptr(ossl_quic_wire_encode_transport_param_bytes(wpkt, id,
  1660. data, data_len)))
  1661. return 0;
  1662. if (id == t->id)
  1663. data[0] ^= 1;
  1664. return 1;
  1665. default:
  1666. return 0;
  1667. }
  1668. }
  1669. static int tparam_on_enc_ext(QTEST_FAULT *qtf, QTEST_ENCRYPTED_EXTENSIONS *ee,
  1670. size_t ee_len, void *arg)
  1671. {
  1672. int rc = 0;
  1673. struct tparam_ctx *ctx = arg;
  1674. PACKET pkt = {0};
  1675. WPACKET wpkt;
  1676. int have_wpkt = 0;
  1677. BUF_MEM *old_bufm = NULL, *new_bufm = NULL;
  1678. unsigned char *tp_p;
  1679. size_t tp_len, written, old_len, eb_len;
  1680. uint64_t id;
  1681. if (!TEST_ptr(old_bufm = BUF_MEM_new()))
  1682. goto err;
  1683. /*
  1684. * Delete transport parameters TLS extension and capture the contents of the
  1685. * extension which was removed.
  1686. */
  1687. if (!TEST_true(qtest_fault_delete_extension(qtf, TLSEXT_TYPE_quic_transport_parameters,
  1688. ee->extensions, &ee->extensionslen,
  1689. old_bufm)))
  1690. goto err;
  1691. if (!TEST_true(PACKET_buf_init(&pkt, (unsigned char *)old_bufm->data, old_bufm->length))
  1692. || !TEST_ptr(new_bufm = BUF_MEM_new())
  1693. || !TEST_true(WPACKET_init(&wpkt, new_bufm)))
  1694. goto err;
  1695. have_wpkt = 1;
  1696. /*
  1697. * Open transport parameters TLS extension:
  1698. *
  1699. * u16 Extension ID (quic_transport_parameters)
  1700. * u16 Extension Data Length
  1701. * ... Extension Data
  1702. *
  1703. */
  1704. if (!TEST_true(WPACKET_put_bytes_u16(&wpkt,
  1705. TLSEXT_TYPE_quic_transport_parameters))
  1706. || !TEST_true(WPACKET_start_sub_packet_u16(&wpkt)))
  1707. goto err;
  1708. for (; PACKET_remaining(&pkt) > 0; ) {
  1709. tp_p = (unsigned char *)ossl_quic_wire_decode_transport_param_bytes(&pkt,
  1710. &id,
  1711. &tp_len);
  1712. if (!TEST_ptr(tp_p)) {
  1713. TEST_mem_eq(PACKET_data(&pkt), PACKET_remaining(&pkt), NULL, 0);
  1714. goto err;
  1715. }
  1716. if (!TEST_true(tparam_handle(ctx, id, tp_p, tp_len, &wpkt)))
  1717. goto err;
  1718. }
  1719. if (ctx->t->op == TPARAM_OP_INJECT || ctx->t->op == TPARAM_OP_DROP_INJECT
  1720. || ctx->t->op == TPARAM_OP_INJECT_TWICE) {
  1721. if (!TEST_ptr(ossl_quic_wire_encode_transport_param_bytes(&wpkt, ctx->t->id,
  1722. ctx->t->buf,
  1723. ctx->t->buf_len)))
  1724. goto err;
  1725. if (ctx->t->op == TPARAM_OP_INJECT_TWICE
  1726. && !TEST_ptr(ossl_quic_wire_encode_transport_param_bytes(&wpkt, ctx->t->id,
  1727. ctx->t->buf,
  1728. ctx->t->buf_len)))
  1729. goto err;
  1730. } else if (ctx->t->op == TPARAM_OP_INJECT_RAW) {
  1731. if (!TEST_true(WPACKET_memcpy(&wpkt, ctx->t->buf, ctx->t->buf_len)))
  1732. goto err;
  1733. }
  1734. if (!TEST_true(WPACKET_close(&wpkt))) /* end extension data, set length */
  1735. goto err;
  1736. if (!TEST_true(WPACKET_get_total_written(&wpkt, &written)))
  1737. goto err;
  1738. WPACKET_finish(&wpkt);
  1739. have_wpkt = 0;
  1740. /*
  1741. * Append the constructed extension blob to the extension block.
  1742. */
  1743. old_len = ee->extensionslen;
  1744. if (!qtest_fault_resize_message(qtf, ee->extensionslen + written))
  1745. goto err;
  1746. memcpy(ee->extensions + old_len, new_bufm->data, written);
  1747. /* Fixup the extension block header (u16 length of entire block). */
  1748. eb_len = (((uint16_t)ee->extensions[0]) << 8) + (uint16_t)ee->extensions[1];
  1749. eb_len += written;
  1750. ee->extensions[0] = (unsigned char)((eb_len >> 8) & 0xFF);
  1751. ee->extensions[1] = (unsigned char)( eb_len & 0xFF);
  1752. rc = 1;
  1753. err:
  1754. if (have_wpkt)
  1755. WPACKET_cleanup(&wpkt);
  1756. BUF_MEM_free(old_bufm);
  1757. BUF_MEM_free(new_bufm);
  1758. return rc;
  1759. }
  1760. static int test_tparam(int idx)
  1761. {
  1762. int testresult = 0;
  1763. SSL_CTX *c_ctx = NULL;
  1764. SSL *c_ssl = NULL;
  1765. QUIC_TSERVER *s = NULL;
  1766. QTEST_FAULT *qtf = NULL;
  1767. struct tparam_ctx ctx = {0};
  1768. ctx.t = &tparam_tests[idx];
  1769. if (!TEST_ptr(c_ctx = SSL_CTX_new_ex(libctx, NULL, OSSL_QUIC_client_method())))
  1770. goto err;
  1771. if (!TEST_true(qtest_create_quic_objects(libctx, c_ctx, NULL, cert,
  1772. privkey, 0, &s,
  1773. &c_ssl, &qtf, NULL)))
  1774. goto err;
  1775. if (!TEST_true(qtest_fault_set_hand_enc_ext_listener(qtf, tparam_on_enc_ext,
  1776. &ctx)))
  1777. goto err;
  1778. if (!TEST_true(qtest_create_quic_connection_ex(s, c_ssl,
  1779. ctx.t->expect_fail != NULL)))
  1780. goto err;
  1781. if (ctx.t->expect_fail != NULL) {
  1782. SSL_CONN_CLOSE_INFO info = {0};
  1783. if (!TEST_true(SSL_get_conn_close_info(c_ssl, &info, sizeof(info))))
  1784. goto err;
  1785. if (!TEST_true((info.flags & SSL_CONN_CLOSE_FLAG_TRANSPORT) != 0)
  1786. || !TEST_uint64_t_eq(info.error_code, OSSL_QUIC_ERR_TRANSPORT_PARAMETER_ERROR)
  1787. || !TEST_ptr(strstr(info.reason, ctx.t->expect_fail))) {
  1788. TEST_error("expected connection closure information mismatch"
  1789. " during TPARAM test: flags=%llu ec=%llu reason='%s'",
  1790. (unsigned long long)info.flags,
  1791. (unsigned long long)info.error_code,
  1792. info.reason);
  1793. goto err;
  1794. }
  1795. }
  1796. testresult = 1;
  1797. err:
  1798. if (!testresult) {
  1799. if (ctx.t->expect_fail != NULL)
  1800. TEST_info("failed during test for id=%llu, op=%d, bl=%zu, "
  1801. "expected failure='%s'", (unsigned long long)ctx.t->id,
  1802. ctx.t->op, ctx.t->buf_len, ctx.t->expect_fail);
  1803. else
  1804. TEST_info("failed during test for id=%llu, op=%d, bl=%zu",
  1805. (unsigned long long)ctx.t->id, ctx.t->op, ctx.t->buf_len);
  1806. }
  1807. ossl_quic_tserver_free(s);
  1808. SSL_free(c_ssl);
  1809. SSL_CTX_free(c_ctx);
  1810. qtest_fault_free(qtf);
  1811. return testresult;
  1812. }
  1813. /***********************************************************************************/
  1814. OPT_TEST_DECLARE_USAGE("provider config certsdir datadir\n")
  1815. int setup_tests(void)
  1816. {
  1817. char *modulename;
  1818. char *configfile;
  1819. libctx = OSSL_LIB_CTX_new();
  1820. if (!TEST_ptr(libctx))
  1821. return 0;
  1822. defctxnull = OSSL_PROVIDER_load(NULL, "null");
  1823. /*
  1824. * Verify that the default and fips providers in the default libctx are not
  1825. * available
  1826. */
  1827. if (!TEST_false(OSSL_PROVIDER_available(NULL, "default"))
  1828. || !TEST_false(OSSL_PROVIDER_available(NULL, "fips")))
  1829. goto err;
  1830. if (!test_skip_common_options()) {
  1831. TEST_error("Error parsing test options\n");
  1832. goto err;
  1833. }
  1834. if (!TEST_ptr(modulename = test_get_argument(0))
  1835. || !TEST_ptr(configfile = test_get_argument(1))
  1836. || !TEST_ptr(certsdir = test_get_argument(2))
  1837. || !TEST_ptr(datadir = test_get_argument(3)))
  1838. goto err;
  1839. if (!TEST_true(OSSL_LIB_CTX_load_config(libctx, configfile)))
  1840. goto err;
  1841. /* Check we have the expected provider available */
  1842. if (!TEST_true(OSSL_PROVIDER_available(libctx, modulename)))
  1843. goto err;
  1844. /* Check the default provider is not available */
  1845. if (strcmp(modulename, "default") != 0
  1846. && !TEST_false(OSSL_PROVIDER_available(libctx, "default")))
  1847. goto err;
  1848. if (strcmp(modulename, "fips") == 0)
  1849. is_fips = 1;
  1850. cert = test_mk_file_path(certsdir, "servercert.pem");
  1851. if (cert == NULL)
  1852. goto err;
  1853. ccert = test_mk_file_path(certsdir, "ee-client-chain.pem");
  1854. if (ccert == NULL)
  1855. goto err;
  1856. cauthca = test_mk_file_path(certsdir, "root-cert.pem");
  1857. if (cauthca == NULL)
  1858. goto err;
  1859. privkey = test_mk_file_path(certsdir, "serverkey.pem");
  1860. if (privkey == NULL)
  1861. goto err;
  1862. cprivkey = test_mk_file_path(certsdir, "ee-key.pem");
  1863. if (privkey == NULL)
  1864. goto err;
  1865. ADD_ALL_TESTS(test_quic_write_read, 3);
  1866. ADD_TEST(test_fin_only_blocking);
  1867. ADD_TEST(test_ciphersuites);
  1868. ADD_TEST(test_cipher_find);
  1869. ADD_TEST(test_version);
  1870. #if defined(DO_SSL_TRACE_TEST)
  1871. ADD_TEST(test_ssl_trace);
  1872. #endif
  1873. ADD_TEST(test_quic_forbidden_apis_ctx);
  1874. ADD_TEST(test_quic_forbidden_apis);
  1875. ADD_TEST(test_quic_forbidden_options);
  1876. ADD_ALL_TESTS(test_quic_set_fd, 3);
  1877. ADD_TEST(test_bio_ssl);
  1878. ADD_TEST(test_back_pressure);
  1879. ADD_TEST(test_multiple_dgrams);
  1880. ADD_ALL_TESTS(test_non_io_retry, 2);
  1881. ADD_TEST(test_quic_psk);
  1882. ADD_ALL_TESTS(test_client_auth, 3);
  1883. ADD_ALL_TESTS(test_alpn, 2);
  1884. ADD_ALL_TESTS(test_noisy_dgram, 2);
  1885. ADD_TEST(test_bw_limit);
  1886. ADD_TEST(test_get_shutdown);
  1887. ADD_ALL_TESTS(test_tparam, OSSL_NELEM(tparam_tests));
  1888. return 1;
  1889. err:
  1890. cleanup_tests();
  1891. return 0;
  1892. }
  1893. void cleanup_tests(void)
  1894. {
  1895. bio_f_noisy_dgram_filter_free();
  1896. bio_f_pkt_split_dgram_filter_free();
  1897. OPENSSL_free(cert);
  1898. OPENSSL_free(privkey);
  1899. OPENSSL_free(ccert);
  1900. OPENSSL_free(cauthca);
  1901. OPENSSL_free(cprivkey);
  1902. OSSL_PROVIDER_unload(defctxnull);
  1903. OSSL_LIB_CTX_free(libctx);
  1904. }