/[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 23 by twoaday, Fri Sep 30 10:10:16 2005 UTC revision 205 by twoaday, Thu Apr 27 12:46:03 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   *   *
6   * WinPT is free software; you can redistribute it and/or modify   * WinPT is free software; you can redistribute it and/or modify
7   * it under the terms of the GNU General Public License as published by   * it under the terms of the GNU General Public License as published by
8   * the Free Software Foundation; either version 2 of the License, or   * the Free Software Foundation; either version 2 of the License, or
9   * (at your option) any later version.   * (at your option) any later version.
10   *   *
11   * WinPT is distributed in the hope that it will be useful,   * WinPT is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   * GNU General Public License for more details.   * GNU General Public License for more details.
15   *   *
16   * You should have received a copy of the GNU General Public License   * You should have received a copy of the GNU General Public License
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 <windows.h>  #include <config.h>
22  #include <commctrl.h>  #endif
23    
24  #include "../resource.h"  #include <windows.h>
25  #include "wptGPG.h"  #include <commctrl.h>
26  #include "wptNLS.h"  #include <time.h>
27  #include "wptW32API.h"  
28  #include "wptVersion.h"  #include "resource.h"
29  #include "wptTypes.h"  #include "wptGPG.h"
30  #include "wptErrors.h"  #include "wptNLS.h"
31  #include "wptCommonCtl.h"  #include "wptW32API.h"
32  #include "wptContext.h"  #include "wptVersion.h"
33  #include "wptDlgs.h"  #include "wptTypes.h"
34  #include "wptUTF8.h"  #include "wptErrors.h"
35  #include "wptRegistry.h"  #include "wptCommonCtl.h"
36  #include "wptKeyList.h"  #include "wptContext.h"
37  #include "wptKeyEdit.h"  #include "wptDlgs.h"
38    #include "wptUTF8.h"
39  static int sig_class_choice = 0;  #include "wptRegistry.h"
40    #include "wptKeylist.h"
41  /* Return a beautified printable fingerprint of @fpr. */  #include "wptKeyEdit.h"
42  static const char*  
43  get_printable_fpr (const char *fpr)  
44  {  /* Return a beautified printable fingerprint of @fpr. */
45      static char pfpr[64];      static const char*
46      int pos = 0;  get_printable_fpr (const char *fpr)
47      size_t i;  {
48        static char pfpr[64];    
49      for (i = 0; i < strlen (fpr); i += 4) {      int pos = 0;
50          pfpr[pos++] = fpr[i];      size_t i;
51          pfpr[pos++] = fpr[i+1];  
52          pfpr[pos++] = fpr[i+2];      for (i = 0; i < strlen (fpr); i += 4) {
53          pfpr[pos++] = fpr[i+3];          pfpr[pos++] = fpr[i];
54          pfpr[pos++] = ' ';          pfpr[pos++] = fpr[i+1];
55      }          pfpr[pos++] = fpr[i+2];
56      return pfpr;          pfpr[pos++] = fpr[i+3];
57  }          pfpr[pos++] = ' ';
58        }
59        return pfpr;
60  /* Return human friendly information about the key @key. */  }
61  static const char*  
62  get_keyinfo (gpgme_key_t key)  
63  {  /* Return human friendly information about the key @key. */
64      static char buf[64+16];  static const char*
65      get_keyinfo (gpgme_key_t key)
66      _snprintf (buf, DIM (buf)-1-16, "%d-bit %s key, ID %s",  {
67          key->subkeys->length,      static char buf[64+16];
68          key->subkeys->pubkey_algo,      struct winpt_key_s k;
69          key->subkeys->keyid+8);  
70      // XXX      memset (&k, 0, sizeof (k));
71      //if (gpgme_key_get_ulong_attr (key, GPGME_ATTR_DIVERT_CARD, NULL, 0))      winpt_get_seckey (key->subkeys->keyid, &k);
72      //  strcat (buf, " (Card)");      _snprintf (buf, DIM (buf)-1-16, "%d-bit %s key, ID %s",
73      return buf;          key->subkeys->length,
74  }          get_key_pubalgo (key->subkeys->pubkey_algo),
75            key->subkeys->keyid+8);
76        if (k.ext->gloflags.divert_to_card)
77  /* Fill the secret key combo-box with all entries from the cache.          strcat (buf, " (Card)");
78     @dlg is the handle to the combo-box. @keyid show which key to skip.      return buf;
79     Return value: 0 on success. */  }
80  static int  
81  do_fill_seckeylist (HWND dlg, const char *keyid)  
82  {  /* Fill the secret key combo-box with all entries from the cache.
83      gpgme_keycache_t sec;     @dlg is the handle to the combo-box. @keyid show which key to skip.
84      gpgme_key_t pk;     Return value: 0 on success. */
85      const char * s;  static int
86      char * uid, * p;      do_fill_seckeylist (HWND dlg, const char *keyid)
87      int i = 0, n=0;  {
88        gpg_keycache_t sec;
89      sec = keycache_get_ctx (0);      gpgme_key_t pk, defkey;
90      if (!sec)      const char *s;
91          BUG (0);      char *uid, *p;
92      gpgme_keycache_rewind (sec);      int i = 0, n = 0, curr_sel = 0;
93      while (!gpgme_keycache_next_key (sec, 1, &pk)) {  
94          if (!pk)      sec = keycache_get_ctx (0);
95              continue;      if (!sec)
96          s = pk->subkeys->keyid;          BUG (0);
97          if (!strcmp (s, keyid))      gpg_keycache_get_default_key (sec, &defkey);
98              continue;      gpg_keycache_rewind (sec);
99          /* skip all ElGamal sign+encrypt keys */      while (!gpg_keycache_next_key (sec, 1, &pk)) {
100          if (pk->subkeys->pubkey_algo == GPGME_PK_ELG)          if (!pk)
101              continue;              continue;
102          /* make sure the public key is okay not: revoked, expired or disabled. */          s = pk->subkeys->keyid;
103          if (pk->expired ||pk->revoked || pk->disabled)          if (!strcmp (s, keyid))
104              continue;              continue;
105          s = pk->uids->name;          /* skip all ElGamal sign+encrypt keys */
106          if (!s)          if (pk->subkeys->pubkey_algo == GPGME_PK_ELG)
107              continue;              continue;
108          uid = utf8_to_wincp (s, strlen (s));          /* make sure the public key is okay not: revoked, expired or disabled. */
109          p = new char[strlen (uid) + 64];          if (pk->expired ||pk->revoked || pk->disabled)
110          if (!p)              continue;
111              BUG (NULL);          s = pk->uids->name;
112          _snprintf (p, strlen (uid) + 63, "%s (%s)", uid, get_keyinfo (pk));          if (!s)
113          SendDlgItemMessage (dlg, IDC_KEYSIGN_KEYLIST, CB_ADDSTRING, i, (LPARAM)(char *)p);              continue;
114          SendDlgItemMessage (dlg, IDC_KEYSIGN_KEYLIST, CB_SETITEMDATA, i++, (LPARAM)(DWORD)pk);          if (defkey && !strcmp (defkey->subkeys->keyid, pk->subkeys->keyid))
115          free_if_alloc (p);              curr_sel = i;
116          free (uid);          uid = utf8_to_native (s);
117          n++;          p = new char[strlen (uid) + 64];
118      }          if (!p)
119      SendDlgItemMessage (dlg, IDC_KEYSIGN_KEYLIST, CB_SETCURSEL, 0, 0);              BUG (NULL);
120      if (!n)          _snprintf (p, strlen (uid) + 63, "%s (%s)", uid, get_keyinfo (pk));
121          return -1;          SendDlgItemMessage (dlg, IDC_KEYSIGN_KEYLIST,
122      return 0;                              CB_ADDSTRING, i, (LPARAM)(char *)p);
123  }          SendDlgItemMessage (dlg, IDC_KEYSIGN_KEYLIST,
124                                CB_SETITEMDATA, i++, (LPARAM)(DWORD)pk);
125            free_if_alloc (p);
126  /* Check if the selected key is protected and en- or disable the          free (uid);
127     passphrase control. */          n++;
128  static void      }
129  do_check_protection (HWND dlg)      SendDlgItemMessage (dlg, IDC_KEYSIGN_KEYLIST,
130  {                          CB_SETCURSEL, (WPARAM)curr_sel, 0);
131      int idx, protec;      if (!n)
132      gpgme_key_t key;          return -1;
133      struct winpt_key_s k;      return 0;
134    }
135      idx = SendDlgItemMessage( dlg, IDC_KEYSIGN_KEYLIST, CB_GETCURSEL, 0, 0 );  
136      key = (gpgme_key_t)SendDlgItemMessage( dlg, IDC_KEYSIGN_KEYLIST, CB_GETITEMDATA, (WPARAM)idx, 0 );  
137      if (key) {  /* Check if the selected key is protected and en- or disable the
138          winpt_get_seckey (key->subkeys->keyid, &k);     passphrase control. */
139          protec = k.is_protected;  static void
140          if (!protec)  do_check_protection (HWND dlg)
141              protec = k.ext->gloflags.divert_to_card;  {
142          EnableWindow (GetDlgItem (dlg, IDC_KEYSIGN_PASSPHRASE), protec? TRUE : FALSE);      int idx, protec;
143      }      gpgme_key_t key;
144  }      struct winpt_key_s k;
145    
146        idx = SendDlgItemMessage( dlg, IDC_KEYSIGN_KEYLIST, CB_GETCURSEL, 0, 0 );
147  /* Dialog box procedure to choose the signature class. */      key = (gpgme_key_t)SendDlgItemMessage( dlg, IDC_KEYSIGN_KEYLIST, CB_GETITEMDATA, (WPARAM)idx, 0 );
148  BOOL CALLBACK      if (key) {
149  sig_class_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)          winpt_get_seckey (key->subkeys->keyid, &k);
150  {          protec = k.is_protected;
151      switch (msg) {          if (!protec)
152      case WM_INITDIALOG:              protec = k.ext->gloflags.divert_to_card;
153          SetWindowText (dlg, _("Choose Signature Class"));          EnableWindow (GetDlgItem (dlg, IDC_KEYSIGN_PASSPHRASE), protec? TRUE : FALSE);
154          SetDlgItemText (dlg, IDC_SIGCLASS_TITLEINF, _("How carefully have you verified the key you are about to sign actually belongs to the person? If you don't know what to anwser, use \"0\"."));      }
155          SetDlgItemText (dlg, IDC_SIGCLASS_CLASS0, _("(0) I will not answer (default)"));  }
156          SetDlgItemText (dlg, IDC_SIGCLASS_CLASS1, _("(1) I have not checked at all."));  
157          SetDlgItemText (dlg, IDC_SIGCLASS_CLASS2, _("(2) I have done causal checking."));  
158          SetDlgItemText (dlg, IDC_SIGCLASS_CLASS3, _("(3) I have done very careful checkings."));  /* Dialog box procedure to choose the signature class. */
159          CheckDlgButton (dlg, IDC_SIGCLASS_CLASS0, BST_CHECKED);  BOOL CALLBACK
160          SetForegroundWindow (dlg);  sig_class_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
161          center_window (dlg, NULL);  {
162          return TRUE;      int sig_class = 0;
163    
164      case WM_COMMAND:      switch (msg) {
165          switch( LOWORD( wparam ) ) {      case WM_INITDIALOG:
166          case IDOK:          SetWindowText (dlg, _("Choose Signature Class"));
167              if (IsDlgButtonChecked (dlg, IDC_SIGCLASS_CLASS0))          SetDlgItemText (dlg, IDC_SIGCLASS_TITLEINF, _("How carefully have you verified the key you are about to sign actually belongs to the person? If you don't know what to anwser, use \"0\"."));
168                  sig_class_choice = 0;          SetDlgItemText (dlg, IDC_SIGCLASS_CLASS0, _("(0) I will not answer (default)"));
169              else if (IsDlgButtonChecked (dlg, IDC_SIGCLASS_CLASS1))          SetDlgItemText (dlg, IDC_SIGCLASS_CLASS1, _("(1) I have not checked at all."));
170                  sig_class_choice = 1;          SetDlgItemText (dlg, IDC_SIGCLASS_CLASS2, _("(2) I have done causal checking."));
171              else if (IsDlgButtonChecked (dlg, IDC_SIGCLASS_CLASS2))          SetDlgItemText (dlg, IDC_SIGCLASS_CLASS3, _("(3) I have done very careful checkings."));
172                  sig_class_choice = 2;          CheckDlgButton (dlg, IDC_SIGCLASS_CLASS0, BST_CHECKED);
173              else if (IsDlgButtonChecked (dlg, IDC_SIGCLASS_CLASS3))          SetForegroundWindow (dlg);
174                  sig_class_choice = 3;          center_window (dlg, NULL);
175              else          return TRUE;
176                  sig_class_choice = 0;  
177              EndDialog (dlg, TRUE);      case WM_COMMAND:
178              return TRUE;          switch (LOWORD (wparam)) {
179          }          case IDOK:
180          break;              if (IsDlgButtonChecked (dlg, IDC_SIGCLASS_CLASS0))
181      }                  sig_class = 0;
182                else if (IsDlgButtonChecked (dlg, IDC_SIGCLASS_CLASS1))
183      return FALSE;                  sig_class = 1;
184  }              else if (IsDlgButtonChecked (dlg, IDC_SIGCLASS_CLASS2))
185                    sig_class = 2;
186                else if (IsDlgButtonChecked (dlg, IDC_SIGCLASS_CLASS3))
187  /* Return the humand friendly expiration date of @key. */                  sig_class = 3;
188  static const char*              else
189  get_expire_date (gpgme_key_t key)                  sig_class = 0;
190  {              EndDialog (dlg, sig_class);
191      static char tmp[64];              return TRUE;
192    
193      u32 u = key->subkeys->expires;          case IDCANCEL:
194      if (!u)              EndDialog (dlg, 0);
195          return "never";              return TRUE;
196      return get_key_expire_date (u);          }
197  }          break;
198        }
199    
200  /* Dialog box procedure to sign a key. */      return FALSE;
201  BOOL CALLBACK  }
202  keysign_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)  
203  {  
204      static winpt_key_t key;  /* Return the humand friendly expiration date of @key. */
205      GpgKeyEdit *ke;  static const char*
206      gpgme_error_t err;  get_expire_date (gpgme_key_t key)
207      gpgme_key_t k;  {
208      SYSTEMTIME st;      u32 u = key->subkeys->expires;
209      HWND h;      if (!u)
210      char keymsg[4096], pwd[256], *uid = NULL;          return _("never");
211      const char *keyid, *s;      return get_key_expire_date (u);
212      u32 created;  }
213      int type, expires=0, idx;  
214        /* Display photo of key @key in a separate window. */
215      switch ( msg )  {  static void
216      case WM_INITDIALOG:  show_photo (winpt_key_t key)
217          if (lparam == NULL)  {
218              dlg_fatal_error (dlg, "Could not get dialog param.");      /* XXX: fill it with life. */
219          #ifndef LANG_DE  }
220          SetWindowText (dlg, _("Key Signing"));  
221          #endif  
222          key = (winpt_key_t) lparam;  /* Check if the given system time @st points to today. */
223          created = key->ctx->subkeys->timestamp;  static int
224          s = key->ctx->uids->uid;  date_is_today (SYSTEMTIME *st)
225          if (s)  {
226              uid = utf8_to_wincp (s, strlen (s));      time_t t;
227          _snprintf (keymsg, sizeof keymsg -1,      struct tm *tm;
228                     _("pub %d/%s created: %s    expires: %s\n\n"  
229                       "Primary key fingerprint: %s\n\n"      t = time (NULL);
230                       "\t%s\n\n"      tm = localtime (&t);
231                       "\nAre you really sure that you want to sign this key with YOUR key?\n"),      if (st->wDay == tm->tm_mday &&
232                     key->ctx->subkeys->length,          st->wYear == tm->tm_year+1900 &&
233                     key->ctx->subkeys->keyid+8,          st->wMonth == tm->tm_mon+1)
234                     get_key_created (key->ctx->subkeys->timestamp),          return -1;
235                     get_expire_date (key->ctx),      return 0;
236                     get_printable_fpr (key->ctx->subkeys->fpr),  }
237                     uid);  
238          free (uid);  
239          s = key->ctx->subkeys->keyid;  /* Dialog box procedure to sign a key. */
240          if (do_fill_seckeylist (dlg, s)) {  BOOL CALLBACK
241              msg_box( dlg, _("No valid secret key found."), _("Key Signing"), MB_ERR );  keysign_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
242              EndDialog( dlg, FALSE );  {
243          }      static winpt_key_t key;
244          SetDlgItemText (dlg, IDC_KEYSIGN_INFOS, keymsg);      GpgKeyEdit *ke;
245          #ifndef LANG_DE      gpgme_error_t err;
246          SetDlgItemText (dlg, IDC_KEYSIGN_LOCAL, _("Sign local only (non exportable signature)"));      gpgme_key_t k;
247          SetDlgItemText (dlg, IDC_KEYSIGN_EXPSIG, _("Signature expires on"));      SYSTEMTIME st;
248          SetDlgItemText (dlg, IDC_KEYSIGN_NREV, _("Sign non-revocably"));      HWND h;
249          #endif      char keymsg[2048], pwd[256];
250          CheckDlgButton (dlg, IDC_KEYSIGN_LOCAL, BST_CHECKED);      const char *keyid, *s;
251          CheckDlgButton (dlg, IDC_KEYSIGN_EXPSIG, BST_UNCHECKED);      int type, expires=0, idx;
252          CheckDlgButton (dlg, IDC_KEYSIGN_ASKLEVEL, BST_UNCHECKED);      int sig_class = 0;
253          EnableWindow (GetDlgItem (dlg, IDC_KEYSIGN_EXPIRES), FALSE);      
254          if (reg_prefs.expert == 0)      switch (msg)  {
255              ShowWindow (GetDlgItem (dlg, IDC_KEYSIGN_NREV), SW_HIDE);      case WM_INITDIALOG:
256          SetForegroundWindow( dlg );          if (lparam == 0)
257          h = GetDlgItem( dlg, IDC_KEYSIGN_PASSPHRASE );              dlg_fatal_error (dlg, "could not get dialog param.");
258          SetFocus( h );          SetWindowText (dlg, _("Key Signing"));
259          return FALSE;          key = (winpt_key_t) lparam;
260                _snprintf (keymsg, sizeof keymsg -1,
261      case WM_DESTROY:                     _("pub %d/%s  created: %s    expires: %s\n\n"
262          sig_class_choice = 0;                       "Primary key fingerprint: %s\n\n"
263          break;                       "\t%s\n\n"
264                         "\nAre you really sure that you want to sign this key with YOUR key?\n"),
265      case WM_SYSCOMMAND:                     key->ctx->subkeys->length,
266          if( LOWORD( wparam ) == SC_CLOSE ) {                     key->ctx->subkeys->keyid+8,
267              SetDlgItemText( dlg, IDC_KEYSIGN_PASSPHRASE, "" );                     get_key_created (key->ctx->subkeys->timestamp),
268              EndDialog( dlg, TRUE );                     get_expire_date (key->ctx),
269          }                     get_printable_fpr (key->ctx->subkeys->fpr),
270          return FALSE;                     key->ext->uids->uid);
271                    s = key->ctx->subkeys->keyid;
272      case WM_COMMAND:          if (do_fill_seckeylist (dlg, s)) {
273          if( HIWORD( wparam ) == CBN_SELCHANGE ) {              msg_box (dlg, _("No valid secret key found."), _("Key Signing"), MB_ERR);
274              do_check_protection( dlg );              EndDialog (dlg, FALSE);
275              break;              break;
276          }          }
277          if (HIWORD (wparam) == BN_CLICKED && LOWORD (wparam) == IDC_KEYSIGN_EXPSIG) {          do_check_protection (dlg);
278              int enable = IsDlgButtonChecked (dlg, IDC_KEYSIGN_EXPSIG);          SetDlgItemText (dlg, IDC_KEYSIGN_INFOS, keymsg);
279              EnableWindow (GetDlgItem (dlg, IDC_KEYSIGN_EXPIRES), enable? TRUE : FALSE);          SetDlgItemText (dlg, IDC_KEYSIGN_LOCAL, _("Sign local only (non exportable signature)"));
280          }          SetDlgItemText (dlg, IDC_KEYSIGN_EXPSIG, _("Signature expires on"));
281            SetDlgItemText (dlg, IDC_KEYSIGN_NREV, _("Sign non-revocably"));
282          switch( LOWORD( wparam ) ) {          SetDlgItemText (dlg, IDC_KEYSIGN_ASKLEVEL, _("&Ask for certification level"));
283          case IDOK:          SetDlgItemText (dlg, IDC_KEYSIGN_PWDINF, _("Passphrase"));
284              if (IsDlgButtonChecked (dlg, IDC_KEYSIGN_ASKLEVEL))          SetDlgItemText (dlg, IDCANCEL, _("&Cancel"));
285                  dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_SIGCLASS, dlg,          SetDlgItemText (dlg, IDC_KEYSIGN_SHOWIMG, _("&Show photo"));
286                                    sig_class_dlg_proc, (LPARAM)NULL,          SetDlgItemText (dlg, IDC_KEYSIGN_HIDE, _("&Hide Typing"));
287                                    _("Choose Signature Class"),  IDS_WINPT_SIGCLASS);          CheckDlgButton (dlg, IDC_KEYSIGN_LOCAL, BST_CHECKED);
288              type = IsDlgButtonChecked (dlg, IDC_KEYSIGN_LOCAL);          CheckDlgButton (dlg, IDC_KEYSIGN_EXPSIG, BST_UNCHECKED);
289              if (type)          CheckDlgButton (dlg, IDC_KEYSIGN_ASKLEVEL, BST_UNCHECKED);
290                  type = GPG_EDITKEY_LSIGN;          EnableWindow (GetDlgItem (dlg, IDC_KEYSIGN_EXPIRES), FALSE);
291              else          if (reg_prefs.expert == 0)
292                  type = GPG_EDITKEY_SIGN;              ShowWindow (GetDlgItem (dlg, IDC_KEYSIGN_NREV), SW_HIDE);
293            if (key->ext && key->ext->attrib.len > 0)
294              if (reg_prefs.expert && IsDlgButtonChecked (dlg, IDC_KEYSIGN_NREV)) {              EnableWindow (GetDlgItem (dlg, IDC_KEYSIGN_SHOWIMG), TRUE);
295                  type = GPG_EDITKEY_NRSIGN;          if (!reg_prefs.gpg.ask_cert_level)
296                  if (type == GPG_EDITKEY_LSIGN)              EnableWindow (GetDlgItem (dlg, IDC_KEYSIGN_ASKLEVEL), FALSE);
297                      type = GPG_EDITKEY_NRLSIGN;          if (!reg_prefs.gpg.ask_cert_expire)
298              }              EnableWindow (GetDlgItem (dlg, IDC_KEYSIGN_EXPSIG), FALSE);
299              if (IsDlgButtonChecked (dlg, IDC_KEYSIGN_EXPSIG)) {          CheckDlgButton (dlg, IDC_KEYSIGN_HIDE, BST_CHECKED);
300                  expires = 1;          SetForegroundWindow (dlg);
301                  DateTime_GetSystemtime (GetDlgItem (dlg, IDC_KEYSIGN_EXPIRES), &st);          h = GetDlgItem (dlg, IDC_KEYSIGN_PASSPHRASE);
302                  sprintf (keymsg, "%04d-%02d-%02d", st.wYear, st.wMonth, st.wDay);          SetFocus (h);
303              }          return FALSE;
304    
305              GetDlgItemText( dlg, IDC_KEYSIGN_PASSPHRASE, pwd, DIM (pwd)-1);      case WM_SYSCOMMAND:
306              keyid = key->ctx->subkeys->keyid;          if (LOWORD (wparam) == SC_CLOSE) {
307              if( !keyid ) {              SetDlgItemText (dlg, IDC_KEYSIGN_PASSPHRASE, "");
308                  msg_box( dlg, _("Could not get Key ID from key."), _("Key Signing"), MB_ERR );              EndDialog (dlg, TRUE);
309                  return TRUE;          }
310              }          return FALSE;
311              ke = new GpgKeyEdit (keyid);          
312              if (!ke)      case WM_COMMAND:
313                  BUG (NULL);          if (HIWORD (wparam) == CBN_SELCHANGE) {
314              ke->setPassphrase (pwd);              do_check_protection (dlg);
315              idx = SendDlgItemMessage (dlg, IDC_KEYSIGN_KEYLIST, CB_GETCURSEL, 0, 0);              break;
316              k = (gpgme_key_t)SendDlgItemMessage (dlg, IDC_KEYSIGN_KEYLIST,          }
317                                                   CB_GETITEMDATA, (WPARAM)idx, 0);          if (HIWORD (wparam) == BN_CLICKED &&
318              if (k)              LOWORD (wparam) == IDC_KEYSIGN_EXPSIG) {
319                  ke->setLocalUser (k);              int enable = IsDlgButtonChecked (dlg, IDC_KEYSIGN_EXPSIG);
320                EnableWindow (GetDlgItem (dlg, IDC_KEYSIGN_EXPIRES), enable? TRUE : FALSE);
321              err = ke->signKey (type, sig_class_choice, expires? keymsg : NULL);          }
322              memset (&pwd, 0, sizeof pwd);          if (HIWORD (wparam) == BN_CLICKED &&
323              delete ke;              LOWORD (wparam) == IDC_KEYSIGN_HIDE) {
324              if (err) {              HWND hwnd = GetDlgItem (dlg, IDC_KEYSIGN_PASSPHRASE);
325                  msg_box (dlg, gpgme_strerror (err), _("Key Signing"), MB_ERR);              int hide = IsDlgButtonChecked (dlg, IDC_KEYSIGN_HIDE);
326                  return TRUE;              SendMessage (hwnd, EM_SETPASSWORDCHAR, hide? '*' : 0, 0);
327              }              SetFocus (hwnd);
328              status_box (dlg, _("Key successfully signed."), PGM_NAME);          }
329              key->update = 1;  
330              EndDialog (dlg, TRUE);          switch (LOWORD (wparam)) {
331              return TRUE;          case IDOK:
332                            if (IsDlgButtonChecked (dlg, IDC_KEYSIGN_ASKLEVEL))
333          case IDCANCEL:                  sig_class = dialog_box_param (glob_hinst,
334              EndDialog (dlg, FALSE);                                                (LPCSTR)IDD_WINPT_SIGCLASS, dlg,
335              return TRUE;                                                sig_class_dlg_proc, (LPARAM)NULL,
336          }                                                _("Choose Signature Class"),
337          break;                                                IDS_WINPT_SIGCLASS);
338      }              type = IsDlgButtonChecked (dlg, IDC_KEYSIGN_LOCAL);
339                    if (type)
340      return FALSE;                  type = GPG_EDITKEY_LSIGN;
341  }              else
342                    type = GPG_EDITKEY_SIGN;
343    
344                if (reg_prefs.expert && IsDlgButtonChecked (dlg, IDC_KEYSIGN_NREV)) {
345                    type = GPG_EDITKEY_NRSIGN;
346                    if (type == GPG_EDITKEY_LSIGN)
347                        type = GPG_EDITKEY_NRLSIGN;
348                }
349                if (IsDlgButtonChecked (dlg, IDC_KEYSIGN_EXPSIG)) {
350                    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);
359                }
360    
361                /* XXX: check for --ask-cert-level and --ask-cert-expire in the gpg.conf
362                        if an advanced button is checked and offer to add it to the config
363                        file. */
364    
365                GetDlgItemText( dlg, IDC_KEYSIGN_PASSPHRASE, pwd, DIM (pwd)-1);
366                keyid = key->ctx->subkeys->keyid;
367                if( !keyid ) {
368                    msg_box( dlg, _("Could not get Key ID from key."), _("Key Signing"), MB_ERR );
369                    return TRUE;
370                }
371                ke = new GpgKeyEdit (keyid);
372                if (!ke)
373                    BUG (NULL);
374                ke->setPassphrase (pwd);
375                idx = SendDlgItemMessage (dlg, IDC_KEYSIGN_KEYLIST, CB_GETCURSEL, 0, 0);
376                k = (gpgme_key_t)SendDlgItemMessage (dlg, IDC_KEYSIGN_KEYLIST,
377                                                     CB_GETITEMDATA, (WPARAM)idx, 0);
378                if (k)
379                    ke->setLocalUser (k);
380    
381                err = ke->signKey (type, sig_class, expires? keymsg : "0");
382                wipememory (pwd, sizeof (pwd));
383                if (err) {
384                    delete ke;
385                    msg_box (dlg, gpgme_strerror (err), _("Key Signing"), MB_ERR);
386                    return TRUE;
387                }
388                if (ke->getResult () != 0)
389                    msg_box (dlg, _("This key is already signed by your key"),
390                             _("Key Signing"), MB_INFO);
391                else {
392                    status_box (dlg, _("Key successfully signed."), _("Key Signing"));
393                    key->update = 1;
394                }
395                delete ke;
396                EndDialog (dlg, TRUE);
397                return TRUE;
398                
399            case IDCANCEL:
400                EndDialog (dlg, FALSE);
401                return TRUE;
402    
403            case IDC_KEYSIGN_SHOWIMG:
404                show_photo (key);
405                return TRUE;
406            }
407            break;
408        }
409        
410        return FALSE;
411    }
412    

Legend:
Removed from v.23  
changed lines
  Added in v.205

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26