0 Replies Latest reply: Mar 4, 2011 4:11 AM by user4928701 RSS

    PKCS11 Api C_GetAttributeValue returns CKR_TEMPLATE_INCONSISTENT

    user4928701
      Hi experts
      I'm using the below code to determine if the token inserted is an EToken
      #define ETCKH_TOKEN_OBJECT 0x80005002
      #define ETCKA_CLIENTLESS_VERSION 0x80001137

      bool CCardDialog::isEToken()
      {
           CK_OBJECT_HANDLE hObject = NULL;
      CK_ULONG ulObjectCount = 0;
      const unsigned long dataClass = CKO_HW_FEATURE;
      const unsigned long fType = ETCKH_TOKEN_OBJECT;

      CK_ATTRIBUTE tokenAttr[] =
      {
      { CKA_CLASS,(void*)&dataClass, sizeof(dataClass) },
      { CKA_HW_FEATURE_TYPE,(void*)&fType, sizeof(fType) }
      };
           CK_SESSION_HANDLE SessionHandle = selectedSlot_->getSession(false);
           //Look for ETCKH_TOKEN_OBJECT via PKCS#11 Find operations
      CK_RV RV = (selectedSlot_->fns)->C_FindObjectsInit(SessionHandle, tokenAttr, sizeof(tokenAttr)/sizeof(CK_ATTRIBUTE));

           if(RV != CKR_OK)
           {
                GLM::logv(LT_STATUS, LS_INFO, 0, "isEToken: Returning false because C_FindObjectsInit returned %d", RV);
                return false;
           }
      RV = (selectedSlot_->fns)->C_FindObjects(SessionHandle, &hObject, 1, &ulObjectCount);
           (selectedSlot_->fns)->C_FindObjectsFinal(SessionHandle);
           if(RV != CKR_OK)
           {
                GLM::logv(LT_STATUS, LS_INFO, 0, "isEToken: Returning false because C_FindObjects returned %d", RV);
                return false;
           }
           GLM::logv(LT_STATUS, LS_INFO, 0, "objectscount=%d",ulObjectCount);
           if(ulObjectCount == 0)
           {
                GLM::logv(LT_STATUS, LS_INFO, 0, "Returning false as the object count is zero.");
           }     
           //clientless/anywhere version
      CK_VERSION clientlessVer = {0,0};
           
           CK_ATTRIBUTE clientlessVerAttr = { ETCKA_CLIENTLESS_VERSION, &clientlessVer, sizeof(clientlessVer) };     
           RV = (selectedSlot_->fns)->C_GetAttributeValue(SessionHandle, hObject, &clientlessVerAttr, sizeof(clientlessVerAttr));     
           if(RV != CKR_OK)
           {
                GLM::logv(LT_STATUS, LS_INFO, 0, "isEToken: Returning false because C_GetAttributeValue returned %d", RV);
                return false;
           }
           GLM::logv(LT_STATUS, LS_INFO, 0, "major=%d minor=%d",clientlessVer.major,clientlessVer.minor);
           if((clientlessVer.major==1 || clientlessVer.major==0) && clientlessVer.minor==0)
                return true;
           return false;
      }

      But the C_GetAttributeValue returns CKR_TEMPLATE_INCONSISTENT. Why does this happen?