jcs's openbsd hax
openbsd
1.\" $OpenBSD: SSL_CTX_set_msg_callback.3,v 1.6 2025/06/08 22:52:00 schwarze Exp $
2.\" OpenSSL SSL_CTX_set_msg_callback.pod e9b77246 Jan 20 19:58:49 2017 +0100
3.\" OpenSSL SSL_CTX_set_msg_callback.pod b97fdb57 Nov 11 09:33:09 2016 +0100
4.\"
5.\" This file was written by Bodo Moeller <bodo@openssl.org>.
6.\" Copyright (c) 2001, 2014, 2016 The OpenSSL Project. All rights reserved.
7.\"
8.\" Redistribution and use in source and binary forms, with or without
9.\" modification, are permitted provided that the following conditions
10.\" are met:
11.\"
12.\" 1. Redistributions of source code must retain the above copyright
13.\" notice, this list of conditions and the following disclaimer.
14.\"
15.\" 2. Redistributions in binary form must reproduce the above copyright
16.\" notice, this list of conditions and the following disclaimer in
17.\" the documentation and/or other materials provided with the
18.\" distribution.
19.\"
20.\" 3. All advertising materials mentioning features or use of this
21.\" software must display the following acknowledgment:
22.\" "This product includes software developed by the OpenSSL Project
23.\" for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
24.\"
25.\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26.\" endorse or promote products derived from this software without
27.\" prior written permission. For written permission, please contact
28.\" openssl-core@openssl.org.
29.\"
30.\" 5. Products derived from this software may not be called "OpenSSL"
31.\" nor may "OpenSSL" appear in their names without prior written
32.\" permission of the OpenSSL Project.
33.\"
34.\" 6. Redistributions of any form whatsoever must retain the following
35.\" acknowledgment:
36.\" "This product includes software developed by the OpenSSL Project
37.\" for use in the OpenSSL Toolkit (http://www.openssl.org/)"
38.\"
39.\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40.\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43.\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50.\" OF THE POSSIBILITY OF SUCH DAMAGE.
51.\"
52.Dd $Mdocdate: June 8 2025 $
53.Dt SSL_CTX_SET_MSG_CALLBACK 3
54.Os
55.Sh NAME
56.Nm SSL_CTX_set_msg_callback ,
57.Nm SSL_CTX_set_msg_callback_arg ,
58.Nm SSL_set_msg_callback ,
59.Nm SSL_set_msg_callback_arg
60.Nd install callback for observing protocol messages
61.Sh SYNOPSIS
62.Lb libssl libcrypto
63.In openssl/ssl.h
64.Ft void
65.Fo SSL_CTX_set_msg_callback
66.Fa "SSL_CTX *ctx"
67.Fa "void (*cb)(int write_p, int version, int content_type, const void *buf, size_t len, SSL *ssl, void *arg)"
68.Fc
69.Ft void
70.Fn SSL_CTX_set_msg_callback_arg "SSL_CTX *ctx" "void *arg"
71.Ft void
72.Fo SSL_set_msg_callback
73.Fa "SSL *ssl"
74.Fa "void (*cb)(int write_p, int version, int content_type, const void *buf, size_t len, SSL *ssl, void *arg)"
75.Fc
76.Ft void
77.Fn SSL_set_msg_callback_arg "SSL *ssl" "void *arg"
78.Sh DESCRIPTION
79.Fn SSL_CTX_set_msg_callback
80or
81.Fn SSL_set_msg_callback
82can be used to define a message callback function
83.Fa cb
84for observing all SSL/TLS protocol messages (such as handshake messages)
85that are received or sent.
86.Fn SSL_CTX_set_msg_callback_arg
87and
88.Fn SSL_set_msg_callback_arg
89can be used to set argument
90.Fa arg
91to the callback function, which is available for arbitrary application use.
92.Pp
93.Fn SSL_CTX_set_msg_callback
94and
95.Fn SSL_CTX_set_msg_callback_arg
96specify default settings that will be copied to new
97.Vt SSL
98objects by
99.Xr SSL_new 3 .
100.Fn SSL_set_msg_callback
101and
102.Fn SSL_set_msg_callback_arg
103modify the actual settings of an
104.Vt SSL
105object.
106Using a
107.Dv NULL
108pointer for
109.Fa cb
110disables the message callback.
111.Pp
112When
113.Fa cb
114is called by the SSL/TLS library for a protocol message,
115the function arguments have the following meaning:
116.Bl -tag -width Ds
117.It Fa write_p
118This flag is 0 when a protocol message has been received and 1 when a protocol
119message has been sent.
120.It Fa version
121The protocol version according to which the protocol message is
122interpreted by the library, such as
123.Dv TLS1_VERSION ,
124.Dv TLS1_1_VERSION ,
125.Dv TLS1_2_VERSION ,
126.Dv DTLS1_VERSION ,
127or
128.Dv DTLS1_2_VERSION .
129.It Fa content_type
130This is one of the
131.Em ContentType
132values defined in the protocol specification
133.Po
134.Dv SSL3_RT_CHANGE_CIPHER_SPEC ,
135.Dv SSL3_RT_ALERT ,
136.Dv SSL3_RT_HANDSHAKE ,
137but never
138.Dv SSL3_RT_APPLICATION_DATA
139because the callback will only be called for protocol messages.
140.Pc
141.It Fa buf , Fa len
142.Fa buf
143points to a buffer containing the protocol message, which consists of
144.Fa len
145bytes.
146The buffer is no longer valid after the callback function has returned.
147.It Fa ssl
148The
149.Vt SSL
150object that received or sent the message.
151.It Fa arg
152The user-defined argument optionally defined by
153.Fn SSL_CTX_set_msg_callback_arg
154or
155.Fn SSL_set_msg_callback_arg .
156.El
157.Pp
158Protocol messages are passed to the callback function after decryption
159and fragment collection where applicable.
160(Thus record boundaries are not visible.)
161.Pp
162If processing a received protocol message results in an error,
163the callback function may not be called.
164For example, the callback function will never see messages that are considered
165too large to be processed.
166.Pp
167Due to automatic protocol version negotiation,
168.Fa version
169is not necessarily the protocol version used by the sender of the message:
170If a TLS 1.0 ClientHello message is received by an SSL 3.0-only server,
171.Fa version
172will be
173.Dv SSL3_VERSION .
174.Sh SEE ALSO
175.Xr ssl 3 ,
176.Xr SSL_new 3
177.Sh HISTORY
178.Fn SSL_CTX_set_msg_callback ,
179.Fn SSL_CTX_set_msg_callback_arg ,
180.Fn SSL_set_msg_callback
181and
182.Fn SSL_set_msg_callback_arg
183first appeared in OpenSSL 0.9.7 and have been available since
184.Ox 3.2 .