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

Contents of /trunk/Src/wptVerifyList.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 76 - (show annotations)
Thu Nov 10 14:07:06 2005 UTC (19 years, 3 months ago) by twoaday
File size: 7002 byte(s)
2005-11-09  Timo Schulz  <ts@g10code.com>
 
        * wptNLS.c (get_gettext_langid): Map user language id to
        printable gettext language strings.
        * wptRegistry.cpp (get_reg_entry_mo): Support for the
        gettext environment.
        * wptFileManager.cpp (fm_encrypt): Close all files before
        the wipe procedure is called.
        * wptVerlist.cpp (verlist_add_sig): Handle the case the
        issuer is not valid but the signature is.
        (verlist_add_sig_log): Likewise. Thanks to the folks on
        winpt-users.


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 #ifdef HAVE_CONFIG_H
22 #include <config.h>
23 #endif
24
25 #include <windows.h>
26 #include <time.h>
27
28 #include "wptTypes.h"
29 #include "wptGPG.h"
30 #include "wptCommonCtl.h"
31 #include "wptKeylist.h"
32 #include "wptNLS.h"
33 #include "wptErrors.h"
34 #include "wptUTF8.h"
35 #include "wptW32API.h"
36
37
38 /* Extract the file name part out of the given path in @path.
39 Return value: file part or NULL on error. */
40 static char*
41 extract_filename (const char *path)
42 {
43 char * fname, *p;
44 int n, len = 0;
45
46 p = strrchr (path, '\\');
47 if (!p)
48 return m_strdup (path);
49 n = p - path;
50 len = strlen (path) - n;
51 fname = new char[len+1];
52 if (!fname)
53 BUG (NULL);
54 memcpy (fname, path+n+1, len);
55 fname[len] = '\0';
56 return fname;
57 }
58
59
60 /* String representaton of the time in @timestamp.
61 Format YEAR-MON-DAY HOUR:MIN:SEC.
62 Return value: time as formatted string. */
63 const char *
64 strtimestamp (long timestamp)
65 {
66 static char timebuf[64] = {0};
67 struct tm *warp;
68
69 warp = localtime (&timestamp);
70 _snprintf (timebuf, sizeof timebuf - 1, "%04d-%02d-%02d %02d:%02d:%02d",
71 warp->tm_year+1900, warp->tm_mon+1, warp->tm_mday,
72 warp->tm_hour, warp->tm_min, warp->tm_sec);
73 return timebuf;
74 }
75
76
77 /* Map the signature summary in @sum to signature status table index.
78 Return value: index to table. */
79 int
80 sigsum_to_index (gpgme_sigsum_t sum)
81 {
82 if ((sum & GPGME_SIGSUM_VALID) && (sum & GPGME_SIGSUM_KEY_REVOKED))
83 return 7;
84 if ((sum & GPGME_SIGSUM_VALID) && (sum & GPGME_SIGSUM_SIG_EXPIRED))
85 return 6;
86 if (sum & GPGME_SIGSUM_GREEN)
87 return 1;
88 else if (sum & GPGME_SIGSUM_RED)
89 return 2;
90 else if (sum & GPGME_SIGSUM_KEY_MISSING)
91 return 3;
92 return 0;
93 }
94
95
96 /* Build a verify signature list control. With the parent window
97 from @ctrl and the mod given in @fm_mode. @lv contains the
98 new control on success.
99 Return value: 0 on success. */
100 int
101 verlist_build (listview_ctrl_t *lv, HWND ctrl, int fm_mode)
102 {
103 int j, rc = 0;
104 struct listview_ctrl_s * c;
105 struct listview_column_s fm_verlist[] = {
106 {0, 100, (char *)_("Name") },
107 {1, 120, (char *)_("Status") },
108 {2, 115, (char *)_("Signed") },
109 {3, 58, (char *)_("Trust") },
110 {4, 160, (char *)_("User ID") },
111 {5, 0, NULL}
112
113 };
114 struct listview_column_s verlist[] = {
115 {0, 140, (char *)_("Status") },
116 {1, 120, (char *)_("Signed") },
117 {2, 58, (char *)_("Trust") },
118 {3, 80, (char *)_("Key ID" )},
119 {4, 160, (char *)_("User ID") },
120 {5, 0, NULL}
121 };
122
123 rc = listview_new (&c);
124 if (rc)
125 return rc;
126
127 c->ctrl = ctrl;
128 if( fm_mode ) {
129 for( j = 0; fm_verlist[j].fieldname; j++ )
130 listview_add_column( c, &fm_verlist[j] );
131 }
132 else {
133 for( j = 0; verlist[j].fieldname; j++ )
134 listview_add_column( c, &verlist[ j ] );
135 }
136 listview_set_ext_style( c );
137 *lv = c;
138 return 0;
139 }
140
141
142 /* Delete the given verify control in @lv. */
143 void
144 verlist_delete (listview_ctrl_t lv)
145 {
146 if (lv) {
147 listview_release (lv);
148 }
149 }
150
151
152 /* Add the given signature in @sig to the verify control @lv.
153 Return value: 0 on success. */
154 int
155 verlist_add_sig (listview_ctrl_t lv, gpgme_signature_t sig)
156 {
157 gpgme_key_t key = NULL;
158 const char * attr;
159 u32 key_attr;
160 char keyid[32+1];
161 char * uid = NULL;
162
163 if (listview_add_item (lv, " "))
164 return WPTERR_GENERAL;
165
166 get_pubkey (sig->fpr, &key);
167
168 if (sig->summary == 0 && gpg_err_code (sig->status) == GPG_ERR_NO_ERROR)
169 attr = get_gpg_sigstat (GPGME_SIGSUM_GREEN);
170 else
171 attr = get_gpg_sigstat (sig->summary);
172 if (attr)
173 listview_add_sub_item (lv, 0, 0, (char *)attr);
174
175 attr = strtimestamp (sig->timestamp);
176 listview_add_sub_item (lv, 0, 1, (char *)attr);
177
178 attr = _("Unknown");
179 if (key) {
180 key_attr = key->uids->validity;
181 attr = get_key_trust2 (NULL, key_attr, 0, 0);
182 }
183 listview_add_sub_item (lv, 0, 2, (char *)attr);
184
185 attr = sig->fpr;
186 if (!attr || strlen (attr) < 8)
187 listview_add_sub_item (lv, 0, 3, "????????");
188 else {
189 if (strlen (attr) == 40)
190 attr += 32;
191 else if (strlen (attr) == 32)
192 attr += 24;
193 else
194 attr += 8;
195 _snprintf (keyid, sizeof keyid -1, "0x%s", attr);
196 listview_add_sub_item (lv, 0, 3, keyid);
197 }
198
199 if (!key) {
200 attr = _("Invalid User ID");
201 listview_add_sub_item( lv, 0, 4, (char *)attr );
202 }
203 else {
204 attr = key->uids->name;
205 uid = utf8_to_wincp (attr, strlen (attr));
206 if (uid) {
207 listview_add_sub_item( lv, 0, 4, (char *)uid );
208 free (uid);
209 }
210 }
211
212 return 0;
213 }
214
215
216 /* Add the given file signature in @log to the verify control @lv.
217 Return value: 0 on success. */
218 int
219 verlist_add_sig_log (listview_ctrl_t lv, file_sig_ctx_t log)
220 {
221 gpgme_signature_t sig = log->sig;
222 gpgme_key_t key = NULL;
223 const char *attr;
224 char t[64], *name;
225
226 if (listview_add_item (lv, ""))
227 return WPTERR_GENERAL;
228
229 get_pubkey (sig->fpr, &key);
230
231 name = extract_filename (log->file);
232 if (name)
233 listview_add_sub_item (lv, 0, 0, name);
234 else
235 listview_add_sub_item (lv, 0, 0, log->file);
236 free_if_alloc (name);
237
238 if (sig->summary == 0 && gpg_err_code (sig->status) == GPG_ERR_NO_ERROR)
239 attr = get_gpg_sigstat (GPGME_SIGSUM_GREEN);
240 else
241 attr = get_gpg_sigstat (sig->summary);
242 if (attr)
243 listview_add_sub_item (lv, 0, 1, attr);
244
245 if (sig->timestamp > 0) {
246 attr = strtimestamp (sig->timestamp);
247 listview_add_sub_item (lv, 0, 2, attr);
248 }
249 else
250 listview_add_sub_item (lv, 0, 2, "No time");
251
252 attr = _("Unknown");
253 if (key)
254 attr = get_key_trust2 (NULL, key->uids->validity, 0, 0);
255 listview_add_sub_item (lv, 0, 3, attr);
256
257 attr = sig->fpr;
258 if (!log->use_uid && strlen (attr) == 40) {
259 _snprintf (t, sizeof (t)-1, "0x%s", attr + 32);
260 listview_add_sub_item (lv, 0, 4, t);
261 }
262 else if( !log->use_uid && strlen( attr ) == 32 ) {
263 _snprintf (t, sizeof (t)-1, "0x%s", attr + 24);
264 listview_add_sub_item (lv, 0, 4, t);
265 }
266 else if (log->user_id) {
267 char *p = utf8_to_wincp (log->user_id, strlen (log->user_id));
268 if (p) {
269 listview_add_sub_item (lv, 0, 4, p);
270 free (p);
271 }
272 }
273 return 0;
274 }

Properties

Name Value
svn:eol-style native

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26