Windows: Add menu option to set default hash and default TrueCrypt mode used for mounting volumes (Menu Settings -> Default Mount Parameters)

This commit is contained in:
Mounir IDRASSI 2015-02-22 00:50:29 +01:00
parent cb9859fa0e
commit 7fb5af6ada
5 changed files with 171 additions and 19 deletions

View File

@ -172,6 +172,7 @@
<control lang="en" key="IDC_VOLUME_PROPERTIES">&amp;Volume Properties...</control>
<control lang="en" key="IDC_VOLUME_TOOLS">Volume &amp;Tools...</control>
<control lang="en" key="IDC_WIPE_CACHE">&amp;Wipe Cache</control>
<control lang="en" key="IDD_DEFAULT_MOUNT_PARAMETERS">VeraCrypt - Mount Parameters</control>
<control lang="en" key="IDD_FAVORITE_VOLUMES">VeraCrypt - Favorite Volumes</control>
<control lang="en" key="IDD_HOTKEYS_DLG">VeraCrypt - System-Wide Hot Keys</control>
<control lang="en" key="IDD_MOUNT_DLG">VeraCrypt</control>
@ -201,6 +202,7 @@
<control lang="en" key="IDM_CREATE_RESCUE_DISK">Create Rescue Disk...</control>
<control lang="en" key="IDM_CREATE_VOLUME">Create New Volume...</control>
<control lang="en" key="IDM_DEFAULT_KEYFILES">Default Keyfiles...</control>
<control lang="en" key="IDM_DEFAULT_MOUNT_PARAMETERS">Default Mount Parameters...</control>
<control lang="en" key="IDM_DONATE">Donate now...</control>
<control lang="en" key="IDM_ENCRYPT_SYSTEM_DEVICE">Encrypt System Partition/Drive...</control>
<control lang="en" key="IDM_FAQ">Frequently Asked Questions</control>

View File

