22 |
#endif |
#endif |
23 |
|
|
24 |
#include <windows.h> |
#include <windows.h> |
25 |
|
#include <assert.h> |
26 |
|
|
27 |
#include "resource.h" |
#include "resource.h" |
28 |
#include "wptErrors.h" |
#include "wptErrors.h" |
42 |
static int |
static int |
43 |
do_check_key (gpgme_key_t key) |
do_check_key (gpgme_key_t key) |
44 |
{ |
{ |
45 |
int okay = 0; |
int invalid = 0; |
46 |
okay = key->expired; |
|
47 |
if (!okay) |
invalid = key->expired; |
48 |
okay = key->revoked; |
if (!invalid) |
49 |
return okay; |
invalid = key->revoked; |
50 |
|
return invalid; |
51 |
} |
} |
52 |
|
|
53 |
|
|
113 |
BUG (0); |
BUG (0); |
114 |
img = k.ext->attrib.d; |
img = k.ext->attrib.d; |
115 |
imglen = k.ext->attrib.len; |
imglen = k.ext->attrib.len; |
116 |
if (!k.ext->attrib.validity) |
if (img && !k.ext->attrib.validity) |
117 |
get_uat_validity (key->subkeys->keyid, &k.ext->attrib.validity); |
get_uat_validity (key->subkeys->keyid, &k.ext->attrib.validity); |
118 |
*r_valid = k.ext->attrib.validity; |
*r_valid = k.ext->attrib.validity; |
119 |
|
|
191 |
static bool |
static bool |
192 |
check_for_desig_rev (gpgme_key_t key) |
check_for_desig_rev (gpgme_key_t key) |
193 |
{ |
{ |
194 |
winpt_key_s k; |
winpt_key_s kk; |
195 |
memset (&k, 0, sizeof (k)); |
|
196 |
if (!winpt_get_pubkey (key->subkeys->keyid, &k)) |
memset (&kk, 0, sizeof (kk)); |
197 |
return k.ext->gloflags.has_desig_rev? true : false; |
if (!winpt_get_pubkey (key->subkeys->keyid, &kk)) |
198 |
|
return kk.ext->gloflags.has_desig_rev? true : false; |
199 |
return false; |
return false; |
200 |
} |
} |
201 |
|
|
208 |
|
|
209 |
if (!k->ext || !k->ext->card_type) |
if (!k->ext || !k->ext->card_type) |
210 |
return ""; |
return ""; |
211 |
_snprintf (buf, sizeof (buf)-1, _("Card-Type: %s\r\n"), k->ext->card_type); |
_snprintf (buf, DIM (buf)-1, _("Card-Type: %s\r\n"), k->ext->card_type); |
212 |
return buf; |
return buf; |
213 |
} |
} |
214 |
|
|
215 |
|
|
216 |
/* Return 1 if at least one user-ID is valid. */ |
/* Return 1 if at least one user-ID is valid. */ |
217 |
static int |
static int |
218 |
key_is_valid (gpgme_key_t k) |
key_is_valid (gpgme_key_t key) |
219 |
{ |
{ |
220 |
gpgme_user_id_t u; |
gpgme_user_id_t u; |
221 |
|
|
222 |
for (u=k->uids; u; u=u->next) { |
for (u=key->uids; u; u=u->next) { |
223 |
if (u->validity >= GPGME_VALIDITY_MARGINAL) |
if (u->validity >= GPGME_VALIDITY_MARGINAL) |
224 |
return 1; |
return 1; |
225 |
} |
} |
240 |
DWORD created, expires; |
DWORD created, expires; |
241 |
|
|
242 |
gpg_keycache_update_attr (k->ext, KC_ATTR_PREFSYM, 0); |
gpg_keycache_update_attr (k->ext, KC_ATTR_PREFSYM, 0); |
243 |
memset (&sk, 0, sizeof (sk)); |
memset (&sk, 0, sizeof (sk)); |
244 |
if (k->key_pair && !winpt_get_seckey (k->keyid, &sk)) |
if (k->key_pair && !winpt_get_seckey (k->keyid, &sk)) |
245 |
k->is_protected = sk.is_protected; |
k->is_protected = sk.is_protected; |
246 |
key = k->ext->key; |
key = k->ext->key; |
273 |
} |
} |
274 |
|
|
275 |
|
|
276 |
|
/* Context to store associated data of the dialog. */ |
277 |
|
struct prop_info_s { |
278 |
|
winpt_key_t key; |
279 |
|
}; |
280 |
|
|
281 |
|
|
282 |
|
static void |
283 |
|
on_init_dialog (HWND dlg, WPARAM wparam, LPARAM lparam) |
284 |
|
{ |
285 |
|
gpgme_validity_t valid; |
286 |
|
|
287 |
|
winpt_key_t k = (winpt_key_t)lparam; |
288 |
|
SetWindowText (dlg, _("Key Properties")); |
289 |
|
SetDlgItemText (dlg, IDC_KEYPROPS_OT_CHANGE, _("&Change")); |
290 |
|
SetDlgItemText (dlg, IDC_KEYPROPS_REVOKERS, _("&Revokers")); |
291 |
|
SetDlgItemText (dlg, IDC_KEYPROPS_CHANGE_PWD, _("Change &Password")); |
292 |
|
SetDlgItemText (dlg, IDC_KEYPROPS_OTINF, _("Ownertrust")); |
293 |
|
|
294 |
|
display_key_info (dlg, k); |
295 |
|
if (!keyprops_load_photo (dlg, k->ctx, &valid)) { |
296 |
|
k->has_photo = 1; |
297 |
|
if (valid < GPGME_VALIDITY_MARGINAL) |
298 |
|
SetDlgItemText (dlg, IDC_KEYPROPS_IMGINF, _("Photo-ID not validated.")); |
299 |
|
} |
300 |
|
if (k->key_pair) |
301 |
|
EnableWindow (GetDlgItem (dlg, IDC_KEYPROPS_CHANGE_PWD), TRUE); |
302 |
|
if (check_for_desig_rev (k->ctx)) |
303 |
|
EnableWindow (GetDlgItem (dlg, IDC_KEYPROPS_REVOKERS), TRUE); |
304 |
|
if (do_check_key (k->ctx)) |
305 |
|
EnableWindow (GetDlgItem (dlg, IDC_KEYPROPS_OT_CHANGE), FALSE); |
306 |
|
center_window (dlg, NULL); |
307 |
|
SetForegroundWindow (dlg); |
308 |
|
} |
309 |
|
|
310 |
|
|
311 |
/* Dialog box procedure to show the key properties. */ |
/* Dialog box procedure to show the key properties. */ |
312 |
BOOL CALLBACK |
BOOL CALLBACK |
313 |
keyprops_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
keyprops_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
314 |
{ |
{ |
315 |
static winpt_key_t k = NULL; |
struct prop_info_s *prop = NULL; |
|
gpgme_validity_t valid; |
|
316 |
const char *inf; |
const char *inf; |
317 |
int rc; |
int rc; |
318 |
|
|
319 |
/* XXX: static variable (k) prevent that the dialog can |
if (msg != WM_INITDIALOG && |
320 |
be opened twice. */ |
(prop = (prop_info_s*)GetWindowLong (dlg, GWL_USERDATA)) == NULL) |
321 |
|
return FALSE; |
322 |
|
|
323 |
switch (msg) { |
switch (msg) { |
324 |
case WM_INITDIALOG: |
case WM_INITDIALOG: |
325 |
if (!lparam) |
assert (lparam != NULL); |
326 |
dlg_fatal_error (dlg, "Could not get dialog param!"); |
prop = new struct prop_info_s; |
327 |
k = (winpt_key_t)lparam; |
prop->key = (winpt_key_t)lparam; |
328 |
SetWindowText (dlg, _("Key Properties")); |
SetWindowLong (dlg, GWL_USERDATA, (LONG)prop); |
329 |
SetDlgItemText (dlg, IDC_KEYPROPS_OT_CHANGE, _("&Change")); |
on_init_dialog (dlg, wparam, lparam); |
|
SetDlgItemText (dlg, IDC_KEYPROPS_REVOKERS, _("&Revokers")); |
|
|
SetDlgItemText (dlg, IDC_KEYPROPS_CHANGE_PWD, _("Change &Password")); |
|
|
SetDlgItemText (dlg, IDC_KEYPROPS_OTINF, _("Ownertrust")); |
|
|
|
|
|
display_key_info (dlg, k); |
|
|
if (!keyprops_load_photo (dlg, k->ctx, &valid)) { |
|
|
k->has_photo = 1; |
|
|
if (valid < GPGME_VALIDITY_MARGINAL) |
|
|
SetDlgItemText (dlg, IDC_KEYPROPS_IMGINF, _("Photo-ID not validated.")); |
|
|
} |
|
|
if (k->key_pair) |
|
|
EnableWindow (GetDlgItem (dlg, IDC_KEYPROPS_CHANGE_PWD), TRUE); |
|
|
if (check_for_desig_rev (k->ctx)) |
|
|
EnableWindow (GetDlgItem (dlg, IDC_KEYPROPS_REVOKERS), TRUE); |
|
|
if (k->ctx->revoked || k->ctx->expired) |
|
|
EnableWindow (GetDlgItem (dlg, IDC_KEYPROPS_OT_CHANGE), FALSE); |
|
|
center_window (dlg, NULL); |
|
|
SetForegroundWindow (dlg); |
|
330 |
return TRUE; |
return TRUE; |
331 |
|
|
332 |
case WM_DESTROY: |
case WM_DESTROY: |
333 |
remove (get_photo_tmpname (dlg)); |
remove (get_photo_tmpname (dlg)); |
334 |
|
delete prop;prop=NULL; |
335 |
|
SetWindowLong (dlg, GWL_USERDATA, 0); |
336 |
break; |
break; |
337 |
|
|
338 |
case WM_PAINT: |
case WM_PAINT: |
339 |
if (k->has_photo) |
if (prop->key->has_photo) |
340 |
keyprops_show_photo (dlg); |
keyprops_show_photo (dlg); |
341 |
break; |
break; |
|
|
|
|
case WM_SYSCOMMAND: |
|
|
if (LOWORD (wparam) == SC_CLOSE) |
|
|
EndDialog (dlg, FALSE); |
|
|
return FALSE; |
|
342 |
|
|
343 |
case WM_COMMAND: |
case WM_COMMAND: |
344 |
switch (LOWORD (wparam)) { |
switch (LOWORD (wparam)) { |
351 |
return TRUE; |
return TRUE; |
352 |
|
|
353 |
case IDC_KEYPROPS_OT_CHANGE: |
case IDC_KEYPROPS_OT_CHANGE: |
354 |
if (do_check_key (k->ctx)) { |
if (do_check_key (prop->key->ctx)) { |
355 |
msg_box (dlg, _("The status of this key is 'revoked' or 'expired'.\n" |
msg_box (dlg, _("The status of this key is 'revoked' or 'expired'.\n" |
356 |
"You cannot change the ownertrust of such keys."), |
"You cannot change the ownertrust of such keys."), |
357 |
_("WinPT Warning"), MB_ERR); |
_("WinPT Warning"), MB_ERR); |
358 |
return TRUE; |
return TRUE; |
359 |
} |
} |
360 |
if (!k->key_pair && !key_is_valid (k->ctx)) { |
if (!prop->key->key_pair && !key_is_valid (prop->key->ctx)) { |
361 |
rc = msg_box (dlg, _("This is a non-valid key.\n" |
rc = msg_box (dlg, _("This is a non-valid key.\n" |
362 |
"Modifying the ownertrust has no effect on such keys.\n\n" |
"Modifying the ownertrust has no effect on such keys.\n\n" |
363 |
"Do you really want to continue?"), |
"Do you really want to continue?"), |
368 |
rc = dialog_box_param (glob_hinst, |
rc = dialog_box_param (glob_hinst, |
369 |
(LPCSTR)IDD_WINPT_KEYEDIT_OWNERTRUST, |
(LPCSTR)IDD_WINPT_KEYEDIT_OWNERTRUST, |
370 |
dlg, keyedit_ownertrust_dlg_proc, |
dlg, keyedit_ownertrust_dlg_proc, |
371 |
(LPARAM)k, _("Change Ownertrust"), |
(LPARAM)prop->key, _("Change Ownertrust"), |
372 |
IDS_WINPT_KEYEDIT_OWNERTRUST); |
IDS_WINPT_KEYEDIT_OWNERTRUST); |
373 |
if (rc == FALSE) /* Cancel */ |
if (rc == FALSE) /* Cancel */ |
374 |
return TRUE; |
return TRUE; |
375 |
|
|
376 |
inf = ownertrust_to_string (k->callback.new_val, k->key_pair); |
inf = ownertrust_to_string (prop->key->callback.new_val, |
377 |
|
prop->key->key_pair); |
378 |
SetDlgItemText (dlg, IDC_KEYPROPS_OT, inf); |
SetDlgItemText (dlg, IDC_KEYPROPS_OT, inf); |
379 |
msg_box (dlg, _("Ownertrust successfully changed."), |
msg_box (dlg, _("Ownertrust successfully changed."), |
380 |
_("GnuPG Status"), MB_OK); |
_("GnuPG Status"), MB_OK); |
381 |
k->update = 1; |
prop->key->update = 1; |
382 |
return TRUE; |
return TRUE; |
383 |
|
|
384 |
case IDC_KEYPROPS_CHANGE_PWD: |
case IDC_KEYPROPS_CHANGE_PWD: |
385 |
keyedit_change_passwd (k, dlg); |
keyedit_change_passwd (prop->key, dlg); |
386 |
return TRUE; |
return TRUE; |
387 |
|
|
388 |
case IDC_KEYPROPS_REVOKERS: |
case IDC_KEYPROPS_REVOKERS: |
389 |
k->update = dialog_box_param ( |
prop->key->update = dialog_box_param (glob_hinst, |
390 |
glob_hinst, (LPCTSTR)IDD_WINPT_KEYREVOKERS, dlg, |
(LPCTSTR)IDD_WINPT_KEYREVOKERS, dlg, |
391 |
key_revokers_dlg_proc, (LPARAM)k, |
key_revokers_dlg_proc, (LPARAM)prop->key, |
392 |
_("Key Revokers"), IDS_WINPT_KEY_REVOKERS); |
_("Key Revokers"), |
393 |
|
IDS_WINPT_KEY_REVOKERS); |
394 |
|
UpdateWindow (dlg); |
395 |
break; |
break; |
396 |
} |
} |
397 |
} |
} |