From 6f5db32d147166ab1617c66844e3297eededc704 Mon Sep 17 00:00:00 2001
From: Gabriele Contini <gcontini@users.noreply.github.com>
Date: 摹曛, 19 9月 2019 20:20:18 +0800
Subject: [PATCH] Feature/mingw cross compile (#51)

---
 src/tools/base_lib/win/CryptoHelperWindows.cpp |   11 +++++++++--
 1 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/src/tools/base_lib/win/CryptoHelperWindows.cpp b/src/tools/base_lib/win/CryptoHelperWindows.cpp
index 98d14b3..99e0b12 100644
--- a/src/tools/base_lib/win/CryptoHelperWindows.cpp
+++ b/src/tools/base_lib/win/CryptoHelperWindows.cpp
@@ -21,14 +21,14 @@
 CryptoHelperWindows::CryptoHelperWindows() {
 	m_hCryptProv = NULL;
 	m_hCryptKey = NULL;
-	if (!CryptAcquireContext(&m_hCryptProv, "license_sign", NULL, PROV_RSA_FULL, 0)) {
+	if (!CryptAcquireContext(&m_hCryptProv, "license_sign", NULL , PROV_RSA_FULL, 0)) {
 		// If the key container cannot be opened, try creating a new
 		// container by specifying a container name and setting the
 		// CRYPT_NEWKEYSET flag.
 		DWORD lastError = GetLastError();
 		printf("Error in CryptAcquireContext (1) 0x%08x \n", lastError);
 		if (NTE_BAD_KEYSET == lastError) {
-			if (!CryptAcquireContext(&m_hCryptProv, "license_sign", NULL, PROV_RSA_FULL, CRYPT_NEWKEYSET)) {
+			if (!CryptAcquireContext(&m_hCryptProv, "license_sign", NULL , PROV_RSA_FULL, CRYPT_NEWKEYSET)) {
 				printf("Warn in CryptAcquireContext: acquiring new user keyset failed 0x%08x, trying less secure mackine keyset \n", GetLastError());
 				//maybe access to protected storage disabled. Try with machine keys (less secure)
 				if (!CryptAcquireContext(&m_hCryptProv, "license_sign", NULL, PROV_RSA_FULL, CRYPT_MACHINE_KEYSET)) {
@@ -71,6 +71,13 @@
 				string("Error generating keys ")
 						+ to_string(static_cast<long long>(dwErrCode)));
 	}
+	//double check the key is really generated
+	if(m_hCryptKey == NULL) {
+		dwErrCode = GetLastError();
+		throw logic_error(
+				string("Error generating keys (2)")
+						+ to_string(static_cast<long long>(dwErrCode)));
+    }
 }
 
 /* This method calls the CryptExportKey function to get the Public key

--
Gitblit v1.9.1