ssl_sess.c 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107
  1. /* ssl/ssl_sess.c */
  2. /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
  3. * All rights reserved.
  4. *
  5. * This package is an SSL implementation written
  6. * by Eric Young (eay@cryptsoft.com).
  7. * The implementation was written so as to conform with Netscapes SSL.
  8. *
  9. * This library is free for commercial and non-commercial use as long as
  10. * the following conditions are aheared to. The following conditions
  11. * apply to all code found in this distribution, be it the RC4, RSA,
  12. * lhash, DES, etc., code; not just the SSL code. The SSL documentation
  13. * included with this distribution is covered by the same copyright terms
  14. * except that the holder is Tim Hudson (tjh@cryptsoft.com).
  15. *
  16. * Copyright remains Eric Young's, and as such any Copyright notices in
  17. * the code are not to be removed.
  18. * If this package is used in a product, Eric Young should be given attribution
  19. * as the author of the parts of the library used.
  20. * This can be in the form of a textual message at program startup or
  21. * in documentation (online or textual) provided with the package.
  22. *
  23. * Redistribution and use in source and binary forms, with or without
  24. * modification, are permitted provided that the following conditions
  25. * are met:
  26. * 1. Redistributions of source code must retain the copyright
  27. * notice, this list of conditions and the following disclaimer.
  28. * 2. Redistributions in binary form must reproduce the above copyright
  29. * notice, this list of conditions and the following disclaimer in the
  30. * documentation and/or other materials provided with the distribution.
  31. * 3. All advertising materials mentioning features or use of this software
  32. * must display the following acknowledgement:
  33. * "This product includes cryptographic software written by
  34. * Eric Young (eay@cryptsoft.com)"
  35. * The word 'cryptographic' can be left out if the rouines from the library
  36. * being used are not cryptographic related :-).
  37. * 4. If you include any Windows specific code (or a derivative thereof) from
  38. * the apps directory (application code) you must include an acknowledgement:
  39. * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
  40. *
  41. * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
  42. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  43. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  44. * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
  45. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  46. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  47. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  48. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  49. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  50. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  51. * SUCH DAMAGE.
  52. *
  53. * The licence and distribution terms for any publically available version or
  54. * derivative of this code cannot be changed. i.e. this code cannot simply be
  55. * copied and put under another distribution licence
  56. * [including the GNU Public Licence.]
  57. */
  58. /* ====================================================================
  59. * Copyright (c) 1998-2006 The OpenSSL Project. All rights reserved.
  60. *
  61. * Redistribution and use in source and binary forms, with or without
  62. * modification, are permitted provided that the following conditions
  63. * are met:
  64. *
  65. * 1. Redistributions of source code must retain the above copyright
  66. * notice, this list of conditions and the following disclaimer.
  67. *
  68. * 2. Redistributions in binary form must reproduce the above copyright
  69. * notice, this list of conditions and the following disclaimer in
  70. * the documentation and/or other materials provided with the
  71. * distribution.
  72. *
  73. * 3. All advertising materials mentioning features or use of this
  74. * software must display the following acknowledgment:
  75. * "This product includes software developed by the OpenSSL Project
  76. * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
  77. *
  78. * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
  79. * endorse or promote products derived from this software without
  80. * prior written permission. For written permission, please contact
  81. * openssl-core@openssl.org.
  82. *
  83. * 5. Products derived from this software may not be called "OpenSSL"
  84. * nor may "OpenSSL" appear in their names without prior written
  85. * permission of the OpenSSL Project.
  86. *
  87. * 6. Redistributions of any form whatsoever must retain the following
  88. * acknowledgment:
  89. * "This product includes software developed by the OpenSSL Project
  90. * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
  91. *
  92. * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
  93. * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  94. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  95. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
  96. * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  97. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  98. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  99. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  100. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  101. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  102. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
  103. * OF THE POSSIBILITY OF SUCH DAMAGE.
  104. * ====================================================================
  105. *
  106. * This product includes cryptographic software written by Eric Young
  107. * (eay@cryptsoft.com). This product includes software written by Tim
  108. * Hudson (tjh@cryptsoft.com).
  109. *
  110. */
  111. /* ====================================================================
  112. * Copyright 2005 Nokia. All rights reserved.
  113. *
  114. * The portions of the attached software ("Contribution") is developed by
  115. * Nokia Corporation and is licensed pursuant to the OpenSSL open source
  116. * license.
  117. *
  118. * The Contribution, originally written by Mika Kousa and Pasi Eronen of
  119. * Nokia Corporation, consists of the "PSK" (Pre-Shared Key) ciphersuites
  120. * support (see RFC 4279) to OpenSSL.
  121. *
  122. * No patent licenses or other rights except those expressly stated in
  123. * the OpenSSL open source license shall be deemed granted or received
  124. * expressly, by implication, estoppel, or otherwise.
  125. *
  126. * No assurances are provided by Nokia that the Contribution does not
  127. * infringe the patent or other intellectual property rights of any third
  128. * party or that the license provides you with all the necessary rights
  129. * to make use of the Contribution.
  130. *
  131. * THE SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. IN
  132. * ADDITION TO THE DISCLAIMERS INCLUDED IN THE LICENSE, NOKIA
  133. * SPECIFICALLY DISCLAIMS ANY LIABILITY FOR CLAIMS BROUGHT BY YOU OR ANY
  134. * OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS OR
  135. * OTHERWISE.
  136. */
  137. #include <stdio.h>
  138. #include <openssl/lhash.h>
  139. #include <openssl/rand.h>
  140. #ifndef OPENSSL_NO_ENGINE
  141. #include <openssl/engine.h>
  142. #endif
  143. #include "ssl_locl.h"
  144. static void SSL_SESSION_list_remove(SSL_CTX *ctx, SSL_SESSION *s);
  145. static void SSL_SESSION_list_add(SSL_CTX *ctx,SSL_SESSION *s);
  146. static int remove_session_lock(SSL_CTX *ctx, SSL_SESSION *c, int lck);
  147. SSL_SESSION *SSL_get_session(const SSL *ssl)
  148. /* aka SSL_get0_session; gets 0 objects, just returns a copy of the pointer */
  149. {
  150. return(ssl->session);
  151. }
  152. SSL_SESSION *SSL_get1_session(SSL *ssl)
  153. /* variant of SSL_get_session: caller really gets something */
  154. {
  155. SSL_SESSION *sess;
  156. /* Need to lock this all up rather than just use CRYPTO_add so that
  157. * somebody doesn't free ssl->session between when we check it's
  158. * non-null and when we up the reference count. */
  159. CRYPTO_w_lock(CRYPTO_LOCK_SSL_SESSION);
  160. sess = ssl->session;
  161. if(sess)
  162. sess->references++;
  163. CRYPTO_w_unlock(CRYPTO_LOCK_SSL_SESSION);
  164. return(sess);
  165. }
  166. int SSL_SESSION_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
  167. CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func)
  168. {
  169. return CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_SSL_SESSION, argl, argp,
  170. new_func, dup_func, free_func);
  171. }
  172. int SSL_SESSION_set_ex_data(SSL_SESSION *s, int idx, void *arg)
  173. {
  174. return(CRYPTO_set_ex_data(&s->ex_data,idx,arg));
  175. }
  176. void *SSL_SESSION_get_ex_data(const SSL_SESSION *s, int idx)
  177. {
  178. return(CRYPTO_get_ex_data(&s->ex_data,idx));
  179. }
  180. SSL_SESSION *SSL_SESSION_new(void)
  181. {
  182. SSL_SESSION *ss;
  183. ss=(SSL_SESSION *)OPENSSL_malloc(sizeof(SSL_SESSION));
  184. if (ss == NULL)
  185. {
  186. SSLerr(SSL_F_SSL_SESSION_NEW,ERR_R_MALLOC_FAILURE);
  187. return(0);
  188. }
  189. memset(ss,0,sizeof(SSL_SESSION));
  190. ss->verify_result = 1; /* avoid 0 (= X509_V_OK) just in case */
  191. ss->references=1;
  192. ss->timeout=60*5+4; /* 5 minute timeout by default */
  193. ss->time=(unsigned long)time(NULL);
  194. ss->prev=NULL;
  195. ss->next=NULL;
  196. ss->compress_meth=0;
  197. #ifndef OPENSSL_NO_TLSEXT
  198. ss->tlsext_hostname = NULL;
  199. #ifndef OPENSSL_NO_EC
  200. ss->tlsext_ecpointformatlist_length = 0;
  201. ss->tlsext_ecpointformatlist = NULL;
  202. ss->tlsext_ellipticcurvelist_length = 0;
  203. ss->tlsext_ellipticcurvelist = NULL;
  204. #endif
  205. #endif
  206. CRYPTO_new_ex_data(CRYPTO_EX_INDEX_SSL_SESSION, ss, &ss->ex_data);
  207. #ifndef OPENSSL_NO_PSK
  208. ss->psk_identity_hint=NULL;
  209. ss->psk_identity=NULL;
  210. #endif
  211. #ifndef OPENSSL_NO_SRP
  212. ss->srp_username=NULL;
  213. #endif
  214. return(ss);
  215. }
  216. const unsigned char *SSL_SESSION_get_id(const SSL_SESSION *s, unsigned int *len)
  217. {
  218. if(len)
  219. *len = s->session_id_length;
  220. return s->session_id;
  221. }
  222. /* Even with SSLv2, we have 16 bytes (128 bits) of session ID space. SSLv3/TLSv1
  223. * has 32 bytes (256 bits). As such, filling the ID with random gunk repeatedly
  224. * until we have no conflict is going to complete in one iteration pretty much
  225. * "most" of the time (btw: understatement). So, if it takes us 10 iterations
  226. * and we still can't avoid a conflict - well that's a reasonable point to call
  227. * it quits. Either the RAND code is broken or someone is trying to open roughly
  228. * very close to 2^128 (or 2^256) SSL sessions to our server. How you might
  229. * store that many sessions is perhaps a more interesting question ... */
  230. #define MAX_SESS_ID_ATTEMPTS 10
  231. static int def_generate_session_id(const SSL *ssl, unsigned char *id,
  232. unsigned int *id_len)
  233. {
  234. unsigned int retry = 0;
  235. do
  236. if (RAND_pseudo_bytes(id, *id_len) <= 0)
  237. return 0;
  238. while(SSL_has_matching_session_id(ssl, id, *id_len) &&
  239. (++retry < MAX_SESS_ID_ATTEMPTS));
  240. if(retry < MAX_SESS_ID_ATTEMPTS)
  241. return 1;
  242. /* else - woops a session_id match */
  243. /* XXX We should also check the external cache --
  244. * but the probability of a collision is negligible, and
  245. * we could not prevent the concurrent creation of sessions
  246. * with identical IDs since we currently don't have means
  247. * to atomically check whether a session ID already exists
  248. * and make a reservation for it if it does not
  249. * (this problem applies to the internal cache as well).
  250. */
  251. return 0;
  252. }
  253. int ssl_get_new_session(SSL *s, int session)
  254. {
  255. /* This gets used by clients and servers. */
  256. unsigned int tmp;
  257. SSL_SESSION *ss=NULL;
  258. GEN_SESSION_CB cb = def_generate_session_id;
  259. if ((ss=SSL_SESSION_new()) == NULL) return(0);
  260. /* If the context has a default timeout, use it */
  261. if (s->session_ctx->session_timeout == 0)
  262. ss->timeout=SSL_get_default_timeout(s);
  263. else
  264. ss->timeout=s->session_ctx->session_timeout;
  265. if (s->session != NULL)
  266. {
  267. SSL_SESSION_free(s->session);
  268. s->session=NULL;
  269. }
  270. if (session)
  271. {
  272. if (s->version == SSL2_VERSION)
  273. {
  274. ss->ssl_version=SSL2_VERSION;
  275. ss->session_id_length=SSL2_SSL_SESSION_ID_LENGTH;
  276. }
  277. else if (s->version == SSL3_VERSION)
  278. {
  279. ss->ssl_version=SSL3_VERSION;
  280. ss->session_id_length=SSL3_SSL_SESSION_ID_LENGTH;
  281. }
  282. else if (s->version == TLS1_VERSION)
  283. {
  284. ss->ssl_version=TLS1_VERSION;
  285. ss->session_id_length=SSL3_SSL_SESSION_ID_LENGTH;
  286. }
  287. else if (s->version == TLS1_1_VERSION)
  288. {
  289. ss->ssl_version=TLS1_1_VERSION;
  290. ss->session_id_length=SSL3_SSL_SESSION_ID_LENGTH;
  291. }
  292. else if (s->version == DTLS1_BAD_VER)
  293. {
  294. ss->ssl_version=DTLS1_BAD_VER;
  295. ss->session_id_length=SSL3_SSL_SESSION_ID_LENGTH;
  296. }
  297. else if (s->version == DTLS1_VERSION)
  298. {
  299. ss->ssl_version=DTLS1_VERSION;
  300. ss->session_id_length=SSL3_SSL_SESSION_ID_LENGTH;
  301. }
  302. else
  303. {
  304. SSLerr(SSL_F_SSL_GET_NEW_SESSION,SSL_R_UNSUPPORTED_SSL_VERSION);
  305. SSL_SESSION_free(ss);
  306. return(0);
  307. }
  308. #ifndef OPENSSL_NO_TLSEXT
  309. /* If RFC4507 ticket use empty session ID */
  310. if (s->tlsext_ticket_expected)
  311. {
  312. ss->session_id_length = 0;
  313. goto sess_id_done;
  314. }
  315. #endif
  316. /* Choose which callback will set the session ID */
  317. CRYPTO_r_lock(CRYPTO_LOCK_SSL_CTX);
  318. if(s->generate_session_id)
  319. cb = s->generate_session_id;
  320. else if(s->session_ctx->generate_session_id)
  321. cb = s->session_ctx->generate_session_id;
  322. CRYPTO_r_unlock(CRYPTO_LOCK_SSL_CTX);
  323. /* Choose a session ID */
  324. tmp = ss->session_id_length;
  325. if(!cb(s, ss->session_id, &tmp))
  326. {
  327. /* The callback failed */
  328. SSLerr(SSL_F_SSL_GET_NEW_SESSION,
  329. SSL_R_SSL_SESSION_ID_CALLBACK_FAILED);
  330. SSL_SESSION_free(ss);
  331. return(0);
  332. }
  333. /* Don't allow the callback to set the session length to zero.
  334. * nor set it higher than it was. */
  335. if(!tmp || (tmp > ss->session_id_length))
  336. {
  337. /* The callback set an illegal length */
  338. SSLerr(SSL_F_SSL_GET_NEW_SESSION,
  339. SSL_R_SSL_SESSION_ID_HAS_BAD_LENGTH);
  340. SSL_SESSION_free(ss);
  341. return(0);
  342. }
  343. /* If the session length was shrunk and we're SSLv2, pad it */
  344. if((tmp < ss->session_id_length) && (s->version == SSL2_VERSION))
  345. memset(ss->session_id + tmp, 0, ss->session_id_length - tmp);
  346. else
  347. ss->session_id_length = tmp;
  348. /* Finally, check for a conflict */
  349. if(SSL_has_matching_session_id(s, ss->session_id,
  350. ss->session_id_length))
  351. {
  352. SSLerr(SSL_F_SSL_GET_NEW_SESSION,
  353. SSL_R_SSL_SESSION_ID_CONFLICT);
  354. SSL_SESSION_free(ss);
  355. return(0);
  356. }
  357. #ifndef OPENSSL_NO_TLSEXT
  358. sess_id_done:
  359. if (s->tlsext_hostname) {
  360. ss->tlsext_hostname = BUF_strdup(s->tlsext_hostname);
  361. if (ss->tlsext_hostname == NULL) {
  362. SSLerr(SSL_F_SSL_GET_NEW_SESSION, ERR_R_INTERNAL_ERROR);
  363. SSL_SESSION_free(ss);
  364. return 0;
  365. }
  366. }
  367. #ifndef OPENSSL_NO_EC
  368. if (s->tlsext_ecpointformatlist)
  369. {
  370. if (ss->tlsext_ecpointformatlist != NULL) OPENSSL_free(ss->tlsext_ecpointformatlist);
  371. if ((ss->tlsext_ecpointformatlist = OPENSSL_malloc(s->tlsext_ecpointformatlist_length)) == NULL)
  372. {
  373. SSLerr(SSL_F_SSL_GET_NEW_SESSION, ERR_R_MALLOC_FAILURE);
  374. SSL_SESSION_free(ss);
  375. return 0;
  376. }
  377. ss->tlsext_ecpointformatlist_length = s->tlsext_ecpointformatlist_length;
  378. memcpy(ss->tlsext_ecpointformatlist, s->tlsext_ecpointformatlist, s->tlsext_ecpointformatlist_length);
  379. }
  380. if (s->tlsext_ellipticcurvelist)
  381. {
  382. if (ss->tlsext_ellipticcurvelist != NULL) OPENSSL_free(ss->tlsext_ellipticcurvelist);
  383. if ((ss->tlsext_ellipticcurvelist = OPENSSL_malloc(s->tlsext_ellipticcurvelist_length)) == NULL)
  384. {
  385. SSLerr(SSL_F_SSL_GET_NEW_SESSION, ERR_R_MALLOC_FAILURE);
  386. SSL_SESSION_free(ss);
  387. return 0;
  388. }
  389. ss->tlsext_ellipticcurvelist_length = s->tlsext_ellipticcurvelist_length;
  390. memcpy(ss->tlsext_ellipticcurvelist, s->tlsext_ellipticcurvelist, s->tlsext_ellipticcurvelist_length);
  391. }
  392. #endif
  393. #endif
  394. }
  395. else
  396. {
  397. ss->session_id_length=0;
  398. }
  399. if (s->sid_ctx_length > sizeof ss->sid_ctx)
  400. {
  401. SSLerr(SSL_F_SSL_GET_NEW_SESSION, ERR_R_INTERNAL_ERROR);
  402. SSL_SESSION_free(ss);
  403. return 0;
  404. }
  405. memcpy(ss->sid_ctx,s->sid_ctx,s->sid_ctx_length);
  406. ss->sid_ctx_length=s->sid_ctx_length;
  407. s->session=ss;
  408. ss->ssl_version=s->version;
  409. ss->verify_result = X509_V_OK;
  410. return(1);
  411. }
  412. int ssl_get_prev_session(SSL *s, unsigned char *session_id, int len,
  413. const unsigned char *limit)
  414. {
  415. /* This is used only by servers. */
  416. SSL_SESSION *ret=NULL;
  417. int fatal = 0;
  418. #ifndef OPENSSL_NO_TLSEXT
  419. int r;
  420. #endif
  421. if (len > SSL_MAX_SSL_SESSION_ID_LENGTH)
  422. goto err;
  423. #ifndef OPENSSL_NO_TLSEXT
  424. r = tls1_process_ticket(s, session_id, len, limit, &ret);
  425. if (r == -1)
  426. {
  427. fatal = 1;
  428. goto err;
  429. }
  430. else if (r == 0 || (!ret && !len))
  431. goto err;
  432. else if (!ret && !(s->session_ctx->session_cache_mode & SSL_SESS_CACHE_NO_INTERNAL_LOOKUP))
  433. #else
  434. if (len == 0)
  435. goto err;
  436. if (!(s->session_ctx->session_cache_mode & SSL_SESS_CACHE_NO_INTERNAL_LOOKUP))
  437. #endif
  438. {
  439. SSL_SESSION data;
  440. data.ssl_version=s->version;
  441. data.session_id_length=len;
  442. if (len == 0)
  443. return 0;
  444. memcpy(data.session_id,session_id,len);
  445. CRYPTO_r_lock(CRYPTO_LOCK_SSL_CTX);
  446. ret=lh_SSL_SESSION_retrieve(s->session_ctx->sessions,&data);
  447. if (ret != NULL)
  448. /* don't allow other threads to steal it: */
  449. CRYPTO_add(&ret->references,1,CRYPTO_LOCK_SSL_SESSION);
  450. CRYPTO_r_unlock(CRYPTO_LOCK_SSL_CTX);
  451. }
  452. if (ret == NULL)
  453. {
  454. int copy=1;
  455. s->session_ctx->stats.sess_miss++;
  456. ret=NULL;
  457. if (s->session_ctx->get_session_cb != NULL
  458. && (ret=s->session_ctx->get_session_cb(s,session_id,len,&copy))
  459. != NULL)
  460. {
  461. s->session_ctx->stats.sess_cb_hit++;
  462. /* Increment reference count now if the session callback
  463. * asks us to do so (note that if the session structures
  464. * returned by the callback are shared between threads,
  465. * it must handle the reference count itself [i.e. copy == 0],
  466. * or things won't be thread-safe). */
  467. if (copy)
  468. CRYPTO_add(&ret->references,1,CRYPTO_LOCK_SSL_SESSION);
  469. /* Add the externally cached session to the internal
  470. * cache as well if and only if we are supposed to. */
  471. if(!(s->session_ctx->session_cache_mode & SSL_SESS_CACHE_NO_INTERNAL_STORE))
  472. /* The following should not return 1, otherwise,
  473. * things are very strange */
  474. SSL_CTX_add_session(s->session_ctx,ret);
  475. }
  476. if (ret == NULL)
  477. goto err;
  478. }
  479. /* Now ret is non-NULL, and we own one of its reference counts. */
  480. if (ret->sid_ctx_length != s->sid_ctx_length
  481. || memcmp(ret->sid_ctx,s->sid_ctx,ret->sid_ctx_length))
  482. {
  483. /* We've found the session named by the client, but we don't
  484. * want to use it in this context. */
  485. #if 0 /* The client cannot always know when a session is not appropriate,
  486. * so we shouldn't generate an error message. */
  487. SSLerr(SSL_F_SSL_GET_PREV_SESSION,SSL_R_ATTEMPT_TO_REUSE_SESSION_IN_DIFFERENT_CONTEXT);
  488. #endif
  489. goto err; /* treat like cache miss */
  490. }
  491. if((s->verify_mode & SSL_VERIFY_PEER) && s->sid_ctx_length == 0)
  492. {
  493. /* We can't be sure if this session is being used out of
  494. * context, which is especially important for SSL_VERIFY_PEER.
  495. * The application should have used SSL[_CTX]_set_session_id_context.
  496. *
  497. * For this error case, we generate an error instead of treating
  498. * the event like a cache miss (otherwise it would be easy for
  499. * applications to effectively disable the session cache by
  500. * accident without anyone noticing).
  501. */
  502. SSLerr(SSL_F_SSL_GET_PREV_SESSION,SSL_R_SESSION_ID_CONTEXT_UNINITIALIZED);
  503. fatal = 1;
  504. goto err;
  505. }
  506. if (ret->cipher == NULL)
  507. {
  508. unsigned char buf[5],*p;
  509. unsigned long l;
  510. p=buf;
  511. l=ret->cipher_id;
  512. l2n(l,p);
  513. if ((ret->ssl_version>>8) >= SSL3_VERSION_MAJOR)
  514. ret->cipher=ssl_get_cipher_by_char(s,&(buf[2]));
  515. else
  516. ret->cipher=ssl_get_cipher_by_char(s,&(buf[1]));
  517. if (ret->cipher == NULL)
  518. goto err;
  519. }
  520. #if 0 /* This is way too late. */
  521. /* If a thread got the session, then 'swaped', and another got
  522. * it and then due to a time-out decided to 'OPENSSL_free' it we could
  523. * be in trouble. So I'll increment it now, then double decrement
  524. * later - am I speaking rubbish?. */
  525. CRYPTO_add(&ret->references,1,CRYPTO_LOCK_SSL_SESSION);
  526. #endif
  527. if (ret->timeout < (long)(time(NULL) - ret->time)) /* timeout */
  528. {
  529. s->session_ctx->stats.sess_timeout++;
  530. /* remove it from the cache */
  531. SSL_CTX_remove_session(s->session_ctx,ret);
  532. goto err;
  533. }
  534. s->session_ctx->stats.sess_hit++;
  535. /* ret->time=time(NULL); */ /* rezero timeout? */
  536. /* again, just leave the session
  537. * if it is the same session, we have just incremented and
  538. * then decremented the reference count :-) */
  539. if (s->session != NULL)
  540. SSL_SESSION_free(s->session);
  541. s->session=ret;
  542. s->verify_result = s->session->verify_result;
  543. return(1);
  544. err:
  545. if (ret != NULL)
  546. SSL_SESSION_free(ret);
  547. if (fatal)
  548. return -1;
  549. else
  550. return 0;
  551. }
  552. int SSL_CTX_add_session(SSL_CTX *ctx, SSL_SESSION *c)
  553. {
  554. int ret=0;
  555. SSL_SESSION *s;
  556. /* add just 1 reference count for the SSL_CTX's session cache
  557. * even though it has two ways of access: each session is in a
  558. * doubly linked list and an lhash */
  559. CRYPTO_add(&c->references,1,CRYPTO_LOCK_SSL_SESSION);
  560. /* if session c is in already in cache, we take back the increment later */
  561. CRYPTO_w_lock(CRYPTO_LOCK_SSL_CTX);
  562. s=lh_SSL_SESSION_insert(ctx->sessions,c);
  563. /* s != NULL iff we already had a session with the given PID.
  564. * In this case, s == c should hold (then we did not really modify
  565. * ctx->sessions), or we're in trouble. */
  566. if (s != NULL && s != c)
  567. {
  568. /* We *are* in trouble ... */
  569. SSL_SESSION_list_remove(ctx,s);
  570. SSL_SESSION_free(s);
  571. /* ... so pretend the other session did not exist in cache
  572. * (we cannot handle two SSL_SESSION structures with identical
  573. * session ID in the same cache, which could happen e.g. when
  574. * two threads concurrently obtain the same session from an external
  575. * cache) */
  576. s = NULL;
  577. }
  578. /* Put at the head of the queue unless it is already in the cache */
  579. if (s == NULL)
  580. SSL_SESSION_list_add(ctx,c);
  581. if (s != NULL)
  582. {
  583. /* existing cache entry -- decrement previously incremented reference
  584. * count because it already takes into account the cache */
  585. SSL_SESSION_free(s); /* s == c */
  586. ret=0;
  587. }
  588. else
  589. {
  590. /* new cache entry -- remove old ones if cache has become too large */
  591. ret=1;
  592. if (SSL_CTX_sess_get_cache_size(ctx) > 0)
  593. {
  594. while (SSL_CTX_sess_number(ctx) >
  595. SSL_CTX_sess_get_cache_size(ctx))
  596. {
  597. if (!remove_session_lock(ctx,
  598. ctx->session_cache_tail, 0))
  599. break;
  600. else
  601. ctx->stats.sess_cache_full++;
  602. }
  603. }
  604. }
  605. CRYPTO_w_unlock(CRYPTO_LOCK_SSL_CTX);
  606. return(ret);
  607. }
  608. int SSL_CTX_remove_session(SSL_CTX *ctx, SSL_SESSION *c)
  609. {
  610. return remove_session_lock(ctx, c, 1);
  611. }
  612. static int remove_session_lock(SSL_CTX *ctx, SSL_SESSION *c, int lck)
  613. {
  614. SSL_SESSION *r;
  615. int ret=0;
  616. if ((c != NULL) && (c->session_id_length != 0))
  617. {
  618. if(lck) CRYPTO_w_lock(CRYPTO_LOCK_SSL_CTX);
  619. if ((r = lh_SSL_SESSION_retrieve(ctx->sessions,c)) == c)
  620. {
  621. ret=1;
  622. r=lh_SSL_SESSION_delete(ctx->sessions,c);
  623. SSL_SESSION_list_remove(ctx,c);
  624. }
  625. if(lck) CRYPTO_w_unlock(CRYPTO_LOCK_SSL_CTX);
  626. if (ret)
  627. {
  628. r->not_resumable=1;
  629. if (ctx->remove_session_cb != NULL)
  630. ctx->remove_session_cb(ctx,r);
  631. SSL_SESSION_free(r);
  632. }
  633. }
  634. else
  635. ret=0;
  636. return(ret);
  637. }
  638. void SSL_SESSION_free(SSL_SESSION *ss)
  639. {
  640. int i;
  641. if(ss == NULL)
  642. return;
  643. i=CRYPTO_add(&ss->references,-1,CRYPTO_LOCK_SSL_SESSION);
  644. #ifdef REF_PRINT
  645. REF_PRINT("SSL_SESSION",ss);
  646. #endif
  647. if (i > 0) return;
  648. #ifdef REF_CHECK
  649. if (i < 0)
  650. {
  651. fprintf(stderr,"SSL_SESSION_free, bad reference count\n");
  652. abort(); /* ok */
  653. }
  654. #endif
  655. CRYPTO_free_ex_data(CRYPTO_EX_INDEX_SSL_SESSION, ss, &ss->ex_data);
  656. OPENSSL_cleanse(ss->key_arg,sizeof ss->key_arg);
  657. OPENSSL_cleanse(ss->master_key,sizeof ss->master_key);
  658. OPENSSL_cleanse(ss->session_id,sizeof ss->session_id);
  659. if (ss->sess_cert != NULL) ssl_sess_cert_free(ss->sess_cert);
  660. if (ss->peer != NULL) X509_free(ss->peer);
  661. if (ss->ciphers != NULL) sk_SSL_CIPHER_free(ss->ciphers);
  662. #ifndef OPENSSL_NO_TLSEXT
  663. if (ss->tlsext_hostname != NULL) OPENSSL_free(ss->tlsext_hostname);
  664. if (ss->tlsext_tick != NULL) OPENSSL_free(ss->tlsext_tick);
  665. #ifndef OPENSSL_NO_EC
  666. ss->tlsext_ecpointformatlist_length = 0;
  667. if (ss->tlsext_ecpointformatlist != NULL) OPENSSL_free(ss->tlsext_ecpointformatlist);
  668. ss->tlsext_ellipticcurvelist_length = 0;
  669. if (ss->tlsext_ellipticcurvelist != NULL) OPENSSL_free(ss->tlsext_ellipticcurvelist);
  670. #endif /* OPENSSL_NO_EC */
  671. #endif
  672. #ifndef OPENSSL_NO_PSK
  673. if (ss->psk_identity_hint != NULL)
  674. OPENSSL_free(ss->psk_identity_hint);
  675. if (ss->psk_identity != NULL)
  676. OPENSSL_free(ss->psk_identity);
  677. #endif
  678. #ifndef OPENSSL_NO_SRP
  679. if (ss->srp_username != NULL)
  680. OPENSSL_free(ss->srp_username);
  681. #endif
  682. OPENSSL_cleanse(ss,sizeof(*ss));
  683. OPENSSL_free(ss);
  684. }
  685. int SSL_set_session(SSL *s, SSL_SESSION *session)
  686. {
  687. int ret=0;
  688. const SSL_METHOD *meth;
  689. if (session != NULL)
  690. {
  691. meth=s->ctx->method->get_ssl_method(session->ssl_version);
  692. if (meth == NULL)
  693. meth=s->method->get_ssl_method(session->ssl_version);
  694. if (meth == NULL)
  695. {
  696. SSLerr(SSL_F_SSL_SET_SESSION,SSL_R_UNABLE_TO_FIND_SSL_METHOD);
  697. return(0);
  698. }
  699. if (meth != s->method)
  700. {
  701. if (!SSL_set_ssl_method(s,meth))
  702. return(0);
  703. if (s->ctx->session_timeout == 0)
  704. session->timeout=SSL_get_default_timeout(s);
  705. else
  706. session->timeout=s->ctx->session_timeout;
  707. }
  708. #ifndef OPENSSL_NO_KRB5
  709. if (s->kssl_ctx && !s->kssl_ctx->client_princ &&
  710. session->krb5_client_princ_len > 0)
  711. {
  712. s->kssl_ctx->client_princ = (char *)OPENSSL_malloc(session->krb5_client_princ_len + 1);
  713. memcpy(s->kssl_ctx->client_princ,session->krb5_client_princ,
  714. session->krb5_client_princ_len);
  715. s->kssl_ctx->client_princ[session->krb5_client_princ_len] = '\0';
  716. }
  717. #endif /* OPENSSL_NO_KRB5 */
  718. /* CRYPTO_w_lock(CRYPTO_LOCK_SSL);*/
  719. CRYPTO_add(&session->references,1,CRYPTO_LOCK_SSL_SESSION);
  720. if (s->session != NULL)
  721. SSL_SESSION_free(s->session);
  722. s->session=session;
  723. s->verify_result = s->session->verify_result;
  724. /* CRYPTO_w_unlock(CRYPTO_LOCK_SSL);*/
  725. ret=1;
  726. }
  727. else
  728. {
  729. if (s->session != NULL)
  730. {
  731. SSL_SESSION_free(s->session);
  732. s->session=NULL;
  733. }
  734. meth=s->ctx->method;
  735. if (meth != s->method)
  736. {
  737. if (!SSL_set_ssl_method(s,meth))
  738. return(0);
  739. }
  740. ret=1;
  741. }
  742. return(ret);
  743. }
  744. long SSL_SESSION_set_timeout(SSL_SESSION *s, long t)
  745. {
  746. if (s == NULL) return(0);
  747. s->timeout=t;
  748. return(1);
  749. }
  750. long SSL_SESSION_get_timeout(const SSL_SESSION *s)
  751. {
  752. if (s == NULL) return(0);
  753. return(s->timeout);
  754. }
  755. long SSL_SESSION_get_time(const SSL_SESSION *s)
  756. {
  757. if (s == NULL) return(0);
  758. return(s->time);
  759. }
  760. long SSL_SESSION_set_time(SSL_SESSION *s, long t)
  761. {
  762. if (s == NULL) return(0);
  763. s->time=t;
  764. return(t);
  765. }
  766. long SSL_CTX_set_timeout(SSL_CTX *s, long t)
  767. {
  768. long l;
  769. if (s == NULL) return(0);
  770. l=s->session_timeout;
  771. s->session_timeout=t;
  772. return(l);
  773. }
  774. long SSL_CTX_get_timeout(const SSL_CTX *s)
  775. {
  776. if (s == NULL) return(0);
  777. return(s->session_timeout);
  778. }
  779. #ifndef OPENSSL_NO_TLSEXT
  780. int SSL_set_session_secret_cb(SSL *s, int (*tls_session_secret_cb)(SSL *s, void *secret, int *secret_len,
  781. STACK_OF(SSL_CIPHER) *peer_ciphers, SSL_CIPHER **cipher, void *arg), void *arg)
  782. {
  783. if (s == NULL) return(0);
  784. s->tls_session_secret_cb = tls_session_secret_cb;
  785. s->tls_session_secret_cb_arg = arg;
  786. return(1);
  787. }
  788. int SSL_set_session_ticket_ext_cb(SSL *s, tls_session_ticket_ext_cb_fn cb,
  789. void *arg)
  790. {
  791. if (s == NULL) return(0);
  792. s->tls_session_ticket_ext_cb = cb;
  793. s->tls_session_ticket_ext_cb_arg = arg;
  794. return(1);
  795. }
  796. int SSL_set_session_ticket_ext(SSL *s, void *ext_data, int ext_len)
  797. {
  798. if (s->version >= TLS1_VERSION)
  799. {
  800. if (s->tlsext_session_ticket)
  801. {
  802. OPENSSL_free(s->tlsext_session_ticket);
  803. s->tlsext_session_ticket = NULL;
  804. }
  805. s->tlsext_session_ticket = OPENSSL_malloc(sizeof(TLS_SESSION_TICKET_EXT) + ext_len);
  806. if (!s->tlsext_session_ticket)
  807. {
  808. SSLerr(SSL_F_SSL_SET_SESSION_TICKET_EXT, ERR_R_MALLOC_FAILURE);
  809. return 0;
  810. }
  811. if (ext_data)
  812. {
  813. s->tlsext_session_ticket->length = ext_len;
  814. s->tlsext_session_ticket->data = s->tlsext_session_ticket + 1;
  815. memcpy(s->tlsext_session_ticket->data, ext_data, ext_len);
  816. }
  817. else
  818. {
  819. s->tlsext_session_ticket->length = 0;
  820. s->tlsext_session_ticket->data = NULL;
  821. }
  822. return 1;
  823. }
  824. return 0;
  825. }
  826. #endif /* OPENSSL_NO_TLSEXT */
  827. typedef struct timeout_param_st
  828. {
  829. SSL_CTX *ctx;
  830. long time;
  831. LHASH_OF(SSL_SESSION) *cache;
  832. } TIMEOUT_PARAM;
  833. static void timeout_doall_arg(SSL_SESSION *s, TIMEOUT_PARAM *p)
  834. {
  835. if ((p->time == 0) || (p->time > (s->time+s->timeout))) /* timeout */
  836. {
  837. /* The reason we don't call SSL_CTX_remove_session() is to
  838. * save on locking overhead */
  839. (void)lh_SSL_SESSION_delete(p->cache,s);
  840. SSL_SESSION_list_remove(p->ctx,s);
  841. s->not_resumable=1;
  842. if (p->ctx->remove_session_cb != NULL)
  843. p->ctx->remove_session_cb(p->ctx,s);
  844. SSL_SESSION_free(s);
  845. }
  846. }
  847. static IMPLEMENT_LHASH_DOALL_ARG_FN(timeout, SSL_SESSION, TIMEOUT_PARAM)
  848. void SSL_CTX_flush_sessions(SSL_CTX *s, long t)
  849. {
  850. unsigned long i;
  851. TIMEOUT_PARAM tp;
  852. tp.ctx=s;
  853. tp.cache=s->sessions;
  854. if (tp.cache == NULL) return;
  855. tp.time=t;
  856. CRYPTO_w_lock(CRYPTO_LOCK_SSL_CTX);
  857. i=CHECKED_LHASH_OF(SSL_SESSION, tp.cache)->down_load;
  858. CHECKED_LHASH_OF(SSL_SESSION, tp.cache)->down_load=0;
  859. lh_SSL_SESSION_doall_arg(tp.cache, LHASH_DOALL_ARG_FN(timeout),
  860. TIMEOUT_PARAM, &tp);
  861. CHECKED_LHASH_OF(SSL_SESSION, tp.cache)->down_load=i;
  862. CRYPTO_w_unlock(CRYPTO_LOCK_SSL_CTX);
  863. }
  864. int ssl_clear_bad_session(SSL *s)
  865. {
  866. if ( (s->session != NULL) &&
  867. !(s->shutdown & SSL_SENT_SHUTDOWN) &&
  868. !(SSL_in_init(s) || SSL_in_before(s)))
  869. {
  870. SSL_CTX_remove_session(s->ctx,s->session);
  871. return(1);
  872. }
  873. else
  874. return(0);
  875. }
  876. /* locked by SSL_CTX in the calling function */
  877. static void SSL_SESSION_list_remove(SSL_CTX *ctx, SSL_SESSION *s)
  878. {
  879. if ((s->next == NULL) || (s->prev == NULL)) return;
  880. if (s->next == (SSL_SESSION *)&(ctx->session_cache_tail))
  881. { /* last element in list */
  882. if (s->prev == (SSL_SESSION *)&(ctx->session_cache_head))
  883. { /* only one element in list */
  884. ctx->session_cache_head=NULL;
  885. ctx->session_cache_tail=NULL;
  886. }
  887. else
  888. {
  889. ctx->session_cache_tail=s->prev;
  890. s->prev->next=(SSL_SESSION *)&(ctx->session_cache_tail);
  891. }
  892. }
  893. else
  894. {
  895. if (s->prev == (SSL_SESSION *)&(ctx->session_cache_head))
  896. { /* first element in list */
  897. ctx->session_cache_head=s->next;
  898. s->next->prev=(SSL_SESSION *)&(ctx->session_cache_head);
  899. }
  900. else
  901. { /* middle of list */
  902. s->next->prev=s->prev;
  903. s->prev->next=s->next;
  904. }
  905. }
  906. s->prev=s->next=NULL;
  907. }
  908. static void SSL_SESSION_list_add(SSL_CTX *ctx, SSL_SESSION *s)
  909. {
  910. if ((s->next != NULL) && (s->prev != NULL))
  911. SSL_SESSION_list_remove(ctx,s);
  912. if (ctx->session_cache_head == NULL)
  913. {
  914. ctx->session_cache_head=s;
  915. ctx->session_cache_tail=s;
  916. s->prev=(SSL_SESSION *)&(ctx->session_cache_head);
  917. s->next=(SSL_SESSION *)&(ctx->session_cache_tail);
  918. }
  919. else
  920. {
  921. s->next=ctx->session_cache_head;
  922. s->next->prev=s;
  923. s->prev=(SSL_SESSION *)&(ctx->session_cache_head);
  924. ctx->session_cache_head=s;
  925. }
  926. }
  927. void SSL_CTX_sess_set_new_cb(SSL_CTX *ctx,
  928. int (*cb)(struct ssl_st *ssl,SSL_SESSION *sess))
  929. {
  930. ctx->new_session_cb=cb;
  931. }
  932. int (*SSL_CTX_sess_get_new_cb(SSL_CTX *ctx))(SSL *ssl, SSL_SESSION *sess)
  933. {
  934. return ctx->new_session_cb;
  935. }
  936. void SSL_CTX_sess_set_remove_cb(SSL_CTX *ctx,
  937. void (*cb)(SSL_CTX *ctx,SSL_SESSION *sess))
  938. {
  939. ctx->remove_session_cb=cb;
  940. }
  941. void (*SSL_CTX_sess_get_remove_cb(SSL_CTX *ctx))(SSL_CTX * ctx,SSL_SESSION *sess)
  942. {
  943. return ctx->remove_session_cb;
  944. }
  945. void SSL_CTX_sess_set_get_cb(SSL_CTX *ctx,
  946. SSL_SESSION *(*cb)(struct ssl_st *ssl,
  947. unsigned char *data,int len,int *copy))
  948. {
  949. ctx->get_session_cb=cb;
  950. }
  951. SSL_SESSION * (*SSL_CTX_sess_get_get_cb(SSL_CTX *ctx))(SSL *ssl,
  952. unsigned char *data,int len,int *copy)
  953. {
  954. return ctx->get_session_cb;
  955. }
  956. void SSL_CTX_set_info_callback(SSL_CTX *ctx,
  957. void (*cb)(const SSL *ssl,int type,int val))
  958. {
  959. ctx->info_callback=cb;
  960. }
  961. void (*SSL_CTX_get_info_callback(SSL_CTX *ctx))(const SSL *ssl,int type,int val)
  962. {
  963. return ctx->info_callback;
  964. }
  965. void SSL_CTX_set_client_cert_cb(SSL_CTX *ctx,
  966. int (*cb)(SSL *ssl, X509 **x509, EVP_PKEY **pkey))
  967. {
  968. ctx->client_cert_cb=cb;
  969. }
  970. int (*SSL_CTX_get_client_cert_cb(SSL_CTX *ctx))(SSL * ssl, X509 ** x509 , EVP_PKEY **pkey)
  971. {
  972. return ctx->client_cert_cb;
  973. }
  974. #ifndef OPENSSL_NO_ENGINE
  975. int SSL_CTX_set_client_cert_engine(SSL_CTX *ctx, ENGINE *e)
  976. {
  977. if (!ENGINE_init(e))
  978. {
  979. SSLerr(SSL_F_SSL_CTX_SET_CLIENT_CERT_ENGINE, ERR_R_ENGINE_LIB);
  980. return 0;
  981. }
  982. if(!ENGINE_get_ssl_client_cert_function(e))
  983. {
  984. SSLerr(SSL_F_SSL_CTX_SET_CLIENT_CERT_ENGINE, SSL_R_NO_CLIENT_CERT_METHOD);
  985. ENGINE_finish(e);
  986. return 0;
  987. }
  988. ctx->client_cert_engine = e;
  989. return 1;
  990. }
  991. #endif
  992. void SSL_CTX_set_cookie_generate_cb(SSL_CTX *ctx,
  993. int (*cb)(SSL *ssl, unsigned char *cookie, unsigned int *cookie_len))
  994. {
  995. ctx->app_gen_cookie_cb=cb;
  996. }
  997. void SSL_CTX_set_cookie_verify_cb(SSL_CTX *ctx,
  998. int (*cb)(SSL *ssl, unsigned char *cookie, unsigned int cookie_len))
  999. {
  1000. ctx->app_verify_cookie_cb=cb;
  1001. }
  1002. IMPLEMENT_PEM_rw(SSL_SESSION, SSL_SESSION, PEM_STRING_SSL_SESSION, SSL_SESSION)