Debian Codegraph @

upstream/debian-unstable/man3/SSL_get_error.3ssl

raw
1 .\" -*- mode: troff; coding: utf-8 -*-
2 .\" Automatically generated by Pod::Man 5.0102 (Pod::Simple 3.45)
3 .\"
4 .\" Standard preamble:
5 .\" ========================================================================
6 .de Sp \" Vertical space (when we can't use .PP)
7 .if t .sp .5v
8 .if n .sp
9 ..
10 .de Vb \" Begin verbatim text
11 .ft CW
12 .nf
13 .ne \\$1
14 ..
15 .de Ve \" End verbatim text
16 .ft R
17 .fi
18 ..
19 .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>.
20 .ie n \{\
21 . ds C` ""
22 . ds C' ""
23 'br\}
24 .el\{\
25 . ds C`
26 . ds C'
27 'br\}
28 .\"
29 .\" Escape single quotes in literal strings from groff's Unicode transform.
30 .ie \n(.g .ds Aq \(aq
31 .el .ds Aq '
32 .\"
33 .\" If the F register is >0, we'll generate index entries on stderr for
34 .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
35 .\" entries marked with X<> in POD. Of course, you'll have to process the
36 .\" output yourself in some meaningful fashion.
37 .\"
38 .\" Avoid warning from groff about undefined register 'F'.
39 .de IX
40 ..
41 .nr rF 0
42 .if \n(.g .if rF .nr rF 1
43 .if (\n(rF:(\n(.g==0)) \{\
44 . if \nF \{\
45 . de IX
46 . tm Index:\\$1\t\\n%\t"\\$2"
47 ..
48 . if !\nF==2 \{\
49 . nr % 0
50 . nr F 2
51 . \}
52 . \}
53 .\}
54 .rr rF
55 .\" ========================================================================
56 .\"
57 .IX Title "SSL_GET_ERROR 3SSL"
58 .TH SSL_GET_ERROR 3SSL 2026-04-07 3.6.2 OpenSSL
59 .\" For nroff, turn off justification. Always turn off hyphenation; it makes
60 .\" way too many mistakes in technical documents.
61 .if n .ad l
62 .nh
63 .SH NAME
64 SSL_get_error \- obtain result code for TLS/SSL I/O operation
65 .SH SYNOPSIS
66 .IX Header "SYNOPSIS"
67 .Vb 1
68 \& #include <openssl/ssl.h>
69 \&
70 \& int SSL_get_error(const SSL *ssl, int ret);
71 .Ve
72 .SH DESCRIPTION
73 .IX Header "DESCRIPTION"
74 \&\fBSSL_get_error()\fR returns a result code (suitable for the C "switch"
75 statement) for a preceding call to \fBSSL_connect()\fR, \fBSSL_accept()\fR, \fBSSL_do_handshake()\fR,
76 \&\fBSSL_read_ex()\fR, \fBSSL_read()\fR, \fBSSL_peek_ex()\fR, \fBSSL_peek()\fR, \fBSSL_shutdown()\fR,
77 \&\fBSSL_write_ex()\fR or \fBSSL_write()\fR on \fBssl\fR. The value returned by that TLS/SSL I/O
78 function must be passed to \fBSSL_get_error()\fR in parameter \fBret\fR.
79 .PP
80 In addition to \fBssl\fR and \fBret\fR, \fBSSL_get_error()\fR inspects the
81 current thread's OpenSSL error queue. Thus, \fBSSL_get_error()\fR must be
82 used in the same thread that performed the TLS/SSL I/O operation, and no
83 other OpenSSL function calls should appear in between. The current
84 thread's error queue must be empty before the TLS/SSL I/O operation is
85 attempted, or \fBSSL_get_error()\fR will not work reliably. Emptying the
86 current thread's error queue is done with \fBERR_clear_error\fR\|(3).
87 .SH NOTES
88 .IX Header "NOTES"
89 Some TLS implementations do not send a close_notify alert on shutdown.
90 .PP
91 On an unexpected EOF, versions before OpenSSL 3.0 returned
92 \&\fBSSL_ERROR_SYSCALL\fR, nothing was added to the error stack, and errno was 0.
93 Since OpenSSL 3.0 the returned error is \fBSSL_ERROR_SSL\fR with a meaningful
94 error on the error stack (SSL_R_UNEXPECTED_EOF_WHILE_READING). This error reason
95 code may be used for control flow decisions (see the man page for
96 \&\fBERR_GET_REASON\fR\|(3) for further details on this).
97 .SH "RETURN VALUES"
98 .IX Header "RETURN VALUES"
99 The following return values can currently occur:
100 .IP SSL_ERROR_NONE 4
101 .IX Item "SSL_ERROR_NONE"
102 The TLS/SSL I/O operation completed. This result code is returned
103 if and only if \fBret > 0\fR.
104 .IP SSL_ERROR_ZERO_RETURN 4
105 .IX Item "SSL_ERROR_ZERO_RETURN"
106 The TLS/SSL peer has closed the connection for writing by sending the
107 close_notify alert.
108 No more data can be read.
109 Note that \fBSSL_ERROR_ZERO_RETURN\fR does not necessarily
110 indicate that the underlying transport has been closed.
111 .Sp
112 This error can also appear when the option \fBSSL_OP_IGNORE_UNEXPECTED_EOF\fR
113 is set. See \fBSSL_CTX_set_options\fR\|(3) for more details.
114 .IP "SSL_ERROR_WANT_READ, SSL_ERROR_WANT_WRITE" 4
115 .IX Item "SSL_ERROR_WANT_READ, SSL_ERROR_WANT_WRITE"
116 The operation did not complete and can be retried later.
117 .Sp
118 For non-QUIC SSL objects, \fBSSL_ERROR_WANT_READ\fR is returned when the last
119 operation was a read operation from a nonblocking \fBBIO\fR.
120 It means that not enough data was available at this time to complete the
121 operation.
122 If at a later time the underlying \fBBIO\fR has data available for reading the same
123 function can be called again.
124 .Sp
125 \&\fBSSL_read()\fR and \fBSSL_read_ex()\fR can also set \fBSSL_ERROR_WANT_READ\fR when there is
126 still unprocessed data available at either the \fBSSL\fR or the \fBBIO\fR layer, even
127 for a blocking \fBBIO\fR.
128 See \fBSSL_read\fR\|(3) for more information.
129 .Sp
130 For non-QUIC SSL objects, \fBSSL_ERROR_WANT_WRITE\fR is returned when the last
131 operation was a write to a nonblocking \fBBIO\fR and it was unable to send all data
132 to the \fBBIO\fR. When the \fBBIO\fR is writable again, the same function can be
133 called again.
134 .Sp
135 Note that the retry may again lead to an \fBSSL_ERROR_WANT_READ\fR or
136 \&\fBSSL_ERROR_WANT_WRITE\fR condition.
137 There is no fixed upper limit for the number of iterations that
138 may be necessary until progress becomes visible at application
139 protocol level.
140 .Sp
141 For QUIC SSL objects, the meaning of \fBSSL_ERROR_WANT_READ\fR and
142 \&\fBSSL_ERROR_WANT_WRITE\fR have different but largely compatible semantics. Since
143 QUIC implements its own flow control and uses UDP datagrams, backpressure
144 conditions in terms of the underlying BIO providing network I/O are not directly
145 relevant to the circumstances in which these errors are produced. In particular,
146 \&\fBSSL_ERROR_WANT_WRITE\fR indicates that the OpenSSL internal send buffer for a
147 given QUIC stream has been filled. Likewise, \fBSSL_ERROR_WANT_READ\fR indicates
148 that the OpenSSL internal receive buffer for a given QUIC stream is empty.
149 .Sp
150 It is safe to call \fBSSL_read()\fR or \fBSSL_read_ex()\fR when more data is available
151 even when the call that set this error was an \fBSSL_write()\fR or \fBSSL_write_ex()\fR.
152 However, if the call was an \fBSSL_write()\fR or \fBSSL_write_ex()\fR, it should be called
153 again to continue sending the application data. If you get \fBSSL_ERROR_WANT_WRITE\fR
154 from \fBSSL_write()\fR or \fBSSL_write_ex()\fR then you should not do any other operation
155 that could trigger \fBIO\fR other than to repeat the previous \fBSSL_write()\fR call.
156 .Sp
157 For socket \fBBIO\fRs (e.g. when \fBSSL_set_fd()\fR was used), \fBselect()\fR or
158 \&\fBpoll()\fR on the underlying socket can be used to find out when the
159 TLS/SSL I/O function should be retried.
160 .Sp
161 Caveat: Any TLS/SSL I/O function can lead to either of
162 \&\fBSSL_ERROR_WANT_READ\fR and \fBSSL_ERROR_WANT_WRITE\fR.
163 In particular,
164 \&\fBSSL_read_ex()\fR, \fBSSL_read()\fR, \fBSSL_peek_ex()\fR, or \fBSSL_peek()\fR may want to write data
165 and \fBSSL_write()\fR or \fBSSL_write_ex()\fR may want to read data.
166 This is mainly because
167 TLS/SSL handshakes may occur at any time during the protocol (initiated by
168 either the client or the server); \fBSSL_read_ex()\fR, \fBSSL_read()\fR, \fBSSL_peek_ex()\fR,
169 \&\fBSSL_peek()\fR, \fBSSL_write_ex()\fR, and \fBSSL_write()\fR will handle any pending handshakes.
170 .IP "SSL_ERROR_WANT_CONNECT, SSL_ERROR_WANT_ACCEPT" 4
171 .IX Item "SSL_ERROR_WANT_CONNECT, SSL_ERROR_WANT_ACCEPT"
172 The operation did not complete; the same TLS/SSL I/O function should be
173 called again later. The underlying BIO was not connected yet to the peer
174 and the call would block in \fBconnect()\fR/\fBaccept()\fR. The SSL function should be
175 called again when the connection is established. These messages can only
176 appear with a \fBBIO_s_connect()\fR or \fBBIO_s_accept()\fR BIO, respectively.
177 In order to find out, when the connection has been successfully established,
178 on many platforms \fBselect()\fR or \fBpoll()\fR for writing on the socket file descriptor
179 can be used.
180 .IP SSL_ERROR_WANT_X509_LOOKUP 4
181 .IX Item "SSL_ERROR_WANT_X509_LOOKUP"
182 The operation did not complete because an application callback set by
183 \&\fBSSL_CTX_set_client_cert_cb()\fR has asked to be called again.
184 The TLS/SSL I/O function should be called again later.
185 Details depend on the application.
186 .IP SSL_ERROR_WANT_ASYNC 4
187 .IX Item "SSL_ERROR_WANT_ASYNC"
188 The operation did not complete because an asynchronous engine is still
189 processing data. This will only occur if the mode has been set to SSL_MODE_ASYNC
190 using \fBSSL_CTX_set_mode\fR\|(3) or \fBSSL_set_mode\fR\|(3) and an asynchronous capable
191 engine is being used. An application can determine whether the engine has
192 completed its processing using \fBselect()\fR or \fBpoll()\fR on the asynchronous wait file
193 descriptor. This file descriptor is available by calling
194 \&\fBSSL_get_all_async_fds\fR\|(3) or \fBSSL_get_changed_async_fds\fR\|(3). The TLS/SSL I/O
195 function should be called again later. The function \fBmust\fR be called from the
196 same thread that the original call was made from.
197 .IP SSL_ERROR_WANT_ASYNC_JOB 4
198 .IX Item "SSL_ERROR_WANT_ASYNC_JOB"
199 The asynchronous job could not be started because there were no async jobs
200 available in the pool (see \fBASYNC_init_thread\fR\|(3)). This will only occur if the
201 mode has been set to SSL_MODE_ASYNC using \fBSSL_CTX_set_mode\fR\|(3) or
202 \&\fBSSL_set_mode\fR\|(3) and a maximum limit has been set on the async job pool
203 through a call to \fBASYNC_init_thread\fR\|(3). The application should retry the
204 operation after a currently executing asynchronous operation for the current
205 thread has completed.
206 .IP SSL_ERROR_WANT_CLIENT_HELLO_CB 4
207 .IX Item "SSL_ERROR_WANT_CLIENT_HELLO_CB"
208 The operation did not complete because an application callback set by
209 \&\fBSSL_CTX_set_client_hello_cb()\fR has asked to be called again.
210 The TLS/SSL I/O function should be called again later.
211 Details depend on the application.
212 .IP SSL_ERROR_SYSCALL 4
213 .IX Item "SSL_ERROR_SYSCALL"
214 Some non-recoverable, fatal I/O error occurred. The OpenSSL error queue may
215 contain more information on the error. For socket I/O on Unix systems, consult
216 \&\fBerrno\fR for details. If this error occurs then no further I/O operations should
217 be performed on the connection and \fBSSL_shutdown()\fR must not be called.
218 .Sp
219 This value can also be returned for other errors, check the error queue for
220 details.
221 .IP SSL_ERROR_SSL 4
222 .IX Item "SSL_ERROR_SSL"
223 A non-recoverable, fatal error in the SSL library occurred, usually a protocol
224 error. The OpenSSL error queue contains more information on the error. If this
225 error occurs then no further I/O operations should be performed on the
226 connection and \fBSSL_shutdown()\fR must not be called.
227 .PP
228 The OpenSSL error queue can be inspected with the \fBERR\fR family of functions,
229 such as \fBERR_print_errors\fR\|(3) and \fBERR_peek_last_error_all\fR\|(3).
230 .SH "SEE ALSO"
231 .IX Header "SEE ALSO"
232 \&\fBssl\fR\|(7),
233 \&\fBERR_clear_error\fR\|(3), \fBERR_print_errors\fR\|(3), \fBERR_peek_last_error_all\fR\|(3)
234 .SH HISTORY
235 .IX Header "HISTORY"
236 The SSL_ERROR_WANT_ASYNC error code was added in OpenSSL 1.1.0.
237 The SSL_ERROR_WANT_CLIENT_HELLO_CB error code was added in OpenSSL 1.1.1.
238 .SH COPYRIGHT
239 .IX Header "COPYRIGHT"
240 Copyright 2000\-2024 The OpenSSL Project Authors. All Rights Reserved.
241 .PP
242 Licensed under the Apache License 2.0 (the "License"). You may not use
243 this file except in compliance with the License. You can obtain a copy
244 in the file LICENSE in the source distribution or at
245 <https://www.openssl.org/source/license.html>.