VeraCrypt
aboutsummaryrefslogtreecommitdiff
path: root/src/Main
diff options
context:
space:
mode:
authorMounir IDRASSI <mounir.idrassi@idrix.fr>2023-09-02 01:37:52 +0200
committerMounir IDRASSI <mounir.idrassi@idrix.fr>2023-09-02 01:37:52 +0200
commit14fee0da1ab5a60f361bc3e1eb317cebab3c222b (patch)
treec8ec23407343fca3ca573f6671a1fde5f4c28b00 /src/Main
parent8e2329bf9e92a1f4e6fadb742e258be94f05d382 (diff)
downloadVeraCrypt-14fee0da1ab5a60f361bc3e1eb317cebab3c222b.tar.gz
VeraCrypt-14fee0da1ab5a60f361bc3e1eb317cebab3c222b.zip
Linux/macOS: preserve unknown entries in configuration file
This helps to preserve unknown entries that may be used by future versions of VeraCrypt (forward compatibility) or entries used by old versions that were removed from current version (backward compatibility)
Diffstat (limited to 'src/Main')
-rw-r--r--src/Main/UserPreferences.cpp34
-rw-r--r--src/Main/UserPreferences.h4
2 files changed, 28 insertions, 10 deletions
diff --git a/src/Main/UserPreferences.cpp b/src/Main/UserPreferences.cpp
index 9dbd35f6..b5a1f42c 100644
--- a/src/Main/UserPreferences.cpp
+++ b/src/Main/UserPreferences.cpp
@@ -58,6 +58,9 @@ namespace VeraCrypt
void UserPreferences::Load()
{
+ // first we clear the unknown config map entries
+ UnknownConfigMapEntries.clear();
+
// Preferences
FilePath cfgPath = Application::GetConfigFilePath (GetPreferencesFileName());
if (cfgPath.IsFile())
@@ -68,14 +71,14 @@ namespace VeraCrypt
configMap[node.Attributes[L"key"]] = node.InnerText;
}
-#define TC_CONFIG_SET(NAME) SetValue (configMap[L###NAME], NAME)
+#define TC_CONFIG_SET(NAME) if (configMap.count(L###NAME) > 0) { SetValue (configMap[L###NAME], NAME); configMap.erase (L###NAME); }
TC_CONFIG_SET (BackgroundTaskEnabled);
TC_CONFIG_SET (BackgroundTaskMenuDismountItemsEnabled);
TC_CONFIG_SET (BackgroundTaskMenuMountItemsEnabled);
TC_CONFIG_SET (BackgroundTaskMenuOpenItemsEnabled);
TC_CONFIG_SET (BeepAfterHotkeyMountDismount);
- SetValue (configMap[L"CachePasswords"], DefaultMountOptions.CachePassword);
+ if (configMap.count(L"CachePasswords") > 0) { SetValue (configMap[L"CachePasswords"], DefaultMountOptions.CachePassword); configMap.erase (L"CachePasswords"); }
TC_CONFIG_SET (CloseBackgroundTaskOnNoVolumes);
TC_CONFIG_SET (CloseExplorerWindowsOnDismount);
TC_CONFIG_SET (CloseSecurityTokenSessionsAfterMount);
@@ -87,7 +90,7 @@ namespace VeraCrypt
TC_CONFIG_SET (DismountOnScreenSaver);
TC_CONFIG_SET (DisplayMessageAfterHotkeyDismount);
TC_CONFIG_SET (BackgroundTaskEnabled);
- SetValue (configMap[L"FilesystemOptions"], DefaultMountOptions.FilesystemOptions);
+ if (configMap.count(L"FilesystemOptions") > 0) { SetValue (configMap[L"FilesystemOptions"], DefaultMountOptions.FilesystemOptions); configMap.erase (L"FilesystemOptions"); }
TC_CONFIG_SET (ForceAutoDismount);
TC_CONFIG_SET (LastSelectedSlotNumber);
TC_CONFIG_SET (MaxVolumeIdleTime);
@@ -95,24 +98,26 @@ namespace VeraCrypt
TC_CONFIG_SET (MountFavoritesOnLogon);
bool readOnly = false;
- SetValue (configMap[L"MountVolumesReadOnly"], readOnly);
+ if (configMap.count(L"MountVolumesReadOnly") > 0) { SetValue (configMap[L"MountVolumesReadOnly"], readOnly); configMap.erase (L"MountVolumesReadOnly"); }
DefaultMountOptions.Protection = readOnly ? VolumeProtection::ReadOnly : VolumeProtection::None;
- SetValue (configMap[L"MountVolumesRemovable"], DefaultMountOptions.Removable);
- SetValue (configMap[L"NoHardwareCrypto"], DefaultMountOptions.NoHardwareCrypto);
- SetValue (configMap[L"NoKernelCrypto"], DefaultMountOptions.NoKernelCrypto);
+ if (configMap.count(L"MountVolumesRemovable") > 0) { SetValue (configMap[L"MountVolumesRemovable"], DefaultMountOptions.Removable); configMap.erase (L"MountVolumesRemovable"); }
+ if (configMap.count(L"NoHardwareCrypto") > 0) { SetValue (configMap[L"NoHardwareCrypto"], DefaultMountOptions.NoHardwareCrypto); configMap.erase (L"NoHardwareCrypto"); }
+ if (configMap.count(L"NoKernelCrypto") > 0) { SetValue (configMap[L"NoKernelCrypto"], DefaultMountOptions.NoKernelCrypto); configMap.erase (L"NoKernelCrypto"); }
TC_CONFIG_SET (OpenExplorerWindowAfterMount);
- SetValue (configMap[L"PreserveTimestamps"], DefaultMountOptions.PreserveTimestamps);
+ if (configMap.count(L"PreserveTimestamps") > 0) { SetValue (configMap[L"PreserveTimestamps"], DefaultMountOptions.PreserveTimestamps); configMap.erase (L"PreserveTimestamps"); }
TC_CONFIG_SET (SaveHistory);
- SetValue (configMap[L"SecurityTokenLibrary"], SecurityTokenModule);
+ if (configMap.count(L"SecurityTokenLibrary") > 0) { SetValue (configMap[L"SecurityTokenLibrary"], SecurityTokenModule); configMap.erase (L"SecurityTokenLibrary"); }
TC_CONFIG_SET (StartOnLogon);
TC_CONFIG_SET (UseKeyfiles);
TC_CONFIG_SET (WipeCacheOnAutoDismount);
TC_CONFIG_SET (WipeCacheOnClose);
wstring defaultPrf;
- SetValue (configMap[L"DefaultPRF"], defaultPrf);
+ if (configMap.count(L"DefaultPRF") > 0) { SetValue (configMap[L"DefaultPRF"], defaultPrf); configMap.erase (L"DefaultPRF"); }
+ if (defaultPrf.empty())
+ defaultPrf = L"autodetection";
shared_ptr <Pkcs5Kdf> savedKdf;
try
{
@@ -125,6 +130,9 @@ namespace VeraCrypt
DefaultMountOptions.Kdf = savedKdf;
DefaultMountOptions.ProtectionKdf = savedKdf;
+
+ // at this point, the configMap should be empty, if not, we have unknown config entries that we need to store
+ UnknownConfigMapEntries = configMap;
}
// Default keyfiles
@@ -228,6 +236,12 @@ namespace VeraCrypt
defaultPrf = DefaultMountOptions.Kdf->GetName ();
formatter.AddEntry (L"DefaultPRF", defaultPrf);
+ // add unknown config entries by iterating over all elements of the UnknownConfigMapEntries map
+ for (map<wxString, wxString>::const_iterator it = UnknownConfigMapEntries.begin(); it != UnknownConfigMapEntries.end(); ++it)
+ {
+ formatter.AddEntry(it->first.c_str(), it->second);
+ }
+
XmlWriter writer (Application::GetConfigFilePath (GetPreferencesFileName(), true));
writer.WriteNode (formatter.XmlConfig);
writer.Close();
diff --git a/src/Main/UserPreferences.h b/src/Main/UserPreferences.h
index 6d53fb5f..3f60b533 100644
--- a/src/Main/UserPreferences.h
+++ b/src/Main/UserPreferences.h
@@ -96,6 +96,10 @@ namespace VeraCrypt
bool WipeCacheOnAutoDismount;
bool WipeCacheOnClose;
+ // A map used to store unknown entries from the configuration file in order to preserve them when saving the configuration.
+ // This helps to preserve unknown entries that may be used by future versions of VeraCrypt or entries used by old versions that were removed from current version.
+ map <wxString, wxString> UnknownConfigMapEntries;
+
protected:
wxString GetDefaultKeyfilesFileName () const { return L"Default Keyfiles.xml"; }
#ifdef TC_PROTOTYPE