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

Legend:
Removed from v.32  
changed lines
  Added in v.77

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26