Skip to content

Commit d79e7cc

Browse files
committed
Check RSA-OAEP mechanims when decrypting
The same check is in all the other methods handling the RSA-OAEP encryption, wrapping and unwrapping, but for some reason, it was missing in the decryption operation. Signed-off-by: Jakub Jelen <[email protected]>
1 parent ac70dc3 commit d79e7cc

File tree

1 file changed

+7
-16
lines changed

1 file changed

+7
-16
lines changed

src/lib/SoftHSM.cpp

+7-16
Original file line numberDiff line numberDiff line change
@@ -2431,6 +2431,10 @@ CK_RV SoftHSM::AsymEncryptInit(CK_SESSION_HANDLE hSession, CK_MECHANISM_PTR pMec
24312431
if (!key->getBooleanValue(CKA_ENCRYPT, false))
24322432
return CKR_KEY_FUNCTION_NOT_PERMITTED;
24332433

2434+
// Check if the specified mechanism is allowed for the key
2435+
if (!isMechanismPermitted(key, pMechanism->mechanism))
2436+
return CKR_MECHANISM_INVALID;
2437+
24342438
// Get key info
24352439
CK_KEY_TYPE keyType = key->getUnsignedLongValue(CKA_KEY_TYPE, CKK_VENDOR_DEFINED);
24362440

@@ -3178,22 +3182,9 @@ CK_RV SoftHSM::AsymDecryptInit(CK_SESSION_HANDLE hSession, CK_MECHANISM_PTR pMec
31783182
case CKM_RSA_PKCS_OAEP:
31793183
if (keyType != CKK_RSA)
31803184
return CKR_KEY_TYPE_INCONSISTENT;
3181-
if (pMechanism->pParameter == NULL_PTR ||
3182-
pMechanism->ulParameterLen != sizeof(CK_RSA_PKCS_OAEP_PARAMS))
3183-
{
3184-
DEBUG_MSG("pParameter must be of type CK_RSA_PKCS_OAEP_PARAMS");
3185-
return CKR_ARGUMENTS_BAD;
3186-
}
3187-
if (CK_RSA_PKCS_OAEP_PARAMS_PTR(pMechanism->pParameter)->hashAlg != CKM_SHA_1)
3188-
{
3189-
DEBUG_MSG("hashAlg must be CKM_SHA_1");
3190-
return CKR_ARGUMENTS_BAD;
3191-
}
3192-
if (CK_RSA_PKCS_OAEP_PARAMS_PTR(pMechanism->pParameter)->mgf != CKG_MGF1_SHA1)
3193-
{
3194-
DEBUG_MSG("mgf must be CKG_MGF1_SHA1");
3195-
return CKR_ARGUMENTS_BAD;
3196-
}
3185+
rv = MechParamCheckRSAPKCSOAEP(pMechanism);
3186+
if (rv != CKR_OK)
3187+
return rv;
31973188

31983189
mechanism = AsymMech::RSA_PKCS_OAEP;
31993190
isRSA = true;

0 commit comments

Comments
 (0)