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

Annotation of /trunk/Src/wptClipVerifyDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 23 - (hide annotations)
Fri Sep 30 10:10:16 2005 UTC (19 years, 5 months ago) by twoaday
File size: 7419 byte(s)
Almost finished phase 1 of the WinPT GPGME port.
Still need more cleanup, comments and tests.


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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26