SSL_CTX_set_info_callback.pod 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. =pod
  2. =head1 NAME
  3. SSL_CTX_set_info_callback,
  4. SSL_CTX_get_info_callback,
  5. SSL_set_info_callback,
  6. SSL_get_info_callback
  7. - handle information callback for SSL connections
  8. =head1 SYNOPSIS
  9. #include <openssl/ssl.h>
  10. void SSL_CTX_set_info_callback(SSL_CTX *ctx,
  11. void (*callback) (const SSL *ssl, int type, int val));
  12. void (*SSL_CTX_get_info_callback(SSL_CTX *ctx)) (const SSL *ssl, int type, int val);
  13. void SSL_set_info_callback(SSL *ssl,
  14. void (*callback) (const SSL *ssl, int type, int val));
  15. void (*SSL_get_info_callback(const SSL *ssl)) (const SSL *ssl, int type, int val);
  16. =head1 DESCRIPTION
  17. SSL_CTX_set_info_callback() sets the B<callback> function, that can be used to
  18. obtain state information for SSL objects created from B<ctx> during connection
  19. setup and use. The setting for B<ctx> is overridden from the setting for
  20. a specific SSL object, if specified.
  21. When B<callback> is NULL, no callback function is used.
  22. SSL_set_info_callback() sets the B<callback> function, that can be used to
  23. obtain state information for B<ssl> during connection setup and use.
  24. When B<callback> is NULL, the callback setting currently valid for
  25. B<ctx> is used.
  26. SSL_CTX_get_info_callback() returns a pointer to the currently set information
  27. callback function for B<ctx>.
  28. SSL_get_info_callback() returns a pointer to the currently set information
  29. callback function for B<ssl>.
  30. =head1 NOTES
  31. When setting up a connection and during use, it is possible to obtain state
  32. information from the SSL/TLS engine. When set, an information callback function
  33. is called whenever a significant event occurs such as: the state changes,
  34. an alert appears, or an error occurs.
  35. The callback function is called as B<callback(SSL *ssl, int where, int ret)>.
  36. The B<where> argument specifies information about where (in which context)
  37. the callback function was called. If B<ret> is 0, an error condition occurred.
  38. If an alert is handled, SSL_CB_ALERT is set and B<ret> specifies the alert
  39. information.
  40. B<where> is a bit-mask made up of the following bits:
  41. =over 4
  42. =item SSL_CB_LOOP
  43. Callback has been called to indicate state change or some other significant
  44. state machine event. This may mean that the callback gets invoked more than once
  45. per state in some situations.
  46. =item SSL_CB_EXIT
  47. Callback has been called to indicate exit of a handshake function. This will
  48. happen after the end of a handshake, but may happen at other times too such as
  49. on error or when IO might otherwise block and nonblocking is being used.
  50. =item SSL_CB_READ
  51. Callback has been called during read operation.
  52. =item SSL_CB_WRITE
  53. Callback has been called during write operation.
  54. =item SSL_CB_ALERT
  55. Callback has been called due to an alert being sent or received.
  56. =item SSL_CB_READ_ALERT (SSL_CB_ALERT|SSL_CB_READ)
  57. =item SSL_CB_WRITE_ALERT (SSL_CB_ALERT|SSL_CB_WRITE)
  58. =item SSL_CB_ACCEPT_LOOP (SSL_ST_ACCEPT|SSL_CB_LOOP)
  59. =item SSL_CB_ACCEPT_EXIT (SSL_ST_ACCEPT|SSL_CB_EXIT)
  60. =item SSL_CB_CONNECT_LOOP (SSL_ST_CONNECT|SSL_CB_LOOP)
  61. =item SSL_CB_CONNECT_EXIT (SSL_ST_CONNECT|SSL_CB_EXIT)
  62. =item SSL_CB_HANDSHAKE_START
  63. Callback has been called because a new handshake is started. It also occurs when
  64. resuming a handshake following a pause to handle early data.
  65. =item SSL_CB_HANDSHAKE_DONE
  66. Callback has been called because a handshake is finished. It also occurs if the
  67. handshake is paused to allow the exchange of early data.
  68. =back
  69. The current state information can be obtained using the
  70. L<SSL_state_string(3)> family of functions.
  71. The B<ret> information can be evaluated using the
  72. L<SSL_alert_type_string(3)> family of functions.
  73. =head1 RETURN VALUES
  74. SSL_set_info_callback() does not provide diagnostic information.
  75. SSL_get_info_callback() returns the current setting.
  76. =head1 EXAMPLES
  77. The following example callback function prints state strings, information
  78. about alerts being handled and error messages to the B<bio_err> BIO.
  79. void apps_ssl_info_callback(const SSL *s, int where, int ret)
  80. {
  81. const char *str;
  82. int w = where & ~SSL_ST_MASK;
  83. if (w & SSL_ST_CONNECT)
  84. str = "SSL_connect";
  85. else if (w & SSL_ST_ACCEPT)
  86. str = "SSL_accept";
  87. else
  88. str = "undefined";
  89. if (where & SSL_CB_LOOP) {
  90. BIO_printf(bio_err, "%s:%s\n", str, SSL_state_string_long(s));
  91. } else if (where & SSL_CB_ALERT) {
  92. str = (where & SSL_CB_READ) ? "read" : "write";
  93. BIO_printf(bio_err, "SSL3 alert %s:%s:%s\n", str,
  94. SSL_alert_type_string_long(ret),
  95. SSL_alert_desc_string_long(ret));
  96. } else if (where & SSL_CB_EXIT) {
  97. if (ret == 0) {
  98. BIO_printf(bio_err, "%s:failed in %s\n",
  99. str, SSL_state_string_long(s));
  100. } else if (ret < 0) {
  101. BIO_printf(bio_err, "%s:error in %s\n",
  102. str, SSL_state_string_long(s));
  103. }
  104. }
  105. }
  106. =head1 SEE ALSO
  107. L<ssl(7)>, L<SSL_state_string(3)>,
  108. L<SSL_alert_type_string(3)>
  109. =head1 COPYRIGHT
  110. Copyright 2001-2020 The OpenSSL Project Authors. All Rights Reserved.
  111. Licensed under the Apache License 2.0 (the "License"). You may not use
  112. this file except in compliance with the License. You can obtain a copy
  113. in the file LICENSE in the source distribution or at
  114. L<https://www.openssl.org/source/license.html>.
  115. =cut