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

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26