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

Annotation of /trunk/Src/wptFileStatDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 256 - (hide annotations)
Sat Aug 5 10:31:06 2006 UTC (18 years, 6 months ago) by twoaday
File size: 7554 byte(s)
1.0.0pre3 release.


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

Properties

Name Value
svn:eol-style native

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26