Deleted Added
full compact
SSL_shutdown.pod (79998) SSL_shutdown.pod (89837)
1=pod
2
3=head1 NAME
4
5SSL_shutdown - shut down a TLS/SSL connection
6
7=head1 SYNOPSIS
8

--- 8 unchanged lines hidden (view full) ---

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
1=pod
2
3=head1 NAME
4
5SSL_shutdown - shut down a TLS/SSL connection
6
7=head1 SYNOPSIS
8

--- 8 unchanged lines hidden (view full) ---

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
25The behaviour of SSL_shutdown() depends on the underlying BIO.
25The shutdown procedure consists of 2 steps: the sending of the "close notify"
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.
26
34
35SSL_shutdown() supports both uni- and bidirectional shutdown by its 2 step
36behaviour.
37
38=over 4
39
40=item When the application is the first party to send the "close notify"
41alert, SSL_shutdown() will only send the alert and the set the
42SSL_SENT_SHUTDOWN flag (so that the session is considered good and will
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.
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
52already processed implicitly inside another function
53(L<SSL_read(3)|SSL_read(3)>), the SSL_RECEIVED_SHUTDOWN flag is set.
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
57SSL_get_shutdown() (see also L<SSL_set_shutdown(3)|SSL_set_shutdown(3)> call.
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
63complete (return value of the first call is 0). As the shutdown is not
64specially handled in the SSLv2 protocol, SSL_shutdown() will succeed on
65the first call.
66
67The behaviour of SSL_shutdown() additionally depends on the underlying BIO.
68
27If the underlying BIO is B<blocking>, SSL_shutdown() will only return once the
69If the underlying BIO is B<blocking>, SSL_shutdown() will only return once the
28handshake has been finished or an error occurred.
70handshake step has been finished or an error occurred.
29
30If the underlying BIO is B<non-blocking>, SSL_shutdown() will also return
31when the underlying BIO could not satisfy the needs of SSL_shutdown()
32to continue the handshake. In this case a call to SSL_get_error() with the
33return value of SSL_shutdown() will yield B<SSL_ERROR_WANT_READ> or
34B<SSL_ERROR_WANT_WRITE>. The calling process then must repeat the call after
35taking appropriate action to satisfy the needs of SSL_shutdown().
36The action depends on the underlying BIO. When using a non-blocking socket,
37nothing is to be done, but select() can be used to check for the required
38condition. When using a buffering BIO, like a BIO pair, data must be written
39into or retrieved out of the BIO before being able to continue.
40
71
72If the underlying BIO is B<non-blocking>, SSL_shutdown() will also return
73when the underlying BIO could not satisfy the needs of SSL_shutdown()
74to continue the handshake. In this case a call to SSL_get_error() with the
75return value of SSL_shutdown() will yield B<SSL_ERROR_WANT_READ> or
76B<SSL_ERROR_WANT_WRITE>. The calling process then must repeat the call after
77taking appropriate action to satisfy the needs of SSL_shutdown().
78The action depends on the underlying BIO. When using a non-blocking socket,
79nothing is to be done, but select() can be used to check for the required
80condition. When using a buffering BIO, like a BIO pair, data must be written
81into or retrieved out of the BIO before being able to continue.
82
83SSL_shutdown() can be modified to only set the connection to "shutdown"
84state but not actually send the "close notify" alert messages,
85see L<SSL_CTX_set_quiet_shutdown(3)|SSL_CTX_set_quiet_shutdown(3)>.
86When "quiet shutdown" is enabled, SSL_shutdown() will always succeed
87and return 1.
88
41=head1 RETURN VALUES
42
43The following return values can occur:
44
45=over 4
46
47=item 1
48
89=head1 RETURN VALUES
90
91The following return values can occur:
92
93=over 4
94
95=item 1
96
49The shutdown was successfully completed.
97The shutdown was successfully completed. The "close notify" alert was sent
98and the peer's "close notify" alert was received.
50
51=item 0
52
99
100=item 0
101
53The shutdown was not successful. Call SSL_get_error() with the return
54value B<ret> to find out the reason.
102The shutdown is not yet finished. Call SSL_shutdown() for a second time,
103if a bidirectional shutdown shall be performed.
104The output of L<SSL_get_error(3)|SSL_get_error(3)> may be misleading, as an
105erroneous SSL_ERROR_SYSCALL may be flagged even though no error occurred.
55
56=item -1
57
58The shutdown was not successful because a fatal error occurred either
106
107=item -1
108
109The shutdown was not successful because a fatal error occurred either
59at the protocol level or a connection failure occurred. It can also occur of
110at the protocol level or a connection failure occurred. It can also occur if
60action is need to continue the operation for non-blocking BIOs.
111action is need to continue the operation for non-blocking BIOs.
61Call SSL_get_error() with the return value B<ret> to find out the reason.
112Call L<SSL_get_error(3)|SSL_get_error(3)> with the return value B<ret>
113to find out the reason.
62
63=back
64
65=head1 SEE ALSO
66
67L<SSL_get_error(3)|SSL_get_error(3)>, L<SSL_connect(3)|SSL_connect(3)>,
68L<SSL_accept(3)|SSL_accept(3)>, L<SSL_set_shutdown(3)|SSL_set_shutdown(3)>,
114
115=back
116
117=head1 SEE ALSO
118
119L<SSL_get_error(3)|SSL_get_error(3)>, L<SSL_connect(3)|SSL_connect(3)>,
120L<SSL_accept(3)|SSL_accept(3)>, L<SSL_set_shutdown(3)|SSL_set_shutdown(3)>,
121L<SSL_CTX_set_quiet_shutdown(3)|SSL_CTX_set_quiet_shutdown(3)>,
69L<SSL_clear(3)|SSL_clear(3)>, L<SSL_free(3)|SSL_free(3)>,
70L<ssl(3)|ssl(3)>, L<bio(3)|bio(3)>
71
72=cut
122L<SSL_clear(3)|SSL_clear(3)>, L<SSL_free(3)|SSL_free(3)>,
123L<ssl(3)|ssl(3)>, L<bio(3)|bio(3)>
124
125=cut