From 9f0a9efa1174e2cc5025e1e19bde4e2f0f21df1b Mon Sep 17 00:00:00 2001 From: alashkova Date: Fri, 21 Feb 2025 08:55:25 +0300 Subject: [PATCH] =?UTF-8?q?SUPPORT-8941.=20=D0=A3=D1=81=D1=82=D1=80=D0=B0?= =?UTF-8?q?=D0=BD=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=B7=D0=B0=D0=BC=D0=B5=D1=87?= =?UTF-8?q?=D0=B0=D0=BD=D0=B8=D0=B9=20=D0=BE=D1=82=20=D0=BB=D0=B0=D0=B1?= =?UTF-8?q?=D0=BE=D1=80=D0=B0=D1=82=D0=BE=D1=80=D0=B8=D0=B8=20=D0=A4=D0=98?= =?UTF-8?q?=D0=9D=D0=A2=D0=95=D0=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/capi.c | 1 - src/utils/capi.h | 11 ----------- src/utils/cryptopro.c | 37 +++++++++++++++++++++++++++++-------- 3 files changed, 29 insertions(+), 20 deletions(-) diff --git a/src/utils/capi.c b/src/utils/capi.c index 4bf63ba..83f8356 100644 --- a/src/utils/capi.c +++ b/src/utils/capi.c @@ -24,7 +24,6 @@ capi_function_list_init(library_t *lib, capi_function_list_t *fl) LIBRARY_RESOLVE(fl->CryptDestroyHash, lib, "CryptDestroyHash"); LIBRARY_RESOLVE(fl->CryptHashData, lib, "CryptHashData"); LIBRARY_RESOLVE(fl->CryptReleaseContext, lib, "CryptReleaseContext"); - LIBRARY_RESOLVE(fl->CryptSignMessage, lib, "CryptSignMessage"); LIBRARY_RESOLVE(fl->GetLastError, lib, "GetLastError"); LIBRARY_RESOLVE(fl->CryptImportPublicKeyInfo, lib, "CryptImportPublicKeyInfo"); LIBRARY_RESOLVE(fl->CryptDestroyKey, lib, "CryptDestroyKey"); diff --git a/src/utils/capi.h b/src/utils/capi.h index f19b875..4ea512b 100644 --- a/src/utils/capi.h +++ b/src/utils/capi.h @@ -15,16 +15,6 @@ typedef struct library_s library_t; DECLARE_FN(WINBASEAPI, DWORD, GET_LAST_ERROR, (void)); DECLARE_FN(WINADVAPI, BOOL, CRYPT_RELEASE_CONTEXT, (HCRYPTPROV hProv, DWORD dwFlags)); -DECLARE_FN(WINCRYPT32API, - BOOL, - CRYPT_SIGN_MESSAGE, - (IN PCRYPT_SIGN_MESSAGE_PARA pSignPara, - IN BOOL fDetachedSignature, - IN DWORD cToBeSigned, - IN const BYTE *rgpbToBeSigned[], - IN DWORD rgcbToBeSigned[], - OUT BYTE *pbSignedBlob, - IN OUT DWORD *pcbSignedBlob)); DECLARE_FN(WINCRYPT32API, BOOL, @@ -227,7 +217,6 @@ DECLARE_FN(WINADVAPI, typedef struct { - CRYPT_SIGN_MESSAGE_FN CryptSignMessage; CERT_FREE_CERTIFICATE_CONTEXT_FN CertFreeCertificateContext; CERT_OPEN_STORE_FN CertOpenStore; CERT_CLOSE_STORE_FN CertCloseStore; diff --git a/src/utils/cryptopro.c b/src/utils/cryptopro.c index 10422f2..f059553 100644 --- a/src/utils/cryptopro.c +++ b/src/utils/cryptopro.c @@ -376,11 +376,17 @@ sign_hash_data(const cryptopro_context_t *ctx, const str_t *data, /*out*/ str_t exit: if (hash) { - cp_function_list.CryptDestroyHash(hash); + if (!cp_function_list.CryptDestroyHash(hash)) { + LOG_ERROR("CryptDestroyHash() failed"); + rc = -1; + } } if (bReleaseContext) { - cp_function_list.CryptReleaseContext(hCryptProv, 0); + if (!cp_function_list.CryptReleaseContext(hCryptProv, 0)) { + LOG_ERROR("CryptReleaseContext() failed"); + rc = -1; + } } @@ -763,15 +769,24 @@ exit: str_t_clear(&sign_reversed); if (hash) { - cp_function_list.CryptDestroyHash(hash); + if (!cp_function_list.CryptDestroyHash(hash)) { + LOG_ERROR("CryptDestroyHash() failed"); + rc = -1; + } } if (hPubKey) { - cp_function_list.CryptDestroyKey(hPubKey); + if (!cp_function_list.CryptDestroyKey(hPubKey)) { + LOG_ERROR("CryptDestroyKey() failed"); + rc = -1; + } } if (hCryptProv) { - cp_function_list.CryptReleaseContext(hCryptProv, 0); + if (!cp_function_list.CryptReleaseContext(hCryptProv, 0)) { + LOG_ERROR("CryptReleaseContext() failed"); + rc = -1; + } } if (certificate) { @@ -796,7 +811,7 @@ exit: int cryptopro_gen_random(unsigned char* data, size_t len) { - HCRYPTPROV hCryptProv = 0; + HCRYPTPROV hCryptProv = 0; LOG_TRACE("cryptopro_gen_random enter"); @@ -811,14 +826,20 @@ cryptopro_gen_random(unsigned char* data, size_t len) goto error; } - cp_function_list.CryptReleaseContext(hCryptProv, 0); + if (!cp_function_list.CryptReleaseContext(hCryptProv, 0)) { + LOG_ERROR("CryptReleaseContext() failed"); + hCryptProv = 0; + goto error; + } LOG_TRACE("cryptopro_gen_random exit"); return 0; error: if (hCryptProv) { - cp_function_list.CryptReleaseContext(hCryptProv, 0); + if (!cp_function_list.CryptReleaseContext(hCryptProv, 0)) { + LOG_ERROR("CryptReleaseContext() failed"); + } } LOG_ERROR("cryptopro_gen_random exit with error. Last error code: 0x%08x",