Skip to content

Commit f3c0156

Browse files
authored
Check RSA-OAEP mechanims when decrypting (#671)
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 f216135 commit f3c0156

1 file changed

Lines changed: 7 additions & 16 deletions

File tree

src/lib/SoftHSM.cpp

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

2457+
// Check if the specified mechanism is allowed for the key
2458+
if (!isMechanismPermitted(key, pMechanism))
2459+
return CKR_MECHANISM_INVALID;
2460+
24572461
// Get key info
24582462
CK_KEY_TYPE keyType = key->getUnsignedLongValue(CKA_KEY_TYPE, CKK_VENDOR_DEFINED);
24592463

@@ -3210,22 +3214,9 @@ CK_RV SoftHSM::AsymDecryptInit(CK_SESSION_HANDLE hSession, CK_MECHANISM_PTR pMec
32103214
case CKM_RSA_PKCS_OAEP:
32113215
if (keyType != CKK_RSA)
32123216
return CKR_KEY_TYPE_INCONSISTENT;
3213-
if (pMechanism->pParameter == NULL_PTR ||
3214-
pMechanism->ulParameterLen != sizeof(CK_RSA_PKCS_OAEP_PARAMS))
3215-
{
3216-
DEBUG_MSG("pParameter must be of type CK_RSA_PKCS_OAEP_PARAMS");
3217-
return CKR_ARGUMENTS_BAD;
3218-
}
3219-
if (CK_RSA_PKCS_OAEP_PARAMS_PTR(pMechanism->pParameter)->hashAlg != CKM_SHA_1)
3220-
{
3221-
DEBUG_MSG("hashAlg must be CKM_SHA_1");
3222-
return CKR_ARGUMENTS_BAD;
3223-
}
3224-
if (CK_RSA_PKCS_OAEP_PARAMS_PTR(pMechanism->pParameter)->mgf != CKG_MGF1_SHA1)
3225-
{
3226-
DEBUG_MSG("mgf must be CKG_MGF1_SHA1");
3227-
return CKR_ARGUMENTS_BAD;
3228-
}
3217+
rv = MechParamCheckRSAPKCSOAEP(pMechanism);
3218+
if (rv != CKR_OK)
3219+
return rv;
32293220

32303221
mechanism = AsymMech::RSA_PKCS_OAEP;
32313222
isRSA = true;

0 commit comments

Comments
 (0)