How to Initialize a token using C_InitToken() from PKCS#11 interface?

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

How to Initialize a token using C_InitToken() from PKCS#11 interface?

Felipe Blauth
Hello, I was in doubt if this is a question for opensc-user or opensc-devel but, since I'm just a user of the tools and libraries offered, i think it suits better here.

About my question, I have a card in which I've created a pkcs#15 structure by running, in terminal, pkcs15-init --create-pkcs15.

After that, I've tryed to use this card coding against PKCS#11 interface, with opensc-pkcs11.so module.

I was able to list slots and I tryed to initialize a token in the first slot, but without sucess. I've initialized the SO pin with 000000, then I wrote:

    CK_RV rv;
  
   CK_UTF8CHAR SOPin[6] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
   CK_UTF8CHAR tokenLabel[32];

   memset(tokenLabel,' ',sizeof(tokenLabel));
   memcpy(tokenLabel, "My Token", strlen("My Token"));

   CK_ULONG PinLen = (CK_ULONG) sizeof(SOPin); 

    rv = C_InitToken(slotList[0], SOPin ,PinLen, tokenLabel);
    if (rv != CKR_OK)
    {
        printf("Error number: %x\n", rv);
    }
   
The slotList is set by calling C_GetSlotList.

And rv returns 0xe0, which is, acording to PKCS#11 specification, CKR_TOKEN_NOT_PRESENT. I don't understand this because I know there's no token in that slot yet, i want to create it :-p

Is there any other command I need to run before using PKCS#11 interface? As far as I know all I need is to create the pkcs#15 structure..

Thank you.

_______________________________________________
opensc-user mailing list
[hidden email]
http://www.opensc-project.org/mailman/listinfo/opensc-user
Reply | Threaded
Open this post in threaded view
|

Re: How to Initialize a token using C_InitToken() from PKCS#11 interface?

Ludovic Rousseau
2010/8/23 Felipe Blauth <[hidden email]>:
> Hello, I was in doubt if this is a question for opensc-user or opensc-devel
> but, since I'm just a user of the tools and libraries offered, i think it
> suits better here.

Since you are doing developement the -devel list should be better.

> About my question, I have a card in which I've created a pkcs#15 structure
> by running, in terminal, pkcs15-init --create-pkcs15.
>
> After that, I've tryed to use this card coding against PKCS#11 interface,
> with opensc-pkcs11.so module.
>
> I was able to list slots and I tryed to initialize a token in the first
> slot, but without sucess. I've initialized the SO pin with 000000, then I
> wrote:
>
>     CK_RV rv;
>
>    CK_UTF8CHAR SOPin[6] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
>    CK_UTF8CHAR tokenLabel[32];
>
>    memset(tokenLabel,' ',sizeof(tokenLabel));
>    memcpy(tokenLabel, "My Token", strlen("My Token"));
>
>    CK_ULONG PinLen = (CK_ULONG) sizeof(SOPin);
>
>     rv = C_InitToken(slotList[0], SOPin ,PinLen, tokenLabel);
>     if (rv != CKR_OK)
>     {
>         printf("Error number: %x\n", rv);
>     }
>
> The slotList is set by calling C_GetSlotList.
>
> And rv returns 0xe0, which is, acording to PKCS#11 specification,
> CKR_TOKEN_NOT_PRESENT. I don't understand this because I know there's no
> token in that slot yet, i want to create it :-p
>
> Is there any other command I need to run before using PKCS#11 interface? As
> far as I know all I need is to create the pkcs#15 structure..

Provide the complete source code so we can help you.

Bye

--
 Dr. Ludovic Rousseau
_______________________________________________
opensc-user mailing list
[hidden email]
http://www.opensc-project.org/mailman/listinfo/opensc-user