SSL_SESSION_GET_TIME(3ossl)

πŸ’– SSL_SESSION_GET_TIME πŸ’– (the 3ossl girlies know)

okay so bestie, welcome to the manual page for SSL_SESSION_GET_TIME and her whole friend group β€” the OpenSSL functions that let you peek at and poke at a session's time and timeout settings. this is giving "clock management but make it TLS" and honestly? we're obsessed. ⏰✨


🌸 NAME 🌸

SSL_SESSION_get_time, SSL_SESSION_set_time, SSL_SESSION_get_timeout, SSL_SESSION_set_timeout, SSL_SESSION_get_time_ex, SSL_SESSION_set_time_ex, SSL_get_time, SSL_set_time, SSL_get_timeout, SSL_set_timeout β€” these are the besties that retrieve and manipulate session time and timeout settings. periodt. πŸ’…


✨ SYNOPSIS ✨

first things first, you gotta include the header, no cap:

#include <openssl/ssl.h>

now here's the main squad, all glow-up'd and not deprecated:

long SSL_SESSION_get_timeout(const SSL_SESSION *s);
long SSL_SESSION_set_timeout(SSL_SESSION *s, long tm);

long SSL_get_timeout(const SSL_SESSION *s);
long SSL_set_timeout(SSL_SESSION *s, long tm);

time_t SSL_SESSION_get_time_ex(const SSL_SESSION *s);
time_t SSL_SESSION_set_time_ex(SSL_SESSION *s, time_t tm);

and now the elders. these ones have been deprecated since OpenSSL 3.4, and you can hide them entirely by defining OPENSSL_API_COMPAT with a suitable version value β€” go look at openssl_user_macros(7) for the deets, iykyk:

long SSL_SESSION_get_time(const SSL_SESSION *s);
long SSL_SESSION_set_time(SSL_SESSION *s, long tm);
long SSL_get_time(const SSL_SESSION *s);
long SSL_set_time(SSL_SESSION *s, long tm);

πŸ¦‹ DESCRIPTION πŸ¦‹

let's get into it, one function at a time, because we don't gatekeep here:

SSL_SESSION_get_time_ex() returns the time at which the session s was established. the time is given in seconds since the Epoch, which means it's compatible with whatever time() hands you back. iconic behavior honestly. πŸŽ€

SSL_SESSION_set_time_ex() replaces the creation time of the session s with the chosen value tm. you get to rewrite history. main character energy.

SSL_SESSION_get_timeout() returns the timeout value set for session s, in seconds. πŸ•

SSL_SESSION_set_timeout() sets the timeout value for session s, in seconds, to tm.

SSL_SESSION_get_time() and SSL_SESSION_set_time() use the long datatype instead of time_t, which is exactly why they're deprecated β€” they're not Y2038-safe on 32 bit systems. 😭 and heads up: those systems still need to be configured to use 64 bit time_t to actually avoid overflow in system time. no shortcuts, bestie.

SSL_get_time(), SSL_set_time(), SSL_get_timeout(), and SSL_set_timeout() are just synonyms for their SSL_SESSION_*() counterparts. same vibes, different name. πŸ’œ


πŸ“ NOTES πŸ“

so how do sessions actually expire? by examining the creation time and the timeout value. both get set at the creation time of the session β€” to the actual time, and to the default timeout value at creation, respectively, as set by SSL_CTX_set_timeout(3).

and with these functions? you can extend or shorten the lifetime of the session. you're literally the one holding the clock. ⏳✨


πŸ’« RETURN VALUES πŸ’«

here's what you get back, fr fr:

  • SSL_SESSION_get_time_ex() and SSL_SESSION_get_timeout() return the currently valid values.
  • SSL_SESSION_set_time_ex() returns time on success.
  • SSL_SESSION_set_timeout() returns 1 on success.
  • and if any of the functions gets passed the NULL pointer for the session s, 0 is returned. sad but true. πŸ™ˆ

πŸ’€ BUGS πŸ’€

the data type long is typically 32 bits on many systems, which is why the old functions SSL_SESSION_get_time() and SSL_SESSION_set_time() are not always Y2038 safe. the drama of it all.

bestie please, use the _ex versions. your future self in 2038 will thank you. 🫢

πŸ‘‘ SEE ALSO πŸ‘‘


🌈 HISTORY 🌈

the functions SSL_SESSION_get_time_ex() and SSL_SESSION_set_time_ex() were added in OpenSSL 3.3. glow-up acquired. ⭐


Copyright 2001-2024 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 3.5.9, dated 2026-09-29, and yeah it's still SSL_SESSION_GET_TIME(3ossl) at the end of the day β€” slay, hydrate, and set your timeouts responsibly. πŸŒΈπŸ’…πŸ¦‹

πŸ“¦ where this page comes from