0

Is there any way to change token label using C_SetAttributeValue? what template is being used to change token name as I tried with below function got error iaik.pkcs.pkcs11.wrapper.PKCS11Exception: CKR_TEMPLATE_INCOMPLETE

token = getToken();
CK_ATTRIBUTE[] attrs = new CK_ATTRIBUTE[2];
attrs[0] = new CK_ATTRIBUTE();
attrs[0].type = PKCS11Constants.CKA_LABEL;
attrs[0].pValue = label.toCharArray();
attrs[1] = new CK_ATTRIBUTE();
attrs[1].type = PKCS11Constants.CKA_ID;
attrs[1].pValue = label.toCharArray();
token.getSlot().getModule().getPKCS11Module().C_SetAttributeValue(
    session.getSessionHandle(), token.getSlot().getSlotID(), attrs, true);
Alexander
  • 1,232
  • 1
  • 15
  • 24
Dyla
  • 9
  • 2
  • 1
    Does this answer your question? [How to change token label without re-initializing it?](https://stackoverflow.com/questions/60556467/how-to-change-token-label-without-re-initializing-it) – always_a_rookie Mar 23 '20 at 14:18

2 Answers2

0

Hello on StackOverflow!

Have a look at C_SetAttributeValue definition:

CK_DEFINE_FUNCTION(CK_RV, C_SetAttributeValue)(
    CK_SESSION_HANDLE hSession,
    CK_OBJECT_HANDLE hObject,
    CK_ATTRIBUTE_PTR pTemplate,
    CK_ULONG ulCount
);

The second parameter is the Object ID, not the slot ID.

Please refer to your library's manufacturer documentation for extensions to PKCS#11 that allow to set token label.

Alexander
  • 1,232
  • 1
  • 15
  • 24
0

C_SetAttributeValue is categorized as an object-management function. More precisely, the cryptoki function C_SetAttributeValue is used to modify or set an attribute value of an object (not token). If you use a standard PKCS#11 library, you should use C_initToken to change or set the token label.

Please note that a company may provide some non-standard functions for its own products. Thus, it might be also a non-standard function or extension in a specific product that helps you to change the token label.

Homaei
  • 177
  • 1
  • 1
  • 10