ssl_sess.c 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219
  1. /*
  2. * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
  3. * Copyright 2005 Nokia. All rights reserved.
  4. *
  5. * Licensed under the OpenSSL license (the "License"). You may not use
  6. * this file except in compliance with the License. You can obtain a copy
  7. * in the file LICENSE in the source distribution or at
  8. * https://www.openssl.org/source/license.html
  9. */
  10. #include <stdio.h>
  11. #include <openssl/lhash.h>
  12. #include <openssl/rand.h>
  13. #include <openssl/engine.h>
  14. #include "ssl_locl.h"
  15. #include "statem/statem_locl.h"
  16. static void SSL_SESSION_list_remove(SSL_CTX *ctx, SSL_SESSION *s);
  17. static void SSL_SESSION_list_add(SSL_CTX *ctx, SSL_SESSION *s);
  18. static int remove_session_lock(SSL_CTX *ctx, SSL_SESSION *c, int lck);
  19. /*
  20. * SSL_get_session() and SSL_get1_session() are problematic in TLS1.3 because,
  21. * unlike in earlier protocol versions, the session ticket may not have been
  22. * sent yet even though a handshake has finished. The session ticket data could
  23. * come in sometime later...or even change if multiple session ticket messages
  24. * are sent from the server. The preferred way for applications to obtain
  25. * a resumable session is to use SSL_CTX_sess_set_new_cb().
  26. */
  27. SSL_SESSION *SSL_get_session(const SSL *ssl)
  28. /* aka SSL_get0_session; gets 0 objects, just returns a copy of the pointer */
  29. {
  30. return (ssl->session);
  31. }
  32. SSL_SESSION *SSL_get1_session(SSL *ssl)
  33. /* variant of SSL_get_session: caller really gets something */
  34. {
  35. SSL_SESSION *sess;
  36. /*
  37. * Need to lock this all up rather than just use CRYPTO_add so that
  38. * somebody doesn't free ssl->session between when we check it's non-null
  39. * and when we up the reference count.
  40. */
  41. CRYPTO_THREAD_read_lock(ssl->lock);
  42. sess = ssl->session;
  43. if (sess)
  44. SSL_SESSION_up_ref(sess);
  45. CRYPTO_THREAD_unlock(ssl->lock);
  46. return sess;
  47. }
  48. int SSL_SESSION_set_ex_data(SSL_SESSION *s, int idx, void *arg)
  49. {
  50. return (CRYPTO_set_ex_data(&s->ex_data, idx, arg));
  51. }
  52. void *SSL_SESSION_get_ex_data(const SSL_SESSION *s, int idx)
  53. {
  54. return (CRYPTO_get_ex_data(&s->ex_data, idx));
  55. }
  56. SSL_SESSION *SSL_SESSION_new(void)
  57. {
  58. SSL_SESSION *ss;
  59. if (!OPENSSL_init_ssl(OPENSSL_INIT_LOAD_SSL_STRINGS, NULL))
  60. return NULL;
  61. ss = OPENSSL_zalloc(sizeof(*ss));
  62. if (ss == NULL) {
  63. SSLerr(SSL_F_SSL_SESSION_NEW, ERR_R_MALLOC_FAILURE);
  64. return NULL;
  65. }
  66. ss->verify_result = 1; /* avoid 0 (= X509_V_OK) just in case */
  67. ss->references = 1;
  68. ss->timeout = 60 * 5 + 4; /* 5 minute timeout by default */
  69. ss->time = (unsigned long)time(NULL);
  70. ss->lock = CRYPTO_THREAD_lock_new();
  71. if (ss->lock == NULL) {
  72. SSLerr(SSL_F_SSL_SESSION_NEW, ERR_R_MALLOC_FAILURE);
  73. OPENSSL_free(ss);
  74. return NULL;
  75. }
  76. if (!CRYPTO_new_ex_data(CRYPTO_EX_INDEX_SSL_SESSION, ss, &ss->ex_data)) {
  77. CRYPTO_THREAD_lock_free(ss->lock);
  78. OPENSSL_free(ss);
  79. return NULL;
  80. }
  81. return ss;
  82. }
  83. SSL_SESSION *SSL_SESSION_dup(SSL_SESSION *src)
  84. {
  85. return ssl_session_dup(src, 1);
  86. }
  87. /*
  88. * Create a new SSL_SESSION and duplicate the contents of |src| into it. If
  89. * ticket == 0 then no ticket information is duplicated, otherwise it is.
  90. */
  91. SSL_SESSION *ssl_session_dup(SSL_SESSION *src, int ticket)
  92. {
  93. SSL_SESSION *dest;
  94. dest = OPENSSL_malloc(sizeof(*src));
  95. if (dest == NULL) {
  96. goto err;
  97. }
  98. memcpy(dest, src, sizeof(*dest));
  99. /*
  100. * Set the various pointers to NULL so that we can call SSL_SESSION_free in
  101. * the case of an error whilst halfway through constructing dest
  102. */
  103. #ifndef OPENSSL_NO_PSK
  104. dest->psk_identity_hint = NULL;
  105. dest->psk_identity = NULL;
  106. #endif
  107. dest->ciphers = NULL;
  108. dest->ext.hostname = NULL;
  109. #ifndef OPENSSL_NO_EC
  110. dest->ext.ecpointformats = NULL;
  111. dest->ext.supportedgroups = NULL;
  112. #endif
  113. dest->ext.tick = NULL;
  114. dest->ext.alpn_selected = NULL;
  115. #ifndef OPENSSL_NO_SRP
  116. dest->srp_username = NULL;
  117. #endif
  118. dest->peer_chain = NULL;
  119. dest->peer = NULL;
  120. dest->ext.tick_nonce = NULL;
  121. memset(&dest->ex_data, 0, sizeof(dest->ex_data));
  122. /* We deliberately don't copy the prev and next pointers */
  123. dest->prev = NULL;
  124. dest->next = NULL;
  125. dest->references = 1;
  126. dest->lock = CRYPTO_THREAD_lock_new();
  127. if (dest->lock == NULL)
  128. goto err;
  129. if (!CRYPTO_new_ex_data(CRYPTO_EX_INDEX_SSL_SESSION, dest, &dest->ex_data))
  130. goto err;
  131. if (src->peer != NULL) {
  132. if (!X509_up_ref(src->peer))
  133. goto err;
  134. dest->peer = src->peer;
  135. }
  136. if (src->peer_chain != NULL) {
  137. dest->peer_chain = X509_chain_up_ref(src->peer_chain);
  138. if (dest->peer_chain == NULL)
  139. goto err;
  140. }
  141. #ifndef OPENSSL_NO_PSK
  142. if (src->psk_identity_hint) {
  143. dest->psk_identity_hint = OPENSSL_strdup(src->psk_identity_hint);
  144. if (dest->psk_identity_hint == NULL) {
  145. goto err;
  146. }
  147. }
  148. if (src->psk_identity) {
  149. dest->psk_identity = OPENSSL_strdup(src->psk_identity);
  150. if (dest->psk_identity == NULL) {
  151. goto err;
  152. }
  153. }
  154. #endif
  155. if (src->ciphers != NULL) {
  156. dest->ciphers = sk_SSL_CIPHER_dup(src->ciphers);
  157. if (dest->ciphers == NULL)
  158. goto err;
  159. }
  160. if (!CRYPTO_dup_ex_data(CRYPTO_EX_INDEX_SSL_SESSION,
  161. &dest->ex_data, &src->ex_data)) {
  162. goto err;
  163. }
  164. if (src->ext.hostname) {
  165. dest->ext.hostname = OPENSSL_strdup(src->ext.hostname);
  166. if (dest->ext.hostname == NULL) {
  167. goto err;
  168. }
  169. }
  170. #ifndef OPENSSL_NO_EC
  171. if (src->ext.ecpointformats) {
  172. dest->ext.ecpointformats =
  173. OPENSSL_memdup(src->ext.ecpointformats,
  174. src->ext.ecpointformats_len);
  175. if (dest->ext.ecpointformats == NULL)
  176. goto err;
  177. }
  178. if (src->ext.supportedgroups) {
  179. dest->ext.supportedgroups =
  180. OPENSSL_memdup(src->ext.supportedgroups,
  181. src->ext.supportedgroups_len);
  182. if (dest->ext.supportedgroups == NULL)
  183. goto err;
  184. }
  185. #endif
  186. if (ticket != 0 && src->ext.tick != NULL) {
  187. dest->ext.tick =
  188. OPENSSL_memdup(src->ext.tick, src->ext.ticklen);
  189. if (dest->ext.tick == NULL)
  190. goto err;
  191. } else {
  192. dest->ext.tick_lifetime_hint = 0;
  193. dest->ext.ticklen = 0;
  194. }
  195. if (src->ext.alpn_selected) {
  196. dest->ext.alpn_selected =
  197. (unsigned char*)OPENSSL_strndup((char*)src->ext.alpn_selected,
  198. src->ext.alpn_selected_len);
  199. if (dest->ext.alpn_selected == NULL) {
  200. goto err;
  201. }
  202. }
  203. if (src->ext.tick_nonce != NULL) {
  204. dest->ext.tick_nonce = OPENSSL_memdup(src->ext.tick_nonce,
  205. src->ext.tick_nonce_len);
  206. if (dest->ext.tick_nonce == NULL)
  207. goto err;
  208. }
  209. #ifndef OPENSSL_NO_SRP
  210. if (src->srp_username) {
  211. dest->srp_username = OPENSSL_strdup(src->srp_username);
  212. if (dest->srp_username == NULL) {
  213. goto err;
  214. }
  215. }
  216. #endif
  217. return dest;
  218. err:
  219. SSLerr(SSL_F_SSL_SESSION_DUP, ERR_R_MALLOC_FAILURE);
  220. SSL_SESSION_free(dest);
  221. return NULL;
  222. }
  223. const unsigned char *SSL_SESSION_get_id(const SSL_SESSION *s, unsigned int *len)
  224. {
  225. if (len)
  226. *len = (unsigned int)s->session_id_length;
  227. return s->session_id;
  228. }
  229. const unsigned char *SSL_SESSION_get0_id_context(const SSL_SESSION *s,
  230. unsigned int *len)
  231. {
  232. if (len != NULL)
  233. *len = (unsigned int)s->sid_ctx_length;
  234. return s->sid_ctx;
  235. }
  236. unsigned int SSL_SESSION_get_compress_id(const SSL_SESSION *s)
  237. {
  238. return s->compress_meth;
  239. }
  240. /*
  241. * SSLv3/TLSv1 has 32 bytes (256 bits) of session ID space. As such, filling
  242. * the ID with random junk repeatedly until we have no conflict is going to
  243. * complete in one iteration pretty much "most" of the time (btw:
  244. * understatement). So, if it takes us 10 iterations and we still can't avoid
  245. * a conflict - well that's a reasonable point to call it quits. Either the
  246. * RAND code is broken or someone is trying to open roughly very close to
  247. * 2^256 SSL sessions to our server. How you might store that many sessions
  248. * is perhaps a more interesting question ...
  249. */
  250. #define MAX_SESS_ID_ATTEMPTS 10
  251. static int def_generate_session_id(SSL *ssl, unsigned char *id,
  252. unsigned int *id_len)
  253. {
  254. unsigned int retry = 0;
  255. do
  256. if (ssl_randbytes(ssl, id, *id_len) <= 0)
  257. return 0;
  258. while (SSL_has_matching_session_id(ssl, id, *id_len) &&
  259. (++retry < MAX_SESS_ID_ATTEMPTS)) ;
  260. if (retry < MAX_SESS_ID_ATTEMPTS)
  261. return 1;
  262. /* else - woops a session_id match */
  263. /*
  264. * XXX We should also check the external cache -- but the probability of
  265. * a collision is negligible, and we could not prevent the concurrent
  266. * creation of sessions with identical IDs since we currently don't have
  267. * means to atomically check whether a session ID already exists and make
  268. * a reservation for it if it does not (this problem applies to the
  269. * internal cache as well).
  270. */
  271. return 0;
  272. }
  273. int ssl_get_new_session(SSL *s, int session)
  274. {
  275. /* This gets used by clients and servers. */
  276. unsigned int tmp;
  277. SSL_SESSION *ss = NULL;
  278. GEN_SESSION_CB cb = def_generate_session_id;
  279. if ((ss = SSL_SESSION_new()) == NULL)
  280. return (0);
  281. /* If the context has a default timeout, use it */
  282. if (s->session_ctx->session_timeout == 0)
  283. ss->timeout = SSL_get_default_timeout(s);
  284. else
  285. ss->timeout = s->session_ctx->session_timeout;
  286. SSL_SESSION_free(s->session);
  287. s->session = NULL;
  288. if (session) {
  289. if (s->version == SSL3_VERSION) {
  290. ss->ssl_version = SSL3_VERSION;
  291. ss->session_id_length = SSL3_SSL_SESSION_ID_LENGTH;
  292. } else if (s->version == TLS1_VERSION) {
  293. ss->ssl_version = TLS1_VERSION;
  294. ss->session_id_length = SSL3_SSL_SESSION_ID_LENGTH;
  295. } else if (s->version == TLS1_1_VERSION) {
  296. ss->ssl_version = TLS1_1_VERSION;
  297. ss->session_id_length = SSL3_SSL_SESSION_ID_LENGTH;
  298. } else if (s->version == TLS1_2_VERSION) {
  299. ss->ssl_version = TLS1_2_VERSION;
  300. ss->session_id_length = SSL3_SSL_SESSION_ID_LENGTH;
  301. } else if (s->version == TLS1_3_VERSION) {
  302. ss->ssl_version = TLS1_3_VERSION;
  303. ss->session_id_length = SSL3_SSL_SESSION_ID_LENGTH;
  304. } else if (s->version == DTLS1_BAD_VER) {
  305. ss->ssl_version = DTLS1_BAD_VER;
  306. ss->session_id_length = SSL3_SSL_SESSION_ID_LENGTH;
  307. } else if (s->version == DTLS1_VERSION) {
  308. ss->ssl_version = DTLS1_VERSION;
  309. ss->session_id_length = SSL3_SSL_SESSION_ID_LENGTH;
  310. } else if (s->version == DTLS1_2_VERSION) {
  311. ss->ssl_version = DTLS1_2_VERSION;
  312. ss->session_id_length = SSL3_SSL_SESSION_ID_LENGTH;
  313. } else {
  314. SSLerr(SSL_F_SSL_GET_NEW_SESSION, SSL_R_UNSUPPORTED_SSL_VERSION);
  315. SSL_SESSION_free(ss);
  316. return (0);
  317. }
  318. /*-
  319. * If RFC5077 ticket, use empty session ID (as server).
  320. * Note that:
  321. * (a) ssl_get_prev_session() does lookahead into the
  322. * ClientHello extensions to find the session ticket.
  323. * When ssl_get_prev_session() fails, statem_srvr.c calls
  324. * ssl_get_new_session() in tls_process_client_hello().
  325. * At that point, it has not yet parsed the extensions,
  326. * however, because of the lookahead, it already knows
  327. * whether a ticket is expected or not.
  328. *
  329. * (b) statem_clnt.c calls ssl_get_new_session() before parsing
  330. * ServerHello extensions, and before recording the session
  331. * ID received from the server, so this block is a noop.
  332. */
  333. if (s->ext.ticket_expected) {
  334. ss->session_id_length = 0;
  335. goto sess_id_done;
  336. }
  337. /* Choose which callback will set the session ID */
  338. CRYPTO_THREAD_read_lock(s->lock);
  339. CRYPTO_THREAD_read_lock(s->session_ctx->lock);
  340. if (s->generate_session_id)
  341. cb = s->generate_session_id;
  342. else if (s->session_ctx->generate_session_id)
  343. cb = s->session_ctx->generate_session_id;
  344. CRYPTO_THREAD_unlock(s->session_ctx->lock);
  345. CRYPTO_THREAD_unlock(s->lock);
  346. /* Choose a session ID */
  347. memset(ss->session_id, 0, ss->session_id_length);
  348. tmp = (int)ss->session_id_length;
  349. if (!cb(s, ss->session_id, &tmp)) {
  350. /* The callback failed */
  351. SSLerr(SSL_F_SSL_GET_NEW_SESSION,
  352. SSL_R_SSL_SESSION_ID_CALLBACK_FAILED);
  353. SSL_SESSION_free(ss);
  354. return (0);
  355. }
  356. /*
  357. * Don't allow the callback to set the session length to zero. nor
  358. * set it higher than it was.
  359. */
  360. if (tmp == 0 || tmp > ss->session_id_length) {
  361. /* The callback set an illegal length */
  362. SSLerr(SSL_F_SSL_GET_NEW_SESSION,
  363. SSL_R_SSL_SESSION_ID_HAS_BAD_LENGTH);
  364. SSL_SESSION_free(ss);
  365. return (0);
  366. }
  367. ss->session_id_length = tmp;
  368. /* Finally, check for a conflict */
  369. if (SSL_has_matching_session_id(s, ss->session_id,
  370. (unsigned int)ss->session_id_length)) {
  371. SSLerr(SSL_F_SSL_GET_NEW_SESSION, SSL_R_SSL_SESSION_ID_CONFLICT);
  372. SSL_SESSION_free(ss);
  373. return (0);
  374. }
  375. sess_id_done:
  376. if (s->ext.hostname) {
  377. ss->ext.hostname = OPENSSL_strdup(s->ext.hostname);
  378. if (ss->ext.hostname == NULL) {
  379. SSLerr(SSL_F_SSL_GET_NEW_SESSION, ERR_R_INTERNAL_ERROR);
  380. SSL_SESSION_free(ss);
  381. return 0;
  382. }
  383. }
  384. } else {
  385. ss->session_id_length = 0;
  386. }
  387. if (s->sid_ctx_length > sizeof ss->sid_ctx) {
  388. SSLerr(SSL_F_SSL_GET_NEW_SESSION, ERR_R_INTERNAL_ERROR);
  389. SSL_SESSION_free(ss);
  390. return 0;
  391. }
  392. memcpy(ss->sid_ctx, s->sid_ctx, s->sid_ctx_length);
  393. ss->sid_ctx_length = s->sid_ctx_length;
  394. s->session = ss;
  395. ss->ssl_version = s->version;
  396. ss->verify_result = X509_V_OK;
  397. /* If client supports extended master secret set it in session */
  398. if (s->s3->flags & TLS1_FLAGS_RECEIVED_EXTMS)
  399. ss->flags |= SSL_SESS_FLAG_EXTMS;
  400. return (1);
  401. }
  402. /*-
  403. * ssl_get_prev attempts to find an SSL_SESSION to be used to resume this
  404. * connection. It is only called by servers.
  405. *
  406. * hello: The parsed ClientHello data
  407. *
  408. * Returns:
  409. * -1: fatal error
  410. * 0: no session found
  411. * 1: a session may have been found.
  412. *
  413. * Side effects:
  414. * - If a session is found then s->session is pointed at it (after freeing an
  415. * existing session if need be) and s->verify_result is set from the session.
  416. * - Both for new and resumed sessions, s->ext.ticket_expected is set to 1
  417. * if the server should issue a new session ticket (to 0 otherwise).
  418. */
  419. int ssl_get_prev_session(SSL *s, CLIENTHELLO_MSG *hello, int *al)
  420. {
  421. /* This is used only by servers. */
  422. SSL_SESSION *ret = NULL;
  423. int fatal = 0;
  424. int try_session_cache = 0;
  425. TICKET_RETURN r;
  426. if (SSL_IS_TLS13(s)) {
  427. if (!tls_parse_extension(s, TLSEXT_IDX_psk_kex_modes,
  428. SSL_EXT_CLIENT_HELLO, hello->pre_proc_exts,
  429. NULL, 0, al)
  430. || !tls_parse_extension(s, TLSEXT_IDX_psk, SSL_EXT_CLIENT_HELLO,
  431. hello->pre_proc_exts, NULL, 0, al))
  432. return -1;
  433. ret = s->session;
  434. } else {
  435. /* sets s->ext.ticket_expected */
  436. r = tls_get_ticket_from_client(s, hello, &ret);
  437. switch (r) {
  438. case TICKET_FATAL_ERR_MALLOC:
  439. case TICKET_FATAL_ERR_OTHER:
  440. fatal = 1;
  441. goto err;
  442. case TICKET_NONE:
  443. case TICKET_EMPTY:
  444. try_session_cache = 1;
  445. break;
  446. case TICKET_NO_DECRYPT:
  447. case TICKET_SUCCESS:
  448. case TICKET_SUCCESS_RENEW:
  449. break;
  450. }
  451. }
  452. if (try_session_cache &&
  453. ret == NULL &&
  454. !(s->session_ctx->session_cache_mode &
  455. SSL_SESS_CACHE_NO_INTERNAL_LOOKUP)) {
  456. SSL_SESSION data;
  457. data.ssl_version = s->version;
  458. memcpy(data.session_id, hello->session_id, hello->session_id_len);
  459. data.session_id_length = hello->session_id_len;
  460. CRYPTO_THREAD_read_lock(s->session_ctx->lock);
  461. ret = lh_SSL_SESSION_retrieve(s->session_ctx->sessions, &data);
  462. if (ret != NULL) {
  463. /* don't allow other threads to steal it: */
  464. SSL_SESSION_up_ref(ret);
  465. }
  466. CRYPTO_THREAD_unlock(s->session_ctx->lock);
  467. if (ret == NULL)
  468. s->session_ctx->stats.sess_miss++;
  469. }
  470. if (try_session_cache &&
  471. ret == NULL && s->session_ctx->get_session_cb != NULL) {
  472. int copy = 1;
  473. ret = s->session_ctx->get_session_cb(s, hello->session_id,
  474. hello->session_id_len,
  475. &copy);
  476. if (ret != NULL) {
  477. s->session_ctx->stats.sess_cb_hit++;
  478. /*
  479. * Increment reference count now if the session callback asks us
  480. * to do so (note that if the session structures returned by the
  481. * callback are shared between threads, it must handle the
  482. * reference count itself [i.e. copy == 0], or things won't be
  483. * thread-safe).
  484. */
  485. if (copy)
  486. SSL_SESSION_up_ref(ret);
  487. /*
  488. * Add the externally cached session to the internal cache as
  489. * well if and only if we are supposed to.
  490. */
  491. if (!
  492. (s->session_ctx->session_cache_mode &
  493. SSL_SESS_CACHE_NO_INTERNAL_STORE)) {
  494. /*
  495. * Either return value of SSL_CTX_add_session should not
  496. * interrupt the session resumption process. The return
  497. * value is intentionally ignored.
  498. */
  499. SSL_CTX_add_session(s->session_ctx, ret);
  500. }
  501. }
  502. }
  503. if (ret == NULL)
  504. goto err;
  505. /* Now ret is non-NULL and we own one of its reference counts. */
  506. /* Check TLS version consistency */
  507. if (ret->ssl_version != s->version)
  508. goto err;
  509. if (ret->sid_ctx_length != s->sid_ctx_length
  510. || memcmp(ret->sid_ctx, s->sid_ctx, ret->sid_ctx_length)) {
  511. /*
  512. * We have the session requested by the client, but we don't want to
  513. * use it in this context.
  514. */
  515. goto err; /* treat like cache miss */
  516. }
  517. if ((s->verify_mode & SSL_VERIFY_PEER) && s->sid_ctx_length == 0) {
  518. /*
  519. * We can't be sure if this session is being used out of context,
  520. * which is especially important for SSL_VERIFY_PEER. The application
  521. * should have used SSL[_CTX]_set_session_id_context. For this error
  522. * case, we generate an error instead of treating the event like a
  523. * cache miss (otherwise it would be easy for applications to
  524. * effectively disable the session cache by accident without anyone
  525. * noticing).
  526. */
  527. SSLerr(SSL_F_SSL_GET_PREV_SESSION,
  528. SSL_R_SESSION_ID_CONTEXT_UNINITIALIZED);
  529. fatal = 1;
  530. goto err;
  531. }
  532. if (ret->timeout < (long)(time(NULL) - ret->time)) { /* timeout */
  533. s->session_ctx->stats.sess_timeout++;
  534. if (try_session_cache) {
  535. /* session was from the cache, so remove it */
  536. SSL_CTX_remove_session(s->session_ctx, ret);
  537. }
  538. goto err;
  539. }
  540. /* Check extended master secret extension consistency */
  541. if (ret->flags & SSL_SESS_FLAG_EXTMS) {
  542. /* If old session includes extms, but new does not: abort handshake */
  543. if (!(s->s3->flags & TLS1_FLAGS_RECEIVED_EXTMS)) {
  544. SSLerr(SSL_F_SSL_GET_PREV_SESSION, SSL_R_INCONSISTENT_EXTMS);
  545. ssl3_send_alert(s, SSL3_AL_FATAL, SSL_AD_ILLEGAL_PARAMETER);
  546. fatal = 1;
  547. goto err;
  548. }
  549. } else if (s->s3->flags & TLS1_FLAGS_RECEIVED_EXTMS) {
  550. /* If new session includes extms, but old does not: do not resume */
  551. goto err;
  552. }
  553. if (!SSL_IS_TLS13(s)) {
  554. /* We already did this for TLS1.3 */
  555. SSL_SESSION_free(s->session);
  556. s->session = ret;
  557. }
  558. s->session_ctx->stats.sess_hit++;
  559. s->verify_result = s->session->verify_result;
  560. return 1;
  561. err:
  562. if (ret != NULL) {
  563. SSL_SESSION_free(ret);
  564. /* In TLSv1.3 s->session was already set to ret, so we NULL it out */
  565. if (SSL_IS_TLS13(s))
  566. s->session = NULL;
  567. if (!try_session_cache) {
  568. /*
  569. * The session was from a ticket, so we should issue a ticket for
  570. * the new session
  571. */
  572. s->ext.ticket_expected = 1;
  573. }
  574. }
  575. if (fatal) {
  576. *al = SSL_AD_INTERNAL_ERROR;
  577. return -1;
  578. }
  579. return 0;
  580. }
  581. int SSL_CTX_add_session(SSL_CTX *ctx, SSL_SESSION *c)
  582. {
  583. int ret = 0;
  584. SSL_SESSION *s;
  585. /*
  586. * add just 1 reference count for the SSL_CTX's session cache even though
  587. * it has two ways of access: each session is in a doubly linked list and
  588. * an lhash
  589. */
  590. SSL_SESSION_up_ref(c);
  591. /*
  592. * if session c is in already in cache, we take back the increment later
  593. */
  594. CRYPTO_THREAD_write_lock(ctx->lock);
  595. s = lh_SSL_SESSION_insert(ctx->sessions, c);
  596. /*
  597. * s != NULL iff we already had a session with the given PID. In this
  598. * case, s == c should hold (then we did not really modify
  599. * ctx->sessions), or we're in trouble.
  600. */
  601. if (s != NULL && s != c) {
  602. /* We *are* in trouble ... */
  603. SSL_SESSION_list_remove(ctx, s);
  604. SSL_SESSION_free(s);
  605. /*
  606. * ... so pretend the other session did not exist in cache (we cannot
  607. * handle two SSL_SESSION structures with identical session ID in the
  608. * same cache, which could happen e.g. when two threads concurrently
  609. * obtain the same session from an external cache)
  610. */
  611. s = NULL;
  612. } else if (s == NULL &&
  613. lh_SSL_SESSION_retrieve(ctx->sessions, c) == NULL) {
  614. /* s == NULL can also mean OOM error in lh_SSL_SESSION_insert ... */
  615. /*
  616. * ... so take back the extra reference and also don't add
  617. * the session to the SSL_SESSION_list at this time
  618. */
  619. s = c;
  620. }
  621. /* Put at the head of the queue unless it is already in the cache */
  622. if (s == NULL)
  623. SSL_SESSION_list_add(ctx, c);
  624. if (s != NULL) {
  625. /*
  626. * existing cache entry -- decrement previously incremented reference
  627. * count because it already takes into account the cache
  628. */
  629. SSL_SESSION_free(s); /* s == c */
  630. ret = 0;
  631. } else {
  632. /*
  633. * new cache entry -- remove old ones if cache has become too large
  634. */
  635. ret = 1;
  636. if (SSL_CTX_sess_get_cache_size(ctx) > 0) {
  637. while (SSL_CTX_sess_number(ctx) > SSL_CTX_sess_get_cache_size(ctx)) {
  638. if (!remove_session_lock(ctx, ctx->session_cache_tail, 0))
  639. break;
  640. else
  641. ctx->stats.sess_cache_full++;
  642. }
  643. }
  644. }
  645. CRYPTO_THREAD_unlock(ctx->lock);
  646. return ret;
  647. }
  648. int SSL_CTX_remove_session(SSL_CTX *ctx, SSL_SESSION *c)
  649. {
  650. return remove_session_lock(ctx, c, 1);
  651. }
  652. static int remove_session_lock(SSL_CTX *ctx, SSL_SESSION *c, int lck)
  653. {
  654. SSL_SESSION *r;
  655. int ret = 0;
  656. if ((c != NULL) && (c->session_id_length != 0)) {
  657. if (lck)
  658. CRYPTO_THREAD_write_lock(ctx->lock);
  659. if ((r = lh_SSL_SESSION_retrieve(ctx->sessions, c)) == c) {
  660. ret = 1;
  661. r = lh_SSL_SESSION_delete(ctx->sessions, c);
  662. SSL_SESSION_list_remove(ctx, c);
  663. }
  664. c->not_resumable = 1;
  665. if (lck)
  666. CRYPTO_THREAD_unlock(ctx->lock);
  667. if (ret)
  668. SSL_SESSION_free(r);
  669. if (ctx->remove_session_cb != NULL)
  670. ctx->remove_session_cb(ctx, c);
  671. } else
  672. ret = 0;
  673. return (ret);
  674. }
  675. void SSL_SESSION_free(SSL_SESSION *ss)
  676. {
  677. int i;
  678. if (ss == NULL)
  679. return;
  680. CRYPTO_DOWN_REF(&ss->references, &i, ss->lock);
  681. REF_PRINT_COUNT("SSL_SESSION", ss);
  682. if (i > 0)
  683. return;
  684. REF_ASSERT_ISNT(i < 0);
  685. CRYPTO_free_ex_data(CRYPTO_EX_INDEX_SSL_SESSION, ss, &ss->ex_data);
  686. OPENSSL_cleanse(ss->master_key, sizeof ss->master_key);
  687. OPENSSL_cleanse(ss->session_id, sizeof ss->session_id);
  688. X509_free(ss->peer);
  689. sk_X509_pop_free(ss->peer_chain, X509_free);
  690. sk_SSL_CIPHER_free(ss->ciphers);
  691. OPENSSL_free(ss->ext.hostname);
  692. OPENSSL_free(ss->ext.tick);
  693. #ifndef OPENSSL_NO_EC
  694. OPENSSL_free(ss->ext.ecpointformats);
  695. ss->ext.ecpointformats = NULL;
  696. ss->ext.ecpointformats_len = 0;
  697. OPENSSL_free(ss->ext.supportedgroups);
  698. ss->ext.supportedgroups = NULL;
  699. ss->ext.supportedgroups_len = 0;
  700. #endif /* OPENSSL_NO_EC */
  701. #ifndef OPENSSL_NO_PSK
  702. OPENSSL_free(ss->psk_identity_hint);
  703. OPENSSL_free(ss->psk_identity);
  704. #endif
  705. #ifndef OPENSSL_NO_SRP
  706. OPENSSL_free(ss->srp_username);
  707. #endif
  708. OPENSSL_free(ss->ext.alpn_selected);
  709. OPENSSL_free(ss->ext.tick_nonce);
  710. CRYPTO_THREAD_lock_free(ss->lock);
  711. OPENSSL_clear_free(ss, sizeof(*ss));
  712. }
  713. int SSL_SESSION_up_ref(SSL_SESSION *ss)
  714. {
  715. int i;
  716. if (CRYPTO_UP_REF(&ss->references, &i, ss->lock) <= 0)
  717. return 0;
  718. REF_PRINT_COUNT("SSL_SESSION", ss);
  719. REF_ASSERT_ISNT(i < 2);
  720. return ((i > 1) ? 1 : 0);
  721. }
  722. int SSL_set_session(SSL *s, SSL_SESSION *session)
  723. {
  724. ssl_clear_bad_session(s);
  725. if (s->ctx->method != s->method) {
  726. if (!SSL_set_ssl_method(s, s->ctx->method))
  727. return 0;
  728. }
  729. if (session != NULL) {
  730. SSL_SESSION_up_ref(session);
  731. s->verify_result = session->verify_result;
  732. }
  733. SSL_SESSION_free(s->session);
  734. s->session = session;
  735. return 1;
  736. }
  737. int SSL_SESSION_set1_id(SSL_SESSION *s, const unsigned char *sid,
  738. unsigned int sid_len)
  739. {
  740. if (sid_len > SSL_MAX_SSL_SESSION_ID_LENGTH) {
  741. SSLerr(SSL_F_SSL_SESSION_SET1_ID,
  742. SSL_R_SSL_SESSION_ID_TOO_LONG);
  743. return 0;
  744. }
  745. s->session_id_length = sid_len;
  746. if (sid != s->session_id)
  747. memcpy(s->session_id, sid, sid_len);
  748. return 1;
  749. }
  750. long SSL_SESSION_set_timeout(SSL_SESSION *s, long t)
  751. {
  752. if (s == NULL)
  753. return (0);
  754. s->timeout = t;
  755. return (1);
  756. }
  757. long SSL_SESSION_get_timeout(const SSL_SESSION *s)
  758. {
  759. if (s == NULL)
  760. return (0);
  761. return (s->timeout);
  762. }
  763. long SSL_SESSION_get_time(const SSL_SESSION *s)
  764. {
  765. if (s == NULL)
  766. return (0);
  767. return (s->time);
  768. }
  769. long SSL_SESSION_set_time(SSL_SESSION *s, long t)
  770. {
  771. if (s == NULL)
  772. return (0);
  773. s->time = t;
  774. return (t);
  775. }
  776. int SSL_SESSION_get_protocol_version(const SSL_SESSION *s)
  777. {
  778. return s->ssl_version;
  779. }
  780. int SSL_SESSION_set_protocol_version(SSL_SESSION *s, int version)
  781. {
  782. s->ssl_version = version;
  783. return 1;
  784. }
  785. const SSL_CIPHER *SSL_SESSION_get0_cipher(const SSL_SESSION *s)
  786. {
  787. return s->cipher;
  788. }
  789. int SSL_SESSION_set_cipher(SSL_SESSION *s, const SSL_CIPHER *cipher)
  790. {
  791. s->cipher = cipher;
  792. return 1;
  793. }
  794. const char *SSL_SESSION_get0_hostname(const SSL_SESSION *s)
  795. {
  796. return s->ext.hostname;
  797. }
  798. int SSL_SESSION_has_ticket(const SSL_SESSION *s)
  799. {
  800. return (s->ext.ticklen > 0) ? 1 : 0;
  801. }
  802. unsigned long SSL_SESSION_get_ticket_lifetime_hint(const SSL_SESSION *s)
  803. {
  804. return s->ext.tick_lifetime_hint;
  805. }
  806. void SSL_SESSION_get0_ticket(const SSL_SESSION *s, const unsigned char **tick,
  807. size_t *len)
  808. {
  809. *len = s->ext.ticklen;
  810. if (tick != NULL)
  811. *tick = s->ext.tick;
  812. }
  813. uint32_t SSL_SESSION_get_max_early_data(const SSL_SESSION *s)
  814. {
  815. return s->ext.max_early_data;
  816. }
  817. X509 *SSL_SESSION_get0_peer(SSL_SESSION *s)
  818. {
  819. return s->peer;
  820. }
  821. int SSL_SESSION_set1_id_context(SSL_SESSION *s, const unsigned char *sid_ctx,
  822. unsigned int sid_ctx_len)
  823. {
  824. if (sid_ctx_len > SSL_MAX_SID_CTX_LENGTH) {
  825. SSLerr(SSL_F_SSL_SESSION_SET1_ID_CONTEXT,
  826. SSL_R_SSL_SESSION_ID_CONTEXT_TOO_LONG);
  827. return 0;
  828. }
  829. s->sid_ctx_length = sid_ctx_len;
  830. if (sid_ctx != s->sid_ctx)
  831. memcpy(s->sid_ctx, sid_ctx, sid_ctx_len);
  832. return 1;
  833. }
  834. int SSL_SESSION_is_resumable(const SSL_SESSION *s)
  835. {
  836. /*
  837. * In the case of EAP-FAST, we can have a pre-shared "ticket" without a
  838. * session ID.
  839. */
  840. return !s->not_resumable
  841. && (s->session_id_length > 0 || s->ext.ticklen > 0);
  842. }
  843. long SSL_CTX_set_timeout(SSL_CTX *s, long t)
  844. {
  845. long l;
  846. if (s == NULL)
  847. return (0);
  848. l = s->session_timeout;
  849. s->session_timeout = t;
  850. return (l);
  851. }
  852. long SSL_CTX_get_timeout(const SSL_CTX *s)
  853. {
  854. if (s == NULL)
  855. return (0);
  856. return (s->session_timeout);
  857. }
  858. int SSL_set_session_secret_cb(SSL *s,
  859. tls_session_secret_cb_fn tls_session_secret_cb,
  860. void *arg)
  861. {
  862. if (s == NULL)
  863. return (0);
  864. s->ext.session_secret_cb = tls_session_secret_cb;
  865. s->ext.session_secret_cb_arg = arg;
  866. return (1);
  867. }
  868. int SSL_set_session_ticket_ext_cb(SSL *s, tls_session_ticket_ext_cb_fn cb,
  869. void *arg)
  870. {
  871. if (s == NULL)
  872. return (0);
  873. s->ext.session_ticket_cb = cb;
  874. s->ext.session_ticket_cb_arg = arg;
  875. return (1);
  876. }
  877. int SSL_set_session_ticket_ext(SSL *s, void *ext_data, int ext_len)
  878. {
  879. if (s->version >= TLS1_VERSION) {
  880. OPENSSL_free(s->ext.session_ticket);
  881. s->ext.session_ticket = NULL;
  882. s->ext.session_ticket =
  883. OPENSSL_malloc(sizeof(TLS_SESSION_TICKET_EXT) + ext_len);
  884. if (s->ext.session_ticket == NULL) {
  885. SSLerr(SSL_F_SSL_SET_SESSION_TICKET_EXT, ERR_R_MALLOC_FAILURE);
  886. return 0;
  887. }
  888. if (ext_data != NULL) {
  889. s->ext.session_ticket->length = ext_len;
  890. s->ext.session_ticket->data = s->ext.session_ticket + 1;
  891. memcpy(s->ext.session_ticket->data, ext_data, ext_len);
  892. } else {
  893. s->ext.session_ticket->length = 0;
  894. s->ext.session_ticket->data = NULL;
  895. }
  896. return 1;
  897. }
  898. return 0;
  899. }
  900. typedef struct timeout_param_st {
  901. SSL_CTX *ctx;
  902. long time;
  903. LHASH_OF(SSL_SESSION) *cache;
  904. } TIMEOUT_PARAM;
  905. static void timeout_cb(SSL_SESSION *s, TIMEOUT_PARAM *p)
  906. {
  907. if ((p->time == 0) || (p->time > (s->time + s->timeout))) { /* timeout */
  908. /*
  909. * The reason we don't call SSL_CTX_remove_session() is to save on
  910. * locking overhead
  911. */
  912. (void)lh_SSL_SESSION_delete(p->cache, s);
  913. SSL_SESSION_list_remove(p->ctx, s);
  914. s->not_resumable = 1;
  915. if (p->ctx->remove_session_cb != NULL)
  916. p->ctx->remove_session_cb(p->ctx, s);
  917. SSL_SESSION_free(s);
  918. }
  919. }
  920. IMPLEMENT_LHASH_DOALL_ARG(SSL_SESSION, TIMEOUT_PARAM);
  921. void SSL_CTX_flush_sessions(SSL_CTX *s, long t)
  922. {
  923. unsigned long i;
  924. TIMEOUT_PARAM tp;
  925. tp.ctx = s;
  926. tp.cache = s->sessions;
  927. if (tp.cache == NULL)
  928. return;
  929. tp.time = t;
  930. CRYPTO_THREAD_write_lock(s->lock);
  931. i = lh_SSL_SESSION_get_down_load(s->sessions);
  932. lh_SSL_SESSION_set_down_load(s->sessions, 0);
  933. lh_SSL_SESSION_doall_TIMEOUT_PARAM(tp.cache, timeout_cb, &tp);
  934. lh_SSL_SESSION_set_down_load(s->sessions, i);
  935. CRYPTO_THREAD_unlock(s->lock);
  936. }
  937. int ssl_clear_bad_session(SSL *s)
  938. {
  939. if ((s->session != NULL) &&
  940. !(s->shutdown & SSL_SENT_SHUTDOWN) &&
  941. !(SSL_in_init(s) || SSL_in_before(s))) {
  942. SSL_CTX_remove_session(s->session_ctx, s->session);
  943. return (1);
  944. } else
  945. return (0);
  946. }
  947. /* locked by SSL_CTX in the calling function */
  948. static void SSL_SESSION_list_remove(SSL_CTX *ctx, SSL_SESSION *s)
  949. {
  950. if ((s->next == NULL) || (s->prev == NULL))
  951. return;
  952. if (s->next == (SSL_SESSION *)&(ctx->session_cache_tail)) {
  953. /* last element in list */
  954. if (s->prev == (SSL_SESSION *)&(ctx->session_cache_head)) {
  955. /* only one element in list */
  956. ctx->session_cache_head = NULL;
  957. ctx->session_cache_tail = NULL;
  958. } else {
  959. ctx->session_cache_tail = s->prev;
  960. s->prev->next = (SSL_SESSION *)&(ctx->session_cache_tail);
  961. }
  962. } else {
  963. if (s->prev == (SSL_SESSION *)&(ctx->session_cache_head)) {
  964. /* first element in list */
  965. ctx->session_cache_head = s->next;
  966. s->next->prev = (SSL_SESSION *)&(ctx->session_cache_head);
  967. } else {
  968. /* middle of list */
  969. s->next->prev = s->prev;
  970. s->prev->next = s->next;
  971. }
  972. }
  973. s->prev = s->next = NULL;
  974. }
  975. static void SSL_SESSION_list_add(SSL_CTX *ctx, SSL_SESSION *s)
  976. {
  977. if ((s->next != NULL) && (s->prev != NULL))
  978. SSL_SESSION_list_remove(ctx, s);
  979. if (ctx->session_cache_head == NULL) {
  980. ctx->session_cache_head = s;
  981. ctx->session_cache_tail = s;
  982. s->prev = (SSL_SESSION *)&(ctx->session_cache_head);
  983. s->next = (SSL_SESSION *)&(ctx->session_cache_tail);
  984. } else {
  985. s->next = ctx->session_cache_head;
  986. s->next->prev = s;
  987. s->prev = (SSL_SESSION *)&(ctx->session_cache_head);
  988. ctx->session_cache_head = s;
  989. }
  990. }
  991. void SSL_CTX_sess_set_new_cb(SSL_CTX *ctx,
  992. int (*cb) (struct ssl_st *ssl, SSL_SESSION *sess))
  993. {
  994. ctx->new_session_cb = cb;
  995. }
  996. int (*SSL_CTX_sess_get_new_cb(SSL_CTX *ctx)) (SSL *ssl, SSL_SESSION *sess) {
  997. return ctx->new_session_cb;
  998. }
  999. void SSL_CTX_sess_set_remove_cb(SSL_CTX *ctx,
  1000. void (*cb) (SSL_CTX *ctx, SSL_SESSION *sess))
  1001. {
  1002. ctx->remove_session_cb = cb;
  1003. }
  1004. void (*SSL_CTX_sess_get_remove_cb(SSL_CTX *ctx)) (SSL_CTX *ctx,
  1005. SSL_SESSION *sess) {
  1006. return ctx->remove_session_cb;
  1007. }
  1008. void SSL_CTX_sess_set_get_cb(SSL_CTX *ctx,
  1009. SSL_SESSION *(*cb) (struct ssl_st *ssl,
  1010. const unsigned char *data,
  1011. int len, int *copy))
  1012. {
  1013. ctx->get_session_cb = cb;
  1014. }
  1015. SSL_SESSION *(*SSL_CTX_sess_get_get_cb(SSL_CTX *ctx)) (SSL *ssl,
  1016. const unsigned char
  1017. *data, int len,
  1018. int *copy) {
  1019. return ctx->get_session_cb;
  1020. }
  1021. void SSL_CTX_set_info_callback(SSL_CTX *ctx,
  1022. void (*cb) (const SSL *ssl, int type, int val))
  1023. {
  1024. ctx->info_callback = cb;
  1025. }
  1026. void (*SSL_CTX_get_info_callback(SSL_CTX *ctx)) (const SSL *ssl, int type,
  1027. int val) {
  1028. return ctx->info_callback;
  1029. }
  1030. void SSL_CTX_set_client_cert_cb(SSL_CTX *ctx,
  1031. int (*cb) (SSL *ssl, X509 **x509,
  1032. EVP_PKEY **pkey))
  1033. {
  1034. ctx->client_cert_cb = cb;
  1035. }
  1036. int (*SSL_CTX_get_client_cert_cb(SSL_CTX *ctx)) (SSL *ssl, X509 **x509,
  1037. EVP_PKEY **pkey) {
  1038. return ctx->client_cert_cb;
  1039. }
  1040. #ifndef OPENSSL_NO_ENGINE
  1041. int SSL_CTX_set_client_cert_engine(SSL_CTX *ctx, ENGINE *e)
  1042. {
  1043. if (!ENGINE_init(e)) {
  1044. SSLerr(SSL_F_SSL_CTX_SET_CLIENT_CERT_ENGINE, ERR_R_ENGINE_LIB);
  1045. return 0;
  1046. }
  1047. if (!ENGINE_get_ssl_client_cert_function(e)) {
  1048. SSLerr(SSL_F_SSL_CTX_SET_CLIENT_CERT_ENGINE,
  1049. SSL_R_NO_CLIENT_CERT_METHOD);
  1050. ENGINE_finish(e);
  1051. return 0;
  1052. }
  1053. ctx->client_cert_engine = e;
  1054. return 1;
  1055. }
  1056. #endif
  1057. void SSL_CTX_set_cookie_generate_cb(SSL_CTX *ctx,
  1058. int (*cb) (SSL *ssl,
  1059. unsigned char *cookie,
  1060. unsigned int *cookie_len))
  1061. {
  1062. ctx->app_gen_cookie_cb = cb;
  1063. }
  1064. void SSL_CTX_set_cookie_verify_cb(SSL_CTX *ctx,
  1065. int (*cb) (SSL *ssl,
  1066. const unsigned char *cookie,
  1067. unsigned int cookie_len))
  1068. {
  1069. ctx->app_verify_cookie_cb = cb;
  1070. }
  1071. IMPLEMENT_PEM_rw(SSL_SESSION, SSL_SESSION, PEM_STRING_SSL_SESSION, SSL_SESSION)