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

Contents of /trunk/Src/wptClipVerifyDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 462 - (show annotations)
Sat Oct 6 10:27:59 2012 UTC (12 years, 4 months ago) by twoaday
File size: 6211 byte(s)
2012-10-06  Timo Schulz  <twoaday@gmx.net>

        * wptClipVerifyDlg.cpp (gpg_clip_verify): Use clipboard
	functions with utf8 support.
	* wptClipSignDlg.cpp (gpg_clip_sign): Likewise.
			

1 /* wptClipVerifyDlg.cpp - WinPT verify dialog
2 * Copyright (C) 2001-2006 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 #ifdef HAVE_CONFIG_H
17 #include <config.h>
18 #endif
19
20 #include <windows.h>
21 #include <time.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 #include "StringBuffer.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 static 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_utf8_new_from_clipboard(&sig, 0, NULL);
68 if (err)
69 goto leave;
70 err = gpgme_data_new (&out);
71 if (err)
72 goto leave;
73 err = gpgme_op_verify (ctx, sig, dat, out);
74 if (err)
75 goto leave;
76 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 if (out)
92 gpgme_data_release (out);
93 gpgme_data_release (sig);
94 return err;
95 }
96
97
98 /* Display the policy URL and/or the notation data of a signature. */
99 static void
100 show_notation_data (HWND dlg, gpgme_ctx_t ctx)
101 {
102 gpgme_sig_notation_t nota;
103 gpgme_sig_notation_t n;
104 gpgme_verify_result_t res;
105 StringBuffer p;
106
107 res = gpgme_op_verify_result (ctx);
108 if (!res || !res->signatures || !res->signatures->notations)
109 return;
110 nota = res->signatures->notations;
111
112 p = "Notation data:\n";
113 for (n=nota; n; n = n->next) {
114 if (!n->name)
115 p = p + "policy url: ";
116 else
117 p = p + n->name + " : " ;
118 p = p + "\"" + n->value + "\"\n";
119 }
120
121 msg_box (dlg, p.getBuffer (), _("Signature Information"), MB_INFO);
122 }
123
124
125 /* Dialog procedure for the clipboard verification. */
126 BOOL CALLBACK
127 clip_verify_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
128 {
129 static verlist_ctrl_t vlv = NULL;
130 static gpgme_ctx_t c = NULL;
131 text_input_s *ctx;
132 gpgme_error_t err;
133 gpgme_signature_t sig = NULL, s;
134 const char *det_data=NULL;
135 int rc = 0, det_len=0;
136
137 switch (msg) {
138 case WM_INITDIALOG:
139 SetWindowText (dlg, _("Verify"));
140 SetDlgItemText (dlg, IDC_VERIFY_SAVE, _("&Save"));
141 ctx = (text_input_s *)lparam;
142 if (ctx) {
143 det_data = ctx->data;
144 det_len = ctx->length;
145 }
146 err = gpg_clip_verify (ctx && ctx->length > 0,
147 det_data, det_len, &c, &sig);
148 if (err) {
149 msg_box (dlg, gpgme_strerror (err), _("Verify"), MB_ERR);
150 EndDialog (dlg, FALSE);
151 return FALSE;
152 }
153
154 if (gpgme_err_code (sig->status) == GPG_ERR_NO_PUBKEY) {
155 gpgme_verify_result_t res;
156
157 if (fetch_key_from_keyserver (dlg, sig)) {
158 EndDialog (dlg, FALSE);
159 return TRUE;
160 }
161 /* We need to call GPG again to get the real sig status. */
162 err = gpg_clip_verify (ctx && ctx->length > 0,
163 det_data, det_len, &c, &sig);
164 if (err) {
165 msg_box (dlg, gpgme_strerror (err), _("Verify"), MB_ERR);
166 EndDialog (dlg, FALSE);
167 return TRUE;
168 }
169 /* Refresh the pointer because a new GPG instance has been
170 created for the new verify operation. */
171 res = gpgme_op_verify_result (c);
172 if (!res || res->signatures == NULL)
173 BUG (0);
174 sig = res->signatures;
175
176 }
177
178 if (gpgme_err_code (sig->status) == GPG_ERR_BAD_SIGNATURE &&
179 !sig->timestamp)
180 ;
181 else if (!sig->timestamp) {
182 msg_box (dlg, _("Invalid signature state."), _("Verify"), MB_ERR);
183 EndDialog (dlg, FALSE);
184 return FALSE;
185 }
186 verlist_build (&vlv, GetDlgItem (dlg, IDC_VERIFY_SIGLIST), 0);
187 verlist_set_info_control (vlv, GetDlgItem (dlg, IDC_VERIFY_INFO));
188
189 for (s = sig; s; s = s->next) {
190 rc = verlist_add_sig (vlv, s);
191 if (rc) {
192 msg_box (dlg, _("Error while adding signature information."),
193 _("Verify"), MB_ERR);
194 break;
195 }
196 }
197
198 if (!sig->notations)
199 ShowWindow (GetDlgItem (dlg, IDC_VERIFY_SIGNOT), SW_HIDE);
200 SetForegroundWindow (dlg);
201 return TRUE;
202
203 case WM_DESTROY:
204 if (c != NULL) {
205 gpgme_release (c);
206 c = NULL;
207 }
208 if (vlv != NULL) {
209 verlist_delete (vlv);
210 vlv = NULL;
211 }
212 return FALSE;
213
214 case WM_COMMAND:
215 switch (LOWORD (wparam )) {
216 case IDCANCEL:
217 EndDialog (dlg, FALSE);
218 return TRUE;
219
220 case IDOK:
221 EndDialog (dlg, TRUE);
222 return TRUE;
223
224 case IDC_VERIFY_SIGNOT:
225 show_notation_data (dlg, c);
226 return TRUE;
227
228 case IDC_VERIFY_SAVE:
229 dialog_box_param (glob_hinst, (LPCTSTR)IDD_WINPT_FILE_SAVE, dlg,
230 file_save_dlg_proc, 0, _("Save Plaintext"),
231 IDS_WINPT_FILE_SAVE);
232 break;
233 }
234 break;
235 }
236
237 return FALSE;
238 }

Properties

Name Value
svn:eol-style native

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26