VeraCrypt
aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Common/Dlgcode.c136
-rw-r--r--src/Common/Dlgcode.h1
-rw-r--r--src/Common/Language.xml2
-rw-r--r--src/ExpandVolume/WinMain.cpp2
-rw-r--r--src/Format/Tcformat.c6
-rw-r--r--src/Mount/Mount.c10
6 files changed, 146 insertions, 11 deletions
diff --git a/src/Common/Dlgcode.c b/src/Common/Dlgcode.c
index bbe836e..4d3fdc7 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 ded8457..974d2e0 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 8c1b3ca..dc5ab17 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">
diff --git a/src/ExpandVolume/WinMain.cpp b/src/ExpandVolume/WinMain.cpp
index 3fea040..f673589 100644
--- a/src/ExpandVolume/WinMain.cpp
+++ b/src/ExpandVolume/WinMain.cpp
@@ -440,7 +440,7 @@ BOOL CALLBACK ExtcvPasswordDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARA
/* make autodetection the default */
SendMessage (hComboBox, CB_SETCURSEL, 0, 0);
- SendMessage (GetDlgItem (hwndDlg, IDC_PASSWORD), EM_LIMITTEXT, MAX_PASSWORD, 0);
+ ToNormalPwdField (hwndDlg, IDC_PASSWORD);
SendMessage (GetDlgItem (hwndDlg, IDC_CACHE), BM_SETCHECK, bCacheInDriver ? BST_CHECKED:BST_UNCHECKED, 0);
SendMessage (GetDlgItem (hwndDlg, IDC_PIM), EM_LIMITTEXT, MAX_PIM, 0);
diff --git a/src/Format/Tcformat.c b/src/Format/Tcformat.c
index c496a72..5437971 100644
--- a/src/Format/Tcformat.c
+++ b/src/Format/Tcformat.c
@@ -4265,7 +4265,7 @@ BOOL CALLBACK PageDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa
/* make autodetection the default */
SendMessage (hComboBox, CB_SETCURSEL, 0, 0);
- SendMessage (GetDlgItem (hwndDlg, IDC_PASSWORD_DIRECT), EM_LIMITTEXT, MAX_PASSWORD, 0);
+ ToNormalPwdField (hwndDlg, IDC_PASSWORD_DIRECT);
SetPassword (hwndDlg, IDC_PASSWORD_DIRECT, szRawPassword);
@@ -4345,8 +4345,8 @@ BOOL CALLBACK PageDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa
StringCbCopyW (str, sizeof(str), GetString ("PASSWORD_HELP"));
}
- SendMessage (GetDlgItem (hwndDlg, IDC_PASSWORD), EM_LIMITTEXT, MAX_PASSWORD, 0);
- SendMessage (GetDlgItem (hwndDlg, IDC_VERIFY), EM_LIMITTEXT, MAX_PASSWORD, 0);
+ ToNormalPwdField (hwndDlg, IDC_PASSWORD);
+ ToNormalPwdField (hwndDlg, IDC_VERIFY);
SetPassword (hwndDlg, IDC_PASSWORD, szRawPassword);
SetPassword (hwndDlg, IDC_VERIFY, szVerify);
diff --git a/src/Mount/Mount.c b/src/Mount/Mount.c
index e5f7b6f..da1d74f 100644
--- a/src/Mount/Mount.c
+++ b/src/Mount/Mount.c
@@ -2169,9 +2169,9 @@ BOOL CALLBACK PasswordChangeDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPAR
SetWindowTextW (hwndDlg, GetString ("IDD_PASSWORDCHANGE_DLG"));
LocalizeDialog (hwndDlg, "IDD_PASSWORDCHANGE_DLG");
- SendMessage (GetDlgItem (hwndDlg, IDC_OLD_PASSWORD), EM_LIMITTEXT, MAX_PASSWORD, 0);
- SendMessage (GetDlgItem (hwndDlg, IDC_PASSWORD), EM_LIMITTEXT, MAX_PASSWORD, 0);
- SendMessage (GetDlgItem (hwndDlg, IDC_VERIFY), EM_LIMITTEXT, MAX_PASSWORD, 0);
+ ToNormalPwdField (hwndDlg, IDC_OLD_PASSWORD);
+ ToNormalPwdField (hwndDlg, IDC_PASSWORD);
+ ToNormalPwdField (hwndDlg, IDC_VERIFY);
SendMessage (GetDlgItem (hwndDlg, IDC_OLD_PIM), EM_LIMITTEXT, MAX_PIM, 0);
SendMessage (GetDlgItem (hwndDlg, IDC_PIM), EM_LIMITTEXT, MAX_PIM, 0);
EnableWindow (GetDlgItem (hwndDlg, IDOK), FALSE);
@@ -2884,7 +2884,7 @@ BOOL CALLBACK PasswordDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lPa
/* make autodetection the default unless a specific PRF was specified in the command line */
SendMessage (hComboBox, CB_SETCURSEL, defaultPrfIndex, 0);
- SendMessage (GetDlgItem (hwndDlg, IDC_PASSWORD), EM_LIMITTEXT, MAX_PASSWORD, 0);
+ ToNormalPwdField (hwndDlg, IDC_PASSWORD);
SendMessage (GetDlgItem (hwndDlg, IDC_CACHE), BM_SETCHECK, bCacheInDriver ? BST_CHECKED:BST_UNCHECKED, 0);
SendMessage (GetDlgItem (hwndDlg, IDC_PIM), EM_LIMITTEXT, MAX_PIM, 0);
@@ -3575,7 +3575,7 @@ BOOL CALLBACK MountOptionsDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM
SetCheckBox (hwndDlg, IDC_KEYFILES_ENABLE_HIDVOL_PROT, hidVolProtKeyFilesParam.EnableKeyFiles);
- SendDlgItemMessage (hwndDlg, IDC_PASSWORD_PROT_HIDVOL, EM_LIMITTEXT, MAX_PASSWORD, 0);
+ ToNormalPwdField (hwndDlg, IDC_PASSWORD_PROT_HIDVOL);
SendDlgItemMessage (hwndDlg, IDC_PIM, EM_LIMITTEXT, MAX_PIM, 0);
if (mountOptions->ProtectedHidVolPassword.Length > 0)