SSL_CTX_SET_KEYLOG_CALLBACK(3ossl)

πŸ’… SSL_CTX_SET_KEYLOG_CALLBACK β€” the OpenSSL one, bestie

okay so this is a page from the OpenSSL manual (you know, the cryptography girlies) and it's all about SSL_CTX_set_keylog_callback, SSL_CTX_get_keylog_callback and SSL_CTX_keylog_cb_func β€” aka logging TLS key material. yes, we're spying on our own handshake. for science. 🧚


✨ NAME ✨

SSL_CTX_set_keylog_callback, SSL_CTX_get_keylog_callback, SSL_CTX_keylog_cb_func β€” logging TLS key material πŸŽ€


🌸 SYNOPSIS 🌸

#include <openssl/ssl.h>

typedef void (*SSL_CTX_keylog_cb_func)(const SSL *ssl, const char *line);

void SSL_CTX_set_keylog_callback(SSL_CTX *ctx, SSL_CTX_keylog_cb_func cb);
SSL_CTX_keylog_cb_func SSL_CTX_get_keylog_callback(const SSL_CTX *ctx);

like, copy that exactly, don't freestyle the signature, ok? πŸ™ˆ


πŸ’– DESCRIPTION πŸ’–

okay so SSL_CTX_set_keylog_callback() sets the TLS key logging callback. this callback gets called whenever TLS key material is generated or received β€” the whole point is letting applications stash that keying material away for debugging purposes. it's giving detective energy πŸ”

SSL_CTX_get_keylog_callback() retrieves the previously set TLS key logging callback. and if no callback has been set? it returns NULL. simple as that. and when there's no key logging callback at all β€” or if SSL_CTX_set_keylog_callback gets called with NULL as the value of cb β€” then no logging of key material will be done. zero. nada. the vibes are silent 🫢

now the callback itself gets called with two items:

  • the ssl object associated with the connection πŸ‘‘
  • line, a string containing the key material in the format used by NSS for its SSLKEYLOGFILE debugging output

and to recreate that file, the key logging callback should log line, followed by a newline. also important, bestie: line will always be a NUL-terminated string. no cap. ✨


πŸ¦‹ RETURN VALUES πŸ¦‹

SSL_CTX_get_keylog_callback() returns a pointer to SSL_CTX_keylog_cb_func, or NULL if the callback is not set. that's it, that's the whole return situation πŸ’œ


🌈 SEE ALSO 🌈


Copyright 2016-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, periodt πŸ’… this was OpenSSL manual page 3.5.9, dated 2026-09-29 β€” go forth and log those keys responsibly, my love πŸŒΈπŸ¦‹β­

πŸ“¦ where this page comes from