56 |
int |
int |
57 |
hkp_send_key (HWND dlg, const char *kserver, u16 port, const char *pattern) |
hkp_send_key (HWND dlg, const char *kserver, u16 port, const char *pattern) |
58 |
{ |
{ |
59 |
gpgme_ctx_t c; |
gpgme_ctx_t c; |
|
gpgme_recipients_t rset; |
|
60 |
gpgme_data_t keydata; |
gpgme_data_t keydata; |
61 |
gpgme_error_t ec; |
gpgme_error_t ec; |
62 |
char *rawkey = NULL, msg[1024]; |
char *rawkey = NULL, msg[1024]; |
63 |
|
size_t n; |
64 |
int rc; |
int rc; |
65 |
|
|
|
ec = gpgme_recipients_new( &rset ); |
|
|
if( ec ) |
|
|
BUG( NULL ); |
|
|
gpgme_recipients_add_name( rset, pattern ); |
|
66 |
ec = gpgme_new( &c ); |
ec = gpgme_new( &c ); |
67 |
if( ec ) |
if( ec ) |
68 |
BUG( NULL ); |
BUG( NULL ); |
69 |
gpgme_control( c, GPGME_CTRL_ARMOR, 1 ); |
gpgme_set_armor (c, 1); |
70 |
ec = gpgme_data_new( &keydata ); |
ec = gpgme_data_new( &keydata ); |
71 |
if( ec ) |
if( ec ) |
72 |
BUG( NULL ); |
BUG( NULL ); |
73 |
rc = (int) gpgme_op_export( c, rset, keydata ); |
rc = (int) gpgme_op_export( c, pattern, 0, keydata ); |
74 |
if( rc ) { |
if( rc ) { |
75 |
msg_box( dlg, gpgme_strerror( (gpgme_error_t)rc ), _("Export"), MB_ERR ); |
msg_box( dlg, gpgme_strerror( (gpgme_error_t)rc ), _("Export"), MB_ERR ); |
76 |
goto leave; |
goto leave; |
77 |
} |
} |
78 |
rawkey = gpgme_data_release_and_return_string (keydata); |
rawkey = gpgme_data_release_and_get_mem (keydata, &n); |
79 |
rc = kserver_sendkey (kserver, port, rawkey, strlen (rawkey)); |
rc = kserver_sendkey (kserver, port, rawkey, n); |
80 |
if (rc) { |
if (rc) { |
81 |
hkp_err_box (dlg, kserver, port, rc); |
hkp_err_box (dlg, kserver, port, rc); |
82 |
goto leave; |
goto leave; |
87 |
|
|
88 |
leave: |
leave: |
89 |
gpgme_release (c); |
gpgme_release (c); |
90 |
gpgme_recipients_release (rset); |
if (rawkey) |
91 |
safe_free (rawkey); |
gpgme_free (rawkey); |
92 |
return rc; |
return rc; |
93 |
} /* hkp_send_key */ |
} /* hkp_send_key */ |
94 |
|
|
95 |
|
|
96 |
int |
int |
97 |
hkp_recv_key (HWND dlg, const char *kserver, u16 port, const char *pattern, int proto, int flags) |
hkp_recv_key (HWND dlg, const char *kserver, u16 port, |
98 |
|
const char *pattern, int proto, int flags) |
99 |
{ |
{ |
100 |
gpgme_ctx_t ctx; |
gpgme_ctx_t ctx; |
101 |
gpgme_data_t keydata; |
gpgme_data_t keydata; |
102 |
gpgme_error_t ec; |
gpgme_error_t ec; |
103 |
int rc, import_res[14]; |
gpgme_import_result_t import_res; |
104 |
char * rawkey = NULL, msg[384]; |
int rc; |
105 |
|
char *rawkey = NULL, msg[384]; |
106 |
|
|
107 |
rawkey = new char[MAX_KEYSIZE]; |
rawkey = new char[MAX_KEYSIZE]; |
108 |
if (!rawkey) |
if (!rawkey) |
124 |
if (rc) { |
if (rc) { |
125 |
log_box (_("Keyserver"), MB_ERR, _("Finger key import failed: %s\n"), |
log_box (_("Keyserver"), MB_ERR, _("Finger key import failed: %s\n"), |
126 |
winpt_strerror (rc)); |
winpt_strerror (rc)); |
127 |
free_if_alloc( rawkey ); |
free_if_alloc (rawkey); |
128 |
return rc; |
return rc; |
129 |
} |
} |
130 |
} |
} |
143 |
if( ec ) |
if( ec ) |
144 |
BUG( NULL ); |
BUG( NULL ); |
145 |
gpgme_data_new_from_mem( &keydata, rawkey, strlen( rawkey ), 1 ); |
gpgme_data_new_from_mem( &keydata, rawkey, strlen( rawkey ), 1 ); |
146 |
rc = gpgme_op_import( ctx, NULL, keydata ); |
rc = gpgme_op_import( ctx, keydata ); |
147 |
if( rc ) { |
if( rc ) { |
148 |
msg_box( dlg, gpgme_strerror( (gpgme_error_t)rc ), _("Import"), MB_ERR ); |
msg_box( dlg, gpgme_strerror( (gpgme_error_t)rc ), _("Import"), MB_ERR ); |
149 |
goto leave; |
goto leave; |
150 |
} |
} |
151 |
gpgme_get_import_status( ctx, import_res, NULL ); |
import_res = gpgme_op_import_result (ctx); |
152 |
} |
} |
153 |
|
|
154 |
/* 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 |
155 |
a summarize at the end is presented and not for each key. */ |
a summarize at the end is presented and not for each key. */ |
156 |
if( !(flags & KM_KS_REFRESH) ) { |
if (!(flags & KM_KS_REFRESH)) { |
157 |
if( import_res[GPGME_IMPSTAT_NPKEYS] == 0 ) { |
if (import_res->new_user_ids == 0) { |
158 |
_snprintf( msg, sizeof (msg) - 1, |
_snprintf (msg, DIM (msg)-1, |
159 |
_("Key '%s' successfully received but nothing was changed."), pattern ); |
_("Key '%s' successfully received but nothing was changed."), pattern ); |
160 |
status_box( dlg, msg, _("GnuPG Status") ); |
status_box (dlg, msg, _("GnuPG Status")); |
161 |
rc = WPTERR_GENERAL; |
rc = WPTERR_GENERAL; |
162 |
goto leave; |
goto leave; |
163 |
} |
} |
164 |
_snprintf( msg, sizeof (msg) - 1, _("Key '%s' sucessfully received and imported."), pattern ); |
_snprintf (msg, DIM (msg)-1, _("Key '%s' sucessfully received and imported."), pattern); |
165 |
status_box( dlg, msg, _("GnuPG Status") ); |
status_box (dlg, msg, _("GnuPG Status")); |
166 |
} |
} |
167 |
|
|
168 |
leave: |
leave: |
353 |
|
|
354 |
switch ( msg ) { |
switch ( msg ) { |
355 |
case WM_INITDIALOG: |
case WM_INITDIALOG: |
356 |
#ifndef LANG_DE |
#ifndef LANG_DE |
357 |
SetWindowText( dlg, _("Keyserver Access") ); |
SetWindowText (dlg, _("Keyserver Access")); |
358 |
SetDlgItemText( dlg, IDC_KEYSERVER_SEND, |
SetDlgItemText (dlg, IDC_KEYSERVER_RECV, _("&Receive")); |
359 |
_("Send key (default is receiving)") ); |
SetDlgItemText (dlg, IDC_KEYSERVER_SEND, |
360 |
SetDlgItemText( dlg, IDC_KEYSERVER_INFO, |
_("Send key (default is receiving)")); |
361 |
_("Please enter the key ID or email address that belongs to the key")); |
SetDlgItemText (dlg, IDC_KEYSERVER_INFO, |
362 |
SetDlgItemText( dlg, IDC_KEYSERVER_INDEX, _("&Search") ); |
_("Please enter the key ID or email address you search for")); |
363 |
#endif |
SetDlgItemText (dlg, IDC_KEYSERVER_INDEX, _("&Search")); |
364 |
|
SetDlgItemText (dlg, IDC_KEYSERVER_PROXSETT, _("C&hange")); |
365 |
|
#endif |
366 |
set_proxy (dlg); |
set_proxy (dlg); |
367 |
keyserver_list_build (&lv, GetDlgItem (dlg, IDC_KEYSERVER_LIST)); |
keyserver_list_build (&lv, GetDlgItem (dlg, IDC_KEYSERVER_LIST)); |
368 |
center_window (dlg); |
center_window (dlg, NULL); |
369 |
SetForegroundWindow (dlg); |
SetForegroundWindow (dlg); |
370 |
return TRUE; |
return TRUE; |
371 |
|
|
448 |
msg_box( dlg, _("Only keyids are allowed."), _("LDAP Keyserver"), MB_INFO ); |
msg_box( dlg, _("Only keyids are allowed."), _("LDAP Keyserver"), MB_INFO ); |
449 |
return FALSE; |
return FALSE; |
450 |
} |
} |
451 |
else if( proto_nr == KSPROTO_FINGER && |
else if (proto_nr == KSPROTO_FINGER) { |
452 |
( strchr( pattern, '@' ) || strchr( pattern, ' ' ) ) ) { |
if (strchr (pattern, '@') || strchr (pattern, ' ')) { |
453 |
msg_box( dlg, _("Only enter the name of the user."), _("FINGER Keyserver"), MB_INFO ); |
msg_box (dlg, _("Only enter the name of the user."), _("FINGER Keyserver"), MB_INFO); |
454 |
return FALSE; |
return FALSE; |
455 |
|
} |
456 |
} |
} |
457 |
else if( check_pattern( pattern ) ) { |
else if( check_pattern( pattern ) ) { |
458 |
msg_box( dlg, _("Only email addresses or keyids are allowed."), _("Keyserver"), MB_INFO ); |
msg_box( dlg, _("Only email addresses or keyids are allowed."), _("HKP Keyserver"), MB_INFO ); |
459 |
return FALSE; |
return FALSE; |
460 |
} |
} |
461 |
rc = hkp_recv_key (dlg, kserver, kserver_get_port (lv), pattern, proto_nr, 0); |
rc = hkp_recv_key (dlg, kserver, kserver_get_port (lv), pattern, proto_nr, 0); |