Skip to content

Commit

Permalink
tests: Verify the C_GetMechanismInfo does fails for not allowed mecha…
Browse files Browse the repository at this point in the history
…nisms
  • Loading branch information
Jakuje committed Sep 6, 2021
1 parent 49786f9 commit f1581cf
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/lib/test/InfoTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,7 @@ void InfoTests::testGetMechanismListConfig()
CK_RV rv;
CK_ULONG ulMechCount = 0;
CK_MECHANISM_TYPE_PTR pMechanismList;
CK_MECHANISM_INFO info;

#ifndef _WIN32
setenv("SOFTHSM2_CONF", "./softhsm2-mech.conf", 1);
Expand Down Expand Up @@ -358,6 +359,20 @@ void InfoTests::testGetMechanismListConfig()
CPPUNIT_ASSERT(pMechanismList[1] == CKM_RSA_PKCS);
free(pMechanismList);

/* Get good mechanism info */
rv = CRYPTOKI_F_PTR( C_GetMechanismInfo(m_initializedTokenSlotID, CKM_RSA_X_509, &info) );
CPPUNIT_ASSERT(rv == CKR_OK);
CPPUNIT_ASSERT(info.flags & CKF_SIGN);
rv = CRYPTOKI_F_PTR( C_GetMechanismInfo(m_initializedTokenSlotID, CKM_RSA_PKCS, &info) );
CPPUNIT_ASSERT(rv == CKR_OK);
CPPUNIT_ASSERT(info.flags & CKF_SIGN);

/* Get bad mechanism info */
rv = CRYPTOKI_F_PTR( C_GetMechanismInfo(m_initializedTokenSlotID, CKM_ECDSA, &info) );
CPPUNIT_ASSERT(rv == CKR_MECHANISM_INVALID);
rv = CRYPTOKI_F_PTR( C_GetMechanismInfo(m_initializedTokenSlotID, CKM_DSA, &info) );
CPPUNIT_ASSERT(rv == CKR_MECHANISM_INVALID);

CRYPTOKI_F_PTR( C_Finalize(NULL_PTR) );
#ifndef _WIN32
setenv("SOFTHSM2_CONF", "./softhsm2.conf", 1);
Expand Down

0 comments on commit f1581cf

Please sign in to comment.