I\'m trying to write a dll which will eventually connect to a virtual token. I tried to make an exportable C_getfunctionlist function which will contain pointer adressess to fun
If you want to use a pkcs#11 implementation's functions in your code you have to load the dll which implements the standard and then use functions provided by the dll. Here comes the code I use on Linux system. I hope it helps.
static char const * PKCS11_SO_NAME = "/usr/lib/pkcs11/PKCS11_API.so";
static void * pkcs11_so;
//list of all pkcs#11 functions
static CK_FUNCTION_LIST_PTR pkcs11;
CK_RV load_pkcs11() {
CK_RV rv = CKR_OK;
CK_RV (*C_GetFunctionList) (CK_FUNCTION_LIST_PTR_PTR) = 0;
pkcs11_so = dlopen(PKCS11_SO_NAME, RTLD_NOW);
if (!pkcs11_so) {
fprintf(stderr, "Error loading pkcs#11 so: %s\n", dlerror());
return CKR_GENERAL_ERROR;
}
rv = load_symbol((void **)&C_GetFunctionList, "C_GetFunctionList");
if (CKR_OK != rv) {
return rv;
}
rv = C_GetFunctionList(&pkcs11);
if (CKR_OK != rv) {
fprintf(stderr, "C_GetFunctionList call failed: 0x%.8lX", rv);
return rv;
}
return CKR_OK;
}