SSL_GET_CURRENT_CIPHER(3ossl)

πŸ“¦ version 3.5.0, in opensuse-leap 16.0

πŸ’… SSL_GET_CURRENT_CIPHER(3ossl) β€” the OpenSSL manual, but make it make sense

okay so bestie, this is the 3ossl page about figuring out which cipher is actually doing the work on your TLS connection. yes, ciphers. yes, the little cryptographic handshake outfits your connection is wearing. we're getting the SSL_CIPHER of a connection and honestly? iconic. πŸ”₯


✨ NAME ✨

SSL_get_current_cipher, SSL_get_cipher_name, SSL_get_cipher, SSL_get_cipher_bits, SSL_get_cipher_version, SSL_get_pending_cipher β€” all of these are here to get the SSL_CIPHER of a connection. that's the whole vibe. πŸŽ€


🌸 SYNOPSIS 🌸

#include <openssl/ssl.h>

const SSL_CIPHER *SSL_get_current_cipher(const SSL *ssl);
const SSL_CIPHER *SSL_get_pending_cipher(const SSL *ssl);

const char *SSL_get_cipher_name(const SSL *s);
const char *SSL_get_cipher(const SSL *s);
int SSL_get_cipher_bits(const SSL *s, int *np);
const char *SSL_get_cipher_version(const SSL *s);

like, copy-paste it exactly, don't come for me. πŸ’œ


πŸ¦‹ DESCRIPTION πŸ¦‹

the main character: SSL_get_current_cipher()

SSL_get_current_cipher() hands you back a pointer to an SSL_CIPHER object β€” and that object is literally the description of the cipher actually being used on a connection that was established with the ssl object. no cap.

⚠️ <red>ssl MUST NOT be NULL.</red> like for real for real, don't do that. πŸ’€

if you want more deets on the cipher object itself, go see SSL_CIPHER_get_name(3). iykyk.

the little helpers 🧚

  • SSL_get_cipher_name() β€” gets you the name of the cipher that's currently in use. slay.
  • SSL_get_cipher() β€” literally identical to SSL_get_cipher_name(). twins. same energy. πŸ‘―
  • SSL_get_cipher_bits() β€” this one's a macro, and it gets you the number of secret/algorithm bits used. numbers, we love her.
  • SSL_get_cipher_version() β€” returns the protocol name. cute.

the mysterious one: SSL_get_pending_cipher() πŸ™ˆ

SSL_get_pending_cipher() returns a pointer to an SSL_CIPHER object containing the description of the cipher (if any) that's been negotiated for future use on the connection established with the ssl object β€” but is not yet in use.

when does that even happen? during handshake processing, babes β€” specifically when control flow can be returned to the application via any of several callback methods. so you're mid-handshake, a callback fires, and you're like "wait what cipher are we gonna use πŸ‘€".

πŸ’€ big caveat time: the internal sequencing of handshake processing and callback invocation is not guaranteed to be stable from release to release. and at present only the callback set by SSL_CTX_set_alpn_select_cb() is guaranteed to have a non-NULL return value. other callbacks may be added to this list over time. so like… don't build your whole personality on it, yk? 🫢

⭐ RETURN VALUES ⭐

  • SSL_get_current_cipher() β€” returns the cipher actually used, or NULL if no session has been established. (no session? no cipher. simple as that.)
  • SSL_get_pending_cipher() β€” returns the cipher to be used at the next change of cipher suite, or NULL if no such cipher is known.

like, NULL is always a possibility bestie, check your returns. 🌈


πŸŽ€ NOTES πŸŽ€

heads up: SSL_get_cipher, SSL_get_cipher_bits, SSL_get_cipher_version, and SSL_get_cipher_name are implemented as macros. so like, they're not real functions, they're macros serving looks. πŸ’…


πŸ‘‘ SEE ALSO πŸ‘‘

go read those too, they're giving lore. πŸ“šβœ¨


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 tea πŸ“ β€” this page is from OpenSSL 3.5.0, dated 2026-09-25, and it's SSL_GET_CURRENT_CIPHER(3ossl) in case you forgot where you were. go get that cipher, bestie, you're gonna ate. πŸ’œπŸ¦‹βœ¨

πŸ“¦ where this page comes from