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

Annotation of /trunk/Src/wptClipVerifyDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 25 - (hide annotations)
Wed Oct 12 10:04:26 2005 UTC (19 years, 4 months ago) by twoaday
File size: 7805 byte(s)
First testing phase finished.
Provide bug fixes for a lot of (minor) problems.

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26