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

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26