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

Contents of /trunk/Src/wptVerifyList.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 219 - (show annotations)
Sat May 27 08:56:00 2006 UTC (18 years, 9 months ago) by twoaday
File size: 8336 byte(s)
2006-05-25  Timo Schulz  <ts@g10code.de>
                                                                                
        * wptGPGUtil.cpp (gpg_rebuild_cache): Return error code.
        * wptGPGME.cpp (winpt_get_seckey): Fix off-by-one bug.
        * wptVerifyList.cpp (verlist_build): New argument type.
        Change all callers.
        (verlist_set_info_control): New.
        (verlist_set_additional_info): New.
        * wptFileVerifyDlg.cpp (file_verify_dlg_proc): Adjust code.
        * wptClipVerifyDlg.cpp (clip_verify_dlg_proc): Likewise.
        * wptFileCBS.cpp (read_cb, write_cb): Add logging.
                                                                                


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

Properties

Name Value
svn:eol-style native

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26