SSL_SESSION_GET0_CIPHER(3ossl)

πŸ’– SSL_SESSION_GET0_CIPHER πŸ’–

okay bestie, so this is the SSL_SESSION_GET0_CIPHER(3ossl) page from the OpenSSL manuals, and it's lowkey one of the cutest little corner-of-the-library situations ever. two functions. that's it. they peek at a session's cipher and they set a session's cipher. that's the whole vibe. let's get into it πŸŽ€


✨ NAME ✨

SSL_SESSION_get0_cipher, SSL_SESSION_set_cipher β€” set and retrieve the SSL cipher associated with a session. literally that's the job description, no notes πŸ’…


🌸 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);

two lines of header include, two function signatures, and we're done. the way that the whole thing fits on a sticky note 😭


πŸ¦‹ DESCRIPTION πŸ¦‹

okay so first up, SSL_SESSION_get0_cipher() retrieves the cipher that was used by the connection when the session was created. and if it can't be determined? you get NULL. that's it, that's the deal 🫢

now the important part, bestie, listen: the value returned is a pointer to an object that's maintained within s, and it should not be released. so do not go freeing it. do not go thinking you own it. it's not yours, it lives inside the session, hands off πŸ™ˆ

then we've got SSL_SESSION_set_cipher(), which you can use to set the ciphersuite associated with the SSL_SESSION s to cipher. and like, a genuinely iconic use case: this could be used to set up a session based PSK β€” go look at SSL_CTX_set_psk_use_session_callback(3) if you want the whole lore. iykyk ✨


πŸ‘‘ RETURN VALUES πŸ‘‘

  • SSL_SESSION_get0_cipher() returns the SSL_CIPHER associated with the SSL_SESSION, or NULL if it cannot be determined. yes, NULL again. it's giving mysterious on purpose πŸ’€
  • SSL_SESSION_set_cipher() returns 1 on success or 0 on failure. classic OpenSSL binary, no in-between, no crumbs.

🌈 SEE ALSO 🌈

everything that lives near this page in the friend group:

go read all of them, fr fr, they're all connected πŸ“š


⭐ HISTORY ⭐

  • SSL_SESSION_get0_cipher() was added in OpenSSL 1.1.0.
  • SSL_SESSION_set_cipher() was added in OpenSSL 1.1.1.

so set_cipher is the baby of the two. a whole patch release younger. iconic in its own right 🍼


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>.

okay real talk, the license part is the one bit you can't vibe your way around β€” read it, respect it, don't skip it πŸŽ€

and that's the whole page, bestie!! this was OpenSSL 3.5.9, dated 2026-09-29, and yes the manual name is right there in the header like always. go forth and never free that cipher pointer. mwah πŸ’–βœ¨

πŸ“¦ where this page comes from