1 |
werner |
36 |
/* wptKeyEditDlgs.cpp - GPG key edit dialogs |
2 |
twoaday |
133 |
* Copyright (C) 2002-2006 Timo Schulz |
3 |
werner |
36 |
* |
4 |
|
|
* This file is part of WinPT. |
5 |
|
|
* |
6 |
|
|
* WinPT is free software; you can redistribute it and/or modify |
7 |
|
|
* it under the terms of the GNU General Public License as published by |
8 |
|
|
* the Free Software Foundation; either version 2 of the License, or |
9 |
|
|
* (at your option) any later version. |
10 |
|
|
* |
11 |
|
|
* WinPT is distributed in the hope that it will be useful, |
12 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 |
|
|
* 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 |
werner |
42 |
#ifdef HAVE_CONFIG_H |
21 |
|
|
#include <config.h> |
22 |
|
|
#endif |
23 |
|
|
|
24 |
werner |
36 |
#include <windows.h> |
25 |
|
|
#include <commctrl.h> |
26 |
werner |
47 |
#include <time.h> |
27 |
twoaday |
200 |
#include <assert.h> |
28 |
|
|
|
29 |
werner |
47 |
#include "resource.h" |
30 |
werner |
36 |
#include "wptTypes.h" |
31 |
|
|
#include "wptW32API.h" |
32 |
|
|
#include "wptVersion.h" |
33 |
|
|
#include "wptGPG.h" |
34 |
|
|
#include "wptCommonCtl.h" |
35 |
|
|
#include "wptContext.h" |
36 |
|
|
#include "wptDlgs.h" |
37 |
|
|
#include "wptNLS.h" |
38 |
|
|
#include "wptUTF8.h" |
39 |
|
|
#include "wptErrors.h" |
40 |
|
|
#include "wptKeylist.h" |
41 |
|
|
#include "wptKeyManager.h" |
42 |
|
|
#include "wptRegistry.h" |
43 |
|
|
#include "wptKeyEdit.h" |
44 |
|
|
|
45 |
|
|
/* All edit key commands. */ |
46 |
|
|
enum keyedit_commands { |
47 |
|
|
CMD_ADDKEY = 0, |
48 |
|
|
CMD_ADDUID, |
49 |
|
|
CMD_ADDPHOTO, |
50 |
|
|
CMD_ADDREVOKER, |
51 |
|
|
CMD_DELUID, |
52 |
|
|
CMD_DELKEY, |
53 |
|
|
CMD_EXPIRE, |
54 |
|
|
CMD_SHOWPREF, |
55 |
twoaday |
170 |
//CMD_SETPREF, |
56 |
werner |
36 |
CMD_PASSWD, |
57 |
|
|
CMD_PRIMARY, |
58 |
|
|
CMD_TRUST, |
59 |
|
|
CMD_REVUID, |
60 |
|
|
CMD_REVKEY, |
61 |
|
|
CMD_DISABLE, |
62 |
twoaday |
170 |
CMD_ENABLE, |
63 |
|
|
CMD_SIGN, |
64 |
|
|
CMD_LSIGN, |
65 |
twoaday |
195 |
CMD_CHECK, |
66 |
twoaday |
200 |
CMD_CLEAN, |
67 |
twoaday |
208 |
CMD_MINIMIZE |
68 |
werner |
36 |
}; |
69 |
|
|
|
70 |
twoaday |
170 |
struct cmdlist_s { |
71 |
|
|
const char *name; |
72 |
|
|
unsigned int need_pair:1; |
73 |
|
|
int id; |
74 |
|
|
} cmdlist[] = { |
75 |
|
|
{"ADDKEY", 1, CMD_ADDKEY}, |
76 |
|
|
{"ADDUID", 1, CMD_ADDUID}, |
77 |
|
|
{"ADDPHOTO", 1, CMD_ADDPHOTO}, |
78 |
|
|
{"ADDREVOKER", 1, CMD_ADDREVOKER}, |
79 |
|
|
{"DELUID", 1, CMD_DELUID}, |
80 |
|
|
{"DELKEY", 1, CMD_DELKEY}, |
81 |
|
|
{"EXPIRE", 1, CMD_EXPIRE}, |
82 |
|
|
{"SHOWPREF", 0, CMD_SHOWPREF}, |
83 |
|
|
/*{"SETPREF", 1, CMD_SETPREF},*/ |
84 |
|
|
{"PASSWD", 1, CMD_PASSWD}, |
85 |
|
|
{"PRIMARY", 1, CMD_PRIMARY}, |
86 |
|
|
{"TRUST", 0, CMD_TRUST}, |
87 |
|
|
{"REVUID", 1, CMD_REVUID}, |
88 |
|
|
{"REVKEY", 1, CMD_REVKEY}, |
89 |
|
|
{"DISABLE", 0, CMD_DISABLE}, |
90 |
|
|
{"ENABLE", 0, CMD_ENABLE}, |
91 |
|
|
{"SIGN", 0, CMD_SIGN}, |
92 |
|
|
{"LSIGN", 0, CMD_LSIGN}, |
93 |
twoaday |
175 |
{"CHECK", 0, CMD_CHECK}, |
94 |
twoaday |
195 |
{"CLEAN", 0, CMD_CLEAN}, |
95 |
twoaday |
208 |
{"MINIMIZE", 0, CMD_MINIMIZE}, |
96 |
twoaday |
170 |
{NULL, 0} |
97 |
|
|
}; |
98 |
werner |
36 |
|
99 |
twoaday |
170 |
|
100 |
werner |
36 |
/* Symbolic ids for the subkey columns. */ |
101 |
|
|
enum subk_col_t { |
102 |
|
|
SUBK_COL_DESC = 0, |
103 |
|
|
SUBK_COL_KEYID = 1, |
104 |
|
|
SUBK_COL_CREATION = 2, |
105 |
|
|
SUBK_COL_EXPIRES = 3, |
106 |
|
|
SUBK_COL_STATUS = 4, |
107 |
|
|
SUBK_COL_C_FLAG = 5, |
108 |
|
|
SUBK_COL_S_FLAG = 6, |
109 |
|
|
SUBK_COL_E_FLAG = 7, |
110 |
|
|
SUBK_COL_A_FLAG = 8 |
111 |
|
|
}; |
112 |
|
|
|
113 |
|
|
/* Symbolic ids for the userid columns. */ |
114 |
|
|
enum uid_col_t { |
115 |
|
|
UID_COL_VALID = 0, |
116 |
|
|
UID_COL_NAME = 1, |
117 |
|
|
UID_COL_EMAIL = 2, |
118 |
|
|
UID_COL_CREATION = 3 |
119 |
|
|
}; |
120 |
|
|
|
121 |
twoaday |
176 |
/* Key edit callback context. */ |
122 |
|
|
struct keyedit_cb_s { |
123 |
twoaday |
218 |
HWND parent; /* parent window handle. */ |
124 |
|
|
const char *keyid; /* key ID of the key. */ |
125 |
|
|
const char *pass; /* pointer to the passphrase. */ |
126 |
werner |
36 |
listview_ctrl_t lv; |
127 |
twoaday |
208 |
int lv_pos; |
128 |
werner |
36 |
void *opaque; |
129 |
|
|
unsigned int finished:1; |
130 |
twoaday |
176 |
unsigned int is_protected:1; |
131 |
werner |
36 |
}; |
132 |
twoaday |
176 |
typedef struct keyedit_cb_s *keyedit_cb_t; |
133 |
werner |
36 |
|
134 |
twoaday |
176 |
|
135 |
|
|
/* Key generation callback context. */ |
136 |
|
|
struct keygen_cb_s { |
137 |
werner |
36 |
int bits; |
138 |
|
|
int algo; |
139 |
|
|
u32 expire; |
140 |
|
|
char *fpr; |
141 |
twoaday |
200 |
char *name; |
142 |
|
|
char *comment; |
143 |
|
|
char *email; |
144 |
werner |
36 |
}; |
145 |
twoaday |
176 |
typedef struct keygen_cb_s *keygen_cb_t; |
146 |
werner |
36 |
|
147 |
twoaday |
200 |
/* Subclass context for the subkey list. */ |
148 |
|
|
static subclass_s keyedit_subkey_proc; |
149 |
werner |
36 |
|
150 |
twoaday |
200 |
/* Subclass context for the user-id list. */ |
151 |
werner |
36 |
static subclass_s keyedit_uid_proc; |
152 |
|
|
|
153 |
|
|
int keygen_check_date (SYSTEMTIME *st); |
154 |
|
|
void get_userid_preflist (char **r_prefs, int * r_flags); |
155 |
twoaday |
150 |
char* get_subkey_keyid (const char *keyid); |
156 |
werner |
36 |
|
157 |
twoaday |
204 |
void ComboBox_AddString_utf8 (HWND cb, const char *txt); |
158 |
werner |
36 |
|
159 |
twoaday |
200 |
static GpgKeyEdit* |
160 |
|
|
create_GpgKeyEdit (const char *keyid) |
161 |
|
|
{ |
162 |
|
|
GpgKeyEdit *ke; |
163 |
|
|
|
164 |
|
|
ke = new GpgKeyEdit (keyid); |
165 |
|
|
if (!ke) |
166 |
|
|
BUG (NULL); |
167 |
|
|
return ke; |
168 |
|
|
} |
169 |
|
|
|
170 |
|
|
|
171 |
werner |
36 |
/* Associate each key with a combo box entry. |
172 |
|
|
Skip the key in @k. */ |
173 |
|
|
static void |
174 |
twoaday |
200 |
do_init_keylist (HWND dlg, const char *keyid) |
175 |
werner |
36 |
{ |
176 |
|
|
gpg_keycache_t pub; |
177 |
|
|
gpgme_key_t key; |
178 |
twoaday |
128 |
const char *s, *kid; |
179 |
werner |
36 |
int i, n; |
180 |
|
|
|
181 |
|
|
pub = keycache_get_ctx (1); |
182 |
|
|
if (!pub) |
183 |
|
|
BUG (0); |
184 |
|
|
|
185 |
|
|
gpg_keycache_rewind (pub); |
186 |
twoaday |
128 |
while( !gpg_keycache_next_key (pub, 0, &key)) { |
187 |
|
|
if (key->expired || key->revoked || |
188 |
twoaday |
78 |
key->disabled || key->invalid) |
189 |
|
|
continue; |
190 |
werner |
36 |
s = key->uids->uid; |
191 |
|
|
kid = key->subkeys->keyid; |
192 |
twoaday |
200 |
if (!s || !strcmp (kid+8, keyid)) |
193 |
werner |
36 |
continue; |
194 |
twoaday |
204 |
ComboBox_AddString_utf8 (GetDlgItem (dlg, IDC_ADDREV_KEYLIST), s); |
195 |
werner |
36 |
} |
196 |
|
|
gpg_keycache_rewind (pub); |
197 |
twoaday |
211 |
n = SendDlgItemMessage (dlg, IDC_ADDREV_KEYLIST, CB_GETCOUNT, 0, 0); |
198 |
werner |
36 |
for (i = 0; i < n; i++) { |
199 |
|
|
gpg_keycache_next_key (pub, 0, &key); |
200 |
|
|
SendDlgItemMessage (dlg, IDC_ADDREV_KEYLIST, CB_SETITEMDATA, |
201 |
|
|
(WPARAM)(int)i, (LPARAM)key); |
202 |
|
|
} |
203 |
|
|
SendDlgItemMessage (dlg, IDC_ADDREV_KEYLIST, CB_SETCURSEL, 0, 0); |
204 |
|
|
} |
205 |
|
|
|
206 |
|
|
|
207 |
|
|
/* Add a new user-id to the list view @lv. */ |
208 |
|
|
static void |
209 |
|
|
do_add_new_userid (listview_ctrl_t lv, |
210 |
twoaday |
201 |
const char *utf8_name, const char *email, |
211 |
|
|
const char *utf8_comment) |
212 |
werner |
36 |
{ |
213 |
twoaday |
218 |
char *p, *native; |
214 |
werner |
36 |
size_t n; |
215 |
|
|
|
216 |
twoaday |
185 |
n = strlen (utf8_name) + strlen (email) + 16; |
217 |
twoaday |
201 |
if (utf8_comment) |
218 |
|
|
n += strlen (utf8_comment); |
219 |
werner |
36 |
p = new char[n+1]; |
220 |
|
|
if (!p) |
221 |
twoaday |
185 |
BUG (NULL); |
222 |
twoaday |
218 |
if (utf8_comment) |
223 |
twoaday |
204 |
sprintf (p, "%s (%s)", utf8_name, utf8_comment); |
224 |
werner |
36 |
else |
225 |
twoaday |
204 |
sprintf (p, "%s", utf8_name); |
226 |
twoaday |
218 |
native = utf8_to_native (p); |
227 |
|
|
free_if_alloc (p); |
228 |
werner |
36 |
|
229 |
|
|
listview_add_item (lv, ""); |
230 |
twoaday |
218 |
listview_add_sub_item (lv, 0, UID_COL_VALID, _("Ultimate" )); |
231 |
|
|
listview_add_sub_item (lv, 0, UID_COL_NAME, native); |
232 |
|
|
listview_add_sub_item (lv, 0, UID_COL_EMAIL, email && *email? email : ""); |
233 |
|
|
listview_add_sub_item (lv, 0, UID_COL_CREATION, get_key_created (time (NULL))); |
234 |
|
|
free_if_alloc (native); |
235 |
twoaday |
129 |
} |
236 |
werner |
36 |
|
237 |
|
|
|
238 |
|
|
static void |
239 |
twoaday |
176 |
do_add_new_subkey (listview_ctrl_t lv, keygen_cb_t keygen, unsigned int flags) |
240 |
werner |
36 |
{ |
241 |
|
|
char info[128], keyid[32]; |
242 |
twoaday |
200 |
const char *expdate, *s; |
243 |
werner |
36 |
int n; |
244 |
|
|
|
245 |
|
|
expdate = keygen->expire? get_key_expire_date (keygen->expire) : _("Never"); |
246 |
twoaday |
218 |
_snprintf (info, sizeof (info)-1, "%d-bit %s", |
247 |
|
|
keygen->bits, |
248 |
werner |
36 |
get_key_pubalgo ((gpgme_pubkey_algo_t)keygen->algo)); |
249 |
twoaday |
218 |
_snprintf (keyid, sizeof (keyid)-1, "0x%s", keygen->fpr+8); |
250 |
twoaday |
211 |
s = get_key_created (time (NULL)); |
251 |
werner |
36 |
n = listview_count_items (lv, 0); |
252 |
|
|
listview_add_item_pos (lv, n); |
253 |
twoaday |
211 |
listview_add_sub_item (lv, n, SUBK_COL_DESC, info); |
254 |
|
|
listview_add_sub_item (lv, n, SUBK_COL_KEYID, keyid); |
255 |
|
|
listview_add_sub_item (lv, n, SUBK_COL_CREATION, s); |
256 |
|
|
listview_add_sub_item (lv, n, SUBK_COL_EXPIRES, expdate); |
257 |
twoaday |
150 |
if (flags & KM_FLAG_REVOKED) |
258 |
|
|
s = _("Revoked"); |
259 |
|
|
else if (flags & KM_FLAG_EXPIRED) |
260 |
|
|
s = _("Expired"); |
261 |
|
|
else |
262 |
|
|
s = _("OK"); |
263 |
twoaday |
211 |
listview_add_sub_item (lv, n, SUBK_COL_STATUS, s); |
264 |
twoaday |
150 |
} |
265 |
werner |
36 |
|
266 |
|
|
|
267 |
|
|
/* Try to find the GPG edit key index which belongs to the user ID |
268 |
twoaday |
160 |
given by the email address @email, @name is used as a fallback. |
269 |
|
|
If @r_inf != NULL, the info context will be returned. |
270 |
werner |
36 |
Return value: index of the user ID or -1 on error. */ |
271 |
|
|
static int |
272 |
twoaday |
160 |
do_find_userid (const char *keyid, const char *email, |
273 |
|
|
const char *name, gpg_uid_info_t *r_inf) |
274 |
werner |
36 |
{ |
275 |
|
|
GpgKeyEdit *ke; |
276 |
|
|
gpgme_error_t err; |
277 |
|
|
gpg_uid_info_t inf, ui; |
278 |
|
|
int pos = -1; |
279 |
|
|
|
280 |
twoaday |
200 |
ke = create_GpgKeyEdit (keyid); |
281 |
werner |
36 |
err = ke->getUseridInfo (&inf); |
282 |
|
|
delete ke; |
283 |
|
|
if (err) { |
284 |
|
|
log_box (_("user ID"), MB_ERR, |
285 |
|
|
_("Could not get key information for: \"%s\":\n%s"), |
286 |
|
|
name, gpgme_strerror (err)); |
287 |
|
|
return -1; |
288 |
|
|
} |
289 |
|
|
|
290 |
|
|
for (ui = inf; ui; ui = ui->next) { |
291 |
twoaday |
205 |
if (name && email && ui->email && ui->name) { |
292 |
twoaday |
160 |
if (!strcmp (ui->email, email) && |
293 |
twoaday |
205 |
!strncmp (ui->name, name, strlen (name))) { |
294 |
twoaday |
160 |
pos = ui->index; |
295 |
|
|
break; |
296 |
|
|
} |
297 |
|
|
continue; |
298 |
|
|
} |
299 |
twoaday |
208 |
if (email && ui->email) { |
300 |
twoaday |
160 |
if (!strcmp (ui->email, email)) { |
301 |
|
|
pos = ui->index; |
302 |
|
|
break; |
303 |
|
|
} |
304 |
|
|
/* The email address is more unique, use the name just |
305 |
|
|
as the fallbck when no email address is available. */ |
306 |
|
|
continue; |
307 |
|
|
} |
308 |
twoaday |
205 |
if (ui->name && name && !strcmp (ui->name, name)) { |
309 |
werner |
36 |
pos = ui->index; |
310 |
|
|
break; |
311 |
|
|
} |
312 |
|
|
} |
313 |
|
|
if (r_inf) |
314 |
|
|
*r_inf = inf; |
315 |
|
|
else |
316 |
|
|
gpg_uid_info_release (inf); |
317 |
|
|
return pos; |
318 |
|
|
} |
319 |
|
|
|
320 |
|
|
|
321 |
twoaday |
128 |
/* Return true if @fname is a JPEG file. */ |
322 |
|
|
bool |
323 |
|
|
is_jpg_file (const char *fname) |
324 |
|
|
{ |
325 |
|
|
FILE *fp; |
326 |
|
|
BYTE buf[10]; |
327 |
|
|
int n; |
328 |
|
|
|
329 |
|
|
fp = fopen (fname, "rb"); |
330 |
|
|
if (!fp) |
331 |
|
|
return false; |
332 |
|
|
n = fread (buf, 1, 10, fp); |
333 |
|
|
fclose (fp); |
334 |
|
|
if (n < 10) |
335 |
|
|
return false; |
336 |
|
|
return buf[6] == 'J' && buf[7] == 'F' && |
337 |
|
|
buf[8] == 'I' && buf[9] == 'F'; |
338 |
|
|
} |
339 |
|
|
|
340 |
|
|
|
341 |
werner |
36 |
/* Dialog box procedure to add a photo. */ |
342 |
|
|
BOOL CALLBACK |
343 |
|
|
keyedit_addphoto_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
344 |
|
|
{ |
345 |
twoaday |
200 |
static keyedit_cb_t cb; |
346 |
werner |
36 |
GpgKeyEdit *ke; |
347 |
twoaday |
200 |
gpgme_error_t err; |
348 |
|
|
const char *s; |
349 |
|
|
char file[128]; |
350 |
werner |
36 |
int id; |
351 |
|
|
|
352 |
|
|
switch( msg ) { |
353 |
|
|
case WM_INITDIALOG: |
354 |
twoaday |
200 |
cb = (keyedit_cb_t)lparam; |
355 |
|
|
if (!cb) |
356 |
werner |
36 |
BUG (NULL); |
357 |
|
|
SetDlgItemText (dlg, IDC_ADDPHOTO_INF, _("Remember that the image is stored within your public key. If you use a very large picture, your key will become very large as well! Keeping the image close to 240x288 is a good size to use.")); |
358 |
|
|
SetDlgItemText (dlg, IDC_ADDPHOTO_FILEINF, _("Pick an image to use for your photo ID.\nThe image must be a JPEG file.")); |
359 |
|
|
SetDlgItemText (dlg, IDC_ADDPHOTO_PWDINF, _("Passphrase")); |
360 |
twoaday |
105 |
SetDlgItemText (dlg, IDCANCEL, _("&Cancel")); |
361 |
twoaday |
128 |
SetWindowText (dlg, _("Add Photo ID")); |
362 |
twoaday |
105 |
SetForegroundWindow (dlg); |
363 |
werner |
36 |
break; |
364 |
|
|
|
365 |
|
|
case WM_DESTROY: |
366 |
|
|
break; |
367 |
|
|
|
368 |
|
|
case WM_SYSCOMMAND: |
369 |
twoaday |
128 |
if (LOWORD (wparam) == SC_CLOSE) |
370 |
|
|
EndDialog (dlg, TRUE); |
371 |
werner |
36 |
break; |
372 |
|
|
|
373 |
|
|
case WM_COMMAND: |
374 |
twoaday |
200 |
switch( LOWORD (wparam)) { |
375 |
werner |
36 |
case IDC_ADDPHOTO_SELFILE: |
376 |
twoaday |
128 |
s = get_fileopen_dlg (dlg, _("Select Image File"), |
377 |
twoaday |
180 |
"JPEG Files (*.jpg, *.jpeg)\0*.jpg;*.jpeg\0\0", |
378 |
twoaday |
128 |
NULL); |
379 |
|
|
if (s && !is_jpg_file (s)) { |
380 |
|
|
log_box (_("Add Photo"), MB_ERR, |
381 |
|
|
_("'%s' is not a valid JPEG file."), s); |
382 |
|
|
return FALSE; |
383 |
|
|
} |
384 |
|
|
if (s && *s) |
385 |
|
|
SetDlgItemText (dlg, IDC_ADDPHOTO_FILE, s); |
386 |
werner |
36 |
break; |
387 |
|
|
|
388 |
|
|
case IDOK: |
389 |
twoaday |
128 |
if (!GetDlgItemText (dlg, IDC_ADDPHOTO_FILE, file, sizeof (file)-1)){ |
390 |
|
|
msg_box( dlg, _("Please enter a file name."), _("Add Photo"), MB_ERR); |
391 |
werner |
36 |
return FALSE; |
392 |
|
|
} |
393 |
twoaday |
218 |
if (get_file_size (file) == 0 || get_file_size (file) > 6144) { |
394 |
twoaday |
128 |
id = msg_box (dlg, _("The JPEG is really large.\n" |
395 |
werner |
36 |
"Are you sure you want to use it?"), |
396 |
twoaday |
128 |
_("Add Photo"), MB_YESNO|MB_INFO); |
397 |
|
|
if (id == IDNO) |
398 |
werner |
36 |
return TRUE; |
399 |
|
|
} |
400 |
twoaday |
200 |
ke = create_GpgKeyEdit (cb->keyid); |
401 |
|
|
if (cb->pass) |
402 |
|
|
ke->setPassphrase (cb->pass); |
403 |
twoaday |
176 |
else |
404 |
|
|
ke->setNoPassphrase (true); |
405 |
twoaday |
200 |
err = ke->addPhotoid (file); |
406 |
werner |
36 |
delete ke; |
407 |
twoaday |
200 |
if (err) { |
408 |
|
|
msg_box (dlg, gpgme_strerror (err), _("Add Photo"), MB_ERR); |
409 |
werner |
36 |
return FALSE; |
410 |
|
|
} |
411 |
|
|
else { |
412 |
twoaday |
200 |
cb->finished = 1; |
413 |
twoaday |
128 |
msg_box (dlg, _("Photo successfully added."), |
414 |
|
|
_("GnuPG Status"), MB_OK); |
415 |
werner |
36 |
} |
416 |
|
|
EndDialog (dlg, TRUE); |
417 |
|
|
break; |
418 |
|
|
|
419 |
|
|
case IDCANCEL: |
420 |
|
|
EndDialog (dlg, FALSE); |
421 |
|
|
break; |
422 |
|
|
} |
423 |
|
|
break; |
424 |
|
|
} |
425 |
|
|
return FALSE; |
426 |
|
|
} |
427 |
|
|
|
428 |
|
|
|
429 |
|
|
/* Dialog box procedure to add a designated revoker. */ |
430 |
|
|
BOOL CALLBACK |
431 |
|
|
keyedit_addrevoker_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
432 |
|
|
{ |
433 |
twoaday |
200 |
static keyedit_cb_t cb; |
434 |
twoaday |
129 |
gpgme_error_t err; |
435 |
werner |
36 |
GpgKeyEdit *ke; |
436 |
twoaday |
204 |
char *uid=NULL; |
437 |
werner |
36 |
|
438 |
twoaday |
129 |
switch (msg) { |
439 |
werner |
36 |
case WM_INITDIALOG: |
440 |
twoaday |
200 |
cb = (keyedit_cb_t)lparam; |
441 |
|
|
if (!cb) |
442 |
twoaday |
129 |
BUG (NULL); |
443 |
twoaday |
200 |
do_init_keylist (dlg, cb->keyid); |
444 |
twoaday |
129 |
SetDlgItemText (dlg, IDC_ADDREV_INF, |
445 |
|
|
_("Appointing a key as designated revoker cannot be undone.")); |
446 |
werner |
36 |
SetDlgItemText (dlg, IDC_ADDREV_KEYINF, _("Public key")); |
447 |
|
|
SetDlgItemText (dlg, IDC_ADDREV_PWDINF, _("Passphrase")); |
448 |
twoaday |
105 |
SetDlgItemText (dlg, IDCANCEL, _("&Cancel")); |
449 |
twoaday |
128 |
SetWindowText (dlg, _("Add Revoker")); |
450 |
twoaday |
105 |
SetForegroundWindow (dlg); |
451 |
twoaday |
218 |
center_window (dlg, cb->parent); |
452 |
werner |
36 |
break; |
453 |
|
|
|
454 |
|
|
case WM_SYSCOMMAND: |
455 |
twoaday |
200 |
if (LOWORD (wparam) == SC_CLOSE) |
456 |
|
|
EndDialog (dlg, FALSE); |
457 |
werner |
36 |
break; |
458 |
|
|
|
459 |
|
|
case WM_COMMAND: |
460 |
twoaday |
200 |
switch (LOWORD (wparam)) { |
461 |
twoaday |
204 |
case IDOK: |
462 |
|
|
if (!GetDlgItemText_utf8 (dlg, IDC_ADDREV_KEYLIST, &uid)) { |
463 |
|
|
msg_box (dlg, _("Please select a user ID."), _("Add Revoker"), MB_ERR); |
464 |
werner |
36 |
return FALSE; |
465 |
|
|
} |
466 |
twoaday |
204 |
|
467 |
twoaday |
200 |
ke = create_GpgKeyEdit (cb->keyid); |
468 |
|
|
if (cb->pass) |
469 |
|
|
ke->setPassphrase (cb->pass); |
470 |
twoaday |
176 |
else |
471 |
|
|
ke->setNoPassphrase (true); |
472 |
twoaday |
204 |
err = ke->addDesignatedRevoker (uid); |
473 |
werner |
36 |
delete ke; |
474 |
twoaday |
204 |
safe_free (uid); |
475 |
werner |
36 |
if (err) { |
476 |
|
|
msg_box (dlg, gpgme_strerror (err), _("Add Revoker"), MB_ERR); |
477 |
|
|
return TRUE; |
478 |
|
|
} |
479 |
|
|
else { |
480 |
twoaday |
200 |
cb->finished = 1; |
481 |
twoaday |
129 |
msg_box (dlg, _("Revoker successfully addded."), |
482 |
|
|
_("GnuPG Status"), MB_OK); |
483 |
werner |
36 |
} |
484 |
twoaday |
129 |
EndDialog (dlg, TRUE); |
485 |
werner |
36 |
break; |
486 |
|
|
|
487 |
|
|
case IDCANCEL: |
488 |
twoaday |
129 |
EndDialog (dlg, FALSE); |
489 |
werner |
36 |
break; |
490 |
|
|
} |
491 |
|
|
break; |
492 |
|
|
} |
493 |
|
|
return FALSE; |
494 |
|
|
} |
495 |
|
|
|
496 |
|
|
|
497 |
|
|
/* Dialog box procedure to add a new user-ID. */ |
498 |
|
|
BOOL CALLBACK |
499 |
|
|
keyedit_adduid_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
500 |
|
|
{ |
501 |
twoaday |
176 |
static keyedit_cb_t ctx; |
502 |
twoaday |
200 |
keygen_cb_t keygen; |
503 |
werner |
36 |
gpgme_error_t err; |
504 |
|
|
GpgKeyEdit *ke; |
505 |
|
|
char *utf8_name = NULL; |
506 |
twoaday |
201 |
char *utf8_comment = NULL; |
507 |
twoaday |
204 |
char email[128]; |
508 |
werner |
36 |
int rc; |
509 |
|
|
|
510 |
twoaday |
176 |
switch (msg) { |
511 |
werner |
36 |
case WM_INITDIALOG: |
512 |
twoaday |
176 |
ctx = (keyedit_cb_t)lparam; |
513 |
twoaday |
200 |
if (!ctx) |
514 |
werner |
36 |
dlg_fatal_error(dlg, "Could not get dialog param!"); |
515 |
|
|
SetWindowText (dlg, _("Add new User ID")); |
516 |
|
|
SetDlgItemText (dlg, IDC_ADDUID_INFNAME, _("&Name")); |
517 |
|
|
SetDlgItemText (dlg, IDC_ADDUID_INFEMAIL, _("&Email")); |
518 |
|
|
SetDlgItemText (dlg, IDC_ADDUID_INFCOMMENT, _("&Comment")); |
519 |
twoaday |
105 |
SetDlgItemText (dlg, IDCANCEL, _("&Cancel")); |
520 |
werner |
36 |
SetForegroundWindow (dlg); |
521 |
twoaday |
218 |
center_window (dlg, ctx->parent); |
522 |
werner |
36 |
return FALSE; |
523 |
|
|
|
524 |
|
|
case WM_SYSCOMMAND: |
525 |
twoaday |
176 |
if (LOWORD (wparam) == SC_CLOSE) |
526 |
werner |
36 |
EndDialog(dlg, TRUE); |
527 |
|
|
return FALSE; |
528 |
|
|
|
529 |
|
|
case WM_COMMAND: |
530 |
|
|
switch ( LOWORD( wparam ) ) { |
531 |
|
|
case IDOK: |
532 |
twoaday |
200 |
keygen = (keygen_cb_t)ctx->opaque; |
533 |
twoaday |
204 |
rc = GetDlgItemText_utf8 (dlg, IDC_ADDUID_NAME, &utf8_name); |
534 |
werner |
36 |
if (!rc || rc < 5) { |
535 |
twoaday |
204 |
msg_box (dlg, _("Please enter a name (min. 5 chars.)"), |
536 |
|
|
_("UserID"), MB_ERR); |
537 |
|
|
free_if_alloc (utf8_name); |
538 |
werner |
36 |
return FALSE; |
539 |
|
|
} |
540 |
twoaday |
204 |
if (strchr (utf8_name, '@')) { |
541 |
|
|
msg_box (dlg, _("Please enter the email address in the email field and not in the name field"), |
542 |
|
|
_("UserID"), MB_INFO); |
543 |
werner |
36 |
return FALSE; |
544 |
|
|
} |
545 |
twoaday |
204 |
|
546 |
|
|
if( !GetDlgItemText (dlg, IDC_ADDUID_EMAIL, email, sizeof (email) -1)) { |
547 |
werner |
36 |
msg_box( dlg, _("Please enter an email address."), _("UserID"), MB_ERR ); |
548 |
|
|
return FALSE; |
549 |
|
|
} |
550 |
twoaday |
190 |
if (check_email_address (email)) { |
551 |
twoaday |
175 |
msg_box (dlg, _("Invalid email address."), _("UserID"), MB_ERR); |
552 |
werner |
36 |
return FALSE; |
553 |
|
|
} |
554 |
|
|
|
555 |
twoaday |
204 |
rc = GetDlgItemText_utf8 (dlg, IDC_ADDUID_COMMENT, &utf8_comment); |
556 |
werner |
36 |
|
557 |
twoaday |
200 |
ke = create_GpgKeyEdit (ctx->keyid); |
558 |
twoaday |
176 |
if (ctx->is_protected) |
559 |
werner |
36 |
ke->setPassphrase (ctx->pass); |
560 |
twoaday |
176 |
else |
561 |
|
|
ke->setNoPassphrase (true); |
562 |
twoaday |
201 |
err = ke->addUserid (utf8_name, utf8_comment, email); |
563 |
werner |
36 |
if (err) |
564 |
|
|
msg_box (dlg, gpgme_strerror (err), _("UserID"), MB_ERR); |
565 |
|
|
else { |
566 |
|
|
msg_box (dlg, _("user ID successfully added."), _("GnuPG Status"), MB_OK); |
567 |
|
|
ctx->finished = 1; |
568 |
twoaday |
201 |
keygen->name = utf8_name; |
569 |
|
|
keygen->comment = utf8_comment; |
570 |
twoaday |
200 |
keygen->email = m_strdup (email); |
571 |
werner |
36 |
} |
572 |
twoaday |
200 |
delete ke; |
573 |
werner |
36 |
EndDialog (dlg, TRUE); |
574 |
|
|
return TRUE; |
575 |
|
|
|
576 |
|
|
case IDCANCEL: |
577 |
|
|
EndDialog (dlg, FALSE); |
578 |
|
|
return FALSE; |
579 |
|
|
} |
580 |
|
|
break; |
581 |
|
|
} |
582 |
|
|
|
583 |
|
|
return FALSE; |
584 |
|
|
} |
585 |
|
|
|
586 |
|
|
|
587 |
|
|
static void |
588 |
|
|
init_keysize_box (HWND dlg, int ctlid) |
589 |
|
|
{ |
590 |
|
|
const char *sizelist[] = { |
591 |
twoaday |
200 |
"1024", "1536", |
592 |
twoaday |
211 |
"2048", "3072", |
593 |
twoaday |
200 |
"4096", NULL |
594 |
werner |
36 |
}; |
595 |
|
|
int i; |
596 |
twoaday |
200 |
|
597 |
werner |
36 |
for (i=0; sizelist[i] != NULL; i++) |
598 |
twoaday |
200 |
SendDlgItemMessage (dlg, ctlid, CB_ADDSTRING, 0, |
599 |
|
|
(LPARAM)(char*)sizelist[i]); |
600 |
werner |
36 |
SendDlgItemMessage (dlg, ctlid, CB_SETCURSEL, (WPARAM)2, 0); |
601 |
|
|
} |
602 |
|
|
|
603 |
twoaday |
200 |
|
604 |
werner |
36 |
static int |
605 |
|
|
get_keysize_from_box (HWND dlg, int ctlid) |
606 |
|
|
{ |
607 |
|
|
int pos; |
608 |
|
|
char buf[32]; |
609 |
|
|
|
610 |
|
|
pos = SendDlgItemMessage (dlg, ctlid, CB_GETCURSEL, 0, 0); |
611 |
|
|
if (pos == CB_ERR) |
612 |
|
|
return -1; |
613 |
|
|
SendDlgItemMessage (dlg, ctlid, CB_GETLBTEXT, pos, (LPARAM)(char*)buf); |
614 |
twoaday |
211 |
return atoi (buf); |
615 |
werner |
36 |
} |
616 |
|
|
|
617 |
|
|
|
618 |
twoaday |
175 |
/* Create a time_t from a system time @st. */ |
619 |
|
|
time_t |
620 |
|
|
w32_mktime (SYSTEMTIME *st) |
621 |
|
|
{ |
622 |
|
|
struct tm tm; |
623 |
|
|
|
624 |
|
|
memset (&tm, 0, sizeof (tm)); |
625 |
|
|
tm.tm_year = st->wYear-1900; |
626 |
|
|
tm.tm_mday = st->wDay+1; |
627 |
|
|
tm.tm_mon = st->wMonth-1; |
628 |
|
|
return mktime (&tm); |
629 |
|
|
} |
630 |
|
|
|
631 |
|
|
|
632 |
twoaday |
129 |
/* Dialog procedure for adding a new secondary key. */ |
633 |
werner |
36 |
BOOL CALLBACK |
634 |
|
|
keyedit_addsubkey_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
635 |
|
|
{ |
636 |
twoaday |
176 |
static keyedit_cb_t ctx; |
637 |
twoaday |
200 |
keygen_cb_t keygen; |
638 |
werner |
36 |
GpgKeyEdit *ke; |
639 |
|
|
gpgme_error_t err; |
640 |
twoaday |
175 |
SYSTEMTIME st; |
641 |
twoaday |
200 |
HWND hwnd; |
642 |
werner |
36 |
int index, size, valid; |
643 |
|
|
|
644 |
|
|
switch (msg) { |
645 |
|
|
case WM_INITDIALOG: |
646 |
twoaday |
176 |
ctx = (keyedit_cb_t)lparam; |
647 |
werner |
36 |
if (!ctx) |
648 |
|
|
dlg_fatal_error (dlg, "Could not get dialog param!"); |
649 |
twoaday |
99 |
|
650 |
werner |
36 |
SetWindowText (dlg, _("Add new Subkey")); |
651 |
|
|
SetDlgItemText (dlg, IDC_ADDSUBKEY_INFALGO, _("Key type")); |
652 |
|
|
SetDlgItemText (dlg, IDC_ADDSUBKEY_INFSIZE, _("Size in bits")); |
653 |
|
|
SetDlgItemText (dlg, IDC_ADDSUBKEY_INFVALID, _("Key expiration")); |
654 |
twoaday |
99 |
SetDlgItemText (dlg, IDC_ADDSUBKEY_EXPIRE, _("&Never")); |
655 |
twoaday |
105 |
SetDlgItemText (dlg, IDCANCEL, _("&Cancel")); |
656 |
twoaday |
99 |
|
657 |
twoaday |
200 |
hwnd = GetDlgItem (dlg, IDC_ADDSUBKEY_ALGO); |
658 |
|
|
listbox_add_string (hwnd, "DSA (sign only)"); |
659 |
|
|
listbox_add_string (hwnd, "ElGamal (encrypt only)"); |
660 |
|
|
listbox_add_string (hwnd, "RSA (sign only)"); |
661 |
|
|
listbox_add_string (hwnd, "RSA (encrypt only)"); |
662 |
werner |
36 |
CheckDlgButton (dlg, IDC_ADDSUBKEY_EXPIRE, BST_CHECKED); |
663 |
|
|
EnableWindow (GetDlgItem (dlg, IDC_ADDSUBKEY_EXPDATE), FALSE); |
664 |
|
|
init_keysize_box (dlg, IDC_ADDSUBKEY_SIZE); |
665 |
twoaday |
105 |
SetForegroundWindow (dlg); |
666 |
twoaday |
218 |
center_window (dlg, ctx->parent); |
667 |
werner |
36 |
return FALSE; |
668 |
|
|
|
669 |
|
|
case WM_SYSCOMMAND: |
670 |
twoaday |
200 |
if (LOWORD (wparam) == SC_CLOSE) |
671 |
twoaday |
150 |
EndDialog (dlg, TRUE); |
672 |
werner |
36 |
return FALSE; |
673 |
|
|
|
674 |
|
|
case WM_COMMAND: |
675 |
twoaday |
150 |
if (HIWORD (wparam) == BN_CLICKED && |
676 |
|
|
LOWORD (wparam) == IDC_ADDSUBKEY_EXPIRE) { |
677 |
werner |
36 |
if (IsDlgButtonChecked (dlg, IDC_ADDSUBKEY_EXPIRE)) |
678 |
|
|
EnableWindow (GetDlgItem (dlg, IDC_ADDSUBKEY_EXPDATE), FALSE); |
679 |
|
|
else |
680 |
|
|
EnableWindow (GetDlgItem (dlg, IDC_ADDSUBKEY_EXPDATE), TRUE); |
681 |
|
|
} |
682 |
twoaday |
150 |
if (HIWORD (wparam) == LBN_SELCHANGE && |
683 |
|
|
LOWORD (wparam) == IDC_ADDSUBKEY_ALGO) { |
684 |
werner |
36 |
index = SendMessage ((HWND)lparam, LB_GETCURSEL, 0, 0); |
685 |
|
|
if (index == 0) |
686 |
|
|
SendDlgItemMessage (dlg, IDC_ADDSUBKEY_SIZE, CB_SETCURSEL, 0, 0); |
687 |
|
|
} |
688 |
|
|
|
689 |
twoaday |
150 |
switch (LOWORD (wparam)) { |
690 |
werner |
36 |
case IDOK: |
691 |
twoaday |
200 |
keygen = (keygen_cb_t)ctx->opaque; |
692 |
|
|
assert (keygen); |
693 |
|
|
hwnd = GetDlgItem (dlg, IDC_ADDSUBKEY_ALGO); |
694 |
|
|
switch (listbox_get_cursel (hwnd)) { |
695 |
werner |
36 |
case 0: index = 2; break; |
696 |
|
|
case 1: index = 4; break; |
697 |
|
|
case 2: index = 5; break; |
698 |
|
|
case 3: index = 6; break; |
699 |
twoaday |
150 |
default: |
700 |
twoaday |
200 |
msg_box (dlg, _("Please select one entry."), |
701 |
|
|
_("Add Subkey"), MB_ERR); |
702 |
werner |
36 |
return FALSE; |
703 |
|
|
} |
704 |
|
|
size = get_keysize_from_box (dlg, IDC_ADDSUBKEY_SIZE); |
705 |
|
|
if (index == 2 && size != 1024) { |
706 |
twoaday |
200 |
msg_box (dlg,_("DSS uses a fixed keysize of 1024. Size changed."), |
707 |
twoaday |
150 |
_("Add Subkey"), MB_INFO); |
708 |
werner |
36 |
size = 1024; |
709 |
|
|
} |
710 |
twoaday |
175 |
|
711 |
twoaday |
200 |
hwnd = GetDlgItem (dlg, IDC_ADDSUBKEY_EXPDATE); |
712 |
|
|
DateTime_GetSystemtime (hwnd, &st); |
713 |
twoaday |
175 |
valid = w32_mktime (&st) - time (NULL); |
714 |
|
|
valid /= 86400; |
715 |
|
|
|
716 |
werner |
36 |
keygen->bits = size; |
717 |
|
|
switch (index) { |
718 |
|
|
case 2: keygen->algo = GPGME_PK_DSA; break; |
719 |
|
|
case 4: keygen->algo = GPGME_PK_ELG_E; break; |
720 |
|
|
case 5: keygen->algo = GPGME_PK_RSA_S; break; |
721 |
|
|
case 6: keygen->algo = GPGME_PK_RSA_E; break; |
722 |
|
|
} |
723 |
|
|
if (valid > 0) |
724 |
|
|
keygen->expire = time (NULL) + valid*24*60*60; |
725 |
|
|
|
726 |
twoaday |
200 |
ke = create_GpgKeyEdit (ctx->keyid); |
727 |
werner |
36 |
ke->setCallback (keygen_cb, NULL); |
728 |
twoaday |
176 |
if (ctx->is_protected) |
729 |
twoaday |
150 |
ke->setPassphrase (ctx->pass); |
730 |
twoaday |
176 |
else |
731 |
|
|
ke->setNoPassphrase (true); |
732 |
werner |
36 |
keygen_cb_dlg_create (); |
733 |
|
|
|
734 |
|
|
err = ke->addSubkey ((gpgme_pubkey_algo_t)index, size, valid); |
735 |
twoaday |
150 |
keygen->fpr = get_subkey_keyid (ctx->keyid); |
736 |
twoaday |
211 |
keygen_cb_dlg_destroy (1); |
737 |
werner |
36 |
if (err) |
738 |
|
|
msg_box (dlg, gpgme_strerror (err), _("Add Subkey"), MB_ERR); |
739 |
|
|
else { |
740 |
twoaday |
200 |
msg_box (dlg, _("Subkey successfully added."), |
741 |
|
|
_("GnuPG Status"), MB_OK); |
742 |
werner |
36 |
ctx->finished = 1; |
743 |
|
|
} |
744 |
|
|
delete ke; |
745 |
twoaday |
129 |
EndDialog (dlg, TRUE); |
746 |
werner |
36 |
return TRUE; |
747 |
|
|
|
748 |
|
|
case IDCANCEL: |
749 |
twoaday |
129 |
EndDialog (dlg, FALSE); |
750 |
werner |
36 |
return FALSE; |
751 |
|
|
} |
752 |
|
|
break; |
753 |
|
|
} |
754 |
|
|
|
755 |
|
|
return FALSE; |
756 |
twoaday |
129 |
} |
757 |
werner |
36 |
|
758 |
|
|
|
759 |
|
|
BOOL |
760 |
|
|
keyedit_add_userid (winpt_key_t k, HWND dlg, listview_ctrl_t lv) |
761 |
|
|
{ |
762 |
twoaday |
176 |
keyedit_cb_s cb; |
763 |
twoaday |
200 |
keygen_cb_s keygen; |
764 |
werner |
36 |
char *pass = NULL; |
765 |
|
|
int cancel = 0; |
766 |
|
|
|
767 |
|
|
if (!k->key_pair) { |
768 |
twoaday |
200 |
msg_box (dlg, _("There is no secret key available!"), |
769 |
|
|
_("Add user ID"), MB_ERR); |
770 |
werner |
36 |
return FALSE; |
771 |
|
|
} |
772 |
|
|
|
773 |
|
|
if (k->is_protected) { |
774 |
twoaday |
200 |
pass = request_passphrase (_("Key Edit"), 1, &cancel); |
775 |
werner |
36 |
if (cancel) |
776 |
|
|
return FALSE; |
777 |
|
|
} |
778 |
twoaday |
200 |
|
779 |
|
|
memset (&keygen, 0, sizeof (keygen)); |
780 |
werner |
36 |
memset (&cb, 0, sizeof cb); |
781 |
twoaday |
218 |
cb.parent = dlg; |
782 |
twoaday |
200 |
cb.opaque = &keygen; |
783 |
twoaday |
176 |
cb.is_protected = k->is_protected; |
784 |
|
|
cb.pass = pass; |
785 |
werner |
36 |
cb.keyid = k->keyid; |
786 |
|
|
dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_KEYEDIT_ADDUID, |
787 |
|
|
dlg, keyedit_adduid_dlg_proc, |
788 |
|
|
(LPARAM)&cb, _("Add user ID"), |
789 |
|
|
IDS_WINPT_KEYEDIT_ADDUID); |
790 |
twoaday |
200 |
if (lv != NULL && cb.finished) |
791 |
|
|
do_add_new_userid (lv, keygen.name, keygen.email, keygen.comment); |
792 |
werner |
36 |
if (cb.finished) |
793 |
|
|
k->update = 1; |
794 |
|
|
|
795 |
twoaday |
200 |
free_if_alloc (keygen.name); |
796 |
|
|
free_if_alloc (keygen.email); |
797 |
|
|
free_if_alloc (keygen.comment); |
798 |
werner |
36 |
sfree_if_alloc (pass); |
799 |
|
|
return TRUE; |
800 |
|
|
} |
801 |
|
|
|
802 |
|
|
|
803 |
twoaday |
200 |
/* Return the keyID of the last subkey. */ |
804 |
werner |
36 |
char* |
805 |
twoaday |
150 |
get_subkey_keyid (const char *keyid) |
806 |
werner |
36 |
{ |
807 |
|
|
gpgme_error_t err; |
808 |
twoaday |
150 |
gpgme_key_t key; |
809 |
werner |
36 |
gpgme_ctx_t ctx; |
810 |
twoaday |
150 |
gpgme_subkey_t subk; |
811 |
twoaday |
200 |
char *kid = NULL; |
812 |
werner |
36 |
|
813 |
|
|
err = gpgme_new (&ctx); |
814 |
|
|
if (err) |
815 |
|
|
return NULL; |
816 |
|
|
err = gpgme_get_key (ctx, keyid, &key, 0); |
817 |
twoaday |
150 |
gpgme_release (ctx); |
818 |
werner |
36 |
if (err) |
819 |
|
|
return NULL; |
820 |
twoaday |
150 |
subk = get_nth_key (key, count_subkeys (key)); |
821 |
twoaday |
200 |
if (subk != NULL) |
822 |
|
|
kid = strdup (subk->keyid); |
823 |
werner |
36 |
gpgme_key_release (key); |
824 |
twoaday |
150 |
return kid; |
825 |
werner |
36 |
} |
826 |
|
|
|
827 |
|
|
|
828 |
|
|
BOOL |
829 |
|
|
keyedit_add_subkey (winpt_key_t k, HWND dlg, listview_ctrl_t lv) |
830 |
|
|
{ |
831 |
twoaday |
176 |
keyedit_cb_s cb; |
832 |
|
|
keygen_cb_s keygen; |
833 |
werner |
36 |
char *pass = NULL; |
834 |
|
|
int cancel = 0; |
835 |
|
|
|
836 |
|
|
if (!k->key_pair) { |
837 |
twoaday |
200 |
msg_box (dlg, _("There is no secret key available!"), |
838 |
|
|
_("Add Subkey"), MB_ERR); |
839 |
werner |
36 |
return FALSE; |
840 |
|
|
} |
841 |
|
|
if (k->is_protected) { |
842 |
|
|
pass = request_passphrase (_("Key Edit"), 1, &cancel); |
843 |
|
|
if (cancel) |
844 |
|
|
return FALSE; |
845 |
|
|
} |
846 |
|
|
|
847 |
|
|
memset (&keygen, 0, sizeof (keygen)); |
848 |
|
|
memset (&cb, 0, sizeof (cb)); |
849 |
|
|
cb.keyid = k->keyid; |
850 |
twoaday |
176 |
cb.is_protected = k->is_protected; |
851 |
|
|
cb.pass = pass; |
852 |
werner |
36 |
cb.opaque = &keygen; |
853 |
|
|
dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_KEYEDIT_ADDSUBKEY, |
854 |
|
|
dlg, keyedit_addsubkey_dlg_proc, |
855 |
|
|
(LPARAM)&cb, _("Add new Subkey"), |
856 |
|
|
IDS_WINPT_KEYEDIT_ADDSUBKEY); |
857 |
twoaday |
200 |
if (lv != NULL && cb.finished) |
858 |
|
|
do_add_new_subkey (lv, &keygen, 0); |
859 |
werner |
36 |
if (cb.finished) |
860 |
|
|
k->update = 1; |
861 |
|
|
|
862 |
twoaday |
200 |
safe_free (keygen.fpr); |
863 |
|
|
sfree_if_alloc (pass); |
864 |
werner |
36 |
return cb.finished? TRUE: FALSE; |
865 |
|
|
} |
866 |
|
|
|
867 |
|
|
|
868 |
|
|
BOOL |
869 |
|
|
keyedit_set_pref_keyserver (winpt_key_t k, HWND dlg) |
870 |
|
|
{ |
871 |
|
|
GpgKeyEdit *ke; |
872 |
|
|
gpgme_error_t err; |
873 |
|
|
struct URL_ctx_s *url; |
874 |
twoaday |
200 |
char *pass = NULL; |
875 |
werner |
36 |
|
876 |
|
|
url = (struct URL_ctx_s *)get_keyserver_URL_dlg (dlg); |
877 |
|
|
if (url->cancel == 1) { |
878 |
|
|
delete url; |
879 |
|
|
return FALSE; |
880 |
|
|
} |
881 |
|
|
|
882 |
|
|
pass = request_passphrase (_("Key Edit"), 1, &url->cancel); |
883 |
|
|
if (url->cancel) { |
884 |
|
|
delete url; |
885 |
|
|
return FALSE; |
886 |
|
|
} |
887 |
|
|
|
888 |
twoaday |
200 |
ke = create_GpgKeyEdit (k->keyid); |
889 |
twoaday |
175 |
if (k->is_protected) |
890 |
|
|
ke->setPassphrase (pass); |
891 |
twoaday |
176 |
else |
892 |
|
|
ke->setNoPassphrase (true); |
893 |
twoaday |
181 |
err = ke->setPreferredKeyserver (-1, url->url); |
894 |
werner |
36 |
if (!err) |
895 |
|
|
msg_box (dlg, _("Preferred keyserver successfully set."), _("Key Edit"), MB_OK); |
896 |
twoaday |
188 |
else |
897 |
|
|
msg_box (dlg, gpgme_strerror (err), _("Key Edit"), MB_ERR); |
898 |
werner |
36 |
|
899 |
|
|
sfree_if_alloc (pass); |
900 |
|
|
delete ke; |
901 |
twoaday |
181 |
delete url; |
902 |
werner |
36 |
return err == 0? 0 : WPTERR_GENERAL; |
903 |
|
|
} |
904 |
|
|
|
905 |
|
|
|
906 |
|
|
/* Add a photo-ID to the key specified in @k. @dlg is the handle of |
907 |
|
|
the calling dialog. */ |
908 |
|
|
BOOL |
909 |
|
|
keyedit_add_photo (winpt_key_t k, HWND dlg) |
910 |
|
|
{ |
911 |
twoaday |
200 |
keyedit_cb_s cb; |
912 |
|
|
char *pass = NULL; |
913 |
|
|
int cancel; |
914 |
|
|
|
915 |
werner |
36 |
if (!k->key_pair) { |
916 |
twoaday |
180 |
msg_box (dlg, _("There is no secret key available!"), |
917 |
|
|
_("Add Photo"), MB_ERR); |
918 |
werner |
36 |
return FALSE; |
919 |
|
|
} |
920 |
twoaday |
200 |
|
921 |
|
|
memset (&cb, 0, sizeof (cb)); |
922 |
|
|
if (k->is_protected) { |
923 |
|
|
pass = request_passphrase (_("Key Edit"), 1, &cancel); |
924 |
|
|
if (cancel) |
925 |
|
|
return FALSE; |
926 |
|
|
} |
927 |
twoaday |
218 |
cb.parent = dlg; |
928 |
twoaday |
200 |
cb.pass = pass; |
929 |
|
|
cb.keyid = k->keyid; |
930 |
|
|
|
931 |
werner |
36 |
DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_KEYEDIT_ADDPHOTO, dlg, |
932 |
twoaday |
200 |
keyedit_addphoto_dlg_proc, (LPARAM)&cb); |
933 |
|
|
|
934 |
|
|
if (cb.finished) |
935 |
|
|
k->update = 1; |
936 |
|
|
sfree_if_alloc (pass); |
937 |
werner |
36 |
return TRUE; |
938 |
|
|
} |
939 |
|
|
|
940 |
|
|
|
941 |
|
|
BOOL |
942 |
|
|
keyedit_add_revoker (winpt_key_t k, HWND dlg) |
943 |
|
|
{ |
944 |
twoaday |
200 |
keyedit_cb_s cb; |
945 |
|
|
char *pass = NULL; |
946 |
|
|
int cancel; |
947 |
|
|
|
948 |
twoaday |
129 |
if (!k->key_pair) { |
949 |
|
|
msg_box (dlg, _("There is no secret key available!"), _("Add Revoker"), MB_ERR); |
950 |
werner |
36 |
return FALSE; |
951 |
|
|
} |
952 |
twoaday |
200 |
|
953 |
|
|
if (k->is_protected) { |
954 |
|
|
pass = request_passphrase (_("Key Edit"), 1, &cancel); |
955 |
|
|
if (cancel) |
956 |
|
|
return FALSE; |
957 |
|
|
} |
958 |
|
|
|
959 |
|
|
memset (&cb, 0, sizeof (cb)); |
960 |
twoaday |
218 |
cb.parent = dlg; |
961 |
twoaday |
200 |
cb.is_protected = k->is_protected; |
962 |
|
|
cb.keyid = k->keyid; |
963 |
|
|
cb.pass = pass; |
964 |
werner |
36 |
DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_KEYEDIT_ADDREV, dlg, |
965 |
twoaday |
200 |
keyedit_addrevoker_dlg_proc, (LPARAM)&cb); |
966 |
|
|
|
967 |
|
|
if (cb.finished) |
968 |
|
|
k->update = 1; |
969 |
|
|
sfree_if_alloc (pass); |
970 |
werner |
36 |
return TRUE; |
971 |
twoaday |
129 |
} |
972 |
werner |
36 |
|
973 |
|
|
|
974 |
twoaday |
165 |
/* Change ownertrust of the given key @key. |
975 |
|
|
Return TRUE if the ownertrust was changed. */ |
976 |
|
|
BOOL |
977 |
|
|
keyedit_change_ownertrust (winpt_key_t key, HWND dlg) |
978 |
|
|
{ |
979 |
|
|
int rc; |
980 |
|
|
|
981 |
|
|
rc = dialog_box_param (glob_hinst, |
982 |
|
|
(LPCSTR)IDD_WINPT_KEYEDIT_OWNERTRUST, |
983 |
|
|
dlg, keyedit_ownertrust_dlg_proc, |
984 |
|
|
(LPARAM)key, _("Change Ownertrust"), |
985 |
|
|
IDS_WINPT_KEYEDIT_OWNERTRUST); |
986 |
twoaday |
170 |
if (rc == TRUE) { |
987 |
|
|
msg_box (dlg, _("Key status changed."), _("Key Edit"), MB_OK); |
988 |
twoaday |
165 |
key->update = 1; |
989 |
twoaday |
170 |
} |
990 |
twoaday |
165 |
return rc; |
991 |
|
|
} |
992 |
|
|
|
993 |
|
|
|
994 |
twoaday |
180 |
/* Check if the given key is supposed to have IDEA |
995 |
|
|
for secret key protection. */ |
996 |
werner |
36 |
static int |
997 |
twoaday |
180 |
is_idea_protect_algo (const char *keyid) |
998 |
werner |
36 |
{ |
999 |
|
|
winpt_key_s k; |
1000 |
|
|
const unsigned char *sym_prefs; |
1001 |
|
|
size_t n; |
1002 |
|
|
|
1003 |
|
|
memset (&k, 0, sizeof (k)); |
1004 |
|
|
if (winpt_get_pubkey (keyid, &k)) |
1005 |
twoaday |
180 |
BUG (0); |
1006 |
werner |
36 |
sym_prefs = k.ext->sym_prefs; |
1007 |
twoaday |
180 |
if (!k.is_v3) |
1008 |
|
|
return 0; |
1009 |
werner |
36 |
if (!sym_prefs) |
1010 |
|
|
return 1; /* assume that only v3 keys have no symmetric cipher preferences |
1011 |
|
|
and thus IDEA is explicit. */ |
1012 |
|
|
for (n = 0; sym_prefs[n]; n++) |
1013 |
|
|
; |
1014 |
|
|
if ((n == 0 || n == 1) && *sym_prefs == 0x01) |
1015 |
|
|
return 1; |
1016 |
|
|
return 0; |
1017 |
twoaday |
180 |
} |
1018 |
werner |
36 |
|
1019 |
|
|
|
1020 |
|
|
BOOL |
1021 |
twoaday |
129 |
keyedit_change_passwd (winpt_key_t k, HWND dlg) |
1022 |
werner |
36 |
{ |
1023 |
twoaday |
200 |
gpgme_error_t err; |
1024 |
werner |
36 |
GpgKeyEdit *ke; |
1025 |
twoaday |
129 |
char *old_pass = NULL; |
1026 |
|
|
char *new_pass = NULL; |
1027 |
werner |
36 |
int cancel = 0; |
1028 |
|
|
|
1029 |
twoaday |
175 |
if (!k->key_pair) { |
1030 |
|
|
msg_box (dlg, _("There is no secret key available!"), |
1031 |
|
|
_("Key Edit"), MB_ERR); |
1032 |
werner |
36 |
return FALSE; |
1033 |
|
|
} |
1034 |
|
|
|
1035 |
twoaday |
180 |
if (!idea_available && is_idea_protect_algo (k->keyid)) { |
1036 |
|
|
msg_box (dlg, _("Cannot change passphrase because the key\n" |
1037 |
|
|
"is protected with the IDEA encryption algorithm."), |
1038 |
|
|
_("Key Edit"), MB_ERR); |
1039 |
werner |
36 |
return FALSE; |
1040 |
|
|
} |
1041 |
|
|
|
1042 |
twoaday |
129 |
if (k->is_protected) { |
1043 |
|
|
old_pass = request_passphrase (_("Current (old) Passphrase"), 1, &cancel); |
1044 |
twoaday |
128 |
if (cancel) |
1045 |
werner |
36 |
return FALSE; |
1046 |
|
|
} |
1047 |
twoaday |
129 |
new_pass = request_passphrase2 (_("New Passphrase" ), 1, &cancel); |
1048 |
|
|
if (cancel) { |
1049 |
|
|
free_if_alloc (old_pass); |
1050 |
werner |
36 |
return FALSE; |
1051 |
|
|
} |
1052 |
|
|
|
1053 |
twoaday |
129 |
if (is_8bit_string (new_pass)) { |
1054 |
|
|
msg_box (dlg, _("The passphrase contains 8-bit characters.\n" |
1055 |
werner |
36 |
"It is not suggested to use charset specific characters."), |
1056 |
twoaday |
129 |
_("Key Edit"), MB_ERR); |
1057 |
|
|
free_if_alloc (old_pass); |
1058 |
|
|
free_if_alloc (new_pass); |
1059 |
werner |
36 |
return FALSE; |
1060 |
|
|
} |
1061 |
|
|
|
1062 |
twoaday |
200 |
ke = create_GpgKeyEdit (k->keyid); |
1063 |
werner |
36 |
ke->setPassphrase (k->is_protected? old_pass : NULL); |
1064 |
twoaday |
200 |
err = ke->changePassphrase (new_pass, 0); |
1065 |
|
|
if (err) |
1066 |
|
|
msg_box (dlg, gpgme_strerror (err), _("Change Passwd"), MB_ERR); |
1067 |
werner |
36 |
else |
1068 |
|
|
msg_box (dlg, _("Passphrase successfully changed."), _("GnuPG status"), MB_OK); |
1069 |
|
|
sfree_if_alloc (old_pass); |
1070 |
|
|
sfree_if_alloc (new_pass); |
1071 |
|
|
delete ke; |
1072 |
|
|
return TRUE; |
1073 |
|
|
} |
1074 |
|
|
|
1075 |
|
|
|
1076 |
twoaday |
165 |
/* Initialize sub key list from key @k and return |
1077 |
|
|
the new listview control. */ |
1078 |
werner |
36 |
listview_ctrl_t |
1079 |
twoaday |
165 |
subkey_list_init (HWND dlg, winpt_key_t k) |
1080 |
werner |
36 |
{ |
1081 |
|
|
LV_ITEM lvi; |
1082 |
|
|
gpgme_subkey_t sub; |
1083 |
|
|
struct listview_column_s cols[] = { |
1084 |
|
|
{0, 80, (char *)_("Description")}, |
1085 |
|
|
{1, 78, (char *)_("Key ID")}, |
1086 |
|
|
{2, 66, (char *)_("Creation")}, |
1087 |
|
|
{3, 66, (char *)_("Expires")}, |
1088 |
|
|
{4, 64, (char *)_("Status")}, |
1089 |
|
|
{5, 16, "C"/*ertify*/}, |
1090 |
|
|
{6, 16, "S"/*ign*/}, |
1091 |
|
|
{7, 16, "E"/*ncrypt*/}, |
1092 |
|
|
{8, 16, "A"/*uth*/}, |
1093 |
|
|
{0, 0, 0} |
1094 |
|
|
}; |
1095 |
|
|
listview_ctrl_t lv; |
1096 |
|
|
char buf[256], tmp[128]; |
1097 |
|
|
const char *t; |
1098 |
twoaday |
211 |
int nkeys = 0, i, bits; |
1099 |
werner |
36 |
|
1100 |
twoaday |
211 |
nkeys = count_subkeys (k->ctx); |
1101 |
werner |
36 |
if( !nkeys ) { |
1102 |
twoaday |
165 |
msg_box (dlg, _("No subkey(s) found."), _("Key Edit"), MB_ERR); |
1103 |
werner |
36 |
return NULL; |
1104 |
|
|
} |
1105 |
|
|
|
1106 |
twoaday |
208 |
listview_new (&lv, GetDlgItem (dlg, IDC_KEYEDIT_KEYLIST)); |
1107 |
|
|
for (i = 0; cols[i].fieldname != NULL; i++) |
1108 |
|
|
listview_add_column (lv, &cols[i]); |
1109 |
werner |
36 |
|
1110 |
twoaday |
215 |
for (i = 0; i < nkeys; i++) { |
1111 |
|
|
listview_add_item (lv, ""); |
1112 |
|
|
listview_add_sub_item (lv, 0, 1, ""); |
1113 |
|
|
memset (&lvi, 0, sizeof (lvi)); |
1114 |
werner |
36 |
lvi.mask = LVIF_PARAM; |
1115 |
twoaday |
215 |
lvi.lParam = (LPARAM)k->ext; |
1116 |
|
|
if( ListView_SetItem (lv->ctrl, &lvi) == FALSE) |
1117 |
|
|
return NULL; |
1118 |
werner |
36 |
} |
1119 |
|
|
|
1120 |
|
|
listview_set_ext_style( lv ); |
1121 |
twoaday |
211 |
for( i = 0, sub = k->ctx->subkeys; i < nkeys; i++, sub = sub->next ) { |
1122 |
werner |
36 |
memset( buf, 0, sizeof buf ); |
1123 |
|
|
|
1124 |
|
|
bits = sub->length; |
1125 |
|
|
_snprintf( tmp, sizeof tmp-1, "%d-bit ", bits ); |
1126 |
|
|
strcat( buf, tmp ); |
1127 |
|
|
|
1128 |
|
|
_snprintf( tmp, sizeof tmp-1, "%s", get_key_pubalgo (sub->pubkey_algo)); |
1129 |
|
|
strcat( buf, tmp ); |
1130 |
|
|
|
1131 |
|
|
listview_add_sub_item( lv, i, 0, buf ); |
1132 |
|
|
t = sub->keyid; |
1133 |
|
|
if( !t ) |
1134 |
|
|
t = "DEADBEEFDEADBEEF"; |
1135 |
|
|
_snprintf( tmp, sizeof tmp-1, "0x%s", t+8 ); |
1136 |
|
|
listview_add_sub_item( lv, i, 1, tmp ); |
1137 |
|
|
|
1138 |
|
|
t = get_key_created (sub->timestamp); |
1139 |
|
|
if( !t ) |
1140 |
werner |
116 |
t = "????" "-??" "-??"; |
1141 |
werner |
36 |
listview_add_sub_item( lv, i, 2, t ); |
1142 |
|
|
|
1143 |
|
|
if( sub->expires ) { |
1144 |
|
|
t = get_key_created (sub->expires); |
1145 |
|
|
listview_add_sub_item( lv, i, 3, t ); |
1146 |
|
|
} |
1147 |
|
|
else |
1148 |
|
|
listview_add_sub_item( lv, i, 3, _("Never") ); |
1149 |
|
|
|
1150 |
|
|
if( sub->expired ) |
1151 |
|
|
t = _("Expired"); |
1152 |
|
|
else if( sub->revoked ) |
1153 |
|
|
t = _("Revoked"); |
1154 |
|
|
else |
1155 |
|
|
t = _("OK"); |
1156 |
|
|
listview_add_sub_item( lv, i, 4, t ); |
1157 |
|
|
|
1158 |
|
|
if (sub->can_certify) t = "*"; else t = ""; |
1159 |
|
|
listview_add_sub_item (lv, i, 5, t); |
1160 |
|
|
if (sub->can_sign) t = "*"; else t = ""; |
1161 |
|
|
listview_add_sub_item( lv, i, 6, t ); |
1162 |
|
|
if (sub->can_encrypt) t = "*"; else t = ""; |
1163 |
|
|
listview_add_sub_item( lv, i, 7, t ); |
1164 |
|
|
if (sub->can_authenticate) t = "*"; else t = ""; |
1165 |
|
|
listview_add_sub_item (lv, i, 8, t); |
1166 |
|
|
} |
1167 |
|
|
return lv; |
1168 |
twoaday |
200 |
} |
1169 |
werner |
36 |
|
1170 |
|
|
|
1171 |
|
|
static listview_ctrl_t |
1172 |
|
|
userid_list_init (HWND dlg, winpt_key_t k) |
1173 |
|
|
{ |
1174 |
|
|
listview_ctrl_t lv = NULL; |
1175 |
|
|
gpgme_key_sig_t ks; |
1176 |
twoaday |
207 |
struct native_uid_s *u; |
1177 |
twoaday |
208 |
int nuids = 0, j, u_attr; |
1178 |
werner |
36 |
struct listview_column_s cols[] = { |
1179 |
|
|
{0, 72, (char *)_("Validity")}, |
1180 |
|
|
{1, 150, (char *)_("Name")}, |
1181 |
|
|
{2, 110, (char *)_("Email")}, |
1182 |
|
|
{3, 76, (char *)_("Creation")}, |
1183 |
|
|
{0, 0, 0} |
1184 |
|
|
}; |
1185 |
|
|
const char *attr; |
1186 |
|
|
|
1187 |
twoaday |
211 |
nuids = count_userids (k->ctx); |
1188 |
werner |
36 |
if (!nuids) { |
1189 |
|
|
msg_box (dlg, _("No user ID(s) found."), _("Key Edit"), MB_ERR); |
1190 |
|
|
return NULL; |
1191 |
|
|
} |
1192 |
|
|
|
1193 |
twoaday |
208 |
listview_new (&lv, GetDlgItem (dlg, IDC_KEYEDIT_UIDLIST)); |
1194 |
werner |
36 |
for( j = 0; cols[j].fieldname != NULL; j++ ) |
1195 |
twoaday |
208 |
listview_add_column (lv, &cols[j]); |
1196 |
werner |
36 |
|
1197 |
twoaday |
211 |
for (j = 0; j < nuids; j++) { |
1198 |
twoaday |
208 |
listview_add_item (lv, " "); |
1199 |
|
|
listview_add_sub_item (lv, 0, 1, " " ); |
1200 |
werner |
36 |
} |
1201 |
|
|
|
1202 |
|
|
listview_set_ext_style (lv); |
1203 |
twoaday |
208 |
for (j = 0, u=k->ext->uids; j < nuids; u=u->next, j++) { |
1204 |
werner |
36 |
if (u->revoked) |
1205 |
|
|
attr = _("Revoked"); |
1206 |
|
|
else { |
1207 |
|
|
u_attr = (int)u->validity; |
1208 |
|
|
attr = get_key_trust2 (NULL, u_attr, 0, 0); |
1209 |
|
|
} |
1210 |
twoaday |
208 |
listview_add_sub_item (lv, j, UID_COL_VALID, (char *)attr); |
1211 |
werner |
36 |
/* XXX: add comment if available */ |
1212 |
twoaday |
208 |
listview_add_sub_item (lv, j, UID_COL_NAME, |
1213 |
twoaday |
204 |
u->name? u->name : _("Invalid user ID")); |
1214 |
|
|
if (u->email) |
1215 |
twoaday |
208 |
listview_add_sub_item (lv, j, UID_COL_EMAIL, u->email); |
1216 |
werner |
36 |
|
1217 |
twoaday |
208 |
ks = get_selfsig (u->signatures, k->keyid, 1); |
1218 |
werner |
36 |
if (ks) |
1219 |
twoaday |
208 |
listview_add_sub_item (lv, j, UID_COL_CREATION, |
1220 |
|
|
get_key_created (ks->timestamp)); |
1221 |
werner |
36 |
} |
1222 |
|
|
if( !k->key_pair ) { |
1223 |
twoaday |
211 |
CheckDlgButton (dlg, IDC_KEYUID_ADD, BST_INDETERMINATE); |
1224 |
|
|
CheckDlgButton (dlg, IDC_KEYUID_REVOKE, BST_INDETERMINATE); |
1225 |
werner |
36 |
} |
1226 |
|
|
return lv; |
1227 |
twoaday |
200 |
} |
1228 |
werner |
36 |
|
1229 |
|
|
|
1230 |
|
|
static void |
1231 |
twoaday |
170 |
do_init_cmdlist (HWND dlg, int is_keypair) |
1232 |
|
|
{ |
1233 |
|
|
const char *s; |
1234 |
werner |
36 |
int i = 0; |
1235 |
|
|
|
1236 |
twoaday |
170 |
for (i = 0; (s=cmdlist[i].name); i++) { |
1237 |
|
|
if (is_keypair) |
1238 |
|
|
SendDlgItemMessage (dlg, IDC_KEYEDIT_CMD, CB_ADDSTRING, 0, |
1239 |
|
|
(LPARAM)(char *)s); |
1240 |
|
|
else if (!cmdlist[i].need_pair) |
1241 |
|
|
SendDlgItemMessage (dlg, IDC_KEYEDIT_CMD, CB_ADDSTRING, 0, |
1242 |
|
|
(LPARAM)(char *)s); |
1243 |
werner |
36 |
} |
1244 |
twoaday |
170 |
SendDlgItemMessage (dlg, IDC_KEYEDIT_CMD, CB_SETCURSEL, 0, 0); |
1245 |
|
|
} |
1246 |
werner |
36 |
|
1247 |
|
|
|
1248 |
twoaday |
165 |
/* Return 1 if the requested command is RFC2440. */ |
1249 |
werner |
36 |
static int |
1250 |
twoaday |
165 |
is_cmd_openpgp (int cmdid) |
1251 |
werner |
36 |
{ |
1252 |
twoaday |
165 |
switch (cmdid) { |
1253 |
werner |
36 |
case CMD_ADDKEY: |
1254 |
|
|
case CMD_ADDPHOTO: |
1255 |
|
|
case CMD_ADDREVOKER: |
1256 |
twoaday |
170 |
//case CMD_SETPREF: |
1257 |
werner |
36 |
return 1; |
1258 |
|
|
} |
1259 |
|
|
return 0; |
1260 |
twoaday |
165 |
} |
1261 |
werner |
36 |
|
1262 |
|
|
|
1263 |
twoaday |
165 |
/* Display a message box with a short description of the commands. */ |
1264 |
werner |
36 |
static void |
1265 |
twoaday |
165 |
do_show_help (HWND dlg) |
1266 |
werner |
36 |
{ |
1267 |
|
|
char helptext[2048]; |
1268 |
|
|
|
1269 |
twoaday |
165 |
_snprintf (helptext, sizeof (helptext)-1, |
1270 |
twoaday |
170 |
_( |
1271 |
werner |
36 |
"ADDUID \t\tadd a user ID\r\n" |
1272 |
|
|
"ADDPHOTO \t\tadd a photo ID\r\n" |
1273 |
|
|
"DELUID \t\tdelete a user ID\r\n" |
1274 |
|
|
"ADDKEY \t\tadd a secondard key\r\n" |
1275 |
|
|
"DELKEY \t\tdelete a secondary key\r\n" |
1276 |
|
|
"ADDREVOKER\t\tadd a revocation key\r\n" |
1277 |
|
|
"EXPIRE \t\tchange the expire date\r\n" |
1278 |
|
|
"SHOWPREF \t\tlist preferences (verbose)\r\n" |
1279 |
twoaday |
170 |
"SETPREF \t\tset preference list\r\n" |
1280 |
werner |
36 |
"UPDPREF \t\tupdated preferences\r\n" |
1281 |
|
|
"PASSWD \t\tchange the passphrase\r\n" |
1282 |
|
|
"PRIMARY \t\tflag user ID as primary\r\n" |
1283 |
|
|
"TRUST \t\tchange the ownertrust\r\n" |
1284 |
|
|
"REVUID \t\trevoke a user ID\r\n" |
1285 |
|
|
"REVKEY \t\trevoke a secondary key\r\n" |
1286 |
|
|
"DISABLE \t\tdisable a key\r\n" |
1287 |
|
|
"ENABLE \t\tenable a key\r\n" |
1288 |
twoaday |
170 |
"SIGN \t\tsign a user-id (exportable)\r\n" |
1289 |
twoaday |
195 |
"LSIGN \t\tsign a user-id (non-exportable)\r\n" |
1290 |
|
|
"CLEAN \t\tremove unusable signatures from key\r\n" |
1291 |
twoaday |
208 |
"MINIMIZE \t\tremove all signatures from key\r\n" |
1292 |
twoaday |
195 |
)); |
1293 |
twoaday |
165 |
msg_box (dlg, helptext, _("Key Edit Help"), MB_OK); |
1294 |
|
|
} |
1295 |
werner |
36 |
|
1296 |
|
|
|
1297 |
|
|
static int |
1298 |
|
|
do_editkey_delkey (winpt_key_t k, HWND dlg, listview_ctrl_t lv) |
1299 |
|
|
{ |
1300 |
|
|
gpgme_error_t err; |
1301 |
|
|
GpgKeyEdit *ke; |
1302 |
|
|
int j, id; |
1303 |
|
|
char tmp[64]; |
1304 |
|
|
|
1305 |
|
|
if (!k->key_pair) |
1306 |
|
|
return FALSE; /* XXX: shall we allow to modify non-secret keys?? */ |
1307 |
|
|
|
1308 |
|
|
if( listview_count_items( lv, 0 ) == 1 ) { |
1309 |
|
|
msg_box( dlg, _("Primary key can not be deleted!"), _("Key Edit"), MB_ERR); |
1310 |
|
|
return FALSE; |
1311 |
|
|
} |
1312 |
|
|
if( (j = listview_get_curr_pos( lv )) == -1 ) { |
1313 |
|
|
msg_box( dlg, _("Please select a key."), _("Key Edit"), MB_ERR ); |
1314 |
|
|
return FALSE; |
1315 |
|
|
} |
1316 |
|
|
if( j == 0 ) { |
1317 |
|
|
msg_box( dlg, _("Primary subkey can not be deleted!"), _("Key Edit"), MB_ERR ); |
1318 |
|
|
return FALSE; |
1319 |
|
|
} |
1320 |
|
|
|
1321 |
twoaday |
200 |
/* XXX: change the warning to make clear that verification won't work |
1322 |
|
|
any longer if this is a sign-only key. */ |
1323 |
|
|
listview_get_item_text (lv, j, 0, tmp, sizeof (tmp) -1); |
1324 |
|
|
id = log_box (_("Key Edit"), MB_YESNO|MB_ICONWARNING, |
1325 |
werner |
36 |
_("\"Subkey %s.\"\n\n" |
1326 |
|
|
"Anything encrypted to the selected subkey will no longer\n" |
1327 |
|
|
"be able to be decrypted.\n\n" |
1328 |
twoaday |
200 |
"Do you really want to delete this subkey?"), tmp); |
1329 |
|
|
if (id == IDNO) |
1330 |
werner |
36 |
return FALSE; |
1331 |
|
|
|
1332 |
|
|
ke = new GpgKeyEdit (k->keyid); |
1333 |
|
|
if (!ke) |
1334 |
|
|
BUG (NULL); |
1335 |
|
|
err = ke->delKey (j); |
1336 |
|
|
if (err) |
1337 |
|
|
msg_box (dlg, gpgme_strerror (err), _("Delete Subkey"), MB_ERR); |
1338 |
|
|
else { |
1339 |
|
|
listview_del_item (lv, j); |
1340 |
|
|
k->update = 1; |
1341 |
|
|
status_box (dlg, _("Subkey successfully deleted."), _("GnuPG status")); |
1342 |
|
|
} |
1343 |
|
|
delete ke; |
1344 |
|
|
return err? FALSE : TRUE; |
1345 |
twoaday |
200 |
} |
1346 |
werner |
36 |
|
1347 |
|
|
|
1348 |
|
|
/* Set the expiration date for the selected key in list view @lv. |
1349 |
|
|
Return value: TRUE on success. */ |
1350 |
|
|
static int |
1351 |
|
|
do_editkey_expire (winpt_key_t k, HWND dlg, listview_ctrl_t lv) |
1352 |
|
|
{ |
1353 |
|
|
gpgme_error_t err; |
1354 |
|
|
GpgKeyEdit *ke; |
1355 |
|
|
date_s udd = {0}; |
1356 |
|
|
char buf[256], * pass = NULL; |
1357 |
|
|
int j, cancel = 0; |
1358 |
|
|
|
1359 |
|
|
if (!k->key_pair) { |
1360 |
twoaday |
41 |
msg_box (dlg, _("There is no secret key available!"), _("Key Edit"), MB_ERR); |
1361 |
werner |
36 |
return FALSE; |
1362 |
|
|
} |
1363 |
twoaday |
41 |
if ((j = listview_get_curr_pos (lv)) == -1) { |
1364 |
werner |
36 |
msg_box( dlg, _("Please select a key."), _("Key Edit"), MB_ERR ); |
1365 |
|
|
return FALSE; |
1366 |
|
|
} |
1367 |
twoaday |
41 |
|
1368 |
|
|
/* If a key already expired, it is possible the user wants to |
1369 |
|
|
set a new expiration date.. */ |
1370 |
|
|
listview_get_item_text (lv, j, SUBK_COL_STATUS, buf, sizeof buf -1); |
1371 |
|
|
if (!strcmp (buf, _("Expired"))) { |
1372 |
|
|
cancel = msg_box (dlg, _("Key already expired.\n\n" |
1373 |
|
|
"Do you want to change the expiration date?"), |
1374 |
|
|
_("Key Edit"), MB_QUEST_ASK); |
1375 |
|
|
if (cancel == IDNO) |
1376 |
|
|
return FALSE; |
1377 |
|
|
cancel = 0; |
1378 |
werner |
36 |
} |
1379 |
twoaday |
41 |
|
1380 |
werner |
36 |
memset (&udd, 0, sizeof udd); |
1381 |
|
|
udd.text = _("Key Expiration Date"); |
1382 |
|
|
dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_DATE, dlg, |
1383 |
|
|
date_dlg_proc, (LPARAM)&udd, |
1384 |
|
|
_("Key Expiration Date"), IDS_WINPT_DATE); |
1385 |
|
|
if (udd.cancel == 1) |
1386 |
|
|
return FALSE; |
1387 |
|
|
if (!keygen_check_date (&udd.st)) { |
1388 |
|
|
msg_box (dlg, _("The date you have chosen lies in the past."), |
1389 |
|
|
_("Key Edit"), MB_ERR); |
1390 |
|
|
return FALSE; |
1391 |
|
|
} |
1392 |
|
|
if( k->is_protected ) { |
1393 |
twoaday |
41 |
pass = request_passphrase (_("Key Edit"), 1, &cancel); |
1394 |
|
|
if (cancel) |
1395 |
werner |
36 |
return FALSE; |
1396 |
|
|
} |
1397 |
|
|
|
1398 |
|
|
ke = new GpgKeyEdit (k->keyid); |
1399 |
|
|
if (!ke) |
1400 |
|
|
BUG (NULL); |
1401 |
|
|
if (k->is_protected) |
1402 |
|
|
ke->setPassphrase (pass); |
1403 |
twoaday |
176 |
else |
1404 |
|
|
ke->setNoPassphrase (true); |
1405 |
twoaday |
175 |
err = ke->setKeyExpireDate (j, w32_mktime (&udd.st), false); |
1406 |
werner |
36 |
if (err) |
1407 |
|
|
msg_box (dlg, gpgme_strerror (err), _("Expire Subkey"), MB_ERR); |
1408 |
|
|
else { |
1409 |
|
|
_snprintf (buf, sizeof buf - 1, "%04d-%02d-%02d", |
1410 |
|
|
udd.st.wYear, udd.st.wMonth, udd.st.wDay); |
1411 |
|
|
listview_add_sub_item (lv, j, SUBK_COL_EXPIRES, buf); |
1412 |
|
|
k->update = 1; |
1413 |
|
|
msg_box (dlg, _("Subkey expire date successfully set."), |
1414 |
|
|
_("GnuPG status"), MB_OK); |
1415 |
|
|
} |
1416 |
|
|
sfree_if_alloc (pass); |
1417 |
|
|
delete ke; |
1418 |
|
|
return TRUE; |
1419 |
|
|
} |
1420 |
|
|
|
1421 |
|
|
|
1422 |
|
|
/* Revoke the selected key in the list view @lv. @k contains |
1423 |
|
|
control information about the global key. |
1424 |
|
|
Return value: TRUE on success. */ |
1425 |
|
|
static int |
1426 |
|
|
do_editkey_revoke (winpt_key_t k, HWND dlg, listview_ctrl_t lv) |
1427 |
|
|
{ |
1428 |
|
|
gpgme_error_t err; |
1429 |
|
|
GpgKeyEdit *ke; |
1430 |
|
|
char buf[256]; |
1431 |
|
|
char *pass = NULL; |
1432 |
|
|
int j, cancel = 0; |
1433 |
|
|
|
1434 |
|
|
if (!k->key_pair) { |
1435 |
|
|
msg_box (dlg, _("There is no secret key available!"), _("Key Edit"), MB_ERR); |
1436 |
|
|
return FALSE; |
1437 |
|
|
} |
1438 |
|
|
|
1439 |
|
|
if ((j = listview_get_curr_pos (lv)) == -1) { |
1440 |
|
|
msg_box( dlg, _("Please select a key."), _("Key Edit"), MB_ERR ); |
1441 |
|
|
return FALSE; |
1442 |
|
|
} |
1443 |
|
|
else if (listview_count_items (lv, 0) == 1) { |
1444 |
|
|
msg_box( dlg, _("No subkeys were found, if you want to revoke the\n" |
1445 |
|
|
"whole key, please use the Key Manager command directly.\n\n" |
1446 |
|
|
"This command is only available to revoke single subkeys"), |
1447 |
|
|
_("Key Edit"), MB_INFO ); |
1448 |
|
|
return FALSE; |
1449 |
|
|
} |
1450 |
|
|
|
1451 |
|
|
listview_get_item_text (lv, j, SUBK_COL_STATUS, buf, sizeof (buf)-1); |
1452 |
|
|
if (!strcmp (buf, _("Revoked"))) { |
1453 |
|
|
msg_box (dlg, _("Key already revoked."), _("Key Edit"), MB_ERR); |
1454 |
|
|
return FALSE; |
1455 |
|
|
} |
1456 |
|
|
|
1457 |
|
|
if (k->is_protected) { |
1458 |
|
|
pass = request_passphrase (_("Key Edit"), 1, &cancel); |
1459 |
|
|
if (cancel) |
1460 |
|
|
return FALSE; |
1461 |
|
|
} |
1462 |
|
|
|
1463 |
|
|
ke = new GpgKeyEdit (k->keyid); |
1464 |
|
|
if (!ke) |
1465 |
|
|
BUG (NULL); |
1466 |
|
|
if (k->is_protected) |
1467 |
|
|
ke->setPassphrase (pass); |
1468 |
twoaday |
176 |
else |
1469 |
|
|
ke->setNoPassphrase (true); |
1470 |
werner |
36 |
err = ke->revokeSubkey (j, 0, NULL); |
1471 |
|
|
if (err) |
1472 |
|
|
msg_box( dlg, gpgme_strerror (err), _("Revoke Subkey"), MB_ERR); |
1473 |
|
|
else { |
1474 |
|
|
listview_add_sub_item (lv, j, SUBK_COL_STATUS, _("Revoked")); |
1475 |
|
|
k->update = 1; |
1476 |
|
|
msg_box( dlg, _("Subkey successfully revoked."), _("GnuPG Status"), MB_OK ); |
1477 |
|
|
} |
1478 |
|
|
sfree_if_alloc (pass); |
1479 |
|
|
delete ke; |
1480 |
|
|
return TRUE; |
1481 |
|
|
} |
1482 |
|
|
|
1483 |
|
|
|
1484 |
|
|
/* Revoked the selected userid in list view @lv. |
1485 |
|
|
Return value: TRUE on success. */ |
1486 |
|
|
int |
1487 |
|
|
do_editkey_revuid (winpt_key_t k, HWND dlg, listview_ctrl_t lv) |
1488 |
|
|
{ |
1489 |
|
|
gpgme_error_t err; |
1490 |
|
|
GpgKeyEdit *ke; |
1491 |
twoaday |
160 |
char buf[128], email[128]; |
1492 |
|
|
char inf[512]; |
1493 |
|
|
char *pass = NULL; |
1494 |
werner |
36 |
int cancel = 0, id = 0, j; |
1495 |
|
|
|
1496 |
|
|
if (!k->key_pair) { |
1497 |
twoaday |
160 |
msg_box (dlg, _("There is no secret key available!"), |
1498 |
|
|
_("Revoke user ID"), MB_ERR); |
1499 |
werner |
36 |
return FALSE; |
1500 |
|
|
} |
1501 |
|
|
|
1502 |
twoaday |
160 |
if (listview_count_items (lv, 0) == 1) { |
1503 |
|
|
msg_box (dlg, _("Key has only one user ID."), _("Key Edit"), MB_ERR); |
1504 |
werner |
36 |
return FALSE; |
1505 |
|
|
} |
1506 |
|
|
|
1507 |
|
|
if( (j = listview_get_curr_pos( lv )) == -1 ) { |
1508 |
|
|
msg_box( dlg, _("Please select a user ID."), _("Key Edit"), MB_ERR ); |
1509 |
|
|
return FALSE; |
1510 |
|
|
} |
1511 |
|
|
|
1512 |
twoaday |
160 |
listview_get_item_text( lv, j, UID_COL_VALID, buf, sizeof buf - 1); |
1513 |
|
|
if (strstr (buf, _("Revoked"))) { |
1514 |
|
|
msg_box (dlg, _("This user ID has been already revoked."), |
1515 |
|
|
_("Key Edit"), MB_INFO); |
1516 |
werner |
36 |
return FALSE; |
1517 |
|
|
} |
1518 |
|
|
|
1519 |
twoaday |
160 |
listview_get_item_text (lv, j, UID_COL_NAME, buf, sizeof buf -1); |
1520 |
|
|
_snprintf (inf, sizeof (inf) -1, _("user ID \"%s\".\n\n" |
1521 |
|
|
"Do you really want to revoke this user ID?"), buf); |
1522 |
|
|
if (msg_box (dlg, inf, _("Key Edit"), MB_WARN_ASK) == IDNO) |
1523 |
werner |
36 |
return FALSE; |
1524 |
twoaday |
160 |
if (k->is_protected) { |
1525 |
werner |
36 |
pass = request_passphrase (_("Key Edit"), 1, &cancel); |
1526 |
twoaday |
68 |
if (cancel) |
1527 |
werner |
36 |
return FALSE; |
1528 |
|
|
} |
1529 |
twoaday |
160 |
listview_get_item_text (lv, j, UID_COL_EMAIL, email, sizeof (email)-1); |
1530 |
|
|
listview_get_item_text (lv, j, UID_COL_NAME, buf, sizeof (buf)-1); |
1531 |
|
|
id = do_find_userid (k->keyid, email, buf, NULL); |
1532 |
werner |
36 |
if (id == -1) |
1533 |
|
|
BUG (NULL); |
1534 |
|
|
|
1535 |
|
|
ke = new GpgKeyEdit (k->keyid); |
1536 |
|
|
if (!ke) |
1537 |
|
|
BUG (NULL); |
1538 |
|
|
if (k->is_protected) |
1539 |
|
|
ke->setPassphrase (pass); |
1540 |
twoaday |
176 |
else |
1541 |
|
|
ke->setNoPassphrase (true); |
1542 |
werner |
36 |
err = ke->revokeUserid (id); |
1543 |
|
|
if (err) |
1544 |
twoaday |
160 |
msg_box (dlg, gpgme_strerror (err), _("Revoke User ID"), MB_ERR); |
1545 |
werner |
36 |
else { |
1546 |
|
|
listview_add_sub_item (lv, j, 0, _("Revoked")); |
1547 |
|
|
k->update = 1; |
1548 |
|
|
status_box (dlg, _("User ID successfully revoked"), _("GnuPG Status")); |
1549 |
|
|
} |
1550 |
|
|
sfree_if_alloc (pass); |
1551 |
|
|
delete ke; |
1552 |
|
|
return err? FALSE : TRUE; |
1553 |
|
|
} |
1554 |
|
|
|
1555 |
|
|
|
1556 |
|
|
static int |
1557 |
|
|
do_editkey_setpref (winpt_key_t k, HWND dlg, listview_ctrl_t lv) |
1558 |
|
|
{ |
1559 |
|
|
gpgme_error_t rc; |
1560 |
|
|
GpgKeyEdit *ke; |
1561 |
|
|
char buf[256], * pass = NULL, * prefs; |
1562 |
|
|
int j, id, cancel=0, flags=0; |
1563 |
|
|
|
1564 |
|
|
if ((j = listview_get_curr_pos (lv)) == -1) { |
1565 |
|
|
msg_box (dlg, _("Please select a user ID."), _("Key Edit"), MB_ERR); |
1566 |
|
|
return FALSE; |
1567 |
|
|
} |
1568 |
|
|
listview_get_item_text (lv, j, 2, buf, sizeof buf-1); |
1569 |
twoaday |
160 |
id = do_find_userid (k->keyid, buf, NULL, NULL); |
1570 |
werner |
36 |
if (id == -1) |
1571 |
|
|
BUG (dlg); |
1572 |
|
|
if (k->is_protected) { |
1573 |
|
|
pass = request_passphrase (_("Key Edit"), 1, &cancel); |
1574 |
|
|
if (cancel) |
1575 |
|
|
return FALSE; |
1576 |
|
|
} |
1577 |
|
|
|
1578 |
|
|
ke = new GpgKeyEdit (k->keyid); |
1579 |
|
|
if (!ke) |
1580 |
|
|
BUG (NULL); |
1581 |
|
|
if (k->is_protected) |
1582 |
|
|
ke->setPassphrase (pass); |
1583 |
twoaday |
176 |
else |
1584 |
|
|
ke->setNoPassphrase (true); |
1585 |
werner |
36 |
|
1586 |
|
|
get_userid_preflist (&prefs, &flags); |
1587 |
|
|
|
1588 |
|
|
rc = ke->setUseridPreferences (id, prefs); |
1589 |
twoaday |
176 |
if (rc) |
1590 |
|
|
msg_box (dlg, _("Could not set user ID preferences"), _("Key Edit"), MB_ERR); |
1591 |
werner |
36 |
|
1592 |
|
|
sfree_if_alloc (pass); |
1593 |
|
|
free_if_alloc (prefs); |
1594 |
|
|
delete ke; |
1595 |
|
|
return 0; |
1596 |
|
|
} |
1597 |
|
|
|
1598 |
|
|
|
1599 |
|
|
static int |
1600 |
|
|
do_editkey_primary (winpt_key_t k, HWND dlg, listview_ctrl_t lv) |
1601 |
|
|
{ |
1602 |
|
|
gpgme_error_t err; |
1603 |
|
|
GpgKeyEdit *ke; |
1604 |
|
|
int j, id, cancel=0; |
1605 |
twoaday |
197 |
char buf[256], *pass = NULL; |
1606 |
werner |
36 |
|
1607 |
|
|
if (listview_count_items (lv, 0) == 1) |
1608 |
|
|
return TRUE; |
1609 |
|
|
if ((j = listview_get_curr_pos (lv)) == -1) { |
1610 |
|
|
msg_box( dlg, _("Please select a user ID."), _("Key Edit"), MB_ERR ); |
1611 |
|
|
return FALSE; |
1612 |
|
|
} |
1613 |
|
|
listview_get_item_text (lv, j, 2, buf, sizeof buf-1); |
1614 |
twoaday |
160 |
id = do_find_userid (k->keyid, buf, NULL, NULL); |
1615 |
werner |
36 |
if (id == -1) |
1616 |
twoaday |
197 |
BUG (0); |
1617 |
werner |
36 |
if (k->is_protected) { |
1618 |
|
|
pass = request_passphrase (_("Key Edit"), 1, &cancel); |
1619 |
twoaday |
128 |
if (cancel) |
1620 |
werner |
36 |
return FALSE; |
1621 |
|
|
} |
1622 |
|
|
|
1623 |
|
|
ke = new GpgKeyEdit (k->keyid); |
1624 |
|
|
if (k->is_protected) |
1625 |
|
|
ke->setPassphrase (pass); |
1626 |
twoaday |
176 |
else |
1627 |
|
|
ke->setNoPassphrase (true); |
1628 |
werner |
36 |
err = ke->setPrimaryUserid (id); |
1629 |
|
|
if (err) |
1630 |
|
|
msg_box (dlg, gpgme_strerror (err), _("Primary"), MB_ERR); |
1631 |
|
|
else { |
1632 |
|
|
k->update = 1; |
1633 |
|
|
status_box (dlg, _("User ID successfully flagged"), _("GnuPG Status")); |
1634 |
|
|
} |
1635 |
|
|
|
1636 |
|
|
sfree_if_alloc (pass); |
1637 |
|
|
delete ke; |
1638 |
|
|
return err? FALSE : TRUE; |
1639 |
|
|
} |
1640 |
|
|
|
1641 |
|
|
|
1642 |
twoaday |
123 |
|
1643 |
twoaday |
128 |
#define CIPHER 11 |
1644 |
|
|
#define HASH 11 |
1645 |
|
|
#define COMPR 4 |
1646 |
|
|
|
1647 |
werner |
36 |
static int |
1648 |
|
|
parse_preflist (HWND dlg, const char *list) |
1649 |
|
|
{ |
1650 |
twoaday |
123 |
char buf[128] = {0}; |
1651 |
|
|
char *p, *pbuf = buf; |
1652 |
|
|
const char *ciphers[CIPHER] = {"", "IDEA", "3DES", |
1653 |
twoaday |
128 |
"CAST5", "BLOWFISH", "", "", |
1654 |
|
|
"AES", "AES192", "AES256", "TWOFISH"}; |
1655 |
|
|
const char *hash[HASH] = {"", "MD5", "SHA1", "RMD160", "", |
1656 |
|
|
"", "", "", "SHA256", "SHA384", "SHA512"}; |
1657 |
twoaday |
123 |
const char *compress[COMPR] = {"", "ZIP", "ZLIB", "BZIP2"}; |
1658 |
werner |
36 |
int n=0; |
1659 |
|
|
|
1660 |
|
|
strncpy (buf, list, 127); |
1661 |
|
|
p = strtok (pbuf, " "); |
1662 |
|
|
while (p != NULL) { |
1663 |
|
|
int algid = atol (p+1); |
1664 |
|
|
n++; |
1665 |
|
|
switch (*p) { |
1666 |
|
|
case 'S': |
1667 |
twoaday |
123 |
SendDlgItemMessage (dlg, IDC_SHOWPREF_CIPHERS, LB_ADDSTRING, 0, |
1668 |
|
|
(LPARAM)(const char*)ciphers[algid % CIPHER]); |
1669 |
werner |
36 |
break; |
1670 |
|
|
|
1671 |
|
|
case 'H': |
1672 |
twoaday |
123 |
SendDlgItemMessage (dlg, IDC_SHOWPREF_HASH, LB_ADDSTRING, 0, |
1673 |
|
|
(LPARAM)(const char*)hash[algid % HASH]); |
1674 |
werner |
36 |
break; |
1675 |
|
|
|
1676 |
|
|
case 'Z': |
1677 |
twoaday |
123 |
SendDlgItemMessage (dlg, IDC_SHOWPREF_ZIP, LB_ADDSTRING, 0, |
1678 |
|
|
(LPARAM)(const char*)compress[algid % COMPR]); |
1679 |
werner |
36 |
break; |
1680 |
|
|
|
1681 |
|
|
default: |
1682 |
|
|
n--; |
1683 |
|
|
} |
1684 |
|
|
p = strtok (NULL, " "); |
1685 |
|
|
} |
1686 |
|
|
return n; |
1687 |
|
|
} |
1688 |
|
|
|
1689 |
|
|
|
1690 |
|
|
/* Dialog box procedure to show the key preferences. */ |
1691 |
|
|
BOOL CALLBACK |
1692 |
|
|
showpref_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
1693 |
|
|
{ |
1694 |
twoaday |
176 |
static keyedit_cb_t cb = NULL; |
1695 |
twoaday |
208 |
gpg_uid_info_t inf=NULL, u; |
1696 |
twoaday |
200 |
gpgme_key_t key; |
1697 |
werner |
36 |
char buf[128]; |
1698 |
|
|
int pos; |
1699 |
|
|
|
1700 |
|
|
switch (msg) { |
1701 |
|
|
case WM_INITDIALOG: |
1702 |
twoaday |
176 |
cb = (keyedit_cb_t)lparam; |
1703 |
twoaday |
200 |
if (!cb) |
1704 |
|
|
BUG (NULL); |
1705 |
|
|
key = (gpgme_key_t)cb->opaque; |
1706 |
twoaday |
208 |
listview_get_item_text (cb->lv, cb->lv_pos, |
1707 |
|
|
UID_COL_EMAIL, buf, sizeof (buf)-1); |
1708 |
|
|
pos = do_find_userid (cb->keyid, buf, NULL, &inf); |
1709 |
|
|
if (pos < 0 || !inf) { |
1710 |
|
|
gpg_uid_info_release (inf); |
1711 |
|
|
EndDialog (dlg, FALSE); |
1712 |
|
|
break; |
1713 |
|
|
} |
1714 |
|
|
for (u=inf; u; u = u->next) { |
1715 |
|
|
if (u->index == pos && u->prefs && *u->prefs) { |
1716 |
|
|
_snprintf (buf, sizeof (buf)-1, "%s", u->name); |
1717 |
|
|
SetDlgItemText (dlg, IDC_SHOWPREF_INFO, buf); |
1718 |
|
|
if (parse_preflist (dlg, u->prefs) <= 0) |
1719 |
werner |
36 |
pos = -1; |
1720 |
twoaday |
208 |
if (u->flags.mdc) |
1721 |
|
|
CheckDlgButton (dlg, IDC_SHOWPREF_MDC, BST_CHECKED); |
1722 |
|
|
break; |
1723 |
werner |
36 |
} |
1724 |
|
|
} |
1725 |
twoaday |
208 |
gpg_uid_info_release (inf); |
1726 |
|
|
if (pos == -1) { |
1727 |
|
|
msg_box (dlg, _("No preferences available."), _("Key Edit"), MB_ERR); |
1728 |
|
|
EndDialog (dlg, FALSE); |
1729 |
|
|
break; |
1730 |
|
|
} |
1731 |
twoaday |
128 |
SetDlgItemText (dlg, IDC_SHOWPREF_MDC, _("MDC feature")); |
1732 |
|
|
SetDlgItemText (dlg, IDC_SHOWPREF_PREFINF, _("Preferences")); |
1733 |
twoaday |
200 |
SetDlgItemText (dlg, IDC_SHOWPREF_UIDHINT, _("user ID:")); |
1734 |
werner |
36 |
SetWindowText (dlg, _("Key Preferences")); |
1735 |
|
|
SetForegroundWindow (dlg); |
1736 |
twoaday |
218 |
center_window (dlg, cb->parent); |
1737 |
werner |
36 |
break; |
1738 |
|
|
|
1739 |
|
|
case WM_COMMAND: |
1740 |
|
|
switch (LOWORD (wparam)) { |
1741 |
|
|
case IDOK: |
1742 |
|
|
EndDialog (dlg, TRUE); |
1743 |
|
|
break; |
1744 |
twoaday |
211 |
|
1745 |
|
|
case IDCANCEL: |
1746 |
|
|
EndDialog (dlg, FALSE); |
1747 |
|
|
break; |
1748 |
werner |
36 |
} |
1749 |
|
|
break; |
1750 |
|
|
} |
1751 |
|
|
return FALSE; |
1752 |
|
|
} |
1753 |
|
|
|
1754 |
|
|
|
1755 |
|
|
static int |
1756 |
|
|
do_editkey_showpref (winpt_key_t k, HWND dlg, listview_ctrl_t lv) |
1757 |
|
|
{ |
1758 |
twoaday |
176 |
struct keyedit_cb_s cb; |
1759 |
twoaday |
208 |
char status[32]; |
1760 |
werner |
36 |
|
1761 |
|
|
if (k->is_v3) |
1762 |
|
|
return TRUE; |
1763 |
|
|
|
1764 |
|
|
if (listview_get_curr_pos (lv) == -1) { |
1765 |
|
|
msg_box (dlg, _("Please select a user ID."), _("Key Edit"), MB_ERR); |
1766 |
|
|
return FALSE; |
1767 |
|
|
} |
1768 |
|
|
memset (&cb, 0, sizeof (cb)); |
1769 |
twoaday |
218 |
cb.parent = dlg; |
1770 |
twoaday |
200 |
cb.opaque = k->ctx; |
1771 |
|
|
cb.keyid = k->keyid; |
1772 |
twoaday |
208 |
cb.lv = lv; |
1773 |
|
|
cb.lv_pos = listview_get_curr_pos (lv); |
1774 |
|
|
|
1775 |
|
|
listview_get_item_text (lv, cb.lv_pos, UID_COL_VALID, |
1776 |
|
|
status, sizeof (status)-1); |
1777 |
|
|
if (!strcmp (status, _("Revoked"))) |
1778 |
|
|
return TRUE; |
1779 |
|
|
|
1780 |
werner |
36 |
DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_KEYEDIT_SHOWPREF, dlg, |
1781 |
|
|
showpref_dlg_proc, (LPARAM)&cb); |
1782 |
|
|
return TRUE; |
1783 |
|
|
} |
1784 |
|
|
|
1785 |
|
|
|
1786 |
|
|
static int |
1787 |
|
|
do_editkey_deluid (winpt_key_t k, HWND dlg, listview_ctrl_t lv) |
1788 |
|
|
{ |
1789 |
|
|
gpgme_error_t err; |
1790 |
|
|
GpgKeyEdit *ke; |
1791 |
twoaday |
160 |
char email[128], name[128]; |
1792 |
|
|
char inf[384]; |
1793 |
werner |
36 |
int j, id = 0; |
1794 |
|
|
|
1795 |
|
|
if (!k->key_pair) |
1796 |
|
|
return FALSE; /* XXX: see do_editkey_delsubkey */ |
1797 |
|
|
|
1798 |
twoaday |
160 |
if (listview_count_items (lv, 0) == 1) { |
1799 |
|
|
msg_box (dlg, _("Primary user ID can not be deleted!"), |
1800 |
|
|
_("Key Edit"), MB_ERR); |
1801 |
werner |
36 |
return FALSE; |
1802 |
|
|
} |
1803 |
twoaday |
160 |
if ((j = listview_get_curr_pos (lv)) == -1) { |
1804 |
|
|
msg_box (dlg, _("Please select a user ID."), _("Key Edit"), MB_ERR); |
1805 |
werner |
36 |
return FALSE; |
1806 |
|
|
} |
1807 |
|
|
|
1808 |
|
|
/* XXX: add a hint that also all signatures will be deleted? */ |
1809 |
twoaday |
160 |
listview_get_item_text (lv, j, UID_COL_NAME, name, DIM(name) -1); |
1810 |
|
|
_snprintf (inf, DIM (inf)-1, _("user ID \"%s\".\n\n" |
1811 |
twoaday |
193 |
"All signatures on this user ID will be also deleted." |
1812 |
|
|
"\n\n" |
1813 |
twoaday |
160 |
"Do you really want to delete this user ID?"), |
1814 |
|
|
name); |
1815 |
|
|
if (msg_box (dlg, inf, _("Key Edit"), MB_YESNO|MB_ICONWARNING) == IDNO) |
1816 |
werner |
36 |
return FALSE; |
1817 |
|
|
|
1818 |
twoaday |
160 |
listview_get_item_text (lv, j, UID_COL_EMAIL, email, DIM (email)-1); |
1819 |
|
|
listview_get_item_text (lv, j, UID_COL_NAME, name, DIM (name)-1); |
1820 |
|
|
id = do_find_userid (k->keyid, email, name, NULL); |
1821 |
werner |
36 |
if (id == -1) |
1822 |
|
|
BUG (dlg); |
1823 |
|
|
|
1824 |
|
|
ke = new GpgKeyEdit (k->keyid); |
1825 |
|
|
if (!ke) |
1826 |
|
|
BUG (NULL); |
1827 |
|
|
|
1828 |
|
|
err = ke->delUserid (id); |
1829 |
twoaday |
160 |
if (err) |
1830 |
|
|
msg_box (dlg, gpgme_strerror (err), _("Delete user ID"), MB_ERR); |
1831 |
werner |
36 |
else { |
1832 |
twoaday |
160 |
listview_del_item (lv, j); |
1833 |
werner |
36 |
k->update = 1; |
1834 |
twoaday |
160 |
status_box (dlg, _("User ID successfully deleted"), _("GnuPG Status")); |
1835 |
werner |
36 |
} |
1836 |
|
|
delete ke; |
1837 |
|
|
return err? FALSE : TRUE; |
1838 |
twoaday |
193 |
} |
1839 |
werner |
36 |
|
1840 |
|
|
|
1841 |
twoaday |
193 |
/* Subclass routine for the subkey listview control to allow shortcuts. */ |
1842 |
werner |
36 |
static BOOL CALLBACK |
1843 |
twoaday |
193 |
subkey_subclass_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
1844 |
werner |
36 |
{ |
1845 |
twoaday |
193 |
int virt_key = 0; |
1846 |
|
|
winpt_key_t key; |
1847 |
|
|
|
1848 |
|
|
switch (msg) { |
1849 |
werner |
36 |
case WM_KEYUP: |
1850 |
twoaday |
193 |
virt_key = (int)wparam; |
1851 |
|
|
key = (winpt_key_t)keyedit_subkey_proc.opaque; |
1852 |
|
|
if (!key || !key->key_pair) |
1853 |
|
|
break; |
1854 |
|
|
|
1855 |
|
|
switch (virt_key) { |
1856 |
werner |
36 |
case VK_DELETE: |
1857 |
twoaday |
193 |
SendDlgItemMessage (keyedit_subkey_proc.dlg, IDC_KEYEDIT_CMD, |
1858 |
|
|
CB_SETCURSEL, CMD_DELKEY, 0); |
1859 |
|
|
send_cmd_id (keyedit_subkey_proc.dlg, IDOK); |
1860 |
werner |
36 |
break; |
1861 |
|
|
|
1862 |
|
|
case VK_INSERT: |
1863 |
twoaday |
200 |
SendDlgItemMessage (keyedit_subkey_proc.dlg, IDC_KEYEDIT_CMD, |
1864 |
|
|
CB_SETCURSEL, CMD_ADDKEY, 0); |
1865 |
|
|
send_cmd_id (keyedit_subkey_proc.dlg, IDOK); |
1866 |
werner |
36 |
break; |
1867 |
|
|
} |
1868 |
|
|
} |
1869 |
twoaday |
193 |
return CallWindowProc (keyedit_subkey_proc.old, dlg, msg, wparam, lparam); |
1870 |
|
|
} |
1871 |
werner |
36 |
|
1872 |
|
|
|
1873 |
|
|
static BOOL CALLBACK |
1874 |
|
|
uid_subclass_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
1875 |
|
|
{ |
1876 |
twoaday |
193 |
int virt_key = 0; |
1877 |
|
|
winpt_key_t key; |
1878 |
|
|
|
1879 |
|
|
switch (msg) { |
1880 |
werner |
36 |
case WM_KEYUP: |
1881 |
twoaday |
193 |
virt_key = (int)wparam; |
1882 |
|
|
key = (winpt_key_t)keyedit_uid_proc.opaque; |
1883 |
|
|
if (!key || !key->key_pair) |
1884 |
|
|
break; |
1885 |
|
|
|
1886 |
werner |
36 |
switch (virt_key) { |
1887 |
|
|
case VK_DELETE: |
1888 |
|
|
SendDlgItemMessage (keyedit_uid_proc.dlg, IDC_KEYEDIT_CMD, |
1889 |
|
|
CB_SETCURSEL, CMD_DELUID, 0); |
1890 |
|
|
send_cmd_id (keyedit_uid_proc.dlg, IDOK); |
1891 |
|
|
break; |
1892 |
|
|
|
1893 |
|
|
case VK_INSERT: |
1894 |
|
|
SendDlgItemMessage (keyedit_uid_proc.dlg, IDC_KEYEDIT_CMD, |
1895 |
|
|
CB_SETCURSEL, CMD_ADDUID, 0); |
1896 |
|
|
send_cmd_id (keyedit_uid_proc.dlg, IDOK); |
1897 |
|
|
break; |
1898 |
|
|
} |
1899 |
|
|
} |
1900 |
twoaday |
193 |
return CallWindowProc (keyedit_uid_proc.old, dlg, msg, wparam, lparam); |
1901 |
|
|
} |
1902 |
werner |
36 |
|
1903 |
|
|
|
1904 |
twoaday |
193 |
/* Enable the key @k when @enable is 1, disable it otherwise. */ |
1905 |
twoaday |
165 |
static void |
1906 |
twoaday |
193 |
do_editkey_enable_disable (winpt_key_t k, HWND dlg, |
1907 |
|
|
listview_ctrl_t lv, int enable) |
1908 |
twoaday |
165 |
{ |
1909 |
|
|
km_enable_disable_key (lv, dlg, 0, enable); |
1910 |
|
|
k->update = 1; |
1911 |
|
|
} |
1912 |
|
|
|
1913 |
|
|
|
1914 |
twoaday |
170 |
/* Return default secret key. */ |
1915 |
|
|
static gpgme_key_t |
1916 |
|
|
get_default_key (void) |
1917 |
|
|
{ |
1918 |
|
|
gpgme_key_t def_sk; |
1919 |
|
|
char *keyid = get_gnupg_default_key (); |
1920 |
|
|
|
1921 |
|
|
get_seckey (keyid, &def_sk); |
1922 |
|
|
free_if_alloc (keyid); |
1923 |
|
|
return def_sk; |
1924 |
|
|
} |
1925 |
|
|
|
1926 |
|
|
|
1927 |
twoaday |
195 |
|
1928 |
|
|
static void |
1929 |
twoaday |
208 |
do_editkey_minimize (winpt_key_t k, HWND dlg) |
1930 |
|
|
{ |
1931 |
|
|
gpgme_error_t err; |
1932 |
|
|
GpgKeyEdit *ke; |
1933 |
|
|
|
1934 |
|
|
ke = create_GpgKeyEdit (k->keyid); |
1935 |
|
|
err = ke->minimizeKey (); |
1936 |
|
|
if (err) |
1937 |
|
|
msg_box (dlg, gpgme_strerror (err), _("Key Edit"), MB_ERR); |
1938 |
|
|
else { |
1939 |
|
|
msg_box (dlg, _("Finished to compact key."), _("Key Edit"), MB_OK); |
1940 |
|
|
k->update = 1; |
1941 |
|
|
} |
1942 |
|
|
delete ke; |
1943 |
|
|
} |
1944 |
|
|
|
1945 |
|
|
|
1946 |
|
|
static void |
1947 |
twoaday |
195 |
do_editkey_clean (winpt_key_t k, HWND dlg) |
1948 |
|
|
{ |
1949 |
|
|
gpgme_error_t err; |
1950 |
|
|
GpgKeyEdit *ke; |
1951 |
|
|
|
1952 |
twoaday |
200 |
ke = create_GpgKeyEdit (k->keyid); |
1953 |
twoaday |
195 |
err = ke->cleanKey (); |
1954 |
|
|
if (err) |
1955 |
twoaday |
197 |
msg_box (dlg, gpgme_strerror (err), _("Key Edit"), MB_ERR); |
1956 |
|
|
else { |
1957 |
twoaday |
195 |
msg_box (dlg, _("Finished to compact key."), _("Key Edit"), MB_OK); |
1958 |
twoaday |
197 |
k->update = 1; |
1959 |
|
|
} |
1960 |
twoaday |
195 |
delete ke; |
1961 |
|
|
} |
1962 |
|
|
|
1963 |
|
|
|
1964 |
twoaday |
193 |
/* Start the dialog to list and display the status of all |
1965 |
|
|
signatures for this key. */ |
1966 |
twoaday |
175 |
static void |
1967 |
|
|
do_editkey_check (winpt_key_t k, HWND dlg) |
1968 |
|
|
{ |
1969 |
twoaday |
176 |
if (!k->ctx) |
1970 |
|
|
get_pubkey (k->keyid, &k->ctx); |
1971 |
|
|
if (!k->uid && k->ctx) |
1972 |
|
|
k->uid = k->ctx->uids->uid; |
1973 |
twoaday |
175 |
DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_KEYSIG_TREE, dlg, |
1974 |
twoaday |
176 |
sigtree_dlg_proc, (LPARAM)k); |
1975 |
twoaday |
175 |
} |
1976 |
|
|
|
1977 |
|
|
|
1978 |
twoaday |
170 |
static int |
1979 |
|
|
do_editkey_sign_userid (winpt_key_t k, HWND dlg, listview_ctrl_t lv, int mode) |
1980 |
|
|
{ |
1981 |
|
|
gpgme_error_t err; |
1982 |
|
|
GpgKeyEdit *ke; |
1983 |
|
|
char *pass = NULL; |
1984 |
|
|
char email[64], name[128]; |
1985 |
|
|
int uid_index; |
1986 |
|
|
int cancel = 0; |
1987 |
|
|
|
1988 |
|
|
uid_index = listview_get_curr_pos (lv); |
1989 |
|
|
if (uid_index == -1) { |
1990 |
|
|
msg_box (dlg, _("Please select a user ID."), _("Key Edit"), MB_ERR); |
1991 |
|
|
return FALSE; |
1992 |
|
|
} |
1993 |
|
|
if (mode == CMD_SIGN) { |
1994 |
|
|
cancel = msg_box (dlg, _("Do you really want to make this sig exportable?"), |
1995 |
|
|
_("Key Edit"), MB_QUEST_ASK); |
1996 |
|
|
if (cancel == IDNO) |
1997 |
|
|
return FALSE; |
1998 |
|
|
} |
1999 |
|
|
|
2000 |
|
|
listview_get_item_text (lv, uid_index, UID_COL_EMAIL, email, sizeof (email)-1); |
2001 |
|
|
listview_get_item_text (lv, uid_index, UID_COL_NAME, name, sizeof (name)-1); |
2002 |
|
|
uid_index = do_find_userid (k->keyid, email, name, NULL); |
2003 |
|
|
if (k->is_protected) { |
2004 |
|
|
pass = request_passphrase (_("Key Edit"), 1, &cancel); |
2005 |
|
|
if (cancel) |
2006 |
|
|
return FALSE; |
2007 |
|
|
} |
2008 |
twoaday |
200 |
ke = create_GpgKeyEdit (k->keyid); |
2009 |
twoaday |
175 |
if (k->is_protected) |
2010 |
|
|
ke->setPassphrase (pass); |
2011 |
twoaday |
176 |
else |
2012 |
|
|
ke->setNoPassphrase (true); |
2013 |
twoaday |
170 |
ke->setLocalUser (get_default_key ()); |
2014 |
|
|
err = ke->signUserid (uid_index, |
2015 |
|
|
mode == CMD_SIGN? GPG_EDITKEY_SIGN : GPG_EDITKEY_LSIGN, |
2016 |
|
|
0, NULL); |
2017 |
|
|
if (!err) { |
2018 |
|
|
msg_box (dlg, _("Key successfully signed."), _("Key Edit"), MB_OK); |
2019 |
|
|
k->update = 1; |
2020 |
|
|
} |
2021 |
|
|
else |
2022 |
|
|
msg_box (dlg, gpgme_strerror (err), _("Key Edit"), MB_ERR); |
2023 |
|
|
delete ke; |
2024 |
|
|
sfree_if_alloc (pass); |
2025 |
|
|
return !err? TRUE : FALSE; |
2026 |
|
|
} |
2027 |
|
|
|
2028 |
|
|
|
2029 |
|
|
static int |
2030 |
|
|
lookup_cmd (HWND dlg) |
2031 |
|
|
{ |
2032 |
|
|
char buf[64]; |
2033 |
|
|
int i; |
2034 |
|
|
|
2035 |
|
|
i = SendDlgItemMessage (dlg, IDC_KEYEDIT_CMD, CB_GETCURSEL, 0, 0); |
2036 |
|
|
if (i == LB_ERR) |
2037 |
|
|
return LB_ERR; |
2038 |
|
|
GetDlgItemText (dlg, IDC_KEYEDIT_CMD, buf, sizeof (buf)-1); |
2039 |
|
|
for (i=0; cmdlist[i].name != NULL; i++) { |
2040 |
|
|
if (!strcmp (buf, cmdlist[i].name)) |
2041 |
|
|
return cmdlist[i].id; |
2042 |
|
|
} |
2043 |
|
|
return LB_ERR; |
2044 |
|
|
} |
2045 |
|
|
|
2046 |
twoaday |
193 |
|
2047 |
twoaday |
208 |
|
2048 |
|
|
gpgme_error_t key_get_revokers (winpt_key_t key, int reload, |
2049 |
|
|
gpg_desig_rev_t *r_rev); |
2050 |
|
|
|
2051 |
|
|
/* Check if the key supports designated revokers and if |
2052 |
|
|
secret keys exist to generate such a revoke cert. */ |
2053 |
|
|
static bool |
2054 |
|
|
check_desig_rev (winpt_key_t key) |
2055 |
|
|
{ |
2056 |
|
|
gpg_desig_rev_t rev, u; |
2057 |
|
|
struct winpt_key_s sk; |
2058 |
|
|
|
2059 |
|
|
if (!key->ext->gloflags.has_desig_rev) |
2060 |
|
|
return false; |
2061 |
|
|
key_get_revokers (key, 0, &rev); |
2062 |
|
|
for (u = rev; u; u = u->next) { |
2063 |
|
|
memset (&sk, 0, sizeof (sk)); |
2064 |
|
|
if (!winpt_get_seckey (u->fpr+32, &sk)) |
2065 |
|
|
return true; |
2066 |
|
|
} |
2067 |
|
|
return false; |
2068 |
|
|
} |
2069 |
|
|
|
2070 |
|
|
|
2071 |
|
|
/* Use the gpg --desig-revoker command to create a revocation |
2072 |
|
|
cert for a key that lists our key as a designated revoker. */ |
2073 |
|
|
static void |
2074 |
|
|
gen_desig_revoke_cert (winpt_key_t key, HWND dlg) |
2075 |
|
|
{ |
2076 |
|
|
const char *warn; |
2077 |
|
|
char *inf, *p; |
2078 |
|
|
int id; |
2079 |
|
|
|
2080 |
|
|
inf = km_key_get_info (key, 0); |
2081 |
|
|
warn = _("Your keys is listed as a designated revoker for the key\n\n" |
2082 |
|
|
"%s\n\n" |
2083 |
|
|
"Are you sure you want to create a revocation certificate\n" |
2084 |
|
|
"which allow to revoke the key listed above?"); |
2085 |
|
|
p = new char[strlen (inf)+1+strlen (warn)+1]; |
2086 |
|
|
sprintf (p, warn, inf); |
2087 |
|
|
free_if_alloc (inf); |
2088 |
|
|
|
2089 |
|
|
id = msg_box (dlg, p, _("Key Edit"), MB_YESNO|MB_ICONWARNING); |
2090 |
|
|
free_if_alloc (p); |
2091 |
|
|
if (id == IDNO) |
2092 |
|
|
return; |
2093 |
|
|
|
2094 |
|
|
key->internal = 1; |
2095 |
|
|
DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_KEYREVOKE, dlg, |
2096 |
|
|
key_revoke_dlg_proc, (LPARAM)key); |
2097 |
|
|
} |
2098 |
|
|
|
2099 |
|
|
|
2100 |
twoaday |
133 |
/* Dialog box procedure for the edit key dialog. */ |
2101 |
werner |
36 |
BOOL CALLBACK |
2102 |
|
|
keyedit_main_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
2103 |
|
|
{ |
2104 |
|
|
static winpt_key_t k; |
2105 |
|
|
static listview_ctrl_t lvsub = NULL, lvuid = NULL; |
2106 |
twoaday |
165 |
int cmd; |
2107 |
werner |
36 |
HWND item; |
2108 |
|
|
|
2109 |
twoaday |
193 |
switch (msg) { |
2110 |
werner |
36 |
case WM_INITDIALOG: |
2111 |
|
|
k = (winpt_key_t)lparam; |
2112 |
|
|
if (!k) |
2113 |
|
|
BUG (NULL); |
2114 |
twoaday |
170 |
do_init_cmdlist (dlg, k->key_pair); |
2115 |
werner |
36 |
lvsub = subkey_list_init (dlg, k); |
2116 |
twoaday |
193 |
if (!lvsub) |
2117 |
|
|
BUG (0); |
2118 |
werner |
36 |
lvuid = userid_list_init (dlg, k); |
2119 |
twoaday |
193 |
if (!lvuid) |
2120 |
|
|
BUG (0); |
2121 |
|
|
item = GetDlgItem (dlg, IDC_KEYEDIT_KEYLIST); |
2122 |
|
|
keyedit_subkey_proc.opaque = (void*)k; |
2123 |
werner |
36 |
keyedit_subkey_proc.dlg = dlg; |
2124 |
|
|
keyedit_subkey_proc.current = (WNDPROC)subkey_subclass_proc; |
2125 |
twoaday |
193 |
keyedit_subkey_proc.old = (WNDPROC)GetWindowLong (item, GWL_WNDPROC); |
2126 |
|
|
if (keyedit_subkey_proc.old) { |
2127 |
|
|
if( !SetWindowLong (item, GWL_WNDPROC, |
2128 |
|
|
(LONG)keyedit_subkey_proc.current)) { |
2129 |
|
|
msg_box (dlg, _("Could not set subkey window procedure."), |
2130 |
|
|
_("Key Edit"), MB_ERR); |
2131 |
|
|
BUG (0); |
2132 |
werner |
36 |
} |
2133 |
|
|
} |
2134 |
twoaday |
193 |
item = GetDlgItem (dlg, IDC_KEYEDIT_UIDLIST); |
2135 |
|
|
keyedit_uid_proc.opaque = (void*)k; |
2136 |
werner |
36 |
keyedit_uid_proc.dlg = dlg; |
2137 |
|
|
keyedit_uid_proc.current = (WNDPROC)uid_subclass_proc; |
2138 |
twoaday |
193 |
keyedit_uid_proc.old = (WNDPROC)GetWindowLong (item, GWL_WNDPROC); |
2139 |
|
|
if (keyedit_uid_proc.old) { |
2140 |
|
|
if (!SetWindowLong (item, GWL_WNDPROC, |
2141 |
|
|
(LONG)keyedit_uid_proc.current)) { |
2142 |
|
|
msg_box (dlg, _("Could not set user ID window procedure."), |
2143 |
|
|
_("Key Edit"), MB_ERR); |
2144 |
|
|
BUG (0); |
2145 |
werner |
36 |
} |
2146 |
|
|
} |
2147 |
twoaday |
170 |
if (k->ctx->revoked) { |
2148 |
werner |
36 |
EnableWindow (GetDlgItem (dlg, IDC_KEYEDIT_CMD), FALSE); |
2149 |
|
|
EnableWindow (GetDlgItem (dlg, IDOK), FALSE); |
2150 |
|
|
} |
2151 |
|
|
SetDlgItemText (dlg, IDC_KEYEDIT_CMDINF, _("Command>")); |
2152 |
twoaday |
117 |
SetDlgItemText (dlg, IDCANCEL, _("&Close")); |
2153 |
twoaday |
88 |
SetDlgItemText (dlg, IDC_KEYEDIT_HELP, _("&Help")); |
2154 |
twoaday |
208 |
SetDlgItemText (dlg, IDC_KEYEDIT_REVOKE, _("&Revoke...")); |
2155 |
|
|
if (!check_desig_rev (k)) |
2156 |
|
|
ShowWindow (GetDlgItem (dlg, IDC_KEYEDIT_REVOKE), SW_HIDE); |
2157 |
twoaday |
88 |
SetWindowText (dlg, _("Key Edit")); |
2158 |
twoaday |
170 |
SetForegroundWindow (dlg); |
2159 |
|
|
center_window (dlg, NULL); |
2160 |
werner |
36 |
return TRUE; |
2161 |
|
|
|
2162 |
|
|
case WM_DESTROY: |
2163 |
twoaday |
193 |
if (lvsub) { |
2164 |
|
|
listview_release (lvsub); |
2165 |
werner |
36 |
lvsub = NULL; |
2166 |
|
|
} |
2167 |
twoaday |
193 |
if (lvuid) { |
2168 |
|
|
listview_release (lvuid); |
2169 |
werner |
36 |
lvuid = NULL; |
2170 |
|
|
} |
2171 |
|
|
break; |
2172 |
|
|
|
2173 |
|
|
case WM_NOTIFY: |
2174 |
|
|
NMHDR * notify; |
2175 |
|
|
notify = (NMHDR *)lparam; |
2176 |
twoaday |
218 |
if (!notify || notify->idFrom != IDC_KEYEDIT_UIDLIST) |
2177 |
|
|
break; |
2178 |
|
|
if (notify->code == NM_DBLCLK) |
2179 |
werner |
36 |
do_editkey_showpref (k, dlg, lvuid); |
2180 |
twoaday |
218 |
if (notify->code == NM_RCLICK && k->key_pair) { |
2181 |
|
|
HMENU hm = LoadMenu (glob_hinst, MAKEINTRESOURCE (IDR_WINPT_KEYEDIT)); |
2182 |
|
|
HMENU popup = GetSubMenu (hm, 0); |
2183 |
|
|
POINT p; |
2184 |
|
|
|
2185 |
|
|
GetCursorPos (&p); |
2186 |
|
|
TrackPopupMenu (popup, TPM_RIGHTALIGN, p.x, p.y, 0, dlg, NULL); |
2187 |
|
|
DestroyMenu (hm); |
2188 |
|
|
DestroyMenu (popup); |
2189 |
|
|
} |
2190 |
werner |
36 |
break; |
2191 |
|
|
|
2192 |
|
|
case WM_COMMAND: |
2193 |
twoaday |
218 |
switch (LOWORD (wparam)) { |
2194 |
werner |
36 |
case IDOK: |
2195 |
twoaday |
170 |
cmd = lookup_cmd (dlg); |
2196 |
werner |
36 |
if (cmd == LB_ERR) { |
2197 |
|
|
msg_box( dlg, _("Please select a command."), _("Key Edit"), MB_INFO ); |
2198 |
|
|
return FALSE; |
2199 |
|
|
} |
2200 |
|
|
if (k->is_v3 && is_cmd_openpgp (cmd)) { |
2201 |
|
|
msg_box (dlg, _("This command cannot be used with PGP 2 (v3) keys.\n"), |
2202 |
|
|
_("Key Edit"), MB_ERR); |
2203 |
|
|
return FALSE; |
2204 |
|
|
} |
2205 |
|
|
switch (cmd) { |
2206 |
|
|
case CMD_SHOWPREF: do_editkey_showpref (k, dlg, lvuid); break; |
2207 |
|
|
case CMD_DELKEY: do_editkey_delkey (k, dlg, lvsub); break; |
2208 |
|
|
case CMD_ADDKEY: keyedit_add_subkey (k, dlg, lvsub); break; |
2209 |
|
|
case CMD_EXPIRE: do_editkey_expire (k, dlg, lvsub); break; |
2210 |
|
|
case CMD_REVKEY: do_editkey_revoke (k, dlg, lvsub); break; |
2211 |
|
|
/*case CMD_SETPREF:do_editkey_setpref( k, dlg, lvuid ); break;*/ |
2212 |
|
|
case CMD_ADDUID: keyedit_add_userid( k, dlg, lvuid ); break; |
2213 |
|
|
case CMD_ADDREVOKER: keyedit_add_revoker( k, dlg ); break; |
2214 |
|
|
case CMD_ADDPHOTO: keyedit_add_photo( k, dlg ); break; |
2215 |
|
|
case CMD_REVUID: do_editkey_revuid( k, dlg, lvuid ); break; |
2216 |
|
|
case CMD_DELUID: do_editkey_deluid( k, dlg, lvuid ); break; |
2217 |
|
|
case CMD_PASSWD: keyedit_change_passwd( k, dlg ); break; |
2218 |
|
|
case CMD_PRIMARY: do_editkey_primary( k, dlg, lvuid ); break; |
2219 |
twoaday |
165 |
case CMD_ENABLE: do_editkey_enable_disable (k, dlg, lvsub, 1); break; |
2220 |
|
|
case CMD_DISABLE: do_editkey_enable_disable (k, dlg, lvsub, 0); break; |
2221 |
twoaday |
175 |
case CMD_CHECK: do_editkey_check (k, dlg); break; |
2222 |
twoaday |
165 |
case CMD_TRUST: keyedit_change_ownertrust (k, dlg); break; |
2223 |
twoaday |
170 |
case CMD_SIGN: |
2224 |
|
|
case CMD_LSIGN: do_editkey_sign_userid (k, dlg, |
2225 |
|
|
lvuid, cmd); |
2226 |
|
|
break; |
2227 |
twoaday |
212 |
case CMD_CLEAN: do_editkey_clean (k, dlg); break; |
2228 |
|
|
case CMD_MINIMIZE: do_editkey_minimize (k, dlg); break; |
2229 |
werner |
36 |
} |
2230 |
twoaday |
218 |
break; |
2231 |
|
|
|
2232 |
werner |
36 |
case IDCANCEL: |
2233 |
|
|
EndDialog (dlg, FALSE); |
2234 |
|
|
break; |
2235 |
|
|
|
2236 |
|
|
case IDC_KEYEDIT_HELP: |
2237 |
|
|
do_show_help (dlg); |
2238 |
|
|
break; |
2239 |
twoaday |
208 |
|
2240 |
|
|
case IDC_KEYEDIT_REVOKE: |
2241 |
|
|
gen_desig_revoke_cert (k, dlg); |
2242 |
|
|
break; |
2243 |
twoaday |
218 |
|
2244 |
|
|
case ID_KEYEDIT_UID_PRIM: |
2245 |
|
|
do_editkey_primary (k, dlg, lvuid); |
2246 |
|
|
break; |
2247 |
|
|
|
2248 |
|
|
case ID_KEYEDIT_UID_DEL: |
2249 |
|
|
do_editkey_deluid (k, dlg, lvuid); |
2250 |
|
|
break; |
2251 |
|
|
|
2252 |
|
|
case ID_KEYEDIT_UID_REV: |
2253 |
|
|
do_editkey_revuid (k, dlg, lvuid); |
2254 |
|
|
break; |
2255 |
werner |
36 |
} |
2256 |
|
|
break; |
2257 |
|
|
} |
2258 |
|
|
return FALSE; |
2259 |
twoaday |
133 |
} |