/[winpt]/trunk/Src/wptPassphraseCB.cpp
ViewVC logotype

Diff of /trunk/Src/wptPassphraseCB.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 214 by twoaday, Sun May 14 18:40:36 2006 UTC revision 255 by twoaday, Tue Aug 1 16:37:23 2006 UTC
# Line 1  Line 1 
1  /* wptPassphraseCB.cpp - GPGME Passphrase Callback  /* wptPassphraseCB.cpp - GPGME Passphrase Callback
2   *      Copyright (C) 2001, 2002, 2003, 2005, 2006 Timo Schulz   *      Copyright (C) 2001, 2002-2006 Timo Schulz
3   *      Copyright (C) 2005 g10 Code GmbH   *      Copyright (C) 2005 g10 Code GmbH
4   *   *
5   * This file is part of WinPT.   * This file is part of WinPT.
# Line 41  Line 41 
41  #include "wptRegistry.h"  #include "wptRegistry.h"
42  #include "wptUTF8.h"  #include "wptUTF8.h"
43    
 const char* get_symkey_algo (int algo);  
44    
45    /* Return the control ID dependent on the mode (sign or decrypt). */
46  #define item_ctrl_id(cmd) \  #define item_ctrl_id(cmd) \
47      ((cmd) == GPG_CMD_DECRYPT? IDC_DECRYPT_PWD : IDC_DECRYPT_SIGN_PWD)      ((cmd) == GPG_CMD_DECRYPT? IDC_DECRYPT_PWD : IDC_DECRYPT_SIGN_PWD)
48    
49  #define item_ctrl_id2(cmd) \  #define item_ctrl_id2(cmd) \
50      ((cmd) == GPG_CMD_DECRYPT? IDC_DECRYPT_HIDE : IDC_DECRYPT_SIGN_HIDE)      ((cmd) == GPG_CMD_DECRYPT? IDC_DECRYPT_HIDE : IDC_DECRYPT_SIGN_HIDE)
51    
52    const char* get_symkey_algo (int algo);
53  void ListBox_AddString_utf8 (HWND lb, const char *txt);  void ListBox_AddString_utf8 (HWND lb, const char *txt);
54    
55    
56  /* Overwrite passphrase and free memory. */  /* Overwrite passphrase and free memory. */
57  static void  static void
58  burn_passphrase (char **pwd)  burn_passphrase (char **pwd)
# Line 70  passphrase_callback_proc (HWND dlg, UINT Line 71  passphrase_callback_proc (HWND dlg, UINT
71      static passphrase_cb_s *c;      static passphrase_cb_s *c;
72      gpgme_decrypt_result_t res=NULL;      gpgme_decrypt_result_t res=NULL;
73      gpgme_sign_result_t res_sig=NULL;      gpgme_sign_result_t res_sig=NULL;
     gpgme_key_t key;  
