From d0b85cf10415a378c11d385066bb27116f2c2df1 Mon Sep 17 00:00:00 2001 From: Shahar Hadas <shaharhd@gmail.com> Date: 周日, 10 5月 2020 19:18:01 +0800 Subject: [PATCH] Fix network detection for Windows OS (#94) --- src/library/os/windows/signature_verifier.cpp | 35 ++++++++++++++--------------------- 1 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/library/os/windows/signature_verifier.cpp b/src/library/os/windows/signature_verifier.cpp index 88194a2..a99894b 100644 --- a/src/library/os/windows/signature_verifier.cpp +++ b/src/library/os/windows/signature_verifier.cpp @@ -15,16 +15,17 @@ #include <wincrypt.h> #include <iphlpapi.h> #include <windows.h> -#pragma comment(lib, "bcrypt.lib") +//#pragma comment(lib, "bcrypt.lib") #include <public_key.h> #include "../../base/logger.h" #include "../../base/base64.h" -#include "../signature_verifier.h" +#include "../signature_verifier.hpp" #define RSA_KEY_BITLEN 1024 namespace license { +namespace os { using namespace std; #define NT_SUCCESS(Status) (((NTSTATUS)(Status)) >= 0) @@ -43,13 +44,6 @@ } PUBKEY_BLOB, *P_PUBKEY_BLOB; #pragma pack(pop) -static BCRYPT_ALG_HANDLE openSignatureProvider() { - DWORD status; - BCRYPT_ALG_HANDLE hSignAlg = nullptr; - - return hSignAlg; -} - static BCRYPT_ALG_HANDLE openHashProvider() { DWORD status; BCRYPT_ALG_HANDLE hHashAlg = nullptr; @@ -61,7 +55,6 @@ static DWORD hashData(BCRYPT_HASH_HANDLE& hHash, const string& data, PBYTE pbHash, DWORD hashDataLenght) { DWORD status; - bool success = false; if (NT_SUCCESS(status = BCryptHashData(hHash, (BYTE*)data.c_str(), (ULONG)data.length(), 0))) { status = BCryptFinishHash(hHash, pbHash, hashDataLenght, 0); } @@ -74,7 +67,7 @@ cout << (len & 0x80) << endl; if ((len & 0x80) > 0) { size_t blen = len & 0x7F; - for (int i = 0; i < blen; i++) { + for (size_t i = 0; i < blen; i++) { result += (*(ptr++) << (i * 8)); } } else { @@ -106,7 +99,7 @@ if (expected_length < length) { return FUNC_RET_ERROR; } - for (int i = 0; i < length; i++) { + for (size_t i = 0; i < length; i++) { location[i] = *(ptr++); } return FUNC_RET_OK; @@ -143,12 +136,11 @@ DWORD status; FUNCTION_RETURN result = FUNC_RET_ERROR; PBYTE pbSignature = nullptr; - DWORD dwSigLen; - BYTE* sigBlob = nullptr; BCRYPT_ALG_HANDLE hSignAlg = nullptr; - // FIXME!! - sigBlob = unbase64(signatureBuffer.c_str(), (int)signatureBuffer.size(), (int*)&dwSigLen); + vector<uint8_t> signatureBlob = unbase64(signatureBuffer); + DWORD dwSigLen = (DWORD) signatureBlob.size(); + BYTE* sigBlob = &signatureBlob[0]; if (NT_SUCCESS(status = BCryptOpenAlgorithmProvider(&hSignAlg, BCRYPT_RSA_ALGORITHM, NULL, 0))) { if ((result = readPublicKey(hSignAlg, &phKey)) == FUNC_RET_OK) { @@ -167,7 +159,8 @@ } else { LOG_DEBUG("Error reading public key"); } - } else { + } + else { result = FUNC_RET_NOT_AVAIL; #ifdef _DEBUG formatError(status, "error opening RSA provider"); @@ -180,9 +173,9 @@ if (hSignAlg != nullptr) { BCryptCloseAlgorithmProvider(hSignAlg, 0); } - if (sigBlob) { - free(sigBlob); - } + //if (sigBlob) { + // free(sigBlob); + //} return result; } @@ -249,5 +242,5 @@ } return result; } - +} // namespace os } /* namespace license */ -- Gitblit v1.9.1