Skip to content

Commit 2a3bfeb

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 <jjelen@redhat.com>
1 parent 28c67fe commit 2a3bfeb

File tree

1 file changed

+7
-16
lines changed

1 file changed

+7
-16
lines changed

src/lib/SoftHSM.cpp

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2430,6 +2430,10 @@ CK_RV SoftHSM::AsymEncryptInit(CK_SESSION_HANDLE hSession, CK_MECHANISM_PTR pMec
24302430
if (!key->getBooleanValue(CKA_ENCRYPT, false))
24312431
return CKR_KEY_FUNCTION_NOT_PERMITTED;
24322432

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

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

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

0 commit comments

Comments
 (0)