SSL_CTX_SET_INFO_CALLBACK(3ossl)
π SSL_CTX_SET_INFO_CALLBACK(3ossl) β the OpenSSL info-callback glow-up π
okay so bestie, this is the <pink>OpenSSL</pink> manual page SSL_CTX_SET_INFO_CALLBACK(3ossl) and it's literally all about the four functions that let you peek at what your SSL connection is doing while it's doing it. gossip girl energy but for handshake state β¨
πΈ NAME πΈ
SSL_CTX_set_info_callback, SSL_CTX_get_info_callback, SSL_set_info_callback, SSL_get_info_callback β handle information callback for SSL connections π¦
like, these are the four besties that let you install (and inspect) a callback that gets pinged with state info. no cap.
β SYNOPSIS β
#include <openssl/ssl.h>
void SSL_CTX_set_info_callback(SSL_CTX *ctx,
void (*callback) (const SSL *ssl, int type, int val));
void (*SSL_CTX_get_info_callback(SSL_CTX *ctx)) (const SSL *ssl, int type, int val);
void SSL_set_info_callback(SSL *ssl,
void (*callback) (const SSL *ssl, int type, int val));
void (*SSL_get_info_callback(const SSL *ssl)) (const SSL *ssl, int type, int val);
look at those return types, they're giving "function returning a function pointer" main character energy π the function-pointer-returning-a-function-pointer situation is iconic and also slightly unhinged, but we respect it.
π DESCRIPTION π
SSL_CTX_set_info_callback()β sets the callback function that can be used to obtain state information for SSL objects created from ctx during connection setup and use. the setting for ctx gets overridden by the setting for a specific SSL object, if one is specified. when callback isNULL, no callback function is used. periodt.SSL_set_info_callback()β sets the callback function that can be used to obtain state information for ssl during connection setup and use. when callback isNULL, the callback setting currently valid for ctx is used instead (so it falls back to the context's vibe π«). ssl MUST NOT beNULL.SSL_CTX_get_info_callback()β returns a pointer to the currently set information callback function for ctx.SSL_get_info_callback()β returns a pointer to the currently set information callback function for ssl.
π¦ NOTES π¦
so when you're setting up a connection and also while it's being used, it is possible to obtain state information from the SSL/TLS engine. when it's set, the information callback function gets called whenever a significant event occurs, such as: the state changes, an alert appears, or an error occurs. literally the group chat notification of the TLS world π
the callback function is called as callback(SSL *ssl, int where, int ret). the where argument specifies information about where (in which context) the callback function was called. if ret is 0, an error condition occurred. if an alert is handled, SSL_CB_ALERT is set and ret specifies the alert information.
where is a bit-mask made up of the following bits π
SSL_CB_LOOPβ callback has been called to indicate state change or some other significant state machine event. this may mean that the callback gets invoked more than once per state in some situations. yes, more than once. she's thorough πSSL_CB_EXITβ callback has been called to indicate exit of a handshake function. this happens after the end of a handshake, but may happen at other times too, such as on error or when IO might otherwise block and nonblocking is being used.SSL_CB_READβ callback has been called during a read operation.SSL_CB_WRITEβ callback has been called during a write operation.SSL_CB_ALERTβ callback has been called due to an alert being sent or received.
and then the combo bits, which are just the above glued together with | π§
SSL_CB_READ_ALERT (SSL_CB_ALERT|SSL_CB_READ)
SSL_CB_WRITE_ALERT (SSL_CB_ALERT|SSL_CB_WRITE)
SSL_CB_ACCEPT_LOOP (SSL_ST_ACCEPT|SSL_CB_LOOP)
SSL_CB_ACCEPT_EXIT (SSL_ST_ACCEPT|SSL_CB_EXIT)
SSL_CB_CONNECT_LOOP (SSL_ST_CONNECT|SSL_CB_LOOP)
SSL_CB_CONNECT_EXIT (SSL_ST_CONNECT|SSL_CB_EXIT)
SSL_CB_HANDSHAKE_STARTβ callback has been called because a new handshake is started. it also occurs when resuming a handshake following a pause to handle early data.SSL_CB_HANDSHAKE_DONEβ callback has been called because a handshake is finished. it also occurs if the handshake is paused to allow the exchange of early data.
the current state information can be obtained using the SSL_state_string(3) family of functions π
the ret information can be evaluated using the SSL_alert_type_string(3) family of functions.
ngl the early-data pause thing trips people up every time β it's in there twice for a reason, bestie, don't skip it π
π RETURN VALUES π
SSL_set_info_callback()β does not provide diagnostic information. she gives you nothing and that's fine π«ΆSSL_get_info_callback()β returns the current setting.
π₯ EXAMPLES π₯
the following example callback function prints state strings, information about alerts being handled and error messages to the bio_err BIO. copy it exactly, she's beautiful:
void apps_ssl_info_callback(const SSL *s, int where, int ret)
{
const char *str;
int w = where & ~SSL_ST_MASK;
if (w & SSL_ST_CONNECT)
str = "SSL_connect";
else if (w & SSL_ST_ACCEPT)
str = "SSL_accept";
else
str = "undefined";
if (where & SSL_CB_LOOP) {
BIO_printf(bio_err, "%s:%s\n", str, SSL_state_string_long(s));
} else if (where & SSL_CB_ALERT) {
str = (where & SSL_CB_READ) ? "read" : "write";
BIO_printf(bio_err, "SSL3 alert %s:%s:%s\n", str,
SSL_alert_type_string_long(ret),
SSL_alert_desc_string_long(ret));
} else if (where & SSL_CB_EXIT) {
if (ret == 0) {
BIO_printf(bio_err, "%s:failed in %s\n",
str, SSL_state_string_long(s));
} else if (ret < 0) {
BIO_printf(bio_err, "%s:error in %s\n",
str, SSL_state_string_long(s));
}
}
}
she ate π
π SEE ALSO π
ssl(7), SSL_state_string(3), SSL_alert_type_string(3)
πΈ COPYRIGHT πΈ
Copyright 2001-2020 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 that's the whole page bestie, no skips, no cap π«Ά this was 3.5.6, dated 2026-04-07, served fresh from SSL_CTX_SET_INFO_CALLBACK(3ossl) β go forth and log your handshakes πβ¨
π¦ where this page comes from
- freebsd 15.1: base 15.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms