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

Contents of /trunk/Src/wptFileStatDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 32 - (show annotations)
Mon Oct 24 08:03:48 2005 UTC (19 years, 4 months ago) by twoaday
File size: 7462 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 /* wptFileStatDlg.cpp - (File Manager) Show file statistics
2 * Copyright (C) 2002, 2003, 2005 Timo Schulz
3 *
4 * This file is part of WinPT.
5 *
6 * WinPT is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (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
14 * GNU 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
21 #include <windows.h>
22 #include <time.h>
23 #include <sys/types.h>
24
25 #include "../resource.h"
26 #include "wptTypes.h"
27 #include "wptNLS.h"
28 #include "wptGPG.h"
29 #include "wptCommonCtl.h"
30 #include "wptContext.h"
31 #include "wptDlgs.h"
32 #include "wptErrors.h"
33 #include "wptW32API.h"
34 #include "openpgp.h"
35
36 static const char*
37 get_pubkey_algo (int algo)
38 {
39 if (algo == 17)
40 return "DSA";
41 else if (is_ELGAMAL (algo))
42 return "ELG";
43 else if (is_RSA (algo))
44 return "RSA";
45 return NULL;
46 }
47
48
49 const char*
50 get_symkey_algo (int algo)
51 {
52 switch (algo) {
53 case 0: return "PLAINTEXT";
54 case 1: return "IDEA";
55 case 2: return "3DES";
56 case 3: return "CAST5";
57 case 4: return "BLOWFISH";
58 case 5: return "RESERVED";
59 case 6: return "RESERVED";
60 case 7: return "AES";
61 case 8: return "AES-192";
62 case 9: return "AES-256";
63 }
64 return "UNKNOWN";
65 }
66
67
68 static const char*
69 get_digest_algo (int algo)
70 {
71 switch (algo) {
72 case 0: return "NONE";
73 case 1: return "MD5";
74 case 2: return "SHA1";
75 case 3: return "RMD160";
76 case 4: return "RESERVED";
77 case 5: return "MD2";
78 case 6: return "RESERVED";
79 case 7: return "RESERVED";
80 case 8: return "SHA256";
81 case 9: return "SHA384";
82 case 10:return "SHA512";
83 }
84 return "UNKNOWN";
85 }
86
87
88 static const char*
89 get_compress_algo (int algo)
90 {
91 switch (algo) {
92 case 0: return "NONE";
93 case 1: return "ZIB";
94 case 2: return "ZLIB";
95 case 3: return "BZIP2";
96 }
97 return "UNKNOWN";
98 }
99
100
101 static const char*
102 get_timestring (long timestamp)
103 {
104 static char ts[64];
105 struct tm *ltm;
106
107 ltm = localtime (&timestamp);
108 _snprintf(ts, sizeof ts -1, "%04d-%02d-%02d",
109 ltm->tm_year + 1900, ltm->tm_mon + 1, ltm->tm_mday);
110 return ts;
111 }
112
113
114 /* List all PGP packets from the file @file.
115 Return value: number of packets. */
116 static int
117 do_list_packets (HWND list, const char *file)
118 {
119 PACKET *pkt;
120 gpg_iobuf_t inp = NULL;
121 armor_filter_context_t afx;
122 size_t n=0;
123 int rc = 0;
124 char inf[1024];
125
126 if (!list || !file) {
127 log_debug ("do_list_packets: !list || !file");
128 return -1;
129 }
130
131 inp = gpg_iobuf_open (file);
132 if (!inp) {
133 log_box (_("File Manager"), MB_ERR, "%s: %s", file,
134 winpt_strerror (WPTERR_FILE_OPEN));
135 return -1;
136 }
137 gpg_iobuf_ioctl( inp, 3, 1, NULL ); /* disable cache */
138 if (gpg_use_armor_filter (inp)) {
139 memset (&afx, 0, sizeof (afx));
140 gpg_iobuf_push_filter (inp, gpg_armor_filter, &afx);
141 }
142 pkt = (PACKET *)calloc(1, sizeof *pkt);
143 gpg_init_packet (pkt);
144 while ((rc = gpg_parse_packet (inp, pkt)) != -1) {
145 switch (pkt->pkttype) {
146 case PKT_PUBKEY_ENC:
147 {PKT_pubkey_enc *enc = pkt->pkt.pubkey_enc; n++;
148 if (!enc)
149 break;
150 _snprintf( inf, sizeof(inf)-1,
151 "public key encryted packet: version %d, algo %s, keyid 0x%08X",
152 enc->version, get_pubkey_algo(enc->pubkey_algo), enc->keyid[1]);
153 listbox_add_string (list, inf);}
154 break;
155
156 case PKT_SYMKEY_ENC:
157 {PKT_symkey_enc *enc = pkt->pkt.symkey_enc; n++;
158 if (!enc)
159 break;
160 _snprintf( inf, sizeof(inf)-1,
161 "symmetric key encrypted packet: version %d, cipher %s, s2k %d, hash %s",
162 enc->version, get_symkey_algo(enc->cipher_algo),
163 enc->s2k.mode, get_digest_algo(enc->s2k.hash_algo) );
164 listbox_add_string( list, inf ); }
165 break;
166
167 case PKT_ENCRYPTED:
168 case PKT_ENCRYPTED_MDC:
169 {PKT_encrypted *enc = pkt->pkt.encrypted; n++;
170 if (!enc)
171 break;
172 _snprintf( inf, sizeof(inf)-1,
173 "encrypted data packet: mdc method %d, length %d",
174 enc->mdc_method, enc->len );
175 listbox_add_string( list, inf ); }
176 break;
177
178 case PKT_PUBLIC_KEY:
179 case PKT_PUBLIC_SUBKEY:
180 {PKT_public_key *pk = pkt->pkt.public_key; n++;
181 if (!pk)
182 break;
183 _snprintf( inf, sizeof(inf)-1,
184 "public key packet: version %d, algo %s, created %s",
185 pk->version, get_pubkey_algo(pk->pubkey_algo),
186 get_timestring(pk->timestamp));
187 listbox_add_string( list, inf ); }
188 break;
189
190 case PKT_SECRET_KEY:
191 case PKT_SECRET_SUBKEY:
192 {PKT_secret_key *sk = pkt->pkt.secret_key; n++;
193 if (!sk)
194 break;
195 _snprintf( inf, sizeof(inf)-1,
196 "secret key packet: version %d, algo %s, created %s mode %d",
197 sk->version, get_pubkey_algo( sk->pubkey_algo ),
198 get_timestring( sk->timestamp ),
199 sk->protect.s2k.mode );
200 listbox_add_string( list, inf ); }
201 break;
202
203
204 case PKT_SIGNATURE:
205 {PKT_signature *sig = pkt->pkt.signature; n++;
206 if (!sig)
207 break;
208 _snprintf( inf, sizeof(inf)-1,
209 "signature packet: version %d, algo %s, keyid 0x%08X, created %s",
210 sig->version, get_pubkey_algo(sig->pubkey_algo), sig->keyid[1],
211 get_timestring(sig->timestamp));
212 listbox_add_string( list, inf ); }
213 break;
214
215
216 case PKT_USER_ID:
217 {PKT_user_id *id = pkt->pkt.user_id; n++;
218 if (!id)
219 break;
220 _snprintf( inf, sizeof(inf)-1, "user id packet: %s", id->name );
221 listbox_add_string( list, inf ); }
222 break;
223
224 case PKT_COMPRESSED:
225 {PKT_compressed *zip = pkt->pkt.compressed; n++;
226 if (!zip)
227 break;
228 _snprintf( inf, sizeof(inf)-1, "compressed packet: algo %s, length %d",
229 get_compress_algo(zip->algorithm), zip->len );
230 listbox_add_string( list, inf ); }
231 break;
232 }
233 gpg_free_packet (pkt);
234 gpg_init_packet (pkt);
235 }
236 gpg_iobuf_close (inp);
237 safe_free (pkt);
238 return n;
239 }
240
241
242 /* Dialog box procedure for showing file status. */
243 BOOL CALLBACK
244 file_stat_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
245 {
246 const char *file;
247 int n;
248
249 switch (msg) {
250 case WM_INITDIALOG:
251 #ifndef LANG_DE
252 SetWindowText (dlg, _("File Status"));
253 #endif
254 file = (const char*)lparam;
255 if (file == NULL)
256 dlg_fatal_error( dlg, "Could not get dialog state!" );
257 n = do_list_packets (GetDlgItem (dlg, IDC_FILE_STAT_LIST), file);
258 if (n < 1) {
259 msg_box (dlg, _("No valid OpenPGP data found."), _("File Status"), MB_ERR);
260 EndDialog (dlg, FALSE);
261 }
262 SetForegroundWindow (dlg);
263 break;
264
265 case WM_SYSCOMMAND:
266 if (LOWORD (wparam) == SC_CLOSE)
267 EndDialog (dlg, TRUE);
268 return TRUE;
269
270 case WM_COMMAND:
271 switch (LOWORD (wparam)) {
272 case IDOK:
273 EndDialog (dlg, TRUE);
274 break;
275 }
276 break;
277 }
278
279 return FALSE;
280 }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26