1
0
mirror of https://github.com/veracrypt/VeraCrypt.git synced 2025-11-11 11:08:02 -06:00

Linux/MacOSX: Implement Unicode passwords suppport. Make validation of parameters in GUI more robust.

This commit is contained in:
Mounir IDRASSI
2015-11-30 11:35:41 +01:00
parent cfadb231d2
commit efa436974d
16 changed files with 195 additions and 225 deletions

View File

@@ -376,7 +376,7 @@ namespace VeraCrypt
ArgNewKeyfiles = ToKeyfileList (str);
if (parser.Found (L"new-password", &str))
ArgNewPassword.reset (new VolumePassword (wstring (str)));
ArgNewPassword = ToUTF8Password (str);
if (parser.Found (L"new-pim", &str))
{
@@ -415,7 +415,7 @@ namespace VeraCrypt
{
if (Preferences.UseStandardInput)
throw_err (L"--password cannot be used with --stdin");
ArgPassword.reset (new VolumePassword (wstring (str)));
ArgPassword = ToUTF8Password (str);
}
if (parser.Found (L"pim", &str))
@@ -456,7 +456,7 @@ namespace VeraCrypt
if (parser.Found (L"protection-password", &str))
{
ArgMountOptions.ProtectionPassword.reset (new VolumePassword (wstring (str)));
ArgMountOptions.ProtectionPassword = ToUTF8Password (str);
ArgMountOptions.Protection = VolumeProtection::HiddenVolumeReadOnly;
}
@@ -713,5 +713,41 @@ namespace VeraCrypt
return filteredVolumes;
}
shared_ptr<VolumePassword> ToUTF8Password (const wchar_t* str, size_t charCount)
{
if (charCount > 0)
{
shared_ptr<SecureBuffer> utf8Buffer = ToUTF8Buffer (str, charCount);
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)
{
if (charCount == (size_t) -1)
charCount = wcslen (str);
if (charCount > 0)
{
wxMBConvUTF8 utf8;
size_t ulen = utf8.FromWChar (NULL, 0, str, charCount);
if (wxCONV_FAILED == ulen)
throw PasswordUTF8Invalid (SRC_POS);
SecureBuffer passwordBuf(ulen);
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);
ConstBufferPtr utf8Buffer ((byte*) passwordBuf, ulen);
return shared_ptr<SecureBuffer>(new SecureBuffer (utf8Buffer));
}
else
return shared_ptr<SecureBuffer>(new SecureBuffer ());
}
auto_ptr <CommandLineInterface> CmdLine;
}