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