|SSL_READ(3)||Library Functions Manual||SSL_READ(3)|
— read bytes from a TLS/SSL connection
*ssl, void *buf,
*ssl, void *buf,
tries to read num bytes from the specified
ssl into the buffer buf.
is identical to
SSL_read() except that no bytes are
removed from the underlying BIO during the read, such that a subsequent call
SSL_read() will yield at least the same bytes
In the following,
SSL_peek() are called “read
If necessary, a read function will negotiate a TLS/SSL session, if not already explicitly performed by SSL_connect(3) or SSL_accept(3). If the peer requests a re-negotiation, it will be performed transparently during the read function operation. The behaviour of the read functions depends on the underlying BIO.
For the transparent negotiation to succeed, the ssl must have been initialized to client or server mode. This is done by calling SSL_set_connect_state(3) or SSL_set_accept_state(3) before the first call to a read function.
The read functions works based on the SSL/TLS records. The data are received in records (with a maximum record size of 16kB). Only when a record has been completely received, it can be processed (decrypted and checked for integrity). Therefore data that was not retrieved at the last read call can still be buffered inside the SSL layer and will be retrieved on the next read call. If num is higher than the number of bytes buffered, the read functions will return with the bytes buffered. If no more bytes are in the buffer, the read functions will trigger the processing of the next record. Only when the record has been received and processed completely will the read functions return reporting success. At most the contents of the record will be returned. As the size of an SSL/TLS record may exceed the maximum packet size of the underlying transport (e.g., TCP), it may be necessary to read several packets from the transport layer before the record is complete and the read call can succeed.
If the underlying BIO is blocking, a read
function will only return once the read operation has been finished or an
error occurred, except when a renegotiation takes place, in which case an
SSL_ERROR_WANT_READ may occur. This behavior can be
controlled with the
SSL_MODE_AUTO_RETRY flag of the
If the underlying BIO is non-blocking, a
read function will also return when the underlying BIO
could not satisfy the needs of the function to continue the operation. In
this case a call to
the return value of the read function will yield
SSL_ERROR_WANT_WRITE. As at any time a
re-negotiation is possible, a read function may also cause write operations.
The calling process must then repeat the call after taking appropriate
action to satisfy the needs of the read function. The action depends on the
underlying BIO. When using a non-blocking socket,
nothing is to be done, but
select(2) can be used to
check for the required condition. When using a buffering
BIO, like a BIO pair, data must
be written into or retrieved out of the BIO before
being able to continue.
SSL_pending(3) can be used to find out whether there are buffered bytes available for immediate retrieval. In this case a read function can be called without blocking or actually receiving new data from the underlying socket.
When a read function operation has to be repeated because of
SSL_ERROR_WANT_WRITE, it must be repeated with the
The following return values can occur:
SSL_RECEIVED_SHUTDOWNflag in the ssl shutdown state is set (see SSL_shutdown(3) and SSL_set_shutdown(3)). It is also possible that the peer simply shut down the underlying transport and the shutdown is incomplete. Call
SSL_get_error() with the return value to find out whether an error occurred or the connection was shut down cleanly (
SSL_get_error() with the return value to find out the reason.
|December 7, 2016||OpenBSD-6.1|