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

Annotation of /trunk/Src/wptClipVerifyDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 219 - (hide annotations)
Sat May 27 08:56:00 2006 UTC (18 years, 9 months ago) by twoaday
File size: 7355 byte(s)
2006-05-25  Timo Schulz  <ts@g10code.de>
                                                                                
        * wptGPGUtil.cpp (gpg_rebuild_cache): Return error code.
        * wptGPGME.cpp (winpt_get_seckey): Fix off-by-one bug.
        * wptVerifyList.cpp (verlist_build): New argument type.
        Change all callers.
        (verlist_set_info_control): New.
        (verlist_set_additional_info): New.
        * wptFileVerifyDlg.cpp (file_verify_dlg_proc): Adjust code.
        * wptClipVerifyDlg.cpp (clip_verify_dlg_proc): Likewise.
        * wptFileCBS.cpp (read_cb, write_cb): Add logging.
                                                                                


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

Properties

Name Value
svn:eol-style native

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26