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

Contents of /trunk/Src/wptKeysigDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 24 - (show annotations)
Sat Oct 8 10:43:08 2005 UTC (19 years, 4 months ago) by twoaday
File size: 12023 byte(s)
Bug fixes to correct some problems introduced by
the MyGPGME to GPGME port.

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26