VeraCrypt
aboutsummaryrefslogtreecommitdiff
path: root/src/Main/Forms/VolumeCreationWizard.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/Main/Forms/VolumeCreationWizard.cpp')
-rw-r--r--src/Main/Forms/VolumeCreationWizard.cpp234
1 files changed, 162 insertions, 72 deletions
diff --git a/src/Main/Forms/VolumeCreationWizard.cpp b/src/Main/Forms/VolumeCreationWizard.cpp
index b6d60f42..2653ff66 100644
--- a/src/Main/Forms/VolumeCreationWizard.cpp
+++ b/src/Main/Forms/VolumeCreationWizard.cpp
@@ -14,6 +14,7 @@
#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"
@@ -58,6 +59,7 @@ namespace VeraCrypt
SelectedVolumeHostType (VolumeHostType::File),
SelectedVolumeType (VolumeType::Normal),
Pim (0),
+ OuterPim (0),
SectorSize (0),
VolumeSize (0)
{
@@ -92,6 +94,8 @@ namespace VeraCrypt
VolumeCreationWizard::~VolumeCreationWizard ()
{
+ burn (&Pim, sizeof (Pim));
+ burn (&OuterPim, sizeof (OuterPim));
}
WizardPage *VolumeCreationWizard::GetPage (WizardStep step)
@@ -113,7 +117,7 @@ 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;
@@ -134,7 +138,7 @@ 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"]);
@@ -175,8 +179,8 @@ 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 is 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
{
@@ -242,11 +246,9 @@ 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;
@@ -254,10 +256,13 @@ namespace VeraCrypt
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)
@@ -270,13 +275,12 @@ 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;
@@ -305,7 +309,7 @@ namespace VeraCrypt
page->SetPageTitle (LangString["FORMAT_FINISHED_TITLE"]);
page->SetPageText (LangString["FORMAT_FINISHED_HELP"]);
- SetCancelButtonText (_("Exit"));
+ SetCancelButtonText (LangString["IDC_EXIT"]);
return page;
}
@@ -346,13 +350,12 @@ namespace VeraCrypt
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;
@@ -462,25 +465,7 @@ namespace VeraCrypt
#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;
- case VolumeCreationOptions::FilesystemType::APFS: fsFormatter = "newfs_apfs"; 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)
{
@@ -494,10 +479,12 @@ namespace VeraCrypt
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
@@ -540,6 +527,16 @@ namespace VeraCrypt
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);
@@ -643,7 +640,7 @@ namespace VeraCrypt
{
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();
}
}
@@ -678,11 +675,11 @@ namespace VeraCrypt
{
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
@@ -692,7 +689,7 @@ 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();
}
}
@@ -792,13 +789,31 @@ 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)
@@ -818,15 +833,42 @@ 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)
@@ -844,15 +886,6 @@ 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)
@@ -888,6 +921,18 @@ 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();
@@ -912,7 +957,7 @@ namespace VeraCrypt
}
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;
}
@@ -930,15 +975,15 @@ 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 = 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
}
@@ -950,7 +995,7 @@ namespace VeraCrypt
{
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())
@@ -985,7 +1030,9 @@ namespace VeraCrypt
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);
@@ -1026,6 +1073,12 @@ namespace VeraCrypt
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:
@@ -1035,12 +1088,23 @@ namespace VeraCrypt
// 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();
}
@@ -1062,8 +1126,22 @@ namespace VeraCrypt
});
#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
@@ -1079,6 +1157,18 @@ namespace VeraCrypt
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)
{