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

Legend:
Removed from v.5  
changed lines
  Added in v.36

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26