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

Diff of /trunk/Src/wptClipVerifyDlg.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 48 by werner, Mon Oct 31 21:14:11 2005 UTC
# Line 1  Line 1 
1  /* wptClipVerifyDlg.cpp - WinPT verify dialog  /* wptClipVerifyDlg.cpp - WinPT verify dialog
2   *      Copyright (C) 2001-2005 Timo Schulz   *      Copyright (C) 2001-2005 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   * You should have received a copy of the GNU General Public License
17   * along with WinPT; if not, write to the Free Software Foundation,   * along with WinPT; if not, write to the Free Software Foundation,
18   * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA   * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
19   */   */
20    
21  #include <windows.h>  #ifdef HAVE_CONFIG_H
22    #include <config.h>
23  #include "../resource.h"  #endif
24  #include "wptGPG.h"  
25  #include "wptTypes.h"  #include <windows.h>
26  #include "wptCommonCtl.h"  #include <time.h>
27  #include "wptKeylist.h"  
28  #include "wptW32API.h"  #include "resource.h"
29  #include "wptKeyserver.h"  #include "wptGPG.h"
30  #include "wptNLS.h"  #include "wptTypes.h"
31  #include "wptContext.h" /* for passwd_s */  #include "wptCommonCtl.h"
32  #include "wptDlgs.h"  #include "wptKeylist.h"
33  #include "wptErrors.h"  #include "wptW32API.h"
34  #include "wptVersion.h"  #include "wptKeyserver.h"
35    #include "wptNLS.h"
36  /* XXX use out directly and do not use gpg_data_extract to store the plain text. */  #include "wptContext.h" /* for passwd_s */
37    #include "wptDlgs.h"
38    #include "wptErrors.h"
39  /* Verify data from the clipboard. If @is_detached is set, a detached  #include "wptVersion.h"
40     signature is assumed with the data the signature was calculated over  
41     in @det_data. The context is returned in @r_ctx and the signature  /* XXX use out directly and do not use gpg_data_extract to store the plain text. */
42     in @r_sig.  
43     Return value: 0 on success. */  
44  gpgme_error_t  /* Verify data from the clipboard. If @is_detached is set, a detached
45  gpg_clip_verify (int is_detached,     signature is assumed with the data the signature was calculated over
46                   const char *det_data, size_t det_len,     in @det_data. The context is returned in @r_ctx and the signature
47                   gpgme_ctx_t *r_ctx,     in @r_sig.
48                   gpgme_signature_t *r_sig)     Return value: 0 on success. */
49  {  gpgme_error_t
50      gpgme_error_t err;  gpg_clip_verify (int is_detached,
51      gpgme_ctx_t ctx;                   const char *det_data, size_t det_len,
52      gpgme_data_t dat = NULL;                   gpgme_ctx_t *r_ctx,
53      gpgme_data_t out = NULL;                   gpgme_signature_t *r_sig)
54      gpgme_data_t sig = NULL;  {
55      gpgme_verify_result_t res;      gpgme_error_t err;
56        gpgme_ctx_t ctx;
57      if (is_detached) {      gpgme_data_t dat = NULL;
58          err = gpgme_data_new_from_mem (&dat, det_data, det_len, 1);      gpgme_data_t out = NULL;
59          if (err)      gpgme_data_t sig = NULL;
60              return err;      gpgme_verify_result_t res;
61      }  
62            if (is_detached) {
63      err = gpgme_new (&ctx);          err = gpgme_data_new_from_mem (&dat, det_data, det_len, 1);
64      if (err)          if (err)
65          goto leave;              return err;
66      err = gpg_data_new_from_clipboard (&sig, 0);      }
67      if (err)      
68          goto leave;      err = gpgme_new (&ctx);
69      err = gpgme_data_new (&out);      if (err)
70      if (err)          goto leave;
71          goto leave;      err = gpg_data_new_from_clipboard (&sig, 0);
72            if (err)
73      err = gpgme_op_verify (ctx, sig, dat, out);          goto leave;
74      if (err)      err = gpgme_data_new (&out);
75          goto leave;      if (err)
76      res = gpgme_op_verify_result (ctx);          goto leave;
77      if (!res || !res->signatures) {      
78          err = gpg_error (GPG_ERR_NO_DATA);      err = gpgme_op_verify (ctx, sig, dat, out);
79          goto leave;      if (err)
80      }          goto leave;
81      *r_sig = res->signatures;      res = gpgme_op_verify_result (ctx);
82      *r_ctx = ctx;      if (!res || !res->signatures) {
83            err = gpg_error (GPG_ERR_NO_DATA);
84  leave:          goto leave;
85      if (err) {      }
86          gpgme_release (ctx);      *r_sig = res->signatures;
87          *r_ctx = NULL;      *r_ctx = ctx;
88      }  
89      if (dat)  leave:
90          gpgme_data_release (dat);      if (err) {
91      if (out)          gpgme_release (ctx);
92          gpgme_data_release (out);          *r_ctx = NULL;
93      gpgme_data_release (sig);      }
94      return err;      if (dat)
95  }          gpgme_data_release (dat);
96        if (out)
97            gpgme_data_release (out);
98  /* Display the policy URL and the notation data of a signature.      gpgme_data_release (sig);
99     If @not is NULL, it is assumed there is no data.      return err;
100     @dlg is the handle to the calling dialog. */  }
101  static void  
102  show_notation_data (HWND dlg, gpgme_sig_notation_t not)  
103  {  /* Display the policy URL and the notation data of a signature.
104      gpgme_sig_notation_t n;     If @not is NULL, it is assumed there is no data.
105      size_t len=0;     @dlg is the handle to the calling dialog. */
106      char *p;  static void
107    show_notation_data (HWND dlg, gpgme_sig_notation_t nota)
108      for (n=not; n; n = n->next) {  {
109          if (n->name)      gpgme_sig_notation_t n;
110              len += strlen (n->name) + 1 + 2;      size_t len=0;
111          else      char *p;
112              len += strlen ("policy URL") + 1 + 2;  
113          len += strlen (n->value) + 1 + 2;      for (n=nota; n; n = n->next) {
114          len += 6;          if (n->name)
115      }              len += strlen (n->name) + 1 + 2;
116      p = (char *)calloc (1, len+64);          else
117      if (!p)              len += strlen ("policy URL") + 1 + 2;
118          BUG (NULL);          len += strlen (n->value) + 1 + 2;
119      strcpy (p, "Notation data:\n");          len += 6;
120      for (n=not; n; n = n->next) {      }
121          if (!n->name)      p = (char *)calloc (1, len+64);
122              strcat (p, "policy url: ");      if (!p)
123          else {          BUG (NULL);
124              strcat (p, n->name);      strcpy (p, "Notation data:\n");
125              strcat (p, " : ");      for (n=nota; n; n = n->next) {
126          }          if (!n->name)
127          strcat (p, "\"");              strcat (p, "policy url: ");
128          strcat (p, n->value);          else {
129          strcat (p, "\"\n");              strcat (p, n->name);
130      }              strcat (p, " : ");
131            }
132      msg_box (dlg, p, _("Signature Information"), MB_INFO);          strcat (p, "\"");
133      free (p);          strcat (p, n->value);
134  }          strcat (p, "\"\n");
135        }
136    
137  /* Dialog procedure for the clipboard verification. */      msg_box (dlg, p, _("Signature Information"), MB_INFO);
138  BOOL CALLBACK      free (p);
139  clip_verify_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)  }
140  {  
141      static listview_ctrl_t lv = NULL;  
142      static text_input_s *ctx = NULL;  /* Dialog procedure for the clipboard verification. */
143      gpgme_error_t err;  BOOL CALLBACK
144      gpgme_signature_t sig = NULL, s;  clip_verify_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
145      gpg_keycache_t kc = NULL;  {
146      gpgme_ctx_t c=NULL;      static listview_ctrl_t lv = NULL;
147      char keyid[16+1];      static text_input_s *ctx = NULL;
148      const char *det_data=NULL;      gpgme_error_t err;
149      u16 port = HKP_PORT;      gpgme_signature_t sig = NULL, s;
150      int rc = 0, det_len=0;      gpg_keycache_t kc = NULL;
151            gpgme_ctx_t c=NULL;
152      switch( msg ) {      const char *det_data=NULL;
153      case WM_INITDIALOG:      u16 port = HKP_PORT;
154      #ifndef LANG_DE      int rc = 0, det_len=0;
155          SetWindowText (dlg, _("Verify"));      
156      #endif      switch( msg ) {
157          kc = keycache_get_ctx (KEYCACHE_PUB);      case WM_INITDIALOG:
158          if (!kc)      #ifndef LANG_DE
159              BUG (NULL);          SetWindowText (dlg, _("Verify"));
160          ctx = (text_input_s *)lparam;      #endif
161          if (ctx) {          kc = keycache_get_ctx (KEYCACHE_PUB);
162              det_data = ctx->data;          if (!kc)
163              det_len = ctx->length;              BUG (NULL);
164          }          ctx = (text_input_s *)lparam;
165          err = gpg_clip_verify (ctx && ctx->length > 0,          if (ctx) {
166                                 det_data, det_len, &c, &sig);              det_data = ctx->data;
167          if (err) {              det_len = ctx->length;
168              msg_box (dlg, gpgme_strerror (err), _("Verify"), MB_ERR);          }
169              if (c)          err = gpg_clip_verify (ctx && ctx->length > 0,
170                  gpgme_release (c);                                 det_data, det_len, &c, &sig);
171              EndDialog (dlg, FALSE);          if (err) {
172              return FALSE;              msg_box (dlg, gpgme_strerror (err), _("Verify"), MB_ERR);
173          }              if (c)
174                    gpgme_release (c);
175          if (gpgme_err_code (sig->status) == GPG_ERR_NO_PUBKEY) {              EndDialog (dlg, FALSE);
176              const char * kserv;              return FALSE;
177              const char *fpr = sig->fpr;          }
178              if (!fpr)  
179                  fpr = "0xDEADBEEF";          if (gpgme_err_code (sig->status) == GPG_ERR_NO_PUBKEY) {
180              if (strlen (fpr) == 40)              const char *keyid;
181                  fpr += 32;              const char *kserv;
182              else              if (!sig->fpr)
183                  fpr += 24;                  BUG (NULL);
184              rc = log_box (_("Verify"), MB_INFO|MB_YESNO,              if (strlen (sig->fpr) == 40)
185                            _("Signature made %s using %s key ID 0x%s\n"                  keyid = sig->fpr+24;
186                            "Cannot check signature: public key not found\n\n"              else
187                            "Do you want to try to retrieve the key from the keyserver?"),                  keyid = sig->fpr+16;
188                            strtimestamp (sig->timestamp),              rc = log_box (_("Verify"), MB_INFO|MB_YESNO,
189                            get_key_pubalgo (sig->pubkey_algo), fpr);                            _("Signature made %s using %s key ID 0x%s\n"
190              if (rc == IDNO) {                            "Cannot check signature: public key not found\n\n"
191                  msg_box (dlg, gpg_sigstat[GPGME_SIG_STAT_NOKEY], _("Verify"), MB_WARN);                            "Do you want to try to retrieve the key from the keyserver?"),
192                  gpgme_release (c);                            strtimestamp (sig->timestamp),
193                  EndDialog (dlg, FALSE);                            get_key_pubalgo (sig->pubkey_algo), keyid+8);
194                  return FALSE;              if (rc == IDNO) {
195              }                  msg_box (dlg, gpg_sigstat[GPGME_SIG_STAT_NOKEY], _("Verify"), MB_WARN);
196              if (0) {                  gpgme_release (c);
197              /* FIXME: does GPGME include the keyserver status                  EndDialog (dlg, FALSE);
198              kserv = gpgme_sig_get_string_attr (sig, GPGME_ATTR_KEYSERVER);                  return FALSE;
199              if (kserv && strncmp (kserv, "hkp://", 6)) {              }
200                  rc = log_box (_("Verify"), MB_INFO|MB_YESNO,              if (0) {
201                                _("The users preferred keyserver is '%s'.\n"              /* FIXME: does GPGME include the keyserver status
202                                  "Do you want to use it to fetch the key?"), kserv);              kserv = gpgme_sig_get_string_attr (sig, GPGME_ATTR_KEYSERVER);
203                  if (rc == IDNO) {              if (kserv && strncmp (kserv, "hkp://", 6)) {
204                      kserv = default_keyserver;                  rc = log_box (_("Verify"), MB_INFO|MB_YESNO,
205                      port = default_keyserver_port;                                _("The users preferred keyserver is '%s'.\n"
206                  }*/                                  "Do you want to use it to fetch the key?"), kserv);
207              }                  if (rc == IDNO) {
208                                    kserv = default_keyserver;
209              else {                      port = default_keyserver_port;
210                  kserv = default_keyserver;                  }*/
211                  port = default_keyserver_port;              }
212              }              else {
213              if (!hkp_recv_key (dlg, kserv, port, keyid, 0, 0)) {                  kserv = default_keyserver;
214                  keycache_reload (dlg);                  port = default_keyserver_port;
215                  kc = keycache_get_ctx (KEYCACHE_PUB);              }
216                  if (!kc)              if (!hkp_recv_key (dlg, kserv, port, keyid+8, 0, 0)) {
217                      BUG (dlg);                  keycache_reload (dlg);
218              }                  kc = keycache_get_ctx (KEYCACHE_PUB);
219          }                  if (!kc)
220          else if (gpgme_err_code (sig->status) == GPG_ERR_BAD_SIGNATURE && !sig->timestamp)                      BUG (dlg);
221                   ;              }
222          else if (!sig->timestamp || !sig->validity) {          }
223              msg_box (dlg, _("Invalid signature state."), _("Verify"), MB_ERR);          else if (gpgme_err_code (sig->status) == GPG_ERR_BAD_SIGNATURE &&
224              gpgme_release (c);                   !sig->timestamp)
225              EndDialog (dlg, FALSE);                   ;
226              return FALSE;          else if (!sig->timestamp || !sig->validity) {
227          }              msg_box (dlg, _("Invalid signature state."), _("Verify"), MB_ERR);
228          verlist_build (&lv, GetDlgItem (dlg, IDC_VERIFY_SIGLIST), 0);              gpgme_release (c);
229                EndDialog (dlg, FALSE);
230          for (s = sig; s; s = s->next) {              return FALSE;
231              rc = verlist_add_sig (lv, s);          }
232              if (rc)          verlist_build (&lv, GetDlgItem (dlg, IDC_VERIFY_SIGLIST), 0);
233                  msg_box (dlg, _("Could not extract key or signature information."),  
234                           _("Verify"), MB_ERR);          for (s = sig; s; s = s->next) {
235          }              rc = verlist_add_sig (lv, s);
236          if (sig->exp_timestamp > (DWORD)time (NULL))              if (rc)
237              SetDlgItemText( dlg, IDC_VERIFY_INFO, _("The signature is expired!") );                  msg_box (dlg, _("Could not extract key or signature information."),
238          if (sig->notations)                           _("Verify"), MB_ERR);
239              show_notation_data (dlg, sig->notations);          }
240          gpgme_release (c);          if (sig->exp_timestamp > (DWORD)time (NULL))
241          SetForegroundWindow (dlg);              SetDlgItemText( dlg, IDC_VERIFY_INFO, _("The signature is expired!") );
242          set_active_window (dlg);          if (sig->notations)
243          return TRUE;              show_notation_data (dlg, sig->notations);
244                    gpgme_release (c);
245      case WM_DESTROY:          SetForegroundWindow (dlg);
246          reset_active_window ();          set_active_window (dlg);
247          if (lv) {          return TRUE;
248              listview_release (lv);          
249              lv = NULL;      case WM_DESTROY:
250          }          reset_active_window ();
251          return FALSE;          if (lv) {
252                        listview_release (lv);
253      case WM_SYSCOMMAND:              lv = NULL;
254          if (LOWORD (wparam) == SC_CLOSE)          }
255              EndDialog (dlg, TRUE);          return FALSE;
256          return FALSE;          
257                case WM_SYSCOMMAND:
258      case WM_COMMAND:          if (LOWORD (wparam) == SC_CLOSE)
259          switch (LOWORD (wparam )) {              EndDialog (dlg, TRUE);
260          case IDOK:          return FALSE;
261              EndDialog (dlg, TRUE);          
262              return FALSE;      case WM_COMMAND:
263                        switch (LOWORD (wparam )) {
264          case IDC_VERIFY_SAVE:          case IDOK:
265              dialog_box_param (glob_hinst, (LPCTSTR)IDD_WINPT_FILE_SAVE, dlg,              EndDialog (dlg, TRUE);
266                                file_save_dlg_proc, NULL, _("Save Plaintext"),              return FALSE;
267                                IDS_WINPT_FILE_SAVE);              
268              break;          case IDC_VERIFY_SAVE:
269          }              dialog_box_param (glob_hinst, (LPCTSTR)IDD_WINPT_FILE_SAVE, dlg,
270          break;                                file_save_dlg_proc, NULL, _("Save Plaintext"),
271      }                                IDS_WINPT_FILE_SAVE);
272                    break;
273      return FALSE;          }
274  }          break;
275        }
276        
277        return FALSE;
278    }
279    

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26