74      gpgme_recipient_t recip=NULL, r;      gpgme_recipient_t recip=NULL, r;
75        winpt_key_s key;
76      void *item;      void *item;
77      const char *id;      const char *id;
78      char *info;      char *info;
# Line 115  passphrase_callback_proc (HWND dlg, UINT Line 116  passphrase_callback_proc (HWND dlg, UINT
116          }          }
117          if (recip != NULL && c->gpg_cmd == GPG_CMD_DECRYPT) {          if (recip != NULL && c->gpg_cmd == GPG_CMD_DECRYPT) {
118              for (r = recip; r; r = r->next) {              for (r = recip; r; r = r->next) {
119                  get_pubkey (r->keyid, &key);                  memset (&key, 0, sizeof (key));
120                  if (key) {                  if (!winpt_get_pubkey (r->keyid, &key)) {
121                      gpgme_user_id_t u = key->uids;                      gpgme_user_id_t u = key.ctx->uids;
122    
123                      id = u->name;                      id = u->name;
124                      if (!id)                      if (!id)
# Line 144  passphrase_callback_proc (HWND dlg, UINT Line 145  passphrase_callback_proc (HWND dlg, UINT
145                  }                  }
146                  ListBox_AddString_utf8 (GetDlgItem (dlg, IDC_DECRYPT_LIST), info);                  ListBox_AddString_utf8 (GetDlgItem (dlg, IDC_DECRYPT_LIST), info);
147                  free_if_alloc (info);                  free_if_alloc (info);
148                    winpt_release_pubkey (&key);
149              }              }
150          }          }
151          else if (c->gpg_cmd == GPG_CMD_DECRYPT)          else if (c->gpg_cmd == GPG_CMD_DECRYPT)
# Line 178  passphrase_callback_proc (HWND dlg, UINT Line 180  passphrase_callback_proc (HWND dlg, UINT
180    
181          case WM_SYSCOMMAND:          case WM_SYSCOMMAND:
182              if (LOWORD (wparam) == SC_CLOSE) {              if (LOWORD (wparam) == SC_CLOSE) {
                 SetDlgItemText (dlg, item_ctrl_id (c->gpg_cmd), "");  
183                  c->cancel = 1;                  c->cancel = 1;
184                  EndDialog (dlg, TRUE);                  EndDialog (dlg, TRUE);
185              }              }
# Line 212  passphrase_callback_proc (HWND dlg, UINT Line 213  passphrase_callback_proc (HWND dlg, UINT
213                      strcpy (c->pwd, "");                      strcpy (c->pwd, "");
214                  }                  }
215                  else {                  else {
216                      c->pwd = new char[n+2];                      char *p = new char[n+2];
217                      if (!c->pwd)                      if (!p)
218                          BUG (NULL);                          BUG (NULL);
219                      SafeGetDlgItemText (dlg, item_ctrl_id (c->gpg_cmd),                      /* Get the passphrase and convert it utf8.
220                                          c->pwd, n+1);                         This does not just the us-ascii charset. */
221                        SafeGetDlgItemText (dlg, item_ctrl_id (c->gpg_cmd), p, n+1);
222                        c->pwd = native_to_utf8 (p);
223                        sfree_if_alloc (p);
224                  }                  }
225                  res = gpgme_op_decrypt_result (c->gpg);                  res = gpgme_op_decrypt_result (c->gpg);
226                  if (!res)                  if (!res)
227                      res_sig = gpgme_op_sign_result (c->gpg);                                  res_sig = gpgme_op_sign_result (c->gpg);            
228                  if (reg_prefs.cache_time > 0 && !c->is_card &&                  if (!c->is_card && reg_prefs.cache_time > 0 &&
229                      (res || res_sig)) {                      (res || res_sig)) {
230                      if (agent_get_cache (c->keyid, &item))                                            if (agent_get_cache (c->keyid, &item))
231                          agent_unlock_cache_entry (&item);                          agent_unlock_cache_entry (&item);
232                      else                      else
233                          agent_put_cache (c->keyid, c->pwd, reg_prefs.cache_time);                          agent_put_cache (c->keyid, c->pwd, reg_prefs.cache_time);
# Line 299  parse_gpg_description (const char *uid_h Line 303  parse_gpg_description (const char *uid_h
303      uid = utf8_to_native (uid_hint);      uid = utf8_to_native (uid_hint);
304      if (strcmp (usedkey, mainkey))      if (strcmp (usedkey, mainkey))
305          _snprintf (desc, size-1,          _snprintf (desc, size-1,
306                     _("You need a passphrase to unlock the secret key for\n"                     _("You need a passphrase to unlock the secret key for user:\n"
307                       "user: \"%s\"\n"                       "\"%s\"\n"
308                       "%s key, ID %s (main key ID %s)\n"),                       "%s key, ID 0x%s (main key ID 0x%s)\n"),
309                     uid, get_key_pubalgo (algo), usedkey+8, mainkey+8);                     uid, get_key_pubalgo (algo), usedkey+8, mainkey+8);
310      else if (!strcmp (usedkey, mainkey))      else if (!strcmp (usedkey, mainkey))
311          _snprintf (desc, size-1,          _snprintf (desc, size-1,
312                     _("You need a passphrase to unlock the secret key for\n"                     _("You need a passphrase to unlock the secret key for user:\n"
313                       "user: \"%s\"\n"                       "\"%s\"\n"
314                       "%s key, ID %s\n"),                       "%s key, ID 0x%s\n"),
315                       uid, get_key_pubalgo (algo), usedkey+8);                       uid, get_key_pubalgo (algo), usedkey+8);
316      safe_free (uid);      safe_free (uid);
317      return 0;      return 0;

Legend:
Removed from v.214  
changed lines
  Added in v.255

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26