/[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 88 by twoaday, Mon Nov 21 12:06:59 2005 UTC revision 211 by twoaday, Sun May 7 12:36:48 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 23  Line 23 
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"
# Line 39  Line 40 
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 69  get_keyinfo (gpgme_key_t key) Line 69  get_keyinfo (gpgme_key_t key)
69    
70      memset (&k, 0, sizeof (k));      memset (&k, 0, sizeof (k));
71      winpt_get_seckey (key->subkeys->keyid, &k);      winpt_get_seckey (key->subkeys->keyid, &k);
72      _snprintf (buf, DIM (buf)-1-16, "%d-bit %s key, ID %s",      _snprintf (buf, DIM (buf)-1-16, _("%d-bit %s key, ID 0x%s"),
73          key->subkeys->length,          key->subkeys->length,
74          get_key_pubalgo (key->subkeys->pubkey_algo),          get_key_pubalgo (key->subkeys->pubkey_algo),
75          key->subkeys->keyid+8);          key->subkeys->keyid+8);
# Line 86  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 110  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          uid = utf8_to_wincp (s, strlen (s));          if (defkey && !strcmp (defkey->subkeys->keyid, pk->subkeys->keyid))
115                curr_sel = i;
116            uid = utf8_to_native (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 153  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 167  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 207  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 218  keysign_dlg_proc (HWND dlg, UINT msg, WP Line 247  keysign_dlg_proc (HWND dlg, UINT msg, WP
247      SYSTEMTIME st;      SYSTEMTIME st;
248      HWND h;      HWND h;
249      char keymsg[2048], pwd[256];      char keymsg[2048], pwd[256];
     char *uid = NULL;  
250      const char *keyid, *s;      const char *keyid, *s;
251      int type, expires=0, idx;      int type, expires=0, idx;
252        int sig_class = 0;
253            
254      switch ( msg )  {      switch (msg)  {
255      case WM_INITDIALOG:      case WM_INITDIALOG:
256          if (lparam == 0)          if (lparam == 0)
257              dlg_fatal_error (dlg, "Could not get dialog param.");              dlg_fatal_error (dlg, "could not get dialog param.");
         #ifndef LANG_DE  
258          SetWindowText (dlg, _("Key Signing"));          SetWindowText (dlg, _("Key Signing"));
         #endif  
259          key = (winpt_key_t) lparam;          key = (winpt_key_t) lparam;
         s = key->ctx->uids->uid;  
         uid = utf8_to_wincp (s, strlen (s));  
260          _snprintf (keymsg, sizeof keymsg -1,          _snprintf (keymsg, sizeof keymsg -1,
261                     _("pub %d/%s  created: %s    expires: %s\n\n"                     _("pub %d/%s  created: %s    expires: %s\n\n"
262                       "Primary key fingerprint: %s\n\n"                       "Primary key fingerprint: %s\n\n"
# Line 242  keysign_dlg_proc (HWND dlg, UINT msg, WP Line 267  keysign_dlg_proc (HWND dlg, UINT msg, WP
267                     get_key_created (key->ctx->subkeys->timestamp),                     get_key_created (key->ctx->subkeys->timestamp),
268                     get_expire_date (key->ctx),                     get_expire_date (key->ctx),
269                     get_printable_fpr (key->ctx->subkeys->fpr),                     get_printable_fpr (key->ctx->subkeys->fpr),
270                     uid);                     key->ext->uids->uid);
         free (uid);  
271          s = key->ctx->subkeys->keyid;          s = key->ctx->subkeys->keyid;
272          if (do_fill_seckeylist (dlg, s)) {          if (do_fill_seckeylist (dlg, s)) {
273              msg_box (dlg, _("No valid secret key found."), _("Key Signing"), MB_ERR);              msg_box (dlg, _("No valid secret key found."), _("Key Signing"), MB_ERR);
274              EndDialog (dlg, FALSE);              EndDialog (dlg, FALSE);
275                break;
276          }          }
277            do_check_protection (dlg);
278          SetDlgItemText (dlg, IDC_KEYSIGN_INFOS, keymsg);          SetDlgItemText (dlg, IDC_KEYSIGN_INFOS, keymsg);
279          SetDlgItemText (dlg, IDC_KEYSIGN_LOCAL, _("Sign local only (non exportable signature)"));          SetDlgItemText (dlg, IDC_KEYSIGN_LOCAL, _("Sign local only (non exportable signature)"));
280          SetDlgItemText (dlg, IDC_KEYSIGN_EXPSIG, _("Signature expires on"));          SetDlgItemText (dlg, IDC_KEYSIGN_EXPSIG, _("Signature expires on"));
# Line 257  keysign_dlg_proc (HWND dlg, UINT msg, WP Line 283  keysign_dlg_proc (HWND dlg, UINT msg, WP
283          SetDlgItemText (dlg, IDC_KEYSIGN_PWDINF, _("Passphrase"));          SetDlgItemText (dlg, IDC_KEYSIGN_PWDINF, _("Passphrase"));
284          SetDlgItemText (dlg, IDCANCEL, _("&Cancel"));          SetDlgItemText (dlg, IDCANCEL, _("&Cancel"));
285          SetDlgItemText (dlg, IDC_KEYSIGN_SHOWIMG, _("&Show photo"));          SetDlgItemText (dlg, IDC_KEYSIGN_SHOWIMG, _("&Show photo"));
286            SetDlgItemText (dlg, IDC_KEYSIGN_HIDE, _("&Hide Typing"));
287          CheckDlgButton (dlg, IDC_KEYSIGN_LOCAL, BST_CHECKED);          CheckDlgButton (dlg, IDC_KEYSIGN_LOCAL, BST_CHECKED);
288          CheckDlgButton (dlg, IDC_KEYSIGN_EXPSIG, BST_UNCHECKED);          CheckDlgButton (dlg, IDC_KEYSIGN_EXPSIG, BST_UNCHECKED);
289          CheckDlgButton (dlg, IDC_KEYSIGN_ASKLEVEL, BST_UNCHECKED);          CheckDlgButton (dlg, IDC_KEYSIGN_ASKLEVEL, BST_UNCHECKED);
# Line 267  keysign_dlg_proc (HWND dlg, UINT msg, WP Line 294  keysign_dlg_proc (HWND dlg, UINT msg, WP
294              EnableWindow (GetDlgItem (dlg, IDC_KEYSIGN_SHOWIMG), TRUE);              EnableWindow (GetDlgItem (dlg, IDC_KEYSIGN_SHOWIMG), TRUE);
295          if (!reg_prefs.gpg.ask_cert_level)          if (!reg_prefs.gpg.ask_cert_level)
296              EnableWindow (GetDlgItem (dlg, IDC_KEYSIGN_ASKLEVEL), FALSE);              EnableWindow (GetDlgItem (dlg, IDC_KEYSIGN_ASKLEVEL), FALSE);
297            if (!reg_prefs.gpg.ask_cert_expire)
298                EnableWindow (GetDlgItem (dlg, IDC_KEYSIGN_EXPSIG), FALSE);
299            CheckDlgButton (dlg, IDC_KEYSIGN_HIDE, BST_CHECKED);
300          SetForegroundWindow (dlg);          SetForegroundWindow (dlg);
301          h = GetDlgItem (dlg, IDC_KEYSIGN_PASSPHRASE);          h = GetDlgItem (dlg, IDC_KEYSIGN_PASSPHRASE);
302          SetFocus (h);          SetFocus (h);
303          return FALSE;          return FALSE;
       
     case WM_DESTROY:  
         sig_class_choice = 0;  
         break;  
304    
305      case WM_SYSCOMMAND:      case WM_SYSCOMMAND:
306          if( LOWORD( wparam ) == SC_CLOSE ) {          if (LOWORD (wparam) == SC_CLOSE) {
307              SetDlgItemText( dlg, IDC_KEYSIGN_PASSPHRASE, "" );              SetDlgItemText (dlg, IDC_KEYSIGN_PASSPHRASE, "");
308              EndDialog( dlg, TRUE );              EndDialog (dlg, TRUE);
309          }          }
310          return FALSE;          return FALSE;
311                    
312      case WM_COMMAND:      case WM_COMMAND:
313          if (HIWORD( wparam ) == CBN_SELCHANGE) {          if (HIWORD (wparam) == CBN_SELCHANGE) {
314              do_check_protection (dlg);              do_check_protection (dlg);
315              break;              break;
316          }          }
317          if (HIWORD (wparam) == BN_CLICKED && LOWORD (wparam) == IDC_KEYSIGN_EXPSIG) {          if (HIWORD (wparam) == BN_CLICKED &&
318                LOWORD (wparam) == IDC_KEYSIGN_EXPSIG) {
319              int enable = IsDlgButtonChecked (dlg, IDC_KEYSIGN_EXPSIG);              int enable = IsDlgButtonChecked (dlg, IDC_KEYSIGN_EXPSIG);
320              EnableWindow (GetDlgItem (dlg, IDC_KEYSIGN_EXPIRES), enable? TRUE : FALSE);              EnableWindow (GetDlgItem (dlg, IDC_KEYSIGN_EXPIRES), enable? TRUE : FALSE);
321          }          }
322            if (HIWORD (wparam) == BN_CLICKED &&
323                LOWORD (wparam) == IDC_KEYSIGN_HIDE) {
324                HWND hwnd = GetDlgItem (dlg, IDC_KEYSIGN_PASSPHRASE);
325                int hide = IsDlgButtonChecked (dlg, IDC_KEYSIGN_HIDE);
326                SendMessage (hwnd, EM_SETPASSWORDCHAR, hide? '*' : 0, 0);
327                SetFocus (hwnd);
328            }
329    
330          switch( LOWORD( wparam ) ) {          switch (LOWORD (wparam)) {
331          case IDOK:          case IDOK:
332              if (IsDlgButtonChecked (dlg, IDC_KEYSIGN_ASKLEVEL))              if (IsDlgButtonChecked (dlg, IDC_KEYSIGN_ASKLEVEL))
333                  dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_SIGCLASS, dlg,                  sig_class = dialog_box_param (glob_hinst,
334                                    sig_class_dlg_proc, (LPARAM)NULL,                                                (LPCSTR)IDD_WINPT_SIGCLASS, dlg,
335                                    _("Choose Signature Class"),  IDS_WINPT_SIGCLASS);                                                sig_class_dlg_proc, (LPARAM)NULL,
336                                                  _("Choose Signature Class"),
337                                                  IDS_WINPT_SIGCLASS);
338              type = IsDlgButtonChecked (dlg, IDC_KEYSIGN_LOCAL);              type = IsDlgButtonChecked (dlg, IDC_KEYSIGN_LOCAL);
339              if (type)              if (type)
340                  type = GPG_EDITKEY_LSIGN;                  type = GPG_EDITKEY_LSIGN;
# Line 311  keysign_dlg_proc (HWND dlg, UINT msg, WP Line 347  keysign_dlg_proc (HWND dlg, UINT msg, WP
347                      type = GPG_EDITKEY_NRLSIGN;                      type = GPG_EDITKEY_NRLSIGN;
348              }              }
349              if (IsDlgButtonChecked (dlg, IDC_KEYSIGN_EXPSIG)) {              if (IsDlgButtonChecked (dlg, IDC_KEYSIGN_EXPSIG)) {
                 expires = 1;  
350                  DateTime_GetSystemtime (GetDlgItem (dlg, IDC_KEYSIGN_EXPIRES), &st);                  DateTime_GetSystemtime (GetDlgItem (dlg, IDC_KEYSIGN_EXPIRES), &st);
351                    if (date_is_today (&st)) {
352                        msg_box (dlg, _("You cannot select today as the expiration date."),
353                                 _("Key Signing"), MB_INFO);
354                        return TRUE;
355                    }
356                    else
357                        expires = 1;
358                  sprintf (keymsg, "%04d-%02d-%02d", st.wYear, st.wMonth, st.wDay);                  sprintf (keymsg, "%04d-%02d-%02d", st.wYear, st.wMonth, st.wDay);
359              }              }
360    
# Line 336  keysign_dlg_proc (HWND dlg, UINT msg, WP Line 378  keysign_dlg_proc (HWND dlg, UINT msg, WP
378              if (k)              if (k)
379                  ke->setLocalUser (k);                  ke->setLocalUser (k);
380    
381              err = ke->signKey (type, sig_class_choice, expires? keymsg : "0");              err = ke->signKey (type, sig_class, expires? keymsg : "0");
382              memset (&pwd, 0, sizeof pwd);                        wipememory (pwd, sizeof (pwd));
383              if (err) {              if (err) {
384                  delete ke;                  delete ke;
385                  msg_box (dlg, gpgme_strerror (err), _("Key Signing"), MB_ERR);                  msg_box (dlg, gpgme_strerror (err), _("Key Signing"), MB_ERR);
386                  return TRUE;                  return TRUE;
387              }              }
388              if (ke->getResult () != 0)              if (ke->getResult () != 0)
389                  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"),
390                             _("Key Signing"), MB_INFO);
391              else {              else {
392                  status_box (dlg, _("Key successfully signed."), PGM_NAME);                  status_box (dlg, _("Key successfully signed."), _("Key Signing"));
393                  key->update = 1;                  key->update = 1;
394              }              }
395              delete ke;              delete ke;

Legend:
Removed from v.88  
changed lines
  Added in v.211

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26