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

Annotation of /trunk/Src/wptClipVerifyDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 24 - (hide annotations)
Sat Oct 8 10:43:08 2005 UTC (19 years, 4 months ago) by twoaday
File size: 7852 byte(s)
Bug fixes to correct some problems introduced by
the MyGPGME to GPGME port.

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26