From c178e325b807258199ae45b2c50c265b4d7ce7af Mon Sep 17 00:00:00 2001 From: Mounir IDRASSI Date: Tue, 30 Dec 2014 17:01:49 +0100 Subject: Linux/MacOSX: Implement TrueCrypt conversion and loading support. Correct many GTK issues linked to multi-threaded origine of events by implementing an automatic mechanism for handling such requests in the main thread. --- src/Core/Core.h | 19 +++++++++------- src/Core/CoreBase.cpp | 18 +++++++++++---- src/Core/CoreBase.h | 4 ++-- src/Core/MountOptions.cpp | 57 +++++++++++++++++++++++++++------------------- src/Core/MountOptions.h | 4 +++- src/Core/Unix/CoreUnix.cpp | 1 + 6 files changed, 63 insertions(+), 40 deletions(-) mode change 100755 => 100644 src/Core/CoreBase.cpp mode change 100755 => 100644 src/Core/CoreBase.h mode change 100755 => 100644 src/Core/MountOptions.cpp mode change 100755 => 100644 src/Core/MountOptions.h (limited to 'src/Core') diff --git a/src/Core/Core.h b/src/Core/Core.h index 1a7a1611..4ff85139 100644 --- a/src/Core/Core.h +++ b/src/Core/Core.h @@ -70,14 +70,15 @@ namespace VeraCrypt bool m_preserveTimestamps; shared_ptr m_password; shared_ptr m_kdf; + bool m_truecryptMode; shared_ptr m_keyfiles; shared_ptr m_newPassword; shared_ptr m_newKeyfiles; shared_ptr m_newPkcs5Kdf; int m_wipeCount; - ChangePasswordThreadRoutine(shared_ptr volumePath, bool preserveTimestamps, shared_ptr password, shared_ptr kdf, shared_ptr keyfiles, shared_ptr newPassword, shared_ptr newKeyfiles, shared_ptr newPkcs5Kdf, int wipeCount) : m_volumePath(volumePath), m_preserveTimestamps(preserveTimestamps), m_password(password), m_kdf(kdf), m_keyfiles(keyfiles), m_newPassword(newPassword), m_newKeyfiles(newKeyfiles), m_newPkcs5Kdf(newPkcs5Kdf), m_wipeCount(wipeCount) {} + ChangePasswordThreadRoutine(shared_ptr volumePath, bool preserveTimestamps, shared_ptr password, shared_ptr kdf, bool truecryptMode, shared_ptr keyfiles, shared_ptr newPassword, shared_ptr newKeyfiles, shared_ptr newPkcs5Kdf, int wipeCount) : m_volumePath(volumePath), m_preserveTimestamps(preserveTimestamps), m_password(password), m_kdf(kdf), m_truecryptMode(truecryptMode), m_keyfiles(keyfiles), m_newPassword(newPassword), m_newKeyfiles(newKeyfiles), m_newPkcs5Kdf(newPkcs5Kdf), m_wipeCount(wipeCount) {} virtual ~ChangePasswordThreadRoutine() { } - virtual void ExecutionCode(void) { Core->ChangePassword(m_volumePath, m_preserveTimestamps, m_password, m_kdf, m_keyfiles, m_newPassword, m_newKeyfiles, m_newPkcs5Kdf, m_wipeCount); } + virtual void ExecutionCode(void) { Core->ChangePassword(m_volumePath, m_preserveTimestamps, m_password, m_kdf, m_truecryptMode, m_keyfiles, m_newPassword, m_newKeyfiles, m_newPkcs5Kdf, m_wipeCount); } }; class OpenVolumeThreadRoutine : public WaitThreadRoutine @@ -87,6 +88,7 @@ namespace VeraCrypt bool m_preserveTimestamps; shared_ptr m_password; shared_ptr m_Kdf; + bool m_truecryptMode; shared_ptr m_keyfiles; VolumeProtection::Enum m_protection; shared_ptr m_protectionPassword; @@ -98,14 +100,14 @@ namespace VeraCrypt bool m_partitionInSystemEncryptionScope; shared_ptr m_pVolume; - OpenVolumeThreadRoutine(shared_ptr volumePath, bool preserveTimestamps, shared_ptr password, shared_ptr Kdf, shared_ptr keyfiles, VolumeProtection::Enum protection = VolumeProtection::None, shared_ptr protectionPassword = shared_ptr (), shared_ptr protectionKdf = shared_ptr (), shared_ptr protectionKeyfiles = shared_ptr (), bool sharedAccessAllowed = false, VolumeType::Enum volumeType = VolumeType::Unknown, bool useBackupHeaders = false, bool partitionInSystemEncryptionScope = false): - m_volumePath(volumePath), m_preserveTimestamps(preserveTimestamps), m_password(password), m_Kdf(Kdf), m_keyfiles(keyfiles), + OpenVolumeThreadRoutine(shared_ptr volumePath, bool preserveTimestamps, shared_ptr password, shared_ptr Kdf, bool truecryptMode, shared_ptr keyfiles, VolumeProtection::Enum protection = VolumeProtection::None, shared_ptr protectionPassword = shared_ptr (), shared_ptr protectionKdf = shared_ptr (), shared_ptr protectionKeyfiles = shared_ptr (), bool sharedAccessAllowed = false, VolumeType::Enum volumeType = VolumeType::Unknown, bool useBackupHeaders = false, bool partitionInSystemEncryptionScope = false): + m_volumePath(volumePath), m_preserveTimestamps(preserveTimestamps), m_password(password), m_Kdf(Kdf), m_truecryptMode(truecryptMode), m_keyfiles(keyfiles), m_protection(protection), m_protectionPassword(protectionPassword), m_protectionKdf(protectionKdf), m_protectionKeyfiles(protectionKeyfiles), m_sharedAccessAllowed(sharedAccessAllowed), m_volumeType(volumeType),m_useBackupHeaders(useBackupHeaders), m_partitionInSystemEncryptionScope(partitionInSystemEncryptionScope) {} ~OpenVolumeThreadRoutine() {} - virtual void ExecutionCode(void) { m_pVolume = Core->OpenVolume(m_volumePath,m_preserveTimestamps,m_password,m_Kdf,m_keyfiles, m_protection,m_protectionPassword,m_protectionKdf, m_protectionKeyfiles,m_sharedAccessAllowed,m_volumeType,m_useBackupHeaders, m_partitionInSystemEncryptionScope); } + virtual void ExecutionCode(void) { m_pVolume = Core->OpenVolume(m_volumePath,m_preserveTimestamps,m_password,m_Kdf,m_truecryptMode,m_keyfiles, m_protection,m_protectionPassword,m_protectionKdf, m_protectionKeyfiles,m_sharedAccessAllowed,m_volumeType,m_useBackupHeaders, m_partitionInSystemEncryptionScope); } }; @@ -129,14 +131,15 @@ namespace VeraCrypt const ConstBufferPtr &m_encryptedData; const VolumePassword &m_password; shared_ptr m_kdf; + bool m_truecryptMode; const Pkcs5KdfList &m_keyDerivationFunctions; const EncryptionAlgorithmList &m_encryptionAlgorithms; const EncryptionModeList &m_encryptionModes; bool m_bResult; - DecryptThreadRoutine(shared_ptr header, const ConstBufferPtr &encryptedData, const VolumePassword &password, shared_ptr kdf, const Pkcs5KdfList &keyDerivationFunctions, const EncryptionAlgorithmList &encryptionAlgorithms, const EncryptionModeList &encryptionModes) - : m_pHeader(header), m_encryptedData(encryptedData), m_password(password), m_kdf(kdf), m_keyDerivationFunctions(keyDerivationFunctions), m_encryptionAlgorithms(encryptionAlgorithms), m_encryptionModes(encryptionModes), m_bResult(false){} + DecryptThreadRoutine(shared_ptr header, const ConstBufferPtr &encryptedData, const VolumePassword &password, shared_ptr kdf, bool truecryptMode, const Pkcs5KdfList &keyDerivationFunctions, const EncryptionAlgorithmList &encryptionAlgorithms, const EncryptionModeList &encryptionModes) + : m_pHeader(header), m_encryptedData(encryptedData), m_password(password), m_kdf(kdf), m_truecryptMode(truecryptMode), m_keyDerivationFunctions(keyDerivationFunctions), m_encryptionAlgorithms(encryptionAlgorithms), m_encryptionModes(encryptionModes), m_bResult(false){} virtual ~DecryptThreadRoutine() { } - virtual void ExecutionCode(void) { m_bResult = m_pHeader->Decrypt(m_encryptedData, m_password, m_kdf, m_keyDerivationFunctions, m_encryptionAlgorithms, m_encryptionModes); } + virtual void ExecutionCode(void) { m_bResult = m_pHeader->Decrypt(m_encryptedData, m_password, m_kdf, m_truecryptMode, m_keyDerivationFunctions, m_encryptionAlgorithms, m_encryptionModes); } }; class WaitThreadUI diff --git a/src/Core/CoreBase.cpp b/src/Core/CoreBase.cpp old mode 100755 new mode 100644 index 0137e204..8dcee144 --- a/src/Core/CoreBase.cpp +++ b/src/Core/CoreBase.cpp @@ -29,7 +29,15 @@ namespace VeraCrypt throw PasswordEmpty (SRC_POS); if (!newPkcs5Kdf) - newPkcs5Kdf = openVolume->GetPkcs5Kdf(); + { + if (openVolume->GetPkcs5Kdf()->GetTrueCryptMode ()) + { + newPkcs5Kdf.reset (openVolume->GetPkcs5Kdf()->Clone()); + newPkcs5Kdf->SetTrueCryptMode (false); + } + else + newPkcs5Kdf = openVolume->GetPkcs5Kdf(); + } if ((openVolume->GetHeader()->GetFlags() & TC_HEADER_FLAG_ENCRYPTED_SYSTEM) != 0 && openVolume->GetType() == VolumeType::Hidden @@ -68,9 +76,9 @@ namespace VeraCrypt } } - void CoreBase::ChangePassword (shared_ptr volumePath, bool preserveTimestamps, shared_ptr password, shared_ptr kdf, shared_ptr keyfiles, shared_ptr newPassword, shared_ptr newKeyfiles, shared_ptr newPkcs5Kdf, int wipeCount) const + void CoreBase::ChangePassword (shared_ptr volumePath, bool preserveTimestamps, shared_ptr password, shared_ptr kdf, bool truecryptMode, shared_ptr keyfiles, shared_ptr newPassword, shared_ptr newKeyfiles, shared_ptr newPkcs5Kdf, int wipeCount) const { - shared_ptr volume = OpenVolume (volumePath, preserveTimestamps, password, kdf, keyfiles); + shared_ptr volume = OpenVolume (volumePath, preserveTimestamps, password, kdf, truecryptMode, keyfiles); ChangePassword (volume, newPassword, newKeyfiles, newPkcs5Kdf, wipeCount); } @@ -242,10 +250,10 @@ namespace VeraCrypt return GetMountedVolume (volumePath); } - shared_ptr CoreBase::OpenVolume (shared_ptr volumePath, bool preserveTimestamps, shared_ptr password, shared_ptr kdf, shared_ptr keyfiles, VolumeProtection::Enum protection, shared_ptr protectionPassword, shared_ptr protectionKdf, shared_ptr protectionKeyfiles, bool sharedAccessAllowed, VolumeType::Enum volumeType, bool useBackupHeaders, bool partitionInSystemEncryptionScope) const + shared_ptr CoreBase::OpenVolume (shared_ptr volumePath, bool preserveTimestamps, shared_ptr password, shared_ptr kdf, bool truecryptMode, shared_ptr keyfiles, VolumeProtection::Enum protection, shared_ptr protectionPassword, shared_ptr protectionKdf, shared_ptr protectionKeyfiles, bool sharedAccessAllowed, VolumeType::Enum volumeType, bool useBackupHeaders, bool partitionInSystemEncryptionScope) const { make_shared_auto (Volume, volume); - volume->Open (*volumePath, preserveTimestamps, password, kdf, keyfiles, protection, protectionPassword, protectionKdf, protectionKeyfiles, sharedAccessAllowed, volumeType, useBackupHeaders, partitionInSystemEncryptionScope); + volume->Open (*volumePath, preserveTimestamps, password, kdf, truecryptMode, keyfiles, protection, protectionPassword, protectionKdf, protectionKeyfiles, sharedAccessAllowed, volumeType, useBackupHeaders, partitionInSystemEncryptionScope); return volume; } diff --git a/src/Core/CoreBase.h b/src/Core/CoreBase.h old mode 100755 new mode 100644 index d7dbcd0e..9f704369 --- a/src/Core/CoreBase.h +++ b/src/Core/CoreBase.h @@ -30,7 +30,7 @@ namespace VeraCrypt virtual ~CoreBase (); virtual void ChangePassword (shared_ptr openVolume, shared_ptr newPassword, shared_ptr newKeyfiles, shared_ptr newPkcs5Kdf = shared_ptr (), int wipeCount = PRAND_HEADER_WIPE_PASSES) const; - virtual void ChangePassword (shared_ptr volumePath, bool preserveTimestamps, shared_ptr password, shared_ptr kdf, shared_ptr keyfiles, shared_ptr newPassword, shared_ptr newKeyfiles, shared_ptr newPkcs5Kdf = shared_ptr (), int wipeCount = PRAND_HEADER_WIPE_PASSES) const; + virtual void ChangePassword (shared_ptr volumePath, bool preserveTimestamps, shared_ptr password, shared_ptr kdf, bool truecryptMode, shared_ptr keyfiles, shared_ptr newPassword, shared_ptr newKeyfiles, shared_ptr newPkcs5Kdf = shared_ptr (), int wipeCount = PRAND_HEADER_WIPE_PASSES) const; virtual void CheckFilesystem (shared_ptr mountedVolume, bool repair = false) const = 0; virtual void CoalesceSlotNumberAndMountPoint (MountOptions &options) const; virtual void CreateKeyfile (const FilePath &keyfilePath) const; @@ -65,7 +65,7 @@ namespace VeraCrypt virtual bool IsVolumeMounted (const VolumePath &volumePath) const; virtual VolumeSlotNumber MountPointToSlotNumber (const DirectoryPath &mountPoint) const = 0; virtual shared_ptr MountVolume (MountOptions &options) = 0; - virtual shared_ptr OpenVolume (shared_ptr volumePath, bool preserveTimestamps, shared_ptr password, shared_ptr Kdf, shared_ptr keyfiles, VolumeProtection::Enum protection = VolumeProtection::None, shared_ptr protectionPassword = shared_ptr (), shared_ptr protectionKdf = shared_ptr (), shared_ptr protectionKeyfiles = shared_ptr (), bool sharedAccessAllowed = false, VolumeType::Enum volumeType = VolumeType::Unknown, bool useBackupHeaders = false, bool partitionInSystemEncryptionScope = false) const; + virtual shared_ptr OpenVolume (shared_ptr volumePath, bool preserveTimestamps, shared_ptr password, shared_ptr Kdf, bool truecryptMode, shared_ptr keyfiles, VolumeProtection::Enum protection = VolumeProtection::None, shared_ptr protectionPassword = shared_ptr (), shared_ptr protectionKdf = shared_ptr (), shared_ptr protectionKeyfiles = shared_ptr (), bool sharedAccessAllowed = false, VolumeType::Enum volumeType = VolumeType::Unknown, bool useBackupHeaders = false, bool partitionInSystemEncryptionScope = false) const; virtual void RandomizeEncryptionAlgorithmKey (shared_ptr encryptionAlgorithm) const; virtual void ReEncryptVolumeHeaderWithNewSalt (const BufferPtr &newHeaderBuffer, shared_ptr header, shared_ptr password, shared_ptr keyfiles) const; virtual void SetAdminPasswordCallback (shared_ptr functor) { } diff --git a/src/Core/MountOptions.cpp b/src/Core/MountOptions.cpp old mode 100755 new mode 100644 index fb813bf0..844d72b4 --- a/src/Core/MountOptions.cpp +++ b/src/Core/MountOptions.cpp @@ -46,6 +46,7 @@ namespace VeraCrypt TC_CLONE (SharedAccessAllowed); TC_CLONE (SlotNumber); TC_CLONE (UseBackupHeaders); + TC_CLONE (TrueCryptMode); } void MountOptions::Deserialize (shared_ptr stream) @@ -72,14 +73,6 @@ namespace VeraCrypt Password = Serializable::DeserializeNew (stream); else Password.reset(); - - if (!sr.DeserializeBool ("KdfNull")) - { - sr.Deserialize ("Kdf", nameValue); - Kdf = Pkcs5Kdf::GetAlgorithm (nameValue); - } - else - Kdf.reset(); if (!sr.DeserializeBool ("PathNull")) Path.reset (new VolumePath (sr.DeserializeWString ("Path"))); @@ -96,19 +89,33 @@ namespace VeraCrypt else ProtectionPassword.reset(); - if (!sr.DeserializeBool ("ProtectionKdfNull")) - { - sr.Deserialize ("ProtectionKdf", nameValue); - ProtectionKdf = Pkcs5Kdf::GetAlgorithm (nameValue); - } - else - ProtectionKdf.reset(); - ProtectionKeyfiles = Keyfile::DeserializeList (stream, "ProtectionKeyfiles"); sr.Deserialize ("Removable", Removable); sr.Deserialize ("SharedAccessAllowed", SharedAccessAllowed); sr.Deserialize ("SlotNumber", SlotNumber); sr.Deserialize ("UseBackupHeaders", UseBackupHeaders); + + sr.Deserialize ("TrueCryptMode", TrueCryptMode); + + try + { + if (!sr.DeserializeBool ("KdfNull")) + { + sr.Deserialize ("Kdf", nameValue); + Kdf = Pkcs5Kdf::GetAlgorithm (nameValue, TrueCryptMode); + } + } + catch(...) {} + + try + { + if (!sr.DeserializeBool ("ProtectionKdfNull")) + { + sr.Deserialize ("ProtectionKdf", nameValue); + ProtectionKdf = Pkcs5Kdf::GetAlgorithm (nameValue, TrueCryptMode); + } + } + catch(...) {} } void MountOptions::Serialize (shared_ptr stream) const @@ -133,10 +140,6 @@ namespace VeraCrypt if (Password) Password->Serialize (stream); - sr.Serialize ("KdfNull", Kdf == nullptr); - if (Kdf) - sr.Serialize ("Kdf", Kdf->GetName()); - sr.Serialize ("PathNull", Path == nullptr); if (Path) sr.Serialize ("Path", wstring (*Path)); @@ -149,15 +152,21 @@ namespace VeraCrypt if (ProtectionPassword) ProtectionPassword->Serialize (stream); - sr.Serialize ("ProtectionKdfNull", ProtectionKdf == nullptr); - if (ProtectionKdf) - sr.Serialize ("ProtectionKdf", ProtectionKdf->GetName()); - Keyfile::SerializeList (stream, "ProtectionKeyfiles", ProtectionKeyfiles); sr.Serialize ("Removable", Removable); sr.Serialize ("SharedAccessAllowed", SharedAccessAllowed); sr.Serialize ("SlotNumber", SlotNumber); sr.Serialize ("UseBackupHeaders", UseBackupHeaders); + + sr.Serialize ("TrueCryptMode", TrueCryptMode); + + sr.Serialize ("KdfNull", Kdf == nullptr); + if (Kdf) + sr.Serialize ("Kdf", Kdf->GetName()); + + sr.Serialize ("ProtectionKdfNull", ProtectionKdf == nullptr); + if (ProtectionKdf) + sr.Serialize ("ProtectionKdf", ProtectionKdf->GetName()); } TC_SERIALIZER_FACTORY_ADD_CLASS (MountOptions); diff --git a/src/Core/MountOptions.h b/src/Core/MountOptions.h old mode 100755 new mode 100644 index 6cb2c549..8ccbffa0 --- a/src/Core/MountOptions.h +++ b/src/Core/MountOptions.h @@ -31,7 +31,8 @@ namespace VeraCrypt Removable (false), SharedAccessAllowed (false), SlotNumber (0), - UseBackupHeaders (false) + UseBackupHeaders (false), + TrueCryptMode (false) { } @@ -63,6 +64,7 @@ namespace VeraCrypt bool SharedAccessAllowed; VolumeSlotNumber SlotNumber; bool UseBackupHeaders; + bool TrueCryptMode; protected: void CopyFrom (const MountOptions &other); diff --git a/src/Core/Unix/CoreUnix.cpp b/src/Core/Unix/CoreUnix.cpp index d33e4b73..0625ed6b 100755 --- a/src/Core/Unix/CoreUnix.cpp +++ b/src/Core/Unix/CoreUnix.cpp @@ -410,6 +410,7 @@ namespace VeraCrypt options.PreserveTimestamps, options.Password, options.Kdf, + options.TrueCryptMode, options.Keyfiles, options.Protection, options.ProtectionPassword, -- cgit v1.2.3