41 |
#include "wptAgent.h" |
#include "wptAgent.h" |
42 |
#include "wptRegistry.h" |
#include "wptRegistry.h" |
43 |
|
|
|
|
|
|
|
|
44 |
const char* get_symkey_algo (int algo); |
const char* get_symkey_algo (int algo); |
45 |
|
|
46 |
#define item_ctrl_id( cmd ) \ |
#define item_ctrl_id( cmd ) \ |
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 = NULL; |
gpgme_decrypt_result_t res=NULL; |
70 |
gpgme_sign_result_t res_sig = NULL; |
gpgme_sign_result_t res_sig=NULL; |
71 |
gpgme_key_t key; |
gpgme_key_t key; |
72 |
gpgme_recipient_t recip=NULL, r; |
gpgme_recipient_t recip=NULL, r; |
73 |
void *item; |
void *item; |
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 |
|
/* Because it depends on the order the keys are stored in the |
96 |
|
keyring whether res->recipients is complete or not, we also |
97 |
|
support that the recipients were externally extracted and then |
98 |
|
we use this list. */ |
99 |
if (c->recipients) |
if (c->recipients) |
100 |
recip = c->recipients; /* recipients were already extracted. */ |
recip = c->recipients; /* recipients were already extracted. */ |
101 |
else { |
else { |
|
/* XXX: not all ENCRYPT_TO entries are listed here. */ |
|
102 |
res = gpgme_op_decrypt_result (c->gpg); |
res = gpgme_op_decrypt_result (c->gpg); |
103 |
if (res && res->recipients) |
if (res && res->recipients) |
104 |
recip = res->recipients; |
recip = res->recipients; |
105 |
} |
} |
106 |
if (recip != NULL && c->gpg_cmd == GPG_CMD_DECRYPT) { |
if (recip != NULL && c->gpg_cmd == GPG_CMD_DECRYPT) { |
107 |
for (r = res->recipients; r; r = r->next) { |
for (r = recip; r; r = r->next) { |
108 |
get_pubkey (r->keyid, &key); |
get_pubkey (r->keyid, &key); |
109 |
if (key) { |
if (key) { |
110 |
|
gpgme_user_id_t u = key->uids; |
111 |
char *uid; |
char *uid; |
112 |
id = key->uids->name; |
|
113 |
|
id = u->name; |
114 |
if (!id) |
if (!id) |
115 |
id = _("Invalid User ID"); |
id = _("Invalid User ID"); |
116 |
uid = utf8_to_wincp (id, strlen (id)); |
uid = utf8_to_wincp (id, strlen (id)); |
117 |
info = new char [32+strlen (uid)+1 + 4 + strlen (r->keyid)+1 |
n = 32+strlen (uid)+1+4+strlen (r->keyid)+1; |
118 |
+ strlen (key->uids->email)+1]; |
if (u->email) |
119 |
|
n += strlen (u->email)+1; |
120 |
|
info = new char [n+1]; |
121 |
if (!info) |
if (!info) |
122 |
BUG (NULL); |
BUG (NULL); |
123 |
sprintf (info, "%s <%s> (%s, 0x%s)", uid, key->uids->email, |
if (!u->email || strlen (u->email) < 1) |
124 |
get_key_pubalgo (r->pubkey_algo), r->keyid+8); |
sprintf (info, "%s (%s, 0x%s)", uid, |
125 |
|
get_key_pubalgo (r->pubkey_algo), r->keyid+8); |
126 |
|
else |
127 |
|
sprintf (info, "%s <%s> (%s, 0x%s)", uid, u->email, |
128 |
|
get_key_pubalgo (r->pubkey_algo), r->keyid+8); |
129 |
free (uid); |
free (uid); |
|
|
|
130 |
} |
} |
131 |
else { |
else { |
132 |
info = new char [32 + strlen (r->keyid)+1 + 4]; |
info = new char [32 + strlen (r->keyid)+1 + 4]; |
167 |
} |
} |
168 |
center_window (dlg, NULL); |
center_window (dlg, NULL); |
169 |
SetForegroundWindow (dlg); |
SetForegroundWindow (dlg); |
|
set_active_window (dlg); |
|
170 |
return FALSE; |
return FALSE; |
171 |
|
|
172 |
case WM_SYSCOMMAND: |
case WM_SYSCOMMAND: |
212 |
} |
} |
213 |
res = gpgme_op_decrypt_result (c->gpg); |
res = gpgme_op_decrypt_result (c->gpg); |
214 |
if (!res) |
if (!res) |
215 |
res_sig = gpgme_op_sign_result (c->gpg); |
res_sig = gpgme_op_sign_result (c->gpg); |
216 |
if (reg_prefs.cache_time > 0 && !c->is_card && |
if (reg_prefs.cache_time > 0 && !c->is_card && |
217 |
((res && res->recipients) || (res_sig && res_sig->signatures))) { |
(res || res_sig)) { |
218 |
if (agent_get_cache (c->keyid, &item)) |
if (agent_get_cache (c->keyid, &item)) |
219 |
agent_unlock_cache_entry (&item); |
agent_unlock_cache_entry (&item); |
220 |
else |
else |
221 |
agent_put_cache (c->keyid, c->pwd, reg_prefs.cache_time); |
agent_put_cache (c->keyid, c->pwd, reg_prefs.cache_time); |
222 |
} |
} |
223 |
c->cancel = 0; |
c->cancel = 0; |
245 |
static char keyid[16+1]; |
static char keyid[16+1]; |
246 |
|
|
247 |
/* XXX: check for leading alpha-chars? */ |
/* XXX: check for leading alpha-chars? */ |
248 |
if (strlen (pass_info) < 16) |
if (strlen (pass_info) < 16) { |
249 |
|
log_debug ("parse_gpg_keyid: error '%s'\r\n", pass_info); |
250 |
return NULL; |
return NULL; |
251 |
|
} |
252 |
/* the format of the desc buffer looks like this: |
/* the format of the desc buffer looks like this: |
253 |
request_keyid[16] main_keyid[16] keytype[1] keylength[4] |
request_keyid[16] main_keyid[16] keytype[1] keylength[4] |
254 |
we use the main keyid to use only one cache entry. */ |
we use the main keyid to use only one cache entry. */ |
274 |
/* 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. */ |
275 |
if (strlen (uid_hint) < 17) { |
if (strlen (uid_hint) < 17) { |
276 |
*desc = 0; |
*desc = 0; |
277 |
|
log_debug ("parse_gpg_description: error '%s'\r\n", uid_hint); |
278 |
return -1; |
return -1; |
279 |
} |
} |
280 |
|
|
315 |
char *p; |
char *p; |
316 |
|
|
317 |
p = strchr (id, '/'); |
p = strchr (id, '/'); |
318 |
if (!p) |
if (!p) { |
319 |
|
log_debug ("extract_serial_no: error '%s'\r\n", id); |
320 |
return NULL; |
return NULL; |
321 |
|
} |
322 |
strncpy (buf, id+(p-id)-6, 6); |
strncpy (buf, id+(p-id)-6, 6); |
323 |
return buf; |
return buf; |
324 |
} |
} |
335 |
void *item; |
void *item; |
336 |
const char *keyid=NULL, *pass; |
const char *keyid=NULL, *pass; |
337 |
DWORD n; |
DWORD n; |
338 |
int rc=0; |
int rc = 0; |
339 |
|
|
340 |
if (!c) |
if (!c) { |
341 |
|
log_debug ("passphrase_cb: error '!c'\r\n"); |
342 |
return gpg_error (GPG_ERR_INV_ARG); |
return gpg_error (GPG_ERR_INV_ARG); |
343 |
|
} |
344 |
c->bad_pwd = prev_was_bad? 1 : 0; |
c->bad_pwd = prev_was_bad? 1 : 0; |
345 |
if (prev_was_bad && !c->cancel) { |
if (prev_was_bad && !c->cancel) { |
346 |
if (c->pwd) |
if (c->pwd) |
363 |
} |
} |
364 |
|
|
365 |
keyid = parse_gpg_keyid (passphrase_info); |
keyid = parse_gpg_keyid (passphrase_info); |
366 |
pass = agent_get_cache (keyid+8, &item); |
pass = agent_get_cache (keyid+8, &item); |
367 |
if (pass) { |
if (pass) { |
368 |
agent_unlock_cache_entry (&item); |
agent_unlock_cache_entry (&item); |
369 |
c->pwd_init = 0; |
c->pwd_init = 0; |
416 |
return 0; |
return 0; |
417 |
} |
} |
418 |
|
|
419 |
WriteFile (hd, c->pwd, strlen (c->pwd), &n, NULL); |
if (!WriteFile (hd, c->pwd, strlen (c->pwd), &n, NULL)) |
420 |
WriteFile (hd, "\n", 1, &n, NULL); |
log_debug ("passphrase_cb: WriteFile() failed ec=%d\n", w32_errno); |
421 |
|
if (!WriteFile (hd, "\n", 1, &n, NULL)) |
422 |
|
log_debug ("passphrase_cb: WriteFile() failed ec=%d\n", w32_errno); |
423 |
return 0; |
return 0; |
424 |
} |
} |
425 |
|
|