/[winpt]/trunk/Src/wptVerifyList.cpp
ViewVC logotype

Contents of /trunk/Src/wptVerifyList.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 286 - (show annotations)
Fri Mar 9 19:34:17 2007 UTC (17 years, 11 months ago) by twoaday
File size: 8846 byte(s)
First part of the patch to fix the v3 verify problem.


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

Properties

Name Value
svn:eol-style native

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26