VeraCrypt
aboutsummaryrefslogtreecommitdiff
path: root/src/ExpandVolume
diff options
context:
space:
mode:
authorMounir IDRASSI <mounir.idrassi@idrix.fr>2015-05-26 01:36:20 +0200
committerMounir IDRASSI <mounir.idrassi@idrix.fr>2015-05-26 01:38:15 +0200
commit8ebf5ac605d57eab80b600a7827d2ba48668d887 (patch)
tree6159a4d45fd79b15746b44ee986ddedb923ab91d /src/ExpandVolume
parent85e5e383f9b879736d7a793a5dc0f9bce20b8383 (diff)
downloadVeraCrypt-8ebf5ac605d57eab80b600a7827d2ba48668d887.tar.gz
VeraCrypt-8ebf5ac605d57eab80b600a7827d2ba48668d887.zip
Windows: first implementation of dynamic mode
Diffstat (limited to 'src/ExpandVolume')
-rw-r--r--src/ExpandVolume/DlgExpandVolume.cpp13
-rw-r--r--src/ExpandVolume/ExpandVolume.c17
-rw-r--r--src/ExpandVolume/ExpandVolume.h3
-rw-r--r--src/ExpandVolume/ExpandVolume.rc17
-rw-r--r--src/ExpandVolume/WinMain.cpp44
-rw-r--r--src/ExpandVolume/resource.h9
6 files changed, 80 insertions, 23 deletions
diff --git a/src/ExpandVolume/DlgExpandVolume.cpp b/src/ExpandVolume/DlgExpandVolume.cpp
index d6982933..554f4f6f 100644
--- a/src/ExpandVolume/DlgExpandVolume.cpp
+++ b/src/ExpandVolume/DlgExpandVolume.cpp
@@ -72,7 +72,7 @@ BOOL CALLBACK ExpandVolProgressDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, L
namespace VeraCryptExpander
{
/* defined in WinMain.c, referenced by ExpandVolumeWizard() */
-int ExtcvAskVolumePassword (HWND hwndDlg, Password *password, int *pkcs5, BOOL* truecryptMode, char *titleStringId, BOOL enableMountOptions);
+int ExtcvAskVolumePassword (HWND hwndDlg, Password *password, int *pkcs5, int *pin, BOOL* truecryptMode, char *titleStringId, BOOL enableMountOptions);
}
@@ -406,6 +406,7 @@ typedef struct
const char *volumePath;
Password *password;
int pkcs5_prf;
+ int pin;
BOOL truecryptMode;
BOOL write;
BOOL preserveTimestamps;
@@ -418,7 +419,7 @@ void CALLBACK OpenVolumeWaitThreadProc(void* pArg, HWND hwndDlg)
OpenVolumeThreadParam* pThreadParam = (OpenVolumeThreadParam*) pArg;
*(pThreadParam)->nStatus = OpenVolume(pThreadParam->context, pThreadParam->volumePath, pThreadParam->password, pThreadParam->pkcs5_prf,
- pThreadParam->truecryptMode, pThreadParam->write, pThreadParam->preserveTimestamps, pThreadParam->useBackupHeader);
+ pThreadParam->pin, pThreadParam->truecryptMode, pThreadParam->write, pThreadParam->preserveTimestamps, pThreadParam->useBackupHeader);
}
/*
@@ -444,7 +445,7 @@ void ExpandVolumeWizard (HWND hwndDlg, char *lpszVolume)
int nStatus = ERR_OS_ERROR;
wchar_t szTmp[4096];
Password VolumePassword;
- int VolumePkcs5 = 0;
+ int VolumePkcs5 = 0, VolumePin = -1;
uint64 hostSize, volSize, hostSizeFree, maxSizeFS;
BOOL bIsDevice, bIsLegacy;
DWORD dwError;
@@ -512,7 +513,7 @@ void ExpandVolumeWizard (HWND hwndDlg, char *lpszVolume)
OpenVolumeContext expandVol;
BOOL truecryptMode = FALSE;
- if (!VeraCryptExpander::ExtcvAskVolumePassword (hwndDlg, &VolumePassword, &VolumePkcs5, &truecryptMode, "ENTER_NORMAL_VOL_PASSWORD", FALSE))
+ if (!VeraCryptExpander::ExtcvAskVolumePassword (hwndDlg, &VolumePassword, &VolumePkcs5, &VolumePin, &truecryptMode, "ENTER_NORMAL_VOL_PASSWORD", FALSE))
{
goto ret;
}
@@ -530,6 +531,7 @@ void ExpandVolumeWizard (HWND hwndDlg, char *lpszVolume)
threadParam.volumePath = lpszVolume;
threadParam.password = &VolumePassword;
threadParam.pkcs5_prf = VolumePkcs5;
+ threadParam.pin = VolumePin;
threadParam.truecryptMode = FALSE;
threadParam.write = FALSE;
threadParam.preserveTimestamps = bPreserveTimestamp;
@@ -576,7 +578,7 @@ void ExpandVolumeWizard (HWND hwndDlg, char *lpszVolume)
WaitCursor();
// auto mount the volume to check the file system type
- nStatus=MountVolTemp(hwndDlg, lpszVolume, &driveNo, &VolumePassword, VolumePkcs5);
+ nStatus=MountVolTemp(hwndDlg, lpszVolume, &driveNo, &VolumePassword, VolumePkcs5, VolumePin);
if (nStatus != ERR_SUCCESS)
goto error;
@@ -651,6 +653,7 @@ void ExpandVolumeWizard (HWND hwndDlg, char *lpszVolume)
VolExpandParam.FileSystem = volFSType;
VolExpandParam.pVolumePassword = &VolumePassword;
VolExpandParam.VolumePkcs5 = VolumePkcs5;
+ VolExpandParam.VolumePin = VolumePin;
VolExpandParam.bIsDevice = bIsDevice;
VolExpandParam.bIsLegacy = bIsLegacy;
VolExpandParam.oldSize = bIsDevice ? volSize : hostSize;
diff --git a/src/ExpandVolume/ExpandVolume.c b/src/ExpandVolume/ExpandVolume.c
index 1d777a11..5b9509be 100644
--- a/src/ExpandVolume/ExpandVolume.c
+++ b/src/ExpandVolume/ExpandVolume.c
@@ -98,7 +98,7 @@ static int FsctlExtendVolume(char * szVolume, LONGLONG nTotalSectors );
int with Truecrypt error code (ERR_SUCCESS on success)
*/
-int MountVolTemp (HWND hwndDlg, char *volumePath, int *driveNo, Password *password, int pkcs5)
+int MountVolTemp (HWND hwndDlg, char *volumePath, int *driveNo, Password *password, int pkcs5, int pin)
{
MountOptions mountOptions;
ZeroMemory (&mountOptions, sizeof (mountOptions));
@@ -118,7 +118,7 @@ int MountVolTemp (HWND hwndDlg, char *volumePath, int *driveNo, Password *passwo
mountOptions.PartitionInInactiveSysEncScope = FALSE;
mountOptions.UseBackupHeader = FALSE;
- if (MountVolume (hwndDlg, *driveNo, volumePath, password, pkcs5, FALSE, FALSE, TRUE, &mountOptions, FALSE, FALSE) < 1)
+ if (MountVolume (hwndDlg, *driveNo, volumePath, password, pkcs5, pin, FALSE, FALSE, TRUE, &mountOptions, FALSE, FALSE) < 1)
{
*driveNo = -3;
return ERR_VOL_MOUNT_FAILED;
@@ -385,7 +385,7 @@ uint64 GetVolumeSizeByDataAreaSize (uint64 dataAreaSize, BOOL legacyVolume)
}
-int ExtendFileSystem (HWND hwndDlg , char *lpszVolume, Password *pVolumePassword, int VolumePkcs5, uint64 newDataAreaSize)
+int ExtendFileSystem (HWND hwndDlg , char *lpszVolume, Password *pVolumePassword, int VolumePkcs5, int VolumePin, uint64 newDataAreaSize)
{
char szVolumeGUID[128];
int driveNo = -1;
@@ -399,7 +399,7 @@ int ExtendFileSystem (HWND hwndDlg , char *lpszVolume, Password *pVolumePassword
DebugAddProgressDlgStatus (hwndDlg, "Mounting volume ...\r\n");
- nStatus=MountVolTemp(hwndDlg, lpszVolume, &driveNo, pVolumePassword, VolumePkcs5);
+ nStatus=MountVolTemp(hwndDlg, lpszVolume, &driveNo, pVolumePassword, VolumePkcs5, VolumePin);
if (nStatus!=ERR_SUCCESS)
{
driveNo = -1;
@@ -500,7 +500,7 @@ error:
Remarks: a lot of code is from TrueCrypt 'Common\Password.c' :: ChangePwd()
*/
-static int ExpandVolume (HWND hwndDlg, char *lpszVolume, Password *pVolumePassword, int VolumePkcs5, uint64 newHostSize, BOOL initFreeSpace)
+static int ExpandVolume (HWND hwndDlg, char *lpszVolume, Password *pVolumePassword, int VolumePkcs5, int VolumePin, uint64 newHostSize, BOOL initFreeSpace)
{
int nDosLinkCreated = 1, nStatus = ERR_OS_ERROR;
char szDiskFile[TC_MAX_PATH], szCFDevice[TC_MAX_PATH];
@@ -644,7 +644,7 @@ static int ExpandVolume (HWND hwndDlg, char *lpszVolume, Password *pVolumePasswo
/* Try to decrypt the header */
- nStatus = ReadVolumeHeader (FALSE, buffer, pVolumePassword, VolumePkcs5, FALSE, &cryptoInfo, NULL);
+ nStatus = ReadVolumeHeader (FALSE, buffer, pVolumePassword, VolumePkcs5, VolumePin, FALSE, &cryptoInfo, NULL);
if (nStatus == ERR_CIPHER_INIT_WEAK_KEY)
nStatus = 0; // We can ignore this error here
@@ -802,6 +802,7 @@ static int ExpandVolume (HWND hwndDlg, char *lpszVolume, Password *pVolumePasswo
cryptoInfo->mode,
pVolumePassword,
cryptoInfo->pkcs5,
+ VolumePin,
(char*)(cryptoInfo->master_keydata),
&ci,
newDataAreaSize,
@@ -968,7 +969,7 @@ error:
if (nStatus == ERR_SUCCESS)
{
- nStatus = ExtendFileSystem (hwndDlg, lpszVolume, pVolumePassword, VolumePkcs5, newDataAreaSize);
+ nStatus = ExtendFileSystem (hwndDlg, lpszVolume, pVolumePassword, VolumePkcs5, VolumePin, newDataAreaSize);
}
return nStatus;
@@ -983,7 +984,7 @@ void __cdecl volTransformThreadFunction (void *pExpandDlgParam)
HWND hwndDlg = (HWND) pParam->hwndDlg;
nStatus = ExpandVolume (hwndDlg, (char*)pParam->szVolumeName, pParam->pVolumePassword,
- pParam->VolumePkcs5, pParam->newSize, pParam->bInitFreeSpace );
+ pParam->VolumePkcs5, pParam->VolumePin, pParam->newSize, pParam->bInitFreeSpace );
if (nStatus!=ERR_SUCCESS && nStatus!=ERR_USER_ABORT)
handleError (hwndDlg, nStatus);
diff --git a/src/ExpandVolume/ExpandVolume.h b/src/ExpandVolume/ExpandVolume.h
index 805f1c02..8fc7c9b7 100644
--- a/src/ExpandVolume/ExpandVolume.h
+++ b/src/ExpandVolume/ExpandVolume.h
@@ -59,6 +59,7 @@ typedef struct
BOOL bInitFreeSpace;
Password *pVolumePassword;
int VolumePkcs5;
+ int VolumePin;
HWND hwndDlg;
} EXPAND_VOL_THREAD_PARAMS;
@@ -74,7 +75,7 @@ extern volatile BOOL bVolTransformThreadCancel; /* TRUE if the user cancels/paus
uint64 GetVolumeDataAreaSize (uint64 volumeSize, BOOL legacyVolume);
uint64 GetVolumeSizeByDataAreaSize (uint64 dataSize, BOOL legacyVolume);
int QueryVolumeInfo (HWND hwndDlg, const char *lpszVolume, uint64 * pHostSizeFree, uint64 * pSizeLimitFS );
-int MountVolTemp (HWND hwndDlg, char *volumePath, int *driveNo, Password *password, int pkcs5);
+int MountVolTemp (HWND hwndDlg, char *volumePath, int *driveNo, Password *password, int pkcs5, int pin);
BOOL GetFileSystemType(const char *szFileName, enum EV_FileSystem *pFS);
BOOL GetNtfsNumberOfSectors(char *rootPath, uint64 *pNumberOfSectors, DWORD *pBytesPerSector);
void __cdecl volTransformThreadFunction (void *hwndDlgArg);
diff --git a/src/ExpandVolume/ExpandVolume.rc b/src/ExpandVolume/ExpandVolume.rc
index 4f337133..7bae8494 100644
--- a/src/ExpandVolume/ExpandVolume.rc
+++ b/src/ExpandVolume/ExpandVolume.rc
@@ -113,24 +113,27 @@ BEGIN
LTEXT "Static",IDC_INFOEXPAND,8,6,361,134,SS_NOPREFIX | SS_SUNKEN,WS_EX_STATICEDGE
END
-IDD_PASSWORD_DLG DIALOGEX 0, 0, 322, 91
+IDD_PASSWORD_DLG DIALOGEX 0, 0, 322, 107
STYLE DS_SETFONT | DS_MODALFRAME | DS_3DLOOK | DS_FIXEDSYS | DS_CENTER | WS_POPUP | WS_VISIBLE | WS_CAPTION
CAPTION "Enter VeraCrypt Volume Password"
FONT 8, "MS Shell Dlg", 0, 0, 0x0
BEGIN
EDITTEXT IDC_PASSWORD,69,8,166,14,ES_PASSWORD | ES_AUTOHSCROLL
CONTROL "Cache passwords and keyfil&es in memory",IDC_CACHE,
- "Button",BS_AUTOCHECKBOX | WS_TABSTOP,70,50,153,10
- CONTROL "&Display password",IDC_SHOW_PASSWORD,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,70,63,83,10
- CONTROL "U&se keyfiles",IDC_KEYFILES_ENABLE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,70,75,83,11
- PUSHBUTTON "&Keyfiles...",IDC_KEY_FILES,171,72,64,14
- PUSHBUTTON "Mount Opti&ons...",IDC_MOUNT_OPTIONS,243,72,64,14
+ "Button",BS_AUTOCHECKBOX | WS_TABSTOP,70,63,153,10
+ CONTROL "&Display password",IDC_SHOW_PASSWORD,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,70,76,83,10
+ CONTROL "U&se keyfiles",IDC_KEYFILES_ENABLE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,70,89,83,11
+ PUSHBUTTON "&Keyfiles...",IDC_KEY_FILES,171,86,64,14
+ PUSHBUTTON "Mount Opti&ons...",IDC_MOUNT_OPTIONS,243,86,64,14
DEFPUSHBUTTON "OK",IDOK,243,8,64,14
PUSHBUTTON "Cancel",IDCANCEL,243,25,64,14
RTEXT "Password:",IDT_PASSWORD,0,10,65,13
COMBOBOX IDC_PKCS5_PRF_ID,69,26,86,90,CBS_DROPDOWNLIST | WS_TABSTOP
RTEXT "PKCS-5 PRF:",IDT_PKCS5_PRF,0,27,65,13
CONTROL "TrueCrypt Mode",IDC_TRUECRYPT_MODE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,159,28,76,10
+ RTEXT "Volume PIN:",IDT_PIN,0,46,65,13
+ EDITTEXT IDC_PIN,69,43,42,14,ES_RIGHT | ES_AUTOHSCROLL | ES_NUMBER
+ LTEXT "(Empty or 0 for default iterations)",IDC_PIN_HELP,115,46,189,8
END
IDD_EXPAND_PROGRESS_DLG DIALOGEX 0, 0, 376, 271
@@ -183,7 +186,7 @@ BEGIN
IDD_PASSWORD_DLG, DIALOG
BEGIN
- BOTTOMMARGIN, 63
+ BOTTOMMARGIN, 102
END
IDD_EXPAND_PROGRESS_DLG, DIALOG
diff --git a/src/ExpandVolume/WinMain.cpp b/src/ExpandVolume/WinMain.cpp
index 68ef281c..f8b3234c 100644
--- a/src/ExpandVolume/WinMain.cpp
+++ b/src/ExpandVolume/WinMain.cpp
@@ -392,6 +392,7 @@ BOOL CALLBACK ExtcvPasswordDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARA
WORD lw = LOWORD (wParam);
static Password *szXPwd;
static int *pkcs5;
+ static int *pin;
static BOOL* truecryptMode;
switch (msg)
@@ -401,6 +402,7 @@ BOOL CALLBACK ExtcvPasswordDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARA
int i, nIndex;
szXPwd = ((PasswordDlgParam *) lParam) -> password;
pkcs5 = ((PasswordDlgParam *) lParam) -> pkcs5;
+ pin = ((PasswordDlgParam *) lParam) -> pin;
truecryptMode = ((PasswordDlgParam *) lParam) -> truecryptMode;
LocalizeDialog (hwndDlg, "IDD_PASSWORD_DLG");
DragAcceptFiles (hwndDlg, TRUE);
@@ -443,6 +445,16 @@ BOOL CALLBACK ExtcvPasswordDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARA
SendMessage (GetDlgItem (hwndDlg, IDC_PASSWORD), EM_LIMITTEXT, MAX_PASSWORD, 0);
SendMessage (GetDlgItem (hwndDlg, IDC_CACHE), BM_SETCHECK, bCacheInDriver ? BST_CHECKED:BST_UNCHECKED, 0);
+ SendMessage (GetDlgItem (hwndDlg, IDC_PIN), EM_LIMITTEXT, MAX_PIN, 0);
+
+ if (*pin >= 0)
+ {
+ /* display the given PIN */
+ char szTmp[MAX_PIN + 1];
+ StringCbPrintfA(szTmp, sizeof(szTmp), "%d", *pin);
+
+ SetDlgItemText (hwndDlg, IDC_PIN, szTmp);
+ }
SetCheckBox (hwndDlg, IDC_KEYFILES_ENABLE, KeyFilesEnable);
@@ -538,6 +550,19 @@ BOOL CALLBACK ExtcvPasswordDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARA
SendMessage (GetDlgItem (hwndDlg, IDC_PASSWORD), EM_SETPASSWORDCHAR, '*', 0);
InvalidateRect (GetDlgItem (hwndDlg, IDC_PASSWORD), NULL, TRUE);
+ SetCheckBox (hwndDlg, IDC_KEYFILES_ENABLE, FALSE);
+ EnableWindow (GetDlgItem (hwndDlg, IDC_KEYFILES_ENABLE), FALSE);
+ EnableWindow (GetDlgItem (hwndDlg, IDC_KEY_FILES), FALSE);
+
+ if (*pin >= 0)
+ {
+ /* display the given PIN */
+ char szTmp[MAX_PIN + 1];
+ StringCbPrintfA(szTmp, sizeof(szTmp), "%d", *pin);
+
+ SetDlgItemText (hwndDlg, IDC_PIN, szTmp);
+ }
+
bPrebootPasswordDlgMode = TRUE;
}
return 1;
@@ -647,6 +672,13 @@ BOOL CALLBACK ExtcvPasswordDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARA
bCacheInDriver = IsButtonChecked (GetDlgItem (hwndDlg, IDC_CACHE));
*pkcs5 = (int) SendMessage (GetDlgItem (hwndDlg, IDC_PKCS5_PRF_ID), CB_GETITEMDATA, SendMessage (GetDlgItem (hwndDlg, IDC_PKCS5_PRF_ID), CB_GETCURSEL, 0, 0), 0);
*truecryptMode = GetCheckBox (hwndDlg, IDC_TRUECRYPT_MODE);
+
+ GetWindowText (GetDlgItem (hwndDlg, IDC_PIN), tmp, MAX_PIN + 1);
+ if (strlen(tmp))
+ *pin = (int) strtol(tmp, NULL, 10); /* IDC_PIN is configured to accept only numbers */
+ else
+ *pin = 0;
+
/* SHA-256 is not supported by TrueCrypt */
if ( (*truecryptMode)
&& ((*pkcs5 == SHA256) || (mountOptions.ProtectHiddenVolume && mountOptions.ProtectedHidVolPkcs5Prf == SHA256))
@@ -655,6 +687,14 @@ BOOL CALLBACK ExtcvPasswordDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARA
Error ("ALGO_NOT_SUPPORTED_FOR_TRUECRYPT_MODE", hwndDlg);
return 1;
}
+
+ if ( (*truecryptMode)
+ && (*pin != 0)
+ )
+ {
+ Error ("PIN_NOT_SUPPORTED_FOR_TRUECRYPT_MODE", hwndDlg);
+ return 1;
+ }
}
// Attempt to wipe password stored in the input field buffer
@@ -753,7 +793,7 @@ int RestoreVolumeHeader (HWND hwndDlg, char *lpszVolume)
return 0;
}
-int ExtcvAskVolumePassword (HWND hwndDlg, Password *password, int *pkcs5, BOOL* truecryptMode, char *titleStringId, BOOL enableMountOptions)
+int ExtcvAskVolumePassword (HWND hwndDlg, Password *password, int *pkcs5, int *pin, BOOL* truecryptMode, char *titleStringId, BOOL enableMountOptions)
{
int result;
PasswordDlgParam dlgParam;
@@ -763,6 +803,7 @@ int ExtcvAskVolumePassword (HWND hwndDlg, Password *password, int *pkcs5, BOOL*
dlgParam.password = password;
dlgParam.pkcs5 = pkcs5;
+ dlgParam.pin = pin;
dlgParam.truecryptMode = truecryptMode;
result = DialogBoxParamW (hInst,
@@ -773,6 +814,7 @@ int ExtcvAskVolumePassword (HWND hwndDlg, Password *password, int *pkcs5, BOOL*
{
password->Length = 0;
*pkcs5 = 0;
+ *pin = 0;
*truecryptMode = FALSE;
burn (&mountOptions.ProtectedHidVolPassword, sizeof (mountOptions.ProtectedHidVolPassword));
burn (&mountOptions.ProtectedHidVolPkcs5Prf, sizeof (mountOptions.ProtectedHidVolPkcs5Prf));
diff --git a/src/ExpandVolume/resource.h b/src/ExpandVolume/resource.h
index 9e2a2d87..29a451db 100644
--- a/src/ExpandVolume/resource.h
+++ b/src/ExpandVolume/resource.h
@@ -66,6 +66,13 @@
#define IDC_EDIT1 1114
#define IDC_BOX_STATUS 1114
#define IDC_TRUECRYPT_MODE 1140
+#define IDC_PREF_TEMP_CACHE_ON_MULTIPLE_MOUNT 1141
+#define IDT_PIN 1142
+#define IDC_PIN 1143
+#define IDC_PIN_HELP 1144
+#define IDT_OLD_PIN 1145
+#define IDC_OLD_PIN 1146
+#define IDC_OLD_PIN_HELP 1147
#define IDM_HELP 40001
#define IDM_ABOUT 40002
#define IDM_UNMOUNT_VOLUME 40003
@@ -137,7 +144,7 @@
#define _APS_NO_MFC 1
#define _APS_NEXT_RESOURCE_VALUE 120
#define _APS_NEXT_COMMAND_VALUE 40064
-#define _APS_NEXT_CONTROL_VALUE 1116
+#define _APS_NEXT_CONTROL_VALUE 1148
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif