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

Annotation of /trunk/Src/wptKeysigDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 32 - (hide annotations)
Mon Oct 24 08:03:48 2005 UTC (19 years, 4 months ago) by twoaday
File size: 12614 byte(s)
2005-10-23  Timo Schulz  <twoaday@g10code.com>
 
        * wptFileManager.cpp (fm_get_file_type): Detect detached sigs.
        * wptKeyList.cpp (keylist_cmp_cb): Take care of expired/revoked keys.
        (get_ext_validity): New.
        * wptFileVerifyDlg.cpp (file_verify_dlg_proc): Several cleanups.
        * wptClipEditDlg.cpp (load_clipboard): Factored out some code into
        this function.
        (load_clipboard_from_file): Likewise.
        (save_clipboard_to_file): New.
        * wptKeyManagerDlg.cpp (keyprops_dlg_proc): Fix stack overflow.

For complete details, see the ChangeLog files.

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26