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

Annotation of /trunk/Src/wptClipVerifyDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 41 - (hide annotations)
Fri Oct 28 07:15:26 2005 UTC (19 years, 4 months ago) by twoaday
File size: 7541 byte(s)
A lot of bug fixes. 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 twoaday 26
21 werner 36 #include <windows.h>
22 twoaday 41 #include <time.h>
23 werner 36
24     #include "../resource.h"
25     #include "wptGPG.h"
26     #include "wptTypes.h"
27     #include "wptCommonCtl.h"
28     #include "wptKeylist.h"
29     #include "wptW32API.h"
30     #include "wptKeyserver.h"
31     #include "wptNLS.h"
32     #include "wptContext.h" /* for passwd_s */
33     #include "wptDlgs.h"
34     #include "wptErrors.h"
35     #include "wptVersion.h"
36    
37     /* XXX use out directly and do not use gpg_data_extract to store the plain text. */
38    
39    
40     /* Verify data from the clipboard. If @is_detached is set, a detached
41     signature is assumed with the data the signature was calculated over
42     in @det_data. The context is returned in @r_ctx and the signature
43     in @r_sig.
44     Return value: 0 on success. */
45     gpgme_error_t
46     gpg_clip_verify (int is_detached,
47     const char *det_data, size_t det_len,
48     gpgme_ctx_t *r_ctx,
49     gpgme_signature_t *r_sig)
50     {
51     gpgme_error_t err;
52     gpgme_ctx_t ctx;
53     gpgme_data_t dat = NULL;
54     gpgme_data_t out = NULL;
55     gpgme_data_t sig = NULL;
56     gpgme_verify_result_t res;
57    
58     if (is_detached) {
59     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     goto leave;
70     err = gpgme_data_new (&out);
71     if (err)
72     goto leave;
73    
74     err = gpgme_op_verify (ctx, sig, dat, out);
75     if (err)
76     goto leave;
77     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     if (out)
93     gpgme_data_release (out);
94     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     len += strlen (n->name) + 1 + 2;
112     else
113     len += strlen ("policy URL") + 1 + 2;
114     len += strlen (n->value) + 1 + 2;
115     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     strcat (p, "\"");
129     strcat (p, n->value);
130     strcat (p, "\"\n");
131     }
132    
133     msg_box (dlg, p, _("Signature Information"), MB_INFO);
134     free (p);
135     }
136    
137    
138     /* Dialog procedure for the clipboard verification. */
139     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     gpgme_signature_t sig = NULL, s;
146     gpg_keycache_t kc = NULL;
147     gpgme_ctx_t c=NULL;
148     const char *det_data=NULL;
149     u16 port = HKP_PORT;
150     int rc = 0, det_len=0;
151    
152     switch( msg ) {
153     case WM_INITDIALOG:
154     #ifndef LANG_DE
155     SetWindowText (dlg, _("Verify"));
156     #endif
157     kc = keycache_get_ctx (KEYCACHE_PUB);
158     if (!kc)
159     BUG (NULL);
160     ctx = (text_input_s *)lparam;
161     if (ctx) {
162     det_data = ctx->data;
163     det_len = ctx->length;
164     }
165     err = gpg_clip_verify (ctx && ctx->length > 0,
166     det_data, det_len, &c, &sig);
167     if (err) {
168     msg_box (dlg, gpgme_strerror (err), _("Verify"), MB_ERR);
169     if (c)
170     gpgme_release (c);
171     EndDialog (dlg, FALSE);
172     return FALSE;
173     }
174    
175     if (gpgme_err_code (sig->status) == GPG_ERR_NO_PUBKEY) {
176 twoaday 41 const char *keyid;
177     const char *kserv;
178     if (!sig->fpr)
179     BUG (NULL);
180     if (strlen (sig->fpr) == 40)
181     keyid = sig->fpr+24;
182     else
183     keyid = sig->fpr+16;
184 werner 36 rc = log_box (_("Verify"), MB_INFO|MB_YESNO,
185     _("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     strtimestamp (sig->timestamp),
189 twoaday 41 get_key_pubalgo (sig->pubkey_algo), keyid+8);
190 werner 36 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     return FALSE;
195     }
196     if (0) {
197     /* FIXME: does GPGME include the keyserver status
198     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     }*/
207     }
208     else {
209     kserv = default_keyserver;
210     port = default_keyserver_port;
211     }
212 twoaday 41 if (!hkp_recv_key (dlg, kserv, port, keyid+8, 0, 0)) {
213 werner 36 keycache_reload (dlg);
214     kc = keycache_get_ctx (KEYCACHE_PUB);
215     if (!kc)
216     BUG (dlg);
217     }
218     }
219 twoaday 41 else if (gpgme_err_code (sig->status) == GPG_ERR_BAD_SIGNATURE &&
220     !sig->timestamp)
221 werner 36 ;
222     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     return FALSE;
227     }
228     verlist_build (&lv, GetDlgItem (dlg, IDC_VERIFY_SIGLIST), 0);
229    
230     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     }
236     if (sig->exp_timestamp > (DWORD)time (NULL))
237     SetDlgItemText( dlg, IDC_VERIFY_INFO, _("The signature is expired!") );
238     if (sig->notations)
239     show_notation_data (dlg, sig->notations);
240     gpgme_release (c);
241     SetForegroundWindow (dlg);
242     set_active_window (dlg);
243     return TRUE;
244    
245     case WM_DESTROY:
246     reset_active_window ();
247     if (lv) {
248     listview_release (lv);
249     lv = NULL;
250     }
251     return FALSE;
252    
253     case WM_SYSCOMMAND:
254     if (LOWORD (wparam) == SC_CLOSE)
255     EndDialog (dlg, TRUE);
256     return FALSE;
257    
258     case WM_COMMAND:
259     switch (LOWORD (wparam )) {
260     case IDOK:
261     EndDialog (dlg, TRUE);
262     return FALSE;
263    
264     case IDC_VERIFY_SAVE:
265     dialog_box_param (glob_hinst, (LPCTSTR)IDD_WINPT_FILE_SAVE, dlg,
266     file_save_dlg_proc, NULL, _("Save Plaintext"),
267     IDS_WINPT_FILE_SAVE);
268     break;
269     }
270     break;
271     }
272    
273     return FALSE;
274     }
275    

Properties

Name Value
svn:eol-style native

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26