1 |
werner |
36 |
/* wptClipVerifyDlg.cpp - WinPT verify dialog |
2 |
twoaday |
256 |
* Copyright (C) 2001-2006 Timo Schulz |
3 |
werner |
36 |
* |
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 |
twoaday |
328 |
* GNU General Public License for more details. |
15 |
werner |
36 |
*/ |
16 |
werner |
42 |
#ifdef HAVE_CONFIG_H |
17 |
|
|
#include <config.h> |
18 |
|
|
#endif |
19 |
|
|
|
20 |
werner |
36 |
#include <windows.h> |
21 |
twoaday |
41 |
#include <time.h> |
22 |
werner |
36 |
|
23 |
werner |
47 |
#include "resource.h" |
24 |
werner |
36 |
#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 |
twoaday |
278 |
#include "StringBuffer.h" |
36 |
werner |
36 |
|
37 |
twoaday |
256 |
/* XXX use @out directly and do not use gpg_data_extract to store the plain text. */ |
38 |
werner |
36 |
|
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 |
twoaday |
271 |
static gpgme_error_t |
46 |
werner |
36 |
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 |
|
|
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 |
twoaday |
256 |
/* Display the policy URL and/or the notation data of a signature. */ |
99 |
werner |
36 |
static void |
100 |
twoaday |
225 |
show_notation_data (HWND dlg, gpgme_ctx_t ctx) |
101 |
werner |
36 |
{ |
102 |
twoaday |
225 |
gpgme_sig_notation_t nota; |
103 |
werner |
36 |
gpgme_sig_notation_t n; |
104 |
twoaday |
225 |
gpgme_verify_result_t res; |
105 |
twoaday |
278 |
StringBuffer p; |
106 |
werner |
36 |
|
107 |
twoaday |
225 |
res = gpgme_op_verify_result (ctx); |
108 |
|
|
if (!res || !res->signatures || !res->signatures->notations) |
109 |
|
|
return; |
110 |
|
|
nota = res->signatures->notations; |
111 |
twoaday |
278 |
|
112 |
|
|
p = "Notation data:\n"; |
113 |
werner |
47 |
for (n=nota; n; n = n->next) { |
114 |
twoaday |
278 |
if (!n->name) |
115 |
|
|
p = p + "policy url: "; |
116 |
werner |
36 |
else |
117 |
twoaday |
278 |
p = p + n->name + " : " ; |
118 |
|
|
p = p + "\"" + n->value + "\"\n"; |
119 |
werner |
36 |
} |
120 |
|
|
|
121 |
twoaday |
278 |
msg_box (dlg, p.getBuffer (), _("Signature Information"), MB_INFO); |
122 |
werner |
36 |
} |
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 |
twoaday |
219 |
static verlist_ctrl_t vlv = NULL; |
130 |
twoaday |
225 |
static gpgme_ctx_t c = NULL; |
131 |
twoaday |
219 |
text_input_s *ctx; |
132 |
werner |
36 |
gpgme_error_t err; |
133 |
|
|
gpgme_signature_t sig = NULL, s; |
134 |
|
|
gpg_keycache_t kc = NULL; |
135 |
|
|
const char *det_data=NULL; |
136 |
|
|
int rc = 0, det_len=0; |
137 |
|
|
|
138 |
twoaday |
201 |
switch (msg) { |
139 |
werner |
36 |
case WM_INITDIALOG: |
140 |
|
|
SetWindowText (dlg, _("Verify")); |
141 |
twoaday |
85 |
SetDlgItemText (dlg, IDC_VERIFY_SAVE, _("&Save")); |
142 |
werner |
36 |
kc = keycache_get_ctx (KEYCACHE_PUB); |
143 |
|
|
ctx = (text_input_s *)lparam; |
144 |
|
|
if (ctx) { |
145 |
|
|
det_data = ctx->data; |
146 |
|
|
det_len = ctx->length; |
147 |
|
|
} |
148 |
twoaday |
225 |
err = gpg_clip_verify (ctx && ctx->length > 0, |
149 |
werner |
36 |
det_data, det_len, &c, &sig); |
150 |
|
|
if (err) { |
151 |
|
|
msg_box (dlg, gpgme_strerror (err), _("Verify"), MB_ERR); |
152 |
|
|
EndDialog (dlg, FALSE); |
153 |
|
|
return FALSE; |
154 |
|
|
} |
155 |
|
|
|
156 |
|
|
if (gpgme_err_code (sig->status) == GPG_ERR_NO_PUBKEY) { |
157 |
twoaday |
271 |
gpgme_verify_result_t res; |
158 |
|
|
|
159 |
twoaday |
225 |
if (fetch_key_from_keyserver (dlg, sig)) { |
160 |
|
|
EndDialog (dlg, FALSE); |
161 |
|
|
return TRUE; |
162 |
werner |
36 |
} |
163 |
twoaday |
271 |
/* We need to call GPG again to get the real sig status. */ |
164 |
|
|
err = gpg_clip_verify (ctx && ctx->length > 0, |
165 |
|
|
det_data, det_len, &c, &sig); |
166 |
|
|
if (err) { |
167 |
|
|
msg_box (dlg, gpgme_strerror (err), _("Verify"), MB_ERR); |
168 |
|
|
EndDialog (dlg, FALSE); |
169 |
|
|
return TRUE; |
170 |
|
|
} |
171 |
|
|
/* Refresh the pointer because a new GPG instance has been |
172 |
|
|
created for the new verify operation. */ |
173 |
|
|
res = gpgme_op_verify_result (c); |
174 |
|
|
if (!res || res->signatures == NULL) |
175 |
|
|
BUG (0); |
176 |
|
|
sig = res->signatures; |
177 |
|
|
|
178 |
twoaday |
225 |
} |
179 |
twoaday |
271 |
|
180 |
|
|
if (gpgme_err_code (sig->status) == GPG_ERR_BAD_SIGNATURE && |
181 |
twoaday |
41 |
!sig->timestamp) |
182 |
werner |
36 |
; |
183 |
twoaday |
76 |
else if (!sig->timestamp) { |
184 |
werner |
36 |
msg_box (dlg, _("Invalid signature state."), _("Verify"), MB_ERR); |
185 |
|
|
EndDialog (dlg, FALSE); |
186 |
|
|
return FALSE; |
187 |
|
|
} |
188 |
twoaday |
219 |
verlist_build (&vlv, GetDlgItem (dlg, IDC_VERIFY_SIGLIST), 0); |
189 |
|
|
verlist_set_info_control (vlv, GetDlgItem (dlg, IDC_VERIFY_INFO)); |
190 |
werner |
36 |
|
191 |
|
|
for (s = sig; s; s = s->next) { |
192 |
twoaday |
219 |
rc = verlist_add_sig (vlv, s); |
193 |
twoaday |
271 |
if (rc) { |
194 |
|
|
msg_box (dlg, _("Error while adding signature information."), |
195 |
werner |
36 |
_("Verify"), MB_ERR); |
196 |
twoaday |
271 |
break; |
197 |
|
|
} |
198 |
werner |
36 |
} |
199 |
twoaday |
219 |
|
200 |
twoaday |
225 |
if (!sig->notations) |
201 |
|
|
ShowWindow (GetDlgItem (dlg, IDC_VERIFY_SIGNOT), SW_HIDE); |
202 |
werner |
36 |
SetForegroundWindow (dlg); |
203 |
|
|
return TRUE; |
204 |
|
|
|
205 |
|
|
case WM_DESTROY: |
206 |
twoaday |
225 |
if (c != NULL) { |
207 |
|
|
gpgme_release (c); |
208 |
|
|
c = NULL; |
209 |
|
|
} |
210 |
|
|
if (vlv != NULL) { |
211 |
twoaday |
219 |
verlist_delete (vlv); |
212 |
|
|
vlv = NULL; |
213 |
werner |
36 |
} |
214 |
|
|
return FALSE; |
215 |
|
|
|
216 |
|
|
case WM_COMMAND: |
217 |
|
|
switch (LOWORD (wparam )) { |
218 |
twoaday |
219 |
case IDCANCEL: |
219 |
|
|
EndDialog (dlg, FALSE); |
220 |
twoaday |
225 |
return TRUE; |
221 |
twoaday |
219 |
|
222 |
werner |
36 |
case IDOK: |
223 |
|
|
EndDialog (dlg, TRUE); |
224 |
twoaday |
225 |
return TRUE; |
225 |
|
|
|
226 |
|
|
case IDC_VERIFY_SIGNOT: |
227 |
|
|
show_notation_data (dlg, c); |
228 |
|
|
return TRUE; |
229 |
werner |
36 |
|
230 |
|
|
case IDC_VERIFY_SAVE: |
231 |
|
|
dialog_box_param (glob_hinst, (LPCTSTR)IDD_WINPT_FILE_SAVE, dlg, |
232 |
twoaday |
73 |
file_save_dlg_proc, 0, _("Save Plaintext"), |
233 |
werner |
36 |
IDS_WINPT_FILE_SAVE); |
234 |
|
|
break; |
235 |
|
|
} |
236 |
|
|
break; |
237 |
|
|
} |
238 |
|
|
|
239 |
|
|
return FALSE; |
240 |
|
|
} |