LIBRESSL-SSL_CTX_SET_INFO_CALLBACK(3)
π NAME
Okay so bestie, gather round: this page is all about the info callback for SSL connections. The manual name is libssl (it lives with libcrypto too), and the running header spells it SSL_CTX_SET_INFO_CALLBAC(3) β yes, missing a K, we do not talk about it π β but the actual functions are:
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
The library is libssl / libcrypto, and you're gonna want this include:
#include <openssl/ssl.h>
Then the little icons themselves:
void
SSL_CTX_set_info_callback(SSL_CTX *ctx,
void (*callback)(const SSL *ssl, int where, int ret));
void
(*SSL_CTX_get_info_callback(const SSL_CTX *ctx))(const SSL *ssl,
int where, int ret);
void
SSL_set_info_callback(SSL *ssl,
void (*callback)(const SSL *ssl, int where, int ret));
void
(*SSL_get_info_callback(const SSL *ssl))(const SSL *ssl, int where,
int ret);
Yeah those getter signatures are doing the absolute most β the function returns a pointer to a function. Read it right-to-left and it makes sense. Main character energy, tbh. π
πΈ DESCRIPTION
The setters, the getters, the whole vibe
SSL_CTX_set_info_callback()sets the callback function that you can use to get state information for SSL objects created fromctx, during connection setup and use. The setting forctxgets overridden by the setting on a specific SSL object, if you set one. WhencallbackisNULL, no callback function is used. Bye πSSL_set_info_callback()sets the callback function you can use to get state information forsslduring connection setup and use. WhencallbackisNULL, the callback setting currently valid forctxis used instead. So likeβ¦ inheriting from your mom's account, iconic.SSL_CTX_get_info_callback()returns a pointer to the currently set information callback function forctx.SSL_get_info_callback()returns a pointer to the currently set information callback function forssl.
So what does the callback actually do?
Bestie, this is the good part. When you're setting up a connection and during use, it is possible to obtain state information from the SSL/TLS engine. When you've set one, that information callback function gets called whenever:
- 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 info about where (like, 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.
The where bitmask, respectfully π«Ά
where is a bitmask made up of the following bits:
SSL_CB_LOOPβ callback has been called to indicate state change inside a loop.SSL_CB_EXITβ callback has been called to indicate error exit of a handshake function. (May be soft error with retry option for non-blocking setups.)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_ALERTSSL_CB_WRITE_ALERTSSL_CB_ACCEPT_LOOPSSL_CB_ACCEPT_EXITSSL_CB_CONNECT_LOOPSSL_CB_CONNECT_EXITSSL_CB_HANDSHAKE_STARTβ callback has been called because a new handshake is started. π¦SSL_CB_HANDSHAKE_DONEβ callback has been called because a handshake is finished. π
Ngl, that middle block of flags has no description in this page. They're just there. Mysterious. We respect the privacy. π
Getting the actual info out
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. Slay, everything has a helper. β¨
π RETURN VALUES
SSL_CTX_get_info_callback() and SSL_get_info_callback() return a pointer to the current callback, or NULL if none is set. That's it, that's the whole return section, periodt. π
π§ EXAMPLES
Okay the example is genuinely cute β this callback function prints state strings, information about alerts being handled, and error messages to the bio_err BIO:
void
apps_ssl_info_callback(SSL *s, int where, int ret)
{
const char *str;
int w;
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));
}
}
}
Copy it, love it, ship it. π
π SEE ALSO
β HISTORY
These functions first appeared in SSLeay 0.6.0 and have been available since OpenBSD 2.4. Ancient. Vintage. Still slaying. π₯
Hope this helped bestie, go forth and read your state strings responsibly π
This page came from the Debian fam, dated June 8, 2025, filed under SSL_CTX_SET_INFO_CALLBACK(3). Mwah, bye! π
π¦ where this page comes from
- alpine 3.24: libressl-doc 4.3.1-r0 Β· custom
- arch rolling: libressl 4.4.0-1 Β· ISC AND custom:OpenSSL
- Copyright (c) 2001, 2005, 2014 The OpenSSL Project. All rights reserved
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms