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

Annotation of /trunk/Src/wptClipVerifyDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 271 - (hide annotations)
Sun Nov 5 08:57:45 2006 UTC (18 years, 3 months ago) by twoaday
File size: 6784 byte(s)


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 twoaday 271 static gpgme_error_t
49 werner 36 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     /* Dialog procedure for the clipboard verification. */
145     BOOL CALLBACK
146     clip_verify_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
147     {
148 twoaday 219 static verlist_ctrl_t vlv = NULL;
149 twoaday 225 static gpgme_ctx_t c = NULL;
150 twoaday 219 text_input_s *ctx;
151 werner 36 gpgme_error_t err;
152     gpgme_signature_t sig = NULL, s;
153     gpg_keycache_t kc = NULL;
154     const char *det_data=NULL;
155     int rc = 0, det_len=0;
156    
157 twoaday 201 switch (msg) {
158 werner 36 case WM_INITDIALOG:
159     SetWindowText (dlg, _("Verify"));
160 twoaday 85 SetDlgItemText (dlg, IDC_VERIFY_SAVE, _("&Save"));
161 werner 36 kc = keycache_get_ctx (KEYCACHE_PUB);
162     ctx = (text_input_s *)lparam;
163     if (ctx) {
164     det_data = ctx->data;
165     det_len = ctx->length;
166     }
167 twoaday 225 err = gpg_clip_verify (ctx && ctx->length > 0,
168 werner 36 det_data, det_len, &c, &sig);
169     if (err) {
170     msg_box (dlg, gpgme_strerror (err), _("Verify"), MB_ERR);
171     EndDialog (dlg, FALSE);
172     return FALSE;
173     }
174    
175     if (gpgme_err_code (sig->status) == GPG_ERR_NO_PUBKEY) {
176 twoaday 271 gpgme_verify_result_t res;
177    
178 twoaday 225 if (fetch_key_from_keyserver (dlg, sig)) {
179     EndDialog (dlg, FALSE);
180     return TRUE;
181 werner 36 }
182 twoaday 271 /* We need to call GPG again to get the real sig status. */
183     err = gpg_clip_verify (ctx && ctx->length > 0,
184     det_data, det_len, &c, &sig);
185     if (err) {
186     msg_box (dlg, gpgme_strerror (err), _("Verify"), MB_ERR);
187     EndDialog (dlg, FALSE);
188     return TRUE;
189     }
190     /* Refresh the pointer because a new GPG instance has been
191     created for the new verify operation. */
192     res = gpgme_op_verify_result (c);
193     if (!res || res->signatures == NULL)
194     BUG (0);
195     sig = res->signatures;
196    
197 twoaday 225 }
198 twoaday 271
199     if (gpgme_err_code (sig->status) == GPG_ERR_BAD_SIGNATURE &&
200 twoaday 41 !sig->timestamp)
201 werner 36 ;
202 twoaday 76 else if (!sig->timestamp) {
203 werner 36 msg_box (dlg, _("Invalid signature state."), _("Verify"), MB_ERR);
204     EndDialog (dlg, FALSE);
205     return FALSE;
206     }
207 twoaday 219 verlist_build (&vlv, GetDlgItem (dlg, IDC_VERIFY_SIGLIST), 0);
208     verlist_set_info_control (vlv, GetDlgItem (dlg, IDC_VERIFY_INFO));
209 werner 36
210     for (s = sig; s; s = s->next) {
211 twoaday 219 rc = verlist_add_sig (vlv, s);
212 twoaday 271 if (rc) {
213     msg_box (dlg, _("Error while adding signature information."),
214 werner 36 _("Verify"), MB_ERR);
215 twoaday 271 break;
216     }
217 werner 36 }
218 twoaday 219
219 twoaday 225 if (!sig->notations)
220     ShowWindow (GetDlgItem (dlg, IDC_VERIFY_SIGNOT), SW_HIDE);
221 werner 36 SetForegroundWindow (dlg);
222     return TRUE;
223    
224     case WM_DESTROY:
225 twoaday 225 if (c != NULL) {
226     gpgme_release (c);
227     c = NULL;
228     }
229     if (vlv != NULL) {
230 twoaday 219 verlist_delete (vlv);
231     vlv = NULL;
232 werner 36 }
233     return FALSE;
234    
235     case WM_COMMAND:
236     switch (LOWORD (wparam )) {
237 twoaday 219 case IDCANCEL:
238     EndDialog (dlg, FALSE);
239 twoaday 225 return TRUE;
240 twoaday 219
241 werner 36 case IDOK:
242     EndDialog (dlg, TRUE);
243 twoaday 225 return TRUE;
244    
245     case IDC_VERIFY_SIGNOT:
246     show_notation_data (dlg, c);
247     return TRUE;
248 werner 36
249     case IDC_VERIFY_SAVE:
250     dialog_box_param (glob_hinst, (LPCTSTR)IDD_WINPT_FILE_SAVE, dlg,
251 twoaday 73 file_save_dlg_proc, 0, _("Save Plaintext"),
252 werner 36 IDS_WINPT_FILE_SAVE);
253     break;
254     }
255     break;
256     }
257    
258     return FALSE;
259     }

Properties

Name Value
svn:eol-style native

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26