1 |
/* wptKeyserverDlg.cpp - Keyserver dialog |
/* wptKeyserverDlg.cpp - Keyserver dialog |
2 |
* Copyright (C) 2000-2006 Timo Schulz |
* Copyright (C) 2000-2007 Timo Schulz |
3 |
* Copyright (C) 2005, 2006 g10 Code GmbH |
* Copyright (C) 2005, 2006 g10 Code GmbH |
4 |
* |
* |
5 |
* This file is part of WinPT. |
* This file is part of WinPT. |
13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 |
* GNU General Public License for more details. |
* GNU General Public License for more details. |
|
* |
|
|
* You should have received a copy of the GNU General Public License |
|
|
* along with WinPT; if not, write to the Free Software Foundation, |
|
|
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
|
16 |
*/ |
*/ |
17 |
#ifdef HAVE_CONFIG_H |
#ifdef HAVE_CONFIG_H |
18 |
#include <config.h> |
#include <config.h> |
23 |
#include <ctype.h> |
#include <ctype.h> |
24 |
|
|
25 |
#include "resource.h" |
#include "resource.h" |
|
#include "wptKeyserver.h" |
|
26 |
#include "wptErrors.h" |
#include "wptErrors.h" |
27 |
#include "wptTypes.h" |
#include "wptTypes.h" |
28 |
#include "wptCommonCtl.h" |
#include "wptCommonCtl.h" |
31 |
#include "wptVersion.h" |
#include "wptVersion.h" |
32 |
#include "wptGPG.h" |
#include "wptGPG.h" |
33 |
#include "wptGPGME.h" |
#include "wptGPGME.h" |
34 |
|
#include "wptKeyserver.h" |
35 |
#include "wptContext.h" /* for passphrase_s */ |
#include "wptContext.h" /* for passphrase_s */ |
36 |
#include "wptKeyManager.h" |
#include "wptKeyManager.h" |
37 |
#include "wptDlgs.h" |
#include "wptDlgs.h" |
38 |
#include "wptUTF8.h" |
#include "wptUTF8.h" |
39 |
#include "wptRegistry.h" |
#include "wptRegistry.h" |
40 |
|
#include "wptKeylist.h" |
41 |
|
|
42 |
char* get_reg_entry_keyserver (const char *); |
char* get_reg_entry_keyserver (const char *); |
43 |
int set_reg_entry_keyserver (const char *, const char *); |
int set_reg_entry_keyserver (const char *, const char *); |
77 |
int |
int |
78 |
hkp_send_key (HWND dlg, const char *kserver, WORD port, const char *pattern) |
hkp_send_key (HWND dlg, const char *kserver, WORD port, const char *pattern) |
79 |
{ |
{ |
80 |
GPGME *gpg; |
GPGME gpg; |
81 |
gpgme_error_t ec; |
gpgme_error_t ec; |
82 |
char *rawkey = NULL; |
char *rawkey = NULL; |
83 |
char msg[256]; |
char msg[256]; |
84 |
|
|
85 |
gpg = new GPGME (); |
gpg.setArmor (true); |
86 |
gpg->setArmor (true); |
ec = gpg.exportToBuffer (pattern, &rawkey); |
|
ec = gpg->exportToBuffer (pattern, &rawkey); |
|
87 |
if (ec) { |
if (ec) { |
88 |
msg_box (dlg, gpgme_strerror (ec), _("Export"), MB_ERR); |
msg_box (dlg, gpgme_strerror (ec), _("Export"), MB_ERR); |
89 |
goto leave; |
goto leave; |
96 |
goto leave; |
goto leave; |
97 |
} |
} |
98 |
|
|
99 |
_snprintf (msg, sizeof (msg) -1, _("Key '%s' successfully sent"), pattern); |
_snprintf (msg, DIM (msg) -1, _("Key '%s' successfully sent"), pattern); |
100 |
status_box (dlg, msg, _("GnuPG status")); |
status_box (dlg, msg, _("GnuPG status")); |
101 |
|
|
102 |
leave: |
leave: |
|
delete gpg; |
|
103 |
free_if_alloc (rawkey); |
free_if_alloc (rawkey); |
104 |
return ec? -1 : 0; |
return ec? -1 : 0; |
105 |
} |
} |
137 |
s = _("Key(s) successfully received but nothing was changed."); |
s = _("Key(s) successfully received but nothing was changed."); |
138 |
else |
else |
139 |
s = _("Key(s) sucessfully received and imported."); |
s = _("Key(s) sucessfully received and imported."); |
140 |
// nice to have the amount of new signatures... |
// nice to have the amount of new signatures... |
141 |
gpgme_data_write (msg, s, strlen (s)); |
gpgme_data_write (msg, s, strlen (s)); |
142 |
gpgme_data_write (msg, "\n\n", 2); |
gpgme_data_write (msg, "\n\n", 2); |
143 |
|
|
170 |
{ |
{ |
171 |
gpgme_import_result_t import_res = NULL; |
gpgme_import_result_t import_res = NULL; |
172 |
gpgme_error_t err; |
gpgme_error_t err; |
173 |
GPGME *gpg = NULL; |
GPGME gpg; |
174 |
char *rawkey = NULL; |
char *rawkey = NULL; |
175 |
int keylen = 0; |
size_t keylen = 0; |
176 |
int rc; |
int rc; |
177 |
|
|
178 |
if (proto == KSPROTO_LDAP) { |
if (proto == KSPROTO_LDAP) { |
207 |
msg_box (dlg, _("This is not a valid OpenPGP key."), |
msg_box (dlg, _("This is not a valid OpenPGP key."), |
208 |
_("Keyserver"), MB_ERR); |
_("Keyserver"), MB_ERR); |
209 |
goto leave; |
goto leave; |
210 |
} |
} |
211 |
gpg = new GPGME (); |
err = gpg.importFromBuffer (rawkey); |
|
err = gpg->importFromBuffer (rawkey); |
|
212 |
if (err) { |
if (err) { |
213 |
msg_box (dlg, gpgme_strerror (err), _("Import"), MB_ERR); |
msg_box (dlg, gpgme_strerror (err), _("Import"), MB_ERR); |
214 |
goto leave; |
goto leave; |
215 |
} |
} |
216 |
import_res = gpg->importGetResult (); |
import_res = gpg.importGetResult (); |
217 |
if (import_res && r_fpr) |
if (import_res && r_fpr) |
218 |
*r_fpr = m_strdup (import_res->imports->fpr); |
*r_fpr = m_strdup (import_res->imports->fpr); |
219 |
|
|
229 |
|
|
230 |
leave: |
leave: |
231 |
free_if_alloc (rawkey); |
free_if_alloc (rawkey); |
|
if (gpg != NULL) |
|
|
delete gpg; |
|
232 |
return rc; |
return rc; |
233 |
} |
} |
234 |
|
|
252 |
} |
} |
253 |
|
|
254 |
|
|
255 |
|
/* Utility function to fetch a key from the keyserver |
256 |
|
based on a given signature (@sig). |
257 |
|
Return 0 on success. */ |
258 |
|
int |
259 |
|
fetch_key_from_keyserver (HWND dlg, gpgme_signature_t sig) |
260 |
|
{ |
261 |
|
const char *keyid; |
262 |
|
char timebuf[128]; |
263 |
|
int id; |
264 |
|
|
265 |
|
// XXX: we have a problem with v3 keys here |
266 |
|
if (!sig->fpr) |
267 |
|
return FALSE; |
268 |
|
if (!get_locale_timedate (sig->timestamp, timebuf, DIM (timebuf)-1)) |
269 |
|
_snprintf (timebuf, DIM (timebuf)-1, "'unknown time'"); |
270 |
|
keyid = get_keyid_from_fpr (sig->fpr); |
271 |
|
id = log_box (_("Verify"), MB_INFO|MB_YESNO, |
272 |
|
_("Signature made %s using %s key ID 0x%s\n" |
273 |
|
"Cannot check signature: public key not found\n\n" |
274 |
|
"Do you want to try to retrieve the key from the keyserver?"), |
275 |
|
timebuf, get_key_pubalgo (sig->pubkey_algo), keyid); |
276 |
|
if (id == IDNO) { |
277 |
|
msg_box (dlg, get_gpg_sigstat (GPGME_SIGSUM_KEY_MISSING), |
278 |
|
_("Verify"), MB_WARN); |
279 |
|
return -1; |
280 |
|
} |
281 |
|
|
282 |
|
if (!hkp_recv_key (dlg, default_keyserver, default_keyserver_port, |
283 |
|
keyid, 0, 0)) { |
284 |
|
keycache_update (0, keyid); |
285 |
|
return 0; |
286 |
|
} |
287 |
|
return -1; |
288 |
|
} |
289 |
|
|
290 |
|
|
291 |
/* Check if the given pattern are either a valid |
/* Check if the given pattern are either a valid |
292 |
email address, a {long, short} keyid or a fingerprint. |
email address, a {long, short} keyid or a fingerprint. |
293 |
Return 0 on success. */ |
Return 0 on success. */ |
587 |
} |
} |
588 |
|
|
589 |
|
|
590 |
|
/* XXX: factor out the pattern code for generic use. */ |
591 |
|
|
592 |
/* Add search pattern @patt to the combo box if it is |
/* Add search pattern @patt to the combo box if it is |
593 |
not already available in the list. */ |
not already available in the list. */ |
594 |
static void |
static void |
604 |
0, (LPARAM)(LPCSTR)patt); |
0, (LPARAM)(LPCSTR)patt); |
605 |
} |
} |
606 |
|
|
607 |
|
|
608 |
|
/* Restore saved pattern from the registry back to the combo box. |
609 |
|
If no pattern were saved, do nothing and just return. */ |
610 |
static void |
static void |
611 |
load_pattern_to_combox (HWND dlg, int ctlid, const char *rkey_name) |
load_pattern_to_combox (HWND dlg, int ctlid, const char *rkey_name) |
612 |
{ |
{ |
613 |
|
char *p, *tok; |
614 |
|
|
615 |
|
p = get_reg_entry (HKEY_CURRENT_USER, "Software\\WinPT", rkey_name); |
616 |
|
if (!p || strlen (p) < 2) { |
617 |
|
free_if_alloc (p); |
618 |
|
return; |
619 |
|
} |
620 |
|
tok = strtok (p, "$"); |
621 |
|
while (tok != NULL) { |
622 |
|
SendDlgItemMessage (dlg, ctlid, CB_ADDSTRING, 0, (LPARAM)(LPCTSTR)tok); |
623 |
|
tok = strtok (NULL, "$"); |
624 |
|
} |
625 |
|
free_if_alloc (p); |
626 |
} |
} |
627 |
|
|
628 |
|
|
629 |
|
/* Save all entries from the combo box given in @ctlid to the |
630 |
|
registry. Concat all values and use '$' as a separator. */ |
631 |
static void |
static void |
632 |
save_pattern_from_combox (HWND dlg, int ctlid, const char *rkey_name) |
save_pattern_from_combox (HWND dlg, int ctlid, const char *rkey_name) |
633 |
{ |
{ |
683 |
SetDlgItemText (dlg, IDC_KEYSERVER_DEFAULT, _("Set &default")); |
SetDlgItemText (dlg, IDC_KEYSERVER_DEFAULT, _("Set &default")); |
684 |
SetDlgItemText (dlg, IDCANCEL, _("&Close")); |
SetDlgItemText (dlg, IDCANCEL, _("&Close")); |
685 |
|
|
686 |
|
load_pattern_to_combox (dlg, IDC_KEYSERVER_SEARCH, "KSsearch"); |
687 |
keyserver_list_build (&lv, GetDlgItem (dlg, IDC_KEYSERVER_LIST)); |
keyserver_list_build (&lv, GetDlgItem (dlg, IDC_KEYSERVER_LIST)); |
688 |
set_default_ks (lv); |
set_default_ks (lv); |
689 |
center_window (dlg, NULL); |
center_window (dlg, NULL); |
695 |
notify = (NMHDR *)lparam; |
notify = (NMHDR *)lparam; |
696 |
if (!notify) |
if (!notify) |
697 |
break; |
break; |
698 |
if (notify->code == NM_CLICK |
if (notify->code == (UINT)NM_CLICK |
699 |
&& notify->idFrom == IDC_KEYSERVER_LIST) |
&& notify->idFrom == (UINT)IDC_KEYSERVER_LIST) |
700 |
lv_idx = listview_get_curr_pos (lv); |
lv_idx = listview_get_curr_pos (lv); |
701 |
else if (notify->code == NM_RCLICK && |
else if (notify->code == (UINT)NM_RCLICK && |
702 |
notify->idFrom == IDC_KEYSERVER_LIST) { |
notify->idFrom == (UINT)IDC_KEYSERVER_LIST) { |
703 |
POINT p; |
POINT p; |
704 |
GetCursorPos (&p); |
GetCursorPos (&p); |
705 |
HMENU hm, pop; |
HMENU hm, pop; |
795 |
_("Keyserver"), MB_INFO); |
_("Keyserver"), MB_INFO); |
796 |
return FALSE; |
return FALSE; |
797 |
} |
} |
|
add_pattern_to_combox (dlg, IDC_KEYSERVER_SEARCH, pattern); |
|
798 |
if (proto_nr == KSPROTO_LDAP && strchr (pattern, '@')) { |
if (proto_nr == KSPROTO_LDAP && strchr (pattern, '@')) { |
799 |
msg_box (dlg, _("Only keyids are allowed."), |
msg_box (dlg, _("Only keyids are allowed."), |
800 |
_("Keyserver"), MB_INFO); |
_("Keyserver"), MB_INFO); |
819 |
keycache_update (0, fpr); |
keycache_update (0, fpr); |
820 |
free_if_alloc (fpr); |
free_if_alloc (fpr); |
821 |
} |
} |
822 |
|
if (!rc) |
823 |
|
add_pattern_to_combox (dlg, IDC_KEYSERVER_SEARCH, pattern); |
824 |
return TRUE; |
return TRUE; |
825 |
|
|
826 |
case IDC_KEYSERVER_DEFAULT: |
case IDC_KEYSERVER_DEFAULT: |