SSL_SESSION_GET0_CIPHER(3SSL)

πŸ’– SSL_SESSION_GET0_CIPHER πŸ’–

okay bestie, so this is a page from the OpenSSL manual, section 3SSL β€” that's the "library functions" section for SSL/TLS stuff. We're talking about getting and setting the cipher that's attached to an SSL session. Cute little duo of functions. Let's get into it πŸŽ€


✨ NAME ✨

SSL_SESSION_get0_cipher, SSL_SESSION_set_cipher β€” grab the SSL cipher linked to a session, or set it. two directions, one glow-up πŸ’…


🌸 SYNOPSIS 🌸

#include <openssl/ssl.h>

const SSL_CIPHER *SSL_SESSION_get0_cipher(const SSL_SESSION *s);
int SSL_SESSION_set_cipher(SSL_SESSION *s, const SSL_CIPHER *cipher);

πŸ¦‹ DESCRIPTION πŸ¦‹

SSL_SESSION_get0_cipher() pulls out the cipher that the connection was using back when the session got created. Literally retrieves it for you. And if it can't figure out which cipher it was? You get NULL, no cipher, nothing, empty. 😭

heads up bestie β€” the thing it hands you is a pointer to an object that lives inside s itself. so do not release it. not yours to free. hands off 🫢

SSL_SESSION_set_cipher() is the other direction, the main character move: it lets you set the ciphersuite associated with the SSL_SESSION s to cipher. Like, what's it for? For example, you could use it to set up a session based PSK β€” check SSL_CTX_set_psk_use_session_callback(3) for the deets ✨


πŸ’« RETURN VALUES πŸ’«

  • SSL_SESSION_get0_cipher() β€” returns the SSL_CIPHER associated with the SSL_SESSION, or NULL if it just cannot be determined. no cipher, no answer, sorry babes πŸ’€
  • SSL_SESSION_set_cipher() β€” returns 1 on success, or 0 if it failed. simple as that.

πŸ‘‘ SEE ALSO πŸ‘‘

go read those too, they're all part of the same little friend group 🌈


⭐ HISTORY ⭐

  • SSL_SESSION_get0_cipher() β€” made its debut in OpenSSL 1.1.0
  • SSL_SESSION_set_cipher() β€” showed up a little later, in OpenSSL 1.1.1

glow-up timeline, honestly πŸ’…


Copyright 2016-2017 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>.


aaaaand that's the whole page, bestie πŸŽ€ no cap, every flag, every return value, every see-also link β€” all accounted for. this iconic little manpage is from OpenSSL 4.0.3, dated 2026-09-29, and yes it lives in section 3SSL. slay, go forth and cipher responsibly πŸ’–βœ¨πŸ¦‹

πŸ“¦ where this page comes from