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

Annotation of /trunk/Src/wptKeysigDlg.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: 13132 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 /* wptKeysigDlg.cpp - Key signature listing
2     * Copyright (C) 2001-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     #include <time.h>
27    
28 werner 47 #include "resource.h"
29 werner 36 #include "wptGPG.h"
30     #include "wptCommonCtl.h"
31     #include "wptContext.h" /* for passphrase_s */
32     #include "wptDlgs.h"
33     #include "wptW32API.h"
34     #include "wptNLS.h"
35 werner 47 #include "wptKeylist.h"
36 werner 36 #include "wptKeyserver.h"
37     #include "wptUTF8.h"
38     #include "wptTypes.h"
39     #include "wptVersion.h"
40     #include "wptErrors.h"
41     #include "wptKeyEdit.h"
42    
43     static subclass_s siglist_proc;
44    
45    
46     static int
47     is_sig (listview_ctrl_t lv, int pos)
48     {
49 twoaday 128 char tmpbuf[200];
50 werner 36
51     if (pos == -1)
52     pos = listview_get_curr_pos (lv);
53     if (pos == -1)
54     return 0;
55 twoaday 128 listview_get_item_text (lv, pos, 0, tmpbuf, sizeof (tmpbuf)-1);
56 werner 36 if (*tmpbuf == ' ')
57     return -1;
58     return 0;
59 twoaday 32 }
60 werner 36
61    
62     /* Delete the selected signature from list view @lv. The
63     key is given in @key. */
64     static int
65     do_delsig (HWND dlg, listview_ctrl_t lv, winpt_key_t key)
66     {
67     int pos, npos, id;
68     int signo=0, uidno=0;
69     GpgKeyEdit *ke;
70     gpgme_error_t err;
71    
72     npos = pos = listview_get_curr_pos (lv);
73     if (!is_sig (lv, -1))
74     return -1;
75     while (pos > 0 && is_sig (lv, pos)) {
76     signo++;
77     pos--;
78     }
79     pos = npos;
80     while (npos > 0) {
81     if (!is_sig (lv, npos))
82     uidno++;
83     npos--;
84     }
85     uidno++;
86    
87     /* XXX: do not allow to delete the self signature */
88     id = log_box (_("Key Manager"), MB_YESNO,
89     _("Are you really sure you want to delete this signature from\n"
90     " \"%s\""), key->uid);
91     if (id == IDNO)
92     return 0;
93    
94     ke = new GpgKeyEdit (key->keyid);
95     if (!ke)
96     BUG (NULL);
97     err = ke->delUseridSignature (uidno, signo);
98     if (err)
99     msg_box (dlg, gpgme_strerror (err), _("Key Manager"), MB_ERR);
100     else
101     listview_del_item (lv, pos);
102     delete ke;
103     key->update = 1; /*update*/
104     return err? -1 : 0;
105     }
106    
107    
108     /* Dialog box procedure to display the signature properties. */
109     static BOOL CALLBACK
110     sigprops_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
111     {
112     static listview_ctrl_t lv;
113     char tmpbuf[256];
114     int n;
115     struct {
116     unsigned int exportable:1;
117     unsigned int expired:1;
118     unsigned int nrev:1;
119     unsigned int rev:1;
120     const char * alg;
121     int _class;
122     } ctx;
123     const char *fmt_templ = _("%s %s signature");
124    
125     switch (msg) {
126     case WM_SYSCOMMAND:
127     if (LOWORD (wparam) == SC_CLOSE)
128     EndDialog (dlg, TRUE);
129     return FALSE;
130    
131     case WM_INITDIALOG:
132 twoaday 88 SetWindowText (dlg, _("Signature Properties"));
133     SetDlgItemText (dlg, IDC_SIGPROPS_EXP, _("Exportable"));
134     SetDlgItemText (dlg, IDC_SIGPROPS_NREV, _("Non-revocably"));
135     SetDlgItemText (dlg, IDC_SIGPROPS_EXPIRED, _("Expired"));
136     SetDlgItemText (dlg, IDC_SIGPROPS_REV, _("Revoked"));
137     SetDlgItemText (dlg, IDC_SIGPROPS_CLASSINF, _("Class"));
138     SetDlgItemText (dlg, IDC_SIGPROPS_EXPSTR, _("Expire date"));
139     SetDlgItemText (dlg, IDC_SIGPROPS_KEYINF, _("Issuer key"));
140     SetDlgItemText (dlg, IDC_SIGPROPS_KEYIDINF, _("Issuer key ID"));
141 werner 36 lv = (listview_ctrl_t)lparam;
142     if (!lv)
143     dlg_fatal_error (dlg, "could not get dialog param");
144     memset (&ctx, 0, sizeof ctx);
145     n = listview_get_curr_pos (lv);
146     listview_get_item_text (lv, n, 2, tmpbuf, DIM (tmpbuf)-1);
147     if (!strstr (tmpbuf, "L"))
148     ctx.exportable = 1;
149     ctx._class = atoi (tmpbuf);
150     if (ctx._class == 0)
151     ctx._class = 10;
152     else if (ctx._class < 10)
153     ctx._class += 10;
154     listview_get_item_text (lv, n, 6, tmpbuf, DIM (tmpbuf)-1);
155     if (strstr (tmpbuf, "DSA"))
156     ctx.alg = "DSA";
157     else if (strstr (tmpbuf, "RSA"))
158     ctx.alg = "RSA";
159     else
160     ctx.alg = "ELG";
161     _snprintf (tmpbuf, DIM (tmpbuf)-1, fmt_templ,
162     ctx.exportable? _("Exportable") : _("Non-exportable"), ctx.alg);
163     SetDlgItemText (dlg, IDC_SIGPROPS_INFO, tmpbuf);
164     listview_get_item_text (lv, n, 4, tmpbuf, DIM (tmpbuf)-1);
165     SetDlgItemText (dlg, IDC_SIGPROPS_KEYID, tmpbuf);
166     SetDlgItemInt (dlg, IDC_SIGPROPS_CLASS, ctx._class, FALSE);
167     if (ctx.exportable)
168     CheckDlgButton (dlg, IDC_SIGPROPS_EXP, BST_CHECKED);
169     listview_get_item_text (lv, n, 0, tmpbuf, DIM (tmpbuf)-1);
170     SetDlgItemText (dlg, IDC_SIGPROPS_ISSUER, tmpbuf+1);
171     tmpbuf[0] = 0;
172     listview_get_item_text (lv, n, 5, tmpbuf, DIM (tmpbuf)-1);
173     if (strlen (tmpbuf) == 0) {
174     ShowWindow (GetDlgItem (dlg, IDC_SIGPROPS_EXPSTR), SW_HIDE);
175     ShowWindow (GetDlgItem (dlg, IDC_SIGPROPS_EXPDATE), SW_HIDE);
176     }
177     else {
178     SYSTEMTIME st;
179     struct tm * tm;
180     time_t t = time (NULL);
181    
182     memset (&st, 0, sizeof st);
183     st.wYear = atoi (tmpbuf);
184     st.wMonth = atoi (tmpbuf+5);
185     st.wDay = atoi (tmpbuf+8);
186     DateTime_SetSystemtime (GetDlgItem (dlg, IDC_SIGPROPS_EXPDATE),
187     GDT_VALID, &st);
188    
189     tm = localtime (&t);
190     tm->tm_mon++;
191     tm->tm_year += 1900;
192     if (tm->tm_year > st.wYear)
193     ctx.expired = 1;
194     else if (tm->tm_mon > st.wMonth)
195     ctx.expired = 1;
196     if (ctx.expired)
197     CheckDlgButton (dlg, IDC_SIGPROPS_EXPIRED, BST_CHECKED);
198     }
199     SetDlgItemText (dlg, IDC_SIGPROPS_EXP, _("Exportable"));
200     SetDlgItemText (dlg, IDC_SIGPROPS_NREV, _("Non-revocably"));
201     SetDlgItemText (dlg, IDC_SIGPROPS_REV, _("Revoked"));
202     SetDlgItemText (dlg, IDC_SIGPROPS_EXPIRED, _("Expired"));
203     SetWindowText (dlg, _("Signature Properties"));
204     SetForegroundWindow (dlg);
205     center_window (dlg, NULL);
206     return TRUE;
207    
208     case WM_COMMAND:
209     switch (LOWORD (wparam)) {
210     case IDOK:
211     EndDialog (dlg, TRUE);
212     break;
213     }
214     }
215    
216     return FALSE;
217     }
218    
219    
220     static BOOL CALLBACK
221     subclass_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
222     {
223     listview_ctrl_t lv;
224     winpt_key_t key;
225    
226     switch (msg) {
227     case WM_KEYUP:
228     int virt_key = (int)wparam;
229     key = (winpt_key_t)siglist_proc.opaque;
230     lv = key->callback.ctl;
231     if (virt_key == VK_SPACE) {
232     if (is_sig (lv, -1))
233     DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_SIGPROPS, dlg,
234     sigprops_dlg_proc, (LPARAM)lv);
235     }
236     else if (virt_key == VK_DELETE)
237     do_delsig (dlg, lv, key);
238     break;
239     }
240     return CallWindowProc (siglist_proc.old, dlg, msg, wparam, lparam);
241     }
242    
243    
244     /* Return 1 if the list view @lv contains non-available keys. */
245     static int
246     check_for_missing_keys (listview_ctrl_t lv)
247     {
248     int i, n;
249     char id[128];
250    
251     n = listview_count_items( lv, 0 );
252     for( i = 0; i < n; i++ ) {
253     listview_get_item_text( lv, i, 1, id, sizeof (id) - 1 );
254     if( !strncmp( id, "NOKEY", 5 ) )
255     return 1;
256     }
257    
258     return 0;
259     }
260    
261    
262     /* Receive all missing keys marked in the list @lv. */
263     static int
264     recv_missing_keys (HWND dlg, listview_ctrl_t lv)
265     {
266 twoaday 65 int i, n, rc=0;
267 werner 36 char id[128], keyid[18+1];
268    
269     n = listview_count_items (lv, 0);
270     for( i = 0; i < n; i++ ) {
271 twoaday 128 listview_get_item_text (lv, i, 1, id, sizeof (id) - 1);
272 werner 36 if( !strncmp( id, "NOKEY", 5 ) ) {
273 twoaday 128 listview_get_item_text( lv, i, 4, keyid, sizeof (keyid) -1);
274     rc = hkp_recv_key (dlg, default_keyserver,
275     default_keyserver_port, keyid, 0, 0);
276 werner 36 if( rc )
277     break;
278     }
279     }
280    
281     return rc;
282     }
283    
284    
285     /* Create a mini popup with available choices. */
286     static void
287     do_create_popup (HWND dlg)
288     {
289     HMENU hm, sm;
290     POINT p;
291    
292     GetCursorPos (&p);
293     hm = LoadMenu (glob_hinst, MAKEINTRESOURCE (IDR_WINPT_KEYSIG_CTX));
294     sm = GetSubMenu (hm, 0);
295    
296     set_menu_text (sm, ID_SIGCTX_PROPS, _("Signature &Properties"));
297     set_menu_text (sm, ID_SIGCTX_KEYPROPS, _("Signing &Key Properties"));
298    
299     TrackPopupMenu (sm, TPM_RIGHTALIGN, p.x, p.y, 0, dlg, NULL);
300    
301     DestroyMenu (hm);
302     DestroyMenu (sm);
303     }
304    
305    
306     /* Load the key property dialog with the selected key from @lv. */
307     static void
308     do_load_keyprops (HWND dlg, listview_ctrl_t lv)
309     {
310     winpt_key_s k;
311     gpgme_key_t key;
312     char keyid[32] = {0};
313     char status[64] = {0}, creation[64] = {0};
314     int n = listview_get_curr_pos (lv);
315    
316     listview_get_item_text (lv, n, 1, status, DIM (status)-1);
317     listview_get_item_text (lv, n, 3, creation, DIM (creation)-1);
318     listview_get_item_text (lv, n, 4, keyid, DIM (keyid)-1);
319     if (!strcmp (status, "NOKEY")) {
320     msg_box (dlg, _("Key not found in keyring, please get it from the keyserver first."),
321     _("Key Manager"), MB_INFO);
322     return;
323     }
324    
325     if ((strlen (keyid) < 3 ||get_pubkey (keyid, &key))) {
326     if (strlen (creation) > 0)
327     msg_box (dlg, _("Key not found in keyring."), _("Key Manager"), MB_INFO);
328     return;
329     }
330     memset (&k, 0, sizeof k);
331     k.keyid = keyid;
332     DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_KEYPROPS, dlg,
333     keyprops_dlg_proc, (LPARAM)&k);
334     }
335    
336    
337     /* Dialog box procedure to list signatures. */
338     BOOL CALLBACK
339     keysig_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
340     {
341     static listview_ctrl_t lv = NULL;
342     static struct winpt_key_s *k;
343     char inf[384], keyid[18+1];
344     int idx = 0, id, rc;
345     HWND sl;
346    
347     switch( msg ) {
348     case WM_INITDIALOG:
349     k = (winpt_key_t) lparam;
350     if (!k)
351     BUG (0);
352     if (k->uid)
353     _snprintf (inf, DIM (inf)-1, _("Signature List for \"%s\""), k->uid);
354     SetWindowText (dlg, inf);
355     SetDlgItemText (dlg, IDC_KEYSIG_RECVKEY, _("&Receive Key"));
356     SetDlgItemText (dlg, IDC_KEYSIG_SIGPROPS, _("&Properties"));
357 twoaday 128
358 werner 36 lv = siglist_load (GetDlgItem (dlg, IDC_KEYSIG_LIST), k->keyid);
359     if (!check_for_missing_keys (lv))
360 twoaday 41 EnableWindow (GetDlgItem (dlg, IDC_KEYSIG_RECVKEY), FALSE);
361 twoaday 129 EnableWindow (GetDlgItem (dlg, IDC_KEYSIG_SIGPROPS), FALSE);
362 werner 36 k->callback.ctl = lv;
363     sl = GetDlgItem (dlg, IDC_KEYSIG_LIST);
364     siglist_proc.dlg = dlg;
365     siglist_proc.opaque = k;
366     siglist_proc.current = (WNDPROC)subclass_dlg_proc;
367     siglist_proc.old = (WNDPROC)GetWindowLong (sl, GWL_WNDPROC);
368     if (siglist_proc.old) {
369     if (!SetWindowLong (sl, GWL_WNDPROC, (LONG)siglist_proc.current)) {
370     msg_box (dlg, _("Could not set keylist window procedure."),
371     _("Key Manager"), MB_ERR);
372     BUG (0);
373     }
374     }
375     SetForegroundWindow (dlg);
376     center_window (dlg, NULL);
377     return TRUE;
378    
379     case WM_DESTROY:
380     if ( lv ) {
381     siglist_delete( lv );
382     lv = NULL;
383     }
384     return FALSE;
385    
386     case WM_SYSCOMMAND:
387     if (LOWORD (wparam) == SC_CLOSE) {
388     if (k->update)
389     keycache_update (0, k->keyid);
390     EndDialog (dlg, TRUE);
391     }
392     return FALSE;
393    
394     case WM_NOTIFY:
395 twoaday 41 NMHDR *notify;
396 werner 36
397     notify = (NMHDR *)lparam;
398 twoaday 41 if (notify && notify->code == NM_DBLCLK
399     && notify->idFrom == IDC_KEYSIG_LIST)
400 werner 36 do_load_keyprops (dlg, lv);
401     if (notify && notify->code == NM_RCLICK &&
402 twoaday 128 notify->idFrom == IDC_KEYSIG_LIST &&
403     is_sig (lv, -1))
404 werner 36 do_create_popup (dlg);
405 twoaday 41 if (notify && notify->code == LVN_ITEMCHANGED &&
406     ((LPNMLISTVIEW)lparam)->uNewState) {
407     idx = listview_get_curr_pos (lv);
408     listview_get_item_text (lv, idx, 1, inf, DIM (inf)-1);
409     EnableWindow (GetDlgItem (dlg, IDC_KEYSIG_RECVKEY),
410     strcmp (inf, "NOKEY") == 0? TRUE: FALSE);
411 twoaday 128 EnableWindow (GetDlgItem (dlg, IDC_KEYSIG_SIGPROPS),
412     is_sig (lv, -1)? TRUE : FALSE);
413 twoaday 41 }
414 werner 36 break;
415    
416     case WM_COMMAND:
417     switch ( LOWORD( wparam ) ) {
418    
419     case ID_SIGCTX_KEYPROPS:
420     do_load_keyprops (dlg, lv);
421     break;
422    
423     case ID_SIGCTX_PROPS:
424     if (is_sig (lv, -1))
425     DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_SIGPROPS, dlg,
426     sigprops_dlg_proc, (LPARAM)lv);
427     break;
428    
429     case IDC_KEYSIG_RECVKEY:
430     idx = listview_get_curr_pos (lv);
431     if (idx == -1) {
432     id = msg_box( dlg, _("Really receive all missing keys?"),
433     _("Key Manager"), MB_YESNO|MB_INFO );
434     if (id == IDYES) {
435     rc = recv_missing_keys (dlg, lv);
436 twoaday 41 if (!rc)
437 werner 36 keycache_set_reload (1);
438     return TRUE;
439     }
440     return TRUE;
441     }
442     listview_get_item_text (lv, idx, 4, keyid, DIM (keyid)-1);
443     rc = hkp_recv_key (dlg, default_keyserver, default_keyserver_port, keyid, 0, 0);
444     if (!rc)
445 twoaday 41 keycache_update (0, keyid);
446 werner 36 return TRUE;
447    
448     case IDC_KEYSIG_SIGPROPS:
449     if (is_sig (lv, -1))
450     DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_SIGPROPS, dlg,
451     sigprops_dlg_proc, (LPARAM)lv);
452     return TRUE;
453    
454     case IDOK:
455     if (k->update)
456     keycache_update (0, k->keyid);
457     EndDialog (dlg, TRUE);
458     return TRUE;
459     }
460     break;
461     }
462     return FALSE;
463     }

Properties

Name Value
svn:eol-style native

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26