mirror of
https://github.com/veracrypt/VeraCrypt.git
synced 2025-11-11 19:08:26 -06:00
Linux/MacOSX: Implement Unicode passwords suppport. Make validation of parameters in GUI more robust.
This commit is contained in:
@@ -790,7 +790,7 @@ namespace VeraCrypt
|
||||
|
||||
void EncryptionTest::TestPkcs5 ()
|
||||
{
|
||||
VolumePassword password ("password", 8);
|
||||
VolumePassword password ((byte*) "password", 8);
|
||||
static const byte saltData[] = { 0x12, 0x34, 0x56, 0x78 };
|
||||
ConstBufferPtr salt (saltData, sizeof (saltData));
|
||||
Buffer derivedKey (4);
|
||||
|
||||
@@ -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));
|
||||
|
||||
PasswordBuffer.Erase ();
|
||||
if (size > 0)
|
||||
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);
|
||||
|
||||
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());
|
||||
}
|
||||
|
||||
void VolumePassword::Set (const VolumePassword &password)
|
||||
|
||||
@@ -22,10 +22,8 @@ namespace VeraCrypt
|
||||
{
|
||||
public:
|
||||
VolumePassword ();
|
||||
VolumePassword (const byte *password, size_t size);
|
||||
VolumePassword (const char *password, size_t size);
|
||||
VolumePassword (const wchar_t *password, size_t charCount);
|
||||
VolumePassword (const wstring &password);
|
||||
VolumePassword (const byte *password, size_t size) { Set (password, size); }
|
||||
VolumePassword (const SecureBuffer &password) { Set (password.Ptr (), password.Size ()); }
|
||||
VolumePassword (const VolumePassword &password) { Set (password); }
|
||||
virtual ~VolumePassword ();
|
||||
|
||||
@@ -35,13 +33,10 @@ namespace VeraCrypt
|
||||
|
||||
operator BufferPtr () const { return BufferPtr (PasswordBuffer); }
|
||||
|
||||
void CheckPortability () const;
|
||||
byte *DataPtr () const { return PasswordBuffer; }
|
||||
bool IsEmpty () const { return PasswordSize == 0; }
|
||||
size_t Size () const { return PasswordSize; }
|
||||
void Set (const byte *password, size_t size);
|
||||
void Set (const wchar_t *password, size_t charCount);
|
||||
void Set (const ConstBufferPtr &password);
|
||||
void Set (const VolumePassword &password);
|
||||
|
||||
TC_SERIALIZABLE (VolumePassword);
|
||||
@@ -51,12 +46,10 @@ namespace VeraCrypt
|
||||
|
||||
protected:
|
||||
void AllocateBuffer ();
|
||||
bool IsPortable () const;
|
||||
|
||||
SecureBuffer PasswordBuffer;
|
||||
|
||||
size_t PasswordSize;
|
||||
bool Unportable;
|
||||
};
|
||||
|
||||
struct PasswordException : public Exception
|
||||
@@ -86,6 +79,8 @@ namespace VeraCrypt
|
||||
TC_EXCEPTION_NODECL (ProtectionPasswordKeyfilesIncorrect); \
|
||||
TC_EXCEPTION (PasswordEmpty); \
|
||||
TC_EXCEPTION (PasswordTooLong); \
|
||||
TC_EXCEPTION (PasswordUTF8TooLong); \
|
||||
TC_EXCEPTION (PasswordUTF8Invalid); \
|
||||
TC_EXCEPTION (UnportablePassword);
|
||||
|
||||
TC_EXCEPTION_SET;
|
||||
|
||||
Reference in New Issue
Block a user