@@ -7043,11 +7043,33 @@ static int DoUserAuthRequestRsa(WOLFSSH* ssh, WS_UserAuthData_PublicKey* pk,
70437043 }
70447044
70457045 if (ret == WS_SUCCESS) {
7046- if (publicKeyTypeSz != pk->publicKeyTypeSz
7047- || publicKeyType == NULL
7048- || WMEMCMP(publicKeyType, pk->publicKeyType,
7049- publicKeyTypeSz) != 0) {
7050-
7046+ int sigTypeOk = 0;
7047+ if (publicKeyType != NULL) {
7048+ if (publicKeyTypeSz == pk->publicKeyTypeSz
7049+ && WMEMCMP(publicKeyType, pk->publicKeyType,
7050+ publicKeyTypeSz) == 0) {
7051+ sigTypeOk = 1;
7052+ }
7053+ #ifdef WOLFSSH_CERTS
7054+ else if (pk->publicKeyTypeSz == 14
7055+ && WMEMCMP(pk->publicKeyType,
7056+ "x509v3-ssh-rsa", 14) == 0) {
7057+ /* RFC 6187 Section 5: the signature uses the underlying
7058+ * RSA algorithm, not the X.509 key type name. */
7059+ if ((publicKeyTypeSz == 7
7060+ && WMEMCMP(publicKeyType, "ssh-rsa", 7) == 0)
7061+ || (publicKeyTypeSz == 12
7062+ && WMEMCMP(publicKeyType,
7063+ "rsa-sha2-256", 12) == 0)
7064+ || (publicKeyTypeSz == 12
7065+ && WMEMCMP(publicKeyType,
7066+ "rsa-sha2-512", 12) == 0)) {
7067+ sigTypeOk = 1;
7068+ }
7069+ }
7070+ #endif
7071+ }
7072+ if (!sigTypeOk) {
70517073 WLOG(WS_LOG_DEBUG,
70527074 "Signature's type does not match public key type");
70537075 ret = WS_INVALID_ALGO_ID;
@@ -7182,10 +7204,29 @@ static int DoUserAuthRequestRsaCert(WOLFSSH* ssh, WS_UserAuthData_PublicKey* pk,
71827204 }
71837205
71847206 if (ret == WS_SUCCESS) {
7185- if (publicKeyTypeSz != pk->publicKeyTypeSz
7186- || WMEMCMP(publicKeyType, pk->publicKeyType,
7187- publicKeyTypeSz) != 0) {
7188-
7207+ int sigTypeOk = 0;
7208+ if (publicKeyTypeSz == pk->publicKeyTypeSz
7209+ && WMEMCMP(publicKeyType, pk->publicKeyType,
7210+ publicKeyTypeSz) == 0) {
7211+ sigTypeOk = 1;
7212+ }
7213+ #ifdef WOLFSSH_CERTS
7214+ else if (pk->publicKeyFmtId == ID_X509V3_SSH_RSA) {
7215+ /* RFC 6187 Section 5: the signature uses the underlying
7216+ * RSA algorithm, not the X.509 key type name. */
7217+ if ((publicKeyTypeSz == 7
7218+ && WMEMCMP(publicKeyType, "ssh-rsa", 7) == 0)
7219+ || (publicKeyTypeSz == 12
7220+ && WMEMCMP(publicKeyType,
7221+ "rsa-sha2-256", 12) == 0)
7222+ || (publicKeyTypeSz == 12
7223+ && WMEMCMP(publicKeyType,
7224+ "rsa-sha2-512", 12) == 0)) {
7225+ sigTypeOk = 1;
7226+ }
7227+ }
7228+ #endif
7229+ if (!sigTypeOk) {
71897230 WLOG(WS_LOG_DEBUG,
71907231 "Signature's type does not match public key type");
71917232 ret = WS_INVALID_ALGO_ID;
0 commit comments