SSL_CTX_ADD_SESSION(3SSL)

πŸ’– SSL_CTX_add_session(3SSL) πŸ’–

okay bestie, welcome to the SSL_CTX_add_session(3SSL) page, aka the manual for the two lil functions that let you personally babysit OpenSSL's session cache like the control freak you are (complimentary). let's get into it ✨


🌸 NAME 🌸

SSL_CTX_add_session, SSL_CTX_remove_session β€” manipulate session cache πŸ’…


πŸŽ€ SYNOPSIS πŸŽ€

#include <openssl/ssl.h>

int SSL_CTX_add_session(SSL_CTX *ctx, SSL_SESSION *c);

int SSL_CTX_remove_session(SSL_CTX *ctx, SSL_SESSION *c);

πŸ¦‹ DESCRIPTION πŸ¦‹

so like. SSL_CTX_add_session() takes the session c and yeets it into the context ctx. and the way that it bumps the reference count for session c by 1?? iconic. also, if a session with the same session id is already living there, the old one gets removed by calling SSL_SESSION_free(3). out with the old, in with the new, no cap 🫢

SSL_CTX_remove_session() does the opposite: it pulls session c out of context ctx and marks it as non-resumable β€” so it's officially not coming back, periodt. and SSL_SESSION_free(3) gets called once for c. one and done, bestie.


✨ NOTES ✨

okay so here's the tea on what actually happens when you slide a new session into the internal session cache πŸ“

first, it checks whether a session with the same session id already exists in there. if it does, it just assumes both sessions are identical (bold assumption but okay). if that same session is stored in a different SSL_SESSION object, then the old session is removed and replaced by the new one. slay, out with the old.

but if the session is actually identical β€” like, the SSL_SESSION object is literally the same object β€” then SSL_CTX_add_session() is a no-op and the return value is 0. nothing happens. it's giving "you already did this" 😭

and now the important part for the server girlies πŸ‘‘: if a server SSL_CTX is configured with the SSL_SESS_CACHE_NO_INTERNAL_STORE flag, then the internal cache will not be populated automatically by new sessions negotiated by the SSL/TLS implementation. BUT β€” and this is the plot twist β€” the internal cache will still be searched automatically for session-resume requests. (and that searching part can be suppressed with SSL_SESS_CACHE_NO_INTERNAL_LOOKUP, iykyk.) so if you want full control over which sessions can be resumed, your girl can just call SSL_CTX_add_session() directly. main character energy, honestly πŸ’…


⭐ RETURN VALUES ⭐

all of these functions hand back the same two values:

  • 0 β€” the operation failed πŸ™ˆ if it was an add, that means someone tried to add the same (identical) session twice. if it was a remove, that means the session was simply not found in the cache. it's giving "not in my house".
  • 1 β€” the operation succeeded. we ate. πŸ”₯

🌈 SEE ALSO 🌈


Copyright 2001-2016 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 bestie, no notes πŸ’– this was version 4.0.3 dated 2026-09-29 from the OpenSSL girlies themselves β€” go forth and manage those sessions responsibly πŸ§šβœ¨πŸŽ€

πŸ“¦ where this page comes from