---
name: "libressl-SSL_get_session"
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_get_session"
---

# libressl-SSL\_get\_session(3)

retrieve TLS/SSL session data

## NAME

**SSL\_get\_session**, **SSL\_get0\_session**, **SSL\_get1\_session** – retrieve TLS/SSL session data

## SYNOPSIS

SSL Library (libssl, -lssl) libcrypto

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

*SSL\_SESSION* *\**\

**SSL\_get\_session**(*const SSL \*ssl*);

*SSL\_SESSION* *\**\

**SSL\_get0\_session**(*const SSL \*ssl*);

*SSL\_SESSION* *\**\

**SSL\_get1\_session**(*SSL \*ssl*);

## DESCRIPTION

**SSL\_get\_session**() returns a pointer to the *SSL\_SESSION* actually used in *ssl*. The reference count of the *SSL\_SESSION* is not incremented, so that the pointer can become invalid by other operations.

**SSL\_get0\_session**() is the same as **SSL\_get\_session**().

**SSL\_get1\_session**() is the same as **SSL\_get\_session**(), but the reference count of the *SSL\_SESSION* is incremented by one.

The *ssl* session contains all information required to re-establish the connection without a new handshake.

**SSL\_get0\_session**() returns a pointer to the actual session. As the reference counter is not incremented, the pointer is only valid while the connection is in use. If SSL\_clear(3) or SSL\_free(3) is called, the session may be removed completely (if considered bad), and the pointer obtained will become invalid. Even if the session is valid, it can be removed at any time due to timeout during SSL\_CTX\_flush\_sessions(3).

If the data is to be kept, **SSL\_get1\_session**() will increment the reference count, so that the session will not be implicitly removed by other operations but stays in memory. In order to remove the session, SSL\_SESSION\_free(3) must be explicitly called once to decrement the reference count again.

*SSL\_SESSION* objects keep internal link information about the session cache list when being inserted into one *SSL\_CTX* object's session cache. One *SSL\_SESSION* object, regardless of its reference count, must therefore only be used with one *SSL\_CTX* object (and the *SSL* objects created from this *SSL\_CTX* object).

## RETURN VALUES

The following return values can occur:

- NULL

  There is no session available in *ssl*.

- Pointer to an *SSL\_SESSION*

  The return value points to the data of an *SSL* session.

## SEE ALSO

[ssl(3)](/ssl/3.md), SSL\_clear(3), SSL\_free(3), SSL\_SESSION\_free(3), SSL\_SESSION\_get0\_peer(3), SSL\_SESSION\_get\_compress\_id(3), SSL\_SESSION\_get\_id(3), SSL\_SESSION\_get\_protocol\_version(3), SSL\_SESSION\_get\_time(3), SSL\_SESSION\_new(3), SSL\_SESSION\_print(3), SSL\_set\_session(3)

## HISTORY

**SSL\_get\_session**() first appeared in SSLeay 0.5.2 and has been available since OpenBSD 2.4.

**SSL\_get0\_session**() and **SSL\_get1\_session**() first appeared in OpenSSL 0.9.5 and have been available since OpenBSD 2.7.
