/[winpt]/trunk/Src/wptPassphraseDlg.cpp
ViewVC logotype

Diff of /trunk/Src/wptPassphraseDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 327 by twoaday, Sat Mar 17 22:13:40 2007 UTC revision 328 by twoaday, Fri Sep 25 16:07:38 2009 UTC
# Line 1  Line 1 
1  /* wptPassphraseDlg.cpp - Dialog to get the passphrase  /* wptPassphraseDlg.cpp - Dialog to get the passphrase
2   *      Copyright (C) 2001-2006 Timo Schulz   *      Copyright (C) 2001-2006, 2009 Timo Schulz
3   *   *
4   * This file is part of WinPT.   * This file is part of WinPT.
5   *   *
# Line 30  Line 30 
30  #include "wptVersion.h"  #include "wptVersion.h"
31  #include "wptTypes.h"  #include "wptTypes.h"
32  #include "wptRegistry.h"  #include "wptRegistry.h"
33    #include "wptErrors.h"
34  #include "StringBuffer.h"  #include "StringBuffer.h"
35    
36    
37  struct passphrase_s {  struct passphrase_s {
38      char *title;    /* Title of the dialog. */      char *title;    /* Title of the dialog. */
39      char pwd[256];  /* The actual passphrase. */      // FIXME: do not use static buffer
40        char pwd[2048];  /* The actual passphrase. */
41      int strict;     /* Do a simple check how good the passphrase is. */      int strict;     /* Do a simple check how good the passphrase is. */
42      int repeat;     /* Indicate last try was wrong. */        int repeat;     /* Indicate last try was wrong. */  
43      int cancel;     /* 1 if user cancelled operation. */      int cancel;     /* 1 if user cancelled operation. */
# Line 47  struct passphrase_s { Line 49  struct passphrase_s {
49    
50  const char* get_keyinfo (gpgme_key_t key);  const char* get_keyinfo (gpgme_key_t key);
51    
52    static subclass_s passwd_edit_proc;
53    
54    /* We sub-class the passphrase edit control to monitor
55       the structure of the passphrase. This output is used
56       as a quality INDICATOR(!). */
57    static BOOL CALLBACK
58    edit_subclass_proc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
59    {  
60        HWND dlg = passwd_edit_proc.dlg;        
61        switch (msg) {
62        case WM_CHAR:
63            int n, pos = 0;
64            n = GetWindowTextLength (GetDlgItem (dlg, IDC_PASSWD_PWD));
65            if (n > 0)
66                pos = n*6;
67            if (pos > 100)
68                pos = 100;
69            SendDlgItemMessage (dlg, IDC_PASSWD_QOP, PBM_SETPOS, (WPARAM)pos, 0);
70            break;
71        }
72        
73        return CallWindowProc (passwd_edit_proc.old, hwnd, msg, wparam, lparam);
74    }
75    
76    
77  /* Fill in the key information in the combo box,  /* Fill in the key information in the combo box,
78     according to the key in @key. */     according to the key in @key. */
# Line 88  passwd_dlg_proc (HWND dlg, UINT msg, WPA Line 114  passwd_dlg_proc (HWND dlg, UINT msg, WPA
114              SetDlgItemText (dlg, IDC_PASSWD_INFO, _("Repeat Passphrase"));              SetDlgItemText (dlg, IDC_PASSWD_INFO, _("Repeat Passphrase"));
115          else          else
116              SetDlgItemText (dlg, IDC_PASSWD_INFO, _("Enter Passphrase"));              SetDlgItemText (dlg, IDC_PASSWD_INFO, _("Enter Passphrase"));
117          if (pwd->key)          if (pwd->key) {
118                ShowWindow (GetDlgItem (dlg, IDC_PASSWD_QOPINF), SW_HIDE);
119                ShowWindow (GetDlgItem (dlg, IDC_PASSWD_QOP), SW_HIDE);
120              set_passphrase_hint (dlg, pwd->key);              set_passphrase_hint (dlg, pwd->key);
121            }
122          else          else
123              ShowWindow (GetDlgItem (dlg, IDC_PASSWD_KEYINF), SW_HIDE);              ShowWindow (GetDlgItem (dlg, IDC_PASSWD_KEYINF), SW_HIDE);
124          SetDlgItemText (dlg, IDC_PASSWD_HIDE, _("&Hide Typing"));          SetDlgItemText (dlg, IDC_PASSWD_HIDE, _("&Hide Typing"));
125          SetDlgItemText (dlg, IDCANCEL, _("&Cancel"));          SetDlgItemText (dlg, IDCANCEL, _("&Cancel"));
126          SetDlgItemText (dlg, IDOK, _("&OK"));          SetDlgItemText (dlg, IDOK, _("&OK"));
127            SetDlgItemText (dlg, IDC_PASSWD_QOPINF, _("Quality indicator:"));
128                    
129            if (!pwd->key) {
130                HWND hwnd;
131                hwnd = GetDlgItem (dlg, IDC_PASSWD_PWD);
132                passwd_edit_proc.dlg = dlg;
133                passwd_edit_proc.current = (WNDPROC)edit_subclass_proc;
134                passwd_edit_proc.old = (WNDPROC)GetWindowLong(hwnd, GWL_WNDPROC);
135                if (passwd_edit_proc.old) {
136                    if (!SetWindowLong (hwnd, GWL_WNDPROC, (LONG)passwd_edit_proc.current)) {
137                        msg_box (dlg, "Could not set keylist window procedure.",
138                                 _("Key Manager"), MB_ERR);
139                        BUG (NULL);
140                    }
141                }
142            }
143    
144          SetFocus (GetDlgItem (dlg, IDC_PASSWD_PWD));          SetFocus (GetDlgItem (dlg, IDC_PASSWD_PWD));
145          center_window2 (dlg, NULL, HWND_TOPMOST);          center_window2 (dlg, NULL, HWND_TOPMOST);
146          center_window (dlg, NULL);          center_window (dlg, NULL);
# Line 110  passwd_dlg_proc (HWND dlg, UINT msg, WPA Line 156  passwd_dlg_proc (HWND dlg, UINT msg, WPA
156      case WM_DESTROY:      case WM_DESTROY:
157          if (!reg_prefs.no_safe_pwd_ctrl)          if (!reg_prefs.no_safe_pwd_ctrl)
158              safe_edit_control_free (dlg, IDC_PASSWD_PWD);              safe_edit_control_free (dlg, IDC_PASSWD_PWD);
159            balloon_msg_disable ();
160          break;          break;
161                    
162      case WM_COMMAND:      case WM_COMMAND:
# Line 128  passwd_dlg_proc (HWND dlg, UINT msg, WPA Line 175  passwd_dlg_proc (HWND dlg, UINT msg, WPA
175              nbytes = SafeGetDlgItemText (dlg, IDC_PASSWD_PWD,              nbytes = SafeGetDlgItemText (dlg, IDC_PASSWD_PWD,
176                                           pwd->pwd, DIM (pwd->pwd)-1);                                           pwd->pwd, DIM (pwd->pwd)-1);
177              if (!nbytes && pwd->not_empty) {              if (!nbytes && pwd->not_empty) {
178                  msg_box (dlg, _("Please enter a passphrase."),                  show_balloon_msg (GetDlgItem (dlg, IDC_PASSWD_PWD),
179                           _("Passphrase Dialog"), MB_ERR);                                    _("Please enter a passphrase."), IDI_ERROR);
180                  return TRUE;                  return TRUE;
181              }              }
182    
# Line 147  passwd_dlg_proc (HWND dlg, UINT msg, WPA Line 194  passwd_dlg_proc (HWND dlg, UINT msg, WPA
194                       is_8bit_string (pwd->pwd)) {                       is_8bit_string (pwd->pwd)) {
195                  cancel = msg_box (dlg,                  cancel = msg_box (dlg,
196                              _("The passphrase contains 8-bit characters.\n"                              _("The passphrase contains 8-bit characters.\n"
197                                "It is not suggested to use charset specific characters.\n"                                "Make sure that all systems you work on properly support UTF-8 handling.\n"
198                                "Continue?"),                                "Continue?"),
199                          _("Key Generation"), MB_ICONWARNING|MB_YESNO);                          _("Key Generation"), MB_ICONWARNING|MB_YESNO);
200                  if (cancel == IDNO) {                  if (cancel == IDNO) {
# Line 191  request_key_passphrase (gpgme_key_t key, Line 238  request_key_passphrase (gpgme_key_t key,
238          *ret_cancel = 1;          *ret_cancel = 1;
239          return NULL;          return NULL;
240      }      }
241      p = native_to_utf8 (pass.pwd);      if (emulate_utf8_bug)
242            p = native_to_utf8 (pass.pwd);
243        else
244            p = m_strdup (pass.pwd);
245      wipememory (pass.pwd, sizeof (pass.pwd));      wipememory (pass.pwd, sizeof (pass.pwd));
246      return p;      return p;
247  }  }
# Line 221  request_passphrase (const char *title, i Line 271  request_passphrase (const char *title, i
271          *ret_cancel = 1;          *ret_cancel = 1;
272          return NULL;          return NULL;
273      }      }
274      p = native_to_utf8 (pass.pwd);      if (emulate_utf8_bug)
275            p = native_to_utf8 (pass.pwd);
276        else
277            p = m_strdup (pass.pwd);
278      wipememory (pass.pwd, sizeof (pass.pwd));      wipememory (pass.pwd, sizeof (pass.pwd));
279      return p;      return p;
280  }  }

Legend:
Removed from v.327  
changed lines
  Added in v.328

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26