SSL_CTX_set_msg_callback.pod 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. =pod
  2. =head1 NAME
  3. SSL_CTX_set_msg_callback,
  4. SSL_CTX_set_msg_callback_arg,
  5. SSL_set_msg_callback,
  6. SSL_set_msg_callback_arg
  7. - install callback for observing protocol messages
  8. =head1 SYNOPSIS
  9. #include <openssl/ssl.h>
  10. void SSL_CTX_set_msg_callback(SSL_CTX *ctx,
  11. void (*cb)(int write_p, int version,
  12. int content_type, const void *buf,
  13. size_t len, SSL *ssl, void *arg));
  14. void SSL_CTX_set_msg_callback_arg(SSL_CTX *ctx, void *arg);
  15. void SSL_set_msg_callback(SSL *ssl,
  16. void (*cb)(int write_p, int version,
  17. int content_type, const void *buf,
  18. size_t len, SSL *ssl, void *arg));
  19. void SSL_set_msg_callback_arg(SSL *ssl, void *arg);
  20. =head1 DESCRIPTION
  21. SSL_CTX_set_msg_callback() or SSL_set_msg_callback() can be used to
  22. define a message callback function I<cb> for observing all SSL/TLS
  23. protocol messages (such as handshake messages) that are received or
  24. sent, as well as other events that occur during processing.
  25. SSL_CTX_set_msg_callback_arg() and SSL_set_msg_callback_arg()
  26. can be used to set argument I<arg> to the callback function, which is
  27. available for arbitrary application use.
  28. SSL_CTX_set_msg_callback() and SSL_CTX_set_msg_callback_arg() specify
  29. default settings that will be copied to new B<SSL> objects by
  30. L<SSL_new(3)>. SSL_set_msg_callback() and
  31. SSL_set_msg_callback_arg() modify the actual settings of an B<SSL>
  32. object. Using a B<NULL> pointer for I<cb> disables the message callback.
  33. When I<cb> is called by the SSL/TLS library the function arguments have the
  34. following meaning:
  35. =over 4
  36. =item I<write_p>
  37. This flag is B<0> when a protocol message has been received and B<1>
  38. when a protocol message has been sent.
  39. =item I<version>
  40. The protocol version according to which the protocol message is
  41. interpreted by the library such as B<TLS1_3_VERSION>, B<TLS1_2_VERSION> etc.
  42. This is set to 0 for the SSL3_RT_HEADER pseudo content type (see NOTES below).
  43. =item I<content_type>
  44. This is one of the content type values defined in the protocol specification
  45. (B<SSL3_RT_CHANGE_CIPHER_SPEC>, B<SSL3_RT_ALERT>, B<SSL3_RT_HANDSHAKE>; but never
  46. B<SSL3_RT_APPLICATION_DATA> because the callback will only be called for protocol
  47. messages). Alternatively it may be a "pseudo" content type. These pseudo
  48. content types are used to signal some other event in the processing of data (see
  49. NOTES below).
  50. =item I<buf>, I<len>
  51. I<buf> points to a buffer containing the protocol message or other data (in the
  52. case of pseudo content types), which consists of I<len> bytes. The buffer is no
  53. longer valid after the callback function has returned.
  54. =item I<ssl>
  55. The B<SSL> object that received or sent the message.
  56. =item I<arg>
  57. The user-defined argument optionally defined by
  58. SSL_CTX_set_msg_callback_arg() or SSL_set_msg_callback_arg().
  59. =back
  60. =head1 NOTES
  61. Protocol messages are passed to the callback function after decryption
  62. and fragment collection where applicable. (Thus record boundaries are
  63. not visible.)
  64. If processing a received protocol message results in an error,
  65. the callback function may not be called. For example, the callback
  66. function will never see messages that are considered too large to be
  67. processed.
  68. Due to automatic protocol version negotiation, I<version> is not
  69. necessarily the protocol version used by the sender of the message: If
  70. a TLS 1.0 ClientHello message is received by an SSL 3.0-only server,
  71. I<version> will be B<SSL3_VERSION>.
  72. Pseudo content type values may be sent at various points during the processing
  73. of data. The following pseudo content types are currently defined:
  74. =over 4
  75. =item B<SSL3_RT_HEADER>
  76. Used when a record is sent or received. The B<buf> contains the record header
  77. bytes only.
  78. =item B<SSL3_RT_INNER_CONTENT_TYPE>
  79. Used when an encrypted TLSv1.3 record is sent or received. In encrypted TLSv1.3
  80. records the content type in the record header is always
  81. SSL3_RT_APPLICATION_DATA. The real content type for the record is contained in
  82. an "inner" content type. B<buf> contains the encoded "inner" content type byte.
  83. =back
  84. =head1 RETURN VALUES
  85. SSL_CTX_set_msg_callback(), SSL_CTX_set_msg_callback_arg(), SSL_set_msg_callback()
  86. and SSL_set_msg_callback_arg() do not return values.
  87. =head1 SEE ALSO
  88. L<ssl(7)>, L<SSL_new(3)>
  89. =head1 HISTORY
  90. The pseudo content type B<SSL3_RT_INNER_CONTENT_TYPE> was added in OpenSSL
  91. 1.1.1.
  92. =head1 COPYRIGHT
  93. Copyright 2001-2018 The OpenSSL Project Authors. All Rights Reserved.
  94. Licensed under the OpenSSL license (the "License"). You may not use
  95. this file except in compliance with the License. You can obtain a copy
  96. in the file LICENSE in the source distribution or at
  97. L<https://www.openssl.org/source/license.html>.
  98. =cut