SSL_SET_SESSION(3)

πŸ“¦ version 4.4.0, in alpine 3.24, arch rolling

πŸ’– SSL_SET_SESSION(3) πŸ’–

okay bestie, so this one lives in the Library Functions Manual and it's part of the libssl / libcrypto fam β€” yes, the crypto girlies. Let's get into it ✨


🌸 SYNOPSIS 🌸

library β€œlibssl” libcrypto #include <openssl/ssl.h>

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

πŸŽ€ DESCRIPTION πŸŽ€

So SSL_set_session() sets session to be used when the TLS/SSL connection is about to be established. That's it, that's the vibe. 🫢

Heads up though: SSL_set_session() is only useful for TLS/SSL clients. Server girlies, this one's not for you πŸ’…

When the session is set, the reference count of session gets incremented by 1. Iconic. But if the session is not reused, that reference count gets decremented again during SSL_connect(). And if you're sitting there like "wait, was it even reused??" β€” you can query that with the SSL_session_reused(3) call. iykyk 😌

Now, if there's already a session set inside ssl β€” like, because it was set with SSL_set_session() before, or because the same ssl was already used for a connection β€” then SSL_SESSION_free(3) will be called for that session. Old session, your time is up 🫑

⚠️ BIG important warning, fr fr: 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 this SSL_CTX object). No sharing, no passing it around like a friendship bracelet. It's giving exclusive relationship πŸ”₯

✨ RETURN VALUES ✨

These are the return values that can occur, bestie:

  • 0 β€” the operation failed 😭 check the error stack to find out the reason.
  • 1 β€” the operation succeeded πŸ‘‘ slay.

πŸ¦‹ SEE ALSO πŸ¦‹

go read those, they're literally the supporting cast πŸ’œ


🌈 HISTORY 🌈

SSL_set_session() first appeared in SSLeay 0.5.2 and has been available since OpenBSD 2.4. a true elder, we stan an OG 🧚


aaaand that's the whole page! this lil gem came from the Debian edition, dated June 8, 2025 β€” mwah, bye bestie πŸ’…πŸŽ€

πŸ“¦ where this page comes from