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