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

Annotation of /trunk/Src/wptFileStatDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 32 - (hide annotations)
Mon Oct 24 08:03:48 2005 UTC (19 years, 4 months ago) by twoaday
File size: 7462 byte(s)
2005-10-23  Timo Schulz  <twoaday@g10code.com>
 
        * wptFileManager.cpp (fm_get_file_type): Detect detached sigs.
        * wptKeyList.cpp (keylist_cmp_cb): Take care of expired/revoked keys.
        (get_ext_validity): New.
        * wptFileVerifyDlg.cpp (file_verify_dlg_proc): Several cleanups.
        * wptClipEditDlg.cpp (load_clipboard): Factored out some code into
        this function.
        (load_clipboard_from_file): Likewise.
        (save_clipboard_to_file): New.
        * wptKeyManagerDlg.cpp (keyprops_dlg_proc): Fix stack overflow.

For complete details, see the ChangeLog files.

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26