Lines Matching refs:session

159 static void SSL_SESSION_list_remove(SSL_CTX *ctx, SSL_SESSION *session);
160 static void SSL_SESSION_list_add(SSL_CTX *ctx, SSL_SESSION *session);
161 static int remove_session_lock(SSL_CTX *ctx, SSL_SESSION *session, int lock);
164 SSL_SESSION *session = (SSL_SESSION *)OPENSSL_malloc(sizeof(SSL_SESSION)); in SSL_SESSION_new() local
165 if (session == NULL) { in SSL_SESSION_new()
169 memset(session, 0, sizeof(SSL_SESSION)); in SSL_SESSION_new()
171 session->verify_result = 1; /* avoid 0 (= X509_V_OK) just in case */ in SSL_SESSION_new()
172 session->references = 1; in SSL_SESSION_new()
173 session->timeout = SSL_DEFAULT_SESSION_TIMEOUT; in SSL_SESSION_new()
174 session->time = (unsigned long)time(NULL); in SSL_SESSION_new()
175 CRYPTO_new_ex_data(&session->ex_data); in SSL_SESSION_new()
176 return session; in SSL_SESSION_new()
179 SSL_SESSION *SSL_SESSION_up_ref(SSL_SESSION *session) { in SSL_SESSION_up_ref() argument
180 if (session != NULL) { in SSL_SESSION_up_ref()
181 CRYPTO_refcount_inc(&session->references); in SSL_SESSION_up_ref()
183 return session; in SSL_SESSION_up_ref()
186 void SSL_SESSION_free(SSL_SESSION *session) { in SSL_SESSION_free() argument
187 if (session == NULL || in SSL_SESSION_free()
188 !CRYPTO_refcount_dec_and_test_zero(&session->references)) { in SSL_SESSION_free()
192 CRYPTO_free_ex_data(&g_ex_data_class, session, &session->ex_data); in SSL_SESSION_free()
194 OPENSSL_cleanse(session->master_key, sizeof(session->master_key)); in SSL_SESSION_free()
195 OPENSSL_cleanse(session->session_id, sizeof(session->session_id)); in SSL_SESSION_free()
196 X509_free(session->peer); in SSL_SESSION_free()
197 sk_X509_pop_free(session->cert_chain, X509_free); in SSL_SESSION_free()
198 OPENSSL_free(session->tlsext_hostname); in SSL_SESSION_free()
199 OPENSSL_free(session->tlsext_tick); in SSL_SESSION_free()
200 OPENSSL_free(session->tlsext_signed_cert_timestamp_list); in SSL_SESSION_free()
201 OPENSSL_free(session->ocsp_response); in SSL_SESSION_free()
202 OPENSSL_free(session->psk_identity); in SSL_SESSION_free()
203 OPENSSL_cleanse(session, sizeof(*session)); in SSL_SESSION_free()
204 OPENSSL_free(session); in SSL_SESSION_free()
207 const uint8_t *SSL_SESSION_get_id(const SSL_SESSION *session, in SSL_SESSION_get_id() argument
210 *out_len = session->session_id_length; in SSL_SESSION_get_id()
212 return session->session_id; in SSL_SESSION_get_id()
215 long SSL_SESSION_get_timeout(const SSL_SESSION *session) { in SSL_SESSION_get_timeout() argument
216 return session->timeout; in SSL_SESSION_get_timeout()
219 long SSL_SESSION_get_time(const SSL_SESSION *session) { in SSL_SESSION_get_time() argument
220 if (session == NULL) { in SSL_SESSION_get_time()
224 return session->time; in SSL_SESSION_get_time()
227 uint32_t SSL_SESSION_get_key_exchange_info(const SSL_SESSION *session) { in SSL_SESSION_get_key_exchange_info() argument
228 return session->key_exchange_info; in SSL_SESSION_get_key_exchange_info()
231 X509 *SSL_SESSION_get0_peer(const SSL_SESSION *session) { in SSL_SESSION_get0_peer() argument
232 return session->peer; in SSL_SESSION_get0_peer()
235 long SSL_SESSION_set_time(SSL_SESSION *session, long time) { in SSL_SESSION_set_time() argument
236 if (session == NULL) { in SSL_SESSION_set_time()
240 session->time = time; in SSL_SESSION_set_time()
244 long SSL_SESSION_set_timeout(SSL_SESSION *session, long timeout) { in SSL_SESSION_set_timeout() argument
245 if (session == NULL) { in SSL_SESSION_set_timeout()
249 session->timeout = timeout; in SSL_SESSION_set_timeout()
253 int SSL_SESSION_set1_id_context(SSL_SESSION *session, const uint8_t *sid_ctx, in SSL_SESSION_set1_id_context() argument
260 session->sid_ctx_length = sid_ctx_len; in SSL_SESSION_set1_id_context()
261 memcpy(session->sid_ctx, sid_ctx, sid_ctx_len); in SSL_SESSION_set1_id_context()
273 return ssl->session; in SSL_get_session()
278 return SSL_SESSION_up_ref(ssl->session); in SSL_get1_session()
293 int SSL_SESSION_set_ex_data(SSL_SESSION *session, int idx, void *arg) { in SSL_SESSION_set_ex_data() argument
294 return CRYPTO_set_ex_data(&session->ex_data, idx, arg); in SSL_SESSION_set_ex_data()
297 void *SSL_SESSION_get_ex_data(const SSL_SESSION *session, int idx) { in SSL_SESSION_get_ex_data() argument
298 return CRYPTO_get_ex_data(&session->ex_data, idx); in SSL_SESSION_get_ex_data()
307 SSL_SESSION *session = SSL_SESSION_new(); in ssl_get_new_session() local
308 if (session == NULL) { in ssl_get_new_session()
314 session->timeout = ssl->initial_ctx->session_timeout; in ssl_get_new_session()
317 session->ssl_version = ssl->version; in ssl_get_new_session()
323 session->session_id_length = 0; in ssl_get_new_session()
325 session->session_id_length = SSL3_SSL_SESSION_ID_LENGTH; in ssl_get_new_session()
326 if (!RAND_bytes(session->session_id, session->session_id_length)) { in ssl_get_new_session()
332 session->tlsext_hostname = BUF_strdup(ssl->tlsext_hostname); in ssl_get_new_session()
333 if (session->tlsext_hostname == NULL) { in ssl_get_new_session()
339 session->session_id_length = 0; in ssl_get_new_session()
342 if (ssl->sid_ctx_length > sizeof(session->sid_ctx)) { in ssl_get_new_session()
346 memcpy(session->sid_ctx, ssl->sid_ctx, ssl->sid_ctx_length); in ssl_get_new_session()
347 session->sid_ctx_length = ssl->sid_ctx_length; in ssl_get_new_session()
349 session->verify_result = X509_V_OK; in ssl_get_new_session()
351 SSL_SESSION_free(ssl->session); in ssl_get_new_session()
352 ssl->session = session; in ssl_get_new_session()
356 SSL_SESSION_free(session); in ssl_get_new_session()
372 SSL_SESSION *session; in ssl_lookup_session() local
382 session = lh_SSL_SESSION_retrieve(ssl->initial_ctx->sessions, &data); in ssl_lookup_session()
383 if (session != NULL) { in ssl_lookup_session()
384 SSL_SESSION_up_ref(session); in ssl_lookup_session()
389 if (session != NULL) { in ssl_lookup_session()
390 *out_session = session; in ssl_lookup_session()
400 session = ssl->initial_ctx->get_session_cb(ssl, (uint8_t *)session_id, in ssl_lookup_session()
402 if (session == NULL) { in ssl_lookup_session()
405 if (session == SSL_magic_pending_session_ptr()) { in ssl_lookup_session()
414 SSL_SESSION_up_ref(session); in ssl_lookup_session()
420 SSL_CTX_add_session(ssl->initial_ctx, session); in ssl_lookup_session()
423 *out_session = session; in ssl_lookup_session()
432 SSL_SESSION *session = NULL; in ssl_get_prev_session() local
444 if (!tls_process_ticket(ssl, &session, &send_ticket, ticket, ticket_len, in ssl_get_prev_session()
452 ssl, &session, ctx->session_id, ctx->session_id_len); in ssl_get_prev_session()
458 if (session == NULL || in ssl_get_prev_session()
459 session->sid_ctx_length != ssl->sid_ctx_length || in ssl_get_prev_session()
460 memcmp(session->sid_ctx, ssl->sid_ctx, ssl->sid_ctx_length) != 0) { in ssl_get_prev_session()
477 if (session->timeout < (long)(time(NULL) - session->time)) { in ssl_get_prev_session()
480 SSL_CTX_remove_session(ssl->initial_ctx, session); in ssl_get_prev_session()
485 *out_session = session; in ssl_get_prev_session()
490 SSL_SESSION_free(session); in ssl_get_prev_session()
496 SSL_SESSION_free(session); in ssl_get_prev_session()
500 int SSL_CTX_add_session(SSL_CTX *ctx, SSL_SESSION *session) { in SSL_CTX_add_session() argument
503 SSL_SESSION_up_ref(session); in SSL_CTX_add_session()
507 if (!lh_SSL_SESSION_insert(ctx->sessions, &old_session, session)) { in SSL_CTX_add_session()
509 SSL_SESSION_free(session); in SSL_CTX_add_session()
514 if (old_session == session) { in SSL_CTX_add_session()
527 SSL_SESSION_list_add(ctx, session); in SSL_CTX_add_session()
542 int SSL_CTX_remove_session(SSL_CTX *ctx, SSL_SESSION *session) { in SSL_CTX_remove_session() argument
543 return remove_session_lock(ctx, session, 1); in SSL_CTX_remove_session()
546 static int remove_session_lock(SSL_CTX *ctx, SSL_SESSION *session, int lock) { in remove_session_lock() argument
549 if (session != NULL && session->session_id_length != 0) { in remove_session_lock()
554 session); in remove_session_lock()
555 if (found_session == session) { in remove_session_lock()
557 found_session = lh_SSL_SESSION_delete(ctx->sessions, session); in remove_session_lock()
558 SSL_SESSION_list_remove(ctx, session); in remove_session_lock()
577 int SSL_set_session(SSL *ssl, SSL_SESSION *session) { in SSL_set_session() argument
578 if (ssl->session == session) { in SSL_set_session()
582 SSL_SESSION_free(ssl->session); in SSL_set_session()
583 ssl->session = session; in SSL_set_session()
584 if (session != NULL) { in SSL_set_session()
585 SSL_SESSION_up_ref(session); in SSL_set_session()
586 ssl->verify_result = session->verify_result; in SSL_set_session()
616 static void timeout_doall_arg(SSL_SESSION *session, void *void_param) { in timeout_doall_arg() argument
620 param->time > (session->time + session->timeout)) { in timeout_doall_arg()
624 (void) lh_SSL_SESSION_delete(param->cache, session); in timeout_doall_arg()
625 SSL_SESSION_list_remove(param->ctx, session); in timeout_doall_arg()
626 session->not_resumable = 1; in timeout_doall_arg()
628 param->ctx->remove_session_cb(param->ctx, session); in timeout_doall_arg()
630 SSL_SESSION_free(session); in timeout_doall_arg()
649 if (ssl->session != NULL && !(ssl->shutdown & SSL_SENT_SHUTDOWN) && in ssl_clear_bad_session()
651 SSL_CTX_remove_session(ssl->ctx, ssl->session); in ssl_clear_bad_session()
659 static void SSL_SESSION_list_remove(SSL_CTX *ctx, SSL_SESSION *session) { in SSL_SESSION_list_remove() argument
660 if (session->next == NULL || session->prev == NULL) { in SSL_SESSION_list_remove()
664 if (session->next == (SSL_SESSION *)&ctx->session_cache_tail) { in SSL_SESSION_list_remove()
666 if (session->prev == (SSL_SESSION *)&ctx->session_cache_head) { in SSL_SESSION_list_remove()
671 ctx->session_cache_tail = session->prev; in SSL_SESSION_list_remove()
672 session->prev->next = (SSL_SESSION *)&(ctx->session_cache_tail); in SSL_SESSION_list_remove()
675 if (session->prev == (SSL_SESSION *)&ctx->session_cache_head) { in SSL_SESSION_list_remove()
677 ctx->session_cache_head = session->next; in SSL_SESSION_list_remove()
678 session->next->prev = (SSL_SESSION *)&(ctx->session_cache_head); in SSL_SESSION_list_remove()
680 session->next->prev = session->prev; in SSL_SESSION_list_remove()
681 session->prev->next = session->next; in SSL_SESSION_list_remove()
684 session->prev = session->next = NULL; in SSL_SESSION_list_remove()
687 static void SSL_SESSION_list_add(SSL_CTX *ctx, SSL_SESSION *session) { in SSL_SESSION_list_add() argument
688 if (session->next != NULL && session->prev != NULL) { in SSL_SESSION_list_add()
689 SSL_SESSION_list_remove(ctx, session); in SSL_SESSION_list_add()
693 ctx->session_cache_head = session; in SSL_SESSION_list_add()
694 ctx->session_cache_tail = session; in SSL_SESSION_list_add()
695 session->prev = (SSL_SESSION *)&(ctx->session_cache_head); in SSL_SESSION_list_add()
696 session->next = (SSL_SESSION *)&(ctx->session_cache_tail); in SSL_SESSION_list_add()
698 session->next = ctx->session_cache_head; in SSL_SESSION_list_add()
699 session->next->prev = session; in SSL_SESSION_list_add()
700 session->prev = (SSL_SESSION *)&(ctx->session_cache_head); in SSL_SESSION_list_add()
701 ctx->session_cache_head = session; in SSL_SESSION_list_add()
706 int (*cb)(SSL *ssl, SSL_SESSION *session)) { in SSL_CTX_sess_set_new_cb() argument
710 int (*SSL_CTX_sess_get_new_cb(SSL_CTX *ctx))(SSL *ssl, SSL_SESSION *session) { in SSL_CTX_sess_get_new_cb()
715 SSL_CTX *ctx, void (*cb)(SSL_CTX *ctx, SSL_SESSION *session)) { in SSL_CTX_sess_set_remove_cb() argument
720 SSL_SESSION *session) { in SSL_CTX_sess_get_remove_cb()