41 |
#include "wptDlgs.h" |
#include "wptDlgs.h" |
42 |
#include "wptUTF8.h" |
#include "wptUTF8.h" |
43 |
|
|
|
#define MAX_KEYSIZE 80000 |
|
44 |
|
|
45 |
char* get_reg_entry_keyserver (const char *); |
char* get_reg_entry_keyserver (const char *); |
46 |
int set_reg_entry_keyserver (const char *, const char *); |
int set_reg_entry_keyserver (const char *, const char *); |
62 |
hkp_err_box (HWND dlg, const char *host, WORD port, int rc) |
hkp_err_box (HWND dlg, const char *host, WORD port, int rc) |
63 |
{ |
{ |
64 |
const char *err = kserver_strerror (); |
const char *err = kserver_strerror (); |
65 |
|
const char *ws_err = wsock_strerror (); |
66 |
log_box (_("Keyserver"), MB_ERR, "%s:%d: %s", |
|
67 |
host, port, winpt_strerror (rc)); |
if (ws_err && strlen (ws_err) > 0) |
68 |
if (err) |
log_box (_("Keyserver"), MB_ERR, "%s:%d: %s", host, port, ws_err); |
69 |
msg_box (dlg, err, wsock_strerror (), MB_ERR); |
else |
70 |
|
log_box (_("Keyserver"), MB_ERR, "%s:%d: %s\n%s", |
71 |
|
host, port, winpt_strerror (rc), err? err : ""); |
72 |
} |
} |
73 |
|
|
74 |
|
|
172 |
{ |
{ |
173 |
gpgme_ctx_t ctx; |
gpgme_ctx_t ctx; |
174 |
gpgme_data_t keydata; |
gpgme_data_t keydata; |
175 |
gpgme_error_t ec; |
gpgme_import_result_t import_res = NULL; |
176 |
gpgme_import_result_t import_res = NULL; |
gpgme_error_t err; |
177 |
char *rawkey = NULL; |
char *rawkey = NULL; |
178 |
|
int keylen = 0; |
179 |
int rc; |
int rc; |
180 |
|
|
|
/* XXX: implement dynamic buffers. */ |
|
|
rawkey = new char[MAX_KEYSIZE]; |
|
|
if (!rawkey) |
|
|
BUG (0); |
|
|
memset (rawkey, 0, MAX_KEYSIZE); |
|
181 |
if (proto == KSPROTO_LDAP) { |
if (proto == KSPROTO_LDAP) { |
182 |
rc = ldap_recvkey (kserver, pattern, rawkey, MAX_KEYSIZE-1); |
rc = ldap_recvkey (kserver, pattern, &rawkey, &keylen); |
183 |
if (rc) { |
if (rc) { |
184 |
msg_box (dlg, _("LDAP key import failed.\n" |
msg_box (dlg, _("LDAP key import failed.\n" |
185 |
"Please make sure you have an online connection" |
"Please make sure you have an online connection" |
190 |
} |
} |
191 |
} |
} |
192 |
else if (proto == KSPROTO_FINGER) { |
else if (proto == KSPROTO_FINGER) { |
193 |
rc = finger_recvkey (kserver, pattern, rawkey, MAX_KEYSIZE-1); |
rc = finger_recvkey (kserver, pattern, &rawkey, &keylen); |
194 |
if (rc) { |
if (rc) { |
195 |
log_box (_("Keyserver"), MB_ERR, |
log_box (_("Keyserver"), MB_ERR, |
196 |
_("Finger key import failed: %s\n"), winpt_strerror (rc)); |
_("Finger key import failed: %s\n"), winpt_strerror (rc)); |
200 |
} |
} |
201 |
else if ((rc = kserver_recvkey (kserver, port, |
else if ((rc = kserver_recvkey (kserver, port, |
202 |
kserver_check_keyid (pattern), |
kserver_check_keyid (pattern), |
203 |
rawkey, MAX_KEYSIZE-1))) { |
&rawkey, &keylen))) { |
204 |
hkp_err_box (dlg, kserver, port, rc); |
hkp_err_box (dlg, kserver, port, rc); |
205 |
free_if_alloc (rawkey); |
free_if_alloc (rawkey); |
206 |
return rc; |
return rc; |
207 |
} |
} |
208 |
else { |
|
209 |
if (!strstr (rawkey, "BEGIN PGP PUBLIC KEY BLOCK")) { |
if (!strstr (rawkey, "BEGIN PGP PUBLIC KEY BLOCK")) { |
210 |
msg_box (dlg, _("This is not a valid OpenPGP key."), |
msg_box (dlg, _("This is not a valid OpenPGP key."), |
211 |
_("Keyserver"), MB_ERR); |
_("Keyserver"), MB_ERR); |
212 |
goto leave; |
goto leave; |
|
} |
|
|
ec = gpgme_new (&ctx); |
|
|
if (ec) |
|
|
BUG (NULL); |
|
|
gpgme_data_new_from_mem (&keydata, rawkey, strlen (rawkey), 1); |
|
|
rc = gpgme_op_import (ctx, keydata); |
|
|
if (rc) { |
|
|
msg_box (dlg, gpgme_strerror ((gpgme_error_t)rc), _("Import"), MB_ERR); |
|
|
goto leave; |
|
|
} |
|
|
import_res = gpgme_op_import_result (ctx); |
|
|
if (import_res && r_fpr) |
|
|
*r_fpr = m_strdup (import_res->imports->fpr); |
|
213 |
} |
} |
214 |
|
if (gpgme_new (&ctx)) |
215 |
|
BUG (NULL); |
216 |
|
gpgme_data_new_from_mem (&keydata, rawkey, strlen (rawkey), 1); |
217 |
|
err = gpgme_op_import (ctx, keydata); |
218 |
|
if (err) { |
219 |
|
msg_box (dlg, gpgme_strerror (err), _("Import"), MB_ERR); |
220 |
|
goto leave; |
221 |
|
} |
222 |
|
import_res = gpgme_op_import_result (ctx); |
223 |
|
if (import_res && r_fpr) |
224 |
|
*r_fpr = m_strdup (import_res->imports->fpr); |
225 |
|
|
226 |
/* if we use the refresh mode, a lot of keys will be fetched and thus only |
/* if we use the refresh mode, a lot of keys will be fetched and thus only |
227 |
a summarize at the end is presented and not for each key. */ |
a summarize at the end is presented and not for each key. */ |
266 |
static int |
static int |
267 |
check_pattern (const char *pattern) |
check_pattern (const char *pattern) |
268 |
{ |
{ |
269 |
int rc = 1; |
int rc = WPTERR_GENERAL; |
270 |
|
|
271 |
/* Whitespace are not allowed! */ |
/* do not allow white spaces. */ |
272 |
if (strchr (pattern, ' ')) { |
if (strchr (pattern, ' ')) |
273 |
rc = WPTERR_GENERAL; |
return rc; |
274 |
goto leave; |
|
275 |
} |
if (strstr (pattern, "0x")) |
276 |
|
pattern += 2; |
277 |
if (((strstr (pattern, "0x")) && (strlen (pattern) == 10)) || |
|
278 |
(strstr(pattern, "0x")) && (strlen (pattern) == 18)) { |
if (((my_iskeychar (pattern[0])) && (strlen (pattern) == 8)) || |
279 |
rc = 0; /* Either long or short keyid */ |
(my_iskeychar (pattern[0])) && (strlen (pattern) == 16)) |
280 |
goto leave; |
rc = 0; /* assume long or short key ID. */ |
281 |
} |
else if (strchr (pattern, '@') && strlen (pattern) >= 3) |
282 |
|
rc = 0; /* assume email address. */ |
283 |
if( (( my_iskeychar( pattern[0] )) && ( strlen( pattern ) == 8 ) ) |
|
|
|| (my_iskeychar(pattern[0])) && ( strlen( pattern ) == 16) ) { |
|
|
rc = 0; |
|
|
goto leave; |
|
|
} |
|
|
|
|
|
if ((strchr (pattern, '@')) && |
|
|
(strlen (pattern) >= 3)) { |
|
|
rc = 0; |
|
|
goto leave; |
|
|
} |
|
|
|
|
|
leave: |
|
284 |
return rc; |
return rc; |
285 |
} |
} |
286 |
|
|
339 |
free_if_alloc (p); |
free_if_alloc (p); |
340 |
} |
} |
341 |
|
|
342 |
|
|
343 |
/* Save the selected keyserver from @lv as the default server. */ |
/* Save the selected keyserver from @lv as the default server. */ |
344 |
static int |
static int |
345 |
save_default_ks (listview_ctrl_t lv) |
save_default_ks (listview_ctrl_t lv) |
604 |
DestroyMenu (hm); |
DestroyMenu (hm); |
605 |
DestroyMenu (pop); |
DestroyMenu (pop); |
606 |
} |
} |
607 |
|
else if (notify->code == LVN_ITEMCHANGED && |
608 |
|
((LPNMLISTVIEW)lparam)->uNewState) { |
609 |
|
/* XXX: disable search for ldap servers. */ |
610 |
|
} |
611 |
return TRUE; |
return TRUE; |
612 |
|
|
613 |
case WM_DESTROY: |
case WM_DESTROY: |
621 |
case WM_SYSCOMMAND: |
case WM_SYSCOMMAND: |
622 |
if (LOWORD (wparam) == SC_CLOSE) |
if (LOWORD (wparam) == SC_CLOSE) |
623 |
EndDialog (dlg, TRUE); |
EndDialog (dlg, TRUE); |
624 |
return FALSE; |
return FALSE; |
625 |
|
|
626 |
case WM_COMMAND: |
case WM_COMMAND: |
627 |
switch (LOWORD (wparam)) { |
switch (LOWORD (wparam)) { |
628 |
case IDC_KEYSERVER_PROXSETT: |
case IDC_KEYSERVER_PROXSETT: |