SSL_SET_SESSION(3SSL)

πŸ’– SSL_SET_SESSION πŸ’–

okay bestie, welcome to the SSL_set_session(3SSL) page from the OpenSSL manual β€” yes, the whole OpenSSL manual, we're in the big leagues now πŸ‘‘


✨ NAME ✨

SSL_set_session β€” set a TLS/SSL session to be used during TLS/SSL connect 🫢


🌸 SYNOPSIS 🌸

#include <openssl/ssl.h>

int SSL_set_session(SSL *ssl, SSL_SESSION *session);

πŸ¦‹ DESCRIPTION πŸ¦‹

So like. SSL_set_session() sets session to be used when the TLS/SSL connection is to be established. That's the whole job. Slay.

Quick vibe check tho: SSL_set_session() is only useful for TLS/SSL clients. Servers, this one is not for you, sorry babe πŸ™ˆ

The way that reference counting works here is so important, so listen up:

  • When the session is set, the reference count of session is incremented by 1.
  • If the session is not reused, the reference count is decremented again during SSL_connect().
  • Wanna know if the session actually got reused? Query it with SSL_session_reused(3) πŸ’…

And here's the part where things get a lil dramatic 😭 β€” if there is already a session set inside ssl (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 session. Yes, even when session is a NULL pointer. No escape.

⚠️ And if that old session is still open, it is considered bad and 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, at the very least, SSL_set_shutdown(3) was used to set the SSL_SENT_SHUTDOWN state. Keep your sessions closed, babes, it's giving hygiene 🧼

πŸ’œ NOTES πŸ’œ

okay this is the "iykyk" section, fr fr.

SSL_SESSION objects keep internal link information about the session cache list when being inserted into one SSL_CTX object's session cache.

So because of that: 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 this SSL_CTX object). No sharing. No side-eyeing other contexts. Monogamy only πŸ‘‘βœ¨


🌈 RETURN VALUES 🌈

Here's what can come back at you:

  • 0 β€” the operation failed; check the error stack to find out the reason. πŸ’€
  • 1 β€” the operation succeeded. πŸŽ‰ ate, no crumbs

πŸ‘‘ SEE ALSO πŸ‘‘

go read these next, bestie, they're all connected:


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 whole page, periodt πŸ’…βœ¨ this one came from OpenSSL 4.0.3, dated 2026-09-29, and it lives under the name SSL_SET_SESSION(3SSL). go forth and set those sessions, bestie πŸŽ€πŸ¦‹πŸ’–

πŸ“¦ where this page comes from