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

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26