/[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 23 by twoaday, Fri Sep 30 10:10:16 2005 UTC revision 36 by werner, Thu Oct 27 15:25:13 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   * This file is part of WinPT.   *
5   *   * This file is part of WinPT.
6   * WinPT is free software; you can redistribute it and/or   *
7   * modify it under the terms of the GNU General Public License   * WinPT is free software; you can redistribute it and/or
8   * as published by the Free Software Foundation; either version 2   * modify it under the terms of the GNU General Public License
9   * of the License, or (at your option) any later version.   * as published by the Free Software Foundation; either version 2
10   *     * of the License, or (at your option) any later version.
11   * WinPT is distributed in the hope that it will be useful,   *  
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of   * WinPT is distributed in the hope that it will be useful,
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * General Public License for more details.   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15   *   * General Public License for more details.
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,   * You should have received a copy of the GNU General Public License
18   * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA   * along with WinPT; if not, write to the Free Software Foundation,
19   */   * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20  #include <windows.h>   */
21  #include <time.h>  #ifdef HAVE_CONFIG_H
22    #include <config.h>
23  #include "wptTypes.h"  #endif
24  #include "wptGPG.h"  
25  #include "wptCommonCtl.h"  #include <windows.h>
26  #include "wptKeylist.h"  #include <windows.h>
27  #include "wptNLS.h"  #include <time.h>
28  #include "wptErrors.h"  
29  #include "wptUTF8.h"  #include "wptTypes.h"
30  #include "wptW32API.h"  #include "wptGPG.h"
31    #include "wptCommonCtl.h"
32    #include "wptKeylist.h"
33  /* Extract the file name part out of the given path in @path.  #include "wptNLS.h"
34     Return value: file part or NULL on error. */  #include "wptErrors.h"
35  static char*  #include "wptUTF8.h"
36  extract_filename (const char *path)  #include "wptW32API.h"
37  {  
38      char * fname, *p;  
39      int n, len = 0;  /* Extract the file name part out of the given path in @path.
40       Return value: file part or NULL on error. */
41      p = strrchr (path, '\\');  static char*
42      if (!p)  extract_filename (const char *path)
43          return m_strdup (path);  {
44      n = p - path;      char * fname, *p;
45      len = strlen (path) - n;      int n, len = 0;
46      fname = new char[len+1];  
47      if (!fname)      p = strrchr (path, '\\');
48          BUG (NULL);      if (!p)
49      memcpy (fname, path+n+1, len);          return m_strdup (path);
50      fname[len] = '\0';      n = p - path;
51      return fname;      len = strlen (path) - n;
52  }      fname = new char[len+1];
53        if (!fname)
54            BUG (NULL);
55  /* String representaton of the time in @timestamp.      memcpy (fname, path+n+1, len);
56     Format YEAR-MON-DAY HOUR:MIN:SEC.      fname[len] = '\0';
57     Return value: time as formatted string. */      return fname;
58  const char *  }
59  strtimestamp (long timestamp)  
60  {  
61      static char timebuf[64] = {0};  /* String representaton of the time in @timestamp.
62      struct tm * warp;     Format YEAR-MON-DAY HOUR:MIN:SEC.
63           Return value: time as formatted string. */
64      warp = localtime (&timestamp);  const char *
65      _snprintf (timebuf, sizeof timebuf - 1, "%04d-%02d-%02d %02d:%02d:%02d",  strtimestamp (long timestamp)
66                 warp->tm_year+1900, warp->tm_mon+1, warp->tm_mday,        {
67                 warp->tm_hour, warp->tm_min, warp->tm_sec);      static char timebuf[64] = {0};
68      return timebuf;      struct tm *warp;
69  }      
70        warp = localtime (&timestamp);
71        _snprintf (timebuf, sizeof timebuf - 1, "%04d-%02d-%02d %02d:%02d:%02d",
72  /* Map the signature summary in @sum to signature status table index.                 warp->tm_year+1900, warp->tm_mon+1, warp->tm_mday,      
73     Return value: index to table. */                 warp->tm_hour, warp->tm_min, warp->tm_sec);
74  int      return timebuf;
75  sigsum_to_index (gpgme_sigsum_t sum)  }
76  {  
77      if ((sum & GPGME_SIGSUM_VALID) && (sum & GPGME_SIGSUM_KEY_REVOKED))  
78          return 7;  /* Map the signature summary in @sum to signature status table index.
79      if ((sum & GPGME_SIGSUM_VALID) && (sum & GPGME_SIGSUM_SIG_EXPIRED))     Return value: index to table. */
80          return 6;  int
81      if (sum & GPGME_SIGSUM_GREEN)  sigsum_to_index (gpgme_sigsum_t sum)
82          return 1;  {
83      else if (sum & GPGME_SIGSUM_RED)      if ((sum & GPGME_SIGSUM_VALID) && (sum & GPGME_SIGSUM_KEY_REVOKED))
84          return 2;          return 7;
85      else if (sum & GPGME_SIGSUM_KEY_MISSING)      if ((sum & GPGME_SIGSUM_VALID) && (sum & GPGME_SIGSUM_SIG_EXPIRED))
86          return 3;          return 6;
87      return 0;      if (sum & GPGME_SIGSUM_GREEN)
88  }          return 1;
89        else if (sum & GPGME_SIGSUM_RED)
90            return 2;
91  /* Build a verify signature list control. With the parent window      else if (sum & GPGME_SIGSUM_KEY_MISSING)
92     from @ctrl and the mod given in @fm_mode. @lv contains the          return 3;
93     new control on success.      return 0;
94     Return value: 0 on success. */  }
95  int  
96  verlist_build (listview_ctrl_t *lv, HWND ctrl, int fm_mode)  
97  {  /* Build a verify signature list control. With the parent window
98      int j, rc = 0;     from @ctrl and the mod given in @fm_mode. @lv contains the
99      struct listview_ctrl_s * c;     new control on success.
100      struct listview_column_s fm_verlist[] = {       Return value: 0 on success. */
101          {0, 100, (char *)_("Name") },  int
102          {1, 120, (char *)_("Status") },  verlist_build (listview_ctrl_t *lv, HWND ctrl, int fm_mode)
103          {2, 115, (char *)_("Signed") },  {
104          {3,  58, (char *)_("Trust") },                int j, rc = 0;
105          {4, 160, (char *)_("User ID") },      struct listview_ctrl_s * c;
106          {5, 0, NULL }      struct listview_column_s fm_verlist[] = {  
107                    {0, 100, (char *)_("Name") },
108      };          {1, 120, (char *)_("Status") },
109      struct listview_column_s verlist[] = {                {2, 115, (char *)_("Signed") },
110          {0, 140, (char *)_("Status") },          {3,  58, (char *)_("Trust") },          
111          {1, 120, (char *)_("Signed") },          {4, 160, (char *)_("User ID") },
112          {2,  58, (char *)_("Trust") },          {5, 0, NULL}
113          {3,  80, (char *)_("Key ID" )},          
114          {4, 160, (char *)_("User ID") },              };
115          {5, 0, NULL }        struct listview_column_s verlist[] = {      
116      };          {0, 140, (char *)_("Status") },
117                {1, 120, (char *)_("Signed") },
118      rc = listview_new( &c );          {2,  58, (char *)_("Trust") },
119      if( rc )          {3,  80, (char *)_("Key ID" )},
120          return rc;          {4, 160, (char *)_("User ID") },
121                {5, 0, NULL}
122      c->ctrl = ctrl;      };
123      if( fm_mode ) {      
124          for( j = 0; fm_verlist[j].fieldname; j++ )            rc = listview_new (&c);
125              listview_add_column( c, &fm_verlist[j] );      if (rc)
126      }          return rc;
127      else {      
128          for( j = 0; verlist[j].fieldname; j++ )      c->ctrl = ctrl;
129              listview_add_column( c, &verlist[ j ] );          if( fm_mode ) {
130      }          for( j = 0; fm_verlist[j].fieldname; j++ )      
131      listview_set_ext_style( c );              listview_add_column( c, &fm_verlist[j] );
132      *lv = c;      }
133      return 0;      else {
134  }          for( j = 0; verlist[j].fieldname; j++ )
135                listview_add_column( c, &verlist[ j ] );    
136        }
137  /* Delete the given verify control in @lv. */      listview_set_ext_style( c );
138  void      *lv = c;
139  verlist_delete (listview_ctrl_t lv)      return 0;
140  {  }
141      if (lv) {  
142          listview_release (lv);    
143      }  /* Delete the given verify control in @lv. */
144  }  void
145    verlist_delete (listview_ctrl_t lv)
146    {
147  /* Add the given signature in @sig to the verify control @lv.      if (lv) {
148     Return value: 0 on success. */          listview_release (lv);  
149  int      }
150  verlist_add_sig (listview_ctrl_t lv, gpgme_signature_t sig)  }
151  {  
152      gpgme_key_t key = NULL;  
153      const char * attr;  /* Add the given signature in @sig to the verify control @lv.
154      u32 key_attr, t;     Return value: 0 on success. */
155      char keyid[32+1];  int
156      char * uid = NULL;  verlist_add_sig (listview_ctrl_t lv, gpgme_signature_t sig)
157        {
158      if( listview_add_item( lv, " " ) )      gpgme_key_t key = NULL;
159          return WPTERR_GENERAL;      const char * attr;
160            u32 key_attr;
161      get_pubkey (sig->fpr, &key);      char keyid[32+1];
162            char * uid = NULL;
163      attr = get_gpg_sigstat (sig->summary);      
164      if( attr )      if (listview_add_item (lv, " "))
165          listview_add_sub_item( lv, 0, 0, (char *)attr );          return WPTERR_GENERAL;
166            
167      t = sig->timestamp;      get_pubkey (sig->fpr, &key);
168      attr = strtimestamp (t);      
169      if( attr )      attr = get_gpg_sigstat (sig->summary);
170          listview_add_sub_item (lv, 0, 1, (char *)attr);      if( attr )
171                listview_add_sub_item (lv, 0, 0, (char *)attr);
172      attr = _("Unknown");      
173      if (key) {      attr = strtimestamp (sig->timestamp);
174          key_attr = key->uids->validity;      listview_add_sub_item (lv, 0, 1, (char *)attr);
175          attr = get_key_trust2 (NULL, key_attr, 0, 0);      
176      }      attr = _("Unknown");
177      listview_add_sub_item( lv, 0, 2, (char *)attr );      if (key) {
178                key_attr = key->uids->validity;
179      attr = sig->fpr;          attr = get_key_trust2 (NULL, key_attr, 0, 0);
180      if (!attr || strlen (attr) < 8)      }
181          listview_add_sub_item (lv, 0, 3, "0xDEADBEEF");      listview_add_sub_item (lv, 0, 2, (char *)attr);
182      else {      
183          if (strlen (attr) == 40)      attr = sig->fpr;
184              attr += 32;      if (!attr || strlen (attr) < 8)
185          else          listview_add_sub_item (lv, 0, 3, "????????");
186              attr += 24;      else {
187          _snprintf (keyid, sizeof keyid -1, "0x%s", attr);          if (strlen (attr) == 40)
188          listview_add_sub_item (lv, 0, 3, keyid);              attr += 32;
189      }          else
190                    attr += 24;
191      if (!key) {          _snprintf (keyid, sizeof keyid -1, "0x%s", attr);
192          attr = _("Invalid User ID");          listview_add_sub_item (lv, 0, 3, keyid);
193          listview_add_sub_item( lv, 0, 4, (char *)attr );      }
194      }      
195      else {      if (!key) {
196          attr = key->uids->name;          attr = _("Invalid User ID");
197          uid = utf8_to_wincp (attr, strlen (attr));          listview_add_sub_item( lv, 0, 4, (char *)attr );
198          if (uid) {      }
199              listview_add_sub_item( lv, 0, 4, (char *)uid );      else {
200              free( uid );          attr = key->uids->name;
201          }          uid = utf8_to_wincp (attr, strlen (attr));
202      }          if (uid) {
203                listview_add_sub_item( lv, 0, 4, (char *)uid );
204      return 0;              free (uid);
205  }          }
206        }
207    
208  /* Add the given file signature in @log to the verify control @lv.      return 0;
209     Return value: 0 on success. */  }
210  int  
211  verlist_add_sig_log (listview_ctrl_t lv, siglog_context_t log)  
212  {  /* Add the given file signature in @log to the verify control @lv.
213      gpgme_signature_t sig = log->sig;     Return value: 0 on success. */
214      gpgme_key_t key = NULL;  int
215      const char *attr;      verlist_add_sig_log (listview_ctrl_t lv, file_sig_ctx_t log)
216      char t[64], *name;  {
217        gpgme_signature_t sig = log->sig;
218      if( listview_add_item( lv, "" ) )      gpgme_key_t key = NULL;
219          return WPTERR_GENERAL;      const char *attr;    
220        char t[64], *name;
221      get_pubkey (sig->fpr, &key);  
222            if (listview_add_item (lv, ""))
223      name = extract_filename (log->file);          return WPTERR_GENERAL;
224      if( name )  
225          listview_add_sub_item (lv, 0, 0, name);      get_pubkey (sig->fpr, &key);
226      free_if_alloc (name);      
227            name = extract_filename (log->file);
228      attr = get_gpg_sigstat (sig->summary);      if (name)
229      if( attr )          listview_add_sub_item (lv, 0, 0, name);
230          listview_add_sub_item( lv, 0, 1, attr );      else
231            listview_add_sub_item (lv, 0, 0, log->file);
232      attr = strtimestamp( sig->timestamp );      free_if_alloc (name);
233      if( attr )      
234          listview_add_sub_item( lv, 0, 2, attr );      attr = get_gpg_sigstat (sig->summary);
235            if (attr)
236      attr = _("Unknown");          listview_add_sub_item (lv, 0, 1, attr);
237      if (key)  
238          attr = get_key_trust2 (NULL, key->owner_trust, 0, 0);      if (sig->timestamp > 0) {
239      listview_add_sub_item( lv, 0, 3, attr );          attr = strtimestamp (sig->timestamp);
240                listview_add_sub_item (lv, 0, 2, attr);
241      attr = sig->fpr;      }
242      if( !log->use_uid && strlen( attr ) == 40 ) {      else
243          _snprintf( t, sizeof t-1, "0x%s", attr + 32 );          listview_add_sub_item (lv, 0, 2, "No time");
244          listview_add_sub_item( lv, 0, 4, t );      
245      }      attr = _("Unknown");
246      else if( !log->use_uid && strlen( attr ) == 32 ) {      if (key)
247          _snprintf( t, sizeof t-1, "0x%s", attr + 24 );          attr = get_key_trust2 (NULL, key->uids->validity, 0, 0);
248          listview_add_sub_item( lv, 0, 4, t );      listview_add_sub_item (lv, 0, 3, attr);
249      }      
250      else if( log->user_id ) {      attr = sig->fpr;
251          char * p = utf8_to_wincp (log->user_id, strlen (log->user_id));      if (!log->use_uid && strlen (attr) == 40) {
252          if( p ) {          _snprintf (t, sizeof (t)-1, "0x%s", attr + 32);
253              listview_add_sub_item( lv, 0, 4, p );          listview_add_sub_item (lv, 0, 4, t);
254              free( p );      }
255          }      else if( !log->use_uid && strlen( attr ) == 32 ) {
256      }          _snprintf (t, sizeof (t)-1, "0x%s", attr + 24);
257      return 0;          listview_add_sub_item (lv, 0, 4, t);
258  }      }
259        else if (log->user_id) {
260            char *p = utf8_to_wincp (log->user_id, strlen (log->user_id));
261            if (p) {
262                listview_add_sub_item (lv, 0, 4, p);
263                free (p);
264            }
265        }
266        return 0;
267    }

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26