SSL_SET_SESSION(3ossl)
๐ SSL_SET_SESSION ๐
okay bestie, welcome to the SSL_set_session(3ossl) page โ it's an OpenSSL one, and it's lowkey iconic. sit down, grab a boba, we're locking in. ๐งโจ
๐ NAME ๐
SSL_set_session โ set a TLS/SSL session to be used during TLS/SSL connect. that's it, that's the whole job. periodt. ๐
๐ธ SYNOPSIS ๐ธ
#include <openssl/ssl.h>
int SSL_set_session(SSL *ssl, SSL_SESSION *session);
like look at it. two args. one int back. she's simple, she's clean, she's giving main character energy. ๐ฆ
โจ DESCRIPTION โจ
so SSL_set_session() sets session to be used when the TLS/SSL connection is about to be established. and ngl? SSL_set_session() is only useful for TLS/SSL clients. server girlies, this one's not for you, sorry bestie. ๐
when the session is set, the reference count of session gets incremented by 1. and if the session is not reused, that reference count gets decremented again during SSL_connect(). it's giving "borrowed it, gave it back". whether the session was actually reused can be queried with the SSL_session_reused(3) call. ๐
now, plot twist ๐ โ if there's already a session set inside ssl (either because it was set with SSL_set_session() before, or because the same ssl was already used for a connection), then SSL_SESSION_free() will be called for that old session. and yes, that's also the case when session is a NULL pointer. bye girl, you're evicted. ๐
and if that old session is still open? it's considered bad and it will be removed from the session cache (if used). a session counts as open if SSL_shutdown(3) was not called for the connection โ or, like, at least if SSL_set_shutdown(3) was used to set the SSL_SENT_SHUTDOWN state. basically: did you say goodbye properly? if not, that's a red flag and it gets yeeted from the cache. ๐ฎ
๐ซถ NOTES ๐ซถ
listen up, this part 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, fr fr, no exceptions โ must only be used with one SSL_CTX object (and the SSL objects created from that SSL_CTX object).
one session, one SSL_CTX. that's the rule. don't be messy about it. ๐ซ it's not a "share with the group chat" situation, it's a "this is mine" situation. ๐ค
๐ RETURN VALUES ๐
here's what you might get back, bestie:
0โ the operation failed. check the error stack to find out the reason. it's giving "something went wrong and you gotta go look". ๐ญ1โ the operation succeeded. slay. we ate. ๐
๐ SEE ALSO ๐
go read these too, they're all in the same friend group:
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 a wrap on the SSL_SET_SESSION(3ossl) page from OpenSSL version 3.5.9, dated 2026-09-29 โ tysm for reading, ily, go reuse your sessions responsibly. mwah. ๐โจ๐๐ฆ๐ธ
๐ฆ where this page comes from
- fedora 43: openssl-devel 1:3.5.9-1.fc43 ยท Apache-2.0
- fedora 43: openssl-devel 1:3.5.9-1.fc43 ยท Apache-2.0
- fedora 44: openssl-devel 1:3.5.9-1.fc44 ยท Apache-2.0
- fedora 44: openssl-devel 1:3.5.9-1.fc44 ยท Apache-2.0
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms