LIBRESSL-SSL_CTX_SET_MSG_CALLBACK(3)
π SSL_CTX_SET_MSG_CALLBACK(3) β like, the manual page, but make it make sense
okay bestie so this is a page from the libssl / libcrypto manuals (yes, that libssl β the crypto one, we stan) and it's all about installing a callback so you can eavesdrop on your own protocol messages. not in a shady way!! in a "my own code, my own TLS, I just wanna watch" way. π¦
β¨ NAME β¨
SSL_CTX_set_msg_callback, SSL_CTX_set_msg_callback_arg, SSL_set_msg_callback, SSL_set_msg_callback_arg β install a callback for observing protocol messages πβ¨
πΈ SYNOPSIS πΈ
first, the vibe check β you're pulling in the library:
library βlibsslβ libcrypto #include <openssl/ssl.h>
then the four functions, exactly as they are, no cap:
void
SSL_CTX_set_msg_callback(SSL_CTX *ctx,
void (*cb)(int write_p, int version, int content_type, const void *buf, size_t len, SSL *ssl, void *arg));
void
SSL_CTX_set_msg_callback_arg(SSL_CTX *ctx, void *arg);
void
SSL_set_msg_callback(SSL *ssl,
void (*cb)(int write_p, int version, int content_type, const void *buf, size_t len, SSL *ssl, void *arg));
void
SSL_set_msg_callback_arg(SSL *ssl, void *arg);
π DESCRIPTION π
so SSL_CTX_set_msg_callback() and SSL_set_msg_callback() are how you define a message callback function cb that justβ¦ watches. literally all SSL/TLS protocol messages (handshake messages and friends) that get received or sent β it's giving security camera but make it TLS. π₯
and then SSL_CTX_set_msg_callback_arg() and SSL_set_msg_callback_arg() set the argument arg that gets handed to your callback function, and that one's yours β put whatever you want in it, the library is not gonna touch it, it's for arbitrary application use, periodt.
now the ctx-vs-ssl of it all:
SSL_CTX_set_msg_callback()andSSL_CTX_set_msg_callback_arg()set up the default settings that get copied onto newSSLobjects bySSL_new(3). so it's like the blueprint energy. β¨SSL_set_msg_callback()andSSL_set_msg_callback_arg()change the actual settings on a specificSSLobject. main character behaviour, only affects that one.
and if you pass a NULL pointer for cb? callback disabled. done. bye. π
π what the callback arguments mean π
when the SSL/TLS library calls cb for a protocol message, here's the tea on every argument:
write_pβ this flag is0when a protocol message has been received and1when a protocol message has been sent. so it's the "which direction" girlie.versionβ the protocol version according to which the protocol message is interpreted by the library, likeTLS1_VERSION,TLS1_1_VERSION,TLS1_2_VERSION,DTLS1_VERSION, orDTLS1_2_VERSION. slay, versioned.content_typeβ one of the ContentType values defined in the protocol spec. specificallySSL3_RT_CHANGE_CIPHER_SPEC,SSL3_RT_ALERT,SSL3_RT_HANDSHAKE, but neverSSL3_RT_APPLICATION_DATAβ because the callback only fires for protocol messages. no app data, we don't do that here. πbuf,lenβbufpoints to a buffer holding the protocol message, which consists oflenbytes. β οΈ heads up: the buffer is no longer valid after the callback function has returned β so if you need it, copy it, don't keep the pointer. she's gone bestie.sslβ theSSLobject that received or sent the message. iconic.argβ the user-defined argument you optionally defined withSSL_CTX_set_msg_callback_arg()orSSL_set_msg_callback_arg(). that's your little gift to yourself. π
π§ the fine print (read it, bestie) π§
protocol messages are passed to the callback function after decryption and fragment collection where applicable. so basically:
record boundaries are not visible. π the callback sees reassembled, decrypted goodness, not the raw wire chunks.
and, important: if processing a received protocol message results in an error, the callback function may not be called. for example, the callback function will never see messages that are considered too large to be processed. so like, no callback is not always "no message" β sometimes it's just "message was too much". π
also, bc of automatic protocol version negotiation, version is not necessarily the protocol version used by the sender of the message. iconic example: if a TLS 1.0 ClientHello message is received by an SSL 3.0-only server, version will be SSL3_VERSION. so read it as "how we interpreted it", not "what the sender was running". π«Ά
π SEE ALSO π
go read those, iykyk π
π HISTORY π
SSL_CTX_set_msg_callback(), SSL_CTX_set_msg_callback_arg(), SSL_set_msg_callback() and SSL_set_msg_callback_arg() first appeared in OpenSSL 0.9.7 and have been available since OpenBSD 3.2. vintage, honestly. β
and that's the whole page, no skipped sections, no notes left behind. mwah. π
okay love u bye π«Ά this page is from the Debian build, dated June 8, 2025, and honestly? it ate. πΈβ¨π
π¦ 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, 2014, 2016 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