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

Annotation of /trunk/Src/wptVerifyList.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 228 - (hide annotations)
Thu Jun 15 11:37:53 2006 UTC (18 years, 8 months ago) by twoaday
File size: 8644 byte(s)
2006-06-15  Timo Schulz  <ts@g10code.de>
                                                                                
        * wptVerList.cpp (verlist_build): Use icons.
        (verlist_add_sig): Set image number according to sig state.
                                                                                


1 werner 36 /* 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 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 (&timestamp);
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     if (sig->exp_timestamp > (DWORD)time (NULL))
129     SendMessage (vlv->infctl, WM_SETTEXT, 0, (LPARAM)(char*)
130     _("The signature is expired!"));
131     else if (sig->validity != GPGME_VALIDITY_MARGINAL &&
132     sig->validity != GPGME_VALIDITY_FULL &&
133     sig->validity != GPGME_VALIDITY_ULTIMATE) {
134     SendMessage (vlv->infctl, WM_SETTEXT, 0, (LPARAM)(char*)
135     _("WARNING: This key is not certified with a trusted signature!\r\n"
136     " There is no indication that the signature belongs to the owner.\r\n"));
137     }
138     else {
139     char *pka_info = get_pka_status (sig);
140     if (pka_info != NULL) {
141     SendMessage (vlv->infctl, WM_SETTEXT, 0, (LPARAM)(char*)pka_info);
142     free_if_alloc (pka_info);
143     }
144     else {
145     SendMessage (vlv->infctl, WM_SETTEXT, 0, (LPARAM)(char*)"");
146     used = 0;
147     }
148     }
149     ShowWindow (vlv->infctl, used? SW_SHOW : SW_HIDE);
150     }
151    
152    
153 werner 36 /* Build a verify signature list control. With the parent window
154     from @ctrl and the mod given in @fm_mode. @lv contains the
155     new control on success.
156     Return value: 0 on success. */
157 twoaday 219 void
158     verlist_build (verlist_ctrl_t *vlv, HWND ctrl, int fm_mode)
159     {
160 twoaday 193 struct listview_column_s verlist[] = {
161 twoaday 228 {0, 120, (char *)_("Name")},
162 twoaday 193 {1, 140, (char *)_("Status") },
163     {2, 120, (char *)_("Signed") },
164     {3, 58, (char *)_("Trust") },
165     {4, 80, (char *)_("Key ID" )},
166     {5, 160, (char *)_("User ID") },
167     {6, 0, NULL}
168 werner 36 };
169 twoaday 228 HICON ico[2];
170 twoaday 219 struct verlist_ctrl_s *v;
171 twoaday 193 int j;
172 werner 36
173 twoaday 219 v = new verlist_ctrl_s;
174     if (!v)
175     BUG (0);
176     memset (v, 0, sizeof *v);
177     listview_new (&v->lv, ctrl);
178 twoaday 193 for(j=0; verlist[j].fieldname; j++)
179 twoaday 219 listview_add_column (v->lv, &verlist[j]);
180 twoaday 193 if (!fm_mode)
181 twoaday 228 listview_set_column_width (v->lv, 0, 80);
182 twoaday 219 listview_set_ext_style (v->lv);
183 twoaday 228 ico[0] = LoadIcon (glob_hinst, (LPCTSTR)IDI_SIG_GOOD);
184     ico[1] = LoadIcon (glob_hinst, (LPCTSTR)IDI_SIG_BAD);
185     listview_set_image_list (v->lv, 16, 16, ico, 2);
186 twoaday 219 *vlv = v;
187 werner 36 }
188    
189    
190 twoaday 219 void
191     verlist_set_info_control (verlist_ctrl_t vlv, HWND infctl)
192     {
193     vlv->infctl = infctl;
194     }
195    
196    
197 werner 36 /* Delete the given verify control in @lv. */
198     void
199 twoaday 219 verlist_delete (verlist_ctrl_t vlv)
200 werner 36 {
201 twoaday 219 if (vlv) {
202     listview_release (vlv->lv);
203     free_if_alloc (vlv);
204 werner 36 }
205     }
206    
207    
208     /* Add the given signature in @sig to the verify control @lv.
209     Return value: 0 on success. */
210     int
211 twoaday 219 verlist_add_sig (verlist_ctrl_t vlv, gpgme_signature_t sig)
212 werner 36 {
213 twoaday 228 listview_ctrl_t lv;
214 twoaday 208 struct winpt_key_s key;
215 werner 36 u32 key_attr;
216 twoaday 205 const char *attr;
217 werner 36 char keyid[32+1];
218 twoaday 228 int is_bad;
219 werner 36
220 twoaday 228 is_bad = sig->summary & GPGME_SIGSUM_RED? 1 : 0;
221 twoaday 219 lv = vlv->lv;
222 twoaday 228 if (listview_add_item_image (lv, " ", is_bad))
223 werner 36 return WPTERR_GENERAL;
224 twoaday 193
225     listview_add_sub_item (lv, 0, VER_COL_NAME, "Clipboard");
226    
227 twoaday 208 memset (&key, 0, sizeof (key));
228     winpt_get_pubkey (sig->fpr, &key);
229 twoaday 76 if (sig->summary == 0 && gpg_err_code (sig->status) == GPG_ERR_NO_ERROR)
230     attr = get_gpg_sigstat (GPGME_SIGSUM_GREEN);
231     else
232     attr = get_gpg_sigstat (sig->summary);
233     if (attr)
234 twoaday 193 listview_add_sub_item (lv, 0, VER_COL_STAT, (char *)attr);
235 werner 36
236     attr = strtimestamp (sig->timestamp);
237 twoaday 193 listview_add_sub_item (lv, 0, VER_COL_SIGNED, (char *)attr);
238 werner 36
239     attr = _("Unknown");
240 twoaday 208 if (key.ctx) {
241     key_attr = key.ext->uids->validity;
242 werner 36 attr = get_key_trust2 (NULL, key_attr, 0, 0);
243     }
244 twoaday 193 listview_add_sub_item (lv, 0, VER_COL_TRUST, (char *)attr);
245 werner 36
246 twoaday 205 attr = get_keyid_from_fpr (sig->fpr);
247     _snprintf (keyid, sizeof keyid -1, "0x%s", attr);
248     listview_add_sub_item (lv, 0, VER_COL_KEYID, keyid);
249 werner 36
250 twoaday 208 attr = key.ctx? key.ext->uids->name : _("user ID not found");
251 twoaday 204 listview_add_sub_item (lv, 0, VER_COL_UID, attr);
252 twoaday 219
253     if (vlv->infctl)
254     verlist_set_additional_info (vlv, sig);
255 werner 36 return 0;
256     }
257    
258    
259     /* Add the given file signature in @log to the verify control @lv.
260     Return value: 0 on success. */
261     int
262 twoaday 219 verlist_add_sig_log (verlist_ctrl_t vlv, file_sig_ctx_t log)
263 werner 36 {
264     gpgme_signature_t sig = log->sig;
265 twoaday 219 struct listview_ctrl_s *lv;
266 twoaday 208 struct winpt_key_s key;
267 twoaday 204 const char *attr;
268 werner 36 char t[64], *name;
269    
270 twoaday 219 lv = vlv->lv;
271 twoaday 109 if (listview_add_item (lv, "")) {
272     log_debug ("verlist_add_sig_log: listview_add_item() failed.\n");
273 werner 36 return WPTERR_GENERAL;
274 twoaday 109 }
275 werner 36
276 twoaday 208 memset (&key, 0, sizeof (key));
277     winpt_get_pubkey (sig->fpr, &key);
278 werner 36
279     name = extract_filename (log->file);
280     if (name)
281 twoaday 193 listview_add_sub_item (lv, 0, VER_COL_NAME, name);
282 werner 36 else
283 twoaday 193 listview_add_sub_item (lv, 0, VER_COL_NAME, log->file);
284 werner 36 free_if_alloc (name);
285 twoaday 109
286 twoaday 76 if (sig->summary == 0 && gpg_err_code (sig->status) == GPG_ERR_NO_ERROR)
287     attr = get_gpg_sigstat (GPGME_SIGSUM_GREEN);
288     else
289     attr = get_gpg_sigstat (sig->summary);
290 werner 36 if (attr)
291 twoaday 193 listview_add_sub_item (lv, 0, VER_COL_STAT, attr);
292 werner 36
293 twoaday 193 if (sig->timestamp > 0)
294 werner 36 attr = strtimestamp (sig->timestamp);
295     else
296 twoaday 193 attr = "No time";
297     listview_add_sub_item (lv, 0, VER_COL_SIGNED, attr);
298    
299 twoaday 208 if (key.ctx != NULL)
300     attr = get_key_trust2 (NULL, key.ctx->uids->validity, 0, 0);
301 twoaday 193 else
302     attr = _("Unknown");
303     listview_add_sub_item (lv, 0, VER_COL_TRUST, attr);
304 twoaday 205
305     attr = get_keyid_from_fpr (sig->fpr);
306     _snprintf (t, sizeof (t)-1, "0x%s", attr);
307 twoaday 193 listview_add_sub_item (lv, 0, VER_COL_KEYID, t);
308 twoaday 204 listview_add_sub_item (lv, 0, VER_COL_UID,
309     log->user_id?
310     log->user_id : _("user ID not found"));
311 twoaday 219 if (vlv->infctl)
312     verlist_set_additional_info (vlv, sig);
313    
314 werner 36 return 0;
315     }

Properties

Name Value
svn:eol-style native

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26