/[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 35 by twoaday, Mon Oct 17 08:49:30 2005 UTC revision 36 by werner, Thu Oct 27 15:25:13 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 <windows.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 not)
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=not; 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=not; 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 ) {      char keyid[16+1];
153      case WM_INITDIALOG:      const char *det_data=NULL;
154      #ifndef LANG_DE      u16 port = HKP_PORT;
155          SetWindowText (dlg, _("Verify"));      int rc = 0, det_len=0;
156      #endif      
157          kc = keycache_get_ctx (KEYCACHE_PUB);      switch( msg ) {
158          if (!kc)      case WM_INITDIALOG:
159              BUG (NULL);      #ifndef LANG_DE
160          ctx = (text_input_s *)lparam;          SetWindowText (dlg, _("Verify"));
161          if (ctx) {      #endif
162              det_data = ctx->data;          kc = keycache_get_ctx (KEYCACHE_PUB);
163              det_len = ctx->length;          if (!kc)
164          }              BUG (NULL);
165          err = gpg_clip_verify (ctx && ctx->length > 0,          ctx = (text_input_s *)lparam;
166                                 det_data, det_len, &c, &sig);          if (ctx) {
167          if (err) {              det_data = ctx->data;
168              msg_box (dlg, gpgme_strerror (err), _("Verify"), MB_ERR);              det_len = ctx->length;
169              if (c)          }
170                  gpgme_release (c);          err = gpg_clip_verify (ctx && ctx->length > 0,
171              EndDialog (dlg, FALSE);                                 det_data, det_len, &c, &sig);
172              return FALSE;          if (err) {
173          }              msg_box (dlg, gpgme_strerror (err), _("Verify"), MB_ERR);
174                if (c)
175          if (gpgme_err_code (sig->status) == GPG_ERR_NO_PUBKEY) {                  gpgme_release (c);
176              const char * kserv;              EndDialog (dlg, FALSE);
177              const char *fpr = sig->fpr;              return FALSE;
178              if (!fpr)          }
179                  fpr = "0xDEADBEEF";  
180              if (strlen (fpr) == 40)          if (gpgme_err_code (sig->status) == GPG_ERR_NO_PUBKEY) {
181                  fpr += 32;              const char * kserv;
182              else              const char *fpr = sig->fpr;
183                  fpr += 24;              if (!fpr)
184              rc = log_box (_("Verify"), MB_INFO|MB_YESNO,                  fpr = "0xDEADBEEF";
185                            _("Signature made %s using %s key ID 0x%s\n"              if (strlen (fpr) == 40)
186                            "Cannot check signature: public key not found\n\n"                  fpr += 32;
187                            "Do you want to try to retrieve the key from the keyserver?"),              else
188                            strtimestamp (sig->timestamp),                  fpr += 24;
189                            get_key_pubalgo (sig->pubkey_algo), fpr);              rc = log_box (_("Verify"), MB_INFO|MB_YESNO,
190              if (rc == IDNO) {                            _("Signature made %s using %s key ID 0x%s\n"
191                  msg_box (dlg, gpg_sigstat[GPGME_SIG_STAT_NOKEY], _("Verify"), MB_WARN);                            "Cannot check signature: public key not found\n\n"
192                  gpgme_release (c);                            "Do you want to try to retrieve the key from the keyserver?"),
193                  EndDialog (dlg, FALSE);                            strtimestamp (sig->timestamp),
194                  return FALSE;                            get_key_pubalgo (sig->pubkey_algo), fpr);
195              }              if (rc == IDNO) {
196              if (0) {                  msg_box (dlg, gpg_sigstat[GPGME_SIG_STAT_NOKEY], _("Verify"), MB_WARN);
197              /* FIXME: does GPGME include the keyserver status                  gpgme_release (c);
198              kserv = gpgme_sig_get_string_attr (sig, GPGME_ATTR_KEYSERVER);                  EndDialog (dlg, FALSE);
199              if (kserv && strncmp (kserv, "hkp://", 6)) {                  return FALSE;
200                  rc = log_box (_("Verify"), MB_INFO|MB_YESNO,              }
201                                _("The users preferred keyserver is '%s'.\n"              if (0) {
202                                  "Do you want to use it to fetch the key?"), kserv);              /* FIXME: does GPGME include the keyserver status
203                  if (rc == IDNO) {              kserv = gpgme_sig_get_string_attr (sig, GPGME_ATTR_KEYSERVER);
204                      kserv = default_keyserver;              if (kserv && strncmp (kserv, "hkp://", 6)) {
205                      port = default_keyserver_port;                  rc = log_box (_("Verify"), MB_INFO|MB_YESNO,
206                  }*/                                _("The users preferred keyserver is '%s'.\n"
207              }                                  "Do you want to use it to fetch the key?"), kserv);
208                                if (rc == IDNO) {
209              else {                      kserv = default_keyserver;
210                  kserv = default_keyserver;                      port = default_keyserver_port;
211                  port = default_keyserver_port;                  }*/
212              }              }
213              if (!hkp_recv_key (dlg, kserv, port, keyid, 0, 0)) {              
214                  keycache_reload (dlg);              else {
215                  kc = keycache_get_ctx (KEYCACHE_PUB);                  kserv = default_keyserver;
216                  if (!kc)                  port = default_keyserver_port;
217                      BUG (dlg);              }
218              }              if (!hkp_recv_key (dlg, kserv, port, keyid, 0, 0)) {
219          }                  keycache_reload (dlg);
220          else if (gpgme_err_code (sig->status) == GPG_ERR_BAD_SIGNATURE && !sig->timestamp)                  kc = keycache_get_ctx (KEYCACHE_PUB);
221                   ;                  if (!kc)
222          else if (!sig->timestamp || !sig->validity) {                      BUG (dlg);
223              msg_box (dlg, _("Invalid signature state."), _("Verify"), MB_ERR);              }
224              gpgme_release (c);          }
225              EndDialog (dlg, FALSE);          else if (gpgme_err_code (sig->status) == GPG_ERR_BAD_SIGNATURE && !sig->timestamp)
226              return FALSE;                   ;
227          }          else if (!sig->timestamp || !sig->validity) {
228          verlist_build (&lv, GetDlgItem (dlg, IDC_VERIFY_SIGLIST), 0);              msg_box (dlg, _("Invalid signature state."), _("Verify"), MB_ERR);
229                gpgme_release (c);
230          for (s = sig; s; s = s->next) {              EndDialog (dlg, FALSE);
231              rc = verlist_add_sig (lv, s);              return FALSE;
232              if (rc)          }
233                  msg_box (dlg, _("Could not extract key or signature information."),          verlist_build (&lv, GetDlgItem (dlg, IDC_VERIFY_SIGLIST), 0);
234                           _("Verify"), MB_ERR);  
235          }          for (s = sig; s; s = s->next) {
236          if (sig->exp_timestamp > (DWORD)time (NULL))              rc = verlist_add_sig (lv, s);
237              SetDlgItemText( dlg, IDC_VERIFY_INFO, _("The signature is expired!") );              if (rc)
238          if (sig->notations)                  msg_box (dlg, _("Could not extract key or signature information."),
239              show_notation_data (dlg, sig->notations);                           _("Verify"), MB_ERR);
240          gpgme_release (c);          }
241          SetForegroundWindow (dlg);          if (sig->exp_timestamp > (DWORD)time (NULL))
242          set_active_window (dlg);              SetDlgItemText( dlg, IDC_VERIFY_INFO, _("The signature is expired!") );
243          return TRUE;          if (sig->notations)
244                        show_notation_data (dlg, sig->notations);
245      case WM_DESTROY:          gpgme_release (c);
246          reset_active_window ();          SetForegroundWindow (dlg);
247          if (lv) {          set_active_window (dlg);
248              listview_release (lv);          return TRUE;
249              lv = NULL;          
250          }      case WM_DESTROY:
251          return FALSE;          reset_active_window ();
252                    if (lv) {
253      case WM_SYSCOMMAND:              listview_release (lv);
254          if (LOWORD (wparam) == SC_CLOSE)              lv = NULL;
255              EndDialog (dlg, TRUE);          }
256          return FALSE;          return FALSE;
257                    
258      case WM_COMMAND:      case WM_SYSCOMMAND:
259          switch (LOWORD (wparam )) {          if (LOWORD (wparam) == SC_CLOSE)
260          case IDOK:              EndDialog (dlg, TRUE);
261              EndDialog (dlg, TRUE);          return FALSE;
262              return FALSE;          
263                    case WM_COMMAND:
264          case IDC_VERIFY_SAVE:          switch (LOWORD (wparam )) {
265              dialog_box_param (glob_hinst, (LPCTSTR)IDD_WINPT_FILE_SAVE, dlg,          case IDOK:
266                                file_save_dlg_proc, NULL, _("Save Plaintext"),              EndDialog (dlg, TRUE);
267                                IDS_WINPT_FILE_SAVE);              return FALSE;
268              break;              
269          }          case IDC_VERIFY_SAVE:
270          break;              dialog_box_param (glob_hinst, (LPCTSTR)IDD_WINPT_FILE_SAVE, dlg,
271      }                                file_save_dlg_proc, NULL, _("Save Plaintext"),
272                                      IDS_WINPT_FILE_SAVE);
273      return FALSE;              break;
274  }          }
275            break;
276        }
277        
278        return FALSE;
279    }
280    

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26