|
2 | 2 | #include "remote.h" |
3 | 3 | #include "packet_encryption.h" |
4 | 4 |
|
| 5 | +// The provider name strings below (MS_ENH_RSA_AES_PROV, MS_ENHANCED_PROV) are |
| 6 | +// TCHAR — LPCWSTR under UNICODE (MSVC vcxproj build), LPCSTR under the mingw |
| 7 | +// docker build. Route through the matching A/W wrapper so both toolchains build. |
| 8 | +#ifdef UNICODE |
| 9 | +#define WINAPI_CryptAcquireContext_TCHAR met_api->win_api.advapi32.CryptAcquireContextW |
| 10 | +#else |
| 11 | +#define WINAPI_CryptAcquireContext_TCHAR met_api->win_api.advapi32.CryptAcquireContextA |
| 12 | +#endif |
| 13 | + |
5 | 14 | typedef struct _CryptProviderParams |
6 | 15 | { |
7 | 16 | const TCHAR* provider; |
@@ -353,10 +362,10 @@ DWORD public_key_encrypt(BYTE* publicKeyDer, UINT publicKeyDerLen, BYTE* data, D |
353 | 362 |
|
354 | 363 | dprintf("[ENC] Key algo: %s", pubKeyInfo->Algorithm.pszObjId); |
355 | 364 |
|
356 | | - if (!met_api->win_api.advapi32.CryptAcquireContextA(&rsaProv, NULL, MS_ENHANCED_PROV, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT)) |
| 365 | + if (!WINAPI_CryptAcquireContext_TCHAR(&rsaProv, NULL, MS_ENHANCED_PROV, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT)) |
357 | 366 | { |
358 | 367 | dprintf("[ENC] Failed to create the RSA provider with CRYPT_VERIFYCONTEXT"); |
359 | | - if (!met_api->win_api.advapi32.CryptAcquireContextA(&rsaProv, NULL, MS_ENHANCED_PROV, PROV_RSA_FULL, CRYPT_NEWKEYSET)) |
| 368 | + if (!WINAPI_CryptAcquireContext_TCHAR(&rsaProv, NULL, MS_ENHANCED_PROV, PROV_RSA_FULL, CRYPT_NEWKEYSET)) |
360 | 369 | { |
361 | 370 | result = GetLastError(); |
362 | 371 | dprintf("[ENC] Failed to create the RSA provider with CRYPT_NEWKEYSET: %u (%x)", result, result); |
@@ -490,7 +499,7 @@ DWORD create_enc_ctx_from_key(Remote* remote, LPBYTE key, DWORD keySize) |
490 | 499 |
|
491 | 500 | for (int i = 0; i < _countof(AesProviders); ++i) |
492 | 501 | { |
493 | | - if (!met_api->win_api.advapi32.CryptAcquireContextA(&ctx->provider, NULL, AesProviders[i].provider, AesProviders[i].type, AesProviders[i].flags)) |
| 502 | + if (!WINAPI_CryptAcquireContext_TCHAR(&ctx->provider, NULL, AesProviders[i].provider, AesProviders[i].type, AesProviders[i].flags)) |
494 | 503 | { |
495 | 504 | result = GetLastError(); |
496 | 505 | dprintf("[ENC] failed to acquire the crypt context %d: %d (%x)", i, result, result); |
@@ -553,7 +562,7 @@ DWORD request_negotiate_aes_key(Remote* remote, Packet* packet) |
553 | 562 |
|
554 | 563 | for (int i = 0; i < _countof(AesProviders); ++i) |
555 | 564 | { |
556 | | - if (!met_api->win_api.advapi32.CryptAcquireContextA(&ctx->provider, NULL, AesProviders[i].provider, AesProviders[i].type, AesProviders[i].flags)) |
| 565 | + if (!WINAPI_CryptAcquireContext_TCHAR(&ctx->provider, NULL, AesProviders[i].provider, AesProviders[i].type, AesProviders[i].flags)) |
557 | 566 | { |
558 | 567 | result = GetLastError(); |
559 | 568 | dprintf("[ENC] failed to acquire the crypt context %d: %d (%x)", i, result, result); |
|
0 commit comments