
#use wml::openssl-macros area=docs page=SSL_CTX_set_msg_callback

<title>Documents, SSL_CTX_set_msg_callback(3)</title>

<h1>SSL_CTX_set_msg_callback(3)</h1>

#use wml::imp::generic

{:
## What's this? [[s|(<STRONG>[^<].+?)</A>(</STRONG><DD>)|$1$2|sg]]
[[s|<P>\s+<P>|<P>|sg]]
[[s|<P>\s+</|</|sg]]
[[s|<DD>\s*<DT>|<DD>&nbsp;<DT>|sg]]
[[s|<DD>\s*</DL>|<DD>&nbsp;</DL>|sg]]
[[s|\[|&#91;|sg]]
[[s|\]|&#93;|sg]]

<!-- INDEX BEGIN -->

<UL>

	<LI><A HREF="#NAME">NAME</A>
	<LI><A HREF="#SYNOPSIS">SYNOPSIS</A>
	<LI><A HREF="#DESCRIPTION">DESCRIPTION</A>
	<LI><A HREF="#NOTES">NOTES</A>
	<LI><A HREF="#SEE_ALSO">SEE ALSO</A>
	<LI><A HREF="#HISTORY">HISTORY</A>
</UL>
<!-- INDEX END -->

<HR>
<P>
<HR>
<H1><A NAME="NAME">NAME</A></H1>
<P>
SSL_CTX_set_msg_callback, SSL_CTX_set_msg_callback_arg,
SSL_set_msg_callback, SSL_get_msg_callback_arg - install callback for
observing protocol messages

</P>
<P>
<HR>
<H1><A NAME="SYNOPSIS">SYNOPSIS</A></H1>
<PRE> #include &lt;openssl/ssl.h&gt;
</PRE>
<PRE> 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);
</PRE>
<PRE> void SSL_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_set_msg_callback_arg(SSL_CTX *ctx, void *arg);
</PRE>
<P>
<HR>
<H1><A NAME="DESCRIPTION">DESCRIPTION</A></H1>
<P>
<CODE>SSL_CTX_set_msg_callback()</CODE> or
<CODE>SSL_set_msg_callback()</CODE> can be used to define a message
callback function <EM>cb</EM> for observing all SSL/TLS protocol messages (such as handshake messages)
that are received or sent. <CODE>SSL_CTX_set_msg_callback_arg()</CODE> and
<CODE>SSL_set_msg_callback_arg()</CODE> can be used to set argument <EM>arg</EM> to the callback function, which is available for arbitrary application use.

</P>
<P>
<CODE>SSL_CTX_set_msg_callback()</CODE> and
<CODE>SSL_CTX_set_msg_callback_arg()</CODE> specify default settings that
will be copied to new <STRONG>SSL</STRONG> objects by
<A HREF="../ssl/SSL_new.html#">SSL_new(3)</A>. <CODE>SSL_set_msg_callback()</CODE> and
<CODE>SSL_set_msg_callback_arg()</CODE> modify the actual settings of an <STRONG>SSL</STRONG>
object. Using a <STRONG>0</STRONG> pointer for <EM>cb</EM> disables the message callback.

</P>
<P>
When <EM>cb</EM> is called by the SSL/TLS library for a protocol message, the function
arguments have the following meaning:

</P>
<DL>
<DT><STRONG><A NAME="item_write_p"><EM>write_p</EM></A></STRONG><DD>
<P>
This flag is <STRONG>0</STRONG> when a protocol message has been received and <STRONG>1</STRONG>
when a protocol message has been sent.

</P>
<DT><STRONG><A NAME="item_version"><EM>version</EM></A></STRONG><DD>
<P>
The protocol version according to which the protocol message is interpreted
by the library. Currently, this is one of
<STRONG>SSL2_VERSION</STRONG>, <STRONG>SSL3_VERSION</STRONG> and <STRONG>TLS1_VERSION</STRONG> (for SSL 2.0, SSL 3.0 and TLS 1.0, respectively).

</P>
<DT><STRONG><A NAME="item_content_type"><EM>content_type</EM></A></STRONG><DD>
<P>
In the case of SSL 2.0, this is always <STRONG>0</STRONG>. In the case of SSL 3.0 or TLS 1.0, this is one of the <STRONG>ContentType</STRONG> values defined in the protocol specification (<STRONG>change_cipher_spec(20)</STRONG>, <STRONG>alert(21)</STRONG>,
<STRONG>handshake(22)</STRONG>; but never <STRONG>application_data(23)</STRONG> because the callback will only be called for protocol messages).

</P>
<DT><STRONG><A NAME="item_buf"><EM>buf</EM>, <EM>len</EM></A></STRONG><DD>
<P>
<EM>buf</EM> points to a buffer containing the protocol message, which consists of <EM>len</EM> bytes. The buffer is no longer valid after the callback function has
returned.

</P>
<DT><STRONG><A NAME="item_ssl"><EM>ssl</EM></A></STRONG><DD>
<P>
The <STRONG>SSL</STRONG> object that received or sent the message.

</P>
<DT><STRONG><A NAME="item_arg"><EM>arg</EM></A></STRONG><DD>
<P>
The user-defined argument optionally defined by
<CODE>SSL_CTX_set_msg_callback_arg()</CODE> or
<CODE>SSL_set_msg_callback_arg().</CODE>

</P>
</DL>
<P>
<HR>
<H1><A NAME="NOTES">NOTES</A></H1>
<P>
Protocol messages are passed to the callback function after decryption and
fragment collection where applicable. (Thus record boundaries are not
visible.)

</P>
<P>
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.

</P>
<P>
Due to automatic protocol version negotiation, <EM>version</EM> 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,
<EM>version</EM> will be <STRONG>SSL3_VERSION</STRONG>.

</P>
<P>
<HR>
<H1><A NAME="SEE_ALSO">SEE ALSO</A></H1>
<P>
<A HREF="../ssl/ssl.html#">ssl(3)</A>, <A HREF="../ssl/SSL_new.html#">SSL_new(3)</A>



</P>
<P>
<HR>
<H1><A NAME="HISTORY">HISTORY</A></H1>
<P>
<CODE>SSL_CTX_set_msg_callback(),</CODE>
<CODE>SSL_CTX_set_msg_callback_arg(),</CODE>
<CODE>SSL_set_msg_callback()</CODE> and
<CODE>SSL_get_msg_callback_arg()</CODE> were added in OpenSSL 0.9.7.

</P>
:}

