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

Annotation of /trunk/Src/wptKeyEditDlgs.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 133 - (hide annotations)
Mon Jan 9 09:15:29 2006 UTC (19 years, 1 month ago) by twoaday
File size: 50662 byte(s)
A lot of minor bug fixes.
New icons.

For a complete history, see the ChangeLog entries.


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

Properties

Name Value
svn:eol-style native

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26