SSL_CTX_set_info_callback.pod 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. =pod
  2. =head1 NAME
  3. SSL_CTX_set_info_callback, SSL_CTX_get_info_callback, SSL_set_info_callback, SSL_get_info_callback - handle information callback for SSL connections
  4. =head1 SYNOPSIS
  5. #include <openssl/ssl.h>
  6. void SSL_CTX_set_info_callback(SSL_CTX *ctx, void (*callback)());
  7. void (*SSL_CTX_get_info_callback(const SSL_CTX *ctx))();
  8. void SSL_set_info_callback(SSL *ssl, void (*callback)());
  9. void (*SSL_get_info_callback(const SSL *ssl))();
  10. =head1 DESCRIPTION
  11. SSL_CTX_set_info_callback() sets the B<callback> function, that can be used to
  12. obtain state information for SSL objects created from B<ctx> during connection
  13. setup and use. The setting for B<ctx> is overridden from the setting for
  14. a specific SSL object, if specified.
  15. When B<callback> is NULL, not callback function is used.
  16. SSL_set_info_callback() sets the B<callback> function, that can be used to
  17. obtain state information for B<ssl> during connection setup and use.
  18. When B<callback> is NULL, the callback setting currently valid for
  19. B<ctx> is used.
  20. SSL_CTX_get_info_callback() returns a pointer to the currently set information
  21. callback function for B<ctx>.
  22. SSL_get_info_callback() returns a pointer to the currently set information
  23. callback function for B<ssl>.
  24. =head1 NOTES
  25. When setting up a connection and during use, it is possible to obtain state
  26. information from the SSL/TLS engine. When set, an information callback function
  27. is called whenever the state changes, an alert appears, or an error occurs.
  28. The callback function is called as B<callback(SSL *ssl, int where, int ret)>.
  29. The B<where> argument specifies information about where (in which context)
  30. the callback function was called. If B<ret> is 0, an error condition occurred.
  31. If an alert is handled, SSL_CB_ALERT is set and B<ret> specifies the alert
  32. information.
  33. B<where> is a bitmask made up of the following bits:
  34. =over 4
  35. =item SSL_CB_LOOP
  36. Callback has been called to indicate state change inside a loop.
  37. =item SSL_CB_EXIT
  38. Callback has been called to indicate error exit of a handshake function.
  39. (May be soft error with retry option for non-blocking setups.)
  40. =item SSL_CB_READ
  41. Callback has been called during read operation.
  42. =item SSL_CB_WRITE
  43. Callback has been called during write operation.
  44. =item SSL_CB_ALERT
  45. Callback has been called due to an alert being sent or received.
  46. =item SSL_CB_READ_ALERT (SSL_CB_ALERT|SSL_CB_READ)
  47. =item SSL_CB_WRITE_ALERT (SSL_CB_ALERT|SSL_CB_WRITE)
  48. =item SSL_CB_ACCEPT_LOOP (SSL_ST_ACCEPT|SSL_CB_LOOP)
  49. =item SSL_CB_ACCEPT_EXIT (SSL_ST_ACCEPT|SSL_CB_EXIT)
  50. =item SSL_CB_CONNECT_LOOP (SSL_ST_CONNECT|SSL_CB_LOOP)
  51. =item SSL_CB_CONNECT_EXIT (SSL_ST_CONNECT|SSL_CB_EXIT)
  52. =item SSL_CB_HANDSHAKE_START
  53. Callback has been called because a new handshake is started.
  54. =item SSL_CB_HANDSHAKE_DONE 0x20
  55. Callback has been called because a handshake is finished.
  56. =back
  57. The current state information can be obtained using the
  58. L<SSL_state_string(3)|SSL_state_string(3)> family of functions.
  59. The B<ret> information can be evaluated using the
  60. L<SSL_alert_type_string(3)|SSL_alert_type_string(3)> family of functions.
  61. =head1 RETURN VALUES
  62. SSL_set_info_callback() does not provide diagnostic information.
  63. SSL_get_info_callback() returns the current setting.
  64. =head1 EXAMPLES
  65. The following example callback function prints state strings, information
  66. about alerts being handled and error messages to the B<bio_err> BIO.
  67. void apps_ssl_info_callback(SSL *s, int where, int ret)
  68. {
  69. const char *str;
  70. int w;
  71. w=where& ~SSL_ST_MASK;
  72. if (w & SSL_ST_CONNECT) str="SSL_connect";
  73. else if (w & SSL_ST_ACCEPT) str="SSL_accept";
  74. else str="undefined";
  75. if (where & SSL_CB_LOOP)
  76. {
  77. BIO_printf(bio_err,"%s:%s\n",str,SSL_state_string_long(s));
  78. }
  79. else if (where & SSL_CB_ALERT)
  80. {
  81. str=(where & SSL_CB_READ)?"read":"write";
  82. BIO_printf(bio_err,"SSL3 alert %s:%s:%s\n",
  83. str,
  84. SSL_alert_type_string_long(ret),
  85. SSL_alert_desc_string_long(ret));
  86. }
  87. else if (where & SSL_CB_EXIT)
  88. {
  89. if (ret == 0)
  90. BIO_printf(bio_err,"%s:failed in %s\n",
  91. str,SSL_state_string_long(s));
  92. else if (ret < 0)
  93. {
  94. BIO_printf(bio_err,"%s:error in %s\n",
  95. str,SSL_state_string_long(s));
  96. }
  97. }
  98. }
  99. =head1 SEE ALSO
  100. L<ssl(3)|ssl(3)>, L<SSL_state_string(3)|SSL_state_string(3)>,
  101. L<SSL_alert_type_string(3)|SSL_alert_type_string(3)>
  102. =cut