diff options
Diffstat (limited to 'src/Main/CommandLineInterface.cpp')
-rw-r--r-- | src/Main/CommandLineInterface.cpp | 26 |
1 files changed, 17 insertions, 9 deletions
diff --git a/src/Main/CommandLineInterface.cpp b/src/Main/CommandLineInterface.cpp index 171bd165..0360921b 100644 --- a/src/Main/CommandLineInterface.cpp +++ b/src/Main/CommandLineInterface.cpp @@ -31,6 +31,7 @@ namespace VeraCrypt ArgVolumeType (VolumeType::Unknown), ArgTrueCryptMode (false), ArgDisableFileSizeCheck (false), + ArgUseLegacyPassword (false), StartBackgroundTask (false) { wxCmdLineParser parser; @@ -98,6 +99,7 @@ namespace VeraCrypt parser.AddParam ( _("Volume path"), wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL); parser.AddParam ( _("Mount point"), wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL); parser.AddSwitch (L"", L"no-size-check", _("Disable check of container size against disk free space.")); + parser.AddSwitch (L"", L"legacy-password-maxlength", _("Use legacy maximum password length (64 UTF-8 bytes)")); wxString str; bool param1IsVolume = false; @@ -336,6 +338,7 @@ namespace VeraCrypt ArgTrueCryptMode = parser.Found (L"truecrypt"); ArgDisableFileSizeCheck = parser.Found (L"no-size-check"); + ArgUseLegacyPassword = parser.Found (L"legacy-password-maxlength") || ArgTrueCryptMode; #if !defined(TC_WINDOWS) && !defined(TC_MACOSX) if (parser.Found (L"fs-options", &str)) @@ -407,7 +410,7 @@ namespace VeraCrypt ArgNewKeyfiles = ToKeyfileList (str); if (parser.Found (L"new-password", &str)) - ArgNewPassword = ToUTF8Password (str.c_str()); + ArgNewPassword = ToUTF8Password (str.c_str(), -1, ArgUseLegacyPassword? VolumePassword::MaxLegacySize : VolumePassword::MaxSize); if (parser.Found (L"new-pim", &str)) { @@ -446,7 +449,7 @@ namespace VeraCrypt { if (Preferences.UseStandardInput) throw_err (L"--password cannot be used with --stdin"); - ArgPassword = ToUTF8Password (str.c_str()); + ArgPassword = ToUTF8Password (str.c_str(), -1, ArgUseLegacyPassword? VolumePassword::MaxLegacySize : VolumePassword::MaxSize); } if (parser.Found (L"pim", &str)) @@ -487,7 +490,7 @@ namespace VeraCrypt if (parser.Found (L"protection-password", &str)) { - ArgMountOptions.ProtectionPassword = ToUTF8Password (str.c_str()); + ArgMountOptions.ProtectionPassword = ToUTF8Password (str.c_str(), -1, ArgUseLegacyPassword? VolumePassword::MaxLegacySize : VolumePassword::MaxSize); ArgMountOptions.Protection = VolumeProtection::HiddenVolumeReadOnly; } @@ -601,7 +604,7 @@ namespace VeraCrypt if (parser.Found (L"token-pin", &str) && !str.IsEmpty ()) { - ArgTokenPin = ToUTF8Buffer (str.c_str(), str.Len ()); + ArgTokenPin = ToUTF8Buffer (str.c_str(), str.Len (), ArgUseLegacyPassword? VolumePassword::MaxLegacySize : VolumePassword::MaxSize); } if (parser.Found (L"verbose")) @@ -776,18 +779,18 @@ namespace VeraCrypt return filteredVolumes; } - shared_ptr<VolumePassword> ToUTF8Password (const wchar_t* str, size_t charCount) + shared_ptr<VolumePassword> ToUTF8Password (const wchar_t* str, size_t charCount, size_t maxUtf8Len) { if (charCount > 0) { - shared_ptr<SecureBuffer> utf8Buffer = ToUTF8Buffer (str, charCount); + shared_ptr<SecureBuffer> utf8Buffer = ToUTF8Buffer (str, charCount, maxUtf8Len); return shared_ptr<VolumePassword>(new VolumePassword (*utf8Buffer)); } else return shared_ptr<VolumePassword>(new VolumePassword ()); } - shared_ptr<SecureBuffer> ToUTF8Buffer (const wchar_t* str, size_t charCount) + shared_ptr<SecureBuffer> ToUTF8Buffer (const wchar_t* str, size_t charCount, size_t maxUtf8Len) { if (charCount == (size_t) -1) charCount = wcslen (str); @@ -802,8 +805,13 @@ namespace VeraCrypt ulen = utf8.FromWChar ((char*) (byte*) passwordBuf, ulen, str, charCount); if (wxCONV_FAILED == ulen) throw PasswordUTF8Invalid (SRC_POS); - if (ulen > VolumePassword::MaxSize) - throw PasswordUTF8TooLong (SRC_POS); + if (ulen > maxUtf8Len) + { + if (maxUtf8Len == VolumePassword::MaxLegacySize) + throw PasswordLegacyUTF8TooLong (SRC_POS); + else + throw PasswordUTF8TooLong (SRC_POS); + } ConstBufferPtr utf8Buffer ((byte*) passwordBuf, ulen); return shared_ptr<SecureBuffer>(new SecureBuffer (utf8Buffer)); |