1 |
/* wptKeyserverDlg.cpp - Keyserver dialog |
/* wptKeyserverDlg.cpp - Keyserver dialog |
2 |
* Copyright (C) 2000-2005 Timo Schulz |
* Copyright (C) 2000-2005 Timo Schulz |
3 |
|
* Copyright (C) 2005 g10 Code GmbH |
4 |
* |
* |
5 |
* This file is part of WinPT. |
* This file is part of WinPT. |
6 |
* |
* |
102 |
} |
} |
103 |
|
|
104 |
|
|
105 |
|
|
106 |
|
/* Show all received keys from the keyserver. */ |
107 |
|
static void |
108 |
|
show_imported_keys (gpgme_import_result_t res) |
109 |
|
{ |
110 |
|
gpgme_import_status_t t; |
111 |
|
gpgme_key_t key; |
112 |
|
gpgme_data_t msg; |
113 |
|
gpgme_ctx_t ctx; |
114 |
|
gpgme_error_t err; |
115 |
|
const char *s; |
116 |
|
char *p; |
117 |
|
size_t n=0; |
118 |
|
|
119 |
|
if (!res) |
120 |
|
return; |
121 |
|
|
122 |
|
err = gpgme_data_new (&msg); |
123 |
|
if (err) |
124 |
|
BUG (NULL); |
125 |
|
err = gpgme_new (&ctx); |
126 |
|
if (err) |
127 |
|
BUG (NULL); |
128 |
|
if (res->considered > 1) { |
129 |
|
s = _("WARNING: multiple keys matched request.\n\n"); |
130 |
|
gpgme_data_write (msg, s, strlen (s)); |
131 |
|
} |
132 |
|
|
133 |
|
if (res->unchanged == res->considered) |
134 |
|
s = _("Key(s) successfully received but nothing was changed."); |
135 |
|
else |
136 |
|
s = _("Key(s) sucessfully received and imported."); |
137 |
|
gpgme_data_write (msg, s, strlen (s)); |
138 |
|
gpgme_data_write (msg, "\n\n", 2); |
139 |
|
|
140 |
|
for (t=res->imports; t; t = t->next) { |
141 |
|
if (!gpgme_get_key (ctx, t->fpr, &key, 0)) { |
142 |
|
s = key->uids->uid; |
143 |
|
gpgme_data_write (msg, s, strlen (s)); |
144 |
|
gpgme_data_write (msg, "\n", 1); |
145 |
|
gpgme_key_release (key); |
146 |
|
} |
147 |
|
} |
148 |
|
gpgme_data_write (msg, "\0", 1); |
149 |
|
p = gpgme_data_release_and_get_mem (msg, &n); |
150 |
|
if (p != NULL) { |
151 |
|
msg_box (NULL, p, _("Imported Keys"), MB_INFO); |
152 |
|
gpgme_free (p); |
153 |
|
} |
154 |
|
gpgme_release (ctx); |
155 |
|
} |
156 |
|
|
157 |
|
|
158 |
/* Receive a key from the keyserver @kserver (port @port) |
/* Receive a key from the keyserver @kserver (port @port) |
159 |
with the pattern @pattern. |
with the pattern @pattern. |
160 |
Return value: 0 on success. */ |
Return value: 0 on success. */ |
161 |
int |
int |
162 |
hkp_recv_key (HWND dlg, const char *kserver, WORD port, |
hkp_recv_key2 (HWND dlg, const char *kserver, WORD port, |
163 |
const char *pattern, int proto, int flags) |
const char *pattern, int proto, int flags, |
164 |
|
char **r_fpr) |
165 |
{ |
{ |
166 |
gpgme_ctx_t ctx; |
gpgme_ctx_t ctx; |
167 |
gpgme_data_t keydata; |
gpgme_data_t keydata; |
168 |
gpgme_error_t ec; |
gpgme_error_t ec; |
169 |
gpgme_import_result_t import_res = NULL; |
gpgme_import_result_t import_res = NULL; |
|
int rc; |
|
170 |
char *rawkey = NULL; |
char *rawkey = NULL; |
171 |
char msg[384]; |
int rc; |
172 |
|
|
173 |
|
/* XXX: implement dynamic buffers. */ |
174 |
rawkey = new char[MAX_KEYSIZE]; |
rawkey = new char[MAX_KEYSIZE]; |
175 |
if (!rawkey) |
if (!rawkey) |
176 |
BUG (0); |
BUG (0); |
218 |
goto leave; |
goto leave; |
219 |
} |
} |
220 |
import_res = gpgme_op_import_result (ctx); |
import_res = gpgme_op_import_result (ctx); |
221 |
|
if (import_res && r_fpr) |
222 |
|
*r_fpr = m_strdup (import_res->imports->fpr); |
223 |
} |
} |
224 |
|
|
225 |
/* 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 |
226 |
a summarize at the end is presented and not for each key. */ |
a summarize at the end is presented and not for each key. */ |
227 |
if (!(flags & KM_KS_REFRESH)) { |
if (!(flags & KM_KS_REFRESH)) { |
228 |
if (import_res && import_res->unchanged == 1) { |
show_imported_keys (import_res); |
229 |
_snprintf (msg, DIM (msg)-1, |
if (import_res && import_res->unchanged == import_res->considered) { |
230 |
_("Key '%s' successfully received but nothing was changed."), pattern ); |
rc = WPTERR_GENERAL; /* no keys updated. */ |
|
status_box (dlg, msg, _("GnuPG Status")); |
|
|
rc = WPTERR_GENERAL; |
|
231 |
goto leave; |
goto leave; |
232 |
} |
} |
|
_snprintf (msg, DIM (msg)-1, _("Key '%s' sucessfully received and imported."), pattern); |
|
|
status_box (dlg, msg, _("GnuPG Status")); |
|
233 |
} |
} |
234 |
|
|
235 |
leave: |
leave: |
236 |
free_if_alloc (rawkey); |
free_if_alloc (rawkey); |
237 |
gpgme_release (ctx); |
gpgme_release (ctx); |
241 |
} |
} |
242 |
|
|
243 |
|
|
244 |
|
/* Alias for hkp_recv_key2 but without the ability to return |
245 |
|
the fingerprint of the key. */ |
246 |
|
int |
247 |
|
hkp_recv_key (HWND dlg, const char *kserver, WORD port, |
248 |
|
const char *pattern, int proto, int flags) |
249 |
|
{ |
250 |
|
return hkp_recv_key2 (dlg, kserver, port, pattern, proto, flags, NULL); |
251 |
|
} |
252 |
|
|
253 |
|
|
254 |
#define my_iskeychar(a) (((a) >='0' && (a) <= '9' ) || ((a) >= 'A' && (a) <= 'F')) |
#define my_iskeychar(a) (((a) >='0' && (a) <= '9' ) || ((a) >= 'A' && (a) <= 'F')) |
255 |
|
|
256 |
static int |
static int |
424 |
{ |
{ |
425 |
static listview_ctrl_t lv = NULL; |
static listview_ctrl_t lv = NULL; |
426 |
static int lv_idx = 0; |
static int lv_idx = 0; |
427 |
int rc, proto_nr = 0; |
static struct genkey_s *key; |
|
char kserver[128], pattern[128]; |
|
|
char proto[16]; |
|
428 |
keyserver_ctx ksc; |
keyserver_ctx ksc; |
429 |
|
char kserver[128], pattern[128]; |
430 |
|
char proto[16]; |
431 |
|
int rc, proto_nr = 0; |
432 |
|
|
433 |
switch ( msg ) { |
switch (msg) { |
434 |
case WM_INITDIALOG: |
case WM_INITDIALOG: |
435 |
|
if (lparam != 0) |
436 |
|
key = (struct genkey_s*)lparam; |
437 |
SetWindowText (dlg, _("Keyserver Access")); |
SetWindowText (dlg, _("Keyserver Access")); |
438 |
SetDlgItemText (dlg, IDC_KEYSERVER_RECV, _("&Receive")); |
SetDlgItemText (dlg, IDC_KEYSERVER_RECV, _("&Receive")); |
439 |
SetDlgItemText (dlg, IDC_KEYSERVER_SEND, |
SetDlgItemText (dlg, IDC_KEYSERVER_SEND, |
443 |
SetDlgItemText (dlg, IDC_KEYSERVER_INDEX, _("&Search")); |
SetDlgItemText (dlg, IDC_KEYSERVER_INDEX, _("&Search")); |
444 |
SetDlgItemText (dlg, IDC_KEYSERVER_PROXSETT, _("C&hange")); |
SetDlgItemText (dlg, IDC_KEYSERVER_PROXSETT, _("C&hange")); |
445 |
SetDlgItemText (dlg, IDC_KEYSERVER_DEFAULT, _("Set &default")); |
SetDlgItemText (dlg, IDC_KEYSERVER_DEFAULT, _("Set &default")); |
446 |
SetDlgItemText (dlg, IDCANCEL, _("&Cancel")); |
SetDlgItemText (dlg, IDCANCEL, _("&Close")); |
447 |
|
|
448 |
set_proxy (dlg); |
set_proxy (dlg); |
449 |
keyserver_list_build (&lv, GetDlgItem (dlg, IDC_KEYSERVER_LIST)); |
keyserver_list_build (&lv, GetDlgItem (dlg, IDC_KEYSERVER_LIST)); |
454 |
case WM_NOTIFY: |
case WM_NOTIFY: |
455 |
NMHDR *notify; |
NMHDR *notify; |
456 |
notify = (NMHDR *)lparam; |
notify = (NMHDR *)lparam; |
457 |
if( notify && notify->code == NM_CLICK |
if (notify && notify->code == NM_CLICK |
458 |
&& notify->idFrom == IDC_KEYSERVER_LIST ) |
&& notify->idFrom == IDC_KEYSERVER_LIST) |
459 |
lv_idx = listview_get_curr_pos( lv ); |
lv_idx = listview_get_curr_pos (lv); |
460 |
return TRUE; |
return TRUE; |
461 |
|
|
462 |
case WM_DESTROY: |
case WM_DESTROY: |
463 |
if( lv ) { |
if (lv) { |
464 |
listview_release( lv ); |
listview_release (lv); |
465 |
lv = NULL; |
lv = NULL; |
466 |
} |
} |
467 |
lv_idx = 0; |
lv_idx = 0; |
468 |
return FALSE; |
return FALSE; |
469 |
|
|
470 |
case WM_SYSCOMMAND: |
case WM_SYSCOMMAND: |
471 |
if( LOWORD( wparam ) == SC_CLOSE ) |
if (LOWORD (wparam) == SC_CLOSE) |
472 |
EndDialog( dlg, TRUE ); |
EndDialog (dlg, TRUE); |
473 |
return FALSE; |
return FALSE; |
474 |
|
|
475 |
case WM_COMMAND: |
case WM_COMMAND: |
476 |
switch( LOWORD( wparam ) ) { |
switch (LOWORD (wparam)) { |
477 |
case IDC_KEYSERVER_PROXSETT: |
case IDC_KEYSERVER_PROXSETT: |
478 |
dialog_box_param( glob_hinst, (LPCTSTR)IDD_WINPT_KEYSERVER_PROXY, glob_hwnd, |
dialog_box_param (glob_hinst, (LPCTSTR)IDD_WINPT_KEYSERVER_PROXY, |
479 |
keyserver_proxy_dlg_proc, NULL, |
dlg, keyserver_proxy_dlg_proc, NULL, |
480 |
_("Proxy Settings"), IDS_WINPT_KEYSERVER_PROXY ); |
_("Proxy Settings"), IDS_WINPT_KEYSERVER_PROXY); |
481 |
set_proxy( dlg ); |
set_proxy (dlg); |
482 |
return TRUE; |
return TRUE; |
483 |
|
|
484 |
case IDC_KEYSERVER_INDEX: |
case IDC_KEYSERVER_INDEX: |
492 |
} |
} |
493 |
listview_get_item_text (lv, lv_idx, 1, proto, sizeof (proto)-1); |
listview_get_item_text (lv, lv_idx, 1, proto, sizeof (proto)-1); |
494 |
if (*proto == 'L') { |
if (*proto == 'L') { |
495 |
msg_box( dlg, _("This is not implemented yet!"), _("Keyserver"), MB_ERR ); |
msg_box (dlg, _("This is not implemented yet!"), |
496 |
|
_("Keyserver"), MB_ERR); |
497 |
return FALSE; |
return FALSE; |
498 |
} |
} |
499 |
listview_get_item_text (lv, lv_idx, 0, kserver, sizeof (kserver)-1); |
listview_get_item_text (lv, lv_idx, 0, kserver, sizeof (kserver)-1); |
500 |
if (!GetDlgItemText (dlg, IDC_KEYSERVER_SEARCH, pattern, sizeof (pattern)-1)) { |
if (!GetDlgItemText (dlg, IDC_KEYSERVER_SEARCH, pattern, sizeof (pattern)-1)) { |
501 |
msg_box (dlg, _("Please enter the search pattern."), _("Keyserver"), MB_INFO); |
msg_box (dlg, _("Please enter the search pattern."), |
502 |
|
_("Keyserver"), MB_INFO); |
503 |
return FALSE; |
return FALSE; |
504 |
} |
} |
505 |
ksc.name = kserver; |
ksc.name = kserver; |
506 |
ksc.pattern = pattern; |
ksc.pattern = pattern; |
507 |
ksc.port = kserver_get_port (lv); |
ksc.port = kserver_get_port (lv); |
508 |
DialogBoxParam( glob_hinst, (LPCSTR)IDD_WINPT_HKPSEARCH, dlg, |
DialogBoxParam (glob_hinst, (LPCSTR)IDD_WINPT_HKPSEARCH, dlg, |
509 |
hkpsearch_dlg_proc, (LPARAM) &ksc ); |
hkpsearch_dlg_proc, (LPARAM) &ksc); |
510 |
return TRUE; |
return TRUE; |
511 |
|
|
512 |
case IDC_KEYSERVER_RECV: |
case IDC_KEYSERVER_RECV: |
521 |
} |
} |
522 |
listview_get_item_text( lv, lv_idx, 1, proto, sizeof (proto)-1 ); |
listview_get_item_text( lv, lv_idx, 1, proto, sizeof (proto)-1 ); |
523 |
proto_nr = KSPROTO_HTTP; |
proto_nr = KSPROTO_HTTP; |
524 |
if( *proto == 'L' ) |
if (*proto == 'L') |
525 |
proto_nr = KSPROTO_LDAP; |
proto_nr = KSPROTO_LDAP; |
526 |
else if( *proto == 'F' ) |
else if (*proto == 'F') |
527 |
proto_nr = KSPROTO_FINGER; |
proto_nr = KSPROTO_FINGER; |
528 |
listview_get_item_text( lv, lv_idx, 0, kserver, sizeof (kserver)-1 ); |
listview_get_item_text (lv, lv_idx, 0, kserver, sizeof (kserver)-1); |
529 |
if( !GetDlgItemText( dlg, IDC_KEYSERVER_SEARCH, pattern, sizeof (pattern)-1 ) ) { |
if( !GetDlgItemText( dlg, IDC_KEYSERVER_SEARCH, pattern, sizeof (pattern)-1)) { |
530 |
msg_box( dlg, _("Please enter the search pattern."), _("Keyserver"), MB_INFO ); |
msg_box (dlg, _("Please enter the search pattern."), |
531 |
|
_("Keyserver"), MB_INFO); |
532 |
return FALSE; |
return FALSE; |
533 |
} |
} |
534 |
if( proto_nr == KSPROTO_LDAP && strchr( pattern, '@' ) ) { |
if (proto_nr == KSPROTO_LDAP && strchr (pattern, '@')) { |
535 |
msg_box( dlg, _("Only keyids are allowed."), _("LDAP Keyserver"), MB_INFO ); |
msg_box (dlg, _("Only keyids are allowed."), _("LDAP Keyserver"), MB_INFO); |
536 |
return FALSE; |
return FALSE; |
537 |
} |
} |
538 |
else if (proto_nr == KSPROTO_FINGER) { |
else if (proto_nr == KSPROTO_FINGER) { |
539 |
if (strchr (pattern, '@') || strchr (pattern, ' ')) { |
if (strchr (pattern, '@') || strchr (pattern, ' ')) { |
540 |
msg_box (dlg, _("Only enter the name of the user."), _("FINGER Keyserver"), MB_INFO); |
msg_box (dlg, _("Only enter the name of the user."), |
541 |
|
_("FINGER Keyserver"), MB_INFO); |
542 |
return FALSE; |
return FALSE; |
543 |
} |
} |
544 |
} |
} |
545 |
else if( check_pattern( pattern ) ) { |
else if (check_pattern (pattern)) { |
546 |
msg_box( dlg, _("Only email addresses or keyids are allowed."), _("HKP Keyserver"), MB_INFO ); |
msg_box (dlg, _("Only email addresses or keyids are allowed."), |
547 |
|
_("HKP Keyserver"), MB_INFO); |
548 |
return FALSE; |
return FALSE; |
549 |
} |
} |
550 |
rc = hkp_recv_key (dlg, kserver, kserver_get_port (lv), pattern, proto_nr, 0); |
rc = hkp_recv_key2 (dlg, kserver, kserver_get_port (lv), |
551 |
if (!rc) |
pattern, proto_nr, 0, key? &key->fpr : NULL); |
552 |
keycache_set_reload (1); |
if (!rc && key->fpr != NULL) { |
553 |
|
keycache_update (0, key->fpr); |
554 |
|
get_pubkey (key->fpr, &key->newkey); |
555 |
|
/* we do not need the fingerprint any longer. */ |
556 |
|
free_if_alloc (key->fpr); |
557 |
|
} |
558 |
return TRUE; |
return TRUE; |
559 |
|
|
560 |
case IDC_KEYSERVER_DEFAULT: |
case IDC_KEYSERVER_DEFAULT: |
570 |
|
|
571 |
return FALSE; |
return FALSE; |
572 |
} |
} |
|
|
|