VeraCrypt
aboutsummaryrefslogtreecommitdiff
path: root/src/Mount/Favorites.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/Mount/Favorites.cpp')
-rw-r--r--src/Mount/Favorites.cpp212
1 files changed, 109 insertions, 103 deletions
diff --git a/src/Mount/Favorites.cpp b/src/Mount/Favorites.cpp
index ee34272f..c829128f 100644
--- a/src/Mount/Favorites.cpp
+++ b/src/Mount/Favorites.cpp
@@ -3,9 +3,9 @@
Copyright (c) 2008-2012 TrueCrypt Developers Association and which is governed
by the TrueCrypt License 3.0.
Modifications and additions to the original source code (contained in this file)
- and all other portions of this file are Copyright (c) 2013-2016 IDRIX
+ and all other portions of this file are Copyright (c) 2013-2017 IDRIX
and are governed by the Apache License 2.0 the full text of which is
contained in the file License.txt included in VeraCrypt binary and source
code distribution packages.
*/
@@ -99,9 +99,8 @@ namespace VeraCrypt
favorite.SystemEncryption = prop.partitionInInactiveSysEncScope ? true : false;
favorite.OpenExplorerWindow = (bExplore == TRUE);
favorite.Pim = prop.volumePim;
favorite.Pkcs5 = prop.pkcs5;
- favorite.TrueCryptMode = (prop.pkcs5Iterations == get_pkcs5_iteration_count(prop.pkcs5, 0, TRUE, prop.partitionInInactiveSysEncScope))? 1 : 0;
memcpy (favorite.VolumeID, prop.volumeID, VOLUME_ID_SIZE);
if (favorite.VolumePathId.empty()
&& IsVolumeDeviceHosted (favorite.Path.c_str())
@@ -242,78 +241,93 @@ namespace VeraCrypt
switch (lw)
{
case IDOK:
-
- /* Global System Favorites settings */
-
- if (SystemFavoritesMode)
{
- BootEncryption BootEncObj (NULL);
+ BOOL bInitialOptionValue = NeedPeriodicDeviceListUpdate;
+
+ /* Global System Favorites settings */
- if (BootEncObj.GetStatus().DriveMounted)
+ if (SystemFavoritesMode)
{
- try
- {
- uint32 reqConfig = IsDlgButtonChecked (hwndDlg, IDC_FAVORITE_OPEN_EXPLORER_WIN_ON_MOUNT) ? TC_DRIVER_CONFIG_CACHE_BOOT_PASSWORD_FOR_SYS_FAVORITES : 0;
- if (reqConfig != (ReadDriverConfigurationFlags() & TC_DRIVER_CONFIG_CACHE_BOOT_PASSWORD_FOR_SYS_FAVORITES))
- BootEncObj.RegisterSystemFavoritesService (reqConfig ? TRUE : FALSE);
+ BootEncryption BootEncObj (NULL);
- SetDriverConfigurationFlag (TC_DRIVER_CONFIG_DISABLE_NONADMIN_SYS_FAVORITES_ACCESS, IsDlgButtonChecked (hwndDlg, IDC_FAVORITE_DISABLE_HOTKEY));
- }
- catch (Exception &e)
+ if (BootEncObj.GetStatus().DriveMounted)
{
- e.Show (hwndDlg);
+ try
+ {
+ uint32 reqConfig = IsDlgButtonChecked (hwndDlg, IDC_FAVORITE_OPEN_EXPLORER_WIN_ON_MOUNT) ? TC_DRIVER_CONFIG_CACHE_BOOT_PASSWORD_FOR_SYS_FAVORITES : 0;
+ if (reqConfig != (ReadDriverConfigurationFlags() & TC_DRIVER_CONFIG_CACHE_BOOT_PASSWORD_FOR_SYS_FAVORITES))
+ BootEncObj.SetDriverConfigurationFlag (TC_DRIVER_CONFIG_CACHE_BOOT_PASSWORD_FOR_SYS_FAVORITES, reqConfig ? true : false);
+
+ if (!BootEncObj.IsSystemFavoritesServiceRunning())
+ {
+ // The system favorites service should be always running
+ // If it is stopped for some reason, we reconfigure it
+ BootEncObj.RegisterSystemFavoritesService (TRUE);
+ }
+
+ SetDriverConfigurationFlag (TC_DRIVER_CONFIG_DISABLE_NONADMIN_SYS_FAVORITES_ACCESS, IsDlgButtonChecked (hwndDlg, IDC_FAVORITE_DISABLE_HOTKEY));
+ }
+ catch (Exception &e)
+ {
+ e.Show (hwndDlg);
+ }
}
}
- }
- /* (System) Favorites list */
+ /* (System) Favorites list */
- if (SelectedItem != -1 && !Favorites.empty())
- SetFavoriteVolume (hwndDlg, Favorites[SelectedItem], SystemFavoritesMode);
+ if (SelectedItem != -1 && !Favorites.empty())
+ SetFavoriteVolume (hwndDlg, Favorites[SelectedItem], SystemFavoritesMode);
- if (SaveFavoriteVolumes (hwndDlg, Favorites, SystemFavoritesMode))
- {
- if (!SystemFavoritesMode)
+ if (SaveFavoriteVolumes (hwndDlg, Favorites, SystemFavoritesMode))
{
- bMountFavoritesOnLogon = FALSE;
-
- foreach (const FavoriteVolume &favorite, Favorites)
+ if (!SystemFavoritesMode)
{
- if (favorite.MountOnLogOn)
+ bMountFavoritesOnLogon = FALSE;
+
+ foreach (const FavoriteVolume &favorite, Favorites)
{
- bMountFavoritesOnLogon = TRUE;
- break;
+ if (favorite.MountOnLogOn)
+ {
+ bMountFavoritesOnLogon = TRUE;
+ break;
+ }
}
- }
- if (!bEnableBkgTask || bCloseBkgTaskWhenNoVolumes || IsNonInstallMode())
- {
- foreach (const FavoriteVolume favorite, Favorites)
+ if (!bEnableBkgTask || bCloseBkgTaskWhenNoVolumes || IsNonInstallMode())
{
- if (favorite.MountOnArrival)
+ foreach (const FavoriteVolume favorite, Favorites)
{
- Warning ("FAVORITE_ARRIVAL_MOUNT_BACKGROUND_TASK_ERR", hwndDlg);
- break;
+ if (favorite.MountOnArrival)
+ {
+ Warning ("FAVORITE_ARRIVAL_MOUNT_BACKGROUND_TASK_ERR", hwndDlg);
+ break;
+ }
}
}
- }
- FavoriteVolumes = Favorites;
+ if (!bInitialOptionValue && NeedPeriodicDeviceListUpdate)
+ {
+ // a favorite was set to use VolumeID. We update the list of devices available for mounting as early as possible
+ UpdateMountableHostDeviceList ();
+ }
+
+ FavoriteVolumes = Favorites;
- ManageStartupSeq();
- SaveSettings (hwndDlg);
- }
- else
- SystemFavoriteVolumes = Favorites;
+ ManageStartupSeq();
+ SaveSettings (hwndDlg);
+ }
+ else
+ SystemFavoriteVolumes = Favorites;
- OnFavoriteVolumesUpdated();
- LoadDriveLetters (hwndDlg, GetDlgItem (MainDlg, IDC_DRIVELIST), 0);
+ OnFavoriteVolumesUpdated();
+ LoadDriveLetters (hwndDlg, GetDlgItem (MainDlg, IDC_DRIVELIST), 0);
- EndDialog (hwndDlg, IDOK);
+ EndDialog (hwndDlg, IDOK);
+ }
}
-
return 1;
case IDCANCEL:
EndDialog (hwndDlg, IDCLOSE);
@@ -381,18 +395,18 @@ namespace VeraCrypt
}
return 1;
case IDC_FAVORITES_HELP_LINK:
- Applink (SystemFavoritesMode ? "sysfavorites" : "favorites", TRUE, "");
+ Applink (SystemFavoritesMode ? "sysfavorites" : "favorites");
return 1;
case IDC_SHOW_PIM:
HandleShowPasswordFieldAction (hwndDlg, IDC_SHOW_PIM, IDC_PIM, 0);
return 1;
case IDC_PIM:
if (hw == EN_CHANGE)
{
- int pim = GetPim (hwndDlg, IDC_PIM);
+ int pim = GetPim (hwndDlg, IDC_PIM, -1);
if (pim > (SystemFavoritesMode? MAX_BOOT_PIM_VALUE: MAX_PIM_VALUE))
{
SetDlgItemText (hwndDlg, IDC_PIM, L"");
SetFocus (GetDlgItem(hwndDlg, IDC_PIM));
@@ -437,15 +451,15 @@ namespace VeraCrypt
return 1;
case WM_CTLCOLORSTATIC:
{
HDC hdc = (HDC) wParam;
- HWND hw = (HWND) lParam;
- if (hw == GetDlgItem(hwndDlg, IDC_FAVORITE_VOLUME_ID))
+ HWND hwnd = (HWND) lParam;
+ if (hwnd == GetDlgItem(hwndDlg, IDC_FAVORITE_VOLUME_ID))
{
// This the favorite ID field. Make its background like normal edit
HBRUSH hbr = GetSysColorBrush (COLOR_WINDOW);
::SelectObject(hdc, hbr);
- return (BOOL) hbr;
+ return (BOOL)(INT_PTR)hbr;
}
}
break;
}
@@ -553,8 +567,9 @@ namespace VeraCrypt
void LoadFavoriteVolumes (vector <FavoriteVolume> &favorites, bool systemFavorites, bool noUacElevation)
{
+ bool bVolumeIdInUse = false;
favorites.clear();
wstring favoritesFilePath = systemFavorites ? GetServiceConfigPath (TC_APPD_FILENAME_SYSTEM_FAVORITE_VOLUMES, false) : GetConfigPath (TC_APPD_FILENAME_FAVORITE_VOLUMES);
if (systemFavorites && !IsAdmin() && !noUacElevation)
@@ -601,9 +616,9 @@ namespace VeraCrypt
XmlGetAttributeText (xml, "ID", label, sizeof (label));
if (strlen (label) == (2*VOLUME_ID_SIZE))
{
- std::vector<byte> arr;
+ std::vector<uint8> arr;
if (HexWideStringToArray (Utf8StringToWide (label).c_str(), arr) && arr.size() == VOLUME_ID_SIZE)
{
memcpy (favorite.VolumeID, &arr[0], VOLUME_ID_SIZE);
}
@@ -617,11 +632,16 @@ namespace VeraCrypt
{
/* support old attribute name before it was changed to PIM*/
XmlGetAttributeText (xml, "pin", label, sizeof (label));
}
- favorite.Pim = strtol (label, NULL, 10);
- if (favorite.Pim < 0 || favorite.Pim > (systemFavorites? MAX_BOOT_PIM_VALUE : MAX_PIM_VALUE))
- favorite.Pim = 0;
+ if (label[0])
+ {
+ favorite.Pim = strtol (label, NULL, 10);
+ if (favorite.Pim < 0 || favorite.Pim > (systemFavorites? MAX_BOOT_PIM_VALUE : MAX_PIM_VALUE))
+ favorite.Pim = -1;
+ }
+ else
+ favorite.Pim = -1;
char boolVal[2];
XmlGetAttributeText (xml, "readonly", boolVal, sizeof (boolVal));
if (boolVal[0])
@@ -671,36 +691,37 @@ namespace VeraCrypt
else
favorite.DisconnectedDevice = true;
}
- XmlGetAttributeText (xml, "TrueCryptMode", boolVal, sizeof (boolVal));
- if (boolVal[0])
- favorite.TrueCryptMode = (boolVal[0] == '1')? 1 : 0;
- else
- favorite.TrueCryptMode = -1;
-
- if (favorite.TrueCryptMode)
- favorite.Pim = 0;
-
XmlGetAttributeText (xml, "pkcs5", label, sizeof (label));
if (label[0])
favorite.Pkcs5 = strtol (label, NULL, 10);
else
favorite.Pkcs5 = -1;
if ( (favorite.Pkcs5 != -1)
&& ( (favorite.Pkcs5 < FIRST_PRF_ID)
|| (favorite.Pkcs5 > LAST_PRF_ID)
- || (favorite.TrueCryptMode == 1 && (0 == get_pkcs5_iteration_count (favorite.Pkcs5, 0, TRUE, favorite.SystemEncryption? TRUE : FALSE)))
)
)
{
favorite.Pkcs5 = -1;
}
+ if (!systemFavorites && favorite.UseVolumeID)
+ bVolumeIdInUse = true;
+
favorites.push_back (favorite);
xml++;
}
+ if (!systemFavorites)
+ {
+ if (bVolumeIdInUse && !DisablePeriodicDeviceListUpdate)
+ NeedPeriodicDeviceListUpdate = TRUE;
+ else
+ NeedPeriodicDeviceListUpdate = FALSE;
+ }
+
free (favoritesXml);
}
@@ -709,9 +730,9 @@ namespace VeraCrypt
FillFavoriteVolumesMenu();
FavoritesOnArrivalMountRequired.clear();
- foreach (const FavoriteVolume favorite, FavoriteVolumes)
+ for (const FavoriteVolume favorite: FavoriteVolumes)
{
if (favorite.MountOnArrival)
{
FavoritesOnArrivalMountRequired.push_back (favorite);
@@ -719,9 +740,9 @@ namespace VeraCrypt
if (IsMountedVolume (favorite.Path.c_str()))
{
bool present = false;
- foreach (const FavoriteVolume favoriteConnected, FavoritesMountedOnArrivalStillConnected)
+ for (const FavoriteVolume favoriteConnected: FavoritesMountedOnArrivalStillConnected)
{
if (favorite.Path == favoriteConnected.Path)
{
present = true;
@@ -757,8 +778,9 @@ namespace VeraCrypt
bool SaveFavoriteVolumes (HWND hwndDlg, const vector <FavoriteVolume> &favorites, bool systemFavorites)
{
FILE *f;
int cnt = 0;
+ bool bVolumeIdInUse = false;
f = _wfopen (GetConfigPath (systemFavorites ? TC_APPD_FILENAME_SYSTEM_FAVORITE_VOLUMES : TC_APPD_FILENAME_FAVORITE_VOLUMES), L"w,ccs=UTF-8");
if (f == NULL)
{
@@ -785,19 +807,14 @@ namespace VeraCrypt
if (!favorite.Label.empty())
s += L" label=\"" + favorite.Label + L"\"";
- if (favorite.Pim > 0)
+ if (favorite.Pim >= 0)
s += L" pim=\"" + IntToWideString(favorite.Pim) + L"\"";
if (favorite.Pkcs5 > 0)
s += L" pkcs5=\"" + IntToWideString(favorite.Pkcs5) + L"\"";
- if (favorite.TrueCryptMode > 0)
- s += L" TrueCryptMode=\"1\"";
- else if (favorite.TrueCryptMode == 0)
- s += L" TrueCryptMode=\"0\"";
-
if (favorite.ReadOnly)
s += L" readonly=\"1\"";
if (favorite.Removable)
@@ -821,9 +838,13 @@ namespace VeraCrypt
if (favorite.UseLabelInExplorer && !favorite.ReadOnly)
s += L" useLabelInExplorer=\"1\"";
if (favorite.UseVolumeID && !IsRepeatedByteArray (0, favorite.VolumeID, sizeof (favorite.VolumeID)))
+ {
s += L" useVolumeID=\"1\"";
+ if (!systemFavorites)
+ bVolumeIdInUse = true;
+ }
s += L">" + wstring (tq) + L"</volume>";
fwprintf (f, L"%ws", s.c_str());
@@ -832,8 +853,16 @@ namespace VeraCrypt
fputws (L"\n\t</favorites>", f);
XmlWriteFooter (f);
+ if (!systemFavorites)
+ {
+ if (bVolumeIdInUse && !DisablePeriodicDeviceListUpdate)
+ NeedPeriodicDeviceListUpdate = TRUE;
+ else
+ NeedPeriodicDeviceListUpdate = FALSE;
+ }
+
if (!CheckFileStreamWriteErrors (hwndDlg, f, systemFavorites ? TC_APPD_FILENAME_SYSTEM_FAVORITE_VOLUMES : TC_APPD_FILENAME_FAVORITE_VOLUMES))
{
fclose (f);
return false;
@@ -905,9 +934,8 @@ namespace VeraCrypt
SetCheckBox (hwndDlg, IDC_FAVORITE_MOUNT_ON_ARRIVAL, favorite.MountOnArrival);
SetCheckBox (hwndDlg, IDC_FAVORITE_MOUNT_READONLY, favorite.ReadOnly);
SetCheckBox (hwndDlg, IDC_FAVORITE_MOUNT_REMOVABLE, favorite.Removable);
SetCheckBox (hwndDlg, IDC_FAVORITE_USE_VOLUME_ID, favorite.UseVolumeID && bIsDevice);
- SetCheckBox (hwndDlg, IDC_TRUECRYPT_MODE, (favorite.TrueCryptMode > 0)? TRUE : FALSE);
/* Populate the PRF algorithms list */
int nIndex, i, nSelected = 0;
HWND hComboBox = GetDlgItem (hwndDlg, IDC_PKCS5_PRF_ID);
@@ -917,15 +945,12 @@ namespace VeraCrypt
SendMessage (hComboBox, CB_SETITEMDATA, nIndex, (LPARAM) 0);
for (i = FIRST_PRF_ID; i <= LAST_PRF_ID; i++)
{
- if (!favorite.SystemEncryption || (favorite.TrueCryptMode != 1) || (i == RIPEMD160))
- {
- nIndex = (int) SendMessage (hComboBox, CB_ADDSTRING, 0, (LPARAM) get_pkcs5_prf_name(i));
- SendMessage (hComboBox, CB_SETITEMDATA, nIndex, (LPARAM) i);
- if (favorite.Pkcs5 == i)
- nSelected = nIndex;
- }
+ nIndex = (int) SendMessage (hComboBox, CB_ADDSTRING, 0, (LPARAM) get_pkcs5_prf_name(i));
+ SendMessage (hComboBox, CB_SETITEMDATA, nIndex, (LPARAM) i);
+ if (favorite.Pkcs5 == i)
+ nSelected = nIndex;
}
if (favorite.Pkcs5 >= 0)
SendMessage (hComboBox, CB_SETCURSEL, nSelected, 0);
@@ -957,9 +982,8 @@ namespace VeraCrypt
EnableWindow (GetDlgItem (hwndDlg, IDC_FAVORITE_MOVE_DOWN), enable);
EnableWindow (GetDlgItem (hwndDlg, IDC_FAVORITE_REMOVE), enable);
EnableWindow (GetDlgItem (hwndDlg, IDT_PKCS5_PRF), enable && !favorite.SystemEncryption);
EnableWindow (GetDlgItem (hwndDlg, IDC_PKCS5_PRF_ID), enable && !favorite.SystemEncryption);
- EnableWindow (GetDlgItem (hwndDlg, IDC_TRUECRYPT_MODE), enable && !favorite.SystemEncryption);
EnableWindow (GetDlgItem (hwndDlg, IDT_PIM), enable);
EnableWindow (GetDlgItem (hwndDlg, IDC_PIM), enable);
EnableWindow (GetDlgItem (hwndDlg, IDC_SHOW_PIM), enable);
EnableWindow (GetDlgItem (hwndDlg, IDC_PIM_HELP), enable);
@@ -1028,34 +1052,16 @@ namespace VeraCrypt
}
else
favorite.Label.clear();
- favorite.Pim = GetPim (hwndDlg, IDC_PIM);
+ favorite.Pim = GetPim (hwndDlg, IDC_PIM, -1);
favorite.UseLabelInExplorer = (IsDlgButtonChecked (hwndDlg, IDC_FAVORITE_USE_LABEL_IN_EXPLORER) != 0);
favorite.UseVolumeID = (IsDlgButtonChecked (hwndDlg, IDC_FAVORITE_USE_VOLUME_ID) != 0);
int nSelected = (int) SendMessage (GetDlgItem (hwndDlg, IDC_PKCS5_PRF_ID), CB_GETCURSEL, 0, 0);
if (nSelected != CB_ERR)
favorite.Pkcs5 = (int) SendMessage (GetDlgItem (hwndDlg, IDC_PKCS5_PRF_ID), CB_GETITEMDATA, nSelected, 0);
else
favorite.Pkcs5 = -1;
- BOOL selectedTrueCryptMode = (IsDlgButtonChecked (hwndDlg, IDC_TRUECRYPT_MODE) != 0)? 1 : 0;
- if ((favorite.TrueCryptMode >= 0) || selectedTrueCryptMode)
- favorite.TrueCryptMode = selectedTrueCryptMode;
-
- if (favorite.TrueCryptMode == 1)
- {
- if ((favorite.Pkcs5 > 0) && !is_pkcs5_prf_supported (favorite.Pkcs5, TRUE, favorite.SystemEncryption? PRF_BOOT_MBR : PRF_BOOT_NO))
- {
- Error ("ALGO_NOT_SUPPORTED_FOR_TRUECRYPT_MODE", hwndDlg);
- favorite.Pkcs5 = 0;
- }
-
- if (favorite.Pim > 0)
- {
- Error ("PIM_NOT_SUPPORTED_FOR_TRUECRYPT_MODE", hwndDlg);
- favorite.Pim = 0;
- }
- }
favorite.ReadOnly = (IsDlgButtonChecked (hwndDlg, IDC_FAVORITE_MOUNT_READONLY) != 0);
favorite.Removable = (IsDlgButtonChecked (hwndDlg, IDC_FAVORITE_MOUNT_REMOVABLE) != 0);