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

Diff of /trunk/Src/wptVerifyList.cpp

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

revision 19 by twoaday, Fri May 20 08:39:15 2005 UTC revision 32 by twoaday, Mon Oct 24 08:03:48 2005 UTC
# Line 1  Line 1 
1  /* wptVerifyList.cpp - Listview for verifying signatures  /* wptVerifyList.cpp - Listview for verifying signatures
2   *      Copyright (C) 2001, 2002, 2003, 2005 Timo Schulz   *      Copyright (C) 2001, 2002, 2003, 2005 Timo Schulz
3     *      Copyright (C) 2005 g10 Code GmbH
4   *   *
5   * This file is part of WinPT.   * This file is part of WinPT.
6   *   *
# Line 17  Line 18 
18   * along with WinPT; if not, write to the Free Software Foundation,   * along with WinPT; if not, write to the Free Software Foundation,
19   * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA   * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20   */   */
 /* x-todo-status: OK */  
   
21  #include <windows.h>  #include <windows.h>
22  #include <time.h>  #include <time.h>
23    
# Line 32  Line 31 
31  #include "wptW32API.h"  #include "wptW32API.h"
32    
33    
34  static char *  /* Extract the file name part out of the given path in @path.
35  extract_filename( const char * path )     Return value: file part or NULL on error. */
36    static char*
37    extract_filename (const char *path)
38  {  {
39      char * fname, * p;      char * fname, *p;
40      int n, len = 0;      int n, len = 0;
41    
42      p = strrchr( path, '\\' );      p = strrchr (path, '\\');
43      if( !p )      if (!p)
44          return m_strdup( path );          return m_strdup (path);
45      n = p - path;      n = p - path;
46      len = strlen( path ) - n;      len = strlen (path) - n;
47      fname = new char[len+1];      fname = new char[len+1];
48      if( !fname )      if (!fname)
49          BUG( NULL );              BUG (NULL);
50      memcpy( fname, path+n+1, len );      memcpy (fname, path+n+1, len);
51      fname[len] = '\0';      fname[len] = '\0';
52      return fname;      return fname;
53  } /* extract_filename */  }
54    
55    
56    /* String representaton of the time in @timestamp.
57       Format YEAR-MON-DAY HOUR:MIN:SEC.
58       Return value: time as formatted string. */
59  const char *  const char *
60  strtimestamp( long timestamp )  strtimestamp (long timestamp)
61  {  {
62      static char timebuf[64] = {0};      static char timebuf[64] = {0};
63      struct tm * warp;      struct tm *warp;
64            
65      warp = localtime( &timestamp );      warp = localtime (&timestamp);
66      _snprintf( timebuf, sizeof timebuf - 1, "%04d-%02d-%02d %02d:%02d:%02d",      _snprintf (timebuf, sizeof timebuf - 1, "%04d-%02d-%02d %02d:%02d:%02d",
67                 warp->tm_year+1900, warp->tm_mon+1, warp->tm_mday,                       warp->tm_year+1900, warp->tm_mon+1, warp->tm_mday,      
68                 warp->tm_hour, warp->tm_min, warp->tm_sec );                 warp->tm_hour, warp->tm_min, warp->tm_sec);
69      return timebuf;      return timebuf;
70  } /* strtimestamp */  }
71    
72    
73    /* Map the signature summary in @sum to signature status table index.
74       Return value: index to table. */
75    int
76    sigsum_to_index (gpgme_sigsum_t sum)
77    {
78        if ((sum & GPGME_SIGSUM_VALID) && (sum & GPGME_SIGSUM_KEY_REVOKED))
79            return 7;
80        if ((sum & GPGME_SIGSUM_VALID) && (sum & GPGME_SIGSUM_SIG_EXPIRED))
81            return 6;
82        if (sum & GPGME_SIGSUM_GREEN)
83            return 1;
84        else if (sum & GPGME_SIGSUM_RED)
85            return 2;
86        else if (sum & GPGME_SIGSUM_KEY_MISSING)
87            return 3;
88        return 0;
89    }
90    
91    
92    /* Build a verify signature list control. With the parent window
93       from @ctrl and the mod given in @fm_mode. @lv contains the
94       new control on success.
95       Return value: 0 on success. */
96  int  int
97  verlist_build (listview_ctrl_t * lv, HWND ctrl, int fm_mode)  verlist_build (listview_ctrl_t *lv, HWND ctrl, int fm_mode)
98  {  {
99      int j, rc = 0;      int j, rc = 0;
100      struct listview_ctrl_s * c;      struct listview_ctrl_s * c;
# Line 77  verlist_build (listview_ctrl_t * lv, HWN Line 104  verlist_build (listview_ctrl_t * lv, HWN
104          {2, 115, (char *)_("Signed") },          {2, 115, (char *)_("Signed") },
105          {3,  58, (char *)_("Trust") },                    {3,  58, (char *)_("Trust") },          
106          {4, 160, (char *)_("User ID") },          {4, 160, (char *)_("User ID") },
107          {5, 0, NULL }          {5, 0, NULL}
108                    
109      };      };
110      struct listview_column_s verlist[] = {            struct listview_column_s verlist[] = {      
# Line 85  verlist_build (listview_ctrl_t * lv, HWN Line 112  verlist_build (listview_ctrl_t * lv, HWN
112          {1, 120, (char *)_("Signed") },          {1, 120, (char *)_("Signed") },
113          {2,  58, (char *)_("Trust") },          {2,  58, (char *)_("Trust") },
114          {3,  80, (char *)_("Key ID" )},          {3,  80, (char *)_("Key ID" )},
115          {4, 160, (char *)_("User ID") },                  {4, 160, (char *)_("User ID") },
116          {5, 0, NULL }            {5, 0, NULL}
117      };      };
118            
119      rc = listview_new( &c );      rc = listview_new (&c);
120      if( rc )      if (rc)
121          return rc;          return rc;
122            
123      c->ctrl = ctrl;      c->ctrl = ctrl;
# Line 105  verlist_build (listview_ctrl_t * lv, HWN Line 132  verlist_build (listview_ctrl_t * lv, HWN
132      listview_set_ext_style( c );      listview_set_ext_style( c );
133      *lv = c;      *lv = c;
134      return 0;      return 0;
135  } /* verlist_build */  }
136    
137    
138    /* Delete the given verify control in @lv. */
139  void  void
140  verlist_delete( listview_ctrl_t lv )  verlist_delete (listview_ctrl_t lv)
141  {  {
142      if( lv ) {      if (lv) {
143          listview_release( lv );          listview_release (lv);  
144      }      }
145  } /* verlist_delete */  }
146    
147    
148    /* Add the given signature in @sig to the verify control @lv.
149       Return value: 0 on success. */
150  int  int
151  verlist_add_sig( listview_ctrl_t lv, gpgme_sig_t sig )  verlist_add_sig (listview_ctrl_t lv, gpgme_signature_t sig)
152  {  {
153      gpgme_key_t key;      gpgme_key_t key = NULL;
154      const char * attr;      const char * attr;
155      u32 key_attr, t;      u32 key_attr;
156      char keyid[32+1];      char keyid[32+1];
157      char * uid = NULL;      char * uid = NULL;
158            
159      if( listview_add_item( lv, " " ) )      if (listview_add_item (lv, " "))
160          return WPTERR_GENERAL;          return WPTERR_GENERAL;
161            
162      if( !gpgme_sig_get_ulong_attr( sig, 0, GPGME_ATTR_TYPE ) )      get_pubkey (sig->fpr, &key);
         return WPTERR_GENERAL; /* No key was stored */  
163            
164      t = gpgme_sig_get_ulong_attr( sig, 0, GPGME_ATTR_VALIDITY );      attr = get_gpg_sigstat (sig->summary);
     attr = gpg_sigstat[t % SIGSTAT_MASK];  
165      if( attr )      if( attr )
166          listview_add_sub_item( lv, 0, 0, (char *)attr );          listview_add_sub_item (lv, 0, 0, (char *)attr);
167            
168      t = gpgme_sig_get_ulong_attr( sig, 0, GPGME_ATTR_CREATED );      attr = strtimestamp (sig->timestamp);
169      attr = strtimestamp( t );      listview_add_sub_item (lv, 0, 1, (char *)attr);
     if( attr )  
         listview_add_sub_item( lv, 0, 1, (char *)attr );  
170            
171      t = gpgme_sig_get_ulong_attr( sig, 0, GPGME_ATTR_TYPE );      attr = _("Unknown");
172      key = (gpgme_key_t)t;      if (key) {
173      key_attr = gpgme_key_get_ulong_attr( key, GPGME_ATTR_VALIDITY, NULL, 0 );          key_attr = key->uids->validity;
174      attr = gpgme_key_expand_attr( GPGME_ATTR_VALIDITY, key_attr );          attr = get_key_trust2 (NULL, key_attr, 0, 0);
175      if( attr )      }
176          listview_add_sub_item( lv, 0, 2, (char *)attr );      listview_add_sub_item (lv, 0, 2, (char *)attr);
177            
178      attr = gpgme_key_get_string_attr( key, GPGME_ATTR_KEYID, NULL, 0 );      attr = sig->fpr;
179      if ( !attr || strlen( attr ) < 8 )      if (!attr || strlen (attr) < 8)
180          attr = "DEADBEEFDEADBEEF";          listview_add_sub_item (lv, 0, 3, "????????");
181      _snprintf( keyid, sizeof keyid -1, "0x%s", attr + 8 );      else {
182      listview_add_sub_item( lv, 0, 3, keyid );          if (strlen (attr) == 40)
183                attr += 32;
184            else
185                attr += 24;
186            _snprintf (keyid, sizeof keyid -1, "0x%s", attr);
187            listview_add_sub_item (lv, 0, 3, keyid);
188        }
189            
190      attr = gpgme_key_get_string_attr( key, GPGME_ATTR_NAME, NULL, 0 );      if (!key) {
     if( !attr ) {  
191          attr = _("Invalid User ID");          attr = _("Invalid User ID");
192          listview_add_sub_item( lv, 0, 4, (char *)attr );          listview_add_sub_item( lv, 0, 4, (char *)attr );
193      }        }
194      else {      else {
195            attr = key->uids->name;
196          uid = utf8_to_wincp (attr, strlen (attr));          uid = utf8_to_wincp (attr, strlen (attr));
197          if ( uid ) {          if (uid) {
198              listview_add_sub_item( lv, 0, 4, (char *)uid );              listview_add_sub_item( lv, 0, 4, (char *)uid );
199              free( uid );              free (uid);
200          }          }
201      }      }
202        
203      return 0;      return 0;
204  } /* verlist_add_sig */  }
205    
206    
207    /* Add the given file signature in @log to the verify control @lv.
208       Return value: 0 on success. */
209  int  int
210  verlist_add_sig_log( listview_ctrl_t lv, siglog_context_t log )  verlist_add_sig_log (listview_ctrl_t lv, file_sig_ctx_t log)
211  {  {
212      gpgme_sig_t sig = log->sig;      gpgme_signature_t sig = log->sig;
213      const char * attr;          gpgme_key_t key = NULL;
214      char t[64], * name;      const char *attr;    
215      u32 i_attr;      char t[64], *name;
216    
217      if( listview_add_item( lv, "" ) )      if (listview_add_item (lv, ""))
218          return WPTERR_GENERAL;          return WPTERR_GENERAL;
       
     name = extract_filename( log->file );  
     if( name )  
         listview_add_sub_item( lv, 0, 0, name );  
     free_if_alloc( name );  
       
     i_attr = gpgme_sig_get_ulong_attr( sig, 0, GPGME_ATTR_VALIDITY );  
     attr = gpg_sigstat[i_attr % SIGSTAT_MASK];  
     if( attr )  
         listview_add_sub_item( lv, 0, 1, attr );  
219    
220      attr = strtimestamp( gpgme_sig_get_ulong_attr( sig, 0, GPGME_ATTR_CREATED ) );      get_pubkey (sig->fpr, &key);
     if( attr )  
         listview_add_sub_item( lv, 0, 2, attr );  
221            
222      attr = gpgme_key_expand_attr( GPGME_ATTR_VALIDITY,      name = extract_filename (log->file);
223                                    gpgme_sig_get_ulong_attr( sig, 0, GPGME_ATTR_OTRUST ) );      if (name)
224      if( attr )          listview_add_sub_item (lv, 0, 0, name);
225          listview_add_sub_item( lv, 0, 3, attr );      else
226            listview_add_sub_item (lv, 0, 0, log->file);
227        free_if_alloc (name);
228        
229        attr = get_gpg_sigstat (sig->summary);
230        if (attr)
231            listview_add_sub_item (lv, 0, 1, attr);
232    
233        if (sig->timestamp > 0) {
234            attr = strtimestamp (sig->timestamp);
235            listview_add_sub_item (lv, 0, 2, attr);
236        }
237        else
238            listview_add_sub_item (lv, 0, 2, "No time");
239            
240      attr = gpgme_sig_get_string_attr( sig, GPGME_ATTR_KEYID );      attr = _("Unknown");
241      if( !log->use_uid && strlen( attr ) == 16 ) {      if (key)
242          _snprintf( t, sizeof t-1, "0x%s", attr + 8 );          attr = get_key_trust2 (NULL, key->uids->validity, 0, 0);
243          listview_add_sub_item( lv, 0, 4, t );      listview_add_sub_item (lv, 0, 3, attr);
244      }      
245      else if( !log->use_uid && strlen( attr ) == 8 ) {      attr = sig->fpr;
246          _snprintf( t, sizeof t-1, "0x%s", attr );      if (!log->use_uid && strlen (attr) == 40) {
247          listview_add_sub_item( lv, 0, 4, t );          _snprintf (t, sizeof (t)-1, "0x%s", attr + 32);
248      }          listview_add_sub_item (lv, 0, 4, t);
249      else if( log->user_id ) {      }
250          char * p = utf8_to_wincp (log->user_id, strlen (log->user_id));      else if( !log->use_uid && strlen( attr ) == 32 ) {
251          if( p ) {          _snprintf (t, sizeof (t)-1, "0x%s", attr + 24);
252              listview_add_sub_item( lv, 0, 4, p );          listview_add_sub_item (lv, 0, 4, t);
253              free( p );      }
254        else if (log->user_id) {
255            char *p = utf8_to_wincp (log->user_id, strlen (log->user_id));
256            if (p) {
257                listview_add_sub_item (lv, 0, 4, p);
258                free (p);
259          }          }
260      }      }
261      return 0;      return 0;
262  } /* verlist_add_sig_log */  }

Legend:
Removed from v.19  
changed lines
  Added in v.32

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26