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