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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26