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 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