LIBRESSL-SSL_CTX_SET_INFO_CALLBACK(3)

πŸ“¦ version 4.4.0, in alpine 3.24, arch rolling

πŸ’… 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 from ctx, during connection setup and use. The setting for ctx gets overridden by the setting on a specific SSL object, if you set one. When callback is NULL, no callback function is used. Bye πŸ‘‹
  • SSL_set_info_callback() sets the callback function you can use to get state information for ssl during connection setup and use. When callback is NULL, the callback setting currently valid for ctx is 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 for ctx.
  • SSL_get_info_callback() returns a pointer to the currently set information callback function for ssl.

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_ALERT
  • SSL_CB_WRITE_ALERT
  • SSL_CB_ACCEPT_LOOP
  • SSL_CB_ACCEPT_EXIT
  • SSL_CB_CONNECT_LOOP
  • SSL_CB_CONNECT_EXIT
  • SSL_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