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

Legend:
Removed from v.25  
changed lines
  Added in v.177

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26