1*af52a8c1Sguenther.\" $OpenBSD: SSL_get_error.3,v 1.5 2018/04/29 07:37:01 guenther Exp $ 25c11e89dSschwarze.\" OpenSSL a528d4f0 Oct 27 13:40:11 2015 -0400 3f1a3c524Sschwarze.\" 45c11e89dSschwarze.\" This file was written by Bodo Moeller <bodo@openssl.org>. 55c11e89dSschwarze.\" Copyright (c) 2000, 2001, 2002, 2005 The OpenSSL Project. All rights reserved. 6f1a3c524Sschwarze.\" 75c11e89dSschwarze.\" Redistribution and use in source and binary forms, with or without 85c11e89dSschwarze.\" modification, are permitted provided that the following conditions 95c11e89dSschwarze.\" are met: 105c11e89dSschwarze.\" 115c11e89dSschwarze.\" 1. Redistributions of source code must retain the above copyright 125c11e89dSschwarze.\" notice, this list of conditions and the following disclaimer. 135c11e89dSschwarze.\" 145c11e89dSschwarze.\" 2. Redistributions in binary form must reproduce the above copyright 155c11e89dSschwarze.\" notice, this list of conditions and the following disclaimer in 165c11e89dSschwarze.\" the documentation and/or other materials provided with the 175c11e89dSschwarze.\" distribution. 185c11e89dSschwarze.\" 195c11e89dSschwarze.\" 3. All advertising materials mentioning features or use of this 205c11e89dSschwarze.\" software must display the following acknowledgment: 215c11e89dSschwarze.\" "This product includes software developed by the OpenSSL Project 225c11e89dSschwarze.\" for use in the OpenSSL Toolkit. (http://www.openssl.org/)" 235c11e89dSschwarze.\" 245c11e89dSschwarze.\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to 255c11e89dSschwarze.\" endorse or promote products derived from this software without 265c11e89dSschwarze.\" prior written permission. For written permission, please contact 275c11e89dSschwarze.\" openssl-core@openssl.org. 285c11e89dSschwarze.\" 295c11e89dSschwarze.\" 5. Products derived from this software may not be called "OpenSSL" 305c11e89dSschwarze.\" nor may "OpenSSL" appear in their names without prior written 315c11e89dSschwarze.\" permission of the OpenSSL Project. 325c11e89dSschwarze.\" 335c11e89dSschwarze.\" 6. Redistributions of any form whatsoever must retain the following 345c11e89dSschwarze.\" acknowledgment: 355c11e89dSschwarze.\" "This product includes software developed by the OpenSSL Project 365c11e89dSschwarze.\" for use in the OpenSSL Toolkit (http://www.openssl.org/)" 375c11e89dSschwarze.\" 385c11e89dSschwarze.\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY 395c11e89dSschwarze.\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 405c11e89dSschwarze.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 415c11e89dSschwarze.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR 425c11e89dSschwarze.\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 435c11e89dSschwarze.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 445c11e89dSschwarze.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 455c11e89dSschwarze.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 465c11e89dSschwarze.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 475c11e89dSschwarze.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 485c11e89dSschwarze.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 495c11e89dSschwarze.\" OF THE POSSIBILITY OF SUCH DAMAGE. 505c11e89dSschwarze.\" 51*af52a8c1Sguenther.Dd $Mdocdate: April 29 2018 $ 52f1a3c524Sschwarze.Dt SSL_GET_ERROR 3 53f1a3c524Sschwarze.Os 54f1a3c524Sschwarze.Sh NAME 55f1a3c524Sschwarze.Nm SSL_get_error 56f1a3c524Sschwarze.Nd obtain result code for TLS/SSL I/O operation 57f1a3c524Sschwarze.Sh SYNOPSIS 58f1a3c524Sschwarze.In openssl/ssl.h 59f1a3c524Sschwarze.Ft int 60f1a3c524Sschwarze.Fn SSL_get_error "const SSL *ssl" "int ret" 61f1a3c524Sschwarze.Sh DESCRIPTION 62f1a3c524Sschwarze.Fn SSL_get_error 63f1a3c524Sschwarzereturns a result code (suitable for the C 64f1a3c524Sschwarze.Dq switch 65f1a3c524Sschwarzestatement) for a preceding call to 66f1a3c524Sschwarze.Xr SSL_connect 3 , 67f1a3c524Sschwarze.Xr SSL_accept 3 , 68f1a3c524Sschwarze.Xr SSL_do_handshake 3 , 69f1a3c524Sschwarze.Xr SSL_read 3 , 70f1a3c524Sschwarze.Xr SSL_peek 3 , 71f1a3c524Sschwarzeor 72f1a3c524Sschwarze.Xr SSL_write 3 73f1a3c524Sschwarzeon 74f1a3c524Sschwarze.Fa ssl . 75f1a3c524SschwarzeThe value returned by that TLS/SSL I/O function must be passed to 76f1a3c524Sschwarze.Fn SSL_get_error 77f1a3c524Sschwarzein parameter 78f1a3c524Sschwarze.Fa ret . 79f1a3c524Sschwarze.Pp 80f1a3c524SschwarzeIn addition to 81f1a3c524Sschwarze.Fa ssl 82f1a3c524Sschwarzeand 83f1a3c524Sschwarze.Fa ret , 84f1a3c524Sschwarze.Fn SSL_get_error 85f1a3c524Sschwarzeinspects the current thread's OpenSSL error queue. 86f1a3c524SschwarzeThus, 87f1a3c524Sschwarze.Fn SSL_get_error 88f1a3c524Sschwarzemust be used in the same thread that performed the TLS/SSL I/O operation, 89f1a3c524Sschwarzeand no other OpenSSL function calls should appear in between. 90f1a3c524SschwarzeThe current thread's error queue must be empty before the TLS/SSL I/O operation 91f1a3c524Sschwarzeis attempted, or 92f1a3c524Sschwarze.Fn SSL_get_error 93f1a3c524Sschwarzewill not work reliably. 94f1a3c524Sschwarze.Sh RETURN VALUES 95f1a3c524SschwarzeThe following return values can currently occur: 96f1a3c524Sschwarze.Bl -tag -width Ds 97f1a3c524Sschwarze.It Dv SSL_ERROR_NONE 98f1a3c524SschwarzeThe TLS/SSL I/O operation completed. 99f1a3c524SschwarzeThis result code is returned if and only if 100f1a3c524Sschwarze.Fa ret 101*af52a8c1Sguenther> 0. 102f1a3c524Sschwarze.It Dv SSL_ERROR_ZERO_RETURN 103f1a3c524SschwarzeThe TLS/SSL connection has been closed. 104f1a3c524SschwarzeIf the protocol version is SSL 3.0 or TLS 1.0, this result code is returned 105f1a3c524Sschwarzeonly if a closure alert has occurred in the protocol, i.e., if the connection 106f1a3c524Sschwarzehas been closed cleanly. 107f1a3c524SschwarzeNote that in this case 108f1a3c524Sschwarze.Dv SSL_ERROR_ZERO_RETURN 109f1a3c524Sschwarzedoes not necessarily indicate that the underlying transport has been closed. 110f1a3c524Sschwarze.It Dv SSL_ERROR_WANT_READ , Dv SSL_ERROR_WANT_WRITE 111f1a3c524SschwarzeThe operation did not complete; 112f1a3c524Sschwarzethe same TLS/SSL I/O function should be called again later. 113f1a3c524SschwarzeIf, by then, the underlying 114f1a3c524Sschwarze.Vt BIO 115f1a3c524Sschwarzehas data available for reading (if the result code is 116f1a3c524Sschwarze.Dv SSL_ERROR_WANT_READ ) 117f1a3c524Sschwarzeor allows writing data 118f1a3c524Sschwarze.Pq Dv SSL_ERROR_WANT_WRITE , 119f1a3c524Sschwarzethen some TLS/SSL protocol progress will take place, 120f1a3c524Sschwarzei.e., at least part of a TLS/SSL record will be read or written. 121f1a3c524SschwarzeNote that the retry may again lead to a 122f1a3c524Sschwarze.Dv SSL_ERROR_WANT_READ 123f1a3c524Sschwarzeor 124f1a3c524Sschwarze.Dv SSL_ERROR_WANT_WRITE 125f1a3c524Sschwarzecondition. 126f1a3c524SschwarzeThere is no fixed upper limit for the number of iterations that may be 127f1a3c524Sschwarzenecessary until progress becomes visible at application protocol level. 128f1a3c524Sschwarze.Pp 129f1a3c524SschwarzeFor socket 130f1a3c524Sschwarze.Fa BIO Ns 131f1a3c524Sschwarzes (e.g., when 132f1a3c524Sschwarze.Fn SSL_set_fd 133f1a3c524Sschwarzewas used), 134f1a3c524Sschwarze.Xr select 2 135f1a3c524Sschwarzeor 136f1a3c524Sschwarze.Xr poll 2 137f1a3c524Sschwarzeon the underlying socket can be used to find out when the TLS/SSL I/O function 138f1a3c524Sschwarzeshould be retried. 139f1a3c524Sschwarze.Pp 140f1a3c524SschwarzeCaveat: Any TLS/SSL I/O function can lead to either of 141f1a3c524Sschwarze.Dv SSL_ERROR_WANT_READ 142f1a3c524Sschwarzeand 143f1a3c524Sschwarze.Dv SSL_ERROR_WANT_WRITE . 144f1a3c524SschwarzeIn particular, 145f1a3c524Sschwarze.Xr SSL_read 3 146f1a3c524Sschwarzeor 147f1a3c524Sschwarze.Xr SSL_peek 3 148f1a3c524Sschwarzemay want to write data and 149f1a3c524Sschwarze.Xr SSL_write 3 150f1a3c524Sschwarzemay want 151f1a3c524Sschwarzeto read data. 152f1a3c524SschwarzeThis is mainly because TLS/SSL handshakes may occur at any time during the 153f1a3c524Sschwarzeprotocol (initiated by either the client or the server); 154f1a3c524Sschwarze.Xr SSL_read 3 , 155f1a3c524Sschwarze.Xr SSL_peek 3 , 156f1a3c524Sschwarzeand 157f1a3c524Sschwarze.Xr SSL_write 3 158f1a3c524Sschwarzewill handle any pending handshakes. 159f1a3c524Sschwarze.It Dv SSL_ERROR_WANT_CONNECT , Dv SSL_ERROR_WANT_ACCEPT 160f1a3c524SschwarzeThe operation did not complete; the same TLS/SSL I/O function should be 161f1a3c524Sschwarzecalled again later. 162f1a3c524SschwarzeThe underlying BIO was not connected yet to the peer and the call would block 163f1a3c524Sschwarzein 164f1a3c524Sschwarze.Xr connect 2 Ns / Ns 165f1a3c524Sschwarze.Xr accept 2 . 166f1a3c524SschwarzeThe SSL function should be 167f1a3c524Sschwarzecalled again when the connection is established. 168f1a3c524SschwarzeThese messages can only appear with a 169f1a3c524Sschwarze.Xr BIO_s_connect 3 170f1a3c524Sschwarzeor 171f1a3c524Sschwarze.Xr BIO_s_accept 3 172f1a3c524Sschwarze.Vt BIO , 173f1a3c524Sschwarzerespectively. 174f1a3c524SschwarzeIn order to find out when the connection has been successfully established, 175f1a3c524Sschwarzeon many platforms 176f1a3c524Sschwarze.Xr select 2 177f1a3c524Sschwarzeor 178f1a3c524Sschwarze.Xr poll 2 179f1a3c524Sschwarzefor writing on the socket file descriptor can be used. 180f1a3c524Sschwarze.It Dv SSL_ERROR_WANT_X509_LOOKUP 181f1a3c524SschwarzeThe operation did not complete because an application callback set by 182f1a3c524Sschwarze.Xr SSL_CTX_set_client_cert_cb 3 183f1a3c524Sschwarzehas asked to be called again. 184f1a3c524SschwarzeThe TLS/SSL I/O function should be called again later. 185f1a3c524SschwarzeDetails depend on the application. 186f1a3c524Sschwarze.It Dv SSL_ERROR_SYSCALL 187f1a3c524SschwarzeSome I/O error occurred. 188f1a3c524SschwarzeThe OpenSSL error queue may contain more information on the error. 189f1a3c524SschwarzeIf the error queue is empty (i.e., 190f1a3c524Sschwarze.Fn ERR_get_error 191f1a3c524Sschwarzereturns 0), 192f1a3c524Sschwarze.Fa ret 193f1a3c524Sschwarzecan be used to find out more about the error: 194f1a3c524SschwarzeIf 195f1a3c524Sschwarze.Fa ret 196f1a3c524Sschwarze== 0, an 197f1a3c524Sschwarze.Dv EOF 198f1a3c524Sschwarzewas observed that violates the protocol. 199f1a3c524SschwarzeIf 200f1a3c524Sschwarze.Fa ret 201f1a3c524Sschwarze== \(mi1, the underlying 202f1a3c524Sschwarze.Vt BIO 203f1a3c524Sschwarzereported an 204f1a3c524SschwarzeI/O error (for socket I/O on Unix systems, consult 205f1a3c524Sschwarze.Dv errno 206f1a3c524Sschwarzefor details). 207f1a3c524Sschwarze.It Dv SSL_ERROR_SSL 208f1a3c524SschwarzeA failure in the SSL library occurred, usually a protocol error. 209f1a3c524SschwarzeThe OpenSSL error queue contains more information on the error. 210f1a3c524Sschwarze.El 211f1a3c524Sschwarze.Sh SEE ALSO 212f1a3c524Sschwarze.Xr err 3 , 213f1a3c524Sschwarze.Xr ssl 3 214f1a3c524Sschwarze.Sh HISTORY 215f1a3c524Sschwarze.Fn SSL_get_error 21610e00d17Sschwarzefirst appeared in SSLeay 0.8.0 and have been available since 2178fba1ec8Sschwarze.Ox 2.4 . 218