diff --git a/src/common/libpkcs11.c b/src/common/libpkcs11.c index 337bb5b1..ef57347a 100644 --- a/src/common/libpkcs11.c +++ b/src/common/libpkcs11.c @@ -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"); diff --git a/src/tools/pkcs11-tool.c b/src/tools/pkcs11-tool.c index 89244795..53861898 100644 --- a/src/tools/pkcs11-tool.c +++ b/src/tools/pkcs11-tool.c @@ -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 {