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

Annotation of /trunk/Src/wptClipVerifyDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 256 - (hide annotations)
Sat Aug 5 10:31:06 2006 UTC (18 years, 6 months ago) by twoaday
File size: 7280 byte(s)
1.0.0pre3 release.


1 werner 36 /* wptClipVerifyDlg.cpp - WinPT verify dialog
2 twoaday 256 * Copyright (C) 2001-2006 Timo Schulz
3 werner 36 *
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 twoaday 256 /* XXX use @out directly and do not use gpg_data_extract to store the plain text. */
41 werner 36
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     err = gpgme_op_verify (ctx, sig, dat, out);
77     if (err)
78     goto leave;
79     res = gpgme_op_verify_result (ctx);
80     if (!res || !res->signatures) {
81     err = gpg_error (GPG_ERR_NO_DATA);
82     goto leave;
83     }
84     *r_sig = res->signatures;
85     *r_ctx = ctx;
86    
87     leave:
88     if (err) {
89     gpgme_release (ctx);
90     *r_ctx = NULL;
91     }
92     if (dat)
93     gpgme_data_release (dat);
94     if (out)
95     gpgme_data_release (out);
96     gpgme_data_release (sig);
97     return err;
98     }
99    
100    
101 twoaday 256 /* Display the policy URL and/or the notation data of a signature. */
102 werner 36 static void
103 twoaday 225 show_notation_data (HWND dlg, gpgme_ctx_t ctx)
104 werner 36 {
105 twoaday 225 gpgme_sig_notation_t nota;
106 werner 36 gpgme_sig_notation_t n;
107 twoaday 225 gpgme_verify_result_t res;
108 werner 36 size_t len=0;
109     char *p;
110    
111 twoaday 225 res = gpgme_op_verify_result (ctx);
112     if (!res || !res->signatures || !res->signatures->notations)
113     return;
114     nota = res->signatures->notations;
115 werner 47 for (n=nota; n; n = n->next) {
116 werner 36 if (n->name)
117     len += strlen (n->name) + 1 + 2;
118     else
119     len += strlen ("policy URL") + 1 + 2;
120     len += strlen (n->value) + 1 + 2;
121     len += 6;
122     }
123     p = (char *)calloc (1, len+64);
124     if (!p)
125     BUG (NULL);
126     strcpy (p, "Notation data:\n");
127 werner 47 for (n=nota; n; n = n->next) {
128 werner 36 if (!n->name)
129     strcat (p, "policy url: ");
130     else {
131     strcat (p, n->name);
132     strcat (p, " : ");
133     }
134     strcat (p, "\"");
135     strcat (p, n->value);
136     strcat (p, "\"\n");
137     }
138    
139     msg_box (dlg, p, _("Signature Information"), MB_INFO);
140 twoaday 225 safe_free (p);
141 werner 36 }
142    
143    
144 twoaday 225 /* Ask the user whether to fetch the missing key from the keyserver. */
145     static BOOL
146     fetch_key_from_keyserver (HWND dlg, gpgme_signature_t sig)
147     {
148     const char *keyid;
149     int id;
150    
151     if (!sig->fpr)
152     return FALSE;
153     keyid = get_keyid_from_fpr (sig->fpr);
154     id = log_box (_("Verify"), MB_INFO|MB_YESNO,
155     _("Signature made %s using %s key ID 0x%s\n"
156     "Cannot check signature: public key not found\n\n"
157     "Do you want to try to retrieve the key from the keyserver?"),
158     strtimestamp (sig->timestamp),
159     get_key_pubalgo (sig->pubkey_algo), keyid);
160     if (id == IDNO) {
161     msg_box (dlg, get_gpg_sigstat (GPGME_SIGSUM_KEY_MISSING),
162     _("Verify"), MB_WARN);
163     return FALSE;
164     }
165    
166     /* XXX: gpgme currently does not include to return the preferred
167     keyserver that might be stored within the signature. */
168    
169 twoaday 256 if (!hkp_recv_key (dlg, default_keyserver, default_keyserver_port,
170     keyid, 0, 0))
171     keycache_update (0, keyid);
172 twoaday 225 return TRUE;
173     }
174    
175    
176 werner 36 /* Dialog procedure for the clipboard verification. */
177     BOOL CALLBACK
178     clip_verify_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
179     {
180 twoaday 219 static verlist_ctrl_t vlv = NULL;
181 twoaday 225 static gpgme_ctx_t c = NULL;
182 twoaday 219 text_input_s *ctx;
183 werner 36 gpgme_error_t err;
184     gpgme_signature_t sig = NULL, s;
185     gpg_keycache_t kc = NULL;
186     const char *det_data=NULL;
187     int rc = 0, det_len=0;
188    
189 twoaday 201 switch (msg) {
190 werner 36 case WM_INITDIALOG:
191     SetWindowText (dlg, _("Verify"));
192 twoaday 85 SetDlgItemText (dlg, IDC_VERIFY_SAVE, _("&Save"));
193 werner 36 kc = keycache_get_ctx (KEYCACHE_PUB);
194     ctx = (text_input_s *)lparam;
195     if (ctx) {
196     det_data = ctx->data;
197     det_len = ctx->length;
198     }
199 twoaday 225 err = gpg_clip_verify (ctx && ctx->length > 0,
200 werner 36 det_data, det_len, &c, &sig);
201     if (err) {
202     msg_box (dlg, gpgme_strerror (err), _("Verify"), MB_ERR);
203     if (c)
204     gpgme_release (c);
205     EndDialog (dlg, FALSE);
206     return FALSE;
207     }
208    
209     if (gpgme_err_code (sig->status) == GPG_ERR_NO_PUBKEY) {
210 twoaday 225 if (fetch_key_from_keyserver (dlg, sig)) {
211 werner 36 gpgme_release (c);
212 twoaday 225 EndDialog (dlg, FALSE);
213     return TRUE;
214 werner 36 }
215 twoaday 225 }
216 twoaday 41 else if (gpgme_err_code (sig->status) == GPG_ERR_BAD_SIGNATURE &&
217     !sig->timestamp)
218 werner 36 ;
219 twoaday 76 else if (!sig->timestamp) {
220 werner 36 msg_box (dlg, _("Invalid signature state."), _("Verify"), MB_ERR);
221     gpgme_release (c);
222     EndDialog (dlg, FALSE);
223     return FALSE;
224     }
225 twoaday 219 verlist_build (&vlv, GetDlgItem (dlg, IDC_VERIFY_SIGLIST), 0);
226     verlist_set_info_control (vlv, GetDlgItem (dlg, IDC_VERIFY_INFO));
227 werner 36
228     for (s = sig; s; s = s->next) {
229 twoaday 219 rc = verlist_add_sig (vlv, s);
230 werner 36 if (rc)
231     msg_box (dlg, _("Could not extract key or signature information."),
232     _("Verify"), MB_ERR);
233     }
234 twoaday 219
235 twoaday 225 if (!sig->notations)
236     ShowWindow (GetDlgItem (dlg, IDC_VERIFY_SIGNOT), SW_HIDE);
237 werner 36 SetForegroundWindow (dlg);
238     return TRUE;
239    
240     case WM_DESTROY:
241 twoaday 225 if (c != NULL) {
242     gpgme_release (c);
243     c = NULL;
244     }
245     if (vlv != NULL) {
246 twoaday 219 verlist_delete (vlv);
247     vlv = NULL;
248 werner 36 }
249     return FALSE;
250    
251     case WM_COMMAND:
252     switch (LOWORD (wparam )) {
253 twoaday 219 case IDCANCEL:
254     EndDialog (dlg, FALSE);
255 twoaday 225 return TRUE;
256 twoaday 219
257 werner 36 case IDOK:
258     EndDialog (dlg, TRUE);
259 twoaday 225 return TRUE;
260    
261     case IDC_VERIFY_SIGNOT:
262     show_notation_data (dlg, c);
263     return TRUE;
264 werner 36
265     case IDC_VERIFY_SAVE:
266     dialog_box_param (glob_hinst, (LPCTSTR)IDD_WINPT_FILE_SAVE, dlg,
267 twoaday 73 file_save_dlg_proc, 0, _("Save Plaintext"),
268 werner 36 IDS_WINPT_FILE_SAVE);
269     break;
270     }
271     break;
272     }
273    
274     return FALSE;
275     }

Properties

Name Value
svn:eol-style native

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26