Add detection of oversized encrypted data and plaintext

This commit is contained in:
Sean Parkinson 2019-06-28 11:46:52 +10:00
parent f51a8fffde
commit 5f9a851adb
3 changed files with 40 additions and 2 deletions

View File

@ -538,7 +538,7 @@ fi
if test "$ENABLED_OPENSSLEXTRA" = "yes" && test "x$ENABLED_OPENSSLCOEXIST" = "xno"
then
AM_CFLAGS="-DOPENSSL_EXTRA -DWOLFSSL_ALWAYS_VERIFY_CB $AM_CFLAGS"
AM_CFLAGS="-DWOLFSSL_VERIFY_CB_ALL_CERTS $AM_CFLAGS"
AM_CFLAGS="-DWOLFSSL_VERIFY_CB_ALL_CERTS -DWOLFSSL_EXTRA_ALERTS $AM_CFLAGS"
fi
if test "$ENABLED_OPENSSLEXTRA" = "yes" && test "$ENABLED_SMALL" = "yes"

View File

@ -13163,6 +13163,30 @@ int ProcessReply(WOLFSSL* ssl)
#endif
}
if (IsEncryptionOn(ssl, 0)) {
int tooLong = 0;
#ifdef WOLFSSL_TLS13
if (IsAtLeastTLSv1_3(ssl->version)) {
tooLong = ssl->curSize > MAX_TLS13_ENC_SZ;
tooLong |= ssl->curSize - ssl->specs.aead_mac_size >
MAX_TLS13_PLAIN_SZ;
}
#endif
#ifdef WOLFSSL_EXTRA_ALERTS
if (!IsAtLeastTLSv1_3(ssl->version))
tooLong = ssl->curSize > MAX_TLS_CIPHER_SZ;
#endif
if (tooLong) {
WOLFSSL_MSG("Encrypted data too long");
#if defined(WOLFSSL_TLS13) || defined(WOLFSSL_EXTRA_ALERTS)
SendAlert(ssl, alert_fatal, record_overflow);
#endif
return BUFFER_ERROR;
}
}
ssl->keys.padSz = 0;
ssl->options.processReply = decryptMessage;
startIdx = ssl->buffers.inputBuffer.idx; /* in case > 1 msg per */
FALL_THROUGH;
@ -13343,6 +13367,15 @@ int ProcessReply(WOLFSSL* ssl)
/* the record layer is here */
case runProcessingOneMessage:
if (ssl->buffers.inputBuffer.length - ssl->keys.padSz -
ssl->buffers.inputBuffer.idx > MAX_PLAINTEXT_SZ) {
WOLFSSL_MSG("Plaintext too long");
#if defined(WOLFSSL_TLS13) || defined(WOLFSSL_EXTRA_ALERTS)
SendAlert(ssl, alert_fatal, record_overflow);
#endif
return BUFFER_ERROR;
}
#ifdef WOLFSSL_DTLS
if (IsDtlsNotSctpMode(ssl)) {
DtlsUpdateWindow(ssl);

View File

@ -1173,7 +1173,6 @@ enum Misc {
HELLO_EXT_EXTMS = 0x0017, /* ID for the extended master secret ext */
SECRET_LEN = WOLFSSL_MAX_MASTER_KEY_LENGTH,
/* pre RSA and all master */
#if defined(WOLFSSL_TLS13)
MAX_PSK_ID_LEN = 256, /* max psk identity/hint supported */
#else
@ -1196,6 +1195,12 @@ enum Misc {
SIZEOF_SENDER = 4, /* clnt or srvr */
FINISHED_SZ = 36, /* WC_MD5_DIGEST_SIZE + WC_SHA_DIGEST_SIZE */
MAX_RECORD_SIZE = 16384, /* 2^14, max size by standard */
MAX_PLAINTEXT_SZ = (1 << 14), /* Max plaintext sz */
MAX_TLS_CIPHER_SZ = (1 << 14) + 2048, /* Max TLS encrypted data sz */
#ifdef WOLFSSL_TLS13
MAX_TLS13_PLAIN_SZ = (1 << 14) + 1, /* Max unencrypted data sz */
MAX_TLS13_ENC_SZ = (1 << 14) + 256, /* Max encrypted data sz */
#endif
MAX_MSG_EXTRA = 38 + WC_MAX_DIGEST_SIZE,
/* max added to msg, mac + pad from */
/* RECORD_HEADER_SZ + BLOCK_SZ (pad) + Max