Skip to content

Commit 4b2cb40

Browse files
committed
wolfDTLS_accept_stateless: Fix handling for early data
- wolfDTLS_accept_stateless now returns before sending any flights. This allows the user to retrieve early data. - wolfio.c: Clearing `userSet` allows our callback to change the address while in stateless parsing
1 parent d456784 commit 4b2cb40

4 files changed

Lines changed: 19 additions & 5 deletions

File tree

src/ssl.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11012,6 +11012,12 @@ int wolfSSL_DTLS_SetCookieSecret(WOLFSSL* ssl,
1101211012
FALL_THROUGH;
1101311013

1101411014
case ACCEPT_FIRST_REPLY_DONE :
11015+
if (ssl->options.returnOnGoodCh) {
11016+
/* Higher level in stack wants us to return. Simulate a
11017+
* WANT_WRITE to accomplish this. */
11018+
ssl->error = WANT_WRITE;
11019+
return WOLFSSL_FATAL_ERROR;
11020+
}
1101511021
if ( (ssl->error = SendServerHello(ssl)) != 0) {
1101611022
#ifdef WOLFSSL_CHECK_ALERT_ON_ERR
1101711023
ProcessReplyEx(ssl, 1); /* See if an alert was sent. */
@@ -11312,15 +11318,19 @@ int wolfDTLS_accept_stateless(WOLFSSL* ssl)
1131211318
if (wolfDTLS_SetChGoodCb(ssl, chGoodDisableReadCB, &cb) != WOLFSSL_SUCCESS)
1131311319
return WOLFSSL_FATAL_ERROR;
1131411320

11321+
ssl->options.returnOnGoodCh = 1;
1131511322
ret = wolfSSL_accept(ssl);
11323+
ssl->options.returnOnGoodCh = 0;
1131611324
/* restore user options */
1131711325
ssl->options.disableRead = disableRead;
1131811326
(void)wolfDTLS_SetChGoodCb(ssl, cb.userCb, cb.userCtx);
1131911327
if (ret == WOLFSSL_SUCCESS) {
1132011328
WOLFSSL_MSG("should not happen. maybe the user called "
1132111329
"wolfDTLS_accept_stateless instead of wolfSSL_accept");
1132211330
}
11323-
else if (ssl->error == WC_NO_ERR_TRACE(WANT_READ)) {
11331+
else if (ssl->error == WC_NO_ERR_TRACE(WANT_READ) ||
11332+
ssl->error == WC_NO_ERR_TRACE(WANT_WRITE)) {
11333+
ssl->error = 0;
1132411334
if (ssl->options.dtlsStateful)
1132511335
ret = WOLFSSL_SUCCESS;
1132611336
else

src/tls13.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14647,6 +14647,12 @@ int wolfSSL_accept_TLSv13(WOLFSSL* ssl)
1464714647
FALL_THROUGH;
1464814648

1464914649
case TLS13_ACCEPT_SECOND_REPLY_DONE :
14650+
if (ssl->options.returnOnGoodCh) {
14651+
/* Higher level in stack wants us to return. Simulate a
14652+
* WANT_WRITE to accomplish this. */
14653+
ssl->error = WANT_WRITE;
14654+
return WOLFSSL_FATAL_ERROR;
14655+
}
1465014656

1465114657
if ((ssl->error = SendTls13ServerHello(ssl, server_hello)) != 0) {
1465214658
WOLFSSL_ERROR(ssl->error);

src/wolfio.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -686,10 +686,6 @@ int EmbedReceiveFrom(WOLFSSL *ssl, char *buf, int sz, void *ctx)
686686
/* Store the peer address. It is used to calculate the DTLS cookie. */
687687
newPeer = dtlsCtx->peer.sa == NULL || !ssl->options.dtlsStateful;
688688
peer = &lclPeer;
689-
if (dtlsCtx->peer.sa != NULL) {
690-
XMEMCPY(peer, (SOCKADDR_S*)dtlsCtx->peer.sa, MIN(sizeof(lclPeer),
691-
dtlsCtx->peer.sz));
692-
}
693689
peerSz = sizeof(lclPeer);
694690
}
695691

@@ -856,6 +852,7 @@ int EmbedReceiveFrom(WOLFSSL *ssl, char *buf, int sz, void *ctx)
856852
/* Store size of saved address. Locking handled internally. */
857853
if (wolfSSL_dtls_set_peer(ssl, peer, peerSz) != WOLFSSL_SUCCESS)
858854
return WOLFSSL_CBIO_ERR_GENERAL;
855+
dtlsCtx->userSet = 0;
859856
}
860857
#ifndef WOLFSSL_PEER_ADDRESS_CHANGES
861858
else {

wolfssl/internal.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5082,6 +5082,7 @@ struct Options {
50825082
#endif
50835083
word16 hrrSentKeyShare:1; /* HRR sent with key share */
50845084
#endif
5085+
word16 returnOnGoodCh:1;
50855086
word16 disableRead:1;
50865087
#ifdef WOLFSSL_DTLS
50875088
byte haveMcast; /* using multicast ? */

0 commit comments

Comments
 (0)