sslapitest.c 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318
  1. /*
  2. * Copyright 2016-2018 The OpenSSL Project Authors. All Rights Reserved.
  3. *
  4. * Licensed under the OpenSSL license (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 <string.h>
  10. #include <openssl/opensslconf.h>
  11. #include <openssl/bio.h>
  12. #include <openssl/crypto.h>
  13. #include <openssl/ssl.h>
  14. #include <openssl/ocsp.h>
  15. #include "ssltestlib.h"
  16. #include "testutil.h"
  17. #include "e_os.h"
  18. static char *cert = NULL;
  19. static char *privkey = NULL;
  20. #ifndef OPENSSL_NO_OCSP
  21. static const unsigned char orespder[] = "Dummy OCSP Response";
  22. static int ocsp_server_called = 0;
  23. static int ocsp_client_called = 0;
  24. static int cdummyarg = 1;
  25. static X509 *ocspcert = NULL;
  26. #endif
  27. #define NUM_EXTRA_CERTS 40
  28. static int execute_test_large_message(const SSL_METHOD *smeth,
  29. const SSL_METHOD *cmeth,
  30. int min_version, int max_version,
  31. int read_ahead)
  32. {
  33. SSL_CTX *cctx = NULL, *sctx = NULL;
  34. SSL *clientssl = NULL, *serverssl = NULL;
  35. int testresult = 0;
  36. int i;
  37. BIO *certbio = BIO_new_file(cert, "r");
  38. X509 *chaincert = NULL;
  39. int certlen;
  40. if (certbio == NULL) {
  41. printf("Can't load the certificate file\n");
  42. goto end;
  43. }
  44. chaincert = PEM_read_bio_X509(certbio, NULL, NULL, NULL);
  45. BIO_free(certbio);
  46. certbio = NULL;
  47. if (chaincert == NULL) {
  48. printf("Unable to load certificate for chain\n");
  49. goto end;
  50. }
  51. if (!create_ssl_ctx_pair(smeth, cmeth, min_version, max_version, &sctx,
  52. &cctx, cert, privkey)) {
  53. printf("Unable to create SSL_CTX pair\n");
  54. goto end;
  55. }
  56. if(read_ahead) {
  57. /*
  58. * Test that read_ahead works correctly when dealing with large
  59. * records
  60. */
  61. SSL_CTX_set_read_ahead(cctx, 1);
  62. }
  63. /*
  64. * We assume the supplied certificate is big enough so that if we add
  65. * NUM_EXTRA_CERTS it will make the overall message large enough. The
  66. * default buffer size is requested to be 16k, but due to the way BUF_MEM
  67. * works, it ends up allocating a little over 21k (16 * 4/3). So, in this test
  68. * we need to have a message larger than that.
  69. */
  70. certlen = i2d_X509(chaincert, NULL);
  71. OPENSSL_assert((certlen * NUM_EXTRA_CERTS)
  72. > ((SSL3_RT_MAX_PLAIN_LENGTH * 4) / 3));
  73. for (i = 0; i < NUM_EXTRA_CERTS; i++) {
  74. if (!X509_up_ref(chaincert)) {
  75. printf("Unable to up ref cert\n");
  76. goto end;
  77. }
  78. if (!SSL_CTX_add_extra_chain_cert(sctx, chaincert)) {
  79. printf("Unable to add extra chain cert %d\n", i);
  80. X509_free(chaincert);
  81. goto end;
  82. }
  83. }
  84. if (!create_ssl_objects(sctx, cctx, &serverssl, &clientssl, NULL, NULL)) {
  85. printf("Unable to create SSL objects\n");
  86. goto end;
  87. }
  88. if (!create_ssl_connection(serverssl, clientssl)) {
  89. printf("Unable to create SSL connection\n");
  90. goto end;
  91. }
  92. /*
  93. * Calling SSL_clear() first is not required but this tests that SSL_clear()
  94. * doesn't leak (when using enable-crypto-mdebug).
  95. */
  96. if (!SSL_clear(serverssl)) {
  97. printf("Unexpected failure from SSL_clear()\n");
  98. goto end;
  99. }
  100. testresult = 1;
  101. end:
  102. X509_free(chaincert);
  103. SSL_free(serverssl);
  104. SSL_free(clientssl);
  105. SSL_CTX_free(sctx);
  106. SSL_CTX_free(cctx);
  107. return testresult;
  108. }
  109. static int test_large_message_tls(void)
  110. {
  111. return execute_test_large_message(TLS_server_method(), TLS_client_method(),
  112. TLS1_VERSION, TLS_MAX_VERSION,
  113. 0);
  114. }
  115. static int test_large_message_tls_read_ahead(void)
  116. {
  117. return execute_test_large_message(TLS_server_method(), TLS_client_method(),
  118. TLS1_VERSION, TLS_MAX_VERSION,
  119. 1);
  120. }
  121. #ifndef OPENSSL_NO_DTLS
  122. static int test_large_message_dtls(void)
  123. {
  124. /*
  125. * read_ahead is not relevant to DTLS because DTLS always acts as if
  126. * read_ahead is set.
  127. */
  128. return execute_test_large_message(DTLS_server_method(),
  129. DTLS_client_method(),
  130. DTLS1_VERSION, DTLS_MAX_VERSION,
  131. 0);
  132. }
  133. #endif
  134. #ifndef OPENSSL_NO_OCSP
  135. static int ocsp_server_cb(SSL *s, void *arg)
  136. {
  137. int *argi = (int *)arg;
  138. unsigned char *orespdercopy = NULL;
  139. STACK_OF(OCSP_RESPID) *ids = NULL;
  140. OCSP_RESPID *id = NULL;
  141. if (*argi == 2) {
  142. /* In this test we are expecting exactly 1 OCSP_RESPID */
  143. SSL_get_tlsext_status_ids(s, &ids);
  144. if (ids == NULL || sk_OCSP_RESPID_num(ids) != 1)
  145. return SSL_TLSEXT_ERR_ALERT_FATAL;
  146. id = sk_OCSP_RESPID_value(ids, 0);
  147. if (id == NULL || !OCSP_RESPID_match(id, ocspcert))
  148. return SSL_TLSEXT_ERR_ALERT_FATAL;
  149. } else if (*argi != 1) {
  150. return SSL_TLSEXT_ERR_ALERT_FATAL;
  151. }
  152. orespdercopy = OPENSSL_memdup(orespder, sizeof(orespder));
  153. if (orespdercopy == NULL)
  154. return SSL_TLSEXT_ERR_ALERT_FATAL;
  155. SSL_set_tlsext_status_ocsp_resp(s, orespdercopy, sizeof(orespder));
  156. ocsp_server_called = 1;
  157. return SSL_TLSEXT_ERR_OK;
  158. }
  159. static int ocsp_client_cb(SSL *s, void *arg)
  160. {
  161. int *argi = (int *)arg;
  162. const unsigned char *respderin;
  163. size_t len;
  164. if (*argi != 1 && *argi != 2)
  165. return 0;
  166. len = SSL_get_tlsext_status_ocsp_resp(s, &respderin);
  167. if (memcmp(orespder, respderin, len) != 0)
  168. return 0;
  169. ocsp_client_called = 1;
  170. return 1;
  171. }
  172. static int test_tlsext_status_type(void)
  173. {
  174. SSL_CTX *cctx = NULL, *sctx = NULL;
  175. SSL *clientssl = NULL, *serverssl = NULL;
  176. int testresult = 0;
  177. STACK_OF(OCSP_RESPID) *ids = NULL;
  178. OCSP_RESPID *id = NULL;
  179. BIO *certbio = NULL;
  180. if (!create_ssl_ctx_pair(TLS_server_method(), TLS_client_method(),
  181. TLS1_VERSION, TLS_MAX_VERSION, &sctx, &cctx,
  182. cert, privkey)) {
  183. printf("Unable to create SSL_CTX pair\n");
  184. return 0;
  185. }
  186. if (SSL_CTX_get_tlsext_status_type(cctx) != -1) {
  187. printf("Unexpected initial value for "
  188. "SSL_CTX_get_tlsext_status_type()\n");
  189. goto end;
  190. }
  191. /* First just do various checks getting and setting tlsext_status_type */
  192. clientssl = SSL_new(cctx);
  193. if (SSL_get_tlsext_status_type(clientssl) != -1) {
  194. printf("Unexpected initial value for SSL_get_tlsext_status_type()\n");
  195. goto end;
  196. }
  197. if (!SSL_set_tlsext_status_type(clientssl, TLSEXT_STATUSTYPE_ocsp)) {
  198. printf("Unexpected fail for SSL_set_tlsext_status_type()\n");
  199. goto end;
  200. }
  201. if (SSL_get_tlsext_status_type(clientssl) != TLSEXT_STATUSTYPE_ocsp) {
  202. printf("Unexpected result for SSL_get_tlsext_status_type()\n");
  203. goto end;
  204. }
  205. SSL_free(clientssl);
  206. clientssl = NULL;
  207. if (!SSL_CTX_set_tlsext_status_type(cctx, TLSEXT_STATUSTYPE_ocsp)) {
  208. printf("Unexpected fail for SSL_CTX_set_tlsext_status_type()\n");
  209. goto end;
  210. }
  211. if (SSL_CTX_get_tlsext_status_type(cctx) != TLSEXT_STATUSTYPE_ocsp) {
  212. printf("Unexpected result for SSL_CTX_get_tlsext_status_type()\n");
  213. goto end;
  214. }
  215. clientssl = SSL_new(cctx);
  216. if (SSL_get_tlsext_status_type(clientssl) != TLSEXT_STATUSTYPE_ocsp) {
  217. printf("Unexpected result for SSL_get_tlsext_status_type() (test 2)\n");
  218. goto end;
  219. }
  220. SSL_free(clientssl);
  221. clientssl = NULL;
  222. /*
  223. * Now actually do a handshake and check OCSP information is exchanged and
  224. * the callbacks get called
  225. */
  226. SSL_CTX_set_tlsext_status_cb(cctx, ocsp_client_cb);
  227. SSL_CTX_set_tlsext_status_arg(cctx, &cdummyarg);
  228. SSL_CTX_set_tlsext_status_cb(sctx, ocsp_server_cb);
  229. SSL_CTX_set_tlsext_status_arg(sctx, &cdummyarg);
  230. if (!create_ssl_objects(sctx, cctx, &serverssl, &clientssl, NULL, NULL)) {
  231. printf("Unable to create SSL objects\n");
  232. goto end;
  233. }
  234. if (!create_ssl_connection(serverssl, clientssl)) {
  235. printf("Unable to create SSL connection\n");
  236. goto end;
  237. }
  238. if (!ocsp_client_called || !ocsp_server_called) {
  239. printf("OCSP callbacks not called\n");
  240. goto end;
  241. }
  242. SSL_free(serverssl);
  243. SSL_free(clientssl);
  244. serverssl = NULL;
  245. clientssl = NULL;
  246. /* Try again but this time force the server side callback to fail */
  247. ocsp_client_called = 0;
  248. ocsp_server_called = 0;
  249. cdummyarg = 0;
  250. if (!create_ssl_objects(sctx, cctx, &serverssl, &clientssl, NULL, NULL)) {
  251. printf("Unable to create SSL objects\n");
  252. goto end;
  253. }
  254. /* This should fail because the callback will fail */
  255. if (create_ssl_connection(serverssl, clientssl)) {
  256. printf("Unexpected success creating the connection\n");
  257. goto end;
  258. }
  259. if (ocsp_client_called || ocsp_server_called) {
  260. printf("OCSP callbacks successfully called unexpectedly\n");
  261. goto end;
  262. }
  263. SSL_free(serverssl);
  264. SSL_free(clientssl);
  265. serverssl = NULL;
  266. clientssl = NULL;
  267. /*
  268. * This time we'll get the client to send an OCSP_RESPID that it will
  269. * accept.
  270. */
  271. ocsp_client_called = 0;
  272. ocsp_server_called = 0;
  273. cdummyarg = 2;
  274. if (!create_ssl_objects(sctx, cctx, &serverssl, &clientssl, NULL, NULL)) {
  275. printf("Unable to create SSL objects\n");
  276. goto end;
  277. }
  278. /*
  279. * We'll just use any old cert for this test - it doesn't have to be an OCSP
  280. * specific one. We'll use the server cert.
  281. */
  282. certbio = BIO_new_file(cert, "r");
  283. if (certbio == NULL) {
  284. printf("Can't load the certificate file\n");
  285. goto end;
  286. }
  287. id = OCSP_RESPID_new();
  288. ids = sk_OCSP_RESPID_new_null();
  289. ocspcert = PEM_read_bio_X509(certbio, NULL, NULL, NULL);
  290. if (id == NULL || ids == NULL || ocspcert == NULL
  291. || !OCSP_RESPID_set_by_key(id, ocspcert)
  292. || !sk_OCSP_RESPID_push(ids, id)) {
  293. printf("Unable to set OCSP_RESPIDs\n");
  294. goto end;
  295. }
  296. id = NULL;
  297. SSL_set_tlsext_status_ids(clientssl, ids);
  298. /* Control has been transferred */
  299. ids = NULL;
  300. BIO_free(certbio);
  301. certbio = NULL;
  302. if (!create_ssl_connection(serverssl, clientssl)) {
  303. printf("Unable to create SSL connection\n");
  304. goto end;
  305. }
  306. if (!ocsp_client_called || !ocsp_server_called) {
  307. printf("OCSP callbacks not called\n");
  308. goto end;
  309. }
  310. testresult = 1;
  311. end:
  312. SSL_free(serverssl);
  313. SSL_free(clientssl);
  314. SSL_CTX_free(sctx);
  315. SSL_CTX_free(cctx);
  316. sk_OCSP_RESPID_pop_free(ids, OCSP_RESPID_free);
  317. OCSP_RESPID_free(id);
  318. BIO_free(certbio);
  319. X509_free(ocspcert);
  320. ocspcert = NULL;
  321. return testresult;
  322. }
  323. #endif /* ndef OPENSSL_NO_OCSP */
  324. typedef struct ssl_session_test_fixture {
  325. const char *test_case_name;
  326. int use_ext_cache;
  327. int use_int_cache;
  328. } SSL_SESSION_TEST_FIXTURE;
  329. static int new_called = 0, remove_called = 0;
  330. static SSL_SESSION_TEST_FIXTURE
  331. ssl_session_set_up(const char *const test_case_name)
  332. {
  333. SSL_SESSION_TEST_FIXTURE fixture;
  334. fixture.test_case_name = test_case_name;
  335. fixture.use_ext_cache = 1;
  336. fixture.use_int_cache = 1;
  337. new_called = remove_called = 0;
  338. return fixture;
  339. }
  340. static void ssl_session_tear_down(SSL_SESSION_TEST_FIXTURE fixture)
  341. {
  342. }
  343. static int new_session_cb(SSL *ssl, SSL_SESSION *sess)
  344. {
  345. new_called++;
  346. return 1;
  347. }
  348. static void remove_session_cb(SSL_CTX *ctx, SSL_SESSION *sess)
  349. {
  350. remove_called++;
  351. }
  352. static int execute_test_session(SSL_SESSION_TEST_FIXTURE fix)
  353. {
  354. SSL_CTX *sctx = NULL, *cctx = NULL;
  355. SSL *serverssl1 = NULL, *clientssl1 = NULL;
  356. SSL *serverssl2 = NULL, *clientssl2 = NULL;
  357. #ifndef OPENSSL_NO_TLS1_1
  358. SSL *serverssl3 = NULL, *clientssl3 = NULL;
  359. #endif
  360. SSL_SESSION *sess1 = NULL, *sess2 = NULL;
  361. int testresult = 0;
  362. if (!create_ssl_ctx_pair(TLS_server_method(), TLS_client_method(),
  363. TLS1_VERSION, TLS_MAX_VERSION, &sctx, &cctx,
  364. cert, privkey)) {
  365. printf("Unable to create SSL_CTX pair\n");
  366. return 0;
  367. }
  368. #ifndef OPENSSL_NO_TLS1_2
  369. /* Only allow TLS1.2 so we can force a connection failure later */
  370. SSL_CTX_set_min_proto_version(cctx, TLS1_2_VERSION);
  371. #endif
  372. /* Set up session cache */
  373. if (fix.use_ext_cache) {
  374. SSL_CTX_sess_set_new_cb(cctx, new_session_cb);
  375. SSL_CTX_sess_set_remove_cb(cctx, remove_session_cb);
  376. }
  377. if (fix.use_int_cache) {
  378. /* Also covers instance where both are set */
  379. SSL_CTX_set_session_cache_mode(cctx, SSL_SESS_CACHE_CLIENT);
  380. } else {
  381. SSL_CTX_set_session_cache_mode(cctx,
  382. SSL_SESS_CACHE_CLIENT
  383. | SSL_SESS_CACHE_NO_INTERNAL_STORE);
  384. }
  385. if (!create_ssl_objects(sctx, cctx, &serverssl1, &clientssl1, NULL,
  386. NULL)) {
  387. printf("Unable to create SSL objects\n");
  388. goto end;
  389. }
  390. if (!create_ssl_connection(serverssl1, clientssl1)) {
  391. printf("Unable to create SSL connection\n");
  392. goto end;
  393. }
  394. sess1 = SSL_get1_session(clientssl1);
  395. if (sess1 == NULL) {
  396. printf("Unexpected NULL session\n");
  397. goto end;
  398. }
  399. if (fix.use_int_cache && SSL_CTX_add_session(cctx, sess1)) {
  400. /* Should have failed because it should already be in the cache */
  401. printf("Unexpected success adding session to cache\n");
  402. goto end;
  403. }
  404. if (fix.use_ext_cache && (new_called != 1 || remove_called != 0)) {
  405. printf("Session not added to cache\n");
  406. goto end;
  407. }
  408. if (!create_ssl_objects(sctx, cctx, &serverssl2, &clientssl2, NULL, NULL)) {
  409. printf("Unable to create second SSL objects\n");
  410. goto end;
  411. }
  412. if (!create_ssl_connection(serverssl2, clientssl2)) {
  413. printf("Unable to create second SSL connection\n");
  414. goto end;
  415. }
  416. sess2 = SSL_get1_session(clientssl2);
  417. if (sess2 == NULL) {
  418. printf("Unexpected NULL session from clientssl2\n");
  419. goto end;
  420. }
  421. if (fix.use_ext_cache && (new_called != 2 || remove_called != 0)) {
  422. printf("Remove session callback unexpectedly called\n");
  423. goto end;
  424. }
  425. /*
  426. * This should clear sess2 from the cache because it is a "bad" session. See
  427. * SSL_set_session() documentation.
  428. */
  429. if (!SSL_set_session(clientssl2, sess1)) {
  430. printf("Unexpected failure setting session\n");
  431. goto end;
  432. }
  433. if (fix.use_ext_cache && (new_called != 2 || remove_called != 1)) {
  434. printf("Failed to call callback to remove session\n");
  435. goto end;
  436. }
  437. if (SSL_get_session(clientssl2) != sess1) {
  438. printf("Unexpected session found\n");
  439. goto end;
  440. }
  441. if (fix.use_int_cache) {
  442. if (!SSL_CTX_add_session(cctx, sess2)) {
  443. /*
  444. * Should have succeeded because it should not already be in the cache
  445. */
  446. printf("Unexpected failure adding session to cache\n");
  447. goto end;
  448. }
  449. if (!SSL_CTX_remove_session(cctx, sess2)) {
  450. printf("Unexpected failure removing session from cache\n");
  451. goto end;
  452. }
  453. /* This is for the purposes of internal cache testing...ignore the
  454. * counter for external cache
  455. */
  456. if (fix.use_ext_cache)
  457. remove_called--;
  458. }
  459. /* This shouldn't be in the cache so should fail */
  460. if (SSL_CTX_remove_session(cctx, sess2)) {
  461. printf("Unexpected success removing session from cache\n");
  462. goto end;
  463. }
  464. if (fix.use_ext_cache && (new_called != 2 || remove_called != 2)) {
  465. printf("Failed to call callback to remove session #2\n");
  466. goto end;
  467. }
  468. #if !defined(OPENSSL_NO_TLS1_1) && !defined(OPENSSL_NO_TLS1_2)
  469. /* Force a connection failure */
  470. SSL_CTX_set_max_proto_version(sctx, TLS1_1_VERSION);
  471. if (!create_ssl_objects(sctx, cctx, &serverssl3, &clientssl3, NULL, NULL)) {
  472. printf("Unable to create third SSL objects\n");
  473. goto end;
  474. }
  475. if (!SSL_set_session(clientssl3, sess1)) {
  476. printf("Unable to set session for third connection\n");
  477. goto end;
  478. }
  479. /* This should fail because of the mismatched protocol versions */
  480. if (create_ssl_connection(serverssl3, clientssl3)) {
  481. printf("Unable to create third SSL connection\n");
  482. goto end;
  483. }
  484. /* We should have automatically removed the session from the cache */
  485. if (fix.use_ext_cache && (new_called != 2 || remove_called != 3)) {
  486. printf("Failed to call callback to remove session #2\n");
  487. goto end;
  488. }
  489. if (fix.use_int_cache && !SSL_CTX_add_session(cctx, sess2)) {
  490. /*
  491. * Should have succeeded because it should not already be in the cache
  492. */
  493. printf("Unexpected failure adding session to cache #2\n");
  494. goto end;
  495. }
  496. #endif
  497. testresult = 1;
  498. end:
  499. SSL_free(serverssl1);
  500. SSL_free(clientssl1);
  501. SSL_free(serverssl2);
  502. SSL_free(clientssl2);
  503. #ifndef OPENSSL_NO_TLS1_1
  504. SSL_free(serverssl3);
  505. SSL_free(clientssl3);
  506. #endif
  507. SSL_SESSION_free(sess1);
  508. SSL_SESSION_free(sess2);
  509. /*
  510. * Check if we need to remove any sessions up-refed for the external cache
  511. */
  512. if (new_called >= 1)
  513. SSL_SESSION_free(sess1);
  514. if (new_called >= 2)
  515. SSL_SESSION_free(sess2);
  516. SSL_CTX_free(sctx);
  517. SSL_CTX_free(cctx);
  518. return testresult;
  519. }
  520. static int test_session_with_only_int_cache(void)
  521. {
  522. SETUP_TEST_FIXTURE(SSL_SESSION_TEST_FIXTURE, ssl_session_set_up);
  523. fixture.use_ext_cache = 0;
  524. EXECUTE_TEST(execute_test_session, ssl_session_tear_down);
  525. }
  526. static int test_session_with_only_ext_cache(void)
  527. {
  528. SETUP_TEST_FIXTURE(SSL_SESSION_TEST_FIXTURE, ssl_session_set_up);
  529. fixture.use_int_cache = 0;
  530. EXECUTE_TEST(execute_test_session, ssl_session_tear_down);
  531. }
  532. static int test_session_with_both_cache(void)
  533. {
  534. SETUP_TEST_FIXTURE(SSL_SESSION_TEST_FIXTURE, ssl_session_set_up);
  535. EXECUTE_TEST(execute_test_session, ssl_session_tear_down);
  536. }
  537. #define USE_NULL 0
  538. #define USE_BIO_1 1
  539. #define USE_BIO_2 2
  540. #define TOTAL_SSL_SET_BIO_TESTS (3 * 3 * 3 * 3)
  541. static void setupbio(BIO **res, BIO *bio1, BIO *bio2, int type)
  542. {
  543. switch (type) {
  544. case USE_NULL:
  545. *res = NULL;
  546. break;
  547. case USE_BIO_1:
  548. *res = bio1;
  549. break;
  550. case USE_BIO_2:
  551. *res = bio2;
  552. break;
  553. }
  554. }
  555. static int test_ssl_set_bio(int idx)
  556. {
  557. SSL_CTX *ctx = SSL_CTX_new(TLS_method());
  558. BIO *bio1 = NULL;
  559. BIO *bio2 = NULL;
  560. BIO *irbio = NULL, *iwbio = NULL, *nrbio = NULL, *nwbio = NULL;
  561. SSL *ssl = NULL;
  562. int initrbio, initwbio, newrbio, newwbio;
  563. int testresult = 0;
  564. if (ctx == NULL) {
  565. printf("Failed to allocate SSL_CTX\n");
  566. goto end;
  567. }
  568. ssl = SSL_new(ctx);
  569. if (ssl == NULL) {
  570. printf("Failed to allocate SSL object\n");
  571. goto end;
  572. }
  573. initrbio = idx % 3;
  574. idx /= 3;
  575. initwbio = idx % 3;
  576. idx /= 3;
  577. newrbio = idx % 3;
  578. idx /= 3;
  579. newwbio = idx;
  580. OPENSSL_assert(newwbio <= 2);
  581. if (initrbio == USE_BIO_1 || initwbio == USE_BIO_1 || newrbio == USE_BIO_1
  582. || newwbio == USE_BIO_1) {
  583. bio1 = BIO_new(BIO_s_mem());
  584. if (bio1 == NULL) {
  585. printf("Failed to allocate bio1\n");
  586. goto end;
  587. }
  588. }
  589. if (initrbio == USE_BIO_2 || initwbio == USE_BIO_2 || newrbio == USE_BIO_2
  590. || newwbio == USE_BIO_2) {
  591. bio2 = BIO_new(BIO_s_mem());
  592. if (bio2 == NULL) {
  593. printf("Failed to allocate bio2\n");
  594. goto end;
  595. }
  596. }
  597. setupbio(&irbio, bio1, bio2, initrbio);
  598. setupbio(&iwbio, bio1, bio2, initwbio);
  599. /*
  600. * We want to maintain our own refs to these BIO, so do an up ref for each
  601. * BIO that will have ownership transferred in the SSL_set_bio() call
  602. */
  603. if (irbio != NULL)
  604. BIO_up_ref(irbio);
  605. if (iwbio != NULL && iwbio != irbio)
  606. BIO_up_ref(iwbio);
  607. SSL_set_bio(ssl, irbio, iwbio);
  608. setupbio(&nrbio, bio1, bio2, newrbio);
  609. setupbio(&nwbio, bio1, bio2, newwbio);
  610. /*
  611. * We will (maybe) transfer ownership again so do more up refs.
  612. * SSL_set_bio() has some really complicated ownership rules where BIOs have
  613. * already been set!
  614. */
  615. if (nrbio != NULL && nrbio != irbio && (nwbio != iwbio || nrbio != nwbio))
  616. BIO_up_ref(nrbio);
  617. if (nwbio != NULL && nwbio != nrbio && (nwbio != iwbio || (nwbio == iwbio && irbio == iwbio)))
  618. BIO_up_ref(nwbio);
  619. SSL_set_bio(ssl, nrbio, nwbio);
  620. testresult = 1;
  621. end:
  622. SSL_free(ssl);
  623. BIO_free(bio1);
  624. BIO_free(bio2);
  625. /*
  626. * This test is checking that the ref counting for SSL_set_bio is correct.
  627. * If we get here and we did too many frees then we will fail in the above
  628. * functions. If we haven't done enough then this will only be detected in
  629. * a crypto-mdebug build
  630. */
  631. SSL_CTX_free(ctx);
  632. return testresult;
  633. }
  634. typedef struct ssl_bio_test_fixture {
  635. const char *test_case_name;
  636. int pop_ssl;
  637. enum { NO_BIO_CHANGE, CHANGE_RBIO, CHANGE_WBIO } change_bio;
  638. } SSL_BIO_TEST_FIXTURE;
  639. static SSL_BIO_TEST_FIXTURE ssl_bio_set_up(const char *const test_case_name)
  640. {
  641. SSL_BIO_TEST_FIXTURE fixture;
  642. fixture.test_case_name = test_case_name;
  643. fixture.pop_ssl = 0;
  644. fixture.change_bio = NO_BIO_CHANGE;
  645. return fixture;
  646. }
  647. static void ssl_bio_tear_down(SSL_BIO_TEST_FIXTURE fixture)
  648. {
  649. }
  650. static int execute_test_ssl_bio(SSL_BIO_TEST_FIXTURE fix)
  651. {
  652. BIO *sslbio = NULL, *membio1 = NULL, *membio2 = NULL;
  653. SSL_CTX *ctx = SSL_CTX_new(TLS_method());
  654. SSL *ssl = NULL;
  655. int testresult = 0;
  656. if (ctx == NULL) {
  657. printf("Failed to allocate SSL_CTX\n");
  658. return 0;
  659. }
  660. ssl = SSL_new(ctx);
  661. if (ssl == NULL) {
  662. printf("Failed to allocate SSL object\n");
  663. goto end;
  664. }
  665. sslbio = BIO_new(BIO_f_ssl());
  666. membio1 = BIO_new(BIO_s_mem());
  667. if (sslbio == NULL || membio1 == NULL) {
  668. printf("Malloc failure creating BIOs\n");
  669. goto end;
  670. }
  671. BIO_set_ssl(sslbio, ssl, BIO_CLOSE);
  672. /*
  673. * If anything goes wrong here then we could leak memory, so this will
  674. * be caught in a crypto-mdebug build
  675. */
  676. BIO_push(sslbio, membio1);
  677. /* Verify changing the rbio/wbio directly does not cause leaks */
  678. if (fix.change_bio != NO_BIO_CHANGE) {
  679. membio2 = BIO_new(BIO_s_mem());
  680. if (membio2 == NULL) {
  681. printf("Malloc failure creating membio2\n");
  682. goto end;
  683. }
  684. if (fix.change_bio == CHANGE_RBIO)
  685. SSL_set0_rbio(ssl, membio2);
  686. else
  687. SSL_set0_wbio(ssl, membio2);
  688. }
  689. ssl = NULL;
  690. if (fix.pop_ssl)
  691. BIO_pop(sslbio);
  692. else
  693. BIO_pop(membio1);
  694. testresult = 1;
  695. end:
  696. BIO_free(membio1);
  697. BIO_free(sslbio);
  698. SSL_free(ssl);
  699. SSL_CTX_free(ctx);
  700. return testresult;
  701. }
  702. static int test_ssl_bio_pop_next_bio(void)
  703. {
  704. SETUP_TEST_FIXTURE(SSL_BIO_TEST_FIXTURE, ssl_bio_set_up);
  705. EXECUTE_TEST(execute_test_ssl_bio, ssl_bio_tear_down);
  706. }
  707. static int test_ssl_bio_pop_ssl_bio(void)
  708. {
  709. SETUP_TEST_FIXTURE(SSL_BIO_TEST_FIXTURE, ssl_bio_set_up);
  710. fixture.pop_ssl = 1;
  711. EXECUTE_TEST(execute_test_ssl_bio, ssl_bio_tear_down);
  712. }
  713. static int test_ssl_bio_change_rbio(void)
  714. {
  715. SETUP_TEST_FIXTURE(SSL_BIO_TEST_FIXTURE, ssl_bio_set_up);
  716. fixture.change_bio = CHANGE_RBIO;
  717. EXECUTE_TEST(execute_test_ssl_bio, ssl_bio_tear_down);
  718. }
  719. static int test_ssl_bio_change_wbio(void)
  720. {
  721. SETUP_TEST_FIXTURE(SSL_BIO_TEST_FIXTURE, ssl_bio_set_up);
  722. fixture.change_bio = CHANGE_WBIO;
  723. EXECUTE_TEST(execute_test_ssl_bio, ssl_bio_tear_down);
  724. }
  725. typedef struct {
  726. /* The list of sig algs */
  727. const int *list;
  728. /* The length of the list */
  729. size_t listlen;
  730. /* A sigalgs list in string format */
  731. const char *liststr;
  732. /* Whether setting the list should succeed */
  733. int valid;
  734. /* Whether creating a connection with the list should succeed */
  735. int connsuccess;
  736. } sigalgs_list;
  737. static const int validlist1[] = {NID_sha256, EVP_PKEY_RSA};
  738. static const int validlist2[] = {NID_sha256, EVP_PKEY_RSA, NID_sha512, EVP_PKEY_EC};
  739. static const int validlist3[] = {NID_sha512, EVP_PKEY_EC};
  740. static const int invalidlist1[] = {NID_undef, EVP_PKEY_RSA};
  741. static const int invalidlist2[] = {NID_sha256, NID_undef};
  742. static const int invalidlist3[] = {NID_sha256, EVP_PKEY_RSA, NID_sha256};
  743. static const int invalidlist4[] = {NID_sha256};
  744. static const sigalgs_list testsigalgs[] = {
  745. {validlist1, OSSL_NELEM(validlist1), NULL, 1, 1},
  746. {validlist2, OSSL_NELEM(validlist2), NULL, 1, 1},
  747. {validlist3, OSSL_NELEM(validlist3), NULL, 1, 0},
  748. {NULL, 0, "RSA+SHA256", 1, 1},
  749. {NULL, 0, "RSA+SHA256:ECDSA+SHA512", 1, 1},
  750. {NULL, 0, "ECDSA+SHA512", 1, 0},
  751. {invalidlist1, OSSL_NELEM(invalidlist1), NULL, 0, 0},
  752. {invalidlist2, OSSL_NELEM(invalidlist2), NULL, 0, 0},
  753. {invalidlist3, OSSL_NELEM(invalidlist3), NULL, 0, 0},
  754. {invalidlist4, OSSL_NELEM(invalidlist4), NULL, 0, 0},
  755. {NULL, 0, "RSA", 0, 0},
  756. {NULL, 0, "SHA256", 0, 0},
  757. {NULL, 0, "RSA+SHA256:SHA256", 0, 0},
  758. {NULL, 0, "Invalid", 0, 0}};
  759. static int test_set_sigalgs(int idx)
  760. {
  761. SSL_CTX *cctx = NULL, *sctx = NULL;
  762. SSL *clientssl = NULL, *serverssl = NULL;
  763. int testresult = 0;
  764. const sigalgs_list *curr;
  765. int testctx;
  766. /* Should never happen */
  767. if ((size_t)idx >= OSSL_NELEM(testsigalgs) * 2)
  768. return 0;
  769. testctx = ((size_t)idx < OSSL_NELEM(testsigalgs));
  770. curr = testctx ? &testsigalgs[idx]
  771. : &testsigalgs[idx - OSSL_NELEM(testsigalgs)];
  772. if (!create_ssl_ctx_pair(TLS_server_method(), TLS_client_method(),
  773. TLS1_VERSION, TLS_MAX_VERSION, &sctx, &cctx,
  774. cert, privkey)) {
  775. printf("Unable to create SSL_CTX pair\n");
  776. return 0;
  777. }
  778. if (testctx) {
  779. int ret;
  780. if (curr->list != NULL)
  781. ret = SSL_CTX_set1_sigalgs(cctx, curr->list, curr->listlen);
  782. else
  783. ret = SSL_CTX_set1_sigalgs_list(cctx, curr->liststr);
  784. if (!ret) {
  785. if (curr->valid)
  786. printf("Unexpected failure setting sigalgs in SSL_CTX (%d)\n",
  787. idx);
  788. else
  789. testresult = 1;
  790. goto end;
  791. }
  792. if (!curr->valid) {
  793. printf("Unexpected success setting sigalgs in SSL_CTX (%d)\n", idx);
  794. goto end;
  795. }
  796. }
  797. if (!create_ssl_objects(sctx, cctx, &serverssl, &clientssl, NULL, NULL)) {
  798. printf("Unable to create SSL objects\n");
  799. goto end;
  800. }
  801. if (!testctx) {
  802. int ret;
  803. if (curr->list != NULL)
  804. ret = SSL_set1_sigalgs(clientssl, curr->list, curr->listlen);
  805. else
  806. ret = SSL_set1_sigalgs_list(clientssl, curr->liststr);
  807. if (!ret) {
  808. if (curr->valid)
  809. printf("Unexpected failure setting sigalgs in SSL (%d)\n", idx);
  810. else
  811. testresult = 1;
  812. goto end;
  813. }
  814. if (!curr->valid) {
  815. printf("Unexpected success setting sigalgs in SSL (%d)\n", idx);
  816. goto end;
  817. }
  818. }
  819. if (curr->connsuccess != create_ssl_connection(serverssl, clientssl)) {
  820. printf("Unexpected return value creating SSL connection (%d)\n", idx);
  821. goto end;
  822. }
  823. testresult = 1;
  824. end:
  825. SSL_free(serverssl);
  826. SSL_free(clientssl);
  827. SSL_CTX_free(sctx);
  828. SSL_CTX_free(cctx);
  829. return testresult;
  830. }
  831. static int clntaddcb = 0;
  832. static int clntparsecb = 0;
  833. static int srvaddcb = 0;
  834. static int srvparsecb = 0;
  835. static int snicb = 0;
  836. #define TEST_EXT_TYPE1 0xff00
  837. static int add_cb(SSL *s, unsigned int ext_type, const unsigned char **out,
  838. size_t *outlen, int *al, void *add_arg)
  839. {
  840. int *server = (int *)add_arg;
  841. unsigned char *data;
  842. if (SSL_is_server(s))
  843. srvaddcb++;
  844. else
  845. clntaddcb++;
  846. if (*server != SSL_is_server(s)
  847. || (data = OPENSSL_malloc(sizeof(*data))) == NULL)
  848. return -1;
  849. *data = 1;
  850. *out = data;
  851. *outlen = sizeof(char);
  852. return 1;
  853. }
  854. static void free_cb(SSL *s, unsigned int ext_type, const unsigned char *out,
  855. void *add_arg)
  856. {
  857. OPENSSL_free((unsigned char *)out);
  858. }
  859. static int parse_cb(SSL *s, unsigned int ext_type, const unsigned char *in,
  860. size_t inlen, int *al, void *parse_arg)
  861. {
  862. int *server = (int *)parse_arg;
  863. if (SSL_is_server(s))
  864. srvparsecb++;
  865. else
  866. clntparsecb++;
  867. if (*server != SSL_is_server(s)
  868. || inlen != sizeof(char)
  869. || *in != 1)
  870. return -1;
  871. return 1;
  872. }
  873. static int sni_cb(SSL *s, int *al, void *arg)
  874. {
  875. SSL_CTX *ctx = (SSL_CTX *)arg;
  876. if (SSL_set_SSL_CTX(s, ctx) == NULL) {
  877. *al = SSL_AD_INTERNAL_ERROR;
  878. return SSL_TLSEXT_ERR_ALERT_FATAL;
  879. }
  880. snicb++;
  881. return SSL_TLSEXT_ERR_OK;
  882. }
  883. /*
  884. * Custom call back tests.
  885. * Test 0: callbacks in TLSv1.2
  886. * Test 1: callbacks in TLSv1.2 with SNI
  887. */
  888. static int test_custom_exts(int tst)
  889. {
  890. SSL_CTX *cctx = NULL, *sctx = NULL, *sctx2 = NULL;
  891. SSL *clientssl = NULL, *serverssl = NULL;
  892. int testresult = 0;
  893. static int server = 1;
  894. static int client = 0;
  895. SSL_SESSION *sess = NULL;
  896. /* Reset callback counters */
  897. clntaddcb = clntparsecb = srvaddcb = srvparsecb = 0;
  898. snicb = 0;
  899. if (!create_ssl_ctx_pair(TLS_server_method(), TLS_client_method(),
  900. TLS1_VERSION, TLS_MAX_VERSION, &sctx, &cctx,
  901. cert, privkey)) {
  902. printf("Unable to create SSL_CTX pair\n");
  903. goto end;
  904. }
  905. if (tst == 1
  906. && !create_ssl_ctx_pair(TLS_server_method(), NULL,
  907. TLS1_VERSION, TLS_MAX_VERSION, &sctx2, NULL,
  908. cert, privkey)) {
  909. printf("Unable to create SSL_CTX pair (2)\n");
  910. goto end;
  911. }
  912. /* Create a client side custom extension */
  913. if (!SSL_CTX_add_client_custom_ext(cctx, TEST_EXT_TYPE1, add_cb, free_cb,
  914. &client, parse_cb, &client)) {
  915. printf("Unable to add client custom extension\n");
  916. goto end;
  917. }
  918. /* Should not be able to add duplicates */
  919. if (SSL_CTX_add_client_custom_ext(cctx, TEST_EXT_TYPE1, add_cb, free_cb,
  920. &client, parse_cb, &client)) {
  921. printf("Unexpected success adding duplicate extension\n");
  922. goto end;
  923. }
  924. /* Create a server side custom extension */
  925. if (!SSL_CTX_add_server_custom_ext(sctx, TEST_EXT_TYPE1, add_cb, free_cb,
  926. &server, parse_cb, &server)) {
  927. printf("Unable to add server custom extension\n");
  928. goto end;
  929. }
  930. if (sctx2 != NULL
  931. && !SSL_CTX_add_server_custom_ext(sctx2, TEST_EXT_TYPE1,
  932. add_cb, free_cb,
  933. &server, parse_cb,
  934. &server)) {
  935. printf("Unable to add server custom extension for SNI\n");
  936. goto end;
  937. }
  938. /* Should not be able to add duplicates */
  939. if (SSL_CTX_add_server_custom_ext(sctx, TEST_EXT_TYPE1, add_cb, free_cb,
  940. &server, parse_cb, &server)) {
  941. printf("Unexpected success adding duplicate extension (2)\n");
  942. goto end;
  943. }
  944. if (tst == 1) {
  945. /* Set up SNI */
  946. if (!SSL_CTX_set_tlsext_servername_callback(sctx, sni_cb)
  947. || !SSL_CTX_set_tlsext_servername_arg(sctx, sctx2)) {
  948. printf("Cannot set SNI callbacks\n");
  949. goto end;
  950. }
  951. }
  952. if (!create_ssl_objects(sctx, cctx, &serverssl, &clientssl, NULL, NULL)
  953. || !create_ssl_connection(serverssl, clientssl)) {
  954. printf("Cannot create SSL connection\n");
  955. goto end;
  956. }
  957. if (clntaddcb != 1
  958. || clntparsecb != 1
  959. || srvaddcb != 1
  960. || srvparsecb != 1
  961. || (tst != 1 && snicb != 0)
  962. || (tst == 1 && snicb != 1)) {
  963. printf("Incorrect callback counts\n");
  964. goto end;
  965. }
  966. sess = SSL_get1_session(clientssl);
  967. SSL_shutdown(clientssl);
  968. SSL_shutdown(serverssl);
  969. SSL_free(serverssl);
  970. SSL_free(clientssl);
  971. serverssl = clientssl = NULL;
  972. if (tst == 1) {
  973. /* We don't bother with the resumption aspects for this test */
  974. testresult = 1;
  975. goto end;
  976. }
  977. if (!create_ssl_objects(sctx, cctx, &serverssl, &clientssl, NULL, NULL)
  978. || !SSL_set_session(clientssl, sess)
  979. || !create_ssl_connection(serverssl, clientssl)) {
  980. printf("Cannot create resumption connection\n");
  981. goto end;
  982. }
  983. /*
  984. * For a resumed session we expect to add the ClientHello extension but we
  985. * should ignore it on the server side.
  986. */
  987. if (clntaddcb != 2
  988. || clntparsecb != 1
  989. || srvaddcb != 1
  990. || srvparsecb != 1) {
  991. printf("Incorrect resumption callback counts\n");
  992. goto end;
  993. }
  994. testresult = 1;
  995. end:
  996. SSL_SESSION_free(sess);
  997. SSL_free(serverssl);
  998. SSL_free(clientssl);
  999. SSL_CTX_free(sctx2);
  1000. SSL_CTX_free(sctx);
  1001. SSL_CTX_free(cctx);
  1002. return testresult;
  1003. }
  1004. static int test_ssl_pending(int tst)
  1005. {
  1006. SSL_CTX *cctx = NULL, *sctx = NULL;
  1007. SSL *clientssl = NULL, *serverssl = NULL;
  1008. int testresult = 0;
  1009. char msg[] = "A test message";
  1010. char buf[5];
  1011. size_t written;
  1012. if (tst == 0) {
  1013. if (!create_ssl_ctx_pair(TLS_server_method(), TLS_client_method(),
  1014. TLS1_VERSION, TLS_MAX_VERSION,
  1015. &sctx, &cctx, cert, privkey)) {
  1016. printf("Failed creating SSL_CTX pair\n");
  1017. goto end;
  1018. }
  1019. } else {
  1020. #ifndef OPENSSL_NO_DTLS
  1021. if (!create_ssl_ctx_pair(DTLS_server_method(), DTLS_client_method(),
  1022. DTLS1_VERSION, DTLS_MAX_VERSION,
  1023. &sctx, &cctx, cert, privkey)) {
  1024. printf("Failed creating SSL_CTX pair\n");
  1025. goto end;
  1026. }
  1027. #else
  1028. return 1;
  1029. #endif
  1030. }
  1031. if (!create_ssl_objects(sctx, cctx, &serverssl, &clientssl, NULL, NULL)
  1032. || !create_ssl_connection(serverssl, clientssl)) {
  1033. printf("Failed creating connection\n");
  1034. goto end;
  1035. }
  1036. written = SSL_write(serverssl, msg, sizeof(msg));
  1037. if (written != sizeof(msg)
  1038. || SSL_read(clientssl, buf, sizeof(buf)) != sizeof(buf)
  1039. || SSL_pending(clientssl) != (int)(written - sizeof(buf))) {
  1040. printf("Failed checking SSL_pending\n");
  1041. goto end;
  1042. }
  1043. testresult = 1;
  1044. end:
  1045. SSL_free(serverssl);
  1046. SSL_free(clientssl);
  1047. SSL_CTX_free(sctx);
  1048. SSL_CTX_free(cctx);
  1049. return testresult;
  1050. }
  1051. int main(int argc, char *argv[])
  1052. {
  1053. BIO *err = NULL;
  1054. int testresult = 1;
  1055. if (argc != 3) {
  1056. printf("Invalid argument count\n");
  1057. return 1;
  1058. }
  1059. cert = argv[1];
  1060. privkey = argv[2];
  1061. err = BIO_new_fp(stderr, BIO_NOCLOSE | BIO_FP_TEXT);
  1062. CRYPTO_set_mem_debug(1);
  1063. CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON);
  1064. ADD_TEST(test_large_message_tls);
  1065. ADD_TEST(test_large_message_tls_read_ahead);
  1066. #ifndef OPENSSL_NO_DTLS
  1067. ADD_TEST(test_large_message_dtls);
  1068. #endif
  1069. #ifndef OPENSSL_NO_OCSP
  1070. ADD_TEST(test_tlsext_status_type);
  1071. #endif
  1072. ADD_TEST(test_session_with_only_int_cache);
  1073. ADD_TEST(test_session_with_only_ext_cache);
  1074. ADD_TEST(test_session_with_both_cache);
  1075. ADD_ALL_TESTS(test_ssl_set_bio, TOTAL_SSL_SET_BIO_TESTS);
  1076. ADD_TEST(test_ssl_bio_pop_next_bio);
  1077. ADD_TEST(test_ssl_bio_pop_ssl_bio);
  1078. ADD_TEST(test_ssl_bio_change_rbio);
  1079. ADD_TEST(test_ssl_bio_change_wbio);
  1080. ADD_ALL_TESTS(test_set_sigalgs, OSSL_NELEM(testsigalgs) * 2);
  1081. ADD_ALL_TESTS(test_custom_exts, 2);
  1082. ADD_ALL_TESTS(test_ssl_pending, 2);
  1083. testresult = run_tests(argv[0]);
  1084. bio_s_mempacket_test_free();
  1085. #ifndef OPENSSL_NO_CRYPTO_MDEBUG
  1086. if (CRYPTO_mem_leaks(err) <= 0)
  1087. testresult = 1;
  1088. #endif
  1089. BIO_free(err);
  1090. if (!testresult)
  1091. printf("PASS\n");
  1092. return testresult;
  1093. }