/[winpt]/trunk/Src/wptKeyEditDlgs.cpp
ViewVC logotype

Contents of /trunk/Src/wptKeyEditDlgs.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 19 - (show annotations)
Fri May 20 08:39:15 2005 UTC (19 years, 9 months ago) by twoaday
File size: 53334 byte(s)
2005-05-09 Timo Schulz  <twoaday@freakmail.de>
                                                                                  
        * wptCommonDlg.cpp (http_file_dlg_proc): Renamed to..
        (http_dlg_proc): ..this.
        (get_keyserver_URL_dlg): New.
        (check_URL): New.
        * wptKeyEditDlgs.cpp (keyedit_set_pref_keyserver): New.
        (keyedit_main_dlg_proc): Avoid massive keycache reloads, just reload
        the single key.
        * wptKeyRevokersDlg.cpp (key_revokers_dlg_proc): Show the key properties
        of the selected desig. revoker.
        * wptVerifyList.cpp (verlist_build): Increase the column size of 'keyid'.
        * wptGPGME.cpp (keycache_update): New.
        * wptKeySigDlg.cpp (keysig_dlg_proc): Update the key if a signature
        was deleted.
        * wptKeyManagerDlg.cpp (keymanager_dlg_proc): Zeroing the key struct
        before we set any values.
                                                                                  

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26