Automatically generated by Pod::Man 5.0102 (Pod::Simple 3.45)
Standard preamble:
========================================================================
..
.... \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>.
. ds C` "" . ds C' "" 'br\} . ds C` . ds C' 'br\}
Escape single quotes in literal strings from groff's Unicode transform.
If the F register is >0, we'll generate index entries on stderr for
titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
entries marked with X<> in POD. Of course, you'll have to process the
output yourself in some meaningful fashion.
Avoid warning from groff about undefined register 'F'.
.. .nr rF 0 . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF ========================================================================
Title "SSL_SHUTDOWN 3ossl"
way too many mistakes in technical documents.
\fBSSL_shutdown_ex() is an extended version of SSL_shutdown(). If non-NULL, args must point to a SSL_SHUTDOWN_EX_ARGS structure and args_len must be set to \f(CWsizeof(SSL_SHUTDOWN_EX_ARGS). The SSL_SHUTDOWN_EX_ARGS structure must be zero-initialized. If args is NULL, the behaviour is the same as passing a zero-initialised SSL_SHUTDOWN_EX_ARGS structure. Currently, all extended arguments relate to usage with QUIC, therefore this call functions identically to SSL_shutdown() when not being used with QUIC.
While the general operation of SSL_shutdown() is common between protocols, the exact nature of how a shutdown is performed depends on the underlying protocol being used. See the section below pertaining to each protocol for more information.
In general, calling SSL_shutdown() in nonblocking mode will initiate the shutdown process and return 0 to indicate that the shutdown process has not yet completed. Once the shutdown process has completed, subsequent calls to \fBSSL_shutdown() will return 1. See the RETURN VALUES section for more information.
\fBSSL_shutdown() should not be called if a previous fatal error has occurred on a connection; i.e., if SSL_get_error\|(3) has returned SSL_ERROR_SYSCALL or \fBSSL_ERROR_SSL.
These steps can occur in either order depending on whether the connection shutdown process was first initiated by the local application or by the peer.
Calling SSL_shutdown() only closes the write direction of the connection; the read direction is closed by the peer. Once SSL_shutdown() is called, \fBSSL_write\|(3) can no longer be used, but SSL_read\|(3) may still be used until the peer decides to close the connection in turn. The peer might continue sending data for some period of time before handling the local application's shutdown indication.
\fBSSL_shutdown() does not affect an underlying network connection such as a TCP connection, which remains open.
If the underlying BIO is nonblocking and the shutdown process is not yet complete (for example, because a close_notify alert message has not yet been received from the peer, or because a close_notify alert message needs to be sent but would currently block), SSL_shutdown() returns 0 to indicate that the shutdown process is still ongoing; in this case, a call to SSL_get_error\|(3) will yield SSL_ERROR_WANT_READ or SSL_ERROR_WANT_WRITE.
An application can then detect completion of the shutdown process by calling \fBSSL_shutdown() again repeatedly until it returns 1, indicating that the shutdown process is complete (with a close_notify alert having both been sent and received).
However, the preferred method of waiting for the shutdown to complete is to use \fBSSL_read\|(3) until SSL_get_error\|(3) indicates EOF by returning \fBSSL_ERROR_ZERO_RETURN. This ensures any data received immediately before the peer's close_notify alert is still provided to the application. It also ensures any final handshake-layer messages received are processed (for example, messages issuing new session tickets).
If this approach is not used, the second call to SSL_shutdown() (to complete the shutdown by confirming receipt of the peer's close_notify message) will fail if it is called when the application has not read all pending application data sent by the peer using SSL_read\|(3).
When calling SSL_shutdown(), the SSL_SENT_SHUTDOWN flag is set once an attempt is made to send a close_notify alert, regardless of whether the attempt was successful. The SSL_RECEIVED_SHUTDOWN flag is set once a close_notify alert is received, which may occur during any call which processes incoming data from the network, such as SSL_read\|(3) or SSL_shutdown(). These flags may be checked using SSL_get_shutdown\|(3).
This alternative "fast shutdown" approach should only be done if it is known that the peer will not send more data, otherwise there is a risk of an application exposing itself to a truncation attack. The full SSL_shutdown() process, in which both parties send close_notify alerts and SSL_shutdown() returns 1, provides a cryptographically authenticated indication of the end of a connection.
This approach of a single SSL_shutdown() call without waiting is preferable to simply calling SSL_free\|(3) or SSL_clear\|(3) as calling SSL_shutdown() beforehand makes an SSL session eligible for subsequent reuse and notifies the peer of connection shutdown.
The fast shutdown approach can only be used if there is no intention to reuse the underlying connection (e.g. a TCP connection) for further communication; in this case, the full shutdown process must be performed to ensure synchronisation.
This is not standards-compliant behaviour. It should only be done when the application protocol in use enables the peer to ensure that all data has been received, such that it doesn't need to wait for a close_notify alert, otherwise application data may be truncated unexpectedly.
If compatibility with such peers is desired, the option \fBSSL_OP_IGNORE_UNEXPECTED_EOF can be set. For more information, see \fBSSL_CTX_set_options\|(3).
Note that use of this option means that the EOF condition for application data does not receive cryptographic protection, and therefore renders an application potentially vulnerable to truncation attacks. Thus, this option must only be used in conjunction with an application protocol which indicates unambiguously when all data has been received.
An alternative approach is to simply avoid calling SSL_read\|(3) if it is known that no more data is going to be sent. This requires an application protocol which indicates unambiguously when all data has been sent.
Therefore, client applications which only write and do not read but which wish to benefit from session resumption are advised to perform a complete shutdown procedure by calling SSL_shutdown() until it returns 1, as described above. This will ensure there is an opportunity for SSL/TLS session ticket messages to be received and processed by OpenSSL.
\fBSSL_shutdown() cannot be used on QUIC stream SSL objects. To conclude a stream normally, see SSL_stream_conclude\|(3); to perform a non-normal stream termination, see SSL_stream_reset\|(3).
\fBSSL_shutdown_ex() may be used instead of SSL_shutdown() by an application to provide additional information to the peer on the reason why a connection is being shut down. The information which can be provided is as follows:
The arguments to SSL_shutdown_ex() are used only on the first call to \fBSSL_shutdown_ex() (or SSL_shutdown()) for a given QUIC connection SSL object. These arguments are ignored on subsequent calls.
These functions do not affect an underlying network BIO or the resource it represents; for example, a UDP datagram provided to a QUIC connection as the network BIO will remain open.
Note that when using QUIC, an application must call SSL_shutdown() if it wants to ensure that all transmitted data was received by the peer. This is unlike a TLS/TCP connection, where reliable transmission of buffered data is the responsibility of the operating system. If an application calls SSL_free() on a QUIC connection SSL object or exits before completing the shutdown process using \fBSSL_shutdown(), data which was written by the application using SSL_write(), but could not yet be transmitted, or which was sent but lost in the network, may not be received by the peer.
When using QUIC, calling SSL_shutdown() allows internal network event processing to be performed. It is important that this processing is performed regularly, whether during connection usage or during shutdown. If an application is not using thread assisted mode, an application conducting shutdown should either ensure that SSL_shutdown() is called regularly, or alternatively ensure that \fBSSL_handle_events() is called regularly. See openssl-quic\|(7) and \fBSSL_handle_events\|(3) for more information.
An exception to this is streams which terminated in a non-normal fashion, for example due to a stream reset; only streams which are non-terminated at the time \fBSSL_shutdown() is called, or which terminated in a normal fashion, have their pending send buffers flushed in this manner.
This behaviour of flushing streams during the shutdown process can be skipped by setting the SSL_SHUTDOWN_FLAG_NO_STREAM_FLUSH flag in a call to \fBSSL_shutdown_ex(); in this case, data remaining in stream send buffers may not be transmitted to the peer. This flag may be used when a non-normal application condition has occurred and the delivery of data written to streams via \fBSSL_write\|(3) is no longer relevant.
As such, there are two shutdown modes available to users of QUIC connection SSL objects:
If SSL_SHUTDOWN_FLAG_RAPID is specified in flags, a rapid shutdown is performed, otherwise an RFC-compliant shutdown is performed.
If an application calls SSL_shutdown_ex() with SSL_SHUTDOWN_FLAG_RAPID, an application can subsequently change its mind about performing a rapid shutdown by making a subsequent call to SSL_shutdown_ex() without the flag set.
If a locally initiated shutdown has already been triggered or the connection has started terminating for another reason, this flag has no effect.
\fBSSL_SHUTDOWN_FLAG_WAIT_PEER implies SSL_SHUTDOWN_FLAG_NO_STREAM_FLUSH, as stream data cannot be flushed after a peer closes the connection. Stream data may still be sent to the peer in any time spent waiting before the peer closes the connection, though there is no guarantee of this.
Licensed under the Apache License 2.0 (the "License"). You may not use this file except in compliance with the License. You can obtain a copy in the file LICENSE in the source distribution or at <https://www.openssl.org/source/license.html>.