Skip to content

Commit 11bb8b3

Browse files
authored
Merge pull request #5543 from SparkiDev/rsa_max_size_fix
RSA max key size checks
2 parents daadd4a + 3bf6baf commit 11bb8b3

2 files changed

Lines changed: 8 additions & 5 deletions

File tree

src/ssl.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6812,14 +6812,16 @@ int ProcessBuffer(WOLFSSL_CTX* ctx, const unsigned char* buff,
68126812

68136813
if (ssl && !ssl->options.verifyNone) {
68146814
if (ssl->options.minRsaKeySz < 0 ||
6815-
keySz < (int)ssl->options.minRsaKeySz) {
6815+
keySz < (int)ssl->options.minRsaKeySz ||
6816+
keySz > (RSA_MAX_SIZE / 8)) {
68166817
ret = RSA_KEY_SIZE_E;
68176818
WOLFSSL_MSG("Certificate RSA key size too small");
68186819
}
68196820
}
68206821
else if (ctx && !ctx->verifyNone) {
68216822
if (ctx->minRsaKeySz < 0 ||
6822-
keySz < (int)ctx->minRsaKeySz) {
6823+
keySz < (int)ctx->minRsaKeySz ||
6824+
keySz > (RSA_MAX_SIZE / 8)) {
68236825
ret = RSA_KEY_SIZE_E;
68246826
WOLFSSL_MSG("Certificate RSA key size too small");
68256827
}

tests/api.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2402,7 +2402,7 @@ static int test_wolfSSL_CertRsaPss(void)
24022402
XFILE f;
24032403
const char* rsaPssSha256Cert = "./certs/rsapss/ca-rsapss.der";
24042404
const char* rsaPssRootSha256Cert = "./certs/rsapss/root-rsapss.pem";
2405-
#ifdef WOLFSSL_SHA384
2405+
#if defined(WOLFSSL_SHA384) && RSA_MAX_SIZE >= 3072
24062406
const char* rsaPssSha384Cert = "./certs/rsapss/ca-3072-rsapss.der";
24072407
const char* rsaPssRootSha384Cert = "./certs/rsapss/root-3072-rsapss.pem";
24082408
#endif
@@ -2417,7 +2417,7 @@ static int test_wolfSSL_CertRsaPss(void)
24172417
AssertNotNull(cm);
24182418
AssertIntEQ(WOLFSSL_SUCCESS,
24192419
wolfSSL_CertManagerLoadCA(cm, rsaPssRootSha256Cert, NULL));
2420-
#ifdef WOLFSSL_SHA384
2420+
#if defined(WOLFSSL_SHA384) && RSA_MAX_SIZE >= 3072
24212421
AssertIntEQ(WOLFSSL_SUCCESS,
24222422
wolfSSL_CertManagerLoadCA(cm, rsaPssRootSha384Cert, NULL));
24232423
#endif
@@ -2430,7 +2430,8 @@ static int test_wolfSSL_CertRsaPss(void)
24302430
AssertIntEQ(wc_ParseCert(&cert, CERT_TYPE, VERIFY, cm), 0);
24312431
wc_FreeDecodedCert(&cert);
24322432

2433-
#if defined(WOLFSSL_SHA384) && defined(WOLFSSL_PSS_LONG_SALT)
2433+
#if defined(WOLFSSL_SHA384) && defined(WOLFSSL_PSS_LONG_SALT) && \
2434+
RSA_MAX_SIZE >= 3072
24342435
f = XFOPEN(rsaPssSha384Cert, "rb");
24352436
AssertTrue((f != XBADFILE));
24362437
bytes = (int)XFREAD(buf, 1, sizeof(buf), f);

0 commit comments

Comments
 (0)