From 9b1cdf244590568e6446ff64953634e7808aaac1 Mon Sep 17 00:00:00 2001 From: S-P Chan Date: Thu, 22 Feb 2024 12:54:43 +0800 Subject: [PATCH] Fallback if C_GetInterface returns 0x54 Addresses #621 Signed-off-by: S-P Chan --- p11-kit/modules.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/p11-kit/modules.c b/p11-kit/modules.c index da0a7f04d..fd99bcc70 100644 --- a/p11-kit/modules.c +++ b/p11-kit/modules.c @@ -365,6 +365,7 @@ dlopen_and_get_function_list (Module *mod, dl_module_t dl; char *error; CK_RV rv; + int fallback = 0; assert (mod != NULL); assert (path != NULL); @@ -392,15 +393,22 @@ dlopen_and_get_function_list (Module *mod, if (gi) { /* Get the default standard interface */ rv = gi ((unsigned char *)"PKCS 11", NULL, &interface, 0); - if (rv != CKR_OK) { + switch(rv) { + case CKR_FUNCTION_NOT_SUPPORTED: + fallback = 1; + break; + case CKR_OK: + /* TODO check the version and flag it somehere? */ + *funcs = interface->pFunctionList; + break; + default: p11_message (_("call to C_GetInterface failed in module: %s: %s"), path, p11_kit_strerror (rv)); return rv; } + } - /* TODO check the version and flag it somehere? */ - *funcs = interface->pFunctionList; - } else { + if (!gi || fallback) { p11_debug ("C_GetInterface not available. Falling back to C_GetFunctionList()"); gfl = p11_dl_symbol (dl, "C_GetFunctionList");