VeraCrypt
aboutsummaryrefslogtreecommitdiff
path: root/src/Common
diff options
context:
space:
mode:
authorMounir IDRASSI <mounir.idrassi@idrix.fr>2018-08-07 00:56:56 +0200
committerMounir IDRASSI <mounir.idrassi@idrix.fr>2018-08-07 00:58:49 +0200
commit41ba7a06d3ac55752f9f50a1454eacdda62b1ae4 (patch)
tree8fa26f832d959bf2c5f7a88f8abe1d845136467c /src/Common
parent88a6e7fd1198fe828d0f2f8ac5a9bbb7e9bfd4a8 (diff)
downloadVeraCrypt-41ba7a06d3ac55752f9f50a1454eacdda62b1ae4.tar.gz
VeraCrypt-41ba7a06d3ac55752f9f50a1454eacdda62b1ae4.zip
Windows: Display a balloon tip warning or error message when the value pasted to password field is truncated or when there is no room for additional characters because of maximum password length reached
Diffstat (limited to 'src/Common')
-rw-r--r--src/Common/Dlgcode.c136
-rw-r--r--src/Common/Dlgcode.h1
-rw-r--r--src/Common/Language.xml2
3 files changed, 137 insertions, 2 deletions
diff --git a/src/Common/Dlgcode.c b/src/Common/Dlgcode.c
index bbe836e7..4d3fdc78 100644
--- a/src/Common/Dlgcode.c
+++ b/src/Common/Dlgcode.c
@@ -81,6 +81,18 @@
#pragma comment( lib, "setupapi.lib" )
+#ifndef TTI_INFO_LARGE
+#define TTI_INFO_LARGE 4
+#endif
+
+#ifndef TTI_WARNING_LARGE
+#define TTI_WARNING_LARGE 5
+#endif
+
+#ifndef TTI_ERROR_LARGE
+#define TTI_ERROR_LARGE 6
+#endif
+
/* GPT Partition Type GUIDs */
#define LOCAL_DEFINE_GUID(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) const GUID name = {l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8}
LOCAL_DEFINE_GUID(PARTITION_ENTRY_UNUSED_GUID, 0x00000000L, 0x0000, 0x0000, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00); // Entry unused
@@ -1178,11 +1190,131 @@ static LRESULT CALLBACK BootPwdFieldProc (HWND hwnd, UINT message, WPARAM wParam
void ToBootPwdField (HWND hwndDlg, UINT ctrlId)
{
HWND hwndCtrl = GetDlgItem (hwndDlg, ctrlId);
-
- SetWindowLongPtrW (hwndCtrl, GWLP_USERDATA, (LONG_PTR) GetWindowLongPtrW (hwndCtrl, GWLP_WNDPROC));
+ WNDPROC originalwp = (WNDPROC) GetWindowLongPtrW (hwndCtrl, GWLP_USERDATA);
+ // if ToNormalPwdField has been called before, GWLP_USERDATA already contains original WNDPROC
+ if (!originalwp)
+ {
+ SetWindowLongPtrW (hwndCtrl, GWLP_USERDATA, (LONG_PTR) GetWindowLongPtrW (hwndCtrl, GWLP_WNDPROC));
+ }
SetWindowLongPtrW (hwndCtrl, GWLP_WNDPROC, (LONG_PTR) BootPwdFieldProc);
}
+// Ensures that a warning is displayed when user is pasting a password longer than the maximum
+// length which is set to 64 characters
+static LRESULT CALLBACK NormalPwdFieldProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
+{
+ WNDPROC wp = (WNDPROC) GetWindowLongPtrW (hwnd, GWLP_USERDATA);
+
+ switch (message)
+ {
+ case WM_PASTE:
+ {
+ bool bBlock = false;
+ if (OpenClipboard (NULL))
+ {
+ HANDLE h = GetClipboardData (CF_UNICODETEXT);
+ if (h)
+ {
+ wchar_t *pchData = (wchar_t*)GlobalLock(h);
+ int txtlen = 0;
+ while (*pchData)
+ {
+ if (*pchData == '\r' || *pchData == '\n')
+ break;
+ else
+ {
+ txtlen++;
+ pchData++;
+ }
+ }
+
+ if (txtlen)
+ {
+ int curLen = GetWindowTextLength (hwnd);
+ if (curLen == MAX_PASSWORD)
+ {
+ EDITBALLOONTIP ebt;
+
+ ebt.cbStruct = sizeof( EDITBALLOONTIP );
+ ebt.pszText = GetString ("PASSWORD_MAXLENGTH_REACHED");
+ ebt.pszTitle = lpszTitle;
+ ebt.ttiIcon = TTI_ERROR_LARGE; // tooltip warning icon
+
+ SendMessage(hwnd, EM_SHOWBALLOONTIP, 0, (LPARAM)&ebt);
+
+ MessageBeep (0xFFFFFFFF);
+
+ bBlock = true;
+ }
+ else if ((txtlen + curLen) > MAX_PASSWORD)
+ {
+ EDITBALLOONTIP ebt;
+
+ ebt.cbStruct = sizeof( EDITBALLOONTIP );
+ ebt.pszText = GetString ("PASSWORD_PASTED_TRUNCATED");
+ ebt.pszTitle = lpszTitle;
+ ebt.ttiIcon = TTI_WARNING_LARGE; // tooltip warning icon
+
+ SendMessage(hwnd, EM_SHOWBALLOONTIP, 0, (LPARAM)&ebt);
+
+ MessageBeep (0xFFFFFFFF);
+ }
+ else
+ SendMessage(hwnd, EM_HIDEBALLOONTIP, 0, 0);
+ }
+ GlobalUnlock(h);
+ }
+ CloseClipboard ();
+ }
+
+ if (bBlock)
+ return FALSE;
+ }
+ break;
+ case WM_CHAR:
+ {
+ DWORD dwStartPos = 0, dwEndPos = 0;
+ short vk = VkKeyScanW ((WCHAR) wParam);
+ BYTE vkCode = LOBYTE (vk);
+ BYTE vkState = HIBYTE (vk);
+ bool ctrlPressed = (vkState & 2) && !(vkState & 4);
+
+ // check if there is a selected text
+ SendMessage (hwnd, EM_GETSEL, (WPARAM) &dwStartPos, (LPARAM) &dwEndPos);
+
+ if ((dwStartPos == dwEndPos)
+ && (vkCode != VK_DELETE) && (vkCode != VK_BACK)
+ && !ctrlPressed
+ && (GetWindowTextLength (hwnd) == MAX_PASSWORD))
+ {
+ EDITBALLOONTIP ebt;
+
+ ebt.cbStruct = sizeof( EDITBALLOONTIP );
+ ebt.pszText = GetString ("PASSWORD_MAXLENGTH_REACHED");
+ ebt.pszTitle = lpszTitle;
+ ebt.ttiIcon = TTI_ERROR_LARGE; // tooltip warning icon
+
+ SendMessage(hwnd, EM_SHOWBALLOONTIP, 0, (LPARAM)&ebt);
+
+ MessageBeep (0xFFFFFFFF);
+ }
+ else
+ SendMessage(hwnd, EM_HIDEBALLOONTIP, 0, 0);
+ }
+ break;
+ }
+
+ return CallWindowProcW (wp, hwnd, message, wParam, lParam);
+}
+
+void ToNormalPwdField (HWND hwndDlg, UINT ctrlId)
+{
+ HWND hwndCtrl = GetDlgItem (hwndDlg, ctrlId);
+
+ SendMessage (hwndCtrl, EM_LIMITTEXT, MAX_PASSWORD, 0);
+ SetWindowLongPtrW (hwndCtrl, GWLP_USERDATA, (LONG_PTR) GetWindowLongPtrW (hwndCtrl, GWLP_WNDPROC));
+ SetWindowLongPtrW (hwndCtrl, GWLP_WNDPROC, (LONG_PTR) NormalPwdFieldProc);
+}
// This function currently serves the following purposes:
diff --git a/src/Common/Dlgcode.h b/src/Common/Dlgcode.h
index ded84578..974d2e05 100644
--- a/src/Common/Dlgcode.h
+++ b/src/Common/Dlgcode.h
@@ -484,6 +484,7 @@ BOOL ToCustHyperlink (HWND hwndDlg, UINT ctrlId, HFONT hFont);
void DisableCloseButton (HWND hwndDlg);
void EnableCloseButton (HWND hwndDlg);
void ToBootPwdField (HWND hwndDlg, UINT ctrlId);
+void ToNormalPwdField (HWND hwndDlg, UINT ctrlId);
void AccommodateTextField (HWND hwndDlg, UINT ctrlId, BOOL bFirstUpdate, HFONT hFont);
BOOL GetDriveLabel (int driveNo, wchar_t *label, int labelSize);
BOOL GetSysDevicePaths (HWND hwndDlg);
diff --git a/src/Common/Language.xml b/src/Common/Language.xml
index 8c1b3ca5..dc5ab171 100644
--- a/src/Common/Language.xml
+++ b/src/Common/Language.xml
@@ -1421,6 +1421,8 @@
<entry lang="en" key="IDC_BLOCK_SYSENC_TRIM">Block TRIM command on system partition/drive</entry>
<entry lang="en" key="WINDOWS_EFI_BOOT_LOADER_MISSING">ERROR: Windows EFI system loader could not be located on the disk. Operation will be aborted.</entry>
<entry lang="en" key="SYSENC_EFI_UNSUPPORTED_SECUREBOOT">It is currently not possible to encrypt a system if SecureBoot is enabled and if VeraCrypt custom keys are not loaded into the machine firmware. SecureBoot needs to be disabled in the BIOS configuration in order to allow system encryption to proceed.</entry>
+ <entry lang="en" key="PASSWORD_PASTED_TRUNCATED">Pasted text truncated because the password maximum length is 64 characters</entry>
+ <entry lang="en" key="PASSWORD_MAXLENGTH_REACHED">Password already reached its maximum length of 64 characters.\nNo additional character is allowed.</entry>
</localization>
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="VeraCrypt">