1
0
mirror of https://github.com/veracrypt/VeraCrypt.git synced 2025-11-11 11:08:02 -06:00

Windows: Fix failure to launch keyfile generator in secure desktop mode

Hooking is not allowed if thread is running in secure desktop so we ignore SetWindowsHookEx failure in this case and random generator will be initialized using the other entropy sources from the system.
This commit is contained in:
Mounir IDRASSI
2021-02-24 21:48:33 +01:00
parent 7efe4e4f2a
commit c1e81d9692

View File

@@ -14,6 +14,7 @@
#include "Tcdefs.h" #include "Tcdefs.h"
#include "Crc.h" #include "Crc.h"
#include "Random.h" #include "Random.h"
#include "Dlgcode.h"
#include "Crypto\cpu.h" #include "Crypto\cpu.h"
#include "Crypto\jitterentropy.h" #include "Crypto\jitterentropy.h"
#include "Crypto\rdrand.h" #include "Crypto\rdrand.h"
@@ -96,6 +97,7 @@ HCRYPTPROV hCryptProv;
/* Init the random number generator, setup the hooks, and start the thread */ /* Init the random number generator, setup the hooks, and start the thread */
int RandinitWithCheck ( int* pAlreadyInitialized) int RandinitWithCheck ( int* pAlreadyInitialized)
{ {
BOOL bIgnoreHookError = FALSE;
DWORD dwLastError = ERROR_SUCCESS; DWORD dwLastError = ERROR_SUCCESS;
if (GetMaxPkcs5OutSize() > RNG_POOL_SIZE) if (GetMaxPkcs5OutSize() > RNG_POOL_SIZE)
TC_THROW_FATAL_EXCEPTION; TC_THROW_FATAL_EXCEPTION;
@@ -129,11 +131,13 @@ int RandinitWithCheck ( int* pAlreadyInitialized)
VirtualLock (pRandPool, RANDOMPOOL_ALLOCSIZE); VirtualLock (pRandPool, RANDOMPOOL_ALLOCSIZE);
} }
bIgnoreHookError = IsThreadInSecureDesktop(GetCurrentThreadId());
hKeyboard = SetWindowsHookEx (WH_KEYBOARD, (HOOKPROC)&KeyboardProc, NULL, GetCurrentThreadId ()); hKeyboard = SetWindowsHookEx (WH_KEYBOARD, (HOOKPROC)&KeyboardProc, NULL, GetCurrentThreadId ());
if (hKeyboard == 0) handleWin32Error (0, SRC_POS); if (hKeyboard == 0 && !bIgnoreHookError) handleWin32Error (0, SRC_POS);
hMouse = SetWindowsHookEx (WH_MOUSE, (HOOKPROC)&MouseProc, NULL, GetCurrentThreadId ()); hMouse = SetWindowsHookEx (WH_MOUSE, (HOOKPROC)&MouseProc, NULL, GetCurrentThreadId ());
if (hMouse == 0) if (hMouse == 0 && !bIgnoreHookError)
{ {
handleWin32Error (0, SRC_POS); handleWin32Error (0, SRC_POS);
goto error; goto error;