1 |
/* wptVerifyList.cpp - Listview for verifying signatures |
/* wptVerifyList.cpp - Listview for verifying signatures |
2 |
* Copyright (C) 2001, 2002, 2003, 2005 Timo Schulz |
* Copyright (C) 2001, 2002, 2003, 2005 Timo Schulz |
3 |
* |
* Copyright (C) 2005 g10 Code GmbH |
4 |
* This file is part of WinPT. |
* |
5 |
* |
* This file is part of WinPT. |
6 |
* WinPT is free software; you can redistribute it and/or |
* |
7 |
* modify it under the terms of the GNU General Public License |
* WinPT is free software; you can redistribute it and/or |
8 |
* as published by the Free Software Foundation; either version 2 |
* modify it under the terms of the GNU General Public License |
9 |
* of the License, or (at your option) any later version. |
* as published by the Free Software Foundation; either version 2 |
10 |
* |
* of the License, or (at your option) any later version. |
11 |
* WinPT is distributed in the hope that it will be useful, |
* |
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
* WinPT is distributed in the hope that it will be useful, |
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 |
* General Public License for more details. |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
15 |
* |
* General Public License for more details. |
16 |
* You should have received a copy of the GNU General Public License |
* |
17 |
* along with WinPT; if not, write to the Free Software Foundation, |
* You should have received a copy of the GNU General Public License |
18 |
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
* along with WinPT; if not, write to the Free Software Foundation, |
19 |
*/ |
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
20 |
/* x-todo-status: OK */ |
*/ |
21 |
|
#ifdef HAVE_CONFIG_H |
22 |
#include <windows.h> |
#include <config.h> |
23 |
#include <time.h> |
#endif |
24 |
|
|
25 |
#include "wptTypes.h" |
#include <windows.h> |
26 |
#include "wptGPG.h" |
#include <time.h> |
27 |
#include "wptCommonCtl.h" |
|
28 |
#include "wptKeylist.h" |
#include "wptTypes.h" |
29 |
#include "wptNLS.h" |
#include "wptGPG.h" |
30 |
#include "wptErrors.h" |
#include "wptCommonCtl.h" |
31 |
#include "wptUTF8.h" |
#include "wptKeylist.h" |
32 |
#include "wptW32API.h" |
#include "wptNLS.h" |
33 |
|
#include "wptErrors.h" |
34 |
|
#include "wptUTF8.h" |
35 |
static char * |
#include "wptW32API.h" |
36 |
extract_filename( const char * path ) |
|
37 |
{ |
|
38 |
char * fname, * p; |
/* Extract the file name part out of the given path in @path. |
39 |
int n, len = 0; |
Return value: file part or NULL on error. */ |
40 |
|
static char* |
41 |
p = strrchr( path, '\\' ); |
extract_filename (const char *path) |
42 |
if( !p ) |
{ |
43 |
return m_strdup( path ); |
char * fname, *p; |
44 |
n = p - path; |
int n, len = 0; |
45 |
len = strlen( path ) - n; |
|
46 |
fname = new char[len+1]; |
p = strrchr (path, '\\'); |
47 |
if( !fname ) |
if (!p) |
48 |
BUG( NULL ); |
return m_strdup (path); |
49 |
memcpy( fname, path+n+1, len ); |
n = p - path; |
50 |
fname[len] = '\0'; |
len = strlen (path) - n; |
51 |
return fname; |
fname = new char[len+1]; |
52 |
} /* extract_filename */ |
if (!fname) |
53 |
|
BUG (NULL); |
54 |
|
memcpy (fname, path+n+1, len); |
55 |
const char * |
fname[len] = '\0'; |
56 |
strtimestamp( long timestamp ) |
return fname; |
57 |
{ |
} |
58 |
static char timebuf[64] = {0}; |
|
59 |
struct tm * warp; |
|
60 |
|
/* String representaton of the time in @timestamp. |
61 |
warp = localtime( ×tamp ); |
Format YEAR-MON-DAY HOUR:MIN:SEC. |
62 |
_snprintf( timebuf, sizeof timebuf - 1, "%04d-%02d-%02d %02d:%02d:%02d", |
Return value: time as formatted string. */ |
63 |
warp->tm_year+1900, warp->tm_mon+1, warp->tm_mday, |
const char * |
64 |
warp->tm_hour, warp->tm_min, warp->tm_sec ); |
strtimestamp (long timestamp) |
65 |
return timebuf; |
{ |
66 |
} /* strtimestamp */ |
static char timebuf[64] = {0}; |
67 |
|
struct tm *warp; |
68 |
|
|
69 |
int |
warp = localtime (×tamp); |
70 |
verlist_build (listview_ctrl_t * lv, HWND ctrl, int fm_mode) |
_snprintf (timebuf, sizeof timebuf - 1, "%04d-%02d-%02d %02d:%02d:%02d", |
71 |
{ |
warp->tm_year+1900, warp->tm_mon+1, warp->tm_mday, |
72 |
int j, rc = 0; |
warp->tm_hour, warp->tm_min, warp->tm_sec); |
73 |
struct listview_ctrl_s * c; |
return timebuf; |
74 |
struct listview_column_s fm_verlist[] = { |
} |
75 |
{0, 100, (char *)_("Name") }, |
|
76 |
{1, 120, (char *)_("Status") }, |
|
77 |
{2, 115, (char *)_("Signed") }, |
/* Build a verify signature list control. With the parent window |
78 |
{3, 58, (char *)_("Trust") }, |
from @ctrl and the mod given in @fm_mode. @lv contains the |
79 |
{4, 160, (char *)_("User ID") }, |
new control on success. |
80 |
{5, 0, NULL } |
Return value: 0 on success. */ |
81 |
|
int |
82 |
}; |
verlist_build (listview_ctrl_t *lv, HWND ctrl, int fm_mode) |
83 |
struct listview_column_s verlist[] = { |
{ |
84 |
{0, 140, (char *)_("Status") }, |
int j, rc = 0; |
85 |
{1, 120, (char *)_("Signed") }, |
struct listview_ctrl_s * c; |
86 |
{2, 58, (char *)_("Trust") }, |
struct listview_column_s fm_verlist[] = { |
87 |
{3, 80, (char *)_("Key ID" )}, |
{0, 100, (char *)_("Name") }, |
88 |
{4, 160, (char *)_("User ID") }, |
{1, 120, (char *)_("Status") }, |
89 |
{5, 0, NULL } |
{2, 115, (char *)_("Signed") }, |
90 |
}; |
{3, 58, (char *)_("Trust") }, |
91 |
|
{4, 160, (char *)_("User ID") }, |
92 |
rc = listview_new( &c ); |
{5, 0, NULL} |
93 |
if( rc ) |
|
94 |
return rc; |
}; |
95 |
|
struct listview_column_s verlist[] = { |
96 |
c->ctrl = ctrl; |
{0, 140, (char *)_("Status") }, |
97 |
if( fm_mode ) { |
{1, 120, (char *)_("Signed") }, |
98 |
for( j = 0; fm_verlist[j].fieldname; j++ ) |
{2, 58, (char *)_("Trust") }, |
99 |
listview_add_column( c, &fm_verlist[j] ); |
{3, 80, (char *)_("Key ID" )}, |
100 |
} |
{4, 160, (char *)_("User ID") }, |
101 |
else { |
{5, 0, NULL} |
102 |
for( j = 0; verlist[j].fieldname; j++ ) |
}; |
103 |
listview_add_column( c, &verlist[ j ] ); |
|
104 |
} |
rc = listview_new (&c); |
105 |
listview_set_ext_style( c ); |
if (rc) |
106 |
*lv = c; |
return rc; |
107 |
return 0; |
|
108 |
} /* verlist_build */ |
c->ctrl = ctrl; |
109 |
|
if( fm_mode ) { |
110 |
|
for( j = 0; fm_verlist[j].fieldname; j++ ) |
111 |
void |
listview_add_column( c, &fm_verlist[j] ); |
112 |
verlist_delete( listview_ctrl_t lv ) |
} |
113 |
{ |
else { |
114 |
if( lv ) { |
for( j = 0; verlist[j].fieldname; j++ ) |
115 |
listview_release( lv ); |
listview_add_column( c, &verlist[ j ] ); |
116 |
} |
} |
117 |
} /* verlist_delete */ |
listview_set_ext_style( c ); |
118 |
|
*lv = c; |
119 |
|
return 0; |
120 |
int |
} |
121 |
verlist_add_sig( listview_ctrl_t lv, gpgme_sig_t sig ) |
|
122 |
{ |
|
123 |
gpgme_key_t key; |
/* Delete the given verify control in @lv. */ |
124 |
const char * attr; |
void |
125 |
u32 key_attr, t; |
verlist_delete (listview_ctrl_t lv) |
126 |
char keyid[32+1]; |
{ |
127 |
char * uid = NULL; |
if (lv) { |
128 |
|
listview_release (lv); |
129 |
if( listview_add_item( lv, " " ) ) |
} |
130 |
return WPTERR_GENERAL; |
} |
131 |
|
|
132 |
if( !gpgme_sig_get_ulong_attr( sig, 0, GPGME_ATTR_TYPE ) ) |
|
133 |
return WPTERR_GENERAL; /* No key was stored */ |
/* Add the given signature in @sig to the verify control @lv. |
134 |
|
Return value: 0 on success. */ |
135 |
t = gpgme_sig_get_ulong_attr( sig, 0, GPGME_ATTR_VALIDITY ); |
int |
136 |
attr = gpg_sigstat[t % SIGSTAT_MASK]; |
verlist_add_sig (listview_ctrl_t lv, gpgme_signature_t sig) |
137 |
if( attr ) |
{ |
138 |
listview_add_sub_item( lv, 0, 0, (char *)attr ); |
gpgme_key_t key = NULL; |
139 |
|
const char * attr; |
140 |
t = gpgme_sig_get_ulong_attr( sig, 0, GPGME_ATTR_CREATED ); |
u32 key_attr; |
141 |
attr = strtimestamp( t ); |
char keyid[32+1]; |
142 |
if( attr ) |
char * uid = NULL; |
143 |
listview_add_sub_item( lv, 0, 1, (char *)attr ); |
|
144 |
|
if (listview_add_item (lv, " ")) |
145 |
t = gpgme_sig_get_ulong_attr( sig, 0, GPGME_ATTR_TYPE ); |
return WPTERR_GENERAL; |
146 |
key = (gpgme_key_t)t; |
|
147 |
key_attr = gpgme_key_get_ulong_attr( key, GPGME_ATTR_VALIDITY, NULL, 0 ); |
get_pubkey (sig->fpr, &key); |
148 |
attr = gpgme_key_expand_attr( GPGME_ATTR_VALIDITY, key_attr ); |
|
149 |
if( attr ) |
if (sig->summary == 0 && gpg_err_code (sig->status) == GPG_ERR_NO_ERROR) |
150 |
listview_add_sub_item( lv, 0, 2, (char *)attr ); |
attr = get_gpg_sigstat (GPGME_SIGSUM_GREEN); |
151 |
|
else |
152 |
attr = gpgme_key_get_string_attr( key, GPGME_ATTR_KEYID, NULL, 0 ); |
attr = get_gpg_sigstat (sig->summary); |
153 |
if ( !attr || strlen( attr ) < 8 ) |
if (attr) |
154 |
attr = "DEADBEEFDEADBEEF"; |
listview_add_sub_item (lv, 0, 0, (char *)attr); |
155 |
_snprintf( keyid, sizeof keyid -1, "0x%s", attr + 8 ); |
|
156 |
listview_add_sub_item( lv, 0, 3, keyid ); |
attr = strtimestamp (sig->timestamp); |
157 |
|
listview_add_sub_item (lv, 0, 1, (char *)attr); |
158 |
attr = gpgme_key_get_string_attr( key, GPGME_ATTR_NAME, NULL, 0 ); |
|
159 |
if( !attr ) { |
attr = _("Unknown"); |
160 |
attr = _("Invalid User ID"); |
if (key) { |
161 |
listview_add_sub_item( lv, 0, 4, (char *)attr ); |
key_attr = key->uids->validity; |
162 |
} |
attr = get_key_trust2 (NULL, key_attr, 0, 0); |
163 |
else { |
} |
164 |
uid = utf8_to_wincp (attr, strlen (attr)); |
listview_add_sub_item (lv, 0, 2, (char *)attr); |
165 |
if ( uid ) { |
|
166 |
listview_add_sub_item( lv, 0, 4, (char *)uid ); |
attr = sig->fpr; |
167 |
free( uid ); |
if (!attr || strlen (attr) < 8) |
168 |
} |
listview_add_sub_item (lv, 0, 3, "????????"); |
169 |
} |
else { |
170 |
|
if (strlen (attr) == 40) |
171 |
return 0; |
attr += 32; |
172 |
} /* verlist_add_sig */ |
else if (strlen (attr) == 32) |
173 |
|
attr += 24; |
174 |
|
else |
175 |
int |
attr += 8; |
176 |
verlist_add_sig_log( listview_ctrl_t lv, siglog_context_t log ) |
_snprintf (keyid, sizeof keyid -1, "0x%s", attr); |
177 |
{ |
listview_add_sub_item (lv, 0, 3, keyid); |
178 |
gpgme_sig_t sig = log->sig; |
} |
179 |
const char * attr; |
|
180 |
char t[64], * name; |
if (!key) { |
181 |
u32 i_attr; |
attr = _("Invalid User ID"); |
182 |
|
listview_add_sub_item( lv, 0, 4, (char *)attr ); |
183 |
if( listview_add_item( lv, "" ) ) |
} |
184 |
return WPTERR_GENERAL; |
else { |
185 |
|
attr = key->uids->name; |
186 |
name = extract_filename( log->file ); |
uid = utf8_to_wincp (attr, strlen (attr)); |
187 |
if( name ) |
if (uid) { |
188 |
listview_add_sub_item( lv, 0, 0, name ); |
listview_add_sub_item( lv, 0, 4, (char *)uid ); |
189 |
free_if_alloc( name ); |
free (uid); |
190 |
|
} |
191 |
i_attr = gpgme_sig_get_ulong_attr( sig, 0, GPGME_ATTR_VALIDITY ); |
} |
192 |
attr = gpg_sigstat[i_attr % SIGSTAT_MASK]; |
|
193 |
if( attr ) |
return 0; |
194 |
listview_add_sub_item( lv, 0, 1, attr ); |
} |
195 |
|
|
196 |
attr = strtimestamp( gpgme_sig_get_ulong_attr( sig, 0, GPGME_ATTR_CREATED ) ); |
|
197 |
if( attr ) |
/* Add the given file signature in @log to the verify control @lv. |
198 |
listview_add_sub_item( lv, 0, 2, attr ); |
Return value: 0 on success. */ |
199 |
|
int |
200 |
attr = gpgme_key_expand_attr( GPGME_ATTR_VALIDITY, |
verlist_add_sig_log (listview_ctrl_t lv, file_sig_ctx_t log) |
201 |
gpgme_sig_get_ulong_attr( sig, 0, GPGME_ATTR_OTRUST ) ); |
{ |
202 |
if( attr ) |
gpgme_signature_t sig = log->sig; |
203 |
listview_add_sub_item( lv, 0, 3, attr ); |
gpgme_key_t key = NULL; |
204 |
|
const char *attr; |
205 |
attr = gpgme_sig_get_string_attr( sig, GPGME_ATTR_KEYID ); |
char t[64], *name; |
206 |
if( !log->use_uid && strlen( attr ) == 16 ) { |
|
207 |
_snprintf( t, sizeof t-1, "0x%s", attr + 8 ); |
if (listview_add_item (lv, "")) { |
208 |
listview_add_sub_item( lv, 0, 4, t ); |
log_debug ("verlist_add_sig_log: listview_add_item() failed.\n"); |
209 |
} |
return WPTERR_GENERAL; |
210 |
else if( !log->use_uid && strlen( attr ) == 8 ) { |
} |
211 |
_snprintf( t, sizeof t-1, "0x%s", attr ); |
|
212 |
listview_add_sub_item( lv, 0, 4, t ); |
get_pubkey (sig->fpr, &key); |
213 |
} |
|
214 |
else if( log->user_id ) { |
name = extract_filename (log->file); |
215 |
char * p = utf8_to_wincp (log->user_id, strlen (log->user_id)); |
if (name) |
216 |
if( p ) { |
listview_add_sub_item (lv, 0, 0, name); |
217 |
listview_add_sub_item( lv, 0, 4, p ); |
else |
218 |
free( p ); |
listview_add_sub_item (lv, 0, 0, log->file); |
219 |
} |
free_if_alloc (name); |
220 |
} |
|
221 |
return 0; |
if (sig->summary == 0 && gpg_err_code (sig->status) == GPG_ERR_NO_ERROR) |
222 |
} /* verlist_add_sig_log */ |
attr = get_gpg_sigstat (GPGME_SIGSUM_GREEN); |
223 |
|
else |
224 |
|
attr = get_gpg_sigstat (sig->summary); |
225 |
|
if (attr) |
226 |
|
listview_add_sub_item (lv, 0, 1, attr); |
227 |
|
|
228 |
|
if (sig->timestamp > 0) { |
229 |
|
attr = strtimestamp (sig->timestamp); |
230 |
|
listview_add_sub_item (lv, 0, 2, attr); |
231 |
|
} |
232 |
|
else |
233 |
|
listview_add_sub_item (lv, 0, 2, "No time"); |
234 |
|
|
235 |
|
attr = _("Unknown"); |
236 |
|
if (key) |
237 |
|
attr = get_key_trust2 (NULL, key->uids->validity, 0, 0); |
238 |
|
listview_add_sub_item (lv, 0, 3, attr); |
239 |
|
|
240 |
|
attr = sig->fpr; |
241 |
|
if (!log->use_uid && strlen (attr) == 40) { |
242 |
|
_snprintf (t, sizeof (t)-1, "0x%s", attr + 32); |
243 |
|
listview_add_sub_item (lv, 0, 4, t); |
244 |
|
} |
245 |
|
else if (!log->use_uid && strlen( attr ) == 32) { |
246 |
|
_snprintf (t, sizeof (t)-1, "0x%s", attr + 24); |
247 |
|
listview_add_sub_item (lv, 0, 4, t); |
248 |
|
} |
249 |
|
else if (log->user_id) { |
250 |
|
char *p = utf8_to_wincp (log->user_id, strlen (log->user_id)); |
251 |
|
if (p) { |
252 |
|
listview_add_sub_item (lv, 0, 4, p); |
253 |
|
free (p); |
254 |
|
} |
255 |
|
} |
256 |
|
return 0; |
257 |
|
} |