]> git.ipfire.org Git - thirdparty/openssl.git/blame - doc/man3/SSL_shutdown.pod
Fix referenses in section 3 manuals
[thirdparty/openssl.git] / doc / man3 / SSL_shutdown.pod
CommitLineData
cc99526d
RL
1=pod
2
3=head1 NAME
4
1e4e5492 5SSL_shutdown - shut down a TLS/SSL connection
cc99526d
RL
6
7=head1 SYNOPSIS
8
9 #include <openssl/ssl.h>
10
11 int SSL_shutdown(SSL *ssl);
12
13=head1 DESCRIPTION
14
1bc74519 15SSL_shutdown() shuts down an active TLS/SSL connection. It sends the
8e495e4a
LJ
16"close notify" shutdown alert to the peer.
17
18=head1 NOTES
19
20SSL_shutdown() tries to send the "close notify" shutdown alert to the peer.
21Whether the operation succeeds or not, the SSL_SENT_SHUTDOWN flag is set and
22a currently open session is considered closed and good and will be kept in the
23session cache for further reuse.
24
9e09eebf 25The shutdown procedure consists of 2 steps: the sending of the "close notify"
b2ed4629
LJ
26shutdown alert and the reception of the peer's "close notify" shutdown
27alert. According to the TLS standard, it is acceptable for an application
28to only send its shutdown alert and then close the underlying connection
29without waiting for the peer's response (this way resources can be saved,
30as the process can already terminate or serve another connection).
31When the underlying connection shall be used for more communications, the
32complete shutdown procedure (bidirectional "close notify" alerts) must be
33performed, so that the peers stay synchronized.
34
35SSL_shutdown() supports both uni- and bidirectional shutdown by its 2 step
36behaviour.
9e09eebf
LJ
37
38=over 4
39
40=item When the application is the first party to send the "close notify"
4a64f3d6 41alert, SSL_shutdown() will only send the alert and then set the
9e09eebf 42SSL_SENT_SHUTDOWN flag (so that the session is considered good and will
b2ed4629
LJ
43be kept in cache). SSL_shutdown() will then return with 0. If a unidirectional
44shutdown is enough (the underlying connection shall be closed anyway), this
45first call to SSL_shutdown() is sufficient. In order to complete the
46bidirectional shutdown handshake, SSL_shutdown() must be called again.
9e09eebf
LJ
47The second call will make SSL_shutdown() wait for the peer's "close notify"
48shutdown alert. On success, the second call to SSL_shutdown() will return
49with 1.
50
51=item If the peer already sent the "close notify" alert B<and> it was
d93eb21c 52already processed implicitly inside another function
9b86974e 53(L<SSL_read(3)>), the SSL_RECEIVED_SHUTDOWN flag is set.
d93eb21c
LJ
54SSL_shutdown() will send the "close notify" alert, set the SSL_SENT_SHUTDOWN
55flag and will immediately return with 1.
56Whether SSL_RECEIVED_SHUTDOWN is already set can be checked using the
9b86974e 57SSL_get_shutdown() (see also L<SSL_set_shutdown(3)> call.
9e09eebf
LJ
58
59=back
60
61It is therefore recommended, to check the return value of SSL_shutdown()
62and call SSL_shutdown() again, if the bidirectional shutdown is not yet
45f55f6a 63complete (return value of the first call is 0).
9e09eebf 64
1bc74519 65The behaviour of SSL_shutdown() additionally depends on the underlying BIO.
cc99526d 66
1e4e5492 67If the underlying BIO is B<blocking>, SSL_shutdown() will only return once the
9e09eebf 68handshake step has been finished or an error occurred.
cc99526d 69
1e4e5492 70If the underlying BIO is B<non-blocking>, SSL_shutdown() will also return
cc99526d
RL
71when the underlying BIO could not satisfy the needs of SSL_shutdown()
72to continue the handshake. In this case a call to SSL_get_error() with the
1e4e5492
UM
73return value of SSL_shutdown() will yield B<SSL_ERROR_WANT_READ> or
74B<SSL_ERROR_WANT_WRITE>. The calling process then must repeat the call after
cc99526d
RL
75taking appropriate action to satisfy the needs of SSL_shutdown().
76The action depends on the underlying BIO. When using a non-blocking socket,
77nothing is to be done, but select() can be used to check for the required
78condition. When using a buffering BIO, like a BIO pair, data must be written
79into or retrieved out of the BIO before being able to continue.
80
cdd7c3ce
LJ
81SSL_shutdown() can be modified to only set the connection to "shutdown"
82state but not actually send the "close notify" alert messages,
9b86974e 83see L<SSL_CTX_set_quiet_shutdown(3)>.
cdd7c3ce
LJ
84When "quiet shutdown" is enabled, SSL_shutdown() will always succeed
85and return 1.
86
cc99526d
RL
87=head1 RETURN VALUES
88
89The following return values can occur:
90
91=over 4
92
c8919dde 93=item Z<>0
cc99526d 94
b2ed4629
LJ
95The shutdown is not yet finished. Call SSL_shutdown() for a second time,
96if a bidirectional shutdown shall be performed.
9b86974e 97The output of L<SSL_get_error(3)> may be misleading, as an
9e09eebf 98erroneous SSL_ERROR_SYSCALL may be flagged even though no error occurred.
cc99526d 99
c8919dde 100=item Z<>1
5cc27077
NA
101
102The shutdown was successfully completed. The "close notify" alert was sent
103and the peer's "close notify" alert was received.
104
fe757304 105=item E<lt>0
cc99526d 106
1e4e5492 107The shutdown was not successful because a fatal error occurred either
9e09eebf 108at the protocol level or a connection failure occurred. It can also occur if
cc99526d 109action is need to continue the operation for non-blocking BIOs.
9b86974e 110Call L<SSL_get_error(3)> with the return value B<ret>
9e09eebf 111to find out the reason.
cc99526d
RL
112
113=back
114
115=head1 SEE ALSO
116
9b86974e
RS
117L<SSL_get_error(3)>, L<SSL_connect(3)>,
118L<SSL_accept(3)>, L<SSL_set_shutdown(3)>,
119L<SSL_CTX_set_quiet_shutdown(3)>,
120L<SSL_clear(3)>, L<SSL_free(3)>,
b97fdb57 121L<ssl(7)>, L<bio(7)>
cc99526d 122
e2f92610
RS
123=head1 COPYRIGHT
124
125Copyright 2000-2016 The OpenSSL Project Authors. All Rights Reserved.
126
127Licensed under the OpenSSL license (the "License"). You may not use
128this file except in compliance with the License. You can obtain a copy
129in the file LICENSE in the source distribution or at
130L<https://www.openssl.org/source/license.html>.
131
132=cut