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

Diff of /trunk/Src/wptKeysignDlg.cpp

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

revision 41 by twoaday, Fri Oct 28 07:15:26 2005 UTC revision 181 by twoaday, Tue Mar 14 11:01:22 2006 UTC
# Line 1  Line 1 
1  /* wptKeysignDlg.cpp - Key signing dialog  /* wptKeysignDlg.cpp - Key signing dialog
2   *      Copyright (C) 2001-2005 Timo Schulz   *      Copyright (C) 2001-2006 Timo Schulz
3   *   *
4   * This file is part of WinPT.   * This file is part of WinPT.
5   *   *
# Line 17  Line 17 
17   * along with WinPT; if not, write to the Free Software Foundation,   * along with WinPT; if not, write to the Free Software Foundation,
18   * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA   * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
19   */   */
20    #ifdef HAVE_CONFIG_H
21    #include <config.h>
22    #endif
23    
24  #include <windows.h>  #include <windows.h>
25  #include <commctrl.h>  #include <commctrl.h>
26    #include <time.h>
27    
28  #include "../resource.h"  #include "resource.h"
29  #include "wptGPG.h"  #include "wptGPG.h"
30  #include "wptNLS.h"  #include "wptNLS.h"
31  #include "wptW32API.h"  #include "wptW32API.h"
# Line 33  Line 37 
37  #include "wptDlgs.h"  #include "wptDlgs.h"
38  #include "wptUTF8.h"  #include "wptUTF8.h"
39  #include "wptRegistry.h"  #include "wptRegistry.h"
40  #include "wptKeyList.h"  #include "wptKeylist.h"
41  #include "wptKeyEdit.h"  #include "wptKeyEdit.h"
42    
 static int sig_class_choice = 0;  
