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

Annotation of /trunk/Src/wptKeyEditDlgs.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 129 - (hide annotations)
Fri Dec 30 13:56:10 2005 UTC (19 years, 2 months ago) by twoaday
File size: 50586 byte(s)
2005-12-27  Timo Schulz  <ts@g10code.com>
                                                                                
        * wptListView.cpp (listview_set_view): New.
        (listview_del_column): New.
        * wptW32API.cpp (get_locale_date): New.
        (get_menu_state): New.
        (force_foreground_window): New.
        * wptVerifyList.cpp (strtimestamp): Support for
        locale date formats.
        * wptGPGUtil.cpp (gpg_revoke_cert): Handle bad
        passphrases.
        * wptKeyEditCB.cpp (editkey_command_handler): Immediately
        return when a bad passphrase was submitted.
        * wptKeyRevokersDlg.cpp (keyrevokers_dlg_proc): Change
        column order.
        * wptKeylist.cpp (keylist_upd_col): New.
        * wptKeyManagerDlg.cpp (update_ui_items): Deactivate
        'Revocation' for public keys.
        (translate_menu_strings): s/Revoke/Revoke Cert.
        (modify_listview_columns): 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 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     nkeys = count_subkeys (key);
972     if( !nkeys ) {
973     msg_box( dlg, _("No subkey(s) found."), _("Key Edit"), MB_ERR );
974     return NULL;
975     }
976    
977     rc = listview_new( &lv );
978     if( rc )
979     BUG( dlg );
980    
981     lv->ctrl = GetDlgItem( dlg, IDC_KEYEDIT_KEYLIST );
982     for( i = 0; cols[i].fieldname != NULL; i++ )
983     listview_add_column( lv, &cols[i] );
984    
985     for( i = 0; i < nkeys; i++ ) {
986     listview_add_item( lv, "" );
987     listview_add_sub_item( lv, 0, 1, "" );
988     memset( &lvi, 0, sizeof lvi );
989     lvi.mask = LVIF_PARAM;
990     lvi.lParam = (LPARAM )key;
991     if( ListView_SetItem( lv->ctrl, &lvi ) == FALSE )
992     return NULL;
993     }
994    
995     listview_set_ext_style( lv );
996     for( i = 0, sub = key->subkeys; i < nkeys; i++, sub = sub->next ) {
997     memset( buf, 0, sizeof buf );
998    
999     bits = sub->length;
1000     _snprintf( tmp, sizeof tmp-1, "%d-bit ", bits );
1001     strcat( buf, tmp );
1002    
1003     _snprintf( tmp, sizeof tmp-1, "%s", get_key_pubalgo (sub->pubkey_algo));
1004     strcat( buf, tmp );
1005    
1006     listview_add_sub_item( lv, i, 0, buf );
1007     t = sub->keyid;
1008     if( !t )
1009     t = "DEADBEEFDEADBEEF";
1010     _snprintf( tmp, sizeof tmp-1, "0x%s", t+8 );
1011     listview_add_sub_item( lv, i, 1, tmp );
1012    
1013     t = get_key_created (sub->timestamp);
1014     if( !t )
1015 werner 116 t = "????" "-??" "-??";
1016 werner 36 listview_add_sub_item( lv, i, 2, t );
1017    
1018     if( sub->expires ) {
1019     t = get_key_created (sub->expires);
1020     listview_add_sub_item( lv, i, 3, t );
1021     }
1022     else
1023     listview_add_sub_item( lv, i, 3, _("Never") );
1024    
1025     if( sub->expired )
1026     t = _("Expired");
1027     else if( sub->revoked )
1028     t = _("Revoked");
1029     else
1030     t = _("OK");
1031     listview_add_sub_item( lv, i, 4, t );
1032    
1033     if (sub->can_certify) t = "*"; else t = "";
1034     listview_add_sub_item (lv, i, 5, t);
1035     if (sub->can_sign) t = "*"; else t = "";
1036     listview_add_sub_item( lv, i, 6, t );
1037     if (sub->can_encrypt) t = "*"; else t = "";
1038     listview_add_sub_item( lv, i, 7, t );
1039     if (sub->can_authenticate) t = "*"; else t = "";
1040     listview_add_sub_item (lv, i, 8, t);
1041     }
1042     return lv;
1043     } /* subkey_list_init */
1044    
1045    
1046     static listview_ctrl_t
1047     userid_list_init (HWND dlg, winpt_key_t k)
1048     {
1049     listview_ctrl_t lv = NULL;
1050     gpgme_key_t key;
1051     gpgme_key_sig_t ks;
1052     gpgme_user_id_t u;
1053     int nuids = 0, rc, j, u_attr;
1054     struct listview_column_s cols[] = {
1055     {0, 72, (char *)_("Validity")},
1056     {1, 150, (char *)_("Name")},
1057     {2, 110, (char *)_("Email")},
1058     {3, 76, (char *)_("Creation")},
1059     {0, 0, 0}
1060     };
1061     const char *attr;
1062    
1063 twoaday 129 if (get_pubkey (k->keyid, &key)) {
1064     msg_box (dlg, _("Could not find key."), _("Key Edit"), MB_ERR);
1065 werner 36 return NULL;
1066     }
1067    
1068     nuids = count_userids (key);
1069     if (!nuids) {
1070     msg_box (dlg, _("No user ID(s) found."), _("Key Edit"), MB_ERR);
1071     return NULL;
1072     }
1073    
1074     rc = listview_new (&lv);
1075 twoaday 129 if (rc)
1076     BUG (dlg);
1077 werner 36 lv->ctrl = GetDlgItem( dlg, IDC_KEYEDIT_UIDLIST );
1078     for( j = 0; cols[j].fieldname != NULL; j++ )
1079     listview_add_column( lv, &cols[j] );
1080    
1081     for( j = 0; j < nuids; j++ ) {
1082     listview_add_item( lv, " " );
1083     listview_add_sub_item( lv, 0, 1, " " );
1084     }
1085    
1086     listview_set_ext_style (lv);
1087     for (j = 0, u=key->uids; j < nuids; u=u->next, j++) {
1088     if (u->revoked)
1089     attr = _("Revoked");
1090     else {
1091     u_attr = (int)u->validity;
1092     attr = get_key_trust2 (NULL, u_attr, 0, 0);
1093     }
1094     listview_add_sub_item( lv, j, 0, (char *)attr );
1095    
1096     /* XXX: add comment if available */
1097     attr = u->name;
1098     if (attr) {
1099 twoaday 129 char *uid = utf8_to_wincp (attr, strlen (attr));
1100 werner 36 if (uid) {
1101     listview_add_sub_item( lv, j, 1, uid );
1102     free( uid );
1103     }
1104     }
1105     else
1106     listview_add_sub_item( lv, j, 1, _("Invalid user ID") );
1107     attr = u->email;
1108     if (attr)
1109     listview_add_sub_item (lv, j, 2, attr);
1110    
1111 twoaday 129 ks = get_selfsig (u, k->keyid, 1);
1112 werner 36 if (ks)
1113     listview_add_sub_item (lv, j, 3, get_key_created (ks->timestamp));
1114     }
1115     if( !k->key_pair ) {
1116     CheckDlgButton( dlg, IDC_KEYUID_ADD, BST_INDETERMINATE );
1117     CheckDlgButton( dlg, IDC_KEYUID_REVOKE, BST_INDETERMINATE );
1118     }
1119     return lv;
1120     } /* userid_list_init */
1121    
1122    
1123     static void
1124     do_init_cmdlist( HWND dlg )
1125     {
1126     const char *cmdlist[] = {
1127     "ADDKEY",
1128     "ADDUID",
1129     "ADDPHOTO",
1130     "ADDREVOKER",
1131     /*"FPR",*/
1132     "DELUID",
1133     "DELKEY",
1134     "DELPHOTO",
1135     /*"DELSIG",*/
1136     "EXPIRE",
1137     /*"PREF",*/
1138     "SHOWPREF",
1139     /*"SETPREF",*/
1140     "PASSWD",
1141     "PRIMARY",
1142     "TRUST",
1143     /*"REVSIG",*/
1144     "REVUID",
1145     "REVKEY",
1146     "DISABLE",
1147     "ENABLE",
1148     "SHOWPHOTO",
1149     NULL
1150     };
1151     const char * s;
1152     int i = 0;
1153    
1154     for( i = 0; (s=cmdlist[i]); i++ ) {
1155     SendDlgItemMessage( dlg, IDC_KEYEDIT_CMD, CB_ADDSTRING, 0,
1156     (LPARAM)(char *)s );
1157     }
1158     SendDlgItemMessage( dlg, IDC_KEYEDIT_CMD, CB_SETCURSEL, 0, 0 );
1159     } /* do_init_cmdlist */
1160    
1161    
1162     static int
1163     is_cmd_openpgp( int cmdid )
1164     {
1165     switch( cmdid ) {
1166     case CMD_ADDKEY:
1167     case CMD_ADDPHOTO:
1168     case CMD_ADDREVOKER:
1169     case CMD_DELPHOTO:
1170     /*case CMD_SHOWPHOTO:*/
1171     /*case CMD_SETPREF:*/
1172     return 1;
1173     }
1174     return 0;
1175     } /* is_cmd_openpgp */
1176    
1177    
1178     static void
1179     do_show_help( HWND dlg )
1180     {
1181     char helptext[2048];
1182    
1183     _snprintf( helptext, sizeof helptext-1,
1184     _(/*"FPR \t\tshow fingerprint\r\n"*/
1185     "ADDUID \t\tadd a user ID\r\n"
1186     "ADDPHOTO \t\tadd a photo ID\r\n"
1187     "DELUID \t\tdelete a user ID\r\n"
1188     "ADDKEY \t\tadd a secondard key\r\n"
1189     "DELKEY \t\tdelete a secondary key\r\n"
1190     "ADDREVOKER\t\tadd a revocation key\r\n"
1191     /*"DELSIG \t\tdelete signatures\r\n"*/
1192     "EXPIRE \t\tchange the expire date\r\n"
1193     /*"PREF \t\tlist preferences (expert)\r\n"
1194     "SHOWPREF \t\tlist preferences (verbose)\r\n"
1195     "SETPREF \t\tset preference list\r\n"*/
1196     "UPDPREF \t\tupdated preferences\r\n"
1197     "PASSWD \t\tchange the passphrase\r\n"
1198     "PRIMARY \t\tflag user ID as primary\r\n"
1199     "TRUST \t\tchange the ownertrust\r\n"
1200     /*"REVSIG \t\trevoke signatures\r\n"*/
1201     "REVUID \t\trevoke a user ID\r\n"
1202     "REVKEY \t\trevoke a secondary key\r\n"
1203     "DISABLE \t\tdisable a key\r\n"
1204     "ENABLE \t\tenable a key\r\n"
1205     /*"SHOWPHOTO \t\tshow photo ID\r\n"*/) );
1206     msg_box( dlg, helptext, _("Key Edit Help"), MB_OK );
1207     } /* do_show_help */
1208    
1209    
1210     static int
1211     do_editkey_delkey (winpt_key_t k, HWND dlg, listview_ctrl_t lv)
1212     {
1213     gpgme_error_t err;
1214     GpgKeyEdit *ke;
1215     int j, id;
1216     char tmp[64];
1217    
1218     if (!k->key_pair)
1219     return FALSE; /* XXX: shall we allow to modify non-secret keys?? */
1220    
1221     if( listview_count_items( lv, 0 ) == 1 ) {
1222     msg_box( dlg, _("Primary key can not be deleted!"), _("Key Edit"), MB_ERR);
1223     return FALSE;
1224     }
1225     if( (j = listview_get_curr_pos( lv )) == -1 ) {
1226     msg_box( dlg, _("Please select a key."), _("Key Edit"), MB_ERR );
1227     return FALSE;
1228     }
1229     if( j == 0 ) {
1230     msg_box( dlg, _("Primary subkey can not be deleted!"), _("Key Edit"), MB_ERR );
1231     return FALSE;
1232     }
1233    
1234     listview_get_item_text( lv, j, 0, tmp, sizeof tmp -1 );
1235     id = log_box( _("Key Edit"), MB_YESNO|MB_ICONWARNING,
1236     _("\"Subkey %s.\"\n\n"
1237     "Anything encrypted to the selected subkey will no longer\n"
1238     "be able to be decrypted.\n\n"
1239     "Do you really want to delete this subkey?"), tmp );
1240     if( id == IDNO )
1241     return FALSE;
1242    
1243     ke = new GpgKeyEdit (k->keyid);
1244     if (!ke)
1245     BUG (NULL);
1246     err = ke->delKey (j);
1247     if (err)
1248     msg_box (dlg, gpgme_strerror (err), _("Delete Subkey"), MB_ERR);
1249     else {
1250     listview_del_item (lv, j);
1251     k->update = 1;
1252     status_box (dlg, _("Subkey successfully deleted."), _("GnuPG status"));
1253     }
1254     delete ke;
1255     return err? FALSE : TRUE;
1256     } /* do_editkey_delkey */
1257    
1258    
1259     /* Set the expiration date for the selected key in list view @lv.
1260     Return value: TRUE on success. */
1261     static int
1262     do_editkey_expire (winpt_key_t k, HWND dlg, listview_ctrl_t lv)
1263     {
1264     gpgme_error_t err;
1265     GpgKeyEdit *ke;
1266     date_s udd = {0};
1267     char buf[256], * pass = NULL;
1268     int j, cancel = 0;
1269    
1270     if (!k->key_pair) {
1271 twoaday 41 msg_box (dlg, _("There is no secret key available!"), _("Key Edit"), MB_ERR);
1272 werner 36 return FALSE;
1273     }
1274 twoaday 41 if ((j = listview_get_curr_pos (lv)) == -1) {
1275 werner 36 msg_box( dlg, _("Please select a key."), _("Key Edit"), MB_ERR );
1276     return FALSE;
1277     }
1278 twoaday 41
1279     /* If a key already expired, it is possible the user wants to
1280     set a new expiration date.. */
1281     listview_get_item_text (lv, j, SUBK_COL_STATUS, buf, sizeof buf -1);
1282     if (!strcmp (buf, _("Expired"))) {
1283     cancel = msg_box (dlg, _("Key already expired.\n\n"
1284     "Do you want to change the expiration date?"),
1285     _("Key Edit"), MB_QUEST_ASK);
1286     if (cancel == IDNO)
1287     return FALSE;
1288     cancel = 0;
1289 werner 36 }
1290 twoaday 41
1291 werner 36 memset (&udd, 0, sizeof udd);
1292     udd.text = _("Key Expiration Date");
1293     dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_DATE, dlg,
1294     date_dlg_proc, (LPARAM)&udd,
1295     _("Key Expiration Date"), IDS_WINPT_DATE);
1296     if (udd.cancel == 1)
1297     return FALSE;
1298     if (!keygen_check_date (&udd.st)) {
1299     msg_box (dlg, _("The date you have chosen lies in the past."),
1300     _("Key Edit"), MB_ERR);
1301     return FALSE;
1302     }
1303     if( k->is_protected ) {
1304 twoaday 41 pass = request_passphrase (_("Key Edit"), 1, &cancel);
1305     if (cancel)
1306 werner 36 return FALSE;
1307     }
1308    
1309     ke = new GpgKeyEdit (k->keyid);
1310     if (!ke)
1311     BUG (NULL);
1312     if (k->is_protected)
1313     ke->setPassphrase (pass);
1314     err = ke->setKeyExpireDate (j, diff_time (NULL, &udd.st), true);
1315     if (err)
1316     msg_box (dlg, gpgme_strerror (err), _("Expire Subkey"), MB_ERR);
1317     else {
1318     _snprintf (buf, sizeof buf - 1, "%04d-%02d-%02d",
1319     udd.st.wYear, udd.st.wMonth, udd.st.wDay);
1320     listview_add_sub_item (lv, j, SUBK_COL_EXPIRES, buf);
1321     k->update = 1;
1322     msg_box (dlg, _("Subkey expire date successfully set."),
1323     _("GnuPG status"), MB_OK);
1324     }
1325     sfree_if_alloc (pass);
1326     delete ke;
1327     return TRUE;
1328     }
1329    
1330    
1331     /* Revoke the selected key in the list view @lv. @k contains
1332     control information about the global key.
1333     Return value: TRUE on success. */
1334     static int
1335     do_editkey_revoke (winpt_key_t k, HWND dlg, listview_ctrl_t lv)
1336     {
1337     gpgme_error_t err;
1338     GpgKeyEdit *ke;
1339     char buf[256];
1340     char *pass = NULL;
1341     int j, cancel = 0;
1342    
1343     if (!k->key_pair) {
1344     msg_box (dlg, _("There is no secret key available!"), _("Key Edit"), MB_ERR);
1345     return FALSE;
1346     }
1347    
1348     if ((j = listview_get_curr_pos (lv)) == -1) {
1349     msg_box( dlg, _("Please select a key."), _("Key Edit"), MB_ERR );
1350     return FALSE;
1351     }
1352     else if (listview_count_items (lv, 0) == 1) {
1353     msg_box( dlg, _("No subkeys were found, if you want to revoke the\n"
1354     "whole key, please use the Key Manager command directly.\n\n"
1355     "This command is only available to revoke single subkeys"),
1356     _("Key Edit"), MB_INFO );
1357     return FALSE;
1358     }
1359    
1360     listview_get_item_text (lv, j, SUBK_COL_STATUS, buf, sizeof (buf)-1);
1361     if (!strcmp (buf, _("Revoked"))) {
1362     msg_box (dlg, _("Key already revoked."), _("Key Edit"), MB_ERR);
1363     return FALSE;
1364     }
1365    
1366     if (k->is_protected) {
1367     pass = request_passphrase (_("Key Edit"), 1, &cancel);
1368     if (cancel)
1369     return FALSE;
1370     }
1371    
1372     ke = new GpgKeyEdit (k->keyid);
1373     if (!ke)
1374     BUG (NULL);
1375     if (k->is_protected)
1376     ke->setPassphrase (pass);
1377     err = ke->revokeSubkey (j, 0, NULL);
1378     if (err)
1379     msg_box( dlg, gpgme_strerror (err), _("Revoke Subkey"), MB_ERR);
1380     else {
1381     listview_add_sub_item (lv, j, SUBK_COL_STATUS, _("Revoked"));
1382     k->update = 1;
1383     msg_box( dlg, _("Subkey successfully revoked."), _("GnuPG Status"), MB_OK );
1384     }
1385     sfree_if_alloc (pass);
1386     delete ke;
1387     return TRUE;
1388     }
1389    
1390    
1391     /* Revoked the selected userid in list view @lv.
1392     Return value: TRUE on success. */
1393     int
1394     do_editkey_revuid (winpt_key_t k, HWND dlg, listview_ctrl_t lv)
1395     {
1396     gpgme_error_t err;
1397     GpgKeyEdit *ke;
1398 twoaday 68 char buf[256], t[512];
1399     char *pass=NULL;
1400 werner 36 int cancel = 0, id = 0, j;
1401    
1402     if (!k->key_pair) {
1403     msg_box( dlg, _("There is no secret key available!"), _("Revoke user ID"), MB_ERR );
1404     return FALSE;
1405     }
1406    
1407     if( listview_count_items( lv, 0 ) == 1 ) {
1408     msg_box( dlg, _("Key has only one user ID."), _("Key Edit"), MB_ERR );
1409     return FALSE;
1410     }
1411    
1412     if( (j = listview_get_curr_pos( lv )) == -1 ) {
1413     msg_box( dlg, _("Please select a user ID."), _("Key Edit"), MB_ERR );
1414     return FALSE;
1415     }
1416    
1417     listview_get_item_text( lv, j, 0, buf, sizeof buf - 1 );
1418     if( strstr( buf, _("Revoked") ) ) {
1419     msg_box( dlg, _("This user ID has been already revoked."), _("Key Edit"), MB_INFO );
1420     return FALSE;
1421     }
1422    
1423     listview_get_item_text (lv, j, 1, buf, sizeof buf -1);
1424     _snprintf( t, sizeof t -1, _("user ID \"%s\".\n\n"
1425     "Do you really want to revoke this user ID?"), buf );
1426     if( msg_box( dlg, t, _("Key Edit"), MB_WARN_ASK) == IDNO )
1427     return FALSE;
1428     if( k->is_protected ) {
1429     pass = request_passphrase (_("Key Edit"), 1, &cancel);
1430 twoaday 68 if (cancel)
1431 werner 36 return FALSE;
1432     }
1433     listview_get_item_text (lv, j, 2, buf, sizeof (buf)-1);
1434     id = do_find_userid (k->keyid, buf, NULL);
1435     if (id == -1)
1436     BUG (NULL);
1437    
1438     ke = new GpgKeyEdit (k->keyid);
1439     if (!ke)
1440     BUG (NULL);
1441     if (k->is_protected)
1442     ke->setPassphrase (pass);
1443     err = ke->revokeUserid (id);
1444     if (err)
1445     msg_box (dlg, gpgme_strerror (err), _("Revoke Signature"), MB_ERR);
1446     else {
1447     listview_add_sub_item (lv, j, 0, _("Revoked"));
1448     k->update = 1;
1449     status_box (dlg, _("User ID successfully revoked"), _("GnuPG Status"));
1450     }
1451     sfree_if_alloc (pass);
1452     delete ke;
1453     return err? FALSE : TRUE;
1454     }
1455    
1456    
1457     static int
1458     do_editkey_setpref (winpt_key_t k, HWND dlg, listview_ctrl_t lv)
1459     {
1460     gpgme_error_t rc;
1461     GpgKeyEdit *ke;
1462     char buf[256], * pass = NULL, * prefs;
1463     int j, id, cancel=0, flags=0;
1464    
1465     if ((j = listview_get_curr_pos (lv)) == -1) {
1466     msg_box (dlg, _("Please select a user ID."), _("Key Edit"), MB_ERR);
1467     return FALSE;
1468     }
1469     listview_get_item_text (lv, j, 2, buf, sizeof buf-1);
1470     id = do_find_userid (k->keyid, buf, NULL);
1471     if (id == -1)
1472     BUG (dlg);
1473     if (k->is_protected) {
1474     pass = request_passphrase (_("Key Edit"), 1, &cancel);
1475     if (cancel)
1476     return FALSE;
1477     }
1478    
1479     ke = new GpgKeyEdit (k->keyid);
1480     if (!ke)
1481     BUG (NULL);
1482     if (k->is_protected)
1483     ke->setPassphrase (pass);
1484    
1485     get_userid_preflist (&prefs, &flags);
1486    
1487     rc = ke->setUseridPreferences (id, prefs);
1488     /* XXX */
1489    
1490     sfree_if_alloc (pass);
1491     free_if_alloc (prefs);
1492     delete ke;
1493     return 0;
1494     }
1495    
1496    
1497     static int
1498     do_editkey_primary (winpt_key_t k, HWND dlg, listview_ctrl_t lv)
1499     {
1500     gpgme_error_t err;
1501     GpgKeyEdit *ke;
1502     int j, id, cancel=0;
1503     char buf[256], * pass = NULL;
1504    
1505     if (listview_count_items (lv, 0) == 1)
1506     return TRUE;
1507     if ((j = listview_get_curr_pos (lv)) == -1) {
1508     msg_box( dlg, _("Please select a user ID."), _("Key Edit"), MB_ERR );
1509     return FALSE;
1510     }
1511     listview_get_item_text (lv, j, 2, buf, sizeof buf-1);
1512     id = do_find_userid (k->keyid, buf, NULL);
1513     if (id == -1)
1514     BUG (dlg);
1515     if (k->is_protected) {
1516     pass = request_passphrase (_("Key Edit"), 1, &cancel);
1517 twoaday 128 if (cancel)
1518 werner 36 return FALSE;
1519     }
1520    
1521     ke = new GpgKeyEdit (k->keyid);
1522     if (k->is_protected)
1523     ke->setPassphrase (pass);
1524     err = ke->setPrimaryUserid (id);
1525     if (err)
1526     msg_box (dlg, gpgme_strerror (err), _("Primary"), MB_ERR);
1527     else {
1528     k->update = 1;
1529     status_box (dlg, _("User ID successfully flagged"), _("GnuPG Status"));
1530     }
1531    
1532     sfree_if_alloc (pass);
1533     delete ke;
1534     return err? FALSE : TRUE;
1535     }
1536    
1537    
1538 twoaday 123
1539 twoaday 128 #define CIPHER 11
1540     #define HASH 11
1541     #define COMPR 4
1542    
1543 werner 36 static int
1544     parse_preflist (HWND dlg, const char *list)
1545     {
1546 twoaday 123 char buf[128] = {0};
1547     char *p, *pbuf = buf;
1548     const char *ciphers[CIPHER] = {"", "IDEA", "3DES",
1549 twoaday 128 "CAST5", "BLOWFISH", "", "",
1550     "AES", "AES192", "AES256", "TWOFISH"};
1551     const char *hash[HASH] = {"", "MD5", "SHA1", "RMD160", "",
1552     "", "", "", "SHA256", "SHA384", "SHA512"};
1553 twoaday 123 const char *compress[COMPR] = {"", "ZIP", "ZLIB", "BZIP2"};
1554 werner 36 int n=0;
1555    
1556     strncpy (buf, list, 127);
1557     p = strtok (pbuf, " ");
1558     while (p != NULL) {
1559     int algid = atol (p+1);
1560     n++;
1561     switch (*p) {
1562     case 'S':
1563 twoaday 123 SendDlgItemMessage (dlg, IDC_SHOWPREF_CIPHERS, LB_ADDSTRING, 0,
1564     (LPARAM)(const char*)ciphers[algid % CIPHER]);
1565 werner 36 break;
1566    
1567     case 'H':
1568 twoaday 123 SendDlgItemMessage (dlg, IDC_SHOWPREF_HASH, LB_ADDSTRING, 0,
1569     (LPARAM)(const char*)hash[algid % HASH]);
1570 werner 36 break;
1571    
1572     case 'Z':
1573 twoaday 123 SendDlgItemMessage (dlg, IDC_SHOWPREF_ZIP, LB_ADDSTRING, 0,
1574     (LPARAM)(const char*)compress[algid % COMPR]);
1575 werner 36 break;
1576    
1577     default:
1578     n--;
1579     }
1580     p = strtok (NULL, " ");
1581     }
1582     return n;
1583     }
1584    
1585    
1586     /* Dialog box procedure to show the key preferences. */
1587     BOOL CALLBACK
1588     showpref_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
1589     {
1590     static keyedit_callback_s *cb = NULL;
1591     gpg_uid_info_t inf=NULL;
1592     char buf[128];
1593     int pos;
1594    
1595     switch (msg) {
1596     case WM_INITDIALOG:
1597     cb = (keyedit_callback_s *)lparam;
1598     if (cb == NULL)
1599     BUG (dlg);
1600 twoaday 121 pos = listview_get_curr_pos (cb->lv);
1601     listview_get_item_text (cb->lv, pos, 2, buf, DIM (buf)-1);
1602 werner 36 SetDlgItemText (dlg, IDC_SHOWPREF_INFO, buf);
1603     pos = do_find_userid (((winpt_key_t)cb->opaque)->keyid, buf, &inf);
1604     if (inf) {
1605     const char *prefs = inf->prefs;
1606     if (prefs && *prefs) {
1607     if (parse_preflist (dlg, prefs) <= 0)
1608     pos = -1;
1609     }
1610     else
1611     pos = -1;
1612     gpg_uid_info_release (inf);
1613     if (pos == -1) {
1614     msg_box (dlg, _("No preferences available."), _("Key Edit"), MB_ERR);
1615     EndDialog (dlg, TRUE);
1616     }
1617     if (inf->flags.mdc)
1618     CheckDlgButton (dlg, IDC_SHOWPREF_MDC, BST_CHECKED);
1619     }
1620 twoaday 128 SetDlgItemText (dlg, IDC_SHOWPREF_MDC, _("MDC feature"));
1621     SetDlgItemText (dlg, IDC_SHOWPREF_PREFINF, _("Preferences"));
1622 werner 36 SetWindowText (dlg, _("Key Preferences"));
1623     SetForegroundWindow (dlg);
1624     break;
1625    
1626     case WM_COMMAND:
1627     switch (LOWORD (wparam)) {
1628     case IDOK:
1629     EndDialog (dlg, TRUE);
1630     break;
1631     }
1632     break;
1633     }
1634     return FALSE;
1635     }
1636    
1637    
1638     static int
1639     do_editkey_showpref (winpt_key_t k, HWND dlg, listview_ctrl_t lv)
1640     {
1641     struct keyedit_callback_s cb;
1642    
1643     if (k->is_v3)
1644     return TRUE;
1645    
1646     if (listview_get_curr_pos (lv) == -1) {
1647     msg_box (dlg, _("Please select a user ID."), _("Key Edit"), MB_ERR);
1648     return FALSE;
1649     }
1650    
1651     memset (&cb, 0, sizeof (cb));
1652     cb.lv = lv;
1653     cb.opaque = k;
1654     DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_KEYEDIT_SHOWPREF, dlg,
1655     showpref_dlg_proc, (LPARAM)&cb);
1656     return TRUE;
1657     }
1658    
1659    
1660     static int
1661     do_editkey_deluid (winpt_key_t k, HWND dlg, listview_ctrl_t lv)
1662     {
1663     gpgme_error_t err;
1664     GpgKeyEdit *ke;
1665     char buf[256], t[512];
1666     int j, id = 0;
1667    
1668     if (!k->key_pair)
1669     return FALSE; /* XXX: see do_editkey_delsubkey */
1670    
1671     if( listview_count_items( lv, 0 ) == 1 ) {
1672     msg_box( dlg, _("Primary user ID can not be deleted!"), _("Key Edit"), MB_ERR );
1673     return FALSE;
1674     }
1675     if( (j = listview_get_curr_pos( lv )) == -1 ) {
1676     msg_box( dlg, _("Please select a user ID."), _("Key Edit"), MB_ERR );
1677     return FALSE;
1678     }
1679    
1680     /* XXX: add a hint that also all signatures will be deleted? */
1681     listview_get_item_text( lv, j, 1, buf, DIM(buf) -1 );
1682     _snprintf( t, DIM (t)-1, _("user ID \"%s\".\n\n"
1683     "Do you really want to delete this user ID?"),
1684     buf);
1685     if( msg_box( dlg, t, _("Key Edit"), MB_YESNO|MB_ICONWARNING ) == IDNO )
1686     return FALSE;
1687    
1688     listview_get_item_text (lv, j, 2, buf, DIM (buf)-1);
1689     id = do_find_userid (k->keyid, buf, NULL);
1690     if (id == -1)
1691     BUG (dlg);
1692    
1693     ke = new GpgKeyEdit (k->keyid);
1694     if (!ke)
1695     BUG (NULL);
1696    
1697     err = ke->delUserid (id);
1698     if( err )
1699     msg_box( dlg, gpgme_strerror (err), _("Delete user ID"), MB_ERR );
1700     else {
1701     listview_del_item( lv, j );
1702     k->update = 1;
1703     status_box( dlg, _("User ID successfully deleted"), _("GnuPG Status") );
1704     }
1705     delete ke;
1706     return err? FALSE : TRUE;
1707     } /* do_editkey_deluid */
1708    
1709    
1710    
1711     static BOOL CALLBACK
1712     subkey_subclass_proc( HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam )
1713     {
1714     switch( msg ) {
1715     case WM_KEYUP:
1716     int virt_key = (int)wparam;
1717     switch( virt_key ) {
1718     case VK_DELETE:
1719     SendDlgItemMessage( keyedit_subkey_proc.dlg, IDC_KEYEDIT_CMD,
1720     CB_SETCURSEL, CMD_DELKEY, 0 );
1721     send_cmd_id( keyedit_subkey_proc.dlg, IDOK );
1722     break;
1723    
1724     case VK_INSERT:
1725     SendDlgItemMessage( keyedit_subkey_proc.dlg, IDC_KEYEDIT_CMD,
1726     CB_SETCURSEL, CMD_ADDKEY, 0 );
1727     send_cmd_id( keyedit_subkey_proc.dlg, IDOK );
1728     break;
1729     }
1730     }
1731     return CallWindowProc( keyedit_subkey_proc.old, dlg, msg, wparam, lparam );
1732     } /* subkey_subclass_proc */
1733    
1734    
1735     static BOOL CALLBACK
1736     uid_subclass_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
1737     {
1738     switch( msg ) {
1739     case WM_KEYUP:
1740     int virt_key = (int)wparam;
1741     switch (virt_key) {
1742     case VK_DELETE:
1743     SendDlgItemMessage (keyedit_uid_proc.dlg, IDC_KEYEDIT_CMD,
1744     CB_SETCURSEL, CMD_DELUID, 0);
1745     send_cmd_id (keyedit_uid_proc.dlg, IDOK);
1746     break;
1747    
1748     case VK_INSERT:
1749     SendDlgItemMessage (keyedit_uid_proc.dlg, IDC_KEYEDIT_CMD,
1750     CB_SETCURSEL, CMD_ADDUID, 0);
1751     send_cmd_id (keyedit_uid_proc.dlg, IDOK);
1752     break;
1753     }
1754     }
1755     return CallWindowProc( keyedit_uid_proc.old, dlg, msg, wparam, lparam );
1756     } /* uid_subclass_proc */
1757    
1758    
1759     BOOL CALLBACK
1760     keyedit_main_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
1761     {
1762     static winpt_key_t k;
1763     static listview_ctrl_t lvsub = NULL, lvuid = NULL;
1764     int cmd, idxsub = 0;
1765     HWND item;
1766    
1767     switch( msg ) {
1768     case WM_INITDIALOG:
1769     k = (winpt_key_t)lparam;
1770     if (!k)
1771     BUG (NULL);
1772     do_init_cmdlist (dlg);
1773     lvsub = subkey_list_init (dlg, k);
1774     if( !lvsub )
1775     BUG( NULL );
1776     lvuid = userid_list_init (dlg, k);
1777     if( !lvuid )
1778     BUG( NULL );
1779     item = GetDlgItem( dlg, IDC_KEYEDIT_KEYLIST );
1780     keyedit_subkey_proc.dlg = dlg;
1781     keyedit_subkey_proc.current = (WNDPROC)subkey_subclass_proc;
1782     keyedit_subkey_proc.old = (WNDPROC)GetWindowLong( item, GWL_WNDPROC );
1783     if( keyedit_subkey_proc.old ) {
1784     if( !SetWindowLong( item, GWL_WNDPROC, (LONG)keyedit_subkey_proc.current ) ) {
1785     msg_box( dlg, _("Could not set subkey window procedure."), _("Key Edit"), MB_ERR );
1786     BUG( NULL );
1787     }
1788     }
1789     item = GetDlgItem( dlg, IDC_KEYEDIT_UIDLIST );
1790     keyedit_uid_proc.dlg = dlg;
1791     keyedit_uid_proc.current = (WNDPROC)uid_subclass_proc;
1792     keyedit_uid_proc.old = (WNDPROC)GetWindowLong( item, GWL_WNDPROC );
1793     if( keyedit_uid_proc.old ) {
1794     if( !SetWindowLong( item, GWL_WNDPROC, (LONG)keyedit_uid_proc.current ) ) {
1795     msg_box( dlg, _("Could not set user ID window procedure."), _("Key Edit"), MB_ERR );
1796     BUG( NULL );
1797     }
1798     }
1799     if (!k->key_pair) {
1800     EnableWindow (GetDlgItem (dlg, IDC_KEYEDIT_CMD), FALSE);
1801     EnableWindow (GetDlgItem (dlg, IDOK), FALSE);
1802     }
1803     SetDlgItemText (dlg, IDC_KEYEDIT_CMDINF, _("Command>"));
1804 twoaday 117 SetDlgItemText (dlg, IDCANCEL, _("&Close"));
1805 twoaday 88 SetDlgItemText (dlg, IDC_KEYEDIT_HELP, _("&Help"));
1806     SetWindowText (dlg, _("Key Edit"));
1807 werner 36 SetForegroundWindow( dlg );
1808     center_window( dlg, NULL );
1809     return TRUE;
1810    
1811     case WM_DESTROY:
1812     if( lvsub ) {
1813     listview_release( lvsub );
1814     lvsub = NULL;
1815     }
1816     if( lvuid ) {
1817     listview_release( lvuid );
1818     lvuid = NULL;
1819     }
1820     break;
1821    
1822     case WM_NOTIFY:
1823     NMHDR * notify;
1824     notify = (NMHDR *)lparam;
1825     if (notify && notify->code == NM_DBLCLK &&
1826     notify->idFrom == IDC_KEYEDIT_UIDLIST)
1827     do_editkey_showpref (k, dlg, lvuid);
1828     break;
1829    
1830     case WM_COMMAND:
1831     switch( LOWORD( wparam ) ) {
1832     case IDOK:
1833     cmd = SendDlgItemMessage (dlg, IDC_KEYEDIT_CMD, CB_GETCURSEL, 0, 0);
1834     if (cmd == LB_ERR) {
1835     msg_box( dlg, _("Please select a command."), _("Key Edit"), MB_INFO );
1836     return FALSE;
1837     }
1838     idxsub = listview_get_curr_pos (lvsub);
1839     if (k->is_v3 && is_cmd_openpgp (cmd)) {
1840     msg_box (dlg, _("This command cannot be used with PGP 2 (v3) keys.\n"),
1841     _("Key Edit"), MB_ERR);
1842     return FALSE;
1843     }
1844     switch (cmd) {
1845     case CMD_SHOWPREF: do_editkey_showpref (k, dlg, lvuid); break;
1846     case CMD_DELKEY: do_editkey_delkey (k, dlg, lvsub); break;
1847     case CMD_ADDKEY: keyedit_add_subkey (k, dlg, lvsub); break;
1848     case CMD_EXPIRE: do_editkey_expire (k, dlg, lvsub); break;
1849     case CMD_REVKEY: do_editkey_revoke (k, dlg, lvsub); break;
1850     /*case CMD_SETPREF:do_editkey_setpref( k, dlg, lvuid ); break;*/
1851     case CMD_ADDUID: keyedit_add_userid( k, dlg, lvuid ); break;
1852     case CMD_ADDREVOKER: keyedit_add_revoker( k, dlg ); break;
1853     case CMD_ADDPHOTO: keyedit_add_photo( k, dlg ); break;
1854     case CMD_REVUID: do_editkey_revuid( k, dlg, lvuid ); break;
1855     case CMD_DELUID: do_editkey_deluid( k, dlg, lvuid ); break;
1856     case CMD_PASSWD: keyedit_change_passwd( k, dlg ); break;
1857     case CMD_PRIMARY: do_editkey_primary( k, dlg, lvuid ); break;
1858     case CMD_ENABLE: km_enable_disable_key( lvsub, dlg, idxsub, 1 ); break;
1859     case CMD_DISABLE: km_enable_disable_key( lvsub, dlg, idxsub, 0 ); break;
1860     }
1861     break;
1862    
1863     case IDCANCEL:
1864     EndDialog (dlg, FALSE);
1865     break;
1866    
1867     case IDC_KEYEDIT_HELP:
1868     do_show_help (dlg);
1869     break;
1870     }
1871     break;
1872     }
1873     return FALSE;
1874 werner 42 } /* keyedit_main_dlg_proc */

Properties

Name Value
svn:eol-style native

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26