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

Annotation of /trunk/Src/wptKeyEditDlgs.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 128 - (hide annotations)
Mon Dec 19 13:05:59 2005 UTC (19 years, 2 months ago) by twoaday
File size: 50651 byte(s)
2005-12-17  Timo Schulz  <ts@g10code.com>
 
        * wptUTF8.cpp: Removed unused charset array.
        * wptSigList.cpp (siglist_build): Increase size for 'class'
        column.
        * wptGPG.cpp (get_gnupg_path): Simplified.
        * WinPT.cpp (load_gpg_env): New.
        (check_crypto_engine): Return type is now bool.
        * wptRegistry.cpp (is_gpg4win_installed): New.
        * wptGPGPrefsDlg.cpp (gpgprefs_dlg_proc): More consistent
        dialog design.
        * wptKeyManagerDlg.cpp (translate_menu_strings): New.
        (translate_popupmenu_strings): New.
        * wptKeyEditDlgs.cpp (is_jpg_file): New.


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

Properties

Name Value
svn:eol-style native

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26