common, pkcs11-tool: Use new PKCS #11 API with fallback to old one

This commit is contained in:
Jakub Jelen 2020-08-17 18:02:22 +02:00 committed by Frank Morgner
parent 224e265266
commit 6e25924eb0
2 changed files with 21 additions and 2 deletions

View File

@ -49,6 +49,7 @@ C_LoadModule(const char *mspec, CK_FUNCTION_LIST_PTR_PTR funcs)
{
sc_pkcs11_module_t *mod;
CK_RV rv, (*c_get_function_list)(CK_FUNCTION_LIST_PTR_PTR);
CK_RV (*c_get_interface)(CK_UTF8CHAR_PTR, CK_VERSION_PTR, CK_INTERFACE_PTR_PTR, CK_FLAGS);
mod = calloc(1, sizeof(*mod));
if (mod == NULL) {
return NULL;
@ -65,6 +66,24 @@ C_LoadModule(const char *mspec, CK_FUNCTION_LIST_PTR_PTR funcs)
goto failed;
}
c_get_interface = (CK_RV (*)(CK_UTF8CHAR_PTR, CK_VERSION_PTR, CK_INTERFACE_PTR_PTR, CK_FLAGS))
sc_dlsym(mod->handle, "C_GetInterface");
if (c_get_interface) {
CK_INTERFACE *interface = NULL;
/* Get default PKCS #11 interface */
rv = c_get_interface((CK_UTF8CHAR_PTR) "PKCS 11", NULL, &interface, 0);
if (rv == CKR_OK) {
/* this is actually 3.0 function list, but it starts
* with the same fields. Only for new functions, it
* needs to be casted to new structure */
*funcs = interface->pFunctionList;
return (void *) mod;
} else {
fprintf(stderr, "C_GetInterface failed %lx, retry 2.x way", rv);
}
}
/* Get the list of function pointers */
c_get_function_list = (CK_RV (*)(CK_FUNCTION_LIST_PTR_PTR))
sc_dlsym(mod->handle, "C_GetFunctionList");

View File

@ -69,7 +69,7 @@
#endif
#ifndef ENABLE_SHARED
extern CK_FUNCTION_LIST pkcs11_function_list;
extern CK_FUNCTION_LIST_3_0 pkcs11_function_list_3_0;
#endif
#define NEED_SESSION_RO 0x01
@ -970,7 +970,7 @@ int main(int argc, char * argv[])
#ifndef ENABLE_SHARED
if (strcmp(opt_module, DEFAULT_PKCS11_PROVIDER) == 0)
p11 = &pkcs11_function_list;
p11 = &pkcs11_function_list_3_0;
else
#endif
{