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

Annotation of /trunk/Src/wptKeyEditDlgs.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 16 - (hide annotations)
Mon May 9 08:54:21 2005 UTC (19 years, 9 months ago) by twoaday
File size: 52078 byte(s)
2005-05-03  Timo Schulz  <twoaday@freakmail.de>
 
        * wptFileManager.cpp (fm_parse_command_line): Handle
        'SYMKEYENC' files. Thanks to the user who reported it.
        * wptKeyEditDlgs.cpp (do_find_userid): Optionally return the context.
        (showpref_dlg_proc): New.
        (keyedit_main_dlg_proc): Support SHOWPREF.
        (userid_list_init): New field 'Email'. Split userID into 'Name' + 'Email'.
        (do_add_new_userid): Adjust for new ListView.
        (do_find_userid): Use email for searching.
        (parse_preflist): New.
 

1 twoaday 2 /* wptKeyEditDlgs.cpp - GPG key edit dialogs
2 twoaday 6 * Copyright (C) 2002-2005 Timo Schulz
3 twoaday 2 *
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 twoaday 16 /*CMD_PREF,*/
51 twoaday 2 CMD_SHOWPREF,
52 twoaday 16 /*CMD_SETPREF,*/
53 twoaday 2 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 twoaday 16 do_add_new_userid (listview_ctrl_t lv, const char * name, const char *email,
125 twoaday 2 const char * comment )
126     {
127     char * p;
128     size_t n;
129    
130 twoaday 16 n = strlen (name) + strlen (email) + 16;
131     if (comment)
132     n += strlen (comment);
133 twoaday 2 p = new char[n+1];
134 twoaday 16 if (!p)
135 twoaday 2 BUG( NULL );
136 twoaday 16 if (comment)
137     sprintf (p, "%s (%s)", name, comment);
138 twoaday 2 else
139 twoaday 16 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 twoaday 2 } /* 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 twoaday 12 int n;
156 twoaday 2
157     expdate = keygen->expire? get_key_expire_date (keygen->expire) : _("Never");
158 twoaday 12 _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 twoaday 2 else s = _("OK");
171 twoaday 12 listview_add_sub_item (lv, n, 4, s);
172 twoaday 2 } /* do_add_new_subkey */
173    
174    
175     static int
176 twoaday 16 do_find_userid (const char * keyid, const char * name, gpgme_uidinfo_t *r_inf)
177 twoaday 2 {
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 twoaday 16 if (err) {
189 twoaday 2 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 twoaday 16 nitems = gpgme_editkey_count_items (inf);
195     while (nitems--) {
196     s = gpgme_editkey_get_string_attr (inf, GPGME_ATTR_EMAIL, nitems);
197 twoaday 2 if (!s)
198     continue;
199 twoaday 16
200     if (!strcmp (s, name)) {
201 twoaday 2 pos = gpgme_editkey_get_ulong_attr (inf, GPGME_ATTR_LEVEL, nitems);
202     break;
203     }
204     }
205    
206 twoaday 16 if (r_inf)
207     *r_inf = inf;
208     else
209     gpgme_uid_info_release (inf);
210 twoaday 2 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     keycache_set_reload( 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     msg_box( dlg, _("Revoker successfully addded."), _("GnuPG Status"), MB_OK );
371     keycache_set_reload( 1 );
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 twoaday 16 free (utf8_name);
446     if (ctx->lv)
447     do_add_new_userid (ctx->lv, name, email, rc?comment : NULL);
448 twoaday 2 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 twoaday 12 keyedit_addsubkey_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
465 twoaday 2 {
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 twoaday 12 SetDlgItemInt( dlg, IDC_ADDSUBKEY_SIZE, DFAULT_KEYSIZE, FALSE );
492 twoaday 2 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 twoaday 6 case 1: index = 4; break;
509     case 2: index = 5; break;
510     case 3: index = 6; break;
511 twoaday 2 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 twoaday 12 else if (index == 2 && size != 1024) {
525 twoaday 2 msg_box( dlg,_("DSS uses a fixed keysize of 1024. Size changed."), _("Add Subkey"), MB_INFO );
526     size = 1024;
527     }
528 twoaday 12 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 twoaday 2 }
538 twoaday 12 else if (size < 1024) {
539 twoaday 2 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 twoaday 12 valid = GetDlgItemInt (dlg, IDC_ADDSUBKEY_VALID, NULL, TRUE);
544     if (valid < 0) {
545 twoaday 2 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 twoaday 6 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 twoaday 2 }
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 twoaday 16 if (!k->key_pair) {
588 twoaday 2 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     msg_box(dlg, _("User ID successfully added"), _("GnuPG Status"), MB_OK );
625     keycache_set_reload( 1 );
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 twoaday 12 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 twoaday 2 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 twoaday 12 memset (&keygen, 0, sizeof (keygen));
688     memset (&cb, 0, sizeof (cb));
689 twoaday 2 cb.ek = ek;
690 twoaday 12 cb.pass = k->is_protected? pass : NULL;
691 twoaday 2 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 twoaday 12 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 twoaday 2 keygen_cb_dlg_create ();
708    
709 twoaday 12 ec = gpgme_op_editkey (ctx, k->keyid);
710     keygen.fpr = get_subkey_fingerprint (ctx, k->keyid);
711 twoaday 2 keygen_cb_dlg_destroy ();
712     keygen_cb (NULL, NULL, 0, 0, 0); /* flush */
713 twoaday 12 if (ec)
714     gpgme_show_error (dlg, ec, ctx, _("Add Subkey"), MB_ERR);
715 twoaday 2 else {
716 twoaday 12 msg_box (dlg, _("Subkey successfully added."), _("GnuPG Status"), MB_OK);
717     if (lv)
718     do_add_new_subkey (lv, &keygen, k->flags);
719     keycache_set_reload (1);
720 twoaday 2 }
721 twoaday 12 free_if_alloc (pass);
722     gpgme_editkey_release (ek);
723     gpgme_release (ctx);
724 twoaday 2
725     return ec? FALSE : TRUE;
726     } /* keyedit_add_subkey */
727    
728    
729     BOOL
730     keyedit_add_photo( winpt_key_t k, HWND dlg )
731     {
732     if( !k->key_pair ) {
733     msg_box( dlg, _("There is no secret key available!"), _("Add Photo"), MB_ERR );
734     return FALSE;
735     }
736     DialogBoxParam( glob_hinst, (LPCTSTR)IDD_WINPT_KEYEDIT_ADDPHOTO, dlg,
737     keyedit_addphoto_dlg_proc, (LPARAM)k );
738     return TRUE;
739     } /* keyedit_add_photo */
740    
741    
742     BOOL
743     keyedit_add_revoker (winpt_key_t k, HWND dlg)
744     {
745     if( !k->key_pair ) {
746     msg_box( dlg, _("There is no secret key available!"), _("Add Revoker"), MB_ERR );
747     return FALSE;
748     }
749     DialogBoxParam( glob_hinst, (LPCTSTR)IDD_WINPT_KEYEDIT_ADDREV, dlg,
750     keyedit_addrevoker_dlg_proc, (LPARAM)k );
751     return TRUE;
752     } /* keyedit_add_revoker */
753    
754    
755     static int
756     is_idea_protect_algo( const char * keyid )
757     {
758     gpgme_key_t key;
759     const char * sym_prefs;
760     size_t n;
761    
762     if( get_pubkey( keyid, &key ) )
763     BUG( NULL );
764     sym_prefs = gpgme_key_get_string_attr( key, GPGME_ATTR_KEY_SYMPREFS, NULL, 0 );
765     if( !sym_prefs )
766     return 1; /* assume that only v3 keys have no symmetric cipher preferences
767     and thus IDEA is explicit. */
768     for( n = 0; sym_prefs[n]; n++ )
769     ;
770     if( (n == 0 || n == 1) && *sym_prefs == 0x01 )
771     return 1;
772     return 0;
773     } /* is_idea_protect_algo */
774    
775    
776     BOOL
777     keyedit_change_passwd( winpt_key_t k, HWND dlg )
778     {
779     gpgme_error_t ec;
780     gpgme_ctx_t ctx;
781     gpgme_editkey_t ek;
782     char * old_pass = NULL, * new_pass = NULL;
783     int cancel = 0;
784    
785     if( !k->key_pair ) {
786     msg_box( dlg, _("There is no secret key available!"), _("Key Edit"), MB_ERR );
787     return FALSE;
788     }
789    
790     if( !idea_available && is_idea_protect_algo( k->keyid ) ) {
791     msg_box( dlg, _("Cannot change passphrase because the key\n"
792     "is protected with the IDEA encryption algorithm."),
793     _("Key Edit"), MB_ERR );
794     return FALSE;
795     }
796    
797     if( k->is_protected ) {
798     old_pass = request_passphrase( _("Current (old) Passphrase"), 1, &cancel );
799     if( cancel )
800     return FALSE;
801     }
802     new_pass = request_passphrase( _("New Passphrase" ), 1, &cancel );
803     if( cancel ) {
804     free_if_alloc( old_pass );
805     return FALSE;
806     }
807    
808     if( is_8bit_string( new_pass ) ) {
809     msg_box( dlg, _("The passphrase contains 8-bit characters.\n"
810     "It is not suggested to use charset specific characters."),
811     _("Key Edit"), MB_ERR );
812     free_if_alloc( old_pass );
813     free_if_alloc( new_pass );
814     return FALSE;
815     }
816    
817     ec = gpgme_new( &ctx );
818     if( !ec )
819     ec = gpgme_editkey_new( &ek );
820     if( ec )
821     BUG( NULL );
822     gpgme_enable_logging( ctx );
823     gpgme_editkey_passwd_set( ek, k->is_protected? old_pass : NULL, new_pass, 0 );
824     gpgme_set_edit_ctx( ctx, ek, GPGME_EDITKEY_PASSWD );
825     ec = gpgme_op_editkey( ctx, k->keyid );
826     if( ec )
827     gpgme_show_error( dlg, ec, ctx, _("Change Passwd"), MB_ERR );
828     else
829     msg_box( dlg, _("Passphrase successfully changed."), _("GnuPG status"), MB_OK );
830     free_if_alloc( old_pass );
831     free_if_alloc( new_pass );
832     gpgme_editkey_release( ek );
833     gpgme_release( ctx );
834     return TRUE;
835     } /* keyedit_change_passwd */
836    
837    
838     listview_ctrl_t
839     subkey_list_init( HWND dlg, winpt_key_t k )
840     {
841     LV_ITEM lvi;
842     gpgme_key_t key;
843     struct listview_column_s cols[] = {
844     {0, 80, (char *)_("Description")},
845     {1, 78, (char *)_("Key ID")},
846     {2, 66, (char *)_("Creation")},
847     {3, 66, (char *)_("Expires")},
848     {4, 64, (char *)_("Status")},
849     {5, 16, "C"/*ertify*/},
850     {6, 16, "S"/*ign*/},
851     {7, 16, "E"/*ncrypt*/},
852     {8, 16, "A"/*uth*/},
853     {0, 0, 0}
854     };
855     listview_ctrl_t lv;
856     char buf[256], tmp[128];
857     const char *t;
858     int nkeys = 0, rc = 0, i, bits, j;
859    
860     if( get_pubkey( k->keyid, &key ) ) {
861     msg_box( dlg, _("Could not find key."), _("Key Edit"), MB_ERR );
862     return NULL;
863     }
864    
865     nkeys = gpgme_key_count_items( key, GPGME_ATTR_KEYID );
866     if( !nkeys ) {
867     msg_box( dlg, _("No subkey(s) found."), _("Key Edit"), MB_ERR );
868     return NULL;
869     }
870    
871     rc = listview_new( &lv );
872     if( rc )
873     BUG( dlg );
874    
875     lv->ctrl = GetDlgItem( dlg, IDC_KEYEDIT_KEYLIST );
876     for( i = 0; cols[i].fieldname != NULL; i++ )
877     listview_add_column( lv, &cols[i] );
878    
879     for( i = 0; i < nkeys; i++ ) {
880     listview_add_item( lv, "" );
881     listview_add_sub_item( lv, 0, 1, "" );
882     memset( &lvi, 0, sizeof lvi );
883     lvi.mask = LVIF_PARAM;
884     lvi.lParam = (LPARAM )key;
885     if( ListView_SetItem( lv->ctrl, &lvi ) == FALSE )
886     return NULL;
887     }
888    
889     listview_set_ext_style( lv );
890     for( i = 0; i < nkeys; i++ ) {
891     memset( buf, 0, sizeof buf );
892    
893     bits = gpgme_key_get_ulong_attr( key, GPGME_ATTR_LEN, NULL, i );
894     _snprintf( tmp, sizeof tmp-1, "%d-bit ", bits );
895     strcat( buf, tmp );
896    
897     j = gpgme_key_get_ulong_attr( key, GPGME_ATTR_ALGO, NULL, i );
898     t = gpgme_key_expand_attr( GPGME_ATTR_ALGO, j );
899     _snprintf( tmp, sizeof tmp-1, "%s", t );
900     strcat( buf, tmp );
901    
902     listview_add_sub_item( lv, i, 0, buf );
903     t = gpgme_key_get_string_attr( key, GPGME_ATTR_KEYID, NULL, i );
904     if( !t )
905     t = "DEADBEEFDEADBEEF";
906     _snprintf( tmp, sizeof tmp-1, "0x%s", t+8 );
907     listview_add_sub_item( lv, i, 1, tmp );
908    
909     j = gpgme_key_get_ulong_attr( key, GPGME_ATTR_CREATED, NULL, i );
910     t = gpgme_key_expand_attr( GPGME_ATTR_CREATED, j );
911     if( !t )
912     t = "????-??-??";
913     listview_add_sub_item( lv, i, 2, t );
914    
915     j = gpgme_key_get_ulong_attr( key, GPGME_ATTR_EXPIRES, NULL, i );
916     if( j ) {
917     t = gpgme_key_expand_attr( GPGME_ATTR_CREATED, j );
918     listview_add_sub_item( lv, i, 3, t );
919     }
920     else
921     listview_add_sub_item( lv, i, 3, _("Never") );
922    
923     if( gpgme_key_get_ulong_attr(key, GPGME_ATTR_KEY_EXPIRED, NULL, i ) )
924     t = _("Expired");
925     else if( gpgme_key_get_ulong_attr( key, GPGME_ATTR_KEY_REVOKED, NULL, i ) )
926     t = _("Revoked");
927     else
928     t = _("OK");
929     listview_add_sub_item( lv, i, 4, t );
930    
931     gpgme_key_get_cability( key, GPGME_ATTR_CAN_CERTIFY, i )?
932     t = "*" : t = "";
933     listview_add_sub_item( lv, i, 5, t );
934     gpgme_key_get_cability( key, GPGME_ATTR_CAN_SIGN, i )?
935     t = "*" : t = "";
936     listview_add_sub_item( lv, i, 6, t );
937     gpgme_key_get_cability( key, GPGME_ATTR_CAN_ENCRYPT, i )?
938     t = "*" : t = "";
939     listview_add_sub_item( lv, i, 7, t );
940    
941     gpgme_key_get_cability (key, GPGME_ATTR_CAN_AUTH, i)?
942     t = "*" : t = "";
943     listview_add_sub_item (lv, i, 8, t);
944     }
945     return lv;
946     } /* subkey_list_init */
947    
948    
949     static listview_ctrl_t
950     userid_list_init (HWND dlg, winpt_key_t k)
951     {
952     listview_ctrl_t lv = NULL;
953     gpgme_key_t key;
954     int nuids = 0, rc, j, u_attr;
955     struct listview_column_s cols[] = {
956     {0, 72, (char *)_("Validity")},
957 twoaday 16 {1, 180, (char *)_("Name")},
958     {2, 90, (char *)_("Email")},
959     {3, 76, (char *)_("Creation")},
960 twoaday 2 {0, 0, 0}
961     };
962     const char *attr;
963    
964 twoaday 16 if (get_pubkey( k->keyid, &key)) {
965 twoaday 2 msg_box( dlg, _("Could not find key."), _("Key Edit"), MB_ERR );
966     return NULL;
967     }
968    
969 twoaday 16 nuids = gpgme_key_count_items (key, GPGME_ATTR_USERID);
970     if (!nuids) {
971     msg_box (dlg, _("No user ID(s) found."), _("Key Edit"), MB_ERR);
972 twoaday 2 return NULL;
973     }
974    
975 twoaday 16 rc = listview_new (&lv);
976 twoaday 2 if( rc )
977     BUG( dlg );
978     lv->ctrl = GetDlgItem( dlg, IDC_KEYEDIT_UIDLIST );
979     for( j = 0; cols[j].fieldname != NULL; j++ )
980     listview_add_column( lv, &cols[j] );
981    
982     for( j = 0; j < nuids; j++ ) {
983     listview_add_item( lv, " " );
984     listview_add_sub_item( lv, 0, 1, " " );
985     }
986    
987     listview_set_ext_style (lv);
988     for (j = 0; j < nuids; j++) {
989     if (gpgme_key_get_ulong_attr (key, GPGME_ATTR_UID_REVOKED, NULL, j))
990     attr = _("Revoked");
991     else {
992     u_attr = gpgme_key_get_ulong_attr (key, GPGME_ATTR_VALIDITY, NULL, j);
993     attr = gpgme_key_expand_attr (GPGME_ATTR_VALIDITY, u_attr);
994     }
995     listview_add_sub_item( lv, j, 0, (char *)attr );
996    
997 twoaday 16 /* XXX: add comment if available */
998     attr = gpgme_key_get_string_attr( key, GPGME_ATTR_NAME, NULL, j );
999     if (attr) {
1000 twoaday 2 char * uid = utf8_to_wincp (attr, strlen (attr));
1001     if (uid) {
1002     listview_add_sub_item( lv, j, 1, uid );
1003     free( uid );
1004     }
1005     }
1006     else
1007     listview_add_sub_item( lv, j, 1, _("Invalid user ID") );
1008 twoaday 16 attr = gpgme_key_get_string_attr (key, GPGME_ATTR_EMAIL, NULL, j);
1009     if (attr)
1010     listview_add_sub_item (lv, j, 2, attr);
1011 twoaday 2 u_attr = gpgme_key_get_ulong_attr (key, GPGME_ATTR_UID_CREATED, NULL, j);
1012     if (u_attr)
1013 twoaday 16 listview_add_sub_item (lv, j, 3, get_key_created (u_attr));
1014 twoaday 2 }
1015     if( !k->key_pair ) {
1016     CheckDlgButton( dlg, IDC_KEYUID_ADD, BST_INDETERMINATE );
1017     CheckDlgButton( dlg, IDC_KEYUID_REVOKE, BST_INDETERMINATE );
1018     }
1019     return lv;
1020     } /* userid_list_init */
1021    
1022    
1023     static void
1024     do_init_cmdlist( HWND dlg )
1025     {
1026     const char *cmdlist[] = {
1027     "ADDKEY",
1028     "ADDUID",
1029     "ADDPHOTO",
1030     "ADDREVOKER",
1031     /*"FPR",*/
1032     "DELUID",
1033     "DELKEY",
1034     "DELPHOTO",
1035     /*"DELSIG",*/
1036     "EXPIRE",
1037 twoaday 16 /*"PREF",*/
1038 twoaday 2 "SHOWPREF",
1039 twoaday 16 /*"SETPREF",*/
1040 twoaday 2 "PASSWD",
1041     "PRIMARY",
1042     "TRUST",
1043     /*"REVSIG",*/
1044     "REVUID",
1045     "REVKEY",
1046     "DISABLE",
1047     "ENABLE",
1048     "SHOWPHOTO",
1049     NULL
1050     };
1051     const char * s;
1052     int i = 0;
1053    
1054     for( i = 0; (s=cmdlist[i]); i++ ) {
1055     SendDlgItemMessage( dlg, IDC_KEYEDIT_CMD, CB_ADDSTRING, 0,
1056     (LPARAM)(char *)s );
1057     }
1058     SendDlgItemMessage( dlg, IDC_KEYEDIT_CMD, CB_SETCURSEL, 0, 0 );
1059     } /* do_init_cmdlist */
1060    
1061    
1062     static int
1063     is_cmd_openpgp( int cmdid )
1064     {
1065     switch( cmdid ) {
1066     case CMD_ADDKEY:
1067     case CMD_ADDPHOTO:
1068     case CMD_ADDREVOKER:
1069     case CMD_DELPHOTO:
1070     /*case CMD_SHOWPHOTO:*/
1071     case CMD_UPDPREF:
1072     return 1;
1073     }
1074     return 0;
1075     } /* is_cmd_openpgp */
1076    
1077    
1078     static void
1079     do_show_help( HWND dlg )
1080     {
1081     char helptext[2048];
1082    
1083     _snprintf( helptext, sizeof helptext-1,
1084     _(/*"FPR \t\tshow fingerprint\r\n"*/
1085     "ADDUID \t\tadd a user ID\r\n"
1086     "ADDPHOTO \t\tadd a photo ID\r\n"
1087     "DELUID \t\tdelete a user ID\r\n"
1088     "ADDKEY \t\tadd a secondard key\r\n"
1089     "DELKEY \t\tdelete a secondary key\r\n"
1090     "ADDREVOKER\t\tadd a revocation key\r\n"
1091     /*"DELSIG \t\tdelete signatures\r\n"*/
1092     "EXPIRE \t\tchange the expire date\r\n"
1093     /*"PREF \t\tlist preferences (expert)\r\n"
1094     "SHOWPREF \t\tlist preferences (verbose)\r\n"
1095     "SETPREF \t\tset preference list\r\n"*/
1096     "UPDPREF \t\tupdated preferences\r\n"
1097     "PASSWD \t\tchange the passphrase\r\n"
1098     "PRIMARY \t\tflag user ID as primary\r\n"
1099     "TRUST \t\tchange the ownertrust\r\n"
1100     /*"REVSIG \t\trevoke signatures\r\n"*/
1101     "REVUID \t\trevoke a user ID\r\n"
1102     "REVKEY \t\trevoke a secondary key\r\n"
1103     "DISABLE \t\tdisable a key\r\n"
1104     "ENABLE \t\tenable a key\r\n"
1105     /*"SHOWPHOTO \t\tshow photo ID\r\n"*/) );
1106     msg_box( dlg, helptext, _("Key Edit Help"), MB_OK );
1107     } /* do_show_help */
1108    
1109    
1110     static int
1111     do_editkey_delkey( winpt_key_t k, HWND dlg, listview_ctrl_t lv )
1112     {
1113     int j, id;
1114     char tmp[64];
1115     gpgme_error_t ec;
1116     gpgme_editkey_t ek;
1117     gpgme_ctx_t ctx;
1118    
1119     if( listview_count_items( lv, 0 ) == 1 ) {
1120     msg_box( dlg, _("Primary key can not be deleted!"), _("Key Edit"), MB_ERR);
1121     return FALSE;
1122     }
1123     if( (j = listview_get_curr_pos( lv )) == -1 ) {
1124     msg_box( dlg, _("Please select a key."), _("Key Edit"), MB_ERR );
1125     return FALSE;
1126     }
1127     if( j == 0 ) {
1128     msg_box( dlg, _("Primary subkey can not be deleted!"), _("Key Edit"), MB_ERR );
1129     return FALSE;
1130     }
1131    
1132     listview_get_item_text( lv, j, 0, tmp, sizeof tmp -1 );
1133     id = log_box( _("Key Edit"), MB_YESNO|MB_ICONWARNING,
1134     _("\"Subkey %s.\"\n\n"
1135     "Anything encrypted to the selected subkey will no longer\n"
1136     "be able to be decrypted.\n\n"
1137     "Do you really want to delete this subkey?"), tmp );
1138     if( id == IDNO )
1139     return FALSE;
1140    
1141     ec = gpgme_new( &ctx );
1142     if( !ec )
1143     ec = gpgme_editkey_new( &ek );
1144     if( ec )
1145     BUG( dlg );
1146     gpgme_enable_logging( ctx );
1147     gpgme_editkey_delkey_set_id( ek, j );
1148     gpgme_set_edit_ctx( ctx, ek, GPGME_EDITKEY_DELKEY );
1149     ec = gpgme_op_editkey( ctx, k->keyid );
1150     if( ec )
1151     gpgme_show_error( dlg, ec, ctx, _("Delete Subkey"), MB_ERR );
1152     else {
1153     listview_del_item( lv, j );
1154     keycache_set_reload( 1 );
1155     status_box( dlg, _("Subkey successfully deleted."), _("GnuPG status") );
1156     }
1157     gpgme_editkey_release( ek );
1158     gpgme_release( ctx );
1159     return ec? FALSE : TRUE;
1160     } /* do_editkey_delkey */
1161    
1162    
1163     static int
1164     do_editkey_expire( winpt_key_t k, HWND dlg, listview_ctrl_t lv )
1165     {
1166     gpgme_error_t ec;
1167     gpgme_editkey_t ek;
1168     gpgme_ctx_t ctx;
1169     date_s udd = {0};
1170     char buf[256], * pass = NULL;
1171     int j, cancel = 0;
1172    
1173     if( !k->key_pair ) {
1174     msg_box( dlg, _("There is no secret key available!"), _("Key Edit"), MB_ERR );
1175     return FALSE;
1176     }
1177     if ( (j = listview_get_curr_pos( lv )) == -1 ) {
1178     msg_box( dlg, _("Please select a key."), _("Key Edit"), MB_ERR );
1179     return FALSE;
1180     }
1181    
1182     listview_get_item_text( lv, j, 3, buf, sizeof buf -1 );
1183     if( !strcmp( buf, _("Expired") ) ) {
1184     msg_box( dlg, _("Key already expired!"), _("Key Edit"), MB_ERR );
1185     return FALSE;
1186     }
1187     memset( &udd, 0, sizeof udd );
1188     udd.text = _("Key Expiration Date");
1189     dialog_box_param( glob_hinst, (LPCSTR)IDD_WINPT_DATE, dlg,
1190     date_dlg_proc, (LPARAM)&udd,
1191     _("Key Expiration Date"), IDS_WINPT_DATE );
1192     if( udd.cancel == 1 )
1193     return FALSE;
1194     if( !keygen_check_date( &udd.st ) ) {
1195     msg_box( dlg, _("The date you have chosen lies in the past."), _("Key Edit"), MB_ERR );
1196     return FALSE;
1197     }
1198     if( k->is_protected ) {
1199     pass = request_passphrase (_("Key Edit"), 1, &cancel );
1200     if( cancel )
1201     return FALSE;
1202     }
1203     _snprintf( buf, sizeof buf - 1, "%04d-%02d-%02d",
1204     udd.st.wYear, udd.st.wMonth, udd.st.wDay );
1205     ec = gpgme_editkey_new( &ek );
1206     if( !ec )
1207     ec = gpgme_new( &ctx );
1208     if( ec )
1209     BUG( dlg );
1210     gpgme_editkey_expire_set( ek, j, 0, buf, k->is_protected? pass : NULL );
1211     gpgme_enable_logging( ctx );
1212     gpgme_set_edit_ctx( ctx, ek, GPGME_EDITKEY_EXPIRE );
1213     ec = gpgme_op_editkey( ctx, k->keyid );
1214     if( ec )
1215     gpgme_show_error( dlg, ec, ctx, _("Expire Subkey"), MB_ERR );
1216     else {
1217     listview_add_sub_item( lv, j, 3, buf );
1218     keycache_set_reload( 1 );
1219     msg_box( dlg, _("Subkey expire date successfully set."), _("GnuPG status"), MB_OK );
1220     }
1221     free_if_alloc( pass );
1222     gpgme_release( ctx );
1223     gpgme_editkey_release( ek );
1224     return TRUE;
1225     } /* do_editkey_expire */
1226    
1227    
1228     static int
1229     do_editkey_revoke( winpt_key_t k, HWND dlg, listview_ctrl_t lv )
1230     {
1231     gpgme_ctx_t ctx;
1232     gpgme_error_t ec;
1233     gpgme_editkey_t ek;
1234     char buf[256], * pass = NULL;
1235     int j, cancel = 0;
1236    
1237     if( !k->key_pair ) {
1238     msg_box( dlg, _("There is no secret key available!"), _("Key Edit"), MB_ERR );
1239     return FALSE;
1240    
1241     }
1242    
1243     if( (j = listview_get_curr_pos( lv )) == -1 ) {
1244     msg_box( dlg, _("Please select a key."), _("Key Edit"), MB_ERR );
1245     return FALSE;
1246     }
1247     else if( listview_count_items( lv, 0 ) == 1 ) {
1248     msg_box( dlg, _("No subkeys were found, if you want to revoke the\n"
1249     "whole key, please use the Key Manager command directly.\n\n"
1250     "This command is only available to revoke single subkeys"),
1251     _("Key Edit"), MB_INFO );
1252     return FALSE;
1253     }
1254    
1255     listview_get_item_text( lv, j, 3, buf, sizeof buf-1 );
1256     if( !strcmp( buf, _("Revoked") ) ) {
1257     msg_box( dlg, _("Key already revoked."), _("Key Edit"), MB_ERR );
1258     return FALSE;
1259     }
1260    
1261     if( k->is_protected ) {
1262     pass = request_passphrase (_("Key Edit"), 1, &cancel);
1263     if( cancel )
1264     return FALSE;
1265     }
1266    
1267     ec = gpgme_editkey_new( &ek );
1268     if( !ec )
1269     ec = gpgme_new( &ctx );
1270     if( ec )
1271     BUG( NULL );
1272     gpgme_enable_logging( ctx );
1273     gpgme_editkey_revkey_set( ek, j, 0, k->is_protected? pass : NULL );
1274     gpgme_set_edit_ctx( ctx, ek, GPGME_EDITKEY_REVKEY );
1275     ec = gpgme_op_editkey( ctx, k->keyid );
1276     if( ec )
1277     gpgme_show_error( dlg, ec, ctx, _("Revoke Subkey"), MB_ERR );
1278     else {
1279     listview_add_sub_item( lv, j, 5, _("Revoked") );
1280     keycache_set_reload( 1 );
1281     msg_box( dlg, _("Subkey successfully revoked."), _("GnuPG Status"), MB_OK );
1282     }
1283     free_if_alloc( pass );
1284     gpgme_release( ctx );
1285     gpgme_editkey_release( ek );
1286     return TRUE;
1287     } /* do_editkey_revoke */
1288    
1289    
1290     int
1291 twoaday 16 do_editkey_revuid (winpt_key_t k, HWND dlg, listview_ctrl_t lv)
1292 twoaday 2 {
1293     gpgme_ctx_t ctx;
1294     gpgme_error_t ec;
1295     gpgme_editkey_t ek;
1296     char buf[256], t[512], * pass;
1297     int cancel = 0, id = 0, j;
1298    
1299     if( !k->key_pair ) {
1300     msg_box( dlg, _("There is no secret key available!"), _("Revoke user ID"), MB_ERR );
1301     return FALSE;
1302     }
1303    
1304     if( listview_count_items( lv, 0 ) == 1 ) {
1305     msg_box( dlg, _("Key has only one user ID."), _("Key Edit"), MB_ERR );
1306     return FALSE;
1307     }
1308    
1309     if( (j = listview_get_curr_pos( lv )) == -1 ) {
1310     msg_box( dlg, _("Please select a user ID."), _("Key Edit"), MB_ERR );
1311     return FALSE;
1312     }
1313    
1314     listview_get_item_text( lv, j, 0, buf, sizeof buf - 1 );
1315     if( strstr( buf, _("Revoked") ) ) {
1316     msg_box( dlg, _("This user ID has been already revoked."), _("Key Edit"), MB_INFO );
1317     return FALSE;
1318     }
1319    
1320     listview_get_item_text( lv, j, 1, buf, sizeof buf -1 );
1321     _snprintf( t, sizeof t -1, _("user ID \"%s\".\n\n"
1322     "Do you really want to revoke this user ID?"), buf );
1323 twoaday 16 if( msg_box( dlg, t, _("Key Edit"), MB_WARN_ASK) == IDNO )
1324 twoaday 2 return FALSE;
1325     if( k->is_protected ) {
1326     pass = request_passphrase (_("Key Edit"), 1, &cancel);
1327     if( cancel )
1328     return FALSE;
1329     }
1330 twoaday 16 id = do_find_userid (k->keyid, buf, NULL);
1331     if (id == -1)
1332     BUG (dlg);
1333     ec = gpgme_new (&ctx);
1334     if (!ec)
1335     ec = gpgme_editkey_new (&ek);
1336 twoaday 2 if( ec )
1337     BUG( dlg );
1338     gpgme_enable_logging( ctx );
1339     gpgme_editkey_revsig_set( ek, id, k->is_protected? pass : NULL );
1340     gpgme_set_edit_ctx( ctx, ek, GPGME_EDITKEY_REVSIG );
1341     ec = gpgme_op_editkey( ctx, k->keyid );
1342 twoaday 16 if (ec)
1343     gpgme_show_error (dlg, ec, ctx, _("Revoke Signature"), MB_ERR);
1344 twoaday 2 else {
1345 twoaday 16 listview_add_sub_item (lv, j, 0, _("Revoked"));
1346     keycache_set_reload (1);
1347     status_box (dlg, _("User ID successfully revoked"), _("GnuPG Status"));
1348 twoaday 2 }
1349 twoaday 16 free_if_alloc (pass);
1350     gpgme_editkey_release (ek);
1351     gpgme_release (ctx);
1352 twoaday 2 return ec? FALSE : TRUE;
1353     } /* do_editkey_revuid */
1354    
1355    
1356     static int
1357     do_editkey_setpref (winpt_key_t k, HWND dlg, listview_ctrl_t lv)
1358     {
1359     gpgme_ctx_t ctx;
1360     gpgme_editkey_t ek;
1361     gpgme_error_t rc;
1362     char buf[256], * pass = NULL, * prefs;
1363     int j, id, cancel=0, flags=0;
1364    
1365     if ((j = listview_get_curr_pos (lv)) == -1) {
1366     msg_box (dlg, _("Please select a user ID."), _("Key Edit"), MB_ERR);
1367     return FALSE;
1368     }
1369     listview_get_item_text (lv, j, 1, buf, sizeof buf-1);
1370 twoaday 16 id = do_find_userid (k->keyid, buf, NULL);
1371 twoaday 2 if (id == -1)
1372     BUG (dlg);
1373     if (k->is_protected) {
1374     pass = request_passphrase (_("Key Edit"), 1, &cancel);
1375     if (cancel)
1376     return FALSE;
1377     }
1378     rc = gpgme_new (&ctx);
1379     if (!rc)
1380     rc = gpgme_editkey_new (&ek);
1381     if (rc)
1382     BUG (NULL);
1383    
1384     get_userid_preflist (&prefs, &flags);
1385     gpgme_editkey_setpref_set (ek, prefs, id, pass);
1386     gpgme_set_edit_ctx (ctx, ek, GPGME_EDITKEY_SETPREF);
1387     rc = gpgme_op_editkey (ctx, k->keyid);
1388     free_if_alloc (pass);
1389    
1390     free_if_alloc (prefs);
1391     gpgme_release (ctx);
1392     gpgme_editkey_release (ek);
1393     return 0;
1394     }
1395    
1396    
1397     static int
1398     do_editkey_primary( winpt_key_t k, HWND dlg, listview_ctrl_t lv )
1399     {
1400     gpgme_ctx_t ctx;
1401     gpgme_editkey_t ek;
1402     gpgme_error_t ec;
1403     int j, id, cancel=0;
1404     char buf[256], * pass = NULL;
1405    
1406     if( (j = listview_get_curr_pos( lv )) == -1 ) {
1407     msg_box( dlg, _("Please select a user ID."), _("Key Edit"), MB_ERR );
1408     return FALSE;
1409     }
1410     listview_get_item_text( lv, j, 1, buf, sizeof buf-1 );
1411 twoaday 16 id = do_find_userid (k->keyid, buf, NULL);
1412 twoaday 2 if( id == -1 )
1413     BUG( dlg );
1414     if( k->is_protected ) {
1415     pass = request_passphrase( _("Key Edit"), 1, &cancel );
1416     if( cancel )
1417     return FALSE;
1418     }
1419    
1420     ec = gpgme_new( &ctx );
1421     if( !ec )
1422     ec = gpgme_editkey_new( &ek );
1423     if( ec )
1424     BUG( dlg );
1425     gpgme_enable_logging( ctx );
1426     gpgme_editkey_primary_set( ek, id, k->is_protected? pass : NULL );
1427     gpgme_set_edit_ctx( ctx, ek, GPGME_EDITKEY_PRIMARY );
1428     ec = gpgme_op_editkey( ctx, k->keyid );
1429     if( ec )
1430     gpgme_show_error( dlg, ec, ctx, _("Primary"), MB_ERR );
1431     else {
1432     keycache_set_reload( 1 );
1433     status_box( dlg, _("User ID successfully flagged"), _("GnuPG Status") );
1434     }
1435    
1436     free_if_alloc( pass );
1437     gpgme_editkey_release( ek );
1438     gpgme_release( ctx );
1439     return ec? FALSE : TRUE;
1440     } /* do_editkey_primary */
1441    
1442    
1443     static int
1444 twoaday 16 parse_preflist (HWND dlg, const char *list)
1445 twoaday 2 {
1446 twoaday 16 char *p;
1447     const char *ciphers[11] = {0, "IDEA", "3DES", "CAST5", "BLOWFISH", 0, 0, "AES", "AES192", "AES256", "TWOFISH"};
1448     const char *hash[4] = {0, "MD5", "SHA1", "RMD160"};
1449     const char *compress[4] = {0, "ZIP", "ZLIB", "BZIP2"};
1450     int n=0;
1451    
1452     p = strtok ((char*)list, " ");
1453     while (p != NULL) {
1454     int algid = atol (p+1);
1455     n++;
1456     switch (*p) {
1457     case 'S':
1458     SendDlgItemMessage (dlg, IDC_SHOWPREF_CIPHERS, LB_ADDSTRING, 0, (LPARAM)(const char*)ciphers[algid % 11]);
1459     break;
1460    
1461     case 'H':
1462     SendDlgItemMessage (dlg, IDC_SHOWPREF_HASH, LB_ADDSTRING, 0, (LPARAM)(const char*)hash[algid % 4]);
1463     break;
1464    
1465     case 'Z':
1466     SendDlgItemMessage (dlg, IDC_SHOWPREF_ZIP, LB_ADDSTRING, 0, (LPARAM)(const char*)compress[algid % 4]);
1467     break;
1468    
1469     default:
1470     n--;
1471     }
1472     p = strtok (NULL, " ");
1473     }
1474     return n;
1475     }
1476    
1477     BOOL CALLBACK
1478     showpref_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
1479     {
1480     static keyedit_callback_s *cb = NULL;
1481     gpgme_uidinfo_t inf=NULL;
1482     char buf[128];
1483     int pos;
1484    
1485     switch (msg) {
1486     case WM_INITDIALOG:
1487     cb = (keyedit_callback_s *)lparam;
1488     if (cb == NULL)
1489     BUG (dlg);
1490     listview_get_item_text (cb->lv, listview_get_curr_pos (cb->lv), 2, buf, DIM (buf)-1);
1491     SetDlgItemText (dlg, IDC_SHOWPREF_INFO, buf);
1492     pos = do_find_userid (((winpt_key_t)cb->opaque)->keyid, buf, &inf);
1493     if (inf) {
1494     const char *prefs;
1495     prefs = gpgme_editkey_get_string_attr (inf, GPGME_ATTR_UID_PREFS, pos-1);
1496     if (prefs && *prefs) {
1497     if (parse_preflist (dlg, prefs) <= 0)
1498     pos = -1;
1499     }
1500     else
1501     pos = -1;
1502     gpgme_uid_info_release (inf);
1503     if (pos == -1) {
1504     msg_box (dlg, _("No preferences available."), _("Key Edit"), MB_ERR);
1505     EndDialog (dlg, TRUE);
1506     }
1507     }
1508     SetForegroundWindow (dlg);
1509     break;
1510    
1511     case WM_COMMAND:
1512     switch (LOWORD (wparam)) {
1513     case IDOK:
1514     EndDialog (dlg, TRUE);
1515     break;
1516     }
1517     break;
1518     }
1519     return FALSE;
1520     }
1521    
1522     static int
1523     do_editkey_showpref (winpt_key_t k, HWND dlg, listview_ctrl_t lv)
1524     {
1525     struct keyedit_callback_s cb;
1526     if (listview_get_curr_pos (lv) == -1) {
1527     msg_box (dlg, _("Please select a user ID."), _("Key Edit"), MB_ERR);
1528     return FALSE;
1529     }
1530    
1531     memset (&cb, 0, sizeof (cb));
1532     cb.lv = lv;
1533     cb.opaque = k;
1534     DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_KEYEDIT_SHOWPREF, dlg,
1535     showpref_dlg_proc, (LPARAM)&cb);
1536     return 0;
1537     }
1538    
1539    
1540     static int
1541     do_editkey_deluid (winpt_key_t k, HWND dlg, listview_ctrl_t lv)
1542     {
1543 twoaday 2 gpgme_ctx_t ctx;
1544     gpgme_editkey_t ek;
1545     gpgme_error_t ec;
1546     char buf[256], t[512];
1547     int j, id = 0;
1548    
1549     if( listview_count_items( lv, 0 ) == 1 ) {
1550     msg_box( dlg, _("Primary user ID can not be deleted!"), _("Key Edit"), MB_ERR );
1551     return FALSE;
1552     }
1553     if( (j = listview_get_curr_pos( lv )) == -1 ) {
1554     msg_box( dlg, _("Please select a user ID."), _("Key Edit"), MB_ERR );
1555     return FALSE;
1556     }
1557    
1558 twoaday 16 listview_get_item_text( lv, j, 1, buf, DIM(buf) -1 );
1559 twoaday 2 _snprintf( t, sizeof t -1, _("user ID \"%s\".\n\n"
1560     "Do you really want to delete this user ID?"), buf );
1561     if( msg_box( dlg, t, _("Key Edit"), MB_YESNO|MB_ICONWARNING ) == IDNO )
1562     return FALSE;
1563    
1564 twoaday 16 listview_get_item_text (lv, j, 2, buf, DIM (buf)-1);
1565     id = do_find_userid (k->keyid, buf, NULL);
1566     if (id == -1)
1567     BUG (dlg);
1568 twoaday 2 ec = gpgme_new( &ctx );
1569     if( !ec )
1570     ec = gpgme_editkey_new( &ek );
1571     if( ec )
1572     BUG( dlg );
1573     gpgme_enable_logging( ctx );
1574     gpgme_editkey_deluid_set_id( ek, id );
1575     gpgme_set_edit_ctx( ctx, ek, GPGME_EDITKEY_DELUID );
1576     ec = gpgme_op_editkey( ctx, k->keyid );
1577     if( ec )
1578     gpgme_show_error( dlg, ec, ctx, _("Delete user ID"), MB_ERR );
1579     else {
1580     listview_del_item( lv, j );
1581     keycache_set_reload( 1 );
1582     status_box( dlg, _("User ID successfully deleted"), _("GnuPG Status") );
1583     }
1584     gpgme_editkey_release( ek );
1585     gpgme_release( ctx );
1586     return ec? FALSE : TRUE;
1587     } /* do_editkey_deluid */
1588    
1589    
1590    
1591     static BOOL CALLBACK
1592     subkey_subclass_proc( HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam )
1593     {
1594     switch( msg ) {
1595     case WM_KEYUP:
1596     int virt_key = (int)wparam;
1597     switch( virt_key ) {
1598     case VK_DELETE:
1599     SendDlgItemMessage( keyedit_subkey_proc.dlg, IDC_KEYEDIT_CMD,
1600     CB_SETCURSEL, CMD_DELKEY, 0 );
1601     send_cmd_id( keyedit_subkey_proc.dlg, IDOK );
1602     break;
1603    
1604     case VK_INSERT:
1605     SendDlgItemMessage( keyedit_subkey_proc.dlg, IDC_KEYEDIT_CMD,
1606     CB_SETCURSEL, CMD_ADDKEY, 0 );
1607     send_cmd_id( keyedit_subkey_proc.dlg, IDOK );
1608     break;
1609     }
1610     }
1611     return CallWindowProc( keyedit_subkey_proc.old, dlg, msg, wparam, lparam );
1612     } /* subkey_subclass_proc */
1613    
1614    
1615     static BOOL CALLBACK
1616 twoaday 16 uid_subclass_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
1617 twoaday 2 {
1618     switch( msg ) {
1619     case WM_KEYUP:
1620     int virt_key = (int)wparam;
1621 twoaday 16 switch (virt_key) {
1622 twoaday 2 case VK_DELETE:
1623 twoaday 16 SendDlgItemMessage (keyedit_uid_proc.dlg, IDC_KEYEDIT_CMD,
1624     CB_SETCURSEL, CMD_DELUID, 0);
1625     send_cmd_id (keyedit_uid_proc.dlg, IDOK);
1626 twoaday 2 break;
1627    
1628     case VK_INSERT:
1629 twoaday 16 SendDlgItemMessage (keyedit_uid_proc.dlg, IDC_KEYEDIT_CMD,
1630     CB_SETCURSEL, CMD_ADDUID, 0);
1631     send_cmd_id (keyedit_uid_proc.dlg, IDOK);
1632 twoaday 2 break;
1633     }
1634     }
1635     return CallWindowProc( keyedit_uid_proc.old, dlg, msg, wparam, lparam );
1636     } /* uid_subclass_proc */
1637    
1638    
1639     BOOL CALLBACK
1640     keyedit_main_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
1641     {
1642     static winpt_key_t k;
1643     static listview_ctrl_t lvsub = NULL, lvuid = NULL;
1644     int cmd, idxsub = 0;
1645     HWND item;
1646    
1647     switch( msg ) {
1648     case WM_INITDIALOG:
1649     k = (winpt_key_t)lparam;
1650 twoaday 16 if (!k)
1651     BUG (NULL);
1652     do_init_cmdlist (dlg);
1653     lvsub = subkey_list_init (dlg, k);
1654 twoaday 2 if( !lvsub )
1655     BUG( NULL );
1656     lvuid = userid_list_init (dlg, k);
1657     if( !lvuid )
1658     BUG( NULL );
1659     item = GetDlgItem( dlg, IDC_KEYEDIT_KEYLIST );
1660     keyedit_subkey_proc.dlg = dlg;
1661     keyedit_subkey_proc.current = (WNDPROC)subkey_subclass_proc;
1662     keyedit_subkey_proc.old = (WNDPROC)GetWindowLong( item, GWL_WNDPROC );
1663     if( keyedit_subkey_proc.old ) {
1664     if( !SetWindowLong( item, GWL_WNDPROC, (LONG)keyedit_subkey_proc.current ) ) {
1665     msg_box( dlg, _("Could not set subkey window procedure."), _("Key Edit"), MB_ERR );
1666     BUG( NULL );
1667     }
1668     }
1669     item = GetDlgItem( dlg, IDC_KEYEDIT_UIDLIST );
1670     keyedit_uid_proc.dlg = dlg;
1671     keyedit_uid_proc.current = (WNDPROC)uid_subclass_proc;
1672     keyedit_uid_proc.old = (WNDPROC)GetWindowLong( item, GWL_WNDPROC );
1673     if( keyedit_uid_proc.old ) {
1674     if( !SetWindowLong( item, GWL_WNDPROC, (LONG)keyedit_uid_proc.current ) ) {
1675     msg_box( dlg, _("Could not set user ID window procedure."), _("Key Edit"), MB_ERR );
1676     BUG( NULL );
1677     }
1678     }
1679     if (!k->key_pair) {
1680     EnableWindow (GetDlgItem (dlg, IDC_KEYEDIT_CMD), FALSE);
1681     EnableWindow (GetDlgItem (dlg, IDOK), FALSE);
1682     }
1683     SetForegroundWindow( dlg );
1684     center_window( dlg );
1685     return TRUE;
1686    
1687     case WM_DESTROY:
1688     if( lvsub ) {
1689     listview_release( lvsub );
1690     lvsub = NULL;
1691     }
1692     if( lvuid ) {
1693     listview_release( lvuid );
1694     lvuid = NULL;
1695     }
1696     break;
1697    
1698 twoaday 16 case WM_NOTIFY:
1699     NMHDR * notify;
1700     notify = (NMHDR *)lparam;
1701     if (notify && notify->code == NM_DBLCLK &&
1702     notify->idFrom == IDC_KEYEDIT_UIDLIST)
1703     do_editkey_showpref (k, dlg, lvuid);
1704     break;
1705    
1706 twoaday 2 case WM_COMMAND:
1707     switch( LOWORD( wparam ) ) {
1708     case IDOK:
1709     cmd = SendDlgItemMessage( dlg, IDC_KEYEDIT_CMD, CB_GETCURSEL, 0, 0 );
1710     if( cmd == LB_ERR ) {
1711     msg_box( dlg, _("Please select a command."), _("Key Edit"), MB_INFO );
1712     return FALSE;
1713     }
1714     idxsub = listview_get_curr_pos( lvsub );
1715     if( km_key_is_v3( lvsub, idxsub==-1? 0 : idxsub ) && is_cmd_openpgp( cmd ) ) {
1716     msg_box( dlg, _("This command cannot be used with PGP 2 (v3) keys\n"
1717     " because it is not OpenPGP compliant."),
1718     _("Key Edit"), MB_ERR );
1719     return FALSE;
1720     }
1721     switch( cmd ) {
1722 twoaday 16 case CMD_SHOWPREF: do_editkey_showpref (k, dlg, lvuid); break;
1723     case CMD_DELKEY: do_editkey_delkey (k, dlg, lvsub); break;
1724     case CMD_ADDKEY: keyedit_add_subkey (k, dlg, lvsub); break;
1725     case CMD_EXPIRE: do_editkey_expire (k, dlg, lvsub); break;
1726     case CMD_REVKEY: do_editkey_revoke (k, dlg, lvsub); break;
1727     /*case CMD_SETPREF:do_editkey_setpref( k, dlg, lvuid ); break;*/
1728 twoaday 2 case CMD_ADDUID: keyedit_add_userid( k, dlg, lvuid ); break;
1729     case CMD_ADDREVOKER: keyedit_add_revoker( k, dlg ); break;
1730     case CMD_ADDPHOTO: keyedit_add_photo( k, dlg ); break;
1731     case CMD_REVUID: do_editkey_revuid( k, dlg, lvuid ); break;
1732     case CMD_DELUID: do_editkey_deluid( k, dlg, lvuid ); break;
1733     case CMD_PASSWD: keyedit_change_passwd( k, dlg ); break;
1734     case CMD_PRIMARY: do_editkey_primary( k, dlg, lvuid ); break;
1735     case CMD_ENABLE: km_enable_disable_key( lvsub, dlg, idxsub, 1 ); break;
1736     case CMD_DISABLE: km_enable_disable_key( lvsub, dlg, idxsub, 0 ); break;
1737     }
1738     break;
1739    
1740     case IDCANCEL:
1741     EndDialog( dlg, FALSE );
1742     break;
1743    
1744     case IDC_KEYEDIT_HELP:
1745 twoaday 16 do_show_help (dlg);
1746 twoaday 2 break;
1747     }
1748     break;
1749     }
1750     return FALSE;
1751     } /* keyedit_main_dlg_proc */

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26