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" |
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 |
|
|
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; |
80 |
c = (passphrase_cb_s *)lparam; |
c = (passphrase_cb_s *)lparam; |
81 |
if (!c) |
if (!c) |
82 |
BUG (0); |
BUG (0); |
83 |
|
SetDlgItemText (dlg, IDC_DECRYPT_HIDE, _("&Hide Typing")); |
84 |
SetWindowText (dlg, c->title); |
SetWindowText (dlg, c->title); |
85 |
if (c->gpg_cmd == GPG_CMD_DECRYPT) { |
if (c->gpg_cmd == GPG_CMD_DECRYPT) { |
86 |
SetDlgItemText (dlg, IDC_DECRYPT_LISTINF, |
SetDlgItemText (dlg, IDC_DECRYPT_LISTINF, |
200 |
} |
} |
201 |
res = gpgme_op_decrypt_result (c->gpg); |
res = gpgme_op_decrypt_result (c->gpg); |
202 |
if (!res) |
if (!res) |
203 |
res_sig = gpgme_op_sign_result (c->gpg); |
res_sig = gpgme_op_sign_result (c->gpg); |
204 |
if (reg_prefs.cache_time > 0 && !c->is_card && |
if (reg_prefs.cache_time > 0 && !c->is_card && |
205 |
((res && res->recipients) || (res_sig && res_sig->signatures))) { |
(res || res_sig)) { |
206 |
if (agent_get_cache (c->keyid, &item)) |
if (agent_get_cache (c->keyid, &item)) |
207 |
agent_unlock_cache_entry (&item); |
agent_unlock_cache_entry (&item); |
208 |
else |
else |
209 |
agent_put_cache (c->keyid, c->pwd, reg_prefs.cache_time); |
agent_put_cache (c->keyid, c->pwd, reg_prefs.cache_time); |
210 |
} |
} |
211 |
c->cancel = 0; |
c->cancel = 0; |
233 |
static char keyid[16+1]; |
static char keyid[16+1]; |
234 |
|
|
235 |
/* XXX: check for leading alpha-chars? */ |
/* XXX: check for leading alpha-chars? */ |
236 |
if (strlen (pass_info) < 16) |
if (strlen (pass_info) < 16) { |
237 |
|
log_debug ("parse_gpg_keyid: error '%s'\r\n", pass_info); |
238 |
return NULL; |
return NULL; |
239 |
|
} |
240 |
/* the format of the desc buffer looks like this: |
/* the format of the desc buffer looks like this: |
241 |
request_keyid[16] main_keyid[16] keytype[1] keylength[4] |
request_keyid[16] main_keyid[16] keytype[1] keylength[4] |
242 |
we use the main keyid to use only one cache entry. */ |
we use the main keyid to use only one cache entry. */ |
258 |
char *uid, *p; |
char *uid, *p; |
259 |
int n=0; |
int n=0; |
260 |
|
|
261 |
|
algo = (gpgme_pubkey_algo_t)0; |
262 |
/* 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. */ |
263 |
if (strlen (uid_hint) < 17) { |
if (strlen (uid_hint) < 17) { |
264 |
*desc = 0; |
*desc = 0; |
265 |
|
log_debug ("parse_gpg_description: error '%s'\r\n", uid_hint); |
266 |
return -1; |
return -1; |
267 |
} |
} |
268 |
|
|
303 |
char *p; |
char *p; |
304 |
|
|
305 |
p = strchr (id, '/'); |
p = strchr (id, '/'); |
306 |
if (!p) |
if (!p) { |
307 |
|
log_debug ("extract_serial_no: error '%s'\r\n", id); |
308 |
return NULL; |
return NULL; |
309 |
|
} |
310 |
strncpy (buf, id+(p-id)-6, 6); |
strncpy (buf, id+(p-id)-6, 6); |
311 |
return buf; |
return buf; |
312 |
} |
} |
321 |
passphrase_cb_s *c = (passphrase_cb_s*)hook; |
passphrase_cb_s *c = (passphrase_cb_s*)hook; |
322 |
HANDLE hd = (HANDLE)fd; |
HANDLE hd = (HANDLE)fd; |
323 |
void *item; |
void *item; |
324 |
const char *keyid, *pass; |
const char *keyid=NULL, *pass; |
325 |
DWORD n; |
DWORD n; |
326 |
int rc; |
int rc = 0; |
327 |
|
|
328 |
if (!c) |
if (!c) { |
329 |
|
log_debug ("passphrase_cb: error '!c'\r\n"); |
330 |
return gpg_error (GPG_ERR_INV_ARG); |
return gpg_error (GPG_ERR_INV_ARG); |
331 |
|
} |
332 |
c->bad_pwd = prev_was_bad? 1 : 0; |
c->bad_pwd = prev_was_bad? 1 : 0; |
333 |
if (prev_was_bad && !c->cancel) { |
if (prev_was_bad && !c->cancel) { |
334 |
if (c->pwd) |
if (c->pwd) |
341 |
if (strlen (passphrase_info) < 16 && |
if (strlen (passphrase_info) < 16 && |
342 |
!strstr (passphrase_info, "OPENPGP")) { |
!strstr (passphrase_info, "OPENPGP")) { |
343 |
/* assume symetric encryption. */ |
/* assume symetric encryption. */ |
344 |
int n=2; |
int pos=2; |
345 |
c->sym.sym_algo = atoi (passphrase_info); |
c->sym.sym_algo = atoi (passphrase_info); |
346 |
if (c->sym.sym_algo > 9) |
if (c->sym.sym_algo > 9) |
347 |
n++; |
pos++; |
348 |
/* XXX: be more strict. */ |
/* XXX: be more strict. */ |
349 |
c->sym.s2k_mode = atoi (passphrase_info+n); |
c->sym.s2k_mode = atoi (passphrase_info+pos); |
350 |
c->sym.s2k_hash = atoi (passphrase_info+n+2); |
c->sym.s2k_hash = atoi (passphrase_info+pos+2); |
351 |
} |
} |
352 |
|
|
353 |
keyid = parse_gpg_keyid (passphrase_info); |
keyid = parse_gpg_keyid (passphrase_info); |
354 |
pass = agent_get_cache (keyid+8, &item); |
pass = agent_get_cache (keyid+8, &item); |
355 |
if (pass) { |
if (pass) { |
356 |
agent_unlock_cache_entry (&item); |
agent_unlock_cache_entry (&item); |
357 |
c->pwd_init = 0; |
c->pwd_init = 0; |
404 |
return 0; |
return 0; |
405 |
} |
} |
406 |
|
|
407 |
WriteFile (hd, c->pwd, strlen (c->pwd), &n, NULL); |
if (!WriteFile (hd, c->pwd, strlen (c->pwd), &n, NULL)) |
408 |
WriteFile (hd, "\n", 1, &n, NULL); |
log_debug ("passphrase_cb: WriteFile() failed ec=%d\n", w32_errno); |
409 |
|
if (!WriteFile (hd, "\n", 1, &n, NULL)) |
410 |
|
log_debug ("passphrase_cb: WriteFile() failed ec=%d\n", w32_errno); |
411 |
return 0; |
return 0; |
412 |
} |
} |
413 |
|
|