forked from wolfSSL/wolfssl
Fix async
This commit is contained in:
27
src/dtls13.c
27
src/dtls13.c
@ -2404,7 +2404,11 @@ static int Dtls13WriteAckMessage(WOLFSSL* ssl,
|
|||||||
c16toa(msgSz, ackMessage);
|
c16toa(msgSz, ackMessage);
|
||||||
ackMessage += OPAQUE16_LEN;
|
ackMessage += OPAQUE16_LEN;
|
||||||
|
|
||||||
|
WOLFSSL_MSG("write ack records");
|
||||||
|
|
||||||
while (recordNumberList != NULL) {
|
while (recordNumberList != NULL) {
|
||||||
|
WOLFSSL_MSG_EX("epoch %d seq %d", recordNumberList->epoch,
|
||||||
|
recordNumberList->seq);
|
||||||
c64toa(&recordNumberList->epoch, ackMessage);
|
c64toa(&recordNumberList->epoch, ackMessage);
|
||||||
ackMessage += OPAQUE64_LEN;
|
ackMessage += OPAQUE64_LEN;
|
||||||
c64toa(&recordNumberList->seq, ackMessage);
|
c64toa(&recordNumberList->seq, ackMessage);
|
||||||
@ -2596,10 +2600,13 @@ int DoDtls13Ack(WOLFSSL* ssl, const byte* input, word32 inputSize,
|
|||||||
if (length % (DTLS13_RN_SIZE) != 0)
|
if (length % (DTLS13_RN_SIZE) != 0)
|
||||||
return PARSE_ERROR;
|
return PARSE_ERROR;
|
||||||
|
|
||||||
|
WOLFSSL_MSG("read ack records");
|
||||||
|
|
||||||
ackMessage = input + OPAQUE16_LEN;
|
ackMessage = input + OPAQUE16_LEN;
|
||||||
for (i = 0; i < length; i += DTLS13_RN_SIZE) {
|
for (i = 0; i < length; i += DTLS13_RN_SIZE) {
|
||||||
ato64(ackMessage + i, &epoch);
|
ato64(ackMessage + i, &epoch);
|
||||||
ato64(ackMessage + i + OPAQUE64_LEN, &seq);
|
ato64(ackMessage + i + OPAQUE64_LEN, &seq);
|
||||||
|
WOLFSSL_MSG_EX("epoch %d seq %d", epoch, seq);
|
||||||
Dtls13RtxRemoveRecord(ssl, epoch, seq);
|
Dtls13RtxRemoveRecord(ssl, epoch, seq);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2670,14 +2677,13 @@ int SendDtls13Ack(WOLFSSL* ssl)
|
|||||||
if (ret != 0)
|
if (ret != 0)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
|
ret = Dtls13WriteAckMessage(ssl, ssl->dtls13Rtx.seenRecords, &length);
|
||||||
|
if (ret != 0)
|
||||||
|
return ret;
|
||||||
|
|
||||||
|
output = GetOutputBuffer(ssl);
|
||||||
|
|
||||||
if (w64IsZero(ssl->dtls13EncryptEpoch->epochNumber)) {
|
if (w64IsZero(ssl->dtls13EncryptEpoch->epochNumber)) {
|
||||||
|
|
||||||
ret = Dtls13WriteAckMessage(ssl, ssl->dtls13Rtx.seenRecords, &length);
|
|
||||||
if (ret != 0)
|
|
||||||
return ret;
|
|
||||||
|
|
||||||
output = GetOutputBuffer(ssl);
|
|
||||||
|
|
||||||
ret = Dtls13RlAddPlaintextHeader(ssl, output, ack, (word16)length);
|
ret = Dtls13RlAddPlaintextHeader(ssl, output, ack, (word16)length);
|
||||||
if (ret != 0)
|
if (ret != 0)
|
||||||
return ret;
|
return ret;
|
||||||
@ -2685,13 +2691,6 @@ int SendDtls13Ack(WOLFSSL* ssl)
|
|||||||
ssl->buffers.outputBuffer.length += length + DTLS_RECORD_HEADER_SZ;
|
ssl->buffers.outputBuffer.length += length + DTLS_RECORD_HEADER_SZ;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
||||||
ret = Dtls13WriteAckMessage(ssl, ssl->dtls13Rtx.seenRecords, &length);
|
|
||||||
if (ret != 0)
|
|
||||||
return ret;
|
|
||||||
|
|
||||||
output = GetOutputBuffer(ssl);
|
|
||||||
|
|
||||||
outputSize = ssl->buffers.outputBuffer.bufferSize -
|
outputSize = ssl->buffers.outputBuffer.bufferSize -
|
||||||
ssl->buffers.outputBuffer.idx -
|
ssl->buffers.outputBuffer.idx -
|
||||||
ssl->buffers.outputBuffer.length;
|
ssl->buffers.outputBuffer.length;
|
||||||
|
@ -17040,8 +17040,23 @@ static int _DtlsUpdateWindow(WOLFSSL* ssl)
|
|||||||
next_hi, next_lo, window);
|
next_hi, next_lo, window);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static WC_INLINE int DtlsShouldUpdateWindow(int ret)
|
||||||
|
{
|
||||||
|
switch (ret) {
|
||||||
|
case 0:
|
||||||
|
#ifdef WOLFSSL_ASYNC_CRYPT
|
||||||
|
case WC_PENDING_E:
|
||||||
|
#endif
|
||||||
|
case APP_DATA_READY:
|
||||||
|
return 1;
|
||||||
|
default:
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef WOLFSSL_DTLS13
|
#ifdef WOLFSSL_DTLS13
|
||||||
static WC_INLINE int Dtls13UpdateWindow(WOLFSSL* ssl)
|
|
||||||
|
static int Dtls13UpdateWindow(WOLFSSL* ssl)
|
||||||
{
|
{
|
||||||
w64wrapper nextSeq, seq;
|
w64wrapper nextSeq, seq;
|
||||||
w64wrapper diff64;
|
w64wrapper diff64;
|
||||||
@ -17104,6 +17119,14 @@ static WC_INLINE int Dtls13UpdateWindow(WOLFSSL* ssl)
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static WC_INLINE int Dtls13UpdateWindowRecordRecvd(WOLFSSL* ssl)
|
||||||
|
{
|
||||||
|
int ret = Dtls13UpdateWindow(ssl);
|
||||||
|
if (ret != 0)
|
||||||
|
return ret;
|
||||||
|
return Dtls13RecordRecvd(ssl);
|
||||||
|
}
|
||||||
#endif /* WOLFSSL_DTLS13 */
|
#endif /* WOLFSSL_DTLS13 */
|
||||||
|
|
||||||
int DtlsMsgDrain(WOLFSSL* ssl)
|
int DtlsMsgDrain(WOLFSSL* ssl)
|
||||||
@ -20805,7 +20828,8 @@ default:
|
|||||||
ssl->buffers.inputBuffer.buffer,
|
ssl->buffers.inputBuffer.buffer,
|
||||||
&ssl->buffers.inputBuffer.idx,
|
&ssl->buffers.inputBuffer.idx,
|
||||||
ssl->buffers.inputBuffer.length);
|
ssl->buffers.inputBuffer.length);
|
||||||
if (ret == 0 && ssl->options.dtlsStateful) {
|
if (DtlsShouldUpdateWindow(ret) &&
|
||||||
|
ssl->options.dtlsStateful) {
|
||||||
if (IsDtlsNotSctpMode(ssl))
|
if (IsDtlsNotSctpMode(ssl))
|
||||||
_DtlsUpdateWindow(ssl);
|
_DtlsUpdateWindow(ssl);
|
||||||
/* Reset timeout as we have received a valid
|
/* Reset timeout as we have received a valid
|
||||||
@ -20826,16 +20850,13 @@ default:
|
|||||||
ssl->buffers.inputBuffer.buffer,
|
ssl->buffers.inputBuffer.buffer,
|
||||||
&ssl->buffers.inputBuffer.idx,
|
&ssl->buffers.inputBuffer.idx,
|
||||||
ssl->buffers.inputBuffer.length);
|
ssl->buffers.inputBuffer.length);
|
||||||
if (ret == 0 && ssl->options.dtlsStateful) {
|
if (DtlsShouldUpdateWindow(ret) &&
|
||||||
ret = Dtls13UpdateWindow(ssl);
|
ssl->options.dtlsStateful) {
|
||||||
if (ret != 0) {
|
int updateRet =
|
||||||
WOLFSSL_ERROR(ret);
|
Dtls13UpdateWindowRecordRecvd(ssl);
|
||||||
return ret;
|
if (updateRet != 0) {
|
||||||
}
|
WOLFSSL_ERROR(updateRet);
|
||||||
ret = Dtls13RecordRecvd(ssl);
|
return updateRet;
|
||||||
if (ret != 0) {
|
|
||||||
WOLFSSL_ERROR(ret);
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#ifdef WOLFSSL_EARLY_DATA
|
#ifdef WOLFSSL_EARLY_DATA
|
||||||
@ -20960,12 +20981,7 @@ default:
|
|||||||
}
|
}
|
||||||
#ifdef WOLFSSL_DTLS13
|
#ifdef WOLFSSL_DTLS13
|
||||||
if (ssl->options.dtls) {
|
if (ssl->options.dtls) {
|
||||||
ret = Dtls13UpdateWindow(ssl);
|
ret = Dtls13UpdateWindowRecordRecvd(ssl);
|
||||||
if (ret != 0) {
|
|
||||||
WOLFSSL_ERROR(ret);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
ret = Dtls13RecordRecvd(ssl);
|
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
WOLFSSL_ERROR(ret);
|
WOLFSSL_ERROR(ret);
|
||||||
return ret;
|
return ret;
|
||||||
@ -21126,16 +21142,10 @@ default:
|
|||||||
ssl->buffers.inputBuffer.buffer,
|
ssl->buffers.inputBuffer.buffer,
|
||||||
&ssl->buffers.inputBuffer.idx, NO_SNIFF);
|
&ssl->buffers.inputBuffer.idx, NO_SNIFF);
|
||||||
#ifdef WOLFSSL_DTLS
|
#ifdef WOLFSSL_DTLS
|
||||||
if (ssl->options.dtls &&
|
if (ssl->options.dtls && DtlsShouldUpdateWindow(ret)) {
|
||||||
(ret == 0 || ret == APP_DATA_READY)) {
|
|
||||||
#ifdef WOLFSSL_DTLS13
|
#ifdef WOLFSSL_DTLS13
|
||||||
if (IsAtLeastTLSv1_3(ssl->version)) {
|
if (IsAtLeastTLSv1_3(ssl->version)) {
|
||||||
int updateRet = Dtls13UpdateWindow(ssl);
|
int updateRet = Dtls13UpdateWindowRecordRecvd(ssl);
|
||||||
if (updateRet != 0) {
|
|
||||||
WOLFSSL_ERROR(updateRet);
|
|
||||||
return updateRet;
|
|
||||||
}
|
|
||||||
updateRet = Dtls13RecordRecvd(ssl);
|
|
||||||
if (updateRet != 0) {
|
if (updateRet != 0) {
|
||||||
WOLFSSL_ERROR(updateRet);
|
WOLFSSL_ERROR(updateRet);
|
||||||
return updateRet;
|
return updateRet;
|
||||||
@ -21180,12 +21190,7 @@ default:
|
|||||||
if (ssl->options.dtls) {
|
if (ssl->options.dtls) {
|
||||||
#ifdef WOLFSSL_DTLS13
|
#ifdef WOLFSSL_DTLS13
|
||||||
if (IsAtLeastTLSv1_3(ssl->version)) {
|
if (IsAtLeastTLSv1_3(ssl->version)) {
|
||||||
ret = Dtls13UpdateWindow(ssl);
|
ret = Dtls13UpdateWindowRecordRecvd(ssl);
|
||||||
if (ret != 0) {
|
|
||||||
WOLFSSL_ERROR(ret);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
ret = Dtls13RecordRecvd(ssl);
|
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
WOLFSSL_ERROR(ret);
|
WOLFSSL_ERROR(ret);
|
||||||
return ret;
|
return ret;
|
||||||
@ -21211,18 +21216,15 @@ default:
|
|||||||
ssl->keys.padSz, &processedSize);
|
ssl->keys.padSz, &processedSize);
|
||||||
ssl->buffers.inputBuffer.idx += processedSize;
|
ssl->buffers.inputBuffer.idx += processedSize;
|
||||||
ssl->buffers.inputBuffer.idx += ssl->keys.padSz;
|
ssl->buffers.inputBuffer.idx += ssl->keys.padSz;
|
||||||
|
if (DtlsShouldUpdateWindow(ret)) {
|
||||||
|
int updateRet = Dtls13UpdateWindowRecordRecvd(ssl);
|
||||||
|
if (updateRet != 0) {
|
||||||
|
WOLFSSL_ERROR(updateRet);
|
||||||
|
return updateRet;
|
||||||
|
}
|
||||||
|
}
|
||||||
if (ret != 0)
|
if (ret != 0)
|
||||||
return ret;
|
return ret;
|
||||||
ret = Dtls13UpdateWindow(ssl);
|
|
||||||
if (ret != 0) {
|
|
||||||
WOLFSSL_ERROR(ret);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
ret = Dtls13RecordRecvd(ssl);
|
|
||||||
if (ret != 0) {
|
|
||||||
WOLFSSL_ERROR(ret);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
FALL_THROUGH;
|
FALL_THROUGH;
|
||||||
|
Reference in New Issue
Block a user