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