From 6bb1f24ed571bccd4d1d247dafdc1dda6eaa3d8d Mon Sep 17 00:00:00 2001 From: Mounir IDRASSI Date: Mon, 4 Feb 2019 11:37:37 +0100 Subject: Automatically truncate passwords for TrueCrypt volumes and System Encryption to the first 64 characters. This fix issues encountered by users of TrueCrypt volumes who were using passwords longer than 64 characters that were truncated in previous version. --- src/Main/Forms/MountOptionsDialog.cpp | 4 ++-- src/Main/Forms/VolumePasswordPanel.cpp | 11 ++++++----- src/Main/Forms/VolumePasswordPanel.h | 4 ++-- 3 files changed, 10 insertions(+), 9 deletions(-) (limited to 'src/Main/Forms') diff --git a/src/Main/Forms/MountOptionsDialog.cpp b/src/Main/Forms/MountOptionsDialog.cpp index c980133f..c54ff8e6 100644 --- a/src/Main/Forms/MountOptionsDialog.cpp +++ b/src/Main/Forms/MountOptionsDialog.cpp @@ -133,7 +133,7 @@ namespace VeraCrypt try { - Options.Password = PasswordPanel->GetPassword(); + Options.Password = PasswordPanel->GetPassword(Options.PartitionInSystemEncryptionScope); } catch (PasswordException& e) { @@ -165,7 +165,7 @@ namespace VeraCrypt { try { - Options.ProtectionPassword = ProtectionPasswordPanel->GetPassword(); + Options.ProtectionPassword = ProtectionPasswordPanel->GetPassword(Options.TrueCryptMode); } catch (PasswordException& e) { diff --git a/src/Main/Forms/VolumePasswordPanel.cpp b/src/Main/Forms/VolumePasswordPanel.cpp index 9bce4c75..2859762c 100644 --- a/src/Main/Forms/VolumePasswordPanel.cpp +++ b/src/Main/Forms/VolumePasswordPanel.cpp @@ -219,15 +219,16 @@ namespace VeraCrypt SetPimValidator (); } - shared_ptr VolumePasswordPanel::GetPassword () const + shared_ptr VolumePasswordPanel::GetPassword (bool bForceLegacyPassword) const { - return GetPassword (PasswordTextCtrl); + return GetPassword (PasswordTextCtrl, bForceLegacyPassword || GetTrueCryptMode()); } - shared_ptr VolumePasswordPanel::GetPassword (wxTextCtrl *textCtrl) const + shared_ptr VolumePasswordPanel::GetPassword (wxTextCtrl *textCtrl, bool bLegacyPassword) const { shared_ptr password; wchar_t passwordBuf[VolumePassword::MaxSize + 1]; + size_t maxPasswordLength = bLegacyPassword? VolumePassword::MaxLegacySize: VolumePassword::MaxSize; finally_do_arg (BufferPtr, BufferPtr (reinterpret_cast (passwordBuf), sizeof (passwordBuf)), { finally_arg.Erase(); }); #ifdef TC_WINDOWS @@ -235,12 +236,12 @@ namespace VeraCrypt 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) + for (size_t i = 0; i < passwordStr.size() && i < maxPasswordLength; ++i) { passwordBuf[i] = (wchar_t) passwordStr[i]; passwordStr[i] = L'X'; } - password = ToUTF8Password (passwordBuf, passwordStr.size() <= VolumePassword::MaxSize ? passwordStr.size() : VolumePassword::MaxSize); + password = ToUTF8Password (passwordBuf, passwordStr.size() <= maxPasswordLength ? passwordStr.size() : maxPasswordLength); #endif return password; } diff --git a/src/Main/Forms/VolumePasswordPanel.h b/src/Main/Forms/VolumePasswordPanel.h index 83efc2ff..cac6c37b 100644 --- a/src/Main/Forms/VolumePasswordPanel.h +++ b/src/Main/Forms/VolumePasswordPanel.h @@ -27,7 +27,7 @@ namespace VeraCrypt void AddKeyfile (shared_ptr keyfile); shared_ptr GetKeyfiles () const { return UseKeyfilesCheckBox->IsChecked() ? Keyfiles : shared_ptr (); } - shared_ptr GetPassword () const; + shared_ptr GetPassword (bool bForceLegacyPassword = false) const; shared_ptr GetPkcs5Kdf (bool &bUnsupportedKdf) const; shared_ptr GetPkcs5Kdf (bool bTrueCryptMode, bool &bUnsupportedKdf) const; int GetVolumePim () const; @@ -49,7 +49,7 @@ namespace VeraCrypt protected: void SetPimValidator (); void DisplayPassword (bool display, wxTextCtrl **textCtrl, int row); - shared_ptr GetPassword (wxTextCtrl *textCtrl) const; + shared_ptr GetPassword (wxTextCtrl *textCtrl, bool bLegacyPassword = false) const; void OnAddKeyfileDirMenuItemSelected (wxCommandEvent& event); void OnAddKeyfilesMenuItemSelected (wxCommandEvent& event); void OnAddSecurityTokenSignatureMenuItemSelected (wxCommandEvent& event); -- cgit v1.2.3