From efa436974d8203485eec6faa1bf0116bb32f6fcd Mon Sep 17 00:00:00 2001 From: Mounir IDRASSI Date: Mon, 30 Nov 2015 11:35:41 +0100 Subject: Linux/MacOSX: Implement Unicode passwords suppport. Make validation of parameters in GUI more robust. --- src/Main/Forms/VolumePasswordPanel.cpp | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) (limited to 'src/Main/Forms/VolumePasswordPanel.cpp') diff --git a/src/Main/Forms/VolumePasswordPanel.cpp b/src/Main/Forms/VolumePasswordPanel.cpp index 03134535..e55b09f0 100644 --- a/src/Main/Forms/VolumePasswordPanel.cpp +++ b/src/Main/Forms/VolumePasswordPanel.cpp @@ -231,7 +231,7 @@ namespace VeraCrypt #ifdef TC_WINDOWS int len = GetWindowText (static_cast (textCtrl->GetHandle()), passwordBuf, VolumePassword::MaxSize + 1); - password.reset (new VolumePassword (passwordBuf, len)); + password = ToUTF8Password (passwordBuf, len); #else wxString passwordStr (textCtrl->GetValue()); // A copy of the password is created here by wxWidgets, which cannot be erased for (size_t i = 0; i < passwordStr.size() && i < VolumePassword::MaxSize; ++i) @@ -239,19 +239,33 @@ namespace VeraCrypt passwordBuf[i] = (wchar_t) passwordStr[i]; passwordStr[i] = L'X'; } - password.reset (new VolumePassword (passwordBuf, passwordStr.size() <= VolumePassword::MaxSize ? passwordStr.size() : VolumePassword::MaxSize)); + password = ToUTF8Password (passwordBuf, passwordStr.size() <= VolumePassword::MaxSize ? passwordStr.size() : VolumePassword::MaxSize); #endif return password; } - shared_ptr VolumePasswordPanel::GetPkcs5Kdf () const + shared_ptr VolumePasswordPanel::GetPkcs5Kdf (bool &bUnsupportedKdf) const { + return GetPkcs5Kdf (GetTrueCryptMode(), bUnsupportedKdf); + } + + shared_ptr VolumePasswordPanel::GetPkcs5Kdf (bool bTrueCryptMode, bool &bUnsupportedKdf) const + { + bUnsupportedKdf = false; try { - return Pkcs5Kdf::GetAlgorithm (wstring (Pkcs5PrfChoice->GetStringSelection()), GetTrueCryptMode()); + int index = Pkcs5PrfChoice->GetSelection (); + if ((wxNOT_FOUND == index) || (0 == index)) + { + // auto-detection + return shared_ptr (); + } + else + return Pkcs5Kdf::GetAlgorithm (wstring (Pkcs5PrfChoice->GetStringSelection()), bTrueCryptMode); } catch (ParameterIncorrect&) { + bUnsupportedKdf = true; return shared_ptr (); } } @@ -419,7 +433,14 @@ namespace VeraCrypt bool VolumePasswordPanel::PasswordsMatch () const { assert (ConfirmPasswordStaticText->IsShown()); - return *GetPassword (PasswordTextCtrl) == *GetPassword (ConfirmPasswordTextCtrl); + try + { + return *GetPassword (PasswordTextCtrl) == *GetPassword (ConfirmPasswordTextCtrl); + } + catch (PasswordException&) + { + return false; + } } void VolumePasswordPanel::WipeTextCtrl (wxTextCtrl *textCtrl) -- cgit v1.2.3