/[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 47 by werner, Mon Oct 31 14:04:59 2005 UTC revision 105 by twoaday, Wed Nov 30 10:22:00 2005 UTC
# Line 24  Line 24 
24  #endif  #endif
25    
26  #include <windows.h>  #include <windows.h>
 #include <windows.h>  
27  #include <ctype.h>  #include <ctype.h>
28    
29  #include "resource.h"  #include "resource.h"
# Line 38  Line 37 
37  #include "wptUTF8.h"  #include "wptUTF8.h"
38  #include "wptErrors.h"  #include "wptErrors.h"
39  #include "wptTypes.h"  #include "wptTypes.h"
40  #include "wptKeyList.h"  #include "wptKeylist.h"
41  #include "wptAgent.h"  #include "wptAgent.h"
42  #include "wptRegistry.h"  #include "wptRegistry.h"
43    
# Line 66  burn_passphrase (char **pwd) Line 65  burn_passphrase (char **pwd)
65  static BOOL CALLBACK  static BOOL CALLBACK
66  passphrase_callback_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)  passphrase_callback_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
67  {      {    
68      static passphrase_cb_s * c;      static passphrase_cb_s *c;
69      gpgme_decrypt_result_t res;      gpgme_decrypt_result_t res=NULL;
70      gpgme_sign_result_t res_sig;      gpgme_sign_result_t res_sig=NULL;
71      gpgme_key_t key;      gpgme_key_t key;
72      gpgme_recipient_t recip, r;      gpgme_recipient_t recip=NULL, r;
73      void *ctx = NULL, *item;      void *item;
74      const char *id;      const char *id;
75      char *info;      char *info;
76      int n;      int n;
# Line 81  passphrase_callback_proc (HWND dlg, UINT Line 80  passphrase_callback_proc (HWND dlg, UINT
80          c = (passphrase_cb_s *)lparam;          c = (passphrase_cb_s *)lparam;
81          if (!c)          if (!c)
82              BUG (0);              BUG (0);
83            SetDlgItemText (dlg, IDCANCEL, _("&Cancel"));
84            SetDlgItemText (dlg, IDC_DECRYPT_HIDE, _("&Hide Typing"));
85          SetWindowText (dlg, c->title);          SetWindowText (dlg, c->title);
86          if (c->gpg_cmd == GPG_CMD_DECRYPT) {          if (c->gpg_cmd == GPG_CMD_DECRYPT) {
87              SetDlgItemText (dlg, IDC_DECRYPT_LISTINF,              SetDlgItemText (dlg, IDC_DECRYPT_LISTINF,
88                              _("Encrypted with the following public key(s)"));                              _("Encrypted with the following public key(s)"));
89              CheckDlgButton (dlg, IDC_DECRYPT_HIDE, BST_CHECKED);              CheckDlgButton (dlg, IDC_DECRYPT_HIDE, BST_CHECKED);
90          }          }
91          else if (c->gpg_cmd == GPG_CMD_SIGN)          else if (c->gpg_cmd == GPG_CMD_SIGN) {
92                SetDlgItemText (dlg, IDC_DECRYPT_SIGN_HIDE, _("&Hide Typing"));
93              CheckDlgButton (dlg, IDC_DECRYPT_SIGN_HIDE, BST_CHECKED);              CheckDlgButton (dlg, IDC_DECRYPT_SIGN_HIDE, BST_CHECKED);
94            }
95          if (c->recipients)          if (c->recipients)
96              recip = c->recipients; /* recipients were already extracted. */              recip = c->recipients; /* recipients were already extracted. */
97          else {          else {
# Line 200  passphrase_callback_proc (HWND dlg, UINT Line 203  passphrase_callback_proc (HWND dlg, UINT
203                  }                  }
204                  res = gpgme_op_decrypt_result (c->gpg);                  res = gpgme_op_decrypt_result (c->gpg);
205                  if (!res)                  if (!res)
206                      res_sig = gpgme_op_sign_result (c->gpg);                      res_sig = gpgme_op_sign_result (c->gpg);            
207                  if (reg_prefs.cache_time > 0 && !c->is_card &&                  if (reg_prefs.cache_time > 0 && !c->is_card &&
208                      ((res && res->recipients) || (res_sig && res_sig->signatures))) {                      (res || res_sig)) {
209                      if (agent_get_cache (c->keyid, &item))                      if (agent_get_cache (c->keyid, &item))                      
210                          agent_unlock_cache_entry (&item);                          agent_unlock_cache_entry (&item);
211                      else                      else
212                          agent_put_cache (c->keyid, c->pwd, reg_prefs.cache_time);                          agent_put_cache (c->keyid, c->pwd, reg_prefs.cache_time);
213                  }                  }
214                  c->cancel = 0;                  c->cancel = 0;
# Line 233  parse_gpg_keyid (const char *pass_info) Line 236  parse_gpg_keyid (const char *pass_info)
236      static char keyid[16+1];      static char keyid[16+1];
237            
238      /* XXX: check for leading alpha-chars? */      /* XXX: check for leading alpha-chars? */
239      if (strlen (pass_info) < 16)      if (strlen (pass_info) < 16) {
240            log_debug ("parse_gpg_keyid: error '%s'\r\n", pass_info);
241          return NULL;          return NULL;
242        }
243      /* the format of the desc buffer looks like this:      /* the format of the desc buffer looks like this:
244         request_keyid[16] main_keyid[16] keytype[1] keylength[4]         request_keyid[16] main_keyid[16] keytype[1] keylength[4]
245         we use the main keyid to use only one cache entry. */         we use the main keyid to use only one cache entry. */
# Line 256  parse_gpg_description (const char *uid_h Line 261  parse_gpg_description (const char *uid_h
261      char *uid, *p;      char *uid, *p;
262      int n=0;      int n=0;
263    
264        algo = (gpgme_pubkey_algo_t)0;
265      /* Each uid_hint contains a long key-ID so it is at least 16 bytes. */      /* Each uid_hint contains a long key-ID so it is at least 16 bytes. */
266      if (strlen (uid_hint) < 17) {      if (strlen (uid_hint) < 17) {
267          *desc = 0;          *desc = 0;
268            log_debug ("parse_gpg_description: error '%s'\r\n", uid_hint);
269          return -1;          return -1;
270      }      }
271    
# Line 299  extract_serial_no (const char *id) Line 306  extract_serial_no (const char *id)
306      char *p;      char *p;
307    
308      p = strchr (id, '/');      p = strchr (id, '/');
309      if (!p)      if (!p) {
310            log_debug ("extract_serial_no: error '%s'\r\n", id);
311          return NULL;          return NULL;
312        }
313      strncpy (buf, id+(p-id)-6, 6);      strncpy (buf, id+(p-id)-6, 6);
314      return buf;      return buf;
315  }  }
# Line 315  passphrase_cb (void *hook, const char *u Line 324  passphrase_cb (void *hook, const char *u
324      passphrase_cb_s *c = (passphrase_cb_s*)hook;      passphrase_cb_s *c = (passphrase_cb_s*)hook;
325      HANDLE hd = (HANDLE)fd;      HANDLE hd = (HANDLE)fd;
326      void *item;      void *item;
327      const char *keyid, *pass;      const char *keyid=NULL, *pass;
328      DWORD n;      DWORD n;
329      int rc;      int rc = 0;
330    
331      if (!c)      if (!c) {
332            log_debug ("passphrase_cb: error '!c'\r\n");
333          return gpg_error (GPG_ERR_INV_ARG);          return gpg_error (GPG_ERR_INV_ARG);
334        }
335      c->bad_pwd = prev_was_bad? 1 : 0;      c->bad_pwd = prev_was_bad? 1 : 0;
336      if (prev_was_bad && !c->cancel) {      if (prev_was_bad && !c->cancel) {
337          if (c->pwd)          if (c->pwd)
# Line 333  passphrase_cb (void *hook, const char *u Line 344  passphrase_cb (void *hook, const char *u
344          if (strlen (passphrase_info) < 16 &&          if (strlen (passphrase_info) < 16 &&
345              !strstr (passphrase_info, "OPENPGP")) {              !strstr (passphrase_info, "OPENPGP")) {
346              /* assume symetric encryption. */              /* assume symetric encryption. */
347              int n=2;              int pos=2;
348              c->sym.sym_algo = atoi (passphrase_info);              c->sym.sym_algo = atoi (passphrase_info);
349              if (c->sym.sym_algo > 9)              if (c->sym.sym_algo > 9)
350                  n++;                  pos++;
351              /* XXX: be more strict. */              /* XXX: be more strict. */
352              c->sym.s2k_mode = atoi (passphrase_info+n);              c->sym.s2k_mode = atoi (passphrase_info+pos);
353              c->sym.s2k_hash = atoi (passphrase_info+n+2);              c->sym.s2k_hash = atoi (passphrase_info+pos+2);
354          }          }
355    
356          keyid = parse_gpg_keyid (passphrase_info);          keyid = parse_gpg_keyid (passphrase_info);
357          pass = agent_get_cache (keyid+8, &item);          pass = agent_get_cache (keyid+8, &item);        
358          if (pass) {          if (pass) {
359              agent_unlock_cache_entry (&item);              agent_unlock_cache_entry (&item);
360              c->pwd_init = 0;              c->pwd_init = 0;
# Line 396  passphrase_cb (void *hook, const char *u Line 407  passphrase_cb (void *hook, const char *u
407          return 0;          return 0;
408      }      }
409    
410      WriteFile (hd, c->pwd, strlen (c->pwd), &n, NULL);      if (!WriteFile (hd, c->pwd, strlen (c->pwd), &n, NULL))
411      WriteFile (hd, "\n", 1, &n, NULL);          log_debug ("passphrase_cb: WriteFile() failed ec=%d\n", w32_errno);
412        if (!WriteFile (hd, "\n", 1, &n, NULL))
413            log_debug ("passphrase_cb: WriteFile() failed ec=%d\n", w32_errno);
414      return 0;      return 0;
415  }  }
416    

Legend:
Removed from v.47  
changed lines
  Added in v.105

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26