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

Contents of /trunk/Src/wptFileStatDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 328 - (show annotations)
Fri Sep 25 16:07:38 2009 UTC (15 years, 5 months ago) by twoaday
File size: 7480 byte(s)


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

Properties

Name Value
svn:eol-style native

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26