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

Annotation of /trunk/Src/wptClipVerifyDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 36 - (hide annotations)
Thu Oct 27 15:25:13 2005 UTC (19 years, 4 months ago) by werner
File size: 7600 byte(s)
First set of changes to use autotools for building.
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 twoaday 26
21 werner 36 #ifdef HAVE_CONFIG_H
22     #include <config.h>
23     #endif
24    
25     #include <windows.h>
26     #include <windows.h>
27    
28     #include "../resource.h"
29     #include "wptGPG.h"
30     #include "wptTypes.h"
31     #include "wptCommonCtl.h"
32     #include "wptKeylist.h"
33     #include "wptW32API.h"
34     #include "wptKeyserver.h"
35     #include "wptNLS.h"
36     #include "wptContext.h" /* for passwd_s */
37     #include "wptDlgs.h"
38     #include "wptErrors.h"
39     #include "wptVersion.h"
40    
41     /* XXX use out directly and do not use gpg_data_extract to store the plain text. */
42    
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     gpgme_error_t
50     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    
78     err = gpgme_op_verify (ctx, sig, dat, out);
79     if (err)
80     goto leave;
81     res = gpgme_op_verify_result (ctx);
82     if (!res || !res->signatures) {
83     err = gpg_error (GPG_ERR_NO_DATA);
84     goto leave;
85     }
86     *r_sig = res->signatures;
87     *r_ctx = ctx;
88    
89     leave:
90     if (err) {
91     gpgme_release (ctx);
92     *r_ctx = NULL;
93     }
94     if (dat)
95     gpgme_data_release (dat);
96     if (out)
97     gpgme_data_release (out);
98     gpgme_data_release (sig);
99     return err;
100     }
101    
102    
103     /* Display the policy URL and the notation data of a signature.
104     If @not is NULL, it is assumed there is no data.
105     @dlg is the handle to the calling dialog. */
106     static void
107     show_notation_data (HWND dlg, gpgme_sig_notation_t not)
108     {
109     gpgme_sig_notation_t n;
110     size_t len=0;
111     char *p;
112    
113     for (n=not; n; n = n->next) {
114     if (n->name)
115     len += strlen (n->name) + 1 + 2;
116     else
117     len += strlen ("policy URL") + 1 + 2;
118     len += strlen (n->value) + 1 + 2;
119     len += 6;
120     }
121     p = (char *)calloc (1, len+64);
122     if (!p)
123     BUG (NULL);
124     strcpy (p, "Notation data:\n");
125     for (n=not; n; n = n->next) {
126     if (!n->name)
127     strcat (p, "policy url: ");
128     else {
129     strcat (p, n->name);
130     strcat (p, " : ");
131     }
132     strcat (p, "\"");
133     strcat (p, n->value);
134     strcat (p, "\"\n");
135     }
136    
137     msg_box (dlg, p, _("Signature Information"), MB_INFO);
138     free (p);
139     }
140    
141    
142     /* Dialog procedure for the clipboard verification. */
143     BOOL CALLBACK
144     clip_verify_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
145     {
146     static listview_ctrl_t lv = NULL;
147     static text_input_s *ctx = NULL;
148     gpgme_error_t err;
149     gpgme_signature_t sig = NULL, s;
150     gpg_keycache_t kc = NULL;
151     gpgme_ctx_t c=NULL;
152     char keyid[16+1];
153     const char *det_data=NULL;
154     u16 port = HKP_PORT;
155     int rc = 0, det_len=0;
156    
157     switch( msg ) {
158     case WM_INITDIALOG:
159     #ifndef LANG_DE
160     SetWindowText (dlg, _("Verify"));
161     #endif
162     kc = keycache_get_ctx (KEYCACHE_PUB);
163     if (!kc)
164     BUG (NULL);
165     ctx = (text_input_s *)lparam;
166     if (ctx) {
167     det_data = ctx->data;
168     det_len = ctx->length;
169     }
170     err = gpg_clip_verify (ctx && ctx->length > 0,
171     det_data, det_len, &c, &sig);
172     if (err) {
173     msg_box (dlg, gpgme_strerror (err), _("Verify"), MB_ERR);
174     if (c)
175     gpgme_release (c);
176     EndDialog (dlg, FALSE);
177     return FALSE;
178     }
179    
180     if (gpgme_err_code (sig->status) == GPG_ERR_NO_PUBKEY) {
181     const char * kserv;
182     const char *fpr = sig->fpr;
183     if (!fpr)
184     fpr = "0xDEADBEEF";
185     if (strlen (fpr) == 40)
186     fpr += 32;
187     else
188     fpr += 24;
189     rc = log_box (_("Verify"), MB_INFO|MB_YESNO,
190     _("Signature made %s using %s key ID 0x%s\n"
191     "Cannot check signature: public key not found\n\n"
192     "Do you want to try to retrieve the key from the keyserver?"),
193     strtimestamp (sig->timestamp),
194     get_key_pubalgo (sig->pubkey_algo), fpr);
195     if (rc == IDNO) {
196     msg_box (dlg, gpg_sigstat[GPGME_SIG_STAT_NOKEY], _("Verify"), MB_WARN);
197     gpgme_release (c);
198     EndDialog (dlg, FALSE);
199     return FALSE;
200     }
201     if (0) {
202     /* FIXME: does GPGME include the keyserver status
203     kserv = gpgme_sig_get_string_attr (sig, GPGME_ATTR_KEYSERVER);
204     if (kserv && strncmp (kserv, "hkp://", 6)) {
205     rc = log_box (_("Verify"), MB_INFO|MB_YESNO,
206     _("The users preferred keyserver is '%s'.\n"
207     "Do you want to use it to fetch the key?"), kserv);
208     if (rc == IDNO) {
209     kserv = default_keyserver;
210     port = default_keyserver_port;
211     }*/
212     }
213    
214     else {
215     kserv = default_keyserver;
216     port = default_keyserver_port;
217     }
218     if (!hkp_recv_key (dlg, kserv, port, keyid, 0, 0)) {
219     keycache_reload (dlg);
220     kc = keycache_get_ctx (KEYCACHE_PUB);
221     if (!kc)
222     BUG (dlg);
223     }
224     }
225     else if (gpgme_err_code (sig->status) == GPG_ERR_BAD_SIGNATURE && !sig->timestamp)
226     ;
227     else if (!sig->timestamp || !sig->validity) {
228     msg_box (dlg, _("Invalid signature state."), _("Verify"), MB_ERR);
229     gpgme_release (c);
230     EndDialog (dlg, FALSE);
231     return FALSE;
232     }
233     verlist_build (&lv, GetDlgItem (dlg, IDC_VERIFY_SIGLIST), 0);
234    
235     for (s = sig; s; s = s->next) {
236     rc = verlist_add_sig (lv, s);
237     if (rc)
238     msg_box (dlg, _("Could not extract key or signature information."),
239     _("Verify"), MB_ERR);
240     }
241     if (sig->exp_timestamp > (DWORD)time (NULL))
242     SetDlgItemText( dlg, IDC_VERIFY_INFO, _("The signature is expired!") );
243     if (sig->notations)
244     show_notation_data (dlg, sig->notations);
245     gpgme_release (c);
246     SetForegroundWindow (dlg);
247     set_active_window (dlg);
248     return TRUE;
249    
250     case WM_DESTROY:
251     reset_active_window ();
252     if (lv) {
253     listview_release (lv);
254     lv = NULL;
255     }
256     return FALSE;
257    
258     case WM_SYSCOMMAND:
259     if (LOWORD (wparam) == SC_CLOSE)
260     EndDialog (dlg, TRUE);
261     return FALSE;
262    
263     case WM_COMMAND:
264     switch (LOWORD (wparam )) {
265     case IDOK:
266     EndDialog (dlg, TRUE);
267     return FALSE;
268    
269     case IDC_VERIFY_SAVE:
270     dialog_box_param (glob_hinst, (LPCTSTR)IDD_WINPT_FILE_SAVE, dlg,
271     file_save_dlg_proc, NULL, _("Save Plaintext"),
272     IDS_WINPT_FILE_SAVE);
273     break;
274     }
275     break;
276     }
277    
278     return FALSE;
279     }
280    

Properties

Name Value
svn:eol-style native

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26