35 |
#include "wptKeylist.h" |
#include "wptKeylist.h" |
36 |
#include "wptKeyManager.h" |
#include "wptKeyManager.h" |
37 |
#include "wptRegistry.h" |
#include "wptRegistry.h" |
38 |
|
#include "wptKeyEdit.h" |
39 |
|
|
40 |
enum keyedit_commands { |
enum keyedit_commands { |
41 |
CMD_ADDKEY = 0, |
CMD_ADDKEY = 0, |
65 |
|
|
66 |
|
|
67 |
struct keyedit_callback_s { |
struct keyedit_callback_s { |
68 |
gpgme_editkey_t ek; |
const char *keyid; |
69 |
const char *pass; |
const char *pass; |
70 |
listview_ctrl_t lv; |
listview_ctrl_t lv; |
71 |
void *opaque; |
void *opaque; |
72 |
|
unsigned int finished:1; |
73 |
}; |
}; |
74 |
typedef struct keyedit_callback_s KEYEDIT_CB; |
typedef struct keyedit_callback_s KEYEDIT_CB; |
75 |
|
|
87 |
|
|
88 |
int keygen_check_date (SYSTEMTIME *st); |
int keygen_check_date (SYSTEMTIME *st); |
89 |
void get_userid_preflist (char **r_prefs, int * r_flags); |
void get_userid_preflist (char **r_prefs, int * r_flags); |
90 |
|
char* get_subkey_fingerprint (const char *keyid); |
91 |
|
|
92 |
|
|
93 |
|
/* Associate each key with a combo box entry. |
94 |
|
Skip the key in @k. */ |
95 |
static void |
static void |
96 |
do_init_keylist (HWND dlg, winpt_key_t k) |
do_init_keylist (HWND dlg, winpt_key_t k) |
97 |
{ |
{ |
105 |
if (!pub) |
if (!pub) |
106 |
BUG (0); |
BUG (0); |
107 |
|
|
108 |
|
gpgme_keycache_rewind (pub); |
109 |
while( !gpgme_keycache_next_key( pub, 0, &key ) ) { |
while( !gpgme_keycache_next_key( pub, 0, &key ) ) { |
110 |
s = gpgme_key_get_string_attr( key, GPGME_ATTR_USERID, NULL, 0 ); |
s = key->uids->uid; |
111 |
kid = gpgme_key_get_string_attr (key, GPGME_ATTR_KEYID, NULL, 0); |
kid = key->subkeys->keyid; |
112 |
if (!s || !strcmp (kid+8, k->keyid+2)) |
if (!s || !strcmp (kid+8, k->keyid+2)) |
113 |
continue; |
continue; |
114 |
u = utf8_to_wincp (s, strlen (s)); |
u = utf8_to_wincp (s, strlen (s)); |
115 |
SendDlgItemMessage (dlg, IDC_ADDREV_KEYLIST, CB_ADDSTRING, |
SendDlgItemMessage (dlg, IDC_ADDREV_KEYLIST, CB_ADDSTRING, |
116 |
0, (WPARAM)(char *)u); |
0, (WPARAM)(char *)u); |
117 |
free( u ); |
free (u); |
118 |
} |
} |
119 |
gpgme_keycache_rewind( pub ); |
gpgme_keycache_rewind (pub); |
120 |
n = SendDlgItemMessage( dlg, IDC_ADDREV_KEYLIST, CB_GETCOUNT, 0, 0 ); |
n = SendDlgItemMessage( dlg, IDC_ADDREV_KEYLIST, CB_GETCOUNT, 0, 0 ); |
121 |
for( i = 0; i < n; i++ ) { |
for (i = 0; i < n; i++) { |
122 |
gpgme_keycache_next_key( pub, 0, &key ); |
gpgme_keycache_next_key (pub, 0, &key); |
123 |
SendDlgItemMessage( dlg, IDC_ADDREV_KEYLIST, CB_SETITEMDATA, |
SendDlgItemMessage (dlg, IDC_ADDREV_KEYLIST, CB_SETITEMDATA, |
124 |
(WPARAM)(int)i, (LPARAM)key ); |
(WPARAM)(int)i, (LPARAM)key); |
125 |
} |
} |
126 |
SendDlgItemMessage( dlg, IDC_ADDREV_KEYLIST, CB_SETCURSEL, 0, 0 ); |
SendDlgItemMessage (dlg, IDC_ADDREV_KEYLIST, CB_SETCURSEL, 0, 0); |
127 |
} /* do_init_keylist */ |
} |
128 |
|
|
129 |
|
|
130 |
|
/* Add a new user-id to the list view @lv. */ |
131 |
static void |
static void |
132 |
do_add_new_userid (listview_ctrl_t lv, const char * name, const char *email, |
do_add_new_userid (listview_ctrl_t lv, |
133 |
const char * comment ) |
const char * name, const char *email, const char * comment) |
134 |
{ |
{ |
135 |
char * p; |
char * p; |
136 |
size_t n; |
size_t n; |
156 |
|
|
157 |
|
|
158 |
static void |
static void |
159 |
do_add_new_subkey (listview_ctrl_t lv, KEYGEN_CB * keygen, unsigned int flags) |
do_add_new_subkey (listview_ctrl_t lv, KEYGEN_CB *keygen, unsigned int flags) |
160 |
{ |
{ |
161 |
char info[128], keyid[32]; |
char info[128], keyid[32]; |
162 |
const char * expdate, * s; |
const char * expdate, * s; |
165 |
expdate = keygen->expire? get_key_expire_date (keygen->expire) : _("Never"); |
expdate = keygen->expire? get_key_expire_date (keygen->expire) : _("Never"); |
166 |
_snprintf (info, sizeof info-1, "%d-bit %s", |
_snprintf (info, sizeof info-1, "%d-bit %s", |
167 |
keygen->bits, |
keygen->bits, |
168 |
gpgme_key_expand_attr (GPGME_ATTR_ALGO, keygen->algo)); |
get_key_pubalgo ((gpgme_pubkey_algo_t)keygen->algo)); |
169 |
_snprintf (keyid, sizeof keyid-1, "0x%s", keygen->fpr+32); |
_snprintf (keyid, sizeof keyid-1, "0x%s", keygen->fpr+32); |
170 |
n = listview_count_items (lv, 0); |
n = listview_count_items (lv, 0); |
171 |
listview_add_item_pos (lv, n); |
listview_add_item_pos (lv, n); |
180 |
} /* do_add_new_subkey */ |
} /* do_add_new_subkey */ |
181 |
|
|
182 |
|
|
183 |
|
/* 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 |
static int |
static int |
187 |
do_find_userid (const char * keyid, const char * name, gpgme_uidinfo_t *r_inf) |
do_find_userid (const char *keyid, const char *name, gpg_uid_info_t *r_inf) |
188 |
{ |
{ |
189 |
gpgme_uidinfo_t inf; |
GpgKeyEdit *ke; |
|
gpgme_ctx_t ctx; |
|
190 |
gpgme_error_t err; |
gpgme_error_t err; |
191 |
int nitems = 0, pos = -1; |
gpg_uid_info_t inf, ui; |
192 |
const char * s; |
int pos = -1; |
193 |
|
|
194 |
err = gpgme_new (&ctx); |
ke = new GpgKeyEdit (keyid); |
195 |
if (err) |
if (!ke) |
196 |
BUG (0); |
BUG (NULL); |
197 |
err = gpgme_op_editkey_get_info (ctx, keyid, &inf); |
err = ke->getUseridInfo (&inf); |
198 |
|
delete ke; |
199 |
if (err) { |
if (err) { |
200 |
log_box (_("user ID"), MB_ERR, _("Could not get key information for: \"%s\""), name); |
log_box (_("user ID"), MB_ERR, _("Could not get key information for: \"%s\""), name); |
|
gpgme_release (ctx); |
|
201 |
return -1; |
return -1; |
202 |
} |
} |
203 |
gpgme_release (ctx); |
|
204 |
nitems = gpgme_editkey_count_items (inf); |
for (ui = inf; ui; ui = ui->next) { |
205 |
while (nitems--) { |
if (!strcmp (ui->email, name)) { |
206 |
s = gpgme_editkey_get_string_attr (inf, GPGME_ATTR_EMAIL, nitems); |
pos = ui->index; |
|
if (!s) |
|
|
continue; |
|
|
|
|
|
if (!strcmp (s, name)) { |
|
|
pos = gpgme_editkey_get_ulong_attr (inf, GPGME_ATTR_LEVEL, nitems); |
|
207 |
break; |
break; |
208 |
} |
} |
209 |
} |
} |
|
|
|
210 |
if (r_inf) |
if (r_inf) |
211 |
*r_inf = inf; |
*r_inf = inf; |
212 |
else |
else |
213 |
gpgme_uid_info_release (inf); |
gpg_uid_info_release (inf); |
214 |
return pos; |
return pos; |
215 |
} /* do_find_userid */ |
} |
216 |
|
|
217 |
|
|
218 |
|
/* Dialog box procedure to add a photo. */ |
219 |
BOOL CALLBACK |
BOOL CALLBACK |
220 |
keyedit_addphoto_dlg_proc( HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam ) |
keyedit_addphoto_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
221 |
{ |
{ |
222 |
static winpt_key_t k; |
static winpt_key_t k; |
223 |
gpgme_editkey_t ek; |
GpgKeyEdit *ke; |
224 |
gpgme_error_t ec; |
gpgme_error_t ec; |
|
gpgme_ctx_t ctx; |
|
225 |
const char * s; |
const char * s; |
226 |
char pwd[128], file[128]; |
char pwd[128], file[128]; |
227 |
int id; |
int id; |
272 |
return FALSE; |
return FALSE; |
273 |
} |
} |
274 |
} |
} |
275 |
ec = gpgme_editkey_new( &ek ); |
ke = new GpgKeyEdit (k->keyid); |
276 |
if( !ec ) |
if (!ke) |
277 |
ec = gpgme_new( &ctx ); |
BUG (NULL); |
278 |
if( ec ) |
|
279 |
BUG( NULL ); |
if (k->is_protected) |
280 |
gpgme_enable_logging( ctx ); |
ke->setPassphrase (pwd); |
281 |
gpgme_editkey_addphoto_set( ek, file, k->is_protected? pwd : NULL ); |
ec = ke->addPhotoid (file); |
282 |
gpgme_set_edit_ctx( ctx, ek, GPGME_EDITKEY_ADDPHOTO ); |
delete ke; |
283 |
ec = gpgme_op_editkey( ctx, k->keyid ); |
memset (pwd, 0, sizeof pwd); |
284 |
gpgme_editkey_release( ek ); |
if (ec) { |
285 |
if( ec ) { |
msg_box (dlg, gpgme_strerror (ec), _("Add Photo"), MB_ERR ); |
|
gpgme_show_error( dlg, ec, ctx, _("Add Photo"), MB_ERR ); |
|
|
gpgme_release( ctx ); |
|
286 |
return FALSE; |
return FALSE; |
287 |
} |
} |
288 |
else { |
else { |
289 |
k->update = 1; |
k->update = 1; |
290 |
msg_box (dlg, _("Photo successfully added."), _("GnuPG Status"), MB_OK); |
msg_box (dlg, _("Photo successfully added."), _("GnuPG Status"), MB_OK); |
291 |
} |
} |
|
gpgme_release (ctx); |
|
292 |
EndDialog (dlg, TRUE); |
EndDialog (dlg, TRUE); |
293 |
break; |
break; |
294 |
|
|
295 |
case IDCANCEL: |
case IDCANCEL: |
296 |
EndDialog( dlg, FALSE ); |
EndDialog (dlg, FALSE); |
297 |
break; |
break; |
298 |
} |
} |
299 |
break; |
break; |
300 |
} |
} |
301 |
return FALSE; |
return FALSE; |
302 |
} /* keyedit_addphoto_dlg_proc */ |
} |
303 |
|
|
304 |
|
|
305 |
|
/* Dialog box procedure to add a designated revoker. */ |
306 |
BOOL CALLBACK |
BOOL CALLBACK |
307 |
keyedit_addrevoker_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
keyedit_addrevoker_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
308 |
{ |
{ |
309 |
static winpt_key_t k; |
static winpt_key_t k; |
310 |
static gpgme_key_t seckey; |
static gpgme_key_t seckey; |
311 |
gpgme_editkey_t ek; |
GpgKeyEdit *ke; |
312 |
gpgme_ctx_t ctx; |
gpgme_error_t err; |
|
gpgme_error_t ec; |
|
313 |
char uid[128], pwd[128]; |
char uid[128], pwd[128]; |
314 |
|
|
315 |
|
|
320 |
BUG( NULL ); |
BUG( NULL ); |
321 |
if( get_seckey( k->keyid, &seckey ) ) |
if( get_seckey( k->keyid, &seckey ) ) |
322 |
BUG( NULL ); |
BUG( NULL ); |
323 |
if( !k->is_protected ) |
if (!k->is_protected) |
324 |
EnableWindow( GetDlgItem( dlg, IDC_ADDREV_PASS ), FALSE ); |
EnableWindow (GetDlgItem (dlg, IDC_ADDREV_PASS), FALSE); |
325 |
do_init_keylist( dlg, k ); |
do_init_keylist (dlg, k); |
326 |
SetDlgItemText (dlg, IDC_ADDREV_INF, _("Appointing a key as designated revoker cannot be undone.")); |
SetDlgItemText (dlg, IDC_ADDREV_INF, _("Appointing a key as designated revoker cannot be undone.")); |
327 |
SetDlgItemText (dlg, IDC_ADDREV_KEYINF, _("Public key")); |
SetDlgItemText (dlg, IDC_ADDREV_KEYINF, _("Public key")); |
328 |
SetDlgItemText (dlg, IDC_ADDREV_PWDINF, _("Passphrase")); |
SetDlgItemText (dlg, IDC_ADDREV_PWDINF, _("Passphrase")); |
351 |
return FALSE; |
return FALSE; |
352 |
} |
} |
353 |
} |
} |
354 |
ec = gpgme_editkey_new( &ek ); |
ke = new GpgKeyEdit (k->keyid); |
355 |
if( !ec ) |
if (k->is_protected) |
356 |
ec = gpgme_new( &ctx ); |
ke->setPassphrase (pwd); |
357 |
if( ec ) |
err = ke->addDesignatedRevoker (uid); |
358 |
BUG( NULL ); |
delete ke; |
359 |
gpgme_enable_logging( ctx ); |
memset (pwd, 0, sizeof pwd); |
360 |
gpgme_editkey_addrev_set( ek, uid, k->is_protected? pwd : NULL ); |
if (err) { |
361 |
gpgme_set_edit_ctx( ctx, ek, GPGME_EDITKEY_ADDREV ); |
msg_box (dlg, gpgme_strerror (err), _("Add Revoker"), MB_ERR); |
362 |
ec = gpgme_op_editkey( ctx, k->keyid ); |
return TRUE; |
|
gpgme_editkey_release( ek ); |
|
|
memset( pwd, 0, sizeof pwd ); |
|
|
if( ec ) { |
|
|
gpgme_show_error( dlg, ec, ctx, _("Add Revoker"), MB_ERR ); |
|
|
gpgme_release( ctx ); |
|
|
return FALSE; |
|
363 |
} |
} |
364 |
else { |
else { |
365 |
k->update = 1; |
k->update = 1; |
366 |
msg_box (dlg, _("Revoker successfully addded."), _("GnuPG Status"), MB_OK); |
msg_box (dlg, _("Revoker successfully addded."), _("GnuPG Status"), MB_OK); |
367 |
} |
} |
|
gpgme_release( ctx ); |
|
368 |
EndDialog( dlg, TRUE ); |
EndDialog( dlg, TRUE ); |
369 |
break; |
break; |
370 |
|
|
375 |
break; |
break; |
376 |
} |
} |
377 |
return FALSE; |
return FALSE; |
378 |
} /* keyedit_addrevoker_dlg_proc */ |
} |
379 |
|
|
380 |
|
|
381 |
|
/* Dialog box procedure to add a new user-ID. */ |
382 |
BOOL CALLBACK |
BOOL CALLBACK |
383 |
keyedit_adduid_dlg_proc( HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam ) |
keyedit_adduid_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
384 |
{ |
{ |
385 |
static KEYEDIT_CB *ctx; |
static KEYEDIT_CB *ctx; |
386 |
|
gpgme_error_t err; |
387 |
|
GpgKeyEdit *ke; |
388 |
char *utf8_name = NULL; |
char *utf8_name = NULL; |
389 |
char name[128], email[128], comment[128]; |
char name[128], email[128], comment[128]; |
390 |
int rc; |
int rc; |
404 |
return FALSE; |
return FALSE; |
405 |
|
|
406 |
case WM_SYSCOMMAND: |
case WM_SYSCOMMAND: |
407 |
if( LOWORD (wparam) == SC_CLOSE ) { |
if (LOWORD (wparam) == SC_CLOSE) { |
|
gpgme_editkey_make_invalid( ctx->ek ); |
|
408 |
EndDialog(dlg, TRUE); |
EndDialog(dlg, TRUE); |
409 |
} |
} |
410 |
return FALSE; |
return FALSE; |
413 |
switch ( LOWORD( wparam ) ) { |
switch ( LOWORD( wparam ) ) { |
414 |
case IDOK: |
case IDOK: |
415 |
rc = GetDlgItemText( dlg, IDC_ADDUID_NAME, name, sizeof name-1 ); |
rc = GetDlgItemText( dlg, IDC_ADDUID_NAME, name, sizeof name-1 ); |
416 |
if( !rc || rc < 5 ) { |
if (!rc || rc < 5) { |
417 |
msg_box( dlg, _("Please enter a name (min. 5 chars.)"), _("UserID"), MB_ERR ); |
msg_box( dlg, _("Please enter a name (min. 5 chars.)"), _("UserID"), MB_ERR ); |
418 |
return FALSE; |
return FALSE; |
419 |
} |
} |
420 |
if( strchr( name, '@' ) ) { |
if (strchr (name, '@')) { |
421 |
msg_box( dlg, _("Please enter the email address in the email field and not in the name field"), _("UserID"), MB_INFO ); |
msg_box( dlg, _("Please enter the email address in the email field and not in the name field"), _("UserID"), MB_INFO ); |
422 |
return FALSE; |
return FALSE; |
423 |
} |
} |
426 |
msg_box( dlg, _("Please enter an email address."), _("UserID"), MB_ERR ); |
msg_box( dlg, _("Please enter an email address."), _("UserID"), MB_ERR ); |
427 |
return FALSE; |
return FALSE; |
428 |
} |
} |
429 |
if( !strchr( email, '@' ) ) { |
if( !strchr( email, '@' ) || strchr (email, ' ')) { |
430 |
msg_box( dlg, _("Invalid email address."), _("UserID"), MB_ERR ); |
msg_box( dlg, _("Invalid email address."), _("UserID"), MB_ERR ); |
431 |
return FALSE; |
return FALSE; |
432 |
} |
} |
433 |
|
|
434 |
rc = GetDlgItemText( dlg, IDC_ADDUID_COMMENT, comment, sizeof comment -1 ); |
rc = GetDlgItemText( dlg, IDC_ADDUID_COMMENT, comment, sizeof comment -1 ); |
435 |
|
|
436 |
/* xxx: something is wrong with the encoding :-( */ |
/* XXX: something is wrong with the encoding :-( */ |
437 |
utf8_name = wincp_to_utf8 (name, strlen (name)); |
utf8_name = wincp_to_utf8 (name, strlen (name)); |
438 |
|
|
439 |
gpgme_editkey_adduid_set( ctx->ek, utf8_name? utf8_name : name, email, |
ke = new GpgKeyEdit (ctx->keyid); |
440 |
rc? comment: NULL, ctx->pass ); |
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 |
free (utf8_name); |
free (utf8_name); |
454 |
if (ctx->lv) |
if (!err && ctx->lv) |
455 |
do_add_new_userid (ctx->lv, name, email, rc?comment : NULL); |
do_add_new_userid (ctx->lv, name, email, rc?comment : NULL); |
456 |
EndDialog( dlg, TRUE ); |
EndDialog (dlg, TRUE); |
457 |
return TRUE; |
return TRUE; |
458 |
|
|
459 |
case IDCANCEL: |
case IDCANCEL: |
460 |
gpgme_editkey_make_invalid( ctx->ek ); |
EndDialog (dlg, FALSE); |
|
EndDialog( dlg, FALSE ); |
|
461 |
return FALSE; |
return FALSE; |
462 |
} |
} |
463 |
break; |
break; |
464 |
} |
} |
465 |
|
|
466 |
return FALSE; |
return FALSE; |
467 |
} /* keyedit_adduid_dlg_proc */ |
} |
468 |
|
|
469 |
|
|
470 |
static int |
static int |
471 |
diff_time (HWND dt) |
diff_time (HWND dt, SYSTEMTIME *in_exp) |
472 |
{ |
{ |
473 |
SYSTEMTIME exp, now; |
SYSTEMTIME exp, now; |
474 |
double e=0, n=0; |
double e=0, n=0; |
475 |
|
|
476 |
DateTime_GetSystemtime (dt, &exp); |
if (in_exp) |
477 |
|
memcpy (&exp, in_exp, sizeof (SYSTEMTIME)); |
478 |
|
else |
479 |
|
DateTime_GetSystemtime (dt, &exp); |
480 |
GetSystemTime (&now); |
GetSystemTime (&now); |
481 |
SystemTimeToVariantTime (&exp, &e); |
SystemTimeToVariantTime (&exp, &e); |
482 |
SystemTimeToVariantTime (&now, &n); |
SystemTimeToVariantTime (&now, &n); |
517 |
{ |
{ |
518 |
static KEYEDIT_CB *ctx; |
static KEYEDIT_CB *ctx; |
519 |
static KEYGEN_CB *keygen; |
static KEYGEN_CB *keygen; |
520 |
gpgme_error_t rc; |
GpgKeyEdit *ke; |
521 |
|
gpgme_error_t err; |
522 |
HWND lb; |
HWND lb; |
523 |
int index, size, valid; |
int index, size, valid; |
524 |
|
|
547 |
|
|
548 |
case WM_SYSCOMMAND: |
case WM_SYSCOMMAND: |
549 |
if( LOWORD (wparam) == SC_CLOSE ) { |
if( LOWORD (wparam) == SC_CLOSE ) { |
|
gpgme_editkey_make_invalid( ctx->ek ); |
|
550 |
EndDialog( dlg, TRUE ); |
EndDialog( dlg, TRUE ); |
551 |
} |
} |
552 |
return FALSE; |
return FALSE; |
581 |
msg_box( dlg,_("DSS uses a fixed keysize of 1024. Size changed."), _("Add Subkey"), MB_INFO ); |
msg_box( dlg,_("DSS uses a fixed keysize of 1024. Size changed."), _("Add Subkey"), MB_INFO ); |
582 |
size = 1024; |
size = 1024; |
583 |
} |
} |
584 |
valid = diff_time (GetDlgItem (dlg, IDC_ADDSUBKEY_EXPDATE)); |
valid = diff_time (GetDlgItem (dlg, IDC_ADDSUBKEY_EXPDATE), NULL); |
585 |
rc = gpgme_editkey_addkey_set (ctx->ek, ctx->pass, index, size, valid); |
|
|
if (rc) { |
|
|
msg_box (dlg, gpgme_strerror (rc), _("Add Subkey"), MB_ERR); |
|
|
return FALSE; |
|
|
} |
|
586 |
keygen->bits = size; |
keygen->bits = size; |
587 |
switch (index) { |
switch (index) { |
588 |
case 2: keygen->algo = GPGME_PK_DSA; break; |
case 2: keygen->algo = GPGME_PK_DSA; break; |
592 |
} |
} |
593 |
if (valid > 0) |
if (valid > 0) |
594 |
keygen->expire = time (NULL) + valid*24*60*60; |
keygen->expire = time (NULL) + valid*24*60*60; |
595 |
EndDialog( dlg, TRUE ); |
|
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 |
|
keygen->fpr = get_subkey_fingerprint (ctx->keyid); |
606 |
|
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 |
|
do_add_new_subkey (ctx->lv, keygen, /*XXXk->flags*/0); |
614 |
|
ctx->finished = 1; |
615 |
|
} |
616 |
|
delete ke; |
617 |
|
EndDialog (dlg, TRUE); |
618 |
return TRUE; |
return TRUE; |
619 |
|
|
620 |
case IDCANCEL: |
case IDCANCEL: |
|
gpgme_editkey_make_invalid (ctx ->ek); |
|
621 |
EndDialog( dlg, FALSE ); |
EndDialog( dlg, FALSE ); |
622 |
return FALSE; |
return FALSE; |
623 |
} |
} |
631 |
BOOL |
BOOL |
632 |
keyedit_add_userid (winpt_key_t k, HWND dlg, listview_ctrl_t lv) |
keyedit_add_userid (winpt_key_t k, HWND dlg, listview_ctrl_t lv) |
633 |
{ |
{ |
|
gpgme_error_t ec; |
|
|
gpgme_ctx_t ctx; |
|
|
gpgme_editkey_t ek; |
|
634 |
KEYEDIT_CB cb; |
KEYEDIT_CB cb; |
635 |
char * pass = NULL; |
char *pass = NULL; |
636 |
int cancel = 0; |
int cancel = 0; |
637 |
|
|
638 |
if (!k->key_pair) { |
if (!k->key_pair) { |
642 |
|
|
643 |
if (k->is_protected) { |
if (k->is_protected) { |
644 |
pass = request_passphrase( _("Key Edit"), 1, &cancel ); |
pass = request_passphrase( _("Key Edit"), 1, &cancel ); |
645 |
if( cancel ) |
if (cancel) |
646 |
return FALSE; |
return FALSE; |
647 |
} |
} |
|
|
|
|
ec = gpgme_editkey_new( &ek ); |
|
|
if( ec ) |
|
|
BUG( dlg ); |
|
648 |
|
|
649 |
memset( &cb, 0, sizeof cb ); |
memset (&cb, 0, sizeof cb); |
|
cb.ek = ek; |
|
650 |
cb.pass = k->is_protected? pass : NULL; |
cb.pass = k->is_protected? pass : NULL; |
651 |
cb.lv = lv; |
cb.lv = lv; |
652 |
dialog_box_param( glob_hinst, (LPCSTR)IDD_WINPT_KEYEDIT_ADDUID, |
cb.keyid = k->keyid; |
653 |
|
dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_KEYEDIT_ADDUID, |
654 |
dlg, keyedit_adduid_dlg_proc, |
dlg, keyedit_adduid_dlg_proc, |
655 |
(LPARAM)&cb, _("Add user ID"), |
(LPARAM)&cb, _("Add user ID"), |
656 |
IDS_WINPT_KEYEDIT_ADDUID ); |
IDS_WINPT_KEYEDIT_ADDUID); |
657 |
if( !gpgme_editkey_is_valid( ek ) ) { |
|
658 |
free_if_alloc( pass ); |
if (cb.finished) |
|
return FALSE; |
|
|
} |
|
|
|
|
|
ec = gpgme_new( &ctx ); |
|
|
if( ec ) |
|
|
BUG( dlg ); |
|
|
gpgme_enable_logging( ctx ); |
|
|
gpgme_set_edit_ctx( ctx, ek, GPGME_EDITKEY_ADDUID ); |
|
|
ec = gpgme_op_editkey( ctx, k->keyid ); |
|
|
if( ec ) |
|
|
gpgme_show_error( dlg, ec, ctx, _("Add user ID"), MB_ERR ); |
|
|
else { |
|
659 |
k->update = 1; |
k->update = 1; |
660 |
msg_box (dlg, _("User ID successfully added"), _("GnuPG Status"), MB_OK); |
|
661 |
} |
sfree_if_alloc (pass); |
|
gpgme_editkey_release( ek ); |
|
|
gpgme_release( ctx ); |
|
|
free_if_alloc( pass ); |
|
662 |
return TRUE; |
return TRUE; |
663 |
} /* keyedit_add_userid */ |
} |
664 |
|
|
665 |
|
|
666 |
char* |
char* |
667 |
get_subkey_fingerprint (gpgme_ctx_t ctx, const char *keyid) |
get_subkey_fingerprint (const char *keyid) |
668 |
{ |
{ |
669 |
static char fpr[40]; |
static char fpr[40]; |
|
const char *s; |
|
670 |
gpgme_error_t err; |
gpgme_error_t err; |
671 |
gpgme_key_t key, main; |
gpgme_key_t key, main; |
672 |
|
gpgme_ctx_t ctx; |
673 |
|
gpgme_subkey_t last_sk, k, new_sk; |
674 |
int n; |
int n; |
675 |
|
|
676 |
/* XXX: this is very slow and complicated */ |
err = gpgme_new (&ctx); |
|
err = gpgme_op_keylist_start (ctx, keyid, 0); |
|
677 |
if (err) |
if (err) |
678 |
return NULL; |
return NULL; |
679 |
err = gpgme_op_keylist_next (ctx, &key); |
err = gpgme_get_key (ctx, keyid, &key, 0); |
680 |
if (err) |
if (err) |
681 |
return NULL; |
return NULL; |
682 |
|
/* XXX: this is very slow and complicated */ |
683 |
|
|
684 |
n = gpgme_key_count_items (key, GPGME_ATTR_KEYID); |
n = count_subkeys (key); |
685 |
s = gpgme_key_get_string_attr (key, GPGME_ATTR_FPR, NULL, n-1); |
last_sk = get_nth_key (key, n-1); |
686 |
strcpy (fpr, s); |
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 |
|
|
693 |
get_pubkey (keyid, &main); |
get_pubkey (keyid, &main); |
694 |
gpgme_key_append (main, key, n-1); |
for (k=main->subkeys; k->next; k=k->next) |
695 |
|
; |
696 |
|
k->next = new_sk; |
697 |
|
|
698 |
gpgme_key_release (key); |
gpgme_key_release (key); |
699 |
return fpr; |
return new_sk->fpr; |
700 |
} |
} |
701 |
|
|
702 |
|
|
703 |
BOOL |
BOOL |
704 |
keyedit_add_subkey (winpt_key_t k, HWND dlg, listview_ctrl_t lv) |
keyedit_add_subkey (winpt_key_t k, HWND dlg, listview_ctrl_t lv) |
705 |
{ |
{ |
|
gpgme_error_t ec; |
|
|
gpgme_ctx_t ctx; |
|
|
gpgme_editkey_t ek; |
|
706 |
KEYEDIT_CB cb; |
KEYEDIT_CB cb; |
707 |
KEYGEN_CB keygen; |
KEYGEN_CB keygen; |
708 |
char * pass = NULL; |
char * pass = NULL; |
709 |
int cancel = 0; |
int cancel = 0; |
710 |
|
|
711 |
if( !k->key_pair ) { |
if (!k->key_pair) { |
712 |
msg_box( dlg, _("There is no secret key available!"), _("Add Subkey"), MB_ERR ); |
msg_box( dlg, _("There is no secret key available!"), _("Add Subkey"), MB_ERR ); |
713 |
return FALSE; |
return FALSE; |
714 |
} |
} |
715 |
if( k->is_protected ) { |
if (k->is_protected) { |
716 |
pass = request_passphrase (_("Key Edit"), 1, &cancel); |
pass = request_passphrase (_("Key Edit"), 1, &cancel); |
717 |
if( cancel ) |
if (cancel) |
718 |
return FALSE; |
return FALSE; |
719 |
} |
} |
720 |
ec = gpgme_editkey_new( &ek ); |
|
|
if( ec ) |
|
|
BUG( dlg ); |
|
|
|
|
721 |
memset (&keygen, 0, sizeof (keygen)); |
memset (&keygen, 0, sizeof (keygen)); |
722 |
memset (&cb, 0, sizeof (cb)); |
memset (&cb, 0, sizeof (cb)); |
723 |
cb.ek = ek; |
cb.keyid = k->keyid; |
724 |
cb.pass = k->is_protected? pass : NULL; |
cb.pass = k->is_protected? pass : NULL; |
725 |
cb.opaque = &keygen; |
cb.opaque = &keygen; |
726 |
dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_KEYEDIT_ADDSUBKEY, |
dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_KEYEDIT_ADDSUBKEY, |
727 |
dlg, keyedit_addsubkey_dlg_proc, |
dlg, keyedit_addsubkey_dlg_proc, |
728 |
(LPARAM)&cb, _("Add new Subkey"), |
(LPARAM)&cb, _("Add new Subkey"), |
729 |
IDS_WINPT_KEYEDIT_ADDSUBKEY ); |
IDS_WINPT_KEYEDIT_ADDSUBKEY); |
730 |
if( !gpgme_editkey_is_valid( ek ) ) { |
if (cb.finished) |
|
free_if_alloc( pass ); |
|
|
return FALSE; |
|
|
} |
|
|
|
|
|
ec = gpgme_new (&ctx); |
|
|
if (ec) |
|
|
BUG (dlg); |
|
|
gpgme_enable_logging (ctx); |
|
|
gpgme_set_edit_ctx (ctx, ek, GPGME_EDITKEY_ADDKEY); |
|
|
gpgme_set_progress_cb (ctx, keygen_cb, NULL); |
|
|
keygen_cb_dlg_create (); |
|
|
|
|
|
ec = gpgme_op_editkey (ctx, k->keyid); |
|
|
keygen.fpr = get_subkey_fingerprint (ctx, k->keyid); |
|
|
keygen_cb_dlg_destroy (); |
|
|
keygen_cb (NULL, NULL, 0, 0, 0); /* flush */ |
|
|
if (ec) |
|
|
gpgme_show_error (dlg, ec, ctx, _("Add Subkey"), MB_ERR); |
|
|
else { |
|
|
msg_box (dlg, _("Subkey successfully added."), _("GnuPG Status"), MB_OK); |
|
|
if (lv) |
|
|
do_add_new_subkey (lv, &keygen, k->flags); |
|
731 |
k->update = 1; |
k->update = 1; |
732 |
} |
|
733 |
free_if_alloc (pass); |
|
734 |
gpgme_editkey_release (ek); |
sfree_if_alloc (pass); |
735 |
gpgme_release (ctx); |
return cb.finished? TRUE: FALSE; |
736 |
|
} |
|
return ec? FALSE : TRUE; |
|
|
} /* keyedit_add_subkey */ |
|
737 |
|
|
738 |
|
|
739 |
BOOL |
BOOL |
740 |
keyedit_set_pref_keyserver (winpt_key_t k, HWND dlg) |
keyedit_set_pref_keyserver (winpt_key_t k, HWND dlg) |
741 |
{ |
{ |
742 |
gpgme_ctx_t ctx; |
GpgKeyEdit *ke; |
|
gpgme_editkey_t ek; |
|
743 |
gpgme_error_t err; |
gpgme_error_t err; |
744 |
struct URL_ctx_s *url; |
struct URL_ctx_s *url; |
745 |
char *pass; |
char *pass; |
756 |
return FALSE; |
return FALSE; |
757 |
} |
} |
758 |
|
|
759 |
err = gpgme_new (&ctx); |
ke = new GpgKeyEdit (k->keyid); |
760 |
if (!err) |
if (!ke) |
761 |
err = gpgme_editkey_new (&ek); |
BUG (NULL); |
762 |
if (err) |
ke->setPassphrase (pass); |
763 |
BUG (0); |
err = ke->setPreferredKeyserver (0 /* XXX */, url->url); |
|
gpgme_editkey_keyserver_set (ek, url->url, -1, pass); |
|
|
gpgme_set_edit_ctx (ctx, ek, GPGME_EDITKEY_KEYSERV); |
|
|
|
|
|
err = gpgme_op_editkey (ctx, k->keyid); |
|
764 |
if (!err) |
if (!err) |
765 |
msg_box (dlg, _("Preferred keyserver successfully set."), _("Key Edit"), MB_OK); |
msg_box (dlg, _("Preferred keyserver successfully set."), _("Key Edit"), MB_OK); |
766 |
|
|
767 |
gpgme_release (ctx); |
sfree_if_alloc (pass); |
768 |
gpgme_editkey_release (ek); |
delete ke; |
|
free_if_alloc (pass); |
|
769 |
delete url; |
delete url; |
770 |
return err == 0? 0 : WPTERR_GENERAL; |
return err == 0? 0 : WPTERR_GENERAL; |
771 |
} |
} |
772 |
|
|
773 |
|
|
774 |
BOOL |
BOOL |
775 |
keyedit_add_photo( winpt_key_t k, HWND dlg ) |
keyedit_add_photo (winpt_key_t k, HWND dlg) |
776 |
{ |
{ |
777 |
if( !k->key_pair ) { |
if (!k->key_pair) { |
778 |
msg_box( dlg, _("There is no secret key available!"), _("Add Photo"), MB_ERR ); |
msg_box( dlg, _("There is no secret key available!"), _("Add Photo"), MB_ERR ); |
779 |
return FALSE; |
return FALSE; |
780 |
} |
} |
791 |
msg_box( dlg, _("There is no secret key available!"), _("Add Revoker"), MB_ERR ); |
msg_box( dlg, _("There is no secret key available!"), _("Add Revoker"), MB_ERR ); |
792 |
return FALSE; |
return FALSE; |
793 |
} |
} |
794 |
DialogBoxParam( glob_hinst, (LPCTSTR)IDD_WINPT_KEYEDIT_ADDREV, dlg, |
DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_KEYEDIT_ADDREV, dlg, |
795 |
keyedit_addrevoker_dlg_proc, (LPARAM)k ); |
keyedit_addrevoker_dlg_proc, (LPARAM)k); |
796 |
return TRUE; |
return TRUE; |
797 |
} /* keyedit_add_revoker */ |
} /* keyedit_add_revoker */ |
798 |
|
|
799 |
|
|
800 |
static int |
static int |
801 |
is_idea_protect_algo( const char * keyid ) |
is_idea_protect_algo (const char * keyid) |
802 |
{ |
{ |
803 |
gpgme_key_t key; |
winpt_key_s k; |
804 |
const char * sym_prefs; |
const unsigned char *sym_prefs; |
805 |
size_t n; |
size_t n; |
806 |
|
|
807 |
if( get_pubkey( keyid, &key ) ) |
memset (&k, 0, sizeof (k)); |
808 |
BUG( NULL ); |
if (winpt_get_pubkey (keyid, &k)) |
809 |
sym_prefs = gpgme_key_get_string_attr( key, GPGME_ATTR_KEY_SYMPREFS, NULL, 0 ); |
BUG (NULL); |
810 |
|
sym_prefs = k.ext->sym_prefs; |
811 |
if (!sym_prefs) |
if (!sym_prefs) |
812 |
return 1; /* assume that only v3 keys have no symmetric cipher preferences |
return 1; /* assume that only v3 keys have no symmetric cipher preferences |
813 |
and thus IDEA is explicit. */ |
and thus IDEA is explicit. */ |
814 |
for( n = 0; sym_prefs[n]; n++ ) |
for (n = 0; sym_prefs[n]; n++) |
815 |
; |
; |
816 |
if( (n == 0 || n == 1) && *sym_prefs == 0x01 ) |
if ((n == 0 || n == 1) && *sym_prefs == 0x01) |
817 |
return 1; |
return 1; |
818 |
return 0; |
return 0; |
819 |
} /* is_idea_protect_algo */ |
} /* is_idea_protect_algo */ |
822 |
BOOL |
BOOL |
823 |
keyedit_change_passwd( winpt_key_t k, HWND dlg ) |
keyedit_change_passwd( winpt_key_t k, HWND dlg ) |
824 |
{ |
{ |
825 |
gpgme_error_t ec; |
GpgKeyEdit *ke; |
826 |
gpgme_ctx_t ctx; |
gpgme_error_t ec; |
827 |
gpgme_editkey_t ek; |
char *old_pass = NULL, *new_pass = NULL; |
|
char * old_pass = NULL, * new_pass = NULL; |
|
828 |
int cancel = 0; |
int cancel = 0; |
829 |
|
|
830 |
if( !k->key_pair ) { |
if( !k->key_pair ) { |
859 |
return FALSE; |
return FALSE; |
860 |
} |
} |
861 |
|
|
862 |
ec = gpgme_new( &ctx ); |
ke = new GpgKeyEdit (k->keyid); |
863 |
if( !ec ) |
if (!ke) |
864 |
ec = gpgme_editkey_new( &ek ); |
BUG (NULL); |
865 |
if( ec ) |
|
866 |
BUG( NULL ); |
ke->setPassphrase (k->is_protected? old_pass : NULL); |
867 |
gpgme_enable_logging( ctx ); |
ec = ke->changePassphrase (new_pass, 0); |
|
gpgme_editkey_passwd_set( ek, k->is_protected? old_pass : NULL, new_pass, 0 ); |
|
|
gpgme_set_edit_ctx( ctx, ek, GPGME_EDITKEY_PASSWD ); |
|
|
ec = gpgme_op_editkey( ctx, k->keyid ); |
|
868 |
if( ec ) |
if( ec ) |
869 |
gpgme_show_error (dlg, ec, ctx, _("Change Passwd"), MB_ERR); |
msg_box (dlg, gpgme_strerror (ec), _("Change Passwd"), MB_ERR); |
870 |
else |
else |
871 |
msg_box (dlg, _("Passphrase successfully changed."), _("GnuPG status"), MB_OK); |
msg_box (dlg, _("Passphrase successfully changed."), _("GnuPG status"), MB_OK); |
872 |
free_if_alloc (old_pass); |
sfree_if_alloc (old_pass); |
873 |
free_if_alloc (new_pass); |
sfree_if_alloc (new_pass); |
874 |
gpgme_editkey_release (ek); |
delete ke; |
|
gpgme_release (ctx); |
|
875 |
return TRUE; |
return TRUE; |
876 |
} /* keyedit_change_passwd */ |
} |
877 |
|
|
878 |
|
|
879 |
listview_ctrl_t |
listview_ctrl_t |
881 |
{ |
{ |
882 |
LV_ITEM lvi; |
LV_ITEM lvi; |
883 |
gpgme_key_t key; |
gpgme_key_t key; |
884 |
|
gpgme_subkey_t sub; |
885 |
struct listview_column_s cols[] = { |
struct listview_column_s cols[] = { |
886 |
{0, 80, (char *)_("Description")}, |
{0, 80, (char *)_("Description")}, |
887 |
{1, 78, (char *)_("Key ID")}, |
{1, 78, (char *)_("Key ID")}, |
897 |
listview_ctrl_t lv; |
listview_ctrl_t lv; |
898 |
char buf[256], tmp[128]; |
char buf[256], tmp[128]; |
899 |
const char *t; |
const char *t; |
900 |
int nkeys = 0, rc = 0, i, bits, j; |
int nkeys = 0, rc = 0, i, bits; |
901 |
|
|
902 |
if( get_pubkey( k->keyid, &key ) ) { |
if( get_pubkey( k->keyid, &key ) ) { |
903 |
msg_box( dlg, _("Could not find key."), _("Key Edit"), MB_ERR ); |
msg_box( dlg, _("Could not find key."), _("Key Edit"), MB_ERR ); |
904 |
return NULL; |
return NULL; |
905 |
} |
} |
906 |
|
nkeys = count_subkeys (key); |
|
nkeys = gpgme_key_count_items( key, GPGME_ATTR_KEYID ); |
|
907 |
if( !nkeys ) { |
if( !nkeys ) { |
908 |
msg_box( dlg, _("No subkey(s) found."), _("Key Edit"), MB_ERR ); |
msg_box( dlg, _("No subkey(s) found."), _("Key Edit"), MB_ERR ); |
909 |
return NULL; |
return NULL; |
928 |
} |
} |
929 |
|
|
930 |
listview_set_ext_style( lv ); |
listview_set_ext_style( lv ); |
931 |
for( i = 0; i < nkeys; i++ ) { |
for( i = 0, sub = key->subkeys; i < nkeys; i++, sub = sub->next ) { |
932 |
memset( buf, 0, sizeof buf ); |
memset( buf, 0, sizeof buf ); |
933 |
|
|
934 |
bits = gpgme_key_get_ulong_attr( key, GPGME_ATTR_LEN, NULL, i ); |
bits = sub->length; |
935 |
_snprintf( tmp, sizeof tmp-1, "%d-bit ", bits ); |
_snprintf( tmp, sizeof tmp-1, "%d-bit ", bits ); |
936 |
strcat( buf, tmp ); |
strcat( buf, tmp ); |
937 |
|
|
938 |
j = gpgme_key_get_ulong_attr( key, GPGME_ATTR_ALGO, NULL, i ); |
_snprintf( tmp, sizeof tmp-1, "%s", get_key_pubalgo (sub->pubkey_algo)); |
|
t = gpgme_key_expand_attr( GPGME_ATTR_ALGO, j ); |
|
|
_snprintf( tmp, sizeof tmp-1, "%s", t ); |
|
939 |
strcat( buf, tmp ); |
strcat( buf, tmp ); |
940 |
|
|
941 |
listview_add_sub_item( lv, i, 0, buf ); |
listview_add_sub_item( lv, i, 0, buf ); |
942 |
t = gpgme_key_get_string_attr( key, GPGME_ATTR_KEYID, NULL, i ); |
t = sub->keyid; |
943 |
if( !t ) |
if( !t ) |
944 |
t = "DEADBEEFDEADBEEF"; |
t = "DEADBEEFDEADBEEF"; |
945 |
_snprintf( tmp, sizeof tmp-1, "0x%s", t+8 ); |
_snprintf( tmp, sizeof tmp-1, "0x%s", t+8 ); |
946 |
listview_add_sub_item( lv, i, 1, tmp ); |
listview_add_sub_item( lv, i, 1, tmp ); |
947 |
|
|
948 |
j = gpgme_key_get_ulong_attr( key, GPGME_ATTR_CREATED, NULL, i ); |
t = get_key_created (sub->timestamp); |
|
t = gpgme_key_expand_attr( GPGME_ATTR_CREATED, j ); |
|
949 |
if( !t ) |
if( !t ) |
950 |
t = "????-??-??"; |
t = "????-??-??"; |
951 |
listview_add_sub_item( lv, i, 2, t ); |
listview_add_sub_item( lv, i, 2, t ); |
952 |
|
|
953 |
j = gpgme_key_get_ulong_attr( key, GPGME_ATTR_EXPIRES, NULL, i ); |
if( sub->expires ) { |
954 |
if( j ) { |
t = get_key_created (sub->expires); |
|
t = gpgme_key_expand_attr( GPGME_ATTR_CREATED, j ); |
|
955 |
listview_add_sub_item( lv, i, 3, t ); |
listview_add_sub_item( lv, i, 3, t ); |
956 |
} |
} |
957 |
else |
else |
958 |
listview_add_sub_item( lv, i, 3, _("Never") ); |
listview_add_sub_item( lv, i, 3, _("Never") ); |
959 |
|
|
960 |
if( gpgme_key_get_ulong_attr(key, GPGME_ATTR_KEY_EXPIRED, NULL, i ) ) |
if( sub->expired ) |
961 |
t = _("Expired"); |
t = _("Expired"); |
962 |
else if( gpgme_key_get_ulong_attr( key, GPGME_ATTR_KEY_REVOKED, NULL, i ) ) |
else if( sub->revoked ) |
963 |
t = _("Revoked"); |
t = _("Revoked"); |
964 |
else |
else |
965 |
t = _("OK"); |
t = _("OK"); |
966 |
listview_add_sub_item( lv, i, 4, t ); |
listview_add_sub_item( lv, i, 4, t ); |
967 |
|
|
968 |
gpgme_key_get_cability( key, GPGME_ATTR_CAN_CERTIFY, i )? |
if (sub->can_certify) t = "*"; else t = ""; |
969 |
t = "*" : t = ""; |
listview_add_sub_item (lv, i, 5, t); |
970 |
listview_add_sub_item( lv, i, 5, t ); |
if (sub->can_sign) t = "*"; else t = ""; |
|
gpgme_key_get_cability( key, GPGME_ATTR_CAN_SIGN, i )? |
|
|
t = "*" : t = ""; |
|
971 |
listview_add_sub_item( lv, i, 6, t ); |
listview_add_sub_item( lv, i, 6, t ); |
972 |
gpgme_key_get_cability( key, GPGME_ATTR_CAN_ENCRYPT, i )? |
if (sub->can_encrypt) t = "*"; else t = ""; |
|
t = "*" : t = ""; |
|
973 |
listview_add_sub_item( lv, i, 7, t ); |
listview_add_sub_item( lv, i, 7, t ); |
974 |
|
if (sub->can_authenticate) t = "*"; else t = ""; |
|
gpgme_key_get_cability (key, GPGME_ATTR_CAN_AUTH, i)? |
|
|
t = "*" : t = ""; |
|
975 |
listview_add_sub_item (lv, i, 8, t); |
listview_add_sub_item (lv, i, 8, t); |
976 |
} |
} |
977 |
return lv; |
return lv; |
983 |
{ |
{ |
984 |
listview_ctrl_t lv = NULL; |
listview_ctrl_t lv = NULL; |
985 |
gpgme_key_t key; |
gpgme_key_t key; |
986 |
|
gpgme_user_id_t u; |
987 |
int nuids = 0, rc, j, u_attr; |
int nuids = 0, rc, j, u_attr; |
988 |
struct listview_column_s cols[] = { |
struct listview_column_s cols[] = { |
989 |
{0, 72, (char *)_("Validity")}, |
{0, 72, (char *)_("Validity")}, |
998 |
msg_box( dlg, _("Could not find key."), _("Key Edit"), MB_ERR ); |
msg_box( dlg, _("Could not find key."), _("Key Edit"), MB_ERR ); |
999 |
return NULL; |
return NULL; |
1000 |
} |
} |
1001 |
|
|
1002 |
nuids = gpgme_key_count_items (key, GPGME_ATTR_USERID); |
nuids = count_userids (key); |
1003 |
if (!nuids) { |
if (!nuids) { |
1004 |
msg_box (dlg, _("No user ID(s) found."), _("Key Edit"), MB_ERR); |
msg_box (dlg, _("No user ID(s) found."), _("Key Edit"), MB_ERR); |
1005 |
return NULL; |
return NULL; |
1018 |
} |
} |
1019 |
|
|
1020 |
listview_set_ext_style (lv); |
listview_set_ext_style (lv); |
1021 |
for (j = 0; j < nuids; j++) { |
for (j = 0, u=key->uids; j < nuids; u=u->next, j++) { |
1022 |
if (gpgme_key_get_ulong_attr (key, GPGME_ATTR_UID_REVOKED, NULL, j)) |
if (u->revoked) |
1023 |
attr = _("Revoked"); |
attr = _("Revoked"); |
1024 |
else { |
else { |
1025 |
u_attr = gpgme_key_get_ulong_attr (key, GPGME_ATTR_VALIDITY, NULL, j); |
u_attr = (int)u->validity; |
1026 |
attr = gpgme_key_expand_attr (GPGME_ATTR_VALIDITY, u_attr); |
attr = get_key_trust2 (NULL, u_attr, 0, 0); |
1027 |
} |
} |
1028 |
listview_add_sub_item( lv, j, 0, (char *)attr ); |
listview_add_sub_item( lv, j, 0, (char *)attr ); |
1029 |
|
|
1030 |
/* XXX: add comment if available */ |
/* XXX: add comment if available */ |
1031 |
attr = gpgme_key_get_string_attr( key, GPGME_ATTR_NAME, NULL, j ); |
attr = u->name; |
1032 |
if (attr) { |
if (attr) { |
1033 |
char * uid = utf8_to_wincp (attr, strlen (attr)); |
char * uid = utf8_to_wincp (attr, strlen (attr)); |
1034 |
if (uid) { |
if (uid) { |
1038 |
} |
} |
1039 |
else |
else |
1040 |
listview_add_sub_item( lv, j, 1, _("Invalid user ID") ); |
listview_add_sub_item( lv, j, 1, _("Invalid user ID") ); |
1041 |
attr = gpgme_key_get_string_attr (key, GPGME_ATTR_EMAIL, NULL, j); |
attr = u->email; |
1042 |
if (attr) |
if (attr) |
1043 |
listview_add_sub_item (lv, j, 2, attr); |
listview_add_sub_item (lv, j, 2, attr); |
1044 |
u_attr = gpgme_key_get_ulong_attr (key, GPGME_ATTR_UID_CREATED, NULL, j); |
u_attr = 0; /* XXX: gpgme user-ids do not store a timestamp. */ |
1045 |
if (u_attr) |
if (u_attr) |
1046 |
listview_add_sub_item (lv, j, 3, get_key_created (u_attr)); |
listview_add_sub_item (lv, j, 3, get_key_created (u_attr)); |
1047 |
} |
} |
1143 |
static int |
static int |
1144 |
do_editkey_delkey (winpt_key_t k, HWND dlg, listview_ctrl_t lv) |
do_editkey_delkey (winpt_key_t k, HWND dlg, listview_ctrl_t lv) |
1145 |
{ |
{ |
1146 |
|
gpgme_error_t err; |
1147 |
|
GpgKeyEdit *ke; |
1148 |
int j, id; |
int j, id; |
1149 |
char tmp[64]; |
char tmp[64]; |
|
gpgme_error_t ec; |
|
|
gpgme_editkey_t ek; |
|
|
gpgme_ctx_t ctx; |
|
1150 |
|
|
1151 |
if (!k->key_pair) |
if (!k->key_pair) |
1152 |
return FALSE; /* XXX: shall we allow to modify non-secret keys?? */ |
return FALSE; /* XXX: shall we allow to modify non-secret keys?? */ |
1173 |
if( id == IDNO ) |
if( id == IDNO ) |
1174 |
return FALSE; |
return FALSE; |
1175 |
|
|
1176 |
ec = gpgme_new( &ctx ); |
ke = new GpgKeyEdit (k->keyid); |
1177 |
if( !ec ) |
if (!ke) |
1178 |
ec = gpgme_editkey_new( &ek ); |
BUG (NULL); |
1179 |
if( ec ) |
err = ke->delKey (j); |
1180 |
BUG( dlg ); |
if (err) |
1181 |
gpgme_enable_logging( ctx ); |
msg_box (dlg, gpgme_strerror (err), _("Delete Subkey"), MB_ERR); |
|
gpgme_editkey_delkey_set_id( ek, j ); |
|
|
gpgme_set_edit_ctx( ctx, ek, GPGME_EDITKEY_DELKEY ); |
|
|
ec = gpgme_op_editkey( ctx, k->keyid ); |
|
|
if( ec ) |
|
|
gpgme_show_error( dlg, ec, ctx, _("Delete Subkey"), MB_ERR ); |
|
1182 |
else { |
else { |
1183 |
listview_del_item( lv, j ); |
listview_del_item (lv, j); |
1184 |
k->update = 1; |
k->update = 1; |
1185 |
status_box( dlg, _("Subkey successfully deleted."), _("GnuPG status") ); |
status_box (dlg, _("Subkey successfully deleted."), _("GnuPG status")); |
1186 |
} |
} |
1187 |
gpgme_editkey_release( ek ); |
delete ke; |
1188 |
gpgme_release( ctx ); |
return err? FALSE : TRUE; |
|
return ec? FALSE : TRUE; |
|
1189 |
} /* do_editkey_delkey */ |
} /* do_editkey_delkey */ |
1190 |
|
|
1191 |
|
|
1192 |
static int |
static int |
1193 |
do_editkey_expire( winpt_key_t k, HWND dlg, listview_ctrl_t lv ) |
do_editkey_expire( winpt_key_t k, HWND dlg, listview_ctrl_t lv ) |
1194 |
{ |
{ |
1195 |
gpgme_error_t ec; |
gpgme_error_t err; |
1196 |
gpgme_editkey_t ek; |
GpgKeyEdit *ke; |
|
gpgme_ctx_t ctx; |
|
1197 |
date_s udd = {0}; |
date_s udd = {0}; |
1198 |
char buf[256], * pass = NULL; |
char buf[256], * pass = NULL; |
1199 |
int j, cancel = 0; |
int j, cancel = 0; |
1228 |
if( cancel ) |
if( cancel ) |
1229 |
return FALSE; |
return FALSE; |
1230 |
} |
} |
1231 |
_snprintf( buf, sizeof buf - 1, "%04d-%02d-%02d", |
|
1232 |
udd.st.wYear, udd.st.wMonth, udd.st.wDay ); |
ke = new GpgKeyEdit (k->keyid); |
1233 |
ec = gpgme_editkey_new( &ek ); |
if (!ke) |
1234 |
if( !ec ) |
BUG (NULL); |
1235 |
ec = gpgme_new( &ctx ); |
if (k->is_protected) |
1236 |
if( ec ) |
ke->setPassphrase (pass); |
1237 |
BUG( dlg ); |
err = ke->setKeyExpireDate (j, diff_time (NULL, &udd.st)); |
1238 |
gpgme_editkey_expire_set( ek, j, 0, buf, k->is_protected? pass : NULL ); |
if (err) |
1239 |
gpgme_enable_logging( ctx ); |
msg_box (dlg, gpgme_strerror (err), _("Expire Subkey"), MB_ERR); |
|
gpgme_set_edit_ctx( ctx, ek, GPGME_EDITKEY_EXPIRE ); |
|
|
ec = gpgme_op_editkey( ctx, k->keyid ); |
|
|
if( ec ) |
|
|
gpgme_show_error( dlg, ec, ctx, _("Expire Subkey"), MB_ERR ); |
|
1240 |
else { |
else { |
1241 |
|
_snprintf( buf, sizeof buf - 1, "%04d-%02d-%02d", |
1242 |
|
udd.st.wYear, udd.st.wMonth, udd.st.wDay ); |
1243 |
listview_add_sub_item( lv, j, 3, buf ); |
listview_add_sub_item( lv, j, 3, buf ); |
1244 |
k->update = 1; |
k->update = 1; |
1245 |
msg_box( dlg, _("Subkey expire date successfully set."), _("GnuPG status"), MB_OK ); |
msg_box( dlg, _("Subkey expire date successfully set."), _("GnuPG status"), MB_OK ); |
1246 |
} |
} |
1247 |
free_if_alloc( pass ); |
sfree_if_alloc (pass); |
1248 |
gpgme_release( ctx ); |
delete ke; |
|
gpgme_editkey_release( ek ); |
|
1249 |
return TRUE; |
return TRUE; |
1250 |
} /* do_editkey_expire */ |
} /* do_editkey_expire */ |
1251 |
|
|
1253 |
static int |
static int |
1254 |
do_editkey_revoke( winpt_key_t k, HWND dlg, listview_ctrl_t lv ) |
do_editkey_revoke( winpt_key_t k, HWND dlg, listview_ctrl_t lv ) |
1255 |
{ |
{ |
1256 |
gpgme_ctx_t ctx; |
gpgme_error_t err; |
1257 |
gpgme_error_t ec; |
GpgKeyEdit *ke; |
|
gpgme_editkey_t ek; |
|
1258 |
char buf[256], * pass = NULL; |
char buf[256], * pass = NULL; |
1259 |
int j, cancel = 0; |
int j, cancel = 0; |
1260 |
|
|
1261 |
if( !k->key_pair ) { |
if( !k->key_pair ) { |
1262 |
msg_box( dlg, _("There is no secret key available!"), _("Key Edit"), MB_ERR ); |
msg_box( dlg, _("There is no secret key available!"), _("Key Edit"), MB_ERR ); |
1263 |
return FALSE; |
return FALSE; |
|
|
|
1264 |
} |
} |
1265 |
|
|
1266 |
if( (j = listview_get_curr_pos( lv )) == -1 ) { |
if( (j = listview_get_curr_pos( lv )) == -1 ) { |
1286 |
if( cancel ) |
if( cancel ) |
1287 |
return FALSE; |
return FALSE; |
1288 |
} |
} |
1289 |
|
|
1290 |
ec = gpgme_editkey_new( &ek ); |
ke = new GpgKeyEdit (k->keyid); |
1291 |
if( !ec ) |
if (!ke) |
1292 |
ec = gpgme_new( &ctx ); |
BUG (NULL); |
1293 |
if( ec ) |
if (k->is_protected) |
1294 |
BUG( NULL ); |
ke->setPassphrase (pass); |
1295 |
gpgme_enable_logging( ctx ); |
err = ke->revokeKey (j, NULL); |
1296 |
gpgme_editkey_revkey_set( ek, j, 0, k->is_protected? pass : NULL ); |
if (err) |
1297 |
gpgme_set_edit_ctx( ctx, ek, GPGME_EDITKEY_REVKEY ); |
msg_box( dlg, gpgme_strerror (err), _("Revoke Subkey"), MB_ERR); |
|
ec = gpgme_op_editkey( ctx, k->keyid ); |
|
|
if( ec ) |
|
|
gpgme_show_error( dlg, ec, ctx, _("Revoke Subkey"), MB_ERR ); |
|
1298 |
else { |
else { |
1299 |
listview_add_sub_item( lv, j, 5, _("Revoked") ); |
listview_add_sub_item( lv, j, 5, _("Revoked") ); |
1300 |
k->update = 1; |
k->update = 1; |
1301 |
msg_box( dlg, _("Subkey successfully revoked."), _("GnuPG Status"), MB_OK ); |
msg_box( dlg, _("Subkey successfully revoked."), _("GnuPG Status"), MB_OK ); |
1302 |
} |
} |
1303 |
free_if_alloc( pass ); |
sfree_if_alloc( pass ); |
1304 |
gpgme_release( ctx ); |
delete ke; |
|
gpgme_editkey_release( ek ); |
|
1305 |
return TRUE; |
return TRUE; |
1306 |
} /* do_editkey_revoke */ |
} /* do_editkey_revoke */ |
1307 |
|
|
1309 |
int |
int |
1310 |
do_editkey_revuid (winpt_key_t k, HWND dlg, listview_ctrl_t lv) |
do_editkey_revuid (winpt_key_t k, HWND dlg, listview_ctrl_t lv) |
1311 |
{ |
{ |
1312 |
gpgme_ctx_t ctx; |
gpgme_error_t err; |
1313 |
gpgme_error_t ec; |
GpgKeyEdit *ke; |
|
gpgme_editkey_t ek; |
|
1314 |
char buf[256], t[512], * pass; |
char buf[256], t[512], * pass; |
1315 |
int cancel = 0, id = 0, j; |
int cancel = 0, id = 0, j; |
1316 |
|
|
1348 |
id = do_find_userid (k->keyid, buf, NULL); |
id = do_find_userid (k->keyid, buf, NULL); |
1349 |
if (id == -1) |
if (id == -1) |
1350 |
BUG (dlg); |
BUG (dlg); |
1351 |
ec = gpgme_new (&ctx); |
|
1352 |
if (!ec) |
ke = new GpgKeyEdit (k->keyid); |
1353 |
ec = gpgme_editkey_new (&ek); |
if (!ke) |
1354 |
if( ec ) |
BUG (NULL); |
1355 |
BUG( dlg ); |
if (k->is_protected) |
1356 |
gpgme_enable_logging( ctx ); |
ke->setPassphrase (pass); |
1357 |
gpgme_editkey_revsig_set( ek, id, k->is_protected? pass : NULL ); |
err = ke->revokeSignature (id, 0); |
1358 |
gpgme_set_edit_ctx( ctx, ek, GPGME_EDITKEY_REVSIG ); |
if (err) |
1359 |
ec = gpgme_op_editkey( ctx, k->keyid ); |
msg_box (dlg, gpgme_strerror (err), _("Revoke Signature"), MB_ERR); |
|
if (ec) |
|
|
gpgme_show_error (dlg, ec, ctx, _("Revoke Signature"), MB_ERR); |
|
1360 |
else { |
else { |
1361 |
listview_add_sub_item (lv, j, 0, _("Revoked")); |
listview_add_sub_item (lv, j, 0, _("Revoked")); |
1362 |
k->update = 1; |
k->update = 1; |
1363 |
status_box (dlg, _("User ID successfully revoked"), _("GnuPG Status")); |
status_box (dlg, _("User ID successfully revoked"), _("GnuPG Status")); |
1364 |
} |
} |
1365 |
free_if_alloc (pass); |
sfree_if_alloc (pass); |
1366 |
gpgme_editkey_release (ek); |
delete ke; |
1367 |
gpgme_release (ctx); |
return err? FALSE : TRUE; |
|
return ec? FALSE : TRUE; |
|
1368 |
} /* do_editkey_revuid */ |
} /* do_editkey_revuid */ |
1369 |
|
|
1370 |
|
|
1371 |
static int |
static int |
1372 |
do_editkey_setpref (winpt_key_t k, HWND dlg, listview_ctrl_t lv) |
do_editkey_setpref (winpt_key_t k, HWND dlg, listview_ctrl_t lv) |
1373 |
{ |
{ |
|
gpgme_ctx_t ctx; |
|
|
gpgme_editkey_t ek; |
|
1374 |
gpgme_error_t rc; |
gpgme_error_t rc; |
1375 |
|
GpgKeyEdit *ke; |
1376 |
char buf[256], * pass = NULL, * prefs; |
char buf[256], * pass = NULL, * prefs; |
1377 |
int j, id, cancel=0, flags=0; |
int j, id, cancel=0, flags=0; |
1378 |
|
|
1389 |
if (cancel) |
if (cancel) |
1390 |
return FALSE; |
return FALSE; |
1391 |
} |
} |
1392 |
rc = gpgme_new (&ctx); |
|
1393 |
if (!rc) |
ke = new GpgKeyEdit (k->keyid); |
1394 |
rc = gpgme_editkey_new (&ek); |
if (!ke) |
|
if (rc) |
|
1395 |
BUG (NULL); |
BUG (NULL); |
1396 |
|
if (k->is_protected) |
1397 |
|
ke->setPassphrase (pass); |
1398 |
|
|
1399 |
get_userid_preflist (&prefs, &flags); |
get_userid_preflist (&prefs, &flags); |
|
gpgme_editkey_setpref_set (ek, prefs, id, pass); |
|
|
gpgme_set_edit_ctx (ctx, ek, GPGME_EDITKEY_SETPREF); |
|
|
rc = gpgme_op_editkey (ctx, k->keyid); |
|
|
free_if_alloc (pass); |
|
1400 |
|
|
1401 |
|
rc = ke->setUseridPreferences (id, prefs); |
1402 |
|
/* XXX */ |
1403 |
|
|
1404 |
|
sfree_if_alloc (pass); |
1405 |
free_if_alloc (prefs); |
free_if_alloc (prefs); |
1406 |
gpgme_release (ctx); |
delete ke; |
|
gpgme_editkey_release (ek); |
|
1407 |
return 0; |
return 0; |
1408 |
} |
} |
1409 |
|
|
1411 |
static int |
static int |
1412 |
do_editkey_primary (winpt_key_t k, HWND dlg, listview_ctrl_t lv) |
do_editkey_primary (winpt_key_t k, HWND dlg, listview_ctrl_t lv) |
1413 |
{ |
{ |
1414 |
gpgme_ctx_t ctx; |
gpgme_error_t err; |
1415 |
gpgme_editkey_t ek; |
GpgKeyEdit *ke; |
|
gpgme_error_t ec; |
|
1416 |
int j, id, cancel=0; |
int j, id, cancel=0; |
1417 |
char buf[256], * pass = NULL; |
char buf[256], * pass = NULL; |
1418 |
|
|
1422 |
msg_box( dlg, _("Please select a user ID."), _("Key Edit"), MB_ERR ); |
msg_box( dlg, _("Please select a user ID."), _("Key Edit"), MB_ERR ); |
1423 |
return FALSE; |
return FALSE; |
1424 |
} |
} |
1425 |
listview_get_item_text( lv, j, 1, buf, sizeof buf-1 ); |
listview_get_item_text (lv, j, 1, buf, sizeof buf-1); |
1426 |
id = do_find_userid (k->keyid, buf, NULL); |
id = do_find_userid (k->keyid, buf, NULL); |
1427 |
if (id == -1) |
if (id == -1) |
1428 |
BUG( dlg ); |
BUG( dlg ); |
1429 |
if (k->is_protected) { |
if (k->is_protected) { |
1430 |
pass = request_passphrase( _("Key Edit"), 1, &cancel ); |
pass = request_passphrase (_("Key Edit"), 1, &cancel); |
1431 |
if( cancel ) |
if( cancel ) |
1432 |
return FALSE; |
return FALSE; |
1433 |
} |
} |
1434 |
|
|
1435 |
ec = gpgme_new( &ctx ); |
ke = new GpgKeyEdit (k->keyid); |
1436 |
if( !ec ) |
if (k->is_protected) |
1437 |
ec = gpgme_editkey_new( &ek ); |
ke->setPassphrase (pass); |
1438 |
if( ec ) |
err = ke->setPrimaryUserid (id); |
1439 |
BUG( dlg ); |
if (err) |
1440 |
gpgme_enable_logging( ctx ); |
msg_box (dlg, gpgme_strerror (err), _("Primary"), MB_ERR); |
|
gpgme_editkey_primary_set( ek, id, k->is_protected? pass : NULL ); |
|
|
gpgme_set_edit_ctx( ctx, ek, GPGME_EDITKEY_PRIMARY ); |
|
|
ec = gpgme_op_editkey( ctx, k->keyid ); |
|
|
if( ec ) |
|
|
gpgme_show_error( dlg, ec, ctx, _("Primary"), MB_ERR ); |
|
1441 |
else { |
else { |
1442 |
k->update = 1; |
k->update = 1; |
1443 |
status_box( dlg, _("User ID successfully flagged"), _("GnuPG Status") ); |
status_box (dlg, _("User ID successfully flagged"), _("GnuPG Status")); |
1444 |
} |
} |
1445 |
|
|
1446 |
free_if_alloc( pass ); |
sfree_if_alloc (pass); |
1447 |
gpgme_editkey_release( ek ); |
delete ke; |
1448 |
gpgme_release( ctx ); |
return err? FALSE : TRUE; |
1449 |
return ec? FALSE : TRUE; |
} |
|
} /* do_editkey_primary */ |
|
1450 |
|
|
1451 |
|
|
1452 |
static int |
static int |
1484 |
return n; |
return n; |
1485 |
} |
} |
1486 |
|
|
1487 |
|
|
1488 |
|
/* Dialog box procedure to show the key preferences. */ |
1489 |
BOOL CALLBACK |
BOOL CALLBACK |
1490 |
showpref_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
showpref_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
1491 |
{ |
{ |
1492 |
static keyedit_callback_s *cb = NULL; |
static keyedit_callback_s *cb = NULL; |
1493 |
gpgme_uidinfo_t inf=NULL; |
gpg_uid_info_t inf=NULL; |
1494 |
char buf[128]; |
char buf[128]; |
1495 |
int pos; |
int pos; |
1496 |
|
|
1503 |
SetDlgItemText (dlg, IDC_SHOWPREF_INFO, buf); |
SetDlgItemText (dlg, IDC_SHOWPREF_INFO, buf); |
1504 |
pos = do_find_userid (((winpt_key_t)cb->opaque)->keyid, buf, &inf); |
pos = do_find_userid (((winpt_key_t)cb->opaque)->keyid, buf, &inf); |
1505 |
if (inf) { |
if (inf) { |
1506 |
const char *prefs; |
const char *prefs = inf->prefs; |
|
prefs = gpgme_editkey_get_string_attr (inf, GPGME_ATTR_UID_PREFS, pos-1); |
|
1507 |
if (prefs && *prefs) { |
if (prefs && *prefs) { |
1508 |
if (parse_preflist (dlg, prefs) <= 0) |
if (parse_preflist (dlg, prefs) <= 0) |
1509 |
pos = -1; |
pos = -1; |
1510 |
} |
} |
1511 |
else |
else |
1512 |
pos = -1; |
pos = -1; |
1513 |
gpgme_uid_info_release (inf); |
gpg_uid_info_release (inf); |
1514 |
if (pos == -1) { |
if (pos == -1) { |
1515 |
msg_box (dlg, _("No preferences available."), _("Key Edit"), MB_ERR); |
msg_box (dlg, _("No preferences available."), _("Key Edit"), MB_ERR); |
1516 |
EndDialog (dlg, TRUE); |
EndDialog (dlg, TRUE); |
1517 |
} |
} |
1518 |
if (gpgme_editkey_get_ulong_attr (inf, GPGME_ATTR_MDC, 0)) |
if (inf->flags.mdc) |
1519 |
CheckDlgButton (dlg, IDC_SHOWPREF_MDC, BST_CHECKED); |
CheckDlgButton (dlg, IDC_SHOWPREF_MDC, BST_CHECKED); |
1520 |
} |
} |
1521 |
SetForegroundWindow (dlg); |
SetForegroundWindow (dlg); |
1532 |
return FALSE; |
return FALSE; |
1533 |
} |
} |
1534 |
|
|
1535 |
|
|
1536 |
static int |
static int |
1537 |
do_editkey_showpref (winpt_key_t k, HWND dlg, listview_ctrl_t lv) |
do_editkey_showpref (winpt_key_t k, HWND dlg, listview_ctrl_t lv) |
1538 |
{ |
{ |
1539 |
struct keyedit_callback_s cb; |
struct keyedit_callback_s cb; |
1540 |
|
|
1541 |
|
if (k->is_v3) |
1542 |
|
return TRUE; |
1543 |
|
|
1544 |
if (listview_get_curr_pos (lv) == -1) { |
if (listview_get_curr_pos (lv) == -1) { |
1545 |
msg_box (dlg, _("Please select a user ID."), _("Key Edit"), MB_ERR); |
msg_box (dlg, _("Please select a user ID."), _("Key Edit"), MB_ERR); |
1546 |
return FALSE; |
return FALSE; |
1551 |
cb.opaque = k; |
cb.opaque = k; |
1552 |
DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_KEYEDIT_SHOWPREF, dlg, |
DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_KEYEDIT_SHOWPREF, dlg, |
1553 |
showpref_dlg_proc, (LPARAM)&cb); |
showpref_dlg_proc, (LPARAM)&cb); |
1554 |
return 0; |
return TRUE; |
1555 |
} |
} |
1556 |
|
|
1557 |
|
|
1558 |
static int |
static int |
1559 |
do_editkey_deluid (winpt_key_t k, HWND dlg, listview_ctrl_t lv) |
do_editkey_deluid (winpt_key_t k, HWND dlg, listview_ctrl_t lv) |
1560 |
{ |
{ |
1561 |
gpgme_ctx_t ctx; |
gpgme_error_t err; |
1562 |
gpgme_editkey_t ek; |
GpgKeyEdit *ke; |
|
gpgme_error_t ec; |
|
1563 |
char buf[256], t[512]; |
char buf[256], t[512]; |
1564 |
int j, id = 0; |
int j, id = 0; |
1565 |
|
|
1587 |
id = do_find_userid (k->keyid, buf, NULL); |
id = do_find_userid (k->keyid, buf, NULL); |
1588 |
if (id == -1) |
if (id == -1) |
1589 |
BUG (dlg); |
BUG (dlg); |
1590 |
ec = gpgme_new( &ctx ); |
|
1591 |
if( !ec ) |
ke = new GpgKeyEdit (k->keyid); |
1592 |
ec = gpgme_editkey_new( &ek ); |
if (!ke) |
1593 |
if( ec ) |
BUG (NULL); |
1594 |
BUG( dlg ); |
|
1595 |
gpgme_enable_logging( ctx ); |
err = ke->delUserid (id); |
1596 |
gpgme_editkey_deluid_set_id( ek, id ); |
if( err ) |
1597 |
gpgme_set_edit_ctx( ctx, ek, GPGME_EDITKEY_DELUID ); |
msg_box( dlg, gpgme_strerror (err), _("Delete user ID"), MB_ERR ); |
|
ec = gpgme_op_editkey( ctx, k->keyid ); |
|
|
if( ec ) |
|
|
gpgme_show_error( dlg, ec, ctx, _("Delete user ID"), MB_ERR ); |
|
1598 |
else { |
else { |
1599 |
listview_del_item( lv, j ); |
listview_del_item( lv, j ); |
1600 |
k->update = 1; |
k->update = 1; |
1601 |
status_box( dlg, _("User ID successfully deleted"), _("GnuPG Status") ); |
status_box( dlg, _("User ID successfully deleted"), _("GnuPG Status") ); |
1602 |
} |
} |
1603 |
gpgme_editkey_release( ek ); |
delete ke; |
1604 |
gpgme_release( ctx ); |
return err? FALSE : TRUE; |
|
return ec? FALSE : TRUE; |
|
1605 |
} /* do_editkey_deluid */ |
} /* do_editkey_deluid */ |
1606 |
|
|
1607 |
|
|
1699 |
EnableWindow (GetDlgItem (dlg, IDOK), FALSE); |
EnableWindow (GetDlgItem (dlg, IDOK), FALSE); |
1700 |
} |
} |
1701 |
SetForegroundWindow( dlg ); |
SetForegroundWindow( dlg ); |
1702 |
center_window( dlg ); |
center_window( dlg, NULL ); |
1703 |
return TRUE; |
return TRUE; |
1704 |
|
|
1705 |
case WM_DESTROY: |
case WM_DESTROY: |