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