diff options
author | Mounir IDRASSI <mounir.idrassi@idrix.fr> | 2016-12-30 12:17:09 +0100 |
---|---|---|
committer | Mounir IDRASSI <mounir.idrassi@idrix.fr> | 2016-12-30 23:56:28 +0100 |
commit | cdbe54e60542231f832d59389381bf9b56b710be (patch) | |
tree | cc71665cba8e86003f65c9385a166e787b8966aa /src/Common | |
parent | d116eba1607ca82d90874018037a19088a4bb26d (diff) | |
download | VeraCrypt-cdbe54e60542231f832d59389381bf9b56b710be.tar.gz VeraCrypt-cdbe54e60542231f832d59389381bf9b56b710be.zip |
Windows: Implement Secure Desktop for password entry. Add option and command line switch to activate it.
Diffstat (limited to 'src/Common')
-rw-r--r-- | src/Common/Dlgcode.c | 176 | ||||
-rw-r--r-- | src/Common/Dlgcode.h | 4 | ||||
-rw-r--r-- | src/Common/Language.xml | 1 |
3 files changed, 181 insertions, 0 deletions
diff --git a/src/Common/Dlgcode.c b/src/Common/Dlgcode.c index 001d7102..3fc5c06a 100644 --- a/src/Common/Dlgcode.c +++ b/src/Common/Dlgcode.c | |||
@@ -26,6 +26,11 @@ | |||
26 | #include <time.h> | 26 | #include <time.h> |
27 | #include <tchar.h> | 27 | #include <tchar.h> |
28 | #include <Richedit.h> | 28 | #include <Richedit.h> |
29 | #ifdef TCMOUNT | ||
30 | #include <Shlwapi.h> | ||
31 | #include <process.h> | ||
32 | #include <Tlhelp32.h> | ||
33 | #endif | ||
29 | 34 | ||
30 | #include "Resource.h" | 35 | #include "Resource.h" |
31 | 36 | ||
@@ -108,6 +113,9 @@ BOOL bShowDisconnectedNetworkDrives = FALSE; | |||
108 | BOOL bHideWaitingDialog = FALSE; | 113 | BOOL bHideWaitingDialog = FALSE; |
109 | BOOL bCmdHideWaitingDialog = FALSE; | 114 | BOOL bCmdHideWaitingDialog = FALSE; |
110 | BOOL bCmdHideWaitingDialogValid = FALSE; | 115 | BOOL bCmdHideWaitingDialogValid = FALSE; |
116 | BOOL bUseSecureDesktop = FALSE; | ||
117 | BOOL bCmdUseSecureDesktop = FALSE; | ||
118 | BOOL bCmdUseSecureDesktopValid = FALSE; | ||
111 | BOOL bStartOnLogon = FALSE; | 119 | BOOL bStartOnLogon = FALSE; |
112 | BOOL bMountDevicesOnLogon = FALSE; | 120 | BOOL bMountDevicesOnLogon = FALSE; |
113 | BOOL bMountFavoritesOnLogon = FALSE; | 121 | BOOL bMountFavoritesOnLogon = FALSE; |
@@ -12225,3 +12233,171 @@ BOOL DeleteDirectory (const wchar_t* szDirName) | |||
12225 | } | 12233 | } |
12226 | return bStatus; | 12234 | return bStatus; |
12227 | } | 12235 | } |
12236 | |||
12237 | #ifdef TCMOUNT | ||
12238 | /*********************************************************************/ | ||
12239 | |||
12240 | static BOOL GenerateRandomString (HWND hwndDlg, LPTSTR szName, DWORD maxCharsCount) | ||
12241 | { | ||
12242 | BOOL bRet = FALSE; | ||
12243 | if (Randinit () != ERR_SUCCESS) | ||
12244 | { | ||
12245 | handleError (hwndDlg, (CryptoAPILastError == ERROR_SUCCESS)? ERR_RAND_INIT_FAILED : ERR_CAPI_INIT_FAILED, SRC_POS); | ||
12246 | } | ||
12247 | else | ||
12248 | { | ||
12249 | BYTE* indexes = (BYTE*) malloc (maxCharsCount + 1); | ||
12250 | bRet = RandgetBytesFull (hwndDlg, indexes, maxCharsCount + 1, TRUE, TRUE); | ||
12251 | if (bRet) | ||
12252 | { | ||
12253 | static LPCTSTR chars = _T("0123456789@#$%^&_-*abcdefghijklmnopqrstuvwxyz"); | ||
12254 | DWORD i, charsLen = (DWORD) _tcslen (chars); | ||
12255 | DWORD effectiveLen = (indexes[0] % (64 - 16)) + 16; // random length between 16 to 64 | ||
12256 | effectiveLen = (effectiveLen > maxCharsCount)? maxCharsCount : effectiveLen; | ||
12257 | |||
12258 | for (i = 0; i < effectiveLen; i++) | ||
12259 | { | ||
12260 | szName[i] = chars[indexes[i + 1] % charsLen]; | ||
12261 | } | ||
12262 | |||
12263 | szName[effectiveLen] = 0; | ||
12264 | } | ||
12265 | burn (indexes, maxCharsCount + 1); | ||
12266 | free (indexes); | ||
12267 | } | ||
12268 | |||
12269 | return bRet; | ||
12270 | } | ||
12271 | |||
12272 | typedef struct | ||
12273 | { | ||
12274 | HDESK hDesk; | ||
12275 | HINSTANCE hInstance; | ||
12276 | LPCWSTR lpTemplateName; | ||
12277 | DLGPROC lpDialogFunc; | ||
12278 | LPARAM dwInitParam; | ||
12279 | INT_PTR retValue; | ||
12280 | } SecureDesktopThreadParam; | ||
12281 | |||
12282 | static DWORD WINAPI SecureDesktopThread(LPVOID lpThreadParameter) | ||
12283 | { | ||
12284 | SecureDesktopThreadParam* pParam = (SecureDesktopThreadParam*) lpThreadParameter; | ||
12285 | |||
12286 | SetThreadDesktop (pParam->hDesk); | ||
12287 | SwitchDesktop (pParam->hDesk); | ||
12288 | |||
12289 | pParam->retValue = DialogBoxParamW (pParam->hInstance, pParam->lpTemplateName, | ||
12290 | NULL, pParam->lpDialogFunc, pParam->dwInitParam); | ||
12291 | |||
12292 | return 0; | ||
12293 | } | ||
12294 | |||
12295 | static void GetCtfMonProcessIdList (map<DWORD, BOOL>& processIdList) | ||
12296 | { | ||
12297 | HANDLE hSnapShot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, NULL); | ||
12298 | PROCESSENTRY32 pEntry; | ||
12299 | BOOL hRes; | ||
12300 | |||
12301 | pEntry.dwSize = sizeof (pEntry); | ||
12302 | processIdList.clear(); | ||
12303 | hRes = Process32First(hSnapShot, &pEntry); | ||
12304 | while (hRes) | ||
12305 | { | ||
12306 | LPTSTR szFileName = PathFindFileName (pEntry.szExeFile); | ||
12307 | if (_wcsicmp(szFileName, L"ctfmon.exe") == 0) | ||
12308 | { | ||
12309 | processIdList[pEntry.th32ProcessID] = TRUE; | ||
12310 | } | ||
12311 | hRes = Process32Next(hSnapShot, &pEntry); | ||
12312 | } | ||
12313 | CloseHandle(hSnapShot); | ||
12314 | } | ||
12315 | |||
12316 | static void KillProcess (DWORD dwProcessId) | ||
12317 | { | ||
12318 | HANDLE hProcess = OpenProcess(PROCESS_TERMINATE, 0, dwProcessId); | ||
12319 | if (hProcess != NULL) | ||
12320 | { | ||
12321 | TerminateProcess(hProcess, (UINT) -1); | ||
12322 | CloseHandle(hProcess); | ||
12323 | } | ||
12324 | } | ||
12325 | |||
12326 | INT_PTR SecureDesktopDialogBoxParam( | ||
12327 | HINSTANCE hInstance, | ||
12328 | LPCWSTR lpTemplateName, | ||
12329 | HWND hWndParent, | ||
12330 | DLGPROC lpDialogFunc, | ||
12331 | LPARAM dwInitParam) | ||
12332 | { | ||
12333 | TCHAR szDesktopName[65] = {0}; | ||
12334 | BOOL bSuccess = FALSE; | ||
12335 | INT_PTR retValue = 0; | ||
12336 | BOOL bEffectiveUseSecureDesktop = bCmdUseSecureDesktopValid? bCmdUseSecureDesktop : bUseSecureDesktop; | ||
12337 | |||
12338 | if (bEffectiveUseSecureDesktop && GenerateRandomString (hWndParent, szDesktopName, 64)) | ||
12339 | { | ||
12340 | map<DWORD, BOOL> ctfmonBeforeList, ctfmonAfterList; | ||
12341 | DWORD desktopAccess = DESKTOP_CREATEMENU | DESKTOP_CREATEWINDOW | DESKTOP_READOBJECTS | DESKTOP_SWITCHDESKTOP | DESKTOP_WRITEOBJECTS; | ||
12342 | HDESK hSecureDesk; | ||
12343 | |||
12344 | // get the initial list of ctfmon.exe processes before creating new desktop | ||
12345 | GetCtfMonProcessIdList (ctfmonBeforeList); | ||
12346 | |||
12347 | hSecureDesk = CreateDesktop (szDesktopName, NULL, NULL, 0, desktopAccess, NULL); | ||
12348 | if (hSecureDesk) | ||
12349 | { | ||
12350 | HDESK hOriginalDesk = GetThreadDesktop (GetCurrentThreadId ()); | ||
12351 | SecureDesktopThreadParam param; | ||
12352 | |||
12353 | param.hDesk = hSecureDesk; | ||
12354 | param.hInstance = hInstance; | ||
12355 | param.lpTemplateName = lpTemplateName; | ||
12356 | param.lpDialogFunc = lpDialogFunc; | ||
12357 | param.dwInitParam = dwInitParam; | ||
12358 | param.retValue = 0; | ||
12359 | |||
12360 | HANDLE hThread = ::CreateThread (NULL, 0, SecureDesktopThread, (LPVOID) ¶m, 0, NULL); | ||
12361 | if (hThread) | ||
12362 | { | ||
12363 | WaitForSingleObject (hThread, INFINITE); | ||
12364 | CloseHandle (hThread); | ||
12365 | |||
12366 | SwitchDesktop (hOriginalDesk); | ||
12367 | SetThreadDesktop (hOriginalDesk); | ||
12368 | |||
12369 | retValue = param.retValue; | ||
12370 | bSuccess = TRUE; | ||
12371 | } | ||
12372 | |||
12373 | CloseDesktop (hSecureDesk); | ||
12374 | |||
12375 | // get the new list of ctfmon.exe processes in order to find the ID of the | ||
12376 | // ctfmon.exe instance that corresponds to the desktop we create so that | ||
12377 | // we can kill it, otherwise it would remain running | ||
12378 | GetCtfMonProcessIdList (ctfmonAfterList); | ||
12379 | |||
12380 | for (map<DWORD, BOOL>::iterator It = ctfmonAfterList.begin(); | ||
12381 | It != ctfmonAfterList.end(); It++) | ||
12382 | { | ||
12383 | if (ctfmonBeforeList[It->first] != TRUE) | ||
12384 | { | ||
12385 | // Kill process | ||
12386 | KillProcess (It->first); | ||
12387 | } | ||
12388 | } | ||
12389 | } | ||
12390 | |||
12391 | burn (szDesktopName, sizeof (szDesktopName)); | ||
12392 | } | ||
12393 | |||
12394 | if (!bSuccess) | ||
12395 | { | ||
12396 | // fallback to displaying in normal desktop | ||
12397 | retValue = DialogBoxParamW (hInstance, lpTemplateName, hWndParent, lpDialogFunc, dwInitParam); | ||
12398 | } | ||
12399 | |||
12400 | return retValue; | ||
12401 | } | ||
12402 | |||
12403 | #endif | ||
diff --git a/src/Common/Dlgcode.h b/src/Common/Dlgcode.h index 86afbe0f..a1930f67 100644 --- a/src/Common/Dlgcode.h +++ b/src/Common/Dlgcode.h | |||
@@ -121,6 +121,9 @@ extern BOOL bShowDisconnectedNetworkDrives; | |||
121 | extern BOOL bHideWaitingDialog; | 121 | extern BOOL bHideWaitingDialog; |
122 | extern BOOL bCmdHideWaitingDialog; | 122 | extern BOOL bCmdHideWaitingDialog; |
123 | extern BOOL bCmdHideWaitingDialogValid; | 123 | extern BOOL bCmdHideWaitingDialogValid; |
124 | extern BOOL bUseSecureDesktop; | ||
125 | extern BOOL bCmdUseSecureDesktop; | ||
126 | extern BOOL bCmdUseSecureDesktopValid; | ||
124 | extern BOOL bStartOnLogon; | 127 | extern BOOL bStartOnLogon; |
125 | extern BOOL bMountDevicesOnLogon; | 128 | extern BOOL bMountDevicesOnLogon; |
126 | extern BOOL bMountFavoritesOnLogon; | 129 | extern BOOL bMountFavoritesOnLogon; |
@@ -514,6 +517,7 @@ BOOL LaunchElevatedProcess (HWND hwndDlg, const wchar_t* szModPath, const wchar_ | |||
514 | BOOL GetFreeDriveLetter(WCHAR* pCh); | 517 | BOOL GetFreeDriveLetter(WCHAR* pCh); |
515 | BOOL RaisePrivileges(void); | 518 | BOOL RaisePrivileges(void); |
516 | BOOL DeleteDirectory (const wchar_t* szDirName); | 519 | BOOL DeleteDirectory (const wchar_t* szDirName); |
520 | INT_PTR SecureDesktopDialogBoxParam (HINSTANCE, LPCWSTR, HWND, DLGPROC, LPARAM); | ||
517 | 521 | ||
518 | #ifdef __cplusplus | 522 | #ifdef __cplusplus |
519 | } | 523 | } |
diff --git a/src/Common/Language.xml b/src/Common/Language.xml index 1addd375..6c5697b4 100644 --- a/src/Common/Language.xml +++ b/src/Common/Language.xml | |||
@@ -1413,6 +1413,7 @@ | |||
1413 | <string lang="en" key="RESCUE_DISK_EFI_CHECK_FAILED">Cannot verify that the Rescue Disk has been correctly extracted.\n\nIf you have extracted the Rescue Disk, please eject and reinsert the USB stick; then click Next to try again. If this does not help, please try another USB stick and/or another ZIP software.\n\nIf you have not extracted the Rescue Disk yet, please do so, and then click Next.\n\nIf you attempted to verify a VeraCrypt Rescue Disk created before you started this wizard, please note that such Rescue Disk cannot be used, because it was created for a different master key. You need to extract the newly generated Rescue Disk ZIP image.</string> | 1413 | <string lang="en" key="RESCUE_DISK_EFI_CHECK_FAILED">Cannot verify that the Rescue Disk has been correctly extracted.\n\nIf you have extracted the Rescue Disk, please eject and reinsert the USB stick; then click Next to try again. If this does not help, please try another USB stick and/or another ZIP software.\n\nIf you have not extracted the Rescue Disk yet, please do so, and then click Next.\n\nIf you attempted to verify a VeraCrypt Rescue Disk created before you started this wizard, please note that such Rescue Disk cannot be used, because it was created for a different master key. You need to extract the newly generated Rescue Disk ZIP image.</string> |
1414 | <string lang="en" key="RESCUE_DISK_EFI_NON_WIZARD_CHECK_FAILED">Cannot verify that the Rescue Disk has been correctly extracted.\n\nIf you have extracted the Rescue Disk image to a USB stick, please eject it and reinsert it; then try again. If this does not help, please try other ZIP software and/or medium.\n\nIf you attempted to verify a VeraCrypt Rescue Disk created for a different master key, password, salt, etc., please note that such Rescue Disk will always fail this verification. To create a new Rescue Disk fully compatible with your current configuration, select 'System' > 'Create Rescue Disk'.</string> | 1414 | <string lang="en" key="RESCUE_DISK_EFI_NON_WIZARD_CHECK_FAILED">Cannot verify that the Rescue Disk has been correctly extracted.\n\nIf you have extracted the Rescue Disk image to a USB stick, please eject it and reinsert it; then try again. If this does not help, please try other ZIP software and/or medium.\n\nIf you attempted to verify a VeraCrypt Rescue Disk created for a different master key, password, salt, etc., please note that such Rescue Disk will always fail this verification. To create a new Rescue Disk fully compatible with your current configuration, select 'System' > 'Create Rescue Disk'.</string> |
1415 | <string lang="en" key="RESCUE_DISK_EFI_NON_WIZARD_CREATION">The Rescue Disk image has been created and stored in this file:\n%s\n\nNow you need to extract the Rescue Disk image to a USB stick that is formatted as FAT/FAT32.\n\nIMPORTANT: Note that the zip file must be extracted directly to the root of the USB stick. For example, if the drive letter of the USB stick is E: then extracting the zip file should create a folder E:\\EFI on the USB stick.\n\nAfter you create the Rescue Disk, select 'System' > 'Verify Rescue Disk' to verify that it has been correctly created.</string> | 1415 | <string lang="en" key="RESCUE_DISK_EFI_NON_WIZARD_CREATION">The Rescue Disk image has been created and stored in this file:\n%s\n\nNow you need to extract the Rescue Disk image to a USB stick that is formatted as FAT/FAT32.\n\nIMPORTANT: Note that the zip file must be extracted directly to the root of the USB stick. For example, if the drive letter of the USB stick is E: then extracting the zip file should create a folder E:\\EFI on the USB stick.\n\nAfter you create the Rescue Disk, select 'System' > 'Verify Rescue Disk' to verify that it has been correctly created.</string> |
1416 | <control lang="en" key="IDC_SECURE_DESKTOP_PASSWORD_ENTRY">Use Secure Desktop for password entry</control> | ||
1416 | </localization> | 1417 | </localization> |
1417 | <!-- XML Schema --> | 1418 | <!-- XML Schema --> |
1418 | <xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema"> | 1419 | <xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema"> |