From ba1e9c8f4d6d65a5d5a73f1721bf2b03e42aa50e Mon Sep 17 00:00:00 2001 From: Mounir IDRASSI Date: Sat, 28 Feb 2015 17:01:39 +0100 Subject: Linux/MacOSX: A configuration option for default hash and default TrueCrypt mode used for mounting volumes (Menu Settings -> Default Mount Parameters). Implement priority of command line arguments over default values. --- src/Main/Forms/Forms.cpp | 24 +++ src/Main/Forms/Forms.h | 6 +- src/Main/Forms/MainFrame.cpp | 37 +++- src/Main/Forms/MainFrame.h | 1 + src/Main/Forms/PreferencesDialog.cpp | 34 ++++ src/Main/Forms/TrueCrypt.fbp | 287 +++++++++++++++++++++++++++++++- src/Main/Forms/VolumeCreationWizard.cpp | 2 + 7 files changed, 385 insertions(+), 6 deletions(-) mode change 100644 => 100755 src/Main/Forms/Forms.cpp mode change 100644 => 100755 src/Main/Forms/Forms.h mode change 100644 => 100755 src/Main/Forms/MainFrame.cpp mode change 100644 => 100755 src/Main/Forms/PreferencesDialog.cpp mode change 100644 => 100755 src/Main/Forms/TrueCrypt.fbp mode change 100644 => 100755 src/Main/Forms/VolumeCreationWizard.cpp (limited to 'src/Main/Forms') diff --git a/src/Main/Forms/Forms.cpp b/src/Main/Forms/Forms.cpp old mode 100644 new mode 100755 index c652929b..d05524db --- a/src/Main/Forms/Forms.cpp +++ b/src/Main/Forms/Forms.cpp @@ -137,6 +137,10 @@ MainFrameBase::MainFrameBase( wxWindow* parent, wxWindowID id, const wxString& t DefaultKeyfilesMenuItem = new wxMenuItem( SettingsMenu, wxID_ANY, wxString( _("Default Keyfiles...") ) , wxEmptyString, wxITEM_NORMAL ); SettingsMenu->Append( DefaultKeyfilesMenuItem ); + wxMenuItem* DefaultMountParametersMenuItem; + DefaultMountParametersMenuItem = new wxMenuItem( SettingsMenu, wxID_ANY, wxString( _("Default Mount Parameters...") ) , wxEmptyString, wxITEM_NORMAL ); + SettingsMenu->Append( DefaultMountParametersMenuItem ); + wxMenuItem* SecurityTokenPreferencesMenuItem; SecurityTokenPreferencesMenuItem = new wxMenuItem( SettingsMenu, wxID_ANY, wxString( _("Security Tokens...") ) , wxEmptyString, wxITEM_NORMAL ); SettingsMenu->Append( SecurityTokenPreferencesMenuItem ); @@ -428,6 +432,7 @@ MainFrameBase::MainFrameBase( wxWindow* parent, wxWindowID id, const wxString& t this->Connect( WipeCachedPasswordsMenuItem->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( MainFrameBase::OnWipeCacheButtonClick ) ); this->Connect( HotkeysMenuItem->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( MainFrameBase::OnHotkeysMenuItemSelected ) ); this->Connect( DefaultKeyfilesMenuItem->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( MainFrameBase::OnDefaultKeyfilesMenuItemSelected ) ); + this->Connect( DefaultMountParametersMenuItem->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( MainFrameBase::OnDefaultMountParametersMenuItemSelected ) ); this->Connect( SecurityTokenPreferencesMenuItem->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( MainFrameBase::OnSecurityTokenPreferencesMenuItemSelected ) ); this->Connect( PreferencesMenuItem->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( MainFrameBase::OnPreferencesMenuItemSelected ) ); this->Connect( UserGuideMenuItem->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( MainFrameBase::OnUserGuideMenuItemSelected ) ); @@ -490,6 +495,7 @@ MainFrameBase::~MainFrameBase() this->Disconnect( wxID_ANY, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( MainFrameBase::OnWipeCacheButtonClick ) ); this->Disconnect( wxID_ANY, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( MainFrameBase::OnHotkeysMenuItemSelected ) ); this->Disconnect( wxID_ANY, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( MainFrameBase::OnDefaultKeyfilesMenuItemSelected ) ); + this->Disconnect( wxID_ANY, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( MainFrameBase::OnDefaultMountParametersMenuItemSelected ) ); this->Disconnect( wxID_ANY, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( MainFrameBase::OnSecurityTokenPreferencesMenuItemSelected ) ); this->Disconnect( wxID_PREFERENCES, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( MainFrameBase::OnPreferencesMenuItemSelected ) ); this->Disconnect( wxID_HELP, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( MainFrameBase::OnUserGuideMenuItemSelected ) ); @@ -1862,6 +1868,24 @@ PreferencesDialogBase::PreferencesDialogBase( wxWindow* parent, wxWindowID id, c CachePasswordsCheckBox = new wxCheckBox( DefaultMountOptionsPage, wxID_ANY, _("Cache passwords in memory"), wxDefaultPosition, wxDefaultSize, 0 ); sbSizer15->Add( CachePasswordsCheckBox, 0, wxALL, 5 ); + TrueCryptModeCheckBox = new wxCheckBox( DefaultMountOptionsPage, wxID_ANY, _("TrueCrypt Mode"), wxDefaultPosition, wxDefaultSize, 0 ); + sbSizer15->Add( TrueCryptModeCheckBox, 0, wxALL, 5 ); + + wxBoxSizer* bSizer163; + bSizer163 = new wxBoxSizer( wxHORIZONTAL ); + + Pkcs5PrfStaticText = new wxStaticText( DefaultMountOptionsPage, wxID_ANY, _("PKCS5-PRF:"), wxDefaultPosition, wxDefaultSize, 0 ); + Pkcs5PrfStaticText->Wrap( -1 ); + bSizer163->Add( Pkcs5PrfStaticText, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 ); + + wxArrayString Pkcs5PrfChoiceChoices; + Pkcs5PrfChoice = new wxChoice( DefaultMountOptionsPage, wxID_ANY, wxDefaultPosition, wxDefaultSize, Pkcs5PrfChoiceChoices, 0 ); + Pkcs5PrfChoice->SetSelection( 0 ); + bSizer163->Add( Pkcs5PrfChoice, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 ); + + + sbSizer15->Add( bSizer163, 0, wxEXPAND, 5 ); + bSizer35->Add( sbSizer15, 0, wxEXPAND|wxALL, 5 ); diff --git a/src/Main/Forms/Forms.h b/src/Main/Forms/Forms.h old mode 100644 new mode 100755 index 9e8a02b0..24097686 --- a/src/Main/Forms/Forms.h +++ b/src/Main/Forms/Forms.h @@ -119,6 +119,7 @@ namespace VeraCrypt virtual void OnWipeCacheButtonClick( wxCommandEvent& event ) { event.Skip(); } virtual void OnHotkeysMenuItemSelected( wxCommandEvent& event ) { event.Skip(); } virtual void OnDefaultKeyfilesMenuItemSelected( wxCommandEvent& event ) { event.Skip(); } + virtual void OnDefaultMountParametersMenuItemSelected( wxCommandEvent& event ) { event.Skip(); } virtual void OnSecurityTokenPreferencesMenuItemSelected( wxCommandEvent& event ) { event.Skip(); } virtual void OnPreferencesMenuItemSelected( wxCommandEvent& event ) { event.Skip(); } virtual void OnUserGuideMenuItemSelected( wxCommandEvent& event ) { event.Skip(); } @@ -550,10 +551,12 @@ namespace VeraCrypt wxCheckBox* PreserveTimestampsCheckBox; wxCheckBox* WipeCacheOnCloseCheckBox; wxCheckBox* WipeCacheOnAutoDismountCheckBox; - wxPanel* DefaultMountOptionsPage; wxCheckBox* MountReadOnlyCheckBox; wxCheckBox* MountRemovableCheckBox; wxCheckBox* CachePasswordsCheckBox; + wxCheckBox* TrueCryptModeCheckBox; + wxStaticText* Pkcs5PrfStaticText; + wxChoice* Pkcs5PrfChoice; wxStaticBoxSizer* FilesystemSizer; wxTextCtrl* FilesystemOptionsTextCtrl; wxPanel* BackgroundTaskPanel; @@ -613,6 +616,7 @@ namespace VeraCrypt public: + wxPanel* DefaultMountOptionsPage; wxPanel* DefaultKeyfilesPage; wxPanel* SecurityTokensPage; wxPanel* HotkeysPage; diff --git a/src/Main/Forms/MainFrame.cpp b/src/Main/Forms/MainFrame.cpp old mode 100644 new mode 100755 index 08184005..41c6ae7d --- a/src/Main/Forms/MainFrame.cpp +++ b/src/Main/Forms/MainFrame.cpp @@ -625,6 +625,14 @@ namespace VeraCrypt try { MountOptions mountOptions (GetPreferences().DefaultMountOptions); + if (CmdLine->ArgTrueCryptMode) + { + mountOptions.TrueCryptMode = CmdLine->ArgTrueCryptMode; + } + if (CmdLine->ArgHash) + { + mountOptions.Kdf = Pkcs5Kdf::GetAlgorithm (*CmdLine->ArgHash, mountOptions.TrueCryptMode); + } if (SlotListCtrl->GetSelectedItemCount() == 1) mountOptions.SlotNumber = SelectedSlotNumber; @@ -642,6 +650,14 @@ namespace VeraCrypt try { MountOptions mountOptions (GetPreferences().DefaultMountOptions); + if (CmdLine->ArgTrueCryptMode) + { + mountOptions.TrueCryptMode = CmdLine->ArgTrueCryptMode; + } + if (CmdLine->ArgHash) + { + mountOptions.Kdf = Pkcs5Kdf::GetAlgorithm (*CmdLine->ArgHash, mountOptions.TrueCryptMode); + } Gui->MountAllFavoriteVolumes (mountOptions); } catch (exception &e) @@ -664,10 +680,13 @@ namespace VeraCrypt MountOptions mountOptions (GetPreferences().DefaultMountOptions); mountOptions.SlotNumber = SelectedSlotNumber; mountOptions.Path = GetSelectedVolumePath(); - mountOptions.TrueCryptMode = CmdLine->ArgTrueCryptMode; + if (CmdLine->ArgTrueCryptMode) + { + mountOptions.TrueCryptMode = CmdLine->ArgTrueCryptMode; + } if (CmdLine->ArgHash) { - mountOptions.Kdf = Pkcs5Kdf::GetAlgorithm (*CmdLine->ArgHash, CmdLine->ArgTrueCryptMode); + mountOptions.Kdf = Pkcs5Kdf::GetAlgorithm (*CmdLine->ArgHash, mountOptions.TrueCryptMode); } try @@ -837,6 +856,13 @@ namespace VeraCrypt dialog.ShowModal(); } + void MainFrame::OnDefaultMountParametersMenuItemSelected(wxCommandEvent& event) + { + PreferencesDialog dialog (this); + dialog.SelectPage (dialog.DefaultMountOptionsPage); + dialog.ShowModal(); + } + void MainFrame::OnDeviceChange (const DirectoryPath &mountPoint) { // Check if any host device has been removed and force dismount of volumes accordingly @@ -886,10 +912,13 @@ namespace VeraCrypt SetVolumePath (favorite.Path); MountOptions mountOptions (GetPreferences().DefaultMountOptions); - mountOptions.TrueCryptMode = CmdLine->ArgTrueCryptMode; + if (CmdLine->ArgTrueCryptMode) + { + mountOptions.TrueCryptMode = CmdLine->ArgTrueCryptMode; + } if (CmdLine->ArgHash) { - mountOptions.Kdf = Pkcs5Kdf::GetAlgorithm (*CmdLine->ArgHash, CmdLine->ArgTrueCryptMode); + mountOptions.Kdf = Pkcs5Kdf::GetAlgorithm (*CmdLine->ArgHash, mountOptions.TrueCryptMode); } favorite.ToMountOptions (mountOptions); diff --git a/src/Main/Forms/MainFrame.h b/src/Main/Forms/MainFrame.h index b31128cb..d2c6ea51 100644 --- a/src/Main/Forms/MainFrame.h +++ b/src/Main/Forms/MainFrame.h @@ -85,6 +85,7 @@ namespace VeraCrypt void OnCreateKeyfileMenuItemSelected (wxCommandEvent& event) { Gui->CreateKeyfile(); } void OnCreateVolumeButtonClick (wxCommandEvent& event); void OnDefaultKeyfilesMenuItemSelected (wxCommandEvent& event); + void OnDefaultMountParametersMenuItemSelected( wxCommandEvent& event ); void OnDismountAllButtonClick (wxCommandEvent& event); void OnDismountVolumeMenuItemSelected (wxCommandEvent& event) { DismountVolume(); } void OnDownloadsMenuItemSelected (wxCommandEvent& event) { Gui->OpenHomepageLink (this, L"downloads"); } diff --git a/src/Main/Forms/PreferencesDialog.cpp b/src/Main/Forms/PreferencesDialog.cpp old mode 100644 new mode 100755 index e22e304b..7e47b408 --- a/src/Main/Forms/PreferencesDialog.cpp +++ b/src/Main/Forms/PreferencesDialog.cpp @@ -48,6 +48,23 @@ namespace VeraCrypt MountRemovableCheckBox->SetValidator (wxGenericValidator (&Preferences.DefaultMountOptions.Removable)); FilesystemOptionsTextCtrl->SetValue (Preferences.DefaultMountOptions.FilesystemOptions); + + TrueCryptModeCheckBox->SetValidator (wxGenericValidator (&Preferences.DefaultMountOptions.TrueCryptMode)); + + int index, prfInitialIndex = 0; + Pkcs5PrfChoice->Append (LangString["AUTODETECTION"]); + + foreach_ref (const Pkcs5Kdf &kdf, Pkcs5Kdf::GetAvailableAlgorithms(false)) + { + index = Pkcs5PrfChoice->Append (kdf.GetName()); + if (Preferences.DefaultMountOptions.Kdf + && (Preferences.DefaultMountOptions.Kdf->GetName() == kdf.GetName()) + ) + { + prfInitialIndex = index; + } + } + Pkcs5PrfChoice->Select (prfInitialIndex); // Keyfiles TC_CHECK_BOX_VALIDATOR (UseKeyfiles); @@ -342,12 +359,29 @@ namespace VeraCrypt #endif if (!Validate()) return; + + shared_ptr selectedKdf; + if (Pkcs5PrfChoice->GetSelection () != 0) + { + try + { + selectedKdf = Pkcs5Kdf::GetAlgorithm (wstring (Pkcs5PrfChoice->GetStringSelection ()), TrueCryptModeCheckBox->IsChecked ()); + } + catch (ParameterIncorrect&) + { + Gui->ShowWarning ("ALGO_NOT_SUPPORTED_FOR_TRUECRYPT_MODE"); + return; + } + } TransferDataFromWindow(); Preferences.DefaultMountOptions.Protection = MountReadOnlyCheckBox->IsChecked() ? VolumeProtection::ReadOnly : VolumeProtection::None; Preferences.DefaultMountOptions.FilesystemOptions = FilesystemOptionsTextCtrl->GetValue(); Preferences.DefaultKeyfiles = *DefaultKeyfilesPanel->GetKeyfiles(); + + Preferences.DefaultMountOptions.Kdf = selectedKdf; + Preferences.DefaultMountOptions.ProtectionKdf = selectedKdf; bool securityTokenModuleChanged = (Preferences.SecurityTokenModule != wstring (Pkcs11ModulePathTextCtrl->GetValue())); Preferences.SecurityTokenModule = wstring (Pkcs11ModulePathTextCtrl->GetValue()); diff --git a/src/Main/Forms/TrueCrypt.fbp b/src/Main/Forms/TrueCrypt.fbp old mode 100644 new mode 100755 index c03beab9..cf43cbf9 --- a/src/Main/Forms/TrueCrypt.fbp +++ b/src/Main/Forms/TrueCrypt.fbp @@ -568,6 +568,21 @@ + + 0 + 1 + + wxID_ANY + wxITEM_NORMAL + Default Mount Parameters... + DefaultMountParametersMenuItem + none + + + OnDefaultMountParametersMenuItemSelected + + + 0 1 @@ -14204,7 +14219,7 @@ 1 - protected + public 1 Resizable @@ -14529,6 +14544,276 @@ + + 5 + wxALL + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + TrueCrypt Mode + + 0 + + + 0 + + 1 + TrueCryptModeCheckBox + 1 + + + protected + 1 + + Resizable + 1 + + + + 0 + + + wxFILTER_NONE + wxDefaultValidator + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 5 + wxEXPAND + 0 + + + bSizer163 + wxHORIZONTAL + none + + 5 + wxALIGN_CENTER_VERTICAL|wxALL + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + PKCS5-PRF: + + 0 + + + 0 + + 1 + Pkcs5PrfStaticText + 1 + + + protected + 1 + + Resizable + 1 + + + + 0 + + + + + -1 + + + + + + + + + + + + + + + + + + + + + + + + + + + 5 + wxALIGN_CENTER_VERTICAL|wxALL + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + + 0 + + + 0 + + 1 + Pkcs5PrfChoice + 1 + + + protected + 1 + + Resizable + 0 + 1 + + + + 0 + + + wxFILTER_NONE + wxDefaultValidator + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Main/Forms/VolumeCreationWizard.cpp b/src/Main/Forms/VolumeCreationWizard.cpp old mode 100644 new mode 100755 index 214c041d..12dc7457 --- a/src/Main/Forms/VolumeCreationWizard.cpp +++ b/src/Main/Forms/VolumeCreationWizard.cpp @@ -437,6 +437,8 @@ namespace VeraCrypt mountOptions.Protection = VolumeProtection::None; mountOptions.Password = Password; mountOptions.Keyfiles = Keyfiles; + mountOptions.Kdf = Kdf; + mountOptions.TrueCryptMode = false; shared_ptr volume = Core->MountVolume (mountOptions); finally_do_arg (shared_ptr , volume, { Core->DismountVolume (finally_arg, true); }); -- cgit v1.2.3