1 |
werner |
36 |
/* wptKeyEditDlgs.cpp - GPG key edit dialogs |
2 |
|
|
* Copyright (C) 2002-2005 Timo Schulz |
3 |
|
|
* |
4 |
|
|
* This file is part of WinPT. |
5 |
|
|
* |
6 |
|
|
* 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 |
8 |
|
|
* the Free Software Foundation; either version 2 of the License, or |
9 |
|
|
* (at your option) any later version. |
10 |
|
|
* |
11 |
|
|
* WinPT is distributed in the hope that it will be useful, |
12 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 |
|
|
* GNU General Public License for more details. |
15 |
|
|
* |
16 |
|
|
* You should have received a copy of the GNU General Public License |
17 |
|
|
* along with WinPT; if not, write to the Free Software Foundation, |
18 |
|
|
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
19 |
|
|
*/ |
20 |
|
|
|
21 |
werner |
42 |
#ifdef HAVE_CONFIG_H |
22 |
|
|
#include <config.h> |
23 |
|
|
#endif |
24 |
|
|
|
25 |
werner |
36 |
#include <windows.h> |
26 |
werner |
48 |
#include <oleauto.h> |
27 |
werner |
36 |
#include <commctrl.h> |
28 |
werner |
47 |
#include <time.h> |
29 |
werner |
36 |
|
30 |
werner |
47 |
#include "resource.h" |
31 |
|
|
|
32 |
werner |
36 |
#include "wptTypes.h" |
33 |
|
|
#include "wptW32API.h" |
34 |
|
|
#include "wptVersion.h" |
35 |
|
|
#include "wptGPG.h" |
36 |
|
|
#include "wptCommonCtl.h" |
37 |
|
|
#include "wptContext.h" |
38 |
|
|
#include "wptDlgs.h" |
39 |
|
|
#include "wptNLS.h" |
40 |
|
|
#include "wptUTF8.h" |
41 |
|
|
#include "wptErrors.h" |
42 |
|
|
#include "wptKeylist.h" |
43 |
|
|
#include "wptKeyManager.h" |
44 |
|
|
#include "wptRegistry.h" |
45 |
|
|
#include "wptKeyEdit.h" |
46 |
|
|
|
47 |
|
|
/* All edit key commands. */ |
48 |
|
|
enum keyedit_commands { |
49 |
|
|
CMD_ADDKEY = 0, |
50 |
|
|
CMD_ADDUID, |
51 |
|
|
CMD_ADDPHOTO, |
52 |
|
|
CMD_ADDREVOKER, |
53 |
|
|
/*CMD_FPR,*/ |
54 |
|
|
CMD_DELUID, |
55 |
|
|
CMD_DELKEY, |
56 |
|
|
CMD_DELPHOTO, |
57 |
|
|
/*CMD_DELSIG,*/ |
58 |
|
|
CMD_EXPIRE, |
59 |
|
|
/*CMD_PREF,*/ |
60 |
|
|
CMD_SHOWPREF, |
61 |
|
|
/*CMD_SETPREF,*/ |
62 |
|
|
/*CMD_UPDPREF,*/ |
63 |
|
|
CMD_PASSWD, |
64 |
|
|
CMD_PRIMARY, |
65 |
|
|
CMD_TRUST, |
66 |
|
|
/*CMD_REVSIG,*/ |
67 |
|
|
CMD_REVUID, |
68 |
|
|
CMD_REVKEY, |
69 |
|
|
CMD_DISABLE, |
70 |
|
|
CMD_ENABLE, |
71 |
|
|
/*CMD_SHOWPHOTO,*/ |
72 |
|
|
}; |
73 |
|
|
|
74 |
|
|
|
75 |
|
|
/* Symbolic ids for the subkey columns. */ |
76 |
|
|
enum subk_col_t { |
77 |
|
|
SUBK_COL_DESC = 0, |
78 |
|
|
SUBK_COL_KEYID = 1, |
79 |
|
|
SUBK_COL_CREATION = 2, |
80 |
|
|
SUBK_COL_EXPIRES = 3, |
81 |
|
|
SUBK_COL_STATUS = 4, |
82 |
|
|
SUBK_COL_C_FLAG = 5, |
83 |
|
|
SUBK_COL_S_FLAG = 6, |
84 |
|
|
SUBK_COL_E_FLAG = 7, |
85 |
|
|
SUBK_COL_A_FLAG = 8 |
86 |
|
|
}; |
87 |
|
|
|
88 |
|
|
/* Symbolic ids for the userid columns. */ |
89 |
|
|
enum uid_col_t { |
90 |
|
|
UID_COL_VALID = 0, |
91 |
|
|
UID_COL_NAME = 1, |
92 |
|
|
UID_COL_EMAIL = 2, |
93 |
|
|
UID_COL_CREATION = 3 |
94 |
|
|
}; |
95 |
|
|
|
96 |
|
|
struct keyedit_callback_s { |
97 |
|
|
const char *keyid; |
98 |
|
|
const char *pass; |
99 |
|
|
listview_ctrl_t lv; |
100 |
|
|
void *opaque; |
101 |
|
|
unsigned int finished:1; |
102 |
|
|
}; |
103 |
|
|
typedef struct keyedit_callback_s KEYEDIT_CB; |
104 |
|
|
|
105 |
|
|
struct keygen_callback_s { |
106 |
|
|
int bits; |
107 |
|
|
int algo; |
108 |
|
|
u32 expire; |
109 |
|
|
char *fpr; |
110 |
|
|
}; |
111 |
|
|
typedef struct keygen_callback_s KEYGEN_CB; |
112 |
|
|
|
113 |
|
|
|
114 |
|
|
static subclass_s keyedit_subkey_proc; |
115 |
|
|
static subclass_s keyedit_uid_proc; |
116 |
|
|
|
117 |
|
|
int keygen_check_date (SYSTEMTIME *st); |
118 |
|
|
void get_userid_preflist (char **r_prefs, int * r_flags); |
119 |
|
|
char* get_subkey_fingerprint (const char *keyid); |
120 |
|
|
|
121 |
|
|
|
122 |
|
|
/* Associate each key with a combo box entry. |
123 |
|
|
Skip the key in @k. */ |
124 |
|
|
static void |
125 |
|
|
do_init_keylist (HWND dlg, winpt_key_t k) |
126 |
|
|
{ |
127 |
|
|
gpg_keycache_t pub; |
128 |
|
|
gpgme_key_t key; |
129 |
|
|
const char * s, * kid; |
130 |
|
|
char * u; |
131 |
|
|
int i, n; |
132 |
|
|
|
133 |
|
|
pub = keycache_get_ctx (1); |
134 |
|
|
if (!pub) |
135 |
|
|
BUG (0); |
136 |
|
|
|
137 |
|
|
gpg_keycache_rewind (pub); |
138 |
|
|
while( !gpg_keycache_next_key( pub, 0, &key ) ) { |
139 |
twoaday |
78 |
if (key->expired || key->revoked || |
140 |
|
|
key->disabled || key->invalid) |
141 |
|
|
continue; |
142 |
|
|
|
143 |
werner |
36 |
s = key->uids->uid; |
144 |
|
|
kid = key->subkeys->keyid; |
145 |
|
|
if (!s || !strcmp (kid+8, k->keyid+2)) |
146 |
|
|
continue; |
147 |
|
|
u = utf8_to_wincp (s, strlen (s)); |
148 |
|
|
SendDlgItemMessage (dlg, IDC_ADDREV_KEYLIST, CB_ADDSTRING, |
149 |
|
|
0, (WPARAM)(char *)u); |
150 |
|
|
free (u); |
151 |
|
|
} |
152 |
|
|
gpg_keycache_rewind (pub); |
153 |
|
|
n = SendDlgItemMessage( dlg, IDC_ADDREV_KEYLIST, CB_GETCOUNT, 0, 0 ); |
154 |
|
|
for (i = 0; i < n; i++) { |
155 |
|
|
gpg_keycache_next_key (pub, 0, &key); |
156 |
|
|
SendDlgItemMessage (dlg, IDC_ADDREV_KEYLIST, CB_SETITEMDATA, |
157 |
|
|
(WPARAM)(int)i, (LPARAM)key); |
158 |
|
|
} |
159 |
|
|
SendDlgItemMessage (dlg, IDC_ADDREV_KEYLIST, CB_SETCURSEL, 0, 0); |
160 |
|
|
} |
161 |
|
|
|
162 |
|
|
|
163 |
|
|
/* Add a new user-id to the list view @lv. */ |
164 |
|
|
static void |
165 |
|
|
do_add_new_userid (listview_ctrl_t lv, |
166 |
|
|
const char * name, const char *email, const char * comment) |
167 |
|
|
{ |
168 |
|
|
char * p; |
169 |
|
|
size_t n; |
170 |
|
|
|
171 |
|
|
n = strlen (name) + strlen (email) + 16; |
172 |
|
|
if (comment) |
173 |
|
|
n += strlen (comment); |
174 |
|
|
p = new char[n+1]; |
175 |
|
|
if (!p) |
176 |
|
|
BUG( NULL ); |
177 |
|
|
if (comment) |
178 |
|
|
sprintf (p, "%s (%s)", name, comment); |
179 |
|
|
else |
180 |
|
|
sprintf (p, "%s", name); |
181 |
|
|
|
182 |
|
|
listview_add_item (lv, ""); |
183 |
|
|
listview_add_sub_item (lv, 0, 0, _("Ultimate" )); |
184 |
|
|
listview_add_sub_item (lv, 0, 1, p); |
185 |
|
|
listview_add_sub_item (lv, 0, 2, email && *email? email : ""); |
186 |
|
|
listview_add_sub_item (lv, 0, 3, get_key_created (time (NULL))); |
187 |
|
|
free_if_alloc (p); |
188 |
|
|
} /* do_add_new_userid */ |
189 |
|
|
|
190 |
|
|
|
191 |
|
|
static void |
192 |
|
|
do_add_new_subkey (listview_ctrl_t lv, KEYGEN_CB *keygen, unsigned int flags) |
193 |
|
|
{ |
194 |
|
|
char info[128], keyid[32]; |
195 |
|
|
const char * expdate, * s; |
196 |
|
|
int n; |
197 |
|
|
|
198 |
|
|
expdate = keygen->expire? get_key_expire_date (keygen->expire) : _("Never"); |
199 |
|
|
_snprintf (info, sizeof info-1, "%d-bit %s", |
200 |
|
|
keygen->bits, |
201 |
|
|
get_key_pubalgo ((gpgme_pubkey_algo_t)keygen->algo)); |
202 |
|
|
_snprintf (keyid, sizeof keyid-1, "0x%s", keygen->fpr+32); |
203 |
|
|
n = listview_count_items (lv, 0); |
204 |
|
|
listview_add_item_pos (lv, n); |
205 |
|
|
listview_add_sub_item (lv, n, 0, info); |
206 |
|
|
listview_add_sub_item (lv, n, 1, keyid); |
207 |
|
|
listview_add_sub_item (lv, n, 2, get_key_created (time (NULL))); |
208 |
|
|
listview_add_sub_item (lv, n, 3, expdate); |
209 |
|
|
if (flags & KM_FLAG_REVOKED) s = _("Revoked"); |
210 |
|
|
else if (flags & KM_FLAG_EXPIRED) s = _("Expired"); |
211 |
|
|
else s = _("OK"); |
212 |
|
|
listview_add_sub_item (lv, n, 4, s); |
213 |
|
|
} /* do_add_new_subkey */ |
214 |
|
|
|
215 |
|
|
|
216 |
|
|
/* Try to find the GPG edit key index which belongs to the user ID |
217 |
|
|
given by @name. If @r_inf != NULL, the info context will be returned. |
218 |
|
|
Return value: index of the user ID or -1 on error. */ |
219 |
|
|
static int |
220 |
|
|
do_find_userid (const char *keyid, const char *name, gpg_uid_info_t *r_inf) |
221 |
|
|
{ |
222 |
|
|
GpgKeyEdit *ke; |
223 |
|
|
gpgme_error_t err; |
224 |
|
|
gpg_uid_info_t inf, ui; |
225 |
|
|
int pos = -1; |
226 |
|
|
|
227 |
|
|
ke = new GpgKeyEdit (keyid); |
228 |
|
|
if (!ke) |
229 |
|
|
BUG (NULL); |
230 |
|
|
err = ke->getUseridInfo (&inf); |
231 |
|
|
delete ke; |
232 |
|
|
if (err) { |
233 |
|
|
log_box (_("user ID"), MB_ERR, |
234 |
|
|
_("Could not get key information for: \"%s\":\n%s"), |
235 |
|
|
name, gpgme_strerror (err)); |
236 |
|
|
return -1; |
237 |
|
|
} |
238 |
|
|
|
239 |
|
|
for (ui = inf; ui; ui = ui->next) { |
240 |
|
|
if (!strcmp (ui->email, name)) { |
241 |
|
|
pos = ui->index; |
242 |
|
|
break; |
243 |
|
|
} |
244 |
|
|
} |
245 |
|
|
if (r_inf) |
246 |
|
|
*r_inf = inf; |
247 |
|
|
else |
248 |
|
|
gpg_uid_info_release (inf); |
249 |
|
|
return pos; |
250 |
|
|
} |
251 |
|
|
|
252 |
|
|
|
253 |
|
|
/* Dialog box procedure to add a photo. */ |
254 |
|
|
BOOL CALLBACK |
255 |
|
|
keyedit_addphoto_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
256 |
|
|
{ |
257 |
|
|
static winpt_key_t k; |
258 |
|
|
GpgKeyEdit *ke; |
259 |
|
|
gpgme_error_t ec; |
260 |
|
|
const char * s; |
261 |
|
|
char pwd[128], file[128]; |
262 |
|
|
int id; |
263 |
|
|
|
264 |
|
|
switch( msg ) { |
265 |
|
|
case WM_INITDIALOG: |
266 |
|
|
k = (winpt_key_t)lparam; |
267 |
|
|
if (!k) |
268 |
|
|
BUG (NULL); |
269 |
|
|
SetDlgItemText (dlg, IDC_ADDPHOTO_INF, _("Remember that the image is stored within your public key. If you use a very large picture, your key will become very large as well! Keeping the image close to 240x288 is a good size to use.")); |
270 |
|
|
SetDlgItemText (dlg, IDC_ADDPHOTO_FILEINF, _("Pick an image to use for your photo ID.\nThe image must be a JPEG file.")); |
271 |
|
|
SetDlgItemText (dlg, IDC_ADDPHOTO_PWDINF, _("Passphrase")); |
272 |
|
|
SetForegroundWindow( dlg ); |
273 |
|
|
break; |
274 |
|
|
|
275 |
|
|
case WM_DESTROY: |
276 |
|
|
break; |
277 |
|
|
|
278 |
|
|
case WM_SYSCOMMAND: |
279 |
|
|
if( LOWORD (wparam) == SC_CLOSE ) |
280 |
|
|
EndDialog( dlg, TRUE ); |
281 |
|
|
break; |
282 |
|
|
|
283 |
|
|
case WM_COMMAND: |
284 |
|
|
switch( LOWORD( wparam ) ) { |
285 |
|
|
|
286 |
|
|
case IDC_ADDPHOTO_SELFILE: |
287 |
twoaday |
77 |
s = get_fileopen_dlg( dlg, _("Select Image File"), _("JPEG Files (*.jpg, *.jpeg)\0*.jpg;*.jpeg\0\0"), NULL ); |
288 |
werner |
36 |
if( s && *s ) |
289 |
|
|
SetDlgItemText( dlg, IDC_ADDPHOTO_FILE, s ); |
290 |
|
|
break; |
291 |
|
|
|
292 |
|
|
case IDOK: |
293 |
|
|
if( !GetDlgItemText( dlg, IDC_ADDPHOTO_FILE, file, sizeof file-1 ) ){ |
294 |
|
|
msg_box( dlg, _("Please enter a file name."), _("Add Photo"), MB_ERR ); |
295 |
|
|
return FALSE; |
296 |
|
|
} |
297 |
|
|
if( get_file_size( file ) == 0 || get_file_size( file ) > 6144 ) { |
298 |
|
|
id = msg_box( dlg, _("The JPEG is really large.\n" |
299 |
|
|
"Are you sure you want to use it?"), |
300 |
|
|
_("Add Photo"), MB_YESNO|MB_INFO ); |
301 |
|
|
if( id == IDNO ) |
302 |
|
|
return TRUE; |
303 |
|
|
} |
304 |
|
|
if( k->is_protected ) { |
305 |
|
|
if( !GetDlgItemText( dlg, IDC_ADDPHOTO_PASS, pwd, sizeof pwd-1 ) ) { |
306 |
|
|
msg_box( dlg, _("Please enter a passphrase."), _("Add Photo"), MB_ERR ); |
307 |
|
|
return FALSE; |
308 |
|
|
} |
309 |
|
|
} |
310 |
|
|
ke = new GpgKeyEdit (k->keyid); |
311 |
|
|
if (!ke) |
312 |
|
|
BUG (NULL); |
313 |
|
|
|
314 |
|
|
if (k->is_protected) |
315 |
|
|
ke->setPassphrase (pwd); |
316 |
|
|
ec = ke->addPhotoid (file); |
317 |
|
|
delete ke; |
318 |
|
|
memset (pwd, 0, sizeof pwd); |
319 |
|
|
if (ec) { |
320 |
|
|
msg_box (dlg, gpgme_strerror (ec), _("Add Photo"), MB_ERR ); |
321 |
|
|
return FALSE; |
322 |
|
|
} |
323 |
|
|
else { |
324 |
|
|
k->update = 1; |
325 |
|
|
msg_box (dlg, _("Photo successfully added."), _("GnuPG Status"), MB_OK); |
326 |
|
|
} |
327 |
|
|
EndDialog (dlg, TRUE); |
328 |
|
|
break; |
329 |
|
|
|
330 |
|
|
case IDCANCEL: |
331 |
|
|
EndDialog (dlg, FALSE); |
332 |
|
|
break; |
333 |
|
|
} |
334 |
|
|
break; |
335 |
|
|
} |
336 |
|
|
return FALSE; |
337 |
|
|
} |
338 |
|
|
|
339 |
|
|
|
340 |
|
|
/* Dialog box procedure to add a designated revoker. */ |
341 |
|
|
BOOL CALLBACK |
342 |
|
|
keyedit_addrevoker_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
343 |
|
|
{ |
344 |
|
|
static winpt_key_t k; |
345 |
|
|
static gpgme_key_t seckey; |
346 |
|
|
GpgKeyEdit *ke; |
347 |
|
|
gpgme_error_t err; |
348 |
|
|
char uid[128], pwd[128]; |
349 |
|
|
|
350 |
|
|
|
351 |
|
|
switch( msg ) { |
352 |
|
|
case WM_INITDIALOG: |
353 |
|
|
k = (winpt_key_t)lparam; |
354 |
|
|
if( !k ) |
355 |
|
|
BUG( NULL ); |
356 |
|
|
if( get_seckey( k->keyid, &seckey ) ) |
357 |
|
|
BUG( NULL ); |
358 |
|
|
if (!k->is_protected) |
359 |
|
|
EnableWindow (GetDlgItem (dlg, IDC_ADDREV_PASS), FALSE); |
360 |
|
|
do_init_keylist (dlg, k); |
361 |
|
|
SetDlgItemText (dlg, IDC_ADDREV_INF, _("Appointing a key as designated revoker cannot be undone.")); |
362 |
|
|
SetDlgItemText (dlg, IDC_ADDREV_KEYINF, _("Public key")); |
363 |
|
|
SetDlgItemText (dlg, IDC_ADDREV_PWDINF, _("Passphrase")); |
364 |
|
|
SetForegroundWindow( dlg ); |
365 |
|
|
break; |
366 |
|
|
|
367 |
|
|
case WM_DESTROY: |
368 |
|
|
break; |
369 |
|
|
|
370 |
|
|
case WM_SYSCOMMAND: |
371 |
|
|
if( LOWORD (wparam) == SC_CLOSE ) |
372 |
|
|
EndDialog( dlg, TRUE ); |
373 |
|
|
break; |
374 |
|
|
|
375 |
|
|
case WM_COMMAND: |
376 |
|
|
switch( LOWORD( wparam ) ) { |
377 |
|
|
case IDOK: |
378 |
|
|
if( !GetDlgItemText( dlg, IDC_ADDREV_KEYLIST, uid, sizeof uid-1 ) ) { |
379 |
|
|
msg_box( dlg, _("Please select a user ID."), _("Add Revoker"), MB_ERR ); |
380 |
|
|
return FALSE; |
381 |
|
|
} |
382 |
|
|
|
383 |
|
|
if( k->is_protected ) { |
384 |
|
|
if( !GetDlgItemText( dlg, IDC_ADDREV_PASS, pwd, sizeof pwd-1 ) ) { |
385 |
|
|
msg_box( dlg, _("Please enter the passphrase."), _("Add Revoker"), MB_ERR ); |
386 |
|
|
return FALSE; |
387 |
|
|
} |
388 |
|
|
} |
389 |
|
|
ke = new GpgKeyEdit (k->keyid); |
390 |
|
|
if (k->is_protected) |
391 |
|
|
ke->setPassphrase (pwd); |
392 |
|
|
err = ke->addDesignatedRevoker (uid); |
393 |
|
|
delete ke; |
394 |
|
|
memset (pwd, 0, sizeof pwd); |
395 |
|
|
if (err) { |
396 |
|
|
msg_box (dlg, gpgme_strerror (err), _("Add Revoker"), MB_ERR); |
397 |
|
|
return TRUE; |
398 |
|
|
} |
399 |
|
|
else { |
400 |
|
|
k->update = 1; |
401 |
|
|
msg_box (dlg, _("Revoker successfully addded."), _("GnuPG Status"), MB_OK); |
402 |
|
|
} |
403 |
|
|
EndDialog( dlg, TRUE ); |
404 |
|
|
break; |
405 |
|
|
|
406 |
|
|
case IDCANCEL: |
407 |
|
|
EndDialog( dlg, FALSE ); |
408 |
|
|
break; |
409 |
|
|
} |
410 |
|
|
break; |
411 |
|
|
} |
412 |
|
|
return FALSE; |
413 |
|
|
} |
414 |
|
|
|
415 |
|
|
|
416 |
|
|
/* Dialog box procedure to add a new user-ID. */ |
417 |
|
|
BOOL CALLBACK |
418 |
|
|
keyedit_adduid_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
419 |
|
|
{ |
420 |
|
|
static KEYEDIT_CB *ctx; |
421 |
|
|
gpgme_error_t err; |
422 |
|
|
GpgKeyEdit *ke; |
423 |
|
|
char *utf8_name = NULL; |
424 |
|
|
char name[128], email[128], comment[128]; |
425 |
|
|
int rc; |
426 |
|
|
|
427 |
|
|
switch ( msg ) { |
428 |
|
|
case WM_INITDIALOG: |
429 |
|
|
ctx = (KEYEDIT_CB *)lparam; |
430 |
|
|
if( !ctx ) |
431 |
|
|
dlg_fatal_error(dlg, "Could not get dialog param!"); |
432 |
twoaday |
99 |
|
433 |
werner |
36 |
SetWindowText (dlg, _("Add new User ID")); |
434 |
|
|
SetDlgItemText (dlg, IDC_ADDUID_INFNAME, _("&Name")); |
435 |
|
|
SetDlgItemText (dlg, IDC_ADDUID_INFEMAIL, _("&Email")); |
436 |
|
|
SetDlgItemText (dlg, IDC_ADDUID_INFCOMMENT, _("&Comment")); |
437 |
twoaday |
99 |
|
438 |
werner |
36 |
SetForegroundWindow (dlg); |
439 |
|
|
return FALSE; |
440 |
|
|
|
441 |
|
|
case WM_SYSCOMMAND: |
442 |
|
|
if (LOWORD (wparam) == SC_CLOSE) { |
443 |
|
|
EndDialog(dlg, TRUE); |
444 |
|
|
} |
445 |
|
|
return FALSE; |
446 |
|
|
|
447 |
|
|
case WM_COMMAND: |
448 |
|
|
switch ( LOWORD( wparam ) ) { |
449 |
|
|
case IDOK: |
450 |
|
|
rc = GetDlgItemText( dlg, IDC_ADDUID_NAME, name, sizeof name-1 ); |
451 |
|
|
if (!rc || rc < 5) { |
452 |
|
|
msg_box( dlg, _("Please enter a name (min. 5 chars.)"), _("UserID"), MB_ERR ); |
453 |
|
|
return FALSE; |
454 |
|
|
} |
455 |
|
|
if (strchr (name, '@')) { |
456 |
|
|
msg_box( dlg, _("Please enter the email address in the email field and not in the name field"), _("UserID"), MB_INFO ); |
457 |
|
|
return FALSE; |
458 |
|
|
} |
459 |
|
|
|
460 |
|
|
if( !GetDlgItemText( dlg, IDC_ADDUID_EMAIL, email, sizeof email -1 ) ) { |
461 |
|
|
msg_box( dlg, _("Please enter an email address."), _("UserID"), MB_ERR ); |
462 |
|
|
return FALSE; |
463 |
|
|
} |
464 |
|
|
if( !strchr( email, '@' ) || strchr (email, ' ')) { |
465 |
|
|
msg_box( dlg, _("Invalid email address."), _("UserID"), MB_ERR ); |
466 |
|
|
return FALSE; |
467 |
|
|
} |
468 |
|
|
|
469 |
|
|
rc = GetDlgItemText( dlg, IDC_ADDUID_COMMENT, comment, sizeof comment -1 ); |
470 |
|
|
|
471 |
|
|
/* XXX: something is wrong with the encoding :-( */ |
472 |
|
|
utf8_name = wincp_to_utf8 (name, strlen (name)); |
473 |
|
|
|
474 |
|
|
ke = new GpgKeyEdit (ctx->keyid); |
475 |
|
|
if (!ke) |
476 |
|
|
BUG (NULL); |
477 |
|
|
if (ctx->pass) |
478 |
|
|
ke->setPassphrase (ctx->pass); |
479 |
|
|
err = ke->addUserid (utf8_name? utf8_name : name, |
480 |
|
|
rc > 0? comment : NULL, email); |
481 |
|
|
if (err) |
482 |
|
|
msg_box (dlg, gpgme_strerror (err), _("UserID"), MB_ERR); |
483 |
|
|
else { |
484 |
|
|
msg_box (dlg, _("user ID successfully added."), _("GnuPG Status"), MB_OK); |
485 |
|
|
ctx->finished = 1; |
486 |
|
|
} |
487 |
|
|
delete ke; |
488 |
|
|
free (utf8_name); |
489 |
|
|
if (!err && ctx->lv) |
490 |
|
|
do_add_new_userid (ctx->lv, name, email, rc?comment : NULL); |
491 |
|
|
EndDialog (dlg, TRUE); |
492 |
|
|
return TRUE; |
493 |
|
|
|
494 |
|
|
case IDCANCEL: |
495 |
|
|
EndDialog (dlg, FALSE); |
496 |
|
|
return FALSE; |
497 |
|
|
} |
498 |
|
|
break; |
499 |
|
|
} |
500 |
|
|
|
501 |
|
|
return FALSE; |
502 |
|
|
} |
503 |
|
|
|
504 |
|
|
|
505 |
|
|
static int |
506 |
|
|
diff_time (HWND dt, SYSTEMTIME *in_exp) |
507 |
|
|
{ |
508 |
|
|
SYSTEMTIME exp, now; |
509 |
|
|
double e=0, n=0; |
510 |
|
|
|
511 |
|
|
if (in_exp) |
512 |
|
|
memcpy (&exp, in_exp, sizeof (SYSTEMTIME)); |
513 |
|
|
else |
514 |
|
|
DateTime_GetSystemtime (dt, &exp); |
515 |
|
|
GetSystemTime (&now); |
516 |
|
|
SystemTimeToVariantTime (&exp, &e); |
517 |
|
|
SystemTimeToVariantTime (&now, &n); |
518 |
|
|
if (n > e) |
519 |
|
|
return 0; |
520 |
|
|
return (int)(e-n); |
521 |
|
|
} |
522 |
|
|
|
523 |
|
|
|
524 |
|
|
static void |
525 |
|
|
init_keysize_box (HWND dlg, int ctlid) |
526 |
|
|
{ |
527 |
|
|
const char *sizelist[] = { |
528 |
|
|
"1024", "1536", "2048", "2560", "3072", "3854", "4096", NULL |
529 |
|
|
}; |
530 |
|
|
int i; |
531 |
|
|
for (i=0; sizelist[i] != NULL; i++) |
532 |
|
|
SendDlgItemMessage (dlg, ctlid, CB_ADDSTRING, 0, (LPARAM)(char*)sizelist[i]); |
533 |
|
|
SendDlgItemMessage (dlg, ctlid, CB_SETCURSEL, (WPARAM)2, 0); |
534 |
|
|
} |
535 |
|
|
|
536 |
|
|
static int |
537 |
|
|
get_keysize_from_box (HWND dlg, int ctlid) |
538 |
|
|
{ |
539 |
|
|
int pos; |
540 |
|
|
char buf[32]; |
541 |
|
|
|
542 |
|
|
pos = SendDlgItemMessage (dlg, ctlid, CB_GETCURSEL, 0, 0); |
543 |
|
|
if (pos == CB_ERR) |
544 |
|
|
return -1; |
545 |
|
|
SendDlgItemMessage (dlg, ctlid, CB_GETLBTEXT, pos, (LPARAM)(char*)buf); |
546 |
|
|
return atol (buf); |
547 |
|
|
} |
548 |
|
|
|
549 |
|
|
|
550 |
|
|
BOOL CALLBACK |
551 |
|
|
keyedit_addsubkey_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
552 |
|
|
{ |
553 |
|
|
static KEYEDIT_CB *ctx; |
554 |
|
|
static KEYGEN_CB *keygen; |
555 |
|
|
GpgKeyEdit *ke; |
556 |
|
|
gpgme_error_t err; |
557 |
|
|
HWND lb; |
558 |
|
|
int index, size, valid; |
559 |
|
|
|
560 |
|
|
switch (msg) { |
561 |
|
|
case WM_INITDIALOG: |
562 |
|
|
ctx = (KEYEDIT_CB *)lparam; |
563 |
|
|
if (!ctx) |
564 |
|
|
dlg_fatal_error (dlg, "Could not get dialog param!"); |
565 |
|
|
keygen = (KEYGEN_CB *)ctx->opaque; |
566 |
twoaday |
99 |
|
567 |
werner |
36 |
SetWindowText (dlg, _("Add new Subkey")); |
568 |
|
|
SetDlgItemText (dlg, IDC_ADDSUBKEY_INFALGO, _("Key type")); |
569 |
|
|
SetDlgItemText (dlg, IDC_ADDSUBKEY_INFSIZE, _("Size in bits")); |
570 |
|
|
SetDlgItemText (dlg, IDC_ADDSUBKEY_INFVALID, _("Key expiration")); |
571 |
twoaday |
99 |
SetDlgItemText (dlg, IDC_ADDSUBKEY_EXPIRE, _("&Never")); |
572 |
|
|
|
573 |
werner |
36 |
lb = GetDlgItem (dlg, IDC_ADDSUBKEY_ALGO); |
574 |
|
|
listbox_add_string (lb, "DSA (sign only)"); |
575 |
|
|
listbox_add_string (lb, "ElGamal (encrypt only)"); |
576 |
|
|
listbox_add_string (lb, "RSA (sign only)"); |
577 |
|
|
listbox_add_string (lb, "RSA (encrypt only)"); |
578 |
|
|
CheckDlgButton (dlg, IDC_ADDSUBKEY_EXPIRE, BST_CHECKED); |
579 |
|
|
EnableWindow (GetDlgItem (dlg, IDC_ADDSUBKEY_EXPDATE), FALSE); |
580 |
|
|
init_keysize_box (dlg, IDC_ADDSUBKEY_SIZE); |
581 |
|
|
SetForegroundWindow( dlg ); |
582 |
|
|
return FALSE; |
583 |
|
|
|
584 |
|
|
case WM_SYSCOMMAND: |
585 |
|
|
if( LOWORD (wparam) == SC_CLOSE ) { |
586 |
|
|
EndDialog( dlg, TRUE ); |
587 |
|
|
} |
588 |
|
|
return FALSE; |
589 |
|
|
|
590 |
|
|
case WM_COMMAND: |
591 |
|
|
if (HIWORD (wparam) == BN_CLICKED && LOWORD (wparam) == IDC_ADDSUBKEY_EXPIRE) { |
592 |
|
|
if (IsDlgButtonChecked (dlg, IDC_ADDSUBKEY_EXPIRE)) |
593 |
|
|
EnableWindow (GetDlgItem (dlg, IDC_ADDSUBKEY_EXPDATE), FALSE); |
594 |
|
|
else |
595 |
|
|
EnableWindow (GetDlgItem (dlg, IDC_ADDSUBKEY_EXPDATE), TRUE); |
596 |
|
|
} |
597 |
|
|
if (HIWORD (wparam) == LBN_SELCHANGE && LOWORD (wparam) == IDC_ADDSUBKEY_ALGO) { |
598 |
|
|
index = SendMessage ((HWND)lparam, LB_GETCURSEL, 0, 0); |
599 |
|
|
if (index == 0) |
600 |
|
|
SendDlgItemMessage (dlg, IDC_ADDSUBKEY_SIZE, CB_SETCURSEL, 0, 0); |
601 |
|
|
} |
602 |
|
|
|
603 |
|
|
switch ( LOWORD(wparam) ) { |
604 |
|
|
case IDOK: |
605 |
|
|
lb = GetDlgItem (dlg, IDC_ADDSUBKEY_ALGO); |
606 |
|
|
switch (listbox_get_cursel (lb)) { |
607 |
|
|
case 0: index = 2; break; |
608 |
|
|
case 1: index = 4; break; |
609 |
|
|
case 2: index = 5; break; |
610 |
|
|
case 3: index = 6; break; |
611 |
|
|
default: |
612 |
|
|
msg_box( dlg, _("Please select one entry."), _("Add Subkey"), MB_ERR ); |
613 |
|
|
return FALSE; |
614 |
|
|
} |
615 |
|
|
size = get_keysize_from_box (dlg, IDC_ADDSUBKEY_SIZE); |
616 |
|
|
if (index == 2 && size != 1024) { |
617 |
|
|
msg_box( dlg,_("DSS uses a fixed keysize of 1024. Size changed."), _("Add Subkey"), MB_INFO ); |
618 |
|
|
size = 1024; |
619 |
|
|
} |
620 |
|
|
valid = diff_time (GetDlgItem (dlg, IDC_ADDSUBKEY_EXPDATE), NULL); |
621 |
|
|
|
622 |
|
|
keygen->bits = size; |
623 |
|
|
switch (index) { |
624 |
|
|
case 2: keygen->algo = GPGME_PK_DSA; break; |
625 |
|
|
case 4: keygen->algo = GPGME_PK_ELG_E; break; |
626 |
|
|
case 5: keygen->algo = GPGME_PK_RSA_S; break; |
627 |
|
|
case 6: keygen->algo = GPGME_PK_RSA_E; break; |
628 |
|
|
} |
629 |
|
|
if (valid > 0) |
630 |
|
|
keygen->expire = time (NULL) + valid*24*60*60; |
631 |
|
|
|
632 |
|
|
ke = new GpgKeyEdit (ctx->keyid); |
633 |
|
|
if (!ke) |
634 |
|
|
BUG (NULL); |
635 |
|
|
ke->setCallback (keygen_cb, NULL); |
636 |
|
|
if (ctx->pass) |
637 |
|
|
ke->setPassphrase (ctx->pass); |
638 |
|
|
keygen_cb_dlg_create (); |
639 |
|
|
|
640 |
|
|
err = ke->addSubkey ((gpgme_pubkey_algo_t)index, size, valid); |
641 |
|
|
keygen->fpr = get_subkey_fingerprint (ctx->keyid); |
642 |
|
|
keygen_cb_dlg_destroy (); |
643 |
|
|
keygen_cb (NULL, NULL, 0, 0, 0); /* flush */ |
644 |
|
|
if (err) |
645 |
|
|
msg_box (dlg, gpgme_strerror (err), _("Add Subkey"), MB_ERR); |
646 |
|
|
else { |
647 |
|
|
msg_box (dlg, _("Subkey successfully added."), _("GnuPG Status"), MB_OK); |
648 |
|
|
if (ctx->lv) |
649 |
|
|
do_add_new_subkey (ctx->lv, keygen, /*XXXk->flags*/0); |
650 |
|
|
ctx->finished = 1; |
651 |
|
|
} |
652 |
|
|
delete ke; |
653 |
|
|
EndDialog (dlg, TRUE); |
654 |
|
|
return TRUE; |
655 |
|
|
|
656 |
|
|
case IDCANCEL: |
657 |
|
|
EndDialog( dlg, FALSE ); |
658 |
|
|
return FALSE; |
659 |
|
|
} |
660 |
|
|
break; |
661 |
|
|
} |
662 |
|
|
|
663 |
|
|
return FALSE; |
664 |
|
|
} /* keyedit_addsubkey_dlg_proc */ |
665 |
|
|
|
666 |
|
|
|
667 |
|
|
BOOL |
668 |
|
|
keyedit_add_userid (winpt_key_t k, HWND dlg, listview_ctrl_t lv) |
669 |
|
|
{ |
670 |
|
|
KEYEDIT_CB cb; |
671 |
|
|
char *pass = NULL; |
672 |
|
|
int cancel = 0; |
673 |
|
|
|
674 |
|
|
if (!k->key_pair) { |
675 |
|
|
msg_box( dlg, _("There is no secret key available!"), _("Add user ID"), MB_ERR ); |
676 |
|
|
return FALSE; |
677 |
|
|
} |
678 |
|
|
|
679 |
|
|
if (k->is_protected) { |
680 |
|
|
pass = request_passphrase( _("Key Edit"), 1, &cancel ); |
681 |
|
|
if (cancel) |
682 |
|
|
return FALSE; |
683 |
|
|
} |
684 |
|
|
|
685 |
|
|
memset (&cb, 0, sizeof cb); |
686 |
|
|
cb.pass = k->is_protected? pass : NULL; |
687 |
|
|
cb.lv = lv; |
688 |
|
|
cb.keyid = k->keyid; |
689 |
|
|
dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_KEYEDIT_ADDUID, |
690 |
|
|
dlg, keyedit_adduid_dlg_proc, |
691 |
|
|
(LPARAM)&cb, _("Add user ID"), |
692 |
|
|
IDS_WINPT_KEYEDIT_ADDUID); |
693 |
|
|
|
694 |
|
|
if (cb.finished) |
695 |
|
|
k->update = 1; |
696 |
|
|
|
697 |
|
|
sfree_if_alloc (pass); |
698 |
|
|
return TRUE; |
699 |
|
|
} |
700 |
|
|
|
701 |
|
|
|
702 |
|
|
char* |
703 |
|
|
get_subkey_fingerprint (const char *keyid) |
704 |
|
|
{ |
705 |
|
|
gpgme_error_t err; |
706 |
|
|
gpgme_key_t key, main; |
707 |
|
|
gpgme_ctx_t ctx; |
708 |
|
|
gpgme_subkey_t last_sk, k, new_sk; |
709 |
|
|
int n; |
710 |
|
|
|
711 |
|
|
err = gpgme_new (&ctx); |
712 |
|
|
if (err) |
713 |
|
|
return NULL; |
714 |
|
|
err = gpgme_get_key (ctx, keyid, &key, 0); |
715 |
|
|
if (err) |
716 |
|
|
return NULL; |
717 |
|
|
/* XXX: this is very slow and complicated */ |
718 |
|
|
|
719 |
|
|
n = count_subkeys (key); |
720 |
|
|
last_sk = get_nth_key (key, n-1); |
721 |
|
|
new_sk = (gpgme_subkey_t)calloc (1, sizeof *new_sk); |
722 |
|
|
if (!new_sk) |
723 |
|
|
BUG (NULL); |
724 |
|
|
memcpy (new_sk, last_sk, sizeof *last_sk); |
725 |
|
|
new_sk->fpr = strdup (last_sk->fpr); |
726 |
|
|
new_sk->keyid = strdup (last_sk->keyid); |
727 |
|
|
|
728 |
|
|
get_pubkey (keyid, &main); |
729 |
|
|
for (k=main->subkeys; k->next; k=k->next) |
730 |
|
|
; |
731 |
|
|
k->next = new_sk; |
732 |
|
|
|
733 |
|
|
gpgme_key_release (key); |
734 |
|
|
return new_sk->fpr; |
735 |
|
|
} |
736 |
|
|
|
737 |
|
|
|
738 |
|
|
BOOL |
739 |
|
|
keyedit_add_subkey (winpt_key_t k, HWND dlg, listview_ctrl_t lv) |
740 |
|
|
{ |
741 |
|
|
KEYEDIT_CB cb; |
742 |
|
|
KEYGEN_CB keygen; |
743 |
|
|
char *pass = NULL; |
744 |
|
|
int cancel = 0; |
745 |
|
|
|
746 |
|
|
if (!k->key_pair) { |
747 |
|
|
msg_box (dlg, _("There is no secret key available!"), _("Add Subkey"), MB_ERR); |
748 |
|
|
return FALSE; |
749 |
|
|
} |
750 |
|
|
if (k->is_protected) { |
751 |
|
|
pass = request_passphrase (_("Key Edit"), 1, &cancel); |
752 |
|
|
if (cancel) |
753 |
|
|
return FALSE; |
754 |
|
|
} |
755 |
|
|
|
756 |
|
|
memset (&keygen, 0, sizeof (keygen)); |
757 |
|
|
memset (&cb, 0, sizeof (cb)); |
758 |
|
|
cb.keyid = k->keyid; |
759 |
|
|
cb.pass = k->is_protected? pass : NULL; |
760 |
|
|
cb.opaque = &keygen; |
761 |
|
|
dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_KEYEDIT_ADDSUBKEY, |
762 |
|
|
dlg, keyedit_addsubkey_dlg_proc, |
763 |
|
|
(LPARAM)&cb, _("Add new Subkey"), |
764 |
|
|
IDS_WINPT_KEYEDIT_ADDSUBKEY); |
765 |
|
|
if (cb.finished) |
766 |
|
|
k->update = 1; |
767 |
|
|
|
768 |
|
|
sfree_if_alloc (pass); |
769 |
|
|
return cb.finished? TRUE: FALSE; |
770 |
|
|
} |
771 |
|
|
|
772 |
|
|
|
773 |
|
|
BOOL |
774 |
|
|
keyedit_set_pref_keyserver (winpt_key_t k, HWND dlg) |
775 |
|
|
{ |
776 |
|
|
GpgKeyEdit *ke; |
777 |
|
|
gpgme_error_t err; |
778 |
|
|
struct URL_ctx_s *url; |
779 |
|
|
char *pass; |
780 |
|
|
|
781 |
|
|
url = (struct URL_ctx_s *)get_keyserver_URL_dlg (dlg); |
782 |
|
|
if (url->cancel == 1) { |
783 |
|
|
delete url; |
784 |
|
|
return FALSE; |
785 |
|
|
} |
786 |
|
|
|
787 |
|
|
pass = request_passphrase (_("Key Edit"), 1, &url->cancel); |
788 |
|
|
if (url->cancel) { |
789 |
|
|
delete url; |
790 |
|
|
return FALSE; |
791 |
|
|
} |
792 |
|
|
|
793 |
|
|
ke = new GpgKeyEdit (k->keyid); |
794 |
|
|
if (!ke) |
795 |
|
|
BUG (NULL); |
796 |
|
|
ke->setPassphrase (pass); |
797 |
|
|
err = ke->setPreferredKeyserver (0 /* XXX */, url->url); |
798 |
|
|
if (!err) |
799 |
|
|
msg_box (dlg, _("Preferred keyserver successfully set."), _("Key Edit"), MB_OK); |
800 |
|
|
|
801 |
|
|
sfree_if_alloc (pass); |
802 |
|
|
delete ke; |
803 |
|
|
delete url; |
804 |
|
|
return err == 0? 0 : WPTERR_GENERAL; |
805 |
|
|
} |
806 |
|
|
|
807 |
|
|
|
808 |
|
|
/* Add a photo-ID to the key specified in @k. @dlg is the handle of |
809 |
|
|
the calling dialog. */ |
810 |
|
|
BOOL |
811 |
|
|
keyedit_add_photo (winpt_key_t k, HWND dlg) |
812 |
|
|
{ |
813 |
|
|
if (!k->key_pair) { |
814 |
|
|
msg_box (dlg, _("There is no secret key available!"), _("Add Photo"), MB_ERR); |
815 |
|
|
return FALSE; |
816 |
|
|
} |
817 |
|
|
DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_KEYEDIT_ADDPHOTO, dlg, |
818 |
|
|
keyedit_addphoto_dlg_proc, (LPARAM)k); |
819 |
|
|
return TRUE; |
820 |
|
|
} |
821 |
|
|
|
822 |
|
|
|
823 |
|
|
BOOL |
824 |
|
|
keyedit_add_revoker (winpt_key_t k, HWND dlg) |
825 |
|
|
{ |
826 |
|
|
if( !k->key_pair ) { |
827 |
|
|
msg_box( dlg, _("There is no secret key available!"), _("Add Revoker"), MB_ERR ); |
828 |
|
|
return FALSE; |
829 |
|
|
} |
830 |
|
|
DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_KEYEDIT_ADDREV, dlg, |
831 |
|
|
keyedit_addrevoker_dlg_proc, (LPARAM)k); |
832 |
|
|
return TRUE; |
833 |
|
|
} /* keyedit_add_revoker */ |
834 |
|
|
|
835 |
|
|
|
836 |
|
|
static int |
837 |
|
|
is_idea_protect_algo (const char * keyid) |
838 |
|
|
{ |
839 |
|
|
winpt_key_s k; |
840 |
|
|
const unsigned char *sym_prefs; |
841 |
|
|
size_t n; |
842 |
|
|
|
843 |
|
|
memset (&k, 0, sizeof (k)); |
844 |
|
|
if (winpt_get_pubkey (keyid, &k)) |
845 |
|
|
BUG (NULL); |
846 |
|
|
sym_prefs = k.ext->sym_prefs; |
847 |
|
|
if (!sym_prefs) |
848 |
|
|
return 1; /* assume that only v3 keys have no symmetric cipher preferences |
849 |
|
|
and thus IDEA is explicit. */ |
850 |
|
|
for (n = 0; sym_prefs[n]; n++) |
851 |
|
|
; |
852 |
|
|
if ((n == 0 || n == 1) && *sym_prefs == 0x01) |
853 |
|
|
return 1; |
854 |
|
|
return 0; |
855 |
|
|
} /* is_idea_protect_algo */ |
856 |
|
|
|
857 |
|
|
|
858 |
|
|
BOOL |
859 |
|
|
keyedit_change_passwd( winpt_key_t k, HWND dlg ) |
860 |
|
|
{ |
861 |
|
|
GpgKeyEdit *ke; |
862 |
|
|
gpgme_error_t ec; |
863 |
|
|
char *old_pass = NULL, *new_pass = NULL; |
864 |
|
|
int cancel = 0; |
865 |
|
|
|
866 |
|
|
if( !k->key_pair ) { |
867 |
|
|
msg_box( dlg, _("There is no secret key available!"), _("Key Edit"), MB_ERR ); |
868 |
|
|
return FALSE; |
869 |
|
|
} |
870 |
|
|
|
871 |
|
|
if( !idea_available && is_idea_protect_algo( k->keyid ) ) { |
872 |
|
|
msg_box( dlg, _("Cannot change passphrase because the key\n" |
873 |
|
|
"is protected with the IDEA encryption algorithm."), |
874 |
|
|
_("Key Edit"), MB_ERR ); |
875 |
|
|
return FALSE; |
876 |
|
|
} |
877 |
|
|
|
878 |
|
|
if( k->is_protected ) { |
879 |
|
|
old_pass = request_passphrase( _("Current (old) Passphrase"), 1, &cancel ); |
880 |
|
|
if( cancel ) |
881 |
|
|
return FALSE; |
882 |
|
|
} |
883 |
|
|
new_pass = request_passphrase( _("New Passphrase" ), 1, &cancel ); |
884 |
|
|
if( cancel ) { |
885 |
|
|
free_if_alloc( old_pass ); |
886 |
|
|
return FALSE; |
887 |
|
|
} |
888 |
|
|
|
889 |
|
|
if( is_8bit_string( new_pass ) ) { |
890 |
|
|
msg_box( dlg, _("The passphrase contains 8-bit characters.\n" |
891 |
|
|
"It is not suggested to use charset specific characters."), |
892 |
|
|
_("Key Edit"), MB_ERR ); |
893 |
|
|
free_if_alloc( old_pass ); |
894 |
|
|
free_if_alloc( new_pass ); |
895 |
|
|
return FALSE; |
896 |
|
|
} |
897 |
|
|
|
898 |
|
|
ke = new GpgKeyEdit (k->keyid); |
899 |
|
|
if (!ke) |
900 |
|
|
BUG (NULL); |
901 |
|
|
|
902 |
|
|
ke->setPassphrase (k->is_protected? old_pass : NULL); |
903 |
|
|
ec = ke->changePassphrase (new_pass, 0); |
904 |
|
|
if( ec ) |
905 |
|
|
msg_box (dlg, gpgme_strerror (ec), _("Change Passwd"), MB_ERR); |
906 |
|
|
else |
907 |
|
|
msg_box (dlg, _("Passphrase successfully changed."), _("GnuPG status"), MB_OK); |
908 |
|
|
sfree_if_alloc (old_pass); |
909 |
|
|
sfree_if_alloc (new_pass); |
910 |
|
|
delete ke; |
911 |
|
|
return TRUE; |
912 |
|
|
} |
913 |
|
|
|
914 |
|
|
|
915 |
|
|
listview_ctrl_t |
916 |
|
|
subkey_list_init( HWND dlg, winpt_key_t k ) |
917 |
|
|
{ |
918 |
|
|
LV_ITEM lvi; |
919 |
|
|
gpgme_key_t key; |
920 |
|
|
gpgme_subkey_t sub; |
921 |
|
|
struct listview_column_s cols[] = { |
922 |
|
|
{0, 80, (char *)_("Description")}, |
923 |
|
|
{1, 78, (char *)_("Key ID")}, |
924 |
|
|
{2, 66, (char *)_("Creation")}, |
925 |
|
|
{3, 66, (char *)_("Expires")}, |
926 |
|
|
{4, 64, (char *)_("Status")}, |
927 |
|
|
{5, 16, "C"/*ertify*/}, |
928 |
|
|
{6, 16, "S"/*ign*/}, |
929 |
|
|
{7, 16, "E"/*ncrypt*/}, |
930 |
|
|
{8, 16, "A"/*uth*/}, |
931 |
|
|
{0, 0, 0} |
932 |
|
|
}; |
933 |
|
|
listview_ctrl_t lv; |
934 |
|
|
char buf[256], tmp[128]; |
935 |
|
|
const char *t; |
936 |
|
|
int nkeys = 0, rc = 0, i, bits; |
937 |
|
|
|
938 |
|
|
if( get_pubkey( k->keyid, &key ) ) { |
939 |
|
|
msg_box( dlg, _("Could not find key."), _("Key Edit"), MB_ERR ); |
940 |
|
|
return NULL; |
941 |
|
|
} |
942 |
|
|
nkeys = count_subkeys (key); |
943 |
|
|
if( !nkeys ) { |
944 |
|
|
msg_box( dlg, _("No subkey(s) found."), _("Key Edit"), MB_ERR ); |
945 |
|
|
return NULL; |
946 |
|
|
} |
947 |
|
|
|
948 |
|
|
rc = listview_new( &lv ); |
949 |
|
|
if( rc ) |
950 |
|
|
BUG( dlg ); |
951 |
|
|
|
952 |
|
|
lv->ctrl = GetDlgItem( dlg, IDC_KEYEDIT_KEYLIST ); |
953 |
|
|
for( i = 0; cols[i].fieldname != NULL; i++ ) |
954 |
|
|
listview_add_column( lv, &cols[i] ); |
955 |
|
|
|
956 |
|
|
for( i = 0; i < nkeys; i++ ) { |
957 |
|
|
listview_add_item( lv, "" ); |
958 |
|
|
listview_add_sub_item( lv, 0, 1, "" ); |
959 |
|
|
memset( &lvi, 0, sizeof lvi ); |
960 |
|
|
lvi.mask = LVIF_PARAM; |
961 |
|
|
lvi.lParam = (LPARAM )key; |
962 |
|
|
if( ListView_SetItem( lv->ctrl, &lvi ) == FALSE ) |
963 |
|
|
return NULL; |
964 |
|
|
} |
965 |
|
|
|
966 |
|
|
listview_set_ext_style( lv ); |
967 |
|
|
for( i = 0, sub = key->subkeys; i < nkeys; i++, sub = sub->next ) { |
968 |
|
|
memset( buf, 0, sizeof buf ); |
969 |
|
|
|
970 |
|
|
bits = sub->length; |
971 |
|
|
_snprintf( tmp, sizeof tmp-1, "%d-bit ", bits ); |
972 |
|
|
strcat( buf, tmp ); |
973 |
|
|
|
974 |
|
|
_snprintf( tmp, sizeof tmp-1, "%s", get_key_pubalgo (sub->pubkey_algo)); |
975 |
|
|
strcat( buf, tmp ); |
976 |
|
|
|
977 |
|
|
listview_add_sub_item( lv, i, 0, buf ); |
978 |
|
|
t = sub->keyid; |
979 |
|
|
if( !t ) |
980 |
|
|
t = "DEADBEEFDEADBEEF"; |
981 |
|
|
_snprintf( tmp, sizeof tmp-1, "0x%s", t+8 ); |
982 |
|
|
listview_add_sub_item( lv, i, 1, tmp ); |
983 |
|
|
|
984 |
|
|
t = get_key_created (sub->timestamp); |
985 |
|
|
if( !t ) |
986 |
|
|
t = "????-??-??"; |
987 |
|
|
listview_add_sub_item( lv, i, 2, t ); |
988 |
|
|
|
989 |
|
|
if( sub->expires ) { |
990 |
|
|
t = get_key_created (sub->expires); |
991 |
|
|
listview_add_sub_item( lv, i, 3, t ); |
992 |
|
|
} |
993 |
|
|
else |
994 |
|
|
listview_add_sub_item( lv, i, 3, _("Never") ); |
995 |
|
|
|
996 |
|
|
if( sub->expired ) |
997 |
|
|
t = _("Expired"); |
998 |
|
|
else if( sub->revoked ) |
999 |
|
|
t = _("Revoked"); |
1000 |
|
|
else |
1001 |
|
|
t = _("OK"); |
1002 |
|
|
listview_add_sub_item( lv, i, 4, t ); |
1003 |
|
|
|
1004 |
|
|
if (sub->can_certify) t = "*"; else t = ""; |
1005 |
|
|
listview_add_sub_item (lv, i, 5, t); |
1006 |
|
|
if (sub->can_sign) t = "*"; else t = ""; |
1007 |
|
|
listview_add_sub_item( lv, i, 6, t ); |
1008 |
|
|
if (sub->can_encrypt) t = "*"; else t = ""; |
1009 |
|
|
listview_add_sub_item( lv, i, 7, t ); |
1010 |
|
|
if (sub->can_authenticate) t = "*"; else t = ""; |
1011 |
|
|
listview_add_sub_item (lv, i, 8, t); |
1012 |
|
|
} |
1013 |
|
|
return lv; |
1014 |
|
|
} /* subkey_list_init */ |
1015 |
|
|
|
1016 |
|
|
|
1017 |
|
|
static listview_ctrl_t |
1018 |
|
|
userid_list_init (HWND dlg, winpt_key_t k) |
1019 |
|
|
{ |
1020 |
|
|
listview_ctrl_t lv = NULL; |
1021 |
|
|
gpgme_key_t key; |
1022 |
|
|
gpgme_key_sig_t ks; |
1023 |
|
|
gpgme_user_id_t u; |
1024 |
|
|
int nuids = 0, rc, j, u_attr; |
1025 |
|
|
struct listview_column_s cols[] = { |
1026 |
|
|
{0, 72, (char *)_("Validity")}, |
1027 |
|
|
{1, 150, (char *)_("Name")}, |
1028 |
|
|
{2, 110, (char *)_("Email")}, |
1029 |
|
|
{3, 76, (char *)_("Creation")}, |
1030 |
|
|
{0, 0, 0} |
1031 |
|
|
}; |
1032 |
|
|
const char *attr; |
1033 |
|
|
|
1034 |
|
|
if (get_pubkey( k->keyid, &key)) { |
1035 |
|
|
msg_box( dlg, _("Could not find key."), _("Key Edit"), MB_ERR ); |
1036 |
|
|
return NULL; |
1037 |
|
|
} |
1038 |
|
|
|
1039 |
|
|
nuids = count_userids (key); |
1040 |
|
|
if (!nuids) { |
1041 |
|
|
msg_box (dlg, _("No user ID(s) found."), _("Key Edit"), MB_ERR); |
1042 |
|
|
return NULL; |
1043 |
|
|
} |
1044 |
|
|
|
1045 |
|
|
rc = listview_new (&lv); |
1046 |
|
|
if( rc ) |
1047 |
|
|
BUG( dlg ); |
1048 |
|
|
lv->ctrl = GetDlgItem( dlg, IDC_KEYEDIT_UIDLIST ); |
1049 |
|
|
for( j = 0; cols[j].fieldname != NULL; j++ ) |
1050 |
|
|
listview_add_column( lv, &cols[j] ); |
1051 |
|
|
|
1052 |
|
|
for( j = 0; j < nuids; j++ ) { |
1053 |
|
|
listview_add_item( lv, " " ); |
1054 |
|
|
listview_add_sub_item( lv, 0, 1, " " ); |
1055 |
|
|
} |
1056 |
|
|
|
1057 |
|
|
listview_set_ext_style (lv); |
1058 |
|
|
for (j = 0, u=key->uids; j < nuids; u=u->next, j++) { |
1059 |
|
|
if (u->revoked) |
1060 |
|
|
attr = _("Revoked"); |
1061 |
|
|
else { |
1062 |
|
|
u_attr = (int)u->validity; |
1063 |
|
|
attr = get_key_trust2 (NULL, u_attr, 0, 0); |
1064 |
|
|
} |
1065 |
|
|
listview_add_sub_item( lv, j, 0, (char *)attr ); |
1066 |
|
|
|
1067 |
|
|
/* XXX: add comment if available */ |
1068 |
|
|
attr = u->name; |
1069 |
|
|
if (attr) { |
1070 |
|
|
char * uid = utf8_to_wincp (attr, strlen (attr)); |
1071 |
|
|
if (uid) { |
1072 |
|
|
listview_add_sub_item( lv, j, 1, uid ); |
1073 |
|
|
free( uid ); |
1074 |
|
|
} |
1075 |
|
|
} |
1076 |
|
|
else |
1077 |
|
|
listview_add_sub_item( lv, j, 1, _("Invalid user ID") ); |
1078 |
|
|
attr = u->email; |
1079 |
|
|
if (attr) |
1080 |
|
|
listview_add_sub_item (lv, j, 2, attr); |
1081 |
|
|
|
1082 |
|
|
ks = get_selfsig (u, k->keyid+2, 1); |
1083 |
|
|
if (ks) |
1084 |
|
|
listview_add_sub_item (lv, j, 3, get_key_created (ks->timestamp)); |
1085 |
|
|
} |
1086 |
|
|
if( !k->key_pair ) { |
1087 |
|
|
CheckDlgButton( dlg, IDC_KEYUID_ADD, BST_INDETERMINATE ); |
1088 |
|
|
CheckDlgButton( dlg, IDC_KEYUID_REVOKE, BST_INDETERMINATE ); |
1089 |
|
|
} |
1090 |
|
|
return lv; |
1091 |
|
|
} /* userid_list_init */ |
1092 |
|
|
|
1093 |
|
|
|
1094 |
|
|
static void |
1095 |
|
|
do_init_cmdlist( HWND dlg ) |
1096 |
|
|
{ |
1097 |
|
|
const char *cmdlist[] = { |
1098 |
|
|
"ADDKEY", |
1099 |
|
|
"ADDUID", |
1100 |
|
|
"ADDPHOTO", |
1101 |
|
|
"ADDREVOKER", |
1102 |
|
|
/*"FPR",*/ |
1103 |
|
|
"DELUID", |
1104 |
|
|
"DELKEY", |
1105 |
|
|
"DELPHOTO", |
1106 |
|
|
/*"DELSIG",*/ |
1107 |
|
|
"EXPIRE", |
1108 |
|
|
/*"PREF",*/ |
1109 |
|
|
"SHOWPREF", |
1110 |
|
|
/*"SETPREF",*/ |
1111 |
|
|
"PASSWD", |
1112 |
|
|
"PRIMARY", |
1113 |
|
|
"TRUST", |
1114 |
|
|
/*"REVSIG",*/ |
1115 |
|
|
"REVUID", |
1116 |
|
|
"REVKEY", |
1117 |
|
|
"DISABLE", |
1118 |
|
|
"ENABLE", |
1119 |
|
|
"SHOWPHOTO", |
1120 |
|
|
NULL |
1121 |
|
|
}; |
1122 |
|
|
const char * s; |
1123 |
|
|
int i = 0; |
1124 |
|
|
|
1125 |
|
|
for( i = 0; (s=cmdlist[i]); i++ ) { |
1126 |
|
|
SendDlgItemMessage( dlg, IDC_KEYEDIT_CMD, CB_ADDSTRING, 0, |
1127 |
|
|
(LPARAM)(char *)s ); |
1128 |
|
|
} |
1129 |
|
|
SendDlgItemMessage( dlg, IDC_KEYEDIT_CMD, CB_SETCURSEL, 0, 0 ); |
1130 |
|
|
} /* do_init_cmdlist */ |
1131 |
|
|
|
1132 |
|
|
|
1133 |
|
|
static int |
1134 |
|
|
is_cmd_openpgp( int cmdid ) |
1135 |
|
|
{ |
1136 |
|
|
switch( cmdid ) { |
1137 |
|
|
case CMD_ADDKEY: |
1138 |
|
|
case CMD_ADDPHOTO: |
1139 |
|
|
case CMD_ADDREVOKER: |
1140 |
|
|
case CMD_DELPHOTO: |
1141 |
|
|
/*case CMD_SHOWPHOTO:*/ |
1142 |
|
|
/*case CMD_SETPREF:*/ |
1143 |
|
|
return 1; |
1144 |
|
|
} |
1145 |
|
|
return 0; |
1146 |
|
|
} /* is_cmd_openpgp */ |
1147 |
|
|
|
1148 |
|
|
|
1149 |
|
|
static void |
1150 |
|
|
do_show_help( HWND dlg ) |
1151 |
|
|
{ |
1152 |
|
|
char helptext[2048]; |
1153 |
|
|
|
1154 |
|
|
_snprintf( helptext, sizeof helptext-1, |
1155 |
|
|
_(/*"FPR \t\tshow fingerprint\r\n"*/ |
1156 |
|
|
"ADDUID \t\tadd a user ID\r\n" |
1157 |
|
|
"ADDPHOTO \t\tadd a photo ID\r\n" |
1158 |
|
|
"DELUID \t\tdelete a user ID\r\n" |
1159 |
|
|
"ADDKEY \t\tadd a secondard key\r\n" |
1160 |
|
|
"DELKEY \t\tdelete a secondary key\r\n" |
1161 |
|
|
"ADDREVOKER\t\tadd a revocation key\r\n" |
1162 |
|
|
/*"DELSIG \t\tdelete signatures\r\n"*/ |
1163 |
|
|
"EXPIRE \t\tchange the expire date\r\n" |
1164 |
|
|
/*"PREF \t\tlist preferences (expert)\r\n" |
1165 |
|
|
"SHOWPREF \t\tlist preferences (verbose)\r\n" |
1166 |
|
|
"SETPREF \t\tset preference list\r\n"*/ |
1167 |
|
|
"UPDPREF \t\tupdated preferences\r\n" |
1168 |
|
|
"PASSWD \t\tchange the passphrase\r\n" |
1169 |
|
|
"PRIMARY \t\tflag user ID as primary\r\n" |
1170 |
|
|
"TRUST \t\tchange the ownertrust\r\n" |
1171 |
|
|
/*"REVSIG \t\trevoke signatures\r\n"*/ |
1172 |
|
|
"REVUID \t\trevoke a user ID\r\n" |
1173 |
|
|
"REVKEY \t\trevoke a secondary key\r\n" |
1174 |
|
|
"DISABLE \t\tdisable a key\r\n" |
1175 |
|
|
"ENABLE \t\tenable a key\r\n" |
1176 |
|
|
/*"SHOWPHOTO \t\tshow photo ID\r\n"*/) ); |
1177 |
|
|
msg_box( dlg, helptext, _("Key Edit Help"), MB_OK ); |
1178 |
|
|
} /* do_show_help */ |
1179 |
|
|
|
1180 |
|
|
|
1181 |
|
|
static int |
1182 |
|
|
do_editkey_delkey (winpt_key_t k, HWND dlg, listview_ctrl_t lv) |
1183 |
|
|
{ |
1184 |
|
|
gpgme_error_t err; |
1185 |
|
|
GpgKeyEdit *ke; |
1186 |
|
|
int j, id; |
1187 |
|
|
char tmp[64]; |
1188 |
|
|
|
1189 |
|
|
if (!k->key_pair) |
1190 |
|
|
return FALSE; /* XXX: shall we allow to modify non-secret keys?? */ |
1191 |
|
|
|
1192 |
|
|
if( listview_count_items( lv, 0 ) == 1 ) { |
1193 |
|
|
msg_box( dlg, _("Primary key can not be deleted!"), _("Key Edit"), MB_ERR); |
1194 |
|
|
return FALSE; |
1195 |
|
|
} |
1196 |
|
|
if( (j = listview_get_curr_pos( lv )) == -1 ) { |
1197 |
|
|
msg_box( dlg, _("Please select a key."), _("Key Edit"), MB_ERR ); |
1198 |
|
|
return FALSE; |
1199 |
|
|
} |
1200 |
|
|
if( j == 0 ) { |
1201 |
|
|
msg_box( dlg, _("Primary subkey can not be deleted!"), _("Key Edit"), MB_ERR ); |
1202 |
|
|
return FALSE; |
1203 |
|
|
} |
1204 |
|
|
|
1205 |
|
|
listview_get_item_text( lv, j, 0, tmp, sizeof tmp -1 ); |
1206 |
|
|
id = log_box( _("Key Edit"), MB_YESNO|MB_ICONWARNING, |
1207 |
|
|
_("\"Subkey %s.\"\n\n" |
1208 |
|
|
"Anything encrypted to the selected subkey will no longer\n" |
1209 |
|
|
"be able to be decrypted.\n\n" |
1210 |
|
|
"Do you really want to delete this subkey?"), tmp ); |
1211 |
|
|
if( id == IDNO ) |
1212 |
|
|
return FALSE; |
1213 |
|
|
|
1214 |
|
|
ke = new GpgKeyEdit (k->keyid); |
1215 |
|
|
if (!ke) |
1216 |
|
|
BUG (NULL); |
1217 |
|
|
err = ke->delKey (j); |
1218 |
|
|
if (err) |
1219 |
|
|
msg_box (dlg, gpgme_strerror (err), _("Delete Subkey"), MB_ERR); |
1220 |
|
|
else { |
1221 |
|
|
listview_del_item (lv, j); |
1222 |
|
|
k->update = 1; |
1223 |
|
|
status_box (dlg, _("Subkey successfully deleted."), _("GnuPG status")); |
1224 |
|
|
} |
1225 |
|
|
delete ke; |
1226 |
|
|
return err? FALSE : TRUE; |
1227 |
|
|
} /* do_editkey_delkey */ |
1228 |
|
|
|
1229 |
|
|
|
1230 |
|
|
/* Set the expiration date for the selected key in list view @lv. |
1231 |
|
|
Return value: TRUE on success. */ |
1232 |
|
|
static int |
1233 |
|
|
do_editkey_expire (winpt_key_t k, HWND dlg, listview_ctrl_t lv) |
1234 |
|
|
{ |
1235 |
|
|
gpgme_error_t err; |
1236 |
|
|
GpgKeyEdit *ke; |
1237 |
|
|
date_s udd = {0}; |
1238 |
|
|
char buf[256], * pass = NULL; |
1239 |
|
|
int j, cancel = 0; |
1240 |
|
|
|
1241 |
|
|
if (!k->key_pair) { |
1242 |
twoaday |
41 |
msg_box (dlg, _("There is no secret key available!"), _("Key Edit"), MB_ERR); |
1243 |
werner |
36 |
return FALSE; |
1244 |
|
|
} |
1245 |
twoaday |
41 |
if ((j = listview_get_curr_pos (lv)) == -1) { |
1246 |
werner |
36 |
msg_box( dlg, _("Please select a key."), _("Key Edit"), MB_ERR ); |
1247 |
|
|
return FALSE; |
1248 |
|
|
} |
1249 |
twoaday |
41 |
|
1250 |
|
|
/* If a key already expired, it is possible the user wants to |
1251 |
|
|
set a new expiration date.. */ |
1252 |
|
|
listview_get_item_text (lv, j, SUBK_COL_STATUS, buf, sizeof buf -1); |
1253 |
|
|
if (!strcmp (buf, _("Expired"))) { |
1254 |
|
|
cancel = msg_box (dlg, _("Key already expired.\n\n" |
1255 |
|
|
"Do you want to change the expiration date?"), |
1256 |
|
|
_("Key Edit"), MB_QUEST_ASK); |
1257 |
|
|
if (cancel == IDNO) |
1258 |
|
|
return FALSE; |
1259 |
|
|
cancel = 0; |
1260 |
werner |
36 |
} |
1261 |
twoaday |
41 |
|
1262 |
werner |
36 |
memset (&udd, 0, sizeof udd); |
1263 |
|
|
udd.text = _("Key Expiration Date"); |
1264 |
|
|
dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_DATE, dlg, |
1265 |
|
|
date_dlg_proc, (LPARAM)&udd, |
1266 |
|
|
_("Key Expiration Date"), IDS_WINPT_DATE); |
1267 |
|
|
if (udd.cancel == 1) |
1268 |
|
|
return FALSE; |
1269 |
|
|
if (!keygen_check_date (&udd.st)) { |
1270 |
|
|
msg_box (dlg, _("The date you have chosen lies in the past."), |
1271 |
|
|
_("Key Edit"), MB_ERR); |
1272 |
|
|
return FALSE; |
1273 |
|
|
} |
1274 |
|
|
if( k->is_protected ) { |
1275 |
twoaday |
41 |
pass = request_passphrase (_("Key Edit"), 1, &cancel); |
1276 |
|
|
if (cancel) |
1277 |
werner |
36 |
return FALSE; |
1278 |
|
|
} |
1279 |
|
|
|
1280 |
|
|
ke = new GpgKeyEdit (k->keyid); |
1281 |
|
|
if (!ke) |
1282 |
|
|
BUG (NULL); |
1283 |
|
|
if (k->is_protected) |
1284 |
|
|
ke->setPassphrase (pass); |
1285 |
|
|
err = ke->setKeyExpireDate (j, diff_time (NULL, &udd.st), true); |
1286 |
|
|
if (err) |
1287 |
|
|
msg_box (dlg, gpgme_strerror (err), _("Expire Subkey"), MB_ERR); |
1288 |
|
|
else { |
1289 |
|
|
_snprintf (buf, sizeof buf - 1, "%04d-%02d-%02d", |
1290 |
|
|
udd.st.wYear, udd.st.wMonth, udd.st.wDay); |
1291 |
|
|
listview_add_sub_item (lv, j, SUBK_COL_EXPIRES, buf); |
1292 |
|
|
k->update = 1; |
1293 |
|
|
msg_box (dlg, _("Subkey expire date successfully set."), |
1294 |
|
|
_("GnuPG status"), MB_OK); |
1295 |
|
|
} |
1296 |
|
|
sfree_if_alloc (pass); |
1297 |
|
|
delete ke; |
1298 |
|
|
return TRUE; |
1299 |
|
|
} |
1300 |
|
|
|
1301 |
|
|
|
1302 |
|
|
/* Revoke the selected key in the list view @lv. @k contains |
1303 |
|
|
control information about the global key. |
1304 |
|
|
Return value: TRUE on success. */ |
1305 |
|
|
static int |
1306 |
|
|
do_editkey_revoke (winpt_key_t k, HWND dlg, listview_ctrl_t lv) |
1307 |
|
|
{ |
1308 |
|
|
gpgme_error_t err; |
1309 |
|
|
GpgKeyEdit *ke; |
1310 |
|
|
char buf[256]; |
1311 |
|
|
char *pass = NULL; |
1312 |
|
|
int j, cancel = 0; |
1313 |
|
|
|
1314 |
|
|
if (!k->key_pair) { |
1315 |
|
|
msg_box (dlg, _("There is no secret key available!"), _("Key Edit"), MB_ERR); |
1316 |
|
|
return FALSE; |
1317 |
|
|
} |
1318 |
|
|
|
1319 |
|
|
if ((j = listview_get_curr_pos (lv)) == -1) { |
1320 |
|
|
msg_box( dlg, _("Please select a key."), _("Key Edit"), MB_ERR ); |
1321 |
|
|
return FALSE; |
1322 |
|
|
} |
1323 |
|
|
else if (listview_count_items (lv, 0) == 1) { |
1324 |
|
|
msg_box( dlg, _("No subkeys were found, if you want to revoke the\n" |
1325 |
|
|
"whole key, please use the Key Manager command directly.\n\n" |
1326 |
|
|
"This command is only available to revoke single subkeys"), |
1327 |
|
|
_("Key Edit"), MB_INFO ); |
1328 |
|
|
return FALSE; |
1329 |
|
|
} |
1330 |
|
|
|
1331 |
|
|
listview_get_item_text (lv, j, SUBK_COL_STATUS, buf, sizeof (buf)-1); |
1332 |
|
|
if (!strcmp (buf, _("Revoked"))) { |
1333 |
|
|
msg_box (dlg, _("Key already revoked."), _("Key Edit"), MB_ERR); |
1334 |
|
|
return FALSE; |
1335 |
|
|
} |
1336 |
|
|
|
1337 |
|
|
if (k->is_protected) { |
1338 |
|
|
pass = request_passphrase (_("Key Edit"), 1, &cancel); |
1339 |
|
|
if (cancel) |
1340 |
|
|
return FALSE; |
1341 |
|
|
} |
1342 |
|
|
|
1343 |
|
|
ke = new GpgKeyEdit (k->keyid); |
1344 |
|
|
if (!ke) |
1345 |
|
|
BUG (NULL); |
1346 |
|
|
if (k->is_protected) |
1347 |
|
|
ke->setPassphrase (pass); |
1348 |
|
|
err = ke->revokeSubkey (j, 0, NULL); |
1349 |
|
|
if (err) |
1350 |
|
|
msg_box( dlg, gpgme_strerror (err), _("Revoke Subkey"), MB_ERR); |
1351 |
|
|
else { |
1352 |
|
|
listview_add_sub_item (lv, j, SUBK_COL_STATUS, _("Revoked")); |
1353 |
|
|
k->update = 1; |
1354 |
|
|
msg_box( dlg, _("Subkey successfully revoked."), _("GnuPG Status"), MB_OK ); |
1355 |
|
|
} |
1356 |
|
|
sfree_if_alloc (pass); |
1357 |
|
|
delete ke; |
1358 |
|
|
return TRUE; |
1359 |
|
|
} |
1360 |
|
|
|
1361 |
|
|
|
1362 |
|
|
/* Revoked the selected userid in list view @lv. |
1363 |
|
|
Return value: TRUE on success. */ |
1364 |
|
|
int |
1365 |
|
|
do_editkey_revuid (winpt_key_t k, HWND dlg, listview_ctrl_t lv) |
1366 |
|
|
{ |
1367 |
|
|
gpgme_error_t err; |
1368 |
|
|
GpgKeyEdit *ke; |
1369 |
twoaday |
68 |
char buf[256], t[512]; |
1370 |
|
|
char *pass=NULL; |
1371 |
werner |
36 |
int cancel = 0, id = 0, j; |
1372 |
|
|
|
1373 |
|
|
if (!k->key_pair) { |
1374 |
|
|
msg_box( dlg, _("There is no secret key available!"), _("Revoke user ID"), MB_ERR ); |
1375 |
|
|
return FALSE; |
1376 |
|
|
} |
1377 |
|
|
|
1378 |
|
|
if( listview_count_items( lv, 0 ) == 1 ) { |
1379 |
|
|
msg_box( dlg, _("Key has only one user ID."), _("Key Edit"), MB_ERR ); |
1380 |
|
|
return FALSE; |
1381 |
|
|
} |
1382 |
|
|
|
1383 |
|
|
if( (j = listview_get_curr_pos( lv )) == -1 ) { |
1384 |
|
|
msg_box( dlg, _("Please select a user ID."), _("Key Edit"), MB_ERR ); |
1385 |
|
|
return FALSE; |
1386 |
|
|
} |
1387 |
|
|
|
1388 |
|
|
listview_get_item_text( lv, j, 0, buf, sizeof buf - 1 ); |
1389 |
|
|
if( strstr( buf, _("Revoked") ) ) { |
1390 |
|
|
msg_box( dlg, _("This user ID has been already revoked."), _("Key Edit"), MB_INFO ); |
1391 |
|
|
return FALSE; |
1392 |
|
|
} |
1393 |
|
|
|
1394 |
|
|
listview_get_item_text (lv, j, 1, buf, sizeof buf -1); |
1395 |
|
|
_snprintf( t, sizeof t -1, _("user ID \"%s\".\n\n" |
1396 |
|
|
"Do you really want to revoke this user ID?"), buf ); |
1397 |
|
|
if( msg_box( dlg, t, _("Key Edit"), MB_WARN_ASK) == IDNO ) |
1398 |
|
|
return FALSE; |
1399 |
|
|
if( k->is_protected ) { |
1400 |
|
|
pass = request_passphrase (_("Key Edit"), 1, &cancel); |
1401 |
twoaday |
68 |
if (cancel) |
1402 |
werner |
36 |
return FALSE; |
1403 |
|
|
} |
1404 |
|
|
listview_get_item_text (lv, j, 2, buf, sizeof (buf)-1); |
1405 |
|
|
id = do_find_userid (k->keyid, buf, NULL); |
1406 |
|
|
if (id == -1) |
1407 |
|
|
BUG (NULL); |
1408 |
|
|
|
1409 |
|
|
ke = new GpgKeyEdit (k->keyid); |
1410 |
|
|
if (!ke) |
1411 |
|
|
BUG (NULL); |
1412 |
|
|
if (k->is_protected) |
1413 |
|
|
ke->setPassphrase (pass); |
1414 |
|
|
err = ke->revokeUserid (id); |
1415 |
|
|
if (err) |
1416 |
|
|
msg_box (dlg, gpgme_strerror (err), _("Revoke Signature"), MB_ERR); |
1417 |
|
|
else { |
1418 |
|
|
listview_add_sub_item (lv, j, 0, _("Revoked")); |
1419 |
|
|
k->update = 1; |
1420 |
|
|
status_box (dlg, _("User ID successfully revoked"), _("GnuPG Status")); |
1421 |
|
|
} |
1422 |
|
|
sfree_if_alloc (pass); |
1423 |
|
|
delete ke; |
1424 |
|
|
return err? FALSE : TRUE; |
1425 |
|
|
} |
1426 |
|
|
|
1427 |
|
|
|
1428 |
|
|
static int |
1429 |
|
|
do_editkey_setpref (winpt_key_t k, HWND dlg, listview_ctrl_t lv) |
1430 |
|
|
{ |
1431 |
|
|
gpgme_error_t rc; |
1432 |
|
|
GpgKeyEdit *ke; |
1433 |
|
|
char buf[256], * pass = NULL, * prefs; |
1434 |
|
|
int j, id, cancel=0, flags=0; |
1435 |
|
|
|
1436 |
|
|
if ((j = listview_get_curr_pos (lv)) == -1) { |
1437 |
|
|
msg_box (dlg, _("Please select a user ID."), _("Key Edit"), MB_ERR); |
1438 |
|
|
return FALSE; |
1439 |
|
|
} |
1440 |
|
|
listview_get_item_text (lv, j, 2, buf, sizeof buf-1); |
1441 |
|
|
id = do_find_userid (k->keyid, buf, NULL); |
1442 |
|
|
if (id == -1) |
1443 |
|
|
BUG (dlg); |
1444 |
|
|
if (k->is_protected) { |
1445 |
|
|
pass = request_passphrase (_("Key Edit"), 1, &cancel); |
1446 |
|
|
if (cancel) |
1447 |
|
|
return FALSE; |
1448 |
|
|
} |
1449 |
|
|
|
1450 |
|
|
ke = new GpgKeyEdit (k->keyid); |
1451 |
|
|
if (!ke) |
1452 |
|
|
BUG (NULL); |
1453 |
|
|
if (k->is_protected) |
1454 |
|
|
ke->setPassphrase (pass); |
1455 |
|
|
|
1456 |
|
|
get_userid_preflist (&prefs, &flags); |
1457 |
|
|
|
1458 |
|
|
rc = ke->setUseridPreferences (id, prefs); |
1459 |
|
|
/* XXX */ |
1460 |
|
|
|
1461 |
|
|
sfree_if_alloc (pass); |
1462 |
|
|
free_if_alloc (prefs); |
1463 |
|
|
delete ke; |
1464 |
|
|
return 0; |
1465 |
|
|
} |
1466 |
|
|
|
1467 |
|
|
|
1468 |
|
|
static int |
1469 |
|
|
do_editkey_primary (winpt_key_t k, HWND dlg, listview_ctrl_t lv) |
1470 |
|
|
{ |
1471 |
|
|
gpgme_error_t err; |
1472 |
|
|
GpgKeyEdit *ke; |
1473 |
|
|
int j, id, cancel=0; |
1474 |
|
|
char buf[256], * pass = NULL; |
1475 |
|
|
|
1476 |
|
|
if (listview_count_items (lv, 0) == 1) |
1477 |
|
|
return TRUE; |
1478 |
|
|
if ((j = listview_get_curr_pos (lv)) == -1) { |
1479 |
|
|
msg_box( dlg, _("Please select a user ID."), _("Key Edit"), MB_ERR ); |
1480 |
|
|
return FALSE; |
1481 |
|
|
} |
1482 |
|
|
listview_get_item_text (lv, j, 2, buf, sizeof buf-1); |
1483 |
|
|
id = do_find_userid (k->keyid, buf, NULL); |
1484 |
|
|
if (id == -1) |
1485 |
|
|
BUG (dlg); |
1486 |
|
|
if (k->is_protected) { |
1487 |
|
|
pass = request_passphrase (_("Key Edit"), 1, &cancel); |
1488 |
|
|
if( cancel ) |
1489 |
|
|
return FALSE; |
1490 |
|
|
} |
1491 |
|
|
|
1492 |
|
|
ke = new GpgKeyEdit (k->keyid); |
1493 |
|
|
if (k->is_protected) |
1494 |
|
|
ke->setPassphrase (pass); |
1495 |
|
|
err = ke->setPrimaryUserid (id); |
1496 |
|
|
if (err) |
1497 |
|
|
msg_box (dlg, gpgme_strerror (err), _("Primary"), MB_ERR); |
1498 |
|
|
else { |
1499 |
|
|
k->update = 1; |
1500 |
|
|
status_box (dlg, _("User ID successfully flagged"), _("GnuPG Status")); |
1501 |
|
|
} |
1502 |
|
|
|
1503 |
|
|
sfree_if_alloc (pass); |
1504 |
|
|
delete ke; |
1505 |
|
|
return err? FALSE : TRUE; |
1506 |
|
|
} |
1507 |
|
|
|
1508 |
|
|
|
1509 |
|
|
static int |
1510 |
|
|
parse_preflist (HWND dlg, const char *list) |
1511 |
|
|
{ |
1512 |
|
|
char *p, buf[128] = {0}, *pbuf = buf; |
1513 |
|
|
const char *ciphers[11] = {0, "IDEA", "3DES", "CAST5", "BLOWFISH", 0, 0, "AES", "AES192", "AES256", "TWOFISH"}; |
1514 |
|
|
const char *hash[11] = {0, "MD5", "SHA1", "RMD160", 0, 0, 0, 0, "SHA256", "SHA384", "SHA512"}; |
1515 |
|
|
const char *compress[4] = {0, "ZIP", "ZLIB", "BZIP2"}; |
1516 |
|
|
int n=0; |
1517 |
|
|
|
1518 |
|
|
strncpy (buf, list, 127); |
1519 |
|
|
p = strtok (pbuf, " "); |
1520 |
|
|
while (p != NULL) { |
1521 |
|
|
int algid = atol (p+1); |
1522 |
|
|
n++; |
1523 |
|
|
switch (*p) { |
1524 |
|
|
case 'S': |
1525 |
|
|
SendDlgItemMessage (dlg, IDC_SHOWPREF_CIPHERS, LB_ADDSTRING, 0, (LPARAM)(const char*)ciphers[algid % 11]); |
1526 |
|
|
break; |
1527 |
|
|
|
1528 |
|
|
case 'H': |
1529 |
|
|
SendDlgItemMessage (dlg, IDC_SHOWPREF_HASH, LB_ADDSTRING, 0, (LPARAM)(const char*)hash[algid % 10]); |
1530 |
|
|
break; |
1531 |
|
|
|
1532 |
|
|
case 'Z': |
1533 |
|
|
SendDlgItemMessage (dlg, IDC_SHOWPREF_ZIP, LB_ADDSTRING, 0, (LPARAM)(const char*)compress[algid % 4]); |
1534 |
|
|
break; |
1535 |
|
|
|
1536 |
|
|
default: |
1537 |
|
|
n--; |
1538 |
|
|
} |
1539 |
|
|
p = strtok (NULL, " "); |
1540 |
|
|
} |
1541 |
|
|
return n; |
1542 |
|
|
} |
1543 |
|
|
|
1544 |
|
|
|
1545 |
|
|
/* Dialog box procedure to show the key preferences. */ |
1546 |
|
|
BOOL CALLBACK |
1547 |
|
|
showpref_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
1548 |
|
|
{ |
1549 |
|
|
static keyedit_callback_s *cb = NULL; |
1550 |
|
|
gpg_uid_info_t inf=NULL; |
1551 |
|
|
char buf[128]; |
1552 |
|
|
int pos; |
1553 |
|
|
|
1554 |
|
|
switch (msg) { |
1555 |
|
|
case WM_INITDIALOG: |
1556 |
|
|
cb = (keyedit_callback_s *)lparam; |
1557 |
|
|
if (cb == NULL) |
1558 |
|
|
BUG (dlg); |
1559 |
|
|
listview_get_item_text (cb->lv, listview_get_curr_pos (cb->lv), 2, buf, DIM (buf)-1); |
1560 |
|
|
SetDlgItemText (dlg, IDC_SHOWPREF_INFO, buf); |
1561 |
|
|
pos = do_find_userid (((winpt_key_t)cb->opaque)->keyid, buf, &inf); |
1562 |
|
|
if (inf) { |
1563 |
|
|
const char *prefs = inf->prefs; |
1564 |
|
|
if (prefs && *prefs) { |
1565 |
|
|
if (parse_preflist (dlg, prefs) <= 0) |
1566 |
|
|
pos = -1; |
1567 |
|
|
} |
1568 |
|
|
else |
1569 |
|
|
pos = -1; |
1570 |
|
|
gpg_uid_info_release (inf); |
1571 |
|
|
if (pos == -1) { |
1572 |
|
|
msg_box (dlg, _("No preferences available."), _("Key Edit"), MB_ERR); |
1573 |
|
|
EndDialog (dlg, TRUE); |
1574 |
|
|
} |
1575 |
|
|
if (inf->flags.mdc) |
1576 |
|
|
CheckDlgButton (dlg, IDC_SHOWPREF_MDC, BST_CHECKED); |
1577 |
|
|
} |
1578 |
|
|
SetWindowText (dlg, _("Key Preferences")); |
1579 |
|
|
SetForegroundWindow (dlg); |
1580 |
|
|
break; |
1581 |
|
|
|
1582 |
|
|
case WM_COMMAND: |
1583 |
|
|
switch (LOWORD (wparam)) { |
1584 |
|
|
case IDOK: |
1585 |
|
|
EndDialog (dlg, TRUE); |
1586 |
|
|
break; |
1587 |
|
|
} |
1588 |
|
|
break; |
1589 |
|
|
} |
1590 |
|
|
return FALSE; |
1591 |
|
|
} |
1592 |
|
|
|
1593 |
|
|
|
1594 |
|
|
static int |
1595 |
|
|
do_editkey_showpref (winpt_key_t k, HWND dlg, listview_ctrl_t lv) |
1596 |
|
|
{ |
1597 |
|
|
struct keyedit_callback_s cb; |
1598 |
|
|
|
1599 |
|
|
if (k->is_v3) |
1600 |
|
|
return TRUE; |
1601 |
|
|
|
1602 |
|
|
if (listview_get_curr_pos (lv) == -1) { |
1603 |
|
|
msg_box (dlg, _("Please select a user ID."), _("Key Edit"), MB_ERR); |
1604 |
|
|
return FALSE; |
1605 |
|
|
} |
1606 |
|
|
|
1607 |
|
|
memset (&cb, 0, sizeof (cb)); |
1608 |
|
|
cb.lv = lv; |
1609 |
|
|
cb.opaque = k; |
1610 |
|
|
DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_KEYEDIT_SHOWPREF, dlg, |
1611 |
|
|
showpref_dlg_proc, (LPARAM)&cb); |
1612 |
|
|
return TRUE; |
1613 |
|
|
} |
1614 |
|
|
|
1615 |
|
|
|
1616 |
|
|
static int |
1617 |
|
|
do_editkey_deluid (winpt_key_t k, HWND dlg, listview_ctrl_t lv) |
1618 |
|
|
{ |
1619 |
|
|
gpgme_error_t err; |
1620 |
|
|
GpgKeyEdit *ke; |
1621 |
|
|
char buf[256], t[512]; |
1622 |
|
|
int j, id = 0; |
1623 |
|
|
|
1624 |
|
|
if (!k->key_pair) |
1625 |
|
|
return FALSE; /* XXX: see do_editkey_delsubkey */ |
1626 |
|
|
|
1627 |
|
|
if( listview_count_items( lv, 0 ) == 1 ) { |
1628 |
|
|
msg_box( dlg, _("Primary user ID can not be deleted!"), _("Key Edit"), MB_ERR ); |
1629 |
|
|
return FALSE; |
1630 |
|
|
} |
1631 |
|
|
if( (j = listview_get_curr_pos( lv )) == -1 ) { |
1632 |
|
|
msg_box( dlg, _("Please select a user ID."), _("Key Edit"), MB_ERR ); |
1633 |
|
|
return FALSE; |
1634 |
|
|
} |
1635 |
|
|
|
1636 |
|
|
/* XXX: add a hint that also all signatures will be deleted? */ |
1637 |
|
|
listview_get_item_text( lv, j, 1, buf, DIM(buf) -1 ); |
1638 |
|
|
_snprintf( t, DIM (t)-1, _("user ID \"%s\".\n\n" |
1639 |
|
|
"Do you really want to delete this user ID?"), |
1640 |
|
|
buf); |
1641 |
|
|
if( msg_box( dlg, t, _("Key Edit"), MB_YESNO|MB_ICONWARNING ) == IDNO ) |
1642 |
|
|
return FALSE; |
1643 |
|
|
|
1644 |
|
|
listview_get_item_text (lv, j, 2, buf, DIM (buf)-1); |
1645 |
|
|
id = do_find_userid (k->keyid, buf, NULL); |
1646 |
|
|
if (id == -1) |
1647 |
|
|
BUG (dlg); |
1648 |
|
|
|
1649 |
|
|
ke = new GpgKeyEdit (k->keyid); |
1650 |
|
|
if (!ke) |
1651 |
|
|
BUG (NULL); |
1652 |
|
|
|
1653 |
|
|
err = ke->delUserid (id); |
1654 |
|
|
if( err ) |
1655 |
|
|
msg_box( dlg, gpgme_strerror (err), _("Delete user ID"), MB_ERR ); |
1656 |
|
|
else { |
1657 |
|
|
listview_del_item( lv, j ); |
1658 |
|
|
k->update = 1; |
1659 |
|
|
status_box( dlg, _("User ID successfully deleted"), _("GnuPG Status") ); |
1660 |
|
|
} |
1661 |
|
|
delete ke; |
1662 |
|
|
return err? FALSE : TRUE; |
1663 |
|
|
} /* do_editkey_deluid */ |
1664 |
|
|
|
1665 |
|
|
|
1666 |
|
|
|
1667 |
|
|
static BOOL CALLBACK |
1668 |
|
|
subkey_subclass_proc( HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam ) |
1669 |
|
|
{ |
1670 |
|
|
switch( msg ) { |
1671 |
|
|
case WM_KEYUP: |
1672 |
|
|
int virt_key = (int)wparam; |
1673 |
|
|
switch( virt_key ) { |
1674 |
|
|
case VK_DELETE: |
1675 |
|
|
SendDlgItemMessage( keyedit_subkey_proc.dlg, IDC_KEYEDIT_CMD, |
1676 |
|
|
CB_SETCURSEL, CMD_DELKEY, 0 ); |
1677 |
|
|
send_cmd_id( keyedit_subkey_proc.dlg, IDOK ); |
1678 |
|
|
break; |
1679 |
|
|
|
1680 |
|
|
case VK_INSERT: |
1681 |
|
|
SendDlgItemMessage( keyedit_subkey_proc.dlg, IDC_KEYEDIT_CMD, |
1682 |
|
|
CB_SETCURSEL, CMD_ADDKEY, 0 ); |
1683 |
|
|
send_cmd_id( keyedit_subkey_proc.dlg, IDOK ); |
1684 |
|
|
break; |
1685 |
|
|
} |
1686 |
|
|
} |
1687 |
|
|
return CallWindowProc( keyedit_subkey_proc.old, dlg, msg, wparam, lparam ); |
1688 |
|
|
} /* subkey_subclass_proc */ |
1689 |
|
|
|
1690 |
|
|
|
1691 |
|
|
static BOOL CALLBACK |
1692 |
|
|
uid_subclass_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
1693 |
|
|
{ |
1694 |
|
|
switch( msg ) { |
1695 |
|
|
case WM_KEYUP: |
1696 |
|
|
int virt_key = (int)wparam; |
1697 |
|
|
switch (virt_key) { |
1698 |
|
|
case VK_DELETE: |
1699 |
|
|
SendDlgItemMessage (keyedit_uid_proc.dlg, IDC_KEYEDIT_CMD, |
1700 |
|
|
CB_SETCURSEL, CMD_DELUID, 0); |
1701 |
|
|
send_cmd_id (keyedit_uid_proc.dlg, IDOK); |
1702 |
|
|
break; |
1703 |
|
|
|
1704 |
|
|
case VK_INSERT: |
1705 |
|
|
SendDlgItemMessage (keyedit_uid_proc.dlg, IDC_KEYEDIT_CMD, |
1706 |
|
|
CB_SETCURSEL, CMD_ADDUID, 0); |
1707 |
|
|
send_cmd_id (keyedit_uid_proc.dlg, IDOK); |
1708 |
|
|
break; |
1709 |
|
|
} |
1710 |
|
|
} |
1711 |
|
|
return CallWindowProc( keyedit_uid_proc.old, dlg, msg, wparam, lparam ); |
1712 |
|
|
} /* uid_subclass_proc */ |
1713 |
|
|
|
1714 |
|
|
|
1715 |
|
|
BOOL CALLBACK |
1716 |
|
|
keyedit_main_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
1717 |
|
|
{ |
1718 |
|
|
static winpt_key_t k; |
1719 |
|
|
static listview_ctrl_t lvsub = NULL, lvuid = NULL; |
1720 |
|
|
int cmd, idxsub = 0; |
1721 |
|
|
HWND item; |
1722 |
|
|
|
1723 |
|
|
switch( msg ) { |
1724 |
|
|
case WM_INITDIALOG: |
1725 |
|
|
k = (winpt_key_t)lparam; |
1726 |
|
|
if (!k) |
1727 |
|
|
BUG (NULL); |
1728 |
|
|
do_init_cmdlist (dlg); |
1729 |
|
|
lvsub = subkey_list_init (dlg, k); |
1730 |
|
|
if( !lvsub ) |
1731 |
|
|
BUG( NULL ); |
1732 |
|
|
lvuid = userid_list_init (dlg, k); |
1733 |
|
|
if( !lvuid ) |
1734 |
|
|
BUG( NULL ); |
1735 |
|
|
item = GetDlgItem( dlg, IDC_KEYEDIT_KEYLIST ); |
1736 |
|
|
keyedit_subkey_proc.dlg = dlg; |
1737 |
|
|
keyedit_subkey_proc.current = (WNDPROC)subkey_subclass_proc; |
1738 |
|
|
keyedit_subkey_proc.old = (WNDPROC)GetWindowLong( item, GWL_WNDPROC ); |
1739 |
|
|
if( keyedit_subkey_proc.old ) { |
1740 |
|
|
if( !SetWindowLong( item, GWL_WNDPROC, (LONG)keyedit_subkey_proc.current ) ) { |
1741 |
|
|
msg_box( dlg, _("Could not set subkey window procedure."), _("Key Edit"), MB_ERR ); |
1742 |
|
|
BUG( NULL ); |
1743 |
|
|
} |
1744 |
|
|
} |
1745 |
|
|
item = GetDlgItem( dlg, IDC_KEYEDIT_UIDLIST ); |
1746 |
|
|
keyedit_uid_proc.dlg = dlg; |
1747 |
|
|
keyedit_uid_proc.current = (WNDPROC)uid_subclass_proc; |
1748 |
|
|
keyedit_uid_proc.old = (WNDPROC)GetWindowLong( item, GWL_WNDPROC ); |
1749 |
|
|
if( keyedit_uid_proc.old ) { |
1750 |
|
|
if( !SetWindowLong( item, GWL_WNDPROC, (LONG)keyedit_uid_proc.current ) ) { |
1751 |
|
|
msg_box( dlg, _("Could not set user ID window procedure."), _("Key Edit"), MB_ERR ); |
1752 |
|
|
BUG( NULL ); |
1753 |
|
|
} |
1754 |
|
|
} |
1755 |
|
|
if (!k->key_pair) { |
1756 |
|
|
EnableWindow (GetDlgItem (dlg, IDC_KEYEDIT_CMD), FALSE); |
1757 |
|
|
EnableWindow (GetDlgItem (dlg, IDOK), FALSE); |
1758 |
|
|
} |
1759 |
|
|
SetDlgItemText (dlg, IDC_KEYEDIT_CMDINF, _("Command>")); |
1760 |
twoaday |
88 |
SetDlgItemText (dlg, IDCANCEL, _("&Exit")); |
1761 |
|
|
SetDlgItemText (dlg, IDC_KEYEDIT_HELP, _("&Help")); |
1762 |
|
|
SetWindowText (dlg, _("Key Edit")); |
1763 |
|
|
|
1764 |
werner |
36 |
SetForegroundWindow( dlg ); |
1765 |
|
|
center_window( dlg, NULL ); |
1766 |
|
|
return TRUE; |
1767 |
|
|
|
1768 |
|
|
case WM_DESTROY: |
1769 |
|
|
if( lvsub ) { |
1770 |
|
|
listview_release( lvsub ); |
1771 |
|
|
lvsub = NULL; |
1772 |
|
|
} |
1773 |
|
|
if( lvuid ) { |
1774 |
|
|
listview_release( lvuid ); |
1775 |
|
|
lvuid = NULL; |
1776 |
|
|
} |
1777 |
|
|
break; |
1778 |
|
|
|
1779 |
|
|
case WM_NOTIFY: |
1780 |
|
|
NMHDR * notify; |
1781 |
|
|
notify = (NMHDR *)lparam; |
1782 |
|
|
if (notify && notify->code == NM_DBLCLK && |
1783 |
|
|
notify->idFrom == IDC_KEYEDIT_UIDLIST) |
1784 |
|
|
do_editkey_showpref (k, dlg, lvuid); |
1785 |
|
|
break; |
1786 |
|
|
|
1787 |
|
|
case WM_COMMAND: |
1788 |
|
|
switch( LOWORD( wparam ) ) { |
1789 |
|
|
case IDOK: |
1790 |
|
|
cmd = SendDlgItemMessage (dlg, IDC_KEYEDIT_CMD, CB_GETCURSEL, 0, 0); |
1791 |
|
|
if (cmd == LB_ERR) { |
1792 |
|
|
msg_box( dlg, _("Please select a command."), _("Key Edit"), MB_INFO ); |
1793 |
|
|
return FALSE; |
1794 |
|
|
} |
1795 |
|
|
idxsub = listview_get_curr_pos (lvsub); |
1796 |
|
|
if (k->is_v3 && is_cmd_openpgp (cmd)) { |
1797 |
|
|
msg_box (dlg, _("This command cannot be used with PGP 2 (v3) keys.\n"), |
1798 |
|
|
_("Key Edit"), MB_ERR); |
1799 |
|
|
return FALSE; |
1800 |
|
|
} |
1801 |
|
|
switch (cmd) { |
1802 |
|
|
case CMD_SHOWPREF: do_editkey_showpref (k, dlg, lvuid); break; |
1803 |
|
|
case CMD_DELKEY: do_editkey_delkey (k, dlg, lvsub); break; |
1804 |
|
|
case CMD_ADDKEY: keyedit_add_subkey (k, dlg, lvsub); break; |
1805 |
|
|
case CMD_EXPIRE: do_editkey_expire (k, dlg, lvsub); break; |
1806 |
|
|
case CMD_REVKEY: do_editkey_revoke (k, dlg, lvsub); break; |
1807 |
|
|
/*case CMD_SETPREF:do_editkey_setpref( k, dlg, lvuid ); break;*/ |
1808 |
|
|
case CMD_ADDUID: keyedit_add_userid( k, dlg, lvuid ); break; |
1809 |
|
|
case CMD_ADDREVOKER: keyedit_add_revoker( k, dlg ); break; |
1810 |
|
|
case CMD_ADDPHOTO: keyedit_add_photo( k, dlg ); break; |
1811 |
|
|
case CMD_REVUID: do_editkey_revuid( k, dlg, lvuid ); break; |
1812 |
|
|
case CMD_DELUID: do_editkey_deluid( k, dlg, lvuid ); break; |
1813 |
|
|
case CMD_PASSWD: keyedit_change_passwd( k, dlg ); break; |
1814 |
|
|
case CMD_PRIMARY: do_editkey_primary( k, dlg, lvuid ); break; |
1815 |
|
|
case CMD_ENABLE: km_enable_disable_key( lvsub, dlg, idxsub, 1 ); break; |
1816 |
|
|
case CMD_DISABLE: km_enable_disable_key( lvsub, dlg, idxsub, 0 ); break; |
1817 |
|
|
} |
1818 |
|
|
break; |
1819 |
|
|
|
1820 |
|
|
case IDCANCEL: |
1821 |
|
|
EndDialog (dlg, FALSE); |
1822 |
|
|
break; |
1823 |
|
|
|
1824 |
|
|
case IDC_KEYEDIT_HELP: |
1825 |
|
|
do_show_help (dlg); |
1826 |
|
|
break; |
1827 |
|
|
} |
1828 |
|
|
break; |
1829 |
|
|
} |
1830 |
|
|
return FALSE; |
1831 |
werner |
42 |
} /* keyedit_main_dlg_proc */ |