Rich Salz | 846e33c | 2016-05-17 14:18:30 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved. |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 3 | * |
Rich Salz | 846e33c | 2016-05-17 14:18:30 -0400 | [diff] [blame] | 4 | * Licensed under the OpenSSL license (the "License"). You may not use |
| 5 | * this file except in compliance with the License. You can obtain a copy |
| 6 | * in the file LICENSE in the source distribution or at |
| 7 | * https://www.openssl.org/source/license.html |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 8 | */ |
Rich Salz | 846e33c | 2016-05-17 14:18:30 -0400 | [diff] [blame] | 9 | |
Nils Larsch | ddac197 | 2006-03-10 23:06:27 +0000 | [diff] [blame] | 10 | /* ==================================================================== |
| 11 | * Copyright 2005 Nokia. All rights reserved. |
| 12 | * |
| 13 | * The portions of the attached software ("Contribution") is developed by |
| 14 | * Nokia Corporation and is licensed pursuant to the OpenSSL open source |
| 15 | * license. |
| 16 | * |
| 17 | * The Contribution, originally written by Mika Kousa and Pasi Eronen of |
| 18 | * Nokia Corporation, consists of the "PSK" (Pre-Shared Key) ciphersuites |
| 19 | * support (see RFC 4279) to OpenSSL. |
| 20 | * |
| 21 | * No patent licenses or other rights except those expressly stated in |
| 22 | * the OpenSSL open source license shall be deemed granted or received |
| 23 | * expressly, by implication, estoppel, or otherwise. |
| 24 | * |
| 25 | * No assurances are provided by Nokia that the Contribution does not |
| 26 | * infringe the patent or other intellectual property rights of any third |
| 27 | * party or that the license provides you with all the necessary rights |
| 28 | * to make use of the Contribution. |
| 29 | * |
| 30 | * THE SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. IN |
| 31 | * ADDITION TO THE DISCLAIMERS INCLUDED IN THE LICENSE, NOKIA |
| 32 | * SPECIFICALLY DISCLAIMS ANY LIABILITY FOR CLAIMS BROUGHT BY YOU OR ANY |
| 33 | * OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS OR |
| 34 | * OTHERWISE. |
| 35 | */ |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 36 | |
| 37 | #include <stdio.h> |
Bodo Möller | ec57782 | 1999-04-23 22:13:45 +0000 | [diff] [blame] | 38 | #include <openssl/lhash.h> |
| 39 | #include <openssl/rand.h> |
Rich Salz | 3c27208 | 2016-03-18 14:30:20 -0400 | [diff] [blame] | 40 | #include <openssl/engine.h> |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 41 | #include "ssl_locl.h" |
| 42 | |
Ralf S. Engelschall | 58964a4 | 1998-12-21 10:56:39 +0000 | [diff] [blame] | 43 | static void SSL_SESSION_list_remove(SSL_CTX *ctx, SSL_SESSION *s); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 44 | static void SSL_SESSION_list_add(SSL_CTX *ctx, SSL_SESSION *s); |
Dr. Stephen Henson | 801294f | 1999-04-29 22:25:52 +0000 | [diff] [blame] | 45 | static int remove_session_lock(SSL_CTX *ctx, SSL_SESSION *c, int lck); |
Ralf S. Engelschall | 58964a4 | 1998-12-21 10:56:39 +0000 | [diff] [blame] | 46 | |
Ben Laurie | 0821bcd | 2005-03-30 10:26:02 +0000 | [diff] [blame] | 47 | SSL_SESSION *SSL_get_session(const SSL *ssl) |
Bodo Möller | 52732b3 | 2000-01-26 22:36:55 +0000 | [diff] [blame] | 48 | /* aka SSL_get0_session; gets 0 objects, just returns a copy of the pointer */ |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 49 | { |
| 50 | return (ssl->session); |
| 51 | } |
Bodo Möller | 52732b3 | 2000-01-26 22:36:55 +0000 | [diff] [blame] | 52 | |
| 53 | SSL_SESSION *SSL_get1_session(SSL *ssl) |
| 54 | /* variant of SSL_get_session: caller really gets something */ |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 55 | { |
| 56 | SSL_SESSION *sess; |
| 57 | /* |
| 58 | * Need to lock this all up rather than just use CRYPTO_add so that |
| 59 | * somebody doesn't free ssl->session between when we check it's non-null |
| 60 | * and when we up the reference count. |
| 61 | */ |
Alessandro Ghedini | 16203f7 | 2016-02-29 17:26:07 +0000 | [diff] [blame] | 62 | CRYPTO_THREAD_read_lock(ssl->lock); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 63 | sess = ssl->session; |
| 64 | if (sess) |
Alessandro Ghedini | 16203f7 | 2016-02-29 17:26:07 +0000 | [diff] [blame] | 65 | SSL_SESSION_up_ref(sess); |
| 66 | CRYPTO_THREAD_unlock(ssl->lock); |
| 67 | return sess; |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 68 | } |
Ralf S. Engelschall | 58964a4 | 1998-12-21 10:56:39 +0000 | [diff] [blame] | 69 | |
Ulf Möller | 6b691a5 | 1999-04-19 21:31:43 +0000 | [diff] [blame] | 70 | int SSL_SESSION_set_ex_data(SSL_SESSION *s, int idx, void *arg) |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 71 | { |
| 72 | return (CRYPTO_set_ex_data(&s->ex_data, idx, arg)); |
| 73 | } |
Ralf S. Engelschall | 58964a4 | 1998-12-21 10:56:39 +0000 | [diff] [blame] | 74 | |
Ben Laurie | 0821bcd | 2005-03-30 10:26:02 +0000 | [diff] [blame] | 75 | void *SSL_SESSION_get_ex_data(const SSL_SESSION *s, int idx) |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 76 | { |
| 77 | return (CRYPTO_get_ex_data(&s->ex_data, idx)); |
| 78 | } |
Ralf S. Engelschall | 58964a4 | 1998-12-21 10:56:39 +0000 | [diff] [blame] | 79 | |
Ulf Möller | 6b691a5 | 1999-04-19 21:31:43 +0000 | [diff] [blame] | 80 | SSL_SESSION *SSL_SESSION_new(void) |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 81 | { |
| 82 | SSL_SESSION *ss; |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 83 | |
Rich Salz | b51bce9 | 2015-08-25 13:25:58 -0400 | [diff] [blame] | 84 | ss = OPENSSL_zalloc(sizeof(*ss)); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 85 | if (ss == NULL) { |
| 86 | SSLerr(SSL_F_SSL_SESSION_NEW, ERR_R_MALLOC_FAILURE); |
Alessandro Ghedini | 16203f7 | 2016-02-29 17:26:07 +0000 | [diff] [blame] | 87 | return NULL; |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 88 | } |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 89 | |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 90 | ss->verify_result = 1; /* avoid 0 (= X509_V_OK) just in case */ |
| 91 | ss->references = 1; |
| 92 | ss->timeout = 60 * 5 + 4; /* 5 minute timeout by default */ |
| 93 | ss->time = (unsigned long)time(NULL); |
Alessandro Ghedini | 16203f7 | 2016-02-29 17:26:07 +0000 | [diff] [blame] | 94 | ss->lock = CRYPTO_THREAD_lock_new(); |
| 95 | if (ss->lock == NULL) { |
| 96 | SSLerr(SSL_F_SSL_SESSION_NEW, ERR_R_MALLOC_FAILURE); |
| 97 | OPENSSL_free(ss); |
| 98 | return NULL; |
| 99 | } |
| 100 | |
FdaSilvaYY | 25a807b | 2016-02-13 19:29:34 +0100 | [diff] [blame] | 101 | if (!CRYPTO_new_ex_data(CRYPTO_EX_INDEX_SSL_SESSION, ss, &ss->ex_data)) { |
| 102 | CRYPTO_THREAD_lock_free(ss->lock); |
| 103 | OPENSSL_free(ss); |
| 104 | return NULL; |
| 105 | } |
Alessandro Ghedini | 16203f7 | 2016-02-29 17:26:07 +0000 | [diff] [blame] | 106 | return ss; |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 107 | } |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 108 | |
Matt Caswell | 98ece4e | 2015-05-18 16:27:48 +0100 | [diff] [blame] | 109 | /* |
| 110 | * Create a new SSL_SESSION and duplicate the contents of |src| into it. If |
| 111 | * ticket == 0 then no ticket information is duplicated, otherwise it is. |
| 112 | */ |
| 113 | SSL_SESSION *ssl_session_dup(SSL_SESSION *src, int ticket) |
| 114 | { |
| 115 | SSL_SESSION *dest; |
| 116 | |
| 117 | dest = OPENSSL_malloc(sizeof(*src)); |
| 118 | if (dest == NULL) { |
| 119 | goto err; |
| 120 | } |
| 121 | memcpy(dest, src, sizeof(*dest)); |
| 122 | |
Matt Caswell | 708cf59 | 2015-06-11 01:30:06 +0100 | [diff] [blame] | 123 | /* |
| 124 | * Set the various pointers to NULL so that we can call SSL_SESSION_free in |
| 125 | * the case of an error whilst halfway through constructing dest |
| 126 | */ |
Matt Caswell | 98ece4e | 2015-05-18 16:27:48 +0100 | [diff] [blame] | 127 | #ifndef OPENSSL_NO_PSK |
Matt Caswell | 708cf59 | 2015-06-11 01:30:06 +0100 | [diff] [blame] | 128 | dest->psk_identity_hint = NULL; |
| 129 | dest->psk_identity = NULL; |
Matt Caswell | 98ece4e | 2015-05-18 16:27:48 +0100 | [diff] [blame] | 130 | #endif |
Matt Caswell | 708cf59 | 2015-06-11 01:30:06 +0100 | [diff] [blame] | 131 | dest->ciphers = NULL; |
| 132 | dest->tlsext_hostname = NULL; |
| 133 | #ifndef OPENSSL_NO_EC |
| 134 | dest->tlsext_ecpointformatlist = NULL; |
| 135 | dest->tlsext_ellipticcurvelist = NULL; |
| 136 | #endif |
| 137 | dest->tlsext_tick = NULL; |
| 138 | #ifndef OPENSSL_NO_SRP |
| 139 | dest->srp_username = NULL; |
| 140 | #endif |
| 141 | memset(&dest->ex_data, 0, sizeof(dest->ex_data)); |
| 142 | |
| 143 | /* We deliberately don't copy the prev and next pointers */ |
| 144 | dest->prev = NULL; |
| 145 | dest->next = NULL; |
| 146 | |
| 147 | dest->references = 1; |
Matt Caswell | 98ece4e | 2015-05-18 16:27:48 +0100 | [diff] [blame] | 148 | |
Alessandro Ghedini | 16203f7 | 2016-02-29 17:26:07 +0000 | [diff] [blame] | 149 | dest->lock = CRYPTO_THREAD_lock_new(); |
| 150 | if (dest->lock == NULL) |
| 151 | goto err; |
| 152 | |
Matt Caswell | 98ece4e | 2015-05-18 16:27:48 +0100 | [diff] [blame] | 153 | if (src->peer != NULL) |
Dr. Stephen Henson | 05f0fb9 | 2015-08-31 20:29:57 +0100 | [diff] [blame] | 154 | X509_up_ref(src->peer); |
Matt Caswell | 98ece4e | 2015-05-18 16:27:48 +0100 | [diff] [blame] | 155 | |
Dr. Stephen Henson | 36f038f | 2015-06-30 13:58:25 +0100 | [diff] [blame] | 156 | if (src->peer_chain != NULL) { |
| 157 | dest->peer_chain = X509_chain_up_ref(src->peer_chain); |
| 158 | if (dest->peer_chain == NULL) |
| 159 | goto err; |
| 160 | } |
Matt Caswell | 708cf59 | 2015-06-11 01:30:06 +0100 | [diff] [blame] | 161 | #ifndef OPENSSL_NO_PSK |
| 162 | if (src->psk_identity_hint) { |
Rich Salz | 7644a9a | 2015-12-16 16:12:24 -0500 | [diff] [blame] | 163 | dest->psk_identity_hint = OPENSSL_strdup(src->psk_identity_hint); |
Matt Caswell | 708cf59 | 2015-06-11 01:30:06 +0100 | [diff] [blame] | 164 | if (dest->psk_identity_hint == NULL) { |
| 165 | goto err; |
| 166 | } |
| 167 | } |
| 168 | if (src->psk_identity) { |
Rich Salz | 7644a9a | 2015-12-16 16:12:24 -0500 | [diff] [blame] | 169 | dest->psk_identity = OPENSSL_strdup(src->psk_identity); |
Matt Caswell | 708cf59 | 2015-06-11 01:30:06 +0100 | [diff] [blame] | 170 | if (dest->psk_identity == NULL) { |
| 171 | goto err; |
| 172 | } |
| 173 | } |
| 174 | #endif |
Matt Caswell | 98ece4e | 2015-05-18 16:27:48 +0100 | [diff] [blame] | 175 | |
FdaSilvaYY | e8aa8b6 | 2016-06-29 00:18:50 +0200 | [diff] [blame] | 176 | if (src->ciphers != NULL) { |
Matt Caswell | 98ece4e | 2015-05-18 16:27:48 +0100 | [diff] [blame] | 177 | dest->ciphers = sk_SSL_CIPHER_dup(src->ciphers); |
| 178 | if (dest->ciphers == NULL) |
| 179 | goto err; |
Matt Caswell | 98ece4e | 2015-05-18 16:27:48 +0100 | [diff] [blame] | 180 | } |
| 181 | |
| 182 | if (!CRYPTO_dup_ex_data(CRYPTO_EX_INDEX_SSL_SESSION, |
Emilia Kasper | a230b26 | 2016-08-05 19:03:17 +0200 | [diff] [blame] | 183 | &dest->ex_data, &src->ex_data)) { |
Matt Caswell | 98ece4e | 2015-05-18 16:27:48 +0100 | [diff] [blame] | 184 | goto err; |
| 185 | } |
| 186 | |
Matt Caswell | 98ece4e | 2015-05-18 16:27:48 +0100 | [diff] [blame] | 187 | if (src->tlsext_hostname) { |
Rich Salz | 7644a9a | 2015-12-16 16:12:24 -0500 | [diff] [blame] | 188 | dest->tlsext_hostname = OPENSSL_strdup(src->tlsext_hostname); |
Matt Caswell | 98ece4e | 2015-05-18 16:27:48 +0100 | [diff] [blame] | 189 | if (dest->tlsext_hostname == NULL) { |
| 190 | goto err; |
| 191 | } |
Matt Caswell | 98ece4e | 2015-05-18 16:27:48 +0100 | [diff] [blame] | 192 | } |
Matt Caswell | 708cf59 | 2015-06-11 01:30:06 +0100 | [diff] [blame] | 193 | #ifndef OPENSSL_NO_EC |
Matt Caswell | 98ece4e | 2015-05-18 16:27:48 +0100 | [diff] [blame] | 194 | if (src->tlsext_ecpointformatlist) { |
| 195 | dest->tlsext_ecpointformatlist = |
Rich Salz | 7644a9a | 2015-12-16 16:12:24 -0500 | [diff] [blame] | 196 | OPENSSL_memdup(src->tlsext_ecpointformatlist, |
Emilia Kasper | a230b26 | 2016-08-05 19:03:17 +0200 | [diff] [blame] | 197 | src->tlsext_ecpointformatlist_length); |
Matt Caswell | 98ece4e | 2015-05-18 16:27:48 +0100 | [diff] [blame] | 198 | if (dest->tlsext_ecpointformatlist == NULL) |
| 199 | goto err; |
Matt Caswell | 98ece4e | 2015-05-18 16:27:48 +0100 | [diff] [blame] | 200 | } |
| 201 | if (src->tlsext_ellipticcurvelist) { |
| 202 | dest->tlsext_ellipticcurvelist = |
Rich Salz | 7644a9a | 2015-12-16 16:12:24 -0500 | [diff] [blame] | 203 | OPENSSL_memdup(src->tlsext_ellipticcurvelist, |
Emilia Kasper | a230b26 | 2016-08-05 19:03:17 +0200 | [diff] [blame] | 204 | src->tlsext_ellipticcurvelist_length); |
Matt Caswell | 98ece4e | 2015-05-18 16:27:48 +0100 | [diff] [blame] | 205 | if (dest->tlsext_ellipticcurvelist == NULL) |
| 206 | goto err; |
Matt Caswell | 98ece4e | 2015-05-18 16:27:48 +0100 | [diff] [blame] | 207 | } |
Matt Caswell | 98ece4e | 2015-05-18 16:27:48 +0100 | [diff] [blame] | 208 | #endif |
| 209 | |
| 210 | if (ticket != 0) { |
Emilia Kasper | a230b26 | 2016-08-05 19:03:17 +0200 | [diff] [blame] | 211 | dest->tlsext_tick = |
| 212 | OPENSSL_memdup(src->tlsext_tick, src->tlsext_ticklen); |
FdaSilvaYY | e8aa8b6 | 2016-06-29 00:18:50 +0200 | [diff] [blame] | 213 | if (dest->tlsext_tick == NULL) |
Matt Caswell | 98ece4e | 2015-05-18 16:27:48 +0100 | [diff] [blame] | 214 | goto err; |
Matt Caswell | 708cf59 | 2015-06-11 01:30:06 +0100 | [diff] [blame] | 215 | } else { |
| 216 | dest->tlsext_tick_lifetime_hint = 0; |
| 217 | dest->tlsext_ticklen = 0; |
Matt Caswell | 98ece4e | 2015-05-18 16:27:48 +0100 | [diff] [blame] | 218 | } |
| 219 | |
| 220 | #ifndef OPENSSL_NO_SRP |
Matt Caswell | 98ece4e | 2015-05-18 16:27:48 +0100 | [diff] [blame] | 221 | if (src->srp_username) { |
Rich Salz | 7644a9a | 2015-12-16 16:12:24 -0500 | [diff] [blame] | 222 | dest->srp_username = OPENSSL_strdup(src->srp_username); |
Matt Caswell | 98ece4e | 2015-05-18 16:27:48 +0100 | [diff] [blame] | 223 | if (dest->srp_username == NULL) { |
| 224 | goto err; |
| 225 | } |
Matt Caswell | 98ece4e | 2015-05-18 16:27:48 +0100 | [diff] [blame] | 226 | } |
| 227 | #endif |
| 228 | |
| 229 | return dest; |
Emilia Kasper | a230b26 | 2016-08-05 19:03:17 +0200 | [diff] [blame] | 230 | err: |
Matt Caswell | 98ece4e | 2015-05-18 16:27:48 +0100 | [diff] [blame] | 231 | SSLerr(SSL_F_SSL_SESSION_DUP, ERR_R_MALLOC_FAILURE); |
| 232 | SSL_SESSION_free(dest); |
| 233 | return NULL; |
| 234 | } |
| 235 | |
Emilia Kasper | a230b26 | 2016-08-05 19:03:17 +0200 | [diff] [blame] | 236 | const unsigned char *SSL_SESSION_get_id(const SSL_SESSION *s, unsigned int *len) |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 237 | { |
| 238 | if (len) |
| 239 | *len = s->session_id_length; |
| 240 | return s->session_id; |
| 241 | } |
Remi Gacogne | fddfc0a | 2016-08-06 12:54:29 +0200 | [diff] [blame] | 242 | const unsigned char *SSL_SESSION_get0_id_context(const SSL_SESSION *s, |
| 243 | unsigned int *len) |
| 244 | { |
| 245 | if (len != NULL) |
| 246 | *len = s->sid_ctx_length; |
| 247 | return s->sid_ctx; |
| 248 | } |
Geoff Thorpe | 4879ec7 | 2003-02-15 20:38:57 +0000 | [diff] [blame] | 249 | |
Dr. Stephen Henson | f9b0b45 | 2011-12-22 15:14:32 +0000 | [diff] [blame] | 250 | unsigned int SSL_SESSION_get_compress_id(const SSL_SESSION *s) |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 251 | { |
| 252 | return s->compress_meth; |
| 253 | } |
Dr. Stephen Henson | f9b0b45 | 2011-12-22 15:14:32 +0000 | [diff] [blame] | 254 | |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 255 | /* |
| 256 | * SSLv3/TLSv1 has 32 bytes (256 bits) of session ID space. As such, filling |
| 257 | * the ID with random junk repeatedly until we have no conflict is going to |
| 258 | * complete in one iteration pretty much "most" of the time (btw: |
| 259 | * understatement). So, if it takes us 10 iterations and we still can't avoid |
| 260 | * a conflict - well that's a reasonable point to call it quits. Either the |
| 261 | * RAND code is broken or someone is trying to open roughly very close to |
| 262 | * 2^256 SSL sessions to our server. How you might store that many sessions |
| 263 | * is perhaps a more interesting question ... |
| 264 | */ |
Geoff Thorpe | dc644fe | 2001-02-21 18:06:26 +0000 | [diff] [blame] | 265 | |
| 266 | #define MAX_SESS_ID_ATTEMPTS 10 |
| 267 | static int def_generate_session_id(const SSL *ssl, unsigned char *id, |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 268 | unsigned int *id_len) |
Geoff Thorpe | dc644fe | 2001-02-21 18:06:26 +0000 | [diff] [blame] | 269 | { |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 270 | unsigned int retry = 0; |
| 271 | do |
Matt Caswell | 266483d | 2015-02-26 11:57:37 +0000 | [diff] [blame] | 272 | if (RAND_bytes(id, *id_len) <= 0) |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 273 | return 0; |
| 274 | while (SSL_has_matching_session_id(ssl, id, *id_len) && |
| 275 | (++retry < MAX_SESS_ID_ATTEMPTS)) ; |
| 276 | if (retry < MAX_SESS_ID_ATTEMPTS) |
| 277 | return 1; |
| 278 | /* else - woops a session_id match */ |
| 279 | /* |
| 280 | * XXX We should also check the external cache -- but the probability of |
| 281 | * a collision is negligible, and we could not prevent the concurrent |
| 282 | * creation of sessions with identical IDs since we currently don't have |
| 283 | * means to atomically check whether a session ID already exists and make |
| 284 | * a reservation for it if it does not (this problem applies to the |
| 285 | * internal cache as well). |
| 286 | */ |
| 287 | return 0; |
Geoff Thorpe | dc644fe | 2001-02-21 18:06:26 +0000 | [diff] [blame] | 288 | } |
| 289 | |
Ulf Möller | 6b691a5 | 1999-04-19 21:31:43 +0000 | [diff] [blame] | 290 | int ssl_get_new_session(SSL *s, int session) |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 291 | { |
| 292 | /* This gets used by clients and servers. */ |
Bodo Möller | b56bce4 | 1999-05-13 15:09:38 +0000 | [diff] [blame] | 293 | |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 294 | unsigned int tmp; |
| 295 | SSL_SESSION *ss = NULL; |
| 296 | GEN_SESSION_CB cb = def_generate_session_id; |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 297 | |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 298 | if ((ss = SSL_SESSION_new()) == NULL) |
| 299 | return (0); |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 300 | |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 301 | /* If the context has a default timeout, use it */ |
| 302 | if (s->session_ctx->session_timeout == 0) |
| 303 | ss->timeout = SSL_get_default_timeout(s); |
| 304 | else |
| 305 | ss->timeout = s->session_ctx->session_timeout; |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 306 | |
Rich Salz | 62adbce | 2015-04-11 10:22:36 -0400 | [diff] [blame] | 307 | SSL_SESSION_free(s->session); |
| 308 | s->session = NULL; |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 309 | |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 310 | if (session) { |
| 311 | if (s->version == SSL3_VERSION) { |
| 312 | ss->ssl_version = SSL3_VERSION; |
| 313 | ss->session_id_length = SSL3_SSL_SESSION_ID_LENGTH; |
| 314 | } else if (s->version == TLS1_VERSION) { |
| 315 | ss->ssl_version = TLS1_VERSION; |
| 316 | ss->session_id_length = SSL3_SSL_SESSION_ID_LENGTH; |
| 317 | } else if (s->version == TLS1_1_VERSION) { |
| 318 | ss->ssl_version = TLS1_1_VERSION; |
| 319 | ss->session_id_length = SSL3_SSL_SESSION_ID_LENGTH; |
| 320 | } else if (s->version == TLS1_2_VERSION) { |
| 321 | ss->ssl_version = TLS1_2_VERSION; |
| 322 | ss->session_id_length = SSL3_SSL_SESSION_ID_LENGTH; |
| 323 | } else if (s->version == DTLS1_BAD_VER) { |
| 324 | ss->ssl_version = DTLS1_BAD_VER; |
| 325 | ss->session_id_length = SSL3_SSL_SESSION_ID_LENGTH; |
| 326 | } else if (s->version == DTLS1_VERSION) { |
| 327 | ss->ssl_version = DTLS1_VERSION; |
| 328 | ss->session_id_length = SSL3_SSL_SESSION_ID_LENGTH; |
| 329 | } else if (s->version == DTLS1_2_VERSION) { |
| 330 | ss->ssl_version = DTLS1_2_VERSION; |
| 331 | ss->session_id_length = SSL3_SSL_SESSION_ID_LENGTH; |
| 332 | } else { |
| 333 | SSLerr(SSL_F_SSL_GET_NEW_SESSION, SSL_R_UNSUPPORTED_SSL_VERSION); |
| 334 | SSL_SESSION_free(ss); |
| 335 | return (0); |
| 336 | } |
Matt Caswell | e481f9b | 2015-05-15 10:49:56 +0100 | [diff] [blame] | 337 | |
Matt Caswell | 35a1cc9 | 2015-01-17 00:06:54 +0000 | [diff] [blame] | 338 | /*- |
| 339 | * If RFC5077 ticket, use empty session ID (as server). |
| 340 | * Note that: |
| 341 | * (a) ssl_get_prev_session() does lookahead into the |
| 342 | * ClientHello extensions to find the session ticket. |
Matt Caswell | d4d7894 | 2016-05-17 11:51:00 +0100 | [diff] [blame] | 343 | * When ssl_get_prev_session() fails, statem_srvr.c calls |
| 344 | * ssl_get_new_session() in tls_process_client_hello(). |
Matt Caswell | 35a1cc9 | 2015-01-17 00:06:54 +0000 | [diff] [blame] | 345 | * At that point, it has not yet parsed the extensions, |
| 346 | * however, because of the lookahead, it already knows |
| 347 | * whether a ticket is expected or not. |
| 348 | * |
Matt Caswell | d4d7894 | 2016-05-17 11:51:00 +0100 | [diff] [blame] | 349 | * (b) statem_clnt.c calls ssl_get_new_session() before parsing |
Matt Caswell | 35a1cc9 | 2015-01-17 00:06:54 +0000 | [diff] [blame] | 350 | * ServerHello extensions, and before recording the session |
| 351 | * ID received from the server, so this block is a noop. |
| 352 | */ |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 353 | if (s->tlsext_ticket_expected) { |
| 354 | ss->session_id_length = 0; |
| 355 | goto sess_id_done; |
| 356 | } |
Matt Caswell | e481f9b | 2015-05-15 10:49:56 +0100 | [diff] [blame] | 357 | |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 358 | /* Choose which callback will set the session ID */ |
Alessandro Ghedini | 16203f7 | 2016-02-29 17:26:07 +0000 | [diff] [blame] | 359 | CRYPTO_THREAD_read_lock(s->lock); |
| 360 | CRYPTO_THREAD_read_lock(s->session_ctx->lock); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 361 | if (s->generate_session_id) |
| 362 | cb = s->generate_session_id; |
| 363 | else if (s->session_ctx->generate_session_id) |
| 364 | cb = s->session_ctx->generate_session_id; |
Alessandro Ghedini | 16203f7 | 2016-02-29 17:26:07 +0000 | [diff] [blame] | 365 | CRYPTO_THREAD_unlock(s->session_ctx->lock); |
| 366 | CRYPTO_THREAD_unlock(s->lock); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 367 | /* Choose a session ID */ |
Kurt Roeckx | 947f315 | 2016-06-05 23:34:57 +0200 | [diff] [blame] | 368 | memset(ss->session_id, 0, ss->session_id_length); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 369 | tmp = ss->session_id_length; |
| 370 | if (!cb(s, ss->session_id, &tmp)) { |
| 371 | /* The callback failed */ |
| 372 | SSLerr(SSL_F_SSL_GET_NEW_SESSION, |
| 373 | SSL_R_SSL_SESSION_ID_CALLBACK_FAILED); |
| 374 | SSL_SESSION_free(ss); |
| 375 | return (0); |
| 376 | } |
| 377 | /* |
| 378 | * Don't allow the callback to set the session length to zero. nor |
| 379 | * set it higher than it was. |
| 380 | */ |
Rich Salz | cc99bfa | 2015-11-23 13:30:04 -0500 | [diff] [blame] | 381 | if (tmp == 0 || tmp > ss->session_id_length) { |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 382 | /* The callback set an illegal length */ |
| 383 | SSLerr(SSL_F_SSL_GET_NEW_SESSION, |
| 384 | SSL_R_SSL_SESSION_ID_HAS_BAD_LENGTH); |
| 385 | SSL_SESSION_free(ss); |
| 386 | return (0); |
| 387 | } |
| 388 | ss->session_id_length = tmp; |
| 389 | /* Finally, check for a conflict */ |
| 390 | if (SSL_has_matching_session_id(s, ss->session_id, |
| 391 | ss->session_id_length)) { |
| 392 | SSLerr(SSL_F_SSL_GET_NEW_SESSION, SSL_R_SSL_SESSION_ID_CONFLICT); |
| 393 | SSL_SESSION_free(ss); |
| 394 | return (0); |
| 395 | } |
Matt Caswell | e481f9b | 2015-05-15 10:49:56 +0100 | [diff] [blame] | 396 | |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 397 | sess_id_done: |
| 398 | if (s->tlsext_hostname) { |
Rich Salz | 7644a9a | 2015-12-16 16:12:24 -0500 | [diff] [blame] | 399 | ss->tlsext_hostname = OPENSSL_strdup(s->tlsext_hostname); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 400 | if (ss->tlsext_hostname == NULL) { |
| 401 | SSLerr(SSL_F_SSL_GET_NEW_SESSION, ERR_R_INTERNAL_ERROR); |
| 402 | SSL_SESSION_free(ss); |
| 403 | return 0; |
| 404 | } |
| 405 | } |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 406 | } else { |
| 407 | ss->session_id_length = 0; |
| 408 | } |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 409 | |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 410 | if (s->sid_ctx_length > sizeof ss->sid_ctx) { |
| 411 | SSLerr(SSL_F_SSL_GET_NEW_SESSION, ERR_R_INTERNAL_ERROR); |
| 412 | SSL_SESSION_free(ss); |
| 413 | return 0; |
| 414 | } |
| 415 | memcpy(ss->sid_ctx, s->sid_ctx, s->sid_ctx_length); |
| 416 | ss->sid_ctx_length = s->sid_ctx_length; |
| 417 | s->session = ss; |
| 418 | ss->ssl_version = s->version; |
| 419 | ss->verify_result = X509_V_OK; |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 420 | |
Dr. Stephen Henson | e7f0d92 | 2015-12-04 19:48:15 +0000 | [diff] [blame] | 421 | /* If client supports extended master secret set it in session */ |
| 422 | if (s->s3->flags & TLS1_FLAGS_RECEIVED_EXTMS) |
| 423 | ss->flags |= SSL_SESS_FLAG_EXTMS; |
| 424 | |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 425 | return (1); |
| 426 | } |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 427 | |
Matt Caswell | 3a83462 | 2015-01-05 00:34:00 +0000 | [diff] [blame] | 428 | /*- |
| 429 | * ssl_get_prev attempts to find an SSL_SESSION to be used to resume this |
Bodo Möller | c519e89 | 2011-09-05 13:36:23 +0000 | [diff] [blame] | 430 | * connection. It is only called by servers. |
| 431 | * |
Emilia Kasper | b3e2272 | 2015-09-30 15:33:12 +0200 | [diff] [blame] | 432 | * ext: ClientHello extensions (including length prefix) |
| 433 | * session_id: ClientHello session ID. |
Bodo Möller | c519e89 | 2011-09-05 13:36:23 +0000 | [diff] [blame] | 434 | * |
| 435 | * Returns: |
| 436 | * -1: error |
| 437 | * 0: a session may have been found. |
| 438 | * |
| 439 | * Side effects: |
| 440 | * - If a session is found then s->session is pointed at it (after freeing an |
| 441 | * existing session if need be) and s->verify_result is set from the session. |
| 442 | * - Both for new and resumed sessions, s->tlsext_ticket_expected is set to 1 |
| 443 | * if the server should issue a new session ticket (to 0 otherwise). |
| 444 | */ |
Emilia Kasper | b3e2272 | 2015-09-30 15:33:12 +0200 | [diff] [blame] | 445 | int ssl_get_prev_session(SSL *s, const PACKET *ext, const PACKET *session_id) |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 446 | { |
| 447 | /* This is used only by servers. */ |
Bodo Möller | b56bce4 | 1999-05-13 15:09:38 +0000 | [diff] [blame] | 448 | |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 449 | SSL_SESSION *ret = NULL; |
| 450 | int fatal = 0; |
| 451 | int try_session_cache = 1; |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 452 | int r; |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 453 | |
Alessandro Ghedini | 293b5ca | 2015-10-08 19:56:03 +0200 | [diff] [blame] | 454 | if (PACKET_remaining(session_id) == 0) |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 455 | try_session_cache = 0; |
Bodo Möller | c519e89 | 2011-09-05 13:36:23 +0000 | [diff] [blame] | 456 | |
Dr. Stephen Henson | e7f0d92 | 2015-12-04 19:48:15 +0000 | [diff] [blame] | 457 | /* sets s->tlsext_ticket_expected and extended master secret flag */ |
| 458 | r = tls_check_serverhello_tlsext_early(s, ext, session_id, &ret); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 459 | switch (r) { |
| 460 | case -1: /* Error during processing */ |
| 461 | fatal = 1; |
| 462 | goto err; |
| 463 | case 0: /* No ticket found */ |
| 464 | case 1: /* Zero length ticket found */ |
| 465 | break; /* Ok to carry on processing session id. */ |
| 466 | case 2: /* Ticket found but not decrypted. */ |
| 467 | case 3: /* Ticket decrypted, *ret has been set. */ |
| 468 | try_session_cache = 0; |
| 469 | break; |
| 470 | default: |
| 471 | abort(); |
| 472 | } |
Bodo Möller | c519e89 | 2011-09-05 13:36:23 +0000 | [diff] [blame] | 473 | |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 474 | if (try_session_cache && |
| 475 | ret == NULL && |
Matt Caswell | 739a5ee | 2015-01-22 03:41:31 +0000 | [diff] [blame] | 476 | !(s->session_ctx->session_cache_mode & |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 477 | SSL_SESS_CACHE_NO_INTERNAL_LOOKUP)) { |
| 478 | SSL_SESSION data; |
Emilia Kasper | 6720297 | 2015-10-01 13:54:11 +0200 | [diff] [blame] | 479 | size_t local_len; |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 480 | data.ssl_version = s->version; |
Kurt Roeckx | 947f315 | 2016-06-05 23:34:57 +0200 | [diff] [blame] | 481 | memset(data.session_id, 0, sizeof(data.session_id)); |
Emilia Kasper | 6720297 | 2015-10-01 13:54:11 +0200 | [diff] [blame] | 482 | if (!PACKET_copy_all(session_id, data.session_id, |
Emilia Kasper | a230b26 | 2016-08-05 19:03:17 +0200 | [diff] [blame] | 483 | sizeof(data.session_id), &local_len)) { |
Emilia Kasper | 6720297 | 2015-10-01 13:54:11 +0200 | [diff] [blame] | 484 | goto err; |
| 485 | } |
| 486 | data.session_id_length = local_len; |
Alessandro Ghedini | 16203f7 | 2016-02-29 17:26:07 +0000 | [diff] [blame] | 487 | CRYPTO_THREAD_read_lock(s->session_ctx->lock); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 488 | ret = lh_SSL_SESSION_retrieve(s->session_ctx->sessions, &data); |
| 489 | if (ret != NULL) { |
| 490 | /* don't allow other threads to steal it: */ |
Alessandro Ghedini | 16203f7 | 2016-02-29 17:26:07 +0000 | [diff] [blame] | 491 | SSL_SESSION_up_ref(ret); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 492 | } |
Alessandro Ghedini | 16203f7 | 2016-02-29 17:26:07 +0000 | [diff] [blame] | 493 | CRYPTO_THREAD_unlock(s->session_ctx->lock); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 494 | if (ret == NULL) |
| 495 | s->session_ctx->stats.sess_miss++; |
| 496 | } |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 497 | |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 498 | if (try_session_cache && |
| 499 | ret == NULL && s->session_ctx->get_session_cb != NULL) { |
| 500 | int copy = 1; |
Emilia Kasper | b698174 | 2016-02-01 15:26:18 +0100 | [diff] [blame] | 501 | ret = s->session_ctx->get_session_cb(s, PACKET_data(session_id), |
| 502 | PACKET_remaining(session_id), |
| 503 | ©); |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 504 | |
Emilia Kasper | bf0fc41 | 2015-10-01 13:00:39 +0200 | [diff] [blame] | 505 | if (ret != NULL) { |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 506 | s->session_ctx->stats.sess_cb_hit++; |
Bodo Möller | 8876bc0 | 1999-05-23 13:07:03 +0000 | [diff] [blame] | 507 | |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 508 | /* |
| 509 | * Increment reference count now if the session callback asks us |
| 510 | * to do so (note that if the session structures returned by the |
| 511 | * callback are shared between threads, it must handle the |
| 512 | * reference count itself [i.e. copy == 0], or things won't be |
| 513 | * thread-safe). |
| 514 | */ |
| 515 | if (copy) |
Alessandro Ghedini | 16203f7 | 2016-02-29 17:26:07 +0000 | [diff] [blame] | 516 | SSL_SESSION_up_ref(ret); |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 517 | |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 518 | /* |
| 519 | * Add the externally cached session to the internal cache as |
| 520 | * well if and only if we are supposed to. |
| 521 | */ |
| 522 | if (! |
Matt Caswell | 739a5ee | 2015-01-22 03:41:31 +0000 | [diff] [blame] | 523 | (s->session_ctx->session_cache_mode & |
Matt Caswell | 69f6823 | 2015-03-06 14:37:17 +0000 | [diff] [blame] | 524 | SSL_SESS_CACHE_NO_INTERNAL_STORE)) { |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 525 | /* |
| 526 | * The following should not return 1, otherwise, things are |
| 527 | * very strange |
| 528 | */ |
Viktor Dukhovni | 61986d3 | 2015-04-16 01:50:03 -0400 | [diff] [blame] | 529 | if (SSL_CTX_add_session(s->session_ctx, ret)) |
Matt Caswell | 69f6823 | 2015-03-06 14:37:17 +0000 | [diff] [blame] | 530 | goto err; |
| 531 | } |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 532 | } |
| 533 | } |
Bodo Möller | c519e89 | 2011-09-05 13:36:23 +0000 | [diff] [blame] | 534 | |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 535 | if (ret == NULL) |
| 536 | goto err; |
Bodo Möller | 8876bc0 | 1999-05-23 13:07:03 +0000 | [diff] [blame] | 537 | |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 538 | /* Now ret is non-NULL and we own one of its reference counts. */ |
Ben Laurie | b4cadc6 | 1999-03-22 12:22:14 +0000 | [diff] [blame] | 539 | |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 540 | if (ret->sid_ctx_length != s->sid_ctx_length |
| 541 | || memcmp(ret->sid_ctx, s->sid_ctx, ret->sid_ctx_length)) { |
| 542 | /* |
| 543 | * We have the session requested by the client, but we don't want to |
| 544 | * use it in this context. |
| 545 | */ |
| 546 | goto err; /* treat like cache miss */ |
| 547 | } |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 548 | |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 549 | if ((s->verify_mode & SSL_VERIFY_PEER) && s->sid_ctx_length == 0) { |
| 550 | /* |
| 551 | * We can't be sure if this session is being used out of context, |
| 552 | * which is especially important for SSL_VERIFY_PEER. The application |
| 553 | * should have used SSL[_CTX]_set_session_id_context. For this error |
| 554 | * case, we generate an error instead of treating the event like a |
| 555 | * cache miss (otherwise it would be easy for applications to |
| 556 | * effectively disable the session cache by accident without anyone |
| 557 | * noticing). |
| 558 | */ |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 559 | |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 560 | SSLerr(SSL_F_SSL_GET_PREV_SESSION, |
| 561 | SSL_R_SESSION_ID_CONTEXT_UNINITIALIZED); |
| 562 | fatal = 1; |
| 563 | goto err; |
| 564 | } |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 565 | |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 566 | if (ret->cipher == NULL) { |
| 567 | unsigned char buf[5], *p; |
| 568 | unsigned long l; |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 569 | |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 570 | p = buf; |
| 571 | l = ret->cipher_id; |
| 572 | l2n(l, p); |
| 573 | if ((ret->ssl_version >> 8) >= SSL3_VERSION_MAJOR) |
| 574 | ret->cipher = ssl_get_cipher_by_char(s, &(buf[2])); |
| 575 | else |
| 576 | ret->cipher = ssl_get_cipher_by_char(s, &(buf[1])); |
| 577 | if (ret->cipher == NULL) |
| 578 | goto err; |
| 579 | } |
| 580 | |
| 581 | if (ret->timeout < (long)(time(NULL) - ret->time)) { /* timeout */ |
| 582 | s->session_ctx->stats.sess_timeout++; |
| 583 | if (try_session_cache) { |
| 584 | /* session was from the cache, so remove it */ |
| 585 | SSL_CTX_remove_session(s->session_ctx, ret); |
| 586 | } |
| 587 | goto err; |
| 588 | } |
| 589 | |
Dr. Stephen Henson | e7f0d92 | 2015-12-04 19:48:15 +0000 | [diff] [blame] | 590 | /* Check extended master secret extension consistency */ |
| 591 | if (ret->flags & SSL_SESS_FLAG_EXTMS) { |
| 592 | /* If old session includes extms, but new does not: abort handshake */ |
| 593 | if (!(s->s3->flags & TLS1_FLAGS_RECEIVED_EXTMS)) { |
| 594 | SSLerr(SSL_F_SSL_GET_PREV_SESSION, SSL_R_INCONSISTENT_EXTMS); |
| 595 | ssl3_send_alert(s, SSL3_AL_FATAL, SSL_AD_HANDSHAKE_FAILURE); |
| 596 | fatal = 1; |
| 597 | goto err; |
| 598 | } |
| 599 | } else if (s->s3->flags & TLS1_FLAGS_RECEIVED_EXTMS) { |
| 600 | /* If new session includes extms, but old does not: do not resume */ |
| 601 | goto err; |
| 602 | } |
| 603 | |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 604 | s->session_ctx->stats.sess_hit++; |
| 605 | |
Rich Salz | 62adbce | 2015-04-11 10:22:36 -0400 | [diff] [blame] | 606 | SSL_SESSION_free(s->session); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 607 | s->session = ret; |
| 608 | s->verify_result = s->session->verify_result; |
| 609 | return 1; |
Bodo Möller | 8876bc0 | 1999-05-23 13:07:03 +0000 | [diff] [blame] | 610 | |
| 611 | err: |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 612 | if (ret != NULL) { |
| 613 | SSL_SESSION_free(ret); |
Matt Caswell | e481f9b | 2015-05-15 10:49:56 +0100 | [diff] [blame] | 614 | |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 615 | if (!try_session_cache) { |
| 616 | /* |
| 617 | * The session was from a ticket, so we should issue a ticket for |
| 618 | * the new session |
| 619 | */ |
| 620 | s->tlsext_ticket_expected = 1; |
| 621 | } |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 622 | } |
| 623 | if (fatal) |
| 624 | return -1; |
| 625 | else |
| 626 | return 0; |
| 627 | } |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 628 | |
Ulf Möller | 6b691a5 | 1999-04-19 21:31:43 +0000 | [diff] [blame] | 629 | int SSL_CTX_add_session(SSL_CTX *ctx, SSL_SESSION *c) |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 630 | { |
| 631 | int ret = 0; |
| 632 | SSL_SESSION *s; |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 633 | |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 634 | /* |
| 635 | * add just 1 reference count for the SSL_CTX's session cache even though |
| 636 | * it has two ways of access: each session is in a doubly linked list and |
| 637 | * an lhash |
| 638 | */ |
Alessandro Ghedini | 16203f7 | 2016-02-29 17:26:07 +0000 | [diff] [blame] | 639 | SSL_SESSION_up_ref(c); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 640 | /* |
| 641 | * if session c is in already in cache, we take back the increment later |
| 642 | */ |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 643 | |
Alessandro Ghedini | 16203f7 | 2016-02-29 17:26:07 +0000 | [diff] [blame] | 644 | CRYPTO_THREAD_write_lock(ctx->lock); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 645 | s = lh_SSL_SESSION_insert(ctx->sessions, c); |
Bodo Möller | 45fd4db | 1999-12-29 14:29:32 +0000 | [diff] [blame] | 646 | |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 647 | /* |
| 648 | * s != NULL iff we already had a session with the given PID. In this |
| 649 | * case, s == c should hold (then we did not really modify |
| 650 | * ctx->sessions), or we're in trouble. |
| 651 | */ |
| 652 | if (s != NULL && s != c) { |
| 653 | /* We *are* in trouble ... */ |
| 654 | SSL_SESSION_list_remove(ctx, s); |
| 655 | SSL_SESSION_free(s); |
| 656 | /* |
| 657 | * ... so pretend the other session did not exist in cache (we cannot |
| 658 | * handle two SSL_SESSION structures with identical session ID in the |
| 659 | * same cache, which could happen e.g. when two threads concurrently |
| 660 | * obtain the same session from an external cache) |
| 661 | */ |
| 662 | s = NULL; |
| 663 | } |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 664 | |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 665 | /* Put at the head of the queue unless it is already in the cache */ |
| 666 | if (s == NULL) |
| 667 | SSL_SESSION_list_add(ctx, c); |
Bodo Möller | 45fd4db | 1999-12-29 14:29:32 +0000 | [diff] [blame] | 668 | |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 669 | if (s != NULL) { |
| 670 | /* |
| 671 | * existing cache entry -- decrement previously incremented reference |
| 672 | * count because it already takes into account the cache |
| 673 | */ |
Ralf S. Engelschall | 58964a4 | 1998-12-21 10:56:39 +0000 | [diff] [blame] | 674 | |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 675 | SSL_SESSION_free(s); /* s == c */ |
| 676 | ret = 0; |
| 677 | } else { |
| 678 | /* |
| 679 | * new cache entry -- remove old ones if cache has become too large |
| 680 | */ |
| 681 | |
| 682 | ret = 1; |
| 683 | |
| 684 | if (SSL_CTX_sess_get_cache_size(ctx) > 0) { |
Emilia Kasper | a230b26 | 2016-08-05 19:03:17 +0200 | [diff] [blame] | 685 | while (SSL_CTX_sess_number(ctx) > SSL_CTX_sess_get_cache_size(ctx)) { |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 686 | if (!remove_session_lock(ctx, ctx->session_cache_tail, 0)) |
| 687 | break; |
| 688 | else |
| 689 | ctx->stats.sess_cache_full++; |
| 690 | } |
| 691 | } |
| 692 | } |
Alessandro Ghedini | 16203f7 | 2016-02-29 17:26:07 +0000 | [diff] [blame] | 693 | CRYPTO_THREAD_unlock(ctx->lock); |
| 694 | return ret; |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 695 | } |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 696 | |
Ulf Möller | 6b691a5 | 1999-04-19 21:31:43 +0000 | [diff] [blame] | 697 | int SSL_CTX_remove_session(SSL_CTX *ctx, SSL_SESSION *c) |
Dr. Stephen Henson | 801294f | 1999-04-29 22:25:52 +0000 | [diff] [blame] | 698 | { |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 699 | return remove_session_lock(ctx, c, 1); |
Dr. Stephen Henson | 801294f | 1999-04-29 22:25:52 +0000 | [diff] [blame] | 700 | } |
| 701 | |
Bodo Möller | 0fda2e3 | 1999-05-01 00:18:54 +0000 | [diff] [blame] | 702 | static int remove_session_lock(SSL_CTX *ctx, SSL_SESSION *c, int lck) |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 703 | { |
| 704 | SSL_SESSION *r; |
| 705 | int ret = 0; |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 706 | |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 707 | if ((c != NULL) && (c->session_id_length != 0)) { |
| 708 | if (lck) |
Alessandro Ghedini | 16203f7 | 2016-02-29 17:26:07 +0000 | [diff] [blame] | 709 | CRYPTO_THREAD_write_lock(ctx->lock); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 710 | if ((r = lh_SSL_SESSION_retrieve(ctx->sessions, c)) == c) { |
| 711 | ret = 1; |
| 712 | r = lh_SSL_SESSION_delete(ctx->sessions, c); |
| 713 | SSL_SESSION_list_remove(ctx, c); |
| 714 | } |
Matt Caswell | e4612d0 | 2016-06-13 11:24:15 +0100 | [diff] [blame] | 715 | c->not_resumable = 1; |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 716 | |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 717 | if (lck) |
Alessandro Ghedini | 16203f7 | 2016-02-29 17:26:07 +0000 | [diff] [blame] | 718 | CRYPTO_THREAD_unlock(ctx->lock); |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 719 | |
Matt Caswell | e4612d0 | 2016-06-13 11:24:15 +0100 | [diff] [blame] | 720 | if (ret) |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 721 | SSL_SESSION_free(r); |
Matt Caswell | e4612d0 | 2016-06-13 11:24:15 +0100 | [diff] [blame] | 722 | |
| 723 | if (ctx->remove_session_cb != NULL) |
| 724 | ctx->remove_session_cb(ctx, c); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 725 | } else |
| 726 | ret = 0; |
| 727 | return (ret); |
| 728 | } |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 729 | |
Ulf Möller | 6b691a5 | 1999-04-19 21:31:43 +0000 | [diff] [blame] | 730 | void SSL_SESSION_free(SSL_SESSION *ss) |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 731 | { |
| 732 | int i; |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 733 | |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 734 | if (ss == NULL) |
| 735 | return; |
Ben Laurie | e03ddfa | 1999-01-07 19:15:59 +0000 | [diff] [blame] | 736 | |
Alessandro Ghedini | 16203f7 | 2016-02-29 17:26:07 +0000 | [diff] [blame] | 737 | CRYPTO_atomic_add(&ss->references, -1, &i, ss->lock); |
Rich Salz | f3f1cf8 | 2016-01-30 12:04:25 -0500 | [diff] [blame] | 738 | REF_PRINT_COUNT("SSL_SESSION", ss); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 739 | if (i > 0) |
| 740 | return; |
Rich Salz | f3f1cf8 | 2016-01-30 12:04:25 -0500 | [diff] [blame] | 741 | REF_ASSERT_ISNT(i < 0); |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 742 | |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 743 | CRYPTO_free_ex_data(CRYPTO_EX_INDEX_SSL_SESSION, ss, &ss->ex_data); |
Ralf S. Engelschall | 58964a4 | 1998-12-21 10:56:39 +0000 | [diff] [blame] | 744 | |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 745 | OPENSSL_cleanse(ss->master_key, sizeof ss->master_key); |
| 746 | OPENSSL_cleanse(ss->session_id, sizeof ss->session_id); |
Rich Salz | 222561f | 2015-04-30 17:33:59 -0400 | [diff] [blame] | 747 | X509_free(ss->peer); |
Dr. Stephen Henson | c34b0f9 | 2015-06-21 19:34:33 +0100 | [diff] [blame] | 748 | sk_X509_pop_free(ss->peer_chain, X509_free); |
Rich Salz | 25aaa98 | 2015-05-01 14:37:16 -0400 | [diff] [blame] | 749 | sk_SSL_CIPHER_free(ss->ciphers); |
Rich Salz | 25aaa98 | 2015-05-01 14:37:16 -0400 | [diff] [blame] | 750 | OPENSSL_free(ss->tlsext_hostname); |
| 751 | OPENSSL_free(ss->tlsext_tick); |
Matt Caswell | e481f9b | 2015-05-15 10:49:56 +0100 | [diff] [blame] | 752 | #ifndef OPENSSL_NO_EC |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 753 | ss->tlsext_ecpointformatlist_length = 0; |
Rich Salz | 25aaa98 | 2015-05-01 14:37:16 -0400 | [diff] [blame] | 754 | OPENSSL_free(ss->tlsext_ecpointformatlist); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 755 | ss->tlsext_ellipticcurvelist_length = 0; |
Rich Salz | 25aaa98 | 2015-05-01 14:37:16 -0400 | [diff] [blame] | 756 | OPENSSL_free(ss->tlsext_ellipticcurvelist); |
Emilia Kasper | a230b26 | 2016-08-05 19:03:17 +0200 | [diff] [blame] | 757 | #endif /* OPENSSL_NO_EC */ |
Nils Larsch | ddac197 | 2006-03-10 23:06:27 +0000 | [diff] [blame] | 758 | #ifndef OPENSSL_NO_PSK |
Rich Salz | 25aaa98 | 2015-05-01 14:37:16 -0400 | [diff] [blame] | 759 | OPENSSL_free(ss->psk_identity_hint); |
| 760 | OPENSSL_free(ss->psk_identity); |
Nils Larsch | ddac197 | 2006-03-10 23:06:27 +0000 | [diff] [blame] | 761 | #endif |
Ben Laurie | edc032b | 2011-03-12 17:01:19 +0000 | [diff] [blame] | 762 | #ifndef OPENSSL_NO_SRP |
Rich Salz | 25aaa98 | 2015-05-01 14:37:16 -0400 | [diff] [blame] | 763 | OPENSSL_free(ss->srp_username); |
Ben Laurie | edc032b | 2011-03-12 17:01:19 +0000 | [diff] [blame] | 764 | #endif |
Alessandro Ghedini | 16203f7 | 2016-02-29 17:26:07 +0000 | [diff] [blame] | 765 | CRYPTO_THREAD_lock_free(ss->lock); |
Rich Salz | 4b45c6e | 2015-04-30 17:57:32 -0400 | [diff] [blame] | 766 | OPENSSL_clear_free(ss, sizeof(*ss)); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 767 | } |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 768 | |
Alessandro Ghedini | 16203f7 | 2016-02-29 17:26:07 +0000 | [diff] [blame] | 769 | int SSL_SESSION_up_ref(SSL_SESSION *ss) |
| 770 | { |
| 771 | int i; |
| 772 | |
| 773 | if (CRYPTO_atomic_add(&ss->references, 1, &i, ss->lock) <= 0) |
| 774 | return 0; |
| 775 | |
| 776 | REF_PRINT_COUNT("SSL_SESSION", ss); |
| 777 | REF_ASSERT_ISNT(i < 2); |
| 778 | return ((i > 1) ? 1 : 0); |
| 779 | } |
| 780 | |
Ulf Möller | 6b691a5 | 1999-04-19 21:31:43 +0000 | [diff] [blame] | 781 | int SSL_set_session(SSL *s, SSL_SESSION *session) |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 782 | { |
Matt Caswell | e70656c | 2016-06-09 13:24:54 +0100 | [diff] [blame] | 783 | ssl_clear_bad_session(s); |
| 784 | if (s->ctx->method != s->method) { |
| 785 | if (!SSL_set_ssl_method(s, s->ctx->method)) |
| 786 | return 0; |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 787 | } |
Matt Caswell | e70656c | 2016-06-09 13:24:54 +0100 | [diff] [blame] | 788 | |
| 789 | if (session != NULL) { |
| 790 | SSL_SESSION_up_ref(session); |
| 791 | s->verify_result = session->verify_result; |
| 792 | } |
| 793 | SSL_SESSION_free(s->session); |
| 794 | s->session = session; |
| 795 | |
| 796 | return 1; |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 797 | } |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 798 | |
Remi Gacogne | fddfc0a | 2016-08-06 12:54:29 +0200 | [diff] [blame] | 799 | int SSL_SESSION_set1_id(SSL_SESSION *s, const unsigned char *sid, |
| 800 | unsigned int sid_len) |
| 801 | { |
| 802 | if (sid_len > SSL_MAX_SSL_SESSION_ID_LENGTH) { |
| 803 | SSLerr(SSL_F_SSL_SESSION_SET1_ID, |
| 804 | SSL_R_SSL_SESSION_ID_TOO_LONG); |
| 805 | return 0; |
| 806 | } |
| 807 | s->session_id_length = sid_len; |
| 808 | memcpy(s->session_id, sid, sid_len); |
| 809 | return 1; |
| 810 | } |
| 811 | |
Ulf Möller | 6b691a5 | 1999-04-19 21:31:43 +0000 | [diff] [blame] | 812 | long SSL_SESSION_set_timeout(SSL_SESSION *s, long t) |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 813 | { |
| 814 | if (s == NULL) |
| 815 | return (0); |
| 816 | s->timeout = t; |
| 817 | return (1); |
| 818 | } |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 819 | |
Ben Laurie | 0821bcd | 2005-03-30 10:26:02 +0000 | [diff] [blame] | 820 | long SSL_SESSION_get_timeout(const SSL_SESSION *s) |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 821 | { |
| 822 | if (s == NULL) |
| 823 | return (0); |
| 824 | return (s->timeout); |
| 825 | } |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 826 | |
Ben Laurie | 0821bcd | 2005-03-30 10:26:02 +0000 | [diff] [blame] | 827 | long SSL_SESSION_get_time(const SSL_SESSION *s) |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 828 | { |
| 829 | if (s == NULL) |
| 830 | return (0); |
| 831 | return (s->time); |
| 832 | } |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 833 | |
Ulf Möller | 6b691a5 | 1999-04-19 21:31:43 +0000 | [diff] [blame] | 834 | long SSL_SESSION_set_time(SSL_SESSION *s, long t) |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 835 | { |
| 836 | if (s == NULL) |
| 837 | return (0); |
| 838 | s->time = t; |
| 839 | return (t); |
| 840 | } |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 841 | |
TJ Saunders | bd01f64 | 2016-05-26 15:40:13 -0700 | [diff] [blame] | 842 | int SSL_SESSION_get_protocol_version(const SSL_SESSION *s) |
| 843 | { |
TJ Saunders | bd01f64 | 2016-05-26 15:40:13 -0700 | [diff] [blame] | 844 | return s->ssl_version; |
| 845 | } |
| 846 | |
Rich Salz | e928132 | 2016-08-12 15:02:00 -0400 | [diff] [blame] | 847 | const SSL_CIPHER *SSL_SESSION_get0_cipher(const SSL_SESSION *s) |
| 848 | { |
| 849 | return s->cipher; |
| 850 | } |
| 851 | |
Lyon Chen | 4b6b848 | 2016-04-11 10:08:00 -0400 | [diff] [blame] | 852 | const char *SSL_SESSION_get0_hostname(const SSL_SESSION *s) |
| 853 | { |
| 854 | return s->tlsext_hostname; |
| 855 | } |
| 856 | |
Matt Caswell | f2baac2 | 2015-02-08 15:43:16 +0000 | [diff] [blame] | 857 | int SSL_SESSION_has_ticket(const SSL_SESSION *s) |
| 858 | { |
| 859 | return (s->tlsext_ticklen > 0) ? 1 : 0; |
| 860 | } |
| 861 | |
| 862 | unsigned long SSL_SESSION_get_ticket_lifetime_hint(const SSL_SESSION *s) |
| 863 | { |
| 864 | return s->tlsext_tick_lifetime_hint; |
| 865 | } |
| 866 | |
Matt Caswell | 48593cb | 2016-08-13 14:29:41 +0100 | [diff] [blame] | 867 | void SSL_SESSION_get0_ticket(const SSL_SESSION *s, const unsigned char **tick, |
Emilia Kasper | a230b26 | 2016-08-05 19:03:17 +0200 | [diff] [blame] | 868 | size_t *len) |
Matt Caswell | b7c9187 | 2015-02-08 23:37:54 +0000 | [diff] [blame] | 869 | { |
| 870 | *len = s->tlsext_ticklen; |
Viktor Dukhovni | 61986d3 | 2015-04-16 01:50:03 -0400 | [diff] [blame] | 871 | if (tick != NULL) |
Matt Caswell | b7c9187 | 2015-02-08 23:37:54 +0000 | [diff] [blame] | 872 | *tick = s->tlsext_tick; |
| 873 | } |
| 874 | |
Dr. Stephen Henson | 08557cf | 2011-04-29 22:37:12 +0000 | [diff] [blame] | 875 | X509 *SSL_SESSION_get0_peer(SSL_SESSION *s) |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 876 | { |
| 877 | return s->peer; |
| 878 | } |
Dr. Stephen Henson | 08557cf | 2011-04-29 22:37:12 +0000 | [diff] [blame] | 879 | |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 880 | int SSL_SESSION_set1_id_context(SSL_SESSION *s, const unsigned char *sid_ctx, |
| 881 | unsigned int sid_ctx_len) |
| 882 | { |
| 883 | if (sid_ctx_len > SSL_MAX_SID_CTX_LENGTH) { |
| 884 | SSLerr(SSL_F_SSL_SESSION_SET1_ID_CONTEXT, |
| 885 | SSL_R_SSL_SESSION_ID_CONTEXT_TOO_LONG); |
| 886 | return 0; |
| 887 | } |
| 888 | s->sid_ctx_length = sid_ctx_len; |
| 889 | memcpy(s->sid_ctx, sid_ctx, sid_ctx_len); |
Dr. Stephen Henson | 08557cf | 2011-04-29 22:37:12 +0000 | [diff] [blame] | 890 | |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 891 | return 1; |
| 892 | } |
Dr. Stephen Henson | 08557cf | 2011-04-29 22:37:12 +0000 | [diff] [blame] | 893 | |
Ulf Möller | 6b691a5 | 1999-04-19 21:31:43 +0000 | [diff] [blame] | 894 | long SSL_CTX_set_timeout(SSL_CTX *s, long t) |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 895 | { |
| 896 | long l; |
| 897 | if (s == NULL) |
| 898 | return (0); |
| 899 | l = s->session_timeout; |
| 900 | s->session_timeout = t; |
| 901 | return (l); |
| 902 | } |
Mark J. Cox | 413c4f4 | 1999-02-16 09:22:21 +0000 | [diff] [blame] | 903 | |
Ben Laurie | 0821bcd | 2005-03-30 10:26:02 +0000 | [diff] [blame] | 904 | long SSL_CTX_get_timeout(const SSL_CTX *s) |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 905 | { |
| 906 | if (s == NULL) |
| 907 | return (0); |
| 908 | return (s->session_timeout); |
| 909 | } |
Mark J. Cox | 413c4f4 | 1999-02-16 09:22:21 +0000 | [diff] [blame] | 910 | |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 911 | int SSL_set_session_secret_cb(SSL *s, |
| 912 | int (*tls_session_secret_cb) (SSL *s, |
| 913 | void *secret, |
| 914 | int *secret_len, |
| 915 | STACK_OF(SSL_CIPHER) |
| 916 | *peer_ciphers, |
Dr. Stephen Henson | 4a640fb | 2015-12-23 00:47:28 +0000 | [diff] [blame] | 917 | const SSL_CIPHER |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 918 | **cipher, |
| 919 | void *arg), |
| 920 | void *arg) |
| 921 | { |
| 922 | if (s == NULL) |
| 923 | return (0); |
| 924 | s->tls_session_secret_cb = tls_session_secret_cb; |
| 925 | s->tls_session_secret_cb_arg = arg; |
| 926 | return (1); |
| 927 | } |
Dr. Stephen Henson | 12bf56c | 2008-11-15 17:18:12 +0000 | [diff] [blame] | 928 | |
| 929 | int SSL_set_session_ticket_ext_cb(SSL *s, tls_session_ticket_ext_cb_fn cb, |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 930 | void *arg) |
| 931 | { |
| 932 | if (s == NULL) |
| 933 | return (0); |
| 934 | s->tls_session_ticket_ext_cb = cb; |
| 935 | s->tls_session_ticket_ext_cb_arg = arg; |
| 936 | return (1); |
| 937 | } |
Dr. Stephen Henson | 12bf56c | 2008-11-15 17:18:12 +0000 | [diff] [blame] | 938 | |
| 939 | int SSL_set_session_ticket_ext(SSL *s, void *ext_data, int ext_len) |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 940 | { |
| 941 | if (s->version >= TLS1_VERSION) { |
Rich Salz | b548a1f | 2015-05-01 10:02:07 -0400 | [diff] [blame] | 942 | OPENSSL_free(s->tlsext_session_ticket); |
| 943 | s->tlsext_session_ticket = NULL; |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 944 | s->tlsext_session_ticket = |
| 945 | OPENSSL_malloc(sizeof(TLS_SESSION_TICKET_EXT) + ext_len); |
Matt Caswell | a71edf3 | 2015-10-30 10:05:53 +0000 | [diff] [blame] | 946 | if (s->tlsext_session_ticket == NULL) { |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 947 | SSLerr(SSL_F_SSL_SET_SESSION_TICKET_EXT, ERR_R_MALLOC_FAILURE); |
| 948 | return 0; |
| 949 | } |
Dr. Stephen Henson | 12bf56c | 2008-11-15 17:18:12 +0000 | [diff] [blame] | 950 | |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 951 | if (ext_data) { |
| 952 | s->tlsext_session_ticket->length = ext_len; |
| 953 | s->tlsext_session_ticket->data = s->tlsext_session_ticket + 1; |
| 954 | memcpy(s->tlsext_session_ticket->data, ext_data, ext_len); |
| 955 | } else { |
| 956 | s->tlsext_session_ticket->length = 0; |
| 957 | s->tlsext_session_ticket->data = NULL; |
| 958 | } |
Dr. Stephen Henson | 12bf56c | 2008-11-15 17:18:12 +0000 | [diff] [blame] | 959 | |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 960 | return 1; |
| 961 | } |
Dr. Stephen Henson | 12bf56c | 2008-11-15 17:18:12 +0000 | [diff] [blame] | 962 | |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 963 | return 0; |
| 964 | } |
Dr. Stephen Henson | 12bf56c | 2008-11-15 17:18:12 +0000 | [diff] [blame] | 965 | |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 966 | typedef struct timeout_param_st { |
| 967 | SSL_CTX *ctx; |
| 968 | long time; |
| 969 | LHASH_OF(SSL_SESSION) *cache; |
| 970 | } TIMEOUT_PARAM; |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 971 | |
Dr. Stephen Henson | 2a056de | 2015-12-24 16:20:54 +0000 | [diff] [blame] | 972 | static void timeout_cb(SSL_SESSION *s, TIMEOUT_PARAM *p) |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 973 | { |
| 974 | if ((p->time == 0) || (p->time > (s->time + s->timeout))) { /* timeout */ |
| 975 | /* |
| 976 | * The reason we don't call SSL_CTX_remove_session() is to save on |
| 977 | * locking overhead |
| 978 | */ |
| 979 | (void)lh_SSL_SESSION_delete(p->cache, s); |
| 980 | SSL_SESSION_list_remove(p->ctx, s); |
| 981 | s->not_resumable = 1; |
| 982 | if (p->ctx->remove_session_cb != NULL) |
| 983 | p->ctx->remove_session_cb(p->ctx, s); |
| 984 | SSL_SESSION_free(s); |
| 985 | } |
| 986 | } |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 987 | |
Dr. Stephen Henson | 2a056de | 2015-12-24 16:20:54 +0000 | [diff] [blame] | 988 | IMPLEMENT_LHASH_DOALL_ARG(SSL_SESSION, TIMEOUT_PARAM); |
Geoff Thorpe | 3c91484 | 2001-01-09 00:24:38 +0000 | [diff] [blame] | 989 | |
Ulf Möller | 6b691a5 | 1999-04-19 21:31:43 +0000 | [diff] [blame] | 990 | void SSL_CTX_flush_sessions(SSL_CTX *s, long t) |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 991 | { |
| 992 | unsigned long i; |
| 993 | TIMEOUT_PARAM tp; |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 994 | |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 995 | tp.ctx = s; |
| 996 | tp.cache = s->sessions; |
| 997 | if (tp.cache == NULL) |
| 998 | return; |
| 999 | tp.time = t; |
Alessandro Ghedini | 16203f7 | 2016-02-29 17:26:07 +0000 | [diff] [blame] | 1000 | CRYPTO_THREAD_write_lock(s->lock); |
Rich Salz | 739a1eb | 2016-05-20 10:46:29 -0400 | [diff] [blame] | 1001 | i = lh_SSL_SESSION_get_down_load(s->sessions); |
| 1002 | lh_SSL_SESSION_set_down_load(s->sessions, 0); |
Dr. Stephen Henson | 2a056de | 2015-12-24 16:20:54 +0000 | [diff] [blame] | 1003 | lh_SSL_SESSION_doall_TIMEOUT_PARAM(tp.cache, timeout_cb, &tp); |
Rich Salz | 739a1eb | 2016-05-20 10:46:29 -0400 | [diff] [blame] | 1004 | lh_SSL_SESSION_set_down_load(s->sessions, i); |
Alessandro Ghedini | 16203f7 | 2016-02-29 17:26:07 +0000 | [diff] [blame] | 1005 | CRYPTO_THREAD_unlock(s->lock); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 1006 | } |
Ralf S. Engelschall | d02b48c | 1998-12-21 10:52:47 +0000 | [diff] [blame] | 1007 | |
Ulf Möller | 6b691a5 | 1999-04-19 21:31:43 +0000 | [diff] [blame] | 1008 | int ssl_clear_bad_session(SSL *s) |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 1009 | { |
| 1010 | if ((s->session != NULL) && |
| 1011 | !(s->shutdown & SSL_SENT_SHUTDOWN) && |
| 1012 | !(SSL_in_init(s) || SSL_in_before(s))) { |
Todd Short | e2bb9b9 | 2016-05-26 13:49:36 -0400 | [diff] [blame] | 1013 | SSL_CTX_remove_session(s->session_ctx, s->session); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 1014 | return (1); |
| 1015 | } else |
| 1016 | return (0); |
| 1017 | } |
Ralf S. Engelschall | 58964a4 | 1998-12-21 10:56:39 +0000 | [diff] [blame] | 1018 | |
| 1019 | /* locked by SSL_CTX in the calling function */ |
Ulf Möller | 6b691a5 | 1999-04-19 21:31:43 +0000 | [diff] [blame] | 1020 | static void SSL_SESSION_list_remove(SSL_CTX *ctx, SSL_SESSION *s) |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 1021 | { |
| 1022 | if ((s->next == NULL) || (s->prev == NULL)) |
| 1023 | return; |
Ralf S. Engelschall | 58964a4 | 1998-12-21 10:56:39 +0000 | [diff] [blame] | 1024 | |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 1025 | if (s->next == (SSL_SESSION *)&(ctx->session_cache_tail)) { |
| 1026 | /* last element in list */ |
| 1027 | if (s->prev == (SSL_SESSION *)&(ctx->session_cache_head)) { |
| 1028 | /* only one element in list */ |
| 1029 | ctx->session_cache_head = NULL; |
| 1030 | ctx->session_cache_tail = NULL; |
| 1031 | } else { |
| 1032 | ctx->session_cache_tail = s->prev; |
| 1033 | s->prev->next = (SSL_SESSION *)&(ctx->session_cache_tail); |
| 1034 | } |
| 1035 | } else { |
| 1036 | if (s->prev == (SSL_SESSION *)&(ctx->session_cache_head)) { |
| 1037 | /* first element in list */ |
| 1038 | ctx->session_cache_head = s->next; |
| 1039 | s->next->prev = (SSL_SESSION *)&(ctx->session_cache_head); |
| 1040 | } else { |
| 1041 | /* middle of list */ |
| 1042 | s->next->prev = s->prev; |
| 1043 | s->prev->next = s->next; |
| 1044 | } |
| 1045 | } |
| 1046 | s->prev = s->next = NULL; |
| 1047 | } |
Ralf S. Engelschall | 58964a4 | 1998-12-21 10:56:39 +0000 | [diff] [blame] | 1048 | |
Ulf Möller | 6b691a5 | 1999-04-19 21:31:43 +0000 | [diff] [blame] | 1049 | static void SSL_SESSION_list_add(SSL_CTX *ctx, SSL_SESSION *s) |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 1050 | { |
| 1051 | if ((s->next != NULL) && (s->prev != NULL)) |
| 1052 | SSL_SESSION_list_remove(ctx, s); |
Ralf S. Engelschall | 58964a4 | 1998-12-21 10:56:39 +0000 | [diff] [blame] | 1053 | |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 1054 | if (ctx->session_cache_head == NULL) { |
| 1055 | ctx->session_cache_head = s; |
| 1056 | ctx->session_cache_tail = s; |
| 1057 | s->prev = (SSL_SESSION *)&(ctx->session_cache_head); |
| 1058 | s->next = (SSL_SESSION *)&(ctx->session_cache_tail); |
| 1059 | } else { |
| 1060 | s->next = ctx->session_cache_head; |
| 1061 | s->next->prev = s; |
| 1062 | s->prev = (SSL_SESSION *)&(ctx->session_cache_head); |
| 1063 | ctx->session_cache_head = s; |
| 1064 | } |
| 1065 | } |
Ralf S. Engelschall | 58964a4 | 1998-12-21 10:56:39 +0000 | [diff] [blame] | 1066 | |
Nils Larsch | 7806f3d | 2006-11-29 20:54:57 +0000 | [diff] [blame] | 1067 | void SSL_CTX_sess_set_new_cb(SSL_CTX *ctx, |
Emilia Kasper | a230b26 | 2016-08-05 19:03:17 +0200 | [diff] [blame] | 1068 | int (*cb) (struct ssl_st *ssl, SSL_SESSION *sess)) |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 1069 | { |
| 1070 | ctx->new_session_cb = cb; |
| 1071 | } |
Nils Larsch | 7806f3d | 2006-11-29 20:54:57 +0000 | [diff] [blame] | 1072 | |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 1073 | int (*SSL_CTX_sess_get_new_cb(SSL_CTX *ctx)) (SSL *ssl, SSL_SESSION *sess) { |
| 1074 | return ctx->new_session_cb; |
| 1075 | } |
Nils Larsch | 7806f3d | 2006-11-29 20:54:57 +0000 | [diff] [blame] | 1076 | |
| 1077 | void SSL_CTX_sess_set_remove_cb(SSL_CTX *ctx, |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 1078 | void (*cb) (SSL_CTX *ctx, SSL_SESSION *sess)) |
| 1079 | { |
| 1080 | ctx->remove_session_cb = cb; |
| 1081 | } |
Nils Larsch | 7806f3d | 2006-11-29 20:54:57 +0000 | [diff] [blame] | 1082 | |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 1083 | void (*SSL_CTX_sess_get_remove_cb(SSL_CTX *ctx)) (SSL_CTX *ctx, |
| 1084 | SSL_SESSION *sess) { |
| 1085 | return ctx->remove_session_cb; |
| 1086 | } |
Nils Larsch | 7806f3d | 2006-11-29 20:54:57 +0000 | [diff] [blame] | 1087 | |
| 1088 | void SSL_CTX_sess_set_get_cb(SSL_CTX *ctx, |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 1089 | SSL_SESSION *(*cb) (struct ssl_st *ssl, |
Emilia Kasper | b698174 | 2016-02-01 15:26:18 +0100 | [diff] [blame] | 1090 | const unsigned char *data, |
| 1091 | int len, int *copy)) |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 1092 | { |
| 1093 | ctx->get_session_cb = cb; |
| 1094 | } |
Nils Larsch | 7806f3d | 2006-11-29 20:54:57 +0000 | [diff] [blame] | 1095 | |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 1096 | SSL_SESSION *(*SSL_CTX_sess_get_get_cb(SSL_CTX *ctx)) (SSL *ssl, |
Emilia Kasper | a230b26 | 2016-08-05 19:03:17 +0200 | [diff] [blame] | 1097 | const unsigned char |
| 1098 | *data, int len, |
| 1099 | int *copy) { |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 1100 | return ctx->get_session_cb; |
| 1101 | } |
Nils Larsch | 7806f3d | 2006-11-29 20:54:57 +0000 | [diff] [blame] | 1102 | |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 1103 | void SSL_CTX_set_info_callback(SSL_CTX *ctx, |
| 1104 | void (*cb) (const SSL *ssl, int type, int val)) |
| 1105 | { |
| 1106 | ctx->info_callback = cb; |
| 1107 | } |
Nils Larsch | 7806f3d | 2006-11-29 20:54:57 +0000 | [diff] [blame] | 1108 | |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 1109 | void (*SSL_CTX_get_info_callback(SSL_CTX *ctx)) (const SSL *ssl, int type, |
| 1110 | int val) { |
| 1111 | return ctx->info_callback; |
| 1112 | } |
Nils Larsch | 7806f3d | 2006-11-29 20:54:57 +0000 | [diff] [blame] | 1113 | |
| 1114 | void SSL_CTX_set_client_cert_cb(SSL_CTX *ctx, |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 1115 | int (*cb) (SSL *ssl, X509 **x509, |
| 1116 | EVP_PKEY **pkey)) |
| 1117 | { |
| 1118 | ctx->client_cert_cb = cb; |
| 1119 | } |
Nils Larsch | 7806f3d | 2006-11-29 20:54:57 +0000 | [diff] [blame] | 1120 | |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 1121 | int (*SSL_CTX_get_client_cert_cb(SSL_CTX *ctx)) (SSL *ssl, X509 **x509, |
| 1122 | EVP_PKEY **pkey) { |
| 1123 | return ctx->client_cert_cb; |
| 1124 | } |
Nils Larsch | 7806f3d | 2006-11-29 20:54:57 +0000 | [diff] [blame] | 1125 | |
Dr. Stephen Henson | 368888b | 2008-06-01 22:33:24 +0000 | [diff] [blame] | 1126 | #ifndef OPENSSL_NO_ENGINE |
| 1127 | int SSL_CTX_set_client_cert_engine(SSL_CTX *ctx, ENGINE *e) |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 1128 | { |
| 1129 | if (!ENGINE_init(e)) { |
| 1130 | SSLerr(SSL_F_SSL_CTX_SET_CLIENT_CERT_ENGINE, ERR_R_ENGINE_LIB); |
| 1131 | return 0; |
| 1132 | } |
| 1133 | if (!ENGINE_get_ssl_client_cert_function(e)) { |
| 1134 | SSLerr(SSL_F_SSL_CTX_SET_CLIENT_CERT_ENGINE, |
| 1135 | SSL_R_NO_CLIENT_CERT_METHOD); |
| 1136 | ENGINE_finish(e); |
| 1137 | return 0; |
| 1138 | } |
| 1139 | ctx->client_cert_engine = e; |
| 1140 | return 1; |
| 1141 | } |
Dr. Stephen Henson | 368888b | 2008-06-01 22:33:24 +0000 | [diff] [blame] | 1142 | #endif |
| 1143 | |
Nils Larsch | 7806f3d | 2006-11-29 20:54:57 +0000 | [diff] [blame] | 1144 | void SSL_CTX_set_cookie_generate_cb(SSL_CTX *ctx, |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 1145 | int (*cb) (SSL *ssl, |
| 1146 | unsigned char *cookie, |
| 1147 | unsigned int *cookie_len)) |
| 1148 | { |
| 1149 | ctx->app_gen_cookie_cb = cb; |
| 1150 | } |
Nils Larsch | 7806f3d | 2006-11-29 20:54:57 +0000 | [diff] [blame] | 1151 | |
| 1152 | void SSL_CTX_set_cookie_verify_cb(SSL_CTX *ctx, |
Emilia Kasper | a230b26 | 2016-08-05 19:03:17 +0200 | [diff] [blame] | 1153 | int (*cb) (SSL *ssl, |
| 1154 | const unsigned char *cookie, |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 1155 | unsigned int cookie_len)) |
| 1156 | { |
| 1157 | ctx->app_verify_cookie_cb = cb; |
| 1158 | } |
Nils Larsch | 7806f3d | 2006-11-29 20:54:57 +0000 | [diff] [blame] | 1159 | |
Emilia Kasper | a230b26 | 2016-08-05 19:03:17 +0200 | [diff] [blame] | 1160 | IMPLEMENT_PEM_rw(SSL_SESSION, SSL_SESSION, PEM_STRING_SSL_SESSION, SSL_SESSION) |