Hello, I tried a simple program that according to PKCS#11v2.20 should work:
And I found the he PKCS#11 provider does not refresh slot list with C_GetSlotList is called with NULL_PTR. This is extremely important for tokens, as the reader hardware is removed and inserted when card is removed and inserted. Lacking Plug&Play support will not enable people to use CCID enabled tokens to use running applications, as most applications calls C_Initialize once. A found the root cause i the libopensc context management. It looks like the libopensc itself does not support Plug&Play, and use fixed reader list at context initialization. I guess there are people that familiar with the code and can propose some design for implementing Plug&Play into libopensc, and then we think of how to propagate this into PKCS#11. Thanks! Alon. --- >From spec: If an application calls C_GetSlotList with a non-NULL pSlotList, and then the user adds or removes a hardware device, the changed slot list will only be visible and effective if C_GetSlotList is called again with NULL. Even if C_ GetSlotList is successfully called this way, it may or may not be the case that the changed slot list will be successfully recognized depending on the library implementation. On some platforms, or earlier PKCS11 compliant libraries, it may be necessary to successfully call C_Initialize or to restart the entire system. --- #include <stdio.h> #include <stdlib.h> #include <string.h> #include <dlfcn.h> #include <unistd.h> #include "pkcs11.h" void p11error (CK_RV rv, char *m) { printf ("fatal %08x-%s\n", rv, m); exit (1); } int main () { CK_FUNCTION_LIST_PTR f; CK_SESSION_HANDLE session; CK_C_GetFunctionList gfl = NULL; CK_RV rv; void *dl; dl = dlopen ("/usr/lib/pkcs11/opensc-pkcs11.so", RTLD_NOW); if (dl == NULL) { perror ("dlopen"); } void *p = dlsym (dl, "C_GetFunctionList"); memmove (&gfl, &p, sizeof (void *)); if (gfl == NULL) { perror ("dlsym"); } rv = gfl (&f); if (rv != CKR_OK) { p11error (rv, "gfl"); } rv = f->C_Initialize (NULL); if (rv != CKR_OK) { p11error (rv, "C_Initialize"); } while (1) { CK_SLOT_ID slots[10]; CK_ULONG slotnum = sizeof (slots) / sizeof (CK_SLOT_ID); rv = f->C_GetSlotList (TRUE, slots, &slotnum); if (rv != CKR_OK) { p11error (rv, "C_GetSlotList"); } printf ("Slots with token: %ld\n", slotnum); sleep (2); } return 0; } _______________________________________________ opensc-devel mailing list opensc-devel@lists.opensc-project.org http://www.opensc-project.org/mailman/listinfo/opensc-devel