SSL_CTX_SET_INFO_CALLBACK(3ossl)
π SSL_CTX_SET_INFO_CALLBACK π
okay so bestie, this one's from the OpenSSL manual, section 3ossl, and it's genuinely so useful β it's all about getting little ping notifications from the SSL/TLS engine when stuff happens β¨
πΈ 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 π
π 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);
π¦ DESCRIPTION π¦
SSL_CTX_set_info_callback()β sets the callback function that you can use to obtain state information for SSL objects created from ctx, during connection setup and use. Slay. The setting for ctx gets overridden by the setting for a specific SSL object, if one is specified. And when callback isNULL, no callback function is used at all β vibes only, no notifications.SSL_set_info_callback()β sets the callback function that you can use to obtain state information for ssl during connection setup and use. When callback isNULL, the callback setting currently valid for ctx is used. Ngl, ssl MUST NOT beNULLβ like, that's a hard no, do not do that πSSL_CTX_get_info_callback()β returns a pointer to the currently set information callback function for ctx. It's giving "what's my callback rn" energy.SSL_get_info_callback()β returns a pointer to the currently set information callback function for ssl. Same vibe, different scope.
β¨ NOTES β¨
When setting up a connection and during use, it is literally possible to obtain state information from the SSL/TLS engine. When set, an information callback function is called whenever a significant event occurs such as: the state changes, an alert appears, or an error occurs. π₯
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 like that πSSL_CB_EXITβ Callback has been called to indicate exit of a handshake function. This will happen 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 read operation.SSL_CB_WRITEβ Callback has been called during write operation.SSL_CB_ALERTβ Callback has been called due to an alert being sent or received.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. β
π RETURN VALUES π
SSL_set_info_callback()β does not provide diagnostic information. That's it, that's the whole answer, she's mysterious like that π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-paste-ready, bestie, go off π«Ά
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));
}
}
}
π SEE ALSO π
ssl(7), SSL_state_string(3), SSL_alert_type_string(3) β go read these next, iykyk π
π 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>.
aaand that's the whole page, bestie, you ate that π this was OpenSSL 3.5.0, dated 2026-09-25, closing out the SSL_CTX_SET_INFO_CALLBACK(3ossl) page β mwah, periodt πβ¨
π¦ where this page comes from
- opensuse-leap 16.0: openssl-3-doc 3.5.0-160000.11.1 Β· Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms