Skip to content

Commit c99f52c

Browse files
MarkAtwoodejohnstown
authored andcommitted
fix: raise wolfSSH RSA user-authentication key minimum
Raise a cryptographic minimum to current guidance. It rejects peers below the new floor by design. - Reject RSA user-authentication keys smaller than 2048 bits with WS_CERT_KEY_SIZE_E, per NIST SP 800-131A. The floor is configurable via a new WOLFSSH_RSA_MIN_KEY_BITS define (default 2048). Issue: F-6517
1 parent 722678d commit c99f52c

2 files changed

Lines changed: 34 additions & 5 deletions

File tree

‎src/internal.c‎

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8458,6 +8458,28 @@ static int DoUserAuthRequestPassword(WOLFSSH* ssh, WS_UserAuthData* authData,
84588458
}
84598459

84608460
#ifndef WOLFSSH_NO_RSA
8461+
/* Utility for the RSA user auth paths. */
8462+
/* returns WS_SUCCESS when the key clears WOLFSSH_RSA_MIN_KEY_BITS. */
8463+
static int CheckRsaKeyBits(RsaKey* key)
8464+
{
8465+
int ret = WS_SUCCESS;
8466+
int keyBits;
8467+
8468+
/* The encrypt size rounds up to a byte; offload builds leave n empty. */
8469+
keyBits = mp_count_bits(&key->n);
8470+
if (keyBits == 0) {
8471+
keyBits = wc_RsaEncryptSize(key) * 8;
8472+
}
8473+
8474+
if (keyBits < WOLFSSH_RSA_MIN_KEY_BITS) {
8475+
WLOG(WS_LOG_DEBUG, "RSA auth key too small (%d bits)", keyBits);
8476+
ret = WS_CERT_KEY_SIZE_E;
8477+
}
8478+
8479+
return ret;
8480+
}
8481+
8482+
84618483
/* Utility for DoUserAuthRequestPublicKey() */
84628484
/* returns negative for error, positive is size of digest. */
84638485
static int DoUserAuthRequestRsa(WOLFSSH* ssh, WS_UserAuthData_PublicKey* pk,
@@ -8546,6 +8568,10 @@ static int DoUserAuthRequestRsa(WOLFSSH* ssh, WS_UserAuthData_PublicKey* pk,
85468568
}
85478569
}
85488570

8571+
if (ret == WS_SUCCESS) {
8572+
ret = CheckRsaKeyBits(key);
8573+
}
8574+
85498575
if (ret == WS_SUCCESS) {
85508576
i = 0;
85518577
/* Check that the signature's pubkey type matches the expected one. */
@@ -8705,11 +8731,7 @@ static int DoUserAuthRequestRsaCert(WOLFSSH* ssh, WS_UserAuthData_PublicKey* pk,
87058731
}
87068732

87078733
if (ret == WS_SUCCESS) {
8708-
int keySz = wc_RsaEncryptSize(key) * 8;
8709-
if (keySz < 2048) {
8710-
WLOG(WS_LOG_DEBUG, "Key size too small (%d)", keySz);
8711-
ret = WS_CERT_KEY_SIZE_E;
8712-
}
8734+
ret = CheckRsaKeyBits(key);
87138735
}
87148736

87158737
if (ret == WS_SUCCESS) {

‎wolfssh/internal.h‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,13 @@ enum NameIdType {
566566
#ifndef WOLFSSH_DEFAULT_GEXDH_MIN
567567
#define WOLFSSH_DEFAULT_GEXDH_MIN 2048
568568
#endif
569+
570+
#ifndef WOLFSSH_RSA_MIN_KEY_BITS
571+
/* Minimum accepted RSA public-key size (bits) for user authentication.
572+
* Per NIST SP 800-131A; override at build time if a smaller key must be
573+
* accepted. */
574+
#define WOLFSSH_RSA_MIN_KEY_BITS 2048
575+
#endif
569576
#ifndef WOLFSSH_DEFAULT_GEXDH_PREFERRED
570577
#define WOLFSSH_DEFAULT_GEXDH_PREFERRED 3072
571578
#endif

0 commit comments

Comments
 (0)