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 "wptTypes.h" |
39 |
static subclass_s siglist_proc; |
#include "wptVersion.h" |
40 |
|
#include "wptErrors.h" |
41 |
|
#include "wptKeyEdit.h" |
42 |
static int inline |
|
43 |
is_sig (listview_ctrl_t lv, int pos) |
static subclass_s siglist_proc; |
44 |
{ |
|
45 |
char tmpbuf[256]; |
|
46 |
|
/* Return -1 if the selected item is a signature. */ |
47 |
if (pos == -1) |
static int |
48 |
pos = listview_get_curr_pos (lv); |
is_sig (listview_ctrl_t lv, int pos) |
49 |
listview_get_item_text (lv, pos, 0, tmpbuf, 200); |
{ |
50 |
if (*tmpbuf == ' ') |
char tmpbuf[200]; |
51 |
return -1; |
|
52 |
return 0; |
if (pos == -1) |
53 |
} |
pos = listview_get_curr_pos (lv); |
54 |
|
if (pos == -1) |
55 |
|
return 0; |
56 |
static int |
listview_get_item_text (lv, pos, SL_COL_UID, tmpbuf, sizeof (tmpbuf)-1); |
57 |
do_delsig (HWND dlg, listview_ctrl_t lv, winpt_key_t key) |
if (*tmpbuf == ' ') |
58 |
{ |
return -1; |
59 |
int pos, npos, id; |
return 0; |
60 |
int signo=0, uidno=0; |
} |
61 |
gpgme_ctx_t ctx; |
|
62 |
gpgme_editkey_t ek; |
|
63 |
gpgme_error_t rc; |
/* Delete the selected signature from list view @lv. The |
64 |
|
key is given in @key. */ |
65 |
npos = pos = listview_get_curr_pos (lv); |
static int |
66 |
if (!is_sig (lv, -1)) |
do_delsig (HWND dlg, listview_ctrl_t lv, winpt_key_t key) |
67 |
return -1; |
{ |
68 |
while (pos > 0 && is_sig (lv, pos)) |
gpgme_error_t err; |
69 |
{ |
GpgKeyEdit ke; |
70 |
signo++; |
char keyid[32]; |
71 |
pos--; |
int pos, npos, id, is_selfsig=0; |
72 |
} |
int signo=0, uidno=0; |
73 |
pos = npos; |
|
74 |
while (npos > 0) |
npos = pos = listview_get_curr_pos (lv); |
75 |
{ |
if (!is_sig (lv, -1)) |
76 |
if (!is_sig (lv, npos)) |
return -1; |
77 |
uidno++; |
listview_get_item_text (lv, pos, SL_COL_KEYID, keyid, sizeof (keyid)-1); |
78 |
npos--; |
if (!strncmp (key->keyid, keyid+2, 8)) |
79 |
} |
is_selfsig = 1; |
80 |
uidno++; |
|
81 |
id = log_box(_("Key Manager"), MB_YESNO, |
while (pos > 0 && is_sig (lv, pos)) { |
82 |
_("Are you really sure you want to delete this signature from\n" |
signo++; |
83 |
" \"%s\""), key->uid); |
pos--; |
84 |
if (id == IDNO) |
} |
85 |
return 0; |
pos = npos; |
86 |
rc = gpgme_new (&ctx); |
while (npos > 0) { |
87 |
if (rc) |
if (!is_sig (lv, npos)) |
88 |
BUG (0); |
uidno++; |
89 |
rc = gpgme_editkey_new (&ek); |
npos--; |
90 |
if (rc) |
} |
91 |
BUG (0); |
uidno++; |
92 |
gpgme_editkey_delsig_set (ek, uidno, signo); |
|
93 |
gpgme_set_edit_ctx (ctx, ek, GPGME_EDITKEY_DELSIG); |
/* XXX: do not allow to delete the self signature */ |
94 |
rc = gpgme_op_editkey (ctx, key->keyid); |
id = log_box (_("Key Manager"), is_selfsig? MB_WARN_ASK : MB_QUEST_ASK, |
95 |
if (rc) |
_("Are you really sure you want to delete this %s from\n\n" |
96 |
msg_box (dlg, gpgme_strerror (rc), _("Key Manager"), MB_ERR); |
" \"%s\""), is_selfsig? _("self signature") : _("signature"), |
97 |
else |
key->uid); |
98 |
listview_del_item (lv, pos); |
if (id == IDNO) |
99 |
gpgme_release (ctx); |
return 0; |
100 |
gpgme_editkey_release (ek); |
|
101 |
return 0; |
ke.setKeyID (key->keyid); |
102 |
} |
err = ke.delUseridSignature (uidno, signo); |
103 |
|
if (err) |
104 |
|
msg_box (dlg, gpgme_strerror (err), _("Key Manager"), MB_ERR); |
105 |
static BOOL CALLBACK |
else |
106 |
sigprops_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
listview_del_item (lv, pos); |
107 |
{ |
if (!err) |
108 |
static listview_ctrl_t lv; |
key->update = 1; |
109 |
char tmpbuf[256]; |
return err? -1 : 0; |
110 |
int n; |
} |
111 |
struct { |
|
112 |
unsigned int exportable:1; |
|
113 |
unsigned int expired:1; |
/* Initialize a datepicker control with the time given in @t. */ |
114 |
unsigned int nrev:1; |
static void |
115 |
unsigned int rev:1; |
init_datepicker_from_time (HWND picker, time_t t) |
116 |
const char * alg; |
{ |
117 |
int _class; |
SYSTEMTIME st; |
118 |
} ctx; |
struct tm *tm; |
119 |
const char * fmt_templ = "%s %s signature"; |
|
120 |
|
tm = localtime (&t); |
121 |
switch (msg) |
memset (&st, 0, sizeof st); |
122 |
{ |
st.wYear = tm->tm_year+1900; |
123 |
case WM_SYSCOMMAND: |
st.wMonth = tm->tm_mon+1; |
124 |
if (LOWORD (wparam) == SC_CLOSE) |
st.wDay = tm->tm_mday; |
125 |
EndDialog (dlg, TRUE); |
DateTime_SetSystemtime (picker, GDT_VALID, &st); |
126 |
return FALSE; |
} |
127 |
|
|
128 |
case WM_INITDIALOG: |
|
129 |
lv = (listview_ctrl_t)lparam; |
/* Dialog box procedure to display the signature properties. */ |
130 |
if (!lv) |
BOOL CALLBACK |
131 |
dlg_fatal_error (dlg, "could not get dialog param"); |
sigprops_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
132 |
memset (&ctx, 0, sizeof ctx); |
{ |
133 |
n = listview_get_curr_pos (lv); |
gpgme_key_sig_t ks; |
134 |
listview_get_item_text (lv, n, 2, tmpbuf, DIM (tmpbuf)-1); |
winpt_key_s issuer; |
135 |
if (!strstr (tmpbuf, "L")) |
char tmpbuf[256]; |
136 |
ctx.exportable = 1; |
static struct { |
137 |
ctx._class = atoi (tmpbuf); |
unsigned int exportable:1; |
138 |
if (ctx._class == 0) |
unsigned int expired:1; |
139 |
ctx._class = 10; |
unsigned int nrev:1; |
140 |
else if (ctx._class < 10) |
unsigned int rev:1; |
141 |
ctx._class += 10; |
const char *alg; |
142 |
listview_get_item_text (lv, n, 6, tmpbuf, DIM (tmpbuf)-1); |
int _class; |
143 |
if (strstr (tmpbuf, "DSA")) |
} ctx; |
144 |
ctx.alg = "DSA"; |
const char *fmt_templ = _("%s %s signature"); |
145 |
else if (strstr (tmpbuf, "RSA")) |
const char *s; |
146 |
ctx.alg = "RSA"; |
|
147 |
else |
switch (msg) { |
148 |
ctx.alg = "ELG"; |
case WM_INITDIALOG: |
149 |
_snprintf (tmpbuf, DIM (tmpbuf)-1, fmt_templ, |
ks = (gpgme_key_sig_t)lparam; |
150 |
ctx.exportable? "Exportable" : "Non-exportable", ctx.alg); |
if (!ks) |
151 |
SetDlgItemText (dlg, IDC_SIGPROPS_INFO, tmpbuf); |
BUG (0); |
152 |
listview_get_item_text (lv, n, 4, tmpbuf, DIM (tmpbuf)-1); |
SetDlgItemText (dlg, IDC_SIGPROPS_EXP, _("Exportable")); |
153 |
SetDlgItemText (dlg, IDC_SIGPROPS_KEYID, tmpbuf); |
SetDlgItemText (dlg, IDC_SIGPROPS_NREV, _("Non-revocably")); |
154 |
SetDlgItemInt (dlg, IDC_SIGPROPS_CLASS, ctx._class, FALSE); |
SetDlgItemText (dlg, IDC_SIGPROPS_EXPIRED, _("Expired")); |
155 |
if (ctx.exportable) |
SetDlgItemText (dlg, IDC_SIGPROPS_REV, _("Revoked")); |
156 |
CheckDlgButton (dlg, IDC_SIGPROPS_EXP, BST_CHECKED); |
SetDlgItemText (dlg, IDC_SIGPROPS_CLASSINF, _("Class")); |
157 |
listview_get_item_text (lv, n, 0, tmpbuf, DIM (tmpbuf)-1); |
SetDlgItemText (dlg, IDC_SIGPROPS_EXPSTR, _("Expire date")); |
158 |
SetDlgItemText (dlg, IDC_SIGPROPS_ISSUER, tmpbuf+1); |
SetDlgItemText (dlg, IDC_SIGPROPS_CREATSTR, _("Creation date")); |
159 |
tmpbuf[0] = 0; |
SetDlgItemText (dlg, IDC_SIGPROPS_KEYINF, _("Issuer key")); |
160 |
listview_get_item_text (lv, n, 5, tmpbuf, DIM (tmpbuf)-1); |
SetDlgItemText (dlg, IDC_SIGPROPS_KEYIDINF, _("Issuer key ID")); |
161 |
if (strlen (tmpbuf) == 0) |
SetDlgItemText (dlg, IDC_SIGPROPS_POLICINF, _("Policy URL")); |
162 |
{ |
SetWindowText (dlg, _("Signature Properties")); |
163 |
ShowWindow (GetDlgItem (dlg, IDC_SIGPROPS_EXPSTR), SW_HIDE); |
|
164 |
ShowWindow (GetDlgItem (dlg, IDC_SIGPROPS_EXPDATE), SW_HIDE); |
memset (&ctx, 0, sizeof ctx); |
165 |
} |
ctx._class = ks->sig_class; |
166 |
else |
if (ctx._class == 0) |
167 |
{ |
ctx._class = 16; |
168 |
SYSTEMTIME st; |
ctx._class -= 6; |
169 |
struct tm * tm; |
if (ks->pubkey_algo == GPGME_PK_DSA) |
170 |
time_t t = time (NULL); |
ctx.alg = "DSA"; |
171 |
|
else if (ks->pubkey_algo == GPGME_PK_RSA) |
172 |
memset (&st, 0, sizeof st); |
ctx.alg = "RSA"; |
173 |
st.wYear = atoi (tmpbuf); |
else |
174 |
st.wMonth = atoi (tmpbuf+5); |
ctx.alg = "ELG"; |
175 |
st.wDay = atoi (tmpbuf+8); |
ctx.exportable = ks->exportable; |
176 |
DateTime_SetSystemtime (GetDlgItem (dlg, IDC_SIGPROPS_EXPDATE), |
_snprintf (tmpbuf, DIM (tmpbuf)-1, fmt_templ, |
177 |
GDT_VALID, &st); |
ctx.exportable? _("Exportable") : _("Non-exportable"), |
178 |
|
ctx.alg); |
179 |
tm = localtime (&t); |
SetDlgItemText (dlg, IDC_SIGPROPS_INFO, tmpbuf); |
180 |
tm->tm_mon++; |
|
181 |
tm->tm_year += 1900; |
_snprintf (tmpbuf, DIM (tmpbuf)-1, "0x%s", ks->keyid+8); |
182 |
if (tm->tm_year > st.wYear) |
SetDlgItemText (dlg, IDC_SIGPROPS_KEYID, tmpbuf); |
183 |
ctx.expired = 1; |
SetDlgItemInt (dlg, IDC_SIGPROPS_CLASS, ctx._class, FALSE); |
184 |
else if (tm->tm_mon > st.wMonth) |
if (ctx.exportable) |
185 |
ctx.expired = 1; |
CheckDlgButton (dlg, IDC_SIGPROPS_EXP, BST_CHECKED); |
186 |
if (ctx.expired) |
memset (&issuer, 0, sizeof (issuer)); |
187 |
CheckDlgButton (dlg, IDC_SIGPROPS_EXPIRED, BST_CHECKED); |
if (!winpt_get_pubkey (ks->keyid+8, &issuer)) |
188 |
} |
s = issuer.ext->uids->uid; |
189 |
SetDlgItemText (dlg, IDC_SIGPROPS_EXP, _("Exportable")); |
else |
190 |
SetDlgItemText (dlg, IDC_SIGPROPS_NREV, _("Non-revocably")); |
s = _(" user ID not found"); |
191 |
SetDlgItemText (dlg, IDC_SIGPROPS_REV, _("Revoked")); |
SetDlgItemText (dlg, IDC_SIGPROPS_ISSUER, s); |
192 |
SetDlgItemText (dlg, IDC_SIGPROPS_EXPIRED, _("Expired")); |
|
193 |
SetForegroundWindow (dlg); |
init_datepicker_from_time (GetDlgItem (dlg, IDC_SIGPROPS_CREATDATE), |
194 |
center_window (dlg); |
ks->timestamp); |
195 |
return TRUE; |
if (ks->expires == 0) { |
196 |
|
ShowWindow (GetDlgItem (dlg, IDC_SIGPROPS_EXPSTR), SW_HIDE); |
197 |
case WM_COMMAND: |
ShowWindow (GetDlgItem (dlg, IDC_SIGPROPS_EXPDATE), SW_HIDE); |
198 |
switch (LOWORD (wparam)) |
} |
199 |
{ |
else { |
200 |
case IDOK: |
init_datepicker_from_time (GetDlgItem (dlg, IDC_SIGPROPS_EXPDATE), |
201 |
EndDialog (dlg, TRUE); |
ks->expires); |
202 |
break; |
if (time (NULL) > ks->expires) |
203 |
} |
ctx.expired = 1; |
204 |
} |
if (ctx.expired) |
205 |
|
CheckDlgButton (dlg, IDC_SIGPROPS_EXPIRED, BST_CHECKED); |
206 |
return FALSE; |
} |
207 |
} |
if (ks->notations && !ks->notations->name && ks->notations->value) |
208 |
|
SetDlgItemText (dlg, IDC_SIGPROPS_POLIC, ks->notations->value); |
209 |
|
|
210 |
static BOOL CALLBACK |
SetDlgItemText (dlg, IDC_SIGPROPS_EXP, _("Exportable")); |
211 |
subclass_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
SetDlgItemText (dlg, IDC_SIGPROPS_NREV, _("Non-revocably")); |
212 |
{ |
SetDlgItemText (dlg, IDC_SIGPROPS_REV, _("Revoked")); |
213 |
listview_ctrl_t lv; |
SetDlgItemText (dlg, IDC_SIGPROPS_EXPIRED, _("Expired")); |
214 |
winpt_key_t key; |
SetWindowText (dlg, _("Signature Properties")); |
215 |
|
SetForegroundWindow (dlg); |
216 |
switch (msg) |
center_window (dlg, NULL); |
217 |
{ |
return TRUE; |
218 |
case WM_KEYUP: |
|
219 |
int virt_key = (int)wparam; |
case WM_COMMAND: |
220 |
key = (winpt_key_t)siglist_proc.opaque; |
if (HIWORD (wparam) == BN_CLICKED) { |
221 |
lv = key->callback.ctl; |
/* Code to prevent the user changes the check buttons. */ |
222 |
if (virt_key == VK_SPACE) |
switch (LOWORD (wparam)) { |
223 |
{ |
case IDC_SIGPROPS_EXP: |
224 |
if (is_sig (lv, -1)) |
CheckDlgButton (dlg, IDC_SIGPROPS_EXP, |
225 |
DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_SIGPROPS, dlg, |
ctx.exportable? BST_CHECKED : BST_UNCHECKED); |
226 |
sigprops_dlg_proc, (LPARAM)lv); |
return TRUE; |
227 |
} |
|
228 |
else if (virt_key == VK_DELETE) |
case IDC_SIGPROPS_EXPIRED: |
229 |
do_delsig (dlg, lv, key); |
CheckDlgButton (dlg, IDC_SIGPROPS_EXPIRED, |
230 |
break; |
ctx.expired? BST_CHECKED : BST_UNCHECKED); |
231 |
} |
return TRUE; |
232 |
return CallWindowProc (siglist_proc.old, dlg, msg, wparam, lparam); |
|
233 |
} |
case IDC_SIGPROPS_REV: |
234 |
|
CheckDlgButton (dlg, IDC_SIGPROPS_REV, |
235 |
|
ctx.rev? BST_CHECKED : BST_UNCHECKED); |
236 |
static int |
return TRUE; |
237 |
check_for_missing_keys (listview_ctrl_t lv) |
|
238 |
{ |
case IDC_SIGPROPS_NREV: |
239 |
int i, n; |
CheckDlgButton (dlg, IDC_SIGPROPS_NREV, |
240 |
char id[128]; |
ctx.nrev? BST_CHECKED : BST_UNCHECKED); |
241 |
|
return TRUE; |
242 |
n = listview_count_items( lv, 0 ); |
} |
243 |
for( i = 0; i < n; i++ ) { |
} |
244 |
listview_get_item_text( lv, i, 1, id, sizeof id - 1 ); |
|
245 |
if( !strncmp( id, "NOKEY", 5 ) ) |
switch (LOWORD (wparam)) { |
246 |
return 1; |
case IDOK: |
247 |
} |
EndDialog (dlg, TRUE); |
248 |
|
break; |
249 |
return 0; |
|
250 |
} /* check_for_missing_keys */ |
case IDCANCEL: |
251 |
|
EndDialog (dlg, FALSE); |
252 |
|
break; |
253 |
static int |
} |
254 |
recv_missing_keys (HWND dlg, listview_ctrl_t lv) |
} |
255 |
{ |
|
256 |
int i, n, rc; |
return FALSE; |
257 |
char id[128], keyid[18+1]; |
} |
258 |
|
|
259 |
n = listview_count_items (lv, 0); |
|
260 |
for( i = 0; i < n; i++ ) { |
/* Subclass window procedure for the list view. */ |
261 |
listview_get_item_text( lv, i, 1, id, sizeof id - 1 ); |
static BOOL CALLBACK |
262 |
if( !strncmp( id, "NOKEY", 5 ) ) { |
subclass_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
263 |
listview_get_item_text( lv, i, 4, keyid, sizeof keyid -1 ); |
{ |
264 |
rc = hkp_recv_key( dlg, default_keyserver, default_keyserver_port, keyid, 0, 0 ); |
listview_ctrl_t lv; |
265 |
if( rc ) |
winpt_key_t key; |
266 |
break; |
gpgme_key_sig_t ks; |
267 |
} |
|
268 |
} |
switch (msg) { |
269 |
|
case WM_KEYUP: |
270 |
return rc; |
int virt_key = (int)wparam; |
271 |
} /* recv_missing_keys */ |
key = (winpt_key_t)siglist_proc.opaque; |
272 |
|
lv = key->callback.ctl; |
273 |
|
if (virt_key == VK_SPACE) { |
274 |
static void |
if (is_sig (lv, -1)) { |
275 |
do_create_popup (HWND dlg) |
ks = (gpgme_key_sig_t)listview_get_item2 (lv, listview_get_curr_pos (lv)); |
276 |
{ |
DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_SIGPROPS, dlg, |
277 |
HMENU hm, sm; |
sigprops_dlg_proc, (LPARAM)ks); |
278 |
POINT p; |
} |
279 |
|
} |
280 |
GetCursorPos (&p); |
else if (virt_key == VK_DELETE) |
281 |
hm = LoadMenu (glob_hinst, MAKEINTRESOURCE (IDR_WINPT_KEYSIG_CTX)); |
do_delsig (dlg, lv, key); |
282 |
sm = GetSubMenu (hm, 0); |
break; |
283 |
|
} |
284 |
TrackPopupMenu (sm, TPM_RIGHTALIGN, p.x, p.y, 0, dlg, NULL); |
return CallWindowProc (siglist_proc.old, dlg, msg, wparam, lparam); |
285 |
|
} |
286 |
DestroyMenu (hm); |
|
287 |
DestroyMenu (sm); |
|
288 |
} |
/* Return 1 if the list view @lv contains non-available keys. */ |
289 |
|
static int |
290 |
|
check_for_missing_keys (listview_ctrl_t lv) |
291 |
static void |
{ |
292 |
do_load_keyprops (HWND dlg, listview_ctrl_t lv) |
int i, n; |
293 |
{ |
char id[128]; |
294 |
winpt_key_s k; |
|
295 |
gpgme_key_t key; |
n = listview_count_items (lv, 0); |
296 |
char keyid[32] = {0}; |
for (i = 0; i < n; i++) { |
297 |
char status[64] = {0}, creation[64] = {0}; |
listview_get_item_text (lv, i, SL_COL_VALID, id, sizeof (id) - 1); |
298 |
int n = listview_get_curr_pos (lv); |
if (!strncmp (id, "NOKEY", 5)) |
299 |
|
return 1; |
300 |
listview_get_item_text (lv, n, 1, status, DIM (status)-1); |
} |
301 |
listview_get_item_text (lv, n, 3, creation, DIM (creation)-1); |
|
302 |
listview_get_item_text (lv, n, 4, keyid, DIM (keyid)-1); |
return 0; |
303 |
if (!strcmp (status, "NOKEY")) { |
} |
304 |
msg_box (dlg, _("Key not found in keyring, please get it from the keyserver first."), |
|
305 |
_("Key Manager"), MB_INFO); |
|
306 |
return; |
/* Receive all missing keys marked in the list @lv. */ |
307 |
} |
static int |
308 |
|
recv_missing_keys (HWND dlg, listview_ctrl_t lv) |
309 |
if ((strlen (keyid) < 3 ||get_pubkey (keyid, &key))) { |
{ |
310 |
if (strlen (creation) > 0) |
char id[128], keyid[18+1]; |
311 |
msg_box (dlg, _("Key not found in keyring."), _("Key Manager"), MB_INFO); |
int i, n, cnt=0; |
312 |
return; |
|
313 |
} |
i = msg_box (dlg, _("Really receive all missing keys?"), |
314 |
memset (&k, 0, sizeof k); |
_("Key Manager"), MB_YESNO|MB_INFO); |
315 |
k.keyid = keyid; |
if (i == IDNO) |
316 |
DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_KEYPROPS, dlg, |
return 0; |
317 |
keyprops_dlg_proc, (LPARAM)&k); |
|
318 |
} |
n = listview_count_items (lv, 0); |
319 |
|
for (i = 0; i < n; i++) { |
320 |
|
listview_get_item_text (lv, i, SL_COL_VALID, id, sizeof (id) - 1); |
321 |
BOOL CALLBACK |
if (!strncmp (id, "NOKEY", 5)) { |
322 |
keysig_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
listview_get_item_text (lv, i, SL_COL_KEYID, |
323 |
{ |
keyid, sizeof (keyid) -1); |
324 |
static listview_ctrl_t lv = NULL; |
if (!hkp_recv_key (dlg, default_keyserver, |
325 |
struct winpt_key_s *k; |
default_keyserver_port, keyid, 0, 0)) { |
326 |
char inf[384], keyid[18+1]; |
keycache_update (0, keyid); |
327 |
int idx = 0, id, rc; |
cnt++; |
328 |
HWND sl; |
} |
329 |
|
else |
330 |
switch( msg ) { |
break; |
331 |
case WM_INITDIALOG: |
} |
332 |
k = (winpt_key_t) lparam; |
} |
333 |
if (!k) |
return cnt; |
334 |
BUG (0); |
} |
335 |
if( k->uid ) |
|
336 |
_snprintf( inf, sizeof inf - 1, _("Signature List for \"%s\""), k->uid ); |
|
337 |
SetWindowText( dlg, inf ); |
/* Create a mini popup with available choices. */ |
338 |
#ifndef LANG_DE |
static void |
339 |
SetDlgItemText( dlg, IDC_KEYSIG_RECVKEY, _("&Receive Key") ); |
do_create_popup (HWND dlg) |
340 |
SetDlgItemText (dlg, IDC_KEYSIG_SIGPROPS, _("&Properties")); |
{ |
341 |
#endif |
HMENU hm, sm; |
342 |
lv = siglist_load( GetDlgItem( dlg, IDC_KEYSIG_LIST ), k->keyid ); |
POINT p; |
343 |
if( !check_for_missing_keys( lv ) ) |
|
344 |
EnableWindow( GetDlgItem( dlg, IDC_KEYSIG_RECVKEY ), FALSE ); |
GetCursorPos (&p); |
345 |
k->callback.ctl = lv; |
hm = LoadMenu (glob_hinst, MAKEINTRESOURCE (IDR_WINPT_KEYSIG_CTX)); |
346 |
sl = GetDlgItem (dlg, IDC_KEYSIG_LIST); |
sm = GetSubMenu (hm, 0); |
347 |
siglist_proc.dlg = dlg; |
set_menu_text (sm, ID_SIGCTX_PROPS, _("Signature &Properties")); |
348 |
siglist_proc.opaque = k; |
set_menu_text (sm, ID_SIGCTX_KEYPROPS, _("Signing &Key Properties")); |
349 |
siglist_proc.current = (WNDPROC)subclass_dlg_proc; |
TrackPopupMenu (sm, TPM_RIGHTALIGN, p.x, p.y, 0, dlg, NULL); |
350 |
siglist_proc.old = (WNDPROC)GetWindowLong (sl, GWL_WNDPROC); |
DestroyMenu (hm); |
351 |
if (siglist_proc.old) |
DestroyMenu (sm); |
352 |
{ |
} |
353 |
if (!SetWindowLong (sl, GWL_WNDPROC, (LONG)siglist_proc.current)) |
|
354 |
{ |
|
355 |
msg_box (dlg, _("Could not set keylist window procedure."), _("Key Manager"), MB_ERR); |
/* Fetch a single key and extract the keyid from the listview |
356 |
BUG (0); |
entry at the pos @idx. */ |
357 |
} |
static int |
358 |
} |
recv_single_key (HWND dlg, listview_ctrl_t lv, int idx) |
359 |
SetForegroundWindow (dlg); |
{ |
360 |
center_window (dlg); |
char keyid[32]; |
361 |
return TRUE; |
int rc; |
362 |
|
|
363 |
case WM_DESTROY: |
listview_get_item_text (lv, idx, SL_COL_KEYID, keyid, DIM (keyid)-1); |
364 |
if ( lv ) { |
rc = hkp_recv_key (dlg, default_keyserver, |
365 |
siglist_delete( lv ); |
default_keyserver_port, keyid, 0, 0); |
366 |
lv = NULL; |
if (!rc) |
367 |
} |
keycache_update (0, keyid); |
368 |
return FALSE; |
return rc; |
369 |
|
} |
370 |
case WM_SYSCOMMAND: |
|
371 |
if( LOWORD ( wparam ) == SC_CLOSE ) |
|
372 |
EndDialog( dlg, TRUE ); |
/* Load the key property dialog with the selected key from @lv. */ |
373 |
return FALSE; |
static void |
374 |
|
do_load_keyprops (HWND dlg, listview_ctrl_t lv) |
375 |
case WM_NOTIFY: |
{ |
376 |
NMHDR * notify; |
winpt_key_s k; |
377 |
|
char keyid[32] = {0}; |
378 |
notify = (NMHDR *)lparam; |
char status[64] = {0}, creation[64] = {0}; |
379 |
if( notify && notify->code == NM_DBLCLK |
int n = listview_get_curr_pos (lv); |
380 |
&& notify->idFrom == IDC_KEYSIG_LIST ) |
|
381 |
do_load_keyprops (dlg, lv); |
listview_get_item_text (lv, n, SL_COL_VALID, status, DIM (status)-1); |
382 |
if (notify && notify->code == NM_RCLICK && |
listview_get_item_text (lv, n, SL_COL_CREATE, creation, DIM (creation)-1); |
383 |
notify->idFrom == IDC_KEYSIG_LIST) |
listview_get_item_text (lv, n, SL_COL_KEYID, keyid, DIM (keyid)-1); |
384 |
do_create_popup (dlg); |
if (!strcmp (status, "NOKEY")) { |
385 |
break; |
int id = msg_box (dlg, _("Key not found in keyring, do you want to fetch it from the keyserver?"), |
386 |
|
_("Key Manager"), MB_QUEST_ASK); |
387 |
case WM_COMMAND: |
if (id == IDNO) |
388 |
switch ( LOWORD( wparam ) ) { |
return; |
389 |
|
if (recv_single_key (dlg, lv, n)) |
390 |
case ID_SIGCTX_KEYPROPS: |
return; |
391 |
do_load_keyprops (dlg, lv); |
} |
392 |
break; |
|
393 |
|
memset (&k, 0, sizeof k); |
394 |
case ID_SIGCTX_PROPS: |
if ((strlen (keyid) < 3 || winpt_get_pubkey (keyid, &k))) { |
395 |
if (is_sig (lv, -1)) |
if (strlen (creation) > 0) |
396 |
DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_SIGPROPS, dlg, |
msg_box (dlg, _("Key not found in keyring."), _("Key Manager"), MB_INFO); |
397 |
sigprops_dlg_proc, (LPARAM)lv); |
return; |
398 |
break; |
} |
399 |
|
DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_KEYPROPS, dlg, |
400 |
case IDC_KEYSIG_RECVKEY: |
keyprops_dlg_proc, (LPARAM)&k); |
401 |
idx = listview_get_curr_pos( lv ); |
} |
402 |
if( idx == -1 ) { |
|
403 |
id = msg_box( dlg, _("Really receive all missing keys?"), |
|
404 |
_("Key Manager"), MB_YESNO|MB_INFO ); |
/* Dialog box procedure to list signatures. */ |
405 |
if( id == IDYES ) { |
BOOL CALLBACK |
406 |
rc = recv_missing_keys( dlg, lv ); |
keysig_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
407 |
if( !rc ) |
{ |
408 |
keycache_set_reload( 1 ); |
static listview_ctrl_t lv = NULL; |
409 |
return TRUE; |
static struct winpt_key_s *k; |
410 |
} |
gpgme_key_sig_t ks; |
411 |
return FALSE; |
HWND sl; |
412 |
} |
char inf[384]; |
413 |
listview_get_item_text (lv, idx, 4, keyid, sizeof keyid - 1); |
int idx = 0; |
414 |
rc = hkp_recv_key (dlg, default_keyserver, default_keyserver_port, keyid, 0, 0); |
|
415 |
if (!rc) |
switch (msg) { |
416 |
keycache_set_reload (1); |
case WM_INITDIALOG: |
417 |
return TRUE; |
k = (winpt_key_t) lparam; |
418 |
|
if (!k) |
419 |
case IDC_KEYSIG_SIGPROPS: |
BUG (0); |
420 |
if (is_sig (lv, -1)) |
if (k->uid) |
421 |
DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_SIGPROPS, dlg, |
_snprintf (inf, DIM (inf)-1, _("Signature List for \"%s\""), k->uid); |
422 |
sigprops_dlg_proc, (LPARAM)lv); |
SetWindowText (dlg, inf); |
423 |
return TRUE; |
SetDlgItemText (dlg, IDC_KEYSIG_RECVKEY, _("&Receive Key")); |
424 |
|
SetDlgItemText (dlg, IDC_KEYSIG_SIGPROPS, _("&Properties")); |
425 |
case IDOK: |
|
426 |
EndDialog (dlg, TRUE); |
lv = siglist_load (GetDlgItem (dlg, IDC_KEYSIG_LIST), k->keyid); |
427 |
return TRUE; |
if (!check_for_missing_keys (lv)) |
428 |
} |
EnableWindow (GetDlgItem (dlg, IDC_KEYSIG_RECVKEY), FALSE); |
429 |
break; |
EnableWindow (GetDlgItem (dlg, IDC_KEYSIG_SIGPROPS), FALSE); |
430 |
} |
k->callback.ctl = lv; |
431 |
return FALSE; |
sl = GetDlgItem (dlg, IDC_KEYSIG_LIST); |
432 |
} /* keysig_dlg_proc */ |
siglist_proc.dlg = dlg; |
433 |
|
siglist_proc.opaque = k; |
434 |
|
siglist_proc.current = (WNDPROC)subclass_dlg_proc; |
435 |
|
siglist_proc.old = (WNDPROC)GetWindowLong (sl, GWL_WNDPROC); |
436 |
|
if (siglist_proc.old) { |
437 |
|
if (!SetWindowLong (sl, GWL_WNDPROC, (LONG)siglist_proc.current)) { |
438 |
|
msg_box (dlg, "Could not set keylist window procedure.", |
439 |
|
_("Key Manager"), MB_ERR); |
440 |
|
BUG (0); |
441 |
|
} |
442 |
|
} |
443 |
|
SetForegroundWindow (dlg); |
444 |
|
center_window (dlg, NULL); |
445 |
|
return TRUE; |
446 |
|
|
447 |
|
case WM_DESTROY: |
448 |
|
if (lv) { |
449 |
|
siglist_delete (lv); |
450 |
|
lv = NULL; |
451 |
|
} |
452 |
|
return FALSE; |
453 |
|
|
454 |
|
case WM_NOTIFY: |
455 |
|
NMHDR *notify; |
456 |
|
|
457 |
|
notify = (NMHDR *)lparam; |
458 |
|
if (!notify) |
459 |
|
return FALSE; |
460 |
|
if (notify->code == NM_DBLCLK && |
461 |
|
notify->idFrom == IDC_KEYSIG_LIST) |
462 |
|
do_load_keyprops (dlg, lv); |
463 |
|
if (notify->code == NM_RCLICK && |
464 |
|
notify->idFrom == IDC_KEYSIG_LIST && |
465 |
|
is_sig (lv, -1)) |
466 |
|
do_create_popup (dlg); |
467 |
|
if (notify->code == LVN_ITEMCHANGED && |
468 |
|
((LPNMLISTVIEW)lparam)->uNewState) { |
469 |
|
idx = listview_get_curr_pos (lv); |
470 |
|
listview_get_item_text (lv, idx, SL_COL_VALID, inf, DIM (inf)-1); |
471 |
|
EnableWindow (GetDlgItem (dlg, IDC_KEYSIG_RECVKEY), |
472 |
|
strcmp (inf, "NOKEY") == 0? TRUE: FALSE); |
473 |
|
EnableWindow (GetDlgItem (dlg, IDC_KEYSIG_SIGPROPS), |
474 |
|
is_sig (lv, -1)? TRUE : FALSE); |
475 |
|
} |
476 |
|
if (notify->code == LVN_COLUMNCLICK) { |
477 |
|
NMLISTVIEW *nft = (LPNMLISTVIEW) lparam; |
478 |
|
int sortby = 0; |
479 |
|
switch (nft->iSubItem) { |
480 |
|
//case 0: sortby = KEY_SORT_USERID; break; |
481 |
|
case 1: sortby = KEY_SORT_VALIDITY; break; |
482 |
|
case 2: sortby = SIG_SORT_CLASS; break; |
483 |
|
case 3: sortby = KEY_SORT_CREATED; break; |
484 |
|
case 4: sortby = KEY_SORT_KEYID; break; |
485 |
|
case 5: sortby = SIG_SORT_EXPIRE; break; |
486 |
|
case 6: sortby = KEY_SORT_ALGO; break; |
487 |
|
default: return TRUE; |
488 |
|
} |
489 |
|
siglist_sort (lv, sortby); |
490 |
|
} |
491 |
|
break; |
492 |
|
|
493 |
|
case WM_COMMAND: |
494 |
|
switch (LOWORD (wparam)) { |
495 |
|
case ID_SIGCTX_KEYPROPS: |
496 |
|
do_load_keyprops (dlg, lv); |
497 |
|
return TRUE; |
498 |
|
|
499 |
|
case ID_SIGCTX_PROPS: |
500 |
|
if (is_sig (lv, -1)) { |
501 |
|
ks = (gpgme_key_sig_t)listview_get_item2 (lv, listview_get_curr_pos (lv)); |
502 |
|
DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_SIGPROPS, dlg, |
503 |
|
sigprops_dlg_proc, (LPARAM)ks); |
504 |
|
} |
505 |
|
return TRUE; |
506 |
|
|
507 |
|
case IDC_KEYSIG_RECVKEY: |
508 |
|
idx = listview_get_curr_pos (lv); |
509 |
|
if (idx == -1) |
510 |
|
recv_missing_keys (dlg, lv); |
511 |
|
else |
512 |
|
recv_single_key (dlg, lv, idx); |
513 |
|
return TRUE; |
514 |
|
|
515 |
|
case IDC_KEYSIG_SIGPROPS: |
516 |
|
if (is_sig (lv, -1)) { |
517 |
|
ks = ks = (gpgme_key_sig_t)listview_get_item2 (lv, listview_get_curr_pos (lv)); |
518 |
|
DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_SIGPROPS, dlg, |
519 |
|
sigprops_dlg_proc, (LPARAM)ks); |
520 |
|
} |
521 |
|
return TRUE; |
522 |
|
|
523 |
|
case IDCANCEL: |
524 |
|
EndDialog (dlg, FALSE); |
525 |
|
return TRUE; |
526 |
|
|
527 |
|
case IDOK: |
528 |
|
EndDialog (dlg, TRUE); |
529 |
|
return TRUE; |
530 |
|
} |
531 |
|
break; |
532 |
|
} |
533 |
|
return FALSE; |
534 |
|
} |