1 |
werner |
36 |
/* 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 |
werner |
47 |
#include "resource.h" |
29 |
werner |
36 |
#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 |
werner |
47 |
#include "wptW32API.h" |
39 |
werner |
36 |
#include "wptVersion.h" |
40 |
|
|
#include "wptKeyEdit.h" |
41 |
werner |
47 |
#include "wptKeylist.h" |
42 |
twoaday |
129 |
#include "wptUTF8.h" |
43 |
werner |
36 |
|
44 |
|
|
|
45 |
twoaday |
129 |
enum revoke_col_t { |
46 |
|
|
REV_COL_NAME = 0, |
47 |
|
|
REV_COL_KEYID = 1, |
48 |
|
|
REV_COL_ALGO = 2 |
49 |
|
|
}; |
50 |
|
|
|
51 |
werner |
36 |
/* Initialize the listview given in @ctrl and return it in @r_lv. */ |
52 |
|
|
static int |
53 |
|
|
revokelist_build (listview_ctrl_t *r_lv, HWND ctrl) |
54 |
|
|
{ |
55 |
|
|
listview_ctrl_t lv; |
56 |
|
|
struct listview_column_s rlist[] = { |
57 |
twoaday |
129 |
{0, 160, (char *)_("Name") }, |
58 |
|
|
{1, 80, (char *)_("Key ID")}, |
59 |
|
|
{2, 55, (char *)_("Algorithm")}, |
60 |
werner |
36 |
{0} |
61 |
|
|
}; |
62 |
|
|
int i, rc; |
63 |
|
|
|
64 |
|
|
rc = listview_new (&lv); |
65 |
|
|
if (rc) |
66 |
|
|
return rc; |
67 |
|
|
lv->ctrl = ctrl; |
68 |
|
|
lv->items = DIM( rlist )-1; |
69 |
|
|
for (i = 0; i < lv->items; i++) |
70 |
|
|
listview_add_column (lv, &rlist[i]); |
71 |
|
|
listview_set_ext_style (lv); |
72 |
|
|
*r_lv = lv; |
73 |
|
|
return 0; |
74 |
|
|
} |
75 |
|
|
|
76 |
|
|
|
77 |
|
|
/* Initialize the listview @ctrl with all designated revokers of the |
78 |
|
|
key @key. @ctx is used to retrieve the rev key from the cache to |
79 |
|
|
show the user-id. |
80 |
|
|
Return value: the initialized listview or NULL on error. */ |
81 |
|
|
static listview_ctrl_t |
82 |
|
|
revokelist_init (HWND ctrl, gpgme_key_t key, gpg_keycache_t ctx) |
83 |
|
|
{ |
84 |
|
|
gpgme_error_t err; |
85 |
twoaday |
129 |
gpgme_key_t revkey; |
86 |
|
|
GpgKeyEdit *ke; |
87 |
werner |
36 |
gpg_desig_rev_t rev=NULL, r; |
88 |
twoaday |
129 |
listview_ctrl_t lv; |
89 |
|
|
const char *alg; |
90 |
|
|
char *uid = NULL; |
91 |
werner |
36 |
|
92 |
|
|
ke = new GpgKeyEdit (key); |
93 |
|
|
if (!ke) |
94 |
|
|
BUG (NULL); |
95 |
|
|
err = ke->getDesignatedRevoker (&rev); |
96 |
|
|
if (err) { |
97 |
|
|
delete ke; |
98 |
twoaday |
129 |
msg_box (NULL, gpgme_strerror (err), |
99 |
|
|
_("Designated Key Revokers"), MB_ERR); |
100 |
werner |
36 |
return NULL; |
101 |
|
|
} |
102 |
|
|
|
103 |
|
|
if (revokelist_build (&lv, ctrl)) |
104 |
|
|
BUG (0); |
105 |
|
|
for (r = rev; r; r = r->next) { |
106 |
|
|
if (get_pubkey (r->fpr+32, &revkey)) |
107 |
twoaday |
129 |
uid = strdup (_("user ID not found")); |
108 |
werner |
36 |
else |
109 |
twoaday |
129 |
uid = utf8_to_wincp2 (revkey->uids->name); |
110 |
werner |
36 |
listview_add_item (lv, ""); |
111 |
twoaday |
129 |
alg = get_key_pubalgo (r->pubkey_algo); |
112 |
|
|
listview_add_sub_item (lv, 0, REV_COL_ALGO, alg); |
113 |
|
|
listview_add_sub_item (lv, 0, REV_COL_KEYID, r->fpr+32); |
114 |
|
|
listview_add_sub_item (lv, 0, REV_COL_NAME, uid); |
115 |
|
|
safe_free (uid); |
116 |
werner |
36 |
} |
117 |
twoaday |
129 |
|
118 |
werner |
36 |
delete ke; |
119 |
|
|
gpg_desig_rev_release (rev); |
120 |
|
|
return lv; |
121 |
|
|
} |
122 |
|
|
|
123 |
|
|
|
124 |
|
|
/* Dialog box procedure to show designated revokers. */ |
125 |
|
|
BOOL CALLBACK |
126 |
|
|
key_revokers_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
127 |
|
|
{ |
128 |
|
|
static listview_ctrl_t lv; |
129 |
twoaday |
161 |
static int key_update = 0; |
130 |
werner |
36 |
gpgme_key_t key; |
131 |
|
|
char buf[128], keyid[32]; |
132 |
|
|
int rc; |
133 |
|
|
|
134 |
|
|
switch( msg ) { |
135 |
|
|
case WM_INITDIALOG: |
136 |
|
|
gpg_keycache_t ctx; |
137 |
|
|
key = (gpgme_key_t)lparam; |
138 |
|
|
if (!key) |
139 |
|
|
dlg_fatal_error( dlg, "Could not get dilaog param" ); |
140 |
|
|
ctx = keycache_get_ctx (1); |
141 |
|
|
if (!ctx) |
142 |
|
|
BUG (dlg); |
143 |
twoaday |
88 |
lv = revokelist_init (GetDlgItem (dlg, IDC_KEYREVOKERS_LIST), key, ctx); |
144 |
|
|
|
145 |
|
|
SetDlgItemText (dlg, IDC_KEYREVOKERS_INF, _("Designated Revoker Keys")); |
146 |
|
|
SetWindowText (dlg, _("Key Revokers")); |
147 |
|
|
SetForegroundWindow (dlg); |
148 |
werner |
36 |
return TRUE; |
149 |
|
|
|
150 |
|
|
case WM_NOTIFY: |
151 |
|
|
NMHDR *notify; |
152 |
|
|
notify = (NMHDR *)lparam; |
153 |
|
|
if (notify && notify->code == NM_DBLCLK && |
154 |
|
|
notify->idFrom == IDC_KEYREVOKERS_LIST) { |
155 |
|
|
int idx = listview_get_curr_pos (lv); |
156 |
twoaday |
129 |
listview_get_item_text (lv, idx, REV_COL_KEYID, keyid, DIM (keyid)-1); |
157 |
|
|
listview_get_item_text (lv, idx, REV_COL_NAME, buf, sizeof (buf)-1); |
158 |
|
|
if (!strcmp (buf, _("user ID not found"))) { |
159 |
werner |
36 |
int id = log_box (_("Designated Key Revokers"), MB_YESNO|MB_INFO, |
160 |
|
|
_("Do you want to retrieve 0x%s via the default keyserver?"), keyid); |
161 |
|
|
if (id == IDNO) |
162 |
|
|
break; |
163 |
|
|
rc = hkp_recv_key (dlg, default_keyserver, |
164 |
twoaday |
129 |
default_keyserver_port, keyid, 0, 0); |
165 |
|
|
if (!rc) { |
166 |
twoaday |
161 |
keycache_update (0, keyid); |
167 |
|
|
key_update = 1; |
168 |
werner |
36 |
if (get_pubkey (keyid, &key)) |
169 |
|
|
BUG (NULL); |
170 |
twoaday |
129 |
if (key->uids && key->uids->name) { |
171 |
|
|
char *uid = utf8_to_wincp2 (key->uids->name); |
172 |
|
|
listview_add_sub_item (lv, idx, REV_COL_NAME, uid); |
173 |
|
|
free (uid); |
174 |
|
|
} |
175 |
werner |
36 |
} |
176 |
|
|
} |
177 |
|
|
else { |
178 |
|
|
struct winpt_key_s k; |
179 |
|
|
memset (&k, 0, sizeof k); |
180 |
|
|
k.keyid = keyid; |
181 |
|
|
DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_KEYPROPS, dlg, |
182 |
|
|
keyprops_dlg_proc, (LPARAM)&k); |
183 |
|
|
} |
184 |
|
|
} |
185 |
|
|
break; |
186 |
|
|
|
187 |
|
|
case WM_DESTROY: |
188 |
|
|
if (lv) { |
189 |
|
|
listview_release (lv); |
190 |
|
|
lv = NULL; |
191 |
|
|
} |
192 |
|
|
return FALSE; |
193 |
|
|
|
194 |
|
|
case WM_COMMAND: |
195 |
|
|
switch (LOWORD (wparam)) { |
196 |
|
|
case IDOK: |
197 |
twoaday |
161 |
EndDialog (dlg, key_update); |
198 |
werner |
36 |
break; |
199 |
|
|
} |
200 |
|
|
break; |
201 |
|
|
} |
202 |
|
|
|
203 |
|
|
return FALSE; |
204 |
|
|
} |