diff options
Diffstat (limited to 'src/lib/libssl/ssl_sess.c')
-rw-r--r-- | src/lib/libssl/ssl_sess.c | 253 |
1 files changed, 32 insertions, 221 deletions
diff --git a/src/lib/libssl/ssl_sess.c b/src/lib/libssl/ssl_sess.c index 8e5d8a0972..8391d62212 100644 --- a/src/lib/libssl/ssl_sess.c +++ b/src/lib/libssl/ssl_sess.c | |||
@@ -55,85 +55,6 @@ | |||
55 | * copied and put under another distribution licence | 55 | * copied and put under another distribution licence |
56 | * [including the GNU Public Licence.] | 56 | * [including the GNU Public Licence.] |
57 | */ | 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 | 58 | ||
138 | #include <stdio.h> | 59 | #include <stdio.h> |
139 | #include <openssl/lhash.h> | 60 | #include <openssl/lhash.h> |
@@ -206,18 +127,8 @@ SSL_SESSION *SSL_SESSION_new(void) | |||
206 | ss->compress_meth=0; | 127 | ss->compress_meth=0; |
207 | #ifndef OPENSSL_NO_TLSEXT | 128 | #ifndef OPENSSL_NO_TLSEXT |
208 | ss->tlsext_hostname = NULL; | 129 | ss->tlsext_hostname = NULL; |
209 | #ifndef OPENSSL_NO_EC | ||
210 | ss->tlsext_ecpointformatlist_length = 0; | ||
211 | ss->tlsext_ecpointformatlist = NULL; | ||
212 | ss->tlsext_ellipticcurvelist_length = 0; | ||
213 | ss->tlsext_ellipticcurvelist = NULL; | ||
214 | #endif | ||
215 | #endif | 130 | #endif |
216 | CRYPTO_new_ex_data(CRYPTO_EX_INDEX_SSL_SESSION, ss, &ss->ex_data); | 131 | CRYPTO_new_ex_data(CRYPTO_EX_INDEX_SSL_SESSION, ss, &ss->ex_data); |
217 | #ifndef OPENSSL_NO_PSK | ||
218 | ss->psk_identity_hint=NULL; | ||
219 | ss->psk_identity=NULL; | ||
220 | #endif | ||
221 | return(ss); | 132 | return(ss); |
222 | } | 133 | } |
223 | 134 | ||
@@ -272,10 +183,10 @@ int ssl_get_new_session(SSL *s, int session) | |||
272 | if ((ss=SSL_SESSION_new()) == NULL) return(0); | 183 | if ((ss=SSL_SESSION_new()) == NULL) return(0); |
273 | 184 | ||
274 | /* If the context has a default timeout, use it */ | 185 | /* If the context has a default timeout, use it */ |
275 | if (s->session_ctx->session_timeout == 0) | 186 | if (s->ctx->session_timeout == 0) |
276 | ss->timeout=SSL_get_default_timeout(s); | 187 | ss->timeout=SSL_get_default_timeout(s); |
277 | else | 188 | else |
278 | ss->timeout=s->session_ctx->session_timeout; | 189 | ss->timeout=s->ctx->session_timeout; |
279 | 190 | ||
280 | if (s->session != NULL) | 191 | if (s->session != NULL) |
281 | { | 192 | { |
@@ -300,11 +211,6 @@ int ssl_get_new_session(SSL *s, int session) | |||
300 | ss->ssl_version=TLS1_VERSION; | 211 | ss->ssl_version=TLS1_VERSION; |
301 | ss->session_id_length=SSL3_SSL_SESSION_ID_LENGTH; | 212 | ss->session_id_length=SSL3_SSL_SESSION_ID_LENGTH; |
302 | } | 213 | } |
303 | else if (s->version == DTLS1_BAD_VER) | ||
304 | { | ||
305 | ss->ssl_version=DTLS1_BAD_VER; | ||
306 | ss->session_id_length=SSL3_SSL_SESSION_ID_LENGTH; | ||
307 | } | ||
308 | else if (s->version == DTLS1_VERSION) | 214 | else if (s->version == DTLS1_VERSION) |
309 | { | 215 | { |
310 | ss->ssl_version=DTLS1_VERSION; | 216 | ss->ssl_version=DTLS1_VERSION; |
@@ -328,8 +234,8 @@ int ssl_get_new_session(SSL *s, int session) | |||
328 | CRYPTO_r_lock(CRYPTO_LOCK_SSL_CTX); | 234 | CRYPTO_r_lock(CRYPTO_LOCK_SSL_CTX); |
329 | if(s->generate_session_id) | 235 | if(s->generate_session_id) |
330 | cb = s->generate_session_id; | 236 | cb = s->generate_session_id; |
331 | else if(s->session_ctx->generate_session_id) | 237 | else if(s->ctx->generate_session_id) |
332 | cb = s->session_ctx->generate_session_id; | 238 | cb = s->ctx->generate_session_id; |
333 | CRYPTO_r_unlock(CRYPTO_LOCK_SSL_CTX); | 239 | CRYPTO_r_unlock(CRYPTO_LOCK_SSL_CTX); |
334 | /* Choose a session ID */ | 240 | /* Choose a session ID */ |
335 | tmp = ss->session_id_length; | 241 | tmp = ss->session_id_length; |
@@ -375,32 +281,6 @@ int ssl_get_new_session(SSL *s, int session) | |||
375 | return 0; | 281 | return 0; |
376 | } | 282 | } |
377 | } | 283 | } |
378 | #ifndef OPENSSL_NO_EC | ||
379 | if (s->tlsext_ecpointformatlist) | ||
380 | { | ||
381 | if (ss->tlsext_ecpointformatlist != NULL) OPENSSL_free(ss->tlsext_ecpointformatlist); | ||
382 | if ((ss->tlsext_ecpointformatlist = OPENSSL_malloc(s->tlsext_ecpointformatlist_length)) == NULL) | ||
383 | { | ||
384 | SSLerr(SSL_F_SSL_GET_NEW_SESSION, ERR_R_MALLOC_FAILURE); | ||
385 | SSL_SESSION_free(ss); | ||
386 | return 0; | ||
387 | } | ||
388 | ss->tlsext_ecpointformatlist_length = s->tlsext_ecpointformatlist_length; | ||
389 | memcpy(ss->tlsext_ecpointformatlist, s->tlsext_ecpointformatlist, s->tlsext_ecpointformatlist_length); | ||
390 | } | ||
391 | if (s->tlsext_ellipticcurvelist) | ||
392 | { | ||
393 | if (ss->tlsext_ellipticcurvelist != NULL) OPENSSL_free(ss->tlsext_ellipticcurvelist); | ||
394 | if ((ss->tlsext_ellipticcurvelist = OPENSSL_malloc(s->tlsext_ellipticcurvelist_length)) == NULL) | ||
395 | { | ||
396 | SSLerr(SSL_F_SSL_GET_NEW_SESSION, ERR_R_MALLOC_FAILURE); | ||
397 | SSL_SESSION_free(ss); | ||
398 | return 0; | ||
399 | } | ||
400 | ss->tlsext_ellipticcurvelist_length = s->tlsext_ellipticcurvelist_length; | ||
401 | memcpy(ss->tlsext_ellipticcurvelist, s->tlsext_ellipticcurvelist, s->tlsext_ellipticcurvelist_length); | ||
402 | } | ||
403 | #endif | ||
404 | #endif | 284 | #endif |
405 | } | 285 | } |
406 | else | 286 | else |
@@ -433,15 +313,15 @@ int ssl_get_prev_session(SSL *s, unsigned char *session_id, int len, | |||
433 | #ifndef OPENSSL_NO_TLSEXT | 313 | #ifndef OPENSSL_NO_TLSEXT |
434 | int r; | 314 | int r; |
435 | #endif | 315 | #endif |
436 | 316 | ||
437 | if (len > SSL_MAX_SSL_SESSION_ID_LENGTH) | 317 | if (len > SSL_MAX_SSL_SESSION_ID_LENGTH) |
438 | goto err; | 318 | goto err; |
439 | #ifndef OPENSSL_NO_TLSEXT | 319 | #ifndef OPENSSL_NO_TLSEXT |
440 | r = tls1_process_ticket(s, session_id, len, limit, &ret); | 320 | r = tls1_process_ticket(s, session_id, len, limit, &ret); |
441 | if (r == -1) | 321 | if (r == -1) |
442 | { | 322 | { |
443 | fatal = 1; | 323 | fatal = 1; |
444 | goto err; | 324 | goto err; |
445 | } | 325 | } |
446 | else if (r == 0 || (!ret && !len)) | 326 | else if (r == 0 || (!ret && !len)) |
447 | goto err; | 327 | goto err; |
@@ -449,7 +329,7 @@ int ssl_get_prev_session(SSL *s, unsigned char *session_id, int len, | |||
449 | #else | 329 | #else |
450 | if (len == 0) | 330 | if (len == 0) |
451 | goto err; | 331 | goto err; |
452 | if (!(s->session_ctx->session_cache_mode & SSL_SESS_CACHE_NO_INTERNAL_LOOKUP)) | 332 | if (!(s->ctx->session_cache_mode & SSL_SESS_CACHE_NO_INTERNAL_LOOKUP)) |
453 | #endif | 333 | #endif |
454 | { | 334 | { |
455 | SSL_SESSION data; | 335 | SSL_SESSION data; |
@@ -457,9 +337,9 @@ int ssl_get_prev_session(SSL *s, unsigned char *session_id, int len, | |||
457 | data.session_id_length=len; | 337 | data.session_id_length=len; |
458 | if (len == 0) | 338 | if (len == 0) |
459 | return 0; | 339 | return 0; |
460 | memcpy(data.session_id,session_id,len); | 340 | memcpy(data.session_id,session_id,len); |
461 | CRYPTO_r_lock(CRYPTO_LOCK_SSL_CTX); | 341 | CRYPTO_r_lock(CRYPTO_LOCK_SSL_CTX); |
462 | ret=lh_SSL_SESSION_retrieve(s->session_ctx->sessions,&data); | 342 | ret=(SSL_SESSION *)lh_retrieve(s->ctx->sessions,&data); |
463 | if (ret != NULL) | 343 | if (ret != NULL) |
464 | /* don't allow other threads to steal it: */ | 344 | /* don't allow other threads to steal it: */ |
465 | CRYPTO_add(&ret->references,1,CRYPTO_LOCK_SSL_SESSION); | 345 | CRYPTO_add(&ret->references,1,CRYPTO_LOCK_SSL_SESSION); |
@@ -470,13 +350,13 @@ int ssl_get_prev_session(SSL *s, unsigned char *session_id, int len, | |||
470 | { | 350 | { |
471 | int copy=1; | 351 | int copy=1; |
472 | 352 | ||
473 | s->session_ctx->stats.sess_miss++; | 353 | s->ctx->stats.sess_miss++; |
474 | ret=NULL; | 354 | ret=NULL; |
475 | if (s->session_ctx->get_session_cb != NULL | 355 | if (s->ctx->get_session_cb != NULL |
476 | && (ret=s->session_ctx->get_session_cb(s,session_id,len,©)) | 356 | && (ret=s->ctx->get_session_cb(s,session_id,len,©)) |
477 | != NULL) | 357 | != NULL) |
478 | { | 358 | { |
479 | s->session_ctx->stats.sess_cb_hit++; | 359 | s->ctx->stats.sess_cb_hit++; |
480 | 360 | ||
481 | /* Increment reference count now if the session callback | 361 | /* Increment reference count now if the session callback |
482 | * asks us to do so (note that if the session structures | 362 | * asks us to do so (note that if the session structures |
@@ -488,10 +368,10 @@ int ssl_get_prev_session(SSL *s, unsigned char *session_id, int len, | |||
488 | 368 | ||
489 | /* Add the externally cached session to the internal | 369 | /* Add the externally cached session to the internal |
490 | * cache as well if and only if we are supposed to. */ | 370 | * cache as well if and only if we are supposed to. */ |
491 | if(!(s->session_ctx->session_cache_mode & SSL_SESS_CACHE_NO_INTERNAL_STORE)) | 371 | if(!(s->ctx->session_cache_mode & SSL_SESS_CACHE_NO_INTERNAL_STORE)) |
492 | /* The following should not return 1, otherwise, | 372 | /* The following should not return 1, otherwise, |
493 | * things are very strange */ | 373 | * things are very strange */ |
494 | SSL_CTX_add_session(s->session_ctx,ret); | 374 | SSL_CTX_add_session(s->ctx,ret); |
495 | } | 375 | } |
496 | if (ret == NULL) | 376 | if (ret == NULL) |
497 | goto err; | 377 | goto err; |
@@ -538,7 +418,7 @@ int ssl_get_prev_session(SSL *s, unsigned char *session_id, int len, | |||
538 | p=buf; | 418 | p=buf; |
539 | l=ret->cipher_id; | 419 | l=ret->cipher_id; |
540 | l2n(l,p); | 420 | l2n(l,p); |
541 | if ((ret->ssl_version>>8) >= SSL3_VERSION_MAJOR) | 421 | if ((ret->ssl_version>>8) == SSL3_VERSION_MAJOR) |
542 | ret->cipher=ssl_get_cipher_by_char(s,&(buf[2])); | 422 | ret->cipher=ssl_get_cipher_by_char(s,&(buf[2])); |
543 | else | 423 | else |
544 | ret->cipher=ssl_get_cipher_by_char(s,&(buf[1])); | 424 | ret->cipher=ssl_get_cipher_by_char(s,&(buf[1])); |
@@ -558,13 +438,13 @@ int ssl_get_prev_session(SSL *s, unsigned char *session_id, int len, | |||
558 | 438 | ||
559 | if (ret->timeout < (long)(time(NULL) - ret->time)) /* timeout */ | 439 | if (ret->timeout < (long)(time(NULL) - ret->time)) /* timeout */ |
560 | { | 440 | { |
561 | s->session_ctx->stats.sess_timeout++; | 441 | s->ctx->stats.sess_timeout++; |
562 | /* remove it from the cache */ | 442 | /* remove it from the cache */ |
563 | SSL_CTX_remove_session(s->session_ctx,ret); | 443 | SSL_CTX_remove_session(s->ctx,ret); |
564 | goto err; | 444 | goto err; |
565 | } | 445 | } |
566 | 446 | ||
567 | s->session_ctx->stats.sess_hit++; | 447 | s->ctx->stats.sess_hit++; |
568 | 448 | ||
569 | /* ret->time=time(NULL); */ /* rezero timeout? */ | 449 | /* ret->time=time(NULL); */ /* rezero timeout? */ |
570 | /* again, just leave the session | 450 | /* again, just leave the session |
@@ -597,7 +477,7 @@ int SSL_CTX_add_session(SSL_CTX *ctx, SSL_SESSION *c) | |||
597 | /* if session c is in already in cache, we take back the increment later */ | 477 | /* if session c is in already in cache, we take back the increment later */ |
598 | 478 | ||
599 | CRYPTO_w_lock(CRYPTO_LOCK_SSL_CTX); | 479 | CRYPTO_w_lock(CRYPTO_LOCK_SSL_CTX); |
600 | s=lh_SSL_SESSION_insert(ctx->sessions,c); | 480 | s=(SSL_SESSION *)lh_insert(ctx->sessions,c); |
601 | 481 | ||
602 | /* s != NULL iff we already had a session with the given PID. | 482 | /* s != NULL iff we already had a session with the given PID. |
603 | * In this case, s == c should hold (then we did not really modify | 483 | * In this case, s == c should hold (then we did not really modify |
@@ -663,10 +543,10 @@ static int remove_session_lock(SSL_CTX *ctx, SSL_SESSION *c, int lck) | |||
663 | if ((c != NULL) && (c->session_id_length != 0)) | 543 | if ((c != NULL) && (c->session_id_length != 0)) |
664 | { | 544 | { |
665 | if(lck) CRYPTO_w_lock(CRYPTO_LOCK_SSL_CTX); | 545 | if(lck) CRYPTO_w_lock(CRYPTO_LOCK_SSL_CTX); |
666 | if ((r = lh_SSL_SESSION_retrieve(ctx->sessions,c)) == c) | 546 | if ((r = (SSL_SESSION *)lh_retrieve(ctx->sessions,c)) == c) |
667 | { | 547 | { |
668 | ret=1; | 548 | ret=1; |
669 | r=lh_SSL_SESSION_delete(ctx->sessions,c); | 549 | r=(SSL_SESSION *)lh_delete(ctx->sessions,c); |
670 | SSL_SESSION_list_remove(ctx,c); | 550 | SSL_SESSION_list_remove(ctx,c); |
671 | } | 551 | } |
672 | 552 | ||
@@ -716,18 +596,6 @@ void SSL_SESSION_free(SSL_SESSION *ss) | |||
716 | #ifndef OPENSSL_NO_TLSEXT | 596 | #ifndef OPENSSL_NO_TLSEXT |
717 | if (ss->tlsext_hostname != NULL) OPENSSL_free(ss->tlsext_hostname); | 597 | if (ss->tlsext_hostname != NULL) OPENSSL_free(ss->tlsext_hostname); |
718 | if (ss->tlsext_tick != NULL) OPENSSL_free(ss->tlsext_tick); | 598 | if (ss->tlsext_tick != NULL) OPENSSL_free(ss->tlsext_tick); |
719 | #ifndef OPENSSL_NO_EC | ||
720 | ss->tlsext_ecpointformatlist_length = 0; | ||
721 | if (ss->tlsext_ecpointformatlist != NULL) OPENSSL_free(ss->tlsext_ecpointformatlist); | ||
722 | ss->tlsext_ellipticcurvelist_length = 0; | ||
723 | if (ss->tlsext_ellipticcurvelist != NULL) OPENSSL_free(ss->tlsext_ellipticcurvelist); | ||
724 | #endif /* OPENSSL_NO_EC */ | ||
725 | #endif | ||
726 | #ifndef OPENSSL_NO_PSK | ||
727 | if (ss->psk_identity_hint != NULL) | ||
728 | OPENSSL_free(ss->psk_identity_hint); | ||
729 | if (ss->psk_identity != NULL) | ||
730 | OPENSSL_free(ss->psk_identity); | ||
731 | #endif | 599 | #endif |
732 | OPENSSL_cleanse(ss,sizeof(*ss)); | 600 | OPENSSL_cleanse(ss,sizeof(*ss)); |
733 | OPENSSL_free(ss); | 601 | OPENSSL_free(ss); |
@@ -736,7 +604,7 @@ void SSL_SESSION_free(SSL_SESSION *ss) | |||
736 | int SSL_set_session(SSL *s, SSL_SESSION *session) | 604 | int SSL_set_session(SSL *s, SSL_SESSION *session) |
737 | { | 605 | { |
738 | int ret=0; | 606 | int ret=0; |
739 | const SSL_METHOD *meth; | 607 | SSL_METHOD *meth; |
740 | 608 | ||
741 | if (session != NULL) | 609 | if (session != NULL) |
742 | { | 610 | { |
@@ -839,75 +707,20 @@ long SSL_CTX_get_timeout(const SSL_CTX *s) | |||
839 | return(s->session_timeout); | 707 | return(s->session_timeout); |
840 | } | 708 | } |
841 | 709 | ||
842 | #ifndef OPENSSL_NO_TLSEXT | ||
843 | int SSL_set_session_secret_cb(SSL *s, int (*tls_session_secret_cb)(SSL *s, void *secret, int *secret_len, | ||
844 | STACK_OF(SSL_CIPHER) *peer_ciphers, SSL_CIPHER **cipher, void *arg), void *arg) | ||
845 | { | ||
846 | if (s == NULL) return(0); | ||
847 | s->tls_session_secret_cb = tls_session_secret_cb; | ||
848 | s->tls_session_secret_cb_arg = arg; | ||
849 | return(1); | ||
850 | } | ||
851 | |||
852 | int SSL_set_session_ticket_ext_cb(SSL *s, tls_session_ticket_ext_cb_fn cb, | ||
853 | void *arg) | ||
854 | { | ||
855 | if (s == NULL) return(0); | ||
856 | s->tls_session_ticket_ext_cb = cb; | ||
857 | s->tls_session_ticket_ext_cb_arg = arg; | ||
858 | return(1); | ||
859 | } | ||
860 | |||
861 | int SSL_set_session_ticket_ext(SSL *s, void *ext_data, int ext_len) | ||
862 | { | ||
863 | if (s->version >= TLS1_VERSION) | ||
864 | { | ||
865 | if (s->tlsext_session_ticket) | ||
866 | { | ||
867 | OPENSSL_free(s->tlsext_session_ticket); | ||
868 | s->tlsext_session_ticket = NULL; | ||
869 | } | ||
870 | |||
871 | s->tlsext_session_ticket = OPENSSL_malloc(sizeof(TLS_SESSION_TICKET_EXT) + ext_len); | ||
872 | if (!s->tlsext_session_ticket) | ||
873 | { | ||
874 | SSLerr(SSL_F_SSL_SET_SESSION_TICKET_EXT, ERR_R_MALLOC_FAILURE); | ||
875 | return 0; | ||
876 | } | ||
877 | |||
878 | if (ext_data) | ||
879 | { | ||
880 | s->tlsext_session_ticket->length = ext_len; | ||
881 | s->tlsext_session_ticket->data = s->tlsext_session_ticket + 1; | ||
882 | memcpy(s->tlsext_session_ticket->data, ext_data, ext_len); | ||
883 | } | ||
884 | else | ||
885 | { | ||
886 | s->tlsext_session_ticket->length = 0; | ||
887 | s->tlsext_session_ticket->data = NULL; | ||
888 | } | ||
889 | |||
890 | return 1; | ||
891 | } | ||
892 | |||
893 | return 0; | ||
894 | } | ||
895 | #endif /* OPENSSL_NO_TLSEXT */ | ||
896 | |||
897 | typedef struct timeout_param_st | 710 | typedef struct timeout_param_st |
898 | { | 711 | { |
899 | SSL_CTX *ctx; | 712 | SSL_CTX *ctx; |
900 | long time; | 713 | long time; |
901 | LHASH_OF(SSL_SESSION) *cache; | 714 | LHASH *cache; |
902 | } TIMEOUT_PARAM; | 715 | } TIMEOUT_PARAM; |
903 | 716 | ||
904 | static void timeout_doall_arg(SSL_SESSION *s, TIMEOUT_PARAM *p) | 717 | static void timeout(SSL_SESSION *s, TIMEOUT_PARAM *p) |
905 | { | 718 | { |
906 | if ((p->time == 0) || (p->time > (s->time+s->timeout))) /* timeout */ | 719 | if ((p->time == 0) || (p->time > (s->time+s->timeout))) /* timeout */ |
907 | { | 720 | { |
908 | /* The reason we don't call SSL_CTX_remove_session() is to | 721 | /* The reason we don't call SSL_CTX_remove_session() is to |
909 | * save on locking overhead */ | 722 | * save on locking overhead */ |
910 | (void)lh_SSL_SESSION_delete(p->cache,s); | 723 | lh_delete(p->cache,s); |
911 | SSL_SESSION_list_remove(p->ctx,s); | 724 | SSL_SESSION_list_remove(p->ctx,s); |
912 | s->not_resumable=1; | 725 | s->not_resumable=1; |
913 | if (p->ctx->remove_session_cb != NULL) | 726 | if (p->ctx->remove_session_cb != NULL) |
@@ -916,7 +729,7 @@ static void timeout_doall_arg(SSL_SESSION *s, TIMEOUT_PARAM *p) | |||
916 | } | 729 | } |
917 | } | 730 | } |
918 | 731 | ||
919 | static IMPLEMENT_LHASH_DOALL_ARG_FN(timeout, SSL_SESSION, TIMEOUT_PARAM) | 732 | static IMPLEMENT_LHASH_DOALL_ARG_FN(timeout, SSL_SESSION *, TIMEOUT_PARAM *) |
920 | 733 | ||
921 | void SSL_CTX_flush_sessions(SSL_CTX *s, long t) | 734 | void SSL_CTX_flush_sessions(SSL_CTX *s, long t) |
922 | { | 735 | { |
@@ -928,11 +741,10 @@ void SSL_CTX_flush_sessions(SSL_CTX *s, long t) | |||
928 | if (tp.cache == NULL) return; | 741 | if (tp.cache == NULL) return; |
929 | tp.time=t; | 742 | tp.time=t; |
930 | CRYPTO_w_lock(CRYPTO_LOCK_SSL_CTX); | 743 | CRYPTO_w_lock(CRYPTO_LOCK_SSL_CTX); |
931 | i=CHECKED_LHASH_OF(SSL_SESSION, tp.cache)->down_load; | 744 | i=tp.cache->down_load; |
932 | CHECKED_LHASH_OF(SSL_SESSION, tp.cache)->down_load=0; | 745 | tp.cache->down_load=0; |
933 | lh_SSL_SESSION_doall_arg(tp.cache, LHASH_DOALL_ARG_FN(timeout), | 746 | lh_doall_arg(tp.cache, LHASH_DOALL_ARG_FN(timeout), &tp); |
934 | TIMEOUT_PARAM, &tp); | 747 | tp.cache->down_load=i; |
935 | CHECKED_LHASH_OF(SSL_SESSION, tp.cache)->down_load=i; | ||
936 | CRYPTO_w_unlock(CRYPTO_LOCK_SSL_CTX); | 748 | CRYPTO_w_unlock(CRYPTO_LOCK_SSL_CTX); |
937 | } | 749 | } |
938 | 750 | ||
@@ -1092,4 +904,3 @@ void SSL_CTX_set_cookie_verify_cb(SSL_CTX *ctx, | |||
1092 | ctx->app_verify_cookie_cb=cb; | 904 | ctx->app_verify_cookie_cb=cb; |
1093 | } | 905 | } |
1094 | 906 | ||
1095 | IMPLEMENT_PEM_rw(SSL_SESSION, SSL_SESSION, PEM_STRING_SSL_SESSION, SSL_SESSION) | ||