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

Annotation of /trunk/Src/wptKeyEditDlgs.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 167 - (hide annotations)
Thu Jan 26 10:17:17 2006 UTC (19 years, 1 month ago) by twoaday
File size: 51886 byte(s)
2006-01-25  Timo Schulz  <ts@g10code.com>
 
        * wptRegistry.cpp (get_reg_entry_gpg): Return NULL if
        the key exist with no value.
        * wptMDSumDlg.cpp (mdsum_dlg_proc): Translate string.
        * wptKeysignDlg.cpp (do_fill_seclist): Select the
        default key if possible.
        * wptFirstRunDlg.cpp (firstrun_dlg_proc): Directly
        return the choice.
        * wptKeylist.cpp (get_key_desc): New.
        (keylist_upd_key): Free memory.
        * wptKeyCache.cpp (gpg_keycache_get_default_key): New.
        (gpg_keycache_set_default_key): New.
        * WinPT.cpp (gpg_prefs_ok): New.
        (WinMain): Only start gpg prefs if needed.
         


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

Properties

Name Value
svn:eol-style native

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26