---
name: "libressl-SSL_CTX_set_session_id_context"
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_set_session_id_context"
---

# libressl-SSL\_CTX\_set\_session\_id\_context(3)

set context within which session can be reused (server side only)

## NAME

**SSL\_CTX\_set\_session\_id\_context**, **SSL\_set\_session\_id\_context** – set context within which session can be reused (server side only)

## SYNOPSIS

SSL Library (libssl, -lssl) libcrypto

**#include \<openssl/ssl.h\>**

*int*\

**SSL\_CTX\_set\_session\_id\_context**(*SSL\_CTX \*ctx*, *const unsigned char \*sid\_ctx*, *unsigned int sid\_ctx\_len*);

*int*\

**SSL\_set\_session\_id\_context**(*SSL \*ssl*, *const unsigned char \*sid\_ctx*, *unsigned int sid\_ctx\_len*);

## DESCRIPTION

**SSL\_CTX\_set\_session\_id\_context**() sets the context *sid\_ctx* of length *sid\_ctx\_len* within which a session can be reused for the *ctx* object.

**SSL\_set\_session\_id\_context**() sets the context *sid\_ctx* of length *sid\_ctx\_len* within which a session can be reused for the *ssl* object.

Sessions are generated within a certain context. When exporting/importing sessions with i2d\_SSL\_SESSION(3) and d2i\_SSL\_SESSION(3), it would be possible to re-import a session generated from another context (e.g., another application), which might lead to malfunctions. Therefore each application must set its own session id context *sid\_ctx* which is used to distinguish the contexts and is stored in exported sessions. The *sid\_ctx* can be any kind of binary data with a given length; it is therefore possible to use, for instance, the name of the application, the hostname, the service name...

The session id context becomes part of the session. The session id context is set by the SSL/TLS server. The **SSL\_CTX\_set\_session\_id\_context**() and **SSL\_set\_session\_id\_context**() functions are therefore only useful on the server side.

OpenSSL clients will check the session id context returned by the server when reusing a session.

The maximum length of the *sid\_ctx* is limited to SSL\_MAX\_SSL\_SESSION\_ID\_LENGTH.

## WARNINGS

If the session id context is not set on an SSL/TLS server and client certificates are used, stored sessions will not be reused but a fatal error will be flagged and the handshake will fail.

If a server returns a different session id context to an OpenSSL client when reusing a session, an error will be flagged and the handshake will fail. OpenSSL servers will always return the correct session id context, as an OpenSSL server checks the session id context itself before reusing a session as described above.

## RETURN VALUES

**SSL\_CTX\_set\_session\_id\_context**() and **SSL\_set\_session\_id\_context**() return the following values:

- 0

  The length *sid\_ctx\_len* of the session id context *sid\_ctx* exceeded the maximum allowed length of SSL\_MAX\_SSL\_SESSION\_ID\_LENGTH. The error is logged to the error stack.

- 1

  The operation succeeded.

## SEE ALSO

[ssl(3)](/ssl/3.md), SSL\_SESSION\_set1\_id\_context(3)

## HISTORY

**SSL\_set\_session\_id\_context**() first appeared in OpenSSL 0.9.2b. **SSL\_CTX\_set\_session\_id\_context**() first appeared in OpenSSL 0.9.3. Both functions have been available since OpenBSD 2.6.
