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

Legend:
Removed from v.25  
changed lines
  Added in v.328

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26