VeraCrypt License
Software distributed under this license is distributed on an "AS
IS" BASIS WITHOUT WARRANTIES OF ANY KIND. THE AUTHORS AND
DISTRIBUTORS OF THE SOFTWARE DISCLAIM ANY LIABILITY. ANYONE WHO
USES, COPIES, MODIFIES, OR (RE)DISTRIBUTES ANY PART OF THE
SOFTWARE IS, BY SUCH ACTION(S), ACCEPTING AND AGREEING TO BE
BOUND BY ALL TERMS AND CONDITIONS OF THIS LICENSE. IF YOU DO NOT
ACCEPT THEM, DO NOT USE, COPY, MODIFY, NOR (RE)DISTRIBUTE THE
SOFTWARE, NOR ANY PART(S) THEREOF.
VeraCrypt is multi-licensed under Apache License 2.0 and
the TrueCrypt License version 3.0, a verbatim copy of both
licenses can be found below.
This license does not grant you rights to use any
contributors' name, logo, or trademarks, including IDRIX,
VeraCrypt and all derivative names.
For example, the following names are not allowed: VeraCrypt,
VeraCrypt+, VeraCrypt Professional, iVeraCrypt, etc. Nor any
other names confusingly similar to the name VeraCrypt (e.g.,
Vera-Crypt, Vera Crypt, VerKrypt, etc.)
____________________________________________________________
Apache License
Version 2.0, January 2004
https://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
____________________________________________________________
TrueCrypt License Version 3.0
Software distributed under this license is distributed on an "AS
IS" BASIS WITHOUT WARRANTIES OF ANY KIND. THE AUTHORS AND
DISTRIBUTORS OF THE SOFTWARE DISCLAIM ANY LIABILITY. ANYONE WHO
USES, COPIES, MODIFIES, OR (RE)DISTRIBUTES ANY PART OF THE
SOFTWARE IS, BY SUCH ACTION(S), ACCEPTING AND AGREEING TO BE
BOUND BY ALL TERMS AND CONDITIONS OF THIS LICENSE. IF YOU DO NOT
ACCEPT THEM, DO NOT USE, COPY, MODIFY, NOR (RE)DISTRIBUTE THE
SOFTWARE, NOR ANY PART(S) THEREOF.
I. Definitions
1. "This Product" means the work (including, but not limited to,
source code, graphics, texts, and accompanying files) made
available under and governed by this version of this license
("License"), as may be indicated by, but is not limited to,
copyright notice(s) attached to or included in the work.
2. "You" means (and "Your" refers to) an individual or a legal
entity (e.g., a non-profit organization, commercial
organization, government agency, etc.) exercising permissions
granted by this License.
3. "Modification" means (and "modify" refers to) any alteration
of This Product, including, but not limited to, addition to or
deletion from the substance or structure of This Product,
translation into another language, repackaging, alteration or
removal of any file included with This Product, and addition of
any new files to This Product.
4. "Your Product" means This Product modified by You, or any
work You derive from (or base on) any part of This Product. In
addition, "Your Product" means any work in which You include any
(modified or unmodified) portion of This Product. However, if
the work in which you include it is an aggregate software
distribution (such as an operating system distribution or a
cover CD-ROM of a magazine) containing multiple separate
products, then the term "Your Product" includes only those
products (in the aggregate software distribution) that use,
include, or depend on a modified or unmodified version of This
Product (and the term "Your Product" does not include the whole
aggregate software distribution). For the purposes of this
License, a product suite consisting of two or more products is
considered a single product (operating system distributions and
cover media of magazines are not considered product suites).
5. "Distribution" means (and "distribute" refers to), regardless
of means or methods, conveyance, transfer, providing, or making
available of This/Your Product or portions thereof to third
parties (including, but not limited to, making This/Your
Product, or portions thereof, available for download to third
parties, whether or not any third party has downloaded the
product, or any portion thereof, made available for download).
II. Use, Copying, and Distribution of This Product
1. Provided that You comply with all applicable terms and
conditions of this License, You may make copies of This Product
(unmodified) and distribute copies of This Product (unmodified)
that are not included in another product forming Your Product
(except as permitted under Chapter III). Note: For terms and
conditions for copying and distribution of modified versions of
This Product, see Chapter III.
2. Provided that You comply with all applicable terms and
conditions of this License, You may use This Product freely (see
also Chapter III) on any number of computers/systems for non-
commercial and/or commercial purposes.
III. Modification, Derivation, and Inclusion in Other Products
1. If all conditions specified in the following paragraphs in
this Chapter (III) are met (for exceptions, see Section III.2)
and if You comply with all other applicable terms and conditions
of this License, You may modify This Product (thus forming Your
Product), derive new works from This Product or portions thereof
(thus forming Your Product), include This Product or portions
thereof in another product (thus forming Your Product, unless
defined otherwise in Chapter I), and You may use (for non-
commercial and/or commercial purposes), copy, and/or distribute
Your Product.
a. The name of Your Product (or of Your modified version of
This Product) must not contain the name TrueCrypt (for
example, the following names are not allowed: TrueCrypt,
TrueCrypt+, TrueCrypt Professional, iTrueCrypt, etc.) nor
any other names confusingly similar to the name TrueCrypt
(e.g., True-Crypt, True Crypt, TruKrypt, etc.)
All occurrences of the name TrueCrypt that could reasonably
be considered to identify Your Product must be removed from
Your Product and from any associated materials. Logo(s)
included in (or attached to) Your Product (and in/to
associated materials) must not incorporate and must not be
confusingly similar to any of the TrueCrypt logos
(including, but not limited to, the non-textual logo
consisting primarily of a key in stylized form) or
portion(s) thereof. All graphics contained in This Product
(logos, icons, etc.) must be removed from Your Product (or
from Your modified version of This Product) and from any
associated materials.
b. The following phrases must be removed from Your Product
and from any associated materials, except the text of this
License: "A TrueCrypt Foundation Release", "Released by
TrueCrypt Foundation", "This is a TrueCrypt Foundation
release."
c. Phrase "Based on TrueCrypt, freely available at
http://www.truecrypt.org/" must be displayed by Your Product
(if technically feasible) and contained in its
documentation. Alternatively, if This Product or its portion
You included in Your Product constitutes only a minor
portion of Your Product, phrase "Portions of this product
are based in part on TrueCrypt, freely available at
http://www.truecrypt.org/" may be displayed instead. In each
of the cases mentioned above in this paragraph,
"http://www.truecrypt.org/" must be a hyperlink (if
technically feasible) pointing to http://www.truecrypt.org/
and You may freely choose the location within the user
interface (if there is any) of Your Product (e.g., an
"About" window, etc.) and the way in which Your Product will
display the respective phrase.
Your Product (and any associated materials, e.g., the
documentation, the content of the official web site of Your
Product, etc.) must not present any Internet address
containing the domain name truecrypt.org (or any domain name
that forwards to the domain name truecrypt.org) in a manner
that might suggest that it is where information about Your
Product may be obtained or where bugs found in Your Product
may be reported or where support for Your Product may be
available or otherwise attempt to indicate that the domain
name truecrypt.org is associated with Your Product.
d. The complete source code of Your Product must be freely
and publicly available (for exceptions, see Section III.2)
at least until You cease to distribute Your Product. This
condition can be met in one or both of the following ways:
(i) You include the complete source code of Your Product
with every copy of Your Product that You make and distribute
and You make all such copies of Your Product available to
the general public free of charge, and/or (ii) You include
information (valid and correct at least until You cease to
distribute Your Product) about where the complete source
code of Your Product can be obtained free of charge (e.g.,
an Internet address) or for a reasonable reproduction fee
with every copy of Your Product that You make and distribute
and, if there is a web site officially associated with Your
Product, You include the aforementioned information about
the source code on a freely and publicly accessible web
page to which such web site links via an easily viewable
hyperlink (at least until You cease to distribute Your
Product).
The source code of Your Product must not be deliberately
obfuscated and it must not be in an intermediate form (e.g.,
the output of a preprocessor). Source code means the
preferred form in which a programmer would usually modify
the program.
Portions of the source code of Your Product not contained in
This Product (e.g., portions added by You in creating Your
Product, whether created by You or by third parties) must be
available under license(s) that (however, see also
Subsection III.1.e) allow(s) anyone to modify and derive new
works from the portions of the source code that are not
contained in This Product and to use, copy, and redistribute
such modifications and/or derivative works. The license(s)
must be perpetual, non-exclusive, royalty-free, no-charge,
and worldwide, and must not invalidate, weaken, restrict,
interpret, amend, modify, interfere with or otherwise affect
any part, term, provision, or clause of this License. The
text(s) of the license(s) must be included with every copy
of Your Product that You make and distribute.
e. You must not change the license terms of This Product in
any way (adding any new terms is considered changing the
license terms even if the original terms are retained),
which means, e.g., that no part of This Product may be put
under another license. You must keep intact all the legal
notices contained in the source code files. You must include
the following items with every copy of Your Product that You
make and distribute: a clear and conspicuous notice stating
that Your Product or portion(s) thereof is/are governed by
this version of the TrueCrypt License, a verbatim copy of
this version of the TrueCrypt License (as contained herein),
a clear and conspicuous notice containing information about
where the included copy of the License can be found, and an
appropriate copyright notice.
2. You are not obligated to comply with Subsection III.1.d if
Your Product is not distributed (i.e., Your Product is available
only to You).
IV. Disclaimer of Liability, Disclaimer of Warranty,
Indemnification
You expressly acknowledge and agree to the following:
1. IN NO EVENT WILL ANY (CO)AUTHOR OF THIS PRODUCT, OR ANY
APPLICABLE INTELLECTUAL-PROPERTY OWNER, OR ANY OTHER PARTY WHO
MAY COPY AND/OR (RE)DISTRIBUTE THIS PRODUCT OR PORTIONS THEREOF,
AS MAY BE PERMITTED HEREIN, BE LIABLE TO YOU OR TO ANY OTHER
PARTY FOR ANY DAMAGES, INCLUDING, BUT NOT LIMITED TO, ANY
DIRECT, INDIRECT, GENERAL, SPECIAL, INCIDENTAL, PUNITIVE,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
TO, CORRUPTION OR LOSS OF DATA, ANY LOSSES SUSTAINED BY YOU OR
THIRD PARTIES, A FAILURE OF THIS PRODUCT TO OPERATE WITH ANY
OTHER PRODUCT, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR
BUSINESS INTERRUPTION), WHETHER IN CONTRACT, STRICT LIABILITY,
TORT (INCLUDING, BUT NOT LIMITED TO, NEGLIGENCE) OR OTHERWISE,
ARISING OUT OF THE USE, COPYING, MODIFICATION, OR
(RE)DISTRIBUTION OF THIS PRODUCT (OR A PORTION THEREOF) OR OF
YOUR PRODUCT (OR A PORTION THEREOF), OR INABILITY TO USE THIS
PRODUCT (OR A PORTION THEREOF), EVEN IF SUCH DAMAGES (OR THE
POSSIBILITY OF SUCH DAMAGES) ARE/WERE PREDICTABLE OR KNOWN TO
ANY (CO)AUTHOR, INTELLECTUAL-PROPERTY OWNER, OR ANY OTHER PARTY.
2. THIS PRODUCT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
KIND, WHETHER EXPRESS, IMPLIED, OR STATUTORY, INCLUDING, BUT NOT
LIMITED TO, THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
PARTICULAR PURPOSE, AND NON-INFRINGEMENT. THE ENTIRE RISK AS TO
THE QUALITY AND PERFORMANCE OF THIS PRODUCT IS WITH YOU. SHOULD
THIS PRODUCT PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL
NECESSARY SERVICING, REPAIR, OR CORRECTION.
3. THIS PRODUCT MAY INCORPORATE IMPLEMENTATIONS OF CRYPTOGRAPHIC
ALGORITHMS THAT ARE REGULATED (E.G., SUBJECT TO EXPORT/IMPORT
CONTROL REGULATIONS) OR ILLEGAL IN SOME COUNTRIES. IT IS SOLELY
YOUR RESPONSIBILITY TO VERIFY THAT IT IS LEGAL TO IMPORT AND/OR
(RE)EXPORT AND/OR USE THIS PRODUCT (OR PORTIONS THEREOF) IN
COUNTRIES WHERE YOU INTEND TO USE IT AND/OR TO WHICH YOU INTEND
TO IMPORT IT AND/OR FROM WHICH YOU INTEND TO EXPORT IT, AND IT
IS SOLELY YOUR RESPONSIBILITY TO COMPLY WITH ANY APPLICABLE
REGULATIONS, RESTRICTIONS, AND LAWS.
4. YOU SHALL INDEMNIFY, DEFEND AND HOLD ALL (CO)AUTHORS OF THIS
PRODUCT, AND APPLICABLE INTELLECTUAL-PROPERTY OWNERS, HARMLESS
FROM AND AGAINST ANY AND ALL LIABILITY, DAMAGES, LOSSES,
SETTLEMENTS, PENALTIES, FINES, COSTS, EXPENSES (INCLUDING
REASONABLE ATTORNEYS' FEES), DEMANDS, CAUSES OF ACTION, CLAIMS,
ACTIONS, PROCEEDINGS, AND SUITS, DIRECTLY RELATED TO OR ARISING
OUT OF YOUR USE, INABILITY TO USE, COPYING, (RE)DISTRIBUTION,
IMPORT AND/OR (RE)EXPORT OF THIS PRODUCT (OR PORTIONS THEREOF)
AND/OR YOUR BREACH OF ANY TERM OF THIS LICENSE.
V. Trademarks
This License does not grant permission to use trademarks
associated with (or applying to) This Product, except for fair
use as defined by applicable law and except for use expressly
permitted or required by this License. Any attempt otherwise to
use trademarks associated with (or applying to) This Product
automatically and immediately terminates Your rights under This
License and may constitute trademark infringement (which may be
prosecuted).
VI. General Terms and Conditions, Miscellaneous Provisions
1. ANYONE WHO USES AND/OR COPIES AND/OR MODIFIES AND/OR CREATES
DERIVATIVE WORKS OF AND/OR (RE)DISTRIBUTES THIS PRODUCT, OR ANY
PORTION(S) THEREOF, IS, BY SUCH ACTION(S), AGREEING TO BE BOUND
BY AND ACCEPTING ALL TERMS AND CONDITIONS OF THIS LICENSE (AND
THE RESPONSIBILITIES AND OBLIGATIONS CONTAINED IN THIS LICENSE).
IF YOU DO NOT ACCEPT (AND AGREE TO BE BOUND BY) ALL TERMS AND
CON/*
Derived from source code of TrueCrypt 7.1a, which is
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-2015 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.
*/
#include "System.h"
#include <set>
#include <typeinfo>
#include <wx/apptrait.h>
#include <wx/cmdline.h>
#include "Platform/PlatformTest.h"
#ifdef TC_UNIX
#include <errno.h>
#include "Platform/Unix/Process.h"
#endif
#include "Platform/SystemInfo.h"
#include "Platform/SystemException.h"
#include "Common/SecurityToken.h"
#include "Volume/EncryptionTest.h"
#include "Application.h"
#include "FavoriteVolume.h"
#include "UserInterface.h"
namespace VeraCrypt
{
UserInterface::UserInterface ()
{
}
UserInterface::~UserInterface ()
{
Core->WarningEvent.Disconnect (this);
Core->VolumeMountedEvent.Disconnect (this);
try
{
if (SecurityToken::IsInitialized())
SecurityToken::CloseLibrary();
}
catch (...) { }
}
void UserInterface::CheckRequirementsForMountingVolume () const
{
#ifdef TC_LINUX
if (!Preferences.NonInteractive)
{
if (!SystemInfo::IsVersionAtLeast (2, 6, 24))
ShowWarning (_("Your system uses an old version of the Linux kernel.\n\nDue to a bug in the Linux kernel, your system may stop responding when writing data to a VeraCrypt volume. This problem can be solved by upgrading the kernel to version 2.6.24 or later."));
}
#endif // TC_LINUX
}
void UserInterface::CloseExplorerWindows (shared_ptr <VolumeInfo> mountedVolume) const
{
#ifdef TC_WINDOWS
struct Args
{
HWND ExplorerWindow;
string DriveRootPath;
};
struct Enumerator
{
static BOOL CALLBACK ChildWindows (HWND hwnd, LPARAM argsLP)
{
Args *args = reinterpret_cast <Args *> (argsLP);
char s[4096];
SendMessageA (hwnd, WM_GETTEXT, sizeof (s), (LPARAM) s);
if (strstr (s, args->DriveRootPath.c_str()) != NULL)
{
PostMessage (args->ExplorerWindow, WM_CLOSE, 0, 0);
return FALSE;
}
return TRUE;
}
static BOOL CALLBACK TopLevelWindows (HWND hwnd, LPARAM argsLP)
{
Args *args = reinterpret_cast <Args *> (argsLP);
char s[4096];
GetClassNameA (hwnd, s, sizeof s);
if (strcmp (s, "CabinetWClass") == 0)
{
GetWindowTextA (hwnd, s, sizeof s);
if (strstr (s, args->DriveRootPath.c_str()) != NULL)
{
PostMessage (hwnd, WM_CLOSE, 0, 0);
return TRUE;
}
args->ExplorerWindow = hwnd;
EnumChildWindows (hwnd, ChildWindows, argsLP);
}
return TRUE;
}
};
Args args;
string mountPoint = mountedVolume->MountPoint;
if (mountPoint.size() < 2 || mountPoint[1] != ':')
return;
args.DriveRootPath = string() + mountPoint[0] + string (":\\");
EnumWindows (Enumerator::TopLevelWindows, (LPARAM) &args);
#endif
}
void UserInterface::DismountAllVolumes (bool ignoreOpenFiles, bool interactive) const
{
try
{
VolumeInfoList mountedVolumes = Core->GetMountedVolumes();
if (mountedVolumes.size() < 1)
ShowInfo (LangString["NO_VOLUMES_MOUNTED"]);
BusyScope busy (this);
DismountVolumes (mountedVolumes, ignoreOpenFiles, interactive);
}
catch (exception &e)
{
ShowError (e);
}
}
void UserInterface::DismountVolume (shared_ptr <VolumeInfo> volume, bool ignoreOpenFiles, bool interactive) const
{
VolumeInfoList volumes;
volumes.push_back (volume);
DismountVolumes (volumes, ignoreOpenFiles, interactive);
}
void UserInterface::DismountVolumes (VolumeInfoList volumes, bool ignoreOpenFiles, bool interactive) const
{
BusyScope busy (this);
volumes.sort (VolumeInfo::FirstVolumeMountedAfterSecond);
wxString message;
bool twoPassMode = volumes.size() > 1;
bool volumesInUse = false;
bool firstPass = true;
#ifdef TC_WINDOWS
if (Preferences.CloseExplorerWindowsOnDismount)
{
foreach (shared_ptr <VolumeInfo> volume, volumes)
CloseExplorerWindows (volume);
}
#endif
while (!volumes.empty())
{
VolumeInfoList volumesLeft;
foreach (shared_ptr <VolumeInfo> volume, volumes)
{
try
{
BusyScope busy (this);
volume = Core->DismountVolume (volume, ignoreOpenFiles);
}
catch (MountedVolumeInUse&)
{
if (!firstPass)
throw;
if (twoPassMode || !interactive)
{
volumesInUse = true;
volumesLeft.push_back (volume);
continue;
}
else
{
if (AskYesNo (StringFormatter (LangString["UNMOUNT_LOCK_FAILED"], wstring (volume->Path)), true, true))
{
BusyScope busy (this);
volume = Core->DismountVolume (volume, true);
}
else
throw UserAbort (SRC_POS);
}
}
catch (...)
{
if (twoPassMode && firstPass)
volumesLeft.push_back (volume);
else
throw;
}
if (volume->HiddenVolumeProtectionTriggered)
ShowWarning (StringFormatter (LangString["DAMAGE_TO_HIDDEN_VOLUME_PREVENTED"], wstring (volume->Path)));
if (Preferences.Verbose)
{
if (!message.IsEmpty())
message += L'\n';
message += StringFormatter (_("Volume \"{0}\" has been dismounted."), wstring (volume->Path));
}
}
if (twoPassMode && firstPass)
{
volumes = volumesLeft;
if (volumesInUse && interactive)
{
if (AskYesNo (LangString["UNMOUNTALL_LOCK_FAILED"], true, true))
ignoreOpenFiles = true;
else
throw UserAbort (SRC_POS);
}
}
else
break;
firstPass = false;
}
if (Preferences.Verbose && !message.IsEmpty())
ShowInfo (message);
}
void UserInterface::DisplayVolumeProperties (const VolumeInfoList &volumes) const
{
if (volumes.size() < 1)
throw_err (LangString["NO_VOLUMES_MOUNTED"]);
wxString prop;
foreach_ref (const VolumeInfo &volume, volumes)
{
prop << _("Slot") << L": " << StringConverter::FromNumber (volume.SlotNumber) << L'\n';
prop << LangString["VOLUME"] << L": " << wstring (volume.Path) << L'\n';
#ifndef TC_WINDOWS
prop << LangString["VIRTUAL_DEVICE"] << L": " << wstring (volume.VirtualDevice) << L'\n';
#endif
prop << LangString["MOUNT_POINT"] << L": " << wstring (volume.MountPoint) << L'\n';
prop << LangString["SIZE"] << L": " << SizeToString (volume.Size) << L'\n';
prop << LangString["TYPE"] << L": " << VolumeTypeToString (volume.Type, volume.TrueCryptMode, volume.Protection) << L'\n';
prop << LangString["READ_ONLY"] << L": " << LangString [volume.Protection == VolumeProtection::ReadOnly ? "UISTR_YES" : "UISTR_NO"] << L'\n';
wxString protection;
if (volume.Type == VolumeType::Hidden)
protection = LangString["NOT_APPLICABLE_OR_NOT_AVAILABLE"];
else if (volume.HiddenVolumeProtectionTriggered)
protection = LangString["HID_VOL_DAMAGE_PREVENTED"];
else
protection = LangString [volume.Protection == VolumeProtection::HiddenVolumeReadOnly ? "UISTR_YES" : "UISTR_NO"];
prop << LangString["HIDDEN_VOL_PROTECTION"] << L": " << protection << L'\n';
prop << LangString["ENCRYPTION_ALGORITHM"] << L": " << volume.EncryptionAlgorithmName << L'\n';
prop << LangString["KEY_SIZE"] << L": " << StringFormatter (L"{0} {1}", volume.EncryptionAlgorithmKeySize * 8, LangString ["BITS"]) << L'\n';
if (volume.EncryptionModeName == L"XTS")
prop << LangString["SECONDARY_KEY_SIZE_XTS"] << L": " << StringFormatter (L"{0} {1}", volume.EncryptionAlgorithmKeySize * 8, LangString ["BITS"]) << L'\n';;
wstringstream blockSize;
blockSize << volume.EncryptionAlgorithmBlockSize * 8;
if (volume.EncryptionAlgorithmBlockSize != volume.EncryptionAlgorithmMinBlockSize)
blockSize << L"/" << volume.EncryptionAlgorithmMinBlockSize * 8;
prop << LangString["BLOCK_SIZE"] << L": " << blockSize.str() + L" " + LangString ["BITS"] << L'\n';
prop << LangString["MODE_OF_OPERATION"] << L": " << volume.EncryptionModeName << L'\n';
prop << LangString["PKCS5_PRF"] << L": " << volume.Pkcs5PrfName << L'\n';
prop << LangString["VOLUME_FORMAT_VERSION"] << L": " << (volume.MinRequiredProgramVersion < 0x10b ? 1 : 2) << L'\n';
prop << LangString["BACKUP_HEADER"] << L": " << LangString[volume.MinRequiredProgramVersion >= 0x10b ? "UISTR_YES" : "UISTR_NO"] << L'\n';
#ifdef TC_LINUX
if (string (volume.VirtualDevice).find ("/dev/mapper/veracrypt") != 0)
{
#endif
prop << LangString["TOTAL_DATA_READ"] << L": " << SizeToString (volume.TotalDataRead) << L'\n';
prop << LangString["TOTAL_DATA_WRITTEN"] << L": " << SizeToString (volume.TotalDataWritten) << L'\n';
#ifdef TC_LINUX
}
#endif
prop << L'\n';
}
ShowString (prop);
}
wxString UserInterface::ExceptionToMessage (const exception &ex)
{
wxString message;
const Exception *e = dynamic_cast <const Exception *> (&ex);
if (e)
{
message = ExceptionToString (*e);
// System exception
const SystemException *sysEx = dynamic_cast <const SystemException *> (&ex);
if (sysEx)
{
if (!message.IsEmpty())
{
message += L"\n\n";
}
message += wxString (sysEx->SystemText()).Trim (true);
}
if (!message.IsEmpty())
{
// Subject
if (!e->GetSubject().empty())
{
message = message.Trim (true);
if (message.EndsWith (L"."))
message.Truncate (message.size() - 1);
if (!message.EndsWith (L":"))
message << L":\n";
else
message << L"\n";
message << e->GetSubject();
}
#ifdef TC_UNIX
if (sysEx && sysEx->GetErrorCode() == EIO)
message << L"\n\n" << LangString["ERR_HARDWARE_ERROR"];
#endif
if (sysEx && sysEx->what())
message << L"\n\n" << StringConverter::ToWide (sysEx->what());
return message;
}
}
// bad_alloc
const bad_alloc *outOfMemory = dynamic_cast <const bad_alloc *> (&ex);
if (outOfMemory)
return _("Out of memory.");
// Unresolved exceptions
string typeName (StringConverter::GetTypeName (typeid (ex)));
size_t pos = typeName.find ("VeraCrypt::");
if (pos != string::npos)
{
return StringConverter::ToWide (typeName.substr (pos + string ("VeraCrypt::").size()))
+ L" at " + StringConverter::ToWide (ex.what());
}
return StringConverter::ToWide (typeName) + L" at " + StringConverter::ToWide (ex.what());
}
wxString UserInterface::ExceptionToString (const Exception &ex)
{
// Error messages
const ErrorMessage *errMsgEx = dynamic_cast <const ErrorMessage *> (&ex);
if (errMsgEx)
return wstring (*errMsgEx).c_str();
// ExecutedProcessFailed
const ExecutedProcessFailed *execEx = dynamic_cast <const ExecutedProcessFailed *> (&ex);
if (execEx)
{
wstring errOutput;
// ElevationFailed
if (dynamic_cast <const ElevationFailed*> (&ex))
errOutput += wxString (_("Failed to obtain administrator privileges")) + (StringConverter::Trim (execEx->GetErrorOutput()).empty() ? L". " : L": ");
errOutput += StringConverter::ToWide (execEx->GetErrorOutput());
if (errOutput.empty())
return errOutput + StringFormatter (_("Command \"{0}\" returned error {1}."), execEx->GetCommand(), execEx->GetExitCode());
return wxString (errOutput).Trim (true);
}
// PasswordIncorrect
if (dynamic_cast <const PasswordException *> (&ex))
{
wxString message = ExceptionTypeToString (typeid (ex));
#ifndef TC_NO_GUI
if (Application::GetUserInterfaceType() == UserInterfaceType::Graphic && wxGetKeyState (WXK_CAPITAL))
message += wxString (L"\n\n") + LangString["CAPSLOCK_ON"];
#endif
if (Keyfile::WasHiddenFilePresentInKeyfilePath())
{
#ifdef TC_UNIX
message += _("\n\nWarning: Hidden files are present in a keyfile path. If you need to use them as keyfiles, remove the leading dot from their filenames. Hidden files are visible only if enabled in system options.");
#else
message += LangString["HIDDEN_FILES_PRESENT_IN_KEYFILE_PATH"];
#endif
}
return message;
}
// PKCS#11 Exception
if (dynamic_cast <const Pkcs11Exception *> (&ex))
{
string errorString = string (dynamic_cast <const Pkcs11Exception &> (ex));
if (LangString.Exists (errorString))
return LangString[errorString];
if (errorString.find ("CKR_") == 0)
{
errorString = errorString.substr (4);
for (size_t i = 0; i < errorString.size(); ++i)
{
if (errorString[i] == '_')
errorString[i] = ' ';
}
}
return LangString["SECURITY_TOKEN_ERROR"] + L":\n\n" + StringConverter::ToWide (errorString);
}
// Other library exceptions
return ExceptionTypeToString (typeid (ex));
}
wxString UserInterface::ExceptionTypeToString (const std::type_info &ex)
{
#define EX2MSG(exception, message) do { if (ex == typeid (exception)) return (message); } while (false)
EX2MSG (DriveLetterUnavailable, LangString["DRIVE_LETTER_UNAVAILABLE"]);
EX2MSG (EncryptedSystemRequired, _("This operation must be performed only when the system hosted on the volume is running."));
EX2MSG (ExternalException, LangString["EXCEPTION_OCCURRED"]);
EX2MSG (InsufficientData, _("Not enough data available."));
EX2MSG (InvalidSecurityTokenKeyfilePath, LangString["INVALID_TOKEN_KEYFILE_PATH"]);
EX2MSG (HigherVersionRequired, LangString["NEW_VERSION_REQUIRED"]);
EX2MSG (KernelCryptoServiceTestFailed, _("Kernel cryptographic service test failed. The cryptographic service of your kernel most likely does not support volumes larger than 2 TB.\n\nPossible solutions:\n- Upgrade the Linux kernel to version 2.6.33 or later.\n- Disable use of the kernel cryptographic services (Settings > Preferences > System Integration) or use 'nokernelcrypto' mount option on the command line."));
EX2MSG (KeyfilePathEmpty, LangString["ERR_KEYFILE_PATH_EMPTY"]);
EX2MSG (LoopDeviceSetupFailed, _("Failed to set up a loop device."));
EX2MSG (MissingArgument, _("A required argument is missing."));
EX2MSG (MissingVolumeData, _("Volume data missing."));
EX2MSG (MountPointRequired, _("Mount point required."));
EX2MSG (MountPointUnavailable, _("Mount point is already in use."));
EX2MSG (NoDriveLetterAvailable, LangString["NO_FREE_DRIVES"]);
EX2MSG (PasswordEmpty, _("No password or keyfile specified."));
EX2MSG (PasswordIncorrect, LangString["PASSWORD_WRONG"]);
EX2MSG (PasswordKeyfilesIncorrect, LangString["PASSWORD_OR_KEYFILE_WRONG"]);
EX2MSG (PasswordOrKeyboardLayoutIncorrect, LangString["PASSWORD_OR_KEYFILE_WRONG"] + _("\n\nNote that pre-boot authentication passwords need to be typed in the pre-boot environment where non-US keyboard layouts are not available. Therefore, pre-boot authentication passwords must always be typed using the standard US keyboard layout (otherwise, the password will be typed incorrectly in most cases). However, note that you do NOT need a real US keyboard; you just need to change the keyboard layout in your operating system."));
EX2MSG (PasswordOrMountOptionsIncorrect, LangString["PASSWORD_OR_KEYFILE_OR_MODE_WRONG"] + _("\n\nNote: If you are attempting to mount a partition located on an encrypted system drive without pre-boot authentication or to mount the encrypted system partition of an operating system that is not running, you can do so by selecting 'Options >' > 'Mount partition using system encryption'."));
EX2MSG (PasswordTooLong, StringFormatter (_("Password is longer than {0} characters."), (int) VolumePassword::MaxSize));
EX2MSG (PartitionDeviceRequired, _("Partition device required."));
EX2MSG (ProtectionPasswordIncorrect, _("Incorrect password to the protected hidden volume or the hidden volume does not exist."));
EX2MSG (ProtectionPasswordKeyfilesIncorrect,_("Incorrect keyfile(s) and/or password to the protected hidden volume or the hidden volume does not exist."));
EX2MSG (RootDeviceUnavailable, LangString["NODRIVER"]);
EX2MSG (SecurityTokenKeyfileAlreadyExists, LangString["TOKEN_KEYFILE_ALREADY_EXISTS"]);
EX2MSG (SecurityTokenKeyfileNotFound, LangString["TOKEN_KEYFILE_NOT_FOUND"]);
EX2MSG (SecurityTokenLibraryNotInitialized, LangString["PKCS11_MODULE_INIT_FAILED"]);
EX2MSG (StringConversionFailed, _("Invalid characters encountered."));
EX2MSG (StringFormatterException, _("Error while parsing formatted string."));
EX2MSG (TemporaryDirectoryFailure, _("Failed to create a file or directory in a temporary directory.\n\nPlease make sure that the temporary directory exists, its security permissions allow you to access it, and there is sufficient disk space."));
EX2MSG (UnportablePassword, LangString["UNSUPPORTED_CHARS_IN_PWD"]);
#if defined (TC_LINUX)
EX2MSG (UnsupportedSectorSize, LangString["SECTOR_SIZE_UNSUPPORTED"]);
EX2MSG (UnsupportedSectorSizeHiddenVolumeProtection, _("Error: The drive uses a sector size other than 512 bytes.\n\nDue to limitations of components available on your platform, outer volumes hosted on the drive cannot be mounted using hidden volume protection.\n\nPossible solutions:\n- Use a drive with 512-byte sectors.\n- Create a file-hosted volume (container) on the drive.\n- Backup the contents of the hidden volume and then update the outer volume."));
EX2MSG (UnsupportedSectorSizeNoKernelCrypto, _("Error: The drive uses a sector size other than 512 bytes.\n\nDue to limitations of components available on your platform, partition/device-hosted volumes on the drive can only be mounted using kernel cryptographic services.\n\nPossible solutions:\n- Enable use of the kernel cryptographic services (Preferences > System Integration).\n- Use a drive with 512-byte sectors.\n- Create a file-hosted volume (container) on the drive."));
#else
EX2MSG (UnsupportedSectorSize, _("Error: The drive uses a sector size other than 512 bytes.\n\nDue to limitations of components available on your platform, partition/device-hosted volumes cannot be created/used on the drive.\n\nPossible solutions:\n- Create a file-hosted volume (container) on the drive.\n- Use a drive with 512-byte sectors.\n- Use VeraCrypt on another platform."));
#endif
EX2MSG (VolumeAlreadyMounted, LangString["VOL_ALREADY_MOUNTED"]);
EX2MSG (VolumeEncryptionNotCompleted, LangString["ERR_ENCRYPTION_NOT_COMPLETED"]);
EX2MSG (VolumeHostInUse, _("The host file/device is already in use."));
EX2MSG (VolumeSlotUnavailable, _("Volume slot unavailable."));
EX2MSG (UnsupportedAlgoInTrueCryptMode, LangString["ALGO_NOT_SUPPORTED_FOR_TRUECRYPT_MODE"]);
EX2MSG (UnsupportedTrueCryptFormat, LangString["UNSUPPORTED_TRUECRYPT_FORMAT"]);
#ifdef TC_MACOSX
EX2MSG (HigherFuseVersionRequired, _("VeraCrypt requires OSXFUSE 2.3 or later with MacFUSE compatibility layer installer.\nPlease ensure that you have selected this compatibility layer during OSXFUSE installation."));
#endif
#undef EX2MSG
return L"";
}
void UserInterface::Init ()
{
SetAppName (Application::GetName());
SetClassName (Application::GetName());
LangString.Init();
Core->Init();
CmdLine.reset (new CommandLineInterface (argc, argv, InterfaceType));
SetPreferences (CmdLine->Preferences);
Core->SetApplicationExecutablePath (Application::GetExecutablePath());
if (!Preferences.NonInteractive)
{
Core->SetAdminPasswordCallback (GetAdminPasswordRequestHandler());
}
else
{
struct AdminPasswordRequestHandler : public GetStringFunctor
{
virtual void operator() (string &str)
{
throw ElevationFailed (SRC_POS, "sudo", 1, "");
}
};
Core->SetAdminPasswordCallback (shared_ptr <GetStringFunctor> (new AdminPasswordRequestHandler));
}
Core->WarningEvent.Connect (EventConnector <UserInterface> (this, &UserInterface::OnWarning));
Core->VolumeMountedEvent.Connect (EventConnector <UserInterface> (this, &UserInterface::OnVolumeMounted));
if (!CmdLine->Preferences.SecurityTokenModule.IsEmpty() && !SecurityToken::IsInitialized())
{
try
{
InitSecurityTokenLibrary();
}
catch (exception &e)
{
if (Preferences.NonInteractive)
throw;
ShowError (e);
}
}
}
void UserInterface::ListMountedVolumes (const VolumeInfoList &volumes) const
{
if (volumes.size() < 1)
throw_err (LangString["NO_VOLUMES_MOUNTED"]);
wxString message;
foreach_ref (const VolumeInfo &volume, volumes)
{
message << volume.SlotNumber << L": " << StringConverter::QuoteSpaces (volume.Path);
if (!volume.VirtualDevice.IsEmpty())
message << L' ' << wstring (volume.VirtualDevice);
else
message << L" - ";
if (!volume.MountPoint.IsEmpty())
message << L' ' << StringConverter::QuoteSpaces (volume.MountPoint);
else
message << L" - ";
message << L'\n';
}
ShowString (message);
}
VolumeInfoList UserInterface::MountAllDeviceHostedVolumes (MountOptions &options) const
{
BusyScope busy (this);
VolumeInfoList newMountedVolumes;
if (!options.MountPoint)
options.MountPoint.reset (new DirectoryPath);
Core->CoalesceSlotNumberAndMountPoint (options);
bool sharedAccessAllowed = options.SharedAccessAllowed;
bool someVolumesShared = false;
HostDeviceList devices;
foreach (shared_ptr <HostDevice> device, Core->GetHostDevices (true))
{
devices.push_back (device);
foreach (shared_ptr <HostDevice> partition, device->Partitions)
devices.push_back (partition);
}
set <wstring> mountedVolumes;
foreach_ref (const VolumeInfo &v, Core->GetMountedVolumes())
mountedVolumes.insert (v.Path);
bool protectedVolumeMounted = false;
bool legacyVolumeMounted = false;
foreach_ref (const HostDevice &device, devices)
{
if (mountedVolumes.find (wstring (device.Path)) != mountedVolumes.end())
continue;
Yield();
options.SlotNumber = Core->GetFirstFreeSlotNumber (options.SlotNumber);
options.MountPoint.reset (new DirectoryPath);
options.Path.reset (new VolumePath (device.Path));
try
{
try
{
options.SharedAccessAllowed = sharedAccessAllowed;
newMountedVolumes.push_back (Core->MountVolume (options));
}
catch (VolumeHostInUse&)
{
if (!sharedAccessAllowed)
{
try
{
options.SharedAccessAllowed = true;
newMountedVolumes.push_back (Core->MountVolume (options));
someVolumesShared = true;
}
catch (VolumeHostInUse&)
{
continue;
}
}
else
continue;
}
if (newMountedVolumes.back()->Protection == VolumeProtection::HiddenVolumeReadOnly)
protectedVolumeMounted = true;
if (newMountedVolumes.back()->EncryptionAlgorithmMinBlockSize == 8)
legacyVolumeMounted = true;
}
catch (DriverError&) { }
catch (MissingVolumeData&) { }
catch (PasswordException&) { }
catch (SystemException&) { }
catch (ExecutedProcessFailed&) { }
}
if (newMountedVolumes.empty())
{
ShowWarning (LangString [options.Keyfiles && !options.Keyfiles->empty() ? "PASSWORD_OR_KEYFILE_WRONG_AUTOMOUNT" : "PASSWORD_WRONG_AUTOMOUNT"]);
}
else
{
if (someVolumesShared)
ShowWarning ("DEVICE_IN_USE_INFO");
if (legacyVolumeMounted)
ShowWarning ("WARN_64_BIT_BLOCK_CIPHER");
if (protectedVolumeMounted)
ShowInfo (LangString[newMountedVolumes.size() > 1 ? "HIDVOL_PROT_WARN_AFTER_MOUNT_PLURAL" : "HIDVOL_PROT_WARN_AFTER_MOUNT"]);
}
if (!newMountedVolumes.empty() && GetPreferences().CloseSecurityTokenSessionsAfterMount)
SecurityToken::CloseAllSessions();
return newMountedVolumes;
}
VolumeInfoList UserInterface::MountAllFavoriteVolumes (MountOptions &options)
{
BusyScope busy (this);
VolumeInfoList newMountedVolumes;
foreach_ref (const FavoriteVolume &favorite, FavoriteVolume::LoadList())
{
shared_ptr <VolumeInfo> mountedVolume = Core->GetMountedVolume (favorite.Path);
if (mountedVolume)
{
if (mountedVolume->MountPoint != favorite.MountPoint)
ShowInfo (StringFormatter (LangString["VOLUME_ALREADY_MOUNTED"], wstring (favorite.Path)));
continue;
}
favorite.ToMountOptions (options);
if (Preferences.NonInteractive)
{
BusyScope busy (this);
newMountedVolumes.push_back (Core->MountVolume (options));
}
else
{
try
{
BusyScope busy (this);
newMountedVolumes.push_back (Core->MountVolume (options));
}
catch (...)
{
UserPreferences prefs = GetPreferences();
if (prefs.CloseSecurityTokenSessionsAfterMount)
Preferences.CloseSecurityTokenSessionsAfterMount = false;
shared_ptr <VolumeInfo> volume = MountVolume (options);
if (prefs.CloseSecurityTokenSessionsAfterMount)
Preferences.CloseSecurityTokenSessionsAfterMount = true;
if (!volume)
break;
newMountedVolumes.push_back (volume);
}
}
}
if (!newMountedVolumes.empty() && GetPreferences().CloseSecurityTokenSessionsAfterMount)
SecurityToken::CloseAllSessions();
return newMountedVolumes;
}
shared_ptr <VolumeInfo> UserInterface::MountVolume (MountOptions &options) const
{
shared_ptr <VolumeInfo> volume;
try
{
volume = MountVolumeThread (options);
}
catch (VolumeHostInUse&)
{
if (options.SharedAccessAllowed)
throw_err (LangString["FILE_IN_USE_FAILED"]);
if (!AskYesNo (StringFormatter (LangString["VOLUME_HOST_IN_USE"], wstring (*options.Path)), false, true))
throw UserAbort (SRC_POS);
try
{
options.SharedAccessAllowed = true;
volume = Core->MountVolume (options);
}
catch (VolumeHostInUse&)
{
throw_err (LangString["FILE_IN_USE_FAILED"]);
}
}
if (volume->EncryptionAlgorithmMinBlockSize == 8)
ShowWarning ("WARN_64_BIT_BLOCK_CIPHER");
if (VolumeHasUnrecommendedExtension (*options.Path))
ShowWarning ("EXE_FILE_EXTENSION_MOUNT_WARNING");
if (options.Protection == VolumeProtection::HiddenVolumeReadOnly)
ShowInfo ("HIDVOL_PROT_WARN_AFTER_MOUNT");
if (GetPreferences().CloseSecurityTokenSessionsAfterMount)
SecurityToken::CloseAllSessions();
return volume;
}
void UserInterface::OnUnhandledException ()
{
try
{
throw;
}
catch (UserAbort&)
{
}
catch (exception &e)
{
ShowError (e);
}
catch (...)
{
ShowError (_("Unknown exception occurred."));
}
Yield();
Application::SetExitCode (1);
}
void UserInterface::OnVolumeMounted (EventArgs &args)
{
shared_ptr <VolumeInfo> mountedVolume = (dynamic_cast <VolumeEventArgs &> (args)).mVolume;
if (Preferences.OpenExplorerWindowAfterMount && !mountedVolume->MountPoint.IsEmpty())
OpenExplorerWindow (mountedVolume->MountPoint);
}
void UserInterface::OnWarning (EventArgs &args)
{
ExceptionEventArgs &e = dynamic_cast <ExceptionEventArgs &> (args);
ShowWarning (e.mException);
}
void UserInterface::OpenExplorerWindow (const DirectoryPath &path)
{
if (path.IsEmpty())
return;
list <string> args;
#ifdef TC_WINDOWS
wstring p (Directory::AppendSeparator (path));
SHFILEINFO fInfo;
SHGetFileInfo (p.c_str(), 0, &fInfo, sizeof (fInfo), 0); // Force explorer to discover the drive
ShellExecute (GetTopWindow() ? static_cast <HWND> (GetTopWindow()->GetHandle()) : nullptr, L"open", p.c_str(), nullptr, nullptr, SW_SHOWNORMAL);
#elif defined (TC_MACOSX)
args.push_back (string (path));
try
{
Process::Execute ("open", args);
}
catch (exception &e) { ShowError (e); }
#else
// MIME handler for directory seems to be unavailable through wxWidgets
wxString desktop = GetTraits()->GetDesktopEnvironment();
if (desktop == L"GNOME")
{
args.push_back ("--no-default-window");
args.push_back ("--no-desktop");
args.push_back (string (path));
try
{
Process::Execute ("nautilus", args, 2000);
}
catch (TimeOut&) { }
catch (exception &e) { ShowError (e); }
}
else if (desktop == L"KDE")
{
try
{
args.push_back (string (path));
Process::Execute ("dolphin", args, 2000);
}
catch (TimeOut&) { }
catch (exception&)
{
args.clear();
args.push_back ("openURL");
args.push_back (string (path));
try
{
Process::Execute ("kfmclient", args, 2000);
}
catch (TimeOut&) { }
catch (exception &e) { ShowError (e); }
}
}
else if (wxFileName::IsFileExecutable (wxT("/usr/bin/xdg-open")))
{
// Fallback on the standard xdg-open command
// which is not always available by default
args.push_back (string (path));
try
{
Process::Execute ("xdg-open", args, 2000);
}
catch (TimeOut&) { }
catch (exception &e) { ShowError (e); }
}
else
{
ShowWarning (wxT("Unable to find a file manager to open the mounted volume"));
}
#endif
}
bool UserInterface::ProcessCommandLine ()
{
CommandLineInterface &cmdLine = *CmdLine;
if (cmdLine.ArgCommand == CommandId::None)
return false;
if (Preferences.UseStandardInput)
{
wstring pwdInput;
wcin >> pwdInput;
cmdLine.ArgPassword = make_shared<VolumePassword> (pwdInput);
}
switch (cmdLine.ArgCommand)
{
case CommandId::AutoMountDevices:
case CommandId::AutoMountFavorites:
case CommandId::AutoMountDevicesFavorites:
case CommandId::MountVolume:
{
cmdLine.ArgMountOptions.Path = cmdLine.ArgVolumePath;
cmdLine.ArgMountOptions.MountPoint = cmdLine.ArgMountPoint;
cmdLine.ArgMountOptions.Password = cmdLine.ArgPassword;
cmdLine.ArgMountOptions.Pim = cmdLine.ArgPim;
cmdLine.ArgMountOptions.Keyfiles = cmdLine.ArgKeyfiles;
cmdLine.ArgMountOptions.SharedAccessAllowed = cmdLine.ArgForce;
cmdLine.ArgMountOptions.TrueCryptMode = cmdLine.ArgTrueCryptMode;
if (cmdLine.ArgHash)
{
cmdLine.ArgMountOptions.Kdf = Pkcs5Kdf::GetAlgorithm (*cmdLine.ArgHash, cmdLine.ArgTrueCryptMode);
}
VolumeInfoList mountedVolumes;
switch (cmdLine.ArgCommand)
{
case CommandId::AutoMountDevices:
case CommandId::AutoMountFavorites:
case CommandId::AutoMountDevicesFavorites:
{
if (cmdLine.ArgCommand == CommandId::AutoMountDevices || cmdLine.ArgCommand == CommandId::AutoMountDevicesFavorites)
{
if (Preferences.NonInteractive)
mountedVolumes = UserInterface::MountAllDeviceHostedVolumes (cmdLine.ArgMountOptions);
else
mountedVolumes = MountAllDeviceHostedVolumes (cmdLine.ArgMountOptions);
}
if (cmdLine.ArgCommand == CommandId::AutoMountFavorites || cmdLine.ArgCommand == CommandId::AutoMountDevicesFavorites)
{
foreach (shared_ptr <VolumeInfo> v, MountAllFavoriteVolumes(cmdLine.ArgMountOptions))
mountedVolumes.push_back (v);
}
}
break;
break;
case CommandId::MountVolume:
if (Preferences.OpenExplorerWindowAfterMount)
{
// Open explorer window for an already mounted volume
shared_ptr <VolumeInfo> mountedVolume = Core->GetMountedVolume (*cmdLine.ArgMountOptions.Path);
if (mountedVolume && !mountedVolume->MountPoint.IsEmpty())
{
OpenExplorerWindow (mountedVolume->MountPoint);
break;
}
}
if (Preferences.NonInteractive)
{
// Volume path
if (!cmdLine.ArgMountOptions.Path)
throw MissingArgument (SRC_POS);
mountedVolumes.push_back (Core->MountVolume (cmdLine.ArgMountOptions));
}
else
{
shared_ptr <VolumeInfo> volume = MountVolume (cmdLine.ArgMountOptions);
if (!volume)
{
Application::SetExitCode (1);
throw UserAbort (SRC_POS);
}
mountedVolumes.push_back (volume);
}
break;
default:
throw ParameterIncorrect (SRC_POS);
}
if (Preferences.Verbose && !mountedVolumes.empty())
{
wxString message;
foreach_ref (const VolumeInfo &volume, mountedVolumes)
{
if (!message.IsEmpty())
message += L'\n';
message += StringFormatter (_("Volume \"{0}\" has been mounted."), wstring (volume.Path));
}
ShowInfo (message);
}
}
return true;
case CommandId::BackupHeaders:
BackupVolumeHeaders (cmdLine.ArgVolumePath);
return true;
case CommandId::ChangePassword:
ChangePassword (cmdLine.ArgVolumePath, cmdLine.ArgPassword, cmdLine.ArgPim, cmdLine.ArgHash, cmdLine.ArgTrueCryptMode, cmdLine.ArgKeyfiles, cmdLine.ArgNewPassword, cmdLine.ArgNewPim, cmdLine.ArgNewKeyfiles, cmdLine.ArgNewHash);
return true;
case CommandId::CreateKeyfile:
CreateKeyfile (cmdLine.ArgFilePath);
return true;
case CommandId::CreateVolume:
{
make_shared_auto (VolumeCreationOptions, options);
if (cmdLine.ArgHash)
{
options->VolumeHeaderKdf = Pkcs5Kdf::GetAlgorithm (*cmdLine.ArgHash, false);
RandomNumberGenerator::SetHash (cmdLine.ArgHash);
}
options->EA = cmdLine.ArgEncryptionAlgorithm;
options->Filesystem = cmdLine.ArgFilesystem;
options->Keyfiles = cmdLine.ArgKeyfiles;
options->Password = cmdLine.ArgPassword;
options->Pim = cmdLine.ArgPim;
options->Quick = cmdLine.ArgQuick;
options->Size = cmdLine.ArgSize;
options->Type = cmdLine.ArgVolumeType;
if (cmdLine.ArgVolumePath)
options->Path = VolumePath (*cmdLine.ArgVolumePath);
CreateVolume (options);
return true;
}
case CommandId::DeleteSecurityTokenKeyfiles:
DeleteSecurityTokenKeyfiles();
return true;
case CommandId::DismountVolumes:
DismountVolumes (cmdLine.ArgVolumes, cmdLine.ArgForce, !Preferences.NonInteractive);
return true;
case CommandId::DisplayVersion:
ShowString (Application::GetName() + L" " + StringConverter::ToWide (Version::String()) + L"\n");
return true;
case CommandId::DisplayVolumeProperties:
DisplayVolumeProperties (cmdLine.ArgVolumes);
return true;
case CommandId::Help:
{
wstring helpText = StringConverter::ToWide (
"Synopsis:\n"
"\n"
"veracrypt [OPTIONS] COMMAND\n"
"veracrypt [OPTIONS] VOLUME_PATH [MOUNT_DIRECTORY]\n"
"\n"
"\n"
"Commands:\n"
"\n"
"--auto-mount=devices|favorites\n"
" Auto mount device-hosted or favorite volumes.\n"
"\n"
"--backup-headers[=VOLUME_PATH]\n"
" Backup volume headers to a file. All required options are requested from the\n"
" user.\n"
"\n"
"-c, --create[=VOLUME_PATH]\n"
" Create a new volume. Most options are requested from the user if not specified\n"
" on command line. See also options --encryption, -k, --filesystem, --hash, -p,\n"
" --random-source, --quick, --size, --volume-type. Note that passing some of the\n"
" options may affect security of the volume (see option -p for more information).\n"
"\n"
" Inexperienced users should use the graphical user interface to create a hidden\n"
" volume. When using the text user interface, the following procedure must be\n"
" followed to create a hidden volume:\n"
" 1) Create an outer volume with no filesystem.\n"
" 2) Create a hidden volume within the outer volume.\n"
" 3) Mount the outer volume using hidden volume protection.\n"
" 4) Create a filesystem on the virtual device of the outer volume.\n"
" 5) Mount the new filesystem and fill it with data.\n"
" 6) Dismount the outer volume.\n"
" If at any step the hidden volume protection is triggered, start again from 1).\n"
"\n"
"--create-keyfile[=FILE_PATH]\n"
" Create a new keyfile containing pseudo-random data.\n"
"\n"
"-C, --change[=VOLUME_PATH]\n"
" Change a password and/or keyfile(s) of a volume. Most options are requested\n"
" from the user if not specified on command line. PKCS-5 PRF HMAC hash\n"
" algorithm can be changed with option --hash. See also options -k,\n"
" --new-keyfiles, --new-password, -p, --random-source.\n"
"\n"
"-d, --dismount[=MOUNTED_VOLUME]\n"
" Dismount a mounted volume. If MOUNTED_VOLUME is not specified, all\n"
" volumes are dismounted. See below for description of MOUNTED_VOLUME.\n"
"\n"
"--delete-token-keyfiles\n"
" Delete keyfiles from security tokens. See also command --list-token-keyfiles.\n"
"\n"
"--export-token-keyfile\n"
" Export a keyfile from a security token. See also command --list-token-keyfiles.\n"
"\n"
"--import-token-keyfiles\n"
" Import keyfiles to a security token. See also option --token-lib.\n"
"\n"
"-l, --list[=MOUNTED_VOLUME]\n"
" Display a list of mounted volumes. If MOUNTED_VOLUME is not specified, all\n"
" volumes are listed. By default, the list contains only volume path, virtual\n"
" device, and mount point. A more detailed list can be enabled by verbose\n"
" output option (-v). See below for description of MOUNTED_VOLUME.\n"
"\n"
"--list-token-keyfiles\n"
" Display a list of all available security token keyfiles. See also command\n"
" --import-token-keyfiles.\n"
"\n"
"--mount[=VOLUME_PATH]\n"
" Mount a volume. Volume path and other options are requested from the user\n"
" if not specified on command line.\n"
"\n"
"--restore-headers[=VOLUME_PATH]\n"
" Restore volume headers from the embedded or an external backup. All required\n"
" options are requested from the user.\n"
"\n"
"--save-preferences\n"
" Save user preferences.\n"
"\n"
"--test\n"
" Test internal algorithms used in the process of encryption and decryption.\n"
"\n"
"--version\n"
" Display program version.\n"
"\n"
"--volume-properties[=MOUNTED_VOLUME]\n"
" Display properties of a mounted volume. See below for description of\n"
" MOUNTED_VOLUME.\n"
"\n"
"MOUNTED_VOLUME:\n"
" Specifies a mounted volume. One of the following forms can be used:\n"
" 1) Path to the encrypted VeraCrypt volume.\n"
" 2) Mount directory of the volume's filesystem (if mounted).\n"
" 3) Slot number of the mounted volume (requires --slot).\n"
"\n"
"\n"
"Options:\n"
"\n"
"--display-password\n"
" Display password characters while typing.\n"
"\n"
"--encryption=ENCRYPTION_ALGORITHM\n"
" Use specified encryption algorithm when creating a new volume.\n"
"\n"
"--filesystem=TYPE\n"
" Filesystem type to mount. The TYPE argument is passed to mount(8) command\n"
" with option -t. Default type is 'auto'. When creating a new volume, this\n"
" option specifies the filesystem to be created on the new volume (only 'FAT'\n"
" and 'none' TYPE is allowed). Filesystem type 'none' disables mounting or\n"
" creating a filesystem.\n"
"\n"
"--force\n"
" Force mounting of a volume in use, dismounting of a volume in use, or\n"
" overwriting a file. Note that this option has no effect on some platforms.\n"
"\n"
"--fs-options=OPTIONS\n"
" Filesystem mount options. The OPTIONS argument is passed to mount(8)\n"
" command with option -o when a filesystem on a VeraCrypt volume is mounted.\n"
" This option is not available on some platforms.\n"
"\n"
"--hash=HASH\n"
" Use specified hash algorithm when creating a new volume or changing password\n"
" and/or keyfiles. This option also specifies the mixing PRF of the random\n"
" number generator.\n"
"\n"
"-k, --keyfiles=KEYFILE1[,KEYFILE2,KEYFILE3,...]\n"
" Use specified keyfiles when mounting a volume or when changing password\n"
" and/or keyfiles. When a directory is specified, all files inside it will be\n"
" used (non-recursively). Multiple keyfiles must be separated by comma.\n"
" Use double comma (,,) to specify a comma contained in keyfile's name.\n"
" Keyfile stored on a security token must be specified as\n"
" token://slot/SLOT_NUMBER/file/FILENAME. An empty keyfile (-k \"\") disables\n"
" interactive requests for keyfiles. See also options --import-token-keyfiles,\n"
" --list-token-keyfiles, --new-keyfiles, --protection-keyfiles.\n"
"\n"
"--load-preferences\n"
" Load user preferences.\n"
"\n"
"-m, --mount-options=OPTION1[,OPTION2,OPTION3,...]\n"
" Specifies comma-separated mount options for a VeraCrypt volume:\n"
" headerbak: Use backup headers when mounting a volume.\n"
" nokernelcrypto: Do not use kernel cryptographic services.\n"
" readonly|ro: Mount volume as read-only.\n"
" system: Mount partition using system encryption.\n"
" timestamp|ts: Do not restore host-file modification timestamp when a volume\n"
" is dismounted (note that the operating system under certain circumstances\n"
" does not alter host-file timestamps, which may be mistakenly interpreted\n"
" to mean that this option does not work).\n"
" See also option --fs-options.\n"
"\n"
"--new-keyfiles=KEYFILE1[,KEYFILE2,KEYFILE3,...]\n"
" Add specified keyfiles to a volume. This option can only be used with command\n"
" -C.\n"
"\n"
"--new-password=PASSWORD\n"
" Specifies a new password. This option can only be used with command -C.\n"
"\n"
"-p, --password=PASSWORD\n"
" Use specified password to mount/open a volume. An empty password can also be\n"
" specified (-p \"\"). Note that passing a password on the command line is\n"
" potentially insecure as the password may be visible in the process list\n"
" (see ps(1)) and/or stored in a command history file or system logs.\n"
"\n"
"--protect-hidden=yes|no\n"
" Write-protect a hidden volume when mounting an outer volume. Before mounting\n"
" the outer volume, the user will be prompted for a password to open the hidden\n"
" volume. The size and position of the hidden volume is then determined and the\n"
" outer volume is mounted with all sectors belonging to the hidden volume\n"
" protected against write operations. When a write to the protected area is\n"
" prevented, the whole volume is switched to read-only mode. Verbose list\n"
" (-v -l) can be used to query the state of the hidden volume protection.\n"
" Warning message is displayed when a volume switched to read-only is being\n"
" dismounted.\n"
"\n"
"--protection-keyfiles=KEYFILE1[,KEYFILE2,KEYFILE3,...]\n"
" Use specified keyfiles to open a hidden volume to be protected. This option\n"
" may be used only when mounting an outer volume with hidden volume protected.\n"
" See also options -k and --protect-hidden.\n"
"\n"
"--protection-password=PASSWORD\n"
" Use specified password to open a hidden volume to be protected. This option\n"
" may be used only when mounting an outer volume with hidden volume protected.\n"
" See also options -p and --protect-hidden.\n"
"\n"
"--quick\n"
" Do not encrypt free space when creating a device-hosted volume. This option\n"
" must not be used when creating an outer volume.\n"
"\n"
"--random-source=FILE\n"
" Use FILE as a source of random data (e.g., when creating a volume) instead\n"
" of requiring the user to type random characters.\n"
"\n"
"--slot=SLOT\n"
" Use specified slot number when mounting, dismounting, or listing a volume.\n"
"\n"
"--size=SIZE\n"
" Use specified size in bytes when creating a new volume.\n"
"\n"
"-t, --text\n"
" Use text user interface. Graphical user interface is used by default if\n"
" available. This option must be specified as the first argument.\n"
"\n"
"--token-lib=LIB_PATH\n"
" Use specified PKCS #11 security token library.\n"
"\n"
"--volume-type=TYPE\n"
" Use specified volume type when creating a new volume. TYPE can be 'normal'\n"
" or 'hidden'. See option -c for more information on creating hidden volumes.\n"
"\n"
"-v, --verbose\n"
" Enable verbose output.\n"
"\n"
"\n"
"IMPORTANT:\n"
"\n"
"If you want to use VeraCrypt, you must follow the security requirements and\n"
"security precautions listed in chapter 'Security Requirements and Precautions'\n"
"in the VeraCrypt documentation (file 'VeraCrypt User Guide.pdf').\n"
"\n"
"\nExamples:\n\n"
"Create a new volume:\n"
"veracrypt -t -c\n"
"\n"
"Mount a volume:\n"
"veracrypt volume.hc /media/veracrypt1\n"
"\n"
"Mount a volume as read-only, using keyfiles:\n"
"veracrypt -m ro -k keyfile1,keyfile2 volume.tc\n"
"\n"
"Mount a volume without mounting its filesystem:\n"
"veracrypt --filesystem=none volume.tc\n"
"\n"
"Mount a volume prompting only for its password:\n"
"veracrypt -t -k \"\" --protect-hidden=no volume.hc /media/veracrypt1\n"
"\n"
"Dismount a volume:\n"
"veracrypt -d volume.tc\n"
"\n"
"Dismount all mounted volumes:\n"
"veracrypt -d\n"
);
#ifndef TC_NO_GUI
if (Application::GetUserInterfaceType() == UserInterfaceType::Graphic)
{
wxDialog dialog (nullptr, wxID_ANY, _("VeraCrypt Command Line Help"), wxDefaultPosition);
wxTextCtrl *textCtrl = new wxTextCtrl (&dialog, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE | wxTE_READONLY);
textCtrl->SetFont (wxFont (wxNORMAL_FONT->GetPointSize(), wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL, false, L"Courier"));
textCtrl->SetValue (helpText);
int fontWidth, fontHeight;
textCtrl->GetTextExtent (L"A", &fontWidth, &fontHeight);
dialog.SetSize (wxSize (fontWidth * 85, fontHeight * 29));
wxBoxSizer *sizer = new wxBoxSizer (wxVERTICAL);
sizer->Add (textCtrl, 1, wxALL | wxEXPAND, 5);
sizer->Add (new wxButton (&dialog, wxID_OK, _("OK")), 0, wxALL | wxALIGN_CENTER_HORIZONTAL, 5);
dialog.SetSizer (sizer);
dialog.Layout();
dialog.ShowModal();
}
else
#endif // !TC_NO_GUI
{
ShowString (L"\n\n");
ShowString (helpText);
}
}
return true;
case CommandId::ExportSecurityTokenKeyfile:
ExportSecurityTokenKeyfile();
return true;
case CommandId::ImportSecurityTokenKeyfiles:
ImportSecurityTokenKeyfiles();
return true;
case CommandId::ListSecurityTokenKeyfiles:
ListSecurityTokenKeyfiles();
return true;
case CommandId::ListVolumes:
if (Preferences.Verbose)
DisplayVolumeProperties (cmdLine.ArgVolumes);
else
ListMountedVolumes (cmdLine.ArgVolumes);
return true;
case CommandId::RestoreHeaders:
RestoreVolumeHeaders (cmdLine.ArgVolumePath);
return true;
case CommandId::SavePreferences:
Preferences.Save();
return true;
case CommandId::Test:
Test();
return true;
default:
throw ParameterIncorrect (SRC_POS);
}
return false;
}
void UserInterface::SetPreferences (const UserPreferences &preferences)
{
Preferences = preferences;
Cipher::EnableHwSupport (!preferences.DefaultMountOptions.NoHardwareCrypto);
PreferencesUpdatedEvent.Raise();
}
void UserInterface::ShowError (const exception &ex) const
{
if (!dynamic_cast <const UserAbort*> (&ex))
DoShowError (ExceptionToMessage (ex));
}
wxString UserInterface::SizeToString (uint64 size) const
{
wstringstream s;
if (size > 1024ULL*1024*1024*1024*1024*99)
s << size/1024/1024/1024/1024/1024 << L" " << LangString["PB"].c_str();
else if (size > 1024ULL*1024*1024*1024*1024)
return wxString::Format (L"%.1f %s", (double)(size/1024.0/1024/1024/1024/1024), LangString["PB"].c_str());
else if (size > 1024ULL*1024*1024*1024*99)
s << size/1024/1024/1024/1024 << L" " << LangString["TB"].c_str();
else if (size > 1024ULL*1024*1024*1024)
return wxString::Format (L"%.1f %s", (double)(size/1024.0/1024/1024/1024), LangString["TB"].c_str());
else if (size > 1024ULL*1024*1024*99)
s << size/1024/1024/1024 << L" " << LangString["GB"].c_str();
else if (size > 1024ULL*1024*1024)
return wxString::Format (L"%.1f %s", (double)(size/1024.0/1024/1024), LangString["GB"].c_str());
else if (size > 1024ULL*1024*99)
s << size/1024/1024 << L" " << LangString["MB"].c_str();
else if (size > 1024ULL*1024)
return wxString::Format (L"%.1f %s", (double)(size/1024.0/1024), LangString["MB"].c_str());
else if (size > 1024ULL)
s << size/1024 << L" " << LangString["KB"].c_str();
else
s << size << L" " << LangString["BYTE"].c_str();
return s.str();
}
wxString UserInterface::SpeedToString (uint64 speed) const
{
wstringstream s;
if (speed > 1024ULL*1024*1024*1024*1024*99)
s << speed/1024/1024/1024/1024/1024 << L" " << LangString["PB_PER_SEC"].c_str();
else if (speed > 1024ULL*1024*1024*1024*1024)
return wxString::Format (L"%.1f %s", (double)(speed/1024.0/1024/1024/1024/1024), LangString["PB_PER_SEC"].c_str());
else if (speed > 1024ULL*1024*1024*1024*99)
s << speed/1024/1024/1024/1024 << L" " << LangString["TB_PER_SEC"].c_str();
else if (speed > 1024ULL*1024*1024*1024)
return wxString::Format (L"%.1f %s", (double)(speed/1024.0/1024/1024/1024), LangString["TB_PER_SEC"].c_str());
else if (speed > 1024ULL*1024*1024*99)
s << speed/1024/1024/1024 << L" " << LangString["GB_PER_SEC"].c_str();
else if (speed > 1024ULL*1024*999)
return wxString::Format (L"%.1f %s", (double)(speed/1024.0/1024/1024), LangString["GB_PER_SEC"].c_str());
else if (speed > 1024ULL*1024*9)
s << speed/1024/1024 << L" " << LangString["MB_PER_SEC"].c_str();
else if (speed > 1024ULL*999)
return wxString::Format (L"%.1f %s", (double)(speed/1024.0/1024), LangString["MB_PER_SEC"].c_str());
else if (speed > 1024ULL)
s << speed/1024 << L" " << LangString["KB_PER_SEC"].c_str();
else
s << speed << L" " << LangString["B_PER_SEC"].c_str();
return s.str();
}
void UserInterface::Test () const
{
if (!PlatformTest::TestAll())
throw TestFailed (SRC_POS);
EncryptionTest::TestAll();
// StringFormatter
if (StringFormatter (L"{9} {8} {7} {6} {5} {4} {3} {2} {1} {0} {{0}}", "1", L"2", '3', L'4', 5, 6, 7, 8, 9, 10) != L"10 9 8 7 6 5 4 3 2 1 {0}")
throw TestFailed (SRC_POS);
try
{
StringFormatter (L"{0} {1}", 1);
throw TestFailed (SRC_POS);
}
catch (StringFormatterException&) { }
try
{
StringFormatter (L"{0} {1} {1}", 1, 2, 3);
throw TestFailed (SRC_POS);
}
catch (StringFormatterException&) { }
try
{
StringFormatter (L"{0} 1}", 1, 2);
throw TestFailed (SRC_POS);
}
catch (StringFormatterException&) { }
try
{
StringFormatter (L"{0} {1", 1, 2);
throw TestFailed (SRC_POS);
}
catch (StringFormatterException&) { }
ShowInfo ("TESTS_PASSED");
}
wxString UserInterface::TimeSpanToString (uint64 seconds) const
{
wstringstream s;
if (seconds >= 60 * 60 * 24 * 2)
s << seconds / (60 * 24 * 60) << L" " << LangString["DAYS"].c_str();
else if (seconds >= 120 * 60)
s << seconds / (60 * 60) << L" " << LangString["HOURS"].c_str();
else if (seconds >= 120)
s << seconds / 60 << L" " << LangString["MINUTES"].c_str();
else
s << seconds << L" " << LangString["SECONDS"].c_str();
return s.str();
}
bool UserInterface::VolumeHasUnrecommendedExtension (const VolumePath &path) const
{
wxString ext = wxFileName (wxString (wstring (path)).Lower()).GetExt();
return ext.IsSameAs (L"exe") || ext.IsSameAs (L"sys") || ext.IsSameAs (L"dll");
}
wxString UserInterface::VolumeTimeToString (VolumeTime volumeTime) const
{
wxString dateStr = VolumeTimeToDateTime (volumeTime).Format();
#ifdef TC_WINDOWS
FILETIME ft;
*(unsigned __int64 *)(&ft) = volumeTime;
SYSTEMTIME st;
FileTimeToSystemTime (&ft, &st);
wchar_t wstr[1024];
if (GetDateFormat (LOCALE_USER_DEFAULT, 0, &st, 0, wstr, array_capacity (wstr)) != 0)
{
dateStr = wstr;
GetTimeFormat (LOCALE_USER_DEFAULT, 0, &st, 0, wstr, array_capacity (wstr));
dateStr += wxString (L" ") + wstr;
}
#endif
return dateStr;
}
wxString UserInterface::VolumeTypeToString (VolumeType::Enum type, bool truecryptMode, VolumeProtection::Enum protection) const
{
wxString sResult;
switch (type)
{
case VolumeType::Normal:
sResult = LangString[protection == VolumeProtection::HiddenVolumeReadOnly ? "OUTER" : "NORMAL"];
break;
case VolumeType::Hidden:
sResult = LangString["HIDDEN"];
break;
default:
sResult = L"?";
break;
}
if (truecryptMode)
sResult = wxT("TrueCrypt-") + sResult;
return sResult;
}
#define VC_CONVERT_EXCEPTION(NAME) if (dynamic_cast<NAME*> (ex)) throw (NAME&) *ex;
void UserInterface::ThrowException (Exception* ex)
{
VC_CONVERT_EXCEPTION (PasswordIncorrect);
VC_CONVERT_EXCEPTION (PasswordKeyfilesIncorrect);
VC_CONVERT_EXCEPTION (PasswordOrKeyboardLayoutIncorrect);
VC_CONVERT_EXCEPTION (PasswordOrMountOptionsIncorrect);
VC_CONVERT_EXCEPTION (ProtectionPasswordIncorrect);
VC_CONVERT_EXCEPTION (ProtectionPasswordKeyfilesIncorrect);
VC_CONVERT_EXCEPTION (PasswordEmpty);
VC_CONVERT_EXCEPTION (PasswordTooLong);
VC_CONVERT_EXCEPTION (UnportablePassword);
VC_CONVERT_EXCEPTION (ElevationFailed);
VC_CONVERT_EXCEPTION (RootDeviceUnavailable);
VC_CONVERT_EXCEPTION (DriveLetterUnavailable);
VC_CONVERT_EXCEPTION (DriverError);
VC_CONVERT_EXCEPTION (EncryptedSystemRequired);
VC_CONVERT_EXCEPTION (HigherFuseVersionRequired);
VC_CONVERT_EXCEPTION (KernelCryptoServiceTestFailed);
VC_CONVERT_EXCEPTION (LoopDeviceSetupFailed);
VC_CONVERT_EXCEPTION (MountPointRequired);
VC_CONVERT_EXCEPTION (MountPointUnavailable);
VC_CONVERT_EXCEPTION (NoDriveLetterAvailable);
VC_CONVERT_EXCEPTION (TemporaryDirectoryFailure);
VC_CONVERT_EXCEPTION (UnsupportedSectorSizeHiddenVolumeProtection);
VC_CONVERT_EXCEPTION (UnsupportedSectorSizeNoKernelCrypto);
VC_CONVERT_EXCEPTION (VolumeAlreadyMounted);
VC_CONVERT_EXCEPTION (VolumeSlotUnavailable);
VC_CONVERT_EXCEPTION (UserInterfaceException);
VC_CONVERT_EXCEPTION (MissingArgument);
VC_CONVERT_EXCEPTION (NoItemSelected);
VC_CONVERT_EXCEPTION (StringFormatterException);
VC_CONVERT_EXCEPTION (ExecutedProcessFailed);
VC_CONVERT_EXCEPTION (AlreadyInitialized);
VC_CONVERT_EXCEPTION (AssertionFailed);
VC_CONVERT_EXCEPTION (ExternalException);
VC_CONVERT_EXCEPTION (InsufficientData);
VC_CONVERT_EXCEPTION (NotApplicable);
VC_CONVERT_EXCEPTION (NotImplemented);
VC_CONVERT_EXCEPTION (NotInitialized);
VC_CONVERT_EXCEPTION (ParameterIncorrect);
VC_CONVERT_EXCEPTION (ParameterTooLarge);
VC_CONVERT_EXCEPTION (PartitionDeviceRequired);
VC_CONVERT_EXCEPTION (StringConversionFailed);
VC_CONVERT_EXCEPTION (TestFailed);
VC_CONVERT_EXCEPTION (TimeOut);
VC_CONVERT_EXCEPTION (UnknownException);
VC_CONVERT_EXCEPTION (UserAbort)
VC_CONVERT_EXCEPTION (CipherInitError);
VC_CONVERT_EXCEPTION (WeakKeyDetected);
VC_CONVERT_EXCEPTION (HigherVersionRequired);
VC_CONVERT_EXCEPTION (KeyfilePathEmpty);
VC_CONVERT_EXCEPTION (MissingVolumeData);
VC_CONVERT_EXCEPTION (MountedVolumeInUse);
VC_CONVERT_EXCEPTION (UnsupportedSectorSize);
VC_CONVERT_EXCEPTION (VolumeEncryptionNotCompleted);
VC_CONVERT_EXCEPTION (VolumeHostInUse);
VC_CONVERT_EXCEPTION (VolumeProtected);
VC_CONVERT_EXCEPTION (VolumeReadOnly);
VC_CONVERT_EXCEPTION (Pkcs11Exception);
VC_CONVERT_EXCEPTION (InvalidSecurityTokenKeyfilePath);
VC_CONVERT_EXCEPTION (SecurityTokenLibraryNotInitialized);
VC_CONVERT_EXCEPTION (SecurityTokenKeyfileAlreadyExists);
VC_CONVERT_EXCEPTION (SecurityTokenKeyfileNotFound);
VC_CONVERT_EXCEPTION (UnsupportedAlgoInTrueCryptMode);
VC_CONVERT_EXCEPTION (UnsupportedTrueCryptFormat);
VC_CONVERT_EXCEPTION (SystemException);
VC_CONVERT_EXCEPTION (CipherException);
VC_CONVERT_EXCEPTION (VolumeException);
VC_CONVERT_EXCEPTION (PasswordException);
throw *ex;
}
}