SSL_CTX_ADD_SESSION(3ossl)

πŸ’– SSL_CTX_ADD_SESSION(3ossl) πŸ’–

okay bestie, welcome to the OpenSSL corner of the manual, this one's all about manipulating session cache β€” the SSL_CTX_add_session and SSL_CTX_remove_session duo. two little functions, one very important job: deciding which sessions get to hang out in the cache and which ones get yeeted. πŸŽ€


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

SSL_CTX_add_session() β€” this one takes session c and drops it into the context ctx. slay. the reference count for session c gets bumped up by 1, so it's officially counted. πŸ’…

now, if a session with the same session id already exists in there? the old session gets removed, and it does that by calling SSL_SESSION_free(3). out with the old, in with the new, no cap.

SSL_CTX_remove_session() β€” this is the opposite vibe. it removes session c from context ctx and marks it as non-resumable (so it can never come back, sorry babe). SSL_SESSION_free(3) gets called once for c.


πŸ‘‘ NOTES πŸ‘‘

so when you add a new session to the internal session cache, it first checks whether a session with the same session id already exists. if so, it just assumes both sessions are identical. and if the same session is stored in a different SSL_SESSION object? the old session is removed and replaced by the new one. bye bestie βœ‹

but if the session is actually identical (like, the SSL_SESSION object is identical), then SSL_CTX_add_session() is a no-op, and the return value is 0. literally does nothing. iconic behaviour honestly.

now here's the tea β˜• β€” 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 the internal cache will still be searched automatically for session-resume requests. (and that searching can be suppressed with SSL_SESS_CACHE_NO_INTERNAL_LOOKUP, iykyk.)

so basically the application can call SSL_CTX_add_session() directly to have full control over which sessions can be resumed, if that's what you're into. main character energy. 🌈


⭐ RETURN VALUES ⭐

both functions return these same values, so pay attention:

  • 0 β€” the operation failed. for the add operation, it means it tried to add the same (identical) session twice πŸ’€. for the remove operation, it means the session was not found in the cache.
  • 1 β€” the operation succeeded. 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>.


okay that's the whole page, you're officially a session cache girlie now πŸ’œ this was OpenSSL 3.5.9, dated 2026-09-29 β€” and remember, SSL_CTX_ADD_SESSION(3ossl), stay hydrated, and may all your sessions resume successfully. πŸ«Άβœ¨πŸ’–

πŸ“¦ where this page comes from