1 |
/* wptKeyPropsDlg.cpp - WinPT key properties dialog |
/* wptKeyPropsDlg.cpp - WinPT key properties dialog |
2 |
* Copyright (C) 2000, 2001, 2002, 2003, 2005 Timo Schulz |
* Copyright (C) 2000, 2001, 2002, 2003, 2005, 2006 Timo Schulz |
3 |
* |
* |
4 |
* This file is part of WinPT. |
* This file is part of WinPT. |
5 |
* |
* |
17 |
* along with WinPT; if not, write to the Free Software Foundation, |
* along with WinPT; if not, write to the Free Software Foundation, |
18 |
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
19 |
*/ |
*/ |
|
|
|
20 |
#ifdef HAVE_CONFIG_H |
#ifdef HAVE_CONFIG_H |
21 |
#include <config.h> |
#include <config.h> |
22 |
#endif |
#endif |
51 |
|
|
52 |
/* Convert a trust integer into a string representation. */ |
/* Convert a trust integer into a string representation. */ |
53 |
static const char* |
static const char* |
54 |
ownertrust_to_string (int val) |
ownertrust_to_string (int val, bool is_keypair) |
55 |
{ |
{ |
56 |
const char *inf; |
const char *inf; |
57 |
int id = val; |
int id = val; |
62 |
case 3: inf = _("I trust marginally"); break; |
case 3: inf = _("I trust marginally"); break; |
63 |
case 4: inf = _("I trust fully"); break; |
case 4: inf = _("I trust fully"); break; |
64 |
case 5: |
case 5: |
65 |
case 6: inf = _("I trust ultimately"); break; |
case 6: |
66 |
|
if (is_keypair) |
67 |
|
inf = _("I trust ultimately (implicit)"); |
68 |
|
else |
69 |
|
inf = _("I trust ultimately"); break; |
70 |
default:inf = _("Unknown"); break; |
default:inf = _("Unknown"); break; |
71 |
} |
} |
72 |
|
|
79 |
static const char* |
static const char* |
80 |
get_photo_tmpname (HWND dlg) |
get_photo_tmpname (HWND dlg) |
81 |
{ |
{ |
82 |
static char buf[64]; |
static char buf[MAX_PATH+128+1]; |
83 |
|
char name[64]; |
84 |
|
|
85 |
_snprintf (buf, sizeof (buf)-1, "winpt_photo_%08lX.tmp", (DWORD)dlg); |
_snprintf (name, sizeof (name)-1, "winpt_photo_%08lX.tmp", (DWORD)dlg); |
86 |
|
get_temp_name (buf, DIM (buf), name); |
87 |
return buf; |
return buf; |
88 |
} |
} |
89 |
|
|
90 |
|
|
91 |
|
static void |
92 |
|
draw_nophoto_img (HWND dlg) |
93 |
|
{ |
94 |
|
/*.. |
95 |
|
n = DrawText (hdc, "No Photo-ID", -1, &r, DT_LEFT); |
96 |
|
..*/ |
97 |
|
} |
98 |
|
|
99 |
|
|
100 |
/* Load the photo from the key @key */ |
/* Load the photo from the key @key */ |
101 |
static int |
static int |
102 |
keyprops_load_photo (HWND dlg, gpgme_key_t key, gpgme_validity_t *r_valid) |
keyprops_load_photo (HWND dlg, gpgme_key_t key, gpgme_validity_t *r_valid) |
114 |
get_uat_validity (key->subkeys->keyid, &k.ext->attrib.validity); |
get_uat_validity (key->subkeys->keyid, &k.ext->attrib.validity); |
115 |
*r_valid = k.ext->attrib.validity; |
*r_valid = k.ext->attrib.validity; |
116 |
|
|
117 |
if (!img || !imglen) |
if (!img || !imglen) { |
118 |
|
draw_nophoto_img (dlg); |
119 |
return -1; |
return -1; |
120 |
|
} |
121 |
|
|
122 |
f = fopen (get_photo_tmpname (dlg), "wb"); |
f = fopen (get_photo_tmpname (dlg), "wb"); |
123 |
if (f) { |
if (f) { |
124 |
for (pos = 0; img[pos] != 0x10; pos++) |
//for (pos = 0; img[pos] != 0x10; pos++) |
125 |
; |
// ; |
126 |
pos += 16; |
pos += 16; |
127 |
fwrite (img + pos, 1, imglen - pos, f); |
fwrite (img + pos, 1, imglen - pos, f); |
|
fwrite (img, 1, imglen, f); |
|
128 |
fclose (f); |
fclose (f); |
129 |
} |
} |
130 |
return 0; |
return 0; |
172 |
static const char* |
static const char* |
173 |
get_pref_cipher (winpt_key_t k) |
get_pref_cipher (winpt_key_t k) |
174 |
{ |
{ |
|
const char *sym_prefs=NULL; |
|
|
|
|
175 |
if (k->is_v3) |
if (k->is_v3) |
176 |
return "IDEA"; |
return "IDEA"; |
177 |
if (!k->ext->sym_prefs) |
if (!k->ext->sym_prefs) |
224 |
gpgme_key_t sk, key; |
gpgme_key_t sk, key; |
225 |
char info[512]; |
char info[512]; |
226 |
const char *inf; |
const char *inf; |
227 |
u32 created, expires; |
u32 created, expires; |
228 |
|
|
229 |
memset (&k2, 0, sizeof (k2)); |
memset (&k2, 0, sizeof (k2)); |
230 |
if (k->key_pair) |
if (k->key_pair) |
231 |
winpt_get_seckey (k->keyid, &k2); |
winpt_get_seckey (k->keyid, &k2); |
232 |
else |
else |
233 |
winpt_get_pubkey (k->keyid, &k2); |
winpt_get_pubkey (k->keyid, &k2); |
234 |
sk = k2.ctx; |
sk = k2.ctx; |
235 |
if (sk) |
if (sk) |
236 |
k->is_protected = k2.is_protected; |
k->is_protected = k2.is_protected; |
237 |
if (get_pubkey (k->keyid, &key)) |
if (get_pubkey (k->keyid, &key)) |
242 |
_("Type: %s\r\n" |
_("Type: %s\r\n" |
243 |
"Key ID: %s\r\n" |
"Key ID: %s\r\n" |
244 |
"Algorithm: %s\r\n" |
"Algorithm: %s\r\n" |
245 |
"Size: %s\r\n" |
"Size: %s bits\r\n" |
246 |
"Created: %s\r\n" |
"Created: %s\r\n" |
247 |
"Expires: %s\r\n" |
"Expires: %s\r\n" |
248 |
"Validity: %s\r\n" |
"Validity: %s\r\n" |
260 |
|
|
261 |
SetDlgItemText (dlg, IDC_KEYPROPS_INFO, info); |
SetDlgItemText (dlg, IDC_KEYPROPS_INFO, info); |
262 |
SetDlgItemText (dlg, IDC_KEYPROPS_FPR, get_key_fpr (key)); |
SetDlgItemText (dlg, IDC_KEYPROPS_FPR, get_key_fpr (key)); |
263 |
inf = ownertrust_to_string (key->owner_trust); |
inf = ownertrust_to_string (key->owner_trust, k->key_pair); |
264 |
SetDlgItemText (dlg, IDC_KEYPROPS_OT, inf); |
SetDlgItemText (dlg, IDC_KEYPROPS_OT, inf); |
265 |
|
|
266 |
*r_key = key; |
*r_key = key; |
276 |
gpgme_validity_t valid; |
gpgme_validity_t valid; |
277 |
refresh_cache_s rcs = {0}; |
refresh_cache_s rcs = {0}; |
278 |
const char *inf; |
const char *inf; |
279 |
|
int cancel = 0; |
280 |
int rc; |
int rc; |
281 |
|
|
282 |
/* XXX: static variable (k) prevent that the dialog can |
/* XXX: static variable (k) prevent that the dialog can |
286 |
if (!lparam) |
if (!lparam) |
287 |
dlg_fatal_error (dlg, "Could not get dialog param!"); |
dlg_fatal_error (dlg, "Could not get dialog param!"); |
288 |
k = (winpt_key_t)lparam; |
k = (winpt_key_t)lparam; |
|
#ifndef LANG_DE |
|
289 |
SetWindowText (dlg, _("Key Properties")); |
SetWindowText (dlg, _("Key Properties")); |
290 |
SetDlgItemText (dlg, IDC_KEYPROPS_OT_CHANGE, _("&Change")); |
SetDlgItemText (dlg, IDC_KEYPROPS_OT_CHANGE, _("&Change")); |
291 |
SetDlgItemText (dlg, IDC_KEYPROPS_REVOKERS, _("&Revokers")); |
SetDlgItemText (dlg, IDC_KEYPROPS_REVOKERS, _("&Revokers")); |
292 |
SetDlgItemText (dlg, IDC_KEYPROPS_CHANGE_PWD, _("Change &Passwd")); |
SetDlgItemText (dlg, IDC_KEYPROPS_CHANGE_PWD, _("Change &Password")); |
293 |
SetDlgItemText (dlg, IDC_KEYPROPS_OTINF, _("Ownertrust")); |
SetDlgItemText (dlg, IDC_KEYPROPS_OTINF, _("Ownertrust")); |
|
#endif |
|
294 |
|
|
295 |
display_key_info (dlg, k, &key); |
display_key_info (dlg, k, &key); |
296 |
if (!keyprops_load_photo (dlg, key, &valid)) { |
if (!keyprops_load_photo (dlg, key, &valid)) { |
302 |
EnableWindow (GetDlgItem (dlg, IDC_KEYPROPS_CHANGE_PWD), TRUE); |
EnableWindow (GetDlgItem (dlg, IDC_KEYPROPS_CHANGE_PWD), TRUE); |
303 |
if (check_for_desig_rev (key)) |
if (check_for_desig_rev (key)) |
304 |
EnableWindow (GetDlgItem (dlg, IDC_KEYPROPS_REVOKERS), TRUE); |
EnableWindow (GetDlgItem (dlg, IDC_KEYPROPS_REVOKERS), TRUE); |
305 |
|
if (key->revoked || key->expired) |
306 |
|
EnableWindow (GetDlgItem (dlg, IDC_KEYPROPS_OT_CHANGE), FALSE); |
307 |
center_window (dlg, NULL); |
center_window (dlg, NULL); |
308 |
SetForegroundWindow (dlg); |
SetForegroundWindow (dlg); |
309 |
return TRUE; |
return TRUE; |
319 |
|
|
320 |
case WM_SYSCOMMAND: |
case WM_SYSCOMMAND: |
321 |
if (LOWORD (wparam) == SC_CLOSE) |
if (LOWORD (wparam) == SC_CLOSE) |
322 |
EndDialog (dlg, TRUE); |
EndDialog (dlg, FALSE); |
323 |
return FALSE; |
return FALSE; |
324 |
|
|
325 |
case WM_COMMAND: |
case WM_COMMAND: |
327 |
case IDOK: |
case IDOK: |
328 |
EndDialog (dlg, TRUE); |
EndDialog (dlg, TRUE); |
329 |
return TRUE; |
return TRUE; |
330 |
|
|
331 |
|
case IDCANCEL: |
332 |
|
EndDialog (dlg, FALSE); |
333 |
|
return TRUE; |
334 |
|
|
335 |
case IDC_KEYPROPS_OT_CHANGE: |
case IDC_KEYPROPS_OT_CHANGE: |
336 |
if (do_check_key (key)) { |
if (do_check_key (key)) { |
339 |
_("WinPT Warning"), MB_ERR); |
_("WinPT Warning"), MB_ERR); |
340 |
return TRUE; |
return TRUE; |
341 |
} |
} |
342 |
if( !k->key_pair && key->uids->validity < 3 ) { |
if (!k->key_pair && key->uids->validity < 3) { |
343 |
rc = msg_box( dlg, _("This is a non-valid key.\n" |
rc = msg_box (dlg, _("This is a non-valid key.\n" |
344 |
"Modifying the ownertrust has no effect on such keys.\n\n" |
"Modifying the ownertrust has no effect on such keys.\n\n" |
345 |
"Do you really want to continue?"), |
"Do you really want to continue?"), |
346 |
_("WinPT Warning"), MB_ICONWARNING|MB_YESNO ); |
_("WinPT Warning"), MB_ICONWARNING|MB_YESNO); |
347 |
if (rc == IDNO) |
if (rc == IDNO) |
348 |
return TRUE; |
return TRUE; |
349 |
} |
} |
350 |
//GetDlgItemText (dlg, IDC_KEYPROPS_OT, info, sizeof info -1); |
rc = dialog_box_param (glob_hinst, |
351 |
dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_KEYEDIT_OWNERTRUST, |
(LPCSTR)IDD_WINPT_KEYEDIT_OWNERTRUST, |
352 |
dlg, (DLGPROC)keyedit_ownertrust_dlg_proc, |
dlg, keyedit_ownertrust_dlg_proc, |
353 |
(LPARAM)k, _("Change Ownertrust"), |
(LPARAM)k, _("Change Ownertrust"), |
354 |
IDS_WINPT_KEYEDIT_OWNERTRUST); |
IDS_WINPT_KEYEDIT_OWNERTRUST); |
355 |
if (k->callback.new_val == -1) { /* Cancel */ |
if (rc == FALSE) /* Cancel */ |
356 |
EndDialog (dlg, FALSE); |
return TRUE; |
|
break; |
|
|
} |
|
357 |
|
|
358 |
inf = ownertrust_to_string (k->callback.new_val); |
inf = ownertrust_to_string (k->callback.new_val, k->key_pair); |
359 |
SetDlgItemText (dlg, IDC_KEYPROPS_OT, inf); |
SetDlgItemText (dlg, IDC_KEYPROPS_OT, inf); |
360 |
msg_box (dlg, _("Ownertrust successfully changed."), |
msg_box (dlg, _("Ownertrust successfully changed."), |
361 |
_("GnuPG Status"), MB_OK); |
_("GnuPG Status"), MB_OK); |
362 |
|
k->update = 1; |
|
/* XXX: modified ownertrust values can effect the entire |
|
|
WoT so we reload the cache. But this is very slow. */ |
|
|
memset (&rcs, 0, sizeof (rcs)); |
|
|
rcs.kr_reload = 1; rcs.kr_update = 1; /* reload only keylist */ |
|
|
DialogBoxParam (glob_hinst, (LPCSTR)IDD_WINPT_KEYCACHE, dlg, |
|
|
keycache_dlg_proc, (LPARAM)&rcs); |
|
363 |
return TRUE; |
return TRUE; |
364 |
|
|
365 |
case IDC_KEYPROPS_CHANGE_PWD: |
case IDC_KEYPROPS_CHANGE_PWD: |
367 |
return TRUE; |
return TRUE; |
368 |
|
|
369 |
case IDC_KEYPROPS_REVOKERS: |
case IDC_KEYPROPS_REVOKERS: |
370 |
dialog_box_param (glob_hinst, (LPCTSTR)IDD_WINPT_KEYREVOKERS, dlg, |
k->update = dialog_box_param ( |
371 |
key_revokers_dlg_proc, (LPARAM)key, |
glob_hinst, (LPCTSTR)IDD_WINPT_KEYREVOKERS, dlg, |
372 |
_("Key Revokers"), IDS_WINPT_KEY_REVOKERS); |
key_revokers_dlg_proc, (LPARAM)key, |
373 |
|
_("Key Revokers"), IDS_WINPT_KEY_REVOKERS); |
374 |
break; |
break; |
375 |
} |
} |
376 |
} |
} |