159191Skris=pod
259191Skris
359191Skris=head1 NAME
459191Skris
568651SkrisSSL_get_error - obtain result code for TLS/SSL I/O operation
659191Skris
759191Skris=head1 SYNOPSIS
859191Skris
959191Skris #include <openssl/ssl.h>
1059191Skris
11160814Ssimon int SSL_get_error(const SSL *ssl, int ret);
1259191Skris
1359191Skris=head1 DESCRIPTION
1459191Skris
1559191SkrisSSL_get_error() returns a result code (suitable for the C "switch"
16100936Snectarstatement) for a preceding call to SSL_connect(), SSL_accept(), SSL_do_handshake(),
1772613SkrisSSL_read(), SSL_peek(), or SSL_write() on B<ssl>.  The value returned by
1872613Skristhat TLS/SSL I/O function must be passed to SSL_get_error() in parameter
1959191SkrisB<ret>.
2059191Skris
2159191SkrisIn addition to B<ssl> and B<ret>, SSL_get_error() inspects the
2259191Skriscurrent thread's OpenSSL error queue.  Thus, SSL_get_error() must be
2368651Skrisused in the same thread that performed the TLS/SSL I/O operation, and no
2459191Skrisother OpenSSL function calls should appear in between.  The current
2568651Skristhread's error queue must be empty before the TLS/SSL I/O operation is
2659191Skrisattempted, or SSL_get_error() will not work reliably.
2759191Skris
2859191Skris=head1 RETURN VALUES
2959191Skris
3059191SkrisThe following return values can currently occur:
3159191Skris
3259191Skris=over 4
3359191Skris
3459191Skris=item SSL_ERROR_NONE
3559191Skris
3668651SkrisThe TLS/SSL I/O operation completed.  This result code is returned
3759191Skrisif and only if B<ret E<gt> 0>.
3859191Skris
3959191Skris=item SSL_ERROR_ZERO_RETURN
4059191Skris
4168651SkrisThe TLS/SSL connection has been closed.  If the protocol version is SSL 3.0
4259191Skrisor TLS 1.0, this result code is returned only if a closure
4368651Skrisalert has occurred in the protocol, i.e. if the connection has been
4468651Skrisclosed cleanly. Note that in this case B<SSL_ERROR_ZERO_RETURN>
4568651Skrisdoes not necessarily indicate that the underlying transport
4668651Skrishas been closed.
4759191Skris
4859191Skris=item SSL_ERROR_WANT_READ, SSL_ERROR_WANT_WRITE
4959191Skris
5068651SkrisThe operation did not complete; the same TLS/SSL I/O function should be
5172613Skriscalled again later.  If, by then, the underlying B<BIO> has data
5272613Skrisavailable for reading (if the result code is B<SSL_ERROR_WANT_READ>)
5372613Skrisor allows writing data (B<SSL_ERROR_WANT_WRITE>), then some TLS/SSL
5472613Skrisprotocol progress will take place, i.e. at least part of an TLS/SSL
5572613Skrisrecord will be read or written.  Note that the retry may again lead to
5672613Skrisa B<SSL_ERROR_WANT_READ> or B<SSL_ERROR_WANT_WRITE> condition.
5772613SkrisThere is no fixed upper limit for the number of iterations that
5872613Skrismay be necessary until progress becomes visible at application
5972613Skrisprotocol level.
6059191Skris
6172613SkrisFor socket B<BIO>s (e.g. when SSL_set_fd() was used), select() or
6272613Skrispoll() on the underlying socket can be used to find out when the
6372613SkrisTLS/SSL I/O function should be retried.
6472613Skris
6568651SkrisCaveat: Any TLS/SSL I/O function can lead to either of
6672613SkrisB<SSL_ERROR_WANT_READ> and B<SSL_ERROR_WANT_WRITE>.  In particular,
6772613SkrisSSL_read() or SSL_peek() may want to write data and SSL_write() may want
6872613Skristo read data.  This is mainly because TLS/SSL handshakes may occur at any
6972613Skristime during the protocol (initiated by either the client or the server);
7072613SkrisSSL_read(), SSL_peek(), and SSL_write() will handle any pending handshakes.
7159191Skris
7289837Skris=item SSL_ERROR_WANT_CONNECT, SSL_ERROR_WANT_ACCEPT
7379998Skris
7479998SkrisThe operation did not complete; the same TLS/SSL I/O function should be
7579998Skriscalled again later. The underlying BIO was not connected yet to the peer
7689837Skrisand the call would block in connect()/accept(). The SSL function should be
7789837Skriscalled again when the connection is established. These messages can only
7889837Skrisappear with a BIO_s_connect() or BIO_s_accept() BIO, respectively.
7979998SkrisIn order to find out, when the connection has been successfully established,
8079998Skrison many platforms select() or poll() for writing on the socket file descriptor
8179998Skriscan be used.
8279998Skris
8359191Skris=item SSL_ERROR_WANT_X509_LOOKUP
8459191Skris
8559191SkrisThe operation did not complete because an application callback set by
8659191SkrisSSL_CTX_set_client_cert_cb() has asked to be called again.
8768651SkrisThe TLS/SSL I/O function should be called again later.
8859191SkrisDetails depend on the application.
8959191Skris
9059191Skris=item SSL_ERROR_SYSCALL
9159191Skris
9259191SkrisSome I/O error occurred.  The OpenSSL error queue may contain more
9359191Skrisinformation on the error.  If the error queue is empty
9459191Skris(i.e. ERR_get_error() returns 0), B<ret> can be used to find out more
9559191Skrisabout the error: If B<ret == 0>, an EOF was observed that violates
9659191Skristhe protocol.  If B<ret == -1>, the underlying B<BIO> reported an
9759191SkrisI/O error (for socket I/O on Unix systems, consult B<errno> for details).
9859191Skris
9959191Skris=item SSL_ERROR_SSL
10059191Skris
10159191SkrisA failure in the SSL library occurred, usually a protocol error.  The
10259191SkrisOpenSSL error queue contains more information on the error.
10359191Skris
10459191Skris=back
10559191Skris
10659191Skris=head1 SEE ALSO
10759191Skris
10859191SkrisL<ssl(3)|ssl(3)>, L<err(3)|err(3)>
10959191Skris
11059191Skris=head1 HISTORY
11159191Skris
11259191SkrisSSL_get_error() was added in SSLeay 0.8.
11359191Skris
11459191Skris=cut
115