Skip to content

Commit 7a2ab9a

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 a181dae commit 7a2ab9a

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
@@ -2433,6 +2433,10 @@ CK_RV SoftHSM::AsymEncryptInit(CK_SESSION_HANDLE hSession, CK_MECHANISM_PTR pMec
24332433
if (!key->getBooleanValue(CKA_ENCRYPT, false))
24342434
return CKR_KEY_FUNCTION_NOT_PERMITTED;
24352435

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

@@ -3189,22 +3193,9 @@ CK_RV SoftHSM::AsymDecryptInit(CK_SESSION_HANDLE hSession, CK_MECHANISM_PTR pMec
31893193
case CKM_RSA_PKCS_OAEP:
31903194
if (keyType != CKK_RSA)
31913195
return CKR_KEY_TYPE_INCONSISTENT;
3192-
if (pMechanism->pParameter == NULL_PTR ||
3193-
pMechanism->ulParameterLen != sizeof(CK_RSA_PKCS_OAEP_PARAMS))
3194-
{
3195-
DEBUG_MSG("pParameter must be of type CK_RSA_PKCS_OAEP_PARAMS");
3196-
return CKR_ARGUMENTS_BAD;
3197-
}
3198-
if (CK_RSA_PKCS_OAEP_PARAMS_PTR(pMechanism->pParameter)->hashAlg != CKM_SHA_1)
3199-
{
3200-
DEBUG_MSG("hashAlg must be CKM_SHA_1");
3201-
return CKR_ARGUMENTS_BAD;
3202-
}
3203-
if (CK_RSA_PKCS_OAEP_PARAMS_PTR(pMechanism->pParameter)->mgf != CKG_MGF1_SHA1)
3204-
{
3205-
DEBUG_MSG("mgf must be CKG_MGF1_SHA1");
3206-
return CKR_ARGUMENTS_BAD;
3207-
}
3196+
rv = MechParamCheckRSAPKCSOAEP(pMechanism);
3197+
if (rv != CKR_OK)
3198+
return rv;
32083199

32093200
mechanism = AsymMech::RSA_PKCS_OAEP;
32103201
isRSA = true;

0 commit comments

Comments
 (0)