SUPPORT-8941. Устранение замечаний от лаборатории ФИНТЕХ

This commit is contained in:
alashkova 2025-02-21 08:55:25 +03:00
parent e351409288
commit 9f0a9efa11
3 changed files with 29 additions and 20 deletions

View file

@ -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");

View file

@ -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;

View file

@ -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) {
@ -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",