SSL_CTX_SESS_SET_GET_CB(3)

πŸ“¦ version 4.1.0, in opensuse-leap 16.0

okay bestie, welcome to SSL_CTX_SESS_SET_GET_CB(3) from the Library Functions Manual πŸ’…βœ¨ this whole page is the server-side external session caching callback squad: setter girlies, getter girlies, and the callback signatures they're obsessed with. Let's get into it.

🌸 NAME 🌸

SSL_CTX_sess_set_new_cb, SSL_CTX_sess_set_remove_cb, SSL_CTX_sess_set_get_cb, SSL_CTX_sess_get_new_cb, SSL_CTX_sess_get_remove_cb, SSL_CTX_sess_get_get_cb β€” provide callback functions for server side external session caching. That's the whole crew, no cap 🫢


✨ SYNOPSIS ✨

First the mandatory include, then the full function lineup. Copy these exactly, bestie β€” no vibes-based edits:

#include <openssl/ssl.h>

void
SSL_CTX_sess_set_new_cb(SSL_CTX *ctx,
    int (*new_session_cb)(SSL *, SSL_SESSION *));

void
SSL_CTX_sess_set_remove_cb(SSL_CTX *ctx,
    void (*remove_session_cb)(SSL_CTX *ctx, SSL_SESSION *));

void
SSL_CTX_sess_set_get_cb(SSL_CTX *ctx,
    SSL_SESSION (*get_session_cb)(SSL *, const unsigned char *, int, int *));

int
(*SSL_CTX_sess_get_new_cb(SSL_CTX *ctx))(SSL *ssl, SSL_SESSION *sess);

void
(*SSL_CTX_sess_get_remove_cb(SSL_CTX *ctx))(SSL_CTX *ctx,
    SSL_SESSION *sess);

SSL_SESSION *
(*SSL_CTX_sess_get_get_cb(SSL_CTX *ctx))(SSL *ssl,
    const unsigned char *data, int len, int *copy);

int
(*new_session_cb)(SSL *ssl, SSL_SESSION *sess);

void
(*remove_session_cb)(SSL_CTX *ctx, SSL_SESSION *sess);

SSL_SESSION *
(*get_session_cb)(SSL *ssl, unsigned char *data, int len, int *copy);

πŸ’– DESCRIPTION πŸ’–

SSL_CTX_sess_set_new_cb() sets the callback function that is automatically called whenever a new session was negotiated. New session alert, iconic behavior πŸŽ€

SSL_CTX_sess_set_remove_cb() sets the callback function that is automatically called whenever a session is removed by the SSL engine β€” because it is considered faulty or because the session has become obsolete from exceeding the timeout value. Bye bestie πŸ’€

SSL_CTX_sess_set_get_cb() sets the callback function that is called whenever a SSL/TLS client proposes to resume a session but the session cannot be found in the internal session cache (see SSL_CTX_set_session_cache_mode(3)). This one is SSL/TLS server only πŸ–₯️✨

SSL_CTX_sess_get_new_cb(), SSL_CTX_sess_get_remove_cb(), and SSL_CTX_sess_get_get_cb() retrieve the function pointers of the provided callback functions. If a callback function has not been set, the NULL pointer is returned. No callback, no pointer, periodt πŸ™ˆ

In order to allow external session caching, synchronization with the internal session cache is realized via callback functions. Inside these callback functions, session can be saved to disk or put into a database using the d2i_SSL_SESSION(3) interface. That's the whole external-cache pipeline, bestie 🧚

The new_session_cb() function is called whenever a new session has been negotiated and session caching is enabled (see SSL_CTX_set_session_cache_mode(3)). The new_session_cb() function is passed the ssl connection and the ssl session sess. If the callback returns 0, the session will be immediately removed again β€” instant regret 😭

The remove_session_cb() function is called whenever the SSL engine removes a session from the internal cache. This happens when the session is removed because it is expired or when a connection was not shut down cleanly. It also happens for all sessions in the internal session cache when SSL_CTX_free(3) is called. The remove_session_cb() function is passed the ctx and the ssl session sess. It does not provide any feedback β€” it's giving silent exit 🫢

The get_session_cb() function is only called on SSL/TLS servers with the session id proposed by the client. The get_session_cb() function is always called, also when session caching was disabled. The get_session_cb() function is passed the ssl connection, the session id of length length at the memory location data. With the parameter copy the callback can require the SSL engine to increment the reference count of the SSL_SESSION object. Normally the reference count is not incremented and therefore the session must not be explicitly freed with SSL_SESSION_free(3). So do not explicitly free it with SSL_SESSION_free(3), periodt πŸ”₯


πŸ¦‹ SEE ALSO πŸ¦‹

Go read these next, bestie:


πŸ’œ HISTORY πŸ’œ

SSL_CTX_sess_set_new_cb(), SSL_CTX_sess_set_get_cb(), SSL_CTX_sess_get_new_cb(), and SSL_CTX_sess_get_get_cb() first appeared in SSLeay 0.6.0. SSL_CTX_sess_set_remove_cb() and SSL_CTX_sess_get_remove_cb() first appeared in SSLeay 0.8.0. These functions have been available since OpenBSD 2.4. Vintage but still slaying πŸ‘‘


That's the whole page, bestie πŸ’– this cutie came from Debian, dated March 29, 2022. Now go forth and cache those sessions externally, periodt πŸŽ€βœ¨

πŸ“¦ where this page comes from