1 |
/* wptKeyPropsDlg.cpp - WinPT key properties dialog |
/* wptKeyPropsDlg.cpp - WinPT key property 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 |
* |
* |
6 |
* WinPT is free software; you can redistribute it and/or modify |
* WinPT is free software; you can redistribute it and/or modify |
7 |
* it under the terms of the GNU General Public License as published by |
* it under the terms of the GNU General Public License as published by |
8 |
* the Free Software Foundation; either version 2 of the License, or |
* the Free Software Foundation; either version 2 of the License, or |
9 |
* (at your option) any later version. |
* (at your option) any later version. |
10 |
* |
* |
11 |
* WinPT is distributed in the hope that it will be useful, |
* WinPT is distributed in the hope that it will be useful, |
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. |
15 |
* |
* |
16 |
* You should have received a copy of the GNU General Public License |
* You should have received a copy of the GNU General Public License |
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 |
21 |
#include <windows.h> |
#include <config.h> |
22 |
|
#endif |
23 |
#include "../resource.h" |
|
24 |
#include "wptErrors.h" |
#include <windows.h> |
25 |
#include "wptGPG.h" |
#include <assert.h> |
26 |
#include "wptCommonCtl.h" |
|
27 |
#include "wptContext.h" /* for passphrase_s */ |
#include "resource.h" |
28 |
#include "wptNLS.h" |
#include "wptErrors.h" |
29 |
#include "wptDlgs.h" |
#include "wptGPG.h" |
30 |
#include "wptTypes.h" |
#include "wptCommonCtl.h" |
31 |
#include "wptKeylist.h" |
#include "wptContext.h" /* for passphrase_s */ |
32 |
#include "wptW32API.h" |
#include "wptNLS.h" |
33 |
#include "wptVersion.h" |
#include "wptDlgs.h" |
34 |
#include "wptKeyEdit.h" |
#include "wptTypes.h" |
35 |
|
#include "wptKeylist.h" |
36 |
int keyedit_ownertrust_get_val (void); |
#include "wptW32API.h" |
37 |
|
#include "wptVersion.h" |
38 |
|
#include "wptKeyEdit.h" |
39 |
static void |
|
40 |
do_change_ownertrust (winpt_key_t k, const char *s) |
|
41 |
{ |
/* Check that the key is not expired or revoked. */ |
42 |
char ot[64]; |
static int |
43 |
|
do_check_key (gpgme_key_t key) |
44 |
if( strstr( s, "ultimate" ) ) { |
{ |
45 |
listview_get_item_text (k->callback.ctl, k->callback.idx, 5, ot, DIM (ot)-1); |
int invalid; |
46 |
strcpy (ot, "Ultimate"); |
|
47 |
listview_add_sub_item (k->callback.ctl, k->callback.idx, 5, ot); |
invalid = key->expired; |
48 |
/* fixme: If we switch back from Ultimate to a lower level */ |
if (!invalid) |
49 |
} |
invalid = key->revoked; |
50 |
} /* do_change_ownertrust */ |
return invalid; |
51 |
|
} |
52 |
|
|
53 |
static int |
|
54 |
do_check_key (gpgme_key_t key) |
/* Convert a trust integer into a string representation. */ |
55 |
{ |
static const char* |
56 |
int okay = 0; |
ownertrust_to_string (int val, bool is_keypair) |
57 |
okay = gpgme_key_get_ulong_attr (key, GPGME_ATTR_KEY_EXPIRED, NULL, 0); |
{ |
58 |
if (!okay) |
const char *inf; |
59 |
okay = gpgme_key_get_ulong_attr (key, GPGME_ATTR_KEY_REVOKED, NULL, 0); |
int id = val; |
60 |
return okay; |
|
61 |
} /* do_check_key */ |
switch (id) { |
62 |
|
case 1: inf = _("Don't know"); break; |
63 |
|
case 2: inf = _("I do NOT trust"); break; |
64 |
static const char* |
case 3: inf = _("I trust marginally"); break; |
65 |
ownertrust_to_string (gpgme_editkey_t ctx, int val) |
case 4: inf = _("I trust fully"); break; |
66 |
{ |
case 5: |
67 |
const char * inf; |
case 6: |
68 |
int id; |
if (is_keypair) |
69 |
|
inf = _("I trust ultimately (implicit)"); |
70 |
if (ctx) |
else |
71 |
id = keyedit_ownertrust_get_val (); |
inf = _("I trust ultimately"); break; |
72 |
else if (!ctx && val) |
default:inf = _("Unknown"); break; |
73 |
id = val; |
} |
74 |
switch (id) { |
|
75 |
case 1: inf = _("Don't know"); break; |
return inf; |
76 |
case 2: inf = _("I do NOT trust"); break; |
} |
77 |
case 3: inf = _("I trust marginally"); break; |
|
78 |
case 4: inf = _("I trust fully"); break; |
|
79 |
case 5: |
/* Generate a unique temp name for the photo which |
80 |
case 6: inf = _("I trust ultimately"); break; |
depends on the dialog handle and return it. */ |
81 |
default:inf = _("Unknown"); break; |
const char* |
82 |
} |
get_photo_tmpname (HWND dlg) |
83 |
|
{ |
84 |
return inf; |
static char buf[MAX_PATH+128+1]; |
85 |
} /* ownertrust_to_string */ |
char name[64]; |
86 |
|
|
87 |
|
_snprintf (name, DIM (name)-1, "winpt_photo_%08lX.tmp", (DWORD)dlg); |
88 |
#define PHOTO_TMPNAME "winpt_temp_photo.jpg" |
get_temp_name (buf, DIM (buf)-1, name); |
89 |
|
return buf; |
90 |
static int |
} |
91 |
keyprops_show_photo (HWND dlg, gpgme_key_t key) |
|
92 |
{ |
|
93 |
RECT r; |
static void |
94 |
POINT p; |
draw_nophoto_img (HWND dlg) |
95 |
HWND h; |
{ |
96 |
const BYTE *img; |
/*.. |
97 |
DWORD imglen = 0; |
n = DrawText (hdc, "No Photo-ID", -1, &r, DT_LEFT); |
98 |
int pos=0; |
..*/ |
99 |
|
} |
100 |
img = (const byte *)gpgme_key_get_string_attr (key, GPGME_ATTR_PHOTO, |
|
101 |
(void **)&imglen, 0); |
|
102 |
if (!img || !imglen) |
|
103 |
return -1; |
/* Delete temporary photo file. */ |
104 |
FILE *f = fopen (PHOTO_TMPNAME, "wb"); |
void |
105 |
if (f) { |
key_unload_photo (HWND dlg) |
106 |
for (pos = 0; img[pos] != 0x10; pos++) |
{ |
107 |
; |
DeleteFile (get_photo_tmpname (dlg)); |
108 |
pos += 16; |
} |
109 |
fwrite (img + pos, 1, imglen - pos, f); |
|
110 |
fwrite (img, 1, imglen, f); |
|
111 |
fclose (f); |
/* Load the photo from the key @key */ |
112 |
} |
int |
113 |
|
key_load_photo (HWND dlg, gpgme_key_t key, gpgme_validity_t *r_valid) |
114 |
h = GetDlgItem (dlg, IDC_KEYPROPS_IMG); |
{ |
115 |
GetWindowRect (h, &r); |
winpt_key_s k; |
116 |
p.x = r.left + 5; |
FILE *fp; |
117 |
p.y = r.top - 2; |
const BYTE *img; |
118 |
memset (&p, 0, sizeof (p)); |
DWORD imglen; |
119 |
PTD_jpg_show (h, &p, PHOTO_TMPNAME); |
|
120 |
unlink (PHOTO_TMPNAME); |
if (winpt_get_pubkey (key->subkeys->keyid, &k)) |
121 |
|
BUG (0); |
122 |
return 0; |
img = k.ext->attrib.d; |
123 |
} |
imglen = k.ext->attrib.len; |
124 |
|
if (img && !k.ext->attrib.validity) |
125 |
|
get_uat_validity (key->subkeys->keyid, &k.ext->attrib.validity); |
126 |
static const char* |
if (r_valid) |
127 |
get_validity (gpgme_key_t key) |
*r_valid = k.ext->attrib.validity; |
128 |
{ |
|
129 |
int val; |
if (!img || !imglen) { |
130 |
val = gpgme_key_get_ulong_attr (key, GPGME_ATTR_KEY_EXPIRED, NULL, 0); |
draw_nophoto_img (dlg); |
131 |
if (val) |
return -1; |
132 |
return "Expired"; |
} |
133 |
val = gpgme_key_get_ulong_attr( key, GPGME_ATTR_KEY_REVOKED, NULL, 0 ); |
|
134 |
if (val) |
fp = fopen (get_photo_tmpname (dlg), "wb"); |
135 |
return "Revoked"; |
if (fp) { |
136 |
val = gpgme_key_get_ulong_attr (key, GPGME_ATTR_VALIDITY, NULL, 0); |
const int pos = 16; |
137 |
return gpgme_key_expand_attr (GPGME_ATTR_VALIDITY, val); |
fwrite (img + pos, 1, imglen - pos, fp); |
138 |
} |
fclose (fp); |
139 |
|
} |
140 |
|
return 0; |
141 |
BOOL CALLBACK |
} |
142 |
keyprops_dlg_proc( HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam ) |
|
143 |
{ |
|
144 |
static winpt_key_t k; |
/* Return string representation of the key validity. @key. */ |
145 |
static gpgme_key_t key, sk; |
static const char* |
146 |
static int photo_done = 0; |
get_validity (gpgme_key_t key) |
147 |
gpgme_editkey_t ek; |
{ |
148 |
gpgme_ctx_t ctx; |
if (key->expired) |
149 |
gpgme_error_t ec; |
return _("Expired"); |
150 |
refresh_cache_s rcs = {0}; |
if (key->revoked) |
151 |
const char *inf; |
return _("Revoked"); |
152 |
const char * sym_prefs; |
if (key->disabled) |
153 |
char info[2048], dummy_symprefs[] = {0x01, 0x00}; |
return _("Disabled"); |
154 |
u32 created, expires; |
if (key->invalid) |
155 |
int ot, cancel = 0; |
return _("Invalid"); |
156 |
int rc; |
return get_key_trust2 (NULL, key->uids->validity, 0, 0); |
157 |
|
} |
158 |
switch (msg) { |
|
159 |
case WM_INITDIALOG: |
|
160 |
if (!lparam) |
/* Return the preferred sym. algorithm from @key as a string. */ |
161 |
dlg_fatal_error( dlg, "Could not get dialog param!" ); |
static const char* |
162 |
k = (winpt_key_t)lparam; |
get_pref_cipher (winpt_key_t k) |
163 |
#ifndef LANG_DE |
{ |
164 |
SetWindowText( dlg, _("Key Properties") ); |
if (k->is_v3) |
165 |
SetDlgItemText (dlg, IDC_KEYPROPS_OT_CHANGE, _("&Change")); |
return "IDEA"; |
166 |
SetDlgItemText (dlg, IDC_KEYPROPS_REVOKERS, _("&Revokers")); |
if (!k->ext || !k->ext->sym_prefs) |
167 |
SetDlgItemText (dlg, IDC_KEYPROPS_CHANGE_PWD, _("Change &Passwd")); |
return "3DES"; |
168 |
#endif |
switch (*k->ext->sym_prefs) { |
169 |
|
case 1: return "IDEA"; |
170 |
photo_done = 0; |
case 2: return "3DES"; |
171 |
get_seckey (k->keyid, &sk); |
case 3: return "CAST5"; |
172 |
if (sk) |
case 4: return "Blowfish"; |
173 |
k->is_protected = gpgme_key_get_ulong_attr( sk, GPGME_ATTR_IS_PROTECTED, NULL, 0 ); |
case 7: return "AES128"; |
174 |
if (get_pubkey (k->keyid, &key)) |
case 8: return "AES192"; |
175 |
BUG (0); |
case 9: return "AES256"; |
176 |
created = gpgme_key_get_ulong_attr( key, GPGME_ATTR_CREATED, NULL, 0 ); |
case 10:return "Twofish"; |
177 |
expires = gpgme_key_get_ulong_attr( key, GPGME_ATTR_EXPIRES, NULL, 0 ); |
default:break; |
178 |
sym_prefs = gpgme_key_get_string_attr( key, GPGME_ATTR_KEY_SYMPREFS, NULL, 0 ); |
} |
179 |
if (!sym_prefs) |
return "Unknown"; |
180 |
sym_prefs = dummy_symprefs; |
} |
181 |
_snprintf (info, sizeof info -1, |
|
182 |
"Type: %s\r\n" |
|
183 |
"Key ID: %s\r\n" |
/* Return true if the key has designated revokers. */ |
184 |
"Algorithm: %s\r\n" |
static bool |
185 |
"Size: %s\r\n" |
check_for_desig_rev (gpgme_key_t key) |
186 |
"Created: %s\r\n" |
{ |
187 |
"Expires: %s\r\n" |
winpt_key_s k; |
188 |
"Validity: %s\r\n" |
|
189 |
"Cipher: %s\r\n", |
memset (&k, 0, sizeof (k)); |
190 |
get_key_type( key ), |
if (!winpt_get_pubkey (key->subkeys->keyid, &k)) |
191 |
k->keyid, |
return k.ext->gloflags.has_desig_rev? true : false; |
192 |
get_key_algo( key, 0 ), |
return false; |
193 |
get_key_size( key, 0 ), |
} |
194 |
get_key_created( created ), |
|
195 |
get_key_expire_date( expires ), |
|
196 |
get_validity (key), |
/* Print information (name) of the smart card. */ |
197 |
gpgme_key_expand_attr( GPGME_ATTR_KEY_SYMPREFS, *sym_prefs ) ); |
static const char* |
198 |
SetDlgItemText( dlg, IDC_KEYPROPS_INFO, info ); |
get_card_type (winpt_key_t k) |
199 |
SetDlgItemText( dlg, IDC_KEYPROPS_FPR, get_key_fpr( key ) ); |
{ |
200 |
ot = gpgme_key_get_ulong_attr( key, GPGME_ATTR_OTRUST, NULL, 0 ); |
static char buf[64]; |
201 |
inf = ownertrust_to_string( NULL, ot ); |
|
202 |
SetDlgItemText( dlg, IDC_KEYPROPS_OT, inf ); |
if (!k->ext || !k->ext->card_type) |
203 |
if( k->key_pair ) |
return ""; |
204 |
EnableWindow( GetDlgItem( dlg, IDC_KEYPROPS_CHANGE_PWD ), TRUE ); |
_snprintf (buf, DIM (buf)-1, _("Card-Type: %s\r\n"), k->ext->card_type); |
205 |
if( gpgme_key_count_items( key, GPGME_ATTR_REVKEY_FPR ) ) |
return buf; |
206 |
EnableWindow( GetDlgItem( dlg, IDC_KEYPROPS_REVOKERS ), TRUE ); |
} |
207 |
center_window (dlg); |
|
208 |
SetForegroundWindow (dlg); |
|
209 |
return TRUE; |
/* Return 1 if at least one user-ID is valid. */ |
210 |
|
static int |
211 |
case WM_PAINT: |
key_is_valid (gpgme_key_t key) |
212 |
if (photo_done == 0) { |
{ |
213 |
photo_done = 1; |
gpgme_user_id_t u; |
214 |
keyprops_show_photo (dlg, key); |
|
215 |
} |
for (u=key->uids; u; u=u->next) { |
216 |
break; |
if (u->validity >= GPGME_VALIDITY_MARGINAL) |
217 |
|
return 1; |
218 |
case WM_SYSCOMMAND: |
} |
219 |
if( LOWORD( wparam ) == SC_CLOSE ) |
return 0; |
220 |
EndDialog( dlg, TRUE ); |
} |
221 |
return FALSE; |
|
222 |
|
|
223 |
case WM_COMMAND: |
/* Return extended algorithm information. */ |
224 |
switch( LOWORD( wparam ) ) { |
const char* |
225 |
case IDOK: |
props_get_key_algo (gpgme_key_t key, int idx) |
226 |
EndDialog( dlg, TRUE ); |
{ |
227 |
return TRUE; |
/* PGP calls the old RSAv3 keys 'RSA Legacy' and because this |
228 |
|
is a good method to differ between OpenPGP v4 cert-only keys |
229 |
case IDC_KEYPROPS_OT_CHANGE: |
and v3 RSA keys, we use the same notation. */ |
230 |
if( do_check_key( key ) ) { |
if (key->subkeys != NULL && strlen (key->subkeys->fpr) == 32) |
231 |
msg_box( dlg, _("The status of this key is 'revoked' or 'expired'.\n" |
return "RSA Legacy"; |
232 |
"You cannot change the ownertrust of such keys."), |
return get_key_algo (key, idx); |
233 |
_("WinPT Warning"), MB_ERR ); |
} |
234 |
return FALSE; |
|
235 |
} |
|
236 |
if( !k->key_pair && gpgme_key_get_ulong_attr( key, GPGME_ATTR_VALIDITY, NULL, 0 ) < 3 ) { |
/* Display the key information for key @k. |
237 |
rc = msg_box( dlg, _("This is a non-valid key.\n" |
Return value: gpgme key on success. */ |
238 |
"Modifying the ownertrust has no effect on such keys.\n" |
static void |
239 |
"Do you really want to continue?"), |
display_key_info (HWND dlg, winpt_key_t k) |
240 |
_("WinPT Warning"), MB_ICONWARNING|MB_YESNO ); |
{ |
241 |
if (rc == IDNO) |
gpgme_key_t key; |
242 |
return FALSE; |
struct winpt_key_s sk; |
243 |
} |
char info[512]; |
244 |
GetDlgItemText( dlg, IDC_KEYPROPS_OT, info, sizeof info -1 ); |
const char *inf; |
245 |
gpgme_editkey_new( &ek ); |
DWORD created, expires; |
246 |
gpgme_editkey_is_secret( ek, k->key_pair ); |
|
247 |
dialog_box_param( glob_hinst, (LPCSTR)IDD_WINPT_KEYEDIT_OWNERTRUST, |
gpg_keycache_update_attr (k->ext, KC_ATTR_PREFSYM, 0); |
248 |
dlg, (DLGPROC)keyedit_ownertrust_dlg_proc, |
memset (&sk, 0, sizeof (sk)); |
249 |
(LPARAM)ek, _("Change Ownertrust"), |
if (k->key_pair && !winpt_get_seckey (k->keyid, &sk)) |
250 |
IDS_WINPT_KEYEDIT_OWNERTRUST ); |
k->is_protected = sk.is_protected; |
251 |
if (!gpgme_editkey_is_valid (ek)) |
key = k->ext->key; |
252 |
return FALSE; |
created = key->subkeys->timestamp; |
253 |
ec = gpgme_new (&ctx); |
expires = key->subkeys->expires; |
254 |
if (ec) |
_snprintf (info, DIM (info)-1, |
255 |
BUG (0); |
_("Type: %s\r\n" |
256 |
gpgme_set_edit_ctx( ctx, ek, GPGME_EDITKEY_TRUST ); |
"Key ID: 0x%s\r\n" |
257 |
ec = gpgme_op_editkey( ctx, k->keyid ); |
"Algorithm: %s\r\n" |
258 |
gpgme_editkey_release( ek ); |
"Size: %s bits\r\n" |
259 |
gpgme_release( ctx ); |
"Created: %s\r\n" |
260 |
if( ec ) { |
"Expires: %s\r\n" |
261 |
msg_box( dlg, gpgme_strerror( ec ), _("Ownertrust"), MB_ERR ); |
"Validity: %s\r\n" |
262 |
return FALSE; |
"Cipher: %s\r\n" |
263 |
} |
"%s\r\n"), |
264 |
inf = ownertrust_to_string (ek, 0); |
get_key_type (key), |
265 |
k->callback.new_val = keyedit_ownertrust_get_val (); |
k->keyid, |
266 |
do_change_ownertrust (k, inf); |
props_get_key_algo (key, 0), |
267 |
SetDlgItemText (dlg, IDC_KEYPROPS_OT, inf); |
get_key_size (key, 0), |
268 |
msg_box (dlg, _("Ownertrust successfully changed."), _("GnuPG Status"), MB_OK); |
get_key_created (created), |
269 |
|
get_key_expire_date (expires), |
270 |
/* reload only the keylist */ |
get_validity (key), |
271 |
rcs.kr_reload = 1; rcs.kr_update = 1; |
get_pref_cipher (k), |
272 |
rcs.tr_update = 0; |
get_card_type (&sk)); |
273 |
DialogBoxParam( glob_hinst, (LPCSTR)IDD_WINPT_KEYCACHE, dlg, |
|
274 |
keycache_dlg_proc, (LPARAM)&rcs ); |
SetDlgItemText (dlg, IDC_KEYPROPS_INFO, info); |
275 |
get_seckey (k->keyid, &sk); |
SetDlgItemText (dlg, IDC_KEYPROPS_FPR, get_key_fpr (key)); |
276 |
if (get_pubkey (k->keyid, &key)) |
inf = ownertrust_to_string (key->owner_trust, k->key_pair); |
277 |
BUG (0); |
SetDlgItemText (dlg, IDC_KEYPROPS_OT, inf); |
278 |
return TRUE; |
} |
279 |
|
|
280 |
case IDC_KEYPROPS_CHANGE_PWD: |
|
281 |
keyedit_change_passwd (k, dlg); |
/* Context to store associated data of the dialog. */ |
282 |
return TRUE; |
struct prop_info_s { |
283 |
|
winpt_key_t key; |
284 |
case IDC_KEYPROPS_REVOKERS: |
}; |
285 |
dialog_box_param( glob_hinst, (LPCTSTR)IDD_WINPT_KEYREVOKERS, dlg, |
|
286 |
key_revokers_dlg_proc, (LPARAM)key, _("Key Revokers"), |
|
287 |
IDS_WINPT_KEY_REVOKERS ); |
static void |
288 |
break; |
on_init_dialog (HWND dlg, WPARAM wparam, LPARAM lparam) |
289 |
} |
{ |
290 |
} |
gpgme_validity_t valid; |
291 |
|
|
292 |
return FALSE; |
winpt_key_t k = (winpt_key_t)lparam; |
293 |
} /* keyprops_dlg_proc */ |
assert (k != NULL); |
294 |
|
SetWindowText (dlg, _("Key Properties")); |
295 |
|
SetDlgItemText (dlg, IDC_KEYPROPS_OT_CHANGE, _("&Change")); |
296 |
|
SetDlgItemText (dlg, IDC_KEYPROPS_REVOKERS, _("&Revokers")); |
297 |
|
SetDlgItemText (dlg, IDC_KEYPROPS_CHANGE_PWD, _("Change &Password")); |
298 |
|
SetDlgItemText (dlg, IDC_KEYPROPS_OTINF, _("Ownertrust")); |
299 |
|
|
300 |
|
display_key_info (dlg, k); |
301 |
|
if (!key_load_photo (dlg, k->ctx, &valid)) { |
302 |
|
k->has_photo = 1; |
303 |
|
if (valid < GPGME_VALIDITY_MARGINAL) |
304 |
|
SetDlgItemText (dlg, IDC_KEYPROPS_IMGINF, _("Photo-ID not validated.")); |
305 |
|
} |
306 |
|
if (k->key_pair) |
307 |
|
EnableWindow (GetDlgItem (dlg, IDC_KEYPROPS_CHANGE_PWD), TRUE); |
308 |
|
if (check_for_desig_rev (k->ctx)) |
309 |
|
EnableWindow (GetDlgItem (dlg, IDC_KEYPROPS_REVOKERS), TRUE); |
310 |
|
if (do_check_key (k->ctx)) |
311 |
|
EnableWindow (GetDlgItem (dlg, IDC_KEYPROPS_OT_CHANGE), FALSE); |
312 |
|
center_window (dlg, NULL); |
313 |
|
SetForegroundWindow (dlg); |
314 |
|
} |
315 |
|
|
316 |
|
|
317 |
|
/* Dialog box procedure to show the key properties. */ |
318 |
|
BOOL CALLBACK |
319 |
|
keyprops_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
320 |
|
{ |
321 |
|
struct prop_info_s *prop = NULL; |
322 |
|
const char *inf; |
323 |
|
int rc; |
324 |
|
|
325 |
|
if (msg != WM_INITDIALOG && |
326 |
|
(prop = (prop_info_s*)GetWindowLong (dlg, GWL_USERDATA)) == NULL) |
327 |
|
return FALSE; |
328 |
|
|
329 |
|
switch (msg) { |
330 |
|
case WM_INITDIALOG: |
331 |
|
assert (lparam != 0); |
332 |
|
prop = new struct prop_info_s; |
333 |
|
prop->key = (winpt_key_t)lparam; |
334 |
|
SetWindowLong (dlg, GWL_USERDATA, (LONG)prop); |
335 |
|
on_init_dialog (dlg, wparam, lparam); |
336 |
|
return TRUE; |
337 |
|
|
338 |
|
case WM_DESTROY: |
339 |
|
key_unload_photo (dlg); |
340 |
|
delete prop;prop = NULL; |
341 |
|
SetWindowLong (dlg, GWL_USERDATA, 0); |
342 |
|
break; |
343 |
|
|
344 |
|
case WM_PAINT: |
345 |
|
/* Display the photo in the frame of the dialog @dlg. |
346 |
|
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; |
354 |
|
|
355 |
|
case WM_COMMAND: |
356 |
|
switch (LOWORD (wparam)) { |
357 |
|
case IDOK: |
358 |
|
EndDialog (dlg, TRUE); |
359 |
|
return TRUE; |
360 |
|
|
361 |
|
case IDCANCEL: |
362 |
|
EndDialog (dlg, FALSE); |
363 |
|
return TRUE; |
364 |
|
|
365 |
|
case IDC_KEYPROPS_OT_CHANGE: |
366 |
|
if (!prop->key->key_pair && !key_is_valid (prop->key->ctx)) { |
367 |
|
rc = msg_box (dlg, _("This is a non-valid key.\n" |
368 |
|
"Modifying the ownertrust has no effect on such keys.\n\n" |
369 |
|
"Do you really want to continue?"), |
370 |
|
_("WinPT Warning"), MB_ICONWARNING|MB_YESNO); |
371 |
|
if (rc == IDNO) |
372 |
|
return TRUE; |
373 |
|
} |
374 |
|
rc = dialog_box_param (glob_hinst, |
375 |
|
(LPCSTR)IDD_WINPT_KEYEDIT_OWNERTRUST, |
376 |
|
dlg, keyedit_ownertrust_dlg_proc, |
377 |
|
(LPARAM)prop->key, _("Change Ownertrust"), |
378 |
|
IDS_WINPT_KEYEDIT_OWNERTRUST); |
379 |
|
if (rc == FALSE) /* Cancel */ |
380 |
|
return TRUE; |
381 |
|
|
382 |
|
inf = ownertrust_to_string (prop->key->callback.new_val, |
383 |
|
prop->key->key_pair); |
384 |
|
SetDlgItemText (dlg, IDC_KEYPROPS_OT, inf); |
385 |
|
msg_box (dlg, _("Ownertrust successfully changed."), |
386 |
|
_("GnuPG Status"), MB_OK); |
387 |
|
prop->key->update = 1; |
388 |
|
return TRUE; |
389 |
|
|
390 |
|
case IDC_KEYPROPS_CHANGE_PWD: |
391 |
|
keyedit_change_passwd (prop->key, dlg); |
392 |
|
return TRUE; |
393 |
|
|
394 |
|
case IDC_KEYPROPS_REVOKERS: |
395 |
|
prop->key->update = dialog_box_param (glob_hinst, |
396 |
|
(LPCTSTR)IDD_WINPT_KEYREVOKERS, dlg, |
397 |
|
key_revokers_dlg_proc, (LPARAM)prop->key, |
398 |
|
_("Key Revokers"), |
399 |
|
IDS_WINPT_KEY_REVOKERS); |
400 |
|
UpdateWindow (dlg); |
401 |
|
break; |
402 |
|
} |
403 |
|
} |
404 |
|
|
405 |
|
return FALSE; |
406 |
|
} |