From b8a2e808c693a59e236b98c3274019e5a25b3089 Mon Sep 17 00:00:00 2001 From: Mounir IDRASSI Date: Mon, 25 Jan 2016 01:35:17 +0100 Subject: MacOSX: Add PIM value validity checks to workaround wxWidget bug that makes wxTextValidator useless when applied to a text control with password attribute (http://trac.wxwidgets.org/ticket/17185). --- src/Main/Forms/ChangePasswordDialog.cpp | 20 +++++++++++++++++++- src/Main/Forms/MountOptionsDialog.cpp | 23 +++++++++++++++++++++-- src/Main/Forms/VolumeCreationWizard.cpp | 6 ++++++ src/Main/Forms/VolumePasswordPanel.cpp | 3 ++- src/Main/Forms/VolumePimWizardPage.cpp | 3 ++- 5 files changed, 50 insertions(+), 5 deletions(-) mode change 100644 => 100755 src/Main/Forms/ChangePasswordDialog.cpp mode change 100644 => 100755 src/Main/Forms/MountOptionsDialog.cpp mode change 100644 => 100755 src/Main/Forms/VolumeCreationWizard.cpp mode change 100644 => 100755 src/Main/Forms/VolumePasswordPanel.cpp mode change 100644 => 100755 src/Main/Forms/VolumePimWizardPage.cpp diff --git a/src/Main/Forms/ChangePasswordDialog.cpp b/src/Main/Forms/ChangePasswordDialog.cpp old mode 100644 new mode 100755 index 9b69be0b..b3e0bd04 --- a/src/Main/Forms/ChangePasswordDialog.cpp +++ b/src/Main/Forms/ChangePasswordDialog.cpp @@ -92,6 +92,12 @@ namespace VeraCrypt Gui->ShowWarning (LangString ["ALGO_NOT_SUPPORTED_FOR_TRUECRYPT_MODE"]); return; } + int currentPim = CurrentPasswordPanel->GetVolumePim(); + if (-1 == currentPim) + { + CurrentPasswordPanel->SetFocusToPimTextCtrl(); + return; + } shared_ptr newPassword; int newPim = 0; @@ -108,6 +114,11 @@ namespace VeraCrypt return; } newPim = NewPasswordPanel->GetVolumePim(); + if (-1 == newPim) + { + NewPasswordPanel->SetFocusToPimTextCtrl(); + return; + } if (newPassword->Size() > 0) { @@ -224,6 +235,9 @@ namespace VeraCrypt if (passwordEmpty && keyfilesEmpty) ok = false; + + if (CurrentPasswordPanel->GetVolumePim () == -1) + ok = false; if (DialogMode == Mode::RemoveAllKeyfiles && (passwordEmpty || keyfilesEmpty)) ok = false; @@ -237,7 +251,11 @@ namespace VeraCrypt ok = false; if (DialogMode == Mode::ChangePasswordAndKeyfiles - && ((NewPasswordPanel->GetPassword()->IsEmpty() && newKeyfilesEmpty) || !NewPasswordPanel->PasswordsMatch())) + && ( (NewPasswordPanel->GetPassword()->IsEmpty() && newKeyfilesEmpty) + || !NewPasswordPanel->PasswordsMatch() + || (NewPasswordPanel->GetVolumePim() == -1) + ) + ) ok = false; } } diff --git a/src/Main/Forms/MountOptionsDialog.cpp b/src/Main/Forms/MountOptionsDialog.cpp old mode 100644 new mode 100755 index 14198e68..207d2479 --- a/src/Main/Forms/MountOptionsDialog.cpp +++ b/src/Main/Forms/MountOptionsDialog.cpp @@ -87,6 +87,25 @@ namespace VeraCrypt void MountOptionsDialog::OnOKButtonClick (wxCommandEvent& event) { bool bUnsupportedKdf = false; + + /* verify that PIM values are valid before continuing*/ + int Pim = PasswordPanel->GetVolumePim(); + int ProtectionPim = (!ReadOnlyCheckBox->IsChecked() && ProtectionCheckBox->IsChecked())? + ProtectionPasswordPanel->GetVolumePim() : 0; + + /* invalid PIM: set focus to PIM field and stop processing */ + if (-1 == Pim) + { + PasswordPanel->SetFocusToPimTextCtrl(); + return; + } + + if (-1 == ProtectionPim) + { + ProtectionPasswordPanel->SetFocusToPimTextCtrl(); + return; + } + TransferDataFromWindow(); try @@ -98,7 +117,7 @@ namespace VeraCrypt Gui->ShowWarning (e); return; } - Options.Pim = PasswordPanel->GetVolumePim(); + Options.Pim = Pim; Options.Kdf = PasswordPanel->GetPkcs5Kdf(bUnsupportedKdf); if (bUnsupportedKdf) { @@ -124,7 +143,7 @@ namespace VeraCrypt return; } Options.Protection = VolumeProtection::HiddenVolumeReadOnly; - Options.ProtectionPim = ProtectionPasswordPanel->GetVolumePim(); + Options.ProtectionPim = ProtectionPim; Options.ProtectionKdf = ProtectionPasswordPanel->GetPkcs5Kdf(Options.TrueCryptMode, bUnsupportedKdf); if (bUnsupportedKdf) { diff --git a/src/Main/Forms/VolumeCreationWizard.cpp b/src/Main/Forms/VolumeCreationWizard.cpp old mode 100644 new mode 100755 index d67f0fe7..a250625b --- a/src/Main/Forms/VolumeCreationWizard.cpp +++ b/src/Main/Forms/VolumeCreationWizard.cpp @@ -792,6 +792,12 @@ namespace VeraCrypt if (forward && Password && !Password->IsEmpty()) { + if (-1 == Pim) + { + // PIM invalid: don't go anywhere + return GetCurrentStep(); + } + if (Password->Size() < VolumePassword::WarningSizeThreshold) { if (Pim > 0 && Pim < 485) diff --git a/src/Main/Forms/VolumePasswordPanel.cpp b/src/Main/Forms/VolumePasswordPanel.cpp old mode 100644 new mode 100755 index 9c0f06ec..16fafa3a --- a/src/Main/Forms/VolumePasswordPanel.cpp +++ b/src/Main/Forms/VolumePasswordPanel.cpp @@ -278,7 +278,8 @@ namespace VeraCrypt long pim = 0; if (pimStr.IsEmpty()) return 0; - if (pimStr.ToLong (&pim)) + if (((size_t) wxNOT_FOUND == pimStr.find_first_not_of (wxT("0123456789"))) + && pimStr.ToLong (&pim)) return (int) pim; else return -1; diff --git a/src/Main/Forms/VolumePimWizardPage.cpp b/src/Main/Forms/VolumePimWizardPage.cpp old mode 100644 new mode 100755 index c5f5e889..0e3d4299 --- a/src/Main/Forms/VolumePimWizardPage.cpp +++ b/src/Main/Forms/VolumePimWizardPage.cpp @@ -38,7 +38,8 @@ namespace VeraCrypt long pim = 0; if (pimStr.IsEmpty()) return 0; - if (pimStr.ToLong (&pim)) + if (((size_t) wxNOT_FOUND == pimStr.find_first_not_of (wxT("0123456789"))) + && pimStr.ToLong (&pim)) return (int) pim; else return -1; -- cgit v1.2.3