1 |
twoaday |
2 |
/* wptKeyEditDlgs.cpp - GPG key edit dialogs |
2 |
twoaday |
6 |
* Copyright (C) 2002-2005 Timo Schulz |
3 |
twoaday |
2 |
* |
4 |
|
|
* This file is part of WinPT. |
5 |
|
|
* |
6 |
|
|
* WinPT is free software; you can redistribute it and/or modify |
7 |
|
|
* it under the terms of the GNU General Public License as published by |
8 |
|
|
* the Free Software Foundation; either version 2 of the License, or |
9 |
|
|
* (at your option) any later version. |
10 |
|
|
* |
11 |
|
|
* WinPT is distributed in the hope that it will be useful, |
12 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 |
|
|
* GNU General Public License for more details. |
15 |
|
|
* |
16 |
|
|
* You should have received a copy of the GNU General Public License |
17 |
|
|
* along with WinPT; if not, write to the Free Software Foundation, |
18 |
|
|
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
19 |
|
|
*/ |
20 |
|
|
|
21 |
|
|
#include <windows.h> |
22 |
|
|
#include <commctrl.h> |
23 |
|
|
#include "../resource.h" |
24 |
|
|
|
25 |
|
|
#include "wptTypes.h" |
26 |
|
|
#include "wptW32API.h" |
27 |
|
|
#include "wptVersion.h" |
28 |
|
|
#include "wptGPG.h" |
29 |
|
|
#include "wptCommonCtl.h" |
30 |
|
|
#include "wptContext.h" |
31 |
|
|
#include "wptDlgs.h" |
32 |
|
|
#include "wptNLS.h" |
33 |
|
|
#include "wptUTF8.h" |
34 |
|
|
#include "wptErrors.h" |
35 |
|
|
#include "wptKeylist.h" |
36 |
|
|
#include "wptKeyManager.h" |
37 |
|
|
#include "wptRegistry.h" |
38 |
twoaday |
23 |
#include "wptKeyEdit.h" |
39 |
twoaday |
2 |
|
40 |
|
|
enum keyedit_commands { |
41 |
|
|
CMD_ADDKEY = 0, |
42 |
|
|
CMD_ADDUID, |
43 |
|
|
CMD_ADDPHOTO, |
44 |
|
|
CMD_ADDREVOKER, |
45 |
|
|
/*CMD_FPR,*/ |
46 |
|
|
CMD_DELUID, |
47 |
|
|
CMD_DELKEY, |
48 |
|
|
CMD_DELPHOTO, |
49 |
|
|
/*CMD_DELSIG,*/ |
50 |
|
|
CMD_EXPIRE, |
51 |
twoaday |
16 |
/*CMD_PREF,*/ |
52 |
twoaday |
2 |
CMD_SHOWPREF, |
53 |
twoaday |
16 |
/*CMD_SETPREF,*/ |
54 |
twoaday |
22 |
/*CMD_UPDPREF,*/ |
55 |
twoaday |
2 |
CMD_PASSWD, |
56 |
|
|
CMD_PRIMARY, |
57 |
|
|
CMD_TRUST, |
58 |
|
|
/*CMD_REVSIG,*/ |
59 |
|
|
CMD_REVUID, |
60 |
|
|
CMD_REVKEY, |
61 |
|
|
CMD_DISABLE, |
62 |
|
|
CMD_ENABLE, |
63 |
|
|
/*CMD_SHOWPHOTO,*/ |
64 |
|
|
}; |
65 |
|
|
|
66 |
|
|
|
67 |
|
|
struct keyedit_callback_s { |
68 |
twoaday |
23 |
const char *keyid; |
69 |
twoaday |
20 |
const char *pass; |
70 |
twoaday |
2 |
listview_ctrl_t lv; |
71 |
twoaday |
20 |
void *opaque; |
72 |
twoaday |
23 |
unsigned int finished:1; |
73 |
twoaday |
2 |
}; |
74 |
|
|
typedef struct keyedit_callback_s KEYEDIT_CB; |
75 |
|
|
|
76 |
|
|
struct keygen_callback_s { |
77 |
twoaday |
20 |
int bits; |
78 |
|
|
int algo; |
79 |
|
|
u32 expire; |
80 |
|
|
char *fpr; |
81 |
twoaday |
2 |
}; |
82 |
|
|
typedef struct keygen_callback_s KEYGEN_CB; |
83 |
|
|
|
84 |
|
|
|
85 |
|
|
static subclass_s keyedit_subkey_proc; |
86 |
|
|
static subclass_s keyedit_uid_proc; |
87 |
|
|
|
88 |
twoaday |
20 |
int keygen_check_date (SYSTEMTIME *st); |
89 |
|
|
void get_userid_preflist (char **r_prefs, int * r_flags); |
90 |
twoaday |
24 |
char* get_subkey_fingerprint (const char *keyid); |
91 |
twoaday |
2 |
|
92 |
twoaday |
23 |
|
93 |
|
|
/* Associate each key with a combo box entry. |
94 |
|
|
Skip the key in @k. */ |
95 |
twoaday |
2 |
static void |
96 |
|
|
do_init_keylist (HWND dlg, winpt_key_t k) |
97 |
|
|
{ |
98 |
|
|
gpgme_keycache_t pub; |
99 |
|
|
gpgme_key_t key; |
100 |
|
|
const char * s, * kid; |
101 |
|
|
char * u; |
102 |
|
|
int i, n; |
103 |
|
|
|
104 |
|
|
pub = keycache_get_ctx (1); |
105 |
|
|
if (!pub) |
106 |
|
|
BUG (0); |
107 |
|
|
|
108 |
twoaday |
23 |
gpgme_keycache_rewind (pub); |
109 |
twoaday |
2 |
while( !gpgme_keycache_next_key( pub, 0, &key ) ) { |
110 |
twoaday |
23 |
s = key->uids->uid; |
111 |
|
|
kid = key->subkeys->keyid; |
112 |
twoaday |
2 |
if (!s || !strcmp (kid+8, k->keyid+2)) |
113 |
|
|
continue; |
114 |
|
|
u = utf8_to_wincp (s, strlen (s)); |
115 |
|
|
SendDlgItemMessage (dlg, IDC_ADDREV_KEYLIST, CB_ADDSTRING, |
116 |
|
|
0, (WPARAM)(char *)u); |
117 |
twoaday |
23 |
free (u); |
118 |
twoaday |
2 |
} |
119 |
twoaday |
23 |
gpgme_keycache_rewind (pub); |
120 |
twoaday |
2 |
n = SendDlgItemMessage( dlg, IDC_ADDREV_KEYLIST, CB_GETCOUNT, 0, 0 ); |
121 |
twoaday |
23 |
for (i = 0; i < n; i++) { |
122 |
|
|
gpgme_keycache_next_key (pub, 0, &key); |
123 |
|
|
SendDlgItemMessage (dlg, IDC_ADDREV_KEYLIST, CB_SETITEMDATA, |
124 |
|
|
(WPARAM)(int)i, (LPARAM)key); |
125 |
twoaday |
2 |
} |
126 |
twoaday |
23 |
SendDlgItemMessage (dlg, IDC_ADDREV_KEYLIST, CB_SETCURSEL, 0, 0); |
127 |
|
|
} |
128 |
twoaday |
2 |
|
129 |
|
|
|
130 |
twoaday |
23 |
/* Add a new user-id to the list view @lv. */ |
131 |
twoaday |
2 |
static void |
132 |
twoaday |
23 |
do_add_new_userid (listview_ctrl_t lv, |
133 |
|
|
const char * name, const char *email, const char * comment) |
134 |
twoaday |
2 |
{ |
135 |
|
|
char * p; |
136 |
|
|
size_t n; |
137 |
|
|
|
138 |
twoaday |
16 |
n = strlen (name) + strlen (email) + 16; |
139 |
|
|
if (comment) |
140 |
|
|
n += strlen (comment); |
141 |
twoaday |
2 |
p = new char[n+1]; |
142 |
twoaday |
16 |
if (!p) |
143 |
twoaday |
2 |
BUG( NULL ); |
144 |
twoaday |
16 |
if (comment) |
145 |
|
|
sprintf (p, "%s (%s)", name, comment); |
146 |
twoaday |
2 |
else |
147 |
twoaday |
16 |
sprintf (p, "%s", name); |
148 |
|
|
|
149 |
|
|
listview_add_item (lv, ""); |
150 |
|
|
listview_add_sub_item (lv, 0, 0, _("Ultimate" )); |
151 |
|
|
listview_add_sub_item (lv, 0, 1, p); |
152 |
|
|
listview_add_sub_item (lv, 0, 2, email && *email? email : ""); |
153 |
|
|
listview_add_sub_item (lv, 0, 3, get_key_created (time (NULL))); |
154 |
|
|
free_if_alloc (p); |
155 |
twoaday |
2 |
} /* do_add_new_userid */ |
156 |
|
|
|
157 |
|
|
|
158 |
|
|
static void |
159 |
twoaday |
23 |
do_add_new_subkey (listview_ctrl_t lv, KEYGEN_CB *keygen, unsigned int flags) |
160 |
twoaday |
2 |
{ |
161 |
|
|
char info[128], keyid[32]; |
162 |
|
|
const char * expdate, * s; |
163 |
twoaday |
12 |
int n; |
164 |
twoaday |
2 |
|
165 |
|
|
expdate = keygen->expire? get_key_expire_date (keygen->expire) : _("Never"); |
166 |
twoaday |
12 |
_snprintf (info, sizeof info-1, "%d-bit %s", |
167 |
|
|
keygen->bits, |
168 |
twoaday |
23 |
get_key_pubalgo ((gpgme_pubkey_algo_t)keygen->algo)); |
169 |
twoaday |
12 |
_snprintf (keyid, sizeof keyid-1, "0x%s", keygen->fpr+32); |
170 |
|
|
n = listview_count_items (lv, 0); |
171 |
|
|
listview_add_item_pos (lv, n); |
172 |
|
|
listview_add_sub_item (lv, n, 0, info); |
173 |
|
|
listview_add_sub_item (lv, n, 1, keyid); |
174 |
|
|
listview_add_sub_item (lv, n, 2, get_key_created (time (NULL))); |
175 |
|
|
listview_add_sub_item (lv, n, 3, expdate); |
176 |
|
|
if (flags & KM_FLAG_REVOKED) s = _("Revoked"); |
177 |
|
|
else if (flags & KM_FLAG_EXPIRED) s = _("Expired"); |
178 |
twoaday |
2 |
else s = _("OK"); |
179 |
twoaday |
12 |
listview_add_sub_item (lv, n, 4, s); |
180 |
twoaday |
2 |
} /* do_add_new_subkey */ |
181 |
|
|
|
182 |
|
|
|
183 |
twoaday |
23 |
/* Try to find the GPG edit key index which belongs to the user ID |
184 |
|
|
given by @name. If @r_inf != NULL, the info context will be returned. |
185 |
|
|
Return value: index of the user ID or -1 on error. */ |
186 |
twoaday |
2 |
static int |
187 |
twoaday |
23 |
do_find_userid (const char *keyid, const char *name, gpg_uid_info_t *r_inf) |
188 |
twoaday |
2 |
{ |
189 |
twoaday |
23 |
GpgKeyEdit *ke; |
190 |
twoaday |
2 |
gpgme_error_t err; |
191 |
twoaday |
23 |
gpg_uid_info_t inf, ui; |
192 |
|
|
int pos = -1; |
193 |
twoaday |
2 |
|
194 |
twoaday |
23 |
ke = new GpgKeyEdit (keyid); |
195 |
|
|
if (!ke) |
196 |
|
|
BUG (NULL); |
197 |
|
|
err = ke->getUseridInfo (&inf); |
198 |
|
|
delete ke; |
199 |
twoaday |
16 |
if (err) { |
200 |
twoaday |
2 |
log_box (_("user ID"), MB_ERR, _("Could not get key information for: \"%s\""), name); |
201 |
|
|
return -1; |
202 |
|
|
} |
203 |
twoaday |
23 |
|
204 |
|
|
for (ui = inf; ui; ui = ui->next) { |
205 |
|
|
if (!strcmp (ui->email, name)) { |
206 |
|
|
pos = ui->index; |
207 |
twoaday |
2 |
break; |
208 |
|
|
} |
209 |
|
|
} |
210 |
twoaday |
16 |
if (r_inf) |
211 |
|
|
*r_inf = inf; |
212 |
|
|
else |
213 |
twoaday |
23 |
gpg_uid_info_release (inf); |
214 |
twoaday |
2 |
return pos; |
215 |
twoaday |
23 |
} |
216 |
twoaday |
2 |
|
217 |
|
|
|
218 |
twoaday |
23 |
/* Dialog box procedure to add a photo. */ |
219 |
twoaday |
2 |
BOOL CALLBACK |
220 |
twoaday |
23 |
keyedit_addphoto_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
221 |
twoaday |
2 |
{ |
222 |
twoaday |
23 |
static winpt_key_t k; |
223 |
|
|
GpgKeyEdit *ke; |
224 |
|
|
gpgme_error_t ec; |
225 |
twoaday |
2 |
const char * s; |
226 |
|
|
char pwd[128], file[128]; |
227 |
|
|
int id; |
228 |
|
|
|
229 |
|
|
switch( msg ) { |
230 |
|
|
case WM_INITDIALOG: |
231 |
|
|
k = (winpt_key_t)lparam; |
232 |
|
|
if( !k ) |
233 |
|
|
BUG( NULL ); |
234 |
|
|
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.")); |
235 |
|
|
SetDlgItemText (dlg, IDC_ADDPHOTO_FILEINF, _("Pick an image to use for your photo ID.\nThe image must be a JPEG file.")); |
236 |
|
|
SetDlgItemText (dlg, IDC_ADDPHOTO_PWDINF, _("Passphrase")); |
237 |
|
|
SetForegroundWindow( dlg ); |
238 |
|
|
break; |
239 |
|
|
|
240 |
|
|
case WM_DESTROY: |
241 |
|
|
break; |
242 |
|
|
|
243 |
|
|
case WM_SYSCOMMAND: |
244 |
|
|
if( LOWORD (wparam) == SC_CLOSE ) |
245 |
|
|
EndDialog( dlg, TRUE ); |
246 |
|
|
break; |
247 |
|
|
|
248 |
|
|
case WM_COMMAND: |
249 |
|
|
switch( LOWORD( wparam ) ) { |
250 |
|
|
|
251 |
|
|
case IDC_ADDPHOTO_SELFILE: |
252 |
|
|
s = get_filename_dlg( dlg, FILE_OPEN, _("Select Image File"), _("JPEG Files (*.jpg, *.jpeg)\0*.jpg;*.jpeg\0\0"), NULL ); |
253 |
|
|
if( s && *s ) |
254 |
|
|
SetDlgItemText( dlg, IDC_ADDPHOTO_FILE, s ); |
255 |
|
|
break; |
256 |
|
|
|
257 |
|
|
case IDOK: |
258 |
|
|
if( !GetDlgItemText( dlg, IDC_ADDPHOTO_FILE, file, sizeof file-1 ) ){ |
259 |
|
|
msg_box( dlg, _("Please enter a file name."), _("Add Photo"), MB_ERR ); |
260 |
|
|
return FALSE; |
261 |
|
|
} |
262 |
|
|
if( get_file_size( file ) == 0 || get_file_size( file ) > 6144 ) { |
263 |
|
|
id = msg_box( dlg, _("The JPEG is really large.\n" |
264 |
|
|
"Are you sure you want to use it?"), |
265 |
|
|
_("Add Photo"), MB_YESNO|MB_INFO ); |
266 |
|
|
if( id == IDNO ) |
267 |
|
|
return TRUE; |
268 |
|
|
} |
269 |
|
|
if( k->is_protected ) { |
270 |
|
|
if( !GetDlgItemText( dlg, IDC_ADDPHOTO_PASS, pwd, sizeof pwd-1 ) ) { |
271 |
|
|
msg_box( dlg, _("Please enter a passphrase."), _("Add Photo"), MB_ERR ); |
272 |
|
|
return FALSE; |
273 |
|
|
} |
274 |
|
|
} |
275 |
twoaday |
23 |
ke = new GpgKeyEdit (k->keyid); |
276 |
|
|
if (!ke) |
277 |
|
|
BUG (NULL); |
278 |
|
|
|
279 |
|
|
if (k->is_protected) |
280 |
|
|
ke->setPassphrase (pwd); |
281 |
|
|
ec = ke->addPhotoid (file); |
282 |
|
|
delete ke; |
283 |
|
|
memset (pwd, 0, sizeof pwd); |
284 |
|
|
if (ec) { |
285 |
|
|
msg_box (dlg, gpgme_strerror (ec), _("Add Photo"), MB_ERR ); |
286 |
twoaday |
2 |
return FALSE; |
287 |
|
|
} |
288 |
|
|
else { |
289 |
twoaday |
19 |
k->update = 1; |
290 |
|
|
msg_box (dlg, _("Photo successfully added."), _("GnuPG Status"), MB_OK); |
291 |
twoaday |
2 |
} |
292 |
twoaday |
19 |
EndDialog (dlg, TRUE); |
293 |
twoaday |
2 |
break; |
294 |
|
|
|
295 |
|
|
case IDCANCEL: |
296 |
twoaday |
23 |
EndDialog (dlg, FALSE); |
297 |
twoaday |
2 |
break; |
298 |
|
|
} |
299 |
|
|
break; |
300 |
|
|
} |
301 |
|
|
return FALSE; |
302 |
twoaday |
23 |
} |
303 |
twoaday |
2 |
|
304 |
|
|
|
305 |
twoaday |
23 |
/* Dialog box procedure to add a designated revoker. */ |
306 |
twoaday |
2 |
BOOL CALLBACK |
307 |
|
|
keyedit_addrevoker_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
308 |
|
|
{ |
309 |
|
|
static winpt_key_t k; |
310 |
|
|
static gpgme_key_t seckey; |
311 |
twoaday |
23 |
GpgKeyEdit *ke; |
312 |
|
|
gpgme_error_t err; |
313 |
twoaday |
2 |
char uid[128], pwd[128]; |
314 |
|
|
|
315 |
|
|
|
316 |
|
|
switch( msg ) { |
317 |
|
|
case WM_INITDIALOG: |
318 |
|
|
k = (winpt_key_t)lparam; |
319 |
|
|
if( !k ) |
320 |
|
|
BUG( NULL ); |
321 |
|
|
if( get_seckey( k->keyid, &seckey ) ) |
322 |
|
|
BUG( NULL ); |
323 |
twoaday |
23 |
if (!k->is_protected) |
324 |
|
|
EnableWindow (GetDlgItem (dlg, IDC_ADDREV_PASS), FALSE); |
325 |
|
|
do_init_keylist (dlg, k); |
326 |
twoaday |
2 |
SetDlgItemText (dlg, IDC_ADDREV_INF, _("Appointing a key as designated revoker cannot be undone.")); |
327 |
|
|
SetDlgItemText (dlg, IDC_ADDREV_KEYINF, _("Public key")); |
328 |
|
|
SetDlgItemText (dlg, IDC_ADDREV_PWDINF, _("Passphrase")); |
329 |
|
|
SetForegroundWindow( dlg ); |
330 |
|
|
break; |
331 |
|
|
|
332 |
|
|
case WM_DESTROY: |
333 |
|
|
break; |
334 |
|
|
|
335 |
|
|
case WM_SYSCOMMAND: |
336 |
|
|
if( LOWORD (wparam) == SC_CLOSE ) |
337 |
|
|
EndDialog( dlg, TRUE ); |
338 |
|
|
break; |
339 |
|
|
|
340 |
|
|
case WM_COMMAND: |
341 |
|
|
switch( LOWORD( wparam ) ) { |
342 |
|
|
case IDOK: |
343 |
|
|
if( !GetDlgItemText( dlg, IDC_ADDREV_KEYLIST, uid, sizeof uid-1 ) ) { |
344 |
|
|
msg_box( dlg, _("Please select a user ID."), _("Add Revoker"), MB_ERR ); |
345 |
|
|
return FALSE; |
346 |
|
|
} |
347 |
|
|
|
348 |
|
|
if( k->is_protected ) { |
349 |
|
|
if( !GetDlgItemText( dlg, IDC_ADDREV_PASS, pwd, sizeof pwd-1 ) ) { |
350 |
|
|
msg_box( dlg, _("Please enter the passphrase."), _("Add Revoker"), MB_ERR ); |
351 |
|
|
return FALSE; |
352 |
|
|
} |
353 |
|
|
} |
354 |
twoaday |
23 |
ke = new GpgKeyEdit (k->keyid); |
355 |
|
|
if (k->is_protected) |
356 |
|
|
ke->setPassphrase (pwd); |
357 |
|
|
err = ke->addDesignatedRevoker (uid); |
358 |
|
|
delete ke; |
359 |
|
|
memset (pwd, 0, sizeof pwd); |
360 |
|
|
if (err) { |
361 |
|
|
msg_box (dlg, gpgme_strerror (err), _("Add Revoker"), MB_ERR); |
362 |
|
|
return TRUE; |
363 |
twoaday |
2 |
} |
364 |
|
|
else { |
365 |
twoaday |
19 |
k->update = 1; |
366 |
|
|
msg_box (dlg, _("Revoker successfully addded."), _("GnuPG Status"), MB_OK); |
367 |
twoaday |
2 |
} |
368 |
|
|
EndDialog( dlg, TRUE ); |
369 |
|
|
break; |
370 |
|
|
|
371 |
|
|
case IDCANCEL: |
372 |
|
|
EndDialog( dlg, FALSE ); |
373 |
|
|
break; |
374 |
|
|
} |
375 |
|
|
break; |
376 |
|
|
} |
377 |
|
|
return FALSE; |
378 |
twoaday |
23 |
} |
379 |
twoaday |
2 |
|
380 |
|
|
|
381 |
twoaday |
23 |
/* Dialog box procedure to add a new user-ID. */ |
382 |
twoaday |
2 |
BOOL CALLBACK |
383 |
twoaday |
23 |
keyedit_adduid_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
384 |
twoaday |
2 |
{ |
385 |
|
|
static KEYEDIT_CB *ctx; |
386 |
twoaday |
23 |
gpgme_error_t err; |
387 |
|
|
GpgKeyEdit *ke; |
388 |
twoaday |
2 |
char *utf8_name = NULL; |
389 |
|
|
char name[128], email[128], comment[128]; |
390 |
|
|
int rc; |
391 |
|
|
|
392 |
|
|
switch ( msg ) { |
393 |
|
|
case WM_INITDIALOG: |
394 |
|
|
ctx = (KEYEDIT_CB *)lparam; |
395 |
|
|
if( !ctx ) |
396 |
|
|
dlg_fatal_error(dlg, "Could not get dialog param!"); |
397 |
|
|
#ifndef LANG_DE |
398 |
|
|
SetWindowText( dlg, _("Add new User ID") ); |
399 |
|
|
SetDlgItemText( dlg, IDC_ADDUID_INFNAME, _("&Name") ); |
400 |
|
|
SetDlgItemText( dlg, IDC_ADDUID_INFEMAIL, _("&Email") ); |
401 |
|
|
SetDlgItemText( dlg, IDC_ADDUID_INFCOMMENT, _("&Comment") ); |
402 |
|
|
#endif |
403 |
|
|
SetForegroundWindow( dlg ); |
404 |
|
|
return FALSE; |
405 |
|
|
|
406 |
|
|
case WM_SYSCOMMAND: |
407 |
twoaday |
23 |
if (LOWORD (wparam) == SC_CLOSE) { |
408 |
twoaday |
2 |
EndDialog(dlg, TRUE); |
409 |
|
|
} |
410 |
|
|
return FALSE; |
411 |
|
|
|
412 |
|
|
case WM_COMMAND: |
413 |
|
|
switch ( LOWORD( wparam ) ) { |
414 |
|
|
case IDOK: |
415 |
|
|
rc = GetDlgItemText( dlg, IDC_ADDUID_NAME, name, sizeof name-1 ); |
416 |
twoaday |
23 |
if (!rc || rc < 5) { |
417 |
twoaday |
2 |
msg_box( dlg, _("Please enter a name (min. 5 chars.)"), _("UserID"), MB_ERR ); |
418 |
|
|
return FALSE; |
419 |
|
|
} |
420 |
twoaday |
23 |
if (strchr (name, '@')) { |
421 |
twoaday |
2 |
msg_box( dlg, _("Please enter the email address in the email field and not in the name field"), _("UserID"), MB_INFO ); |
422 |
|
|
return FALSE; |
423 |
|
|
} |
424 |
|
|
|
425 |
|
|
if( !GetDlgItemText( dlg, IDC_ADDUID_EMAIL, email, sizeof email -1 ) ) { |
426 |
|
|
msg_box( dlg, _("Please enter an email address."), _("UserID"), MB_ERR ); |
427 |
|
|
return FALSE; |
428 |
|
|
} |
429 |
twoaday |
23 |
if( !strchr( email, '@' ) || strchr (email, ' ')) { |
430 |
twoaday |
2 |
msg_box( dlg, _("Invalid email address."), _("UserID"), MB_ERR ); |
431 |
|
|
return FALSE; |
432 |
|
|
} |
433 |
|
|
|
434 |
|
|
rc = GetDlgItemText( dlg, IDC_ADDUID_COMMENT, comment, sizeof comment -1 ); |
435 |
|
|
|
436 |
twoaday |
23 |
/* XXX: something is wrong with the encoding :-( */ |
437 |
twoaday |
2 |
utf8_name = wincp_to_utf8 (name, strlen (name)); |
438 |
|
|
|
439 |
twoaday |
23 |
ke = new GpgKeyEdit (ctx->keyid); |
440 |
|
|
if (!ke) |
441 |
|
|
BUG (NULL); |
442 |
|
|
if (ctx->pass) |
443 |
|
|
ke->setPassphrase (ctx->pass); |
444 |
|
|
err = ke->addUserid (utf8_name? utf8_name : name, email, |
445 |
|
|
rc > 0? comment : NULL); |
446 |
|
|
if (err) |
447 |
|
|
msg_box (dlg, gpgme_strerror (err), _("UserID"), MB_ERR); |
448 |
|
|
else { |
449 |
|
|
msg_box (dlg, _("user ID successfully added."), _("GnuPG Status"), MB_OK); |
450 |
|
|
ctx->finished = 1; |
451 |
|
|
} |
452 |
|
|
delete ke; |
453 |
twoaday |
16 |
free (utf8_name); |
454 |
twoaday |
23 |
if (!err && ctx->lv) |
455 |
twoaday |
16 |
do_add_new_userid (ctx->lv, name, email, rc?comment : NULL); |
456 |
twoaday |
23 |
EndDialog (dlg, TRUE); |
457 |
twoaday |
2 |
return TRUE; |
458 |
|
|
|
459 |
|
|
case IDCANCEL: |
460 |
twoaday |
23 |
EndDialog (dlg, FALSE); |
461 |
twoaday |
2 |
return FALSE; |
462 |
|
|
} |
463 |
|
|
break; |
464 |
|
|
} |
465 |
|
|
|
466 |
|
|
return FALSE; |
467 |
twoaday |
23 |
} |
468 |
twoaday |
2 |
|
469 |
|
|
|
470 |
twoaday |
22 |
static int |
471 |
twoaday |
24 |
diff_time (HWND dt, SYSTEMTIME *in_exp) |
472 |
twoaday |
22 |
{ |
473 |
|
|
SYSTEMTIME exp, now; |
474 |
|
|
double e=0, n=0; |
475 |
|
|
|
476 |
twoaday |
24 |
if (in_exp) |
477 |
|
|
memcpy (&exp, in_exp, sizeof (SYSTEMTIME)); |
478 |
|
|
else |
479 |
|
|
DateTime_GetSystemtime (dt, &exp); |
480 |
twoaday |
22 |
GetSystemTime (&now); |
481 |
|
|
SystemTimeToVariantTime (&exp, &e); |
482 |
|
|
SystemTimeToVariantTime (&now, &n); |
483 |
|
|
if (n > e) |
484 |
|
|
return 0; |
485 |
|
|
return (int)(e-n); |
486 |
|
|
} |
487 |
|
|
|
488 |
|
|
|
489 |
|
|
static void |
490 |
|
|
init_keysize_box (HWND dlg, int ctlid) |
491 |
|
|
{ |
492 |
|
|
const char *sizelist[] = { |
493 |
|
|
"1024", "1536", "2048", "2560", "3072", "3854", "4096", NULL |
494 |
|
|
}; |
495 |
|
|
int i; |
496 |
|
|
for (i=0; sizelist[i] != NULL; i++) |
497 |
|
|
SendDlgItemMessage (dlg, ctlid, CB_ADDSTRING, 0, (LPARAM)(char*)sizelist[i]); |
498 |
|
|
SendDlgItemMessage (dlg, ctlid, CB_SETCURSEL, (WPARAM)2, 0); |
499 |
|
|
} |
500 |
|
|
|
501 |
|
|
static int |
502 |
|
|
get_keysize_from_box (HWND dlg, int ctlid) |
503 |
|
|
{ |
504 |
|
|
int pos; |
505 |
|
|
char buf[32]; |
506 |
|
|
|
507 |
|
|
pos = SendDlgItemMessage (dlg, ctlid, CB_GETCURSEL, 0, 0); |
508 |
|
|
if (pos == CB_ERR) |
509 |
|
|
return -1; |
510 |
|
|
SendDlgItemMessage (dlg, ctlid, CB_GETLBTEXT, pos, (LPARAM)(char*)buf); |
511 |
|
|
return atol (buf); |
512 |
|
|
} |
513 |
|
|
|
514 |
|
|
|
515 |
twoaday |
2 |
BOOL CALLBACK |
516 |
twoaday |
12 |
keyedit_addsubkey_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
517 |
twoaday |
2 |
{ |
518 |
twoaday |
22 |
static KEYEDIT_CB *ctx; |
519 |
|
|
static KEYGEN_CB *keygen; |
520 |
twoaday |
23 |
GpgKeyEdit *ke; |
521 |
|
|
gpgme_error_t err; |
522 |
twoaday |
22 |
HWND lb; |
523 |
twoaday |
2 |
int index, size, valid; |
524 |
|
|
|
525 |
twoaday |
22 |
switch (msg) { |
526 |
twoaday |
2 |
case WM_INITDIALOG: |
527 |
|
|
ctx = (KEYEDIT_CB *)lparam; |
528 |
|
|
if( !ctx ) |
529 |
|
|
dlg_fatal_error( dlg, "Could not get dialog param!" ); |
530 |
|
|
keygen = (KEYGEN_CB *)ctx->opaque; |
531 |
|
|
#ifndef LANG_DE |
532 |
twoaday |
22 |
SetWindowText (dlg, _("Add new Subkey")); |
533 |
|
|
SetDlgItemText (dlg, IDC_ADDSUBKEY_INFALGO, _("Key type")); |
534 |
|
|
SetDlgItemText (dlg, IDC_ADDSUBKEY_INFSIZE, _("Size in bits")); |
535 |
|
|
SetDlgItemText (dlg, IDC_ADDSUBKEY_INFVALID, _("Key expiration")); |
536 |
twoaday |
2 |
#endif |
537 |
twoaday |
22 |
lb = GetDlgItem (dlg, IDC_ADDSUBKEY_ALGO); |
538 |
|
|
listbox_add_string (lb, "DSA (sign only)"); |
539 |
|
|
listbox_add_string (lb, "ElGamal (encrypt only)"); |
540 |
|
|
listbox_add_string (lb, "RSA (sign only)"); |
541 |
|
|
listbox_add_string (lb, "RSA (encrypt only)"); |
542 |
|
|
CheckDlgButton (dlg, IDC_ADDSUBKEY_EXPIRE, BST_CHECKED); |
543 |
|
|
EnableWindow (GetDlgItem (dlg, IDC_ADDSUBKEY_EXPDATE), FALSE); |
544 |
|
|
init_keysize_box (dlg, IDC_ADDSUBKEY_SIZE); |
545 |
twoaday |
2 |
SetForegroundWindow( dlg ); |
546 |
|
|
return FALSE; |
547 |
|
|
|
548 |
|
|
case WM_SYSCOMMAND: |
549 |
|
|
if( LOWORD (wparam) == SC_CLOSE ) { |
550 |
|
|
EndDialog( dlg, TRUE ); |
551 |
|
|
} |
552 |
|
|
return FALSE; |
553 |
|
|
|
554 |
|
|
case WM_COMMAND: |
555 |
twoaday |
22 |
if (HIWORD (wparam) == BN_CLICKED && LOWORD (wparam) == IDC_ADDSUBKEY_EXPIRE) { |
556 |
|
|
if (IsDlgButtonChecked (dlg, IDC_ADDSUBKEY_EXPIRE)) |
557 |
|
|
EnableWindow (GetDlgItem (dlg, IDC_ADDSUBKEY_EXPDATE), FALSE); |
558 |
|
|
else |
559 |
|
|
EnableWindow (GetDlgItem (dlg, IDC_ADDSUBKEY_EXPDATE), TRUE); |
560 |
|
|
} |
561 |
|
|
if (HIWORD (wparam) == LBN_SELCHANGE && LOWORD (wparam) == IDC_ADDSUBKEY_ALGO) { |
562 |
|
|
index = SendMessage ((HWND)lparam, LB_GETCURSEL, 0, 0); |
563 |
|
|
if (index == 0) |
564 |
|
|
SendDlgItemMessage (dlg, IDC_ADDSUBKEY_SIZE, CB_SETCURSEL, 0, 0); |
565 |
|
|
} |
566 |
|
|
|
567 |
twoaday |
2 |
switch ( LOWORD(wparam) ) { |
568 |
|
|
case IDOK: |
569 |
twoaday |
22 |
lb = GetDlgItem (dlg, IDC_ADDSUBKEY_ALGO); |
570 |
twoaday |
2 |
switch (listbox_get_cursel (lb)) { |
571 |
|
|
case 0: index = 2; break; |
572 |
twoaday |
6 |
case 1: index = 4; break; |
573 |
|
|
case 2: index = 5; break; |
574 |
|
|
case 3: index = 6; break; |
575 |
twoaday |
2 |
default: |
576 |
|
|
msg_box( dlg, _("Please select one entry."), _("Add Subkey"), MB_ERR ); |
577 |
|
|
return FALSE; |
578 |
|
|
} |
579 |
twoaday |
22 |
size = get_keysize_from_box (dlg, IDC_ADDSUBKEY_SIZE); |
580 |
|
|
if (index == 2 && size != 1024) { |
581 |
twoaday |
2 |
msg_box( dlg,_("DSS uses a fixed keysize of 1024. Size changed."), _("Add Subkey"), MB_INFO ); |
582 |
|
|
size = 1024; |
583 |
|
|
} |
584 |
twoaday |
24 |
valid = diff_time (GetDlgItem (dlg, IDC_ADDSUBKEY_EXPDATE), NULL); |
585 |
twoaday |
23 |
|
586 |
twoaday |
2 |
keygen->bits = size; |
587 |
|
|
switch (index) { |
588 |
|
|
case 2: keygen->algo = GPGME_PK_DSA; break; |
589 |
twoaday |
6 |
case 4: keygen->algo = GPGME_PK_ELG_E; break; |
590 |
|
|
case 5: keygen->algo = GPGME_PK_RSA_S; break; |
591 |
|
|
case 6: keygen->algo = GPGME_PK_RSA_E; break; |
592 |
twoaday |
2 |
} |
593 |
twoaday |
22 |
if (valid > 0) |
594 |
twoaday |
2 |
keygen->expire = time (NULL) + valid*24*60*60; |
595 |
twoaday |
23 |
|
596 |
|
|
ke = new GpgKeyEdit (ctx->keyid); |
597 |
|
|
if (!ke) |
598 |
|
|
BUG (NULL); |
599 |
|
|
ke->setCallback (keygen_cb, NULL); |
600 |
|
|
if (ctx->pass) |
601 |
|
|
ke->setPassphrase (ctx->pass); |
602 |
|
|
keygen_cb_dlg_create (); |
603 |
|
|
|
604 |
|
|
err = ke->addSubkey ((gpgme_pubkey_algo_t)index, size, valid); |
605 |
twoaday |
24 |
keygen->fpr = get_subkey_fingerprint (ctx->keyid); |
606 |
twoaday |
23 |
keygen_cb_dlg_destroy (); |
607 |
|
|
keygen_cb (NULL, NULL, 0, 0, 0); /* flush */ |
608 |
|
|
if (err) |
609 |
|
|
msg_box (dlg, gpgme_strerror (err), _("Add Subkey"), MB_ERR); |
610 |
|
|
else { |
611 |
|
|
msg_box (dlg, _("Subkey successfully added."), _("GnuPG Status"), MB_OK); |
612 |
|
|
if (ctx->lv) |
613 |
twoaday |
24 |
do_add_new_subkey (ctx->lv, keygen, /*XXXk->flags*/0); |
614 |
twoaday |
23 |
ctx->finished = 1; |
615 |
|
|
} |
616 |
|
|
delete ke; |
617 |
|
|
EndDialog (dlg, TRUE); |
618 |
twoaday |
2 |
return TRUE; |
619 |
|
|
|
620 |
|
|
case IDCANCEL: |
621 |
|
|
EndDialog( dlg, FALSE ); |
622 |
|
|
return FALSE; |
623 |
|
|
} |
624 |
|
|
break; |
625 |
|
|
} |
626 |
|
|
|
627 |
|
|
return FALSE; |
628 |
|
|
} /* keyedit_addsubkey_dlg_proc */ |
629 |
|
|
|
630 |
|
|
|
631 |
|
|
BOOL |
632 |
|
|
keyedit_add_userid (winpt_key_t k, HWND dlg, listview_ctrl_t lv) |
633 |
|
|
{ |
634 |
|
|
KEYEDIT_CB cb; |
635 |
twoaday |
23 |
char *pass = NULL; |
636 |
twoaday |
2 |
int cancel = 0; |
637 |
|
|
|
638 |
twoaday |
16 |
if (!k->key_pair) { |
639 |
twoaday |
2 |
msg_box( dlg, _("There is no secret key available!"), _("Add user ID"), MB_ERR ); |
640 |
|
|
return FALSE; |
641 |
|
|
} |
642 |
|
|
|
643 |
|
|
if (k->is_protected) { |
644 |
|
|
pass = request_passphrase( _("Key Edit"), 1, &cancel ); |
645 |
twoaday |
23 |
if (cancel) |
646 |
twoaday |
2 |
return FALSE; |
647 |
|
|
} |
648 |
|
|
|
649 |
twoaday |
23 |
memset (&cb, 0, sizeof cb); |
650 |
twoaday |
2 |
cb.pass = k->is_protected? pass : NULL; |
651 |
|
|
cb.lv = lv; |
652 |
twoaday |
23 |
cb.keyid = k->keyid; |
653 |
|
|
dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_KEYEDIT_ADDUID, |
654 |
twoaday |
2 |
dlg, keyedit_adduid_dlg_proc, |
655 |
twoaday |
23 |
(LPARAM)&cb, _("Add user ID"), |
656 |
|
|
IDS_WINPT_KEYEDIT_ADDUID); |
657 |
|
|
|
658 |
|
|
if (cb.finished) |
659 |
twoaday |
19 |
k->update = 1; |
660 |
twoaday |
23 |
|
661 |
|
|
sfree_if_alloc (pass); |
662 |
twoaday |
2 |
return TRUE; |
663 |
twoaday |
23 |
} |
664 |
twoaday |
2 |
|
665 |
|
|
|
666 |
twoaday |
12 |
char* |
667 |
twoaday |
24 |
get_subkey_fingerprint (const char *keyid) |
668 |
twoaday |
12 |
{ |
669 |
|
|
static char fpr[40]; |
670 |
|
|
gpgme_error_t err; |
671 |
|
|
gpgme_key_t key, main; |
672 |
twoaday |
24 |
gpgme_ctx_t ctx; |
673 |
|
|
gpgme_subkey_t last_sk, k, new_sk; |
674 |
twoaday |
12 |
int n; |
675 |
|
|
|
676 |
twoaday |
24 |
err = gpgme_new (&ctx); |
677 |
|
|
if (err) |
678 |
|
|
return NULL; |
679 |
twoaday |
23 |
err = gpgme_get_key (ctx, keyid, &key, 0); |
680 |
twoaday |
12 |
if (err) |
681 |
|
|
return NULL; |
682 |
twoaday |
23 |
/* XXX: this is very slow and complicated */ |
683 |
twoaday |
12 |
|
684 |
twoaday |
23 |
n = count_subkeys (key); |
685 |
twoaday |
24 |
last_sk = get_nth_key (key, n-1); |
686 |
|
|
new_sk = (gpgme_subkey_t)calloc (1, sizeof *new_sk); |
687 |
|
|
if (!new_sk) |
688 |
|
|
BUG (NULL); |
689 |
|
|
memcpy (new_sk, last_sk, sizeof *last_sk); |
690 |
|
|
new_sk->fpr = strdup (last_sk->fpr); |
691 |
|
|
new_sk->keyid = strdup (last_sk->keyid); |
692 |
twoaday |
12 |
|
693 |
|
|
get_pubkey (keyid, &main); |
694 |
twoaday |
24 |
for (k=main->subkeys; k->next; k=k->next) |
695 |
|
|
; |
696 |
|
|
k->next = new_sk; |
697 |
twoaday |
12 |
|
698 |
|
|
gpgme_key_release (key); |
699 |
twoaday |
24 |
return new_sk->fpr; |
700 |
twoaday |
12 |
} |
701 |
|
|
|
702 |
|
|
|
703 |
twoaday |
2 |
BOOL |
704 |
|
|
keyedit_add_subkey (winpt_key_t k, HWND dlg, listview_ctrl_t lv) |
705 |
|
|
{ |
706 |
|
|
KEYEDIT_CB cb; |
707 |
|
|
KEYGEN_CB keygen; |
708 |
|
|
char * pass = NULL; |
709 |
|
|
int cancel = 0; |
710 |
|
|
|
711 |
twoaday |
23 |
if (!k->key_pair) { |
712 |
twoaday |
2 |
msg_box( dlg, _("There is no secret key available!"), _("Add Subkey"), MB_ERR ); |
713 |
|
|
return FALSE; |
714 |
|
|
} |
715 |
twoaday |
23 |
if (k->is_protected) { |
716 |
twoaday |
2 |
pass = request_passphrase (_("Key Edit"), 1, &cancel); |
717 |
twoaday |
23 |
if (cancel) |
718 |
twoaday |
2 |
return FALSE; |
719 |
|
|
} |
720 |
twoaday |
23 |
|
721 |
twoaday |
12 |
memset (&keygen, 0, sizeof (keygen)); |
722 |
|
|
memset (&cb, 0, sizeof (cb)); |
723 |
twoaday |
23 |
cb.keyid = k->keyid; |
724 |
twoaday |
12 |
cb.pass = k->is_protected? pass : NULL; |
725 |
twoaday |
2 |
cb.opaque = &keygen; |
726 |
twoaday |
19 |
dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_KEYEDIT_ADDSUBKEY, |
727 |
twoaday |
2 |
dlg, keyedit_addsubkey_dlg_proc, |
728 |
twoaday |
19 |
(LPARAM)&cb, _("Add new Subkey"), |
729 |
twoaday |
23 |
IDS_WINPT_KEYEDIT_ADDSUBKEY); |
730 |
|
|
if (cb.finished) |
731 |
twoaday |
19 |
k->update = 1; |
732 |
twoaday |
23 |
|
733 |
twoaday |
2 |
|
734 |
twoaday |
23 |
sfree_if_alloc (pass); |
735 |
|
|
return cb.finished? TRUE: FALSE; |
736 |
|
|
} |
737 |
twoaday |
2 |
|
738 |
twoaday |
23 |
|
739 |
twoaday |
2 |
BOOL |
740 |
twoaday |
19 |
keyedit_set_pref_keyserver (winpt_key_t k, HWND dlg) |
741 |
|
|
{ |
742 |
twoaday |
23 |
GpgKeyEdit *ke; |
743 |
twoaday |
19 |
gpgme_error_t err; |
744 |
|
|
struct URL_ctx_s *url; |
745 |
|
|
char *pass; |
746 |
|
|
|
747 |
|
|
url = (struct URL_ctx_s *)get_keyserver_URL_dlg (dlg); |
748 |
|
|
if (url->cancel == 1) { |
749 |
|
|
delete url; |
750 |
|
|
return FALSE; |
751 |
|
|
} |
752 |
|
|
|
753 |
|
|
pass = request_passphrase (_("Key Edit"), 1, &url->cancel); |
754 |
|
|
if (url->cancel) { |
755 |
|
|
delete url; |
756 |
|
|
return FALSE; |
757 |
|
|
} |
758 |
|
|
|
759 |
twoaday |
23 |
ke = new GpgKeyEdit (k->keyid); |
760 |
|
|
if (!ke) |
761 |
|
|
BUG (NULL); |
762 |
|
|
ke->setPassphrase (pass); |
763 |
|
|
err = ke->setPreferredKeyserver (0 /* XXX */, url->url); |
764 |
twoaday |
19 |
if (!err) |
765 |
|
|
msg_box (dlg, _("Preferred keyserver successfully set."), _("Key Edit"), MB_OK); |
766 |
|
|
|
767 |
twoaday |
23 |
sfree_if_alloc (pass); |
768 |
|
|
delete ke; |
769 |
twoaday |
19 |
delete url; |
770 |
|
|
return err == 0? 0 : WPTERR_GENERAL; |
771 |
|
|
} |
772 |
|
|
|
773 |
|
|
|
774 |
|
|
BOOL |
775 |
twoaday |
23 |
keyedit_add_photo (winpt_key_t k, HWND dlg) |
776 |
twoaday |
2 |
{ |
777 |
twoaday |
23 |
if (!k->key_pair) { |
778 |
twoaday |
2 |
msg_box( dlg, _("There is no secret key available!"), _("Add Photo"), MB_ERR ); |
779 |
|
|
return FALSE; |
780 |
|
|
} |
781 |
|
|
DialogBoxParam( glob_hinst, (LPCTSTR)IDD_WINPT_KEYEDIT_ADDPHOTO, dlg, |
782 |
|
|
keyedit_addphoto_dlg_proc, (LPARAM)k ); |
783 |
|
|
return TRUE; |
784 |
|
|
} /* keyedit_add_photo */ |
785 |
|
|
|
786 |
|
|
|
787 |
|
|
BOOL |
788 |
|
|
keyedit_add_revoker (winpt_key_t k, HWND dlg) |
789 |
|
|
{ |
790 |
|
|
if( !k->key_pair ) { |
791 |
|
|
msg_box( dlg, _("There is no secret key available!"), _("Add Revoker"), MB_ERR ); |
792 |
|
|
return FALSE; |
793 |
|
|
} |
794 |
twoaday |
23 |
DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_KEYEDIT_ADDREV, dlg, |
795 |
|
|
keyedit_addrevoker_dlg_proc, (LPARAM)k); |
796 |
twoaday |
2 |
return TRUE; |
797 |
|
|
} /* keyedit_add_revoker */ |
798 |
|
|
|
799 |
|
|
|
800 |
|
|
static int |
801 |
twoaday |
23 |
is_idea_protect_algo (const char * keyid) |
802 |
twoaday |
2 |
{ |
803 |
twoaday |
23 |
winpt_key_s k; |
804 |
twoaday |
24 |
const unsigned char *sym_prefs; |
805 |
twoaday |
2 |
size_t n; |
806 |
|
|
|
807 |
twoaday |
24 |
memset (&k, 0, sizeof (k)); |
808 |
twoaday |
23 |
if (winpt_get_pubkey (keyid, &k)) |
809 |
|
|
BUG (NULL); |
810 |
|
|
sym_prefs = k.ext->sym_prefs; |
811 |
twoaday |
20 |
if (!sym_prefs) |
812 |
twoaday |
2 |
return 1; /* assume that only v3 keys have no symmetric cipher preferences |
813 |
|
|
and thus IDEA is explicit. */ |
814 |
twoaday |
23 |
for (n = 0; sym_prefs[n]; n++) |
815 |
twoaday |
2 |
; |
816 |
twoaday |
23 |
if ((n == 0 || n == 1) && *sym_prefs == 0x01) |
817 |
twoaday |
2 |
return 1; |
818 |
|
|
return 0; |
819 |
|
|
} /* is_idea_protect_algo */ |
820 |
|
|
|
821 |
|
|
|
822 |
|
|
BOOL |
823 |
|
|
keyedit_change_passwd( winpt_key_t k, HWND dlg ) |
824 |
|
|
{ |
825 |
twoaday |
23 |
GpgKeyEdit *ke; |
826 |
|
|
gpgme_error_t ec; |
827 |
|
|
char *old_pass = NULL, *new_pass = NULL; |
828 |
twoaday |
2 |
int cancel = 0; |
829 |
|
|
|
830 |
|
|
if( !k->key_pair ) { |
831 |
|
|
msg_box( dlg, _("There is no secret key available!"), _("Key Edit"), MB_ERR ); |
832 |
|
|
return FALSE; |
833 |
|
|
} |
834 |
|
|
|
835 |
|
|
if( !idea_available && is_idea_protect_algo( k->keyid ) ) { |
836 |
|
|
msg_box( dlg, _("Cannot change passphrase because the key\n" |
837 |
|
|
"is protected with the IDEA encryption algorithm."), |
838 |
|
|
_("Key Edit"), MB_ERR ); |
839 |
|
|
return FALSE; |
840 |
|
|
} |
841 |
|
|
|
842 |
|
|
if( k->is_protected ) { |
843 |
|
|
old_pass = request_passphrase( _("Current (old) Passphrase"), 1, &cancel ); |
844 |
|
|
if( cancel ) |
845 |
|
|
return FALSE; |
846 |
|
|
} |
847 |
|
|
new_pass = request_passphrase( _("New Passphrase" ), 1, &cancel ); |
848 |
|
|
if( cancel ) { |
849 |
|
|
free_if_alloc( old_pass ); |
850 |
|
|
return FALSE; |
851 |
|
|
} |
852 |
|
|
|
853 |
|
|
if( is_8bit_string( new_pass ) ) { |
854 |
|
|
msg_box( dlg, _("The passphrase contains 8-bit characters.\n" |
855 |
|
|
"It is not suggested to use charset specific characters."), |
856 |
|
|
_("Key Edit"), MB_ERR ); |
857 |
|
|
free_if_alloc( old_pass ); |
858 |
|
|
free_if_alloc( new_pass ); |
859 |
|
|
return FALSE; |
860 |
|
|
} |
861 |
|
|
|
862 |
twoaday |
23 |
ke = new GpgKeyEdit (k->keyid); |
863 |
|
|
if (!ke) |
864 |
|
|
BUG (NULL); |
865 |
|
|
|
866 |
|
|
ke->setPassphrase (k->is_protected? old_pass : NULL); |
867 |
|
|
ec = ke->changePassphrase (new_pass, 0); |
868 |
twoaday |
2 |
if( ec ) |
869 |
twoaday |
23 |
msg_box (dlg, gpgme_strerror (ec), _("Change Passwd"), MB_ERR); |
870 |
twoaday |
2 |
else |
871 |
twoaday |
19 |
msg_box (dlg, _("Passphrase successfully changed."), _("GnuPG status"), MB_OK); |
872 |
twoaday |
23 |
sfree_if_alloc (old_pass); |
873 |
|
|
sfree_if_alloc (new_pass); |
874 |
|
|
delete ke; |
875 |
twoaday |
2 |
return TRUE; |
876 |
twoaday |
23 |
} |
877 |
twoaday |
2 |
|
878 |
|
|
|
879 |
|
|
listview_ctrl_t |
880 |
|
|
subkey_list_init( HWND dlg, winpt_key_t k ) |
881 |
|
|
{ |
882 |
|
|
LV_ITEM lvi; |
883 |
|
|
gpgme_key_t key; |
884 |
twoaday |
23 |
gpgme_subkey_t sub; |
885 |
twoaday |
2 |
struct listview_column_s cols[] = { |
886 |
|
|
{0, 80, (char *)_("Description")}, |
887 |
|
|
{1, 78, (char *)_("Key ID")}, |
888 |
|
|
{2, 66, (char *)_("Creation")}, |
889 |
|
|
{3, 66, (char *)_("Expires")}, |
890 |
|
|
{4, 64, (char *)_("Status")}, |
891 |
|
|
{5, 16, "C"/*ertify*/}, |
892 |
|
|
{6, 16, "S"/*ign*/}, |
893 |
|
|
{7, 16, "E"/*ncrypt*/}, |
894 |
|
|
{8, 16, "A"/*uth*/}, |
895 |
|
|
{0, 0, 0} |
896 |
|
|
}; |
897 |
|
|
listview_ctrl_t lv; |
898 |
|
|
char buf[256], tmp[128]; |
899 |
|
|
const char *t; |
900 |
twoaday |
24 |
int nkeys = 0, rc = 0, i, bits; |
901 |
twoaday |
2 |
|
902 |
|
|
if( get_pubkey( k->keyid, &key ) ) { |
903 |
|
|
msg_box( dlg, _("Could not find key."), _("Key Edit"), MB_ERR ); |
904 |
|
|
return NULL; |
905 |
|
|
} |
906 |
twoaday |
23 |
nkeys = count_subkeys (key); |
907 |
twoaday |
2 |
if( !nkeys ) { |
908 |
|
|
msg_box( dlg, _("No subkey(s) found."), _("Key Edit"), MB_ERR ); |
909 |
|
|
return NULL; |
910 |
|
|
} |
911 |
|
|
|
912 |
|
|
rc = listview_new( &lv ); |
913 |
|
|
if( rc ) |
914 |
|
|
BUG( dlg ); |
915 |
|
|
|
916 |
|
|
lv->ctrl = GetDlgItem( dlg, IDC_KEYEDIT_KEYLIST ); |
917 |
|
|
for( i = 0; cols[i].fieldname != NULL; i++ ) |
918 |
|
|
listview_add_column( lv, &cols[i] ); |
919 |
|
|
|
920 |
|
|
for( i = 0; i < nkeys; i++ ) { |
921 |
|
|
listview_add_item( lv, "" ); |
922 |
|
|
listview_add_sub_item( lv, 0, 1, "" ); |
923 |
|
|
memset( &lvi, 0, sizeof lvi ); |
924 |
|
|
lvi.mask = LVIF_PARAM; |
925 |
|
|
lvi.lParam = (LPARAM )key; |
926 |
|
|
if( ListView_SetItem( lv->ctrl, &lvi ) == FALSE ) |
927 |
|
|
return NULL; |
928 |
|
|
} |
929 |
|
|
|
930 |
|
|
listview_set_ext_style( lv ); |
931 |
twoaday |
23 |
for( i = 0, sub = key->subkeys; i < nkeys; i++, sub = sub->next ) { |
932 |
twoaday |
2 |
memset( buf, 0, sizeof buf ); |
933 |
|
|
|
934 |
twoaday |
23 |
bits = sub->length; |
935 |
twoaday |
2 |
_snprintf( tmp, sizeof tmp-1, "%d-bit ", bits ); |
936 |
|
|
strcat( buf, tmp ); |
937 |
|
|
|
938 |
twoaday |
24 |
_snprintf( tmp, sizeof tmp-1, "%s", get_key_pubalgo (sub->pubkey_algo)); |
939 |
twoaday |
2 |
strcat( buf, tmp ); |
940 |
|
|
|
941 |
|
|
listview_add_sub_item( lv, i, 0, buf ); |
942 |
twoaday |
24 |
t = sub->keyid; |
943 |
twoaday |
2 |
if( !t ) |
944 |
|
|
t = "DEADBEEFDEADBEEF"; |
945 |
|
|
_snprintf( tmp, sizeof tmp-1, "0x%s", t+8 ); |
946 |
|
|
listview_add_sub_item( lv, i, 1, tmp ); |
947 |
|
|
|
948 |
twoaday |
24 |
t = get_key_created (sub->timestamp); |
949 |
twoaday |
2 |
if( !t ) |
950 |
|
|
t = "????-??-??"; |
951 |
|
|
listview_add_sub_item( lv, i, 2, t ); |
952 |
|
|
|
953 |
twoaday |
24 |
if( sub->expires ) { |
954 |
|
|
t = get_key_created (sub->expires); |
955 |
twoaday |
2 |
listview_add_sub_item( lv, i, 3, t ); |
956 |
|
|
} |
957 |
|
|
else |
958 |
|
|
listview_add_sub_item( lv, i, 3, _("Never") ); |
959 |
|
|
|
960 |
twoaday |
24 |
if( sub->expired ) |
961 |
twoaday |
2 |
t = _("Expired"); |
962 |
twoaday |
24 |
else if( sub->revoked ) |
963 |
twoaday |
2 |
t = _("Revoked"); |
964 |
|
|
else |
965 |
|
|
t = _("OK"); |
966 |
|
|
listview_add_sub_item( lv, i, 4, t ); |
967 |
|
|
|
968 |
twoaday |
24 |
if (sub->can_certify) t = "*"; else t = ""; |
969 |
|
|
listview_add_sub_item (lv, i, 5, t); |
970 |
|
|
if (sub->can_sign) t = "*"; else t = ""; |
971 |
twoaday |
2 |
listview_add_sub_item( lv, i, 6, t ); |
972 |
twoaday |
24 |
if (sub->can_encrypt) t = "*"; else t = ""; |
973 |
twoaday |
2 |
listview_add_sub_item( lv, i, 7, t ); |
974 |
twoaday |
24 |
if (sub->can_authenticate) t = "*"; else t = ""; |
975 |
twoaday |
2 |
listview_add_sub_item (lv, i, 8, t); |
976 |
|
|
} |
977 |
|
|
return lv; |
978 |
|
|
} /* subkey_list_init */ |
979 |
|
|
|
980 |
|
|
|
981 |
|
|
static listview_ctrl_t |
982 |
|
|
userid_list_init (HWND dlg, winpt_key_t k) |
983 |
|
|
{ |
984 |
|
|
listview_ctrl_t lv = NULL; |
985 |
|
|
gpgme_key_t key; |
986 |
twoaday |
24 |
gpgme_user_id_t u; |
987 |
twoaday |
2 |
int nuids = 0, rc, j, u_attr; |
988 |
|
|
struct listview_column_s cols[] = { |
989 |
|
|
{0, 72, (char *)_("Validity")}, |
990 |
twoaday |
20 |
{1, 150, (char *)_("Name")}, |
991 |
|
|
{2, 110, (char *)_("Email")}, |
992 |
twoaday |
16 |
{3, 76, (char *)_("Creation")}, |
993 |
twoaday |
2 |
{0, 0, 0} |
994 |
|
|
}; |
995 |
|
|
const char *attr; |
996 |
|
|
|
997 |
twoaday |
16 |
if (get_pubkey( k->keyid, &key)) { |
998 |
twoaday |
2 |
msg_box( dlg, _("Could not find key."), _("Key Edit"), MB_ERR ); |
999 |
|
|
return NULL; |
1000 |
|
|
} |
1001 |
twoaday |
23 |
|
1002 |
|
|
nuids = count_userids (key); |
1003 |
twoaday |
16 |
if (!nuids) { |
1004 |
|
|
msg_box (dlg, _("No user ID(s) found."), _("Key Edit"), MB_ERR); |
1005 |
twoaday |
2 |
return NULL; |
1006 |
|
|
} |
1007 |
|
|
|
1008 |
twoaday |
16 |
rc = listview_new (&lv); |
1009 |
twoaday |
2 |
if( rc ) |
1010 |
|
|
BUG( dlg ); |
1011 |
|
|
lv->ctrl = GetDlgItem( dlg, IDC_KEYEDIT_UIDLIST ); |
1012 |
|
|
for( j = 0; cols[j].fieldname != NULL; j++ ) |
1013 |
|
|
listview_add_column( lv, &cols[j] ); |
1014 |
|
|
|
1015 |
|
|
for( j = 0; j < nuids; j++ ) { |
1016 |
|
|
listview_add_item( lv, " " ); |
1017 |
|
|
listview_add_sub_item( lv, 0, 1, " " ); |
1018 |
|
|
} |
1019 |
|
|
|
1020 |
|
|
listview_set_ext_style (lv); |
1021 |
twoaday |
24 |
for (j = 0, u=key->uids; j < nuids; u=u->next, j++) { |
1022 |
|
|
if (u->revoked) |
1023 |
twoaday |
2 |
attr = _("Revoked"); |
1024 |
|
|
else { |
1025 |
twoaday |
24 |
u_attr = (int)u->validity; |
1026 |
|
|
attr = get_key_trust2 (NULL, u_attr, 0, 0); |
1027 |
twoaday |
2 |
} |
1028 |
|
|
listview_add_sub_item( lv, j, 0, (char *)attr ); |
1029 |
|
|
|
1030 |
twoaday |
16 |
/* XXX: add comment if available */ |
1031 |
twoaday |
24 |
attr = u->name; |
1032 |
twoaday |
16 |
if (attr) { |
1033 |
twoaday |
2 |
char * uid = utf8_to_wincp (attr, strlen (attr)); |
1034 |
|
|
if (uid) { |
1035 |
|
|
listview_add_sub_item( lv, j, 1, uid ); |
1036 |
|
|
free( uid ); |
1037 |
|
|
} |
1038 |
|
|
} |
1039 |
|
|
else |
1040 |
|
|
listview_add_sub_item( lv, j, 1, _("Invalid user ID") ); |
1041 |
twoaday |
24 |
attr = u->email; |
1042 |
twoaday |
16 |
if (attr) |
1043 |
|
|
listview_add_sub_item (lv, j, 2, attr); |
1044 |
twoaday |
24 |
u_attr = 0; /* XXX: gpgme user-ids do not store a timestamp. */ |
1045 |
twoaday |
2 |
if (u_attr) |
1046 |
twoaday |
16 |
listview_add_sub_item (lv, j, 3, get_key_created (u_attr)); |
1047 |
twoaday |
2 |
} |
1048 |
|
|
if( !k->key_pair ) { |
1049 |
|
|
CheckDlgButton( dlg, IDC_KEYUID_ADD, BST_INDETERMINATE ); |
1050 |
|
|
CheckDlgButton( dlg, IDC_KEYUID_REVOKE, BST_INDETERMINATE ); |
1051 |
|
|
} |
1052 |
|
|
return lv; |
1053 |
|
|
} /* userid_list_init */ |
1054 |
|
|
|
1055 |
|
|
|
1056 |
|
|
static void |
1057 |
|
|
do_init_cmdlist( HWND dlg ) |
1058 |
|
|
{ |
1059 |
|
|
const char *cmdlist[] = { |
1060 |
|
|
"ADDKEY", |
1061 |
|
|
"ADDUID", |
1062 |
|
|
"ADDPHOTO", |
1063 |
|
|
"ADDREVOKER", |
1064 |
|
|
/*"FPR",*/ |
1065 |
|
|
"DELUID", |
1066 |
|
|
"DELKEY", |
1067 |
|
|
"DELPHOTO", |
1068 |
|
|
/*"DELSIG",*/ |
1069 |
|
|
"EXPIRE", |
1070 |
twoaday |
16 |
/*"PREF",*/ |
1071 |
twoaday |
2 |
"SHOWPREF", |
1072 |
twoaday |
16 |
/*"SETPREF",*/ |
1073 |
twoaday |
2 |
"PASSWD", |
1074 |
|
|
"PRIMARY", |
1075 |
|
|
"TRUST", |
1076 |
|
|
/*"REVSIG",*/ |
1077 |
|
|
"REVUID", |
1078 |
|
|
"REVKEY", |
1079 |
|
|
"DISABLE", |
1080 |
|
|
"ENABLE", |
1081 |
|
|
"SHOWPHOTO", |
1082 |
|
|
NULL |
1083 |
|
|
}; |
1084 |
|
|
const char * s; |
1085 |
|
|
int i = 0; |
1086 |
|
|
|
1087 |
|
|
for( i = 0; (s=cmdlist[i]); i++ ) { |
1088 |
|
|
SendDlgItemMessage( dlg, IDC_KEYEDIT_CMD, CB_ADDSTRING, 0, |
1089 |
|
|
(LPARAM)(char *)s ); |
1090 |
|
|
} |
1091 |
|
|
SendDlgItemMessage( dlg, IDC_KEYEDIT_CMD, CB_SETCURSEL, 0, 0 ); |
1092 |
|
|
} /* do_init_cmdlist */ |
1093 |
|
|
|
1094 |
|
|
|
1095 |
|
|
static int |
1096 |
|
|
is_cmd_openpgp( int cmdid ) |
1097 |
|
|
{ |
1098 |
|
|
switch( cmdid ) { |
1099 |
|
|
case CMD_ADDKEY: |
1100 |
|
|
case CMD_ADDPHOTO: |
1101 |
|
|
case CMD_ADDREVOKER: |
1102 |
|
|
case CMD_DELPHOTO: |
1103 |
|
|
/*case CMD_SHOWPHOTO:*/ |
1104 |
twoaday |
22 |
/*case CMD_SETPREF:*/ |
1105 |
twoaday |
2 |
return 1; |
1106 |
|
|
} |
1107 |
|
|
return 0; |
1108 |
|
|
} /* is_cmd_openpgp */ |
1109 |
|
|
|
1110 |
|
|
|
1111 |
|
|
static void |
1112 |
|
|
do_show_help( HWND dlg ) |
1113 |
|
|
{ |
1114 |
|
|
char helptext[2048]; |
1115 |
|
|
|
1116 |
|
|
_snprintf( helptext, sizeof helptext-1, |
1117 |
|
|
_(/*"FPR \t\tshow fingerprint\r\n"*/ |
1118 |
|
|
"ADDUID \t\tadd a user ID\r\n" |
1119 |
|
|
"ADDPHOTO \t\tadd a photo ID\r\n" |
1120 |
|
|
"DELUID \t\tdelete a user ID\r\n" |
1121 |
|
|
"ADDKEY \t\tadd a secondard key\r\n" |
1122 |
|
|
"DELKEY \t\tdelete a secondary key\r\n" |
1123 |
|
|
"ADDREVOKER\t\tadd a revocation key\r\n" |
1124 |
|
|
/*"DELSIG \t\tdelete signatures\r\n"*/ |
1125 |
|
|
"EXPIRE \t\tchange the expire date\r\n" |
1126 |
|
|
/*"PREF \t\tlist preferences (expert)\r\n" |
1127 |
|
|
"SHOWPREF \t\tlist preferences (verbose)\r\n" |
1128 |
|
|
"SETPREF \t\tset preference list\r\n"*/ |
1129 |
|
|
"UPDPREF \t\tupdated preferences\r\n" |
1130 |
|
|
"PASSWD \t\tchange the passphrase\r\n" |
1131 |
|
|
"PRIMARY \t\tflag user ID as primary\r\n" |
1132 |
|
|
"TRUST \t\tchange the ownertrust\r\n" |
1133 |
|
|
/*"REVSIG \t\trevoke signatures\r\n"*/ |
1134 |
|
|
"REVUID \t\trevoke a user ID\r\n" |
1135 |
|
|
"REVKEY \t\trevoke a secondary key\r\n" |
1136 |
|
|
"DISABLE \t\tdisable a key\r\n" |
1137 |
|
|
"ENABLE \t\tenable a key\r\n" |
1138 |
|
|
/*"SHOWPHOTO \t\tshow photo ID\r\n"*/) ); |
1139 |
|
|
msg_box( dlg, helptext, _("Key Edit Help"), MB_OK ); |
1140 |
|
|
} /* do_show_help */ |
1141 |
|
|
|
1142 |
|
|
|
1143 |
|
|
static int |
1144 |
twoaday |
19 |
do_editkey_delkey (winpt_key_t k, HWND dlg, listview_ctrl_t lv) |
1145 |
twoaday |
2 |
{ |
1146 |
twoaday |
24 |
gpgme_error_t err; |
1147 |
|
|
GpgKeyEdit *ke; |
1148 |
twoaday |
2 |
int j, id; |
1149 |
|
|
char tmp[64]; |
1150 |
|
|
|
1151 |
twoaday |
19 |
if (!k->key_pair) |
1152 |
|
|
return FALSE; /* XXX: shall we allow to modify non-secret keys?? */ |
1153 |
|
|
|
1154 |
twoaday |
2 |
if( listview_count_items( lv, 0 ) == 1 ) { |
1155 |
|
|
msg_box( dlg, _("Primary key can not be deleted!"), _("Key Edit"), MB_ERR); |
1156 |
|
|
return FALSE; |
1157 |
|
|
} |
1158 |
|
|
if( (j = listview_get_curr_pos( lv )) == -1 ) { |
1159 |
|
|
msg_box( dlg, _("Please select a key."), _("Key Edit"), MB_ERR ); |
1160 |
|
|
return FALSE; |
1161 |
|
|
} |
1162 |
|
|
if( j == 0 ) { |
1163 |
|
|
msg_box( dlg, _("Primary subkey can not be deleted!"), _("Key Edit"), MB_ERR ); |
1164 |
|
|
return FALSE; |
1165 |
|
|
} |
1166 |
|
|
|
1167 |
|
|
listview_get_item_text( lv, j, 0, tmp, sizeof tmp -1 ); |
1168 |
|
|
id = log_box( _("Key Edit"), MB_YESNO|MB_ICONWARNING, |
1169 |
|
|
_("\"Subkey %s.\"\n\n" |
1170 |
|
|
"Anything encrypted to the selected subkey will no longer\n" |
1171 |
|
|
"be able to be decrypted.\n\n" |
1172 |
|
|
"Do you really want to delete this subkey?"), tmp ); |
1173 |
|
|
if( id == IDNO ) |
1174 |
|
|
return FALSE; |
1175 |
|
|
|
1176 |
twoaday |
24 |
ke = new GpgKeyEdit (k->keyid); |
1177 |
|
|
if (!ke) |
1178 |
|
|
BUG (NULL); |
1179 |
|
|
err = ke->delKey (j); |
1180 |
|
|
if (err) |
1181 |
|
|
msg_box (dlg, gpgme_strerror (err), _("Delete Subkey"), MB_ERR); |
1182 |
twoaday |
2 |
else { |
1183 |
twoaday |
24 |
listview_del_item (lv, j); |
1184 |
twoaday |
19 |
k->update = 1; |
1185 |
twoaday |
24 |
status_box (dlg, _("Subkey successfully deleted."), _("GnuPG status")); |
1186 |
twoaday |
2 |
} |
1187 |
twoaday |
24 |
delete ke; |
1188 |
|
|
return err? FALSE : TRUE; |
1189 |
twoaday |
2 |
} /* do_editkey_delkey */ |
1190 |
|
|
|
1191 |
|
|
|
1192 |
|
|
static int |
1193 |
|
|
do_editkey_expire( winpt_key_t k, HWND dlg, listview_ctrl_t lv ) |
1194 |
|
|
{ |
1195 |
twoaday |
24 |
gpgme_error_t err; |
1196 |
|
|
GpgKeyEdit *ke; |
1197 |
twoaday |
2 |
date_s udd = {0}; |
1198 |
|
|
char buf[256], * pass = NULL; |
1199 |
|
|
int j, cancel = 0; |
1200 |
|
|
|
1201 |
|
|
if( !k->key_pair ) { |
1202 |
|
|
msg_box( dlg, _("There is no secret key available!"), _("Key Edit"), MB_ERR ); |
1203 |
|
|
return FALSE; |
1204 |
|
|
} |
1205 |
|
|
if ( (j = listview_get_curr_pos( lv )) == -1 ) { |
1206 |
|
|
msg_box( dlg, _("Please select a key."), _("Key Edit"), MB_ERR ); |
1207 |
|
|
return FALSE; |
1208 |
|
|
} |
1209 |
|
|
|
1210 |
|
|
listview_get_item_text( lv, j, 3, buf, sizeof buf -1 ); |
1211 |
|
|
if( !strcmp( buf, _("Expired") ) ) { |
1212 |
|
|
msg_box( dlg, _("Key already expired!"), _("Key Edit"), MB_ERR ); |
1213 |
|
|
return FALSE; |
1214 |
|
|
} |
1215 |
|
|
memset( &udd, 0, sizeof udd ); |
1216 |
|
|
udd.text = _("Key Expiration Date"); |
1217 |
|
|
dialog_box_param( glob_hinst, (LPCSTR)IDD_WINPT_DATE, dlg, |
1218 |
|
|
date_dlg_proc, (LPARAM)&udd, |
1219 |
|
|
_("Key Expiration Date"), IDS_WINPT_DATE ); |
1220 |
|
|
if( udd.cancel == 1 ) |
1221 |
|
|
return FALSE; |
1222 |
|
|
if( !keygen_check_date( &udd.st ) ) { |
1223 |
|
|
msg_box( dlg, _("The date you have chosen lies in the past."), _("Key Edit"), MB_ERR ); |
1224 |
|
|
return FALSE; |
1225 |
|
|
} |
1226 |
|
|
if( k->is_protected ) { |
1227 |
|
|
pass = request_passphrase (_("Key Edit"), 1, &cancel ); |
1228 |
|
|
if( cancel ) |
1229 |
|
|
return FALSE; |
1230 |
|
|
} |
1231 |
twoaday |
24 |
|
1232 |
|
|
ke = new GpgKeyEdit (k->keyid); |
1233 |
|
|
if (!ke) |
1234 |
|
|
BUG (NULL); |
1235 |
|
|
if (k->is_protected) |
1236 |
|
|
ke->setPassphrase (pass); |
1237 |
|
|
err = ke->setKeyExpireDate (j, diff_time (NULL, &udd.st)); |
1238 |
|
|
if (err) |
1239 |
|
|
msg_box (dlg, gpgme_strerror (err), _("Expire Subkey"), MB_ERR); |
1240 |
twoaday |
2 |
else { |
1241 |
twoaday |
24 |
_snprintf( buf, sizeof buf - 1, "%04d-%02d-%02d", |
1242 |
|
|
udd.st.wYear, udd.st.wMonth, udd.st.wDay ); |
1243 |
twoaday |
2 |
listview_add_sub_item( lv, j, 3, buf ); |
1244 |
twoaday |
19 |
k->update = 1; |
1245 |
twoaday |
2 |
msg_box( dlg, _("Subkey expire date successfully set."), _("GnuPG status"), MB_OK ); |
1246 |
|
|
} |
1247 |
twoaday |
24 |
sfree_if_alloc (pass); |
1248 |
|
|
delete ke; |
1249 |
twoaday |
2 |
return TRUE; |
1250 |
|
|
} /* do_editkey_expire */ |
1251 |
|
|
|
1252 |
|
|
|
1253 |
|
|
static int |
1254 |
|
|
do_editkey_revoke( winpt_key_t k, HWND dlg, listview_ctrl_t lv ) |
1255 |
|
|
{ |
1256 |
twoaday |
24 |
gpgme_error_t err; |
1257 |
|
|
GpgKeyEdit *ke; |
1258 |
twoaday |
2 |
char buf[256], * pass = NULL; |
1259 |
|
|
int j, cancel = 0; |
1260 |
|
|
|
1261 |
|
|
if( !k->key_pair ) { |
1262 |
|
|
msg_box( dlg, _("There is no secret key available!"), _("Key Edit"), MB_ERR ); |
1263 |
|
|
return FALSE; |
1264 |
|
|
} |
1265 |
|
|
|
1266 |
|
|
if( (j = listview_get_curr_pos( lv )) == -1 ) { |
1267 |
|
|
msg_box( dlg, _("Please select a key."), _("Key Edit"), MB_ERR ); |
1268 |
|
|
return FALSE; |
1269 |
|
|
} |
1270 |
|
|
else if( listview_count_items( lv, 0 ) == 1 ) { |
1271 |
|
|
msg_box( dlg, _("No subkeys were found, if you want to revoke the\n" |
1272 |
|
|
"whole key, please use the Key Manager command directly.\n\n" |
1273 |
|
|
"This command is only available to revoke single subkeys"), |
1274 |
|
|
_("Key Edit"), MB_INFO ); |
1275 |
|
|
return FALSE; |
1276 |
|
|
} |
1277 |
|
|
|
1278 |
|
|
listview_get_item_text( lv, j, 3, buf, sizeof buf-1 ); |
1279 |
|
|
if( !strcmp( buf, _("Revoked") ) ) { |
1280 |
|
|
msg_box( dlg, _("Key already revoked."), _("Key Edit"), MB_ERR ); |
1281 |
|
|
return FALSE; |
1282 |
|
|
} |
1283 |
|
|
|
1284 |
|
|
if( k->is_protected ) { |
1285 |
|
|
pass = request_passphrase (_("Key Edit"), 1, &cancel); |
1286 |
|
|
if( cancel ) |
1287 |
|
|
return FALSE; |
1288 |
|
|
} |
1289 |
twoaday |
24 |
|
1290 |
|
|
ke = new GpgKeyEdit (k->keyid); |
1291 |
|
|
if (!ke) |
1292 |
|
|
BUG (NULL); |
1293 |
|
|
if (k->is_protected) |
1294 |
|
|
ke->setPassphrase (pass); |
1295 |
|
|
err = ke->revokeKey (j, NULL); |
1296 |
|
|
if (err) |
1297 |
|
|
msg_box( dlg, gpgme_strerror (err), _("Revoke Subkey"), MB_ERR); |
1298 |
twoaday |
2 |
else { |
1299 |
|
|
listview_add_sub_item( lv, j, 5, _("Revoked") ); |
1300 |
twoaday |
19 |
k->update = 1; |
1301 |
twoaday |
2 |
msg_box( dlg, _("Subkey successfully revoked."), _("GnuPG Status"), MB_OK ); |
1302 |
|
|
} |
1303 |
twoaday |
24 |
sfree_if_alloc( pass ); |
1304 |
|
|
delete ke; |
1305 |
twoaday |
2 |
return TRUE; |
1306 |
|
|
} /* do_editkey_revoke */ |
1307 |
|
|
|
1308 |
|
|
|
1309 |
|
|
int |
1310 |
twoaday |
16 |
do_editkey_revuid (winpt_key_t k, HWND dlg, listview_ctrl_t lv) |
1311 |
twoaday |
2 |
{ |
1312 |
twoaday |
24 |
gpgme_error_t err; |
1313 |
|
|
GpgKeyEdit *ke; |
1314 |
twoaday |
2 |
char buf[256], t[512], * pass; |
1315 |
|
|
int cancel = 0, id = 0, j; |
1316 |
|
|
|
1317 |
|
|
if( !k->key_pair ) { |
1318 |
|
|
msg_box( dlg, _("There is no secret key available!"), _("Revoke user ID"), MB_ERR ); |
1319 |
|
|
return FALSE; |
1320 |
|
|
} |
1321 |
|
|
|
1322 |
|
|
if( listview_count_items( lv, 0 ) == 1 ) { |
1323 |
|
|
msg_box( dlg, _("Key has only one user ID."), _("Key Edit"), MB_ERR ); |
1324 |
|
|
return FALSE; |
1325 |
|
|
} |
1326 |
|
|
|
1327 |
|
|
if( (j = listview_get_curr_pos( lv )) == -1 ) { |
1328 |
|
|
msg_box( dlg, _("Please select a user ID."), _("Key Edit"), MB_ERR ); |
1329 |
|
|
return FALSE; |
1330 |
|
|
} |
1331 |
|
|
|
1332 |
|
|
listview_get_item_text( lv, j, 0, buf, sizeof buf - 1 ); |
1333 |
|
|
if( strstr( buf, _("Revoked") ) ) { |
1334 |
|
|
msg_box( dlg, _("This user ID has been already revoked."), _("Key Edit"), MB_INFO ); |
1335 |
|
|
return FALSE; |
1336 |
|
|
} |
1337 |
|
|
|
1338 |
|
|
listview_get_item_text( lv, j, 1, buf, sizeof buf -1 ); |
1339 |
|
|
_snprintf( t, sizeof t -1, _("user ID \"%s\".\n\n" |
1340 |
|
|
"Do you really want to revoke this user ID?"), buf ); |
1341 |
twoaday |
16 |
if( msg_box( dlg, t, _("Key Edit"), MB_WARN_ASK) == IDNO ) |
1342 |
twoaday |
2 |
return FALSE; |
1343 |
|
|
if( k->is_protected ) { |
1344 |
|
|
pass = request_passphrase (_("Key Edit"), 1, &cancel); |
1345 |
|
|
if( cancel ) |
1346 |
|
|
return FALSE; |
1347 |
|
|
} |
1348 |
twoaday |
16 |
id = do_find_userid (k->keyid, buf, NULL); |
1349 |
|
|
if (id == -1) |
1350 |
|
|
BUG (dlg); |
1351 |
twoaday |
24 |
|
1352 |
|
|
ke = new GpgKeyEdit (k->keyid); |
1353 |
|
|
if (!ke) |
1354 |
|
|
BUG (NULL); |
1355 |
|
|
if (k->is_protected) |
1356 |
|
|
ke->setPassphrase (pass); |
1357 |
|
|
err = ke->revokeSignature (id, 0); |
1358 |
|
|
if (err) |
1359 |
|
|
msg_box (dlg, gpgme_strerror (err), _("Revoke Signature"), MB_ERR); |
1360 |
twoaday |
2 |
else { |
1361 |
twoaday |
16 |
listview_add_sub_item (lv, j, 0, _("Revoked")); |
1362 |
twoaday |
19 |
k->update = 1; |
1363 |
twoaday |
16 |
status_box (dlg, _("User ID successfully revoked"), _("GnuPG Status")); |
1364 |
twoaday |
2 |
} |
1365 |
twoaday |
23 |
sfree_if_alloc (pass); |
1366 |
twoaday |
24 |
delete ke; |
1367 |
|
|
return err? FALSE : TRUE; |
1368 |
twoaday |
2 |
} /* do_editkey_revuid */ |
1369 |
|
|
|
1370 |
|
|
|
1371 |
|
|
static int |
1372 |
|
|
do_editkey_setpref (winpt_key_t k, HWND dlg, listview_ctrl_t lv) |
1373 |
|
|
{ |
1374 |
|
|
gpgme_error_t rc; |
1375 |
twoaday |
24 |
GpgKeyEdit *ke; |
1376 |
twoaday |
2 |
char buf[256], * pass = NULL, * prefs; |
1377 |
|
|
int j, id, cancel=0, flags=0; |
1378 |
|
|
|
1379 |
|
|
if ((j = listview_get_curr_pos (lv)) == -1) { |
1380 |
|
|
msg_box (dlg, _("Please select a user ID."), _("Key Edit"), MB_ERR); |
1381 |
|
|
return FALSE; |
1382 |
|
|
} |
1383 |
|
|
listview_get_item_text (lv, j, 1, buf, sizeof buf-1); |
1384 |
twoaday |
16 |
id = do_find_userid (k->keyid, buf, NULL); |
1385 |
twoaday |
2 |
if (id == -1) |
1386 |
|
|
BUG (dlg); |
1387 |
|
|
if (k->is_protected) { |
1388 |
|
|
pass = request_passphrase (_("Key Edit"), 1, &cancel); |
1389 |
|
|
if (cancel) |
1390 |
|
|
return FALSE; |
1391 |
|
|
} |
1392 |
twoaday |
24 |
|
1393 |
|
|
ke = new GpgKeyEdit (k->keyid); |
1394 |
|
|
if (!ke) |
1395 |
twoaday |
2 |
BUG (NULL); |
1396 |
twoaday |
24 |
if (k->is_protected) |
1397 |
|
|
ke->setPassphrase (pass); |
1398 |
twoaday |
2 |
|
1399 |
|
|
get_userid_preflist (&prefs, &flags); |
1400 |
twoaday |
24 |
|
1401 |
|
|
rc = ke->setUseridPreferences (id, prefs); |
1402 |
|
|
/* XXX */ |
1403 |
|
|
|
1404 |
twoaday |
23 |
sfree_if_alloc (pass); |
1405 |
twoaday |
2 |
free_if_alloc (prefs); |
1406 |
twoaday |
24 |
delete ke; |
1407 |
twoaday |
2 |
return 0; |
1408 |
|
|
} |
1409 |
|
|
|
1410 |
|
|
|
1411 |
|
|
static int |
1412 |
twoaday |
22 |
do_editkey_primary (winpt_key_t k, HWND dlg, listview_ctrl_t lv) |
1413 |
twoaday |
2 |
{ |
1414 |
twoaday |
23 |
gpgme_error_t err; |
1415 |
|
|
GpgKeyEdit *ke; |
1416 |
twoaday |
2 |
int j, id, cancel=0; |
1417 |
|
|
char buf[256], * pass = NULL; |
1418 |
|
|
|
1419 |
twoaday |
22 |
if (listview_count_items (lv, 0) == 1) |
1420 |
|
|
return TRUE; |
1421 |
|
|
if ((j = listview_get_curr_pos (lv)) == -1) { |
1422 |
twoaday |
2 |
msg_box( dlg, _("Please select a user ID."), _("Key Edit"), MB_ERR ); |
1423 |
|
|
return FALSE; |
1424 |
|
|
} |
1425 |
twoaday |
23 |
listview_get_item_text (lv, j, 1, buf, sizeof buf-1); |
1426 |
twoaday |
16 |
id = do_find_userid (k->keyid, buf, NULL); |
1427 |
twoaday |
22 |
if (id == -1) |
1428 |
twoaday |
2 |
BUG( dlg ); |
1429 |
twoaday |
22 |
if (k->is_protected) { |
1430 |
twoaday |
23 |
pass = request_passphrase (_("Key Edit"), 1, &cancel); |
1431 |
twoaday |
2 |
if( cancel ) |
1432 |
|
|
return FALSE; |
1433 |
|
|
} |
1434 |
|
|
|
1435 |
twoaday |
23 |
ke = new GpgKeyEdit (k->keyid); |
1436 |
|
|
if (k->is_protected) |
1437 |
|
|
ke->setPassphrase (pass); |
1438 |
|
|
err = ke->setPrimaryUserid (id); |
1439 |
|
|
if (err) |
1440 |
|
|
msg_box (dlg, gpgme_strerror (err), _("Primary"), MB_ERR); |
1441 |
twoaday |
2 |
else { |
1442 |
twoaday |
19 |
k->update = 1; |
1443 |
twoaday |
23 |
status_box (dlg, _("User ID successfully flagged"), _("GnuPG Status")); |
1444 |
twoaday |
2 |
} |
1445 |
|
|
|
1446 |
twoaday |
23 |
sfree_if_alloc (pass); |
1447 |
|
|
delete ke; |
1448 |
|
|
return err? FALSE : TRUE; |
1449 |
|
|
} |
1450 |
twoaday |
2 |
|
1451 |
|
|
|
1452 |
|
|
static int |
1453 |
twoaday |
16 |
parse_preflist (HWND dlg, const char *list) |
1454 |
twoaday |
2 |
{ |
1455 |
twoaday |
20 |
char *p, buf[128] = {0}, *pbuf = buf; |
1456 |
twoaday |
16 |
const char *ciphers[11] = {0, "IDEA", "3DES", "CAST5", "BLOWFISH", 0, 0, "AES", "AES192", "AES256", "TWOFISH"}; |
1457 |
twoaday |
20 |
const char *hash[11] = {0, "MD5", "SHA1", "RMD160", 0, 0, 0, 0, "SHA256", "SHA384", "SHA512"}; |
1458 |
twoaday |
16 |
const char *compress[4] = {0, "ZIP", "ZLIB", "BZIP2"}; |
1459 |
|
|
int n=0; |
1460 |
|
|
|
1461 |
twoaday |
20 |
strncpy (buf, list, 127); |
1462 |
|
|
p = strtok (pbuf, " "); |
1463 |
twoaday |
16 |
while (p != NULL) { |
1464 |
|
|
int algid = atol (p+1); |
1465 |
|
|
n++; |
1466 |
|
|
switch (*p) { |
1467 |
|
|
case 'S': |
1468 |
|
|
SendDlgItemMessage (dlg, IDC_SHOWPREF_CIPHERS, LB_ADDSTRING, 0, (LPARAM)(const char*)ciphers[algid % 11]); |
1469 |
|
|
break; |
1470 |
|
|
|
1471 |
|
|
case 'H': |
1472 |
twoaday |
20 |
SendDlgItemMessage (dlg, IDC_SHOWPREF_HASH, LB_ADDSTRING, 0, (LPARAM)(const char*)hash[algid % 10]); |
1473 |
twoaday |
16 |
break; |
1474 |
|
|
|
1475 |
|
|
case 'Z': |
1476 |
|
|
SendDlgItemMessage (dlg, IDC_SHOWPREF_ZIP, LB_ADDSTRING, 0, (LPARAM)(const char*)compress[algid % 4]); |
1477 |
|
|
break; |
1478 |
|
|
|
1479 |
|
|
default: |
1480 |
|
|
n--; |
1481 |
|
|
} |
1482 |
|
|
p = strtok (NULL, " "); |
1483 |
|
|
} |
1484 |
|
|
return n; |
1485 |
|
|
} |
1486 |
|
|
|
1487 |
twoaday |
23 |
|
1488 |
|
|
/* Dialog box procedure to show the key preferences. */ |
1489 |
twoaday |
16 |
BOOL CALLBACK |
1490 |
|
|
showpref_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
1491 |
|
|
{ |
1492 |
|
|
static keyedit_callback_s *cb = NULL; |
1493 |
twoaday |
24 |
gpg_uid_info_t inf=NULL; |
1494 |
twoaday |
16 |
char buf[128]; |
1495 |
|
|
int pos; |
1496 |
|
|
|
1497 |
|
|
switch (msg) { |
1498 |
|
|
case WM_INITDIALOG: |
1499 |
|
|
cb = (keyedit_callback_s *)lparam; |
1500 |
|
|
if (cb == NULL) |
1501 |
|
|
BUG (dlg); |
1502 |
|
|
listview_get_item_text (cb->lv, listview_get_curr_pos (cb->lv), 2, buf, DIM (buf)-1); |
1503 |
|
|
SetDlgItemText (dlg, IDC_SHOWPREF_INFO, buf); |
1504 |
|
|
pos = do_find_userid (((winpt_key_t)cb->opaque)->keyid, buf, &inf); |
1505 |
|
|
if (inf) { |
1506 |
twoaday |
24 |
const char *prefs = inf->prefs; |
1507 |
twoaday |
16 |
if (prefs && *prefs) { |
1508 |
|
|
if (parse_preflist (dlg, prefs) <= 0) |
1509 |
|
|
pos = -1; |
1510 |
|
|
} |
1511 |
|
|
else |
1512 |
|
|
pos = -1; |
1513 |
twoaday |
24 |
gpg_uid_info_release (inf); |
1514 |
twoaday |
16 |
if (pos == -1) { |
1515 |
|
|
msg_box (dlg, _("No preferences available."), _("Key Edit"), MB_ERR); |
1516 |
|
|
EndDialog (dlg, TRUE); |
1517 |
|
|
} |
1518 |
twoaday |
24 |
if (inf->flags.mdc) |
1519 |
twoaday |
19 |
CheckDlgButton (dlg, IDC_SHOWPREF_MDC, BST_CHECKED); |
1520 |
twoaday |
16 |
} |
1521 |
|
|
SetForegroundWindow (dlg); |
1522 |
|
|
break; |
1523 |
|
|
|
1524 |
|
|
case WM_COMMAND: |
1525 |
|
|
switch (LOWORD (wparam)) { |
1526 |
|
|
case IDOK: |
1527 |
|
|
EndDialog (dlg, TRUE); |
1528 |
|
|
break; |
1529 |
|
|
} |
1530 |
|
|
break; |
1531 |
|
|
} |
1532 |
|
|
return FALSE; |
1533 |
|
|
} |
1534 |
|
|
|
1535 |
twoaday |
23 |
|
1536 |
twoaday |
16 |
static int |
1537 |
|
|
do_editkey_showpref (winpt_key_t k, HWND dlg, listview_ctrl_t lv) |
1538 |
|
|
{ |
1539 |
|
|
struct keyedit_callback_s cb; |
1540 |
twoaday |
23 |
|
1541 |
|
|
if (k->is_v3) |
1542 |
|
|
return TRUE; |
1543 |
|
|
|
1544 |
twoaday |
16 |
if (listview_get_curr_pos (lv) == -1) { |
1545 |
|
|
msg_box (dlg, _("Please select a user ID."), _("Key Edit"), MB_ERR); |
1546 |
|
|
return FALSE; |
1547 |
|
|
} |
1548 |
|
|
|
1549 |
|
|
memset (&cb, 0, sizeof (cb)); |
1550 |
|
|
cb.lv = lv; |
1551 |
|
|
cb.opaque = k; |
1552 |
|
|
DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_KEYEDIT_SHOWPREF, dlg, |
1553 |
|
|
showpref_dlg_proc, (LPARAM)&cb); |
1554 |
twoaday |
23 |
return TRUE; |
1555 |
twoaday |
16 |
} |
1556 |
|
|
|
1557 |
|
|
|
1558 |
|
|
static int |
1559 |
|
|
do_editkey_deluid (winpt_key_t k, HWND dlg, listview_ctrl_t lv) |
1560 |
|
|
{ |
1561 |
twoaday |
24 |
gpgme_error_t err; |
1562 |
|
|
GpgKeyEdit *ke; |
1563 |
twoaday |
2 |
char buf[256], t[512]; |
1564 |
|
|
int j, id = 0; |
1565 |
|
|
|
1566 |
twoaday |
19 |
if (!k->key_pair) |
1567 |
|
|
return FALSE; /* XXX: see do_editkey_delsubkey */ |
1568 |
|
|
|
1569 |
twoaday |
2 |
if( listview_count_items( lv, 0 ) == 1 ) { |
1570 |
|
|
msg_box( dlg, _("Primary user ID can not be deleted!"), _("Key Edit"), MB_ERR ); |
1571 |
|
|
return FALSE; |
1572 |
|
|
} |
1573 |
|
|
if( (j = listview_get_curr_pos( lv )) == -1 ) { |
1574 |
|
|
msg_box( dlg, _("Please select a user ID."), _("Key Edit"), MB_ERR ); |
1575 |
|
|
return FALSE; |
1576 |
|
|
} |
1577 |
|
|
|
1578 |
twoaday |
19 |
/* XXX: add a hint that also all signatures will be deleted? */ |
1579 |
twoaday |
16 |
listview_get_item_text( lv, j, 1, buf, DIM(buf) -1 ); |
1580 |
twoaday |
19 |
_snprintf( t, DIM (t)-1, _("user ID \"%s\".\n\n" |
1581 |
|
|
"Do you really want to delete this user ID?"), |
1582 |
|
|
buf); |
1583 |
twoaday |
2 |
if( msg_box( dlg, t, _("Key Edit"), MB_YESNO|MB_ICONWARNING ) == IDNO ) |
1584 |
|
|
return FALSE; |
1585 |
|
|
|
1586 |
twoaday |
16 |
listview_get_item_text (lv, j, 2, buf, DIM (buf)-1); |
1587 |
|
|
id = do_find_userid (k->keyid, buf, NULL); |
1588 |
|
|
if (id == -1) |
1589 |
|
|
BUG (dlg); |
1590 |
twoaday |
24 |
|
1591 |
|
|
ke = new GpgKeyEdit (k->keyid); |
1592 |
|
|
if (!ke) |
1593 |
|
|
BUG (NULL); |
1594 |
|
|
|
1595 |
|
|
err = ke->delUserid (id); |
1596 |
|
|
if( err ) |
1597 |
|
|
msg_box( dlg, gpgme_strerror (err), _("Delete user ID"), MB_ERR ); |
1598 |
twoaday |
2 |
else { |
1599 |
|
|
listview_del_item( lv, j ); |
1600 |
twoaday |
19 |
k->update = 1; |
1601 |
twoaday |
2 |
status_box( dlg, _("User ID successfully deleted"), _("GnuPG Status") ); |
1602 |
|
|
} |
1603 |
twoaday |
24 |
delete ke; |
1604 |
|
|
return err? FALSE : TRUE; |
1605 |
twoaday |
2 |
} /* do_editkey_deluid */ |
1606 |
|
|
|
1607 |
|
|
|
1608 |
|
|
|
1609 |
|
|
static BOOL CALLBACK |
1610 |
|
|
subkey_subclass_proc( HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam ) |
1611 |
|
|
{ |
1612 |
|
|
switch( msg ) { |
1613 |
|
|
case WM_KEYUP: |
1614 |
|
|
int virt_key = (int)wparam; |
1615 |
|
|
switch( virt_key ) { |
1616 |
|
|
case VK_DELETE: |
1617 |
|
|
SendDlgItemMessage( keyedit_subkey_proc.dlg, IDC_KEYEDIT_CMD, |
1618 |
|
|
CB_SETCURSEL, CMD_DELKEY, 0 ); |
1619 |
|
|
send_cmd_id( keyedit_subkey_proc.dlg, IDOK ); |
1620 |
|
|
break; |
1621 |
|
|
|
1622 |
|
|
case VK_INSERT: |
1623 |
|
|
SendDlgItemMessage( keyedit_subkey_proc.dlg, IDC_KEYEDIT_CMD, |
1624 |
|
|
CB_SETCURSEL, CMD_ADDKEY, 0 ); |
1625 |
|
|
send_cmd_id( keyedit_subkey_proc.dlg, IDOK ); |
1626 |
|
|
break; |
1627 |
|
|
} |
1628 |
|
|
} |
1629 |
|
|
return CallWindowProc( keyedit_subkey_proc.old, dlg, msg, wparam, lparam ); |
1630 |
|
|
} /* subkey_subclass_proc */ |
1631 |
|
|
|
1632 |
|
|
|
1633 |
|
|
static BOOL CALLBACK |
1634 |
twoaday |
16 |
uid_subclass_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
1635 |
twoaday |
2 |
{ |
1636 |
|
|
switch( msg ) { |
1637 |
|
|
case WM_KEYUP: |
1638 |
|
|
int virt_key = (int)wparam; |
1639 |
twoaday |
16 |
switch (virt_key) { |
1640 |
twoaday |
2 |
case VK_DELETE: |
1641 |
twoaday |
16 |
SendDlgItemMessage (keyedit_uid_proc.dlg, IDC_KEYEDIT_CMD, |
1642 |
|
|
CB_SETCURSEL, CMD_DELUID, 0); |
1643 |
|
|
send_cmd_id (keyedit_uid_proc.dlg, IDOK); |
1644 |
twoaday |
2 |
break; |
1645 |
|
|
|
1646 |
|
|
case VK_INSERT: |
1647 |
twoaday |
16 |
SendDlgItemMessage (keyedit_uid_proc.dlg, IDC_KEYEDIT_CMD, |
1648 |
|
|
CB_SETCURSEL, CMD_ADDUID, 0); |
1649 |
|
|
send_cmd_id (keyedit_uid_proc.dlg, IDOK); |
1650 |
twoaday |
2 |
break; |
1651 |
|
|
} |
1652 |
|
|
} |
1653 |
|
|
return CallWindowProc( keyedit_uid_proc.old, dlg, msg, wparam, lparam ); |
1654 |
|
|
} /* uid_subclass_proc */ |
1655 |
|
|
|
1656 |
|
|
|
1657 |
|
|
BOOL CALLBACK |
1658 |
|
|
keyedit_main_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
1659 |
|
|
{ |
1660 |
|
|
static winpt_key_t k; |
1661 |
|
|
static listview_ctrl_t lvsub = NULL, lvuid = NULL; |
1662 |
|
|
int cmd, idxsub = 0; |
1663 |
|
|
HWND item; |
1664 |
|
|
|
1665 |
|
|
switch( msg ) { |
1666 |
|
|
case WM_INITDIALOG: |
1667 |
|
|
k = (winpt_key_t)lparam; |
1668 |
twoaday |
16 |
if (!k) |
1669 |
|
|
BUG (NULL); |
1670 |
|
|
do_init_cmdlist (dlg); |
1671 |
|
|
lvsub = subkey_list_init (dlg, k); |
1672 |
twoaday |
2 |
if( !lvsub ) |
1673 |
|
|
BUG( NULL ); |
1674 |
|
|
lvuid = userid_list_init (dlg, k); |
1675 |
|
|
if( !lvuid ) |
1676 |
|
|
BUG( NULL ); |
1677 |
|
|
item = GetDlgItem( dlg, IDC_KEYEDIT_KEYLIST ); |
1678 |
|
|
keyedit_subkey_proc.dlg = dlg; |
1679 |
|
|
keyedit_subkey_proc.current = (WNDPROC)subkey_subclass_proc; |
1680 |
|
|
keyedit_subkey_proc.old = (WNDPROC)GetWindowLong( item, GWL_WNDPROC ); |
1681 |
|
|
if( keyedit_subkey_proc.old ) { |
1682 |
|
|
if( !SetWindowLong( item, GWL_WNDPROC, (LONG)keyedit_subkey_proc.current ) ) { |
1683 |
|
|
msg_box( dlg, _("Could not set subkey window procedure."), _("Key Edit"), MB_ERR ); |
1684 |
|
|
BUG( NULL ); |
1685 |
|
|
} |
1686 |
|
|
} |
1687 |
|
|
item = GetDlgItem( dlg, IDC_KEYEDIT_UIDLIST ); |
1688 |
|
|
keyedit_uid_proc.dlg = dlg; |
1689 |
|
|
keyedit_uid_proc.current = (WNDPROC)uid_subclass_proc; |
1690 |
|
|
keyedit_uid_proc.old = (WNDPROC)GetWindowLong( item, GWL_WNDPROC ); |
1691 |
|
|
if( keyedit_uid_proc.old ) { |
1692 |
|
|
if( !SetWindowLong( item, GWL_WNDPROC, (LONG)keyedit_uid_proc.current ) ) { |
1693 |
|
|
msg_box( dlg, _("Could not set user ID window procedure."), _("Key Edit"), MB_ERR ); |
1694 |
|
|
BUG( NULL ); |
1695 |
|
|
} |
1696 |
|
|
} |
1697 |
|
|
if (!k->key_pair) { |
1698 |
|
|
EnableWindow (GetDlgItem (dlg, IDC_KEYEDIT_CMD), FALSE); |
1699 |
|
|
EnableWindow (GetDlgItem (dlg, IDOK), FALSE); |
1700 |
|
|
} |
1701 |
|
|
SetForegroundWindow( dlg ); |
1702 |
twoaday |
23 |
center_window( dlg, NULL ); |
1703 |
twoaday |
2 |
return TRUE; |
1704 |
|
|
|
1705 |
|
|
case WM_DESTROY: |
1706 |
|
|
if( lvsub ) { |
1707 |
|
|
listview_release( lvsub ); |
1708 |
|
|
lvsub = NULL; |
1709 |
|
|
} |
1710 |
|
|
if( lvuid ) { |
1711 |
|
|
listview_release( lvuid ); |
1712 |
|
|
lvuid = NULL; |
1713 |
|
|
} |
1714 |
|
|
break; |
1715 |
|
|
|
1716 |
twoaday |
16 |
case WM_NOTIFY: |
1717 |
|
|
NMHDR * notify; |
1718 |
|
|
notify = (NMHDR *)lparam; |
1719 |
|
|
if (notify && notify->code == NM_DBLCLK && |
1720 |
|
|
notify->idFrom == IDC_KEYEDIT_UIDLIST) |
1721 |
|
|
do_editkey_showpref (k, dlg, lvuid); |
1722 |
|
|
break; |
1723 |
|
|
|
1724 |
twoaday |
2 |
case WM_COMMAND: |
1725 |
|
|
switch( LOWORD( wparam ) ) { |
1726 |
|
|
case IDOK: |
1727 |
twoaday |
22 |
cmd = SendDlgItemMessage (dlg, IDC_KEYEDIT_CMD, CB_GETCURSEL, 0, 0); |
1728 |
|
|
if (cmd == LB_ERR) { |
1729 |
twoaday |
2 |
msg_box( dlg, _("Please select a command."), _("Key Edit"), MB_INFO ); |
1730 |
|
|
return FALSE; |
1731 |
|
|
} |
1732 |
twoaday |
22 |
idxsub = listview_get_curr_pos (lvsub); |
1733 |
twoaday |
20 |
if (k->is_v3 && is_cmd_openpgp (cmd)) { |
1734 |
|
|
msg_box (dlg, _("This command cannot be used with PGP 2 (v3) keys.\n"), |
1735 |
|
|
_("Key Edit"), MB_ERR); |
1736 |
twoaday |
2 |
return FALSE; |
1737 |
|
|
} |
1738 |
twoaday |
20 |
switch (cmd) { |
1739 |
twoaday |
16 |
case CMD_SHOWPREF: do_editkey_showpref (k, dlg, lvuid); break; |
1740 |
|
|
case CMD_DELKEY: do_editkey_delkey (k, dlg, lvsub); break; |
1741 |
|
|
case CMD_ADDKEY: keyedit_add_subkey (k, dlg, lvsub); break; |
1742 |
|
|
case CMD_EXPIRE: do_editkey_expire (k, dlg, lvsub); break; |
1743 |
|
|
case CMD_REVKEY: do_editkey_revoke (k, dlg, lvsub); break; |
1744 |
|
|
/*case CMD_SETPREF:do_editkey_setpref( k, dlg, lvuid ); break;*/ |
1745 |
twoaday |
2 |
case CMD_ADDUID: keyedit_add_userid( k, dlg, lvuid ); break; |
1746 |
|
|
case CMD_ADDREVOKER: keyedit_add_revoker( k, dlg ); break; |
1747 |
|
|
case CMD_ADDPHOTO: keyedit_add_photo( k, dlg ); break; |
1748 |
|
|
case CMD_REVUID: do_editkey_revuid( k, dlg, lvuid ); break; |
1749 |
|
|
case CMD_DELUID: do_editkey_deluid( k, dlg, lvuid ); break; |
1750 |
|
|
case CMD_PASSWD: keyedit_change_passwd( k, dlg ); break; |
1751 |
|
|
case CMD_PRIMARY: do_editkey_primary( k, dlg, lvuid ); break; |
1752 |
|
|
case CMD_ENABLE: km_enable_disable_key( lvsub, dlg, idxsub, 1 ); break; |
1753 |
|
|
case CMD_DISABLE: km_enable_disable_key( lvsub, dlg, idxsub, 0 ); break; |
1754 |
|
|
} |
1755 |
|
|
break; |
1756 |
|
|
|
1757 |
|
|
case IDCANCEL: |
1758 |
twoaday |
19 |
EndDialog (dlg, FALSE); |
1759 |
twoaday |
2 |
break; |
1760 |
|
|
|
1761 |
|
|
case IDC_KEYEDIT_HELP: |
1762 |
twoaday |
16 |
do_show_help (dlg); |
1763 |
twoaday |
2 |
break; |
1764 |
|
|
} |
1765 |
|
|
break; |
1766 |
|
|
} |
1767 |
|
|
return FALSE; |
1768 |
|
|
} /* keyedit_main_dlg_proc */ |