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

Annotation of /trunk/Src/wptVerifyList.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 23 - (hide annotations)
Fri Sep 30 10:10:16 2005 UTC (19 years, 5 months ago) by twoaday
File size: 6807 byte(s)
Almost finished phase 1 of the WinPT GPGME port.
Still need more cleanup, comments and tests.


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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26