diff options
Diffstat (limited to 'src/Main/Forms/VolumeCreationWizard.cpp')
-rw-r--r-- | src/Main/Forms/VolumeCreationWizard.cpp | 283 |
1 files changed, 195 insertions, 88 deletions
diff --git a/src/Main/Forms/VolumeCreationWizard.cpp b/src/Main/Forms/VolumeCreationWizard.cpp index 776e98eb..311738ca 100644 --- a/src/Main/Forms/VolumeCreationWizard.cpp +++ b/src/Main/Forms/VolumeCreationWizard.cpp @@ -3,9 +3,9 @@ Copyright (c) 2008-2012 TrueCrypt Developers Association and which is governed by the TrueCrypt License 3.0. Modifications and additions to the original source code (contained in this file) - and all other portions of this file are Copyright (c) 2013-2016 IDRIX + and all other portions of this file are Copyright (c) 2013-2017 IDRIX and are governed by the Apache License 2.0 the full text of which is contained in the file License.txt included in VeraCrypt binary and source code distribution packages. */ @@ -13,8 +13,9 @@ #include "System.h" #include "Platform/SystemInfo.h" #ifdef TC_UNIX #include <unistd.h> +#include <sys/statvfs.h> // header for statvfs #include "Platform/Unix/Process.h" #endif #include "Core/RandomNumberGenerator.h" #include "Core/VolumeCreator.h" @@ -35,8 +36,32 @@ #include "WaitDialog.h" namespace VeraCrypt { + class OpenOuterVolumeFunctor : public Functor + { + public: + OpenOuterVolumeFunctor (const DirectoryPath &outerVolumeMountPoint) : OuterVolumeMountPoint (outerVolumeMountPoint) { } + + virtual void operator() () + { + Gui->OpenExplorerWindow (OuterVolumeMountPoint); + } + + DirectoryPath OuterVolumeMountPoint; + }; + +#ifdef TC_MACOSX + + bool VolumeCreationWizard::ProcessEvent(wxEvent& event) + { + if(GraphicUserInterface::HandlePasswordEntryCustomEvent (event)) + return true; + else + return WizardFrame::ProcessEvent(event); + } +#endif + VolumeCreationWizard::VolumeCreationWizard (wxWindow* parent) : WizardFrame (parent), CrossPlatformSupport (true), DisplayKeyInfo (false), @@ -46,16 +71,21 @@ namespace VeraCrypt SelectedFilesystemType (VolumeCreationOptions::FilesystemType::FAT), SelectedVolumeHostType (VolumeHostType::File), SelectedVolumeType (VolumeType::Normal), Pim (0), + OuterPim (0), SectorSize (0), VolumeSize (0) { RandomNumberGenerator::Start(); SetTitle (LangString["INTRO_TITLE"]); SetImage (Resources::GetVolumeCreationWizardBitmap (Gui->GetCharHeight (this) * 21)); SetMaxStaticTextWidth (55); + +#ifdef TC_MACOSX + GraphicUserInterface::InstallPasswordEntryCustomKeyboardShortcuts (this); +#endif SetStep (Step::VolumeHostType); class Timer : public wxTimer @@ -76,8 +106,10 @@ namespace VeraCrypt } VolumeCreationWizard::~VolumeCreationWizard () { + burn (&Pim, sizeof (Pim)); + burn (&OuterPim, sizeof (OuterPim)); } WizardPage *VolumeCreationWizard::GetPage (WizardStep step) { @@ -97,9 +129,9 @@ namespace VeraCrypt page->SetPageTitle (LangString["INTRO_TITLE"]); page->AddChoice (VolumeHostType::File, LangString["IDC_FILE_CONTAINER"], LangString["IDT_FILE_CONTAINER"], L"introcontainer", LangString["IDC_MORE_INFO_ON_CONTAINERS"]); - page->AddChoice (VolumeHostType::Device, _("Create a volume within a partition/&drive"), _("Formats and encrypts a non-system partition, entire external or secondary drive, entire USB stick, etc.")); + page->AddChoice (VolumeHostType::Device, LangString["IDC_NONSYS_DEVICE"], LangString["IDT_NON_SYS_DEVICE"]); page->SetSelection (SelectedVolumeHostType); return page; } @@ -118,9 +150,9 @@ namespace VeraCrypt case Step::VolumeLocation: { VolumeLocationWizardPage *page = new VolumeLocationWizardPage (GetPageParent(), SelectedVolumeHostType); - page->SetPageTitle (LangString["VOLUME_LOCATION"]); + page->SetPageTitle (LangString["LOCATION"]); if (SelectedVolumeType == VolumeType::Hidden) page->SetPageText (LangString[SelectedVolumeHostType == VolumeHostType::File ? "FILE_HELP_HIDDEN_HOST_VOL" : "DEVICE_HELP_HIDDEN_HOST_VOL"]); else @@ -159,10 +191,10 @@ namespace VeraCrypt } else if (SelectedVolumeType == VolumeType::Hidden) { pageTitle = LangString["SIZE_HIDVOL_TITLE"]; - pageText = LangString["SIZE_HELP_HIDDEN_VOL"] + L"\n\n" + _("Please note that if your operating system does not allocate files from the beginning of the free space, the maximum possible hidden volume size may be much smaller than the size of the free space on the outer volume. This not a bug in VeraCrypt but a limitation of the operating system."); - freeSpaceText = StringFormatter (_("Maximum possible hidden volume size for this volume is {0}."), Gui->SizeToString (MaxHiddenVolumeSize)); + pageText = LangString["SIZE_HELP_HIDDEN_VOL"] + L"\n\n" + LangString["LINUX_DYNAMIC_NOTICE"]; + freeSpaceText = StringFormatter (LangString["LINUX_MAX_HIDDEN_SIZE"], Gui->SizeToString (MaxHiddenVolumeSize)); } else { pageTitle = LangString["SIZE_TITLE"]; @@ -226,24 +258,25 @@ namespace VeraCrypt { SingleChoiceWizardPage <bool> *page = new SingleChoiceWizardPage <bool> (GetPageParent(), wxEmptyString, true); page->SetPageTitle (LangString["FILESYS_PAGE_TITLE"]); - page->AddChoice (false, _("I will not store files larger than 4 GB on the volume"), - _("Choose this option if you do not need to store files larger than 4 GB (4,294,967,296 bytes) on the volume.")); + page->AddChoice (true, LangString["UISTR_YES"],LangString["FILESYS_PAGE_HELP_QUESTION"]); - page->AddChoice (true, _("I will store files larger than 4 GB on the volume"), - _("Choose this option if you need to store files larger than 4 GB (4,294,967,296 bytes) on the volume.")); + page->AddChoice (false, LangString["UISTR_NO"],LangString["FILESYS_PAGE_HELP_EXPLANATION"]); page->SetSelection (LargeFilesSupport); return page; } case Step::FormatOptions: { - VolumeFormatOptionsWizardPage *page = new VolumeFormatOptionsWizardPage (GetPageParent(), VolumeSize, SectorSize, + shared_ptr <VolumeLayout> layout ((OuterVolume || SelectedVolumeType != VolumeType::Hidden)? (VolumeLayout*) new VolumeLayoutV2Normal() : (VolumeLayout*) new VolumeLayoutV2Hidden()); + uint64 filesystemSize = layout->GetMaxDataSize (VolumeSize); + + VolumeFormatOptionsWizardPage *page = new VolumeFormatOptionsWizardPage (GetPageParent(), filesystemSize, SectorSize, SelectedVolumePath.IsDevice() && (OuterVolume || SelectedVolumeType != VolumeType::Hidden), OuterVolume, LargeFilesSupport); - page->SetPageTitle (_("Format Options")); + page->SetPageTitle (LangString["FORMAT_TITLE"]); page->SetFilesystemType (SelectedFilesystemType); if (!OuterVolume && SelectedVolumeType == VolumeType::Hidden) QuickFormatEnabled = true; @@ -254,15 +287,14 @@ namespace VeraCrypt case Step::CrossPlatformSupport: { SingleChoiceWizardPage <bool> *page = new SingleChoiceWizardPage <bool> (GetPageParent(), wxEmptyString, true); - page->SetPageTitle (_("Cross-Platform Support")); + page->SetPageTitle ( LangString["LINUX_CROSS_SUPPORT"]); - page->AddChoice (true, _("I will mount the volume on other platforms"), - _("Choose this option if you need to use the volume on other platforms.")); + page->AddChoice (true, LangString["LINUX_CROSS_SUPPORT_OTHER"], LangString["LINUX_CROSS_SUPPORT_OTHER_HELP"]); - page->AddChoice (false, StringFormatter (_("I will mount the volume only on {0}"), SystemInfo::GetPlatformName()), - _("Choose this option if you do not need to use the volume on other platforms.")); + page->AddChoice (false, StringFormatter ( LangString["LINUX_CROSS_SUPPORT_ONLY"], SystemInfo::GetPlatformName()), + LangString["LINUX_CROSS_SUPPORT_ONLY_HELP"]); page->SetSelection (CrossPlatformSupport); return page; } @@ -289,9 +321,9 @@ namespace VeraCrypt InfoWizardPage *page = new InfoWizardPage (GetPageParent()); page->SetPageTitle (LangString["FORMAT_FINISHED_TITLE"]); page->SetPageText (LangString["FORMAT_FINISHED_HELP"]); - SetCancelButtonText (_("Exit")); + SetCancelButtonText (LangString["IDC_EXIT"]); return page; } case Step::OuterVolumeContents: @@ -318,27 +350,14 @@ namespace VeraCrypt Close(); return new InfoWizardPage (GetPageParent()); } - struct OpenOuterVolumeFunctor : public Functor - { - OpenOuterVolumeFunctor (const DirectoryPath &outerVolumeMountPoint) : OuterVolumeMountPoint (outerVolumeMountPoint) { } - - virtual void operator() () - { - Gui->OpenExplorerWindow (OuterVolumeMountPoint); - } - - DirectoryPath OuterVolumeMountPoint; - }; - - InfoWizardPage *page = new InfoWizardPage (GetPageParent(), _("Open Outer Volume"), + InfoWizardPage *page = new InfoWizardPage (GetPageParent(), LangString["LINUX_OPEN_OUTER_VOL"], shared_ptr <Functor> (new OpenOuterVolumeFunctor (MountedOuterVolume->MountPoint))); page->SetPageTitle (LangString["HIDVOL_HOST_FILLING_TITLE"]); - page->SetPageText (StringFormatter ( - _("Outer volume has been successfully created and mounted as '{0}'. To this volume you should now copy some sensitive-looking files that you actually do NOT want to hide. The files will be there for anyone forcing you to disclose your password. You will reveal only the password for this outer volume, not for the hidden one. The files that you really care about will be stored in the hidden volume, which will be created later on. When you finish copying, click Next. Do not dismount the volume.\n\nNote: After you click Next, the outer volume will be analyzed to determine the size of uninterrupted area of free space whose end is aligned with the end of the volume. This area will accommodate the hidden volume, so it will limit its maximum possible size. The procedure ensures no data on the outer volume are overwritten by the hidden volume."), + page->SetPageText (StringFormatter (LangString["LINUX_OUTER_VOL_IS_MOUNTED"], wstring (MountedOuterVolume->MountPoint))); return page; } @@ -371,14 +390,14 @@ namespace VeraCrypt { event.Skip(); if (!IsWorkInProgress() && RandomNumberGenerator::IsRunning()) { - RandomNumberGenerator::AddToPool (ConstBufferPtr (reinterpret_cast <byte *> (&event), sizeof (event))); + RandomNumberGenerator::AddToPool (ConstBufferPtr (reinterpret_cast <uint8 *> (&event), sizeof (event))); long coord = event.GetX(); - RandomNumberGenerator::AddToPool (ConstBufferPtr (reinterpret_cast <byte *> (&coord), sizeof (coord))); + RandomNumberGenerator::AddToPool (ConstBufferPtr (reinterpret_cast <uint8 *> (&coord), sizeof (coord))); coord = event.GetY(); - RandomNumberGenerator::AddToPool (ConstBufferPtr (reinterpret_cast <byte *> (&coord), sizeof (coord))); + RandomNumberGenerator::AddToPool (ConstBufferPtr (reinterpret_cast <uint8 *> (&coord), sizeof (coord))); VolumeCreationProgressWizardPage *page = dynamic_cast <VolumeCreationProgressWizardPage *> (GetCurrentPage()); if (page) { @@ -423,9 +442,9 @@ namespace VeraCrypt { if (!IsWorkInProgress()) { wxLongLong time = wxGetLocalTimeMillis(); - RandomNumberGenerator::AddToPool (ConstBufferPtr (reinterpret_cast <byte *> (&time), sizeof (time))); + RandomNumberGenerator::AddToPool (ConstBufferPtr (reinterpret_cast <uint8 *> (&time), sizeof (time))); } } void VolumeCreationWizard::OnVolumeCreatorFinished () @@ -446,26 +465,9 @@ namespace VeraCrypt Creator->CheckResult(); #ifdef TC_UNIX // Format non-FAT filesystem - const char *fsFormatter = nullptr; - - switch (SelectedFilesystemType) - { -#if defined (TC_LINUX) - case VolumeCreationOptions::FilesystemType::Ext2: fsFormatter = "mkfs.ext2"; break; - case VolumeCreationOptions::FilesystemType::Ext3: fsFormatter = "mkfs.ext3"; break; - case VolumeCreationOptions::FilesystemType::Ext4: fsFormatter = "mkfs.ext4"; break; - case VolumeCreationOptions::FilesystemType::NTFS: fsFormatter = "mkfs.ntfs"; break; - case VolumeCreationOptions::FilesystemType::exFAT: fsFormatter = "mkfs.exfat"; break; -#elif defined (TC_MACOSX) - case VolumeCreationOptions::FilesystemType::MacOsExt: fsFormatter = "newfs_hfs"; break; - case VolumeCreationOptions::FilesystemType::exFAT: fsFormatter = "newfs_exfat"; break; -#elif defined (TC_FREEBSD) || defined (TC_SOLARIS) - case VolumeCreationOptions::FilesystemType::UFS: fsFormatter = "newfs" ; break; -#endif - default: break; - } + const char *fsFormatter = VolumeCreationOptions::FilesystemType::GetFsFormatter (SelectedFilesystemType); if (fsFormatter) { wxBusyCursor busy; @@ -477,12 +479,14 @@ namespace VeraCrypt mountOptions.Password = Password; mountOptions.Pim = Pim; mountOptions.Keyfiles = Keyfiles; mountOptions.Kdf = Kdf; - mountOptions.TrueCryptMode = false; shared_ptr <VolumeInfo> volume = Core->MountVolume (mountOptions); finally_do_arg (shared_ptr <VolumeInfo>, volume, { Core->DismountVolume (finally_arg, true); }); + + shared_ptr <VolumeLayout> layout((volume->Type == VolumeType::Normal)? (VolumeLayout*) new VolumeLayoutV2Normal() : (VolumeLayout*) new VolumeLayoutV2Hidden()); + uint64 filesystemSize = layout->GetMaxDataSize (VolumeSize); Thread::Sleep (2000); // Try to prevent race conditions caused by OS // Temporarily take ownership of the device if the user is not an administrator @@ -523,8 +527,18 @@ namespace VeraCrypt // Perform a quick NTFS formatting if (SelectedFilesystemType == VolumeCreationOptions::FilesystemType::NTFS) args.push_back ("-f"); + if (SelectedFilesystemType == VolumeCreationOptions::FilesystemType::Btrfs) + { + args.push_back ("-f"); + if (filesystemSize < VC_MIN_LARGE_BTRFS_VOLUME_SIZE) + { + // use mixed mode for small BTRFS volumes + args.push_back ("-M"); + } + } + args.push_back (string (virtualDevice)); Process::Execute (fsFormatter, args); } @@ -626,9 +640,9 @@ namespace VeraCrypt foreach_ref (const HostDevice &partition, drive.Partitions) { if (partition.MountPoint == "/") { - Gui->ShowError (_("Error: You are trying to encrypt a system drive.\n\nVeraCrypt can encrypt a system drive only under Windows.")); + Gui->ShowError (LangString["LINUX_ERROR_TRY_ENCRYPT_SYSTEM_DRIVE"]); return GetCurrentStep(); } } @@ -661,13 +675,13 @@ namespace VeraCrypt if (!mountPoint.IsEmpty()) { if (mountPoint == "/") { - Gui->ShowError (_("Error: You are trying to encrypt a system partition.\n\nVeraCrypt can encrypt system partitions only under Windows.")); + Gui->ShowError (LangString["LINUX_ERROR_TRY_ENCRYPT_SYSTEM_PARTITION"]); return GetCurrentStep(); } - if (!Gui->AskYesNo (StringFormatter (_("WARNING: Formatting of the device will destroy all data on filesystem '{0}'.\n\nDo you want to continue?"), wstring (mountPoint)), false, true)) + if (!Gui->AskYesNo (StringFormatter (LangString["LINUX_WARNING_FORMAT_DESTROY_FS"], wstring (mountPoint)), false, true)) return GetCurrentStep(); try { @@ -675,9 +689,9 @@ namespace VeraCrypt } catch (exception &e) { Gui->ShowError (e); - Gui->ShowError (StringFormatter (_("The filesystem of the selected device is currently mounted. Please dismount '{0}' before proceeding."), wstring (mountPoint))); + Gui->ShowError (StringFormatter (LangString["LINUX_MOUNTET_HINT"], wstring (mountPoint))); return GetCurrentStep(); } } } @@ -775,15 +789,33 @@ namespace VeraCrypt { // Clear PIM Pim = 0; - // Skip PIM - if (forward && OuterVolume) + if (forward && !OuterVolume && SelectedVolumeType == VolumeType::Hidden) { - // Use FAT to prevent problems with free space - QuickFormatEnabled = false; - SelectedFilesystemType = VolumeCreationOptions::FilesystemType::FAT; - return Step::CreationProgress; + shared_ptr <VolumePassword> hiddenPassword; + try + { + hiddenPassword = Keyfile::ApplyListToPassword (Keyfiles, Password, Gui->GetPreferences().EMVSupportEnabled); + } + catch (...) + { + hiddenPassword = Password; + } + + // check if Outer and Hidden passwords are the same + if ( (hiddenPassword && !hiddenPassword->IsEmpty() && OuterPassword && !OuterPassword->IsEmpty() && (*(OuterPassword.get()) == *(hiddenPassword.get()))) + || + ((!hiddenPassword || hiddenPassword->IsEmpty()) && (!OuterPassword || OuterPassword->IsEmpty())) + ) + { + //check if they have also the same PIM + if (OuterPim == Pim) + { + Gui->ShowError (LangString["LINUX_HIDDEN_PASS_NO_DIFF"]); + return GetCurrentStep(); + } + } } if (VolumeSize > 4 * BYTES_PER_GB) { @@ -801,17 +833,44 @@ namespace VeraCrypt { VolumePimWizardPage *page = dynamic_cast <VolumePimWizardPage *> (GetCurrentPage()); Pim = page->GetVolumePim(); - if (forward && Password && !Password->IsEmpty()) + if (-1 == Pim) + { + // PIM invalid: don't go anywhere + Gui->ShowError ("PIM_TOO_BIG"); + return GetCurrentStep(); + } + + if (forward && !OuterVolume && SelectedVolumeType == VolumeType::Hidden) { - if (-1 == Pim) + shared_ptr <VolumePassword> hiddenPassword; + try { - // PIM invalid: don't go anywhere - Gui->ShowError ("PIM_TOO_BIG"); - return GetCurrentStep(); + hiddenPassword = Keyfile::ApplyListToPassword (Keyfiles, Password, Gui->GetPreferences().EMVSupportEnabled); + } + catch (...) + { + hiddenPassword = Password; } + // check if Outer and Hidden passwords are the same + if ( (hiddenPassword && !hiddenPassword->IsEmpty() && OuterPassword && !OuterPassword->IsEmpty() && (*(OuterPassword.get()) == *(hiddenPassword.get()))) + || + ((!hiddenPassword || hiddenPassword->IsEmpty()) && (!OuterPassword || OuterPassword->IsEmpty())) + ) + { + //check if they have also the same PIM + if (OuterPim == Pim) + { + Gui->ShowError (LangString["LINUX_HIDDEN_PASS_NO_DIFF"]); + return GetCurrentStep(); + } + } + } + + if (forward && Password && !Password->IsEmpty()) + { if (Password->Size() < VolumePassword::WarningSizeThreshold) { if (Pim > 0 && Pim < 485) { @@ -827,17 +886,8 @@ namespace VeraCrypt } } } - - if (forward && OuterVolume) - { - // Use FAT to prevent problems with free space - QuickFormatEnabled = false; - SelectedFilesystemType = VolumeCreationOptions::FilesystemType::FAT; - return Step::CreationProgress; - } - if (VolumeSize > 4 * BYTES_PER_GB) { if (VolumeSize <= TC_MAX_FAT_SECTOR_COUNT * SectorSize) return Step::LargeFilesSupport; @@ -871,8 +921,20 @@ namespace VeraCrypt case Step::FormatOptions: { VolumeFormatOptionsWizardPage *page = dynamic_cast <VolumeFormatOptionsWizardPage *> (GetCurrentPage()); + + if (forward && OuterVolume) + { + if (page->GetFilesystemType() != VolumeCreationOptions::FilesystemType::FAT) + { + if (!Gui->AskYesNo (LangString["LINUX_CONFIRM_INNER_VOLUME_CALC"], false, true)) + { + return GetCurrentStep(); + } + } + } + SelectedFilesystemType = page->GetFilesystemType(); QuickFormatEnabled = page->IsQuickFormatEnabled(); if (SelectedFilesystemType != VolumeCreationOptions::FilesystemType::None @@ -895,9 +957,9 @@ namespace VeraCrypt return GetCurrentStep(); } if (forward && CrossPlatformSupport) - Gui->ShowWarning (StringFormatter (_("Please note that the volume will not be formatted with a FAT filesystem and, therefore, you may be required to install additional filesystem drivers on platforms other than {0}, which will enable you to mount the volume."), SystemInfo::GetPlatformName())); + Gui->ShowWarning (StringFormatter (LangString["LINUX_NOT_FAT_HINT"], SystemInfo::GetPlatformName())); return Step::CreationProgress; } @@ -913,17 +975,17 @@ namespace VeraCrypt { if (OuterVolume && VolumeSize > TC_MAX_FAT_SECTOR_COUNT * SectorSize) { uint64 limit = TC_MAX_FAT_SECTOR_COUNT * SectorSize / BYTES_PER_TB; - wstring err = StringFormatter (_("Error: The hidden volume to be created is larger than {0} TB ({1} GB).\n\nPossible solutions:\n- Create a container/partition smaller than {0} TB.\n"), limit, limit * 1024); + wstring err = static_cast<wstring>(StringFormatter (LangString["LINUX_ERROR_SIZE_HIDDEN_VOL"], limit, limit * 1024)); if (SectorSize < 4096) { - err += _("- Use a drive with 4096-byte sectors to be able to create partition/device-hosted hidden volumes up to 16 TB in size"); + err += LangString["LINUX_MAX_SIZE_HINT"]; #if defined (TC_LINUX) - err += _(".\n"); + err += LangString["LINUX_DOT_LF"]; #else - err += _(" (not supported by components available on this platform).\n"); + err += LangString["LINUX_NOT_SUPPORTED"]; #endif } Gui->ShowError (err); @@ -933,9 +995,9 @@ namespace VeraCrypt if (SelectedVolumePath.IsDevice()) { wxString confirmMsg = LangString["OVERWRITEPROMPT_DEVICE"]; - if (!Gui->AskYesNo (wxString::Format (confirmMsg, wxString (_("DEVICE")).c_str(), wstring (SelectedVolumePath).c_str(), L""), false, true)) + if (!Gui->AskYesNo (wxString::Format (confirmMsg, wxString (LangString["DEVICE"]).c_str(), wstring (SelectedVolumePath).c_str(), L""), false, true)) return GetCurrentStep(); } else if (FilesystemPath (wstring (SelectedVolumePath)).IsFile()) { @@ -968,9 +1030,11 @@ namespace VeraCrypt options->Path = SelectedVolumePath; options->Quick = QuickFormatEnabled; options->Size = VolumeSize; options->Type = OuterVolume ? VolumeType::Normal : SelectedVolumeType; - options->VolumeHeaderKdf = Pkcs5Kdf::GetAlgorithm (*SelectedHash, false); + options->VolumeHeaderKdf = Pkcs5Kdf::GetAlgorithm (*SelectedHash); + options->EMVSupportEnabled = Gui->GetPreferences().EMVSupportEnabled; + Creator.reset (new VolumeCreator); VolumeCreatorThreadRoutine routine(options, Creator); Gui->ExecuteWaitThreadRoutine (this, &routine); @@ -1009,8 +1073,14 @@ namespace VeraCrypt case Step::VolumeCreatedInfo: Creator.reset(); SetCancelButtonText (L""); + // clear saved credentials + Password.reset(); + OuterPassword.reset(); + burn (&Pim, sizeof (Pim)); + burn (&OuterPim, sizeof (OuterPim)); + return Step::VolumeHostType; case Step::OuterVolumeContents: try @@ -1018,14 +1088,25 @@ namespace VeraCrypt // Determine maximum size of the hidden volume. Scan cluster table offline as a live filesystem test would // require using FUSE and loop device which cannot be used for devices with sectors larger than 512. wxBusyCursor busy; + bool outerVolumeAvailableSpaceValid = false; + uint64 outerVolumeAvailableSpace = 0; MaxHiddenVolumeSize = 0; Gui->SetActiveFrame (this); if (MountedOuterVolume) { +#ifdef TC_UNIX + const DirectoryPath &outerVolumeMountPoint = MountedOuterVolume->MountPoint; + struct statvfs stat; + if (statvfs(((string)outerVolumeMountPoint).c_str(), &stat) == 0) + { + outerVolumeAvailableSpace = (uint64) stat.f_bsize * (uint64) stat.f_bavail; + outerVolumeAvailableSpaceValid = true; + } +#endif Core->DismountVolume (MountedOuterVolume); MountedOuterVolume.reset(); } @@ -1045,10 +1126,24 @@ namespace VeraCrypt Core->SetFileOwner (finally_arg, finally_arg2); }); #endif - shared_ptr <Volume> outerVolume = Core->OpenVolume (make_shared <VolumePath> (SelectedVolumePath), true, Password, Pim, Kdf, false, Keyfiles, VolumeProtection::ReadOnly); - MaxHiddenVolumeSize = Core->GetMaxHiddenVolumeSize (outerVolume); + shared_ptr <Volume> outerVolume = Core->OpenVolume (make_shared <VolumePath> (SelectedVolumePath), true, Password, Pim, Kdf, Keyfiles, VolumeProtection::ReadOnly); + try + { + MaxHiddenVolumeSize = Core->GetMaxHiddenVolumeSize (outerVolume); + } + catch (ParameterIncorrect& ) + { + // Outer volume not using FAT + // estimate maximum hidden volume size as 80% of available size of outer volume + if (outerVolumeAvailableSpaceValid) + { + MaxHiddenVolumeSize =(4ULL * outerVolumeAvailableSpace) / 5ULL; + } + else + throw; + } // Add a reserve (in case the user mounts the outer volume and creates new files // on it by accident or OS writes some new data behind his or her back, such as // System Restore etc.) @@ -1062,8 +1157,20 @@ namespace VeraCrypt else MaxHiddenVolumeSize -= reservedSize; MaxHiddenVolumeSize -= MaxHiddenVolumeSize % outerVolume->GetSectorSize(); // Must be a multiple of the sector size + + // remember Outer password and keyfiles in order to be able to compare it with those of Hidden volume + try + { + OuterPassword = Keyfile::ApplyListToPassword (Keyfiles, Password, Gui->GetPreferences().EMVSupportEnabled); + } + catch (...) + { + OuterPassword = Password; + } + + OuterPim = Pim; } catch (exception &e) { Gui->SetActiveFrame (this); |