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

Annotation of /trunk/Src/wptVerifyList.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 32 - (hide annotations)
Mon Oct 24 08:03:48 2005 UTC (19 years, 4 months ago) by twoaday
File size: 6919 byte(s)
2005-10-23  Timo Schulz  <twoaday@g10code.com>
 
        * wptFileManager.cpp (fm_get_file_type): Detect detached sigs.
        * wptKeyList.cpp (keylist_cmp_cb): Take care of expired/revoked keys.
        (get_ext_validity): New.
        * wptFileVerifyDlg.cpp (file_verify_dlg_proc): Several cleanups.
        * wptClipEditDlg.cpp (load_clipboard): Factored out some code into
        this function.
        (load_clipboard_from_file): Likewise.
        (save_clipboard_to_file): New.
        * wptKeyManagerDlg.cpp (keyprops_dlg_proc): Fix stack overflow.

For complete details, see the ChangeLog files.

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26