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