diff options
author | Mounir IDRASSI <mounir.idrassi@idrix.fr> | 2020-03-03 01:34:21 +0100 |
---|---|---|
committer | Mounir IDRASSI <mounir.idrassi@idrix.fr> | 2020-03-10 10:32:45 +0100 |
commit | fa72ac51c4cb7d7a3184c718a48af589ebf9cf94 (patch) | |
tree | 04b57bd1b49c9ef0bf7204be7c8555138c396e57 | |
parent | 65500305404a6100b50161343637c115e5718c9e (diff) | |
download | VeraCrypt-fa72ac51c4cb7d7a3184c718a48af589ebf9cf94.tar.gz VeraCrypt-fa72ac51c4cb7d7a3184c718a48af589ebf9cf94.zip |
Windows: Support using token keyfile when creating file container using command line
-rw-r--r-- | src/Format/Tcformat.c | 34 |
1 files changed, 33 insertions, 1 deletions
diff --git a/src/Format/Tcformat.c b/src/Format/Tcformat.c index 3d394c16..976809de 100644 --- a/src/Format/Tcformat.c +++ b/src/Format/Tcformat.c @@ -259,8 +259,10 @@ BOOL bOperationSuccess = FALSE; BOOL bGuiMode = TRUE; BOOL bSystemIsGPT = FALSE; +KeyFile *FirstCmdKeyFile = NULL; + int nPbar = 0; /* Control ID of progress bar:- for format code */ wchar_t HeaderKeyGUIView [KEY_GUI_VIEW_SIZE]; wchar_t MasterKeyGUIView [KEY_GUI_VIEW_SIZE]; @@ -487,8 +489,10 @@ static void localcleanup (void) burn (maskRandPool, sizeof(maskRandPool)); burn (szFileName, sizeof(szFileName)); burn (szDiskFile, sizeof(szDiskFile)); + KeyFileRemoveAll (&FirstCmdKeyFile); + // Attempt to wipe the GUI fields showing portions of randpool, of the master and header keys wmemset (tmp, L'X', ARRAYSIZE(tmp)); tmp [ARRAYSIZE(tmp)-1] = 0; SetWindowText (hRandPool, tmp); @@ -6175,9 +6179,9 @@ BOOL CALLBACK MainDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa showKeys = FALSE; bGuiMode = FALSE; - if (CmdVolumePassword.Length == 0) + if (CmdVolumePassword.Length == 0 && !FirstCmdKeyFile) AbortProcess ("ERR_PASSWORD_MISSING"); if (CmdVolumeFileSize == 0) AbortProcess ("ERR_SIZE_MISSING"); @@ -6330,8 +6334,13 @@ BOOL CALLBACK MainDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa exit (1); } } + if (!KeyFilesApply (hwndDlg, &volumePassword, FirstCmdKeyFile, NULL)) + { + exit (1); + } + volTransformThreadFunction (hwndDlg); exit (bOperationSuccess? 0 : 1); } @@ -9007,8 +9016,9 @@ void ExtractCommandLine (HWND hwndDlg, wchar_t *lpszCommandLine) OptionNoSizeCheck, OptionQuickFormat, OptionFastCreateFile, OptionEnableMemoryProtection, + OptionKeyfile, }; argument args[]= { @@ -9031,8 +9041,9 @@ void ExtractCommandLine (HWND hwndDlg, wchar_t *lpszCommandLine) { OptionNoSizeCheck, L"/nosizecheck", NULL, FALSE }, { OptionQuickFormat, L"/quick", NULL, FALSE }, { OptionFastCreateFile, L"/fastcreatefile", NULL, FALSE }, { OptionEnableMemoryProtection, L"/protectMemory", NULL, FALSE }, + { OptionKeyfile, L"/keyfile", L"/k", FALSE }, // Internal { CommandResumeSysEncLogOn, L"/acsysenc", L"/a", TRUE }, { CommandResumeSysEnc, L"/csysenc", L"/c", TRUE }, @@ -9449,8 +9460,29 @@ void ExtractCommandLine (HWND hwndDlg, wchar_t *lpszCommandLine) AbortProcess ("COMMAND_LINE_ERROR"); } break; + case OptionKeyfile: + { + wchar_t tmpPath [2 * TC_MAX_PATH] = {0}; + if (HAS_ARGUMENT == GetArgumentValue (lpszCommandLineArgs, &i, + nNoCommandLineArgs, tmpPath, ARRAYSIZE (tmpPath))) + { + KeyFile *kf; + RelativePath2Absolute (tmpPath); + kf = (KeyFile *) malloc (sizeof (KeyFile)); + if (kf) + { + StringCchCopyW (kf->FileName, ARRAYSIZE(kf->FileName), tmpPath); + FirstCmdKeyFile = KeyFileAdd (FirstCmdKeyFile, kf); + } + } + else + AbortProcess ("COMMAND_LINE_ERROR"); + } + + break; + default: DialogBoxParamW (hInst, MAKEINTRESOURCEW (IDD_COMMANDHELP_DLG), hwndDlg, (DLGPROC) CommandHelpDlgProc, (LPARAM) &as); |