@@ -12918,6 +12918,99 @@ static void pkcs11_close_session(int flags, void* args)
1291812918 }
1291912919}
1292012920
12921+ /* Test for bug fix in internal.c where bitwise OR was changed to AND
12922+ * This test validates that private objects (CKA_PRIVATE = TRUE) are properly
12923+ * filtered based on login state:
12924+ * - When not logged in: private objects should NOT be found
12925+ * - When logged in: private objects should be found
12926+ */
12927+ static CK_RV test_private_object_access (void * args )
12928+ {
12929+ CK_SESSION_HANDLE session = * (CK_SESSION_HANDLE * )args ;
12930+ CK_RV ret ;
12931+ CK_OBJECT_HANDLE obj = CK_INVALID_HANDLE ;
12932+ static byte keyData [] = { 0x01 , 0x02 , 0x03 , 0x04 };
12933+ static byte id [] = { 0x10 , 0x11 , 0x12 , 0x13 };
12934+ CK_BBOOL isPrivate = CK_TRUE ;
12935+ CK_ATTRIBUTE tmpl [] = {
12936+ { CKA_CLASS , & secretKeyClass , sizeof (secretKeyClass ) },
12937+ { CKA_KEY_TYPE , & genericKeyType , sizeof (genericKeyType ) },
12938+ { CKA_VALUE , keyData , sizeof (keyData ) },
12939+ { CKA_PRIVATE , & isPrivate , sizeof (isPrivate ) },
12940+ { CKA_TOKEN , & ckTrue , sizeof (ckTrue ) },
12941+ { CKA_ID , id , sizeof (id ) },
12942+ };
12943+ CK_ULONG tmplCnt = sizeof (tmpl ) / sizeof (* tmpl );
12944+ CK_ATTRIBUTE findTmpl [] = {
12945+ { CKA_ID , id , sizeof (id ) },
12946+ };
12947+ CK_ULONG findTmplCnt = sizeof (findTmpl ) / sizeof (* findTmpl );
12948+ CK_OBJECT_HANDLE found ;
12949+ CK_ULONG count ;
12950+
12951+ /* Create a private object while logged in (test setup logs us in) */
12952+ ret = funcList -> C_CreateObject (session , tmpl , tmplCnt , & obj );
12953+ CHECK_CKR (ret , "Create Private Object" );
12954+
12955+ if (ret == CKR_OK ) {
12956+ /* Logout to test private object access control */
12957+ ret = funcList -> C_Logout (session );
12958+ CHECK_CKR (ret , "Logout for private object test" );
12959+ }
12960+
12961+ if (ret == CKR_OK ) {
12962+ /* Try to find the private object while not logged in - should NOT find it */
12963+ ret = funcList -> C_FindObjectsInit (session , findTmpl , findTmplCnt );
12964+ CHECK_CKR (ret , "Find Objects Init - not logged in" );
12965+ if (ret == CKR_OK ) {
12966+ ret = funcList -> C_FindObjects (session , & found , 1 , & count );
12967+ CHECK_CKR (ret , "Find Objects - not logged in" );
12968+ }
12969+ if (ret == CKR_OK && count != 0 ) {
12970+ ret = -1 ;
12971+ CHECK_CKR (ret , "Private object should not be found when not logged in" );
12972+ }
12973+ if (ret == CKR_OK ) {
12974+ ret = funcList -> C_FindObjectsFinal (session );
12975+ CHECK_CKR (ret , "Find Objects Final - not logged in" );
12976+ }
12977+ }
12978+
12979+ if (ret == CKR_OK ) {
12980+ /* Login as user */
12981+ ret = funcList -> C_Login (session , CKU_USER , userPin , userPinLen );
12982+ CHECK_CKR (ret , "Login for private object test" );
12983+ }
12984+
12985+ if (ret == CKR_OK ) {
12986+ /* Now try to find the private object while logged in - should find it */
12987+ ret = funcList -> C_FindObjectsInit (session , findTmpl , findTmplCnt );
12988+ CHECK_CKR (ret , "Find Objects Init - logged in" );
12989+ if (ret == CKR_OK ) {
12990+ ret = funcList -> C_FindObjects (session , & found , 1 , & count );
12991+ CHECK_CKR (ret , "Find Objects - logged in" );
12992+ }
12993+ if (ret == CKR_OK && count != 1 ) {
12994+ ret = -1 ;
12995+ CHECK_CKR (ret , "Private object should be found when logged in" );
12996+ }
12997+ if (ret == CKR_OK && found != obj ) {
12998+ ret = -1 ;
12999+ CHECK_CKR (ret , "Found object should match created object" );
13000+ }
13001+ if (ret == CKR_OK ) {
13002+ ret = funcList -> C_FindObjectsFinal (session );
13003+ CHECK_CKR (ret , "Find Objects Final - logged in" );
13004+ }
13005+ }
13006+
13007+ if (obj != CK_INVALID_HANDLE ) {
13008+ funcList -> C_DestroyObject (session , obj );
13009+ }
13010+
13011+ return ret ;
13012+ }
13013+
1292113014static TEST_FUNC testFunc [] = {
1292213015 PKCS11TEST_FUNC_NO_INIT_DECL (test_get_function_list ),
1292313016 PKCS11TEST_FUNC_NO_INIT_DECL (test_not_initialized ),
@@ -12951,6 +13044,7 @@ static TEST_FUNC testFunc[] = {
1295113044 PKCS11TEST_FUNC_SESS_DECL (test_attributes_dh ),
1295213045#endif
1295313046 PKCS11TEST_FUNC_SESS_DECL (test_find_objects ),
13047+ PKCS11TEST_FUNC_SESS_DECL (test_private_object_access ),
1295413048 PKCS11TEST_FUNC_SESS_DECL (test_encrypt_decrypt ),
1295513049 PKCS11TEST_FUNC_SESS_DECL (test_digest_fail ),
1295613050 PKCS11TEST_FUNC_SESS_DECL (test_sign_verify ),
0 commit comments