1 |
werner |
36 |
/* wptKeyRevokersDlg.cpp - Designated Revoker Keys |
2 |
twoaday |
328 |
* Copyright (C) 2002, 2003, 2005, 2007, 2009 Timo Schulz |
3 |
werner |
36 |
* 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 |
|
|
#ifdef HAVE_CONFIG_H |
18 |
|
|
#include <config.h> |
19 |
|
|
#endif |
20 |
|
|
|
21 |
|
|
#include <windows.h> |
22 |
|
|
#include <commctrl.h> |
23 |
|
|
|
24 |
werner |
47 |
#include "resource.h" |
25 |
werner |
36 |
#include "wptCommonCtl.h" |
26 |
|
|
#include "wptNLS.h" |
27 |
|
|
#include "wptTypes.h" |
28 |
|
|
#include "wptGPG.h" |
29 |
|
|
#include "wptCommonCtl.h" |
30 |
|
|
#include "wptContext.h" |
31 |
|
|
#include "wptDlgs.h" |
32 |
|
|
#include "wptErrors.h" |
33 |
|
|
#include "wptKeyserver.h" |
34 |
werner |
47 |
#include "wptW32API.h" |
35 |
werner |
36 |
#include "wptVersion.h" |
36 |
|
|
#include "wptKeyEdit.h" |
37 |
werner |
47 |
#include "wptKeylist.h" |
38 |
twoaday |
212 |
#include "wptKeyManager.h" |
39 |
werner |
36 |
|
40 |
twoaday |
212 |
/* symbolic column IDs */ |
41 |
twoaday |
129 |
enum revoke_col_t { |
42 |
|
|
REV_COL_NAME = 0, |
43 |
|
|
REV_COL_KEYID = 1, |
44 |
|
|
}; |
45 |
|
|
|
46 |
werner |
36 |
/* Initialize the listview given in @ctrl and return it in @r_lv. */ |
47 |
twoaday |
208 |
static void |
48 |
werner |
36 |
revokelist_build (listview_ctrl_t *r_lv, HWND ctrl) |
49 |
|
|
{ |
50 |
|
|
listview_ctrl_t lv; |
51 |
|
|
struct listview_column_s rlist[] = { |
52 |
twoaday |
129 |
{0, 160, (char *)_("Name") }, |
53 |
|
|
{1, 80, (char *)_("Key ID")}, |
54 |
werner |
36 |
{0} |
55 |
|
|
}; |
56 |
|
|
|
57 |
twoaday |
208 |
listview_new (&lv, ctrl); |
58 |
|
|
lv->items = DIM (rlist)-1; |
59 |
twoaday |
328 |
for (int i = 0; i < lv->items; i++) |
60 |
werner |
36 |
listview_add_column (lv, &rlist[i]); |
61 |
|
|
listview_set_ext_style (lv); |
62 |
|
|
*r_lv = lv; |
63 |
twoaday |
208 |
} |
64 |
|
|
|
65 |
|
|
|
66 |
|
|
/* Get the key revokers of the key @key. |
67 |
|
|
If reload is 1, an update is forced otherwise the |
68 |
|
|
cached revokers are returned. */ |
69 |
|
|
gpgme_error_t |
70 |
|
|
key_get_revokers (winpt_key_t key, int reload, gpg_desig_rev_t *r_rev) |
71 |
|
|
{ |
72 |
|
|
gpgme_error_t err; |
73 |
|
|
gpg_desig_rev_t rev; |
74 |
twoaday |
304 |
GpgKeyEdit ke; |
75 |
twoaday |
208 |
|
76 |
|
|
if (!reload && key->ext->rev) { |
77 |
|
|
*r_rev = key->ext->rev; |
78 |
|
|
return 0; |
79 |
|
|
} |
80 |
twoaday |
304 |
ke.setKeyID (key->keyid); |
81 |
|
|
err = ke.getDesignatedRevoker (&rev); |
82 |
twoaday |
208 |
if (err) { |
83 |
|
|
gpg_desig_rev_release (rev); |
84 |
|
|
return err; |
85 |
|
|
} |
86 |
|
|
if (key->ext->rev) |
87 |
|
|
gpg_desig_rev_release (rev); |
88 |
|
|
key->ext->rev = rev; |
89 |
|
|
*r_rev = rev; |
90 |
werner |
36 |
return 0; |
91 |
|
|
} |
92 |
|
|
|
93 |
|
|
|
94 |
|
|
/* Initialize the listview @ctrl with all designated revokers of the |
95 |
twoaday |
208 |
key @key. |
96 |
werner |
36 |
Return value: the initialized listview or NULL on error. */ |
97 |
twoaday |
328 |
static keylist_ctrl_t |
98 |
twoaday |
208 |
revokelist_init (HWND ctrl, winpt_key_t key) |
99 |
werner |
36 |
{ |
100 |
|
|
gpgme_error_t err; |
101 |
twoaday |
208 |
struct winpt_key_s revkey; |
102 |
werner |
36 |
gpg_desig_rev_t rev=NULL, r; |
103 |
twoaday |
129 |
listview_ctrl_t lv; |
104 |
twoaday |
225 |
const char *uid = NULL, *kid; |
105 |
twoaday |
193 |
char keyid[32]; |
106 |
werner |
36 |
|
107 |
twoaday |
208 |
err = key_get_revokers (key, 0, &rev); |
108 |
werner |
36 |
if (err) { |
109 |
twoaday |
129 |
msg_box (NULL, gpgme_strerror (err), |
110 |
|
|
_("Designated Key Revokers"), MB_ERR); |
111 |
werner |
36 |
return NULL; |
112 |
|
|
} |
113 |
twoaday |
208 |
revokelist_build (&lv, ctrl); |
114 |
werner |
36 |
for (r = rev; r; r = r->next) { |
115 |
twoaday |
208 |
memset (&revkey, 0, sizeof (revkey)); |
116 |
twoaday |
225 |
kid = get_keyid_from_fpr (r->fpr); |
117 |
|
|
if (winpt_get_pubkey (kid, &revkey)) |
118 |
twoaday |
204 |
uid = _("user ID not found"); |
119 |
werner |
36 |
else |
120 |
twoaday |
208 |
uid = revkey.ext->uids->name; |
121 |
twoaday |
304 |
_snprintf (keyid, DIM (keyid)-1, "0x%s", kid); |
122 |
twoaday |
212 |
listview_add_item2 (lv, "", revkey.ext); |
123 |
twoaday |
193 |
listview_add_sub_item (lv, 0, REV_COL_KEYID, keyid); |
124 |
twoaday |
129 |
listview_add_sub_item (lv, 0, REV_COL_NAME, uid); |
125 |
werner |
36 |
} |
126 |
twoaday |
328 |
|
127 |
|
|
keylist_ctrl_t kl = new keylist_ctrl_s; |
128 |
|
|
kl->keys = NULL; |
129 |
|
|
kl->lv = lv; |
130 |
|
|
return kl; |
131 |
werner |
36 |
} |
132 |
|
|
|
133 |
|
|
|
134 |
|
|
/* Dialog box procedure to show designated revokers. */ |
135 |
|
|
BOOL CALLBACK |
136 |
|
|
key_revokers_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
137 |
|
|
{ |
138 |
twoaday |
328 |
static keylist_ctrl_t kl = NULL; |
139 |
twoaday |
161 |
static int key_update = 0; |
140 |
twoaday |
208 |
winpt_key_t key; |
141 |
werner |
36 |
char buf[128], keyid[32]; |
142 |
|
|
int rc; |
143 |
|
|
|
144 |
twoaday |
208 |
switch (msg) { |
145 |
twoaday |
225 |
case WM_INITDIALOG: |
146 |
twoaday |
208 |
key = (winpt_key_t)lparam; |
147 |
werner |
36 |
if (!key) |
148 |
twoaday |
225 |
BUG (0); |
149 |
twoaday |
328 |
kl = revokelist_init (GetDlgItem (dlg, IDC_KEYREVOKERS_LIST), key); |
150 |
twoaday |
88 |
SetDlgItemText (dlg, IDC_KEYREVOKERS_INF, _("Designated Revoker Keys")); |
151 |
|
|
SetWindowText (dlg, _("Key Revokers")); |
152 |
|
|
SetForegroundWindow (dlg); |
153 |
werner |
36 |
return TRUE; |
154 |
|
|
|
155 |
|
|
case WM_NOTIFY: |
156 |
|
|
NMHDR *notify; |
157 |
|
|
notify = (NMHDR *)lparam; |
158 |
twoaday |
208 |
if (notify && notify->code == (UINT)NM_DBLCLK && |
159 |
werner |
36 |
notify->idFrom == IDC_KEYREVOKERS_LIST) { |
160 |
twoaday |
328 |
int idx = listview_get_curr_pos (kl->lv); |
161 |
twoaday |
212 |
|
162 |
twoaday |
328 |
listview_get_item_text (kl->lv, idx, REV_COL_KEYID, keyid, DIM (keyid)-1); |
163 |
|
|
listview_get_item_text (kl->lv, idx, REV_COL_NAME, buf, DIM (buf)-1); |
164 |
twoaday |
129 |
if (!strcmp (buf, _("user ID not found"))) { |
165 |
werner |
36 |
int id = log_box (_("Designated Key Revokers"), MB_YESNO|MB_INFO, |
166 |
twoaday |
208 |
_("Do you want to retrieve %s via the default keyserver?"), keyid); |
167 |
werner |
36 |
if (id == IDNO) |
168 |
|
|
break; |
169 |
twoaday |
208 |
rc = hkp_recv_key (dlg, default_keyserver, |
170 |
twoaday |
129 |
default_keyserver_port, keyid, 0, 0); |
171 |
|
|
if (!rc) { |
172 |
twoaday |
208 |
struct winpt_key_s pk; |
173 |
|
|
|
174 |
twoaday |
161 |
keycache_update (0, keyid); |
175 |
|
|
key_update = 1; |
176 |
twoaday |
208 |
memset (&pk, 0, sizeof (pk)); |
177 |
|
|
if (winpt_get_pubkey (keyid, &pk)) |
178 |
werner |
36 |
BUG (NULL); |
179 |
twoaday |
225 |
/* XXX: utf8 decode problem. */ |
180 |
twoaday |
208 |
if (pk.ext && pk.ext->uids) |
181 |
twoaday |
328 |
listview_add_sub_item (kl->lv, idx, REV_COL_NAME, pk.ext->uids->name); |
182 |
werner |
36 |
} |
183 |
|
|
} |
184 |
|
|
else { |
185 |
|
|
struct winpt_key_s k; |
186 |
twoaday |
212 |
|
187 |
werner |
36 |
memset (&k, 0, sizeof k); |
188 |
twoaday |
328 |
km_get_key (kl, idx, &k); |
189 |
werner |
36 |
DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_KEYPROPS, dlg, |
190 |
|
|
keyprops_dlg_proc, (LPARAM)&k); |
191 |
|
|
} |
192 |
|
|
} |
193 |
|
|
break; |
194 |
|
|
|
195 |
|
|
case WM_DESTROY: |
196 |
twoaday |
328 |
if (kl) { |
197 |
|
|
keylist_delete (kl); |
198 |
|
|
kl = NULL; |
199 |
werner |
36 |
} |
200 |
twoaday |
328 |
break; |
201 |
werner |
36 |
|
202 |
|
|
case WM_COMMAND: |
203 |
|
|
switch (LOWORD (wparam)) { |
204 |
|
|
case IDOK: |
205 |
twoaday |
161 |
EndDialog (dlg, key_update); |
206 |
werner |
36 |
break; |
207 |
twoaday |
208 |
|
208 |
|
|
case IDCANCEL: |
209 |
|
|
EndDialog (dlg, 0); |
210 |
|
|
break; |
211 |
werner |
36 |
} |
212 |
|
|
break; |
213 |
|
|
} |
214 |
|
|
|
215 |
|
|
return FALSE; |
216 |
|
|
} |