Skip to content

Commit 3a88107

Browse files
committed
Fix async
1 parent 2c6c520 commit 3a88107

2 files changed

Lines changed: 56 additions & 55 deletions

File tree

src/dtls13.c

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2404,7 +2404,11 @@ static int Dtls13WriteAckMessage(WOLFSSL* ssl,
24042404
c16toa(msgSz, ackMessage);
24052405
ackMessage += OPAQUE16_LEN;
24062406

2407+
WOLFSSL_MSG("write ack records");
2408+
24072409
while (recordNumberList != NULL) {
2410+
WOLFSSL_MSG_EX("epoch %d seq %d", recordNumberList->epoch,
2411+
recordNumberList->seq);
24082412
c64toa(&recordNumberList->epoch, ackMessage);
24092413
ackMessage += OPAQUE64_LEN;
24102414
c64toa(&recordNumberList->seq, ackMessage);
@@ -2596,10 +2600,13 @@ int DoDtls13Ack(WOLFSSL* ssl, const byte* input, word32 inputSize,
25962600
if (length % (DTLS13_RN_SIZE) != 0)
25972601
return PARSE_ERROR;
25982602

2603+
WOLFSSL_MSG("read ack records");
2604+
25992605
ackMessage = input + OPAQUE16_LEN;
26002606
for (i = 0; i < length; i += DTLS13_RN_SIZE) {
26012607
ato64(ackMessage + i, &epoch);
26022608
ato64(ackMessage + i + OPAQUE64_LEN, &seq);
2609+
WOLFSSL_MSG_EX("epoch %d seq %d", epoch, seq);
26032610
Dtls13RtxRemoveRecord(ssl, epoch, seq);
26042611
}
26052612

@@ -2670,28 +2677,20 @@ int SendDtls13Ack(WOLFSSL* ssl)
26702677
if (ret != 0)
26712678
return ret;
26722679

2673-
if (w64IsZero(ssl->dtls13EncryptEpoch->epochNumber)) {
2674-
2675-
ret = Dtls13WriteAckMessage(ssl, ssl->dtls13Rtx.seenRecords, &length);
2676-
if (ret != 0)
2677-
return ret;
2680+
ret = Dtls13WriteAckMessage(ssl, ssl->dtls13Rtx.seenRecords, &length);
2681+
if (ret != 0)
2682+
return ret;
26782683

2679-
output = GetOutputBuffer(ssl);
2684+
output = GetOutputBuffer(ssl);
26802685

2686+
if (w64IsZero(ssl->dtls13EncryptEpoch->epochNumber)) {
26812687
ret = Dtls13RlAddPlaintextHeader(ssl, output, ack, (word16)length);
26822688
if (ret != 0)
26832689
return ret;
26842690

26852691
ssl->buffers.outputBuffer.length += length + DTLS_RECORD_HEADER_SZ;
26862692
}
26872693
else {
2688-
2689-
ret = Dtls13WriteAckMessage(ssl, ssl->dtls13Rtx.seenRecords, &length);
2690-
if (ret != 0)
2691-
return ret;
2692-
2693-
output = GetOutputBuffer(ssl);
2694-
26952694
outputSize = ssl->buffers.outputBuffer.bufferSize -
26962695
ssl->buffers.outputBuffer.idx -
26972696
ssl->buffers.outputBuffer.length;

src/internal.c

Lines changed: 44 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -17040,8 +17040,23 @@ static int _DtlsUpdateWindow(WOLFSSL* ssl)
1704017040
next_hi, next_lo, window);
1704117041
}
1704217042

17043+
static WC_INLINE int DtlsShouldUpdateWindow(int ret)
17044+
{
17045+
switch (ret) {
17046+
case 0:
17047+
#ifdef WOLFSSL_ASYNC_CRYPT
17048+
case WC_PENDING_E:
17049+
#endif
17050+
case APP_DATA_READY:
17051+
return 1;
17052+
default:
17053+
return 0;
17054+
}
17055+
}
17056+
1704317057
#ifdef WOLFSSL_DTLS13
17044-
static WC_INLINE int Dtls13UpdateWindow(WOLFSSL* ssl)
17058+
17059+
static int Dtls13UpdateWindow(WOLFSSL* ssl)
1704517060
{
1704617061
w64wrapper nextSeq, seq;
1704717062
w64wrapper diff64;
@@ -17104,6 +17119,14 @@ static WC_INLINE int Dtls13UpdateWindow(WOLFSSL* ssl)
1710417119

1710517120
return 0;
1710617121
}
17122+
17123+
static WC_INLINE int Dtls13UpdateWindowRecordRecvd(WOLFSSL* ssl)
17124+
{
17125+
int ret = Dtls13UpdateWindow(ssl);
17126+
if (ret != 0)
17127+
return ret;
17128+
return Dtls13RecordRecvd(ssl);
17129+
}
1710717130
#endif /* WOLFSSL_DTLS13 */
1710817131

1710917132
int DtlsMsgDrain(WOLFSSL* ssl)
@@ -20805,7 +20828,8 @@ int ProcessReplyEx(WOLFSSL* ssl, int allowSocketErr)
2080520828
ssl->buffers.inputBuffer.buffer,
2080620829
&ssl->buffers.inputBuffer.idx,
2080720830
ssl->buffers.inputBuffer.length);
20808-
if (ret == 0 && ssl->options.dtlsStateful) {
20831+
if (DtlsShouldUpdateWindow(ret) &&
20832+
ssl->options.dtlsStateful) {
2080920833
if (IsDtlsNotSctpMode(ssl))
2081020834
_DtlsUpdateWindow(ssl);
2081120835
/* Reset timeout as we have received a valid
@@ -20826,16 +20850,13 @@ int ProcessReplyEx(WOLFSSL* ssl, int allowSocketErr)
2082620850
ssl->buffers.inputBuffer.buffer,
2082720851
&ssl->buffers.inputBuffer.idx,
2082820852
ssl->buffers.inputBuffer.length);
20829-
if (ret == 0 && ssl->options.dtlsStateful) {
20830-
ret = Dtls13UpdateWindow(ssl);
20831-
if (ret != 0) {
20832-
WOLFSSL_ERROR(ret);
20833-
return ret;
20834-
}
20835-
ret = Dtls13RecordRecvd(ssl);
20836-
if (ret != 0) {
20837-
WOLFSSL_ERROR(ret);
20838-
return ret;
20853+
if (DtlsShouldUpdateWindow(ret) &&
20854+
ssl->options.dtlsStateful) {
20855+
int updateRet =
20856+
Dtls13UpdateWindowRecordRecvd(ssl);
20857+
if (updateRet != 0) {
20858+
WOLFSSL_ERROR(updateRet);
20859+
return updateRet;
2083920860
}
2084020861
}
2084120862
#ifdef WOLFSSL_EARLY_DATA
@@ -20960,12 +20981,7 @@ int ProcessReplyEx(WOLFSSL* ssl, int allowSocketErr)
2096020981
}
2096120982
#ifdef WOLFSSL_DTLS13
2096220983
if (ssl->options.dtls) {
20963-
ret = Dtls13UpdateWindow(ssl);
20964-
if (ret != 0) {
20965-
WOLFSSL_ERROR(ret);
20966-
return ret;
20967-
}
20968-
ret = Dtls13RecordRecvd(ssl);
20984+
ret = Dtls13UpdateWindowRecordRecvd(ssl);
2096920985
if (ret != 0) {
2097020986
WOLFSSL_ERROR(ret);
2097120987
return ret;
@@ -21126,16 +21142,10 @@ int ProcessReplyEx(WOLFSSL* ssl, int allowSocketErr)
2112621142
ssl->buffers.inputBuffer.buffer,
2112721143
&ssl->buffers.inputBuffer.idx, NO_SNIFF);
2112821144
#ifdef WOLFSSL_DTLS
21129-
if (ssl->options.dtls &&
21130-
(ret == 0 || ret == APP_DATA_READY)) {
21145+
if (ssl->options.dtls && DtlsShouldUpdateWindow(ret)) {
2113121146
#ifdef WOLFSSL_DTLS13
2113221147
if (IsAtLeastTLSv1_3(ssl->version)) {
21133-
int updateRet = Dtls13UpdateWindow(ssl);
21134-
if (updateRet != 0) {
21135-
WOLFSSL_ERROR(updateRet);
21136-
return updateRet;
21137-
}
21138-
updateRet = Dtls13RecordRecvd(ssl);
21148+
int updateRet = Dtls13UpdateWindowRecordRecvd(ssl);
2113921149
if (updateRet != 0) {
2114021150
WOLFSSL_ERROR(updateRet);
2114121151
return updateRet;
@@ -21180,12 +21190,7 @@ int ProcessReplyEx(WOLFSSL* ssl, int allowSocketErr)
2118021190
if (ssl->options.dtls) {
2118121191
#ifdef WOLFSSL_DTLS13
2118221192
if (IsAtLeastTLSv1_3(ssl->version)) {
21183-
ret = Dtls13UpdateWindow(ssl);
21184-
if (ret != 0) {
21185-
WOLFSSL_ERROR(ret);
21186-
return ret;
21187-
}
21188-
ret = Dtls13RecordRecvd(ssl);
21193+
ret = Dtls13UpdateWindowRecordRecvd(ssl);
2118921194
if (ret != 0) {
2119021195
WOLFSSL_ERROR(ret);
2119121196
return ret;
@@ -21211,18 +21216,15 @@ int ProcessReplyEx(WOLFSSL* ssl, int allowSocketErr)
2121121216
ssl->keys.padSz, &processedSize);
2121221217
ssl->buffers.inputBuffer.idx += processedSize;
2121321218
ssl->buffers.inputBuffer.idx += ssl->keys.padSz;
21214-
if (ret != 0)
21215-
return ret;
21216-
ret = Dtls13UpdateWindow(ssl);
21217-
if (ret != 0) {
21218-
WOLFSSL_ERROR(ret);
21219-
return ret;
21219+
if (DtlsShouldUpdateWindow(ret)) {
21220+
int updateRet = Dtls13UpdateWindowRecordRecvd(ssl);
21221+
if (updateRet != 0) {
21222+
WOLFSSL_ERROR(updateRet);
21223+
return updateRet;
21224+
}
2122021225
}
21221-
ret = Dtls13RecordRecvd(ssl);
21222-
if (ret != 0) {
21223-
WOLFSSL_ERROR(ret);
21226+
if (ret != 0)
2122421227
return ret;
21225-
}
2122621228
break;
2122721229
}
2122821230
FALL_THROUGH;

0 commit comments

Comments
 (0)