/[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 24 by twoaday, Sat Oct 8 10:43:08 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          msg_box (NULL, "detached sig", "debug", 0);      gpgme_data_t out = NULL;
59          err = gpgme_data_new_from_mem (&dat, det_data, det_len, 1);      gpgme_data_t sig = NULL;
60          if (err)      gpgme_verify_result_t res;
61              return err;  
62      }      if (is_detached) {
63                err = gpgme_data_new_from_mem (&dat, det_data, det_len, 1);
64      err = gpgme_new (&ctx);          if (err)
65      if (err)              return err;
66          goto leave;      }
67      err = gpg_data_new_from_clipboard (&sig, 0);      
68      if (err)      err = gpgme_new (&ctx);
69          goto leave;      if (err)
70      err = gpgme_data_new (&out);          goto leave;
71      if (err)      err = gpg_data_new_from_clipboard (&sig, 0);
72          goto leave;      if (err)
73                goto leave;
74      err = gpgme_op_verify (ctx, sig, dat, out);      err = gpgme_data_new (&out);
75      if (err)      if (err)
76          goto leave;          goto leave;
77      res = gpgme_op_verify_result (ctx);      
78      if (!res || !res->signatures) {      err = gpgme_op_verify (ctx, sig, dat, out);
79          err = gpg_error (GPG_ERR_NO_DATA);      if (err)
80          goto leave;          goto leave;
81      }      res = gpgme_op_verify_result (ctx);
82      *r_sig = res->signatures;      if (!res || !res->signatures) {
83      *r_ctx = ctx;          err = gpg_error (GPG_ERR_NO_DATA);
84            goto leave;
85  leave:      }
86      if (err) {      *r_sig = res->signatures;
87          gpgme_release (ctx);      *r_ctx = ctx;
88          *r_ctx = NULL;  
89      }  leave:
90      if (dat)      if (err) {
91          gpgme_data_release (dat);          gpgme_release (ctx);
92      if (out)          *r_ctx = NULL;
93          gpgme_data_release (out);      }
94      gpgme_data_release (sig);      if (dat)
95      return err;          gpgme_data_release (dat);
96  }      if (out)
97            gpgme_data_release (out);
98        gpgme_data_release (sig);
99  /* Display the policy URL and the notation data of a signature.      return err;
100     If @not is NULL, it is assumed there is no data.  }
101     @dlg is the handle to the calling dialog. */  
102  static void  
103  show_notation_data (HWND dlg, gpgme_sig_notation_t not)  /* Display the policy URL and the notation data of a signature.
104  {     If @not is NULL, it is assumed there is no data.
105      gpgme_sig_notation_t n;     @dlg is the handle to the calling dialog. */
106      size_t len=0;  static void
107      char *p;  show_notation_data (HWND dlg, gpgme_sig_notation_t nota)
108    {
109      for (n=not; n; n = n->next) {      gpgme_sig_notation_t n;
110          if (n->name)      size_t len=0;
111              len += strlen (n->name) + 1 + 2;      char *p;
112          else  
113              len += strlen ("policy URL") + 1 + 2;      for (n=nota; n; n = n->next) {
114          len += strlen (n->value) + 1 + 2;          if (n->name)
115          len += 6;              len += strlen (n->name) + 1 + 2;
116      }          else
117      p = (char *)calloc (1, len+64);              len += strlen ("policy URL") + 1 + 2;
118      if (!p)          len += strlen (n->value) + 1 + 2;
119          BUG (NULL);          len += 6;
120      strcpy (p, "Notation data:\n");      }
121      for (n=not; n; n = n->next) {      p = (char *)calloc (1, len+64);
122          if (!n->name)      if (!p)
123              strcat (p, "policy url: ");          BUG (NULL);
124          else {      strcpy (p, "Notation data:\n");
125              strcat (p, n->name);      for (n=nota; n; n = n->next) {
126              strcat (p, " : ");          if (!n->name)
127          }              strcat (p, "policy url: ");
128          strcat (p, "\"");          else {
129          strcat (p, n->value);              strcat (p, n->name);
130          strcat (p, "\"\n");              strcat (p, " : ");
131      }          }
132            strcat (p, "\"");
133      msg_box (dlg, p, _("Signature Information"), MB_INFO);          strcat (p, n->value);
134      free (p);          strcat (p, "\"\n");
135  }      }
136    
137        msg_box (dlg, p, _("Signature Information"), MB_INFO);
138  /* Dialog procedure for the clipboard verification. */      free (p);
139  BOOL CALLBACK  }
140  clip_verify_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)  
141  {  
142      static listview_ctrl_t lv = NULL;  /* Dialog procedure for the clipboard verification. */
143      static text_input_s *ctx = NULL;  BOOL CALLBACK
144      gpgme_error_t err;  clip_verify_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
145      gpgme_signature_t sig = NULL, s;  {
146      gpgme_keycache_t kc = NULL;      static listview_ctrl_t lv = NULL;
147      gpgme_ctx_t c=NULL;      static text_input_s *ctx = NULL;
148      char keyid[16+1];      gpgme_error_t err;
149      const char *det_data=NULL;      gpgme_signature_t sig = NULL, s;
150      u16 port = HKP_PORT;      gpg_keycache_t kc = NULL;
151      int rc = 0, det_len=0;      gpgme_ctx_t c=NULL;
152            const char *det_data=NULL;
153      switch( msg ) {      u16 port = HKP_PORT;
154      case WM_INITDIALOG:      int rc = 0, det_len=0;
155      #ifndef LANG_DE      
156          SetWindowText (dlg, _("Verify"));      switch( msg ) {
157      #endif      case WM_INITDIALOG:
158          kc = keycache_get_ctx (KEYCACHE_PUB);      #ifndef LANG_DE
159          if (!kc)          SetWindowText (dlg, _("Verify"));
160              BUG (NULL);      #endif
161          ctx = (text_input_s *)lparam;          kc = keycache_get_ctx (KEYCACHE_PUB);
162          if (ctx) {          if (!kc)
163              det_data = ctx->data;              BUG (NULL);
164              det_len = ctx->length;          ctx = (text_input_s *)lparam;
165          }          if (ctx) {
166          err = gpg_clip_verify (ctx && ctx->length > 0,              det_data = ctx->data;
167                                 det_data, det_len, &c, &sig);              det_len = ctx->length;
168          if (err) {          }
169              msg_box (dlg, gpgme_strerror (err), _("Verify"), MB_ERR);          err = gpg_clip_verify (ctx && ctx->length > 0,
170              if (c)                                 det_data, det_len, &c, &sig);
171                  gpgme_release (c);          if (err) {
172              EndDialog (dlg, FALSE);              msg_box (dlg, gpgme_strerror (err), _("Verify"), MB_ERR);
173              return FALSE;              if (c)
174          }                  gpgme_release (c);
175                EndDialog (dlg, FALSE);
176          if (gpgme_err_code (sig->status) == GPG_ERR_NO_PUBKEY) {              return FALSE;
177              const char * kserv;          }
178              const char *fpr = sig->fpr;  
179              if (!fpr)          if (gpgme_err_code (sig->status) == GPG_ERR_NO_PUBKEY) {
180                  fpr = "0xDEADBEEF";              const char *keyid;
181              if (strlen (fpr) == 40)              const char *kserv;
182                  fpr += 32;              if (!sig->fpr)
183              else                  BUG (NULL);
184                  fpr += 24;              if (strlen (sig->fpr) == 40)
185              rc = log_box (_("Verify"), MB_INFO|MB_YESNO,                  keyid = sig->fpr+24;
186                            _("Signature made %s using %s key ID 0x%s\n"              else
187                            "Cannot check signature: public key not found\n\n"                  keyid = sig->fpr+16;
188                            "Do you want to try to retrieve the key from the keyserver?"),              rc = log_box (_("Verify"), MB_INFO|MB_YESNO,
189                            strtimestamp (sig->timestamp),                            _("Signature made %s using %s key ID 0x%s\n"
190                            get_key_pubalgo (sig->pubkey_algo), fpr);                            "Cannot check signature: public key not found\n\n"
191              if (rc == IDNO) {                            "Do you want to try to retrieve the key from the keyserver?"),
192                  msg_box (dlg, gpg_sigstat[GPGME_SIG_STAT_NOKEY], _("Verify"), MB_WARN);                            strtimestamp (sig->timestamp),
193                  gpgme_release (c);                            get_key_pubalgo (sig->pubkey_algo), keyid+8);
194                  EndDialog (dlg, FALSE);              if (rc == IDNO) {
195                  return FALSE;                  msg_box (dlg, gpg_sigstat[GPGME_SIG_STAT_NOKEY], _("Verify"), MB_WARN);
196              }                  gpgme_release (c);
197              if (0) {                  EndDialog (dlg, FALSE);
198              /* FIXME: does GPGME include the keyserver status                  return FALSE;
199              kserv = gpgme_sig_get_string_attr (sig, GPGME_ATTR_KEYSERVER);              }
200              if (kserv && strncmp (kserv, "hkp://", 6)) {              if (0) {
201                  rc = log_box (_("Verify"), MB_INFO|MB_YESNO,              /* FIXME: does GPGME include the keyserver status
202                                _("The users preferred keyserver is '%s'.\n"              kserv = gpgme_sig_get_string_attr (sig, GPGME_ATTR_KEYSERVER);
203                                  "Do you want to use it to fetch the key?"), kserv);              if (kserv && strncmp (kserv, "hkp://", 6)) {
204                  if (rc == IDNO) {                  rc = log_box (_("Verify"), MB_INFO|MB_YESNO,
205                      kserv = default_keyserver;                                _("The users preferred keyserver is '%s'.\n"
206                      port = default_keyserver_port;                                  "Do you want to use it to fetch the key?"), kserv);
207                  }*/                  if (rc == IDNO) {
208              }                      kserv = default_keyserver;
209                                    port = default_keyserver_port;
210              else {                  }*/
211                  kserv = default_keyserver;              }
212                  port = default_keyserver_port;              else {
213              }                  kserv = default_keyserver;
214              if (!hkp_recv_key (dlg, kserv, port, keyid, 0, 0)) {                  port = default_keyserver_port;
215                  keycache_reload (dlg);              }
216                  kc = keycache_get_ctx (KEYCACHE_PUB);              if (!hkp_recv_key (dlg, kserv, port, keyid+8, 0, 0)) {
217                  if (!kc)                  keycache_reload (dlg);
218                      BUG (dlg);                  kc = keycache_get_ctx (KEYCACHE_PUB);
219              }                  if (!kc)
220          }                      BUG (dlg);
221          else if (gpgme_err_code (sig->status) == GPG_ERR_BAD_SIGNATURE && !sig->timestamp)              }
222                   ;          }
223          else if (!sig->timestamp || !sig->validity) {          else if (gpgme_err_code (sig->status) == GPG_ERR_BAD_SIGNATURE &&
224              msg_box (dlg, _("Invalid signature state."), _("Verify"), MB_ERR);                   !sig->timestamp)
225              gpgme_release (c);                   ;
226              EndDialog (dlg, FALSE);          else if (!sig->timestamp || !sig->validity) {
227              return FALSE;              msg_box (dlg, _("Invalid signature state."), _("Verify"), MB_ERR);
228          }              gpgme_release (c);
229          verlist_build (&lv, GetDlgItem (dlg, IDC_VERIFY_SIGLIST), 0);              EndDialog (dlg, FALSE);
230                return FALSE;
231          for (s = sig; s; s = s->next) {          }
232              rc = verlist_add_sig (lv, s);          verlist_build (&lv, GetDlgItem (dlg, IDC_VERIFY_SIGLIST), 0);
233              if (rc)  
234                  msg_box (dlg, _("Could not extract key or signature information."),          for (s = sig; s; s = s->next) {
235                           _("Verify"), MB_ERR);              rc = verlist_add_sig (lv, s);
236          }              if (rc)
237          if (sig->exp_timestamp > (DWORD)time (NULL))                  msg_box (dlg, _("Could not extract key or signature information."),
238              SetDlgItemText( dlg, IDC_VERIFY_INFO, _("The signature is expired!") );                           _("Verify"), MB_ERR);
239          if (sig->notations)          }
240              show_notation_data (dlg, sig->notations);          if (sig->exp_timestamp > (DWORD)time (NULL))
241          gpgme_release (c);              SetDlgItemText( dlg, IDC_VERIFY_INFO, _("The signature is expired!") );
242          SetForegroundWindow (dlg);          if (sig->notations)
243          set_active_window (dlg);              show_notation_data (dlg, sig->notations);
244          return TRUE;          gpgme_release (c);
245                    SetForegroundWindow (dlg);
246      case WM_DESTROY:          set_active_window (dlg);
247          reset_active_window ();          return TRUE;
248          if (lv) {          
249              listview_release (lv);      case WM_DESTROY:
250              lv = NULL;          reset_active_window ();
251          }          if (lv) {
252          return FALSE;              listview_release (lv);
253                        lv = NULL;
254      case WM_SYSCOMMAND:          }
255          if (LOWORD (wparam) == SC_CLOSE)          return FALSE;
256              EndDialog (dlg, TRUE);          
257          return FALSE;      case WM_SYSCOMMAND:
258                    if (LOWORD (wparam) == SC_CLOSE)
259      case WM_COMMAND:              EndDialog (dlg, TRUE);
260          switch (LOWORD (wparam )) {          return FALSE;
261          case IDOK:          
262              EndDialog (dlg, TRUE);      case WM_COMMAND:
263              return FALSE;          switch (LOWORD (wparam )) {
264                        case IDOK:
265          case IDC_VERIFY_SAVE:              EndDialog (dlg, TRUE);
266              dialog_box_param (glob_hinst, (LPCTSTR)IDD_WINPT_FILE_SAVE, dlg,              return FALSE;
267                                file_save_dlg_proc, NULL, _("Save Plaintext"),              
268                                IDS_WINPT_FILE_SAVE);          case IDC_VERIFY_SAVE:
269              break;              dialog_box_param (glob_hinst, (LPCTSTR)IDD_WINPT_FILE_SAVE, dlg,
270          }                                file_save_dlg_proc, NULL, _("Save Plaintext"),
271          break;                                IDS_WINPT_FILE_SAVE);
272      }              break;
273                }
274      return FALSE;          break;
275  }      }
276        
277        return FALSE;
278    }
279    

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26