---
name: "libressl-SSL_CTX_sess_set_get_cb"
section: "3"
platform: "linux"
package: "libressl"
version: "4.4.0-1"
release: "Arch Linux 2026-11-01"
platforms: ["linux"]
url: "https://new.carta.tech/libressl-SSL_CTX_sess_set_get_cb"
---

# libressl-SSL\_CTX\_sess\_set\_get\_cb(3)

provide callback functions for server side external session caching

## 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

## SYNOPSIS

SSL Library (libssl, -lssl) libcrypto

**#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 which is automatically called whenever a new session was negotiated.

**SSL\_CTX\_sess\_set\_remove\_cb**() sets the callback function which is automatically called whenever a session is removed by the SSL engine (because it is considered faulty or the session has become obsolete because of exceeding the timeout value).

**SSL\_CTX\_sess\_set\_get\_cb**() sets the callback function which is called whenever an 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)). (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.

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.

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.

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.

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).

## SEE ALSO

d2i\_SSL\_SESSION(3), [ssl(3)](/ssl/3.md), SSL\_CTX\_flush\_sessions(3), SSL\_CTX\_free(3), SSL\_CTX\_set\_session\_cache\_mode(3), SSL\_SESSION\_free(3)

## 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.
