SSL_CTX_SET_INFO_CALLBACK(3ossl)

πŸ“¦ version 3.5.0, in opensuse-leap 16.0

πŸ’… 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 is NULL, 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 is NULL, the callback setting currently valid for ctx is used. Ngl, ssl MUST NOT be NULL β€” 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 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