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

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26