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