VirtualBox

source: vbox/trunk/src/libs/openssl-3.0.9/ssl/ssl_sess.c@ 100755

Last change on this file since 100755 was 100487, checked in by vboxsync, 19 months ago

openssl-3.0.9: Applied and adjusted our OpenSSL changes we made to 3.0.7. bugref:10484

File size: 40.8 KB
Line 
1/*
2 * Copyright 1995-2023 The OpenSSL Project Authors. All Rights Reserved.
3 * Copyright 2005 Nokia. All rights reserved.
4 *
5 * Licensed under the Apache License 2.0 (the "License"). You may not use
6 * this file except in compliance with the License. You can obtain a copy
7 * in the file LICENSE in the source distribution or at
8 * https://www.openssl.org/source/license.html
9 */
10
11#if defined(__TANDEM) && defined(_SPT_MODEL_)
12# include <spthread.h>
13# include <spt_extensions.h> /* timeval */
14#endif
15#include <stdio.h>
16#include "e_os.h"
17#include <openssl/rand.h>
18#include <openssl/engine.h>
19#include "internal/refcount.h"
20#include "internal/cryptlib.h"
21#include "ssl_local.h"
22#include "statem/statem_local.h"
23
24static void SSL_SESSION_list_remove(SSL_CTX *ctx, SSL_SESSION *s);
25static void SSL_SESSION_list_add(SSL_CTX *ctx, SSL_SESSION *s);
26static int remove_session_lock(SSL_CTX *ctx, SSL_SESSION *c, int lck);
27
28DEFINE_STACK_OF(SSL_SESSION)
29
30__owur static int sess_timedout(time_t t, SSL_SESSION *ss)
31{
32 /* if timeout overflowed, it can never timeout! */
33 if (ss->timeout_ovf)
34 return 0;
35 return t > ss->calc_timeout;
36}
37
38/*
39 * Returns -1/0/+1 as other XXXcmp-type functions
40 * Takes overflow of calculated timeout into consideration
41 */
42__owur static int timeoutcmp(SSL_SESSION *a, SSL_SESSION *b)
43{
44 /* if only one overflowed, then it is greater */
45 if (a->timeout_ovf && !b->timeout_ovf)
46 return 1;
47 if (!a->timeout_ovf && b->timeout_ovf)
48 return -1;
49 /* No overflow, or both overflowed, so straight compare is safe */
50 if (a->calc_timeout < b->calc_timeout)
51 return -1;
52 if (a->calc_timeout > b->calc_timeout)
53 return 1;
54 return 0;
55}
56
57/*
58 * Calculates effective timeout, saving overflow state
59 * Locking must be done by the caller of this function
60 */
61void ssl_session_calculate_timeout(SSL_SESSION *ss)
62{
63 /* Force positive timeout */
64 if (ss->timeout < 0)
65 ss->timeout = 0;
66 ss->calc_timeout = ss->time + ss->timeout;
67 /*
68 * |timeout| is always zero or positive, so the check for
69 * overflow only needs to consider if |time| is positive
70 */
71 ss->timeout_ovf = ss->time > 0 && ss->calc_timeout < ss->time;
72 /*
73 * N.B. Realistic overflow can only occur in our lifetimes on a
74 * 32-bit machine in January 2038.
75 * However, There are no controls to limit the |timeout|
76 * value, except to keep it positive.
77 */
78}
79
80/*
81 * SSL_get_session() and SSL_get1_session() are problematic in TLS1.3 because,
82 * unlike in earlier protocol versions, the session ticket may not have been
83 * sent yet even though a handshake has finished. The session ticket data could
84 * come in sometime later...or even change if multiple session ticket messages
85 * are sent from the server. The preferred way for applications to obtain
86 * a resumable session is to use SSL_CTX_sess_set_new_cb().
87 */
88
89SSL_SESSION *SSL_get_session(const SSL *ssl)
90/* aka SSL_get0_session; gets 0 objects, just returns a copy of the pointer */
91{
92 return ssl->session;
93}
94
95SSL_SESSION *SSL_get1_session(SSL *ssl)
96/* variant of SSL_get_session: caller really gets something */
97{
98 SSL_SESSION *sess;
99 /*
100 * Need to lock this all up rather than just use CRYPTO_add so that
101 * somebody doesn't free ssl->session between when we check it's non-null
102 * and when we up the reference count.
103 */
104 if (!CRYPTO_THREAD_read_lock(ssl->lock))
105 return NULL;
106 sess = ssl->session;
107 if (sess)
108 SSL_SESSION_up_ref(sess);
109 CRYPTO_THREAD_unlock(ssl->lock);
110 return sess;
111}
112
113int SSL_SESSION_set_ex_data(SSL_SESSION *s, int idx, void *arg)
114{
115 return CRYPTO_set_ex_data(&s->ex_data, idx, arg);
116}
117
118void *SSL_SESSION_get_ex_data(const SSL_SESSION *s, int idx)
119{
120 return CRYPTO_get_ex_data(&s->ex_data, idx);
121}
122
123SSL_SESSION *SSL_SESSION_new(void)
124{
125 SSL_SESSION *ss;
126
127 if (!OPENSSL_init_ssl(OPENSSL_INIT_LOAD_SSL_STRINGS, NULL))
128 return NULL;
129
130 ss = OPENSSL_zalloc(sizeof(*ss));
131 if (ss == NULL) {
132 ERR_raise(ERR_LIB_SSL, ERR_R_MALLOC_FAILURE);
133 return NULL;
134 }
135
136 ss->verify_result = 1; /* avoid 0 (= X509_V_OK) just in case */
137 ss->references = 1;
138 ss->timeout = 60 * 5 + 4; /* 5 minute timeout by default */
139 ss->time = time(NULL);
140 ssl_session_calculate_timeout(ss);
141 ss->lock = CRYPTO_THREAD_lock_new();
142 if (ss->lock == NULL) {
143 ERR_raise(ERR_LIB_SSL, ERR_R_MALLOC_FAILURE);
144 OPENSSL_free(ss);
145 return NULL;
146 }
147
148 if (!CRYPTO_new_ex_data(CRYPTO_EX_INDEX_SSL_SESSION, ss, &ss->ex_data)) {
149 CRYPTO_THREAD_lock_free(ss->lock);
150 OPENSSL_free(ss);
151 return NULL;
152 }
153 return ss;
154}
155
156SSL_SESSION *SSL_SESSION_dup(const SSL_SESSION *src)
157{
158 return ssl_session_dup(src, 1);
159}
160
161/*
162 * Create a new SSL_SESSION and duplicate the contents of |src| into it. If
163 * ticket == 0 then no ticket information is duplicated, otherwise it is.
164 */
165SSL_SESSION *ssl_session_dup(const SSL_SESSION *src, int ticket)
166{
167 SSL_SESSION *dest;
168
169 dest = OPENSSL_malloc(sizeof(*dest));
170 if (dest == NULL) {
171 goto err;
172 }
173 memcpy(dest, src, sizeof(*dest));
174
175 /*
176 * Set the various pointers to NULL so that we can call SSL_SESSION_free in
177 * the case of an error whilst halfway through constructing dest
178 */
179#ifndef OPENSSL_NO_PSK
180 dest->psk_identity_hint = NULL;
181 dest->psk_identity = NULL;
182#endif
183 dest->ext.hostname = NULL;
184 dest->ext.tick = NULL;
185 dest->ext.alpn_selected = NULL;
186#ifndef OPENSSL_NO_SRP
187 dest->srp_username = NULL;
188#endif
189 dest->peer_chain = NULL;
190 dest->peer = NULL;
191 dest->ticket_appdata = NULL;
192 memset(&dest->ex_data, 0, sizeof(dest->ex_data));
193
194 /* As the copy is not in the cache, we remove the associated pointers */
195 dest->prev = NULL;
196 dest->next = NULL;
197 dest->owner = NULL;
198
199 dest->references = 1;
200
201 dest->lock = CRYPTO_THREAD_lock_new();
202 if (dest->lock == NULL)
203 goto err;
204
205 if (!CRYPTO_new_ex_data(CRYPTO_EX_INDEX_SSL_SESSION, dest, &dest->ex_data))
206 goto err;
207
208 if (src->peer != NULL) {
209 if (!X509_up_ref(src->peer))
210 goto err;
211 dest->peer = src->peer;
212 }
213
214 if (src->peer_chain != NULL) {
215 dest->peer_chain = X509_chain_up_ref(src->peer_chain);
216 if (dest->peer_chain == NULL)
217 goto err;
218 }
219#ifndef OPENSSL_NO_PSK
220 if (src->psk_identity_hint) {
221 dest->psk_identity_hint = OPENSSL_strdup(src->psk_identity_hint);
222 if (dest->psk_identity_hint == NULL) {
223 goto err;
224 }
225 }
226 if (src->psk_identity) {
227 dest->psk_identity = OPENSSL_strdup(src->psk_identity);
228 if (dest->psk_identity == NULL) {
229 goto err;
230 }
231 }
232#endif
233
234 if (!CRYPTO_dup_ex_data(CRYPTO_EX_INDEX_SSL_SESSION,
235 &dest->ex_data, &src->ex_data)) {
236 goto err;
237 }
238
239 if (src->ext.hostname) {
240 dest->ext.hostname = OPENSSL_strdup(src->ext.hostname);
241 if (dest->ext.hostname == NULL) {
242 goto err;
243 }
244 }
245
246 if (ticket != 0 && src->ext.tick != NULL) {
247 dest->ext.tick =
248 OPENSSL_memdup(src->ext.tick, src->ext.ticklen);
249 if (dest->ext.tick == NULL)
250 goto err;
251 } else {
252 dest->ext.tick_lifetime_hint = 0;
253 dest->ext.ticklen = 0;
254 }
255
256 if (src->ext.alpn_selected != NULL) {
257 dest->ext.alpn_selected = OPENSSL_memdup(src->ext.alpn_selected,
258 src->ext.alpn_selected_len);
259 if (dest->ext.alpn_selected == NULL)
260 goto err;
261 }
262
263#ifndef OPENSSL_NO_SRP
264 if (src->srp_username) {
265 dest->srp_username = OPENSSL_strdup(src->srp_username);
266 if (dest->srp_username == NULL) {
267 goto err;
268 }
269 }
270#endif
271
272 if (src->ticket_appdata != NULL) {
273 dest->ticket_appdata =
274 OPENSSL_memdup(src->ticket_appdata, src->ticket_appdata_len);
275 if (dest->ticket_appdata == NULL)
276 goto err;
277 }
278
279 return dest;
280 err:
281 ERR_raise(ERR_LIB_SSL, ERR_R_MALLOC_FAILURE);
282 SSL_SESSION_free(dest);
283 return NULL;
284}
285
286const unsigned char *SSL_SESSION_get_id(const SSL_SESSION *s, unsigned int *len)
287{
288 if (len)
289 *len = (unsigned int)s->session_id_length;
290 return s->session_id;
291}
292const unsigned char *SSL_SESSION_get0_id_context(const SSL_SESSION *s,
293 unsigned int *len)
294{
295 if (len != NULL)
296 *len = (unsigned int)s->sid_ctx_length;
297 return s->sid_ctx;
298}
299
300unsigned int SSL_SESSION_get_compress_id(const SSL_SESSION *s)
301{
302 return s->compress_meth;
303}
304
305/*
306 * SSLv3/TLSv1 has 32 bytes (256 bits) of session ID space. As such, filling
307 * the ID with random junk repeatedly until we have no conflict is going to
308 * complete in one iteration pretty much "most" of the time (btw:
309 * understatement). So, if it takes us 10 iterations and we still can't avoid
310 * a conflict - well that's a reasonable point to call it quits. Either the
311 * RAND code is broken or someone is trying to open roughly very close to
312 * 2^256 SSL sessions to our server. How you might store that many sessions
313 * is perhaps a more interesting question ...
314 */
315
316#define MAX_SESS_ID_ATTEMPTS 10
317static int def_generate_session_id(SSL *ssl, unsigned char *id,
318 unsigned int *id_len)
319{
320 unsigned int retry = 0;
321 do
322 if (RAND_bytes_ex(ssl->ctx->libctx, id, *id_len, 0) <= 0)
323 return 0;
324 while (SSL_has_matching_session_id(ssl, id, *id_len) &&
325 (++retry < MAX_SESS_ID_ATTEMPTS)) ;
326 if (retry < MAX_SESS_ID_ATTEMPTS)
327 return 1;
328 /* else - woops a session_id match */
329 /*
330 * XXX We should also check the external cache -- but the probability of
331 * a collision is negligible, and we could not prevent the concurrent
332 * creation of sessions with identical IDs since we currently don't have
333 * means to atomically check whether a session ID already exists and make
334 * a reservation for it if it does not (this problem applies to the
335 * internal cache as well).
336 */
337 return 0;
338}
339
340int ssl_generate_session_id(SSL *s, SSL_SESSION *ss)
341{
342 unsigned int tmp;
343 GEN_SESSION_CB cb = def_generate_session_id;
344
345 switch (s->version) {
346 case SSL3_VERSION:
347 case TLS1_VERSION:
348 case TLS1_1_VERSION:
349 case TLS1_2_VERSION:
350 case TLS1_3_VERSION:
351 case DTLS1_BAD_VER:
352 case DTLS1_VERSION:
353 case DTLS1_2_VERSION:
354 ss->session_id_length = SSL3_SSL_SESSION_ID_LENGTH;
355 break;
356 default:
357 SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_R_UNSUPPORTED_SSL_VERSION);
358 return 0;
359 }
360
361 /*-
362 * If RFC5077 ticket, use empty session ID (as server).
363 * Note that:
364 * (a) ssl_get_prev_session() does lookahead into the
365 * ClientHello extensions to find the session ticket.
366 * When ssl_get_prev_session() fails, statem_srvr.c calls
367 * ssl_get_new_session() in tls_process_client_hello().
368 * At that point, it has not yet parsed the extensions,
369 * however, because of the lookahead, it already knows
370 * whether a ticket is expected or not.
371 *
372 * (b) statem_clnt.c calls ssl_get_new_session() before parsing
373 * ServerHello extensions, and before recording the session
374 * ID received from the server, so this block is a noop.
375 */
376 if (s->ext.ticket_expected) {
377 ss->session_id_length = 0;
378 return 1;
379 }
380
381 /* Choose which callback will set the session ID */
382 if (!CRYPTO_THREAD_read_lock(s->lock))
383 return 0;
384 if (!CRYPTO_THREAD_read_lock(s->session_ctx->lock)) {
385 CRYPTO_THREAD_unlock(s->lock);
386 SSLfatal(s, SSL_AD_INTERNAL_ERROR,
387 SSL_R_SESSION_ID_CONTEXT_UNINITIALIZED);
388 return 0;
389 }
390 if (s->generate_session_id)
391 cb = s->generate_session_id;
392 else if (s->session_ctx->generate_session_id)
393 cb = s->session_ctx->generate_session_id;
394 CRYPTO_THREAD_unlock(s->session_ctx->lock);
395 CRYPTO_THREAD_unlock(s->lock);
396 /* Choose a session ID */
397 memset(ss->session_id, 0, ss->session_id_length);
398 tmp = (int)ss->session_id_length;
399 if (!cb(s, ss->session_id, &tmp)) {
400 /* The callback failed */
401 SSLfatal(s, SSL_AD_INTERNAL_ERROR,
402 SSL_R_SSL_SESSION_ID_CALLBACK_FAILED);
403 return 0;
404 }
405 /*
406 * Don't allow the callback to set the session length to zero. nor
407 * set it higher than it was.
408 */
409 if (tmp == 0 || tmp > ss->session_id_length) {
410 /* The callback set an illegal length */
411 SSLfatal(s, SSL_AD_INTERNAL_ERROR,
412 SSL_R_SSL_SESSION_ID_HAS_BAD_LENGTH);
413 return 0;
414 }
415 ss->session_id_length = tmp;
416 /* Finally, check for a conflict */
417 if (SSL_has_matching_session_id(s, ss->session_id,
418 (unsigned int)ss->session_id_length)) {
419 SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_R_SSL_SESSION_ID_CONFLICT);
420 return 0;
421 }
422
423 return 1;
424}
425
426int ssl_get_new_session(SSL *s, int session)
427{
428 /* This gets used by clients and servers. */
429
430 SSL_SESSION *ss = NULL;
431
432 if ((ss = SSL_SESSION_new()) == NULL) {
433 SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_MALLOC_FAILURE);
434 return 0;
435 }
436
437 /* If the context has a default timeout, use it */
438 if (s->session_ctx->session_timeout == 0)
439 ss->timeout = SSL_get_default_timeout(s);
440 else
441 ss->timeout = s->session_ctx->session_timeout;
442 ssl_session_calculate_timeout(ss);
443
444 SSL_SESSION_free(s->session);
445 s->session = NULL;
446
447 if (session) {
448 if (SSL_IS_TLS13(s)) {
449 /*
450 * We generate the session id while constructing the
451 * NewSessionTicket in TLSv1.3.
452 */
453 ss->session_id_length = 0;
454 } else if (!ssl_generate_session_id(s, ss)) {
455 /* SSLfatal() already called */
456 SSL_SESSION_free(ss);
457 return 0;
458 }
459
460 } else {
461 ss->session_id_length = 0;
462 }
463
464 if (s->sid_ctx_length > sizeof(ss->sid_ctx)) {
465 SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR);
466 SSL_SESSION_free(ss);
467 return 0;
468 }
469 memcpy(ss->sid_ctx, s->sid_ctx, s->sid_ctx_length);
470 ss->sid_ctx_length = s->sid_ctx_length;
471 s->session = ss;
472 ss->ssl_version = s->version;
473 ss->verify_result = X509_V_OK;
474
475 /* If client supports extended master secret set it in session */
476 if (s->s3.flags & TLS1_FLAGS_RECEIVED_EXTMS)
477 ss->flags |= SSL_SESS_FLAG_EXTMS;
478
479 return 1;
480}
481
482SSL_SESSION *lookup_sess_in_cache(SSL *s, const unsigned char *sess_id,
483 size_t sess_id_len)
484{
485 SSL_SESSION *ret = NULL;
486
487 if ((s->session_ctx->session_cache_mode
488 & SSL_SESS_CACHE_NO_INTERNAL_LOOKUP) == 0) {
489 SSL_SESSION data;
490
491 data.ssl_version = s->version;
492 if (!ossl_assert(sess_id_len <= SSL_MAX_SSL_SESSION_ID_LENGTH))
493 return NULL;
494
495 memcpy(data.session_id, sess_id, sess_id_len);
496 data.session_id_length = sess_id_len;
497
498 if (!CRYPTO_THREAD_read_lock(s->session_ctx->lock))
499 return NULL;
500 ret = lh_SSL_SESSION_retrieve(s->session_ctx->sessions, &data);
501 if (ret != NULL) {
502 /* don't allow other threads to steal it: */
503 SSL_SESSION_up_ref(ret);
504 }
505 CRYPTO_THREAD_unlock(s->session_ctx->lock);
506 if (ret == NULL)
507 ssl_tsan_counter(s->session_ctx, &s->session_ctx->stats.sess_miss);
508 }
509
510 if (ret == NULL && s->session_ctx->get_session_cb != NULL) {
511 int copy = 1;
512
513 ret = s->session_ctx->get_session_cb(s, sess_id, sess_id_len, &copy);
514
515 if (ret != NULL) {
516 ssl_tsan_counter(s->session_ctx,
517 &s->session_ctx->stats.sess_cb_hit);
518
519 /*
520 * Increment reference count now if the session callback asks us
521 * to do so (note that if the session structures returned by the
522 * callback are shared between threads, it must handle the
523 * reference count itself [i.e. copy == 0], or things won't be
524 * thread-safe).
525 */
526 if (copy)
527 SSL_SESSION_up_ref(ret);
528
529 /*
530 * Add the externally cached session to the internal cache as
531 * well if and only if we are supposed to.
532 */
533 if ((s->session_ctx->session_cache_mode &
534 SSL_SESS_CACHE_NO_INTERNAL_STORE) == 0) {
535 /*
536 * Either return value of SSL_CTX_add_session should not
537 * interrupt the session resumption process. The return
538 * value is intentionally ignored.
539 */
540 (void)SSL_CTX_add_session(s->session_ctx, ret);
541 }
542 }
543 }
544
545 return ret;
546}
547
548/*-
549 * ssl_get_prev attempts to find an SSL_SESSION to be used to resume this
550 * connection. It is only called by servers.
551 *
552 * hello: The parsed ClientHello data
553 *
554 * Returns:
555 * -1: fatal error
556 * 0: no session found
557 * 1: a session may have been found.
558 *
559 * Side effects:
560 * - If a session is found then s->session is pointed at it (after freeing an
561 * existing session if need be) and s->verify_result is set from the session.
562 * - Both for new and resumed sessions, s->ext.ticket_expected is set to 1
563 * if the server should issue a new session ticket (to 0 otherwise).
564 */
565int ssl_get_prev_session(SSL *s, CLIENTHELLO_MSG *hello)
566{
567 /* This is used only by servers. */
568
569 SSL_SESSION *ret = NULL;
570 int fatal = 0;
571 int try_session_cache = 0;
572 SSL_TICKET_STATUS r;
573
574 if (SSL_IS_TLS13(s)) {
575 /*
576 * By default we will send a new ticket. This can be overridden in the
577 * ticket processing.
578 */
579 s->ext.ticket_expected = 1;
580 if (!tls_parse_extension(s, TLSEXT_IDX_psk_kex_modes,
581 SSL_EXT_CLIENT_HELLO, hello->pre_proc_exts,
582 NULL, 0)
583 || !tls_parse_extension(s, TLSEXT_IDX_psk, SSL_EXT_CLIENT_HELLO,
584 hello->pre_proc_exts, NULL, 0))
585 return -1;
586
587 ret = s->session;
588 } else {
589 /* sets s->ext.ticket_expected */
590 r = tls_get_ticket_from_client(s, hello, &ret);
591 switch (r) {
592 case SSL_TICKET_FATAL_ERR_MALLOC:
593 case SSL_TICKET_FATAL_ERR_OTHER:
594 fatal = 1;
595 SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR);
596 goto err;
597 case SSL_TICKET_NONE:
598 case SSL_TICKET_EMPTY:
599 if (hello->session_id_len > 0) {
600 try_session_cache = 1;
601 ret = lookup_sess_in_cache(s, hello->session_id,
602 hello->session_id_len);
603 }
604 break;
605 case SSL_TICKET_NO_DECRYPT:
606 case SSL_TICKET_SUCCESS:
607 case SSL_TICKET_SUCCESS_RENEW:
608 break;
609 }
610 }
611
612 if (ret == NULL)
613 goto err;
614
615 /* Now ret is non-NULL and we own one of its reference counts. */
616
617 /* Check TLS version consistency */
618 if (ret->ssl_version != s->version)
619 goto err;
620
621 if (ret->sid_ctx_length != s->sid_ctx_length
622 || memcmp(ret->sid_ctx, s->sid_ctx, ret->sid_ctx_length)) {
623 /*
624 * We have the session requested by the client, but we don't want to
625 * use it in this context.
626 */
627 goto err; /* treat like cache miss */
628 }
629
630 if ((s->verify_mode & SSL_VERIFY_PEER) && s->sid_ctx_length == 0) {
631 /*
632 * We can't be sure if this session is being used out of context,
633 * which is especially important for SSL_VERIFY_PEER. The application
634 * should have used SSL[_CTX]_set_session_id_context. For this error
635 * case, we generate an error instead of treating the event like a
636 * cache miss (otherwise it would be easy for applications to
637 * effectively disable the session cache by accident without anyone
638 * noticing).
639 */
640
641 SSLfatal(s, SSL_AD_INTERNAL_ERROR,
642 SSL_R_SESSION_ID_CONTEXT_UNINITIALIZED);
643 fatal = 1;
644 goto err;
645 }
646
647 if (sess_timedout(time(NULL), ret)) {
648 ssl_tsan_counter(s->session_ctx, &s->session_ctx->stats.sess_timeout);
649 if (try_session_cache) {
650 /* session was from the cache, so remove it */
651 SSL_CTX_remove_session(s->session_ctx, ret);
652 }
653 goto err;
654 }
655
656 /* Check extended master secret extension consistency */
657 if (ret->flags & SSL_SESS_FLAG_EXTMS) {
658 /* If old session includes extms, but new does not: abort handshake */
659 if (!(s->s3.flags & TLS1_FLAGS_RECEIVED_EXTMS)) {
660 SSLfatal(s, SSL_AD_ILLEGAL_PARAMETER, SSL_R_INCONSISTENT_EXTMS);
661 fatal = 1;
662 goto err;
663 }
664 } else if (s->s3.flags & TLS1_FLAGS_RECEIVED_EXTMS) {
665 /* If new session includes extms, but old does not: do not resume */
666 goto err;
667 }
668
669 if (!SSL_IS_TLS13(s)) {
670 /* We already did this for TLS1.3 */
671 SSL_SESSION_free(s->session);
672 s->session = ret;
673 }
674
675 ssl_tsan_counter(s->session_ctx, &s->session_ctx->stats.sess_hit);
676 s->verify_result = s->session->verify_result;
677 return 1;
678
679 err:
680 if (ret != NULL) {
681 SSL_SESSION_free(ret);
682 /* In TLSv1.3 s->session was already set to ret, so we NULL it out */
683 if (SSL_IS_TLS13(s))
684 s->session = NULL;
685
686 if (!try_session_cache) {
687 /*
688 * The session was from a ticket, so we should issue a ticket for
689 * the new session
690 */
691 s->ext.ticket_expected = 1;
692 }
693 }
694 if (fatal)
695 return -1;
696
697 return 0;
698}
699
700int SSL_CTX_add_session(SSL_CTX *ctx, SSL_SESSION *c)
701{
702 int ret = 0;
703 SSL_SESSION *s;
704
705 /*
706 * add just 1 reference count for the SSL_CTX's session cache even though
707 * it has two ways of access: each session is in a doubly linked list and
708 * an lhash
709 */
710 SSL_SESSION_up_ref(c);
711 /*
712 * if session c is in already in cache, we take back the increment later
713 */
714
715 if (!CRYPTO_THREAD_write_lock(ctx->lock)) {
716 SSL_SESSION_free(c);
717 return 0;
718 }
719 s = lh_SSL_SESSION_insert(ctx->sessions, c);
720
721 /*
722 * s != NULL iff we already had a session with the given PID. In this
723 * case, s == c should hold (then we did not really modify
724 * ctx->sessions), or we're in trouble.
725 */
726 if (s != NULL && s != c) {
727 /* We *are* in trouble ... */
728 SSL_SESSION_list_remove(ctx, s);
729 SSL_SESSION_free(s);
730 /*
731 * ... so pretend the other session did not exist in cache (we cannot
732 * handle two SSL_SESSION structures with identical session ID in the
733 * same cache, which could happen e.g. when two threads concurrently
734 * obtain the same session from an external cache)
735 */
736 s = NULL;
737 } else if (s == NULL &&
738 lh_SSL_SESSION_retrieve(ctx->sessions, c) == NULL) {
739 /* s == NULL can also mean OOM error in lh_SSL_SESSION_insert ... */
740
741 /*
742 * ... so take back the extra reference and also don't add
743 * the session to the SSL_SESSION_list at this time
744 */
745 s = c;
746 }
747
748 /* Adjust last used time, and add back into the cache at the appropriate spot */
749 if (ctx->session_cache_mode & SSL_SESS_CACHE_UPDATE_TIME) {
750 c->time = time(NULL);
751 ssl_session_calculate_timeout(c);
752 }
753
754 if (s == NULL) {
755 /*
756 * new cache entry -- remove old ones if cache has become too large
757 * delete cache entry *before* add, so we don't remove the one we're adding!
758 */
759
760 ret = 1;
761
762 if (SSL_CTX_sess_get_cache_size(ctx) > 0) {
763 while (SSL_CTX_sess_number(ctx) >= SSL_CTX_sess_get_cache_size(ctx)) {
764 if (!remove_session_lock(ctx, ctx->session_cache_tail, 0))
765 break;
766 else
767 ssl_tsan_counter(ctx, &ctx->stats.sess_cache_full);
768 }
769 }
770 }
771
772 SSL_SESSION_list_add(ctx, c);
773
774 if (s != NULL) {
775 /*
776 * existing cache entry -- decrement previously incremented reference
777 * count because it already takes into account the cache
778 */
779
780 SSL_SESSION_free(s); /* s == c */
781 ret = 0;
782 }
783 CRYPTO_THREAD_unlock(ctx->lock);
784 return ret;
785}
786
787int SSL_CTX_remove_session(SSL_CTX *ctx, SSL_SESSION *c)
788{
789 return remove_session_lock(ctx, c, 1);
790}
791
792static int remove_session_lock(SSL_CTX *ctx, SSL_SESSION *c, int lck)
793{
794 SSL_SESSION *r;
795 int ret = 0;
796
797 if ((c != NULL) && (c->session_id_length != 0)) {
798 if (lck) {
799 if (!CRYPTO_THREAD_write_lock(ctx->lock))
800 return 0;
801 }
802 if ((r = lh_SSL_SESSION_retrieve(ctx->sessions, c)) != NULL) {
803 ret = 1;
804 r = lh_SSL_SESSION_delete(ctx->sessions, r);
805 SSL_SESSION_list_remove(ctx, r);
806 }
807 c->not_resumable = 1;
808
809 if (lck)
810 CRYPTO_THREAD_unlock(ctx->lock);
811
812 if (ctx->remove_session_cb != NULL)
813 ctx->remove_session_cb(ctx, c);
814
815 if (ret)
816 SSL_SESSION_free(r);
817 }
818 return ret;
819}
820
821void SSL_SESSION_free(SSL_SESSION *ss)
822{
823 int i;
824
825 if (ss == NULL)
826 return;
827 CRYPTO_DOWN_REF(&ss->references, &i, ss->lock);
828 REF_PRINT_COUNT("SSL_SESSION", ss);
829 if (i > 0)
830 return;
831 REF_ASSERT_ISNT(i < 0);
832
833 CRYPTO_free_ex_data(CRYPTO_EX_INDEX_SSL_SESSION, ss, &ss->ex_data);
834
835 OPENSSL_cleanse(ss->master_key, sizeof(ss->master_key));
836 OPENSSL_cleanse(ss->session_id, sizeof(ss->session_id));
837 X509_free(ss->peer);
838 sk_X509_pop_free(ss->peer_chain, X509_free);
839 OPENSSL_free(ss->ext.hostname);
840 OPENSSL_free(ss->ext.tick);
841#ifndef OPENSSL_NO_PSK
842 OPENSSL_free(ss->psk_identity_hint);
843 OPENSSL_free(ss->psk_identity);
844#endif
845#ifndef OPENSSL_NO_SRP
846 OPENSSL_free(ss->srp_username);
847#endif
848 OPENSSL_free(ss->ext.alpn_selected);
849 OPENSSL_free(ss->ticket_appdata);
850 CRYPTO_THREAD_lock_free(ss->lock);
851 OPENSSL_clear_free(ss, sizeof(*ss));
852}
853
854int SSL_SESSION_up_ref(SSL_SESSION *ss)
855{
856 int i;
857
858 if (CRYPTO_UP_REF(&ss->references, &i, ss->lock) <= 0)
859 return 0;
860
861 REF_PRINT_COUNT("SSL_SESSION", ss);
862 REF_ASSERT_ISNT(i < 2);
863 return ((i > 1) ? 1 : 0);
864}
865
866int SSL_set_session(SSL *s, SSL_SESSION *session)
867{
868 ssl_clear_bad_session(s);
869 if (s->ctx->method != s->method) {
870 if (!SSL_set_ssl_method(s, s->ctx->method))
871 return 0;
872 }
873
874 if (session != NULL) {
875 SSL_SESSION_up_ref(session);
876 s->verify_result = session->verify_result;
877 }
878 SSL_SESSION_free(s->session);
879 s->session = session;
880
881 return 1;
882}
883
884int SSL_SESSION_set1_id(SSL_SESSION *s, const unsigned char *sid,
885 unsigned int sid_len)
886{
887 if (sid_len > SSL_MAX_SSL_SESSION_ID_LENGTH) {
888 ERR_raise(ERR_LIB_SSL, SSL_R_SSL_SESSION_ID_TOO_LONG);
889 return 0;
890 }
891 s->session_id_length = sid_len;
892 if (sid != s->session_id)
893 memcpy(s->session_id, sid, sid_len);
894 return 1;
895}
896
897long SSL_SESSION_set_timeout(SSL_SESSION *s, long t)
898{
899 time_t new_timeout = (time_t)t;
900
901 if (s == NULL || t < 0)
902 return 0;
903 if (s->owner != NULL) {
904 if (!CRYPTO_THREAD_write_lock(s->owner->lock))
905 return 0;
906 s->timeout = new_timeout;
907 ssl_session_calculate_timeout(s);
908 SSL_SESSION_list_add(s->owner, s);
909 CRYPTO_THREAD_unlock(s->owner->lock);
910 } else {
911 s->timeout = new_timeout;
912 ssl_session_calculate_timeout(s);
913 }
914 return 1;
915}
916
917long SSL_SESSION_get_timeout(const SSL_SESSION *s)
918{
919 if (s == NULL)
920 return 0;
921 return (long)s->timeout;
922}
923
924long SSL_SESSION_get_time(const SSL_SESSION *s)
925{
926 if (s == NULL)
927 return 0;
928 return (long)s->time;
929}
930
931long SSL_SESSION_set_time(SSL_SESSION *s, long t)
932{
933 time_t new_time = (time_t)t;
934
935 if (s == NULL)
936 return 0;
937 if (s->owner != NULL) {
938 if (!CRYPTO_THREAD_write_lock(s->owner->lock))
939 return 0;
940 s->time = new_time;
941 ssl_session_calculate_timeout(s);
942 SSL_SESSION_list_add(s->owner, s);
943 CRYPTO_THREAD_unlock(s->owner->lock);
944 } else {
945 s->time = new_time;
946 ssl_session_calculate_timeout(s);
947 }
948 return t;
949}
950
951int SSL_SESSION_get_protocol_version(const SSL_SESSION *s)
952{
953 return s->ssl_version;
954}
955
956int SSL_SESSION_set_protocol_version(SSL_SESSION *s, int version)
957{
958 s->ssl_version = version;
959 return 1;
960}
961
962const SSL_CIPHER *SSL_SESSION_get0_cipher(const SSL_SESSION *s)
963{
964 return s->cipher;
965}
966
967int SSL_SESSION_set_cipher(SSL_SESSION *s, const SSL_CIPHER *cipher)
968{
969 s->cipher = cipher;
970 return 1;
971}
972
973const char *SSL_SESSION_get0_hostname(const SSL_SESSION *s)
974{
975 return s->ext.hostname;
976}
977
978int SSL_SESSION_set1_hostname(SSL_SESSION *s, const char *hostname)
979{
980 OPENSSL_free(s->ext.hostname);
981 if (hostname == NULL) {
982 s->ext.hostname = NULL;
983 return 1;
984 }
985 s->ext.hostname = OPENSSL_strdup(hostname);
986
987 return s->ext.hostname != NULL;
988}
989
990int SSL_SESSION_has_ticket(const SSL_SESSION *s)
991{
992 return (s->ext.ticklen > 0) ? 1 : 0;
993}
994
995unsigned long SSL_SESSION_get_ticket_lifetime_hint(const SSL_SESSION *s)
996{
997 return s->ext.tick_lifetime_hint;
998}
999
1000void SSL_SESSION_get0_ticket(const SSL_SESSION *s, const unsigned char **tick,
1001 size_t *len)
1002{
1003 *len = s->ext.ticklen;
1004 if (tick != NULL)
1005 *tick = s->ext.tick;
1006}
1007
1008uint32_t SSL_SESSION_get_max_early_data(const SSL_SESSION *s)
1009{
1010 return s->ext.max_early_data;
1011}
1012
1013int SSL_SESSION_set_max_early_data(SSL_SESSION *s, uint32_t max_early_data)
1014{
1015 s->ext.max_early_data = max_early_data;
1016
1017 return 1;
1018}
1019
1020void SSL_SESSION_get0_alpn_selected(const SSL_SESSION *s,
1021 const unsigned char **alpn,
1022 size_t *len)
1023{
1024 *alpn = s->ext.alpn_selected;
1025 *len = s->ext.alpn_selected_len;
1026}
1027
1028int SSL_SESSION_set1_alpn_selected(SSL_SESSION *s, const unsigned char *alpn,
1029 size_t len)
1030{
1031 OPENSSL_free(s->ext.alpn_selected);
1032 if (alpn == NULL || len == 0) {
1033 s->ext.alpn_selected = NULL;
1034 s->ext.alpn_selected_len = 0;
1035 return 1;
1036 }
1037 s->ext.alpn_selected = OPENSSL_memdup(alpn, len);
1038 if (s->ext.alpn_selected == NULL) {
1039 s->ext.alpn_selected_len = 0;
1040 return 0;
1041 }
1042 s->ext.alpn_selected_len = len;
1043
1044 return 1;
1045}
1046
1047X509 *SSL_SESSION_get0_peer(SSL_SESSION *s)
1048{
1049 return s->peer;
1050}
1051
1052int SSL_SESSION_set1_id_context(SSL_SESSION *s, const unsigned char *sid_ctx,
1053 unsigned int sid_ctx_len)
1054{
1055 if (sid_ctx_len > SSL_MAX_SID_CTX_LENGTH) {
1056 ERR_raise(ERR_LIB_SSL, SSL_R_SSL_SESSION_ID_CONTEXT_TOO_LONG);
1057 return 0;
1058 }
1059 s->sid_ctx_length = sid_ctx_len;
1060 if (sid_ctx != s->sid_ctx)
1061 memcpy(s->sid_ctx, sid_ctx, sid_ctx_len);
1062
1063 return 1;
1064}
1065
1066int SSL_SESSION_is_resumable(const SSL_SESSION *s)
1067{
1068 /*
1069 * In the case of EAP-FAST, we can have a pre-shared "ticket" without a
1070 * session ID.
1071 */
1072 return !s->not_resumable
1073 && (s->session_id_length > 0 || s->ext.ticklen > 0);
1074}
1075
1076long SSL_CTX_set_timeout(SSL_CTX *s, long t)
1077{
1078 long l;
1079 if (s == NULL)
1080 return 0;
1081 l = s->session_timeout;
1082 s->session_timeout = t;
1083 return l;
1084}
1085
1086long SSL_CTX_get_timeout(const SSL_CTX *s)
1087{
1088 if (s == NULL)
1089 return 0;
1090 return s->session_timeout;
1091}
1092
1093int SSL_set_session_secret_cb(SSL *s,
1094 tls_session_secret_cb_fn tls_session_secret_cb,
1095 void *arg)
1096{
1097 if (s == NULL)
1098 return 0;
1099 s->ext.session_secret_cb = tls_session_secret_cb;
1100 s->ext.session_secret_cb_arg = arg;
1101 return 1;
1102}
1103
1104int SSL_set_session_ticket_ext_cb(SSL *s, tls_session_ticket_ext_cb_fn cb,
1105 void *arg)
1106{
1107 if (s == NULL)
1108 return 0;
1109 s->ext.session_ticket_cb = cb;
1110 s->ext.session_ticket_cb_arg = arg;
1111 return 1;
1112}
1113
1114int SSL_set_session_ticket_ext(SSL *s, void *ext_data, int ext_len)
1115{
1116 if (s->version >= TLS1_VERSION) {
1117 OPENSSL_free(s->ext.session_ticket);
1118 s->ext.session_ticket = NULL;
1119 s->ext.session_ticket =
1120 OPENSSL_malloc(sizeof(TLS_SESSION_TICKET_EXT) + ext_len);
1121 if (s->ext.session_ticket == NULL) {
1122 ERR_raise(ERR_LIB_SSL, ERR_R_MALLOC_FAILURE);
1123 return 0;
1124 }
1125
1126 if (ext_data != NULL) {
1127 s->ext.session_ticket->length = ext_len;
1128 s->ext.session_ticket->data = s->ext.session_ticket + 1;
1129 memcpy(s->ext.session_ticket->data, ext_data, ext_len);
1130 } else {
1131 s->ext.session_ticket->length = 0;
1132 s->ext.session_ticket->data = NULL;
1133 }
1134
1135 return 1;
1136 }
1137
1138 return 0;
1139}
1140
1141void SSL_CTX_flush_sessions(SSL_CTX *s, long t)
1142{
1143 STACK_OF(SSL_SESSION) *sk;
1144 SSL_SESSION *current;
1145 unsigned long i;
1146
1147 if (!CRYPTO_THREAD_write_lock(s->lock))
1148 return;
1149
1150 sk = sk_SSL_SESSION_new_null();
1151 i = lh_SSL_SESSION_get_down_load(s->sessions);
1152 lh_SSL_SESSION_set_down_load(s->sessions, 0);
1153
1154 /*
1155 * Iterate over the list from the back (oldest), and stop
1156 * when a session can no longer be removed.
1157 * Add the session to a temporary list to be freed outside
1158 * the SSL_CTX lock.
1159 * But still do the remove_session_cb() within the lock.
1160 */
1161 while (s->session_cache_tail != NULL) {
1162 current = s->session_cache_tail;
1163 if (t == 0 || sess_timedout((time_t)t, current)) {
1164 lh_SSL_SESSION_delete(s->sessions, current);
1165 SSL_SESSION_list_remove(s, current);
1166 current->not_resumable = 1;
1167 if (s->remove_session_cb != NULL)
1168 s->remove_session_cb(s, current);
1169 /*
1170 * Throw the session on a stack, it's entirely plausible
1171 * that while freeing outside the critical section, the
1172 * session could be re-added, so avoid using the next/prev
1173 * pointers. If the stack failed to create, or the session
1174 * couldn't be put on the stack, just free it here
1175 */
1176 if (sk == NULL || !sk_SSL_SESSION_push(sk, current))
1177 SSL_SESSION_free(current);
1178 } else {
1179 break;
1180 }
1181 }
1182
1183 lh_SSL_SESSION_set_down_load(s->sessions, i);
1184 CRYPTO_THREAD_unlock(s->lock);
1185
1186 sk_SSL_SESSION_pop_free(sk, SSL_SESSION_free);
1187}
1188
1189int ssl_clear_bad_session(SSL *s)
1190{
1191 if ((s->session != NULL) &&
1192 !(s->shutdown & SSL_SENT_SHUTDOWN) &&
1193 !(SSL_in_init(s) || SSL_in_before(s))) {
1194 SSL_CTX_remove_session(s->session_ctx, s->session);
1195 return 1;
1196 } else
1197 return 0;
1198}
1199
1200/* locked by SSL_CTX in the calling function */
1201static void SSL_SESSION_list_remove(SSL_CTX *ctx, SSL_SESSION *s)
1202{
1203 if ((s->next == NULL) || (s->prev == NULL))
1204 return;
1205
1206 if (s->next == (SSL_SESSION *)&(ctx->session_cache_tail)) {
1207 /* last element in list */
1208 if (s->prev == (SSL_SESSION *)&(ctx->session_cache_head)) {
1209 /* only one element in list */
1210 ctx->session_cache_head = NULL;
1211 ctx->session_cache_tail = NULL;
1212 } else {
1213 ctx->session_cache_tail = s->prev;
1214 s->prev->next = (SSL_SESSION *)&(ctx->session_cache_tail);
1215 }
1216 } else {
1217 if (s->prev == (SSL_SESSION *)&(ctx->session_cache_head)) {
1218 /* first element in list */
1219 ctx->session_cache_head = s->next;
1220 s->next->prev = (SSL_SESSION *)&(ctx->session_cache_head);
1221 } else {
1222 /* middle of list */
1223 s->next->prev = s->prev;
1224 s->prev->next = s->next;
1225 }
1226 }
1227 s->prev = s->next = NULL;
1228 s->owner = NULL;
1229}
1230
1231static void SSL_SESSION_list_add(SSL_CTX *ctx, SSL_SESSION *s)
1232{
1233 SSL_SESSION *next;
1234
1235 if ((s->next != NULL) && (s->prev != NULL))
1236 SSL_SESSION_list_remove(ctx, s);
1237
1238 if (ctx->session_cache_head == NULL) {
1239 ctx->session_cache_head = s;
1240 ctx->session_cache_tail = s;
1241 s->prev = (SSL_SESSION *)&(ctx->session_cache_head);
1242 s->next = (SSL_SESSION *)&(ctx->session_cache_tail);
1243 } else {
1244 if (timeoutcmp(s, ctx->session_cache_head) >= 0) {
1245 /*
1246 * if we timeout after (or the same time as) the first
1247 * session, put us first - usual case
1248 */
1249 s->next = ctx->session_cache_head;
1250 s->next->prev = s;
1251 s->prev = (SSL_SESSION *)&(ctx->session_cache_head);
1252 ctx->session_cache_head = s;
1253 } else if (timeoutcmp(s, ctx->session_cache_tail) < 0) {
1254 /* if we timeout before the last session, put us last */
1255 s->prev = ctx->session_cache_tail;
1256 s->prev->next = s;
1257 s->next = (SSL_SESSION *)&(ctx->session_cache_tail);
1258 ctx->session_cache_tail = s;
1259 } else {
1260 /*
1261 * we timeout somewhere in-between - if there is only
1262 * one session in the cache it will be caught above
1263 */
1264 next = ctx->session_cache_head->next;
1265 while (next != (SSL_SESSION*)&(ctx->session_cache_tail)) {
1266 if (timeoutcmp(s, next) >= 0) {
1267 s->next = next;
1268 s->prev = next->prev;
1269 next->prev->next = s;
1270 next->prev = s;
1271 break;
1272 }
1273 next = next->next;
1274 }
1275 }
1276 }
1277 s->owner = ctx;
1278}
1279
1280void SSL_CTX_sess_set_new_cb(SSL_CTX *ctx,
1281 int (*cb) (struct ssl_st *ssl, SSL_SESSION *sess))
1282{
1283 ctx->new_session_cb = cb;
1284}
1285
1286int (*SSL_CTX_sess_get_new_cb(SSL_CTX *ctx)) (SSL *ssl, SSL_SESSION *sess) {
1287 return ctx->new_session_cb;
1288}
1289
1290void SSL_CTX_sess_set_remove_cb(SSL_CTX *ctx,
1291 void (*cb) (SSL_CTX *ctx, SSL_SESSION *sess))
1292{
1293 ctx->remove_session_cb = cb;
1294}
1295
1296void (*SSL_CTX_sess_get_remove_cb(SSL_CTX *ctx)) (SSL_CTX *ctx,
1297 SSL_SESSION *sess) {
1298 return ctx->remove_session_cb;
1299}
1300
1301void SSL_CTX_sess_set_get_cb(SSL_CTX *ctx,
1302 SSL_SESSION *(*cb) (struct ssl_st *ssl,
1303 const unsigned char *data,
1304 int len, int *copy))
1305{
1306 ctx->get_session_cb = cb;
1307}
1308
1309SSL_SESSION *(*SSL_CTX_sess_get_get_cb(SSL_CTX *ctx)) (SSL *ssl,
1310 const unsigned char
1311 *data, int len,
1312 int *copy) {
1313 return ctx->get_session_cb;
1314}
1315
1316void SSL_CTX_set_info_callback(SSL_CTX *ctx,
1317 void (*cb) (const SSL *ssl, int type, int val))
1318{
1319 ctx->info_callback = cb;
1320}
1321
1322void (*SSL_CTX_get_info_callback(SSL_CTX *ctx)) (const SSL *ssl, int type,
1323 int val) {
1324 return ctx->info_callback;
1325}
1326
1327void SSL_CTX_set_client_cert_cb(SSL_CTX *ctx,
1328 int (*cb) (SSL *ssl, X509 **x509,
1329 EVP_PKEY **pkey))
1330{
1331 ctx->client_cert_cb = cb;
1332}
1333
1334int (*SSL_CTX_get_client_cert_cb(SSL_CTX *ctx)) (SSL *ssl, X509 **x509,
1335 EVP_PKEY **pkey) {
1336 return ctx->client_cert_cb;
1337}
1338
1339void SSL_CTX_set_cookie_generate_cb(SSL_CTX *ctx,
1340 int (*cb) (SSL *ssl,
1341 unsigned char *cookie,
1342 unsigned int *cookie_len))
1343{
1344 ctx->app_gen_cookie_cb = cb;
1345}
1346
1347void SSL_CTX_set_cookie_verify_cb(SSL_CTX *ctx,
1348 int (*cb) (SSL *ssl,
1349 const unsigned char *cookie,
1350 unsigned int cookie_len))
1351{
1352 ctx->app_verify_cookie_cb = cb;
1353}
1354
1355int SSL_SESSION_set1_ticket_appdata(SSL_SESSION *ss, const void *data, size_t len)
1356{
1357 OPENSSL_free(ss->ticket_appdata);
1358 ss->ticket_appdata_len = 0;
1359 if (data == NULL || len == 0) {
1360 ss->ticket_appdata = NULL;
1361 return 1;
1362 }
1363 ss->ticket_appdata = OPENSSL_memdup(data, len);
1364 if (ss->ticket_appdata != NULL) {
1365 ss->ticket_appdata_len = len;
1366 return 1;
1367 }
1368 return 0;
1369}
1370
1371int SSL_SESSION_get0_ticket_appdata(SSL_SESSION *ss, void **data, size_t *len)
1372{
1373 *data = ss->ticket_appdata;
1374 *len = ss->ticket_appdata_len;
1375 return 1;
1376}
1377
1378void SSL_CTX_set_stateless_cookie_generate_cb(
1379 SSL_CTX *ctx,
1380 int (*cb) (SSL *ssl,
1381 unsigned char *cookie,
1382 size_t *cookie_len))
1383{
1384 ctx->gen_stateless_cookie_cb = cb;
1385}
1386
1387void SSL_CTX_set_stateless_cookie_verify_cb(
1388 SSL_CTX *ctx,
1389 int (*cb) (SSL *ssl,
1390 const unsigned char *cookie,
1391 size_t cookie_len))
1392{
1393 ctx->verify_stateless_cookie_cb = cb;
1394}
1395
1396IMPLEMENT_PEM_rw(SSL_SESSION, SSL_SESSION, PEM_STRING_SSL_SESSION, SSL_SESSION)
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette