common, pkcs11-tool: Use new PKCS #11 API with fallback to old one
This commit is contained in:
parent
224e265266
commit
6e25924eb0
|
@ -49,6 +49,7 @@ C_LoadModule(const char *mspec, CK_FUNCTION_LIST_PTR_PTR funcs)
|
||||||
{
|
{
|
||||||
sc_pkcs11_module_t *mod;
|
sc_pkcs11_module_t *mod;
|
||||||
CK_RV rv, (*c_get_function_list)(CK_FUNCTION_LIST_PTR_PTR);
|
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));
|
mod = calloc(1, sizeof(*mod));
|
||||||
if (mod == NULL) {
|
if (mod == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -65,6 +66,24 @@ C_LoadModule(const char *mspec, CK_FUNCTION_LIST_PTR_PTR funcs)
|
||||||
goto failed;
|
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 */
|
/* Get the list of function pointers */
|
||||||
c_get_function_list = (CK_RV (*)(CK_FUNCTION_LIST_PTR_PTR))
|
c_get_function_list = (CK_RV (*)(CK_FUNCTION_LIST_PTR_PTR))
|
||||||
sc_dlsym(mod->handle, "C_GetFunctionList");
|
sc_dlsym(mod->handle, "C_GetFunctionList");
|
||||||
|
|
|
@ -69,7 +69,7 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef ENABLE_SHARED
|
#ifndef ENABLE_SHARED
|
||||||
extern CK_FUNCTION_LIST pkcs11_function_list;
|
extern CK_FUNCTION_LIST_3_0 pkcs11_function_list_3_0;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define NEED_SESSION_RO 0x01
|
#define NEED_SESSION_RO 0x01
|
||||||
|
@ -970,7 +970,7 @@ int main(int argc, char * argv[])
|
||||||
|
|
||||||
#ifndef ENABLE_SHARED
|
#ifndef ENABLE_SHARED
|
||||||
if (strcmp(opt_module, DEFAULT_PKCS11_PROVIDER) == 0)
|
if (strcmp(opt_module, DEFAULT_PKCS11_PROVIDER) == 0)
|
||||||
p11 = &pkcs11_function_list;
|
p11 = &pkcs11_function_list_3_0;
|
||||||
else
|
else
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue