.\" $OpenBSD: SSL_CTX_set_msg_callback.3,v 1.5 2021/04/15 16:43:27 tb Exp $ .\" OpenSSL SSL_CTX_set_msg_callback.pod e9b77246 Jan 20 19:58:49 2017 +0100 .\" OpenSSL SSL_CTX_set_msg_callback.pod b97fdb57 Nov 11 09:33:09 2016 +0100 .\" .\" This file was written by Bodo Moeller . .\" Copyright (c) 2001, 2014, 2016 The OpenSSL Project. All rights reserved. .\" .\" Redistribution and use in source and binary forms, with or without .\" modification, are permitted provided that the following conditions .\" are met: .\" .\" 1. Redistributions of source code must retain the above copyright .\" notice, this list of conditions and the following disclaimer. .\" .\" 2. Redistributions in binary form must reproduce the above copyright .\" notice, this list of conditions and the following disclaimer in .\" the documentation and/or other materials provided with the .\" distribution. .\" .\" 3. All advertising materials mentioning features or use of this .\" software must display the following acknowledgment: .\" "This product includes software developed by the OpenSSL Project .\" for use in the OpenSSL Toolkit. (http://www.openssl.org/)" .\" .\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to .\" endorse or promote products derived from this software without .\" prior written permission. For written permission, please contact .\" openssl-core@openssl.org. .\" .\" 5. Products derived from this software may not be called "OpenSSL" .\" nor may "OpenSSL" appear in their names without prior written .\" permission of the OpenSSL Project. .\" .\" 6. Redistributions of any form whatsoever must retain the following .\" acknowledgment: .\" "This product includes software developed by the OpenSSL Project .\" for use in the OpenSSL Toolkit (http://www.openssl.org/)" .\" .\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY .\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR .\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR .\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, .\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT .\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; .\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, .\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED .\" OF THE POSSIBILITY OF SUCH DAMAGE. .\" .Dd $Mdocdate: April 15 2021 $ .Dt SSL_CTX_SET_MSG_CALLBACK 3 .Os .Sh NAME .Nm SSL_CTX_set_msg_callback , .Nm SSL_CTX_set_msg_callback_arg , .Nm SSL_set_msg_callback , .Nm SSL_set_msg_callback_arg .Nd install callback for observing protocol messages .Sh SYNOPSIS .In openssl/ssl.h .Ft void .Fo SSL_CTX_set_msg_callback .Fa "SSL_CTX *ctx" .Fa "void (*cb)(int write_p, int version, int content_type, const void *buf, size_t len, SSL *ssl, void *arg)" .Fc .Ft void .Fn SSL_CTX_set_msg_callback_arg "SSL_CTX *ctx" "void *arg" .Ft void .Fo SSL_set_msg_callback .Fa "SSL *ssl" .Fa "void (*cb)(int write_p, int version, int content_type, const void *buf, size_t len, SSL *ssl, void *arg)" .Fc .Ft void .Fn SSL_set_msg_callback_arg "SSL *ssl" "void *arg" .Sh DESCRIPTION .Fn SSL_CTX_set_msg_callback or .Fn SSL_set_msg_callback can be used to define a message callback function .Fa cb for observing all SSL/TLS protocol messages (such as handshake messages) that are received or sent. .Fn SSL_CTX_set_msg_callback_arg and .Fn SSL_set_msg_callback_arg can be used to set argument .Fa arg to the callback function, which is available for arbitrary application use. .Pp .Fn SSL_CTX_set_msg_callback and .Fn SSL_CTX_set_msg_callback_arg specify default settings that will be copied to new .Vt SSL objects by .Xr SSL_new 3 . .Fn SSL_set_msg_callback and .Fn SSL_set_msg_callback_arg modify the actual settings of an .Vt SSL object. Using a .Dv NULL pointer for .Fa cb disables the message callback. .Pp When .Fa cb is called by the SSL/TLS library for a protocol message, the function arguments have the following meaning: .Bl -tag -width Ds .It Fa write_p This flag is 0 when a protocol message has been received and 1 when a protocol message has been sent. .It Fa version The protocol version according to which the protocol message is interpreted by the library, such as .Dv TLS1_VERSION , .Dv TLS1_1_VERSION , .Dv TLS1_2_VERSION , .Dv DTLS1_VERSION , or .Dv DTLS1_2_VERSION . .It Fa content_type This is one of the .Em ContentType values defined in the protocol specification .Po .Dv SSL3_RT_CHANGE_CIPHER_SPEC , .Dv SSL3_RT_ALERT , .Dv SSL3_RT_HANDSHAKE , but never .Dv SSL3_RT_APPLICATION_DATA because the callback will only be called for protocol messages. .Pc .It Fa buf , Fa len .Fa buf points to a buffer containing the protocol message, which consists of .Fa len bytes. The buffer is no longer valid after the callback function has returned. .It Fa ssl The .Vt SSL object that received or sent the message. .It Fa arg The user-defined argument optionally defined by .Fn SSL_CTX_set_msg_callback_arg or .Fn SSL_set_msg_callback_arg . .El .Pp Protocol messages are passed to the callback function after decryption and fragment collection where applicable. (Thus record boundaries are not visible.) .Pp 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. .Pp Due to automatic protocol version negotiation, .Fa version is not necessarily the protocol version used by the sender of the message: If a TLS 1.0 ClientHello message is received by an SSL 3.0-only server, .Fa version will be .Dv SSL3_VERSION . .Sh SEE ALSO .Xr ssl 3 , .Xr SSL_new 3 .Sh HISTORY .Fn SSL_CTX_set_msg_callback , .Fn SSL_CTX_set_msg_callback_arg , .Fn SSL_set_msg_callback and .Fn SSL_set_msg_callback_arg first appeared in OpenSSL 0.9.7 and have been available since .Ox 3.2 .