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

Legend:
Removed from v.2  
changed lines
  Added in v.170

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26