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/Volume/Volume.cpp | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) (limited to 'src/Volume/Volume.cpp') diff --git a/src/Volume/Volume.cpp b/src/Volume/Volume.cpp index 362b342c..f1f248ba 100755 --- a/src/Volume/Volume.cpp +++ b/src/Volume/Volume.cpp @@ -23,7 +23,8 @@ namespace VeraCrypt VolumeDataSize (0), TopWriteOffset (0), TotalDataRead (0), - TotalDataWritten (0) + TotalDataWritten (0), + TrueCryptMode (false) { } @@ -62,7 +63,7 @@ namespace VeraCrypt return EA->GetMode(); } - void Volume::Open (const VolumePath &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) + void Volume::Open (const VolumePath &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) { make_shared_auto (File, file); @@ -93,14 +94,21 @@ namespace VeraCrypt throw; } - return Open (file, password, kdf, keyfiles, protection, protectionPassword, protectionKdf,protectionKeyfiles, volumeType, useBackupHeaders, partitionInSystemEncryptionScope); + return Open (file, password, kdf, truecryptMode, keyfiles, protection, protectionPassword, protectionKdf,protectionKeyfiles, volumeType, useBackupHeaders, partitionInSystemEncryptionScope); } - void Volume::Open (shared_ptr volumeFile, shared_ptr password, shared_ptr kdf, shared_ptr keyfiles, VolumeProtection::Enum protection, shared_ptr protectionPassword, shared_ptr protectionKdf,shared_ptr protectionKeyfiles, VolumeType::Enum volumeType, bool useBackupHeaders, bool partitionInSystemEncryptionScope) + void Volume::Open (shared_ptr volumeFile, shared_ptr password, shared_ptr kdf, bool truecryptMode, shared_ptr keyfiles, VolumeProtection::Enum protection, shared_ptr protectionPassword, shared_ptr protectionKdf,shared_ptr protectionKeyfiles, VolumeType::Enum volumeType, bool useBackupHeaders, bool partitionInSystemEncryptionScope) { if (!volumeFile) throw ParameterIncorrect (SRC_POS); + // TrueCrypt doesn't support SHA-256 + if (kdf && truecryptMode && (kdf->GetName() == L"HMAC-SHA-256")) + throw UnsupportedAlgoInTrueCryptMode (SRC_POS); + + if (truecryptMode && partitionInSystemEncryptionScope) + throw ParameterIncorrect (SRC_POS); + Protection = protection; VolumeFile = volumeFile; SystemEncryption = partitionInSystemEncryptionScope; @@ -182,11 +190,11 @@ namespace VeraCrypt shared_ptr header = layout->GetHeader(); - if (header->Decrypt (headerBuffer, *passwordKey, kdf, layout->GetSupportedKeyDerivationFunctions(), layoutEncryptionAlgorithms, layoutEncryptionModes)) + if (header->Decrypt (headerBuffer, *passwordKey, kdf, truecryptMode, layout->GetSupportedKeyDerivationFunctions(truecryptMode), layoutEncryptionAlgorithms, layoutEncryptionModes)) { // Header decrypted - if (typeid (*layout) == typeid (VolumeLayoutV2Normal) && header->GetRequiredMinProgramVersion() < 0x10b) + if (!truecryptMode && typeid (*layout) == typeid (VolumeLayoutV2Normal) && header->GetRequiredMinProgramVersion() < 0x10b) { // VolumeLayoutV1Normal has been opened as VolumeLayoutV2Normal layout.reset (new VolumeLayoutV1Normal); @@ -194,6 +202,7 @@ namespace VeraCrypt layout->SetHeader (header); } + TrueCryptMode = truecryptMode; Type = layout->GetType(); SectorSize = header->GetSectorSize(); @@ -231,7 +240,7 @@ namespace VeraCrypt Volume protectedVolume; protectedVolume.Open (VolumeFile, - protectionPassword, protectionKdf, protectionKeyfiles, + protectionPassword, protectionKdf, truecryptMode, protectionKeyfiles, VolumeProtection::ReadOnly, shared_ptr (), shared_ptr (),shared_ptr (), VolumeType::Hidden, @@ -269,11 +278,12 @@ namespace VeraCrypt Buffer mbr (VolumeFile->GetDeviceSectorSize()); driveDevice.ReadAt (mbr, 0); - // Search for the string "VeraCrypt" - size_t nameLen = strlen (TC_APP_NAME); + // Search for the string "VeraCrypt" or "TrueCrypt" + const char* bootSignature = truecryptMode? "TrueCrypt" : TC_APP_NAME; + size_t nameLen = strlen (bootSignature); for (size_t i = 0; i < mbr.Size() - nameLen; ++i) { - if (memcmp (mbr.Ptr() + i, TC_APP_NAME, nameLen) == 0) + if (memcmp (mbr.Ptr() + i, bootSignature, nameLen) == 0) throw PasswordOrMountOptionsIncorrect (SRC_POS); } } -- cgit v1.2.3