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

Annotation of /trunk/Src/wptKeyEditDlgs.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 22 - (hide annotations)
Wed Aug 10 11:33:35 2005 UTC (19 years, 6 months ago) by twoaday
File size: 53692 byte(s)
2005-08-06  Timo Schulz  <twoaday@freakmail.de>
 
        * wptGPGME.cpp (keycache_update): Reload OpenPGP parts
        of the secret key.
        (keycache_init): cache name of secret keyring.
        * wptKeyList.cpp (keylist_upd_key): Do not add long keyid.
        (get_key_type): Do not assume 'ultimate' means key pair.
        * wptKeyEditDlgs.cpp (diff_time): New.
        (keyedit_addsubkey_dlg_proc): Changed design and use
        diff_time. Drop checks for invalid keylength (< 1024, > 4096)
        because the combo box automatically handles this.
        * wptKeyManager.cpp (km_set_implicit_trust): Return error code.
        * wptGPG.cpp (get_backup_name): New.
        (gnupg_backup_keyrings): Rotate backup names, from 0..3.
        * wptClipImportDialog.cpp (clip_import_dlg_proc): Free memory.
        * wptKeyManagerDlg.cpp (keymanager_dlg_proc): Use 0x short keyid and
        not the long keyid.


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 22 /*CMD_UPDPREF,*/
54 twoaday 2 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 twoaday 20 const char *pass;
69 twoaday 2 listview_ctrl_t lv;
70 twoaday 20 void *opaque;
71 twoaday 2 };
72     typedef struct keyedit_callback_s KEYEDIT_CB;
73    
74     struct keygen_callback_s {
75 twoaday 20 int bits;
76     int algo;
77     u32 expire;
78     char *fpr;
79 twoaday 2 };
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 twoaday 20 int keygen_check_date (SYSTEMTIME *st);
87     void get_userid_preflist (char **r_prefs, int * r_flags);
88 twoaday 2
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 twoaday 19 k->update = 1;
288     msg_box (dlg, _("Photo successfully added."), _("GnuPG Status"), MB_OK);
289 twoaday 2 }
290 twoaday 19 gpgme_release (ctx);
291     EndDialog (dlg, TRUE);
292 twoaday 2 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 twoaday 19 k->update = 1;
371     msg_box (dlg, _("Revoker successfully addded."), _("GnuPG Status"), MB_OK);
372 twoaday 2 }
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 twoaday 22 static int
464     diff_time (HWND dt)
465     {
466     SYSTEMTIME exp, now;
467     double e=0, n=0;
468    
469     DateTime_GetSystemtime (dt, &exp);
470     GetSystemTime (&now);
471     SystemTimeToVariantTime (&exp, &e);
472     SystemTimeToVariantTime (&now, &n);
473     if (n > e)
474     return 0;
475     return (int)(e-n);
476     }
477    
478    
479     static void
480     init_keysize_box (HWND dlg, int ctlid)
481     {
482     const char *sizelist[] = {
483     "1024", "1536", "2048", "2560", "3072", "3854", "4096", NULL
484     };
485     int i;
486     for (i=0; sizelist[i] != NULL; i++)
487     SendDlgItemMessage (dlg, ctlid, CB_ADDSTRING, 0, (LPARAM)(char*)sizelist[i]);
488     SendDlgItemMessage (dlg, ctlid, CB_SETCURSEL, (WPARAM)2, 0);
489     }
490    
491     static int
492     get_keysize_from_box (HWND dlg, int ctlid)
493     {
494     int pos;
495     char buf[32];
496    
497     pos = SendDlgItemMessage (dlg, ctlid, CB_GETCURSEL, 0, 0);
498     if (pos == CB_ERR)
499     return -1;
500     SendDlgItemMessage (dlg, ctlid, CB_GETLBTEXT, pos, (LPARAM)(char*)buf);
501     return atol (buf);
502     }
503    
504    
505 twoaday 2 BOOL CALLBACK
506 twoaday 12 keyedit_addsubkey_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
507 twoaday 2 {
508 twoaday 22 static KEYEDIT_CB *ctx;
509     static KEYGEN_CB *keygen;
510     gpgme_error_t rc;
511     HWND lb;
512 twoaday 2 int index, size, valid;
513    
514 twoaday 22 switch (msg) {
515 twoaday 2 case WM_INITDIALOG:
516     ctx = (KEYEDIT_CB *)lparam;
517     if( !ctx )
518     dlg_fatal_error( dlg, "Could not get dialog param!" );
519     keygen = (KEYGEN_CB *)ctx->opaque;
520     #ifndef LANG_DE
521 twoaday 22 SetWindowText (dlg, _("Add new Subkey"));
522     SetDlgItemText (dlg, IDC_ADDSUBKEY_INFALGO, _("Key type"));
523     SetDlgItemText (dlg, IDC_ADDSUBKEY_INFSIZE, _("Size in bits"));
524     SetDlgItemText (dlg, IDC_ADDSUBKEY_INFVALID, _("Key expiration"));
525 twoaday 2 #endif
526 twoaday 22 lb = GetDlgItem (dlg, IDC_ADDSUBKEY_ALGO);
527     listbox_add_string (lb, "DSA (sign only)");
528     listbox_add_string (lb, "ElGamal (encrypt only)");
529     listbox_add_string (lb, "RSA (sign only)");
530     listbox_add_string (lb, "RSA (encrypt only)");
531     CheckDlgButton (dlg, IDC_ADDSUBKEY_EXPIRE, BST_CHECKED);
532     EnableWindow (GetDlgItem (dlg, IDC_ADDSUBKEY_EXPDATE), FALSE);
533     init_keysize_box (dlg, IDC_ADDSUBKEY_SIZE);
534 twoaday 2 SetForegroundWindow( dlg );
535     return FALSE;
536    
537     case WM_SYSCOMMAND:
538     if( LOWORD (wparam) == SC_CLOSE ) {
539     gpgme_editkey_make_invalid( ctx->ek );
540     EndDialog( dlg, TRUE );
541     }
542     return FALSE;
543    
544     case WM_COMMAND:
545 twoaday 22 if (HIWORD (wparam) == BN_CLICKED && LOWORD (wparam) == IDC_ADDSUBKEY_EXPIRE) {
546     if (IsDlgButtonChecked (dlg, IDC_ADDSUBKEY_EXPIRE))
547     EnableWindow (GetDlgItem (dlg, IDC_ADDSUBKEY_EXPDATE), FALSE);
548     else
549     EnableWindow (GetDlgItem (dlg, IDC_ADDSUBKEY_EXPDATE), TRUE);
550     }
551     if (HIWORD (wparam) == LBN_SELCHANGE && LOWORD (wparam) == IDC_ADDSUBKEY_ALGO) {
552     index = SendMessage ((HWND)lparam, LB_GETCURSEL, 0, 0);
553     if (index == 0)
554     SendDlgItemMessage (dlg, IDC_ADDSUBKEY_SIZE, CB_SETCURSEL, 0, 0);
555     }
556    
557 twoaday 2 switch ( LOWORD(wparam) ) {
558     case IDOK:
559 twoaday 22 lb = GetDlgItem (dlg, IDC_ADDSUBKEY_ALGO);
560 twoaday 2 switch (listbox_get_cursel (lb)) {
561     case 0: index = 2; break;
562 twoaday 6 case 1: index = 4; break;
563     case 2: index = 5; break;
564     case 3: index = 6; break;
565 twoaday 2 default:
566     msg_box( dlg, _("Please select one entry."), _("Add Subkey"), MB_ERR );
567     return FALSE;
568     }
569 twoaday 22 size = get_keysize_from_box (dlg, IDC_ADDSUBKEY_SIZE);
570     if (index == 2 && size != 1024) {
571 twoaday 2 msg_box( dlg,_("DSS uses a fixed keysize of 1024. Size changed."), _("Add Subkey"), MB_INFO );
572     size = 1024;
573     }
574 twoaday 22 valid = diff_time (GetDlgItem (dlg, IDC_ADDSUBKEY_EXPDATE));
575 twoaday 2 rc = gpgme_editkey_addkey_set (ctx->ek, ctx->pass, index, size, valid);
576     if (rc) {
577     msg_box (dlg, gpgme_strerror (rc), _("Add Subkey"), MB_ERR);
578     return FALSE;
579     }
580     keygen->bits = size;
581     switch (index) {
582     case 2: keygen->algo = GPGME_PK_DSA; break;
583 twoaday 6 case 4: keygen->algo = GPGME_PK_ELG_E; break;
584     case 5: keygen->algo = GPGME_PK_RSA_S; break;
585     case 6: keygen->algo = GPGME_PK_RSA_E; break;
586 twoaday 2 }
587 twoaday 22 if (valid > 0)
588 twoaday 2 keygen->expire = time (NULL) + valid*24*60*60;
589     EndDialog( dlg, TRUE );
590     return TRUE;
591    
592     case IDCANCEL:
593 twoaday 22 gpgme_editkey_make_invalid (ctx ->ek);
594 twoaday 2 EndDialog( dlg, FALSE );
595     return FALSE;
596     }
597     break;
598     }
599    
600     return FALSE;
601     } /* keyedit_addsubkey_dlg_proc */
602    
603    
604     BOOL
605     keyedit_add_userid (winpt_key_t k, HWND dlg, listview_ctrl_t lv)
606     {
607     gpgme_error_t ec;
608     gpgme_ctx_t ctx;
609     gpgme_editkey_t ek;
610     KEYEDIT_CB cb;
611     char * pass = NULL;
612     int cancel = 0;
613    
614 twoaday 16 if (!k->key_pair) {
615 twoaday 2 msg_box( dlg, _("There is no secret key available!"), _("Add user ID"), MB_ERR );
616     return FALSE;
617     }
618    
619     if (k->is_protected) {
620     pass = request_passphrase( _("Key Edit"), 1, &cancel );
621     if( cancel )
622     return FALSE;
623     }
624    
625     ec = gpgme_editkey_new( &ek );
626     if( ec )
627     BUG( dlg );
628    
629     memset( &cb, 0, sizeof cb );
630     cb.ek = ek;
631     cb.pass = k->is_protected? pass : NULL;
632     cb.lv = lv;
633     dialog_box_param( glob_hinst, (LPCSTR)IDD_WINPT_KEYEDIT_ADDUID,
634     dlg, keyedit_adduid_dlg_proc,
635     (LPARAM)&cb, _("Add user ID"),
636     IDS_WINPT_KEYEDIT_ADDUID );
637     if( !gpgme_editkey_is_valid( ek ) ) {
638     free_if_alloc( pass );
639     return FALSE;
640     }
641    
642     ec = gpgme_new( &ctx );
643     if( ec )
644     BUG( dlg );
645     gpgme_enable_logging( ctx );
646     gpgme_set_edit_ctx( ctx, ek, GPGME_EDITKEY_ADDUID );
647     ec = gpgme_op_editkey( ctx, k->keyid );
648     if( ec )
649     gpgme_show_error( dlg, ec, ctx, _("Add user ID"), MB_ERR );
650     else {
651 twoaday 19 k->update = 1;
652     msg_box (dlg, _("User ID successfully added"), _("GnuPG Status"), MB_OK);
653 twoaday 2 }
654     gpgme_editkey_release( ek );
655     gpgme_release( ctx );
656     free_if_alloc( pass );
657     return TRUE;
658     } /* keyedit_add_userid */
659    
660    
661 twoaday 12 char*
662     get_subkey_fingerprint (gpgme_ctx_t ctx, const char *keyid)
663     {
664     static char fpr[40];
665     const char *s;
666     gpgme_error_t err;
667     gpgme_key_t key, main;
668     int n;
669    
670     /* XXX: this is very slow and complicated */
671     err = gpgme_op_keylist_start (ctx, keyid, 0);
672     if (err)
673     return NULL;
674     err = gpgme_op_keylist_next (ctx, &key);
675     if (err)
676     return NULL;
677    
678     n = gpgme_key_count_items (key, GPGME_ATTR_KEYID);
679     s = gpgme_key_get_string_attr (key, GPGME_ATTR_FPR, NULL, n-1);
680     strcpy (fpr, s);
681    
682     get_pubkey (keyid, &main);
683     gpgme_key_append (main, key, n-1);
684    
685     gpgme_key_release (key);
686     return fpr;
687     }
688    
689    
690 twoaday 2 BOOL
691     keyedit_add_subkey (winpt_key_t k, HWND dlg, listview_ctrl_t lv)
692     {
693     gpgme_error_t ec;
694     gpgme_ctx_t ctx;
695     gpgme_editkey_t ek;
696     KEYEDIT_CB cb;
697     KEYGEN_CB keygen;
698     char * pass = NULL;
699     int cancel = 0;
700    
701     if( !k->key_pair ) {
702     msg_box( dlg, _("There is no secret key available!"), _("Add Subkey"), MB_ERR );
703     return FALSE;
704     }
705     if( k->is_protected ) {
706     pass = request_passphrase (_("Key Edit"), 1, &cancel);
707     if( cancel )
708     return FALSE;
709     }
710     ec = gpgme_editkey_new( &ek );
711     if( ec )
712     BUG( dlg );
713    
714 twoaday 12 memset (&keygen, 0, sizeof (keygen));
715     memset (&cb, 0, sizeof (cb));
716 twoaday 2 cb.ek = ek;
717 twoaday 12 cb.pass = k->is_protected? pass : NULL;
718 twoaday 2 cb.opaque = &keygen;
719 twoaday 19 dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_KEYEDIT_ADDSUBKEY,
720 twoaday 2 dlg, keyedit_addsubkey_dlg_proc,
721 twoaday 19 (LPARAM)&cb, _("Add new Subkey"),
722 twoaday 2 IDS_WINPT_KEYEDIT_ADDSUBKEY );
723     if( !gpgme_editkey_is_valid( ek ) ) {
724     free_if_alloc( pass );
725     return FALSE;
726     }
727    
728 twoaday 12 ec = gpgme_new (&ctx);
729     if (ec)
730     BUG (dlg);
731     gpgme_enable_logging (ctx);
732     gpgme_set_edit_ctx (ctx, ek, GPGME_EDITKEY_ADDKEY);
733     gpgme_set_progress_cb (ctx, keygen_cb, NULL);
734 twoaday 2 keygen_cb_dlg_create ();
735    
736 twoaday 12 ec = gpgme_op_editkey (ctx, k->keyid);
737     keygen.fpr = get_subkey_fingerprint (ctx, k->keyid);
738 twoaday 2 keygen_cb_dlg_destroy ();
739     keygen_cb (NULL, NULL, 0, 0, 0); /* flush */
740 twoaday 12 if (ec)
741     gpgme_show_error (dlg, ec, ctx, _("Add Subkey"), MB_ERR);
742 twoaday 2 else {
743 twoaday 12 msg_box (dlg, _("Subkey successfully added."), _("GnuPG Status"), MB_OK);
744     if (lv)
745     do_add_new_subkey (lv, &keygen, k->flags);
746 twoaday 19 k->update = 1;
747 twoaday 2 }
748 twoaday 12 free_if_alloc (pass);
749     gpgme_editkey_release (ek);
750     gpgme_release (ctx);
751 twoaday 2
752     return ec? FALSE : TRUE;
753     } /* keyedit_add_subkey */
754    
755    
756     BOOL
757 twoaday 19 keyedit_set_pref_keyserver (winpt_key_t k, HWND dlg)
758     {
759     gpgme_ctx_t ctx;
760     gpgme_editkey_t ek;
761     gpgme_error_t err;
762     struct URL_ctx_s *url;
763     char *pass;
764    
765     url = (struct URL_ctx_s *)get_keyserver_URL_dlg (dlg);
766     if (url->cancel == 1) {
767     delete url;
768     return FALSE;
769     }
770    
771     pass = request_passphrase (_("Key Edit"), 1, &url->cancel);
772     if (url->cancel) {
773     delete url;
774     return FALSE;
775     }
776    
777     err = gpgme_new (&ctx);
778     if (!err)
779     err = gpgme_editkey_new (&ek);
780     if (err)
781     BUG (0);
782     gpgme_editkey_keyserver_set (ek, url->url, -1, pass);
783     gpgme_set_edit_ctx (ctx, ek, GPGME_EDITKEY_KEYSERV);
784    
785     err = gpgme_op_editkey (ctx, k->keyid);
786     if (!err)
787     msg_box (dlg, _("Preferred keyserver successfully set."), _("Key Edit"), MB_OK);
788    
789     gpgme_release (ctx);
790     gpgme_editkey_release (ek);
791     free_if_alloc (pass);
792     delete url;
793     return err == 0? 0 : WPTERR_GENERAL;
794     }
795    
796    
797     BOOL
798 twoaday 2 keyedit_add_photo( winpt_key_t k, HWND dlg )
799     {
800     if( !k->key_pair ) {
801     msg_box( dlg, _("There is no secret key available!"), _("Add Photo"), MB_ERR );
802     return FALSE;
803     }
804     DialogBoxParam( glob_hinst, (LPCTSTR)IDD_WINPT_KEYEDIT_ADDPHOTO, dlg,
805     keyedit_addphoto_dlg_proc, (LPARAM)k );
806     return TRUE;
807     } /* keyedit_add_photo */
808    
809    
810     BOOL
811     keyedit_add_revoker (winpt_key_t k, HWND dlg)
812     {
813     if( !k->key_pair ) {
814     msg_box( dlg, _("There is no secret key available!"), _("Add Revoker"), MB_ERR );
815     return FALSE;
816     }
817     DialogBoxParam( glob_hinst, (LPCTSTR)IDD_WINPT_KEYEDIT_ADDREV, dlg,
818     keyedit_addrevoker_dlg_proc, (LPARAM)k );
819     return TRUE;
820     } /* keyedit_add_revoker */
821    
822    
823     static int
824     is_idea_protect_algo( const char * keyid )
825     {
826     gpgme_key_t key;
827     const char * sym_prefs;
828     size_t n;
829    
830     if( get_pubkey( keyid, &key ) )
831     BUG( NULL );
832     sym_prefs = gpgme_key_get_string_attr( key, GPGME_ATTR_KEY_SYMPREFS, NULL, 0 );
833 twoaday 20 if (!sym_prefs)
834 twoaday 2 return 1; /* assume that only v3 keys have no symmetric cipher preferences
835     and thus IDEA is explicit. */
836     for( n = 0; sym_prefs[n]; n++ )
837     ;
838     if( (n == 0 || n == 1) && *sym_prefs == 0x01 )
839     return 1;
840     return 0;
841     } /* is_idea_protect_algo */
842    
843    
844     BOOL
845     keyedit_change_passwd( winpt_key_t k, HWND dlg )
846     {
847     gpgme_error_t ec;
848     gpgme_ctx_t ctx;
849     gpgme_editkey_t ek;
850     char * old_pass = NULL, * new_pass = NULL;
851     int cancel = 0;
852    
853     if( !k->key_pair ) {
854     msg_box( dlg, _("There is no secret key available!"), _("Key Edit"), MB_ERR );
855     return FALSE;
856     }
857    
858     if( !idea_available && is_idea_protect_algo( k->keyid ) ) {
859     msg_box( dlg, _("Cannot change passphrase because the key\n"
860     "is protected with the IDEA encryption algorithm."),
861     _("Key Edit"), MB_ERR );
862     return FALSE;
863     }
864    
865     if( k->is_protected ) {
866     old_pass = request_passphrase( _("Current (old) Passphrase"), 1, &cancel );
867     if( cancel )
868     return FALSE;
869     }
870     new_pass = request_passphrase( _("New Passphrase" ), 1, &cancel );
871     if( cancel ) {
872     free_if_alloc( old_pass );
873     return FALSE;
874     }
875    
876     if( is_8bit_string( new_pass ) ) {
877     msg_box( dlg, _("The passphrase contains 8-bit characters.\n"
878     "It is not suggested to use charset specific characters."),
879     _("Key Edit"), MB_ERR );
880     free_if_alloc( old_pass );
881     free_if_alloc( new_pass );
882     return FALSE;
883     }
884    
885     ec = gpgme_new( &ctx );
886     if( !ec )
887     ec = gpgme_editkey_new( &ek );
888     if( ec )
889     BUG( NULL );
890     gpgme_enable_logging( ctx );
891     gpgme_editkey_passwd_set( ek, k->is_protected? old_pass : NULL, new_pass, 0 );
892     gpgme_set_edit_ctx( ctx, ek, GPGME_EDITKEY_PASSWD );
893     ec = gpgme_op_editkey( ctx, k->keyid );
894     if( ec )
895 twoaday 19 gpgme_show_error (dlg, ec, ctx, _("Change Passwd"), MB_ERR);
896 twoaday 2 else
897 twoaday 19 msg_box (dlg, _("Passphrase successfully changed."), _("GnuPG status"), MB_OK);
898     free_if_alloc (old_pass);
899     free_if_alloc (new_pass);
900     gpgme_editkey_release (ek);
901     gpgme_release (ctx);
902 twoaday 2 return TRUE;
903     } /* keyedit_change_passwd */
904    
905    
906     listview_ctrl_t
907     subkey_list_init( HWND dlg, winpt_key_t k )
908     {
909     LV_ITEM lvi;
910     gpgme_key_t key;
911     struct listview_column_s cols[] = {
912     {0, 80, (char *)_("Description")},
913     {1, 78, (char *)_("Key ID")},
914     {2, 66, (char *)_("Creation")},
915     {3, 66, (char *)_("Expires")},
916     {4, 64, (char *)_("Status")},
917     {5, 16, "C"/*ertify*/},
918     {6, 16, "S"/*ign*/},
919     {7, 16, "E"/*ncrypt*/},
920     {8, 16, "A"/*uth*/},
921     {0, 0, 0}
922     };
923     listview_ctrl_t lv;
924     char buf[256], tmp[128];
925     const char *t;
926     int nkeys = 0, rc = 0, i, bits, j;
927    
928     if( get_pubkey( k->keyid, &key ) ) {
929     msg_box( dlg, _("Could not find key."), _("Key Edit"), MB_ERR );
930     return NULL;
931     }
932    
933     nkeys = gpgme_key_count_items( key, GPGME_ATTR_KEYID );
934     if( !nkeys ) {
935     msg_box( dlg, _("No subkey(s) found."), _("Key Edit"), MB_ERR );
936     return NULL;
937     }
938    
939     rc = listview_new( &lv );
940     if( rc )
941     BUG( dlg );
942    
943     lv->ctrl = GetDlgItem( dlg, IDC_KEYEDIT_KEYLIST );
944     for( i = 0; cols[i].fieldname != NULL; i++ )
945     listview_add_column( lv, &cols[i] );
946    
947     for( i = 0; i < nkeys; i++ ) {
948     listview_add_item( lv, "" );
949     listview_add_sub_item( lv, 0, 1, "" );
950     memset( &lvi, 0, sizeof lvi );
951     lvi.mask = LVIF_PARAM;
952     lvi.lParam = (LPARAM )key;
953     if( ListView_SetItem( lv->ctrl, &lvi ) == FALSE )
954     return NULL;
955     }
956    
957     listview_set_ext_style( lv );
958     for( i = 0; i < nkeys; i++ ) {
959     memset( buf, 0, sizeof buf );
960    
961     bits = gpgme_key_get_ulong_attr( key, GPGME_ATTR_LEN, NULL, i );
962     _snprintf( tmp, sizeof tmp-1, "%d-bit ", bits );
963     strcat( buf, tmp );
964    
965     j = gpgme_key_get_ulong_attr( key, GPGME_ATTR_ALGO, NULL, i );
966     t = gpgme_key_expand_attr( GPGME_ATTR_ALGO, j );
967     _snprintf( tmp, sizeof tmp-1, "%s", t );
968     strcat( buf, tmp );
969    
970     listview_add_sub_item( lv, i, 0, buf );
971     t = gpgme_key_get_string_attr( key, GPGME_ATTR_KEYID, NULL, i );
972     if( !t )
973     t = "DEADBEEFDEADBEEF";
974     _snprintf( tmp, sizeof tmp-1, "0x%s", t+8 );
975     listview_add_sub_item( lv, i, 1, tmp );
976    
977     j = gpgme_key_get_ulong_attr( key, GPGME_ATTR_CREATED, NULL, i );
978     t = gpgme_key_expand_attr( GPGME_ATTR_CREATED, j );
979     if( !t )
980     t = "????-??-??";
981     listview_add_sub_item( lv, i, 2, t );
982    
983     j = gpgme_key_get_ulong_attr( key, GPGME_ATTR_EXPIRES, NULL, i );
984     if( j ) {
985     t = gpgme_key_expand_attr( GPGME_ATTR_CREATED, j );
986     listview_add_sub_item( lv, i, 3, t );
987     }
988     else
989     listview_add_sub_item( lv, i, 3, _("Never") );
990    
991     if( gpgme_key_get_ulong_attr(key, GPGME_ATTR_KEY_EXPIRED, NULL, i ) )
992     t = _("Expired");
993     else if( gpgme_key_get_ulong_attr( key, GPGME_ATTR_KEY_REVOKED, NULL, i ) )
994     t = _("Revoked");
995     else
996     t = _("OK");
997     listview_add_sub_item( lv, i, 4, t );
998    
999     gpgme_key_get_cability( key, GPGME_ATTR_CAN_CERTIFY, i )?
1000     t = "*" : t = "";
1001     listview_add_sub_item( lv, i, 5, t );
1002     gpgme_key_get_cability( key, GPGME_ATTR_CAN_SIGN, i )?
1003     t = "*" : t = "";
1004     listview_add_sub_item( lv, i, 6, t );
1005     gpgme_key_get_cability( key, GPGME_ATTR_CAN_ENCRYPT, i )?
1006     t = "*" : t = "";
1007     listview_add_sub_item( lv, i, 7, t );
1008    
1009     gpgme_key_get_cability (key, GPGME_ATTR_CAN_AUTH, i)?
1010     t = "*" : t = "";
1011     listview_add_sub_item (lv, i, 8, t);
1012     }
1013     return lv;
1014     } /* subkey_list_init */
1015    
1016    
1017     static listview_ctrl_t
1018     userid_list_init (HWND dlg, winpt_key_t k)
1019     {
1020     listview_ctrl_t lv = NULL;
1021     gpgme_key_t key;
1022     int nuids = 0, rc, j, u_attr;
1023     struct listview_column_s cols[] = {
1024     {0, 72, (char *)_("Validity")},
1025 twoaday 20 {1, 150, (char *)_("Name")},
1026     {2, 110, (char *)_("Email")},
1027 twoaday 16 {3, 76, (char *)_("Creation")},
1028 twoaday 2 {0, 0, 0}
1029     };
1030     const char *attr;
1031    
1032 twoaday 16 if (get_pubkey( k->keyid, &key)) {
1033 twoaday 2 msg_box( dlg, _("Could not find key."), _("Key Edit"), MB_ERR );
1034     return NULL;
1035     }
1036    
1037 twoaday 16 nuids = gpgme_key_count_items (key, GPGME_ATTR_USERID);
1038     if (!nuids) {
1039     msg_box (dlg, _("No user ID(s) found."), _("Key Edit"), MB_ERR);
1040 twoaday 2 return NULL;
1041     }
1042    
1043 twoaday 16 rc = listview_new (&lv);
1044 twoaday 2 if( rc )
1045     BUG( dlg );
1046     lv->ctrl = GetDlgItem( dlg, IDC_KEYEDIT_UIDLIST );
1047     for( j = 0; cols[j].fieldname != NULL; j++ )
1048     listview_add_column( lv, &cols[j] );
1049    
1050     for( j = 0; j < nuids; j++ ) {
1051     listview_add_item( lv, " " );
1052     listview_add_sub_item( lv, 0, 1, " " );
1053     }
1054    
1055     listview_set_ext_style (lv);
1056     for (j = 0; j < nuids; j++) {
1057     if (gpgme_key_get_ulong_attr (key, GPGME_ATTR_UID_REVOKED, NULL, j))
1058     attr = _("Revoked");
1059     else {
1060     u_attr = gpgme_key_get_ulong_attr (key, GPGME_ATTR_VALIDITY, NULL, j);
1061     attr = gpgme_key_expand_attr (GPGME_ATTR_VALIDITY, u_attr);
1062     }
1063     listview_add_sub_item( lv, j, 0, (char *)attr );
1064    
1065 twoaday 16 /* XXX: add comment if available */
1066     attr = gpgme_key_get_string_attr( key, GPGME_ATTR_NAME, NULL, j );
1067     if (attr) {
1068 twoaday 2 char * uid = utf8_to_wincp (attr, strlen (attr));
1069     if (uid) {
1070     listview_add_sub_item( lv, j, 1, uid );
1071     free( uid );
1072     }
1073     }
1074     else
1075     listview_add_sub_item( lv, j, 1, _("Invalid user ID") );
1076 twoaday 16 attr = gpgme_key_get_string_attr (key, GPGME_ATTR_EMAIL, NULL, j);
1077     if (attr)
1078     listview_add_sub_item (lv, j, 2, attr);
1079 twoaday 2 u_attr = gpgme_key_get_ulong_attr (key, GPGME_ATTR_UID_CREATED, NULL, j);
1080     if (u_attr)
1081 twoaday 16 listview_add_sub_item (lv, j, 3, get_key_created (u_attr));
1082 twoaday 2 }
1083     if( !k->key_pair ) {
1084     CheckDlgButton( dlg, IDC_KEYUID_ADD, BST_INDETERMINATE );
1085     CheckDlgButton( dlg, IDC_KEYUID_REVOKE, BST_INDETERMINATE );
1086     }
1087     return lv;
1088     } /* userid_list_init */
1089    
1090    
1091     static void
1092     do_init_cmdlist( HWND dlg )
1093     {
1094     const char *cmdlist[] = {
1095     "ADDKEY",
1096     "ADDUID",
1097     "ADDPHOTO",
1098     "ADDREVOKER",
1099     /*"FPR",*/
1100     "DELUID",
1101     "DELKEY",
1102     "DELPHOTO",
1103     /*"DELSIG",*/
1104     "EXPIRE",
1105 twoaday 16 /*"PREF",*/
1106 twoaday 2 "SHOWPREF",
1107 twoaday 16 /*"SETPREF",*/
1108 twoaday 2 "PASSWD",
1109     "PRIMARY",
1110     "TRUST",
1111     /*"REVSIG",*/
1112     "REVUID",
1113     "REVKEY",
1114     "DISABLE",
1115     "ENABLE",
1116     "SHOWPHOTO",
1117     NULL
1118     };
1119     const char * s;
1120     int i = 0;
1121    
1122     for( i = 0; (s=cmdlist[i]); i++ ) {
1123     SendDlgItemMessage( dlg, IDC_KEYEDIT_CMD, CB_ADDSTRING, 0,
1124     (LPARAM)(char *)s );
1125     }
1126     SendDlgItemMessage( dlg, IDC_KEYEDIT_CMD, CB_SETCURSEL, 0, 0 );
1127     } /* do_init_cmdlist */
1128    
1129    
1130     static int
1131     is_cmd_openpgp( int cmdid )
1132     {
1133     switch( cmdid ) {
1134     case CMD_ADDKEY:
1135     case CMD_ADDPHOTO:
1136     case CMD_ADDREVOKER:
1137     case CMD_DELPHOTO:
1138     /*case CMD_SHOWPHOTO:*/
1139 twoaday 22 /*case CMD_SETPREF:*/
1140 twoaday 2 return 1;
1141     }
1142     return 0;
1143     } /* is_cmd_openpgp */
1144    
1145    
1146     static void
1147     do_show_help( HWND dlg )
1148     {
1149     char helptext[2048];
1150    
1151     _snprintf( helptext, sizeof helptext-1,
1152     _(/*"FPR \t\tshow fingerprint\r\n"*/
1153     "ADDUID \t\tadd a user ID\r\n"
1154     "ADDPHOTO \t\tadd a photo ID\r\n"
1155     "DELUID \t\tdelete a user ID\r\n"
1156     "ADDKEY \t\tadd a secondard key\r\n"
1157     "DELKEY \t\tdelete a secondary key\r\n"
1158     "ADDREVOKER\t\tadd a revocation key\r\n"
1159     /*"DELSIG \t\tdelete signatures\r\n"*/
1160     "EXPIRE \t\tchange the expire date\r\n"
1161     /*"PREF \t\tlist preferences (expert)\r\n"
1162     "SHOWPREF \t\tlist preferences (verbose)\r\n"
1163     "SETPREF \t\tset preference list\r\n"*/
1164     "UPDPREF \t\tupdated preferences\r\n"
1165     "PASSWD \t\tchange the passphrase\r\n"
1166     "PRIMARY \t\tflag user ID as primary\r\n"
1167     "TRUST \t\tchange the ownertrust\r\n"
1168     /*"REVSIG \t\trevoke signatures\r\n"*/
1169     "REVUID \t\trevoke a user ID\r\n"
1170     "REVKEY \t\trevoke a secondary key\r\n"
1171     "DISABLE \t\tdisable a key\r\n"
1172     "ENABLE \t\tenable a key\r\n"
1173     /*"SHOWPHOTO \t\tshow photo ID\r\n"*/) );
1174     msg_box( dlg, helptext, _("Key Edit Help"), MB_OK );
1175     } /* do_show_help */
1176    
1177    
1178     static int
1179 twoaday 19 do_editkey_delkey (winpt_key_t k, HWND dlg, listview_ctrl_t lv)
1180 twoaday 2 {
1181     int j, id;
1182     char tmp[64];
1183     gpgme_error_t ec;
1184     gpgme_editkey_t ek;
1185     gpgme_ctx_t ctx;
1186    
1187 twoaday 19 if (!k->key_pair)
1188     return FALSE; /* XXX: shall we allow to modify non-secret keys?? */
1189    
1190 twoaday 2 if( listview_count_items( lv, 0 ) == 1 ) {
1191     msg_box( dlg, _("Primary key can not be deleted!"), _("Key Edit"), MB_ERR);
1192     return FALSE;
1193     }
1194     if( (j = listview_get_curr_pos( lv )) == -1 ) {
1195     msg_box( dlg, _("Please select a key."), _("Key Edit"), MB_ERR );
1196     return FALSE;
1197     }
1198     if( j == 0 ) {
1199     msg_box( dlg, _("Primary subkey can not be deleted!"), _("Key Edit"), MB_ERR );
1200     return FALSE;
1201     }
1202    
1203     listview_get_item_text( lv, j, 0, tmp, sizeof tmp -1 );
1204     id = log_box( _("Key Edit"), MB_YESNO|MB_ICONWARNING,
1205     _("\"Subkey %s.\"\n\n"
1206     "Anything encrypted to the selected subkey will no longer\n"
1207     "be able to be decrypted.\n\n"
1208     "Do you really want to delete this subkey?"), tmp );
1209     if( id == IDNO )
1210     return FALSE;
1211    
1212     ec = gpgme_new( &ctx );
1213     if( !ec )
1214     ec = gpgme_editkey_new( &ek );
1215     if( ec )
1216     BUG( dlg );
1217     gpgme_enable_logging( ctx );
1218     gpgme_editkey_delkey_set_id( ek, j );
1219     gpgme_set_edit_ctx( ctx, ek, GPGME_EDITKEY_DELKEY );
1220     ec = gpgme_op_editkey( ctx, k->keyid );
1221     if( ec )
1222     gpgme_show_error( dlg, ec, ctx, _("Delete Subkey"), MB_ERR );
1223     else {
1224     listview_del_item( lv, j );
1225 twoaday 19 k->update = 1;
1226 twoaday 2 status_box( dlg, _("Subkey successfully deleted."), _("GnuPG status") );
1227     }
1228     gpgme_editkey_release( ek );
1229     gpgme_release( ctx );
1230     return ec? FALSE : TRUE;
1231     } /* do_editkey_delkey */
1232    
1233    
1234     static int
1235     do_editkey_expire( winpt_key_t k, HWND dlg, listview_ctrl_t lv )
1236     {
1237     gpgme_error_t ec;
1238     gpgme_editkey_t ek;
1239     gpgme_ctx_t ctx;
1240     date_s udd = {0};
1241     char buf[256], * pass = NULL;
1242     int j, cancel = 0;
1243    
1244     if( !k->key_pair ) {
1245     msg_box( dlg, _("There is no secret key available!"), _("Key Edit"), MB_ERR );
1246     return FALSE;
1247     }
1248     if ( (j = listview_get_curr_pos( lv )) == -1 ) {
1249     msg_box( dlg, _("Please select a key."), _("Key Edit"), MB_ERR );
1250     return FALSE;
1251     }
1252    
1253     listview_get_item_text( lv, j, 3, buf, sizeof buf -1 );
1254     if( !strcmp( buf, _("Expired") ) ) {
1255     msg_box( dlg, _("Key already expired!"), _("Key Edit"), MB_ERR );
1256     return FALSE;
1257     }
1258     memset( &udd, 0, sizeof udd );
1259     udd.text = _("Key Expiration Date");
1260     dialog_box_param( glob_hinst, (LPCSTR)IDD_WINPT_DATE, dlg,
1261     date_dlg_proc, (LPARAM)&udd,
1262     _("Key Expiration Date"), IDS_WINPT_DATE );
1263     if( udd.cancel == 1 )
1264     return FALSE;
1265     if( !keygen_check_date( &udd.st ) ) {
1266     msg_box( dlg, _("The date you have chosen lies in the past."), _("Key Edit"), MB_ERR );
1267     return FALSE;
1268     }
1269     if( k->is_protected ) {
1270     pass = request_passphrase (_("Key Edit"), 1, &cancel );
1271     if( cancel )
1272     return FALSE;
1273     }
1274     _snprintf( buf, sizeof buf - 1, "%04d-%02d-%02d",
1275     udd.st.wYear, udd.st.wMonth, udd.st.wDay );
1276     ec = gpgme_editkey_new( &ek );
1277     if( !ec )
1278     ec = gpgme_new( &ctx );
1279     if( ec )
1280     BUG( dlg );
1281     gpgme_editkey_expire_set( ek, j, 0, buf, k->is_protected? pass : NULL );
1282     gpgme_enable_logging( ctx );
1283     gpgme_set_edit_ctx( ctx, ek, GPGME_EDITKEY_EXPIRE );
1284     ec = gpgme_op_editkey( ctx, k->keyid );
1285     if( ec )
1286     gpgme_show_error( dlg, ec, ctx, _("Expire Subkey"), MB_ERR );
1287     else {
1288     listview_add_sub_item( lv, j, 3, buf );
1289 twoaday 19 k->update = 1;
1290 twoaday 2 msg_box( dlg, _("Subkey expire date successfully set."), _("GnuPG status"), MB_OK );
1291     }
1292     free_if_alloc( pass );
1293     gpgme_release( ctx );
1294     gpgme_editkey_release( ek );
1295     return TRUE;
1296     } /* do_editkey_expire */
1297    
1298    
1299     static int
1300     do_editkey_revoke( winpt_key_t k, HWND dlg, listview_ctrl_t lv )
1301     {
1302     gpgme_ctx_t ctx;
1303     gpgme_error_t ec;
1304     gpgme_editkey_t ek;
1305     char buf[256], * pass = NULL;
1306     int j, cancel = 0;
1307    
1308     if( !k->key_pair ) {
1309     msg_box( dlg, _("There is no secret key available!"), _("Key Edit"), MB_ERR );
1310     return FALSE;
1311    
1312     }
1313    
1314     if( (j = listview_get_curr_pos( lv )) == -1 ) {
1315     msg_box( dlg, _("Please select a key."), _("Key Edit"), MB_ERR );
1316     return FALSE;
1317     }
1318     else if( listview_count_items( lv, 0 ) == 1 ) {
1319     msg_box( dlg, _("No subkeys were found, if you want to revoke the\n"
1320     "whole key, please use the Key Manager command directly.\n\n"
1321     "This command is only available to revoke single subkeys"),
1322     _("Key Edit"), MB_INFO );
1323     return FALSE;
1324     }
1325    
1326     listview_get_item_text( lv, j, 3, buf, sizeof buf-1 );
1327     if( !strcmp( buf, _("Revoked") ) ) {
1328     msg_box( dlg, _("Key already revoked."), _("Key Edit"), MB_ERR );
1329     return FALSE;
1330     }
1331    
1332     if( k->is_protected ) {
1333     pass = request_passphrase (_("Key Edit"), 1, &cancel);
1334     if( cancel )
1335     return FALSE;
1336     }
1337    
1338     ec = gpgme_editkey_new( &ek );
1339     if( !ec )
1340     ec = gpgme_new( &ctx );
1341     if( ec )
1342     BUG( NULL );
1343     gpgme_enable_logging( ctx );
1344     gpgme_editkey_revkey_set( ek, j, 0, k->is_protected? pass : NULL );
1345     gpgme_set_edit_ctx( ctx, ek, GPGME_EDITKEY_REVKEY );
1346     ec = gpgme_op_editkey( ctx, k->keyid );
1347     if( ec )
1348     gpgme_show_error( dlg, ec, ctx, _("Revoke Subkey"), MB_ERR );
1349     else {
1350     listview_add_sub_item( lv, j, 5, _("Revoked") );
1351 twoaday 19 k->update = 1;
1352 twoaday 2 msg_box( dlg, _("Subkey successfully revoked."), _("GnuPG Status"), MB_OK );
1353     }
1354     free_if_alloc( pass );
1355     gpgme_release( ctx );
1356     gpgme_editkey_release( ek );
1357     return TRUE;
1358     } /* do_editkey_revoke */
1359    
1360    
1361     int
1362 twoaday 16 do_editkey_revuid (winpt_key_t k, HWND dlg, listview_ctrl_t lv)
1363 twoaday 2 {
1364     gpgme_ctx_t ctx;
1365     gpgme_error_t ec;
1366     gpgme_editkey_t ek;
1367     char buf[256], t[512], * pass;
1368     int cancel = 0, id = 0, j;
1369    
1370     if( !k->key_pair ) {
1371     msg_box( dlg, _("There is no secret key available!"), _("Revoke user ID"), MB_ERR );
1372     return FALSE;
1373     }
1374    
1375     if( listview_count_items( lv, 0 ) == 1 ) {
1376     msg_box( dlg, _("Key has only one user ID."), _("Key Edit"), MB_ERR );
1377     return FALSE;
1378     }
1379    
1380     if( (j = listview_get_curr_pos( lv )) == -1 ) {
1381     msg_box( dlg, _("Please select a user ID."), _("Key Edit"), MB_ERR );
1382     return FALSE;
1383     }
1384    
1385     listview_get_item_text( lv, j, 0, buf, sizeof buf - 1 );
1386     if( strstr( buf, _("Revoked") ) ) {
1387     msg_box( dlg, _("This user ID has been already revoked."), _("Key Edit"), MB_INFO );
1388     return FALSE;
1389     }
1390    
1391     listview_get_item_text( lv, j, 1, buf, sizeof buf -1 );
1392     _snprintf( t, sizeof t -1, _("user ID \"%s\".\n\n"
1393     "Do you really want to revoke this user ID?"), buf );
1394 twoaday 16 if( msg_box( dlg, t, _("Key Edit"), MB_WARN_ASK) == IDNO )
1395 twoaday 2 return FALSE;
1396     if( k->is_protected ) {
1397     pass = request_passphrase (_("Key Edit"), 1, &cancel);
1398     if( cancel )
1399     return FALSE;
1400     }
1401 twoaday 16 id = do_find_userid (k->keyid, buf, NULL);
1402     if (id == -1)
1403     BUG (dlg);
1404     ec = gpgme_new (&ctx);
1405     if (!ec)
1406     ec = gpgme_editkey_new (&ek);
1407 twoaday 2 if( ec )
1408     BUG( dlg );
1409     gpgme_enable_logging( ctx );
1410     gpgme_editkey_revsig_set( ek, id, k->is_protected? pass : NULL );
1411     gpgme_set_edit_ctx( ctx, ek, GPGME_EDITKEY_REVSIG );
1412     ec = gpgme_op_editkey( ctx, k->keyid );
1413 twoaday 16 if (ec)
1414     gpgme_show_error (dlg, ec, ctx, _("Revoke Signature"), MB_ERR);
1415 twoaday 2 else {
1416 twoaday 16 listview_add_sub_item (lv, j, 0, _("Revoked"));
1417 twoaday 19 k->update = 1;
1418 twoaday 16 status_box (dlg, _("User ID successfully revoked"), _("GnuPG Status"));
1419 twoaday 2 }
1420 twoaday 16 free_if_alloc (pass);
1421     gpgme_editkey_release (ek);
1422     gpgme_release (ctx);
1423 twoaday 2 return ec? FALSE : TRUE;
1424     } /* do_editkey_revuid */
1425    
1426    
1427     static int
1428     do_editkey_setpref (winpt_key_t k, HWND dlg, listview_ctrl_t lv)
1429     {
1430     gpgme_ctx_t ctx;
1431     gpgme_editkey_t ek;
1432     gpgme_error_t rc;
1433     char buf[256], * pass = NULL, * prefs;
1434     int j, id, cancel=0, flags=0;
1435    
1436     if ((j = listview_get_curr_pos (lv)) == -1) {
1437     msg_box (dlg, _("Please select a user ID."), _("Key Edit"), MB_ERR);
1438     return FALSE;
1439     }
1440     listview_get_item_text (lv, j, 1, buf, sizeof buf-1);
1441 twoaday 16 id = do_find_userid (k->keyid, buf, NULL);
1442 twoaday 2 if (id == -1)
1443     BUG (dlg);
1444     if (k->is_protected) {
1445     pass = request_passphrase (_("Key Edit"), 1, &cancel);
1446     if (cancel)
1447     return FALSE;
1448     }
1449     rc = gpgme_new (&ctx);
1450     if (!rc)
1451     rc = gpgme_editkey_new (&ek);
1452     if (rc)
1453     BUG (NULL);
1454    
1455     get_userid_preflist (&prefs, &flags);
1456     gpgme_editkey_setpref_set (ek, prefs, id, pass);
1457     gpgme_set_edit_ctx (ctx, ek, GPGME_EDITKEY_SETPREF);
1458     rc = gpgme_op_editkey (ctx, k->keyid);
1459     free_if_alloc (pass);
1460    
1461     free_if_alloc (prefs);
1462     gpgme_release (ctx);
1463     gpgme_editkey_release (ek);
1464     return 0;
1465     }
1466    
1467    
1468     static int
1469 twoaday 22 do_editkey_primary (winpt_key_t k, HWND dlg, listview_ctrl_t lv)
1470 twoaday 2 {
1471     gpgme_ctx_t ctx;
1472     gpgme_editkey_t ek;
1473     gpgme_error_t ec;
1474     int j, id, cancel=0;
1475     char buf[256], * pass = NULL;
1476    
1477 twoaday 22 if (listview_count_items (lv, 0) == 1)
1478     return TRUE;
1479     if ((j = listview_get_curr_pos (lv)) == -1) {
1480 twoaday 2 msg_box( dlg, _("Please select a user ID."), _("Key Edit"), MB_ERR );
1481     return FALSE;
1482     }
1483     listview_get_item_text( lv, j, 1, buf, sizeof buf-1 );
1484 twoaday 16 id = do_find_userid (k->keyid, buf, NULL);
1485 twoaday 22 if (id == -1)
1486 twoaday 2 BUG( dlg );
1487 twoaday 22 if (k->is_protected) {
1488 twoaday 2 pass = request_passphrase( _("Key Edit"), 1, &cancel );
1489     if( cancel )
1490     return FALSE;
1491     }
1492    
1493     ec = gpgme_new( &ctx );
1494     if( !ec )
1495     ec = gpgme_editkey_new( &ek );
1496     if( ec )
1497     BUG( dlg );
1498     gpgme_enable_logging( ctx );
1499     gpgme_editkey_primary_set( ek, id, k->is_protected? pass : NULL );
1500     gpgme_set_edit_ctx( ctx, ek, GPGME_EDITKEY_PRIMARY );
1501     ec = gpgme_op_editkey( ctx, k->keyid );
1502     if( ec )
1503     gpgme_show_error( dlg, ec, ctx, _("Primary"), MB_ERR );
1504     else {
1505 twoaday 19 k->update = 1;
1506 twoaday 2 status_box( dlg, _("User ID successfully flagged"), _("GnuPG Status") );
1507     }
1508    
1509     free_if_alloc( pass );
1510     gpgme_editkey_release( ek );
1511     gpgme_release( ctx );
1512     return ec? FALSE : TRUE;
1513     } /* do_editkey_primary */
1514    
1515    
1516     static int
1517 twoaday 16 parse_preflist (HWND dlg, const char *list)
1518 twoaday 2 {
1519 twoaday 20 char *p, buf[128] = {0}, *pbuf = buf;
1520 twoaday 16 const char *ciphers[11] = {0, "IDEA", "3DES", "CAST5", "BLOWFISH", 0, 0, "AES", "AES192", "AES256", "TWOFISH"};
1521 twoaday 20 const char *hash[11] = {0, "MD5", "SHA1", "RMD160", 0, 0, 0, 0, "SHA256", "SHA384", "SHA512"};
1522 twoaday 16 const char *compress[4] = {0, "ZIP", "ZLIB", "BZIP2"};
1523     int n=0;
1524    
1525 twoaday 20 strncpy (buf, list, 127);
1526     p = strtok (pbuf, " ");
1527 twoaday 16 while (p != NULL) {
1528     int algid = atol (p+1);
1529     n++;
1530     switch (*p) {
1531     case 'S':
1532     SendDlgItemMessage (dlg, IDC_SHOWPREF_CIPHERS, LB_ADDSTRING, 0, (LPARAM)(const char*)ciphers[algid % 11]);
1533     break;
1534    
1535     case 'H':
1536 twoaday 20 SendDlgItemMessage (dlg, IDC_SHOWPREF_HASH, LB_ADDSTRING, 0, (LPARAM)(const char*)hash[algid % 10]);
1537 twoaday 16 break;
1538    
1539     case 'Z':
1540     SendDlgItemMessage (dlg, IDC_SHOWPREF_ZIP, LB_ADDSTRING, 0, (LPARAM)(const char*)compress[algid % 4]);
1541     break;
1542    
1543     default:
1544     n--;
1545     }
1546     p = strtok (NULL, " ");
1547     }
1548     return n;
1549     }
1550    
1551     BOOL CALLBACK
1552     showpref_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
1553     {
1554     static keyedit_callback_s *cb = NULL;
1555     gpgme_uidinfo_t inf=NULL;
1556     char buf[128];
1557     int pos;
1558    
1559     switch (msg) {
1560     case WM_INITDIALOG:
1561     cb = (keyedit_callback_s *)lparam;
1562     if (cb == NULL)
1563     BUG (dlg);
1564     listview_get_item_text (cb->lv, listview_get_curr_pos (cb->lv), 2, buf, DIM (buf)-1);
1565     SetDlgItemText (dlg, IDC_SHOWPREF_INFO, buf);
1566     pos = do_find_userid (((winpt_key_t)cb->opaque)->keyid, buf, &inf);
1567     if (inf) {
1568     const char *prefs;
1569     prefs = gpgme_editkey_get_string_attr (inf, GPGME_ATTR_UID_PREFS, pos-1);
1570     if (prefs && *prefs) {
1571     if (parse_preflist (dlg, prefs) <= 0)
1572     pos = -1;
1573     }
1574     else
1575     pos = -1;
1576     gpgme_uid_info_release (inf);
1577     if (pos == -1) {
1578     msg_box (dlg, _("No preferences available."), _("Key Edit"), MB_ERR);
1579     EndDialog (dlg, TRUE);
1580     }
1581 twoaday 19 if (gpgme_editkey_get_ulong_attr (inf, GPGME_ATTR_MDC, 0))
1582     CheckDlgButton (dlg, IDC_SHOWPREF_MDC, BST_CHECKED);
1583 twoaday 16 }
1584     SetForegroundWindow (dlg);
1585     break;
1586    
1587     case WM_COMMAND:
1588     switch (LOWORD (wparam)) {
1589     case IDOK:
1590     EndDialog (dlg, TRUE);
1591     break;
1592     }
1593     break;
1594     }
1595     return FALSE;
1596     }
1597    
1598     static int
1599     do_editkey_showpref (winpt_key_t k, HWND dlg, listview_ctrl_t lv)
1600     {
1601     struct keyedit_callback_s cb;
1602     if (listview_get_curr_pos (lv) == -1) {
1603     msg_box (dlg, _("Please select a user ID."), _("Key Edit"), MB_ERR);
1604     return FALSE;
1605     }
1606    
1607     memset (&cb, 0, sizeof (cb));
1608     cb.lv = lv;
1609     cb.opaque = k;
1610     DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_KEYEDIT_SHOWPREF, dlg,
1611     showpref_dlg_proc, (LPARAM)&cb);
1612     return 0;
1613     }
1614    
1615    
1616     static int
1617     do_editkey_deluid (winpt_key_t k, HWND dlg, listview_ctrl_t lv)
1618     {
1619 twoaday 2 gpgme_ctx_t ctx;
1620     gpgme_editkey_t ek;
1621     gpgme_error_t ec;
1622     char buf[256], t[512];
1623     int j, id = 0;
1624    
1625 twoaday 19 if (!k->key_pair)
1626     return FALSE; /* XXX: see do_editkey_delsubkey */
1627    
1628 twoaday 2 if( listview_count_items( lv, 0 ) == 1 ) {
1629     msg_box( dlg, _("Primary user ID can not be deleted!"), _("Key Edit"), MB_ERR );
1630     return FALSE;
1631     }
1632     if( (j = listview_get_curr_pos( lv )) == -1 ) {
1633     msg_box( dlg, _("Please select a user ID."), _("Key Edit"), MB_ERR );
1634     return FALSE;
1635     }
1636    
1637 twoaday 19 /* XXX: add a hint that also all signatures will be deleted? */
1638 twoaday 16 listview_get_item_text( lv, j, 1, buf, DIM(buf) -1 );
1639 twoaday 19 _snprintf( t, DIM (t)-1, _("user ID \"%s\".\n\n"
1640     "Do you really want to delete this user ID?"),
1641     buf);
1642 twoaday 2 if( msg_box( dlg, t, _("Key Edit"), MB_YESNO|MB_ICONWARNING ) == IDNO )
1643     return FALSE;
1644    
1645 twoaday 16 listview_get_item_text (lv, j, 2, buf, DIM (buf)-1);
1646     id = do_find_userid (k->keyid, buf, NULL);
1647     if (id == -1)
1648     BUG (dlg);
1649 twoaday 2 ec = gpgme_new( &ctx );
1650     if( !ec )
1651     ec = gpgme_editkey_new( &ek );
1652     if( ec )
1653     BUG( dlg );
1654     gpgme_enable_logging( ctx );
1655     gpgme_editkey_deluid_set_id( ek, id );
1656     gpgme_set_edit_ctx( ctx, ek, GPGME_EDITKEY_DELUID );
1657     ec = gpgme_op_editkey( ctx, k->keyid );
1658     if( ec )
1659     gpgme_show_error( dlg, ec, ctx, _("Delete user ID"), MB_ERR );
1660     else {
1661     listview_del_item( lv, j );
1662 twoaday 19 k->update = 1;
1663 twoaday 2 status_box( dlg, _("User ID successfully deleted"), _("GnuPG Status") );
1664     }
1665     gpgme_editkey_release( ek );
1666     gpgme_release( ctx );
1667     return ec? FALSE : TRUE;
1668     } /* do_editkey_deluid */
1669    
1670    
1671    
1672     static BOOL CALLBACK
1673     subkey_subclass_proc( HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam )
1674     {
1675     switch( msg ) {
1676     case WM_KEYUP:
1677     int virt_key = (int)wparam;
1678     switch( virt_key ) {
1679     case VK_DELETE:
1680     SendDlgItemMessage( keyedit_subkey_proc.dlg, IDC_KEYEDIT_CMD,
1681     CB_SETCURSEL, CMD_DELKEY, 0 );
1682     send_cmd_id( keyedit_subkey_proc.dlg, IDOK );
1683     break;
1684    
1685     case VK_INSERT:
1686     SendDlgItemMessage( keyedit_subkey_proc.dlg, IDC_KEYEDIT_CMD,
1687     CB_SETCURSEL, CMD_ADDKEY, 0 );
1688     send_cmd_id( keyedit_subkey_proc.dlg, IDOK );
1689     break;
1690     }
1691     }
1692     return CallWindowProc( keyedit_subkey_proc.old, dlg, msg, wparam, lparam );
1693     } /* subkey_subclass_proc */
1694    
1695    
1696     static BOOL CALLBACK
1697 twoaday 16 uid_subclass_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
1698 twoaday 2 {
1699     switch( msg ) {
1700     case WM_KEYUP:
1701     int virt_key = (int)wparam;
1702 twoaday 16 switch (virt_key) {
1703 twoaday 2 case VK_DELETE:
1704 twoaday 16 SendDlgItemMessage (keyedit_uid_proc.dlg, IDC_KEYEDIT_CMD,
1705     CB_SETCURSEL, CMD_DELUID, 0);
1706     send_cmd_id (keyedit_uid_proc.dlg, IDOK);
1707 twoaday 2 break;
1708    
1709     case VK_INSERT:
1710 twoaday 16 SendDlgItemMessage (keyedit_uid_proc.dlg, IDC_KEYEDIT_CMD,
1711     CB_SETCURSEL, CMD_ADDUID, 0);
1712     send_cmd_id (keyedit_uid_proc.dlg, IDOK);
1713 twoaday 2 break;
1714     }
1715     }
1716     return CallWindowProc( keyedit_uid_proc.old, dlg, msg, wparam, lparam );
1717     } /* uid_subclass_proc */
1718    
1719    
1720     BOOL CALLBACK
1721     keyedit_main_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
1722     {
1723     static winpt_key_t k;
1724     static listview_ctrl_t lvsub = NULL, lvuid = NULL;
1725     int cmd, idxsub = 0;
1726     HWND item;
1727    
1728     switch( msg ) {
1729     case WM_INITDIALOG:
1730     k = (winpt_key_t)lparam;
1731 twoaday 16 if (!k)
1732     BUG (NULL);
1733     do_init_cmdlist (dlg);
1734     lvsub = subkey_list_init (dlg, k);
1735 twoaday 2 if( !lvsub )
1736     BUG( NULL );
1737     lvuid = userid_list_init (dlg, k);
1738     if( !lvuid )
1739     BUG( NULL );
1740     item = GetDlgItem( dlg, IDC_KEYEDIT_KEYLIST );
1741     keyedit_subkey_proc.dlg = dlg;
1742     keyedit_subkey_proc.current = (WNDPROC)subkey_subclass_proc;
1743     keyedit_subkey_proc.old = (WNDPROC)GetWindowLong( item, GWL_WNDPROC );
1744     if( keyedit_subkey_proc.old ) {
1745     if( !SetWindowLong( item, GWL_WNDPROC, (LONG)keyedit_subkey_proc.current ) ) {
1746     msg_box( dlg, _("Could not set subkey window procedure."), _("Key Edit"), MB_ERR );
1747     BUG( NULL );
1748     }
1749     }
1750     item = GetDlgItem( dlg, IDC_KEYEDIT_UIDLIST );
1751     keyedit_uid_proc.dlg = dlg;
1752     keyedit_uid_proc.current = (WNDPROC)uid_subclass_proc;
1753     keyedit_uid_proc.old = (WNDPROC)GetWindowLong( item, GWL_WNDPROC );
1754     if( keyedit_uid_proc.old ) {
1755     if( !SetWindowLong( item, GWL_WNDPROC, (LONG)keyedit_uid_proc.current ) ) {
1756     msg_box( dlg, _("Could not set user ID window procedure."), _("Key Edit"), MB_ERR );
1757     BUG( NULL );
1758     }
1759     }
1760     if (!k->key_pair) {
1761     EnableWindow (GetDlgItem (dlg, IDC_KEYEDIT_CMD), FALSE);
1762     EnableWindow (GetDlgItem (dlg, IDOK), FALSE);
1763     }
1764     SetForegroundWindow( dlg );
1765     center_window( dlg );
1766     return TRUE;
1767    
1768     case WM_DESTROY:
1769     if( lvsub ) {
1770     listview_release( lvsub );
1771     lvsub = NULL;
1772     }
1773     if( lvuid ) {
1774     listview_release( lvuid );
1775     lvuid = NULL;
1776     }
1777     break;
1778    
1779 twoaday 16 case WM_NOTIFY:
1780     NMHDR * notify;
1781     notify = (NMHDR *)lparam;
1782     if (notify && notify->code == NM_DBLCLK &&
1783     notify->idFrom == IDC_KEYEDIT_UIDLIST)
1784     do_editkey_showpref (k, dlg, lvuid);
1785     break;
1786    
1787 twoaday 2 case WM_COMMAND:
1788     switch( LOWORD( wparam ) ) {
1789     case IDOK:
1790 twoaday 22 cmd = SendDlgItemMessage (dlg, IDC_KEYEDIT_CMD, CB_GETCURSEL, 0, 0);
1791     if (cmd == LB_ERR) {
1792 twoaday 2 msg_box( dlg, _("Please select a command."), _("Key Edit"), MB_INFO );
1793     return FALSE;
1794     }
1795 twoaday 22 idxsub = listview_get_curr_pos (lvsub);
1796 twoaday 20 if (k->is_v3 && is_cmd_openpgp (cmd)) {
1797     msg_box (dlg, _("This command cannot be used with PGP 2 (v3) keys.\n"),
1798     _("Key Edit"), MB_ERR);
1799 twoaday 2 return FALSE;
1800     }
1801 twoaday 20 switch (cmd) {
1802 twoaday 16 case CMD_SHOWPREF: do_editkey_showpref (k, dlg, lvuid); break;
1803     case CMD_DELKEY: do_editkey_delkey (k, dlg, lvsub); break;
1804     case CMD_ADDKEY: keyedit_add_subkey (k, dlg, lvsub); break;
1805     case CMD_EXPIRE: do_editkey_expire (k, dlg, lvsub); break;
1806     case CMD_REVKEY: do_editkey_revoke (k, dlg, lvsub); break;
1807     /*case CMD_SETPREF:do_editkey_setpref( k, dlg, lvuid ); break;*/
1808 twoaday 2 case CMD_ADDUID: keyedit_add_userid( k, dlg, lvuid ); break;
1809     case CMD_ADDREVOKER: keyedit_add_revoker( k, dlg ); break;
1810     case CMD_ADDPHOTO: keyedit_add_photo( k, dlg ); break;
1811     case CMD_REVUID: do_editkey_revuid( k, dlg, lvuid ); break;
1812     case CMD_DELUID: do_editkey_deluid( k, dlg, lvuid ); break;
1813     case CMD_PASSWD: keyedit_change_passwd( k, dlg ); break;
1814     case CMD_PRIMARY: do_editkey_primary( k, dlg, lvuid ); break;
1815     case CMD_ENABLE: km_enable_disable_key( lvsub, dlg, idxsub, 1 ); break;
1816     case CMD_DISABLE: km_enable_disable_key( lvsub, dlg, idxsub, 0 ); break;
1817     }
1818     break;
1819    
1820     case IDCANCEL:
1821 twoaday 19 EndDialog (dlg, FALSE);
1822 twoaday 2 break;
1823    
1824     case IDC_KEYEDIT_HELP:
1825 twoaday 16 do_show_help (dlg);
1826 twoaday 2 break;
1827     }
1828     break;
1829     }
1830     return FALSE;
1831     } /* keyedit_main_dlg_proc */

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26