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

Contents of /trunk/Src/wptFileStatDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 271 - (show annotations)
Sun Nov 5 08:57:45 2006 UTC (18 years, 3 months ago) by twoaday
File size: 7482 byte(s)


1 /* wptFileStatDlg.cpp - List the status of an OpenPGP file
2 * Copyright (C) 2002, 2003, 2005, 2006 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 #ifdef HAVE_CONFIG_H
21 #include <config.h>
22 #endif
23
24 #include <windows.h>
25 #include <time.h>
26 #include <sys/types.h>
27
28 #include "resource.h"
29 #include "wptTypes.h"
30 #include "wptGPG.h"
31 #include "wptCommonCtl.h"
32 #include "wptContext.h"
33 #include "wptErrors.h"
34 #include "wptW32API.h"
35 #include "wptUTF8.h"
36 #include "openpgp.h"
37
38 /* Make sure that the list won't consume too much memory. */
39 #define MAX_PKTS 1024
40
41 /* Return the date in locale format. */
42 const char*
43 get_fmt_date (long timest)
44 {
45 static char buf[64];
46
47 get_locale_date (timest, buf, DIM (buf)-1);
48 return buf;
49 }
50
51
52 /* Return humand readable public key algo. */
53 static const char*
54 get_pubkey_algo (int algo)
55 {
56 if (algo == 17)
57 return "DSA";
58 else if (is_ELGAMAL (algo))
59 return "ELG";
60 else if (is_RSA (algo))
61 return "RSA";
62 return NULL;
63 }
64
65
66 /* Return human readable symmetric algo. */
67 const char*
68 get_symkey_algo (int algo)
69 {
70 switch (algo) {
71 case 0: return "PLAINTEXT";
72 case 1: return "IDEA";
73 case 2: return "3DES";
74 case 3: return "CAST5";
75 case 4: return "BLOWFISH";
76 case 7: return "AES128";
77 case 8: return "AES192";
78 case 9: return "AES256";
79 default: break;
80 }
81 return "UNKNOWN";
82 }
83
84
85 /* Return human readable hash algo. */
86 static const char*
87 get_digest_algo (int algo)
88 {
89 switch (algo) {
90 case 0: return "NONE";
91 case 1: return "MD5";
92 case 2: return "SHA1";
93 case 3: return "RMD160";
94 case 5: return "MD2";
95 case 8: return "SHA256";
96 case 9: return "SHA384";
97 case 10:return "SHA512";
98 default: break;
99 }
100 return "UNKNOWN";
101 }
102
103
104 /* Return human readable compress algo. */
105 static const char*
106 get_compress_algo (int algo)
107 {
108 switch (algo) {
109 case 0: return "NONE";
110 case 1: return "ZIB";
111 case 2: return "ZLIB";
112 case 3: return "BZIP2";
113 default: break;
114 }
115 return "UNKNOWN";
116 }
117
118
119 /* Return human string to key algo. */
120 static const char*
121 get_s2k_algo (int algo)
122 {
123 switch (algo) {
124 case 0: return "SIMPLE";
125 case 1: return "SALTED";
126 case 3: return "ITER+SALTED";
127 default:break;
128 }
129 return "INVALID";
130 }
131
132
133 /* List all OpenPGP packets from the file @file.
134 Return value: number of packets. */
135 static int
136 do_list_packets (HWND list, const char *file)
137 {
138 PACKET *pkt;
139 gpg_iobuf_t inp = NULL;
140 armor_filter_context_t afx;
141 size_t n=0;
142 int rc = 0;
143 char inf[1024], *p;
144
145 if (!list || !file) {
146 log_debug ("do_list_packets: invalid parameters\n");
147 return -1;
148 }
149
150 inp = gpg_iobuf_open (file);
151 if (!inp) {
152 log_box (_("File Manager"), MB_ERR, "%s: %s", file,
153 winpt_strerror (WPTERR_FILE_OPEN));
154 return -1;
155 }
156 gpg_iobuf_ioctl (inp, 3, 1, NULL); /* disable cache */
157 if (gpg_use_armor_filter (inp)) {
158 memset (&afx, 0, sizeof (afx));
159 gpg_iobuf_push_filter (inp, gpg_armor_filter, &afx);
160 }
161 pkt = (PACKET *)calloc(1, sizeof *pkt);
162 gpg_init_packet (pkt);
163 while ((rc = gpg_parse_packet (inp, pkt)) != -1) {
164 switch (pkt->pkttype) {
165 case PKT_PUBKEY_ENC:
166 {PKT_pubkey_enc *enc = pkt->pkt.pubkey_enc; n++;
167 if (!enc)
168 break;
169 _snprintf (inf, DIM(inf)-1,
170 "public key encryted packet: version %d, algo %s, keyid 0x%08X",
171 enc->version, get_pubkey_algo(enc->pubkey_algo), enc->keyid[1]);
172 listbox_add_string (list, inf);}
173 break;
174
175 case PKT_SYMKEY_ENC:
176 {PKT_symkey_enc *enc = pkt->pkt.symkey_enc; n++;
177 if (!enc)
178 break;
179 _snprintf (inf, DIM(inf)-1,
180 "symmetric key encrypted packet: version %d, cipher %s, s2k %s, hash %s",
181 enc->version, get_symkey_algo (enc->cipher_algo),
182 get_s2k_algo (enc->s2k.mode),
183 get_digest_algo (enc->s2k.hash_algo));
184 listbox_add_string (list, inf); }
185 break;
186
187 case PKT_ENCRYPTED:
188 case PKT_ENCRYPTED_MDC:
189 {PKT_encrypted *enc = pkt->pkt.encrypted; n++;
190 if (!enc)
191 break;
192 _snprintf (inf, DIM(inf)-1,
193 "encrypted data packet: mdc method %d, length %d",
194 enc->mdc_method, enc->len);
195 listbox_add_string (list, inf); }
196 break;
197
198 case PKT_PUBLIC_KEY:
199 case PKT_PUBLIC_SUBKEY:
200 {PKT_public_key *pk = pkt->pkt.public_key; n++;
201 if (!pk)
202 break;
203 _snprintf( inf, DIM(inf)-1,
204 "public key packet: version %d, algo %s, created %s",
205 pk->version, get_pubkey_algo (pk->pubkey_algo),
206 get_fmt_date (pk->timestamp));
207 listbox_add_string (list, inf); }
208 break;
209
210 case PKT_SECRET_KEY:
211 case PKT_SECRET_SUBKEY:
212 {PKT_secret_key *sk = pkt->pkt.secret_key; n++;
213 if (!sk)
214 break;
215 _snprintf( inf, DIM(inf)-1,
216 "secret key packet: version %d, algo %s, created %s mode %d",
217 sk->version, get_pubkey_algo (sk->pubkey_algo),
218 get_fmt_date (sk->timestamp),
219 sk->protect.s2k.mode);
220 listbox_add_string (list, inf); }
221 break;
222
223 case PKT_SIGNATURE:
224 {PKT_signature *sig = pkt->pkt.signature; n++;
225 if (!sig)
226 break;
227 _snprintf( inf, DIM(inf)-1,
228 "signature packet: version %d, algo %s, keyid 0x%08X, created %s",
229 sig->version, get_pubkey_algo(sig->pubkey_algo), sig->keyid[1],
230 get_fmt_date (sig->timestamp));
231 listbox_add_string (list, inf); }
232 break;
233
234
235 case PKT_USER_ID:
236 {PKT_user_id *id = pkt->pkt.user_id; n++;
237 if (!id)
238 break;
239 p = utf8_to_native (id->name);
240 _snprintf (inf, DIM (inf)-1, "user id packet: %s", p);
241 free_if_alloc (p);
242 listbox_add_string (list, inf); }
243 break;
244
245 case PKT_COMPRESSED:
246 {PKT_compressed *zip = pkt->pkt.compressed; n++;
247 if (!zip)
248 break;
249 _snprintf (inf, DIM(inf)-1,
250 "compressed packet: algo %s, length %d",
251 get_compress_algo(zip->algorithm), zip->len);
252 listbox_add_string (list, inf); }
253 break;
254
255 default:
256 break;
257 }
258 gpg_free_packet (pkt);
259 gpg_init_packet (pkt);
260 if (n > MAX_PKTS)
261 break;
262 }
263 gpg_iobuf_close (inp);
264 safe_free (pkt);
265 return n;
266 }
267
268
269 /* Dialog box procedure for showing file status. */
270 BOOL CALLBACK
271 file_stat_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
272 {
273 const char *file;
274
275 switch (msg) {
276 case WM_INITDIALOG:
277 file = (const char*)lparam;
278 if (!file)
279 BUG (0);
280 if (do_list_packets (GetDlgItem (dlg, IDC_FILE_STAT_LIST), file) < 1) {
281 msg_box (dlg, _("No valid OpenPGP data found."),
282 _("File Status"), MB_ERR);
283 EndDialog (dlg, FALSE);
284 return TRUE;
285 }
286 SetWindowText (dlg, _("File Status"));
287 SetForegroundWindow (dlg);
288 break;
289
290 case WM_COMMAND:
291 switch (LOWORD (wparam)) {
292 case IDOK:
293 EndDialog (dlg, TRUE);
294 break;
295
296 case IDCANCEL:
297 EndDialog (dlg, FALSE);
298 break;
299 }
300 break;
301 }
302
303 return FALSE;
304 }

Properties

Name Value
svn:eol-style native

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26