SSL_SET_SESSION(3ossl)
π SSL_SET_SESSION (3ossl) β the bestie guide
okay so bestie, this page is SSL_set_session(3ossl) from the OpenSSL manual, and it's basically about handing a client a session to reuse. lowkey important, highkey specific. let's go π
β¨ SYNOPSIS β¨
#include <openssl/ssl.h>
int SSL_set_session(SSL *ssl, SSL_SESSION *session);
πΈ DESCRIPTION πΈ
SSL_set_session() sets session to be used when the TLS/SSL connection is about to be established. and bestie, hear me: SSL_set_session() is only useful for TLS/SSL clients. servers, this is not your era, sorry π«Ά
When the session is set, the reference count of session is incremented by 1. iconic. but if the session is not reused, that reference count gets decremented again during SSL_connect(). whether the session actually got reused? you can query that with the SSL_session_reused(3) call. vibe check on the session, basically β¨
now here's the part where you gotta pay attention π if there is already a session set inside ssl β either because it was set with SSL_set_session() before, or because that same ssl was already used for a connection β then SSL_SESSION_free() will be called for that old session. yes, even when session is a NULL pointer. that's the case too.
and if that old session is still open, it's considered bad π and will be removed from the session cache (if one is used). A session counts as "open" if SSL_shutdown(3) was not called for the connection β or at least if SSL_set_shutdown(3) wasn't used to set the SSL_SENT_SHUTDOWN state. no clean goodbye = still open, and the vibes are rancid.
π¦ NOTES π¦
real talk, this one matters.
SSL_SESSION objects keep internal link information about the session cache list when they get inserted into one SSL_CTX object's session cache. so one SSL_SESSION object β regardless of its reference count β must therefore only be used with one SSL_CTX object (and the SSL objects created from that SSL_CTX object). no sharing between contexts, bestie. it's giving exclusive relationship, and honestly that's the way it has to be π
π RETURN VALUES π
The following return values can occur:
0β the operation failed π check the error stack to find out the reason.1β the operation succeeded π₯ slay.
π SEE ALSO π
ssl(7), SSL_SESSION_free(3), SSL_get_session(3), SSL_session_reused(3), SSL_CTX_set_session_cache_mode(3)
π COPYRIGHT π
Copyright 2000-2022 The OpenSSL Project Authors. All Rights Reserved.
Licensed under the Apache License 2.0 (the "License"). You may not use this file except in compliance with the License. You can obtain a copy in the file LICENSE in the source distribution or at <https://www.openssl.org/source/license.html>.
and that's the page, bestie π this was OpenSSL version 3.5.0, dated 2026-09-25, and it's filed under SSL_SET_SESSION(3ossl). go forth and reuse those sessions responsibly π
β¨π
π¦ where this page comes from
- opensuse-leap 16.0: openssl-3-doc 3.5.0-160000.11.1 Β· Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms