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

Annotation of /trunk/Src/wptClipVerifyDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 278 - (hide annotations)
Mon Jan 15 22:02:04 2007 UTC (18 years, 1 month ago) by twoaday
File size: 6482 byte(s)
See ChangeLog.


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 twoaday 278 #include "StringBuffer.h"
40 werner 36
41 twoaday 256 /* XXX use @out directly and do not use gpg_data_extract to store the plain text. */
42 werner 36
43    
44     /* Verify data from the clipboard. If @is_detached is set, a detached
45     signature is assumed with the data the signature was calculated over
46     in @det_data. The context is returned in @r_ctx and the signature
47     in @r_sig.
48     Return value: 0 on success. */
49 twoaday 271 static gpgme_error_t
50 werner 36 gpg_clip_verify (int is_detached,
51     const char *det_data, size_t det_len,
52     gpgme_ctx_t *r_ctx,
53     gpgme_signature_t *r_sig)
54     {
55     gpgme_error_t err;
56     gpgme_ctx_t ctx;
57     gpgme_data_t dat = NULL;
58     gpgme_data_t out = NULL;
59     gpgme_data_t sig = NULL;
60     gpgme_verify_result_t res;
61    
62     if (is_detached) {
63     err = gpgme_data_new_from_mem (&dat, det_data, det_len, 1);
64     if (err)
65     return err;
66     }
67    
68     err = gpgme_new (&ctx);
69     if (err)
70     goto leave;
71     err = gpg_data_new_from_clipboard (&sig, 0);
72     if (err)
73     goto leave;
74     err = gpgme_data_new (&out);
75     if (err)
76     goto leave;
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 twoaday 256 /* Display the policy URL and/or the notation data of a signature. */
103 werner 36 static void
104 twoaday 225 show_notation_data (HWND dlg, gpgme_ctx_t ctx)
105 werner 36 {
106 twoaday 225 gpgme_sig_notation_t nota;
107 werner 36 gpgme_sig_notation_t n;
108 twoaday 225 gpgme_verify_result_t res;
109 twoaday 278 StringBuffer p;
110 werner 36
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 twoaday 278
116     p = "Notation data:\n";
117 werner 47 for (n=nota; n; n = n->next) {
118 twoaday 278 if (!n->name)
119     p = p + "policy url: ";
120 werner 36 else
121 twoaday 278 p = p + n->name + " : " ;
122     p = p + "\"" + n->value + "\"\n";
123 werner 36 }
124    
125 twoaday 278 msg_box (dlg, p.getBuffer (), _("Signature Information"), MB_INFO);
126 werner 36 }
127    
128    
129     /* Dialog procedure for the clipboard verification. */
130     BOOL CALLBACK
131     clip_verify_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
132     {
133 twoaday 219 static verlist_ctrl_t vlv = NULL;
134 twoaday 225 static gpgme_ctx_t c = NULL;
135 twoaday 219 text_input_s *ctx;
136 werner 36 gpgme_error_t err;
137     gpgme_signature_t sig = NULL, s;
138     gpg_keycache_t kc = NULL;
139     const char *det_data=NULL;
140     int rc = 0, det_len=0;
141    
142 twoaday 201 switch (msg) {
143 werner 36 case WM_INITDIALOG:
144     SetWindowText (dlg, _("Verify"));
145 twoaday 85 SetDlgItemText (dlg, IDC_VERIFY_SAVE, _("&Save"));
146 werner 36 kc = keycache_get_ctx (KEYCACHE_PUB);
147     ctx = (text_input_s *)lparam;
148     if (ctx) {
149     det_data = ctx->data;
150     det_len = ctx->length;
151     }
152 twoaday 225 err = gpg_clip_verify (ctx && ctx->length > 0,
153 werner 36 det_data, det_len, &c, &sig);
154     if (err) {
155     msg_box (dlg, gpgme_strerror (err), _("Verify"), MB_ERR);
156     EndDialog (dlg, FALSE);
157     return FALSE;
158     }
159    
160     if (gpgme_err_code (sig->status) == GPG_ERR_NO_PUBKEY) {
161 twoaday 271 gpgme_verify_result_t res;
162    
163 twoaday 225 if (fetch_key_from_keyserver (dlg, sig)) {
164     EndDialog (dlg, FALSE);
165     return TRUE;
166 werner 36 }
167 twoaday 271 /* We need to call GPG again to get the real sig status. */
168     err = gpg_clip_verify (ctx && ctx->length > 0,
169     det_data, det_len, &c, &sig);
170     if (err) {
171     msg_box (dlg, gpgme_strerror (err), _("Verify"), MB_ERR);
172     EndDialog (dlg, FALSE);
173     return TRUE;
174     }
175     /* Refresh the pointer because a new GPG instance has been
176     created for the new verify operation. */
177     res = gpgme_op_verify_result (c);
178     if (!res || res->signatures == NULL)
179     BUG (0);
180     sig = res->signatures;
181    
182 twoaday 225 }
183 twoaday 271
184     if (gpgme_err_code (sig->status) == GPG_ERR_BAD_SIGNATURE &&
185 twoaday 41 !sig->timestamp)
186 werner 36 ;
187 twoaday 76 else if (!sig->timestamp) {
188 werner 36 msg_box (dlg, _("Invalid signature state."), _("Verify"), MB_ERR);
189     EndDialog (dlg, FALSE);
190     return FALSE;
191     }
192 twoaday 219 verlist_build (&vlv, GetDlgItem (dlg, IDC_VERIFY_SIGLIST), 0);
193     verlist_set_info_control (vlv, GetDlgItem (dlg, IDC_VERIFY_INFO));
194 werner 36
195     for (s = sig; s; s = s->next) {
196 twoaday 219 rc = verlist_add_sig (vlv, s);
197 twoaday 271 if (rc) {
198     msg_box (dlg, _("Error while adding signature information."),
199 werner 36 _("Verify"), MB_ERR);
200 twoaday 271 break;
201     }
202 werner 36 }
203 twoaday 219
204 twoaday 225 if (!sig->notations)
205     ShowWindow (GetDlgItem (dlg, IDC_VERIFY_SIGNOT), SW_HIDE);
206 werner 36 SetForegroundWindow (dlg);
207     return TRUE;
208    
209     case WM_DESTROY:
210 twoaday 225 if (c != NULL) {
211     gpgme_release (c);
212     c = NULL;
213     }
214     if (vlv != NULL) {
215 twoaday 219 verlist_delete (vlv);
216     vlv = NULL;
217 werner 36 }
218     return FALSE;
219    
220     case WM_COMMAND:
221     switch (LOWORD (wparam )) {
222 twoaday 219 case IDCANCEL:
223     EndDialog (dlg, FALSE);
224 twoaday 225 return TRUE;
225 twoaday 219
226 werner 36 case IDOK:
227     EndDialog (dlg, TRUE);
228 twoaday 225 return TRUE;
229    
230     case IDC_VERIFY_SIGNOT:
231     show_notation_data (dlg, c);
232     return TRUE;
233 werner 36
234     case IDC_VERIFY_SAVE:
235     dialog_box_param (glob_hinst, (LPCTSTR)IDD_WINPT_FILE_SAVE, dlg,
236 twoaday 73 file_save_dlg_proc, 0, _("Save Plaintext"),
237 werner 36 IDS_WINPT_FILE_SAVE);
238     break;
239     }
240     break;
241     }
242    
243     return FALSE;
244     }

Properties

Name Value
svn:eol-style native

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26