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 |
* |
* |
106 |
with the pattern @pattern. |
with the pattern @pattern. |
107 |
Return value: 0 on success. */ |
Return value: 0 on success. */ |
108 |
int |
int |
109 |
hkp_recv_key (HWND dlg, const char *kserver, WORD port, |
hkp_recv_key2 (HWND dlg, const char *kserver, WORD port, |
110 |
const char *pattern, int proto, int flags) |
const char *pattern, int proto, int flags, |
111 |
|
char **r_fpr) |
112 |
{ |
{ |
113 |
gpgme_ctx_t ctx; |
gpgme_ctx_t ctx; |
114 |
gpgme_data_t keydata; |
gpgme_data_t keydata; |
115 |
gpgme_error_t ec; |
gpgme_error_t ec; |
116 |
gpgme_import_result_t import_res = NULL; |
gpgme_import_result_t import_res = NULL; |
|
int rc; |
|
117 |
char *rawkey = NULL; |
char *rawkey = NULL; |
118 |
char msg[384]; |
char msg[384]; |
119 |
|
int rc; |
120 |
|
|
121 |
|
/* XXX: implement dynamic buffers. */ |
122 |
rawkey = new char[MAX_KEYSIZE]; |
rawkey = new char[MAX_KEYSIZE]; |
123 |
if (!rawkey) |
if (!rawkey) |
124 |
BUG (0); |
BUG (0); |
166 |
goto leave; |
goto leave; |
167 |
} |
} |
168 |
import_res = gpgme_op_import_result (ctx); |
import_res = gpgme_op_import_result (ctx); |
169 |
|
if (r_fpr) |
170 |
|
*r_fpr = m_strdup (import_res->imports->fpr); |
171 |
} |
} |
172 |
|
|
173 |
/* 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 |
193 |
} |
} |
194 |
|
|
195 |
|
|
196 |
|
/* Alias for hkp_recv_key2 but without the ability to return |
197 |
|
the fingerprint of the key. */ |
198 |
|
int |
199 |
|
hkp_recv_key (HWND dlg, const char *kserver, WORD port, |
200 |
|
const char *pattern, int proto, int flags) |
201 |
|
{ |
202 |
|
return hkp_recv_key2 (dlg, kserver, port, pattern, proto, flags, NULL); |
203 |
|
} |
204 |
|
|
205 |
|
|
206 |
#define my_iskeychar(a) (((a) >='0' && (a) <= '9' ) || ((a) >= 'A' && (a) <= 'F')) |
#define my_iskeychar(a) (((a) >='0' && (a) <= '9' ) || ((a) >= 'A' && (a) <= 'F')) |
207 |
|
|
208 |
static int |
static int |
376 |
{ |
{ |
377 |
static listview_ctrl_t lv = NULL; |
static listview_ctrl_t lv = NULL; |
378 |
static int lv_idx = 0; |
static int lv_idx = 0; |
379 |
int rc, proto_nr = 0; |
static struct genkey_s *key; |
|
char kserver[128], pattern[128]; |
|
|
char proto[16]; |
|
380 |
keyserver_ctx ksc; |
keyserver_ctx ksc; |
381 |
|
char kserver[128], pattern[128]; |
382 |
|
char proto[16]; |
383 |
|
int rc, proto_nr = 0; |
384 |
|
|
385 |
switch ( msg ) { |
switch (msg) { |
386 |
case WM_INITDIALOG: |
case WM_INITDIALOG: |
387 |
|
if (lparam != 0) |
388 |
|
key = (struct genkey_s*)lparam; |
389 |
SetWindowText (dlg, _("Keyserver Access")); |
SetWindowText (dlg, _("Keyserver Access")); |
390 |
SetDlgItemText (dlg, IDC_KEYSERVER_RECV, _("&Receive")); |
SetDlgItemText (dlg, IDC_KEYSERVER_RECV, _("&Receive")); |
391 |
SetDlgItemText (dlg, IDC_KEYSERVER_SEND, |
SetDlgItemText (dlg, IDC_KEYSERVER_SEND, |
406 |
case WM_NOTIFY: |
case WM_NOTIFY: |
407 |
NMHDR *notify; |
NMHDR *notify; |
408 |
notify = (NMHDR *)lparam; |
notify = (NMHDR *)lparam; |
409 |
if( notify && notify->code == NM_CLICK |
if (notify && notify->code == NM_CLICK |
410 |
&& notify->idFrom == IDC_KEYSERVER_LIST ) |
&& notify->idFrom == IDC_KEYSERVER_LIST) |
411 |
lv_idx = listview_get_curr_pos( lv ); |
lv_idx = listview_get_curr_pos (lv); |
412 |
return TRUE; |
return TRUE; |
413 |
|
|
414 |
case WM_DESTROY: |
case WM_DESTROY: |
415 |
if( lv ) { |
if (lv) { |
416 |
listview_release( lv ); |
listview_release (lv); |
417 |
lv = NULL; |
lv = NULL; |
418 |
} |
} |
419 |
lv_idx = 0; |
lv_idx = 0; |
420 |
return FALSE; |
return FALSE; |
421 |
|
|
422 |
case WM_SYSCOMMAND: |
case WM_SYSCOMMAND: |
423 |
if( LOWORD( wparam ) == SC_CLOSE ) |
if (LOWORD (wparam) == SC_CLOSE) |
424 |
EndDialog( dlg, TRUE ); |
EndDialog (dlg, TRUE); |
425 |
return FALSE; |
return FALSE; |
426 |
|
|
427 |
case WM_COMMAND: |
case WM_COMMAND: |
428 |
switch( LOWORD( wparam ) ) { |
switch (LOWORD (wparam)) { |
429 |
case IDC_KEYSERVER_PROXSETT: |
case IDC_KEYSERVER_PROXSETT: |
430 |
dialog_box_param( glob_hinst, (LPCTSTR)IDD_WINPT_KEYSERVER_PROXY, glob_hwnd, |
dialog_box_param (glob_hinst, (LPCTSTR)IDD_WINPT_KEYSERVER_PROXY, |
431 |
keyserver_proxy_dlg_proc, NULL, |
dlg, keyserver_proxy_dlg_proc, 0, |
432 |
_("Proxy Settings"), IDS_WINPT_KEYSERVER_PROXY ); |
_("Proxy Settings"), IDS_WINPT_KEYSERVER_PROXY); |
433 |
set_proxy( dlg ); |
set_proxy (dlg); |
434 |
return TRUE; |
return TRUE; |
435 |
|
|
436 |
case IDC_KEYSERVER_INDEX: |
case IDC_KEYSERVER_INDEX: |
444 |
} |
} |
445 |
listview_get_item_text (lv, lv_idx, 1, proto, sizeof (proto)-1); |
listview_get_item_text (lv, lv_idx, 1, proto, sizeof (proto)-1); |
446 |
if (*proto == 'L') { |
if (*proto == 'L') { |
447 |
msg_box( dlg, _("This is not implemented yet!"), _("Keyserver"), MB_ERR ); |
msg_box (dlg, _("This is not implemented yet!"), |
448 |
|
_("Keyserver"), MB_ERR); |
449 |
return FALSE; |
return FALSE; |
450 |
} |
} |
451 |
listview_get_item_text (lv, lv_idx, 0, kserver, sizeof (kserver)-1); |
listview_get_item_text (lv, lv_idx, 0, kserver, sizeof (kserver)-1); |
452 |
if (!GetDlgItemText (dlg, IDC_KEYSERVER_SEARCH, pattern, sizeof (pattern)-1)) { |
if (!GetDlgItemText (dlg, IDC_KEYSERVER_SEARCH, pattern, sizeof (pattern)-1)) { |
453 |
msg_box (dlg, _("Please enter the search pattern."), _("Keyserver"), MB_INFO); |
msg_box (dlg, _("Please enter the search pattern."), |
454 |
|
_("Keyserver"), MB_INFO); |
455 |
return FALSE; |
return FALSE; |
456 |
} |
} |
457 |
ksc.name = kserver; |
ksc.name = kserver; |
458 |
ksc.pattern = pattern; |
ksc.pattern = pattern; |
459 |
ksc.port = kserver_get_port (lv); |
ksc.port = kserver_get_port (lv); |
460 |
DialogBoxParam( glob_hinst, (LPCSTR)IDD_WINPT_HKPSEARCH, dlg, |
DialogBoxParam (glob_hinst, (LPCSTR)IDD_WINPT_HKPSEARCH, dlg, |
461 |
hkpsearch_dlg_proc, (LPARAM) &ksc ); |
hkpsearch_dlg_proc, (LPARAM) &ksc); |
462 |
return TRUE; |
return TRUE; |
463 |
|
|
464 |
case IDC_KEYSERVER_RECV: |
case IDC_KEYSERVER_RECV: |
473 |
} |
} |
474 |
listview_get_item_text( lv, lv_idx, 1, proto, sizeof (proto)-1 ); |
listview_get_item_text( lv, lv_idx, 1, proto, sizeof (proto)-1 ); |
475 |
proto_nr = KSPROTO_HTTP; |
proto_nr = KSPROTO_HTTP; |
476 |
if( *proto == 'L' ) |
if (*proto == 'L') |
477 |
proto_nr = KSPROTO_LDAP; |
proto_nr = KSPROTO_LDAP; |
478 |
else if( *proto == 'F' ) |
else if (*proto == 'F') |
479 |
proto_nr = KSPROTO_FINGER; |
proto_nr = KSPROTO_FINGER; |
480 |
listview_get_item_text( lv, lv_idx, 0, kserver, sizeof (kserver)-1 ); |
listview_get_item_text (lv, lv_idx, 0, kserver, sizeof (kserver)-1); |
481 |
if( !GetDlgItemText( dlg, IDC_KEYSERVER_SEARCH, pattern, sizeof (pattern)-1 ) ) { |
if( !GetDlgItemText( dlg, IDC_KEYSERVER_SEARCH, pattern, sizeof (pattern)-1)) { |
482 |
msg_box( dlg, _("Please enter the search pattern."), _("Keyserver"), MB_INFO ); |
msg_box (dlg, _("Please enter the search pattern."), |
483 |
|
_("Keyserver"), MB_INFO); |
484 |
return FALSE; |
return FALSE; |
485 |
} |
} |
486 |
if( proto_nr == KSPROTO_LDAP && strchr( pattern, '@' ) ) { |
if (proto_nr == KSPROTO_LDAP && strchr (pattern, '@')) { |
487 |
msg_box( dlg, _("Only keyids are allowed."), _("LDAP Keyserver"), MB_INFO ); |
msg_box (dlg, _("Only keyids are allowed."), _("LDAP Keyserver"), MB_INFO); |
488 |
return FALSE; |
return FALSE; |
489 |
} |
} |
490 |
else if (proto_nr == KSPROTO_FINGER) { |
else if (proto_nr == KSPROTO_FINGER) { |
491 |
if (strchr (pattern, '@') || strchr (pattern, ' ')) { |
if (strchr (pattern, '@') || strchr (pattern, ' ')) { |
492 |
msg_box (dlg, _("Only enter the name of the user."), _("FINGER Keyserver"), MB_INFO); |
msg_box (dlg, _("Only enter the name of the user."), |
493 |
|
_("FINGER Keyserver"), MB_INFO); |
494 |
return FALSE; |
return FALSE; |
495 |
} |
} |
496 |
} |
} |
497 |
else if( check_pattern( pattern ) ) { |
else if (check_pattern (pattern)) { |
498 |
msg_box( dlg, _("Only email addresses or keyids are allowed."), _("HKP Keyserver"), MB_INFO ); |
msg_box (dlg, _("Only email addresses or keyids are allowed."), |
499 |
|
_("HKP Keyserver"), MB_INFO); |
500 |
return FALSE; |
return FALSE; |
501 |
} |
} |
502 |
rc = hkp_recv_key (dlg, kserver, kserver_get_port (lv), pattern, proto_nr, 0); |
rc = hkp_recv_key2 (dlg, kserver, kserver_get_port (lv), |
503 |
if (!rc) |
pattern, proto_nr, 0, key? &key->fpr : NULL); |
504 |
keycache_set_reload (1); |
if (!rc && key->fpr != NULL) { |
505 |
|
keycache_update (0, key->fpr); |
506 |
|
get_pubkey (key->fpr, &key->newkey); |
507 |
|
/* we do not need the fingerprint any longer. */ |
508 |
|
free_if_alloc (key->fpr); |
509 |
|
} |
510 |
return TRUE; |
return TRUE; |
511 |
|
|
512 |
case IDC_KEYSERVER_DEFAULT: |
case IDC_KEYSERVER_DEFAULT: |
522 |
|
|
523 |
return FALSE; |
return FALSE; |
524 |
} |
} |
|
|
|