VeraCrypt
aboutsummaryrefslogtreecommitdiff
path: root/src/Common
diff options
context:
space:
mode:
authorMounir IDRASSI <mounir.idrassi@idrix.fr>2015-08-24 01:31:30 +0200
committerMounir IDRASSI <mounir.idrassi@idrix.fr>2015-08-27 02:18:40 +0200
commitad3b8eca694ed4d7a0ff17f955736725aad0cea6 (patch)
tree1faaca5e08fdd89b7304b2ceec00366e4fb70564 /src/Common
parent20cb199e55f2f29316a24ff5723c2f8e3b0f4a98 (diff)
downloadVeraCrypt-ad3b8eca694ed4d7a0ff17f955736725aad0cea6.tar.gz
VeraCrypt-ad3b8eca694ed4d7a0ff17f955736725aad0cea6.zip
Windows: Protect against using a container file as its own keyfile. Normalizing path names to never use '/' but always '\'.
Diffstat (limited to 'src/Common')
-rw-r--r--src/Common/Dlgcode.c10
-rw-r--r--src/Common/Dlgcode.h1
-rw-r--r--src/Common/Keyfiles.c31
-rw-r--r--src/Common/Keyfiles.h3
-rw-r--r--src/Common/Language.xml1
5 files changed, 39 insertions, 7 deletions
diff --git a/src/Common/Dlgcode.c b/src/Common/Dlgcode.c
index abad5e70..ead50a73 100644
--- a/src/Common/Dlgcode.c
+++ b/src/Common/Dlgcode.c
@@ -6184,6 +6184,16 @@ BOOL CheckFileExtension (char *fileName)
return FALSE;
}
+void CorrectFileName (char* fileName)
+{
+ /* replace '/' by '\' */
+ size_t i, len = strlen (fileName);
+ for (i = 0; i < len; i++)
+ {
+ if (fileName [i] == '/')
+ fileName [i] = '\\';
+ }
+}
void IncreaseWrongPwdRetryCount (int count)
{
diff --git a/src/Common/Dlgcode.h b/src/Common/Dlgcode.h
index e3f73e07..fa7a2b38 100644
--- a/src/Common/Dlgcode.h
+++ b/src/Common/Dlgcode.h
@@ -328,6 +328,7 @@ static BOOL CALLBACK CloseVolumeExplorerWindowsEnum( HWND hwnd, LPARAM driveNo);
BOOL CloseVolumeExplorerWindows (HWND hwnd, int driveNo);
BOOL CheckCapsLock (HWND hwnd, BOOL quiet);
BOOL CheckFileExtension (char *fileName);
+void CorrectFileName (char* fileName);
void IncreaseWrongPwdRetryCount (int count);
void ResetWrongPwdRetryCount (void);
BOOL WrongPwdRetryCountOverLimit (void);
diff --git a/src/Common/Keyfiles.c b/src/Common/Keyfiles.c
index 26973252..549ffe6e 100644
--- a/src/Common/Keyfiles.c
+++ b/src/Common/Keyfiles.c
@@ -222,7 +222,7 @@ close:
}
-BOOL KeyFilesApply (HWND hwndDlg, Password *password, KeyFile *firstKeyFile)
+BOOL KeyFilesApply (HWND hwndDlg, Password *password, KeyFile *firstKeyFile, const char* volumeFileName)
{
BOOL status = TRUE;
KeyFile kfSubStruct;
@@ -322,7 +322,7 @@ BOOL KeyFilesApply (HWND hwndDlg, Password *password, KeyFile *firstKeyFile)
StringCbPrintfA (kfSub->FileName, sizeof(kfSub->FileName), "%s%c%s", kf->FileName,
'\\',
fBuf.name
- );
+ );
// Determine whether it's a path or a file
if (stat (kfSub->FileName, &statStruct) != 0)
@@ -346,6 +346,13 @@ BOOL KeyFilesApply (HWND hwndDlg, Password *password, KeyFile *firstKeyFile)
continue;
}
+ CorrectFileName (kfSub->FileName);
+ if (volumeFileName && (_stricmp (volumeFileName, kfSub->FileName) == 0))
+ {
+ // skip if it is the current container file name
+ continue;
+ }
+
++keyfileCount;
// Apply keyfile to the pool
@@ -474,13 +481,25 @@ BOOL CALLBACK KeyFilesDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lPa
{
if (SelectMultipleFiles (hwndDlg, "SELECT_KEYFILE", kf->FileName, sizeof(kf->FileName),bHistory))
{
+ bool containerFileSkipped = false;
do
{
- param->FirstKeyFile = KeyFileAdd (param->FirstKeyFile, kf);
- LoadKeyList (hwndDlg, param->FirstKeyFile);
-
- kf = (KeyFile *) malloc (sizeof (KeyFile));
+ CorrectFileName (kf->FileName);
+ if (_stricmp (param->VolumeFileName, kf->FileName) == 0)
+ containerFileSkipped = true;
+ else
+ {
+ param->FirstKeyFile = KeyFileAdd (param->FirstKeyFile, kf);
+ LoadKeyList (hwndDlg, param->FirstKeyFile);
+
+ kf = (KeyFile *) malloc (sizeof (KeyFile));
+ }
} while (SelectMultipleFilesNext (kf->FileName, sizeof(kf->FileName)));
+
+ if (containerFileSkipped)
+ {
+ Warning ("SELECTED_KEYFILE_IS_CONTAINER_FILE", hwndDlg);
+ }
}
free (kf);
diff --git a/src/Common/Keyfiles.h b/src/Common/Keyfiles.h
index 61ca83e6..8400ebc3 100644
--- a/src/Common/Keyfiles.h
+++ b/src/Common/Keyfiles.h
@@ -30,6 +30,7 @@ typedef struct KeyFileStruct
typedef struct
{
+ char VolumeFileName[MAX_PATH + 1];
BOOL EnableKeyFiles;
KeyFile *FirstKeyFile;
} KeyFilesDlgParam;
@@ -38,7 +39,7 @@ KeyFile *KeyFileAdd (KeyFile *firstKeyFile, KeyFile *keyFile);
void KeyFileRemoveAll (KeyFile **firstKeyFile);
KeyFile *KeyFileClone (KeyFile *keyFile);
KeyFile *KeyFileCloneAll (KeyFile *firstKeyFile);
-BOOL KeyFilesApply (HWND hwndDlg, Password *password, KeyFile *firstKeyFile);
+BOOL KeyFilesApply (HWND hwndDlg, Password *password, KeyFile *firstKeyFilem, const char* volumeFileName);
BOOL CALLBACK KeyFilesDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam);
BOOL KeyfilesPopupMenu (HWND hwndDlg, POINT popupPosition, KeyFilesDlgParam *dialogParam);
diff --git a/src/Common/Language.xml b/src/Common/Language.xml
index 558cc6d6..c47b1b84 100644
--- a/src/Common/Language.xml
+++ b/src/Common/Language.xml
@@ -647,6 +647,7 @@
<string lang="en" key="SELECT_KEYFILE">Select Keyfile</string>
<string lang="en" key="SELECT_KEYFILE_PATH">Select a keyfile search path. WARNING: Note that only the path will be remembered, not the filenames!</string>
<string lang="en" key="SELECT_KEYFILE_GENERATION_DIRECTORY">Select a directory where to store the keyfiles.</string>
+ <string lang="en" key="SELECTED_KEYFILE_IS_CONTAINER_FILE">The current container file was selected as a keyfile. It will be skipped.</string>
<string lang="en" key="SERPENT_HELP">Designed by Ross Anderson, Eli Biham, and Lars Knudsen. Published in 1998. 256-bit key, 128-bit block. Mode of operation is XTS. Serpent was one of the AES finalists.</string>
<string lang="en" key="SIZE_HELP">Please specify the size of the container you want to create.\n\nIf you create a dynamic (sparse-file) container, this parameter will specify its maximum possible size.\n\nNote that the minimum possible size of a FAT volume is 292 KB. The minimum possible size of an NTFS volume is 3792 KB.</string>
<string lang="en" key="SIZE_HELP_HIDDEN_HOST_VOL">Please specify the size of the outer volume to be created (you will first create the outer volume and then a hidden volume within it). The minimum possible size of a volume within which a hidden volume is intended to be created is 340 KB.</string>