Skip to content

Commit 06f04de

Browse files
authored
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
2 parents 83ae724 + 7b0fefb commit 06f04de

3 files changed

Lines changed: 19 additions & 18 deletions

File tree

doc/dox_comments/header_files/ssl.h

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13938,9 +13938,11 @@ int wolfSSL_write_early_data(WOLFSSL* ssl, const void* data,
1393813938
1393913939
\brief This function reads any early data from a client on resumption.
1394013940
Call this function instead of wolfSSL_accept() or wolfSSL_accept_TLSv13()
13941-
to accept a client and read any early data in the handshake.
13942-
If there is no early data than the handshake will be processed as normal.
13943-
This function is only used with servers.
13941+
to accept a client and read any early data in the handshake. The function
13942+
should be invoked until wolfSSL_is_init_finished() returns true. Early data
13943+
may be sent by the client in multiple messsages. If there is no early data
13944+
then the handshake will be processed as normal. This function is only used
13945+
with servers.
1394413946
1394513947
\param [in,out] ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
1394613948
\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,
1395113953
not using TLSv1.3.
1395213954
\return SIDE_ERROR if called with a client.
1395313955
\return WOLFSSL_FATAL_ERROR if accepting a connection fails.
13954-
\return WOLFSSL_SUCCESS if successful.
13956+
\return Number of early data bytes read (may be zero).
1395513957
1395613958
_Example_
1395713959
\code
@@ -13963,19 +13965,16 @@ int wolfSSL_write_early_data(WOLFSSL* ssl, const void* data,
1396313965
char buffer[80];
1396413966
...
1396513967
13966-
ret = wolfSSL_read_early_data(ssl, earlyData, sizeof(earlyData), &outSz);
13967-
if (ret != SSL_SUCCESS) {
13968-
err = wolfSSL_get_error(ssl, ret);
13969-
printf(“error = %d, %s\n”, err, wolfSSL_ERR_error_string(err, buffer));
13970-
}
13971-
if (outSz > 0) {
13972-
// early data available
13973-
}
13974-
ret = wolfSSL_accept_TLSv13(ssl);
13975-
if (ret != SSL_SUCCESS) {
13976-
err = wolfSSL_get_error(ssl, ret);
13977-
printf(“error = %d, %s\n”, err, wolfSSL_ERR_error_string(err, buffer));
13978-
}
13968+
do {
13969+
ret = wolfSSL_read_early_data(ssl, earlyData, sizeof(earlyData), &outSz);
13970+
if (ret < 0) {
13971+
err = wolfSSL_get_error(ssl, ret);
13972+
printf(“error = %d, %s\n”, err, wolfSSL_ERR_error_string(err, buffer));
13973+
}
13974+
if (outSz > 0) {
13975+
// early data available
13976+
}
13977+
} while (!wolfSSL_is_init_finished(ssl));
1397913978
\endcode
1398013979
1398113980
\sa wolfSSL_write_early_data

src/tls13.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14357,6 +14357,7 @@ int wolfSSL_read_early_data(WOLFSSL* ssl, void* data, int sz, int* outSz)
1435714357
if (!IsAtLeastTLSv1_3(ssl->version))
1435814358
return BAD_FUNC_ARG;
1435914359

14360+
*outSz = 0;
1436014361
#ifndef NO_WOLFSSL_SERVER
1436114362
if (ssl->options.side == WOLFSSL_CLIENT_END)
1436214363
return SIDE_ERROR;

tests/api.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69268,6 +69268,7 @@ static int test_tls13_early_data(void)
6926869268
ExpectFalse(wolfSSL_is_init_finished(ssl_s));
6926969269
ExpectIntEQ(wolfSSL_read_early_data(ssl_s, msgBuf, sizeof(msgBuf),
6927069270
&read), 0);
69271+
ExpectIntEQ(read, 0);
6927169272
ExpectTrue(wolfSSL_is_init_finished(ssl_s));
6927269273

6927369274
ExpectIntEQ(wolfSSL_connect(ssl_c), WOLFSSL_SUCCESS);
@@ -69278,7 +69279,7 @@ static int test_tls13_early_data(void)
6927869279
ExpectFalse(wolfSSL_is_init_finished(ssl_s));
6927969280
ExpectIntEQ(wolfSSL_read_early_data(ssl_s, msgBuf, sizeof(msgBuf),
6928069281
&read), 0);
69281-
69282+
ExpectIntEQ(read, 0);
6928269283
ExpectTrue(wolfSSL_is_init_finished(ssl_s));
6928369284

6928469285
/* Read server 0.5-RTT data */

0 commit comments

Comments
 (0)