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

Annotation of /trunk/Src/wptFileStatDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


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

Properties

Name Value
svn:eol-style native

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26