From 515895342820a9d0a35391ec4d316c3782a75768 Mon Sep 17 00:00:00 2001 From: Mounir IDRASSI Date: Sun, 19 Jul 2015 08:46:27 +0200 Subject: User Interface enhancements for PIM --- src/Main/CommandLineInterface.cpp | 14 ++-- src/Main/Forms/ChangePasswordDialog.cpp | 7 ++ src/Main/Forms/Forms.cpp | 31 ++++---- src/Main/Forms/Forms.h | 2 + src/Main/Forms/MainFrame.cpp | 17 +++++ src/Main/Forms/TrueCrypt.fbp | 115 ++++++++++++++++++++++++++---- src/Main/Forms/VolumeCreationWizard.cpp | 33 ++++++++- src/Main/Forms/VolumePasswordPanel.cpp | 97 +++++++++++++++++++------ src/Main/Forms/VolumePasswordPanel.h | 11 ++- src/Main/Forms/VolumePasswordWizardPage.h | 5 +- src/Main/Forms/VolumePimWizardPage.cpp | 25 ++++++- src/Main/Forms/VolumePimWizardPage.h | 2 + 12 files changed, 305 insertions(+), 54 deletions(-) diff --git a/src/Main/CommandLineInterface.cpp b/src/Main/CommandLineInterface.cpp index 7eaef070..c3c82f42 100644 --- a/src/Main/CommandLineInterface.cpp +++ b/src/Main/CommandLineInterface.cpp @@ -378,13 +378,16 @@ namespace VeraCrypt try { ArgNewPim = StringConverter::ToInt32 (wstring (str)); - if (ArgNewPim < 0) - throw_err (LangString["PARAMETER_INCORRECT"] + L": " + str); } catch (...) { throw_err (LangString["PARAMETER_INCORRECT"] + L": " + str); } + + if (ArgNewPim < 0) + throw_err (LangString["PARAMETER_INCORRECT"] + L": " + str); + else if (ArgNewPim > 0 && ArgTrueCryptMode) + throw_err (LangString["PIM_NOT_SUPPORTED_FOR_TRUECRYPT_MODE"]); } if (parser.Found (L"non-interactive")) @@ -403,13 +406,16 @@ namespace VeraCrypt try { ArgPim = StringConverter::ToInt32 (wstring (str)); - if (ArgPim < 0) - throw_err (LangString["PARAMETER_INCORRECT"] + L": " + str); } catch (...) { throw_err (LangString["PARAMETER_INCORRECT"] + L": " + str); } + + if (ArgPim < 0) + throw_err (LangString["PARAMETER_INCORRECT"] + L": " + str); + else if (ArgPim > 0 && ArgTrueCryptMode) + throw_err (LangString["PIM_NOT_SUPPORTED_FOR_TRUECRYPT_MODE"]); } if (parser.Found (L"protect-hidden", &str)) diff --git a/src/Main/Forms/ChangePasswordDialog.cpp b/src/Main/Forms/ChangePasswordDialog.cpp index 702b01e4..1cb920ee 100644 --- a/src/Main/Forms/ChangePasswordDialog.cpp +++ b/src/Main/Forms/ChangePasswordDialog.cpp @@ -227,5 +227,12 @@ namespace VeraCrypt } OKButton->Enable (ok); + + if (DialogMode == Mode::ChangePasswordAndKeyfiles) + { + bool pimChanged = (CurrentPasswordPanel->GetVolumePim() != NewPasswordPanel->GetVolumePim()); + NewPasswordPanel->UpdatePimHelpText(pimChanged); + } + } } diff --git a/src/Main/Forms/Forms.cpp b/src/Main/Forms/Forms.cpp index ea769954..f6c20cec 100644 --- a/src/Main/Forms/Forms.cpp +++ b/src/Main/Forms/Forms.cpp @@ -861,7 +861,7 @@ ChangePasswordDialogBase::ChangePasswordDialogBase( wxWindow* parent, wxWindowID CurrentPasswordPanelSizer = new wxBoxSizer( wxVERTICAL ); - CurrentSizer->Add( CurrentPasswordPanelSizer, 0, wxALIGN_RIGHT, 5 ); + CurrentSizer->Add( CurrentPasswordPanelSizer, 0, wxALIGN_LEFT, 5 ); bSizer32->Add( CurrentSizer, 0, wxEXPAND, 5 ); @@ -871,7 +871,7 @@ ChangePasswordDialogBase::ChangePasswordDialogBase( wxWindow* parent, wxWindowID NewPasswordPanelSizer = new wxBoxSizer( wxVERTICAL ); - NewSizer->Add( NewPasswordPanelSizer, 0, wxALIGN_RIGHT, 5 ); + NewSizer->Add( NewPasswordPanelSizer, 0, wxALIGN_LEFT, 5 ); bSizer32->Add( NewSizer, 0, wxTOP|wxEXPAND, 5 ); @@ -3217,50 +3217,53 @@ VolumePasswordPanelBase::VolumePasswordPanelBase( wxWindow* parent, wxWindowID i VolumePimHelpStaticText->Wrap( -1 ); GridBagSizer->Add( VolumePimHelpStaticText, wxGBPosition( 3, 2 ), wxGBSpan( 1, 1 ), wxALIGN_CENTER_VERTICAL|wxALIGN_RIGHT|wxBOTTOM|wxLEFT|wxRIGHT, 5 ); + PimCheckBox = new wxCheckBox( this, wxID_ANY, _("Use PIM"), wxDefaultPosition, wxDefaultSize, 0 ); + GridBagSizer->Add( PimCheckBox, wxGBPosition( 4, 1 ), wxGBSpan( 1, 2 ), wxTOP|wxBOTTOM|wxLEFT|wxALIGN_CENTER_VERTICAL, 5 ); + CacheCheckBox = new wxCheckBox( this, wxID_ANY, _("Cach&e passwords and keyfiles in memory "), wxDefaultPosition, wxDefaultSize, 0 ); - GridBagSizer->Add( CacheCheckBox, wxGBPosition( 4, 1 ), wxGBSpan( 1, 2 ), wxTOP|wxBOTTOM|wxLEFT|wxALIGN_CENTER_VERTICAL, 5 ); + GridBagSizer->Add( CacheCheckBox, wxGBPosition( 5, 1 ), wxGBSpan( 1, 2 ), wxTOP|wxBOTTOM|wxLEFT|wxALIGN_CENTER_VERTICAL, 5 ); DisplayPasswordCheckBox = new wxCheckBox( this, wxID_ANY, _("&Display password"), wxDefaultPosition, wxDefaultSize, 0 ); - GridBagSizer->Add( DisplayPasswordCheckBox, wxGBPosition( 5, 1 ), wxGBSpan( 1, 2 ), wxTOP|wxBOTTOM|wxLEFT|wxALIGN_CENTER_VERTICAL, 5 ); + GridBagSizer->Add( DisplayPasswordCheckBox, wxGBPosition( 6, 1 ), wxGBSpan( 1, 2 ), wxTOP|wxBOTTOM|wxLEFT|wxALIGN_CENTER_VERTICAL, 5 ); UseKeyfilesCheckBox = new wxCheckBox( this, wxID_ANY, _("U&se keyfiles"), wxDefaultPosition, wxDefaultSize, 0 ); - GridBagSizer->Add( UseKeyfilesCheckBox, wxGBPosition( 6, 1 ), wxGBSpan( 1, 1 ), wxTOP|wxRIGHT|wxLEFT, 5 ); + GridBagSizer->Add( UseKeyfilesCheckBox, wxGBPosition( 7, 1 ), wxGBSpan( 1, 1 ), wxTOP|wxRIGHT|wxLEFT, 5 ); KeyfilesButton = new wxButton( this, wxID_ANY, _("&Keyfiles..."), wxDefaultPosition, wxDefaultSize, 0 ); - GridBagSizer->Add( KeyfilesButton, wxGBPosition( 6, 2 ), wxGBSpan( 1, 1 ), wxALIGN_RIGHT|wxALIGN_BOTTOM|wxLEFT, 5 ); + GridBagSizer->Add( KeyfilesButton, wxGBPosition( 7, 2 ), wxGBSpan( 1, 1 ), wxALIGN_RIGHT|wxALIGN_BOTTOM|wxLEFT, 5 ); Pkcs5PrfSizer = new wxBoxSizer( wxVERTICAL ); - GridBagSizer->Add( Pkcs5PrfSizer, wxGBPosition( 7, 1 ), wxGBSpan( 1, 1 ), wxEXPAND|wxTOP|wxBOTTOM, 5 ); + GridBagSizer->Add( Pkcs5PrfSizer, wxGBPosition( 8, 1 ), wxGBSpan( 1, 1 ), wxEXPAND|wxTOP|wxBOTTOM, 5 ); Pkcs5PrfStaticText = new wxStaticText( this, wxID_ANY, _("PKCS-5 PRF:"), wxDefaultPosition, wxDefaultSize, 0 ); Pkcs5PrfStaticText->Wrap( -1 ); - GridBagSizer->Add( Pkcs5PrfStaticText, wxGBPosition( 8, 0 ), wxGBSpan( 1, 1 ), wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL|wxRIGHT, 5 ); + GridBagSizer->Add( Pkcs5PrfStaticText, wxGBPosition( 9, 0 ), wxGBSpan( 1, 1 ), wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL|wxRIGHT, 5 ); wxString Pkcs5PrfChoiceChoices[] = { _("Unchanged") }; int Pkcs5PrfChoiceNChoices = sizeof( Pkcs5PrfChoiceChoices ) / sizeof( wxString ); Pkcs5PrfChoice = new wxChoice( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, Pkcs5PrfChoiceNChoices, Pkcs5PrfChoiceChoices, 0 ); Pkcs5PrfChoice->SetSelection( 0 ); - GridBagSizer->Add( Pkcs5PrfChoice, wxGBPosition( 8, 1 ), wxGBSpan( 1, 1 ), wxALIGN_CENTER_VERTICAL|wxLEFT, 5 ); + GridBagSizer->Add( Pkcs5PrfChoice, wxGBPosition( 9, 1 ), wxGBSpan( 1, 1 ), wxALIGN_CENTER_VERTICAL|wxLEFT, 5 ); TrueCryptModeCheckBox = new wxCheckBox( this, wxID_ANY, _("TrueCrypt Mode"), wxDefaultPosition, wxDefaultSize, 0 ); - GridBagSizer->Add( TrueCryptModeCheckBox, wxGBPosition( 8, 2 ), wxGBSpan( 1, 1 ), wxALIGN_CENTER_VERTICAL|wxLEFT, 5 ); + GridBagSizer->Add( TrueCryptModeCheckBox, wxGBPosition( 9, 2 ), wxGBSpan( 1, 1 ), wxALIGN_CENTER_VERTICAL|wxLEFT, 5 ); HeaderWipeCountText = new wxStaticText( this, wxID_ANY, _("Header Wipe:"), wxDefaultPosition, wxDefaultSize, 0 ); HeaderWipeCountText->Wrap( -1 ); - GridBagSizer->Add( HeaderWipeCountText, wxGBPosition( 9, 0 ), wxGBSpan( 1, 1 ), wxALIGN_CENTER_VERTICAL|wxALIGN_RIGHT|wxRIGHT, 5 ); + GridBagSizer->Add( HeaderWipeCountText, wxGBPosition( 10, 0 ), wxGBSpan( 1, 1 ), wxALIGN_CENTER_VERTICAL|wxALIGN_RIGHT|wxRIGHT, 5 ); wxString HeaderWipeCountChoices[] = { _("1-pass"), _("3-pass"), _("7-pass"), _("35-pass"), _("256-pass") }; int HeaderWipeCountNChoices = sizeof( HeaderWipeCountChoices ) / sizeof( wxString ); HeaderWipeCount = new wxChoice( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, HeaderWipeCountNChoices, HeaderWipeCountChoices, 0 ); HeaderWipeCount->SetSelection( 1 ); - GridBagSizer->Add( HeaderWipeCount, wxGBPosition( 9, 1 ), wxGBSpan( 1, 1 ), wxALL, 5 ); + GridBagSizer->Add( HeaderWipeCount, wxGBPosition( 10, 1 ), wxGBSpan( 1, 1 ), wxALL, 5 ); PasswordPlaceholderSizer = new wxBoxSizer( wxVERTICAL ); - GridBagSizer->Add( PasswordPlaceholderSizer, wxGBPosition( 10, 1 ), wxGBSpan( 1, 2 ), wxTOP|wxEXPAND, 5 ); + GridBagSizer->Add( PasswordPlaceholderSizer, wxGBPosition( 11, 1 ), wxGBSpan( 1, 2 ), wxTOP|wxEXPAND, 5 ); GridBagSizer->AddGrowableCol( 1 ); @@ -3276,6 +3279,7 @@ VolumePasswordPanelBase::VolumePasswordPanelBase( wxWindow* parent, wxWindowID i PasswordTextCtrl->Connect( wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler( VolumePasswordPanelBase::OnTextChanged ), NULL, this ); ConfirmPasswordTextCtrl->Connect( wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler( VolumePasswordPanelBase::OnTextChanged ), NULL, this ); VolumePimTextCtrl->Connect( wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler( VolumePasswordPanelBase::OnPimChanged ), NULL, this ); + PimCheckBox->Connect( wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler( VolumePasswordPanelBase::OnUsePimCheckBoxClick ), NULL, this ); DisplayPasswordCheckBox->Connect( wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler( VolumePasswordPanelBase::OnDisplayPasswordCheckBoxClick ), NULL, this ); UseKeyfilesCheckBox->Connect( wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler( VolumePasswordPanelBase::OnUseKeyfilesCheckBoxClick ), NULL, this ); KeyfilesButton->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( VolumePasswordPanelBase::OnKeyfilesButtonClick ), NULL, this ); @@ -3290,6 +3294,7 @@ VolumePasswordPanelBase::~VolumePasswordPanelBase() PasswordTextCtrl->Disconnect( wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler( VolumePasswordPanelBase::OnTextChanged ), NULL, this ); ConfirmPasswordTextCtrl->Disconnect( wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler( VolumePasswordPanelBase::OnTextChanged ), NULL, this ); VolumePimTextCtrl->Disconnect( wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler( VolumePasswordPanelBase::OnPimChanged ), NULL, this ); + PimCheckBox->Disconnect( wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler( VolumePasswordPanelBase::OnUsePimCheckBoxClick ), NULL, this ); DisplayPasswordCheckBox->Disconnect( wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler( VolumePasswordPanelBase::OnDisplayPasswordCheckBoxClick ), NULL, this ); UseKeyfilesCheckBox->Disconnect( wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler( VolumePasswordPanelBase::OnUseKeyfilesCheckBoxClick ), NULL, this ); KeyfilesButton->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( VolumePasswordPanelBase::OnKeyfilesButtonClick ), NULL, this ); diff --git a/src/Main/Forms/Forms.h b/src/Main/Forms/Forms.h index 1c4baa79..e950ac2e 100644 --- a/src/Main/Forms/Forms.h +++ b/src/Main/Forms/Forms.h @@ -963,6 +963,7 @@ namespace VeraCrypt wxStaticText* VolumePimStaticText; wxTextCtrl* VolumePimTextCtrl; wxStaticText* VolumePimHelpStaticText; + wxCheckBox* PimCheckBox; wxCheckBox* CacheCheckBox; wxCheckBox* DisplayPasswordCheckBox; wxCheckBox* UseKeyfilesCheckBox; @@ -978,6 +979,7 @@ namespace VeraCrypt // Virtual event handlers, overide them in your derived class virtual void OnTextChanged( wxCommandEvent& event ) { event.Skip(); } virtual void OnPimChanged( wxCommandEvent& event ) { event.Skip(); } + virtual void OnUsePimCheckBoxClick( wxCommandEvent& event ) { event.Skip(); } virtual void OnDisplayPasswordCheckBoxClick( wxCommandEvent& event ) { event.Skip(); } virtual void OnUseKeyfilesCheckBoxClick( wxCommandEvent& event ) { event.Skip(); } virtual void OnKeyfilesButtonClick( wxCommandEvent& event ) { event.Skip(); } diff --git a/src/Main/Forms/MainFrame.cpp b/src/Main/Forms/MainFrame.cpp index b4f2983f..0799f325 100644 --- a/src/Main/Forms/MainFrame.cpp +++ b/src/Main/Forms/MainFrame.cpp @@ -638,6 +638,10 @@ namespace VeraCrypt { mountOptions.Kdf = Pkcs5Kdf::GetAlgorithm (*CmdLine->ArgHash, mountOptions.TrueCryptMode); } + if (CmdLine->ArgPim > 0) + { + mountOptions.Pim = CmdLine->ArgPim; + } if (SlotListCtrl->GetSelectedItemCount() == 1) mountOptions.SlotNumber = SelectedSlotNumber; @@ -663,6 +667,11 @@ namespace VeraCrypt { mountOptions.Kdf = Pkcs5Kdf::GetAlgorithm (*CmdLine->ArgHash, mountOptions.TrueCryptMode); } + if (CmdLine->ArgPim > 0) + { + mountOptions.Pim = CmdLine->ArgPim; + } + Gui->MountAllFavoriteVolumes (mountOptions); } catch (exception &e) @@ -693,6 +702,10 @@ namespace VeraCrypt { mountOptions.Kdf = Pkcs5Kdf::GetAlgorithm (*CmdLine->ArgHash, mountOptions.TrueCryptMode); } + if (CmdLine->ArgPim > 0) + { + mountOptions.Pim = CmdLine->ArgPim; + } try { @@ -945,6 +958,10 @@ namespace VeraCrypt { mountOptions.Kdf = Pkcs5Kdf::GetAlgorithm (*CmdLine->ArgHash, mountOptions.TrueCryptMode); } + if (CmdLine->ArgPim > 0) + { + mountOptions.Pim = CmdLine->ArgPim; + } favorite.ToMountOptions (mountOptions); shared_ptr volume = Gui->MountVolume (mountOptions); diff --git a/src/Main/Forms/TrueCrypt.fbp b/src/Main/Forms/TrueCrypt.fbp index 78ecb556..25dfe831 100644 --- a/src/Main/Forms/TrueCrypt.fbp +++ b/src/Main/Forms/TrueCrypt.fbp @@ -5063,7 +5063,7 @@ 5 - wxALIGN_RIGHT + wxALIGN_LEFT 0 @@ -5088,7 +5088,7 @@ 5 - wxALIGN_RIGHT + wxALIGN_LEFT 0 @@ -26107,6 +26107,97 @@ 4 1 + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + Use PIM + + 0 + + + 0 + + 1 + PimCheckBox + 1 + + + protected + 1 + + Resizable + 1 + + + + 0 + + + wxFILTER_NONE + wxDefaultValidator + + + + + + OnUsePimCheckBoxClick + + + + + + + + + + + + + + + + + + + + + + + + + + 5 + 2 + 1 + wxTOP|wxBOTTOM|wxLEFT|wxALIGN_CENTER_VERTICAL + 5 + 1 + 1 1 1 @@ -26195,7 +26286,7 @@ 2 1 wxTOP|wxBOTTOM|wxLEFT|wxALIGN_CENTER_VERTICAL - 5 + 6 1 1 @@ -26286,7 +26377,7 @@ 1 1 wxTOP|wxRIGHT|wxLEFT - 6 + 7 1 1 @@ -26377,7 +26468,7 @@ 1 2 wxALIGN_RIGHT|wxALIGN_BOTTOM|wxLEFT - 6 + 7 1 1 @@ -26468,7 +26559,7 @@ 1 1 wxEXPAND|wxTOP|wxBOTTOM - 7 + 8 1 @@ -26482,7 +26573,7 @@ 1 0 wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL|wxRIGHT - 8 + 9 1 1 @@ -26568,7 +26659,7 @@ 1 1 wxALIGN_CENTER_VERTICAL|wxLEFT - 8 + 9 1 1 @@ -26659,7 +26750,7 @@ 1 2 wxALIGN_CENTER_VERTICAL|wxLEFT - 8 + 9 1 1 @@ -26750,7 +26841,7 @@ 1 0 wxALIGN_CENTER_VERTICAL|wxALIGN_RIGHT|wxRIGHT - 9 + 10 1 1 @@ -26836,7 +26927,7 @@ 1 1 wxALL - 9 + 10 1 1 @@ -26927,7 +27018,7 @@ 2 1 wxTOP|wxEXPAND - 10 + 11 1 diff --git a/src/Main/Forms/VolumeCreationWizard.cpp b/src/Main/Forms/VolumeCreationWizard.cpp index 8382127a..440155c7 100644 --- a/src/Main/Forms/VolumeCreationWizard.cpp +++ b/src/Main/Forms/VolumeCreationWizard.cpp @@ -42,6 +42,7 @@ namespace VeraCrypt SelectedFilesystemType (VolumeCreationOptions::FilesystemType::FAT), SelectedVolumeHostType (VolumeHostType::File), SelectedVolumeType (VolumeType::Normal), + Pim (0), SectorSize (0), VolumeSize (0) { @@ -85,6 +86,7 @@ namespace VeraCrypt OuterVolume = false; LargeFilesSupport = false; QuickFormatEnabled = false; + Pim = 0; SingleChoiceWizardPage *page = new SingleChoiceWizardPage (GetPageParent(), wxEmptyString, true); page->SetMinSize (wxSize (Gui->GetCharWidth (this) * 58, Gui->GetCharHeight (this) * 18 + 5)); @@ -186,6 +188,8 @@ namespace VeraCrypt case Step::VolumePassword: { VolumePasswordWizardPage *page = new VolumePasswordWizardPage (GetPageParent(), Password, Keyfiles); + page->EnableUsePim (); // force displaying "Use PIM" + page->SetPimSelected (Pim > 0); if (OuterVolume) page->SetPageTitle (LangString["PASSWORD_HIDVOL_HOST_TITLE"]); @@ -210,6 +214,7 @@ namespace VeraCrypt page->SetPageTitle (LangString["PIM_TITLE"]); page->SetPageText (LangString["PIM_HELP"]); + page->SetVolumePim (Pim); return page; } @@ -339,6 +344,7 @@ namespace VeraCrypt ClearHistory(); OuterVolume = false; LargeFilesSupport = false; + Pim = 0; InfoWizardPage *page = new InfoWizardPage (GetPageParent()); page->SetPageTitle (LangString["HIDVOL_PRE_CIPHER_TITLE"]); @@ -747,8 +753,33 @@ namespace VeraCrypt } } } + + if (page->IsPimSelected ()) + return Step::VolumePim; + else + { + // Clear PIM + Pim = 0; + + // Skip PIM + if (forward && OuterVolume) + { + // Use FAT to prevent problems with free space + QuickFormatEnabled = false; + SelectedFilesystemType = VolumeCreationOptions::FilesystemType::FAT; + return Step::CreationProgress; + } - return Step::VolumePim; + if (VolumeSize > 4 * BYTES_PER_GB) + { + if (VolumeSize <= TC_MAX_FAT_SECTOR_COUNT * SectorSize) + return Step::LargeFilesSupport; + else + SelectedFilesystemType = VolumeCreationOptions::FilesystemType::GetPlatformNative(); + } + + return Step::FormatOptions; + } } case Step::VolumePim: diff --git a/src/Main/Forms/VolumePasswordPanel.cpp b/src/Main/Forms/VolumePasswordPanel.cpp index 0d1e6931..08b9b828 100644 --- a/src/Main/Forms/VolumePasswordPanel.cpp +++ b/src/Main/Forms/VolumePasswordPanel.cpp @@ -15,7 +15,7 @@ namespace VeraCrypt { VolumePasswordPanel::VolumePasswordPanel (wxWindow* parent, MountOptions* options, shared_ptr password, bool disableTruecryptMode, shared_ptr keyfiles, bool enableCache, bool enablePassword, bool enableKeyfiles, bool enableConfirmation, bool enablePkcs5Prf, bool isMountPassword, const wxString &passwordLabel) - : VolumePasswordPanelBase (parent), Keyfiles (new KeyfileList) + : VolumePasswordPanelBase (parent), Keyfiles (new KeyfileList), EnablePimEntry (true) { if (keyfiles) { @@ -55,9 +55,17 @@ namespace VeraCrypt PasswordTextCtrl->Show (enablePassword); DisplayPasswordCheckBox->Show (enablePassword); - VolumePimStaticText->Show (enablePassword && (!enableConfirmation || (enablePkcs5Prf && !isMountPassword))); - VolumePimTextCtrl->Show (enablePassword && (!enableConfirmation || (enablePkcs5Prf && !isMountPassword))); - VolumePimHelpStaticText->Show (enablePassword && (!enableConfirmation || (enablePkcs5Prf && !isMountPassword))); + + EnablePimEntry = enablePassword && (!enableConfirmation || (enablePkcs5Prf && !isMountPassword)); + PimCheckBox->Show (EnablePimEntry); + VolumePimStaticText->Show (false); + VolumePimTextCtrl->Show (false); + VolumePimHelpStaticText->Show (false); + + wxTextValidator validator (wxFILTER_INCLUDE_CHAR_LIST); // wxFILTER_NUMERIC does not exclude - . , etc. + const wxChar *valArr[] = { L"0", L"1", L"2", L"3", L"4", L"5", L"6", L"7", L"8", L"9" }; + validator.SetIncludes (wxArrayString (array_capacity (valArr), (const wxChar **) &valArr)); + VolumePimTextCtrl->SetValidator (validator); ConfirmPasswordStaticText->Show (enableConfirmation); ConfirmPasswordTextCtrl->Show (enableConfirmation); @@ -76,12 +84,23 @@ namespace VeraCrypt TrueCryptModeCheckBox->SetValue (options->TrueCryptMode); if (options->TrueCryptMode) { + PimCheckBox->Enable (false); VolumePimStaticText->Enable (false); VolumePimTextCtrl->Enable (false); VolumePimHelpStaticText->Enable (false); } } + if (EnablePimEntry && options && options->Pim > 0) + { + PimCheckBox->SetValue (true); + PimCheckBox->Show (false); + VolumePimStaticText->Show (true); + VolumePimTextCtrl->Show (true); + VolumePimHelpStaticText->Show (true); + SetVolumePim (options->Pim); + } + if (enablePkcs5Prf) { int index, prfInitialIndex = 0; @@ -225,7 +244,7 @@ namespace VeraCrypt int VolumePasswordPanel::GetVolumePim () const { - if (VolumePimTextCtrl->IsEnabled ()) + if (VolumePimTextCtrl->IsEnabled () && VolumePimTextCtrl->IsShown ()) { wxString pimStr (VolumePimTextCtrl->GetValue()); long pim = 0; @@ -239,7 +258,19 @@ namespace VeraCrypt else return 0; } - + + void VolumePasswordPanel::SetVolumePim (int pim) + { + if (pim > 0) + { + VolumePimTextCtrl->SetValue (StringConverter::FromNumber (pim)); + } + else + { + VolumePimTextCtrl->SetValue (wxT("")); + } + } + bool VolumePasswordPanel::GetTrueCryptMode () const { return TrueCryptModeCheckBox->GetValue (); @@ -379,27 +410,53 @@ namespace VeraCrypt textCtrl->SetValue (wxString (L'X', textCtrl->GetLineLength(0))); GetPassword (textCtrl); } - - void VolumePasswordPanel::OnPimChanged (wxCommandEvent& event) - { - if (ConfirmPasswordTextCtrl->IsShown()) + + bool VolumePasswordPanel::UpdatePimHelpText (bool pimChanged) + { + bool guiUpdated = false; + if (pimChanged && VolumePimHelpStaticText->GetForegroundColour() != *wxRED) { - if (GetVolumePim() != 0) - { - VolumePimHelpStaticText->SetForegroundColour(*wxRED); - VolumePimHelpStaticText->SetLabel(LangString["PIM_CHANGE_WARNING"]); - } - else - { - VolumePimHelpStaticText->SetForegroundColour(*wxBLACK); - VolumePimHelpStaticText->SetLabel(LangString["IDC_PIM_HELP"]); - } + VolumePimHelpStaticText->SetForegroundColour(*wxRED); + VolumePimHelpStaticText->SetLabel(LangString["PIM_CHANGE_WARNING"]); + guiUpdated = true; + } + if (!pimChanged && VolumePimHelpStaticText->GetForegroundColour() != *wxBLACK) + { + VolumePimHelpStaticText->SetForegroundColour(*wxBLACK); + VolumePimHelpStaticText->SetLabel(LangString["IDC_PIM_HELP"]); + guiUpdated = true; + } + + if (guiUpdated) + { + Layout(); + Fit(); + GetParent()->Layout(); + GetParent()->Fit(); + } + return guiUpdated; + } + + void VolumePasswordPanel::OnUsePimCheckBoxClick( wxCommandEvent& event ) + { + if (EnablePimEntry) + { + PimCheckBox->Show (false); + VolumePimStaticText->Show (true); + VolumePimTextCtrl->Show (true); + VolumePimHelpStaticText->Show (true); + + Layout(); + Fit(); + GetParent()->Layout(); + GetParent()->Fit(); } } void VolumePasswordPanel::OnTrueCryptModeChecked( wxCommandEvent& event ) { bool bEnablePIM = !GetTrueCryptMode (); + PimCheckBox->Enable (bEnablePIM); VolumePimStaticText->Enable (bEnablePIM); VolumePimTextCtrl->Enable (bEnablePIM); VolumePimHelpStaticText->Enable (bEnablePIM); diff --git a/src/Main/Forms/VolumePasswordPanel.h b/src/Main/Forms/VolumePasswordPanel.h index f090a2bc..3518b2bb 100644 --- a/src/Main/Forms/VolumePasswordPanel.h +++ b/src/Main/Forms/VolumePasswordPanel.h @@ -30,8 +30,13 @@ namespace VeraCrypt int GetHeaderWipeCount () const; void SetCacheCheckBoxValidator (const wxGenericValidator &validator) { CacheCheckBox->SetValidator (validator); } void SetFocusToPasswordTextCtrl () { PasswordTextCtrl->SetSelection (-1, -1); PasswordTextCtrl->SetFocus(); } - void SetFocusToPimTextCtrl () { VolumePimTextCtrl->SetSelection (-1, -1); VolumePimTextCtrl->SetFocus(); } + void SetFocusToPimTextCtrl () { VolumePimTextCtrl->SetSelection (-1, -1); VolumePimTextCtrl->SetFocus(); } + void SetVolumePim (int pim); bool PasswordsMatch () const; + void EnableUsePim () { PimCheckBox->Enable (true); PimCheckBox->Show (true); } + bool IsUsePimChecked () const { return PimCheckBox->GetValue (); } + void SetUsePimChecked (bool checked) const { PimCheckBox->SetValue (checked); } + bool UpdatePimHelpText (bool pimChanged); Event UpdateEvent; @@ -46,7 +51,8 @@ namespace VeraCrypt void OnKeyfilesButtonRightClick (wxMouseEvent& event); void OnKeyfilesButtonRightDown (wxMouseEvent& event); void OnTextChanged (wxCommandEvent& event) { OnUpdate(); } - void OnPimChanged (wxCommandEvent& event); + void OnPimChanged (wxCommandEvent& event) { OnUpdate(); } + void OnUsePimCheckBoxClick( wxCommandEvent& event ); void OnUpdate () { UpdateEvent.Raise(); } void OnUseKeyfilesCheckBoxClick (wxCommandEvent& event) { OnUpdate(); } void WipeTextCtrl (wxTextCtrl *textCtrl); @@ -54,6 +60,7 @@ namespace VeraCrypt shared_ptr Keyfiles; shared_ptr UpdateCallback; + bool EnablePimEntry; }; } diff --git a/src/Main/Forms/VolumePasswordWizardPage.h b/src/Main/Forms/VolumePasswordWizardPage.h index aad86c86..652aed88 100644 --- a/src/Main/Forms/VolumePasswordWizardPage.h +++ b/src/Main/Forms/VolumePasswordWizardPage.h @@ -22,7 +22,10 @@ namespace VeraCrypt shared_ptr GetKeyfiles () const { return PasswordPanel->GetKeyfiles(); } shared_ptr GetPassword () const { return PasswordPanel->GetPassword(); } - int GetVolumePim () const { return PasswordPanel->GetVolumePim(); } + void EnableUsePim () { PasswordPanel->EnableUsePim (); } + bool IsPimSelected () const { return PasswordPanel->IsUsePimChecked ();} + void SetPimSelected (bool selected) const { PasswordPanel->SetUsePimChecked (selected);} + shared_ptr GetPkcs5Kdf () const { return PasswordPanel->GetPkcs5Kdf(); } bool IsValid (); void SetMaxStaticTextWidth (int width) { InfoStaticText->Wrap (width); } diff --git a/src/Main/Forms/VolumePimWizardPage.cpp b/src/Main/Forms/VolumePimWizardPage.cpp index 58d9d6af..36dc4c7f 100644 --- a/src/Main/Forms/VolumePimWizardPage.cpp +++ b/src/Main/Forms/VolumePimWizardPage.cpp @@ -23,6 +23,10 @@ namespace VeraCrypt VolumePimWizardPage::VolumePimWizardPage (wxPanel* parent) : VolumePimWizardPageBase (parent) { + wxTextValidator validator (wxFILTER_INCLUDE_CHAR_LIST); // wxFILTER_NUMERIC does not exclude - . , etc. + const wxChar *valArr[] = { L"0", L"1", L"2", L"3", L"4", L"5", L"6", L"7", L"8", L"9" }; + validator.SetIncludes (wxArrayString (array_capacity (valArr), (const wxChar **) &valArr)); + VolumePimTextCtrl->SetValidator (validator); } VolumePimWizardPage::~VolumePimWizardPage () @@ -46,6 +50,20 @@ namespace VeraCrypt return 0; } + void VolumePimWizardPage::SetVolumePim (int pim) + { + if (pim > 0) + { + VolumePimTextCtrl->SetValue (StringConverter::FromNumber (pim)); + } + else + { + VolumePimTextCtrl->SetValue (wxT("")); + } + + OnPimChanged (pim); + } + bool VolumePimWizardPage::IsValid () { return true; @@ -53,7 +71,12 @@ namespace VeraCrypt void VolumePimWizardPage::OnPimChanged (wxCommandEvent& event) { - if (GetVolumePim() != 0) + OnPimChanged (GetVolumePim ()); + } + + void VolumePimWizardPage::OnPimChanged (int pim) + { + if (pim > 0) { VolumePimHelpStaticText->SetForegroundColour(*wxRED); VolumePimHelpStaticText->SetLabel(LangString["PIM_CHANGE_WARNING"]); diff --git a/src/Main/Forms/VolumePimWizardPage.h b/src/Main/Forms/VolumePimWizardPage.h index eff35e1e..ae097004 100644 --- a/src/Main/Forms/VolumePimWizardPage.h +++ b/src/Main/Forms/VolumePimWizardPage.h @@ -28,12 +28,14 @@ namespace VeraCrypt ~VolumePimWizardPage (); int GetVolumePim () const; + void SetVolumePim (int pim); bool IsValid (); void SetMaxStaticTextWidth (int width) { InfoStaticText->Wrap (width); } void SetPageText (const wxString &text) { InfoStaticText->SetLabel (text); } protected: void OnPimChanged (wxCommandEvent& event); + void OnPimChanged (int pim); }; } -- cgit v1.2.3