1e71b7053SJung-uk Kim=pod 2e71b7053SJung-uk Kim 3e71b7053SJung-uk Kim=head1 NAME 4e71b7053SJung-uk Kim 5e71b7053SJung-uk KimSSL_CTX_set_msg_callback, 6e71b7053SJung-uk KimSSL_CTX_set_msg_callback_arg, 7e71b7053SJung-uk KimSSL_set_msg_callback, 8e71b7053SJung-uk KimSSL_set_msg_callback_arg 9e71b7053SJung-uk Kim- install callback for observing protocol messages 10e71b7053SJung-uk Kim 11e71b7053SJung-uk Kim=head1 SYNOPSIS 12e71b7053SJung-uk Kim 13e71b7053SJung-uk Kim #include <openssl/ssl.h> 14e71b7053SJung-uk Kim 15e71b7053SJung-uk Kim void SSL_CTX_set_msg_callback(SSL_CTX *ctx, 16e71b7053SJung-uk Kim void (*cb)(int write_p, int version, 17e71b7053SJung-uk Kim int content_type, const void *buf, 18e71b7053SJung-uk Kim size_t len, SSL *ssl, void *arg)); 19e71b7053SJung-uk Kim void SSL_CTX_set_msg_callback_arg(SSL_CTX *ctx, void *arg); 20e71b7053SJung-uk Kim 21e71b7053SJung-uk Kim void SSL_set_msg_callback(SSL *ssl, 22e71b7053SJung-uk Kim void (*cb)(int write_p, int version, 23e71b7053SJung-uk Kim int content_type, const void *buf, 24e71b7053SJung-uk Kim size_t len, SSL *ssl, void *arg)); 25e71b7053SJung-uk Kim void SSL_set_msg_callback_arg(SSL *ssl, void *arg); 26e71b7053SJung-uk Kim 27e71b7053SJung-uk Kim=head1 DESCRIPTION 28e71b7053SJung-uk Kim 29e71b7053SJung-uk KimSSL_CTX_set_msg_callback() or SSL_set_msg_callback() can be used to 30e71b7053SJung-uk Kimdefine a message callback function I<cb> for observing all SSL/TLS 31e71b7053SJung-uk Kimprotocol messages (such as handshake messages) that are received or 32e71b7053SJung-uk Kimsent, as well as other events that occur during processing. 33e71b7053SJung-uk KimSSL_CTX_set_msg_callback_arg() and SSL_set_msg_callback_arg() 34e71b7053SJung-uk Kimcan be used to set argument I<arg> to the callback function, which is 35e71b7053SJung-uk Kimavailable for arbitrary application use. 36e71b7053SJung-uk Kim 37e71b7053SJung-uk KimSSL_CTX_set_msg_callback() and SSL_CTX_set_msg_callback_arg() specify 38e71b7053SJung-uk Kimdefault settings that will be copied to new B<SSL> objects by 39e71b7053SJung-uk KimL<SSL_new(3)>. SSL_set_msg_callback() and 40e71b7053SJung-uk KimSSL_set_msg_callback_arg() modify the actual settings of an B<SSL> 41e71b7053SJung-uk Kimobject. Using a B<NULL> pointer for I<cb> disables the message callback. 42e71b7053SJung-uk Kim 43e71b7053SJung-uk KimWhen I<cb> is called by the SSL/TLS library the function arguments have the 44e71b7053SJung-uk Kimfollowing meaning: 45e71b7053SJung-uk Kim 46e71b7053SJung-uk Kim=over 4 47e71b7053SJung-uk Kim 48e71b7053SJung-uk Kim=item I<write_p> 49e71b7053SJung-uk Kim 50e71b7053SJung-uk KimThis flag is B<0> when a protocol message has been received and B<1> 51e71b7053SJung-uk Kimwhen a protocol message has been sent. 52e71b7053SJung-uk Kim 53e71b7053SJung-uk Kim=item I<version> 54e71b7053SJung-uk Kim 55e71b7053SJung-uk KimThe protocol version according to which the protocol message is 56e71b7053SJung-uk Kiminterpreted by the library such as B<TLS1_3_VERSION>, B<TLS1_2_VERSION> etc. 57e71b7053SJung-uk KimThis is set to 0 for the SSL3_RT_HEADER pseudo content type (see NOTES below). 58e71b7053SJung-uk Kim 59e71b7053SJung-uk Kim=item I<content_type> 60e71b7053SJung-uk Kim 61e71b7053SJung-uk KimThis is one of the content type values defined in the protocol specification 62e71b7053SJung-uk Kim(B<SSL3_RT_CHANGE_CIPHER_SPEC>, B<SSL3_RT_ALERT>, B<SSL3_RT_HANDSHAKE>; but never 63e71b7053SJung-uk KimB<SSL3_RT_APPLICATION_DATA> because the callback will only be called for protocol 64e71b7053SJung-uk Kimmessages). Alternatively it may be a "pseudo" content type. These pseudo 65e71b7053SJung-uk Kimcontent types are used to signal some other event in the processing of data (see 66e71b7053SJung-uk KimNOTES below). 67e71b7053SJung-uk Kim 68e71b7053SJung-uk Kim=item I<buf>, I<len> 69e71b7053SJung-uk Kim 70e71b7053SJung-uk KimI<buf> points to a buffer containing the protocol message or other data (in the 71e71b7053SJung-uk Kimcase of pseudo content types), which consists of I<len> bytes. The buffer is no 72e71b7053SJung-uk Kimlonger valid after the callback function has returned. 73e71b7053SJung-uk Kim 74e71b7053SJung-uk Kim=item I<ssl> 75e71b7053SJung-uk Kim 76e71b7053SJung-uk KimThe B<SSL> object that received or sent the message. 77e71b7053SJung-uk Kim 78e71b7053SJung-uk Kim=item I<arg> 79e71b7053SJung-uk Kim 80e71b7053SJung-uk KimThe user-defined argument optionally defined by 81e71b7053SJung-uk KimSSL_CTX_set_msg_callback_arg() or SSL_set_msg_callback_arg(). 82e71b7053SJung-uk Kim 83e71b7053SJung-uk Kim=back 84e71b7053SJung-uk Kim 85e71b7053SJung-uk Kim=head1 NOTES 86e71b7053SJung-uk Kim 87e71b7053SJung-uk KimProtocol messages are passed to the callback function after decryption 88e71b7053SJung-uk Kimand fragment collection where applicable. (Thus record boundaries are 89e71b7053SJung-uk Kimnot visible.) 90e71b7053SJung-uk Kim 91e71b7053SJung-uk KimIf processing a received protocol message results in an error, 92e71b7053SJung-uk Kimthe callback function may not be called. For example, the callback 93e71b7053SJung-uk Kimfunction will never see messages that are considered too large to be 94e71b7053SJung-uk Kimprocessed. 95e71b7053SJung-uk Kim 96e71b7053SJung-uk KimDue to automatic protocol version negotiation, I<version> is not 97e71b7053SJung-uk Kimnecessarily the protocol version used by the sender of the message: If 98e71b7053SJung-uk Kima TLS 1.0 ClientHello message is received by an SSL 3.0-only server, 99e71b7053SJung-uk KimI<version> will be B<SSL3_VERSION>. 100e71b7053SJung-uk Kim 101e71b7053SJung-uk KimPseudo content type values may be sent at various points during the processing 102e71b7053SJung-uk Kimof data. The following pseudo content types are currently defined: 103e71b7053SJung-uk Kim 104e71b7053SJung-uk Kim=over 4 105e71b7053SJung-uk Kim 106e71b7053SJung-uk Kim=item B<SSL3_RT_HEADER> 107e71b7053SJung-uk Kim 108e71b7053SJung-uk KimUsed when a record is sent or received. The B<buf> contains the record header 109e71b7053SJung-uk Kimbytes only. 110e71b7053SJung-uk Kim 111e71b7053SJung-uk Kim=item B<SSL3_RT_INNER_CONTENT_TYPE> 112e71b7053SJung-uk Kim 113e71b7053SJung-uk KimUsed when an encrypted TLSv1.3 record is sent or received. In encrypted TLSv1.3 114e71b7053SJung-uk Kimrecords the content type in the record header is always 115e71b7053SJung-uk KimSSL3_RT_APPLICATION_DATA. The real content type for the record is contained in 116e71b7053SJung-uk Kiman "inner" content type. B<buf> contains the encoded "inner" content type byte. 117e71b7053SJung-uk Kim 118e71b7053SJung-uk Kim=back 119e71b7053SJung-uk Kim 120e71b7053SJung-uk Kim=head1 RETURN VALUES 121e71b7053SJung-uk Kim 122e71b7053SJung-uk KimSSL_CTX_set_msg_callback(), SSL_CTX_set_msg_callback_arg(), SSL_set_msg_callback() 123e71b7053SJung-uk Kimand SSL_set_msg_callback_arg() do not return values. 124e71b7053SJung-uk Kim 125e71b7053SJung-uk Kim=head1 SEE ALSO 126e71b7053SJung-uk Kim 127e71b7053SJung-uk KimL<ssl(7)>, L<SSL_new(3)> 128e71b7053SJung-uk Kim 129e71b7053SJung-uk Kim=head1 HISTORY 130e71b7053SJung-uk Kim 1316935a639SJung-uk KimThe pseudo content type B<SSL3_RT_INNER_CONTENT_TYPE> was added in OpenSSL 1.1.1. 132e71b7053SJung-uk Kim 133e71b7053SJung-uk Kim=head1 COPYRIGHT 134e71b7053SJung-uk Kim 135e71b7053SJung-uk KimCopyright 2001-2018 The OpenSSL Project Authors. All Rights Reserved. 136e71b7053SJung-uk Kim 137*b077aed3SPierre ProncheryLicensed under the Apache License 2.0 (the "License"). You may not use 138e71b7053SJung-uk Kimthis file except in compliance with the License. You can obtain a copy 139e71b7053SJung-uk Kimin the file LICENSE in the source distribution or at 140e71b7053SJung-uk KimL<https://www.openssl.org/source/license.html>. 141e71b7053SJung-uk Kim 142e71b7053SJung-uk Kim=cut 143