SSL_get_error.3ossl 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. .\" -*- mode: troff; coding: utf-8 -*-
  2. .\" Automatically generated by Pod::Man 5.01 (Pod::Simple 3.43)
  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 3ossl"
  58. .TH SSL_GET_ERROR 3ossl 2025-01-17 3.4.0 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.
  86. .SH NOTES
  87. .IX Header "NOTES"
  88. Some TLS implementations do not send a close_notify alert on shutdown.
  89. .PP
  90. On an unexpected EOF, versions before OpenSSL 3.0 returned
  91. \&\fBSSL_ERROR_SYSCALL\fR, nothing was added to the error stack, and errno was 0.
  92. Since OpenSSL 3.0 the returned error is \fBSSL_ERROR_SSL\fR with a meaningful
  93. error on the error stack (SSL_R_UNEXPECTED_EOF_WHILE_READING). This error reason
  94. code may be used for control flow decisions (see the man page for
  95. \&\fBERR_GET_REASON\fR\|(3) for further details on this).
  96. .SH "RETURN VALUES"
  97. .IX Header "RETURN VALUES"
  98. The following return values can currently occur:
  99. .IP SSL_ERROR_NONE 4
  100. .IX Item "SSL_ERROR_NONE"
  101. The TLS/SSL I/O operation completed. This result code is returned
  102. if and only if \fBret > 0\fR.
  103. .IP SSL_ERROR_ZERO_RETURN 4
  104. .IX Item "SSL_ERROR_ZERO_RETURN"
  105. The TLS/SSL peer has closed the connection for writing by sending the
  106. close_notify alert.
  107. No more data can be read.
  108. Note that \fBSSL_ERROR_ZERO_RETURN\fR does not necessarily
  109. indicate that the underlying transport has been closed.
  110. .Sp
  111. This error can also appear when the option \fBSSL_OP_IGNORE_UNEXPECTED_EOF\fR
  112. is set. See \fBSSL_CTX_set_options\fR\|(3) for more details.
  113. .IP "SSL_ERROR_WANT_READ, SSL_ERROR_WANT_WRITE" 4
  114. .IX Item "SSL_ERROR_WANT_READ, SSL_ERROR_WANT_WRITE"
  115. The operation did not complete and can be retried later.
  116. .Sp
  117. For non-QUIC SSL objects, \fBSSL_ERROR_WANT_READ\fR is returned when the last
  118. operation was a read operation from a nonblocking \fBBIO\fR.
  119. It means that not enough data was available at this time to complete the
  120. operation.
  121. If at a later time the underlying \fBBIO\fR has data available for reading the same
  122. function can be called again.
  123. .Sp
  124. \&\fBSSL_read()\fR and \fBSSL_read_ex()\fR can also set \fBSSL_ERROR_WANT_READ\fR when there is
  125. still unprocessed data available at either the \fBSSL\fR or the \fBBIO\fR layer, even
  126. for a blocking \fBBIO\fR.
  127. See \fBSSL_read\fR\|(3) for more information.
  128. .Sp
  129. For non-QUIC SSL objects, \fBSSL_ERROR_WANT_WRITE\fR is returned when the last
  130. operation was a write to a nonblocking \fBBIO\fR and it was unable to send all data
  131. to the \fBBIO\fR. When the \fBBIO\fR is writable again, the same function can be
  132. called again.
  133. .Sp
  134. Note that the retry may again lead to an \fBSSL_ERROR_WANT_READ\fR or
  135. \&\fBSSL_ERROR_WANT_WRITE\fR condition.
  136. There is no fixed upper limit for the number of iterations that
  137. may be necessary until progress becomes visible at application
  138. protocol level.
  139. .Sp
  140. For QUIC SSL objects, the meaning of \fBSSL_ERROR_WANT_READ\fR and
  141. \&\fBSSL_ERROR_WANT_WRITE\fR have different but largely compatible semantics. Since
  142. QUIC implements its own flow control and uses UDP datagrams, backpressure
  143. conditions in terms of the underlying BIO providing network I/O are not directly
  144. relevant to the circumstances in which these errors are produced. In particular,
  145. \&\fBSSL_ERROR_WANT_WRITE\fR indicates that the OpenSSL internal send buffer for a
  146. given QUIC stream has been filled. Likewise, \fBSSL_ERROR_WANT_READ\fR indicates
  147. that the OpenSSL internal receive buffer for a given QUIC stream is empty.
  148. .Sp
  149. It is safe to call \fBSSL_read()\fR or \fBSSL_read_ex()\fR when more data is available
  150. even when the call that set this error was an \fBSSL_write()\fR or \fBSSL_write_ex()\fR.
  151. However, if the call was an \fBSSL_write()\fR or \fBSSL_write_ex()\fR, it should be called
  152. again to continue sending the application data. If you get \fBSSL_ERROR_WANT_WRITE\fR
  153. from \fBSSL_write()\fR or \fBSSL_write_ex()\fR then you should not do any other operation
  154. that could trigger \fBIO\fR other than to repeat the previous \fBSSL_write()\fR call.
  155. .Sp
  156. For socket \fBBIO\fRs (e.g. when \fBSSL_set_fd()\fR was used), \fBselect()\fR or
  157. \&\fBpoll()\fR on the underlying socket can be used to find out when the
  158. TLS/SSL I/O function should be retried.
  159. .Sp
  160. Caveat: Any TLS/SSL I/O function can lead to either of
  161. \&\fBSSL_ERROR_WANT_READ\fR and \fBSSL_ERROR_WANT_WRITE\fR.
  162. In particular,
  163. \&\fBSSL_read_ex()\fR, \fBSSL_read()\fR, \fBSSL_peek_ex()\fR, or \fBSSL_peek()\fR may want to write data
  164. and \fBSSL_write()\fR or \fBSSL_write_ex()\fR may want to read data.
  165. This is mainly because
  166. TLS/SSL handshakes may occur at any time during the protocol (initiated by
  167. either the client or the server); \fBSSL_read_ex()\fR, \fBSSL_read()\fR, \fBSSL_peek_ex()\fR,
  168. \&\fBSSL_peek()\fR, \fBSSL_write_ex()\fR, and \fBSSL_write()\fR will handle any pending handshakes.
  169. .IP "SSL_ERROR_WANT_CONNECT, SSL_ERROR_WANT_ACCEPT" 4
  170. .IX Item "SSL_ERROR_WANT_CONNECT, SSL_ERROR_WANT_ACCEPT"
  171. The operation did not complete; the same TLS/SSL I/O function should be
  172. called again later. The underlying BIO was not connected yet to the peer
  173. and the call would block in \fBconnect()\fR/\fBaccept()\fR. The SSL function should be
  174. called again when the connection is established. These messages can only
  175. appear with a \fBBIO_s_connect()\fR or \fBBIO_s_accept()\fR BIO, respectively.
  176. In order to find out, when the connection has been successfully established,
  177. on many platforms \fBselect()\fR or \fBpoll()\fR for writing on the socket file descriptor
  178. can be used.
  179. .IP SSL_ERROR_WANT_X509_LOOKUP 4
  180. .IX Item "SSL_ERROR_WANT_X509_LOOKUP"
  181. The operation did not complete because an application callback set by
  182. \&\fBSSL_CTX_set_client_cert_cb()\fR has asked to be called again.
  183. The TLS/SSL I/O function should be called again later.
  184. Details depend on the application.
  185. .IP SSL_ERROR_WANT_ASYNC 4
  186. .IX Item "SSL_ERROR_WANT_ASYNC"
  187. The operation did not complete because an asynchronous engine is still
  188. processing data. This will only occur if the mode has been set to SSL_MODE_ASYNC
  189. using \fBSSL_CTX_set_mode\fR\|(3) or \fBSSL_set_mode\fR\|(3) and an asynchronous capable
  190. engine is being used. An application can determine whether the engine has
  191. completed its processing using \fBselect()\fR or \fBpoll()\fR on the asynchronous wait file
  192. descriptor. This file descriptor is available by calling
  193. \&\fBSSL_get_all_async_fds\fR\|(3) or \fBSSL_get_changed_async_fds\fR\|(3). The TLS/SSL I/O
  194. function should be called again later. The function \fBmust\fR be called from the
  195. same thread that the original call was made from.
  196. .IP SSL_ERROR_WANT_ASYNC_JOB 4
  197. .IX Item "SSL_ERROR_WANT_ASYNC_JOB"
  198. The asynchronous job could not be started because there were no async jobs
  199. available in the pool (see \fBASYNC_init_thread\fR\|(3)). This will only occur if the
  200. mode has been set to SSL_MODE_ASYNC using \fBSSL_CTX_set_mode\fR\|(3) or
  201. \&\fBSSL_set_mode\fR\|(3) and a maximum limit has been set on the async job pool
  202. through a call to \fBASYNC_init_thread\fR\|(3). The application should retry the
  203. operation after a currently executing asynchronous operation for the current
  204. thread has completed.
  205. .IP SSL_ERROR_WANT_CLIENT_HELLO_CB 4
  206. .IX Item "SSL_ERROR_WANT_CLIENT_HELLO_CB"
  207. The operation did not complete because an application callback set by
  208. \&\fBSSL_CTX_set_client_hello_cb()\fR has asked to be called again.
  209. The TLS/SSL I/O function should be called again later.
  210. Details depend on the application.
  211. .IP SSL_ERROR_SYSCALL 4
  212. .IX Item "SSL_ERROR_SYSCALL"
  213. Some non-recoverable, fatal I/O error occurred. The OpenSSL error queue may
  214. contain more information on the error. For socket I/O on Unix systems, consult
  215. \&\fBerrno\fR for details. If this error occurs then no further I/O operations should
  216. be performed on the connection and \fBSSL_shutdown()\fR must not be called.
  217. .Sp
  218. This value can also be returned for other errors, check the error queue for
  219. details.
  220. .IP SSL_ERROR_SSL 4
  221. .IX Item "SSL_ERROR_SSL"
  222. A non-recoverable, fatal error in the SSL library occurred, usually a protocol
  223. error. The OpenSSL error queue contains more information on the error. If this
  224. error occurs then no further I/O operations should be performed on the
  225. connection and \fBSSL_shutdown()\fR must not be called.
  226. .SH "SEE ALSO"
  227. .IX Header "SEE ALSO"
  228. \&\fBssl\fR\|(7)
  229. .SH HISTORY
  230. .IX Header "HISTORY"
  231. The SSL_ERROR_WANT_ASYNC error code was added in OpenSSL 1.1.0.
  232. The SSL_ERROR_WANT_CLIENT_HELLO_CB error code was added in OpenSSL 1.1.1.
  233. .SH COPYRIGHT
  234. .IX Header "COPYRIGHT"
  235. Copyright 2000\-2024 The OpenSSL Project Authors. All Rights Reserved.
  236. .PP
  237. Licensed under the Apache License 2.0 (the "License"). You may not use
  238. this file except in compliance with the License. You can obtain a copy
  239. in the file LICENSE in the source distribution or at
  240. <https://www.openssl.org/source/license.html>.