1 |
/* wptKeysigDlg.cpp - Key signature listing |
/* wptKeysigDlg.cpp - Key signature listing |
2 |
* Copyright (C) 2001-2005 Timo Schulz |
* Copyright (C) 2001-2006 Timo Schulz |
3 |
* |
* |
4 |
* This file is part of WinPT. |
* This file is part of WinPT. |
5 |
* |
* |
6 |
* WinPT is free software; you can redistribute it and/or modify |
* 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 |
* 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 |
* the Free Software Foundation; either version 2 of the License, or |
9 |
* (at your option) any later version. |
* (at your option) any later version. |
10 |
* |
* |
11 |
* WinPT is distributed in the hope that it will be useful, |
* WinPT is distributed in the hope that it will be useful, |
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 |
* GNU General Public License for more details. |
* GNU General Public License for more details. |
15 |
* |
* |
16 |
* You should have received a copy of the GNU General Public License |
* You should have received a copy of the GNU General Public License |
17 |
* along with WinPT; if not, write to the Free Software Foundation, |
* along with WinPT; if not, write to the Free Software Foundation, |
18 |
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
19 |
*/ |
*/ |
20 |
|
#ifdef HAVE_CONFIG_H |
21 |
#include <windows.h> |
#include <config.h> |
22 |
#include <commctrl.h> |
#endif |
23 |
#include <time.h> |
|
24 |
|
#include <windows.h> |
25 |
#include "../resource.h" |
#include <commctrl.h> |
26 |
#include "wptGPG.h" |
#include <time.h> |
27 |
#include "wptCommonCtl.h" |
|
28 |
#include "wptContext.h" /* for passphrase_s */ |
#include "resource.h" |
29 |
#include "wptDlgs.h" |
#include "wptGPG.h" |
30 |
#include "wptW32API.h" |
#include "wptCommonCtl.h" |
31 |
#include "wptNLS.h" |
#include "wptContext.h" /* for passphrase_s */ |
32 |
#include "wptKeyList.h" |
#include "wptDlgs.h" |
33 |
#include "wptKeyserver.h" |
#include "wptW32API.h" |
34 |
#include "wptUTF8.h" |
#include "wptNLS.h" |
35 |
#include "wptTypes.h" |
#include "wptKeylist.h" |
36 |
#include "wptVersion.h" |
#include "wptKeyserver.h" |
37 |
#include "wptErrors.h" |
#include "wptUTF8.h" |
38 |
#include "wptKeyEdit.h" |
#include "wptTypes.h" |
39 |
|
#include "wptVersion.h" |
40 |
static subclass_s siglist_proc; |
#include "wptErrors.h" |
41 |
|
#include "wptKeyEdit.h" |
42 |
|
|
43 |
static int |
static subclass_s siglist_proc; |
44 |
is_sig (listview_ctrl_t lv, int pos) |
|
45 |
{ |
|
46 |
char tmpbuf[256]; |
static int |
47 |
|
is_sig (listview_ctrl_t lv, int pos) |
48 |
if (pos == -1) |
{ |
49 |
pos = listview_get_curr_pos (lv); |
char tmpbuf[200]; |
50 |
if (pos == -1) |
|
51 |
return 0; |
if (pos == -1) |
52 |
listview_get_item_text (lv, pos, 0, tmpbuf, 200); |
pos = listview_get_curr_pos (lv); |
53 |
if (*tmpbuf == ' ') |
if (pos == -1) |
54 |
return -1; |
return 0; |
55 |
return 0; |
listview_get_item_text (lv, pos, SL_COL_UID, tmpbuf, sizeof (tmpbuf)-1); |
56 |
} |
if (*tmpbuf == ' ') |
57 |
|
return -1; |
58 |
|
return 0; |
59 |
/* Delete the selected signature from list view @lv. The |
} |
60 |
key is given in @key. */ |
|
61 |
static int |
|
62 |
do_delsig (HWND dlg, listview_ctrl_t lv, winpt_key_t key) |
/* Delete the selected signature from list view @lv. The |
63 |
{ |
key is given in @key. */ |
64 |
int pos, npos, id; |
static int |
65 |
int signo=0, uidno=0; |
do_delsig (HWND dlg, listview_ctrl_t lv, winpt_key_t key) |
66 |
GpgKeyEdit *ke; |
{ |
67 |
gpgme_error_t err; |
int pos, npos, id; |
68 |
|
int signo=0, uidno=0; |
69 |
npos = pos = listview_get_curr_pos (lv); |
GpgKeyEdit *ke; |
70 |
if (!is_sig (lv, -1)) |
gpgme_error_t err; |
71 |
return -1; |
|
72 |
while (pos > 0 && is_sig (lv, pos)) { |
npos = pos = listview_get_curr_pos (lv); |
73 |
signo++; |
if (!is_sig (lv, -1)) |
74 |
pos--; |
return -1; |
75 |
} |
while (pos > 0 && is_sig (lv, pos)) { |
76 |
pos = npos; |
signo++; |
77 |
while (npos > 0) { |
pos--; |
78 |
if (!is_sig (lv, npos)) |
} |
79 |
uidno++; |
pos = npos; |
80 |
npos--; |
while (npos > 0) { |
81 |
} |
if (!is_sig (lv, npos)) |
82 |
uidno++; |
uidno++; |
83 |
|
npos--; |
84 |
/* XXX: do not allow to delete the self signature */ |
} |
85 |
id = log_box (_("Key Manager"), MB_YESNO, |
uidno++; |
86 |
_("Are you really sure you want to delete this signature from\n" |
|
87 |
" \"%s\""), key->uid); |
/* XXX: do not allow to delete the self signature */ |
88 |
if (id == IDNO) |
id = log_box (_("Key Manager"), MB_YESNO, |
89 |
return 0; |
_("Are you really sure you want to delete this signature from\n" |
90 |
|
" \"%s\""), key->uid); |
91 |
ke = new GpgKeyEdit (key->keyid); |
if (id == IDNO) |
92 |
if (!ke) |
return 0; |
93 |
BUG (NULL); |
|
94 |
err = ke->delUseridSignature (uidno, signo); |
ke = new GpgKeyEdit (key->keyid); |
95 |
if (err) |
if (!ke) |
96 |
msg_box (dlg, gpgme_strerror (err), _("Key Manager"), MB_ERR); |
BUG (NULL); |
97 |
else |
err = ke->delUseridSignature (uidno, signo); |
98 |
listview_del_item (lv, pos); |
if (err) |
99 |
delete ke; |
msg_box (dlg, gpgme_strerror (err), _("Key Manager"), MB_ERR); |
100 |
key->update = 1; /*update*/ |
else |
101 |
return err? -1 : 0; |
listview_del_item (lv, pos); |
102 |
} |
delete ke; |
103 |
|
key->update = 1; /*update*/ |
104 |
|
return err? -1 : 0; |
105 |
/* Dialog box procedure to display the signature properties. */ |
} |
106 |
static BOOL CALLBACK |
|
107 |
sigprops_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
|
108 |
{ |
/* Dialog box procedure to display the signature properties. */ |
109 |
static listview_ctrl_t lv; |
static BOOL CALLBACK |
110 |
char tmpbuf[256]; |
sigprops_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
111 |
int n; |
{ |
112 |
struct { |
static listview_ctrl_t lv; |
113 |
unsigned int exportable:1; |
char tmpbuf[256]; |
114 |
unsigned int expired:1; |
int n; |
115 |
unsigned int nrev:1; |
struct { |
116 |
unsigned int rev:1; |
unsigned int exportable:1; |
117 |
const char * alg; |
unsigned int expired:1; |
118 |
int _class; |
unsigned int nrev:1; |
119 |
} ctx; |
unsigned int rev:1; |
120 |
const char *fmt_templ = _("%s %s signature"); |
const char * alg; |
121 |
|
int _class; |
122 |
switch (msg) { |
} ctx; |
123 |
case WM_SYSCOMMAND: |
const char *fmt_templ = _("%s %s signature"); |
124 |
if (LOWORD (wparam) == SC_CLOSE) |
|
125 |
EndDialog (dlg, TRUE); |
switch (msg) { |
126 |
return FALSE; |
case WM_SYSCOMMAND: |
127 |
|
if (LOWORD (wparam) == SC_CLOSE) |
128 |
case WM_INITDIALOG: |
EndDialog (dlg, TRUE); |
129 |
lv = (listview_ctrl_t)lparam; |
return FALSE; |
130 |
if (!lv) |
|
131 |
dlg_fatal_error (dlg, "could not get dialog param"); |
case WM_INITDIALOG: |
132 |
memset (&ctx, 0, sizeof ctx); |
SetWindowText (dlg, _("Signature Properties")); |
133 |
n = listview_get_curr_pos (lv); |
SetDlgItemText (dlg, IDC_SIGPROPS_EXP, _("Exportable")); |
134 |
listview_get_item_text (lv, n, 2, tmpbuf, DIM (tmpbuf)-1); |
SetDlgItemText (dlg, IDC_SIGPROPS_NREV, _("Non-revocably")); |
135 |
if (!strstr (tmpbuf, "L")) |
SetDlgItemText (dlg, IDC_SIGPROPS_EXPIRED, _("Expired")); |
136 |
ctx.exportable = 1; |
SetDlgItemText (dlg, IDC_SIGPROPS_REV, _("Revoked")); |
137 |
ctx._class = atoi (tmpbuf); |
SetDlgItemText (dlg, IDC_SIGPROPS_CLASSINF, _("Class")); |
138 |
if (ctx._class == 0) |
SetDlgItemText (dlg, IDC_SIGPROPS_EXPSTR, _("Expire date")); |
139 |
ctx._class = 10; |
SetDlgItemText (dlg, IDC_SIGPROPS_KEYINF, _("Issuer key")); |
140 |
else if (ctx._class < 10) |
SetDlgItemText (dlg, IDC_SIGPROPS_KEYIDINF, _("Issuer key ID")); |
141 |
ctx._class += 10; |
lv = (listview_ctrl_t)lparam; |
142 |
listview_get_item_text (lv, n, 6, tmpbuf, DIM (tmpbuf)-1); |
if (!lv) |
143 |
if (strstr (tmpbuf, "DSA")) |
dlg_fatal_error (dlg, "could not get dialog param"); |
144 |
ctx.alg = "DSA"; |
memset (&ctx, 0, sizeof ctx); |
145 |
else if (strstr (tmpbuf, "RSA")) |
n = listview_get_curr_pos (lv); |
146 |
ctx.alg = "RSA"; |
listview_get_item_text (lv, n, SL_COL_CLASS, tmpbuf, DIM (tmpbuf)-1); |
147 |
else |
if (!strstr (tmpbuf, "L")) |
148 |
ctx.alg = "ELG"; |
ctx.exportable = 1; |
149 |
_snprintf (tmpbuf, DIM (tmpbuf)-1, fmt_templ, |
ctx._class = atoi (tmpbuf); |
150 |
ctx.exportable? _("Exportable") : _("Non-exportable"), ctx.alg); |
if (ctx._class == 0) |
151 |
SetDlgItemText (dlg, IDC_SIGPROPS_INFO, tmpbuf); |
ctx._class = 10; |
152 |
listview_get_item_text (lv, n, 4, tmpbuf, DIM (tmpbuf)-1); |
else if (ctx._class < 10) |
153 |
SetDlgItemText (dlg, IDC_SIGPROPS_KEYID, tmpbuf); |
ctx._class += 10; |
154 |
SetDlgItemInt (dlg, IDC_SIGPROPS_CLASS, ctx._class, FALSE); |
listview_get_item_text (lv, n, SL_COL_ALGO, tmpbuf, DIM (tmpbuf)-1); |
155 |
if (ctx.exportable) |
if (strstr (tmpbuf, "DSA")) |
156 |
CheckDlgButton (dlg, IDC_SIGPROPS_EXP, BST_CHECKED); |
ctx.alg = "DSA"; |
157 |
listview_get_item_text (lv, n, 0, tmpbuf, DIM (tmpbuf)-1); |
else if (strstr (tmpbuf, "RSA")) |
158 |
SetDlgItemText (dlg, IDC_SIGPROPS_ISSUER, tmpbuf+1); |
ctx.alg = "RSA"; |
159 |
tmpbuf[0] = 0; |
else |
160 |
listview_get_item_text (lv, n, 5, tmpbuf, DIM (tmpbuf)-1); |
ctx.alg = "ELG"; |
161 |
if (strlen (tmpbuf) == 0) { |
_snprintf (tmpbuf, DIM (tmpbuf)-1, fmt_templ, |
162 |
ShowWindow (GetDlgItem (dlg, IDC_SIGPROPS_EXPSTR), SW_HIDE); |
ctx.exportable? _("Exportable") : _("Non-exportable"), ctx.alg); |
163 |
ShowWindow (GetDlgItem (dlg, IDC_SIGPROPS_EXPDATE), SW_HIDE); |
SetDlgItemText (dlg, IDC_SIGPROPS_INFO, tmpbuf); |
164 |
} |
listview_get_item_text (lv, n, SL_COL_KEYID, tmpbuf, DIM (tmpbuf)-1); |
165 |
else { |
SetDlgItemText (dlg, IDC_SIGPROPS_KEYID, tmpbuf); |
166 |
SYSTEMTIME st; |
SetDlgItemInt (dlg, IDC_SIGPROPS_CLASS, ctx._class, FALSE); |
167 |
struct tm * tm; |
if (ctx.exportable) |
168 |
time_t t = time (NULL); |
CheckDlgButton (dlg, IDC_SIGPROPS_EXP, BST_CHECKED); |
169 |
|
listview_get_item_text (lv, n, SL_COL_UID, tmpbuf, DIM (tmpbuf)-1); |
170 |
memset (&st, 0, sizeof st); |
SetDlgItemText (dlg, IDC_SIGPROPS_ISSUER, tmpbuf+1); |
171 |
st.wYear = atoi (tmpbuf); |
tmpbuf[0] = 0; |
172 |
st.wMonth = atoi (tmpbuf+5); |
listview_get_item_text (lv, n, SL_COL_EXPIRE, tmpbuf, DIM (tmpbuf)-1); |
173 |
st.wDay = atoi (tmpbuf+8); |
if (strlen (tmpbuf) == 0) { |
174 |
DateTime_SetSystemtime (GetDlgItem (dlg, IDC_SIGPROPS_EXPDATE), |
ShowWindow (GetDlgItem (dlg, IDC_SIGPROPS_EXPSTR), SW_HIDE); |
175 |
GDT_VALID, &st); |
ShowWindow (GetDlgItem (dlg, IDC_SIGPROPS_EXPDATE), SW_HIDE); |
176 |
|
} |
177 |
tm = localtime (&t); |
else { |
178 |
tm->tm_mon++; |
SYSTEMTIME st; |
179 |
tm->tm_year += 1900; |
struct tm * tm; |
180 |
if (tm->tm_year > st.wYear) |
time_t t = time (NULL); |
181 |
ctx.expired = 1; |
|
182 |
else if (tm->tm_mon > st.wMonth) |
memset (&st, 0, sizeof st); |
183 |
ctx.expired = 1; |
st.wYear = atoi (tmpbuf); |
184 |
if (ctx.expired) |
st.wMonth = atoi (tmpbuf+5); |
185 |
CheckDlgButton (dlg, IDC_SIGPROPS_EXPIRED, BST_CHECKED); |
st.wDay = atoi (tmpbuf+8); |
186 |
} |
DateTime_SetSystemtime (GetDlgItem (dlg, IDC_SIGPROPS_EXPDATE), |
187 |
SetDlgItemText (dlg, IDC_SIGPROPS_EXP, _("Exportable")); |
GDT_VALID, &st); |
188 |
SetDlgItemText (dlg, IDC_SIGPROPS_NREV, _("Non-revocably")); |
|
189 |
SetDlgItemText (dlg, IDC_SIGPROPS_REV, _("Revoked")); |
tm = localtime (&t); |
190 |
SetDlgItemText (dlg, IDC_SIGPROPS_EXPIRED, _("Expired")); |
tm->tm_mon++; |
191 |
SetWindowText (dlg, _("Signature Properties")); |
tm->tm_year += 1900; |
192 |
SetForegroundWindow (dlg); |
if (tm->tm_year > st.wYear) |
193 |
center_window (dlg, NULL); |
ctx.expired = 1; |
194 |
return TRUE; |
else if (tm->tm_mon > st.wMonth) |
195 |
|
ctx.expired = 1; |
196 |
case WM_COMMAND: |
if (ctx.expired) |
197 |
switch (LOWORD (wparam)) { |
CheckDlgButton (dlg, IDC_SIGPROPS_EXPIRED, BST_CHECKED); |
198 |
case IDOK: |
} |
199 |
EndDialog (dlg, TRUE); |
SetDlgItemText (dlg, IDC_SIGPROPS_EXP, _("Exportable")); |
200 |
break; |
SetDlgItemText (dlg, IDC_SIGPROPS_NREV, _("Non-revocably")); |
201 |
} |
SetDlgItemText (dlg, IDC_SIGPROPS_REV, _("Revoked")); |
202 |
} |
SetDlgItemText (dlg, IDC_SIGPROPS_EXPIRED, _("Expired")); |
203 |
|
SetWindowText (dlg, _("Signature Properties")); |
204 |
return FALSE; |
SetForegroundWindow (dlg); |
205 |
} |
center_window (dlg, NULL); |
206 |
|
return TRUE; |
207 |
|
|
208 |
static BOOL CALLBACK |
case WM_COMMAND: |
209 |
subclass_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
switch (LOWORD (wparam)) { |
210 |
{ |
case IDOK: |
211 |
listview_ctrl_t lv; |
EndDialog (dlg, TRUE); |
212 |
winpt_key_t key; |
break; |
213 |
|
} |
214 |
switch (msg) { |
} |
215 |
case WM_KEYUP: |
|
216 |
int virt_key = (int)wparam; |
return FALSE; |
217 |
key = (winpt_key_t)siglist_proc.opaque; |
} |
218 |
lv = key->callback.ctl; |
|
219 |
if (virt_key == VK_SPACE) { |
|
220 |
if (is_sig (lv, -1)) |
static BOOL CALLBACK |
221 |
DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_SIGPROPS, dlg, |
subclass_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
222 |
sigprops_dlg_proc, (LPARAM)lv); |
{ |
223 |
} |
listview_ctrl_t lv; |
224 |
else if (virt_key == VK_DELETE) |
winpt_key_t key; |
225 |
do_delsig (dlg, lv, key); |
|
226 |
break; |
switch (msg) { |
227 |
} |
case WM_KEYUP: |
228 |
return CallWindowProc (siglist_proc.old, dlg, msg, wparam, lparam); |
int virt_key = (int)wparam; |
229 |
} |
key = (winpt_key_t)siglist_proc.opaque; |
230 |
|
lv = key->callback.ctl; |
231 |
|
if (virt_key == VK_SPACE) { |
232 |
/* Return 1 if the list view @lv contains non-available keys. */ |
if (is_sig (lv, -1)) |
233 |
static int |
DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_SIGPROPS, dlg, |
234 |
check_for_missing_keys (listview_ctrl_t lv) |
sigprops_dlg_proc, (LPARAM)lv); |
235 |
{ |
} |
236 |
int i, n; |
else if (virt_key == VK_DELETE) |
237 |
char id[128]; |
do_delsig (dlg, lv, key); |
238 |
|
break; |
239 |
n = listview_count_items( lv, 0 ); |
} |
240 |
for( i = 0; i < n; i++ ) { |
return CallWindowProc (siglist_proc.old, dlg, msg, wparam, lparam); |
241 |
listview_get_item_text( lv, i, 1, id, sizeof (id) - 1 ); |
} |
242 |
if( !strncmp( id, "NOKEY", 5 ) ) |
|
243 |
return 1; |
|
244 |
} |
/* Return 1 if the list view @lv contains non-available keys. */ |
245 |
|
static int |
246 |
return 0; |
check_for_missing_keys (listview_ctrl_t lv) |
247 |
} |
{ |
248 |
|
int i, n; |
249 |
|
char id[128]; |
250 |
/* Receive all missing keys marked in the list @lv. */ |
|
251 |
static int |
n = listview_count_items( lv, 0 ); |
252 |
recv_missing_keys (HWND dlg, listview_ctrl_t lv) |
for( i = 0; i < n; i++ ) { |
253 |
{ |
listview_get_item_text (lv, i, SL_COL_VALID, id, sizeof (id) - 1); |
254 |
int i, n, rc; |
if (!strncmp (id, "NOKEY", 5)) |
255 |
char id[128], keyid[18+1]; |
return 1; |
256 |
|
} |
257 |
n = listview_count_items (lv, 0); |
|
258 |
for( i = 0; i < n; i++ ) { |
return 0; |
259 |
listview_get_item_text( lv, i, 1, id, sizeof id - 1 ); |
} |
260 |
if( !strncmp( id, "NOKEY", 5 ) ) { |
|
261 |
listview_get_item_text( lv, i, 4, keyid, sizeof keyid -1 ); |
|
262 |
rc = hkp_recv_key( dlg, default_keyserver, default_keyserver_port, keyid, 0, 0 ); |
/* Receive all missing keys marked in the list @lv. */ |
263 |
if( rc ) |
static void |
264 |
break; |
recv_missing_keys (HWND dlg, listview_ctrl_t lv) |
265 |
} |
{ |
266 |
} |
int i, n, cnt=0; |
267 |
|
char id[128], keyid[18+1]; |
268 |
return rc; |
|
269 |
} |
i = msg_box (dlg, _("Really receive all missing keys?"), |
270 |
|
_("Key Manager"), MB_YESNO|MB_INFO); |
271 |
|
if (i == IDNO) |
272 |
/* Create a mini popup with available choices. */ |
return; |
273 |
static void |
|
274 |
do_create_popup (HWND dlg) |
n = listview_count_items (lv, 0); |
275 |
{ |
for (i = 0; i < n; i++) { |
276 |
HMENU hm, sm; |
listview_get_item_text (lv, i, SL_COL_VALID, id, sizeof (id) - 1); |
277 |
POINT p; |
if (!strncmp (id, "NOKEY", 5)) { |
278 |
|
listview_get_item_text (lv, i, SL_COL_KEYID, |
279 |
GetCursorPos (&p); |
keyid, sizeof (keyid) -1); |
280 |
hm = LoadMenu (glob_hinst, MAKEINTRESOURCE (IDR_WINPT_KEYSIG_CTX)); |
if (!hkp_recv_key (dlg, default_keyserver, |
281 |
sm = GetSubMenu (hm, 0); |
default_keyserver_port, keyid, 0, 0)) |
282 |
|
cnt++; |
283 |
set_menu_text (sm, ID_SIGCTX_PROPS, _("Signature &Properties")); |
else |
284 |
set_menu_text (sm, ID_SIGCTX_KEYPROPS, _("Signing &Key Properties")); |
break; |
285 |
|
} |
286 |
TrackPopupMenu (sm, TPM_RIGHTALIGN, p.x, p.y, 0, dlg, NULL); |
} |
287 |
|
if (cnt > 0) |
288 |
DestroyMenu (hm); |
keycache_set_reload (1); |
289 |
DestroyMenu (sm); |
} |
290 |
} |
|
291 |
|
|
292 |
|
/* Create a mini popup with available choices. */ |
293 |
/* Load the key property dialog with the selected key from @lv. */ |
static void |
294 |
static void |
do_create_popup (HWND dlg) |
295 |
do_load_keyprops (HWND dlg, listview_ctrl_t lv) |
{ |
296 |
{ |
HMENU hm, sm; |
297 |
winpt_key_s k; |
POINT p; |
298 |
gpgme_key_t key; |
|
299 |
char keyid[32] = {0}; |
GetCursorPos (&p); |
300 |
char status[64] = {0}, creation[64] = {0}; |
hm = LoadMenu (glob_hinst, MAKEINTRESOURCE (IDR_WINPT_KEYSIG_CTX)); |
301 |
int n = listview_get_curr_pos (lv); |
sm = GetSubMenu (hm, 0); |
302 |
|
|
303 |
listview_get_item_text (lv, n, 1, status, DIM (status)-1); |
set_menu_text (sm, ID_SIGCTX_PROPS, _("Signature &Properties")); |
304 |
listview_get_item_text (lv, n, 3, creation, DIM (creation)-1); |
set_menu_text (sm, ID_SIGCTX_KEYPROPS, _("Signing &Key Properties")); |
305 |
listview_get_item_text (lv, n, 4, keyid, DIM (keyid)-1); |
|
306 |
if (!strcmp (status, "NOKEY")) { |
TrackPopupMenu (sm, TPM_RIGHTALIGN, p.x, p.y, 0, dlg, NULL); |
307 |
msg_box (dlg, _("Key not found in keyring, please get it from the keyserver first."), |
|
308 |
_("Key Manager"), MB_INFO); |
DestroyMenu (hm); |
309 |
return; |
DestroyMenu (sm); |
310 |
} |
} |
311 |
|
|
312 |
if ((strlen (keyid) < 3 ||get_pubkey (keyid, &key))) { |
|
313 |
if (strlen (creation) > 0) |
/* Fetch a single key and extract the keyid from the listview |
314 |
msg_box (dlg, _("Key not found in keyring."), _("Key Manager"), MB_INFO); |
entry at the pos @idx. */ |
315 |
return; |
static int |
316 |
} |
recv_single_key (HWND dlg, listview_ctrl_t lv, int idx) |
317 |
memset (&k, 0, sizeof k); |
{ |
318 |
k.keyid = keyid; |
char keyid[32]; |
319 |
DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_KEYPROPS, dlg, |
int rc; |
320 |
keyprops_dlg_proc, (LPARAM)&k); |
|
321 |
} |
listview_get_item_text (lv, idx, SL_COL_KEYID, keyid, DIM (keyid)-1); |
322 |
|
rc = hkp_recv_key (dlg, default_keyserver, |
323 |
|
default_keyserver_port, keyid, 0, 0); |
324 |
/* Dialog box procedure to list signatures. */ |
|
325 |
BOOL CALLBACK |
if (!rc) |
326 |
keysig_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
keycache_update (0, keyid); |
327 |
{ |
return rc; |
328 |
static listview_ctrl_t lv = NULL; |
} |
329 |
static struct winpt_key_s *k; |
|
330 |
char inf[384], keyid[18+1]; |
|
331 |
int idx = 0, id, rc; |
/* Load the key property dialog with the selected key from @lv. */ |
332 |
HWND sl; |
static void |
333 |
|
do_load_keyprops (HWND dlg, listview_ctrl_t lv) |
334 |
switch( msg ) { |
{ |
335 |
case WM_INITDIALOG: |
winpt_key_s k; |
336 |
k = (winpt_key_t) lparam; |
gpgme_key_t key; |
337 |
if (!k) |
char keyid[32] = {0}; |
338 |
BUG (0); |
char status[64] = {0}, creation[64] = {0}; |
339 |
if (k->uid) |
int n = listview_get_curr_pos (lv); |
340 |
_snprintf (inf, DIM (inf)-1, _("Signature List for \"%s\""), k->uid); |
|
341 |
SetWindowText (dlg, inf); |
listview_get_item_text (lv, n, SL_COL_VALID, status, DIM (status)-1); |
342 |
#ifndef LANG_DE |
listview_get_item_text (lv, n, SL_COL_CREATE, creation, DIM (creation)-1); |
343 |
SetDlgItemText (dlg, IDC_KEYSIG_RECVKEY, _("&Receive Key")); |
listview_get_item_text (lv, n, SL_COL_KEYID, keyid, DIM (keyid)-1); |
344 |
SetDlgItemText (dlg, IDC_KEYSIG_SIGPROPS, _("&Properties")); |
if (!strcmp (status, "NOKEY")) { |
345 |
#endif |
int id = msg_box (dlg, _("Key not found in keyring, do you want to fetch it from the keyserver?"), |
346 |
lv = siglist_load (GetDlgItem (dlg, IDC_KEYSIG_LIST), k->keyid); |
_("Key Manager"), MB_QUEST_ASK); |
347 |
if (!check_for_missing_keys (lv)) |
if (id == IDNO) |
348 |
EnableWindow (GetDlgItem( dlg, IDC_KEYSIG_RECVKEY ), FALSE); |
return; |
349 |
k->callback.ctl = lv; |
if (recv_single_key (dlg, lv, n)) |
350 |
sl = GetDlgItem (dlg, IDC_KEYSIG_LIST); |
return; |
351 |
siglist_proc.dlg = dlg; |
} |
352 |
siglist_proc.opaque = k; |
|
353 |
siglist_proc.current = (WNDPROC)subclass_dlg_proc; |
if ((strlen (keyid) < 3 ||get_pubkey (keyid, &key))) { |
354 |
siglist_proc.old = (WNDPROC)GetWindowLong (sl, GWL_WNDPROC); |
if (strlen (creation) > 0) |
355 |
if (siglist_proc.old) { |
msg_box (dlg, _("Key not found in keyring."), _("Key Manager"), MB_INFO); |
356 |
if (!SetWindowLong (sl, GWL_WNDPROC, (LONG)siglist_proc.current)) { |
return; |
357 |
msg_box (dlg, _("Could not set keylist window procedure."), |
} |
358 |
_("Key Manager"), MB_ERR); |
memset (&k, 0, sizeof k); |
359 |
BUG (0); |
k.keyid = keyid; |
360 |
} |
DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_KEYPROPS, dlg, |
361 |
} |
keyprops_dlg_proc, (LPARAM)&k); |
362 |
SetForegroundWindow (dlg); |
} |
363 |
center_window (dlg, NULL); |
|
364 |
return TRUE; |
|
365 |
|
/* Dialog box procedure to list signatures. */ |
366 |
case WM_DESTROY: |
BOOL CALLBACK |
367 |
if ( lv ) { |
keysig_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
368 |
siglist_delete( lv ); |
{ |
369 |
lv = NULL; |
static listview_ctrl_t lv = NULL; |
370 |
} |
static struct winpt_key_s *k; |
371 |
return FALSE; |
char inf[384]; |
372 |
|
int idx = 0; |
373 |
case WM_SYSCOMMAND: |
HWND sl; |
374 |
if (LOWORD (wparam) == SC_CLOSE) { |
|
375 |
if (k->update) |
switch (msg) { |
376 |
keycache_update (0, k->keyid); |
case WM_INITDIALOG: |
377 |
EndDialog (dlg, TRUE); |
k = (winpt_key_t) lparam; |
378 |
} |
if (!k) |
379 |
return FALSE; |
BUG (0); |
380 |
|
if (k->uid) |
381 |
case WM_NOTIFY: |
_snprintf (inf, DIM (inf)-1, _("Signature List for \"%s\""), k->uid); |
382 |
NMHDR * notify; |
SetWindowText (dlg, inf); |
383 |
|
SetDlgItemText (dlg, IDC_KEYSIG_RECVKEY, _("&Receive Key")); |
384 |
notify = (NMHDR *)lparam; |
SetDlgItemText (dlg, IDC_KEYSIG_SIGPROPS, _("&Properties")); |
385 |
if( notify && notify->code == NM_DBLCLK |
|
386 |
&& notify->idFrom == IDC_KEYSIG_LIST ) |
lv = siglist_load (GetDlgItem (dlg, IDC_KEYSIG_LIST), k->keyid); |
387 |
do_load_keyprops (dlg, lv); |
if (!check_for_missing_keys (lv)) |
388 |
if (notify && notify->code == NM_RCLICK && |
EnableWindow (GetDlgItem (dlg, IDC_KEYSIG_RECVKEY), FALSE); |
389 |
notify->idFrom == IDC_KEYSIG_LIST) |
EnableWindow (GetDlgItem (dlg, IDC_KEYSIG_SIGPROPS), FALSE); |
390 |
do_create_popup (dlg); |
k->callback.ctl = lv; |
391 |
break; |
sl = GetDlgItem (dlg, IDC_KEYSIG_LIST); |
392 |
|
siglist_proc.dlg = dlg; |
393 |
case WM_COMMAND: |
siglist_proc.opaque = k; |
394 |
switch ( LOWORD( wparam ) ) { |
siglist_proc.current = (WNDPROC)subclass_dlg_proc; |
395 |
|
siglist_proc.old = (WNDPROC)GetWindowLong (sl, GWL_WNDPROC); |
396 |
case ID_SIGCTX_KEYPROPS: |
if (siglist_proc.old) { |
397 |
do_load_keyprops (dlg, lv); |
if (!SetWindowLong (sl, GWL_WNDPROC, (LONG)siglist_proc.current)) { |
398 |
break; |
msg_box (dlg, _("Could not set keylist window procedure."), |
399 |
|
_("Key Manager"), MB_ERR); |
400 |
case ID_SIGCTX_PROPS: |
BUG (0); |
401 |
if (is_sig (lv, -1)) |
} |
402 |
DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_SIGPROPS, dlg, |
} |
403 |
sigprops_dlg_proc, (LPARAM)lv); |
SetForegroundWindow (dlg); |
404 |
break; |
center_window (dlg, NULL); |
405 |
|
return TRUE; |
406 |
case IDC_KEYSIG_RECVKEY: |
|
407 |
idx = listview_get_curr_pos (lv); |
case WM_DESTROY: |
408 |
if (idx == -1) { |
if (lv) { |
409 |
id = msg_box( dlg, _("Really receive all missing keys?"), |
siglist_delete (lv); |
410 |
_("Key Manager"), MB_YESNO|MB_INFO ); |
lv = NULL; |
411 |
if (id == IDYES) { |
} |
412 |
rc = recv_missing_keys (dlg, lv); |
return FALSE; |
413 |
if( !rc ) |
|
414 |
keycache_set_reload (1); |
case WM_SYSCOMMAND: |
415 |
return TRUE; |
if (LOWORD (wparam) == SC_CLOSE) { |
416 |
} |
if (k->update) |
417 |
return TRUE; |
keycache_update (0, k->keyid); |
418 |
} |
EndDialog (dlg, TRUE); |
419 |
listview_get_item_text (lv, idx, 1, inf, DIM (inf)-1); |
} |
420 |
if (strcmp (inf, "NOKEY")) |
return FALSE; |
421 |
return FALSE; |
|
422 |
listview_get_item_text (lv, idx, 4, keyid, DIM (keyid)-1); |
case WM_NOTIFY: |
423 |
rc = hkp_recv_key (dlg, default_keyserver, default_keyserver_port, keyid, 0, 0); |
NMHDR *notify; |
424 |
if (!rc) |
|
425 |
keycache_set_reload (1); |
notify = (NMHDR *)lparam; |
426 |
return TRUE; |
if (!notify) |
427 |
|
return FALSE; |
428 |
case IDC_KEYSIG_SIGPROPS: |
if (notify->code == NM_DBLCLK |
429 |
if (is_sig (lv, -1)) |
&& notify->idFrom == IDC_KEYSIG_LIST) |
430 |
DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_SIGPROPS, dlg, |
do_load_keyprops (dlg, lv); |
431 |
sigprops_dlg_proc, (LPARAM)lv); |
if (notify->code == NM_RCLICK && |
432 |
return TRUE; |
notify->idFrom == IDC_KEYSIG_LIST && |
433 |
|
is_sig (lv, -1)) |
434 |
case IDOK: |
do_create_popup (dlg); |
435 |
if (k->update) |
if (notify->code == LVN_ITEMCHANGED && |
436 |
keycache_update (0, k->keyid); |
((LPNMLISTVIEW)lparam)->uNewState) { |
437 |
EndDialog (dlg, TRUE); |
idx = listview_get_curr_pos (lv); |
438 |
return TRUE; |
listview_get_item_text (lv, idx, SL_COL_VALID, inf, DIM (inf)-1); |
439 |
} |
EnableWindow (GetDlgItem (dlg, IDC_KEYSIG_RECVKEY), |
440 |
break; |
strcmp (inf, "NOKEY") == 0? TRUE: FALSE); |
441 |
} |
EnableWindow (GetDlgItem (dlg, IDC_KEYSIG_SIGPROPS), |
442 |
return FALSE; |
is_sig (lv, -1)? TRUE : FALSE); |
443 |
|
} |
444 |
|
if (notify->code == LVN_COLUMNCLICK) { |
445 |
|
NMLISTVIEW *nft = (LPNMLISTVIEW) lparam; |
446 |
|
int sortby = 0; |
447 |
|
switch (nft->iSubItem) { |
448 |
|
//case 0: sortby = KEY_SORT_USERID; break; |
449 |
|
case 1: sortby = KEY_SORT_VALIDITY; break; |
450 |
|
case 2: sortby = SIG_SORT_CLASS; break; |
451 |
|
case 3: sortby = KEY_SORT_CREATED; break; |
452 |
|
case 4: sortby = KEY_SORT_KEYID; break; |
453 |
|
case 5: sortby = SIG_SORT_EXPIRE; break; |
454 |
|
case 6: sortby = KEY_SORT_ALGO; break; |
455 |
|
default: return TRUE; |
456 |
|
} |
457 |
|
siglist_sort (lv, sortby); |
458 |
|
} |
459 |
|
break; |
460 |
|
|
461 |
|
case WM_COMMAND: |
462 |
|
switch (LOWORD (wparam)) { |
463 |
|
case ID_SIGCTX_KEYPROPS: |
464 |
|
do_load_keyprops (dlg, lv); |
465 |
|
break; |
466 |
|
|
467 |
|
case ID_SIGCTX_PROPS: |
468 |
|
if (is_sig (lv, -1)) |
469 |
|
DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_SIGPROPS, dlg, |
470 |
|
sigprops_dlg_proc, (LPARAM)lv); |
471 |
|
break; |
472 |
|
|
473 |
|
case IDC_KEYSIG_RECVKEY: |
474 |
|
idx = listview_get_curr_pos (lv); |
475 |
|
if (idx == -1) |
476 |
|
recv_missing_keys (dlg, lv); |
477 |
|
else |
478 |
|
recv_single_key (dlg, lv, idx); |
479 |
|
return TRUE; |
480 |
|
|
481 |
|
case IDC_KEYSIG_SIGPROPS: |
482 |
|
if (is_sig (lv, -1)) |
483 |
|
DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_SIGPROPS, dlg, |
484 |
|
sigprops_dlg_proc, (LPARAM)lv); |
485 |
|
return TRUE; |
486 |
|
|
487 |
|
case IDOK: |
488 |
|
if (k->update) |
489 |
|
keycache_update (0, k->keyid); |
490 |
|
EndDialog (dlg, TRUE); |
491 |
|
return TRUE; |
492 |
|
} |
493 |
|
break; |
494 |
|
} |
495 |
|
return FALSE; |
496 |
} |
} |