@@ -7581,6 +7581,7 @@ static CK_RV test_hmac_sha512_fail(void* args)
75817581static CK_RV test_x509 (void * args )
75827582{
75837583 CK_RV ret = CKR_OK ;
7584+ int sessFlags = CKF_SERIAL_SESSION | CKF_RW_SESSION ;
75847585 CK_SESSION_HANDLE session = * (CK_SESSION_HANDLE * )args ;
75857586 CK_CERTIFICATE_TYPE certType = CKC_X_509 ;
75867587 CK_UTF8CHAR label [] = "A certificate object" ;
@@ -7733,6 +7734,11 @@ static CK_RV test_x509(void* args)
77337734 { CKA_VALUE , NULL , 0 }
77347735 };
77357736 CK_ULONG getTmplCnt = sizeof (getTmpl ) / sizeof (* getTmpl );
7737+ CK_ATTRIBUTE findTmpl [] = {
7738+ { CKA_ID , id , sizeof (id )}
7739+ };
7740+ CK_ULONG findTmplCnt = sizeof (findTmpl ) / sizeof (* findTmpl );
7741+ CK_ULONG count = 1 ;
77367742
77377743 ret = funcList -> C_CreateObject (session , tmpl , tmplCnt , & obj );
77387744 CHECK_CKR (ret , "Create certificate object" );
@@ -7762,8 +7768,61 @@ static CK_RV test_x509(void* args)
77627768 XFREE (getTmpl [0 ].pValue , NULL , DYNAMIC_TYPE_TMP_BUFFER );
77637769 }
77647770 }
7771+ }
7772+
7773+ /* Do a login/logout cycle and check that the value still matches */
7774+ if (userPinLen != 0 )
7775+ funcList -> C_Logout (session );
7776+ funcList -> C_CloseSession (session );
7777+
7778+ ret = funcList -> C_OpenSession (slot , sessFlags , NULL , NULL , & session );
7779+ CHECK_CKR (ret , "Open Session" );
7780+ if (ret == CKR_OK && userPinLen != 0 ) {
7781+ ret = funcList -> C_Login (session , CKU_USER , userPin , userPinLen );
7782+ CHECK_CKR (ret , "Login" );
7783+ }
7784+
7785+ ret = funcList -> C_FindObjectsInit (session , findTmpl , findTmplCnt );
7786+ CHECK_CKR (ret , "C_FindObjectsInit" );
7787+ if (ret == CKR_OK ) {
7788+ ret = funcList -> C_FindObjects (session , & obj , 1 , & count );
7789+ CHECK_CKR (ret , "C_FindObjects" );
7790+ if (ret == CKR_OK ) {
7791+ ret = funcList -> C_FindObjectsFinal (session );
7792+ CHECK_CKR (ret , "C_FindObjectsFinal" );
7793+ }
7794+ }
7795+
7796+ if (ret == CKR_OK ) {
7797+ getTmpl [0 ].pValue = NULL ;
7798+ getTmpl [0 ].ulValueLen = 0 ;
7799+ ret = funcList -> C_GetAttributeValue (session , obj , getTmpl , getTmplCnt );
7800+ CHECK_CKR (ret , "C_GetAttributeValue" );
7801+ if (ret == CKR_OK ) {
7802+ getTmpl [0 ].pValue = XMALLOC (getTmpl [0 ].ulValueLen * sizeof (byte ),
7803+ NULL , DYNAMIC_TYPE_TMP_BUFFER );
7804+ if (getTmpl [0 ].pValue == NULL )
7805+ ret = CKR_DEVICE_MEMORY ;
7806+ CHECK_CKR (ret , "Allocate get attribute memory" );
7807+
7808+ if (ret == CKR_OK ) {
7809+ ret = funcList -> C_GetAttributeValue (session , obj , getTmpl , getTmplCnt );
7810+ CHECK_CKR (ret , "C_GetAttributeValue" );
7811+
7812+ if (sizeof (certificate ) != getTmpl [0 ].ulValueLen ) {
7813+ ret = CKR_GENERAL_ERROR ;
7814+ }
7815+ if (XMEMCMP (certificate , getTmpl [0 ].pValue , sizeof (certificate )) != 0 ) {
7816+ ret = CKR_GENERAL_ERROR ;
7817+ }
7818+ CHECK_CKR (ret , "Verify that stored cert matches original" );
7819+
7820+ XFREE (getTmpl [0 ].pValue , NULL , DYNAMIC_TYPE_TMP_BUFFER );
7821+ }
7822+ }
77657823 ret = funcList -> C_DestroyObject (session , obj );
77667824 }
7825+
77677826 return ret ;
77687827}
77697828
0 commit comments