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> |
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 |
size_t keylen = 0; |
size_t keylen = 0; |
176 |
int rc; |
int rc; |
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 |
|
|
259 |
fetch_key_from_keyserver (HWND dlg, gpgme_signature_t sig) |
fetch_key_from_keyserver (HWND dlg, gpgme_signature_t sig) |
260 |
{ |
{ |
261 |
const char *keyid; |
const char *keyid; |
262 |
|
char timebuf[128]; |
263 |
int id; |
int id; |
264 |
|
|
265 |
|
// XXX: we have a problem with v3 keys here |
266 |
if (!sig->fpr) |
if (!sig->fpr) |
267 |
return FALSE; |
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); |
keyid = get_keyid_from_fpr (sig->fpr); |
271 |
id = log_box (_("Verify"), MB_INFO|MB_YESNO, |
id = log_box (_("Verify"), MB_INFO|MB_YESNO, |
272 |
_("Signature made %s using %s key ID 0x%s\n" |
_("Signature made %s using %s key ID 0x%s\n" |
273 |
"Cannot check signature: public key not found\n\n" |
"Cannot check signature: public key not found\n\n" |
274 |
"Do you want to try to retrieve the key from the keyserver?"), |
"Do you want to try to retrieve the key from the keyserver?"), |
275 |
strtimestamp (sig->timestamp), |
timebuf, get_key_pubalgo (sig->pubkey_algo), keyid); |
|
get_key_pubalgo (sig->pubkey_algo), keyid); |
|
276 |
if (id == IDNO) { |
if (id == IDNO) { |
277 |
msg_box (dlg, get_gpg_sigstat (GPGME_SIGSUM_KEY_MISSING), |
msg_box (dlg, get_gpg_sigstat (GPGME_SIGSUM_KEY_MISSING), |
278 |
_("Verify"), MB_WARN); |
_("Verify"), MB_WARN); |
287 |
return -1; |
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. */ |
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; |