问题
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 functions suported by PCKS#11 standard but i can't figure out why i can't access those functions in the program that uses the dll. I tried to load just the C_Initializefunction.
extern "C" __declspec(dllexport)
CK_RV C_GetFunctionList(CK_FUNCTION_LIST_PTR_PTR ppFunctionList) {
CK_FUNCTION_LIST_PTR function_list;
function_list=new CK_FUNCTION_LIST;
function_list->C_Initialize=&C_Initialize;
ppFunctionList=&function_list;
return CKR_OK;
}
回答1:
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;
}
来源:https://stackoverflow.com/questions/15615001/pkcs11-c-getfunctionlist-in-a-dll