33 |
#include "wptVersion.h" |
#include "wptVersion.h" |
34 |
#include "wptKeyEdit.h" |
#include "wptKeyEdit.h" |
35 |
|
|
|
|
|
36 |
static void |
static void |
37 |
do_change_ownertrust (winpt_key_t k, const char *s) |
do_change_ownertrust (winpt_key_t k, const char *s) |
38 |
{ |
{ |
44 |
listview_add_sub_item (k->callback.ctl, k->callback.idx, 5, ot); |
listview_add_sub_item (k->callback.ctl, k->callback.idx, 5, ot); |
45 |
/* fixme: If we switch back from Ultimate to a lower level */ |
/* fixme: If we switch back from Ultimate to a lower level */ |
46 |
} |
} |
47 |
} /* do_change_ownertrust */ |
} |
48 |
|
|
49 |
|
|
50 |
|
/* Check that the key is not expired or revoked. */ |
51 |
static int |
static int |
52 |
do_check_key (gpgme_key_t key) |
do_check_key (gpgme_key_t key) |
53 |
{ |
{ |
56 |
if (!okay) |
if (!okay) |
57 |
okay = key->revoked; |
okay = key->revoked; |
58 |
return okay; |
return okay; |
59 |
} /* do_check_key */ |
} |
60 |
|
|
61 |
|
|
62 |
|
/* Convert a trust integer into a string representation. */ |
63 |
static const char* |
static const char* |
64 |
ownertrust_to_string (int val) |
ownertrust_to_string (int val) |
65 |
{ |
{ |
76 |
} |
} |
77 |
|
|
78 |
return inf; |
return inf; |
79 |
} /* ownertrust_to_string */ |
} |
80 |
|
|
81 |
|
|
82 |
#define PHOTO_TMPNAME "winpt_temp_photo.jpg" |
#define PHOTO_TMPNAME "winpt_temp_photo.jpg" |
83 |
|
|
84 |
|
/* Load the photo from the key @key */ |
85 |
static int |
static int |
86 |
keyprops_show_photo (HWND dlg, gpgme_key_t key) |
keyprops_load_photo (gpgme_key_t key, gpgme_validity_t *r_valid) |
87 |
{ |
{ |
88 |
RECT r; |
winpt_key_s k; |
89 |
POINT p; |
FILE *f; |
|
HWND h; |
|
90 |
const BYTE *img; |
const BYTE *img; |
91 |
DWORD imglen = 0; |
DWORD imglen = 0; |
92 |
int pos=0; |
int pos=0; |
|
winpt_key_s k; |
|
93 |
|
|
94 |
winpt_get_pubkey (key->subkeys->keyid, &k); |
winpt_get_pubkey (key->subkeys->keyid, &k); |
95 |
img = k.ext->attrib.d; |
img = k.ext->attrib.d; |
96 |
imglen = k.ext->attrib.len; |
imglen = k.ext->attrib.len; |
97 |
|
if (!k.ext->attrib.validity) |
98 |
|
get_uat_validity (key->subkeys->keyid, &k.ext->attrib.validity); |
99 |
|
*r_valid = k.ext->attrib.validity; |
100 |
|
|
101 |
if (!img || !imglen) |
if (!img || !imglen) |
102 |
return -1; |
return -1; |
103 |
FILE *f = fopen (PHOTO_TMPNAME, "wb"); |
f = fopen (PHOTO_TMPNAME, "wb"); |
104 |
if (f) { |
if (f) { |
105 |
for (pos = 0; img[pos] != 0x10; pos++) |
for (pos = 0; img[pos] != 0x10; pos++) |
106 |
; |
; |
109 |
fwrite (img, 1, imglen, f); |
fwrite (img, 1, imglen, f); |
110 |
fclose (f); |
fclose (f); |
111 |
} |
} |
112 |
|
return 0; |
113 |
|
} |
114 |
|
|
115 |
|
|
116 |
|
/* Display the photo in the image control in the dialog @dlg. */ |
117 |
|
static int |
118 |
|
keyprops_show_photo (HWND dlg) |
119 |
|
{ |
120 |
|
RECT r; |
121 |
|
POINT p; |
122 |
|
HWND h; |
123 |
|
|
124 |
h = GetDlgItem (dlg, IDC_KEYPROPS_IMG); |
h = GetDlgItem (dlg, IDC_KEYPROPS_IMG); |
125 |
GetWindowRect (h, &r); |
GetWindowRect (h, &r); |
127 |
p.y = r.top - 2; |
p.y = r.top - 2; |
128 |
memset (&p, 0, sizeof (p)); |
memset (&p, 0, sizeof (p)); |
129 |
PTD_jpg_show (h, &p, PHOTO_TMPNAME); |
PTD_jpg_show (h, &p, PHOTO_TMPNAME); |
130 |
unlink (PHOTO_TMPNAME); |
|
|
|
|
131 |
return 0; |
return 0; |
132 |
} |
} |
133 |
|
|
139 |
int val; |
int val; |
140 |
val = key->expired; |
val = key->expired; |
141 |
if (val) |
if (val) |
142 |
return "Expired"; |
return _("Expired"); |
143 |
val = key->revoked; |
val = key->revoked; |
144 |
if (val) |
if (val) |
145 |
return "Revoked"; |
return _("Revoked"); |
146 |
return get_key_trust2 (NULL, key->uids->validity, 0, 0); |
return get_key_trust2 (NULL, key->uids->validity, 0, 0); |
147 |
} |
} |
148 |
|
|
183 |
} |
} |
184 |
|
|
185 |
|
|
186 |
|
/* Print information (name) of the smart card. */ |
187 |
|
static const char* |
188 |
|
get_card_type (winpt_key_t k) |
189 |
|
{ |
190 |
|
static char buf[64]; |
191 |
|
|
192 |
|
if (!k->ext->card_type) |
193 |
|
return ""; |
194 |
|
_snprintf (buf, sizeof (buf)-1, _("Card-Type: %s\r\n"), k->ext->card_type); |
195 |
|
return buf; |
196 |
|
} |
197 |
|
|
198 |
|
|
199 |
|
/* Display the key information for key @k. |
200 |
|
Return value: gpgme key on success. */ |
201 |
|
static void |
202 |
|
display_key_info (HWND dlg, winpt_key_t k, gpgme_key_t *r_key) |
203 |
|
{ |
204 |
|
struct winpt_key_s k2; |
205 |
|
gpgme_key_t sk, key; |
206 |
|
char info[512]; |
207 |
|
const char *inf; |
208 |
|
u32 created, expires; |
209 |
|
|
210 |
|
memset (&k2, 0, sizeof (k2)); |
211 |
|
if (k->key_pair) |
212 |
|
winpt_get_seckey (k->keyid, &k2); |
213 |
|
else |
214 |
|
winpt_get_pubkey (k->keyid, &k2); |
215 |
|
sk = k2.ctx; |
216 |
|
if (sk) |
217 |
|
k->is_protected = k2.is_protected; |
218 |
|
if (get_pubkey (k->keyid, &key)) |
219 |
|
BUG (0); |
220 |
|
created = key->subkeys->timestamp; |
221 |
|
expires = key->subkeys->expires; |
222 |
|
_snprintf (info, DIM (info)-1, |
223 |
|
_("Type: %s\r\n" |
224 |
|
"Key ID: %s\r\n" |
225 |
|
"Algorithm: %s\r\n" |
226 |
|
"Size: %s\r\n" |
227 |
|
"Created: %s\r\n" |
228 |
|
"Expires: %s\r\n" |
229 |
|
"Validity: %s\r\n" |
230 |
|
"Cipher: %s\r\n" |
231 |
|
"%s\r\n"), |
232 |
|
get_key_type (key), |
233 |
|
k->keyid, |
234 |
|
get_key_algo (key, 0), |
235 |
|
get_key_size (key, 0), |
236 |
|
get_key_created (created), |
237 |
|
get_key_expire_date (expires), |
238 |
|
get_validity (key), |
239 |
|
get_pref_cipher (&k2), |
240 |
|
get_card_type (&k2)); |
241 |
|
|
242 |
|
SetDlgItemText (dlg, IDC_KEYPROPS_INFO, info); |
243 |
|
SetDlgItemText (dlg, IDC_KEYPROPS_FPR, get_key_fpr (key)); |
244 |
|
inf = ownertrust_to_string (key->owner_trust); |
245 |
|
SetDlgItemText (dlg, IDC_KEYPROPS_OT, inf); |
246 |
|
|
247 |
|
*r_key = key; |
248 |
|
} |
249 |
|
|
250 |
|
|
251 |
/* Dialog box procedure to show the key properties. */ |
/* Dialog box procedure to show the key properties. */ |
252 |
BOOL CALLBACK |
BOOL CALLBACK |
253 |
keyprops_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
keyprops_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
254 |
{ |
{ |
255 |
static winpt_key_t k; |
static winpt_key_t k; |
256 |
static gpgme_key_t key, sk; |
static gpgme_key_t key; |
257 |
static int photo_done = 0; |
static int has_photo = 0; |
258 |
struct winpt_key_s k2; |
gpgme_validity_t valid; |
259 |
refresh_cache_s rcs = {0}; |
refresh_cache_s rcs = {0}; |
260 |
const char *inf; |
const char *inf; |
261 |
char info[2048]; |
int cancel = 0; |
|
u32 created, expires; |
|
|
int ot, cancel = 0; |
|
262 |
int rc; |
int rc; |
263 |
|
|
264 |
switch (msg) { |
switch (msg) { |
265 |
case WM_INITDIALOG: |
case WM_INITDIALOG: |
266 |
if (!lparam) |
if (!lparam) |
267 |
dlg_fatal_error( dlg, "Could not get dialog param!" ); |
dlg_fatal_error (dlg, "Could not get dialog param!"); |
268 |
k = (winpt_key_t)lparam; |
k = (winpt_key_t)lparam; |
269 |
#ifndef LANG_DE |
#ifndef LANG_DE |
270 |
SetWindowText( dlg, _("Key Properties") ); |
SetWindowText (dlg, _("Key Properties")); |
271 |
SetDlgItemText (dlg, IDC_KEYPROPS_OT_CHANGE, _("&Change")); |
SetDlgItemText (dlg, IDC_KEYPROPS_OT_CHANGE, _("&Change")); |
272 |
SetDlgItemText (dlg, IDC_KEYPROPS_REVOKERS, _("&Revokers")); |
SetDlgItemText (dlg, IDC_KEYPROPS_REVOKERS, _("&Revokers")); |
273 |
SetDlgItemText (dlg, IDC_KEYPROPS_CHANGE_PWD, _("Change &Passwd")); |
SetDlgItemText (dlg, IDC_KEYPROPS_CHANGE_PWD, _("Change &Passwd")); |
274 |
|
SetDlgItemText (dlg, IDC_KEYPROPS_OTINF, _("Ownertrust")); |
275 |
#endif |
#endif |
276 |
|
|
277 |
photo_done = 0; |
display_key_info (dlg, k, &key); |
278 |
memset (&k2, 0, sizeof (k2)); |
if (!keyprops_load_photo (key, &valid)) { |
279 |
if (k->key_pair) |
has_photo = 1; |
280 |
winpt_get_seckey (k->keyid, &k2); |
if (valid != 0 && valid < GPGME_VALIDITY_MARGINAL) |
281 |
else |
SetDlgItemText (dlg, IDC_KEYPROPS_IMGINF, _("Photo-ID not checked.")); |
282 |
winpt_get_pubkey (k->keyid, &k2); |
} |
|
sk = k2.ctx; |
|
|
if (sk) |
|
|
k->is_protected = k2.is_protected; |
|
|
if (get_pubkey (k->keyid, &key)) |
|
|
BUG (0); |
|
|
created = key->subkeys->timestamp; |
|
|
expires = key->subkeys->expires; |
|
|
_snprintf (info, DIM (info)-1, |
|
|
"Type: %s\r\n" |
|
|
"Key ID: %s\r\n" |
|
|
"Algorithm: %s\r\n" |
|
|
"Size: %s\r\n" |
|
|
"Created: %s\r\n" |
|
|
"Expires: %s\r\n" |
|
|
"Validity: %s\r\n" |
|
|
"Cipher: %s\r\n", |
|
|
get_key_type (key), |
|
|
k->keyid, |
|
|
get_key_algo (key, 0), |
|
|
get_key_size (key, 0), |
|
|
get_key_created (created), |
|
|
get_key_expire_date (expires), |
|
|
get_validity (key), |
|
|
get_pref_cipher (&k2)); |
|
|
SetDlgItemText (dlg, IDC_KEYPROPS_INFO, info); |
|
|
SetDlgItemText (dlg, IDC_KEYPROPS_FPR, get_key_fpr (key)); |
|
|
ot = gpgme_key_get_ulong_attr( key, GPGME_ATTR_OTRUST, NULL, 0 ); |
|
|
inf = ownertrust_to_string (ot); |
|
|
SetDlgItemText( dlg, IDC_KEYPROPS_OT, inf ); |
|
283 |
if (k->key_pair) |
if (k->key_pair) |
284 |
EnableWindow( GetDlgItem( dlg, IDC_KEYPROPS_CHANGE_PWD ), TRUE ); |
EnableWindow (GetDlgItem (dlg, IDC_KEYPROPS_CHANGE_PWD), TRUE); |
285 |
if (check_for_desig_rev (key)) |
if (check_for_desig_rev (key)) |
286 |
EnableWindow( GetDlgItem( dlg, IDC_KEYPROPS_REVOKERS ), TRUE ); |
EnableWindow (GetDlgItem (dlg, IDC_KEYPROPS_REVOKERS), TRUE); |
287 |
center_window (dlg, NULL); |
center_window (dlg, NULL); |
288 |
SetForegroundWindow (dlg); |
SetForegroundWindow (dlg); |
289 |
return TRUE; |
return TRUE; |
290 |
|
|
291 |
|
case WM_DESTROY: |
292 |
|
has_photo = 0; |
293 |
|
unlink (PHOTO_TMPNAME); |
294 |
|
break; |
295 |
|
|
296 |
case WM_PAINT: |
case WM_PAINT: |
297 |
if (photo_done == 0) { |
if (has_photo) |
298 |
photo_done = 1; |
keyprops_show_photo (dlg); |
|
keyprops_show_photo (dlg, key); |
|
|
} |
|
299 |
break; |
break; |
300 |
|
|
301 |
case WM_SYSCOMMAND: |
case WM_SYSCOMMAND: |
302 |
if( LOWORD( wparam ) == SC_CLOSE ) |
if (LOWORD (wparam) == SC_CLOSE) |
303 |
EndDialog( dlg, TRUE ); |
EndDialog (dlg, TRUE); |
304 |
return FALSE; |
return FALSE; |
305 |
|
|
306 |
case WM_COMMAND: |
case WM_COMMAND: |
307 |
switch( LOWORD( wparam ) ) { |
switch (LOWORD (wparam)) { |
308 |
case IDOK: |
case IDOK: |
309 |
EndDialog( dlg, TRUE ); |
EndDialog (dlg, TRUE); |
310 |
return TRUE; |
return TRUE; |
311 |
|
|
312 |
case IDC_KEYPROPS_OT_CHANGE: |
case IDC_KEYPROPS_OT_CHANGE: |
313 |
if( do_check_key( key ) ) { |
if (do_check_key (key)) { |
314 |
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" |
315 |
"You cannot change the ownertrust of such keys."), |
"You cannot change the ownertrust of such keys."), |
316 |
_("WinPT Warning"), MB_ERR ); |
_("WinPT Warning"), MB_ERR); |
317 |
return FALSE; |
return TRUE; |
318 |
} |
} |
319 |
if( !k->key_pair && key->uids->validity < 3 ) { |
if( !k->key_pair && key->uids->validity < 3 ) { |
320 |
rc = msg_box( dlg, _("This is a non-valid key.\n" |
rc = msg_box( dlg, _("This is a non-valid key.\n" |
322 |
"Do you really want to continue?"), |
"Do you really want to continue?"), |
323 |
_("WinPT Warning"), MB_ICONWARNING|MB_YESNO ); |
_("WinPT Warning"), MB_ICONWARNING|MB_YESNO ); |
324 |
if (rc == IDNO) |
if (rc == IDNO) |
325 |
return FALSE; |
return TRUE; |
326 |
} |
} |
327 |
GetDlgItemText( dlg, IDC_KEYPROPS_OT, info, sizeof info -1 ); |
//GetDlgItemText (dlg, IDC_KEYPROPS_OT, info, sizeof info -1); |
|
|
|
|
|
|
328 |
dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_KEYEDIT_OWNERTRUST, |
dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_KEYEDIT_OWNERTRUST, |
329 |
dlg, (DLGPROC)keyedit_ownertrust_dlg_proc, |
dlg, (DLGPROC)keyedit_ownertrust_dlg_proc, |
330 |
(LPARAM)k, _("Change Ownertrust"), |
(LPARAM)k, _("Change Ownertrust"), |
337 |
inf = ownertrust_to_string (k->callback.new_val); |
inf = ownertrust_to_string (k->callback.new_val); |
338 |
do_change_ownertrust (k, inf); |
do_change_ownertrust (k, inf); |
339 |
SetDlgItemText (dlg, IDC_KEYPROPS_OT, inf); |
SetDlgItemText (dlg, IDC_KEYPROPS_OT, inf); |
340 |
msg_box (dlg, _("Ownertrust successfully changed."), _("GnuPG Status"), MB_OK); |
msg_box (dlg, _("Ownertrust successfully changed."), |
341 |
|
_("GnuPG Status"), MB_OK); |
342 |
|
|
343 |
/* reload only the keylist */ |
/* reload only the keylist */ |
344 |
rcs.kr_reload = 1; rcs.kr_update = 1; |
rcs.kr_reload = 1; rcs.kr_update = 1; |
345 |
rcs.tr_update = 0; |
rcs.tr_update = 0; |
346 |
DialogBoxParam( glob_hinst, (LPCSTR)IDD_WINPT_KEYCACHE, dlg, |
DialogBoxParam (glob_hinst, (LPCSTR)IDD_WINPT_KEYCACHE, dlg, |
347 |
keycache_dlg_proc, (LPARAM)&rcs ); |
keycache_dlg_proc, (LPARAM)&rcs); |
|
/* XXX: old code!? |
|
|
get_seckey (k->keyid, &sk); |
|
|
if (get_pubkey (k->keyid, &key)) |
|
|
BUG (0); |
|
|
*/ |
|
348 |
return TRUE; |
return TRUE; |
349 |
|
|
350 |
case IDC_KEYPROPS_CHANGE_PWD: |
case IDC_KEYPROPS_CHANGE_PWD: |
351 |
keyedit_change_passwd (k, dlg); |
keyedit_change_passwd (k, dlg); |
352 |
return TRUE; |
return TRUE; |
353 |
|
|
354 |
case IDC_KEYPROPS_REVOKERS: |
case IDC_KEYPROPS_REVOKERS: |
355 |
dialog_box_param (glob_hinst, (LPCTSTR)IDD_WINPT_KEYREVOKERS, dlg, |
dialog_box_param (glob_hinst, (LPCTSTR)IDD_WINPT_KEYREVOKERS, dlg, |
356 |
key_revokers_dlg_proc, (LPARAM)key, _("Key Revokers"), |
key_revokers_dlg_proc, (LPARAM)key, _("Key Revokers"), |
357 |
IDS_WINPT_KEY_REVOKERS); |
IDS_WINPT_KEY_REVOKERS); |
361 |
|
|
362 |
return FALSE; |
return FALSE; |
363 |
} |
} |
|
|
|