From a7d5b6a4774c92736c89e8d6122b13c75c8d17c8 Mon Sep 17 00:00:00 2001 From: Mounir IDRASSI Date: Sun, 3 Nov 2019 22:54:23 +0100 Subject: Linux/MacOSX: Add switch to force the use of legacy maximum password length (64 UTF8 bytes) The switch is --legacy-password-maxlength --- src/Main/Forms/VolumePasswordPanel.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'src/Main/Forms/VolumePasswordPanel.cpp') diff --git a/src/Main/Forms/VolumePasswordPanel.cpp b/src/Main/Forms/VolumePasswordPanel.cpp index 8d5e8bc5..ac30075e 100644 --- a/src/Main/Forms/VolumePasswordPanel.cpp +++ b/src/Main/Forms/VolumePasswordPanel.cpp @@ -21,6 +21,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), EnablePimEntry (true) { + size_t maxPasswordLength = CmdLine->ArgUseLegacyPassword? VolumePassword::MaxLegacySize : VolumePassword::MaxSize; if (keyfiles) { *Keyfiles = *keyfiles; @@ -32,8 +33,8 @@ namespace VeraCrypt UseKeyfilesCheckBox->SetValue (Gui->GetPreferences().UseKeyfiles && !Keyfiles->empty()); } - PasswordTextCtrl->SetMaxLength (VolumePassword::MaxSize); - ConfirmPasswordTextCtrl->SetMaxLength (VolumePassword::MaxSize); + PasswordTextCtrl->SetMaxLength (maxPasswordLength); + ConfirmPasswordTextCtrl->SetMaxLength (maxPasswordLength); if (!passwordLabel.empty()) { @@ -195,9 +196,10 @@ namespace VeraCrypt FreezeScope freeze (this); bool isPim = (*textCtrl == VolumePimTextCtrl); int colspan = isPim? 1 : 2; + size_t maxPasswordLength = CmdLine->ArgUseLegacyPassword? VolumePassword::MaxLegacySize : VolumePassword::MaxSize; wxTextCtrl *newTextCtrl = new wxTextCtrl (this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, display ? 0 : wxTE_PASSWORD); - newTextCtrl->SetMaxLength (isPim? MAX_PIM_DIGITS : VolumePassword::MaxSize); + newTextCtrl->SetMaxLength (isPim? MAX_PIM_DIGITS : maxPasswordLength); newTextCtrl->SetValue ((*textCtrl)->GetValue()); newTextCtrl->SetMinSize ((*textCtrl)->GetSize()); @@ -226,12 +228,12 @@ namespace VeraCrypt { shared_ptr password; wchar_t passwordBuf[VolumePassword::MaxSize + 1]; - size_t maxPasswordLength = bLegacyPassword? VolumePassword::MaxLegacySize: VolumePassword::MaxSize; + size_t maxPasswordLength = (bLegacyPassword || CmdLine->ArgUseLegacyPassword)? VolumePassword::MaxLegacySize: VolumePassword::MaxSize; finally_do_arg (BufferPtr, BufferPtr (reinterpret_cast (passwordBuf), sizeof (passwordBuf)), { finally_arg.Erase(); }); #ifdef TC_WINDOWS int len = GetWindowText (static_cast (textCtrl->GetHandle()), passwordBuf, VolumePassword::MaxSize + 1); - password = ToUTF8Password (passwordBuf, len); + password = ToUTF8Password (passwordBuf, len, maxPasswordLength); #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 < maxPasswordLength; ++i) @@ -239,7 +241,7 @@ namespace VeraCrypt passwordBuf[i] = (wchar_t) passwordStr[i]; passwordStr[i] = L'X'; } - password = ToUTF8Password (passwordBuf, passwordStr.size() <= maxPasswordLength ? passwordStr.size() : maxPasswordLength); + password = ToUTF8Password (passwordBuf, passwordStr.size() <= maxPasswordLength ? passwordStr.size() : maxPasswordLength, maxPasswordLength); #endif return password; } -- cgit v1.2.3