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

Contents of /trunk/Src/wptFileStatDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 25 - (show annotations)
Wed Oct 12 10:04:26 2005 UTC (19 years, 4 months ago) by twoaday
File size: 7500 byte(s)
First testing phase finished.
Provide bug fixes for a lot of (minor) problems.

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26