Blame doc/man3/SSL_get_error.pod

Packit c4476c
=pod
Packit c4476c
Packit c4476c
=head1 NAME
Packit c4476c
Packit c4476c
SSL_get_error - obtain result code for TLS/SSL I/O operation
Packit c4476c
Packit c4476c
=head1 SYNOPSIS
Packit c4476c
Packit c4476c
 #include <openssl/ssl.h>
Packit c4476c
Packit c4476c
 int SSL_get_error(const SSL *ssl, int ret);
Packit c4476c
Packit c4476c
=head1 DESCRIPTION
Packit c4476c
Packit c4476c
SSL_get_error() returns a result code (suitable for the C "switch"
Packit c4476c
statement) for a preceding call to SSL_connect(), SSL_accept(), SSL_do_handshake(),
Packit c4476c
SSL_read_ex(), SSL_read(), SSL_peek_ex(), SSL_peek(), SSL_shutdown(),
Packit c4476c
SSL_write_ex() or SSL_write() on B<ssl>.  The value returned by that TLS/SSL I/O
Packit c4476c
function must be passed to SSL_get_error() in parameter B<ret>.
Packit c4476c
Packit c4476c
In addition to B<ssl> and B<ret>, SSL_get_error() inspects the
Packit c4476c
current thread's OpenSSL error queue.  Thus, SSL_get_error() must be
Packit c4476c
used in the same thread that performed the TLS/SSL I/O operation, and no
Packit c4476c
other OpenSSL function calls should appear in between.  The current
Packit c4476c
thread's error queue must be empty before the TLS/SSL I/O operation is
Packit c4476c
attempted, or SSL_get_error() will not work reliably.
Packit c4476c
Packit c4476c
=head1 RETURN VALUES
Packit c4476c
Packit c4476c
The following return values can currently occur:
Packit c4476c
Packit c4476c
=over 4
Packit c4476c
Packit c4476c
=item SSL_ERROR_NONE
Packit c4476c
Packit c4476c
The TLS/SSL I/O operation completed.  This result code is returned
Packit c4476c
if and only if B<ret E<gt> 0>.
Packit c4476c
Packit c4476c
=item SSL_ERROR_ZERO_RETURN
Packit c4476c
Packit c4476c
The TLS/SSL peer has closed the connection for writing by sending the
Packit c4476c
close_notify alert.
Packit c4476c
No more data can be read.
Packit c4476c
Note that B<SSL_ERROR_ZERO_RETURN> does not necessarily
Packit c4476c
indicate that the underlying transport has been closed.
Packit c4476c
Packit c4476c
=item SSL_ERROR_WANT_READ, SSL_ERROR_WANT_WRITE
Packit c4476c
Packit c4476c
The operation did not complete and can be retried later.
Packit c4476c
Packit c4476c
B<SSL_ERROR_WANT_READ> is returned when the last operation was a read
Packit c4476c
operation from a non-blocking B<BIO>.
Packit c4476c
It means that not enough data was available at this time to complete the
Packit c4476c
operation.
Packit c4476c
If at a later time the underlying B<BIO> has data available for reading the same
Packit c4476c
function can be called again.
Packit c4476c
Packit c4476c
SSL_read() and SSL_read_ex() can also set B<SSL_ERROR_WANT_READ> when there is
Packit c4476c
still unprocessed data available at either the B<SSL> or the B<BIO> layer, even
Packit c4476c
for a blocking B<BIO>.
Packit c4476c
See L<SSL_read(3)> for more information.
Packit c4476c
Packit c4476c
B<SSL_ERROR_WANT_WRITE> is returned when the last operation was a write
Packit c4476c
to a non-blocking B<BIO> and it was unable to sent all data to the B<BIO>.
Packit c4476c
When the B<BIO> is writeable again, the same function can be called again.
Packit c4476c
Packit c4476c
Note that the retry may again lead to an B<SSL_ERROR_WANT_READ> or
Packit c4476c
B<SSL_ERROR_WANT_WRITE> condition.
Packit c4476c
There is no fixed upper limit for the number of iterations that
Packit c4476c
may be necessary until progress becomes visible at application
Packit c4476c
protocol level.
Packit c4476c
Packit c4476c
It is safe to call SSL_read() or SSL_read_ex() when more data is available
Packit c4476c
even when the call that set this error was an SSL_write() or SSL_write_ex().
Packit c4476c
However if the call was an SSL_write() or SSL_write_ex(), it should be called
Packit c4476c
again to continue sending the application data.
Packit c4476c
Packit c4476c
For socket B<BIO>s (e.g. when SSL_set_fd() was used), select() or
Packit c4476c
poll() on the underlying socket can be used to find out when the
Packit c4476c
TLS/SSL I/O function should be retried.
Packit c4476c
Packit c4476c
Caveat: Any TLS/SSL I/O function can lead to either of
Packit c4476c
B<SSL_ERROR_WANT_READ> and B<SSL_ERROR_WANT_WRITE>.
Packit c4476c
In particular,
Packit c4476c
SSL_read_ex(), SSL_read(), SSL_peek_ex(), or SSL_peek() may want to write data
Packit c4476c
and SSL_write() or SSL_write_ex() may want to read data.
Packit c4476c
This is mainly because
Packit c4476c
TLS/SSL handshakes may occur at any time during the protocol (initiated by
Packit c4476c
either the client or the server); SSL_read_ex(), SSL_read(), SSL_peek_ex(),
Packit c4476c
SSL_peek(), SSL_write_ex(), and SSL_write() will handle any pending handshakes.
Packit c4476c
Packit c4476c
=item SSL_ERROR_WANT_CONNECT, SSL_ERROR_WANT_ACCEPT
Packit c4476c
Packit c4476c
The operation did not complete; the same TLS/SSL I/O function should be
Packit c4476c
called again later. The underlying BIO was not connected yet to the peer
Packit c4476c
and the call would block in connect()/accept(). The SSL function should be
Packit c4476c
called again when the connection is established. These messages can only
Packit c4476c
appear with a BIO_s_connect() or BIO_s_accept() BIO, respectively.
Packit c4476c
In order to find out, when the connection has been successfully established,
Packit c4476c
on many platforms select() or poll() for writing on the socket file descriptor
Packit c4476c
can be used.
Packit c4476c
Packit c4476c
=item SSL_ERROR_WANT_X509_LOOKUP
Packit c4476c
Packit c4476c
The operation did not complete because an application callback set by
Packit c4476c
SSL_CTX_set_client_cert_cb() has asked to be called again.
Packit c4476c
The TLS/SSL I/O function should be called again later.
Packit c4476c
Details depend on the application.
Packit c4476c
Packit c4476c
=item SSL_ERROR_WANT_ASYNC
Packit c4476c
Packit c4476c
The operation did not complete because an asynchronous engine is still
Packit c4476c
processing data. This will only occur if the mode has been set to SSL_MODE_ASYNC
Packit c4476c
using L<SSL_CTX_set_mode(3)> or L<SSL_set_mode(3)> and an asynchronous capable
Packit c4476c
engine is being used. An application can determine whether the engine has
Packit c4476c
completed its processing using select() or poll() on the asynchronous wait file
Packit c4476c
descriptor. This file descriptor is available by calling
Packit c4476c
L<SSL_get_all_async_fds(3)> or L<SSL_get_changed_async_fds(3)>. The TLS/SSL I/O
Packit c4476c
function should be called again later. The function B<must> be called from the
Packit c4476c
same thread that the original call was made from.
Packit c4476c
Packit c4476c
=item SSL_ERROR_WANT_ASYNC_JOB
Packit c4476c
Packit c4476c
The asynchronous job could not be started because there were no async jobs
Packit c4476c
available in the pool (see ASYNC_init_thread(3)). This will only occur if the
Packit c4476c
mode has been set to SSL_MODE_ASYNC using L<SSL_CTX_set_mode(3)> or
Packit c4476c
L<SSL_set_mode(3)> and a maximum limit has been set on the async job pool
Packit c4476c
through a call to L<ASYNC_init_thread(3)>. The application should retry the
Packit c4476c
operation after a currently executing asynchronous operation for the current
Packit c4476c
thread has completed.
Packit c4476c
Packit c4476c
=item SSL_ERROR_WANT_CLIENT_HELLO_CB
Packit c4476c
Packit c4476c
The operation did not complete because an application callback set by
Packit c4476c
SSL_CTX_set_client_hello_cb() has asked to be called again.
Packit c4476c
The TLS/SSL I/O function should be called again later.
Packit c4476c
Details depend on the application.
Packit c4476c
Packit c4476c
=item SSL_ERROR_SYSCALL
Packit c4476c
Packit c4476c
Some non-recoverable, fatal I/O error occurred. The OpenSSL error queue may
Packit c4476c
contain more information on the error. For socket I/O on Unix systems, consult
Packit c4476c
B<errno> for details. If this error occurs then no further I/O operations should
Packit c4476c
be performed on the connection and SSL_shutdown() must not be called.
Packit c4476c
Packit c4476c
This value can also be returned for other errors, check the error queue for
Packit c4476c
details.
Packit c4476c
Packit c4476c
=item SSL_ERROR_SSL
Packit c4476c
Packit c4476c
A non-recoverable, fatal error in the SSL library occurred, usually a protocol
Packit c4476c
error.  The OpenSSL error queue contains more information on the error. If this
Packit c4476c
error occurs then no further I/O operations should be performed on the
Packit c4476c
connection and SSL_shutdown() must not be called.
Packit c4476c
Packit c4476c
=back
Packit c4476c
Packit c4476c
=head1 BUGS
Packit c4476c
Packit c4476c
The B<SSL_ERROR_SYSCALL> with B<errno> value of 0 indicates unexpected EOF from
Packit c4476c
the peer. This will be properly reported as B<SSL_ERROR_SSL> with reason
Packit c4476c
code B<SSL_R_UNEXPECTED_EOF_WHILE_READING> in the OpenSSL 3.0 release because
Packit c4476c
it is truly a TLS protocol error to terminate the connection without
Packit c4476c
a SSL_shutdown().
Packit c4476c
Packit c4476c
The issue is kept unfixed in OpenSSL 1.1.1 releases because many applications
Packit c4476c
which choose to ignore this protocol error depend on the existing way of
Packit c4476c
reporting the error.
Packit c4476c
Packit c4476c
=head1 SEE ALSO
Packit c4476c
Packit c4476c
L<ssl(7)>
Packit c4476c
Packit c4476c
=head1 HISTORY
Packit c4476c
Packit c4476c
The SSL_ERROR_WANT_ASYNC error code was added in OpenSSL 1.1.0.
Packit c4476c
The SSL_ERROR_WANT_CLIENT_HELLO_CB error code was added in OpenSSL 1.1.1.
Packit c4476c
Packit c4476c
=head1 COPYRIGHT
Packit c4476c
Packit c4476c
Copyright 2000-2020 The OpenSSL Project Authors. All Rights Reserved.
Packit c4476c
Packit c4476c
Licensed under the OpenSSL license (the "License").  You may not use
Packit c4476c
this file except in compliance with the License.  You can obtain a copy
Packit c4476c
in the file LICENSE in the source distribution or at
Packit c4476c
L<https://www.openssl.org/source/license.html>.
Packit c4476c
Packit c4476c
=cut