2
0

SSL_shutdown.pod 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. =pod
  2. =head1 NAME
  3. SSL_shutdown - shut down a TLS/SSL connection
  4. =head1 SYNOPSIS
  5. #include <openssl/ssl.h>
  6. int SSL_shutdown(SSL *ssl);
  7. =head1 DESCRIPTION
  8. SSL_shutdown() shuts down an active TLS/SSL connection. It sends the
  9. "close notify" shutdown alert to the peer.
  10. =head1 NOTES
  11. SSL_shutdown() tries to send the "close notify" shutdown alert to the peer.
  12. Whether the operation succeeds or not, the SSL_SENT_SHUTDOWN flag is set and
  13. a currently open session is considered closed and good and will be kept in the
  14. session cache for further reuse.
  15. The shutdown procedure consists of 2 steps: the sending of the "close notify"
  16. shutdown alert and the reception of the peer's "close notify" shutdown
  17. alert. According to the TLS standard, it is acceptable for an application
  18. to only send its shutdown alert and then close the underlying connection
  19. without waiting for the peer's response (this way resources can be saved,
  20. as the process can already terminate or serve another connection).
  21. When the underlying connection shall be used for more communications, the
  22. complete shutdown procedure (bidirectional "close notify" alerts) must be
  23. performed, so that the peers stay synchronized.
  24. SSL_shutdown() supports both uni- and bidirectional shutdown by its 2 step
  25. behaviour.
  26. =over 4
  27. =item When the application is the first party to send the "close notify"
  28. alert, SSL_shutdown() will only send the alert and then set the
  29. SSL_SENT_SHUTDOWN flag (so that the session is considered good and will
  30. be kept in cache). SSL_shutdown() will then return with 0. If a unidirectional
  31. shutdown is enough (the underlying connection shall be closed anyway), this
  32. first call to SSL_shutdown() is sufficient. In order to complete the
  33. bidirectional shutdown handshake, SSL_shutdown() must be called again.
  34. The second call will make SSL_shutdown() wait for the peer's "close notify"
  35. shutdown alert. On success, the second call to SSL_shutdown() will return
  36. with 1.
  37. =item If the peer already sent the "close notify" alert B<and> it was
  38. already processed implicitly inside another function
  39. (L<SSL_read(3)|SSL_read(3)>), the SSL_RECEIVED_SHUTDOWN flag is set.
  40. SSL_shutdown() will send the "close notify" alert, set the SSL_SENT_SHUTDOWN
  41. flag and will immediately return with 1.
  42. Whether SSL_RECEIVED_SHUTDOWN is already set can be checked using the
  43. SSL_get_shutdown() (see also L<SSL_set_shutdown(3)|SSL_set_shutdown(3)> call.
  44. =back
  45. It is therefore recommended, to check the return value of SSL_shutdown()
  46. and call SSL_shutdown() again, if the bidirectional shutdown is not yet
  47. complete (return value of the first call is 0). As the shutdown is not
  48. specially handled in the SSLv2 protocol, SSL_shutdown() will succeed on
  49. the first call.
  50. The behaviour of SSL_shutdown() additionally depends on the underlying BIO.
  51. If the underlying BIO is B<blocking>, SSL_shutdown() will only return once the
  52. handshake step has been finished or an error occurred.
  53. If the underlying BIO is B<non-blocking>, SSL_shutdown() will also return
  54. when the underlying BIO could not satisfy the needs of SSL_shutdown()
  55. to continue the handshake. In this case a call to SSL_get_error() with the
  56. return value of SSL_shutdown() will yield B<SSL_ERROR_WANT_READ> or
  57. B<SSL_ERROR_WANT_WRITE>. The calling process then must repeat the call after
  58. taking appropriate action to satisfy the needs of SSL_shutdown().
  59. The action depends on the underlying BIO. When using a non-blocking socket,
  60. nothing is to be done, but select() can be used to check for the required
  61. condition. When using a buffering BIO, like a BIO pair, data must be written
  62. into or retrieved out of the BIO before being able to continue.
  63. SSL_shutdown() can be modified to only set the connection to "shutdown"
  64. state but not actually send the "close notify" alert messages,
  65. see L<SSL_CTX_set_quiet_shutdown(3)|SSL_CTX_set_quiet_shutdown(3)>.
  66. When "quiet shutdown" is enabled, SSL_shutdown() will always succeed
  67. and return 1.
  68. =head1 RETURN VALUES
  69. The following return values can occur:
  70. =over 4
  71. =item Z<>0
  72. The shutdown is not yet finished. Call SSL_shutdown() for a second time,
  73. if a bidirectional shutdown shall be performed.
  74. The output of L<SSL_get_error(3)|SSL_get_error(3)> may be misleading, as an
  75. erroneous SSL_ERROR_SYSCALL may be flagged even though no error occurred.
  76. =item Z<>1
  77. The shutdown was successfully completed. The "close notify" alert was sent
  78. and the peer's "close notify" alert was received.
  79. =item -1
  80. The shutdown was not successful because a fatal error occurred either
  81. at the protocol level or a connection failure occurred. It can also occur if
  82. action is need to continue the operation for non-blocking BIOs.
  83. Call L<SSL_get_error(3)|SSL_get_error(3)> with the return value B<ret>
  84. to find out the reason.
  85. =back
  86. =head1 SEE ALSO
  87. L<SSL_get_error(3)|SSL_get_error(3)>, L<SSL_connect(3)|SSL_connect(3)>,
  88. L<SSL_accept(3)|SSL_accept(3)>, L<SSL_set_shutdown(3)|SSL_set_shutdown(3)>,
  89. L<SSL_CTX_set_quiet_shutdown(3)|SSL_CTX_set_quiet_shutdown(3)>,
  90. L<SSL_clear(3)|SSL_clear(3)>, L<SSL_free(3)|SSL_free(3)>,
  91. L<ssl(3)|ssl(3)>, L<bio(3)|bio(3)>
  92. =cut