VeraCrypt
aboutsummaryrefslogtreecommitdiff
path: root/src/Mount/Mount.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/Mount/Mount.c')
-rw-r--r--src/Mount/Mount.c159
1 files changed, 142 insertions, 17 deletions
diff --git a/src/Mount/Mount.c b/src/Mount/Mount.c
index c7835f0e..427c1a93 100644
--- a/src/Mount/Mount.c
+++ b/src/Mount/Mount.c
@@ -121,14 +121,16 @@ int nSelectedDriveIndex = -1; /* Item number of selected drive */
int cmdUnmountDrive = 0; /* Volume drive letter to unmount (-1 = all) */
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;
MountOptions mountOptions;
MountOptions defaultMountOptions;
KeyFile *FirstCmdKeyFile;
@@ -548,12 +550,21 @@ void LoadSettings (HWND hwndDlg)
if (bHistoryCmdLine != TRUE)
{
LoadCombo (GetDlgItem (hwndDlg, IDC_VOLUME));
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)
{
WaitCursor ();
@@ -631,12 +642,16 @@ void SaveSettings (HWND hwndDlg)
if (GetPreferredLangId () != NULL)
ConfigWriteString ("Language", GetPreferredLangId ());
// PKCS#11 Library Path
ConfigWriteString ("SecurityTokenLibrary", SecurityTokenLibraryPath[0] ? SecurityTokenLibraryPath : "");
+ // Mount Options
+ ConfigWriteInt ("DefaultPRF", DefaultVolumePkcs5);
+ ConfigWriteInt ("DefaultTrueCryptMode", DefaultVolumeTrueCryptMode);
+
ConfigWriteEnd (hwndDlg);
// History
DumpCombo (GetDlgItem (hwndDlg, IDC_VOLUME), IsButtonChecked (GetDlgItem (hwndDlg, IDC_NO_HISTORY)));
NormalCursor ();
@@ -2663,12 +2678,13 @@ BOOL CALLBACK PreferencesDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM
AppendMenuW (popup, MF_STRING, IDM_LANGUAGE, GetString ("IDM_LANGUAGE"));
AppendMenuW (popup, MF_STRING, IDM_HOTKEY_SETTINGS, GetString ("IDM_HOTKEY_SETTINGS"));
AppendMenuW (popup, MF_STRING, IDM_PERFORMANCE_SETTINGS, GetString ("IDM_PERFORMANCE_SETTINGS"));
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;
GetWindowRect (GetDlgItem (hwndDlg, IDC_MORE_SETTINGS), &rect);
int menuItem = TrackPopupMenu (popup, TPM_RETURNCMD | TPM_LEFTBUTTON, rect.left + 2, rect.top + 2, 0, hwndDlg, NULL);
@@ -3699,13 +3715,22 @@ static int AskVolumePassword (HWND hwndDlg, Password *password, int *pkcs5, BOOL
// GUI actions
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;
if (nDosDriveNo == 0)
nDosDriveNo = HIWORD (GetSelectedLong (GetDlgItem (hwndDlg, IDC_DRIVELIST))) - 'A';
@@ -3746,26 +3771,26 @@ static BOOL Mount (HWND hwndDlg, int nDosDriveNo, char *szFileName)
ResetWrongPwdRetryCount ();
// 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)
{
Password emptyPassword;
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));
}
// Test password and/or keyfiles used for the previous volume
@@ -3784,19 +3809,19 @@ static BOOL Mount (HWND hwndDlg, int nDosDriveNo, char *szFileName)
while (mounted == 0)
{
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))
goto ret;
else
{
@@ -4059,12 +4084,22 @@ static BOOL MountAllDevices (HWND hwndDlg, BOOL bPasswordPrompt)
{
HWND driveList = GetDlgItem (hwndDlg, IDC_DRIVELIST);
int selDrive = ListView_GetSelectionMark (driveList);
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;
bPrebootPasswordDlgMode = FALSE;
if (selDrive == -1)
@@ -4077,14 +4112,14 @@ static BOOL MountAllDevices (HWND hwndDlg, BOOL bPasswordPrompt)
do
{
if (!bHeaderBakRetry)
{
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;
else
{
VolumePkcs5 = GuiPkcs5;
@@ -4094,14 +4129,14 @@ static BOOL MountAllDevices (HWND hwndDlg, BOOL bPasswordPrompt)
}
}
else if (CmdVolumePasswordValid)
{
bPasswordPrompt = FALSE;
VolumePassword = CmdVolumePassword;
- VolumePkcs5 = CmdVolumePkcs5;
- VolumeTrueCryptMode = CmdVolumeTrueCryptMode;
+ VolumePkcs5 = EffectiveVolumePkcs5;
+ VolumeTrueCryptMode = EffectiveVolumeTrueCryptMode;
}
WaitCursor();
if (FirstCmdKeyFile)
KeyFilesApply (hwndDlg, &VolumePassword, FirstCmdKeyFile);
@@ -5129,26 +5164,36 @@ BOOL CALLBACK MainDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa
exitCode = 1;
}
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))
{
BOOL reportBadPasswd = CmdVolumePassword.Length > 0;
if (FirstCmdKeyFile)
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));
}
if (FirstCmdKeyFile)
@@ -5157,14 +5202,14 @@ BOOL CALLBACK MainDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa
KeyFilesEnable = TRUE;
}
// 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);
if (!AskVolumePassword (hwndDlg, &VolumePassword, &GuiPkcs5, &GuiTrueCryptMode, NULL, TRUE))
break;
else
@@ -6624,12 +6669,18 @@ BOOL CALLBACK MainDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa
if (lw == IDM_DEFAULT_KEYFILES)
{
KeyfileDefaultsDlg (hwndDlg);
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));
char volPathLower[TC_MAX_PATH];
wchar_t volPathLowerW[TC_MAX_PATH];
@@ -8942,12 +8993,86 @@ static BOOL CALLBACK SecurityTokenPreferencesDlgProc (HWND hwndDlg, UINT msg, WP
return 0;
}
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)
{
DialogBoxParamW (hInst, MAKEINTRESOURCEW (IDD_TOKEN_PREFERENCES), hwndDlg, (DLGPROC) SecurityTokenPreferencesDlgProc, 0);
}