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

Annotation of /trunk/Src/wptFileStatDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 22 - (hide annotations)
Wed Aug 10 11:33:35 2005 UTC (19 years, 6 months ago) by twoaday
File size: 7505 byte(s)
2005-08-06  Timo Schulz  <twoaday@freakmail.de>
 
        * wptGPGME.cpp (keycache_update): Reload OpenPGP parts
        of the secret key.
        (keycache_init): cache name of secret keyring.
        * wptKeyList.cpp (keylist_upd_key): Do not add long keyid.
        (get_key_type): Do not assume 'ultimate' means key pair.
        * wptKeyEditDlgs.cpp (diff_time): New.
        (keyedit_addsubkey_dlg_proc): Changed design and use
        diff_time. Drop checks for invalid keylength (< 1024, > 4096)
        because the combo box automatically handles this.
        * wptKeyManager.cpp (km_set_implicit_trust): Return error code.
        * wptGPG.cpp (get_backup_name): New.
        (gnupg_backup_keyrings): Rotate backup names, from 0..3.
        * wptClipImportDialog.cpp (clip_import_dlg_proc): Free memory.
        * wptKeyManagerDlg.cpp (keymanager_dlg_proc): Use 0x short keyid and
        not the long keyid.


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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26