1 |
werner |
36 |
/* wptVerifyList.cpp - Listview for verifying signatures |
2 |
twoaday |
256 |
* Copyright (C) 2001, 2002, 2003, 2005, 2006 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 |
8 |
|
|
* modify it under the terms of the GNU General Public License |
9 |
|
|
* as published by the Free Software Foundation; either version 2 |
10 |
|
|
* of the License, or (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 GNU |
15 |
|
|
* 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 |
twoaday |
129 |
|
22 |
werner |
36 |
#ifdef HAVE_CONFIG_H |
23 |
|
|
#include <config.h> |
24 |
|
|
#endif |
25 |
|
|
|
26 |
|
|
#include <windows.h> |
27 |
|
|
#include <time.h> |
28 |
|
|
|
29 |
twoaday |
228 |
#include "resource.h" |
30 |
werner |
36 |
#include "wptTypes.h" |
31 |
|
|
#include "wptGPG.h" |
32 |
|
|
#include "wptCommonCtl.h" |
33 |
|
|
#include "wptKeylist.h" |
34 |
|
|
#include "wptNLS.h" |
35 |
twoaday |
208 |
#include "wptContext.h" |
36 |
werner |
36 |
#include "wptErrors.h" |
37 |
|
|
#include "wptW32API.h" |
38 |
twoaday |
228 |
#include "wptVersion.h" |
39 |
werner |
36 |
|
40 |
twoaday |
193 |
/* Symbolic column IDs */ |
41 |
|
|
enum { |
42 |
|
|
VER_COL_NAME = 0, |
43 |
|
|
VER_COL_STAT = 1, |
44 |
|
|
VER_COL_SIGNED = 2, |
45 |
|
|
VER_COL_TRUST = 3, |
46 |
|
|
VER_COL_KEYID = 4, |
47 |
|
|
VER_COL_UID = 5 |
48 |
|
|
}; |
49 |
|
|
|
50 |
|
|
|
51 |
werner |
36 |
/* Extract the file name part out of the given path in @path. |
52 |
|
|
Return value: file part or NULL on error. */ |
53 |
|
|
static char* |
54 |
|
|
extract_filename (const char *path) |
55 |
|
|
{ |
56 |
|
|
char * fname, *p; |
57 |
|
|
int n, len = 0; |
58 |
|
|
|
59 |
|
|
p = strrchr (path, '\\'); |
60 |
|
|
if (!p) |
61 |
|
|
return m_strdup (path); |
62 |
|
|
n = p - path; |
63 |
|
|
len = strlen (path) - n; |
64 |
|
|
fname = new char[len+1]; |
65 |
|
|
if (!fname) |
66 |
|
|
BUG (NULL); |
67 |
|
|
memcpy (fname, path+n+1, len); |
68 |
|
|
fname[len] = '\0'; |
69 |
|
|
return fname; |
70 |
|
|
} |
71 |
|
|
|
72 |
|
|
|
73 |
|
|
/* String representaton of the time in @timestamp. |
74 |
|
|
Format YEAR-MON-DAY HOUR:MIN:SEC. |
75 |
|
|
Return value: time as formatted string. */ |
76 |
twoaday |
129 |
const char* |
77 |
werner |
36 |
strtimestamp (long timestamp) |
78 |
|
|
{ |
79 |
twoaday |
129 |
static char timebuf[64]; |
80 |
werner |
36 |
struct tm *warp; |
81 |
twoaday |
129 |
const char *dat; |
82 |
werner |
36 |
|
83 |
twoaday |
129 |
dat = get_locale_date (timestamp, timebuf, sizeof (timebuf)-1); |
84 |
werner |
36 |
warp = localtime (×tamp); |
85 |
twoaday |
129 |
if (!dat) |
86 |
|
|
_snprintf (timebuf, sizeof (timebuf) - 1, |
87 |
|
|
"%04d-%02d-%02d %02d:%02d:%02d", |
88 |
|
|
warp->tm_year+1900, warp->tm_mon+1, warp->tm_mday, |
89 |
|
|
warp->tm_hour, warp->tm_min, warp->tm_sec); |
90 |
|
|
else |
91 |
|
|
_snprintf (timebuf, sizeof (timebuf)-1, |
92 |
|
|
"%s %02d:%02d:%02d", dat, |
93 |
|
|
warp->tm_hour, warp->tm_min, warp->tm_sec); |
94 |
|
|
|
95 |
werner |
36 |
return timebuf; |
96 |
|
|
} |
97 |
|
|
|
98 |
|
|
|
99 |
twoaday |
219 |
/* Return human printable PKA status. |
100 |
|
|
If no pka information is available, return NULL. */ |
101 |
|
|
char* |
102 |
|
|
get_pka_status (gpgme_signature_t sig) |
103 |
|
|
{ |
104 |
|
|
const char *fmt; |
105 |
|
|
char *pka_inf; |
106 |
|
|
|
107 |
|
|
if (sig->pka_trust == 0 || !sig->pka_address) |
108 |
|
|
return NULL; |
109 |
|
|
fmt = _("PKA: Verified signer's address is '%s'"); |
110 |
|
|
pka_inf = new char[strlen (fmt)+strlen (sig->pka_address)+2]; |
111 |
|
|
if (!pka_inf) |
112 |
|
|
BUG (NULL); |
113 |
|
|
sprintf (pka_inf, fmt, sig->pka_address); |
114 |
|
|
return pka_inf; |
115 |
|
|
} |
116 |
|
|
|
117 |
|
|
|
118 |
|
|
/* Set additional signature information according to the |
119 |
|
|
signature @sig. If no info control is used, just return. */ |
120 |
|
|
void |
121 |
|
|
verlist_set_additional_info (verlist_ctrl_t vlv, gpgme_signature_t sig) |
122 |
|
|
{ |
123 |
|
|
int used = 1; |
124 |
|
|
|
125 |
|
|
if (!vlv->infctl) |
126 |
|
|
return; |
127 |
|
|
|
128 |
twoaday |
256 |
/* if the signature is bad, we just hide the window and return. */ |
129 |
|
|
if (sig->summary & GPGME_SIGSUM_RED) { |
130 |
|
|
ShowWindow (vlv->infctl, SW_HIDE); |
131 |
|
|
return; |
132 |
|
|
} |
133 |
twoaday |
262 |
/* XXX: if the summary does not contain GPGME_SIGSUM_GREEN, issue a warning. */ |
134 |
|
|
if (sig->validity != GPGME_VALIDITY_MARGINAL && |
135 |
|
|
sig->validity != GPGME_VALIDITY_FULL && |
136 |
|
|
sig->validity != GPGME_VALIDITY_ULTIMATE && |
137 |
|
|
!(sig->summary & GPGME_SIGSUM_KEY_MISSING)) { |
138 |
twoaday |
219 |
SendMessage (vlv->infctl, WM_SETTEXT, 0, (LPARAM)(char*) |
139 |
|
|
_("WARNING: This key is not certified with a trusted signature!\r\n" |
140 |
|
|
" There is no indication that the signature belongs to the owner.\r\n")); |
141 |
|
|
} |
142 |
twoaday |
262 |
else if (sig->exp_timestamp > (DWORD)time (NULL)) |
143 |
|
|
SendMessage (vlv->infctl, WM_SETTEXT, 0, (LPARAM)(char*) |
144 |
|
|
_("The signature is expired!")); |
145 |
twoaday |
219 |
else { |
146 |
|
|
char *pka_info = get_pka_status (sig); |
147 |
|
|
if (pka_info != NULL) { |
148 |
|
|
SendMessage (vlv->infctl, WM_SETTEXT, 0, (LPARAM)(char*)pka_info); |
149 |
|
|
free_if_alloc (pka_info); |
150 |
|
|
} |
151 |
|
|
else { |
152 |
|
|
SendMessage (vlv->infctl, WM_SETTEXT, 0, (LPARAM)(char*)""); |
153 |
|
|
used = 0; |
154 |
|
|
} |
155 |
|
|
} |
156 |
|
|
ShowWindow (vlv->infctl, used? SW_SHOW : SW_HIDE); |
157 |
|
|
} |
158 |
|
|
|
159 |
|
|
|
160 |
werner |
36 |
/* Build a verify signature list control. With the parent window |
161 |
|
|
from @ctrl and the mod given in @fm_mode. @lv contains the |
162 |
|
|
new control on success. |
163 |
|
|
Return value: 0 on success. */ |
164 |
twoaday |
219 |
void |
165 |
|
|
verlist_build (verlist_ctrl_t *vlv, HWND ctrl, int fm_mode) |
166 |
|
|
{ |
167 |
twoaday |
193 |
struct listview_column_s verlist[] = { |
168 |
twoaday |
228 |
{0, 120, (char *)_("Name")}, |
169 |
twoaday |
256 |
{1, 140, (char *)_("Status")}, |
170 |
|
|
{2, 120, (char *)_("Signed")}, |
171 |
twoaday |
193 |
{3, 58, (char *)_("Trust") }, |
172 |
|
|
{4, 80, (char *)_("Key ID" )}, |
173 |
twoaday |
256 |
{5, 160, (char *)_("User ID")}, |
174 |
twoaday |
193 |
{6, 0, NULL} |
175 |
werner |
36 |
}; |
176 |
twoaday |
228 |
HICON ico[2]; |
177 |
twoaday |
219 |
struct verlist_ctrl_s *v; |
178 |
twoaday |
193 |
int j; |
179 |
werner |
36 |
|
180 |
twoaday |
219 |
v = new verlist_ctrl_s; |
181 |
|
|
if (!v) |
182 |
|
|
BUG (0); |
183 |
|
|
memset (v, 0, sizeof *v); |
184 |
|
|
listview_new (&v->lv, ctrl); |
185 |
twoaday |
193 |
for(j=0; verlist[j].fieldname; j++) |
186 |
twoaday |
219 |
listview_add_column (v->lv, &verlist[j]); |
187 |
twoaday |
193 |
if (!fm_mode) |
188 |
twoaday |
228 |
listview_set_column_width (v->lv, 0, 80); |
189 |
twoaday |
219 |
listview_set_ext_style (v->lv); |
190 |
twoaday |
228 |
ico[0] = LoadIcon (glob_hinst, (LPCTSTR)IDI_SIG_GOOD); |
191 |
|
|
ico[1] = LoadIcon (glob_hinst, (LPCTSTR)IDI_SIG_BAD); |
192 |
|
|
listview_set_image_list (v->lv, 16, 16, ico, 2); |
193 |
twoaday |
219 |
*vlv = v; |
194 |
werner |
36 |
} |
195 |
|
|
|
196 |
|
|
|
197 |
twoaday |
219 |
void |
198 |
|
|
verlist_set_info_control (verlist_ctrl_t vlv, HWND infctl) |
199 |
|
|
{ |
200 |
|
|
vlv->infctl = infctl; |
201 |
|
|
} |
202 |
|
|
|
203 |
|
|
|
204 |
werner |
36 |
/* Delete the given verify control in @lv. */ |
205 |
|
|
void |
206 |
twoaday |
219 |
verlist_delete (verlist_ctrl_t vlv) |
207 |
werner |
36 |
{ |
208 |
twoaday |
219 |
if (vlv) { |
209 |
|
|
listview_release (vlv->lv); |
210 |
|
|
free_if_alloc (vlv); |
211 |
werner |
36 |
} |
212 |
|
|
} |
213 |
|
|
|
214 |
|
|
|
215 |
|
|
/* Add the given signature in @sig to the verify control @lv. |
216 |
|
|
Return value: 0 on success. */ |
217 |
|
|
int |
218 |
twoaday |
219 |
verlist_add_sig (verlist_ctrl_t vlv, gpgme_signature_t sig) |
219 |
werner |
36 |
{ |
220 |
twoaday |
228 |
listview_ctrl_t lv; |
221 |
twoaday |
256 |
struct winpt_key_s key; |
222 |
twoaday |
205 |
const char *attr; |
223 |
werner |
36 |
char keyid[32+1]; |
224 |
twoaday |
256 |
u32 key_attr; |
225 |
twoaday |
228 |
int is_bad; |
226 |
werner |
36 |
|
227 |
twoaday |
228 |
is_bad = sig->summary & GPGME_SIGSUM_RED? 1 : 0; |
228 |
twoaday |
219 |
lv = vlv->lv; |
229 |
twoaday |
228 |
if (listview_add_item_image (lv, " ", is_bad)) |
230 |
werner |
36 |
return WPTERR_GENERAL; |
231 |
twoaday |
193 |
|
232 |
twoaday |
270 |
listview_add_sub_item (lv, 0, VER_COL_NAME, _("Clipboard")); |
233 |
twoaday |
193 |
|
234 |
twoaday |
208 |
memset (&key, 0, sizeof (key)); |
235 |
|
|
winpt_get_pubkey (sig->fpr, &key); |
236 |
twoaday |
76 |
if (sig->summary == 0 && gpg_err_code (sig->status) == GPG_ERR_NO_ERROR) |
237 |
|
|
attr = get_gpg_sigstat (GPGME_SIGSUM_GREEN); |
238 |
|
|
else |
239 |
|
|
attr = get_gpg_sigstat (sig->summary); |
240 |
|
|
if (attr) |
241 |
twoaday |
193 |
listview_add_sub_item (lv, 0, VER_COL_STAT, (char *)attr); |
242 |
werner |
36 |
|
243 |
|
|
attr = strtimestamp (sig->timestamp); |
244 |
twoaday |
193 |
listview_add_sub_item (lv, 0, VER_COL_SIGNED, (char *)attr); |
245 |
werner |
36 |
|
246 |
|
|
attr = _("Unknown"); |
247 |
twoaday |
208 |
if (key.ctx) { |
248 |
|
|
key_attr = key.ext->uids->validity; |
249 |
werner |
36 |
attr = get_key_trust2 (NULL, key_attr, 0, 0); |
250 |
|
|
} |
251 |
twoaday |
193 |
listview_add_sub_item (lv, 0, VER_COL_TRUST, (char *)attr); |
252 |
werner |
36 |
|
253 |
twoaday |
205 |
attr = get_keyid_from_fpr (sig->fpr); |
254 |
|
|
_snprintf (keyid, sizeof keyid -1, "0x%s", attr); |
255 |
|
|
listview_add_sub_item (lv, 0, VER_COL_KEYID, keyid); |
256 |
werner |
36 |
|
257 |
twoaday |
208 |
attr = key.ctx? key.ext->uids->name : _("user ID not found"); |
258 |
twoaday |
204 |
listview_add_sub_item (lv, 0, VER_COL_UID, attr); |
259 |
twoaday |
219 |
|
260 |
|
|
if (vlv->infctl) |
261 |
|
|
verlist_set_additional_info (vlv, sig); |
262 |
werner |
36 |
return 0; |
263 |
|
|
} |
264 |
|
|
|
265 |
|
|
|
266 |
|
|
/* Add the given file signature in @log to the verify control @lv. |
267 |
|
|
Return value: 0 on success. */ |
268 |
|
|
int |
269 |
twoaday |
219 |
verlist_add_sig_log (verlist_ctrl_t vlv, file_sig_ctx_t log) |
270 |
werner |
36 |
{ |
271 |
|
|
gpgme_signature_t sig = log->sig; |
272 |
twoaday |
219 |
struct listview_ctrl_s *lv; |
273 |
twoaday |
208 |
struct winpt_key_s key; |
274 |
twoaday |
204 |
const char *attr; |
275 |
werner |
36 |
char t[64], *name; |
276 |
twoaday |
270 |
int is_bad; |
277 |
werner |
36 |
|
278 |
twoaday |
219 |
lv = vlv->lv; |
279 |
twoaday |
270 |
is_bad = sig->summary & GPGME_SIGSUM_RED? 1 : 0; |
280 |
|
|
if (listview_add_item_image (lv, "", is_bad)) { |
281 |
twoaday |
109 |
log_debug ("verlist_add_sig_log: listview_add_item() failed.\n"); |
282 |
werner |
36 |
return WPTERR_GENERAL; |
283 |
twoaday |
109 |
} |
284 |
werner |
36 |
|
285 |
twoaday |
208 |
memset (&key, 0, sizeof (key)); |
286 |
|
|
winpt_get_pubkey (sig->fpr, &key); |
287 |
werner |
36 |
|
288 |
|
|
name = extract_filename (log->file); |
289 |
|
|
if (name) |
290 |
twoaday |
193 |
listview_add_sub_item (lv, 0, VER_COL_NAME, name); |
291 |
werner |
36 |
else |
292 |
twoaday |
193 |
listview_add_sub_item (lv, 0, VER_COL_NAME, log->file); |
293 |
werner |
36 |
free_if_alloc (name); |
294 |
twoaday |
109 |
|
295 |
twoaday |
76 |
if (sig->summary == 0 && gpg_err_code (sig->status) == GPG_ERR_NO_ERROR) |
296 |
|
|
attr = get_gpg_sigstat (GPGME_SIGSUM_GREEN); |
297 |
|
|
else |
298 |
|
|
attr = get_gpg_sigstat (sig->summary); |
299 |
werner |
36 |
if (attr) |
300 |
twoaday |
193 |
listview_add_sub_item (lv, 0, VER_COL_STAT, attr); |
301 |
werner |
36 |
|
302 |
twoaday |
193 |
if (sig->timestamp > 0) |
303 |
werner |
36 |
attr = strtimestamp (sig->timestamp); |
304 |
|
|
else |
305 |
twoaday |
193 |
attr = "No time"; |
306 |
|
|
listview_add_sub_item (lv, 0, VER_COL_SIGNED, attr); |
307 |
|
|
|
308 |
twoaday |
208 |
if (key.ctx != NULL) |
309 |
|
|
attr = get_key_trust2 (NULL, key.ctx->uids->validity, 0, 0); |
310 |
twoaday |
193 |
else |
311 |
|
|
attr = _("Unknown"); |
312 |
|
|
listview_add_sub_item (lv, 0, VER_COL_TRUST, attr); |
313 |
twoaday |
205 |
|
314 |
|
|
attr = get_keyid_from_fpr (sig->fpr); |
315 |
|
|
_snprintf (t, sizeof (t)-1, "0x%s", attr); |
316 |
twoaday |
193 |
listview_add_sub_item (lv, 0, VER_COL_KEYID, t); |
317 |
twoaday |
204 |
listview_add_sub_item (lv, 0, VER_COL_UID, |
318 |
|
|
log->user_id? |
319 |
|
|
log->user_id : _("user ID not found")); |
320 |
twoaday |
219 |
if (vlv->infctl) |
321 |
|
|
verlist_set_additional_info (vlv, sig); |
322 |
|
|
|
323 |
werner |
36 |
return 0; |
324 |
|
|
} |