[winpr,ssl] check winpr_InitializeSSL return

This commit is contained in:
Armin Novak
2026-03-02 09:05:26 +01:00
parent 90536b924e
commit 0f46216a24
10 changed files with 37 additions and 18 deletions

View File

@@ -1397,7 +1397,9 @@ static BOOL setup_string(wArrayList* list)
rdpAssistanceFile* freerdp_assistance_file_new(void) rdpAssistanceFile* freerdp_assistance_file_new(void)
{ {
winpr_InitializeSSL(WINPR_SSL_INIT_DEFAULT); if (!winpr_InitializeSSL(WINPR_SSL_INIT_DEFAULT))
return nullptr;
rdpAssistanceFile* file = calloc(1, sizeof(rdpAssistanceFile)); rdpAssistanceFile* file = calloc(1, sizeof(rdpAssistanceFile));
if (!file) if (!file)
return nullptr; return nullptr;

View File

@@ -286,11 +286,11 @@ static BOOL test_msrsc_incident_file_type2(wLog* log)
int TestCommonAssistance(int argc, char* argv[]) int TestCommonAssistance(int argc, char* argv[])
{ {
wLog* log = nullptr;
WINPR_UNUSED(argc); WINPR_UNUSED(argc);
WINPR_UNUSED(argv); WINPR_UNUSED(argv);
log = WLog_Get(__func__); wLog* log = WLog_Get(__func__);
winpr_InitializeSSL(WINPR_SSL_INIT_DEFAULT); if (!winpr_InitializeSSL(WINPR_SSL_INIT_DEFAULT))
return -1;
for (size_t x = 0; x < ARRAYSIZE(fail_tests); x++) for (size_t x = 0; x < ARRAYSIZE(fail_tests); x++)
{ {

View File

@@ -1479,7 +1479,9 @@ int main(int argc, char* argv[])
} }
WTSRegisterWtsApiFunctionTable(FreeRDP_InitWtsApi()); WTSRegisterWtsApiFunctionTable(FreeRDP_InitWtsApi());
winpr_InitializeSSL(WINPR_SSL_INIT_DEFAULT); if (!winpr_InitializeSSL(WINPR_SSL_INIT_DEFAULT))
return -1;
instance = freerdp_listener_new(); instance = freerdp_listener_new();
if (!instance) if (!instance)

View File

@@ -813,7 +813,8 @@ BOOL pf_server_start(proxyServer* server)
WINPR_ASSERT(server); WINPR_ASSERT(server);
WTSRegisterWtsApiFunctionTable(FreeRDP_InitWtsApi()); WTSRegisterWtsApiFunctionTable(FreeRDP_InitWtsApi());
winpr_InitializeSSL(WINPR_SSL_INIT_DEFAULT); if (!winpr_InitializeSSL(WINPR_SSL_INIT_DEFAULT))
goto error;
if (WSAStartup(MAKEWORD(2, 2), &wsaData) != 0) if (WSAStartup(MAKEWORD(2, 2), &wsaData) != 0)
goto error; goto error;
@@ -853,7 +854,8 @@ BOOL pf_server_start_from_socket(proxyServer* server, int socket)
WINPR_ASSERT(server); WINPR_ASSERT(server);
WTSRegisterWtsApiFunctionTable(FreeRDP_InitWtsApi()); WTSRegisterWtsApiFunctionTable(FreeRDP_InitWtsApi());
winpr_InitializeSSL(WINPR_SSL_INIT_DEFAULT); if (!winpr_InitializeSSL(WINPR_SSL_INIT_DEFAULT))
goto error;
if (WSAStartup(MAKEWORD(2, 2), &wsaData) != 0) if (WSAStartup(MAKEWORD(2, 2), &wsaData) != 0)
goto error; goto error;

View File

@@ -233,7 +233,8 @@ int TestCryptoCipher(int argc, char* argv[])
WINPR_UNUSED(argc); WINPR_UNUSED(argc);
WINPR_UNUSED(argv); WINPR_UNUSED(argv);
winpr_InitializeSSL(WINPR_SSL_INIT_DEFAULT); if (!winpr_InitializeSSL(WINPR_SSL_INIT_DEFAULT))
return -1;
if (!test_crypto_cipher_aes_128_cbc(TRUE)) if (!test_crypto_cipher_aes_128_cbc(TRUE))
return -1; return -1;

View File

@@ -297,7 +297,8 @@ int TestCryptoHash(int argc, char* argv[])
WINPR_UNUSED(argc); WINPR_UNUSED(argc);
WINPR_UNUSED(argv); WINPR_UNUSED(argv);
winpr_InitializeSSL(WINPR_SSL_INIT_DEFAULT); if (!winpr_InitializeSSL(WINPR_SSL_INIT_DEFAULT))
return -1;
if (!test_crypto_hash_md5()) if (!test_crypto_hash_md5())
return -1; return -1;

View File

@@ -9,6 +9,7 @@ static const char* SECRET_PASSWORD_TEST = "MySecretPassword123!";
int TestCryptoProtectMemory(int argc, char* argv[]) int TestCryptoProtectMemory(int argc, char* argv[])
{ {
int rc = -1;
UINT32 cbPlainText = 0; UINT32 cbPlainText = 0;
UINT32 cbCipherText = 0; UINT32 cbCipherText = 0;
const char* pPlainText = nullptr; const char* pPlainText = nullptr;
@@ -30,12 +31,13 @@ int TestCryptoProtectMemory(int argc, char* argv[])
} }
CopyMemory(pCipherText, pPlainText, cbPlainText); CopyMemory(pCipherText, pPlainText, cbPlainText);
ZeroMemory(&pCipherText[cbPlainText], (cbCipherText - cbPlainText)); ZeroMemory(&pCipherText[cbPlainText], (cbCipherText - cbPlainText));
winpr_InitializeSSL(WINPR_SSL_INIT_DEFAULT); if (!winpr_InitializeSSL(WINPR_SSL_INIT_DEFAULT))
goto fail;
if (!CryptProtectMemory(pCipherText, cbCipherText, CRYPTPROTECTMEMORY_SAME_PROCESS)) if (!CryptProtectMemory(pCipherText, cbCipherText, CRYPTPROTECTMEMORY_SAME_PROCESS))
{ {
printf("CryptProtectMemory failure\n"); printf("CryptProtectMemory failure\n");
return -1; goto fail;
} }
printf("PlainText: %s (cbPlainText = %" PRIu32 ", cbCipherText = %" PRIu32 ")\n", pPlainText, printf("PlainText: %s (cbPlainText = %" PRIu32 ", cbCipherText = %" PRIu32 ")\n", pPlainText,
@@ -45,11 +47,14 @@ int TestCryptoProtectMemory(int argc, char* argv[])
if (!CryptUnprotectMemory(pCipherText, cbCipherText, CRYPTPROTECTMEMORY_SAME_PROCESS)) if (!CryptUnprotectMemory(pCipherText, cbCipherText, CRYPTPROTECTMEMORY_SAME_PROCESS))
{ {
printf("CryptUnprotectMemory failure\n"); printf("CryptUnprotectMemory failure\n");
return -1; goto fail;
} }
printf("Decrypted CipherText: %s\n", pCipherText); printf("Decrypted CipherText: %s\n", pCipherText);
SecureZeroMemory(pCipherText, cbCipherText); SecureZeroMemory(pCipherText, cbCipherText);
rc = 0;
fail:
free(pCipherText); free(pCipherText);
return 0; return rc;
} }

View File

@@ -587,12 +587,13 @@ SECURITY_STATUS schannel_openssl_decrypt_message(SCHANNEL_OPENSSL* context, PSec
SCHANNEL_OPENSSL* schannel_openssl_new(void) SCHANNEL_OPENSSL* schannel_openssl_new(void)
{ {
SCHANNEL_OPENSSL* context = nullptr; if (!winpr_InitializeSSL(WINPR_SSL_INIT_DEFAULT))
context = (SCHANNEL_OPENSSL*)calloc(1, sizeof(SCHANNEL_OPENSSL)); return nullptr;
SCHANNEL_OPENSSL* context = (SCHANNEL_OPENSSL*)calloc(1, sizeof(SCHANNEL_OPENSSL));
if (context != nullptr) if (context != nullptr)
{ {
winpr_InitializeSSL(WINPR_SSL_INIT_DEFAULT);
context->connected = FALSE; context->connected = FALSE;
} }

View File

@@ -972,7 +972,8 @@ static BOOL WINPR_init(void)
static BOOL CALLBACK sspi_init(WINPR_ATTR_UNUSED PINIT_ONCE InitOnce, static BOOL CALLBACK sspi_init(WINPR_ATTR_UNUSED PINIT_ONCE InitOnce,
WINPR_ATTR_UNUSED PVOID Parameter, WINPR_ATTR_UNUSED PVOID* Context) WINPR_ATTR_UNUSED PVOID Parameter, WINPR_ATTR_UNUSED PVOID* Context)
{ {
winpr_InitializeSSL(WINPR_SSL_INIT_DEFAULT); if (!winpr_InitializeSSL(WINPR_SSL_INIT_DEFAULT))
return FALSE;
sspi_ContextBufferAllocTableNew(); sspi_ContextBufferAllocTableNew();
if (!SCHANNEL_init()) if (!SCHANNEL_init())
return FALSE; return FALSE;

View File

@@ -153,7 +153,11 @@ int main(int argc, char* argv[])
printf("missing username or password\n\n"); printf("missing username or password\n\n");
return usage_and_exit(); return usage_and_exit();
} }
winpr_InitializeSSL(WINPR_SSL_INIT_DEFAULT); if (!winpr_InitializeSSL(WINPR_SSL_INIT_DEFAULT))
{
printf("winpr_InitializeSSL failed\n\n");
return usage_and_exit();
}
UserLength = strlen(User); UserLength = strlen(User);
PasswordLength = strlen(Password); PasswordLength = strlen(Password);