VeraCrypt
aboutsummaryrefslogtreecommitdiff
path: root/src/Volume/VolumePassword.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/Volume/VolumePassword.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/Volume/VolumePassword.cpp')
-rw-r--r--src/Volume/VolumePassword.cpp96
1 files changed, 5 insertions, 91 deletions
diff --git a/src/Volume/VolumePassword.cpp b/src/Volume/VolumePassword.cpp
index c36f910d..c6d27a67 100644
--- a/src/Volume/VolumePassword.cpp
+++ b/src/Volume/VolumePassword.cpp
@@ -16,31 +16,11 @@
namespace VeraCrypt
{
- VolumePassword::VolumePassword () : PasswordSize (0), Unportable (false)
+ VolumePassword::VolumePassword () : PasswordSize (0)
{
AllocateBuffer ();
}
- VolumePassword::VolumePassword (const char *password, size_t size)
- {
- Set ((const byte *) password, size);
- }
-
- VolumePassword::VolumePassword (const byte *password, size_t size)
- {
- Set (password, size);
- }
-
- VolumePassword::VolumePassword (const wchar_t *password, size_t charCount)
- {
- Set (password, charCount);
- }
-
- VolumePassword::VolumePassword (const wstring &password)
- {
- Set (password.c_str(), password.size());
- }
-
VolumePassword::~VolumePassword ()
{
}
@@ -51,12 +31,6 @@ namespace VeraCrypt
PasswordBuffer.Allocate (MaxSize);
}
- void VolumePassword::CheckPortability () const
- {
- if (Unportable || !IsPortable())
- throw UnportablePassword (SRC_POS);
- }
-
void VolumePassword::Deserialize (shared_ptr <Stream> stream)
{
Serializer sr (stream);
@@ -69,16 +43,6 @@ namespace VeraCrypt
sr.Deserialize ("WipeData", wipeBuffer);
}
- bool VolumePassword::IsPortable () const
- {
- for (size_t i = 0; i < PasswordSize; i++)
- {
- if (PasswordBuffer[i] >= 0x7f || PasswordBuffer[i] < 0x20)
- return false;
- }
- return true;
- }
-
void VolumePassword::Serialize (shared_ptr <Stream> stream) const
{
Serializable::Serialize (stream);
@@ -98,62 +62,12 @@ namespace VeraCrypt
if (size > MaxSize)
throw PasswordTooLong (SRC_POS);
-
- PasswordBuffer.CopyFrom (ConstBufferPtr (password, size));
- PasswordSize = size;
- Unportable = !IsPortable();
- }
-
- void VolumePassword::Set (const wchar_t *password, size_t charCount)
- {
- if (charCount > MaxSize)
- throw PasswordTooLong (SRC_POS);
+ PasswordBuffer.Erase ();
+ if (size > 0)
+ PasswordBuffer.CopyFrom (ConstBufferPtr (password, size));
- union Conv
- {
- byte b[sizeof (wchar_t)];
- wchar_t c;
- };
-
- Conv conv;
- conv.c = L'A';
-
- int lsbPos = -1;
- for (size_t i = 0; i < sizeof (conv.b); ++i)
- {
- if (conv.b[i] == L'A')
- {
- lsbPos = i;
- break;
- }
- }
-
- if (lsbPos == -1)
- throw ParameterIncorrect (SRC_POS);
-
- bool unportable = false;
- byte passwordBuf[MaxSize];
- for (size_t i = 0; i < charCount; ++i)
- {
- conv.c = password[i];
- passwordBuf[i] = conv.b[lsbPos];
- for (int j = 0; j < (int) sizeof (wchar_t); ++j)
- {
- if (j != lsbPos && conv.b[j] != 0)
- unportable = true;
- }
- }
-
- Set (passwordBuf, charCount);
-
- if (unportable)
- Unportable = true;
- }
-
- void VolumePassword::Set (const ConstBufferPtr &password)
- {
- Set (password, password.Size());
+ PasswordSize = size;
}
void VolumePassword::Set (const VolumePassword &password)