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",