1 |
twoaday |
2 |
/* wptKeysigDlg.cpp - Key signature listing |
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 |
|
|
#include <commctrl.h> |
23 |
|
|
#include <time.h> |
24 |
|
|
|
25 |
|
|
#include "../resource.h" |
26 |
|
|
#include "wptGPG.h" |
27 |
|
|
#include "wptCommonCtl.h" |
28 |
|
|
#include "wptContext.h" /* for passphrase_s */ |
29 |
|
|
#include "wptDlgs.h" |
30 |
|
|
#include "wptW32API.h" |
31 |
|
|
#include "wptNLS.h" |
32 |
|
|
#include "wptKeyList.h" |
33 |
|
|
#include "wptKeyserver.h" |
34 |
|
|
#include "wptUTF8.h" |
35 |
|
|
#include "wptTypes.h" |
36 |
|
|
#include "wptVersion.h" |
37 |
|
|
#include "wptErrors.h" |
38 |
|
|
|
39 |
|
|
static subclass_s siglist_proc; |
40 |
|
|
|
41 |
|
|
|
42 |
|
|
static int inline |
43 |
|
|
is_sig (listview_ctrl_t lv, int pos) |
44 |
|
|
{ |
45 |
|
|
char tmpbuf[256]; |
46 |
|
|
|
47 |
|
|
if (pos == -1) |
48 |
|
|
pos = listview_get_curr_pos (lv); |
49 |
|
|
listview_get_item_text (lv, pos, 0, tmpbuf, 200); |
50 |
|
|
if (*tmpbuf == ' ') |
51 |
|
|
return -1; |
52 |
|
|
return 0; |
53 |
|
|
} |
54 |
|
|
|
55 |
|
|
|
56 |
|
|
static int |
57 |
|
|
do_delsig (HWND dlg, listview_ctrl_t lv, winpt_key_t key) |
58 |
|
|
{ |
59 |
|
|
int pos, npos, id; |
60 |
|
|
int signo=0, uidno=0; |
61 |
|
|
gpgme_ctx_t ctx; |
62 |
|
|
gpgme_editkey_t ek; |
63 |
|
|
gpgme_error_t rc; |
64 |
|
|
|
65 |
|
|
npos = pos = listview_get_curr_pos (lv); |
66 |
|
|
if (!is_sig (lv, -1)) |
67 |
|
|
return -1; |
68 |
|
|
while (pos > 0 && is_sig (lv, pos)) |
69 |
|
|
{ |
70 |
|
|
signo++; |
71 |
|
|
pos--; |
72 |
|
|
} |
73 |
|
|
pos = npos; |
74 |
|
|
while (npos > 0) |
75 |
|
|
{ |
76 |
|
|
if (!is_sig (lv, npos)) |
77 |
|
|
uidno++; |
78 |
|
|
npos--; |
79 |
|
|
} |
80 |
|
|
uidno++; |
81 |
|
|
id = log_box(_("Key Manager"), MB_YESNO, |
82 |
|
|
_("Are you really sure you want to delete this signature from\n" |
83 |
|
|
" \"%s\""), key->uid); |
84 |
|
|
if (id == IDNO) |
85 |
|
|
return 0; |
86 |
|
|
rc = gpgme_new (&ctx); |
87 |
|
|
if (rc) |
88 |
|
|
BUG (0); |
89 |
|
|
rc = gpgme_editkey_new (&ek); |
90 |
|
|
if (rc) |
91 |
|
|
BUG (0); |
92 |
|
|
gpgme_editkey_delsig_set (ek, uidno, signo); |
93 |
|
|
gpgme_set_edit_ctx (ctx, ek, GPGME_EDITKEY_DELSIG); |
94 |
|
|
rc = gpgme_op_editkey (ctx, key->keyid); |
95 |
|
|
if (rc) |
96 |
|
|
msg_box (dlg, gpgme_strerror (rc), _("Key Manager"), MB_ERR); |
97 |
|
|
else |
98 |
|
|
listview_del_item (lv, pos); |
99 |
|
|
gpgme_release (ctx); |
100 |
|
|
gpgme_editkey_release (ek); |
101 |
twoaday |
19 |
key->update = 1; /*update*/ |
102 |
twoaday |
2 |
return 0; |
103 |
|
|
} |
104 |
|
|
|
105 |
|
|
|
106 |
|
|
static BOOL CALLBACK |
107 |
|
|
sigprops_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
108 |
|
|
{ |
109 |
|
|
static listview_ctrl_t lv; |
110 |
|
|
char tmpbuf[256]; |
111 |
|
|
int n; |
112 |
|
|
struct { |
113 |
|
|
unsigned int exportable:1; |
114 |
|
|
unsigned int expired:1; |
115 |
|
|
unsigned int nrev:1; |
116 |
|
|
unsigned int rev:1; |
117 |
|
|
const char * alg; |
118 |
|
|
int _class; |
119 |
|
|
} ctx; |
120 |
|
|
const char * fmt_templ = "%s %s signature"; |
121 |
|
|
|
122 |
twoaday |
19 |
switch (msg) { |
123 |
twoaday |
2 |
case WM_SYSCOMMAND: |
124 |
|
|
if (LOWORD (wparam) == SC_CLOSE) |
125 |
|
|
EndDialog (dlg, TRUE); |
126 |
|
|
return FALSE; |
127 |
|
|
|
128 |
|
|
case WM_INITDIALOG: |
129 |
|
|
lv = (listview_ctrl_t)lparam; |
130 |
|
|
if (!lv) |
131 |
|
|
dlg_fatal_error (dlg, "could not get dialog param"); |
132 |
|
|
memset (&ctx, 0, sizeof ctx); |
133 |
|
|
n = listview_get_curr_pos (lv); |
134 |
|
|
listview_get_item_text (lv, n, 2, tmpbuf, DIM (tmpbuf)-1); |
135 |
|
|
if (!strstr (tmpbuf, "L")) |
136 |
|
|
ctx.exportable = 1; |
137 |
|
|
ctx._class = atoi (tmpbuf); |
138 |
|
|
if (ctx._class == 0) |
139 |
|
|
ctx._class = 10; |
140 |
|
|
else if (ctx._class < 10) |
141 |
|
|
ctx._class += 10; |
142 |
|
|
listview_get_item_text (lv, n, 6, tmpbuf, DIM (tmpbuf)-1); |
143 |
|
|
if (strstr (tmpbuf, "DSA")) |
144 |
|
|
ctx.alg = "DSA"; |
145 |
|
|
else if (strstr (tmpbuf, "RSA")) |
146 |
|
|
ctx.alg = "RSA"; |
147 |
|
|
else |
148 |
|
|
ctx.alg = "ELG"; |
149 |
|
|
_snprintf (tmpbuf, DIM (tmpbuf)-1, fmt_templ, |
150 |
|
|
ctx.exportable? "Exportable" : "Non-exportable", ctx.alg); |
151 |
|
|
SetDlgItemText (dlg, IDC_SIGPROPS_INFO, tmpbuf); |
152 |
|
|
listview_get_item_text (lv, n, 4, tmpbuf, DIM (tmpbuf)-1); |
153 |
|
|
SetDlgItemText (dlg, IDC_SIGPROPS_KEYID, tmpbuf); |
154 |
|
|
SetDlgItemInt (dlg, IDC_SIGPROPS_CLASS, ctx._class, FALSE); |
155 |
|
|
if (ctx.exportable) |
156 |
|
|
CheckDlgButton (dlg, IDC_SIGPROPS_EXP, BST_CHECKED); |
157 |
|
|
listview_get_item_text (lv, n, 0, tmpbuf, DIM (tmpbuf)-1); |
158 |
|
|
SetDlgItemText (dlg, IDC_SIGPROPS_ISSUER, tmpbuf+1); |
159 |
|
|
tmpbuf[0] = 0; |
160 |
|
|
listview_get_item_text (lv, n, 5, tmpbuf, DIM (tmpbuf)-1); |
161 |
twoaday |
13 |
if (strlen (tmpbuf) == 0) { |
162 |
twoaday |
2 |
ShowWindow (GetDlgItem (dlg, IDC_SIGPROPS_EXPSTR), SW_HIDE); |
163 |
|
|
ShowWindow (GetDlgItem (dlg, IDC_SIGPROPS_EXPDATE), SW_HIDE); |
164 |
|
|
} |
165 |
twoaday |
13 |
else { |
166 |
twoaday |
2 |
SYSTEMTIME st; |
167 |
|
|
struct tm * tm; |
168 |
|
|
time_t t = time (NULL); |
169 |
|
|
|
170 |
|
|
memset (&st, 0, sizeof st); |
171 |
|
|
st.wYear = atoi (tmpbuf); |
172 |
|
|
st.wMonth = atoi (tmpbuf+5); |
173 |
|
|
st.wDay = atoi (tmpbuf+8); |
174 |
|
|
DateTime_SetSystemtime (GetDlgItem (dlg, IDC_SIGPROPS_EXPDATE), |
175 |
|
|
GDT_VALID, &st); |
176 |
|
|
|
177 |
|
|
tm = localtime (&t); |
178 |
|
|
tm->tm_mon++; |
179 |
|
|
tm->tm_year += 1900; |
180 |
|
|
if (tm->tm_year > st.wYear) |
181 |
|
|
ctx.expired = 1; |
182 |
|
|
else if (tm->tm_mon > st.wMonth) |
183 |
|
|
ctx.expired = 1; |
184 |
|
|
if (ctx.expired) |
185 |
|
|
CheckDlgButton (dlg, IDC_SIGPROPS_EXPIRED, BST_CHECKED); |
186 |
|
|
} |
187 |
|
|
SetDlgItemText (dlg, IDC_SIGPROPS_EXP, _("Exportable")); |
188 |
|
|
SetDlgItemText (dlg, IDC_SIGPROPS_NREV, _("Non-revocably")); |
189 |
|
|
SetDlgItemText (dlg, IDC_SIGPROPS_REV, _("Revoked")); |
190 |
|
|
SetDlgItemText (dlg, IDC_SIGPROPS_EXPIRED, _("Expired")); |
191 |
|
|
SetForegroundWindow (dlg); |
192 |
|
|
center_window (dlg); |
193 |
|
|
return TRUE; |
194 |
|
|
|
195 |
|
|
case WM_COMMAND: |
196 |
twoaday |
13 |
switch (LOWORD (wparam)) { |
197 |
twoaday |
2 |
case IDOK: |
198 |
|
|
EndDialog (dlg, TRUE); |
199 |
|
|
break; |
200 |
|
|
} |
201 |
|
|
} |
202 |
|
|
|
203 |
|
|
return FALSE; |
204 |
|
|
} |
205 |
|
|
|
206 |
|
|
|
207 |
|
|
static BOOL CALLBACK |
208 |
|
|
subclass_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
209 |
|
|
{ |
210 |
|
|
listview_ctrl_t lv; |
211 |
|
|
winpt_key_t key; |
212 |
|
|
|
213 |
twoaday |
19 |
switch (msg) { |
214 |
twoaday |
2 |
case WM_KEYUP: |
215 |
|
|
int virt_key = (int)wparam; |
216 |
|
|
key = (winpt_key_t)siglist_proc.opaque; |
217 |
|
|
lv = key->callback.ctl; |
218 |
twoaday |
19 |
if (virt_key == VK_SPACE) { |
219 |
twoaday |
2 |
if (is_sig (lv, -1)) |
220 |
|
|
DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_SIGPROPS, dlg, |
221 |
|
|
sigprops_dlg_proc, (LPARAM)lv); |
222 |
|
|
} |
223 |
|
|
else if (virt_key == VK_DELETE) |
224 |
|
|
do_delsig (dlg, lv, key); |
225 |
|
|
break; |
226 |
|
|
} |
227 |
|
|
return CallWindowProc (siglist_proc.old, dlg, msg, wparam, lparam); |
228 |
|
|
} |
229 |
|
|
|
230 |
|
|
|
231 |
|
|
static int |
232 |
|
|
check_for_missing_keys (listview_ctrl_t lv) |
233 |
|
|
{ |
234 |
|
|
int i, n; |
235 |
|
|
char id[128]; |
236 |
|
|
|
237 |
|
|
n = listview_count_items( lv, 0 ); |
238 |
|
|
for( i = 0; i < n; i++ ) { |
239 |
|
|
listview_get_item_text( lv, i, 1, id, sizeof id - 1 ); |
240 |
|
|
if( !strncmp( id, "NOKEY", 5 ) ) |
241 |
|
|
return 1; |
242 |
|
|
} |
243 |
|
|
|
244 |
|
|
return 0; |
245 |
|
|
} /* check_for_missing_keys */ |
246 |
|
|
|
247 |
|
|
|
248 |
|
|
static int |
249 |
|
|
recv_missing_keys (HWND dlg, listview_ctrl_t lv) |
250 |
|
|
{ |
251 |
|
|
int i, n, rc; |
252 |
|
|
char id[128], keyid[18+1]; |
253 |
|
|
|
254 |
|
|
n = listview_count_items (lv, 0); |
255 |
|
|
for( i = 0; i < n; i++ ) { |
256 |
|
|
listview_get_item_text( lv, i, 1, id, sizeof id - 1 ); |
257 |
|
|
if( !strncmp( id, "NOKEY", 5 ) ) { |
258 |
|
|
listview_get_item_text( lv, i, 4, keyid, sizeof keyid -1 ); |
259 |
|
|
rc = hkp_recv_key( dlg, default_keyserver, default_keyserver_port, keyid, 0, 0 ); |
260 |
|
|
if( rc ) |
261 |
|
|
break; |
262 |
|
|
} |
263 |
|
|
} |
264 |
|
|
|
265 |
|
|
return rc; |
266 |
|
|
} /* recv_missing_keys */ |
267 |
|
|
|
268 |
|
|
|
269 |
|
|
static void |
270 |
|
|
do_create_popup (HWND dlg) |
271 |
|
|
{ |
272 |
|
|
HMENU hm, sm; |
273 |
|
|
POINT p; |
274 |
|
|
|
275 |
|
|
GetCursorPos (&p); |
276 |
|
|
hm = LoadMenu (glob_hinst, MAKEINTRESOURCE (IDR_WINPT_KEYSIG_CTX)); |
277 |
|
|
sm = GetSubMenu (hm, 0); |
278 |
|
|
|
279 |
|
|
TrackPopupMenu (sm, TPM_RIGHTALIGN, p.x, p.y, 0, dlg, NULL); |
280 |
|
|
|
281 |
|
|
DestroyMenu (hm); |
282 |
|
|
DestroyMenu (sm); |
283 |
|
|
} |
284 |
|
|
|
285 |
|
|
|
286 |
|
|
static void |
287 |
|
|
do_load_keyprops (HWND dlg, listview_ctrl_t lv) |
288 |
|
|
{ |
289 |
|
|
winpt_key_s k; |
290 |
|
|
gpgme_key_t key; |
291 |
|
|
char keyid[32] = {0}; |
292 |
|
|
char status[64] = {0}, creation[64] = {0}; |
293 |
|
|
int n = listview_get_curr_pos (lv); |
294 |
|
|
|
295 |
|
|
listview_get_item_text (lv, n, 1, status, DIM (status)-1); |
296 |
|
|
listview_get_item_text (lv, n, 3, creation, DIM (creation)-1); |
297 |
|
|
listview_get_item_text (lv, n, 4, keyid, DIM (keyid)-1); |
298 |
|
|
if (!strcmp (status, "NOKEY")) { |
299 |
|
|
msg_box (dlg, _("Key not found in keyring, please get it from the keyserver first."), |
300 |
|
|
_("Key Manager"), MB_INFO); |
301 |
|
|
return; |
302 |
|
|
} |
303 |
|
|
|
304 |
|
|
if ((strlen (keyid) < 3 ||get_pubkey (keyid, &key))) { |
305 |
|
|
if (strlen (creation) > 0) |
306 |
|
|
msg_box (dlg, _("Key not found in keyring."), _("Key Manager"), MB_INFO); |
307 |
|
|
return; |
308 |
|
|
} |
309 |
|
|
memset (&k, 0, sizeof k); |
310 |
|
|
k.keyid = keyid; |
311 |
|
|
DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_KEYPROPS, dlg, |
312 |
|
|
keyprops_dlg_proc, (LPARAM)&k); |
313 |
|
|
} |
314 |
|
|
|
315 |
twoaday |
19 |
|
316 |
twoaday |
2 |
BOOL CALLBACK |
317 |
|
|
keysig_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
318 |
|
|
{ |
319 |
|
|
static listview_ctrl_t lv = NULL; |
320 |
twoaday |
19 |
static struct winpt_key_s *k; |
321 |
twoaday |
2 |
char inf[384], keyid[18+1]; |
322 |
|
|
int idx = 0, id, rc; |
323 |
|
|
HWND sl; |
324 |
|
|
|
325 |
|
|
switch( msg ) { |
326 |
|
|
case WM_INITDIALOG: |
327 |
|
|
k = (winpt_key_t) lparam; |
328 |
|
|
if (!k) |
329 |
|
|
BUG (0); |
330 |
twoaday |
19 |
if (k->uid) |
331 |
|
|
_snprintf (inf, DIM (inf)-1, _("Signature List for \"%s\""), k->uid); |
332 |
|
|
SetWindowText (dlg, inf); |
333 |
twoaday |
2 |
#ifndef LANG_DE |
334 |
twoaday |
19 |
SetDlgItemText (dlg, IDC_KEYSIG_RECVKEY, _("&Receive Key")); |
335 |
twoaday |
2 |
SetDlgItemText (dlg, IDC_KEYSIG_SIGPROPS, _("&Properties")); |
336 |
|
|
#endif |
337 |
|
|
lv = siglist_load( GetDlgItem( dlg, IDC_KEYSIG_LIST ), k->keyid ); |
338 |
|
|
if( !check_for_missing_keys( lv ) ) |
339 |
|
|
EnableWindow( GetDlgItem( dlg, IDC_KEYSIG_RECVKEY ), FALSE ); |
340 |
|
|
k->callback.ctl = lv; |
341 |
|
|
sl = GetDlgItem (dlg, IDC_KEYSIG_LIST); |
342 |
|
|
siglist_proc.dlg = dlg; |
343 |
|
|
siglist_proc.opaque = k; |
344 |
|
|
siglist_proc.current = (WNDPROC)subclass_dlg_proc; |
345 |
|
|
siglist_proc.old = (WNDPROC)GetWindowLong (sl, GWL_WNDPROC); |
346 |
twoaday |
19 |
if (siglist_proc.old) { |
347 |
|
|
if (!SetWindowLong (sl, GWL_WNDPROC, (LONG)siglist_proc.current)) { |
348 |
twoaday |
2 |
msg_box (dlg, _("Could not set keylist window procedure."), _("Key Manager"), MB_ERR); |
349 |
|
|
BUG (0); |
350 |
|
|
} |
351 |
|
|
} |
352 |
|
|
SetForegroundWindow (dlg); |
353 |
|
|
center_window (dlg); |
354 |
|
|
return TRUE; |
355 |
|
|
|
356 |
|
|
case WM_DESTROY: |
357 |
|
|
if ( lv ) { |
358 |
|
|
siglist_delete( lv ); |
359 |
|
|
lv = NULL; |
360 |
|
|
} |
361 |
|
|
return FALSE; |
362 |
|
|
|
363 |
|
|
case WM_SYSCOMMAND: |
364 |
twoaday |
19 |
if (LOWORD (wparam) == SC_CLOSE) { |
365 |
|
|
if (k->update) |
366 |
|
|
keycache_update (k->keyid); |
367 |
|
|
EndDialog (dlg, TRUE); |
368 |
|
|
} |
369 |
twoaday |
2 |
return FALSE; |
370 |
|
|
|
371 |
|
|
case WM_NOTIFY: |
372 |
|
|
NMHDR * notify; |
373 |
|
|
|
374 |
|
|
notify = (NMHDR *)lparam; |
375 |
|
|
if( notify && notify->code == NM_DBLCLK |
376 |
|
|
&& notify->idFrom == IDC_KEYSIG_LIST ) |
377 |
|
|
do_load_keyprops (dlg, lv); |
378 |
|
|
if (notify && notify->code == NM_RCLICK && |
379 |
|
|
notify->idFrom == IDC_KEYSIG_LIST) |
380 |
|
|
do_create_popup (dlg); |
381 |
|
|
break; |
382 |
|
|
|
383 |
|
|
case WM_COMMAND: |
384 |
|
|
switch ( LOWORD( wparam ) ) { |
385 |
|
|
|
386 |
|
|
case ID_SIGCTX_KEYPROPS: |
387 |
|
|
do_load_keyprops (dlg, lv); |
388 |
|
|
break; |
389 |
|
|
|
390 |
|
|
case ID_SIGCTX_PROPS: |
391 |
|
|
if (is_sig (lv, -1)) |
392 |
|
|
DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_SIGPROPS, dlg, |
393 |
|
|
sigprops_dlg_proc, (LPARAM)lv); |
394 |
|
|
break; |
395 |
|
|
|
396 |
|
|
case IDC_KEYSIG_RECVKEY: |
397 |
|
|
idx = listview_get_curr_pos( lv ); |
398 |
|
|
if( idx == -1 ) { |
399 |
|
|
id = msg_box( dlg, _("Really receive all missing keys?"), |
400 |
|
|
_("Key Manager"), MB_YESNO|MB_INFO ); |
401 |
twoaday |
19 |
if (id == IDYES) { |
402 |
|
|
rc = recv_missing_keys (dlg, lv); |
403 |
twoaday |
2 |
if( !rc ) |
404 |
twoaday |
19 |
keycache_set_reload (1); |
405 |
twoaday |
2 |
return TRUE; |
406 |
|
|
} |
407 |
|
|
return FALSE; |
408 |
|
|
} |
409 |
|
|
listview_get_item_text (lv, idx, 4, keyid, sizeof keyid - 1); |
410 |
|
|
rc = hkp_recv_key (dlg, default_keyserver, default_keyserver_port, keyid, 0, 0); |
411 |
|
|
if (!rc) |
412 |
|
|
keycache_set_reload (1); |
413 |
|
|
return TRUE; |
414 |
|
|
|
415 |
|
|
case IDC_KEYSIG_SIGPROPS: |
416 |
|
|
if (is_sig (lv, -1)) |
417 |
|
|
DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_SIGPROPS, dlg, |
418 |
|
|
sigprops_dlg_proc, (LPARAM)lv); |
419 |
|
|
return TRUE; |
420 |
|
|
|
421 |
|
|
case IDOK: |
422 |
twoaday |
19 |
if (k->update) |
423 |
|
|
keycache_update (k->keyid); |
424 |
twoaday |
2 |
EndDialog (dlg, TRUE); |
425 |
|
|
return TRUE; |
426 |
|
|
} |
427 |
|
|
break; |
428 |
|
|
} |
429 |
|
|
return FALSE; |
430 |
|
|
} /* keysig_dlg_proc */ |