Windows: Implement specifying the size of the generated keyfiles and also letting VeraCrypt choose random size values.

This commit is contained in:
Mounir IDRASSI 2014-12-09 00:11:15 +01:00
parent 32e72d1117
commit eb9cb16aeb
4 changed files with 77 additions and 18 deletions

View File

@ -194,14 +194,14 @@ BEGIN
CONTROL "",IDC_INFO_BOX_TEXT,"RichEdit20A",ES_MULTILINE | ES_READONLY | ES_NUMBER | WS_BORDER | WS_VSCROLL | WS_TABSTOP,5,6,361,188
END
IDD_KEYFILE_GENERATOR DIALOGEX 0, 0, 308, 303
IDD_KEYFILE_GENERATOR DIALOGEX 0, 0, 308, 325
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | DS_CENTER | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "VeraCrypt - Keyfile Generator"
FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN
DEFPUSHBUTTON "Close",IDCLOSE,237,10,59,14
COMBOBOX IDC_PRF_ID,79,49,91,90,CBS_DROPDOWNLIST | WS_TABSTOP
PUSHBUTTON "Generate and Save Keyfile...",IDC_GENERATE_AND_SAVE_KEYFILE,92,281,131,14
PUSHBUTTON "Generate and Save Keyfile...",IDC_GENERATE_AND_SAVE_KEYFILE,92,302,141,14
LTEXT "IMPORTANT: Move your mouse as randomly as possible within this window. The longer you move it, the better. This significantly increases the cryptographic strength of the keyfile.",IDT_KEYFILE_GENERATOR_NOTE,11,5,213,33
CONTROL "",IDC_STATIC,"Static",SS_ETCHEDHORZ,1,40,307,1,WS_EX_STATICEDGE
RTEXT "Mixing PRF:",IDT_PRF,6,51,67,10,SS_CENTERIMAGE
@ -210,8 +210,12 @@ BEGIN
CONTROL "Display pool content",IDC_DISPLAY_POOL_CONTENTS,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,191,51,111,10
LTEXT "Number of keyfiles:",IDT_NUMBER_KEYFILES,9,247,75,8
EDITTEXT IDC_NUMBER_KEYFILES,92,244,51,14,ES_RIGHT | ES_AUTOHSCROLL | ES_NUMBER
LTEXT "Keyfiles base name:",IDT_KEYFILES_BASE_NAME,9,266,75,8
EDITTEXT IDC_KEYFILES_BASE_NAME,92,263,131,14,ES_AUTOHSCROLL
LTEXT "Keyfiles base name:",IDT_KEYFILES_BASE_NAME,9,287,75,8
EDITTEXT IDC_KEYFILES_BASE_NAME,92,284,141,14,ES_AUTOHSCROLL
LTEXT "Keyfiles size (in Bytes):",IDT_KEYFILES_SIZE,9,266,75,8
EDITTEXT IDC_KEYFILES_SIZE,92,264,51,14,ES_RIGHT | ES_AUTOHSCROLL | ES_NUMBER
CONTROL "Random size ( 64 <-> 1048576 )",IDC_KEYFILES_RANDOM_SIZE,
"Button",BS_AUTOCHECKBOX | WS_TABSTOP,149,266,140,10
END
IDD_MULTI_CHOICE_DLG DIALOGEX 0, 0, 167, 322
@ -377,7 +381,7 @@ BEGIN
LEFTMARGIN, 7
RIGHTMARGIN, 299
TOPMARGIN, 7
BOTTOMMARGIN, 299
BOTTOMMARGIN, 321
END
IDD_MULTI_CHOICE_DLG, DIALOG

View File

