Skip to content

Commit

Permalink
Add option to remove early sanity checks
Browse files Browse the repository at this point in the history
  • Loading branch information
julek-wolfssl committed Dec 12, 2023
1 parent 627310d commit 493bb17
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/dtls13.c
Original file line number Diff line number Diff line change
Expand Up @@ -363,11 +363,13 @@ int Dtls13ProcessBufferedMessages(WOLFSSL* ssl)
if (!msg->ready)
break;

#ifndef WOLFSSL_DISABLE_EARLY_SANITY_CHECKS
ret = MsgCheckEncryption(ssl, msg->type, msg->encrypted);
if (ret != 0) {
SendAlert(ssl, alert_fatal, unexpected_message);
break;
}
#endif

/* We may have DTLS <=1.2 msgs stored from before we knew which version
* we were going to use. Interpret correctly. */
Expand Down
14 changes: 13 additions & 1 deletion src/internal.c
Original file line number Diff line number Diff line change
Expand Up @@ -10718,6 +10718,8 @@ int CheckAvailableSize(WOLFSSL *ssl, int size)
return 0;
}

#ifndef WOLFSSL_DISABLE_EARLY_SANITY_CHECKS

int MsgCheckEncryption(WOLFSSL* ssl, byte type, byte encrypted)
{
#ifdef WOLFSSL_QUIC
Expand Down Expand Up @@ -10952,6 +10954,8 @@ static int MsgCheckBoundary(const WOLFSSL* ssl, byte type,
return 0;
}

#endif /* WOLFSSL_DISABLE_EARLY_SANITY_CHECKS */

/**
* This check is performed as soon as the handshake message type becomes known.
* These checks can not be delayed and need to be performed when the msg is
Expand All @@ -10967,8 +10971,9 @@ static int MsgCheckBoundary(const WOLFSSL* ssl, byte type,
*/
int EarlySanityCheckMsgReceived(WOLFSSL* ssl, byte type, word32 msgSz)
{
byte version_negotiated = 0;
int ret = 0;
#ifndef WOLFSSL_DISABLE_EARLY_SANITY_CHECKS
byte version_negotiated = 0;

WOLFSSL_ENTER("EarlySanityCheckMsgReceived");

Expand All @@ -10995,6 +11000,11 @@ int EarlySanityCheckMsgReceived(WOLFSSL* ssl, byte type, word32 msgSz)
SendAlert(ssl, alert_fatal, unexpected_message);

WOLFSSL_LEAVE("EarlySanityCheckMsgReceived", ret);
#else
(void)ssl;
(void)type;
(void)msgSz;
#endif

return ret;
}
Expand Down Expand Up @@ -17568,11 +17578,13 @@ int DtlsMsgDrain(WOLFSSL* ssl)
item->ready && ret == 0) {
word32 idx = 0;

#ifndef WOLFSSL_DISABLE_EARLY_SANITY_CHECKS
ret = MsgCheckEncryption(ssl, item->type, item->encrypted);
if (ret != 0) {
SendAlert(ssl, alert_fatal, unexpected_message);
break;
}
#endif

#ifdef WOLFSSL_NO_TLS12
ret = DoTls13HandShakeMsgType(ssl, item->fullMsg, &idx, item->type,
Expand Down
4 changes: 4 additions & 0 deletions tests/api.c
Original file line number Diff line number Diff line change
Expand Up @@ -67471,7 +67471,11 @@ static int test_TLSX_CA_NAMES_bad_extension(void)
}

ExpectIntEQ(wolfSSL_connect(ssl_c), -1);
#ifndef WOLFSSL_DISABLE_EARLY_SANITY_CHECKS
ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), OUT_OF_ORDER_E);
#else
ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), BUFFER_ERROR);
#endif

wolfSSL_free(ssl_c);
ssl_c = NULL;
Expand Down

0 comments on commit 493bb17

Please sign in to comment.