43    
44  /* Return a beautified printable fingerprint of @fpr. */  /* Return a beautified printable fingerprint of @fpr. */
45  static const char*  static const char*
# Line 83  static int Line 86  static int
86  do_fill_seckeylist (HWND dlg, const char *keyid)  do_fill_seckeylist (HWND dlg, const char *keyid)
87  {  {
88      gpg_keycache_t sec;      gpg_keycache_t sec;
89      gpgme_key_t pk;      gpgme_key_t pk, defkey;
90      const char * s;      const char *s;
91      char * uid, * p;          char *uid, *p;
92      int i = 0, n=0;      int i = 0, n = 0, curr_sel = 0;
93    
94      sec = keycache_get_ctx (0);      sec = keycache_get_ctx (0);
95      if (!sec)      if (!sec)
96          BUG (0);          BUG (0);
97        gpg_keycache_get_default_key (sec, &defkey);
98      gpg_keycache_rewind (sec);      gpg_keycache_rewind (sec);
99      while (!gpg_keycache_next_key (sec, 1, &pk)) {      while (!gpg_keycache_next_key (sec, 1, &pk)) {
100          if (!pk)          if (!pk)
# Line 107  do_fill_seckeylist (HWND dlg, const char Line 111  do_fill_seckeylist (HWND dlg, const char
111          s = pk->uids->name;          s = pk->uids->name;
112          if (!s)          if (!s)
113              continue;              continue;
114            if (defkey && !strcmp (defkey->subkeys->keyid, pk->subkeys->keyid))
115                curr_sel = i;
116          uid = utf8_to_wincp (s, strlen (s));          uid = utf8_to_wincp (s, strlen (s));
117          p = new char[strlen (uid) + 64];          p = new char[strlen (uid) + 64];
118          if (!p)          if (!p)
119              BUG (NULL);              BUG (NULL);
120          _snprintf (p, strlen (uid) + 63, "%s (%s)", uid, get_keyinfo (pk));          _snprintf (p, strlen (uid) + 63, "%s (%s)", uid, get_keyinfo (pk));
121          SendDlgItemMessage (dlg, IDC_KEYSIGN_KEYLIST, CB_ADDSTRING, i, (LPARAM)(char *)p);          SendDlgItemMessage (dlg, IDC_KEYSIGN_KEYLIST,
122          SendDlgItemMessage (dlg, IDC_KEYSIGN_KEYLIST, CB_SETITEMDATA, i++, (LPARAM)(DWORD)pk);                              CB_ADDSTRING, i, (LPARAM)(char *)p);
123            SendDlgItemMessage (dlg, IDC_KEYSIGN_KEYLIST,
124                                CB_SETITEMDATA, i++, (LPARAM)(DWORD)pk);
125          free_if_alloc (p);          free_if_alloc (p);
126          free (uid);          free (uid);
127          n++;          n++;
128      }      }
129      SendDlgItemMessage (dlg, IDC_KEYSIGN_KEYLIST, CB_SETCURSEL, 0, 0);      SendDlgItemMessage (dlg, IDC_KEYSIGN_KEYLIST,
130                            CB_SETCURSEL, (WPARAM)curr_sel, 0);
131      if (!n)      if (!n)
132          return -1;          return -1;
133      return 0;      return 0;
# Line 150  do_check_protection (HWND dlg) Line 159  do_check_protection (HWND dlg)
159  BOOL CALLBACK  BOOL CALLBACK
160  sig_class_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)  sig_class_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
161  {  {
162        int sig_class = 0;
163    
164      switch (msg) {      switch (msg) {
165      case WM_INITDIALOG:      case WM_INITDIALOG:
166          SetWindowText (dlg, _("Choose Signature Class"));          SetWindowText (dlg, _("Choose Signature Class"));
# Line 164  sig_class_dlg_proc (HWND dlg, UINT msg, Line 175  sig_class_dlg_proc (HWND dlg, UINT msg,
175          return TRUE;          return TRUE;
176    
177      case WM_COMMAND:      case WM_COMMAND:
178          switch( LOWORD( wparam ) ) {          switch (LOWORD (wparam)) {
179          case IDOK:          case IDOK:
180              if (IsDlgButtonChecked (dlg, IDC_SIGCLASS_CLASS0))              if (IsDlgButtonChecked (dlg, IDC_SIGCLASS_CLASS0))
181                  sig_class_choice = 0;                  sig_class = 0;
182              else if (IsDlgButtonChecked (dlg, IDC_SIGCLASS_CLASS1))              else if (IsDlgButtonChecked (dlg, IDC_SIGCLASS_CLASS1))
183                  sig_class_choice = 1;                  sig_class = 1;
184              else if (IsDlgButtonChecked (dlg, IDC_SIGCLASS_CLASS2))              else if (IsDlgButtonChecked (dlg, IDC_SIGCLASS_CLASS2))
185                  sig_class_choice = 2;                  sig_class = 2;
186              else if (IsDlgButtonChecked (dlg, IDC_SIGCLASS_CLASS3))              else if (IsDlgButtonChecked (dlg, IDC_SIGCLASS_CLASS3))
187                  sig_class_choice = 3;                  sig_class = 3;
188              else              else
189                  sig_class_choice = 0;                  sig_class = 0;
190              EndDialog (dlg, TRUE);              EndDialog (dlg, sig_class);
191                return TRUE;
192    
193            case IDCANCEL:
194                EndDialog (dlg, 0);
195              return TRUE;              return TRUE;
196          }          }
197          break;          break;
# Line 190  sig_class_dlg_proc (HWND dlg, UINT msg, Line 205  sig_class_dlg_proc (HWND dlg, UINT msg,
205  static const char*  static const char*
206  get_expire_date (gpgme_key_t key)  get_expire_date (gpgme_key_t key)
207  {  {
     static char tmp[64];  
   
208      u32 u = key->subkeys->expires;      u32 u = key->subkeys->expires;
209      if (!u)      if (!u)
210          return _("never");          return _("never");
# Line 206  show_photo (winpt_key_t key) Line 219  show_photo (winpt_key_t key)
219  }  }
220    
221    
222    /* Check if the given system time @st points to today. */
223    static int
224    date_is_today (SYSTEMTIME *st)
225    {
226        time_t t;
227        struct tm *tm;
228    
229        t = time (NULL);
230        tm = localtime (&t);
231        if (st->wDay == tm->tm_mday &&
232            st->wYear == tm->tm_year+1900 &&
233            st->wMonth == tm->tm_mon+1)
234            return -1;
235        return 0;
236    }
237    
238    
239  /* Dialog box procedure to sign a key. */  /* Dialog box procedure to sign a key. */
240  BOOL CALLBACK  BOOL CALLBACK
241  keysign_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)  keysign_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
# Line 220  keysign_dlg_proc (HWND dlg, UINT msg, WP Line 250  keysign_dlg_proc (HWND dlg, UINT msg, WP
250      char *uid = NULL;      char *uid = NULL;
251      const char *keyid, *s;      const char *keyid, *s;
252      int type, expires=0, idx;      int type, expires=0, idx;
253        int sig_class = 0;
254            
255      switch ( msg )  {      switch (msg)  {
256      case WM_INITDIALOG:      case WM_INITDIALOG:
257          if (lparam == NULL)          if (lparam == 0)
258              dlg_fatal_error (dlg, "Could not get dialog param.");              dlg_fatal_error (dlg, "could not get dialog param.");
         #ifndef LANG_DE  
259          SetWindowText (dlg, _("Key Signing"));          SetWindowText (dlg, _("Key Signing"));
         #endif  
260          key = (winpt_key_t) lparam;          key = (winpt_key_t) lparam;
261          s = key->ctx->uids->uid;          s = key->ctx->uids->uid;
262          uid = utf8_to_wincp (s, strlen (s));          uid = utf8_to_wincp (s, strlen (s));
# Line 242  keysign_dlg_proc (HWND dlg, UINT msg, WP Line 271  keysign_dlg_proc (HWND dlg, UINT msg, WP
271                     get_expire_date (key->ctx),                     get_expire_date (key->ctx),
272                     get_printable_fpr (key->ctx->subkeys->fpr),                     get_printable_fpr (key->ctx->subkeys->fpr),
273                     uid);                     uid);
274          free (uid);          safe_free (uid);
275          s = key->ctx->subkeys->keyid;          s = key->ctx->subkeys->keyid;
276          if (do_fill_seckeylist (dlg, s)) {          if (do_fill_seckeylist (dlg, s)) {
277              msg_box (dlg, _("No valid secret key found."), _("Key Signing"), MB_ERR);              msg_box (dlg, _("No valid secret key found."), _("Key Signing"), MB_ERR);
278              EndDialog (dlg, FALSE);              EndDialog (dlg, FALSE);
279          }          }
280            do_check_protection (dlg);
281          SetDlgItemText (dlg, IDC_KEYSIGN_INFOS, keymsg);          SetDlgItemText (dlg, IDC_KEYSIGN_INFOS, keymsg);
         #ifndef LANG_DE  
282          SetDlgItemText (dlg, IDC_KEYSIGN_LOCAL, _("Sign local only (non exportable signature)"));          SetDlgItemText (dlg, IDC_KEYSIGN_LOCAL, _("Sign local only (non exportable signature)"));
283          SetDlgItemText (dlg, IDC_KEYSIGN_EXPSIG, _("Signature expires on"));          SetDlgItemText (dlg, IDC_KEYSIGN_EXPSIG, _("Signature expires on"));
284          SetDlgItemText (dlg, IDC_KEYSIGN_NREV, _("Sign non-revocably"));          SetDlgItemText (dlg, IDC_KEYSIGN_NREV, _("Sign non-revocably"));
285          SetDlgItemText (dlg, IDC_KEYSIGN_ASKLEVEL, _("&Ask for certification level"));          SetDlgItemText (dlg, IDC_KEYSIGN_ASKLEVEL, _("&Ask for certification level"));
286          SetDlgItemText (dlg, IDC_KEYSIGN_PWDINF, _("Passphrase"));          SetDlgItemText (dlg, IDC_KEYSIGN_PWDINF, _("Passphrase"));
287          #endif          SetDlgItemText (dlg, IDCANCEL, _("&Cancel"));
288            SetDlgItemText (dlg, IDC_KEYSIGN_SHOWIMG, _("&Show photo"));
289            SetDlgItemText (dlg, IDC_KEYSIGN_HIDE, _("&Hide Typing"));
290          CheckDlgButton (dlg, IDC_KEYSIGN_LOCAL, BST_CHECKED);          CheckDlgButton (dlg, IDC_KEYSIGN_LOCAL, BST_CHECKED);
291          CheckDlgButton (dlg, IDC_KEYSIGN_EXPSIG, BST_UNCHECKED);          CheckDlgButton (dlg, IDC_KEYSIGN_EXPSIG, BST_UNCHECKED);
292          CheckDlgButton (dlg, IDC_KEYSIGN_ASKLEVEL, BST_UNCHECKED);          CheckDlgButton (dlg, IDC_KEYSIGN_ASKLEVEL, BST_UNCHECKED);
# Line 266  keysign_dlg_proc (HWND dlg, UINT msg, WP Line 297  keysign_dlg_proc (HWND dlg, UINT msg, WP
297              EnableWindow (GetDlgItem (dlg, IDC_KEYSIGN_SHOWIMG), TRUE);              EnableWindow (GetDlgItem (dlg, IDC_KEYSIGN_SHOWIMG), TRUE);
298          if (!reg_prefs.gpg.ask_cert_level)          if (!reg_prefs.gpg.ask_cert_level)
299              EnableWindow (GetDlgItem (dlg, IDC_KEYSIGN_ASKLEVEL), FALSE);              EnableWindow (GetDlgItem (dlg, IDC_KEYSIGN_ASKLEVEL), FALSE);
300            if (!reg_prefs.gpg.ask_cert_expire)
301                EnableWindow (GetDlgItem (dlg, IDC_KEYSIGN_EXPSIG), FALSE);
302            CheckDlgButton (dlg, IDC_KEYSIGN_HIDE, BST_CHECKED);
303          SetForegroundWindow (dlg);          SetForegroundWindow (dlg);
304          h = GetDlgItem (dlg, IDC_KEYSIGN_PASSPHRASE);          h = GetDlgItem (dlg, IDC_KEYSIGN_PASSPHRASE);
305          SetFocus (h);          SetFocus (h);
306          return FALSE;          return FALSE;
       
     case WM_DESTROY:  
         sig_class_choice = 0;  
         break;  
307    
308      case WM_SYSCOMMAND:      case WM_SYSCOMMAND:
309          if( LOWORD( wparam ) == SC_CLOSE ) {          if (LOWORD (wparam) == SC_CLOSE) {
310              SetDlgItemText( dlg, IDC_KEYSIGN_PASSPHRASE, "" );              SetDlgItemText (dlg, IDC_KEYSIGN_PASSPHRASE, "");
311              EndDialog( dlg, TRUE );              EndDialog (dlg, TRUE);
312          }          }
313          return FALSE;          return FALSE;
314                    
315      case WM_COMMAND:      case WM_COMMAND:
316          if (HIWORD( wparam ) == CBN_SELCHANGE) {          if (HIWORD (wparam) == CBN_SELCHANGE) {
317              do_check_protection (dlg);              do_check_protection (dlg);
318              break;              break;
319          }          }
320          if (HIWORD (wparam) == BN_CLICKED && LOWORD (wparam) == IDC_KEYSIGN_EXPSIG) {          if (HIWORD (wparam) == BN_CLICKED &&
321                LOWORD (wparam) == IDC_KEYSIGN_EXPSIG) {
322              int enable = IsDlgButtonChecked (dlg, IDC_KEYSIGN_EXPSIG);              int enable = IsDlgButtonChecked (dlg, IDC_KEYSIGN_EXPSIG);
323              EnableWindow (GetDlgItem (dlg, IDC_KEYSIGN_EXPIRES), enable? TRUE : FALSE);              EnableWindow (GetDlgItem (dlg, IDC_KEYSIGN_EXPIRES), enable? TRUE : FALSE);
324          }          }
325            if (HIWORD (wparam) == BN_CLICKED &&
326                LOWORD (wparam) == IDC_KEYSIGN_HIDE) {
327                HWND hwnd = GetDlgItem (dlg, IDC_KEYSIGN_PASSPHRASE);
328                int hide = IsDlgButtonChecked (dlg, IDC_KEYSIGN_HIDE);
329                SendMessage (hwnd, EM_SETPASSWORDCHAR, hide? '*' : 0, 0);
330                SetFocus (hwnd);
331            }
332    
333          switch( LOWORD( wparam ) ) {          switch (LOWORD (wparam)) {
334          case IDOK:          case IDOK:
335              if (IsDlgButtonChecked (dlg, IDC_KEYSIGN_ASKLEVEL))              if (IsDlgButtonChecked (dlg, IDC_KEYSIGN_ASKLEVEL))
336                  dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_SIGCLASS, dlg,                  sig_class = dialog_box_param (glob_hinst,
337                                    sig_class_dlg_proc, (LPARAM)NULL,                                                (LPCSTR)IDD_WINPT_SIGCLASS, dlg,
338                                    _("Choose Signature Class"),  IDS_WINPT_SIGCLASS);                                                sig_class_dlg_proc, (LPARAM)NULL,
339                                                  _("Choose Signature Class"),
340                                                  IDS_WINPT_SIGCLASS);
341              type = IsDlgButtonChecked (dlg, IDC_KEYSIGN_LOCAL);              type = IsDlgButtonChecked (dlg, IDC_KEYSIGN_LOCAL);
342              if (type)              if (type)
343                  type = GPG_EDITKEY_LSIGN;                  type = GPG_EDITKEY_LSIGN;
# Line 310  keysign_dlg_proc (HWND dlg, UINT msg, WP Line 350  keysign_dlg_proc (HWND dlg, UINT msg, WP
350                      type = GPG_EDITKEY_NRLSIGN;                      type = GPG_EDITKEY_NRLSIGN;
351              }              }
352              if (IsDlgButtonChecked (dlg, IDC_KEYSIGN_EXPSIG)) {              if (IsDlgButtonChecked (dlg, IDC_KEYSIGN_EXPSIG)) {
                 expires = 1;  
353                  DateTime_GetSystemtime (GetDlgItem (dlg, IDC_KEYSIGN_EXPIRES), &st);                  DateTime_GetSystemtime (GetDlgItem (dlg, IDC_KEYSIGN_EXPIRES), &st);
354                    if (date_is_today (&st)) {
355                        msg_box (dlg, _("You cannot select today as the expiration date."),
356                                 _("Key Signing"), MB_INFO);
357                        return TRUE;
358                    }
359                    else
360                        expires = 1;
361                  sprintf (keymsg, "%04d-%02d-%02d", st.wYear, st.wMonth, st.wDay);                  sprintf (keymsg, "%04d-%02d-%02d", st.wYear, st.wMonth, st.wDay);
362              }              }
363    
# Line 335  keysign_dlg_proc (HWND dlg, UINT msg, WP Line 381  keysign_dlg_proc (HWND dlg, UINT msg, WP
381              if (k)              if (k)
382                  ke->setLocalUser (k);                  ke->setLocalUser (k);
383    
384              err = ke->signKey (type, sig_class_choice, expires? keymsg : "0");              err = ke->signKey (type, sig_class, expires? keymsg : "0");
385              memset (&pwd, 0, sizeof pwd);                        wipememory (pwd, sizeof (pwd));
386              if (err) {              if (err) {
387                  delete ke;                  delete ke;
388                  msg_box (dlg, gpgme_strerror (err), _("Key Signing"), MB_ERR);                  msg_box (dlg, gpgme_strerror (err), _("Key Signing"), MB_ERR);
389                  return TRUE;                  return TRUE;
390              }              }
391              if (ke->getResult () != 0)              if (ke->getResult () != 0)
392                  msg_box (dlg, _("This key is already signed by your key"), _("Key Signing"), MB_INFO);                  msg_box (dlg, _("This key is already signed by your key"),
393                             _("Key Signing"), MB_INFO);
394              else {              else {
395                  status_box (dlg, _("Key successfully signed."), PGM_NAME);                  status_box (dlg, _("Key successfully signed."), _("Key Signing"));
396                  key->update = 1;                  key->update = 1;
397              }              }
398              delete ke;              delete ke;

Legend:
Removed from v.41  
changed lines
  Added in v.181

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26