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

Diff of /trunk/Src/wptFileStatDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2 by twoaday, Mon Jan 31 11:02:21 2005 UTC revision 178 by twoaday, Tue Feb 21 12:12:23 2006 UTC
# Line 1  Line 1 
1  /* wptFileStatDlg.cpp - (File Manager) Show file statistics  /* wptFileStatDlg.cpp - (File Manager) Show file statistics
2   *      Copyright (C) 2002, 2003 Timo Schulz   *      Copyright (C) 2002, 2003, 2005 Timo Schulz
3   *   *
4   * This file is part of WinPT.   * This file is part of WinPT.
5   *   *
6   * WinPT is free software; you can redistribute it and/or modify   * 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   * 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   * the Free Software Foundation; either version 2 of the License, or
9   * (at your option) any later version.   * (at your option) any later version.
10   *   *
11   * WinPT is distributed in the hope that it will be useful,   * WinPT is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   * GNU General Public License for more details.   * GNU General Public License for more details.
15   *   *
16   * You should have received a copy of the GNU General Public License   * You should have received a copy of the GNU General Public License
17   * along with WinPT; if not, write to the Free Software Foundation,   * along with WinPT; if not, write to the Free Software Foundation,
18   * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA   * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
19   */   */
20    #ifdef HAVE_CONFIG_H
21  #include <windows.h>  #include <config.h>
22  #include <time.h>  #endif
23  #include <sys/types.h>  
24    #include <windows.h>
25  #include "../resource.h"  #include <time.h>
26  #include "wptTypes.h"  #include <sys/types.h>
27  #include "wptNLS.h"  
28  #include "wptGPG.h"  #include "resource.h"
29  #include "wptCommonCtl.h"  #include "wptTypes.h"
30  #include "wptContext.h"  #include "wptNLS.h"
31  #include "wptDlgs.h"  #include "wptGPG.h"
32  #include "wptErrors.h"  #include "wptCommonCtl.h"
33  #include "wptW32API.h"  #include "wptContext.h"
34  #include "openpgp.h"  #include "wptDlgs.h"
35    #include "wptErrors.h"
36  static const char*  #include "wptW32API.h"
37  get_pubkey_algo( int algo )  #include "openpgp.h"
38  {        
39      if ( algo == 17 )  static const char*
40          return "DSA";    get_pubkey_algo (int algo)
41     else if ( is_ELGAMAL(algo) )  {      
42          return "ELG";        if (algo == 17)
43      else if ( is_RSA(algo) )          return "DSA";  
44          return "RSA";     else if (is_ELGAMAL (algo))
45      return NULL;          return "ELG";  
46  } /* get_algo */      else if (is_RSA (algo))
47            return "RSA";
48  static const char*      return NULL;
49  get_symkey_algo (int algo)  }
50  {  
51      switch (algo)  
52      {  const char*
53      case 0: return "PLAINTEXT";  get_symkey_algo (int algo)
54      case 1: return "IDEA";  {
55      case 2: return "3DES";      switch (algo) {
56      case 3: return "CAST5";      case 0: return "PLAINTEXT";
57      case 4: return "BLOWFISH";      case 1: return "IDEA";
58      case 5: return "RESERVED";      case 2: return "3DES";
59      case 6: return "RESERVED";      case 3: return "CAST5";
60      case 7: return "AES";      case 4: return "BLOWFISH";
61      case 8: return "AES-192";      case 5: return "RESERVED";
62      case 9: return "AES-256";      case 6: return "RESERVED";
63      }          case 7: return "AES";
64      return "UNKNOWN";      case 8: return "AES-192";
65  } /* get_symkey_algo */      case 9: return "AES-256";
66        default: break;
67  static const char*      }    
68  get_digest_algo (int algo)      return "UNKNOWN";
69  {  }
70      switch (algo)  
71      {  
72      case 0: return "NONE";  static const char*
73      case 1: return "MD5";  get_digest_algo (int algo)
74      case 2: return "SHA1";  {
75      case 3: return "RMD160";      switch (algo) {
76      case 4: return "RESERVED";      case 0: return "NONE";
77      case 5: return "MD2";      case 1: return "MD5";
78      case 6: return "RESERVED";      case 2: return "SHA1";
79      case 7: return "RESERVED";      case 3: return "RMD160";
80      }      case 4: return "RESERVED";
81      return "UNKNOWN";      case 5: return "MD2";
82  } /* get_digest_algo */      case 6: return "RESERVED";
83        case 7: return "RESERVED";
84  static const char*      case 8: return "SHA256";
85  get_compress_algo (int algo)      case 9: return "SHA384";
86  {      case 10:return "SHA512";
87      switch (algo)      default: break;
88      {      }
89      case 0: return "NONE";      return "UNKNOWN";
90      case 1: return "ZIB";  }
91      case 2: return "ZLIB";  
92      case 3: return "BZIP2";  
93      }  static const char*
94      return "UNKNOWN";  get_compress_algo (int algo)
95  } /* get_compress_algo */  {
96        switch (algo) {
97        case 0: return "NONE";
98  static const char*      case 1: return "ZIB";
99  get_timestring (long timestamp)      case 2: return "ZLIB";
100  {      case 3: return "BZIP2";
101      static char ts[64];      default: break;
102      struct tm *ltm;      }
103        return "UNKNOWN";
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;  static const char*
108  } /* get_timestring */  get_s2k_algo (int algo)
109    {
110        switch (algo) {
111  static int      case 0: return "SIMPLE";
112  do_list_packets (HWND list, const char *file)      case 1: return "SALTED";
113  {      case 3: return "ITER+SALTED";
114      PACKET *pkt = (PACKET *)calloc( 1, sizeof *pkt );      default:break;
115      gpg_iobuf_t inp = NULL;      }
116      armor_filter_context_t afx;      return "INVALID";
117      int rc = 0;  }
118      char inf[1024];  
119    
120      if( !list || file == NULL ) {  static const char*
121          safe_free( pkt );  get_timestring (long timestamp)
122          return -1;  {
123      }      static char ts[64];
124        struct tm *ltm;
125      inp = gpg_iobuf_open( file );  
126      if( inp == NULL ) {      ltm = localtime (&timestamp);
127          log_box( _("File Manager"), MB_ERR, "%s: %s", file,      _snprintf(ts, sizeof ts -1, "%04d-%02d-%02d",
128                   winpt_strerror( WPTERR_FILE_OPEN ) );                  ltm->tm_year + 1900, ltm->tm_mon + 1, ltm->tm_mday);
129          safe_free( pkt );      return ts;
130          return -1;  }
131      }  
132      gpg_iobuf_ioctl( inp, 3, 1, NULL ); /* disable cache */  
133      if( gpg_use_armor_filter( inp ) ) {  /* List all PGP packets from the file @file.
134          memset( &afx, 0, sizeof afx );     Return value: number of packets. */
135          gpg_iobuf_push_filter( inp, gpg_armor_filter, &afx );  static int
136      }    do_list_packets (HWND list, const char *file)
137      gpg_init_packet( pkt );  {
138      while ( (rc = gpg_parse_packet( inp, pkt )) != -1 ) {      PACKET *pkt;
139          switch ( pkt->pkttype ) {            gpg_iobuf_t inp = NULL;
140          case PKT_PUBKEY_ENC:      armor_filter_context_t afx;
141              {PKT_pubkey_enc *enc = pkt->pkt.pubkey_enc;      size_t n=0;
142              if (!enc)      int rc = 0;
143                  break;      char inf[1024];
144              _snprintf( inf, sizeof(inf)-1,        
145                  "public key encryted packet: version %d, algo %s, keyid 0x%08X",                      if (!list || !file) {
146                  enc->version, get_pubkey_algo(enc->pubkey_algo), enc->keyid[1]);          log_debug ("do_list_packets: !list || !file");
147              listbox_add_string( list, inf );}          return -1;
148              break;      }
149                    
150          case PKT_SYMKEY_ENC:      inp = gpg_iobuf_open (file);
151              {PKT_symkey_enc *enc = pkt->pkt.symkey_enc;      if (!inp) {
152              if (!enc)          log_box (_("File Manager"), MB_ERR, "%s: %s", file,
153                  break;                   winpt_strerror (WPTERR_FILE_OPEN));
154              _snprintf( inf, sizeof(inf)-1,                return -1;
155                  "symmetric key encrypted packet: version %d, cipher %s, s2k %d, hash %s",                    }
156                  enc->version, get_symkey_algo(enc->cipher_algo),                      gpg_iobuf_ioctl( inp, 3, 1, NULL ); /* disable cache */
157                  enc->s2k.mode, get_digest_algo(enc->s2k.hash_algo) );      if (gpg_use_armor_filter (inp)) {
158              listbox_add_string( list, inf ); }          memset (&afx, 0, sizeof (afx));
159              break;          gpg_iobuf_push_filter (inp, gpg_armor_filter, &afx);
160        }
161          case PKT_ENCRYPTED:          pkt = (PACKET *)calloc(1, sizeof *pkt);
162          case PKT_ENCRYPTED_MDC:      gpg_init_packet (pkt);
163              {PKT_encrypted *enc = pkt->pkt.encrypted;      while ((rc = gpg_parse_packet (inp, pkt)) != -1) {
164              if (!enc)          switch (pkt->pkttype) {
165                  break;          case PKT_PUBKEY_ENC:
166              _snprintf( inf, sizeof(inf)-1,                    {PKT_pubkey_enc *enc = pkt->pkt.pubkey_enc; n++;
167                  "encrypted data packet: mdc method %d, length %d",                            if (!enc)
168                  enc->mdc_method, enc->len );                  break;
169              listbox_add_string( list, inf ); }              _snprintf( inf, sizeof(inf)-1,      
170              break;                  "public key encryted packet: version %d, algo %s, keyid 0x%08X",
171                    enc->version, get_pubkey_algo(enc->pubkey_algo), enc->keyid[1]);
172          case PKT_PUBLIC_KEY:              listbox_add_string (list, inf);}
173          case PKT_PUBLIC_SUBKEY:              break;
174              {PKT_public_key *pk = pkt->pkt.public_key;                  
175              if (!pk)          case PKT_SYMKEY_ENC:
176                  break;              {PKT_symkey_enc *enc = pkt->pkt.symkey_enc; n++;
177              _snprintf( inf, sizeof(inf)-1,              if (!enc)
178                  "public key packet: version %d, algo %s, created %s",                  break;
179                  pk->version, get_pubkey_algo(pk->pubkey_algo),              _snprintf (inf, sizeof(inf)-1,
180                  get_timestring(pk->timestamp));                  "symmetric key encrypted packet: version %d, cipher %s, s2k %s, hash %s",
181              listbox_add_string( list, inf ); }                  enc->version, get_symkey_algo(enc->cipher_algo),                
182              break;                  get_s2k_algo (enc->s2k.mode), get_digest_algo(enc->s2k.hash_algo));
183                listbox_add_string (list, inf); }
184          case PKT_SECRET_KEY:              break;
185          case PKT_SECRET_SUBKEY:      
186              {PKT_secret_key *sk = pkt->pkt.secret_key;          case PKT_ENCRYPTED:    
187              if (!sk)          case PKT_ENCRYPTED_MDC:
188                  break;              {PKT_encrypted *enc = pkt->pkt.encrypted; n++;
189              _snprintf( inf, sizeof(inf)-1,              if (!enc)
190                  "secret key packet: version %d, algo %s, created %s mode %d",                  break;
191                  sk->version,  get_pubkey_algo( sk->pubkey_algo ),              _snprintf( inf, sizeof(inf)-1,      
192                  get_timestring( sk->timestamp ),                  "encrypted data packet: mdc method %d, length %d",              
193                  sk->protect.s2k.mode );                  enc->mdc_method, enc->len );
194              listbox_add_string( list, inf ); }              listbox_add_string( list, inf ); }
195              break;              break;
196    
197                            case PKT_PUBLIC_KEY:
198          case PKT_SIGNATURE:          case PKT_PUBLIC_SUBKEY:
199              {PKT_signature *sig = pkt->pkt.signature;              {PKT_public_key *pk = pkt->pkt.public_key; n++;
200              if (!sig)              if (!pk)
201                  break;                  break;
202              _snprintf( inf, sizeof(inf)-1,              _snprintf( inf, sizeof(inf)-1,
203                  "signature packet: version %d, algo %s, keyid 0x%08X, created %s",                  "public key packet: version %d, algo %s, created %s",
204                  sig->version, get_pubkey_algo(sig->pubkey_algo), sig->keyid[1],                  pk->version, get_pubkey_algo(pk->pubkey_algo),
205                  get_timestring(sig->timestamp));                  get_timestring(pk->timestamp));
206              listbox_add_string( list, inf ); }              listbox_add_string( list, inf ); }
207              break;              break;
208    
209                            case PKT_SECRET_KEY:
210          case PKT_USER_ID:          case PKT_SECRET_SUBKEY:    
211              {PKT_user_id *id = pkt->pkt.user_id;              {PKT_secret_key *sk = pkt->pkt.secret_key; n++;
212              if (!id)              if (!sk)
213                  break;                  break;
214              _snprintf( inf, sizeof(inf)-1, "user id packet: %s", id->name );              _snprintf( inf, sizeof(inf)-1,
215              listbox_add_string( list, inf ); }                  "secret key packet: version %d, algo %s, created %s mode %d",
216              break;                  sk->version,  get_pubkey_algo( sk->pubkey_algo ),
217                                get_timestring( sk->timestamp ),
218          case PKT_COMPRESSED:                  sk->protect.s2k.mode );
219              {PKT_compressed *zip = pkt->pkt.compressed;              listbox_add_string( list, inf ); }
220              if (!zip)              break;
221                  break;  
222              _snprintf( inf, sizeof(inf)-1, "compressed packet: algo %s, length %d",                  
223                  get_compress_algo(zip->algorithm), zip->len );          case PKT_SIGNATURE:
224              listbox_add_string( list, inf ); }              {PKT_signature *sig = pkt->pkt.signature; n++;
225              break;              if (!sig)
226          }                  break;
227          gpg_free_packet( pkt );              _snprintf( inf, sizeof(inf)-1,
228          gpg_init_packet( pkt );                  "signature packet: version %d, algo %s, keyid 0x%08X, created %s",
229      }                  sig->version, get_pubkey_algo(sig->pubkey_algo), sig->keyid[1],
230      gpg_iobuf_close( inp );                  get_timestring(sig->timestamp));
231      safe_free( pkt );              listbox_add_string( list, inf ); }
232      return rc;              break;
233  } /* do_list_packets */  
234                    
235            case PKT_USER_ID:
236  BOOL CALLBACK              {PKT_user_id *id = pkt->pkt.user_id; n++;
237  file_stat_dlg_proc( HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam )              if (!id)
238  {                  break;
239      const char *file;              _snprintf( inf, sizeof(inf)-1, "user id packet: %s", id->name );
240                    listbox_add_string( list, inf ); }
241      switch ( msg ) {              break;
242      case WM_INITDIALOG:              
243          #ifndef LANG_DE          case PKT_COMPRESSED:
244          SetWindowText( dlg, _("File Status") );              {PKT_compressed *zip = pkt->pkt.compressed; n++;
245          #endif              if (!zip)
246          file = (const char*)lparam;                  break;
247          if( file == NULL )              _snprintf( inf, sizeof(inf)-1, "compressed packet: algo %s, length %d",
248              dlg_fatal_error( dlg, "Could not get dialog state!" );                  get_compress_algo(zip->algorithm), zip->len );
249          do_list_packets( GetDlgItem( dlg, IDC_FILE_STAT_LIST ), file );              listbox_add_string( list, inf ); }
250          SetForegroundWindow( dlg );              break;
251          break;  
252                    default:
253      case WM_SYSCOMMAND:              break;
254          if( LOWORD( wparam ) == SC_CLOSE )          }
255              EndDialog( dlg, TRUE );          gpg_free_packet (pkt);
256          return FALSE;          gpg_init_packet (pkt);
257                }
258      case WM_COMMAND:      gpg_iobuf_close (inp);
259          switch( LOWORD( wparam ) ) {      safe_free (pkt);
260          case IDOK:      return n;
261              EndDialog( dlg, TRUE );  }
262              break;  
263          }  
264          break;  /* Dialog box procedure for showing file status. */
265      }  BOOL CALLBACK
266        file_stat_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
267      return FALSE;  {
268  } /* file_stat_dlg_proc */      const char *file;
269        int n;
270        
271        switch (msg) {
272        case WM_INITDIALOG:
273            #ifndef LANG_DE
274            SetWindowText (dlg, _("File Status"));
275            #endif
276            file = (const char*)lparam;
277            if (file == NULL)
278                dlg_fatal_error( dlg, "Could not get dialog state!" );
279            n = do_list_packets (GetDlgItem (dlg, IDC_FILE_STAT_LIST), file);
280            if (n < 1) {
281                msg_box (dlg, _("No valid OpenPGP data found."), _("File Status"), MB_ERR);
282                EndDialog (dlg, FALSE);
283            }
284            SetForegroundWindow (dlg);
285            break;
286            
287        case WM_SYSCOMMAND:
288            if (LOWORD (wparam) == SC_CLOSE)
289                EndDialog (dlg, TRUE);
290            return TRUE;
291            
292        case WM_COMMAND:
293            switch (LOWORD (wparam)) {
294            case IDOK:
295                EndDialog (dlg, TRUE);
296                break;
297            }
298            break;
299        }
300        
301        return FALSE;
302    }

Legend:
Removed from v.2  
changed lines
  Added in v.178

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26