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

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26