1 |
/* wptKeysignDlg.cpp - Key signing dialog |
/* wptKeysignDlg.cpp - Key signing dialog |
2 |
* Copyright (C) 2001-2005 Timo Schulz |
* Copyright (C) 2001-2006, 2008-2009 Timo Schulz |
3 |
* |
* |
4 |
* This file is part of WinPT. |
* This file is part of WinPT. |
5 |
* |
* |
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 |
* 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 |
|
15 |
*/ |
*/ |
|
|
|
16 |
#ifdef HAVE_CONFIG_H |
#ifdef HAVE_CONFIG_H |
17 |
#include <config.h> |
#include <config.h> |
18 |
#endif |
#endif |
19 |
|
|
20 |
#include <windows.h> |
#include <windows.h> |
|
#include <windows.h> |
|
21 |
#include <commctrl.h> |
#include <commctrl.h> |
22 |
|
#include <time.h> |
23 |
|
#include <assert.h> |
24 |
|
|
25 |
#include "../resource.h" |
#include "resource.h" |
26 |
#include "wptGPG.h" |
#include "wptGPG.h" |
27 |
#include "wptNLS.h" |
#include "wptNLS.h" |
28 |
#include "wptW32API.h" |
#include "wptW32API.h" |
34 |
#include "wptDlgs.h" |
#include "wptDlgs.h" |
35 |
#include "wptUTF8.h" |
#include "wptUTF8.h" |
36 |
#include "wptRegistry.h" |
#include "wptRegistry.h" |
37 |
#include "wptKeyList.h" |
#include "wptKeylist.h" |
38 |
#include "wptKeyEdit.h" |
#include "wptKeyEdit.h" |
39 |
|
#include "StringBuffer.h" |
40 |
|
|
41 |
static int sig_class_choice = 0; |
|
42 |
|
int key_load_photo (winpt_key_t key, |
43 |
|
char *photo_file, size_t photo_file_size, |
44 |
|
gpgme_validity_t *r_valid); |
45 |
|
int get_photo_tmpname (gpgme_key_t key, char *buf, size_t buflen); |
46 |
|
|
47 |
/* Return a beautified printable fingerprint of @fpr. */ |
/* Return a beautified printable fingerprint of @fpr. */ |
48 |
static const char* |
static const char* |
49 |
get_printable_fpr (const char *fpr) |
get_printable_fpr (const char *fpr) |
50 |
{ |
{ |
51 |
static char pfpr[64]; |
static char pfpr[128]; |
52 |
int pos = 0; |
int pos = 0; |
53 |
size_t i; |
size_t i; |
54 |
|
|
55 |
|
memset (pfpr, 0, sizeof (pfpr)); |
56 |
for (i = 0; i < strlen (fpr); i += 4) { |
for (i = 0; i < strlen (fpr); i += 4) { |
57 |
pfpr[pos++] = fpr[i]; |
pfpr[pos++] = fpr[i]; |
58 |
pfpr[pos++] = fpr[i+1]; |
pfpr[pos++] = fpr[i+1]; |
65 |
|
|
66 |
|
|
67 |
/* Return human friendly information about the key @key. */ |
/* Return human friendly information about the key @key. */ |
68 |
static const char* |
const char* |
69 |
get_keyinfo (gpgme_key_t key) |
get_keyinfo (gpgme_key_t key) |
70 |
{ |
{ |
71 |
static char buf[64+16]; |
static char buf[64+16]; |
72 |
struct winpt_key_s k; |
struct winpt_key_s k; |
73 |
|
|
74 |
memset (&k, 0, sizeof (k)); |
memset (&k, 0, sizeof (k)); |
75 |
winpt_get_seckey (key->subkeys->keyid, &k); |
if (winpt_get_seckey (key->subkeys->keyid, &k)) |
76 |
_snprintf (buf, DIM (buf)-1-16, "%d-bit %s key, ID %s", |
BUG (0); |
77 |
key->subkeys->length, |
_snprintf (buf, DIM (buf)-1-16, _("%d-bit %s key, ID 0x%s"), |
78 |
get_key_pubalgo (key->subkeys->pubkey_algo), |
key->subkeys->length, |
79 |
key->subkeys->keyid+8); |
get_key_pubalgo (key->subkeys->pubkey_algo), |
80 |
|
key->subkeys->keyid+8); |
81 |
if (k.ext->gloflags.divert_to_card) |
if (k.ext->gloflags.divert_to_card) |
82 |
strcat (buf, " (Card)"); |
strcat (buf, _(" (Card)")); |
83 |
return buf; |
return buf; |
84 |
} |
} |
85 |
|
|
91 |
do_fill_seckeylist (HWND dlg, const char *keyid) |
do_fill_seckeylist (HWND dlg, const char *keyid) |
92 |
{ |
{ |
93 |
gpg_keycache_t sec; |
gpg_keycache_t sec; |
94 |
gpgme_key_t pk; |
gpgme_key_t pk, defkey; |
95 |
const char * s; |
const char *s; |
96 |
char * uid, * p; |
char *uid; |
97 |
int i = 0, n=0; |
int i = 0, n = 0, curr_sel = 0; |
98 |
|
|
99 |
sec = keycache_get_ctx (0); |
sec = keycache_get_ctx (0); |
100 |
if (!sec) |
gpg_keycache_get_default_key (sec, &defkey); |
|
BUG (0); |
|
101 |
gpg_keycache_rewind (sec); |
gpg_keycache_rewind (sec); |
102 |
while (!gpg_keycache_next_key (sec, 1, &pk)) { |
while (!gpg_keycache_next_key (sec, 1, &pk)) { |
103 |
|
StringBuffer p; |
104 |
|
|
105 |
if (!pk) |
if (!pk) |
106 |
continue; |
continue; |
107 |
s = pk->subkeys->keyid; |
s = pk->subkeys->keyid; |
116 |
s = pk->uids->name; |
s = pk->uids->name; |
117 |
if (!s) |
if (!s) |
118 |
continue; |
continue; |
119 |
uid = utf8_to_wincp (s, strlen (s)); |
if (defkey && !strcmp (defkey->subkeys->keyid, pk->subkeys->keyid)) |
120 |
p = new char[strlen (uid) + 64]; |
curr_sel = i; |
121 |
if (!p) |
|
122 |
BUG (NULL); |
uid = utf8_to_native (s); |
123 |
_snprintf (p, strlen (uid) + 63, "%s (%s)", uid, get_keyinfo (pk)); |
p = uid; |
124 |
SendDlgItemMessage (dlg, IDC_KEYSIGN_KEYLIST, CB_ADDSTRING, i, (LPARAM)(char *)p); |
p = p + " (" + get_keyinfo (pk) + ")"; |
125 |
SendDlgItemMessage (dlg, IDC_KEYSIGN_KEYLIST, CB_SETITEMDATA, i++, (LPARAM)(DWORD)pk); |
SendDlgItemMessage (dlg, IDC_KEYSIGN_KEYLIST, |
126 |
free_if_alloc (p); |
CB_ADDSTRING, i, (LPARAM)(char *)p.getBuffer ()); |
127 |
free (uid); |
SendDlgItemMessage (dlg, IDC_KEYSIGN_KEYLIST, |
128 |
|
CB_SETITEMDATA, i++, (LPARAM)(DWORD)pk); |
129 |
|
safe_free (uid); |
130 |
n++; |
n++; |
131 |
} |
} |
132 |
SendDlgItemMessage (dlg, IDC_KEYSIGN_KEYLIST, CB_SETCURSEL, 0, 0); |
SendDlgItemMessage (dlg, IDC_KEYSIGN_KEYLIST, |
133 |
|
CB_SETCURSEL, (WPARAM)curr_sel, 0); |
134 |
if (!n) |
if (!n) |
135 |
return -1; |
return -1; |
136 |
return 0; |
return 0; |
142 |
static void |
static void |
143 |
do_check_protection (HWND dlg) |
do_check_protection (HWND dlg) |
144 |
{ |
{ |
|
int idx, protec; |
|
145 |
gpgme_key_t key; |
gpgme_key_t key; |
146 |
struct winpt_key_s k; |
struct winpt_key_s k; |
147 |
|
int idx, protec; |
148 |
|
|
149 |
idx = SendDlgItemMessage( dlg, IDC_KEYSIGN_KEYLIST, CB_GETCURSEL, 0, 0 ); |
idx = SendDlgItemMessage (dlg, IDC_KEYSIGN_KEYLIST, CB_GETCURSEL, 0, 0); |
150 |
key = (gpgme_key_t)SendDlgItemMessage( dlg, IDC_KEYSIGN_KEYLIST, CB_GETITEMDATA, (WPARAM)idx, 0 ); |
key = (gpgme_key_t)SendDlgItemMessage (dlg, IDC_KEYSIGN_KEYLIST, |
151 |
if (key) { |
CB_GETITEMDATA, (WPARAM)idx, 0); |
152 |
winpt_get_seckey (key->subkeys->keyid, &k); |
if (!key) |
153 |
protec = k.is_protected; |
return; |
154 |
if (!protec) |
if (winpt_get_seckey (key->subkeys->keyid, &k)) |
155 |
protec = k.ext->gloflags.divert_to_card; |
BUG (0); |
156 |
EnableWindow (GetDlgItem (dlg, IDC_KEYSIGN_PASSPHRASE), protec? TRUE : FALSE); |
protec = k.is_protected; |
157 |
} |
if (!protec) |
158 |
|
protec = k.ext->gloflags.divert_to_card; |
159 |
|
EnableWindow (GetDlgItem (dlg, IDC_KEYSIGN_PASSPHRASE), |
160 |
|
protec? TRUE : FALSE); |
161 |
} |
} |
162 |
|
|
163 |
|
|
165 |
BOOL CALLBACK |
BOOL CALLBACK |
166 |
sig_class_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
sig_class_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
167 |
{ |
{ |
168 |
|
HWND parent; |
169 |
|
|
170 |
switch (msg) { |
switch (msg) { |
171 |
case WM_INITDIALOG: |
case WM_INITDIALOG: |
172 |
|
parent = (HWND)lparam; |
173 |
SetWindowText (dlg, _("Choose Signature Class")); |
SetWindowText (dlg, _("Choose Signature Class")); |
174 |
SetDlgItemText (dlg, IDC_SIGCLASS_TITLEINF, _("How carefully have you verified the key you are about to sign actually belongs to the person? If you don't know what to anwser, use \"0\".")); |
SetDlgItemText (dlg, IDC_SIGCLASS_TITLEINF, |
175 |
SetDlgItemText (dlg, IDC_SIGCLASS_CLASS0, _("(0) I will not answer (default)")); |
_("How carefully have you verified the key you are about to sign actually belongs to the person? If you don't know what to anwser, use \"0\".")); |
176 |
SetDlgItemText (dlg, IDC_SIGCLASS_CLASS1, _("(1) I have not checked at all.")); |
SetDlgItemText (dlg, IDC_SIGCLASS_CLASS0, |
177 |
SetDlgItemText (dlg, IDC_SIGCLASS_CLASS2, _("(2) I have done causal checking.")); |
_("(0) I will not answer (default)")); |
178 |
SetDlgItemText (dlg, IDC_SIGCLASS_CLASS3, _("(3) I have done very careful checkings.")); |
SetDlgItemText (dlg, IDC_SIGCLASS_CLASS1, |
179 |
|
_("(1) I have not checked at all.")); |
180 |
|
SetDlgItemText (dlg, IDC_SIGCLASS_CLASS2, |
181 |
|
_("(2) I have done causal checking.")); |
182 |
|
SetDlgItemText (dlg, IDC_SIGCLASS_CLASS3, |
183 |
|
_("(3) I have done very careful checking.")); |
184 |
CheckDlgButton (dlg, IDC_SIGCLASS_CLASS0, BST_CHECKED); |
CheckDlgButton (dlg, IDC_SIGCLASS_CLASS0, BST_CHECKED); |
185 |
SetForegroundWindow (dlg); |
SetForegroundWindow (dlg); |
186 |
center_window (dlg, NULL); |
center_window (dlg, parent? parent : NULL); |
187 |
return TRUE; |
return TRUE; |
188 |
|
|
189 |
case WM_COMMAND: |
case WM_COMMAND: |
190 |
switch( LOWORD( wparam ) ) { |
switch (LOWORD (wparam)) { |
191 |
case IDOK: |
case IDOK: |
192 |
|
int sig_class; |
193 |
|
|
194 |
if (IsDlgButtonChecked (dlg, IDC_SIGCLASS_CLASS0)) |
if (IsDlgButtonChecked (dlg, IDC_SIGCLASS_CLASS0)) |
195 |
sig_class_choice = 0; |
sig_class = 0; |
196 |
else if (IsDlgButtonChecked (dlg, IDC_SIGCLASS_CLASS1)) |
else if (IsDlgButtonChecked (dlg, IDC_SIGCLASS_CLASS1)) |
197 |
sig_class_choice = 1; |
sig_class = 1; |
198 |
else if (IsDlgButtonChecked (dlg, IDC_SIGCLASS_CLASS2)) |
else if (IsDlgButtonChecked (dlg, IDC_SIGCLASS_CLASS2)) |
199 |
sig_class_choice = 2; |
sig_class = 2; |
200 |
else if (IsDlgButtonChecked (dlg, IDC_SIGCLASS_CLASS3)) |
else if (IsDlgButtonChecked (dlg, IDC_SIGCLASS_CLASS3)) |
201 |
sig_class_choice = 3; |
sig_class = 3; |
202 |
else |
else |
203 |
sig_class_choice = 0; |
sig_class = 0; |
204 |
EndDialog (dlg, TRUE); |
EndDialog (dlg, sig_class); |
205 |
return TRUE; |
break; |
206 |
|
|
207 |
|
case IDCANCEL: |
208 |
|
EndDialog (dlg, 0); |
209 |
|
break; |
210 |
} |
} |
211 |
break; |
break; |
212 |
} |
} |
219 |
static const char* |
static const char* |
220 |
get_expire_date (gpgme_key_t key) |
get_expire_date (gpgme_key_t key) |
221 |
{ |
{ |
|
static char tmp[64]; |
|
|
|
|
222 |
u32 u = key->subkeys->expires; |
u32 u = key->subkeys->expires; |
223 |
if (!u) |
if (!u) |
224 |
return _("never"); |
return _("never"); |
225 |
return get_key_expire_date (u); |
return get_key_expire_date (u); |
226 |
} |
} |
227 |
|
|
228 |
/* Display photo of key @key in a separate window. */ |
|
229 |
|
/* Check if the given system time @st points to today. */ |
230 |
|
static int |
231 |
|
date_is_today (SYSTEMTIME *st) |
232 |
|
{ |
233 |
|
time_t t; |
234 |
|
struct tm *tm; |
235 |
|
|
236 |
|
t = time (NULL); |
237 |
|
tm = localtime (&t); |
238 |
|
if (st->wDay == tm->tm_mday && |
239 |
|
st->wYear == tm->tm_year+1900 && |
240 |
|
st->wMonth == tm->tm_mon+1) |
241 |
|
return -1; |
242 |
|
return 0; |
243 |
|
} |
244 |
|
|
245 |
|
|
246 |
|
/* Display all needed information about the key @key in the dialog @dlg. */ |
247 |
static void |
static void |
248 |
show_photo (winpt_key_t key) |
display_keyinfo (HWND dlg, winpt_key_t key) |
249 |
{ |
{ |
250 |
/* XXX: fill it with life. */ |
StringBuffer kinf; |
251 |
|
struct native_uid_s *u; |
252 |
|
char tmp[256]; |
253 |
|
int len; |
254 |
|
|
255 |
|
_snprintf (tmp, DIM (tmp) -1, |
256 |
|
_("pub %d/0x%s created: %s expires: %s\n\n" |
257 |
|
"Key fingerprint:\n%s\n\n"), |
258 |
|
key->ctx->subkeys->length, |
259 |
|
key->ctx->subkeys->keyid+8, |
260 |
|
get_key_created (key->ctx->subkeys->timestamp), |
261 |
|
get_expire_date (key->ctx), |
262 |
|
get_printable_fpr (key->ctx->subkeys->fpr)); |
263 |
|
kinf = tmp; |
264 |
|
for (len=0, u = key->ext->uids; u; u = u->next) { |
265 |
|
if (u->revoked) |
266 |
|
continue; |
267 |
|
if (len++ > 2) |
268 |
|
break; |
269 |
|
kinf = kinf + " \""; |
270 |
|
if (strlen (u->uid) > 128) { |
271 |
|
kinf.add (u->uid, 128); |
272 |
|
kinf += "..."; |
273 |
|
// FIXME: make sure at least the e-mail address will be shown! |
274 |
|
} |
275 |
|
else |
276 |
|
kinf += u->uid; |
277 |
|
kinf += "\"\n"; |
278 |
|
} |
279 |
|
SetDlgItemText (dlg, IDC_KEYSIGN_INFOS, kinf.getBuffer ()); |
280 |
|
} |
281 |
|
|
282 |
|
|
283 |
|
void set_gpg_auto_passphrase_cb (passphrase_cb_s *cb, const char *title); |
284 |
|
gpgme_error_t passphrase_cb (void *hook, const char *uid_hint, |
285 |
|
const char *passphrase_info, |
286 |
|
int prev_was_bad, int fd); |
287 |
|
|
288 |
|
/* Perform the actual procedure to sign the key. */ |
289 |
|
static BOOL |
290 |
|
on_click_ok (HWND dlg, winpt_key_t key) |
291 |
|
{ |
292 |
|
gpgme_key_t k; |
293 |
|
gpgme_error_t err; |
294 |
|
SYSTEMTIME st; |
295 |
|
GpgKeyEdit ke; |
296 |
|
int sig_class = 0; |
297 |
|
char keymsg[64]; |
298 |
|
int type, expires=0, idx; |
299 |
|
|
300 |
|
if (IsDlgButtonChecked (dlg, IDC_KEYSIGN_ASKLEVEL)) |
301 |
|
sig_class = dialog_box_param (glob_hinst, |
302 |
|
(LPCSTR)IDD_WINPT_SIGCLASS, dlg, |
303 |
|
sig_class_dlg_proc, (LPARAM)dlg, |
304 |
|
_("Choose Signature Class"), |
305 |
|
IDS_WINPT_SIGCLASS); |
306 |
|
type = IsDlgButtonChecked (dlg, IDC_KEYSIGN_LOCAL); |
307 |
|
if (type) |
308 |
|
type = GPG_EDITKEY_LSIGN; |
309 |
|
else |
310 |
|
type = GPG_EDITKEY_SIGN; |
311 |
|
|
312 |
|
if (reg_prefs.expert && IsDlgButtonChecked (dlg, IDC_KEYSIGN_NREV)) { |
313 |
|
type = GPG_EDITKEY_NRSIGN; |
314 |
|
if (type == GPG_EDITKEY_LSIGN) |
315 |
|
type = GPG_EDITKEY_NRLSIGN; |
316 |
|
} |
317 |
|
|
318 |
|
if (IsDlgButtonChecked (dlg, IDC_KEYSIGN_EXPSIG)) { |
319 |
|
DateTime_GetSystemtime (GetDlgItem (dlg, IDC_KEYSIGN_EXPIRES), &st); |
320 |
|
if (date_is_today (&st)) { |
321 |
|
show_balloon_msg (GetDlgItem (dlg, IDC_KEYSIGN_EXPIRES), |
322 |
|
_("You cannot select today as the expiration date."), |
323 |
|
IDI_WARNING); |
324 |
|
return TRUE; |
325 |
|
} |
326 |
|
else |
327 |
|
expires = 1; |
328 |
|
_snprintf (keymsg, DIM (keymsg)-1, "%04d-%02d-%02d", |
329 |
|
st.wYear, st.wMonth, st.wDay); |
330 |
|
} |
331 |
|
|
332 |
|
assert (key->ctx->subkeys->keyid != NULL); /* should be always true. */ |
333 |
|
ke.setKeyID (key->ctx->subkeys->keyid); |
334 |
|
|
335 |
|
// XXX: callback hangs after bad passphrase |
336 |
|
passphrase_cb_s cb; |
337 |
|
set_gpg_auto_passphrase_cb (&cb, _("Key Edit")); |
338 |
|
ke.setPassphraseCallback (passphrase_cb, (void*)&cb); |
339 |
|
|
340 |
|
HWND klist = GetDlgItem (dlg, IDC_KEYSIGN_KEYLIST); |
341 |
|
idx = SendMessage (klist, CB_GETCURSEL, 0, 0); |
342 |
|
k = (gpgme_key_t)SendDlgItemMessage (dlg, IDC_KEYSIGN_KEYLIST, |
343 |
|
CB_GETITEMDATA, (WPARAM)idx, 0); |
344 |
|
if (k != NULL) |
345 |
|
ke.setLocalUser (k); |
346 |
|
|
347 |
|
err = ke.signKey (type, sig_class, expires? keymsg : "0"); |
348 |
|
release_gpg_passphrase_cb (&cb); |
349 |
|
if (err) { |
350 |
|
msg_box (dlg, gpgme_strerror (err), _("Key Signing"), MB_ERR); |
351 |
|
return TRUE; |
352 |
|
} |
353 |
|
else if (ke.getResult () != 0) { |
354 |
|
show_balloon_msg (klist, _("This key is already signed by your key"), |
355 |
|
IDI_INFORMATION); |
356 |
|
return TRUE; |
357 |
|
} |
358 |
|
else { |
359 |
|
status_box (dlg, _("Key successfully signed."), _("Key Signing")); |
360 |
|
key->update = 1; |
361 |
|
} |
362 |
|
EndDialog (dlg, TRUE); |
363 |
|
return TRUE; |
364 |
} |
} |
365 |
|
|
366 |
|
|
369 |
keysign_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
keysign_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
370 |
{ |
{ |
371 |
static winpt_key_t key; |
static winpt_key_t key; |
372 |
GpgKeyEdit *ke; |
char buf[MAX_PATH+128+1]; |
373 |
gpgme_error_t err; |
const char *s; |
|
gpgme_key_t k; |
|
|
SYSTEMTIME st; |
|
|
HWND h; |
|
|
char keymsg[2048], pwd[256]; |
|
|
char *uid = NULL; |
|
|
const char *keyid, *s; |
|
|
int type, expires=0, idx; |
|
374 |
|
|
375 |
switch ( msg ) { |
switch (msg) { |
376 |
case WM_INITDIALOG: |
case WM_INITDIALOG: |
|
if (lparam == NULL) |
|
|
dlg_fatal_error (dlg, "Could not get dialog param."); |
|
|
#ifndef LANG_DE |
|
|
SetWindowText (dlg, _("Key Signing")); |
|
|
#endif |
|
377 |
key = (winpt_key_t) lparam; |
key = (winpt_key_t) lparam; |
378 |
s = key->ctx->uids->uid; |
if (!key) |
379 |
uid = utf8_to_wincp (s, strlen (s)); |
BUG (0); |
|
_snprintf (keymsg, sizeof keymsg -1, |
|
|
_("pub %d/%s created: %s expires: %s\n\n" |
|
|
"Primary key fingerprint: %s\n\n" |
|
|
"\t%s\n\n" |
|
|
"\nAre you really sure that you want to sign this key with YOUR key?\n"), |
|
|
key->ctx->subkeys->length, |
|
|
key->ctx->subkeys->keyid+8, |
|
|
get_key_created (key->ctx->subkeys->timestamp), |
|
|
get_expire_date (key->ctx), |
|
|
get_printable_fpr (key->ctx->subkeys->fpr), |
|
|
uid); |
|
|
free (uid); |
|
380 |
s = key->ctx->subkeys->keyid; |
s = key->ctx->subkeys->keyid; |
381 |
if (do_fill_seckeylist (dlg, s)) { |
if (do_fill_seckeylist (dlg, s)) { |
382 |
msg_box (dlg, _("No valid secret key found."), _("Key Signing"), MB_ERR); |
msg_box (dlg, _("No valid secret key found."), |
383 |
|
_("Key Signing"), MB_ERR); |
384 |
EndDialog (dlg, FALSE); |
EndDialog (dlg, FALSE); |
385 |
} |
return TRUE; |
386 |
SetDlgItemText (dlg, IDC_KEYSIGN_INFOS, keymsg); |
} |
387 |
#ifndef LANG_DE |
display_keyinfo (dlg, key); |
388 |
SetDlgItemText (dlg, IDC_KEYSIGN_LOCAL, _("Sign local only (non exportable signature)")); |
SetDlgItemText (dlg, IDC_KEYSIGN_LOCAL, _("Sign local only (non exportable signature)")); |
389 |
SetDlgItemText (dlg, IDC_KEYSIGN_EXPSIG, _("Signature expires on")); |
SetDlgItemText (dlg, IDC_KEYSIGN_EXPSIG, _("Signature expires on")); |
390 |
SetDlgItemText (dlg, IDC_KEYSIGN_NREV, _("Sign non-revocably")); |
SetDlgItemText (dlg, IDC_KEYSIGN_NREV, _("Sign non-revocably")); |
391 |
SetDlgItemText (dlg, IDC_KEYSIGN_ASKLEVEL, _("&Ask for certification level")); |
SetDlgItemText (dlg, IDC_KEYSIGN_ASKLEVEL, _("&Ask for certification level")); |
392 |
SetDlgItemText (dlg, IDC_KEYSIGN_PWDINF, _("Passphrase")); |
SetDlgItemText (dlg, IDCANCEL, _("&Cancel")); |
393 |
#endif |
SetDlgItemText (dlg, IDC_KEYSIGN_CONFIRMSIGN, _("Are you really sure that you want to sign this key with YOUR key?")); |
394 |
|
SetWindowText (dlg, _("Key Signing")); |
395 |
CheckDlgButton (dlg, IDC_KEYSIGN_LOCAL, BST_CHECKED); |
CheckDlgButton (dlg, IDC_KEYSIGN_LOCAL, BST_CHECKED); |
396 |
CheckDlgButton (dlg, IDC_KEYSIGN_EXPSIG, BST_UNCHECKED); |
CheckDlgButton (dlg, IDC_KEYSIGN_EXPSIG, BST_UNCHECKED); |
397 |
CheckDlgButton (dlg, IDC_KEYSIGN_ASKLEVEL, BST_UNCHECKED); |
CheckDlgButton (dlg, IDC_KEYSIGN_ASKLEVEL, BST_UNCHECKED); |
398 |
EnableWindow (GetDlgItem (dlg, IDC_KEYSIGN_EXPIRES), FALSE); |
EnableWindow (GetDlgItem (dlg, IDC_KEYSIGN_EXPIRES), FALSE); |
399 |
if (reg_prefs.expert == 0) |
if (reg_prefs.expert == 0) |
400 |
ShowWindow (GetDlgItem (dlg, IDC_KEYSIGN_NREV), SW_HIDE); |
ShowWindow (GetDlgItem (dlg, IDC_KEYSIGN_NREV), SW_HIDE); |
401 |
|
if (!reg_prefs.gpg.ask_cert_level) |
402 |
|
EnableWindow (GetDlgItem (dlg, IDC_KEYSIGN_ASKLEVEL), FALSE); |
403 |
|
if (!reg_prefs.gpg.ask_cert_expire) |
404 |
|
EnableWindow (GetDlgItem (dlg, IDC_KEYSIGN_EXPSIG), FALSE); |
405 |
if (key->ext && key->ext->attrib.len > 0) |
if (key->ext && key->ext->attrib.len > 0) |
406 |
EnableWindow (GetDlgItem (dlg, IDC_KEYSIGN_SHOWIMG), TRUE); |
key_load_photo (key, buf, DIM(buf)-1, NULL); |
407 |
|
CheckDlgButton (dlg, IDC_KEYSIGN_HIDE, BST_CHECKED); |
408 |
SetForegroundWindow (dlg); |
SetForegroundWindow (dlg); |
409 |
h = GetDlgItem (dlg, IDC_KEYSIGN_PASSPHRASE); |
SetFocus (GetDlgItem (dlg, IDOK)); |
|
SetFocus (h); |
|
410 |
return FALSE; |
return FALSE; |
411 |
|
|
412 |
case WM_DESTROY: |
case WM_DESTROY: |
413 |
sig_class_choice = 0; |
balloon_msg_disable (); |
414 |
|
if (key->ext && key->ext->attrib.len > 0) { |
415 |
|
get_photo_tmpname (key->ctx, buf, DIM(buf)-1); |
416 |
|
DeleteFile (buf); |
417 |
|
} |
418 |
break; |
break; |
419 |
|
|
420 |
case WM_SYSCOMMAND: |
case WM_PAINT: |
421 |
if( LOWORD( wparam ) == SC_CLOSE ) { |
if (key->ext != NULL && key->ext->attrib.len > 0) { |
422 |
SetDlgItemText( dlg, IDC_KEYSIGN_PASSPHRASE, "" ); |
POINT p; |
423 |
EndDialog( dlg, TRUE ); |
p.x = p.y = 0; |
424 |
} |
get_photo_tmpname (key->ctx, buf, DIM (buf)-1); |
425 |
return FALSE; |
if (jpg_show (GetDlgItem (dlg, IDC_SHOWPHOTO_IMG), &p, buf)) |
426 |
|
EndDialog (dlg, TRUE); |
|
case WM_COMMAND: |
|
|
if (HIWORD( wparam ) == CBN_SELCHANGE) { |
|
|
do_check_protection (dlg); |
|
|
break; |
|
427 |
} |
} |
428 |
if (HIWORD (wparam) == BN_CLICKED && LOWORD (wparam) == IDC_KEYSIGN_EXPSIG) { |
break; |
429 |
|
|
430 |
|
case WM_COMMAND: |
431 |
|
if (HIWORD (wparam) == BN_CLICKED && |
432 |
|
LOWORD (wparam) == IDC_KEYSIGN_EXPSIG) { |
433 |
int enable = IsDlgButtonChecked (dlg, IDC_KEYSIGN_EXPSIG); |
int enable = IsDlgButtonChecked (dlg, IDC_KEYSIGN_EXPSIG); |
434 |
EnableWindow (GetDlgItem (dlg, IDC_KEYSIGN_EXPIRES), enable? TRUE : FALSE); |
EnableWindow (GetDlgItem (dlg, IDC_KEYSIGN_EXPIRES), |
435 |
|
enable? TRUE : FALSE); |
436 |
} |
} |
437 |
|
|
438 |
switch( LOWORD( wparam ) ) { |
switch (LOWORD (wparam)) { |
439 |
case IDOK: |
case IDOK: |
440 |
if (IsDlgButtonChecked (dlg, IDC_KEYSIGN_ASKLEVEL)) |
balloon_msg_disable (); |
441 |
dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_SIGCLASS, dlg, |
return on_click_ok (dlg, key); |
|
sig_class_dlg_proc, (LPARAM)NULL, |
|
|
_("Choose Signature Class"), IDS_WINPT_SIGCLASS); |
|
|
type = IsDlgButtonChecked (dlg, IDC_KEYSIGN_LOCAL); |
|
|
if (type) |
|
|
type = GPG_EDITKEY_LSIGN; |
|
|
else |
|
|
type = GPG_EDITKEY_SIGN; |
|
|
|
|
|
if (reg_prefs.expert && IsDlgButtonChecked (dlg, IDC_KEYSIGN_NREV)) { |
|
|
type = GPG_EDITKEY_NRSIGN; |
|
|
if (type == GPG_EDITKEY_LSIGN) |
|
|
type = GPG_EDITKEY_NRLSIGN; |
|
|
} |
|
|
if (IsDlgButtonChecked (dlg, IDC_KEYSIGN_EXPSIG)) { |
|
|
expires = 1; |
|
|
DateTime_GetSystemtime (GetDlgItem (dlg, IDC_KEYSIGN_EXPIRES), &st); |
|
|
sprintf (keymsg, "%04d-%02d-%02d", st.wYear, st.wMonth, st.wDay); |
|
|
} |
|
|
|
|
|
/* XXX: check for --ask-cert-level and --ask-cert-expire in the gpg.conf |
|
|
if an advanced button is checked and offer to add it to the config |
|
|
file. */ |
|
|
|
|
|
GetDlgItemText( dlg, IDC_KEYSIGN_PASSPHRASE, pwd, DIM (pwd)-1); |
|
|
keyid = key->ctx->subkeys->keyid; |
|
|
if( !keyid ) { |
|
|
msg_box( dlg, _("Could not get Key ID from key."), _("Key Signing"), MB_ERR ); |
|
|
return TRUE; |
|
|
} |
|
|
ke = new GpgKeyEdit (keyid); |
|
|
if (!ke) |
|
|
BUG (NULL); |
|
|
ke->setPassphrase (pwd); |
|
|
idx = SendDlgItemMessage (dlg, IDC_KEYSIGN_KEYLIST, CB_GETCURSEL, 0, 0); |
|
|
k = (gpgme_key_t)SendDlgItemMessage (dlg, IDC_KEYSIGN_KEYLIST, |
|
|
CB_GETITEMDATA, (WPARAM)idx, 0); |
|
|
if (k) |
|
|
ke->setLocalUser (k); |
|
|
|
|
|
err = ke->signKey (type, sig_class_choice, expires? keymsg : "0"); |
|
|
memset (&pwd, 0, sizeof pwd); |
|
|
if (err) { |
|
|
delete ke; |
|
|
msg_box (dlg, gpgme_strerror (err), _("Key Signing"), MB_ERR); |
|
|
return TRUE; |
|
|
} |
|
|
if (ke->getResult () != 0) |
|
|
msg_box (dlg, _("This key is already signed by your key"), _("Key Signing"), MB_INFO); |
|
|
else { |
|
|
status_box (dlg, _("Key successfully signed."), PGM_NAME); |
|
|
key->update = 1; |
|
|
} |
|
|
delete ke; |
|
|
EndDialog (dlg, TRUE); |
|
|
return TRUE; |
|
442 |
|
|
443 |
case IDCANCEL: |
case IDCANCEL: |
444 |
EndDialog (dlg, FALSE); |
EndDialog (dlg, FALSE); |
445 |
return TRUE; |
return TRUE; |
|
|
|
|
case IDC_KEYSIGN_SHOWIMG: |
|
|
show_photo (key); |
|
|
return TRUE; |
|
446 |
} |
} |
447 |
break; |
break; |
448 |
} |
} |
449 |
|
|
450 |
return FALSE; |
return FALSE; |
451 |
} |
} |
|
|
|