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

Annotation of /trunk/Src/wptClipVerifyDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 85 - (hide annotations)
Fri Nov 18 07:20:40 2005 UTC (19 years, 3 months ago) by twoaday
File size: 7589 byte(s)
2005-11-17  Timo Schulz  <ts@g10code.com>
 
        * wptGPG.cpp (check_last_gnupg_access): Kludge to avoid that
        the cache will be loaded twice.
        * wptRegistry.cpp (regist_inst_winpt): More comments.
        * wptKeyManagerDlg.cpp (do_center_window): Make sure that
        neg. coordinates are never used.
        * wptClipVerifyDlg.cpp (clip_verify_dlg_proc): Localize all
        strings.
        * wptPassphraseCB.cpp (passphrase_callback_proc): Likewise.
        * wptFileManagerDlg.cpp (filemanager_dlg_proc): Localize menu
        and save 'AlwaysOnTop' in the registry.
         

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

Properties

Name Value
svn:eol-style native

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26