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

Annotation of /trunk/Src/wptClipVerifyDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 208 - (hide annotations)
Mon May 1 12:22:18 2006 UTC (18 years, 10 months ago) by twoaday
File size: 8129 byte(s)
See ChangeLog.


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 twoaday 201 /* Return human printable PKA status.
142     If no pka information is available, return NULL. */
143     char*
144     get_pka_status (gpgme_signature_t sig)
145     {
146     const char *fmt;
147     char *pka_inf;
148    
149     if (sig->pka_trust == 0 || !sig->pka_address)
150     return NULL;
151     fmt = _("PKA: Verified signer's address is '%s'");
152     pka_inf = new char[strlen (fmt)+strlen (sig->pka_address)+2];
153     if (!pka_inf)
154     BUG (NULL);
155     sprintf (pka_inf, fmt, sig->pka_address);
156     return pka_inf;
157     }
158    
159    
160 werner 36 /* Dialog procedure for the clipboard verification. */
161     BOOL CALLBACK
162     clip_verify_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
163     {
164     static listview_ctrl_t lv = NULL;
165     static text_input_s *ctx = NULL;
166     gpgme_error_t err;
167     gpgme_signature_t sig = NULL, s;
168     gpg_keycache_t kc = NULL;
169     gpgme_ctx_t c=NULL;
170     const char *det_data=NULL;
171 twoaday 181 WORD port = HKP_PORT;
172 werner 36 int rc = 0, det_len=0;
173    
174 twoaday 201 switch (msg) {
175 werner 36 case WM_INITDIALOG:
176     SetWindowText (dlg, _("Verify"));
177 twoaday 85 SetDlgItemText (dlg, IDC_VERIFY_SAVE, _("&Save"));
178 werner 36 kc = keycache_get_ctx (KEYCACHE_PUB);
179     if (!kc)
180     BUG (NULL);
181     ctx = (text_input_s *)lparam;
182     if (ctx) {
183     det_data = ctx->data;
184     det_len = ctx->length;
185     }
186     err = gpg_clip_verify (ctx && ctx->length > 0,
187     det_data, det_len, &c, &sig);
188     if (err) {
189     msg_box (dlg, gpgme_strerror (err), _("Verify"), MB_ERR);
190     if (c)
191     gpgme_release (c);
192     EndDialog (dlg, FALSE);
193     return FALSE;
194     }
195    
196     if (gpgme_err_code (sig->status) == GPG_ERR_NO_PUBKEY) {
197 twoaday 41 const char *keyid;
198     const char *kserv;
199     if (!sig->fpr)
200     BUG (NULL);
201 twoaday 208 keyid = get_keyid_from_fpr (sig->fpr);
202 werner 36 rc = log_box (_("Verify"), MB_INFO|MB_YESNO,
203     _("Signature made %s using %s key ID 0x%s\n"
204     "Cannot check signature: public key not found\n\n"
205     "Do you want to try to retrieve the key from the keyserver?"),
206     strtimestamp (sig->timestamp),
207 twoaday 208 get_key_pubalgo (sig->pubkey_algo), keyid);
208 werner 36 if (rc == IDNO) {
209 twoaday 109 msg_box (dlg, get_gpg_sigstat (GPGME_SIGSUM_KEY_MISSING), _("Verify"), MB_WARN);
210 werner 36 gpgme_release (c);
211     EndDialog (dlg, FALSE);
212     return FALSE;
213     }
214     if (0) {
215     /* FIXME: does GPGME include the keyserver status
216     kserv = gpgme_sig_get_string_attr (sig, GPGME_ATTR_KEYSERVER);
217     if (kserv && strncmp (kserv, "hkp://", 6)) {
218     rc = log_box (_("Verify"), MB_INFO|MB_YESNO,
219     _("The users preferred keyserver is '%s'.\n"
220     "Do you want to use it to fetch the key?"), kserv);
221     if (rc == IDNO) {
222     kserv = default_keyserver;
223     port = default_keyserver_port;
224     }*/
225     }
226     else {
227     kserv = default_keyserver;
228     port = default_keyserver_port;
229     }
230 twoaday 41 if (!hkp_recv_key (dlg, kserv, port, keyid+8, 0, 0)) {
231 twoaday 161 keycache_update (0, keyid+8);
232 werner 36 kc = keycache_get_ctx (KEYCACHE_PUB);
233     if (!kc)
234     BUG (dlg);
235     }
236     }
237 twoaday 41 else if (gpgme_err_code (sig->status) == GPG_ERR_BAD_SIGNATURE &&
238     !sig->timestamp)
239 werner 36 ;
240 twoaday 76 else if (!sig->timestamp) {
241 werner 36 msg_box (dlg, _("Invalid signature state."), _("Verify"), MB_ERR);
242     gpgme_release (c);
243     EndDialog (dlg, FALSE);
244     return FALSE;
245     }
246     verlist_build (&lv, GetDlgItem (dlg, IDC_VERIFY_SIGLIST), 0);
247    
248     for (s = sig; s; s = s->next) {
249     rc = verlist_add_sig (lv, s);
250     if (rc)
251     msg_box (dlg, _("Could not extract key or signature information."),
252     _("Verify"), MB_ERR);
253     }
254     if (sig->exp_timestamp > (DWORD)time (NULL))
255 twoaday 201 SetDlgItemText (dlg, IDC_VERIFY_INFO, _("The signature is expired!"));
256     else {
257     char *pka_info = get_pka_status (sig);
258     if (pka_info != NULL) {
259     SetDlgItemText (dlg, IDC_VERIFY_INFO, pka_info);
260     free_if_alloc (pka_info);
261     }
262     }
263 werner 36 if (sig->notations)
264     show_notation_data (dlg, sig->notations);
265     gpgme_release (c);
266     SetForegroundWindow (dlg);
267     return TRUE;
268    
269     case WM_DESTROY:
270     if (lv) {
271     listview_release (lv);
272     lv = NULL;
273     }
274     return FALSE;
275    
276     case WM_SYSCOMMAND:
277     if (LOWORD (wparam) == SC_CLOSE)
278     EndDialog (dlg, TRUE);
279     return FALSE;
280    
281     case WM_COMMAND:
282     switch (LOWORD (wparam )) {
283     case IDOK:
284     EndDialog (dlg, TRUE);
285     return FALSE;
286    
287     case IDC_VERIFY_SAVE:
288     dialog_box_param (glob_hinst, (LPCTSTR)IDD_WINPT_FILE_SAVE, dlg,
289 twoaday 73 file_save_dlg_proc, 0, _("Save Plaintext"),
290 werner 36 IDS_WINPT_FILE_SAVE);
291     break;
292     }
293     break;
294     }
295    
296     return FALSE;
297     }
298    

Properties

Name Value
svn:eol-style native

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26