Merge pull request #3967 from embhorn/zd12116

PKCS#11: Add debug for failure in wc_Pkcs11_Initialize
This commit is contained in:
Sean Parkinson
2021-04-21 08:06:14 +10:00
committed by GitHub

View File

@@ -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. * 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] op PKCS #11 operation that was attempted.
* @param [in] rv PKCS #11 return value. * @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) { if (ret == 0) {
dev->func = NULL; dev->func = NULL;
func = dlsym(dev->dlHandle, "C_GetFunctionList"); func = dlsym(dev->dlHandle, "C_GetFunctionList");
if (func == NULL) if (func == NULL) {
WOLFSSL_MSG(dlerror());
ret = WC_HW_E; ret = WC_HW_E;
}
} }
if (ret == 0) { 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; ret = WC_HW_E;
}
} }
if (ret == 0) { if (ret == 0) {
XMEMSET(&args, 0x00, sizeof(args)); XMEMSET(&args, 0x00, sizeof(args));
args.flags = CKF_OS_LOCKING_OK; 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; ret = WC_INIT_E;
}
} }
if (ret != 0) if (ret != 0)