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

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26