@ -124,8 +124,10 @@ Password VolumePassword; /* Password used for mounting volumes */
Password CmdVolumePassword; /* Password passed from command line */
int VolumePkcs5 = 0;
int CmdVolumePkcs5 = 0;
int DefaultVolumePkcs5 = 0;
BOOL VolumeTrueCryptMode = FALSE;
BOOL CmdVolumeTrueCryptMode = FALSE;
BOOL DefaultVolumeTrueCryptMode = FALSE;
BOOL CmdVolumePasswordValid = FALSE;
MountOptions CmdMountOptions;
BOOL CmdMountOptionsValid = FALSE;
@ -551,6 +553,15 @@ void LoadSettings (HWND hwndDlg)
if (CmdLineVolumeSpecified)
SetWindowText (GetDlgItem (hwndDlg, IDC_VOLUME), szFileName);
}
// Mount Options
DefaultVolumePkcs5 = ConfigReadInt ("DefaultPRF", 0);
DefaultVolumeTrueCryptMode = ConfigReadInt ("DefaultTrueCryptMode", FALSE);
if (DefaultVolumePkcs5 < 0 || DefaultVolumePkcs5 > LAST_PRF_ID)
DefaultVolumePkcs5 = 0;
if (DefaultVolumeTrueCryptMode != TRUE && DefaultVolumeTrueCryptMode != FALSE)
DefaultVolumeTrueCryptMode = FALSE;
}
void SaveSettings (HWND hwndDlg)
@ -634,6 +645,10 @@ void SaveSettings (HWND hwndDlg)
// PKCS#11 Library Path
ConfigWriteString ("SecurityTokenLibrary", SecurityTokenLibraryPath[0] ? SecurityTokenLibraryPath : "");
// Mount Options
ConfigWriteInt ("DefaultPRF", DefaultVolumePkcs5);
ConfigWriteInt ("DefaultTrueCryptMode", DefaultVolumeTrueCryptMode);
ConfigWriteEnd (hwndDlg);
// History
@ -2666,6 +2681,7 @@ BOOL CALLBACK PreferencesDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM
AppendMenuW (popup, MF_STRING, IDM_SYSENC_SETTINGS, GetString ("IDM_SYSENC_SETTINGS"));
AppendMenuW (popup, MF_STRING, IDM_SYS_FAVORITES_SETTINGS, GetString ("IDM_SYS_FAVORITES_SETTINGS"));
AppendMenuW (popup, MF_STRING, IDM_DEFAULT_KEYFILES, GetString ("IDM_DEFAULT_KEYFILES"));
AppendMenuW (popup, MF_STRING, IDM_DEFAULT_MOUNT_PARAMETERS, GetString ("IDM_DEFAULT_MOUNT_PARAMETERS"));
AppendMenuW (popup, MF_STRING, IDM_TOKEN_PREFERENCES, GetString ("IDM_TOKEN_PREFERENCES"));
RECT rect;
@ -3702,7 +3718,16 @@ static BOOL Mount (HWND hwndDlg, int nDosDriveNo, char *szFileName)
{
BOOL status = FALSE;
char fileName[MAX_PATH];
int mounted = 0;
int mounted = 0, EffectiveVolumePkcs5 = CmdVolumePkcs5;
BOOL EffectiveVolumeTrueCryptMode = CmdVolumeTrueCryptMode;
/* Priority is given to command line parameters
* Default values used only when nothing specified in command line
*/
if (EffectiveVolumePkcs5 == 0)
EffectiveVolumePkcs5 = DefaultVolumePkcs5;
if (!EffectiveVolumeTrueCryptMode)
EffectiveVolumeTrueCryptMode = DefaultVolumeTrueCryptMode;
bPrebootPasswordDlgMode = mountOptions.PartitionInInactiveSysEncScope;
@ -3749,7 +3774,7 @@ static BOOL Mount (HWND hwndDlg, int nDosDriveNo, char *szFileName)
// First try cached passwords and if they fail ask user for a new one
WaitCursor ();
mounted = MountVolume (hwndDlg, nDosDriveNo, szFileName, NULL, CmdVolumePkcs5, CmdVolumeTrueCryptMode, bCacheInDriver, bForceMount, &mountOptions, Silent, FALSE);
mounted = MountVolume (hwndDlg, nDosDriveNo, szFileName, NULL, EffectiveVolumePkcs5, EffectiveVolumeTrueCryptMode, bCacheInDriver, bForceMount, &mountOptions, Silent, FALSE);
// If keyfiles are enabled, test empty password first
if (!mounted && KeyFilesEnable && FirstKeyFile)
@ -3758,11 +3783,11 @@ static BOOL Mount (HWND hwndDlg, int nDosDriveNo, char *szFileName)
emptyPassword.Length = 0;
KeyFilesApply (hwndDlg, &emptyPassword, FirstKeyFile);
mounted = MountVolume (hwndDlg, nDosDriveNo, szFileName, &emptyPassword, CmdVolumePkcs5, CmdVolumeTrueCryptMode, bCacheInDriver, bForceMount, &mountOptions, Silent, FALSE);
mounted = MountVolume (hwndDlg, nDosDriveNo, szFileName, &emptyPassword, EffectiveVolumePkcs5, EffectiveVolumeTrueCryptMode, bCacheInDriver, bForceMount, &mountOptions, Silent, FALSE);
if (mounted)
{
VolumePkcs5 = CmdVolumePkcs5;
VolumeTrueCryptMode = CmdVolumeTrueCryptMode;
VolumePkcs5 = EffectiveVolumePkcs5;
VolumeTrueCryptMode = EffectiveVolumeTrueCryptMode;
}
burn (&emptyPassword, sizeof (emptyPassword));
@ -3787,13 +3812,13 @@ static BOOL Mount (HWND hwndDlg, int nDosDriveNo, char *szFileName)
if (CmdVolumePassword.Length > 0)
{
VolumePassword = CmdVolumePassword;
VolumePkcs5 = CmdVolumePkcs5;
VolumeTrueCryptMode = CmdVolumeTrueCryptMode;
VolumePkcs5 = EffectiveVolumePkcs5;
VolumeTrueCryptMode = EffectiveVolumeTrueCryptMode;
}
else if (!Silent)
{
int GuiPkcs5 = CmdVolumePkcs5;
BOOL GuiTrueCryptMode = CmdVolumeTrueCryptMode;
int GuiPkcs5 = EffectiveVolumePkcs5;
BOOL GuiTrueCryptMode = EffectiveVolumeTrueCryptMode;
StringCbCopyA (PasswordDlgVolume, sizeof(PasswordDlgVolume), szFileName);
if (!AskVolumePassword (hwndDlg, &VolumePassword, &GuiPkcs5, &GuiTrueCryptMode, NULL, TRUE))
@ -4062,6 +4087,16 @@ static BOOL MountAllDevices (HWND hwndDlg, BOOL bPasswordPrompt)
BOOL shared = FALSE, status = FALSE, bHeaderBakRetry = FALSE;
int mountedVolCount = 0;
vector <HostDevice> devices;
int EffectiveVolumePkcs5 = CmdVolumePkcs5;
BOOL EffectiveVolumeTrueCryptMode = CmdVolumeTrueCryptMode;
/* Priority is given to command line parameters
* Default values used only when nothing specified in command line
*/
if (EffectiveVolumePkcs5 == 0)
EffectiveVolumePkcs5 = DefaultVolumePkcs5;
if (!EffectiveVolumeTrueCryptMode)
EffectiveVolumeTrueCryptMode = DefaultVolumeTrueCryptMode;
VolumePassword.Length = 0;
mountOptions = defaultMountOptions;
@ -4080,8 +4115,8 @@ static BOOL MountAllDevices (HWND hwndDlg, BOOL bPasswordPrompt)
{
if (!CmdVolumePasswordValid && bPasswordPrompt)
{
int GuiPkcs5 = CmdVolumePkcs5;
BOOL GuiTrueCryptMode = CmdVolumeTrueCryptMode;
int GuiPkcs5 = EffectiveVolumePkcs5;
BOOL GuiTrueCryptMode = EffectiveVolumeTrueCryptMode;
PasswordDlgVolume[0] = '\0';
if (!AskVolumePassword (hwndDlg, &VolumePassword, &GuiPkcs5, &GuiTrueCryptMode, NULL, TRUE))
goto ret;
@ -4097,8 +4132,8 @@ static BOOL MountAllDevices (HWND hwndDlg, BOOL bPasswordPrompt)
{
bPasswordPrompt = FALSE;
VolumePassword = CmdVolumePassword;
VolumePkcs5 = CmdVolumePkcs5;
VolumeTrueCryptMode = CmdVolumeTrueCryptMode;
VolumePkcs5 = EffectiveVolumePkcs5;
VolumeTrueCryptMode = EffectiveVolumeTrueCryptMode;
}
WaitCursor();
@ -5132,9 +5167,19 @@ BOOL CALLBACK MainDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa
if (szFileName[0] != 0 && !IsMountedVolume (szFileName))
{
BOOL mounted;
int EffectiveVolumePkcs5 = CmdVolumePkcs5;
BOOL EffectiveVolumeTrueCryptMode = CmdVolumeTrueCryptMode;
/* Priority is given to command line parameters
* Default values used only when nothing specified in command line
*/
if (EffectiveVolumePkcs5 == 0)
EffectiveVolumePkcs5 = DefaultVolumePkcs5;
if (!EffectiveVolumeTrueCryptMode)
EffectiveVolumeTrueCryptMode = DefaultVolumeTrueCryptMode;
// Cached password
mounted = MountVolume (hwndDlg, szDriveLetter[0] - 'A', szFileName, NULL, CmdVolumePkcs5, CmdVolumeTrueCryptMode, bCacheInDriver, bForceMount, &mountOptions, Silent, FALSE);
mounted = MountVolume (hwndDlg, szDriveLetter[0] - 'A', szFileName, NULL, EffectiveVolumePkcs5, EffectiveVolumeTrueCryptMode, bCacheInDriver, bForceMount, &mountOptions, Silent, FALSE);
// Command line password or keyfiles
if (!mounted && (CmdVolumePassword.Length != 0 || FirstCmdKeyFile))
@ -5145,7 +5190,7 @@ BOOL CALLBACK MainDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa
KeyFilesApply (hwndDlg, &CmdVolumePassword, FirstCmdKeyFile);
mounted = MountVolume (hwndDlg, szDriveLetter[0] - 'A',
szFileName, &CmdVolumePassword, CmdVolumePkcs5, CmdVolumeTrueCryptMode, bCacheInDriver, bForceMount,
szFileName, &CmdVolumePassword, EffectiveVolumePkcs5, EffectiveVolumeTrueCryptMode, bCacheInDriver, bForceMount,
&mountOptions, Silent, reportBadPasswd);
burn (&CmdVolumePassword, sizeof (CmdVolumePassword));
@ -5160,8 +5205,8 @@ BOOL CALLBACK MainDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa
// Ask user for password
while (!mounted && !Silent)
{
int GuiPkcs5 = CmdVolumePkcs5;
BOOL GuiTrueCryptMode = CmdVolumeTrueCryptMode;
int GuiPkcs5 = EffectiveVolumePkcs5;
BOOL GuiTrueCryptMode = EffectiveVolumeTrueCryptMode;
VolumePassword.Length = 0;
StringCbCopyA (PasswordDlgVolume, sizeof(PasswordDlgVolume),szFileName);
@ -6627,6 +6672,12 @@ BOOL CALLBACK MainDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa
return 1;
}
if (lw == IDM_DEFAULT_MOUNT_PARAMETERS)
{
DialogBoxParamW (hInst, MAKEINTRESOURCEW (IDD_DEFAULT_MOUNT_PARAMETERS), hwndDlg, (DLGPROC) DefaultMountParametersDlgProc, 0);
return 1;
}
if (lw == IDM_ADD_VOLUME_TO_FAVORITES || lw == IDM_ADD_VOLUME_TO_SYSTEM_FAVORITES)
{
LPARAM selectedDrive = GetSelectedLong (GetDlgItem (hwndDlg, IDC_DRIVELIST));
@ -8945,6 +8996,80 @@ static BOOL CALLBACK SecurityTokenPreferencesDlgProc (HWND hwndDlg, UINT msg, WP
return 0;
}
static BOOL CALLBACK DefaultMountParametersDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
WORD lw = LOWORD (wParam);
switch (msg)
{
case WM_INITDIALOG:
{
LocalizeDialog (hwndDlg, "IDD_DEFAULT_MOUNT_PARAMETERS");
SendMessage (GetDlgItem (hwndDlg, IDC_TRUECRYPT_MODE), BM_SETCHECK,
DefaultVolumeTrueCryptMode ? BST_CHECKED:BST_UNCHECKED, 0);
/* Populate the PRF algorithms list */
int i, nIndex, defaultPrfIndex = 0;
HWND hComboBox = GetDlgItem (hwndDlg, IDC_PKCS5_PRF_ID);
SendMessage (hComboBox, CB_RESETCONTENT, 0, 0);
nIndex = SendMessageW (hComboBox, CB_ADDSTRING, 0, (LPARAM) GetString ("AUTODETECTION"));
SendMessage (hComboBox, CB_SETITEMDATA, nIndex, (LPARAM) 0);
for (i = FIRST_PRF_ID; i <= LAST_PRF_ID; i++)
{
nIndex = SendMessage (hComboBox, CB_ADDSTRING, 0, (LPARAM) get_pkcs5_prf_name(i));
SendMessage (hComboBox, CB_SETITEMDATA, nIndex, (LPARAM) i);
if (DefaultVolumePkcs5 && (DefaultVolumePkcs5 == i))
defaultPrfIndex = nIndex;
}
/* make autodetection the default unless a specific PRF was specified in the command line */
SendMessage (hComboBox, CB_SETCURSEL, defaultPrfIndex, 0);
return 0;
}
case WM_COMMAND:
switch (lw)
{
case IDCANCEL:
EndDialog (hwndDlg, lw);
return 1;
case IDOK:
{
int pkcs5 = (int) SendMessage (GetDlgItem (hwndDlg, IDC_PKCS5_PRF_ID), CB_GETITEMDATA, SendMessage (GetDlgItem (hwndDlg, IDC_PKCS5_PRF_ID), CB_GETCURSEL, 0, 0), 0);
BOOL truecryptMode = GetCheckBox (hwndDlg, IDC_TRUECRYPT_MODE);
/* SHA-256 is not supported by TrueCrypt */
if ( (truecryptMode)
&& (pkcs5 == SHA256)
)
{
Error ("ALGO_NOT_SUPPORTED_FOR_TRUECRYPT_MODE", hwndDlg);
}
else
{
WaitCursor ();
DefaultVolumeTrueCryptMode = truecryptMode;
DefaultVolumePkcs5 = pkcs5;
SaveSettings (hwndDlg);
NormalCursor ();
EndDialog (hwndDlg, lw);
}
return 1;
}
}
return 0;
}
return 0;
}
void SecurityTokenPreferencesDialog (HWND hwndDlg)
{

View File

@ -110,6 +110,7 @@ uint32 ReadDriverConfigurationFlags ();
void AnalyzeKernelMiniDump (HWND hwndDlg);
void HookMouseWheel (HWND hwndDlg, UINT ctrlId);
static BOOL HandleDriveListMouseWheelEvent (UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL bListMustBePointed);
static BOOL CALLBACK DefaultMountParametersDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam);
#ifdef __cplusplus
}

View File

@ -331,6 +331,18 @@ BEGIN
GROUPBOX "Global Settings",IDC_FAV_VOL_OPTIONS_GLOBAL_SETTINGS_BOX,7,202,366,49
END
IDD_DEFAULT_MOUNT_PARAMETERS DIALOGEX 0, 0, 167, 65
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | DS_CENTER | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "VeraCrypt - Mount Parameters"
FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN
DEFPUSHBUTTON "OK",IDOK,57,44,50,14
PUSHBUTTON "Cancel",IDCANCEL,111,44,50,14
COMBOBOX IDC_PKCS5_PRF_ID,57,24,103,90,CBS_DROPDOWNLIST | WS_TABSTOP
LTEXT "PKCS-5 PRF:",IDT_PKCS5_PRF,8,26,44,11
CONTROL "TrueCrypt Mode",IDC_TRUECRYPT_MODE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,7,76,10
END
/////////////////////////////////////////////////////////////////////////////
//
@ -422,6 +434,14 @@ BEGIN
TOPMARGIN, 7
BOTTOMMARGIN, 269
END
IDD_DEFAULT_MOUNT_PARAMETERS, DIALOG
BEGIN
LEFTMARGIN, 7
RIGHTMARGIN, 160
TOPMARGIN, 7
BOTTOMMARGIN, 58
END
END
#endif // APSTUDIO_INVOKED
@ -594,6 +614,7 @@ BEGIN
MENUITEM "Performance...", IDM_PERFORMANCE_SETTINGS
MENUITEM SEPARATOR
MENUITEM "Default Keyfiles...", IDM_DEFAULT_KEYFILES
MENUITEM "Default Mount Parameters...", IDM_DEFAULT_MOUNT_PARAMETERS
MENUITEM "Security Tokens...", IDM_TOKEN_PREFERENCES
MENUITEM SEPARATOR
MENUITEM "Preferences...", IDM_PREFERENCES

View File

@ -20,6 +20,7 @@
#define IDD_TOKEN_PREFERENCES 115
#define IDD_SYSENC_SETTINGS 116
#define IDD_FAVORITE_VOLUMES 117
#define IDD_DEFAULT_MOUNT_PARAMETERS 118
#define IDC_PREF_MOUNT_READONLY 1000
#define IDC_PREF_MOUNT_REMOVABLE 1001
#define IDC_VERIFY 1002
@ -226,14 +227,16 @@
#define IDM_ANALYZE_SYSTEM_CRASH 40063
#define IDM_DONATE 40064
#define IDM_VOLUME_EXPANDER 40065
#define ID_SETTINGS_DEFAULTMOUNTOPTIONS 40066
#define IDM_DEFAULT_MOUNT_PARAMETERS 40067
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NO_MFC 1
#define _APS_NEXT_RESOURCE_VALUE 118
#define _APS_NEXT_COMMAND_VALUE 40066
#define _APS_NEXT_RESOURCE_VALUE 119
#define _APS_NEXT_COMMAND_VALUE 40068
#define _APS_NEXT_CONTROL_VALUE 1141
#define _APS_NEXT_SYMED_VALUE 101
#endif