Merge pull request #7222 from rizlik/early_data_fix

tls13: wolfSSL_read_early_data() set outSz to 0 if no early data and update doc
This commit is contained in:
David Garske
2024-02-12 11:38:46 -08:00
committed by GitHub
3 changed files with 19 additions and 18 deletions

View File

@ -13938,9 +13938,11 @@ int wolfSSL_write_early_data(WOLFSSL* ssl, const void* data,
\brief This function reads any early data from a client on resumption. \brief This function reads any early data from a client on resumption.
Call this function instead of wolfSSL_accept() or wolfSSL_accept_TLSv13() Call this function instead of wolfSSL_accept() or wolfSSL_accept_TLSv13()
to accept a client and read any early data in the handshake. to accept a client and read any early data in the handshake. The function
If there is no early data than the handshake will be processed as normal. should be invoked until wolfSSL_is_init_finished() returns true. Early data
This function is only used with servers. may be sent by the client in multiple messsages. If there is no early data
then the handshake will be processed as normal. This function is only used
with servers.
\param [in,out] ssl a pointer to a WOLFSSL structure, created using wolfSSL_new(). \param [in,out] ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
\param [out] data a buffer to hold the early data read from client. \param [out] data a buffer to hold the early data read from client.
@ -13951,7 +13953,7 @@ int wolfSSL_write_early_data(WOLFSSL* ssl, const void* data,
not using TLSv1.3. not using TLSv1.3.
\return SIDE_ERROR if called with a client. \return SIDE_ERROR if called with a client.
\return WOLFSSL_FATAL_ERROR if accepting a connection fails. \return WOLFSSL_FATAL_ERROR if accepting a connection fails.
\return WOLFSSL_SUCCESS if successful. \return Number of early data bytes read (may be zero).
_Example_ _Example_
\code \code
@ -13963,19 +13965,16 @@ int wolfSSL_write_early_data(WOLFSSL* ssl, const void* data,
char buffer[80]; char buffer[80];
... ...
ret = wolfSSL_read_early_data(ssl, earlyData, sizeof(earlyData), &outSz); do {
if (ret != SSL_SUCCESS) { ret = wolfSSL_read_early_data(ssl, earlyData, sizeof(earlyData), &outSz);
err = wolfSSL_get_error(ssl, ret); if (ret < 0) {
printf(“error = %d, %s\n”, err, wolfSSL_ERR_error_string(err, buffer)); err = wolfSSL_get_error(ssl, ret);
} printf(“error = %d, %s\n”, err, wolfSSL_ERR_error_string(err, buffer));
if (outSz > 0) { }
// early data available if (outSz > 0) {
} // early data available
ret = wolfSSL_accept_TLSv13(ssl); }
if (ret != SSL_SUCCESS) { } while (!wolfSSL_is_init_finished(ssl));
err = wolfSSL_get_error(ssl, ret);
printf(“error = %d, %s\n”, err, wolfSSL_ERR_error_string(err, buffer));
}
\endcode \endcode
\sa wolfSSL_write_early_data \sa wolfSSL_write_early_data

View File

@ -14357,6 +14357,7 @@ int wolfSSL_read_early_data(WOLFSSL* ssl, void* data, int sz, int* outSz)
if (!IsAtLeastTLSv1_3(ssl->version)) if (!IsAtLeastTLSv1_3(ssl->version))
return BAD_FUNC_ARG; return BAD_FUNC_ARG;
*outSz = 0;
#ifndef NO_WOLFSSL_SERVER #ifndef NO_WOLFSSL_SERVER
if (ssl->options.side == WOLFSSL_CLIENT_END) if (ssl->options.side == WOLFSSL_CLIENT_END)
return SIDE_ERROR; return SIDE_ERROR;

View File

@ -69268,6 +69268,7 @@ static int test_tls13_early_data(void)
ExpectFalse(wolfSSL_is_init_finished(ssl_s)); ExpectFalse(wolfSSL_is_init_finished(ssl_s));
ExpectIntEQ(wolfSSL_read_early_data(ssl_s, msgBuf, sizeof(msgBuf), ExpectIntEQ(wolfSSL_read_early_data(ssl_s, msgBuf, sizeof(msgBuf),
&read), 0); &read), 0);
ExpectIntEQ(read, 0);
ExpectTrue(wolfSSL_is_init_finished(ssl_s)); ExpectTrue(wolfSSL_is_init_finished(ssl_s));
ExpectIntEQ(wolfSSL_connect(ssl_c), WOLFSSL_SUCCESS); ExpectIntEQ(wolfSSL_connect(ssl_c), WOLFSSL_SUCCESS);
@ -69278,7 +69279,7 @@ static int test_tls13_early_data(void)
ExpectFalse(wolfSSL_is_init_finished(ssl_s)); ExpectFalse(wolfSSL_is_init_finished(ssl_s));
ExpectIntEQ(wolfSSL_read_early_data(ssl_s, msgBuf, sizeof(msgBuf), ExpectIntEQ(wolfSSL_read_early_data(ssl_s, msgBuf, sizeof(msgBuf),
&read), 0); &read), 0);
ExpectIntEQ(read, 0);
ExpectTrue(wolfSSL_is_init_finished(ssl_s)); ExpectTrue(wolfSSL_is_init_finished(ssl_s));
/* Read server 0.5-RTT data */ /* Read server 0.5-RTT data */