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

Contents of /trunk/Src/wptKeyRevokersDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 225 - (show annotations)
Tue Jun 6 13:37:59 2006 UTC (18 years, 8 months ago) by twoaday
File size: 5870 byte(s)


1 /* wptKeyRevokersDlg.cpp - Designated Revoker Keys
2 * Copyright (C) 2002, 2003, 2005 Timo Schulz
3 * Copyright (C) 2005 g10 Code GmbH
4 *
5 * This file is part of WinPT.
6 *
7 * WinPT is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * WinPT is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with WinPT; if not, write to the Free Software Foundation,
19 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
20 */
21 #ifdef HAVE_CONFIG_H
22 #include <config.h>
23 #endif
24
25 #include <windows.h>
26 #include <commctrl.h>
27
28 #include "resource.h"
29 #include "wptCommonCtl.h"
30 #include "wptNLS.h"
31 #include "wptTypes.h"
32 #include "wptGPG.h"
33 #include "wptCommonCtl.h"
34 #include "wptContext.h"
35 #include "wptDlgs.h"
36 #include "wptErrors.h"
37 #include "wptKeyserver.h"
38 #include "wptW32API.h"
39 #include "wptVersion.h"
40 #include "wptKeyEdit.h"
41 #include "wptKeylist.h"
42 #include "wptKeyManager.h"
43
44 /* symbolic column IDs */
45 enum revoke_col_t {
46 REV_COL_NAME = 0,
47 REV_COL_KEYID = 1,
48 REV_COL_ALGO = 2
49 };
50
51 /* Initialize the listview given in @ctrl and return it in @r_lv. */
52 static void
53 revokelist_build (listview_ctrl_t *r_lv, HWND ctrl)
54 {
55 listview_ctrl_t lv;
56 struct listview_column_s rlist[] = {
57 {0, 160, (char *)_("Name") },
58 {1, 80, (char *)_("Key ID")},
59 {2, 55, (char *)_("Algorithm")},
60 {0}
61 };
62 int i;
63
64 listview_new (&lv, ctrl);
65 lv->items = DIM (rlist)-1;
66 for (i = 0; i < lv->items; i++)
67 listview_add_column (lv, &rlist[i]);
68 listview_set_ext_style (lv);
69 *r_lv = lv;
70 }
71
72
73 /* Get the key revokers of the key @key.
74 If reload is 1, an update is forced otherwise the
75 cached revokers are returned. */
76 gpgme_error_t
77 key_get_revokers (winpt_key_t key, int reload, gpg_desig_rev_t *r_rev)
78 {
79 gpgme_error_t err;
80 gpg_desig_rev_t rev;
81 GpgKeyEdit *ke;
82
83 if (!reload && key->ext->rev) {
84 *r_rev = key->ext->rev;
85 return 0;
86 }
87 ke = new GpgKeyEdit (key->keyid);
88 if (!ke)
89 BUG (NULL);
90 err = ke->getDesignatedRevoker (&rev);
91 delete ke;
92 if (err) {
93 gpg_desig_rev_release (rev);
94 return err;
95 }
96 if (key->ext->rev)
97 gpg_desig_rev_release (rev);
98 key->ext->rev = rev;
99 *r_rev = rev;
100 return 0;
101 }
102
103
104 /* Initialize the listview @ctrl with all designated revokers of the
105 key @key.
106 Return value: the initialized listview or NULL on error. */
107 static listview_ctrl_t
108 revokelist_init (HWND ctrl, winpt_key_t key)
109 {
110 gpgme_error_t err;
111 struct winpt_key_s revkey;
112 gpg_desig_rev_t rev=NULL, r;
113 listview_ctrl_t lv;
114 const char *alg;
115 const char *uid = NULL, *kid;
116 char keyid[32];
117
118 err = key_get_revokers (key, 0, &rev);
119 if (err) {
120 msg_box (NULL, gpgme_strerror (err),
121 _("Designated Key Revokers"), MB_ERR);
122 return NULL;
123 }
124 revokelist_build (&lv, ctrl);
125 for (r = rev; r; r = r->next) {
126 memset (&revkey, 0, sizeof (revkey));
127 kid = get_keyid_from_fpr (r->fpr);
128 if (winpt_get_pubkey (kid, &revkey))
129 uid = _("user ID not found");
130 else
131 uid = revkey.ext->uids->name;
132 _snprintf (keyid, sizeof (keyid)-1, "0x%s", kid);
133 listview_add_item2 (lv, "", revkey.ext);
134 alg = get_key_pubalgo (r->pubkey_algo);
135 listview_add_sub_item (lv, 0, REV_COL_ALGO, alg);
136 listview_add_sub_item (lv, 0, REV_COL_KEYID, keyid);
137 listview_add_sub_item (lv, 0, REV_COL_NAME, uid);
138 }
139 return lv;
140 }
141
142
143 /* Dialog box procedure to show designated revokers. */
144 BOOL CALLBACK
145 key_revokers_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
146 {
147 static listview_ctrl_t lv;
148 static int key_update = 0;
149 winpt_key_t key;
150 char buf[128], keyid[32];
151 int rc;
152
153 switch (msg) {
154 case WM_INITDIALOG:
155 key = (winpt_key_t)lparam;
156 if (!key)
157 BUG (0);
158 lv = revokelist_init (GetDlgItem (dlg, IDC_KEYREVOKERS_LIST), key);
159 SetDlgItemText (dlg, IDC_KEYREVOKERS_INF, _("Designated Revoker Keys"));
160 SetWindowText (dlg, _("Key Revokers"));
161 SetForegroundWindow (dlg);
162 return TRUE;
163
164 case WM_NOTIFY:
165 NMHDR *notify;
166 notify = (NMHDR *)lparam;
167 if (notify && notify->code == (UINT)NM_DBLCLK &&
168 notify->idFrom == IDC_KEYREVOKERS_LIST) {
169 int idx = listview_get_curr_pos (lv);
170
171 listview_get_item_text (lv, idx, REV_COL_KEYID, keyid, DIM (keyid)-1);
172 listview_get_item_text (lv, idx, REV_COL_NAME, buf, sizeof (buf)-1);
173 if (!strcmp (buf, _("user ID not found"))) {
174 int id = log_box (_("Designated Key Revokers"), MB_YESNO|MB_INFO,
175 _("Do you want to retrieve %s via the default keyserver?"), keyid);
176 if (id == IDNO)
177 break;
178 rc = hkp_recv_key (dlg, default_keyserver,
179 default_keyserver_port, keyid, 0, 0);
180 if (!rc) {
181 struct winpt_key_s pk;
182
183 keycache_update (0, keyid);
184 key_update = 1;
185 memset (&pk, 0, sizeof (pk));
186 if (winpt_get_pubkey (keyid, &pk))
187 BUG (NULL);
188 /* XXX: utf8 decode problem. */
189 if (pk.ext && pk.ext->uids)
190 listview_add_sub_item (lv, idx, REV_COL_NAME, pk.ext->uids->name);
191 }
192 }
193 else {
194 struct winpt_key_s k;
195
196 memset (&k, 0, sizeof k);
197 km_get_key (lv, idx, &k);
198 DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_KEYPROPS, dlg,
199 keyprops_dlg_proc, (LPARAM)&k);
200 }
201 }
202 break;
203
204 case WM_DESTROY:
205 if (lv) {
206 listview_release (lv);
207 lv = NULL;
208 }
209 return FALSE;
210
211 case WM_COMMAND:
212 switch (LOWORD (wparam)) {
213 case IDOK:
214 EndDialog (dlg, key_update);
215 break;
216
217 case IDCANCEL:
218 EndDialog (dlg, 0);
219 break;
220 }
221 break;
222 }
223
224 return FALSE;
225 }

Properties

Name Value
svn:eol-style native

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26