1 |
/* wptKeyPropsDlg.cpp - WinPT key properties dialog |
/* wptKeyPropsDlg.cpp - WinPT key property dialog |
2 |
* Copyright (C) 2000, 2001, 2002, 2003, 2005, 2006 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. |
42 |
static int |
static int |
43 |
do_check_key (gpgme_key_t key) |
do_check_key (gpgme_key_t key) |
44 |
{ |
{ |
45 |
int invalid = 0; |
int invalid; |
46 |
|
|
47 |
invalid = key->expired; |
invalid = key->expired; |
48 |
if (!invalid) |
if (!invalid) |
78 |
|
|
79 |
/* Generate a unique temp name for the photo which |
/* Generate a unique temp name for the photo which |
80 |
depends on the dialog handle and return it. */ |
depends on the dialog handle and return it. */ |
81 |
static const char* |
const char* |
82 |
get_photo_tmpname (HWND dlg) |
get_photo_tmpname (HWND dlg) |
83 |
{ |
{ |
84 |
static char buf[MAX_PATH+128+1]; |
static char buf[MAX_PATH+128+1]; |
85 |
char name[64]; |
char name[64]; |
86 |
|
|
87 |
_snprintf (name, sizeof (name)-1, "winpt_photo_%08lX.tmp", (DWORD)dlg); |
_snprintf (name, DIM (name)-1, "winpt_photo_%08lX.tmp", (DWORD)dlg); |
88 |
get_temp_name (buf, DIM (buf)-1, name); |
get_temp_name (buf, DIM (buf)-1, name); |
89 |
return buf; |
return buf; |
90 |
} |
} |
99 |
} |
} |
100 |
|
|
101 |
|
|
102 |
|
|
103 |
|
/* Delete temporary photo file. */ |
104 |
|
void |
105 |
|
key_unload_photo (HWND dlg) |
106 |
|
{ |
107 |
|
DeleteFile (get_photo_tmpname (dlg)); |
108 |
|
} |
109 |
|
|
110 |
|
|
111 |
/* Load the photo from the key @key */ |
/* Load the photo from the key @key */ |
112 |
static int |
int |
113 |
keyprops_load_photo (HWND dlg, gpgme_key_t key, gpgme_validity_t *r_valid) |
key_load_photo (HWND dlg, gpgme_key_t key, gpgme_validity_t *r_valid) |
114 |
{ |
{ |
115 |
winpt_key_s k; |
winpt_key_s k; |
116 |
FILE *f; |
FILE *fp; |
117 |
const BYTE *img; |
const BYTE *img; |
118 |
DWORD imglen = 0; |
DWORD imglen = 0; |
119 |
int pos=0; |
int pos=0; |
124 |
imglen = k.ext->attrib.len; |
imglen = k.ext->attrib.len; |
125 |
if (img && !k.ext->attrib.validity) |
if (img && !k.ext->attrib.validity) |
126 |
get_uat_validity (key->subkeys->keyid, &k.ext->attrib.validity); |
get_uat_validity (key->subkeys->keyid, &k.ext->attrib.validity); |
127 |
*r_valid = k.ext->attrib.validity; |
if (r_valid) |
128 |
|
*r_valid = k.ext->attrib.validity; |
129 |
|
|
130 |
if (!img || !imglen) { |
if (!img || !imglen) { |
131 |
draw_nophoto_img (dlg); |
draw_nophoto_img (dlg); |
132 |
return -1; |
return -1; |
133 |
} |
} |
134 |
|
|
135 |
f = fopen (get_photo_tmpname (dlg), "wb"); |
fp = fopen (get_photo_tmpname (dlg), "wb"); |
136 |
if (f) { |
if (fp) { |
137 |
pos += 16; |
pos += 16; |
138 |
fwrite (img + pos, 1, imglen - pos, f); |
fwrite (img + pos, 1, imglen - pos, fp); |
139 |
fclose (f); |
fclose (fp); |
140 |
} |
} |
141 |
return 0; |
return 0; |
142 |
} |
} |
143 |
|
|
144 |
|
|
|
/* Display the photo in the image control in the dialog @dlg. */ |
|
|
static int |
|
|
keyprops_show_photo (HWND dlg) |
|
|
{ |
|
|
RECT r; |
|
|
POINT p; |
|
|
HWND h; |
|
|
|
|
|
h = GetDlgItem (dlg, IDC_KEYPROPS_IMG); |
|
|
GetWindowRect (h, &r); |
|
|
p.x = r.left + 5; |
|
|
p.y = r.top - 2; |
|
|
memset (&p, 0, sizeof (p)); |
|
|
PTD_jpg_show (h, &p, get_photo_tmpname (dlg)); |
|
|
|
|
|
return 0; |
|
|
} |
|
|
|
|
|
|
|
145 |
/* Return string representation of the key validity. @key. */ |
/* Return string representation of the key validity. @key. */ |
146 |
static const char* |
static const char* |
147 |
get_validity (gpgme_key_t key) |
get_validity (gpgme_key_t key) |
152 |
return _("Revoked"); |
return _("Revoked"); |
153 |
if (key->disabled) |
if (key->disabled) |
154 |
return _("Disabled"); |
return _("Disabled"); |
155 |
|
if (key->invalid) |
156 |
|
return _("Invalid"); |
157 |
return get_key_trust2 (NULL, key->uids->validity, 0, 0); |
return get_key_trust2 (NULL, key->uids->validity, 0, 0); |
158 |
} |
} |
159 |
|
|
175 |
case 8: return "AES192"; |
case 8: return "AES192"; |
176 |
case 9: return "AES256"; |
case 9: return "AES256"; |
177 |
case 10:return "Twofish"; |
case 10:return "Twofish"; |
178 |
|
default:break; |
179 |
} |
} |
180 |
return "Unknown"; |
return "Unknown"; |
181 |
} |
} |
185 |
static bool |
static bool |
186 |
check_for_desig_rev (gpgme_key_t key) |
check_for_desig_rev (gpgme_key_t key) |
187 |
{ |
{ |
188 |
winpt_key_s kk; |
winpt_key_s k; |
189 |
|
|
190 |
memset (&kk, 0, sizeof (kk)); |
memset (&k, 0, sizeof (k)); |
191 |
if (!winpt_get_pubkey (key->subkeys->keyid, &kk)) |
if (!winpt_get_pubkey (key->subkeys->keyid, &k)) |
192 |
return kk.ext->gloflags.has_desig_rev? true : false; |
return k.ext->gloflags.has_desig_rev? true : false; |
193 |
return false; |
return false; |
194 |
} |
} |
195 |
|
|
221 |
} |
} |
222 |
|
|
223 |
|
|
224 |
|
/* Return extended algorithm information. */ |
225 |
|
const char* |
226 |
|
props_get_key_algo (gpgme_key_t key, int idx) |
227 |
|
{ |
228 |
|
/* PGP calls the old RSAv3 keys 'RSA Legacy' and because this |
229 |
|
is a good method to differ between OpenPGP v4 cert-only keys |
230 |
|
and v3 RSA keys, we use the same notation. */ |
231 |
|
if (key->subkeys != NULL && strlen (key->subkeys->fpr) == 32) |
232 |
|
return "RSA Legacy"; |
233 |
|
return get_key_algo (key, idx); |
234 |
|
} |
235 |
|
|
236 |
|
|
237 |
/* Display the key information for key @k. |
/* Display the key information for key @k. |
238 |
Return value: gpgme key on success. */ |
Return value: gpgme key on success. */ |
264 |
"%s\r\n"), |
"%s\r\n"), |
265 |
get_key_type (key), |
get_key_type (key), |
266 |
k->keyid, |
k->keyid, |
267 |
get_key_algo (key, 0), |
props_get_key_algo (key, 0), |
268 |
get_key_size (key, 0), |
get_key_size (key, 0), |
269 |
get_key_created (created), |
get_key_created (created), |
270 |
get_key_expire_date (expires), |
get_key_expire_date (expires), |
298 |
SetDlgItemText (dlg, IDC_KEYPROPS_OTINF, _("Ownertrust")); |
SetDlgItemText (dlg, IDC_KEYPROPS_OTINF, _("Ownertrust")); |
299 |
|
|
300 |
display_key_info (dlg, k); |
display_key_info (dlg, k); |
301 |
if (!keyprops_load_photo (dlg, k->ctx, &valid)) { |
if (!key_load_photo (dlg, k->ctx, &valid)) { |
302 |
k->has_photo = 1; |
k->has_photo = 1; |
303 |
if (valid < GPGME_VALIDITY_MARGINAL) |
if (valid < GPGME_VALIDITY_MARGINAL) |
304 |
SetDlgItemText (dlg, IDC_KEYPROPS_IMGINF, _("Photo-ID not validated.")); |
SetDlgItemText (dlg, IDC_KEYPROPS_IMGINF, _("Photo-ID not validated.")); |
305 |
} |
} |
306 |
if (k->key_pair) |
if (k->key_pair) |
307 |
EnableWindow (GetDlgItem (dlg, IDC_KEYPROPS_CHANGE_PWD), TRUE); |
EnableWindow (GetDlgItem (dlg, IDC_KEYPROPS_CHANGE_PWD), TRUE); |
308 |
if (check_for_desig_rev (k->ctx)) |
if (check_for_desig_rev (k->ctx)) |
328 |
|
|
329 |
switch (msg) { |
switch (msg) { |
330 |
case WM_INITDIALOG: |
case WM_INITDIALOG: |
331 |
assert (lparam != NULL); |
assert (lparam != 0); |
332 |
prop = new struct prop_info_s; |
prop = new struct prop_info_s; |
333 |
prop->key = (winpt_key_t)lparam; |
prop->key = (winpt_key_t)lparam; |
334 |
SetWindowLong (dlg, GWL_USERDATA, (LONG)prop); |
SetWindowLong (dlg, GWL_USERDATA, (LONG)prop); |
336 |
return TRUE; |
return TRUE; |
337 |
|
|
338 |
case WM_DESTROY: |
case WM_DESTROY: |
339 |
remove (get_photo_tmpname (dlg)); |
key_unload_photo (dlg); |
340 |
delete prop;prop=NULL; |
delete prop;prop = NULL; |
341 |
SetWindowLong (dlg, GWL_USERDATA, 0); |
SetWindowLong (dlg, GWL_USERDATA, 0); |
342 |
break; |
break; |
343 |
|
|
344 |
case WM_PAINT: |
case WM_PAINT: |
345 |
if (prop->key->has_photo) |
/* Display the photo in the frame of the dialog @dlg. |
346 |
keyprops_show_photo (dlg); |
The coordinates are fixed to (0,0). */ |
347 |
|
if (prop->key->has_photo) { |
348 |
|
POINT p; |
349 |
|
p.x = p.y = 0; |
350 |
|
PTD_jpg_show (GetDlgItem (dlg, IDC_KEYPROPS_IMG), |
351 |
|
&p, get_photo_tmpname (dlg)); |
352 |
|
} |
353 |
break; |
break; |
354 |
|
|
355 |
case WM_COMMAND: |
case WM_COMMAND: |
356 |
switch (LOWORD (wparam)) { |
switch (LOWORD (wparam)) { |
357 |
case IDOK: |
case IDOK: |
363 |
return TRUE; |
return TRUE; |
364 |
|
|
365 |
case IDC_KEYPROPS_OT_CHANGE: |
case IDC_KEYPROPS_OT_CHANGE: |
|
if (do_check_key (prop->key->ctx)) { |
|
|
msg_box (dlg, _("The status of this key is 'revoked' or 'expired'.\n" |
|
|
"You cannot change the ownertrust of such keys."), |
|
|
_("WinPT Warning"), MB_ERR); |
|
|
return TRUE; |
|
|
} |
|
366 |
if (!prop->key->key_pair && !key_is_valid (prop->key->ctx)) { |
if (!prop->key->key_pair && !key_is_valid (prop->key->ctx)) { |
367 |
rc = msg_box (dlg, _("This is a non-valid key.\n" |
rc = msg_box (dlg, _("This is a non-valid key.\n" |
368 |
"Modifying the ownertrust has no effect on such keys.\n\n" |
"Modifying the ownertrust has no effect on such keys.\n\n" |