1 |
/* wptCardDlg.cpp - Smart Card support |
/* wptCardDlg.cpp - Smart Card support |
2 |
* Copyright (C) 2003, 2004, 2005 Timo Schulz |
* Copyright (C) 2003, 2004, 2005 Timo Schulz |
3 |
|
* Copyright (C) 2005 g10 Code GmbH |
4 |
* |
* |
5 |
* This file is part of WinPT. |
* This file is part of WinPT. |
6 |
* |
* |
36 |
#include "wptUTF8.h" |
#include "wptUTF8.h" |
37 |
#include "wptCardEdit.h" |
#include "wptCardEdit.h" |
38 |
#include "wptCard.h" |
#include "wptCard.h" |
39 |
|
#include "wptContext.h" |
40 |
|
|
41 |
int keygen_check_date (SYSTEMTIME * st); |
int keygen_check_date (SYSTEMTIME * st); |
42 |
|
|
58 |
{IDC_CEDIT_NAME, "No Name"}, |
{IDC_CEDIT_NAME, "No Name"}, |
59 |
{IDC_CEDIT_NAME2, "No Surname"}, |
{IDC_CEDIT_NAME2, "No Surname"}, |
60 |
{IDC_CEDIT_KEYURL, "No Key-URL"}, |
{IDC_CEDIT_KEYURL, "No Key-URL"}, |
61 |
{IDC_CEDIT_LOGIN, "No Login name"}, |
{IDC_CEDIT_LOGIN, "No Login name"}, |
62 |
{0}, |
{0}, |
63 |
}; |
}; |
64 |
|
|
65 |
|
|
66 |
|
|
67 |
|
/* XXX: simplify code. */ |
68 |
|
char* |
69 |
|
get_printable_version (const char *version) |
70 |
|
{ |
71 |
|
static char buf[16]; |
72 |
|
char tmp_maj[3]={0}, tmp_min[3]={0}; |
73 |
|
|
74 |
|
strncpy (tmp_maj, version, 2); |
75 |
|
strncpy (tmp_min, version+2, 2); |
76 |
|
sprintf (buf, "%d.%d", atoi (tmp_maj), atoi (tmp_min)); |
77 |
|
return buf; |
78 |
|
} |
79 |
|
|
80 |
/* Return all card attributes from @card. @n contains |
/* Return all card attributes from @card. @n contains |
81 |
the number of items which were returned. */ |
the number of items which were returned. */ |
82 |
char** |
char** |
90 |
BUG (0); |
BUG (0); |
91 |
p[0] = card->aid; |
p[0] = card->aid; |
92 |
p[1] = card->vendor; |
p[1] = card->vendor; |
93 |
p[2] = card->ver; |
p[2] = get_printable_version (card->version); |
94 |
p[3] = card->serial; |
p[3] = card->serial; |
95 |
p[4] = card->givenname; |
p[4] = card->givenname; |
96 |
p[5] = card->surname; |
p[5] = card->surname; |
109 |
if (!_lang) |
if (!_lang) |
110 |
return 0; |
return 0; |
111 |
for (i=0; (s = lang[i]); i++) { |
for (i=0; (s = lang[i]); i++) { |
112 |
if (!strcmp( _lang, s )) |
if (!strcmp (_lang, s )) |
113 |
return i; |
return i; |
114 |
} |
} |
115 |
return 0; |
return 0; |
140 |
returned information. |
returned information. |
141 |
Return value: card context or NULL on error. */ |
Return value: card context or NULL on error. */ |
142 |
gpg_card_t |
gpg_card_t |
143 |
gpg_load_scard (void) |
gpg_card_load (void) |
144 |
{ |
{ |
145 |
gpgme_error_t err; |
gpgme_error_t err; |
146 |
GpgCardEdit *ce; |
GpgCardEdit *ce; |
163 |
gpg_card_release (card); |
gpg_card_release (card); |
164 |
card = NULL; |
card = NULL; |
165 |
} |
} |
166 |
|
else { |
167 |
|
struct winpt_key_s key; |
168 |
|
memset (&key, 0, sizeof (key)); |
169 |
|
winpt_get_pubkey (card->fpr[1]+32, &key); |
170 |
|
if (key.ext) { |
171 |
|
key.ext->card_type = strdup (card->card_type); |
172 |
|
if (!key.ext->card_type) |
173 |
|
BUG (NULL); |
174 |
|
/* memory will be released in gpg_keycache_release (). */ |
175 |
|
} |
176 |
|
} |
177 |
|
|
178 |
leave: |
leave: |
179 |
delete ce; |
delete ce; |
213 |
card_status (HWND dlg, gpg_card_t card) |
card_status (HWND dlg, gpg_card_t card) |
214 |
{ |
{ |
215 |
static int fprbuf[] = {IDC_CEDIT_FPR1, IDC_CEDIT_FPR2, IDC_CEDIT_FPR3, 0}; |
static int fprbuf[] = {IDC_CEDIT_FPR1, IDC_CEDIT_FPR2, IDC_CEDIT_FPR3, 0}; |
216 |
const char * s; |
static int fprtime[] = {IDC_CEDIT_SIG_FPRTIME, IDC_CEDIT_DEC_FPRTIME, IDC_CEDIT_AUTH_FPRTIME, 0}; |
217 |
|
const char *s; |
218 |
char **attrs; |
char **attrs; |
219 |
|
char cardinf[128]; |
220 |
int idx=0, n=0; |
int idx=0, n=0; |
221 |
|
|
222 |
if (!card->aid) { |
if (!card->aid) { |
226 |
SetDlgItemText (dlg, IDC_CEDIT_AID, card->aid); |
SetDlgItemText (dlg, IDC_CEDIT_AID, card->aid); |
227 |
SetDlgItemInt (dlg, IDC_CEDIT_SIGCOUNT, card->sig_count, TRUE); |
SetDlgItemInt (dlg, IDC_CEDIT_SIGCOUNT, card->sig_count, TRUE); |
228 |
|
|
229 |
for( idx=0; fprbuf[idx]; idx++ ) |
for (idx=0; fprbuf[idx]; idx++) { |
230 |
print_fpr (dlg, fprbuf[idx], card->fpr[idx]); |
print_fpr (dlg, fprbuf[idx], card->fpr[idx]); |
231 |
|
SetDlgItemText (dlg, fprtime[idx], card->fpr_created_str[idx]); |
232 |
|
} |
233 |
|
|
234 |
attrs = card_get_items (card, &n); |
attrs = card_get_items (card, &n); |
|
/* XXX: show version as 1.1 not 0101 */ |
|
235 |
for (idx=1; attr_tab[idx].ctlid; idx++) { |
for (idx=1; attr_tab[idx].ctlid; idx++) { |
236 |
s = attrs[idx]; |
s = attrs[idx]; |
237 |
SetDlgItemText (dlg, attr_tab[idx].ctlid, s && *s? s : attr_tab[idx].err); |
SetDlgItemText (dlg, attr_tab[idx].ctlid, s && *s? s : attr_tab[idx].err); |
249 |
} |
} |
250 |
SendDlgItemMessage (dlg, IDC_CEDIT_SEX, CB_SETCURSEL, (WPARAM)idx, 0); |
SendDlgItemMessage (dlg, IDC_CEDIT_SEX, CB_SETCURSEL, (WPARAM)idx, 0); |
251 |
|
|
252 |
|
s = card->serial; |
253 |
|
while (s && *s == '0') s++; |
254 |
|
_snprintf (cardinf, sizeof (cardinf)-1, |
255 |
|
"Card Edit - %s serial no. %s version %s", |
256 |
|
card->card_type, s, get_printable_version (card->version)); |
257 |
|
SetWindowText (dlg, cardinf); |
258 |
|
|
259 |
return 0; |
return 0; |
260 |
} |
} |
261 |
|
|
267 |
const char * s; |
const char * s; |
268 |
int i; |
int i; |
269 |
|
|
270 |
for( i=0; (s = sex[i]); i++ ) |
for (i=0; (s = sex[i]); i++) |
271 |
SendDlgItemMessage( dlg, IDC_CEDIT_SEX, CB_ADDSTRING, 0, (LPARAM) s ); |
SendDlgItemMessage (dlg, IDC_CEDIT_SEX, CB_ADDSTRING, 0, (LPARAM) s); |
272 |
SendDlgItemMessage( dlg, IDC_CEDIT_SEX, CB_SETCURSEL, 0, 0 ); |
SendDlgItemMessage (dlg, IDC_CEDIT_SEX, CB_SETCURSEL, 0, 0); |
273 |
for( i=0; (s = lang[i]); i++ ) |
for (i=0; (s = lang[i]); i++) |
274 |
SendDlgItemMessage( dlg, IDC_CEDIT_LANG, CB_ADDSTRING, 0, (LPARAM)s ); |
SendDlgItemMessage (dlg, IDC_CEDIT_LANG, CB_ADDSTRING, 0, (LPARAM)s); |
275 |
SendDlgItemMessage( dlg, IDC_CEDIT_LANG, CB_SETCURSEL, 0, 0 ); |
SendDlgItemMessage (dlg, IDC_CEDIT_LANG, CB_SETCURSEL, 0, 0); |
276 |
} |
} |
277 |
|
|
278 |
|
|
|
|
|
279 |
/* Return 0 if the given string @str has the proper format. */ |
/* Return 0 if the given string @str has the proper format. */ |
280 |
static int |
static int |
281 |
check_string (const char *str, int flags) |
check_string (const char *str, int flags) |
282 |
{ |
{ |
283 |
size_t i; |
size_t i; |
284 |
for( i=0; i < strlen( str ); i++ ) { |
for (i=0; i < strlen (str); i++) { |
285 |
if( flags & 0x02 && !isalpha( str[i] ) ) |
if (flags & 0x02 && !isalpha (str[i])) |
286 |
return -1; |
return -1; |
287 |
} |
} |
288 |
return 0; |
return 0; |
290 |
|
|
291 |
|
|
292 |
static int |
static int |
293 |
do_proc_card_cmds (HWND dlg, struct pin_cb_ctx_s * pincb, gpg_card_t card) |
do_proc_card_cmds (HWND dlg, struct pin_cb_ctx_s *pincb, gpg_card_t card) |
294 |
{ |
{ |
295 |
static struct { |
static struct { |
296 |
int id; |
int id; |
301 |
{IDC_CEDIT_NAME, GPG_EDITCARD_NAME, 1, 0}, |
{IDC_CEDIT_NAME, GPG_EDITCARD_NAME, 1, 0}, |
302 |
{IDC_CEDIT_LANG2, GPG_EDITCARD_LANG, 1, 0}, |
{IDC_CEDIT_LANG2, GPG_EDITCARD_LANG, 1, 0}, |
303 |
{IDC_CEDIT_SEX2, GPG_EDITCARD_SEX, 1|1,0}, |
{IDC_CEDIT_SEX2, GPG_EDITCARD_SEX, 1|1,0}, |
304 |
{IDC_CEDIT_KEYURL,GPG_EDITCARD_KEYURL,1, 0}, |
{IDC_CEDIT_KEYURL,GPG_EDITCARD_KEYURL,1|4,0}, |
305 |
{IDC_CEDIT_LOGIN, GPG_EDITCARD_LOGIN, 1, 0}, |
{IDC_CEDIT_LOGIN, GPG_EDITCARD_LOGIN, 1, 0}, |
306 |
{0} |
{0} |
307 |
}; |
}; |
334 |
n++; |
n++; |
335 |
} |
} |
336 |
} |
} |
337 |
if( !pincb || !card ) /* just return the changed elements */ |
if (!pincb || !card) /* just return the changed elements */ |
338 |
return n; |
return n; |
339 |
if( !n ) |
if (!n) |
340 |
|
return 0; |
341 |
|
if (!pincb->apin) { |
342 |
|
msg_box (dlg, _("No PINs found."), _("Card Edit"), MB_ERR); |
343 |
return 0; |
return 0; |
344 |
|
} |
345 |
|
|
346 |
ce = new GpgCardEdit (); |
ce = new GpgCardEdit (); |
347 |
if (!ce) |
if (!ce) |
348 |
BUG( NULL ); |
BUG (NULL); |
349 |
ce->setAdminPIN (pincb->apin); |
ce->setAdminPIN (pincb->apin); |
350 |
ce->setPIN (pincb->upin); |
/*ce->setPIN (pincb->upin);*/ |
351 |
for( i=0; idctl[i].id; i++ ) { |
for( i=0; idctl[i].id; i++ ) { |
352 |
if( idctl[i].changed ) { |
if( idctl[i].changed ) { |
353 |
GetDlgItemText( dlg, idctl[i].id, buf, sizeof (buf)-1 ); |
GetDlgItemText( dlg, idctl[i].id, buf, sizeof (buf)-1 ); |
361 |
_("Card Edit"), MB_ERR ); |
_("Card Edit"), MB_ERR ); |
362 |
errc--; continue; |
errc--; continue; |
363 |
} |
} |
364 |
|
if ((idctl[i].us_ascii & 4) && |
365 |
|
(!strchr (buf, ':') || !strstr (buf, "//"))) { |
366 |
|
/* XXX: better URL check. */ |
367 |
|
msg_box (dlg, _("Invalid URL."), _("Card Edit"), MB_ERR); |
368 |
|
errc--; continue; |
369 |
|
} |
370 |
if( idctl[i].cmd == GPG_EDITCARD_NAME ) { |
if( idctl[i].cmd == GPG_EDITCARD_NAME ) { |
371 |
/* The "name" command actually needs two fields */ |
/* The "name" command actually needs two fields */ |
372 |
GetDlgItemText( dlg, IDC_CEDIT_NAME2, tmp, sizeof tmp-1 ); |
GetDlgItemText( dlg, IDC_CEDIT_NAME2, tmp, sizeof tmp-1 ); |
376 |
use_arg2 = 0; |
use_arg2 = 0; |
377 |
err = ce->doCmd (idctl[i].cmd, buf, use_arg2? tmp : NULL); |
err = ce->doCmd (idctl[i].cmd, buf, use_arg2? tmp : NULL); |
378 |
if (err) { |
if (err) { |
379 |
msg_box( dlg, _("Could not modify card attribute."), |
log_box (_("Card Edit"), MB_ERR, |
380 |
_("Card Edit"), MB_ERR ); |
_("Could not modify card attribute: %s"), |
381 |
|
gpgme_strerror (err)); |
382 |
errc--; |
errc--; |
383 |
|
/* If no card is inserted, we leave the loop. */ |
384 |
|
if (gpgme_err_code (err) == GPG_ERR_CARD_NOT_PRESENT) |
385 |
|
break; |
386 |
} |
} |
387 |
} |
} |
388 |
} |
} |
389 |
if( !errc ) { |
if (!errc) { |
390 |
/* if the operation(s) succeeded, reset the modify flag for each control */ |
/* if the operation(s) succeeded, reset the modify flag for each control */ |
391 |
for( i = 0; idctl[i].id; i++ ) |
for( i = 0; idctl[i].id; i++ ) |
392 |
SendDlgItemMessage( dlg, idctl[i].id, EM_SETMODIFY, (WPARAM)(UINT)FALSE, 0 ); |
SendDlgItemMessage( dlg, idctl[i].id, EM_SETMODIFY, (WPARAM)(UINT)FALSE, 0 ); |
425 |
char * p; |
char * p; |
426 |
size_t n; |
size_t n; |
427 |
|
|
428 |
if( (which == GPG_EDITCARD_CHAPIN && pincb->apin) || |
if( (which == CARD_ADMIN_PIN && pincb->apin) || |
429 |
(which == GPG_EDITCARD_CHUPIN && pincb->upin) ) |
(which == CARD_USER_PIN && pincb->upin) ) |
430 |
return 0; |
return 0; |
431 |
|
|
432 |
if( which == GPG_EDITCARD_CHAPIN ) |
if (which == CARD_ADMIN_PIN) |
433 |
s = _("Please enter the 'Admin PIN'"); |
s = _("Please enter the 'Admin PIN'"); |
434 |
else if( which == GPG_EDITCARD_CHUPIN ) |
else if (which == CARD_USER_PIN) |
435 |
s = _("Please enter the 'User PIN'"); |
s = _("Please enter the 'User PIN'"); |
436 |
else |
else |
437 |
s = _("Please enter the PIN"); |
s = _("Please enter the PIN"); |
459 |
BUG (0); |
BUG (0); |
460 |
} |
} |
461 |
DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_PIN, dlg, |
DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_PIN, dlg, |
462 |
pin_cb_dlg_proc, (LPARAM)pincb); |
pin_cb_dlg_proc, (LPARAM)pincb); |
463 |
if (!pincb->apin && !pincb->upin) { |
if (!pincb->apin && !pincb->upin) { |
464 |
safe_free (pincb->info_text); |
safe_free (pincb->info_text); |
465 |
return -1; |
return -1; |
489 |
return TRUE; |
return TRUE; |
490 |
|
|
491 |
case WM_DESTROY: |
case WM_DESTROY: |
492 |
free_if_alloc (pincb.info_text); |
free_pincb (&pincb); |
|
sfree_if_alloc (pincb.apin); |
|
|
sfree_if_alloc (pincb.upin); |
|
493 |
memset (&pincb, 0, sizeof pincb); |
memset (&pincb, 0, sizeof pincb); |
494 |
break; |
break; |
495 |
|
|
505 |
case IDC_CEDIT_LANG: dstid = IDC_CEDIT_LANG2; break; |
case IDC_CEDIT_LANG: dstid = IDC_CEDIT_LANG2; break; |
506 |
case IDC_CEDIT_SEX: dstid = IDC_CEDIT_SEX2; break; |
case IDC_CEDIT_SEX: dstid = IDC_CEDIT_SEX2; break; |
507 |
} |
} |
508 |
GetDlgItemText (dlg, ctlid, tmp, 127); |
GetDlgItemText (dlg, ctlid, tmp, sizeof (tmp)-1); |
509 |
SetDlgItemText (dlg, dstid, tmp); |
SetDlgItemText (dlg, dstid, tmp); |
510 |
break; |
break; |
511 |
} |
} |
512 |
switch( LOWORD( wparam ) ) { |
switch (LOWORD (wparam)) { |
513 |
case IDC_CEDIT_CHPIN: |
case IDC_CEDIT_CHPIN: |
514 |
DialogBoxParam( glob_hinst, (LPCTSTR)IDD_WINPT_CARD_CHPIN, dlg, |
DialogBoxParam( glob_hinst, (LPCTSTR)IDD_WINPT_CARD_CHPIN, dlg, |
515 |
card_changepin_dlg_proc, NULL ); |
card_changepin_dlg_proc, NULL ); |
528 |
break; |
break; |
529 |
|
|
530 |
case IDOK: |
case IDOK: |
531 |
n = do_proc_card_cmds( dlg, NULL, NULL ); |
n = do_proc_card_cmds (dlg, NULL, NULL); |
532 |
if( n ) { |
if (n) { |
533 |
if( do_askpin( dlg, GPG_EDITCARD_CHAPIN, card, &pincb ) ) |
if (do_askpin (dlg, CARD_ADMIN_PIN, card, &pincb)) |
534 |
EndDialog( dlg, FALSE ); |
EndDialog (dlg, FALSE); |
535 |
if( do_askpin( dlg, GPG_EDITCARD_CHUPIN, card, &pincb ) ) |
} |
536 |
EndDialog( dlg, FALSE ); |
do_proc_card_cmds (dlg, &pincb, card); |
537 |
} |
free_pincb (&pincb); |
538 |
do_proc_card_cmds( dlg, &pincb, card ); |
if (!n) |
539 |
free_pincb( &pincb ); |
EndDialog (dlg, TRUE); |
|
if( !n ) |
|
|
EndDialog( dlg, TRUE ); |
|
540 |
break; |
break; |
541 |
|
|
542 |
case IDCANCEL: |
case IDCANCEL: |
573 |
BOOL CALLBACK |
BOOL CALLBACK |
574 |
card_keygen_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
card_keygen_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
575 |
{ |
{ |
|
static int state = 0; |
|
|
static int pwd_state = 0; |
|
576 |
gpgme_error_t err; |
gpgme_error_t err; |
577 |
GpgCardEdit *ce; |
GpgCardEdit *ce; |
578 |
char name[128], email[128], comment[128]; |
char name[128], email[128], comment[128]; |
583 |
|
|
584 |
switch (msg) { |
switch (msg) { |
585 |
case WM_INITDIALOG: |
case WM_INITDIALOG: |
|
state = 0; |
|
|
pwd_state = 1; |
|
586 |
center_window (dlg, NULL); |
center_window (dlg, NULL); |
587 |
CheckDlgButton (dlg, IDC_CKEYGEN_REPLACE, BST_CHECKED); |
CheckDlgButton (dlg, IDC_CKEYGEN_REPLACE, BST_CHECKED); |
588 |
CheckDlgButton (dlg, IDC_CKEYGEN_NEVER, BST_CHECKED); |
CheckDlgButton (dlg, IDC_CKEYGEN_NEVER, BST_CHECKED); |
589 |
CheckDlgButton (dlg, IDC_CKEYGEN_BACKUP, BST_CHECKED); |
CheckDlgButton (dlg, IDC_CKEYGEN_BACKUP, BST_CHECKED); |
590 |
EnableWindow (GetDlgItem (dlg, IDC_CKEYGEN_VALID), FALSE); |
EnableWindow (GetDlgItem (dlg, IDC_CKEYGEN_VALID), FALSE); |
591 |
SendDlgItemMessage (dlg, IDC_CKEYGEN_ALG, CB_ADDSTRING, 0, (LPARAM)(const char*)"RSA"); |
SendDlgItemMessage (dlg, IDC_CKEYGEN_ALG, CB_ADDSTRING, 0, |
592 |
|
(LPARAM)(const char*)"RSA"); |
593 |
SendDlgItemMessage (dlg, IDC_CKEYGEN_ALG, CB_SETCURSEL, 0, 0); |
SendDlgItemMessage (dlg, IDC_CKEYGEN_ALG, CB_SETCURSEL, 0, 0); |
594 |
SetFocus (GetDlgItem (dlg, IDC_CKEYGEN_NAME)); |
SetFocus (GetDlgItem (dlg, IDC_CKEYGEN_NAME)); |
595 |
SetForegroundWindow (dlg); |
SetForegroundWindow (dlg); |
596 |
return FALSE; |
return FALSE; |
597 |
|
|
598 |
|
case WM_SYSCOMMAND: |
599 |
|
if (LOWORD (wparam) == SC_CLOSE) |
600 |
|
EndDialog (dlg, TRUE); |
601 |
|
return FALSE; |
602 |
|
|
603 |
case WM_COMMAND: |
case WM_COMMAND: |
604 |
if (HIWORD (wparam) == BN_CLICKED) { |
if (HIWORD (wparam) == BN_CLICKED && |
605 |
switch (LOWORD (wparam)) { |
(LOWORD (wparam) == IDC_CKEYGEN_BACKUP) || |
606 |
case IDC_CKEYGEN_NEVER: |
LOWORD (wparam) == IDC_CKEYGEN_NEVER) { |
607 |
state ^= 1; |
EnableWindow (GetDlgItem (dlg, IDC_CKEYGEN_VALID), |
608 |
EnableWindow (GetDlgItem (dlg, IDC_CKEYGEN_VALID), state); |
IsDlgButtonChecked (dlg, IDC_CKEYGEN_NEVER)? 0: 1); |
609 |
break; |
EnableWindow (GetDlgItem (dlg, IDC_CKEYGEN_PASS), |
610 |
|
IsDlgButtonChecked (dlg, IDC_CKEYGEN_BACKUP)? 1 : 0); |
611 |
case IDC_CKEYGEN_BACKUP: |
return TRUE; |
612 |
pwd_state ^= 1; |
} |
|
EnableWindow (GetDlgItem (dlg, IDC_CKEYGEN_PASS), pwd_state); |
|
|
break; |
|
|
} |
|
|
} |
|
613 |
|
|
614 |
switch (LOWORD (wparam)) { |
switch (LOWORD (wparam)) { |
615 |
case IDOK: |
case IDOK: |
637 |
return TRUE; |
return TRUE; |
638 |
} |
} |
639 |
n = GetDlgItemText (dlg, IDC_CKEYGEN_PASS, pass, sizeof (pass)-1); |
n = GetDlgItemText (dlg, IDC_CKEYGEN_PASS, pass, sizeof (pass)-1); |
640 |
if (!n && pwd_state == 1) { |
if (!n && IsDlgButtonChecked (dlg, IDC_CKEYGEN_BACKUP)) { |
641 |
msg_box (dlg, _("Please enter an off-card passphrase."), _("Card Edit"), MB_ERR); |
msg_box (dlg, _("Please enter an off-card passphrase."), _("Card Edit"), MB_ERR); |
642 |
return TRUE; |
return TRUE; |
643 |
} |
} |
644 |
n = item_get_text_length (dlg, IDC_CKEYGEN_COMMENT); |
n = item_get_text_length (dlg, IDC_CKEYGEN_COMMENT); |
645 |
if (n > 0) |
if (n > 0) |
646 |
GetDlgItemText (dlg, IDC_CKEYGEN_COMMENT, comment, sizeof (comment)-1); |
GetDlgItemText (dlg, IDC_CKEYGEN_COMMENT, comment, sizeof (comment)-1); |
647 |
if (is_8bit_string (name) ||is_8bit_string (comment)) { |
if (is_8bit_string (name) || n > 0 && is_8bit_string (comment)) { |
648 |
msg_box (dlg, _("Please use plain ASCII charset for the fields."), |
msg_box (dlg, _("Please use plain ASCII charset for the fields."), |
649 |
_("Card Edit"), MB_INFO); |
_("Card Edit"), MB_INFO); |
650 |
return TRUE; |
return TRUE; |
651 |
} |
} |
652 |
memset (&pincb, 0, sizeof (pincb)); |
memset (&pincb, 0, sizeof (pincb)); |
653 |
if (do_askpin (dlg, GPG_EDITCARD_CHAPIN, NULL, &pincb)) { |
if (do_askpin (dlg, CARD_ADMIN_PIN, NULL, &pincb)) { |
654 |
free_pincb (&pincb); |
free_pincb (&pincb); |
655 |
return TRUE; |
return TRUE; |
656 |
} |
} |
657 |
if (do_askpin (dlg, GPG_EDITCARD_CHUPIN, NULL, &pincb)) { |
if (do_askpin (dlg, CARD_USER_PIN, NULL, &pincb)) { |
658 |
free_pincb (&pincb); |
free_pincb (&pincb); |
659 |
return TRUE; |
return TRUE; |
660 |
} |
} |
669 |
if (!keygen_check_date (&st)) { |
if (!keygen_check_date (&st)) { |
670 |
msg_box (dlg, _("The date you have chosen lies in the past."), |
msg_box (dlg, _("The date you have chosen lies in the past."), |
671 |
_("Card Edit"), MB_ERR); |
_("Card Edit"), MB_ERR); |
672 |
|
free_pincb (&pincb); |
673 |
delete ce; |
delete ce; |
674 |
return TRUE; |
return TRUE; |
675 |
} |
} |
686 |
ce->setPIN (pincb.upin); |
ce->setPIN (pincb.upin); |
687 |
ce->setAdminPIN (pincb.apin); |
ce->setAdminPIN (pincb.apin); |
688 |
|
|
689 |
SetCursor( LoadCursor (NULL, IDC_WAIT)); |
SetCursor (LoadCursor (NULL, IDC_WAIT)); |
690 |
err = ce->genKey (card_flags, name, email, n? comment: NULL, |
err = ce->genKey (card_flags, name, email, n? comment: NULL, |
691 |
expires? valid : 0); |
expires? valid : 0, NULL); |
692 |
|
|
693 |
SetCursor (LoadCursor (NULL, IDC_ARROW)); |
SetCursor (LoadCursor (NULL, IDC_ARROW)); |
694 |
/* |
|
695 |
if (gpgme_err_code (err) == GPG_ERR_CANCELLED) |
if (gpgme_err_code (err) == GPG_ERR_CANCELED) |
696 |
msg_box (dlg, _("Operation was canceled. It seems that there are " |
msg_box (dlg, _("Operation was canceled. It seems that there are " |
697 |
"existing\nkeys on the cards. You need to mark the " |
"existing\nkeys on the cards. You need to mark the " |
698 |
"'Overwrite' flag."), _("Card Edit"), MB_INFO); |
"'Overwrite' flag."), _("Card Edit"), MB_INFO); |
699 |
else */ |
else |
700 |
if (err) |
if (err) |
701 |
msg_box (dlg, "The operation does not succeed.\n" |
msg_box (dlg, "The operation does not succeed.\n" |
702 |
"Please make sure you entered the right PIN's." |
"Please make sure you entered the right PIN's." |
707 |
memset (pass, 0, sizeof (pass)); |
memset (pass, 0, sizeof (pass)); |
708 |
free_pincb (&pincb); |
free_pincb (&pincb); |
709 |
delete ce; |
delete ce; |
710 |
break; |
return TRUE; |
711 |
|
|
712 |
case IDCANCEL: |
case IDCANCEL: |
713 |
EndDialog (dlg, FALSE); |
EndDialog (dlg, FALSE); |
733 |
msg_box (NULL, _("Please enter the new card PIN."), _("Card Edit"), MB_ERR); |
msg_box (NULL, _("Please enter the new card PIN."), _("Card Edit"), MB_ERR); |
734 |
return -1; |
return -1; |
735 |
} |
} |
736 |
if (which == GPG_EDITCARD_CHAPIN |
if (which == CARD_ADMIN_PIN |
737 |
&& pinlen < 8) { |
&& pinlen < 8) { |
738 |
msg_box (NULL, _("Admin PIN must be minimal 8 characters."), _("Card Edit"), MB_ERR); |
msg_box (NULL, _("Admin PIN must be minimal 8 characters."), _("Card Edit"), MB_ERR); |
739 |
return -1; |
return -1; |
740 |
} |
} |
741 |
if (which == GPG_EDITCARD_CHUPIN |
if (which == CARD_USER_PIN |
742 |
&& pinlen < 6) { |
&& pinlen < 6) { |
743 |
msg_box (NULL, _("PIN must be minimal 6 characters."), _("Card Edit"), MB_ERR); |
msg_box (NULL, _("PIN must be minimal 6 characters."), _("Card Edit"), MB_ERR); |
744 |
return -1; |
return -1; |
770 |
if (HIWORD (wparam) == BN_CLICKED && LOWORD (wparam) == IDC_CHPIN_HIDE) { |
if (HIWORD (wparam) == BN_CLICKED && LOWORD (wparam) == IDC_CHPIN_HIDE) { |
771 |
HWND hwnd; |
HWND hwnd; |
772 |
hide ^= 1; |
hide ^= 1; |
773 |
|
hwnd = GetDlgItem (dlg, IDC_CHPIN_OLDPIN); |
774 |
|
SendMessage (hwnd, EM_SETPASSWORDCHAR, hide? '*' : 0, 0); |
775 |
|
SetFocus (hwnd); |
776 |
hwnd = GetDlgItem (dlg, IDC_CHPIN_NEWPIN); |
hwnd = GetDlgItem (dlg, IDC_CHPIN_NEWPIN); |
777 |
SendMessage (hwnd, EM_SETPASSWORDCHAR, hide? '*' : 0, 0); |
SendMessage (hwnd, EM_SETPASSWORDCHAR, hide? '*' : 0, 0); |
778 |
SetFocus (hwnd); |
SetFocus (hwnd); |
783 |
switch( LOWORD( wparam ) ) { |
switch( LOWORD( wparam ) ) { |
784 |
case IDOK: |
case IDOK: |
785 |
if (IsDlgButtonChecked (dlg, IDC_CHPIN_ISADMIN)) |
if (IsDlgButtonChecked (dlg, IDC_CHPIN_ISADMIN)) |
786 |
which = GPG_EDITCARD_CHAPIN; |
which = CARD_ADMIN_PIN; |
787 |
else if (IsDlgButtonChecked (dlg, IDC_CHPIN_ISWORK)) |
else if (IsDlgButtonChecked (dlg, IDC_CHPIN_ISWORK)) |
788 |
which = GPG_EDITCARD_CHUPIN; |
which = CARD_USER_PIN; |
|
else |
|
|
BUG (0); |
|
789 |
|
|
790 |
n = item_get_text_length (dlg, IDC_CHPIN_OLDPIN); |
n = item_get_text_length (dlg, IDC_CHPIN_OLDPIN); |
791 |
if (check_pin_len (which, 1, n)) |
if (check_pin_len (which, 1, n)) |
800 |
GetDlgItemText (dlg, IDC_CHPIN_NEWPIN, pnew, sizeof (pnew)-1); |
GetDlgItemText (dlg, IDC_CHPIN_NEWPIN, pnew, sizeof (pnew)-1); |
801 |
GetDlgItemText (dlg, IDC_CHPIN_NEWPIN2, pnew2, sizeof (pnew2)-1); |
GetDlgItemText (dlg, IDC_CHPIN_NEWPIN2, pnew2, sizeof (pnew2)-1); |
802 |
if (strcmp (pnew, pnew2)) { |
if (strcmp (pnew, pnew2)) { |
803 |
msg_box (dlg, _("Passphrases do not match. Please try again."), _("Card Edit"), MB_ERR); |
msg_box (dlg, _("Passphrases do not match. Please try again."), |
804 |
|
_("Card Edit"), MB_ERR); |
805 |
return TRUE; |
return TRUE; |
806 |
} |
} |
807 |
|
|
808 |
ce = new GpgCardEdit (); |
ce = new GpgCardEdit (); |
809 |
if (!ce) |
if (!ce) |
810 |
BUG (0); |
BUG (0); |
811 |
ce->setPIN (pold); |
if (which == CARD_ADMIN_PIN) |
812 |
|
ce->setAdminPIN (pold); |
813 |
|
else |
814 |
|
ce->setPIN (pold); |
815 |
ce->setNewPIN (pnew); |
ce->setNewPIN (pnew); |
816 |
ce->setType (which); |
err = ce->changePIN (which == CARD_ADMIN_PIN? GPG_EDITCARD_CHAPIN : |
817 |
|
GPG_EDITCARD_CHUPIN); |
|
err = ce->changePIN (); |
|
818 |
if (err) |
if (err) |
819 |
msg_box (dlg, gpgme_strerror (err), _("Card Edit"), MB_ERR); |
msg_box (dlg, gpgme_strerror (err), _("Card Edit"), MB_ERR); |
820 |
else { |
else { |
821 |
msg_box( dlg, _("PIN successfully changed."), _("Card Edit"), MB_OK ); |
msg_box (dlg, _("PIN successfully changed."), |
822 |
|
_("Card Edit"), MB_OK); |
823 |
SetDlgItemText (dlg, IDC_CHPIN_NEWPIN, ""); |
SetDlgItemText (dlg, IDC_CHPIN_NEWPIN, ""); |
824 |
SetDlgItemText (dlg, IDC_CHPIN_OLDPIN, ""); |
SetDlgItemText (dlg, IDC_CHPIN_OLDPIN, ""); |
825 |
SetDlgItemText (dlg, IDC_CHPIN_NEWPIN2, ""); |
SetDlgItemText (dlg, IDC_CHPIN_NEWPIN2, ""); |
826 |
} |
} |
827 |
|
memset (pold, 0, sizeof (pold)); |
828 |
|
memset (pnew, 0, sizeof (pnew)); |
829 |
|
memset (pnew2, 0, sizeof (pnew2)); |
830 |
delete ce; |
delete ce; |
831 |
break; |
break; |
832 |
|
|
834 |
SetDlgItemText (dlg, IDC_CHPIN_NEWPIN, ""); |
SetDlgItemText (dlg, IDC_CHPIN_NEWPIN, ""); |
835 |
SetDlgItemText (dlg, IDC_CHPIN_OLDPIN, ""); |
SetDlgItemText (dlg, IDC_CHPIN_OLDPIN, ""); |
836 |
SetDlgItemText (dlg, IDC_CHPIN_NEWPIN2, ""); |
SetDlgItemText (dlg, IDC_CHPIN_NEWPIN2, ""); |
837 |
EndDialog( dlg, FALSE ); |
EndDialog (dlg, FALSE); |
838 |
break; |
break; |
839 |
} |
} |
840 |
break; |
break; |