From 94eb096e42844136af5035a3ff955ceec1917957 Mon Sep 17 00:00:00 2001 From: Eric Blankenhorn Date: Mon, 19 Apr 2021 09:20:15 -0500 Subject: [PATCH] Add debug for failure in wc_Pkcs11_Initialize --- wolfcrypt/src/wc_pkcs11.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/wolfcrypt/src/wc_pkcs11.c b/wolfcrypt/src/wc_pkcs11.c index 3c4600e5e..0c9f82b18 100644 --- a/wolfcrypt/src/wc_pkcs11.c +++ b/wolfcrypt/src/wc_pkcs11.c @@ -340,7 +340,7 @@ static void pkcs11_dump_template(CK_ATTRIBUTE* templ, CK_ULONG cnt) /* * Log a PKCS #11 return value with the name of function called. * - * This is only for debugging purposes. Only the values needed are recognised. + * This is only for debugging purposes. Only the values needed are recognized. * * @param [in] op PKCS #11 operation that was attempted. * @param [in] rv PKCS #11 return value. @@ -415,19 +415,31 @@ int wc_Pkcs11_Initialize(Pkcs11Dev* dev, const char* library, void* heap) if (ret == 0) { dev->func = NULL; func = dlsym(dev->dlHandle, "C_GetFunctionList"); - if (func == NULL) + if (func == NULL) { + WOLFSSL_MSG(dlerror()); ret = WC_HW_E; + } } if (ret == 0) { - if (((CK_C_GetFunctionList)func)(&dev->func) != CKR_OK) + ret = ((CK_C_GetFunctionList)func)(&dev->func); + if (ret != CKR_OK) { +#ifdef WOLFSSL_DEBUG_PKCS11 + pkcs11_rv("CK_C_GetFunctionList", ret); +#endif ret = WC_HW_E; + } } if (ret == 0) { XMEMSET(&args, 0x00, sizeof(args)); args.flags = CKF_OS_LOCKING_OK; - if (dev->func->C_Initialize(&args) != CKR_OK) + ret = dev->func->C_Initialize(&args); + if (ret != CKR_OK) { +#ifdef WOLFSSL_DEBUG_PKCS11 + pkcs11_rv("C_Initialize", ret); +#endif ret = WC_INIT_E; + } } if (ret != 0)