@ -4996,8 +4996,12 @@ BOOL CALLBACK KeyfileGeneratorDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LP
#endif
SetTimer (hwndDlg, 0xfd, RANDPOOL_DISPLAY_REFRESH_INTERVAL, NULL);
SendMessage (GetDlgItem (hwndDlg, IDC_POOL_CONTENTS), WM_SETFONT, (WPARAM) hFixedDigitFont, (LPARAM) TRUE);
SendMessage (GetDlgItem (hwndDlg, IDC_NUMBER_KEYFILES), EM_SETLIMITTEXT, (WPARAM) (TC_MAX_PATH - 1), 0);
// 9-digit limit for the number of keyfiles (more than enough!)
SendMessage (GetDlgItem (hwndDlg, IDC_NUMBER_KEYFILES), EM_SETLIMITTEXT, (WPARAM) 9, 0);
SetWindowText(GetDlgItem (hwndDlg, IDC_NUMBER_KEYFILES), "1");
// maximum keyfile size is 1048576, so limit the edit control to 7 characters
SendMessage (GetDlgItem (hwndDlg, IDC_KEYFILES_SIZE), EM_SETLIMITTEXT, (WPARAM) 7, 0);
SetWindowText(GetDlgItem (hwndDlg, IDC_KEYFILES_SIZE), "64");
// set the maximum length of the keyfile base name to (TC_MAX_PATH - 1)
SendMessage (GetDlgItem (hwndDlg, IDC_KEYFILES_BASE_NAME), EM_SETLIMITTEXT, (WPARAM) (TC_MAX_PATH - 1), 0);
return 1;
@ -5064,23 +5068,28 @@ BOOL CALLBACK KeyfileGeneratorDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LP
return 1;
}
if (lw == IDC_KEYFILES_RANDOM_SIZE)
{
EnableWindow(GetDlgItem (hwndDlg, IDC_KEYFILES_SIZE), !GetCheckBox (hwndDlg, IDC_KEYFILES_RANDOM_SIZE));
}
if (lw == IDC_GENERATE_AND_SAVE_KEYFILE)
{
char szNumberKeyFiles[TC_MAX_PATH] = {0};
char szNumber[16] = {0};
char szFileBaseName[TC_MAX_PATH];
char szDirName[TC_MAX_PATH];
char szFileName [3*TC_MAX_PATH];
unsigned char keyfile [MAX_PASSWORD];
char szFileName [2*TC_MAX_PATH + 16];
unsigned char *keyfile = NULL;
int fhKeyfile = -1, status;
long keyfilesCount = 0, i;
long keyfilesCount = 0, keyfilesSize = 0, i;
char* fileExtensionPtr = 0;
char szSuffix[32];
BOOL bBaseNameValid = FALSE;
BOOL bRandomSize = GetCheckBox (hwndDlg, IDC_KEYFILES_RANDOM_SIZE);
if (!GetWindowText(GetDlgItem (hwndDlg, IDC_NUMBER_KEYFILES), szNumberKeyFiles, TC_MAX_PATH))
szNumberKeyFiles[0] = 0;
if (!GetWindowText(GetDlgItem (hwndDlg, IDC_NUMBER_KEYFILES), szNumber, sizeof(szNumber)))
szNumber[0] = 0;
keyfilesCount = strtoul(szNumberKeyFiles, NULL, 0);
keyfilesCount = strtoul(szNumber, NULL, 0);
if (keyfilesCount <= 0 || keyfilesCount == LONG_MAX)
{
Warning("KEYFILE_INCORRECT_NUMBER");
@ -5088,6 +5097,20 @@ BOOL CALLBACK KeyfileGeneratorDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LP
return 1;
}
if (!bRandomSize)
{
if (!GetWindowText(GetDlgItem (hwndDlg, IDC_KEYFILES_SIZE), szNumber, sizeof(szNumber)))
szNumber[0] = 0;
keyfilesSize = strtoul(szNumber, NULL, 0);
if (keyfilesSize < 64 || keyfilesSize > 1024*1024)
{
Warning("KEYFILE_INCORRECT_SIZE");
SendMessage(hwndDlg, WM_NEXTDLGCTL, (WPARAM) GetDlgItem (hwndDlg, IDC_KEYFILES_SIZE), TRUE);
return 1;
}
}
if (!GetWindowText(GetDlgItem (hwndDlg, IDC_KEYFILES_BASE_NAME), szFileBaseName, TC_MAX_PATH))
szFileBaseName[0] = 0;
@ -5117,6 +5140,8 @@ BOOL CALLBACK KeyfileGeneratorDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LP
WaitCursor();
keyfile = (unsigned char*) TCalloc( bRandomSize? KEYFILE_MAX_READ_LEN : keyfilesSize );
for (i= 0; i < keyfilesCount; i++)
{
StringCbCopy(szFileName, sizeof(szFileName), szDirName);
@ -5154,6 +5179,7 @@ BOOL CALLBACK KeyfileGeneratorDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LP
status = AskWarnNoYesString (s);
if (status == IDNO)
{
TCfree(keyfile);
NormalCursor();
return 1;
}
@ -5162,33 +5188,56 @@ BOOL CALLBACK KeyfileGeneratorDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LP
/* Conceive the file */
if ((fhKeyfile = _open(szFileName, _O_CREAT|_O_TRUNC|_O_WRONLY|_O_BINARY, _S_IREAD|_S_IWRITE)) == -1)
{
TCfree(keyfile);
NormalCursor();
handleWin32Error (hwndDlg);
return 1;
}
if (bRandomSize)
{
/* Generate a random size */
if (!RandgetBytes ((unsigned char*) &keyfilesSize, sizeof(keyfilesSize), FALSE))
{
_close (fhKeyfile);
DeleteFile (szFileName);
TCfree(keyfile);
NormalCursor();
return 1;
}
/* since keyfilesSize < 1024 * 1024, we mask with 0x000FFFFF */
keyfilesSize = (long) (((unsigned long) keyfilesSize) & 0x000FFFFF);
keyfilesSize %= ((KEYFILE_MAX_READ_LEN - 64) + 1);
keyfilesSize += 64;
}
/* Generate the keyfile */
if (!RandgetBytes (keyfile, sizeof(keyfile), TRUE))
if (!RandgetBytesFull (keyfile, keyfilesSize, TRUE, TRUE))
{
_close (fhKeyfile);
DeleteFile (szFileName);
TCfree(keyfile);
NormalCursor();
return 1;
}
/* Write the keyfile */
status = _write (fhKeyfile, keyfile, sizeof(keyfile));
burn (keyfile, sizeof(keyfile));
status = _write (fhKeyfile, keyfile, keyfilesSize);
burn (keyfile, keyfilesSize);
_close (fhKeyfile);
if (status == -1)
{
TCfree(keyfile);
NormalCursor();
handleWin32Error (hwndDlg);
return 1;
}
}
TCfree(keyfile);
NormalCursor();
Info("KEYFILE_CREATED");

View File

@ -44,6 +44,7 @@
<control lang="en" key="IDC_HIDVOL_WIZ_MODE_FULL">Normal mode</control>
<control lang="en" key="IDC_KB">&amp;KB</control>
<control lang="en" key="IDC_KEYFILES_ENABLE">U&amp;se keyfiles</control>
<control lang="en" key="IDC_KEYFILES_RANDOM_SIZE">Random size ( 64 <-> 1048576 )</control>
<control lang="en" key="IDC_KEY_FILES">&amp;Keyfiles...</control>
<control lang="en" key="IDC_LINK_HASH_INFO">Information on hash algorithms</control>
<control lang="en" key="IDC_LINK_MORE_INFO_ABOUT_CIPHER">More information</control>
@ -332,6 +333,7 @@
<control lang="en" key="IDT_KEYFILE_WARNING">WARNING: If you lose a keyfile or if any bit of its first 1024 kilobytes changes, it will be impossible to mount volumes that use the keyfile!</control>
<control lang="en" key="IDT_KEY_UNIT">bits</control>
<control lang="en" key="IDT_NUMBER_KEYFILES">Number of keyfiles:</control>
<control lang="en" key="IDT_KEYFILES_SIZE">Keyfiles size (in Bytes):</control>
<control lang="en" key="IDT_KEYFILES_BASE_NAME">Keyfiles base name:</control>
<control lang="en" key="IDT_LANGPACK_AUTHORS">Translated by:</control>
<control lang="en" key="IDT_PLAINTEXT">Plaintext size:</control>
@ -868,6 +870,7 @@
<string lang="en" key="ENTER_HEADER_BACKUP_PASSWORD">Enter password for the header stored in backup file</string>
<string lang="en" key="KEYFILE_CREATED">Keyfiles have been successfully created.</string>
<string lang="en" key="KEYFILE_INCORRECT_NUMBER">The number of keyfiles you supplied is invalid.</string>
<string lang="en" key="KEYFILE_INCORRECT_SIZE">The keyfile size must be comprized between 64 and 1048576 bytes.</string>
<string lang="en" key="KEYFILE_EMPTY_BASE_NAME">Please enter a name for the keyfile(s) to be generated</string>
<string lang="en" key="KEYFILE_INVALID_BASE_NAME">The base name of the keyfile(s) is invalid</string>
<string lang="en" key="KEYFILE_ALREADY_EXISTS">The keyfile '%s' already exists.\nDo you want to overwrite it? The generation process will be stopped if you answer No.</string>

View File

@ -180,6 +180,9 @@
#define IDC_NUMBER_KEYFILES 5118
#define IDT_KEYFILES_BASE_NAME 5119
#define IDC_KEYFILES_BASE_NAME 5120
#define IDC_KEYFILES_SIZE 5121
#define IDC_KEYFILES_RANDOM_SIZE 5122
#define IDT_KEYFILES_SIZE 5123
// Next default values for new objects
//
@ -188,7 +191,7 @@
#define _APS_NO_MFC 1
#define _APS_NEXT_RESOURCE_VALUE 542
#define _APS_NEXT_COMMAND_VALUE 40001
#define _APS_NEXT_CONTROL_VALUE 5121
#define _APS_NEXT_CONTROL_VALUE 5124
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif