VeraCrypt
aboutsummaryrefslogtreecommitdiff
path: root/src/Main/CommandLineInterface.cpp
diff options
context:
space:
mode:
authorMounir IDRASSI <mounir.idrassi@idrix.fr>2015-11-30 11:35:41 +0100
committerMounir IDRASSI <mounir.idrassi@idrix.fr>2015-11-30 13:58:19 +0100
commitefa436974d8203485eec6faa1bf0116bb32f6fcd (patch)
tree97a5ef2eea0310a12db399151de7ca97dbd47ece /src/Main/CommandLineInterface.cpp
parentcfadb231d24bd292a6ea3708b776bde8f06e50ab (diff)
downloadVeraCrypt-efa436974d8203485eec6faa1bf0116bb32f6fcd.tar.gz
VeraCrypt-efa436974d8203485eec6faa1bf0116bb32f6fcd.zip
Linux/MacOSX: Implement Unicode passwords suppport. Make validation of parameters in GUI more robust.
Diffstat (limited to 'src/Main/CommandLineInterface.cpp')
-rw-r--r--src/Main/CommandLineInterface.cpp42
1 files changed, 39 insertions, 3 deletions
diff --git a/src/Main/CommandLineInterface.cpp b/src/Main/CommandLineInterface.cpp
index 3563f0b0..1b2ec46a 100644
--- a/src/Main/CommandLineInterface.cpp
+++ b/src/Main/CommandLineInterface.cpp
@@ -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;
}