Skip to content

Commit be7c9a4

Browse files
committed
F-2386 - https://fenrir.wolfssl.com/finding/2386 - Add test for CKA_VERIFY attribute enforcement in C_VerifyRecoverInit
1 parent 6dfe00d commit be7c9a4

1 file changed

Lines changed: 36 additions & 0 deletions

File tree

tests/pkcs11test.c

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5722,6 +5722,39 @@ static CK_RV test_verify_recover_x509(void* args)
57225722
}
57235723
#endif
57245724

5725+
#ifndef NO_RSA
5726+
static CK_RV test_verify_recover_op_not_supported(void* args)
5727+
{
5728+
CK_SESSION_HANDLE session = *(CK_SESSION_HANDLE*)args;
5729+
CK_RV ret;
5730+
CK_OBJECT_HANDLE pubKey;
5731+
CK_BBOOL falseVal = CK_FALSE;
5732+
CK_BBOOL trueVal = CK_TRUE;
5733+
CK_MECHANISM mech = { CKM_RSA_PKCS, NULL_PTR, 0 };
5734+
5735+
CK_ATTRIBUTE rsaPubNoVerify[] = {
5736+
{ CKA_CLASS, &pubKeyClass, sizeof(pubKeyClass) },
5737+
{ CKA_KEY_TYPE, &rsaKeyType, sizeof(rsaKeyType) },
5738+
{ CKA_ENCRYPT, &trueVal, sizeof(trueVal) },
5739+
{ CKA_VERIFY, &falseVal, sizeof(falseVal) },
5740+
{ CKA_MODULUS, rsa_2048_modulus, sizeof(rsa_2048_modulus) },
5741+
{ CKA_PUBLIC_EXPONENT, rsa_2048_pub_exp, sizeof(rsa_2048_pub_exp) },
5742+
};
5743+
5744+
ret = funcList->C_CreateObject(session, rsaPubNoVerify,
5745+
sizeof(rsaPubNoVerify)/sizeof(*rsaPubNoVerify),
5746+
&pubKey);
5747+
CHECK_CKR(ret, "Create RSA pub key with CKA_VERIFY=FALSE");
5748+
if (ret == CKR_OK) {
5749+
ret = funcList->C_VerifyRecoverInit(session, &mech, pubKey);
5750+
CHECK_CKR_FAIL(ret, CKR_KEY_TYPE_INCONSISTENT,
5751+
"VerifyRecoverInit should fail with CKA_VERIFY=FALSE");
5752+
}
5753+
5754+
return ret;
5755+
}
5756+
#endif
5757+
57255758
static CK_RV test_encdec_digest(void* args)
57265759
{
57275760
CK_SESSION_HANDLE session = *(CK_SESSION_HANDLE*)args;
@@ -16836,6 +16869,9 @@ static TEST_FUNC testFunc[] = {
1683616869
PKCS11TEST_FUNC_SESS_DECL(test_verify_recover_pkcs),
1683716870
PKCS11TEST_FUNC_SESS_DECL(test_verify_recover_x509),
1683816871
PKCS11TEST_FUNC_SESS_DECL(test_verify_recover_init_double),
16872+
#endif
16873+
#ifndef NO_RSA
16874+
PKCS11TEST_FUNC_SESS_DECL(test_verify_recover_op_not_supported),
1683916875
#endif
1684016876
PKCS11TEST_FUNC_SESS_DECL(test_encdec_digest),
1684116877
PKCS11TEST_FUNC_SESS_DECL(test_encdec_signverify),

0 commit comments

Comments
 (0)