Windows: Solve detection issue when resuming encryption. Add separate logic for manual selection of device and display error message in case of failure.

This commit is contained in:
Mounir IDRASSI 2015-05-06 20:38:30 +02:00
parent 061292130d
commit b3646b3237
7 changed files with 122 additions and 28 deletions

View File

@ -3016,6 +3016,7 @@ BOOL CALLBACK RawDevicesDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM l
{ {
LVCOLUMNW LvCol; LVCOLUMNW LvCol;
HWND hList = GetDlgItem (hwndDlg, IDC_DEVICELIST); HWND hList = GetDlgItem (hwndDlg, IDC_DEVICELIST);
RawDevicesDlgParam* pDlgParam = (RawDevicesDlgParam *) lParam;
LocalizeDialog (hwndDlg, "IDD_RAWDEVICES_DLG"); LocalizeDialog (hwndDlg, "IDD_RAWDEVICES_DLG");
@ -3048,9 +3049,14 @@ BOOL CALLBACK RawDevicesDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM l
devices.clear(); devices.clear();
itemToDeviceMap.clear(); itemToDeviceMap.clear();
WaitCursor(); if (pDlgParam->devices.empty())
devices = GetAvailableHostDevices (false, true, false); {
NormalCursor(); WaitCursor();
devices = GetAvailableHostDevices (false, true, false);
NormalCursor();
}
else
devices = pDlgParam->devices;
if (devices.empty()) if (devices.empty())
{ {
@ -3140,7 +3146,7 @@ BOOL CALLBACK RawDevicesDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM l
item.iItem = line++; item.iItem = line++;
} }
lpszFileName = (char *) lParam; lpszFileName = pDlgParam->pszFileName;
#ifdef VOLFORMAT #ifdef VOLFORMAT
EnableWindow (GetDlgItem (hwndDlg, IDOK), FALSE); EnableWindow (GetDlgItem (hwndDlg, IDOK), FALSE);
@ -3153,15 +3159,33 @@ BOOL CALLBACK RawDevicesDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM l
// catch non-device line selected // catch non-device line selected
if (msg == WM_NOTIFY && ((LPNMHDR) lParam)->code == LVN_ITEMCHANGED && (((LPNMLISTVIEW) lParam)->uNewState & LVIS_FOCUSED )) if (msg == WM_NOTIFY && ((LPNMHDR) lParam)->code == LVN_ITEMCHANGED && (((LPNMLISTVIEW) lParam)->uNewState & LVIS_FOCUSED ))
{ {
BOOL bEnableOkButton = FALSE;
LVITEM LvItem; LVITEM LvItem;
memset(&LvItem,0,sizeof(LvItem)); memset(&LvItem,0,sizeof(LvItem));
LvItem.mask = LVIF_TEXT | LVIF_PARAM; LvItem.mask = LVIF_TEXT | LVIF_PARAM;
LvItem.iItem = ((LPNMLISTVIEW) lParam)->iItem; LvItem.iItem = ((LPNMLISTVIEW) lParam)->iItem;
LvItem.pszText = lpszFileName; LvItem.pszText = lpszFileName;
LvItem.cchTextMax = TC_MAX_PATH; LvItem.cchTextMax = TC_MAX_PATH;
lpszFileName[0] = 0;
SendMessage (GetDlgItem (hwndDlg, IDC_DEVICELIST), LVM_GETITEM, LvItem.iItem, (LPARAM) &LvItem); SendMessage (GetDlgItem (hwndDlg, IDC_DEVICELIST), LVM_GETITEM, LvItem.iItem, (LPARAM) &LvItem);
EnableWindow (GetDlgItem ((HWND) hwndDlg, IDOK), lpszFileName[0] != 0 && lpszFileName[0] != ' '); if (lpszFileName[0] != 0 && lpszFileName[0] != ' ')
{
bEnableOkButton = TRUE;
#ifdef VOLFORMAT
if ( bInPlaceEncNonSysResumed && (WizardMode == WIZARD_MODE_NONSYS_DEVICE)
&& LvItem.iItem != -1 && itemToDeviceMap.find (LvItem.iItem) != itemToDeviceMap.end()
)
{
const HostDevice selectedDevice = itemToDeviceMap[LvItem.iItem];
if (selectedDevice.ContainsSystem)
{
bEnableOkButton = FALSE;
}
}
#endif
}
EnableWindow (GetDlgItem ((HWND) hwndDlg, IDOK), bEnableOkButton);
return 1; return 1;
} }
@ -3181,6 +3205,12 @@ BOOL CALLBACK RawDevicesDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM l
{ {
if (WizardMode != WIZARD_MODE_SYS_DEVICE) if (WizardMode != WIZARD_MODE_SYS_DEVICE)
{ {
if (bInPlaceEncNonSysResumed && (WizardMode == WIZARD_MODE_NONSYS_DEVICE))
{
// disable selection
return 1;
}
if (AskYesNo ("CONFIRM_SYSTEM_ENCRYPTION_MODE", hwndDlg) == IDNO) if (AskYesNo ("CONFIRM_SYSTEM_ENCRYPTION_MODE", hwndDlg) == IDNO)
{ {
EndDialog (hwndDlg, IDCANCEL); EndDialog (hwndDlg, IDCANCEL);
@ -3243,6 +3273,12 @@ BOOL CALLBACK RawDevicesDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM l
{ {
if (WizardMode != WIZARD_MODE_SYS_DEVICE) if (WizardMode != WIZARD_MODE_SYS_DEVICE)
{ {
if (bInPlaceEncNonSysResumed && (WizardMode == WIZARD_MODE_NONSYS_DEVICE))
{
// disable selection
return 1;
}
if (AskYesNo ("CONFIRM_SYSTEM_ENCRYPTION_MODE", hwndDlg) == IDNO) if (AskYesNo ("CONFIRM_SYSTEM_ENCRYPTION_MODE", hwndDlg) == IDNO)
{ {
NormalCursor (); NormalCursor ();

View File

@ -514,6 +514,12 @@ struct HostDevice
std::vector <HostDevice> Partitions; std::vector <HostDevice> Partitions;
}; };
struct RawDevicesDlgParam
{
std::vector <HostDevice> devices;
char *pszFileName;
};
BOOL BrowseFilesInDir (HWND hwndDlg, char *stringId, char *initialDir, char *lpszFileName, BOOL keepHistory, BOOL saveMode, wchar_t *browseFilter, const wchar_t *initialFileName = NULL, const wchar_t *defaultExtension = NULL); BOOL BrowseFilesInDir (HWND hwndDlg, char *stringId, char *initialDir, char *lpszFileName, BOOL keepHistory, BOOL saveMode, wchar_t *browseFilter, const wchar_t *initialFileName = NULL, const wchar_t *defaultExtension = NULL);
std::wstring SingleStringToWide (const std::string &singleString); std::wstring SingleStringToWide (const std::string &singleString);
std::wstring Utf8StringToWide (const std::string &utf8String); std::wstring Utf8StringToWide (const std::string &utf8String);

View File

@ -606,6 +606,8 @@
<string lang="en" key="HIDDEN_FILES_PRESENT_IN_KEYFILE_PATH">\n\nWARNING: Hidden file(s) have been found in a keyfile search path. Such hidden files cannot be used as keyfiles. If you need to use them as keyfiles, remove their 'Hidden' attribute (right-click each of them, select 'Properties', uncheck 'Hidden' and click OK). Note: Hidden files are visible only if the corresponding option is enabled (Computer > Organize > 'Folder and search options' > View).</string> <string lang="en" key="HIDDEN_FILES_PRESENT_IN_KEYFILE_PATH">\n\nWARNING: Hidden file(s) have been found in a keyfile search path. Such hidden files cannot be used as keyfiles. If you need to use them as keyfiles, remove their 'Hidden' attribute (right-click each of them, select 'Properties', uncheck 'Hidden' and click OK). Note: Hidden files are visible only if the corresponding option is enabled (Computer > Organize > 'Folder and search options' > View).</string>
<string lang="en" key="HIDDEN_VOL_PROT_PASSWORD_US_KEYB_LAYOUT">If you are attempting to protect a hidden volume containing a hidden system, please make sure you are using the standard US keyboard layout when typing the password for the hidden volume. This is required due to the fact that the password needs to be typed in the pre-boot environment (before Windows starts) where non-US Windows keyboard layouts are not available.</string> <string lang="en" key="HIDDEN_VOL_PROT_PASSWORD_US_KEYB_LAYOUT">If you are attempting to protect a hidden volume containing a hidden system, please make sure you are using the standard US keyboard layout when typing the password for the hidden volume. This is required due to the fact that the password needs to be typed in the pre-boot environment (before Windows starts) where non-US Windows keyboard layouts are not available.</string>
<string lang="en" key="FOUND_NO_PARTITION_W_DEFERRED_INPLACE_ENC">VeraCrypt has not found any volume where non-system encryption has been interrupted and where the volume header can be decrypted using the supplied password and/or keyfile(s).\n\nPlease make sure the password and/or keyfile(s) are correct and that the partition/volume is not being used by the system or applications (including antivirus software).</string> <string lang="en" key="FOUND_NO_PARTITION_W_DEFERRED_INPLACE_ENC">VeraCrypt has not found any volume where non-system encryption has been interrupted and where the volume header can be decrypted using the supplied password and/or keyfile(s).\n\nPlease make sure the password and/or keyfile(s) are correct and that the partition/volume is not being used by the system or applications (including antivirus software).</string>
<string lang="en" key="SELECTED_PARTITION_ALREADY_INPLACE_ENC">The selected partition/device is already fully encrypted.\nHeader Flags = 0x%.8X</string>
<string lang="en" key="SELECTED_PARTITION_NOT_INPLACE_ENC">The selected partition/device is not using in-place encryption.\nHeader Flags = 0x%.8X</string>
<string lang="en" key="SYSENC_MOUNT_WITHOUT_PBA_NOTE">\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 'System' > 'Mount Without Pre-Boot Authentication'.</string> <string lang="en" key="SYSENC_MOUNT_WITHOUT_PBA_NOTE">\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 'System' > 'Mount Without Pre-Boot Authentication'.</string>
<string lang="en" key="MOUNT_WITHOUT_PBA_VOL_ON_ACTIVE_SYSENC_DRIVE">In this mode, you cannot mount a partition located on a drive whose portion is within the key scope of active system encryption.\n\nBefore you can mount this partition in this mode, you need to either boot an operating system installed on a different drive (encrypted or unencrypted) or boot an unencrypted operating system.</string> <string lang="en" key="MOUNT_WITHOUT_PBA_VOL_ON_ACTIVE_SYSENC_DRIVE">In this mode, you cannot mount a partition located on a drive whose portion is within the key scope of active system encryption.\n\nBefore you can mount this partition in this mode, you need to either boot an operating system installed on a different drive (encrypted or unencrypted) or boot an unencrypted operating system.</string>
<string lang="en" key="PREV">&lt; &amp;Back</string> <string lang="en" key="PREV">&lt; &amp;Back</string>

View File

@ -796,8 +796,10 @@ static BOOL SelectContainer (HWND hwndDlg)
static BOOL SelectPartition (HWND hwndDlg) static BOOL SelectPartition (HWND hwndDlg)
{ {
RawDevicesDlgParam param;
param.pszFileName = szFileName;
int nResult = DialogBoxParamW (hInst, MAKEINTRESOURCEW (IDD_RAWDEVICES_DLG), hwndDlg, int nResult = DialogBoxParamW (hInst, MAKEINTRESOURCEW (IDD_RAWDEVICES_DLG), hwndDlg,
(DLGPROC) RawDevicesDlgProc, (LPARAM) & szFileName[0]); (DLGPROC) RawDevicesDlgProc, (LPARAM) & param);
if (nResult == IDOK) if (nResult == IDOK)
{ {
AddComboItem (GetDlgItem (hwndDlg, IDC_VOLUME), szFileName, bHistory); AddComboItem (GetDlgItem (hwndDlg, IDC_VOLUME), szFileName, bHistory);

View File

@ -259,33 +259,77 @@ vector <HostDevice> DeferredNonSysInPlaceEncDevices;
void CALLBACK ResumeInPlaceEncWaitThreadProc(void* pArg, HWND hwndDlg) void CALLBACK ResumeInPlaceEncWaitThreadProc(void* pArg, HWND hwndDlg)
{ {
char szDevicePath[MAX_PATH] = {0}; char szDevicePath[MAX_PATH] = {0};
RawDevicesDlgParam param;
param.devices = GetAvailableHostDevices (false, true, false);
param.pszFileName = szDevicePath;
DeferredNonSysInPlaceEncDevices.clear(); DeferredNonSysInPlaceEncDevices.clear();
if (IDOK != DialogBoxParamW (hInst,
if ((IDOK == DialogBoxParamW (hInst,
MAKEINTRESOURCEW (IDD_RAWDEVICES_DLG), hwndDlg, MAKEINTRESOURCEW (IDD_RAWDEVICES_DLG), hwndDlg,
(DLGPROC) RawDevicesDlgProc, (LPARAM) & szDevicePath[0])) (DLGPROC) RawDevicesDlgProc, (LPARAM) &param)) && strlen(szDevicePath))
{ {
szDevicePath[0] = 0; foreach (const HostDevice &device, param.devices)
}
foreach (const HostDevice &device, GetAvailableHostDevices (true, true))
{
if (device.IsPartition || device.DynamicVolume)
{ {
if ((strlen(szDevicePath) > 0) && (device.Path != szDevicePath)) if (device.Path == szDevicePath)
continue;
OpenVolumeContext volume;
if (OpenVolume (&volume, device.Path.c_str(), &volumePassword, hash_algo, FALSE, FALSE, FALSE, TRUE) == ERR_SUCCESS)
{ {
if ((volume.CryptoInfo->HeaderFlags & TC_HEADER_FLAG_NONSYS_INPLACE_ENC) != 0 OpenVolumeContext volume;
&& volume.CryptoInfo->EncryptedAreaLength.Value != volume.CryptoInfo->VolumeSize.Value) int status = OpenVolume (&volume, device.Path.c_str(), &volumePassword, hash_algo, FALSE, FALSE, FALSE, TRUE);
if ( status == ERR_SUCCESS)
{ {
DeferredNonSysInPlaceEncDevices.push_back (device); if ((volume.CryptoInfo->HeaderFlags & TC_HEADER_FLAG_NONSYS_INPLACE_ENC) != 0
&& volume.CryptoInfo->EncryptedAreaLength.Value != volume.CryptoInfo->VolumeSize.Value)
{
DeferredNonSysInPlaceEncDevices.push_back (device);
}
else if (volume.CryptoInfo->EncryptedAreaLength.Value == volume.CryptoInfo->VolumeSize.Value)
{
WCHAR szMsg[1024];
StringCbPrintfW(szMsg, sizeof(szMsg), GetString ("SELECTED_PARTITION_ALREADY_INPLACE_ENC"),
volume.CryptoInfo->HeaderFlags);
ErrorDirect(szMsg, hwndDlg);
}
else
{
WCHAR szMsg[1024];
StringCbPrintfW(szMsg, sizeof(szMsg), GetString ("SELECTED_PARTITION_NOT_INPLACE_ENC"),
volume.CryptoInfo->HeaderFlags);
ErrorDirect(szMsg, hwndDlg);
}
CloseVolume (&volume);
}
else
{
handleError(hwndDlg, status);
} }
CloseVolume (&volume); break;
}
}
}
else
{
foreach (const HostDevice &device, param.devices)
{
if ( !device.ContainsSystem
&& (device.IsPartition || device.DynamicVolume || device.IsVirtualPartition || device.Partitions.empty())
)
{
OpenVolumeContext volume;
if (OpenVolume (&volume, device.Path.c_str(), &volumePassword, hash_algo, FALSE, FALSE, FALSE, TRUE) == ERR_SUCCESS)
{
if ((volume.CryptoInfo->HeaderFlags & TC_HEADER_FLAG_NONSYS_INPLACE_ENC) != 0
&& volume.CryptoInfo->EncryptedAreaLength.Value != volume.CryptoInfo->VolumeSize.Value)
{
DeferredNonSysInPlaceEncDevices.push_back (device);
}
CloseVolume (&volume);
}
} }
} }
} }
@ -5232,10 +5276,11 @@ BOOL CALLBACK PageDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa
else else
{ {
// Select device // Select device
RawDevicesDlgParam param;
param.pszFileName = szFileName;
int nResult = DialogBoxParamW (hInst, int nResult = DialogBoxParamW (hInst,
MAKEINTRESOURCEW (IDD_RAWDEVICES_DLG), GetParent (hwndDlg), MAKEINTRESOURCEW (IDD_RAWDEVICES_DLG), GetParent (hwndDlg),
(DLGPROC) RawDevicesDlgProc, (LPARAM) & szFileName[0]); (DLGPROC) RawDevicesDlgProc, (LPARAM) & param);
// Check administrator privileges // Check administrator privileges
if (!strstr (szFileName, "Floppy") && !IsAdmin() && !IsUacSupported ()) if (!strstr (szFileName, "Floppy") && !IsAdmin() && !IsUacSupported ())

View File

@ -94,6 +94,7 @@ extern __int64 NonSysInplaceEncBytesDone;
extern __int64 NonSysInplaceEncTotalSize; extern __int64 NonSysInplaceEncTotalSize;
extern int nPbar; extern int nPbar;
extern volatile int WizardMode; extern volatile int WizardMode;
extern volatile BOOL bInPlaceEncNonSysResumed;
extern char HeaderKeyGUIView [KEY_GUI_VIEW_SIZE]; extern char HeaderKeyGUIView [KEY_GUI_VIEW_SIZE];
extern char MasterKeyGUIView [KEY_GUI_VIEW_SIZE]; extern char MasterKeyGUIView [KEY_GUI_VIEW_SIZE];

View File

@ -4823,8 +4823,10 @@ BOOL SelectContainer (HWND hwndDlg)
BOOL SelectPartition (HWND hwndDlg) BOOL SelectPartition (HWND hwndDlg)
{ {
RawDevicesDlgParam param;
param.pszFileName = szFileName;
int nResult = DialogBoxParamW (hInst, MAKEINTRESOURCEW (IDD_RAWDEVICES_DLG), hwndDlg, int nResult = DialogBoxParamW (hInst, MAKEINTRESOURCEW (IDD_RAWDEVICES_DLG), hwndDlg,
(DLGPROC) RawDevicesDlgProc, (LPARAM) & szFileName[0]); (DLGPROC) RawDevicesDlgProc, (LPARAM) & param);
if (nResult == IDOK) if (nResult == IDOK)
{ {
AddComboItem (GetDlgItem (hwndDlg, IDC_VOLUME), szFileName, bHistory); AddComboItem (GetDlgItem (hwndDlg, IDC_VOLUME), szFileName, bHistory);