SSL_GET_SESSION(3SSL)
π SSL_GET_SESSION π
okay bestie, we're diving into SSL_GET_SESSION(3SSL) β that's the manual page, bestie, part of the OpenSSL crew, and it's literally all about retrieving TLS/SSL session data. yes queen, we're going there β¨
β¨ NAME β¨
SSL_get_session, SSL_get0_session, SSL_get1_session β retrieve TLS/SSL session data π
πΈ SYNOPSIS πΈ
like, here's the whole vibe, copy-paste ready:
#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 π
okay so, three functions, one job, and the difference is literally just the reference count. let's break it down fr fr:
SSL_get_session()β returns a pointer to theSSL_SESSIONactually used inssl. and bestie, hear me: the reference count of theSSL_SESSIONis not incremented, so that pointer can become invalid by other operations. it's giving borrowed, not gifted πSSL_get0_session()β it's the same asSSL_get_session(). that's it. that's the function. iconic minimalism π«ΆSSL_get1_session()β also the same asSSL_get_session(), BUT the reference count of theSSL_SESSIONis incremented by one. so this one's the one that actually holds on π₯
π NOTES π
alright, pull up a chair, this is the long part but it's important, no cap π§
the ssl session contains all information required to re-establish the connection without a full handshake for SSL versions up to and including TLSv1.2. in TLSv1.3 the same is true, but sessions are established after the main handshake has occurred. the server will send the session information to the client at a time of its choosing β which may be some while after the initial connection is established (or never, if the server is being like that π).
so if you call these functions on the client side in TLSv1.3 before the session has been established, you'll still get an SSL_SESSION object back, but lowkey that object cannot be used for resuming the session. to figure out whether an SSL_SESSION object can be used for resumption or not, go read SSL_SESSION_is_resumable(3). it's got the answers you need π
also, and this is the tea: in TLSv1.3, a server can send multiple messages that establish a session for a single connection. in that case:
- on the client side, the above functions will only return information on the last session that was received.
- on the server side, they will only return information on the last session that was sent β or, if no session tickets were sent, then the session for the current connection.
the preferred way for applications to obtain a resumable SSL_SESSION object is to use a new session callback as described in SSL_CTX_sess_set_new_cb(3). the new session callback is only invoked when a session is actually established, so this avoids the whole problem described above where an application obtains an SSL_SESSION object that cannot be used for resumption in TLSv1.3. plus it also enables applications to obtain information about all sessions sent by the server. obsessed with that for real β¨
now, a session will be automatically removed from the session cache and marked as non-resumable if the connection is not closed down cleanly β like, e.g., if a fatal error occurs on the connection, or SSL_shutdown(3) is not called prior to SSL_free(3). so be a good citizen and close your connections properly, bestie π
and inTLSv1.3it is recommended that eachSSL_SESSIONobject is only used for resumption once. periodt.
okay so SSL_get0_session() returns a pointer to the actual session. since the reference counter is not incremented, that 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 it's considered bad), and the pointer you obtained will become invalid. and even if the session is valid, it can be removed at any time due to timeout during SSL_CTX_flush_sessions(3). so like... don't hold onto it, okay? π
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. to remove the session, SSL_SESSION_free(3) must be explicitly called once to decrement the reference count again. one call, one decrement, that's the deal π
and one more thing β SSL_SESSION objects keep internal link information about the session cache list when being inserted into one SSL_CTX object's session cache. so 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). no sharing, no cross-pollinating, it's a monogamous situation π
β RETURN VALUES β
the following return values can occur:
NULLβ there is no session available inssl. it's empty, babes, nothing there π- Pointer to an
SSL_SESSIONβ the return value points to the data of an SSL session. yay, success, slay π
π¦ SEE ALSO π¦
go check out the bestie pages too, iykyk:
π COPYRIGHT π
Copyright 2000-2018 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>.
and that's the whole page, bestie!! this was OpenSSL version 4.0.3, dated 2026-09-29 β mwah, go forth and manage your sessions responsibly πβ¨ππ«Ά
π¦ where this page comes from
- ubuntu stonking: libssl-doc 4.0.3-1ubuntu1 Β· Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms