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 |
* |
* |
57 |
{IDC_CEDIT_NAME, "No Name"}, |
{IDC_CEDIT_NAME, "No Name"}, |
58 |
{IDC_CEDIT_NAME2, "No Surname"}, |
{IDC_CEDIT_NAME2, "No Surname"}, |
59 |
{IDC_CEDIT_KEYURL, "No Key-URL"}, |
{IDC_CEDIT_KEYURL, "No Key-URL"}, |
60 |
{IDC_CEDIT_LOGIN, "No Login name"}, |
{IDC_CEDIT_LOGIN, "No Login name"}, |
61 |
{0}, |
{0}, |
62 |
}; |
}; |
63 |
|
|
64 |
|
|
65 |
|
|
66 |
|
/* XXX: simplify code. */ |
67 |
|
char* |
68 |
|
get_printable_version (const char *version) |
69 |
|
{ |
70 |
|
static char buf[16]; |
71 |
|
char tmp_maj[3]={0}, tmp_min[3]={0}; |
72 |
|
|
73 |
|
strncpy (tmp_maj, version, 2); |
74 |
|
strncpy (tmp_min, version+2, 2); |
75 |
|
sprintf (buf, "%d.%d", atoi (tmp_maj), atoi (tmp_min)); |
76 |
|
return buf; |
77 |
|
} |
78 |
|
|
79 |
/* Return all card attributes from @card. @n contains |
/* Return all card attributes from @card. @n contains |
80 |
the number of items which were returned. */ |
the number of items which were returned. */ |
81 |
char** |
char** |
89 |
BUG (0); |
BUG (0); |
90 |
p[0] = card->aid; |
p[0] = card->aid; |
91 |
p[1] = card->vendor; |
p[1] = card->vendor; |
92 |
p[2] = card->ver; |
p[2] = get_printable_version (card->version); |
93 |
p[3] = card->serial; |
p[3] = card->serial; |
94 |
p[4] = card->givenname; |
p[4] = card->givenname; |
95 |
p[5] = card->surname; |
p[5] = card->surname; |
108 |
if (!_lang) |
if (!_lang) |
109 |
return 0; |
return 0; |
110 |
for (i=0; (s = lang[i]); i++) { |
for (i=0; (s = lang[i]); i++) { |
111 |
if (!strcmp( _lang, s )) |
if (!strcmp (_lang, s )) |
112 |
return i; |
return i; |
113 |
} |
} |
114 |
return 0; |
return 0; |
139 |
returned information. |
returned information. |
140 |
Return value: card context or NULL on error. */ |
Return value: card context or NULL on error. */ |
141 |
gpg_card_t |
gpg_card_t |
142 |
gpg_load_scard (void) |
gpg_card_load (void) |
143 |
{ |
{ |
144 |
gpgme_error_t err; |
gpgme_error_t err; |
145 |
GpgCardEdit *ce; |
GpgCardEdit *ce; |
201 |
card_status (HWND dlg, gpg_card_t card) |
card_status (HWND dlg, gpg_card_t card) |
202 |
{ |
{ |
203 |
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}; |
204 |
const char * s; |
static int fprtime[] = {IDC_CEDIT_SIG_FPRTIME, IDC_CEDIT_DEC_FPRTIME, IDC_CEDIT_AUTH_FPRTIME, 0}; |
205 |
|
const char *s; |
206 |
char **attrs; |
char **attrs; |
207 |
|
char cardinf[128]; |
208 |
int idx=0, n=0; |
int idx=0, n=0; |
209 |
|
|
210 |
if (!card->aid) { |
if (!card->aid) { |
214 |
SetDlgItemText (dlg, IDC_CEDIT_AID, card->aid); |
SetDlgItemText (dlg, IDC_CEDIT_AID, card->aid); |
215 |
SetDlgItemInt (dlg, IDC_CEDIT_SIGCOUNT, card->sig_count, TRUE); |
SetDlgItemInt (dlg, IDC_CEDIT_SIGCOUNT, card->sig_count, TRUE); |
216 |
|
|
217 |
for( idx=0; fprbuf[idx]; idx++ ) |
for (idx=0; fprbuf[idx]; idx++) { |
218 |
print_fpr (dlg, fprbuf[idx], card->fpr[idx]); |
print_fpr (dlg, fprbuf[idx], card->fpr[idx]); |
219 |
|
SetDlgItemText (dlg, fprtime[idx], card->fpr_created_str[idx]); |
220 |
|
} |
221 |
|
|
222 |
attrs = card_get_items (card, &n); |
attrs = card_get_items (card, &n); |
|
/* XXX: show version as 1.1 not 0101 */ |
|
223 |
for (idx=1; attr_tab[idx].ctlid; idx++) { |
for (idx=1; attr_tab[idx].ctlid; idx++) { |
224 |
s = attrs[idx]; |
s = attrs[idx]; |
225 |
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); |
237 |
} |
} |
238 |
SendDlgItemMessage (dlg, IDC_CEDIT_SEX, CB_SETCURSEL, (WPARAM)idx, 0); |
SendDlgItemMessage (dlg, IDC_CEDIT_SEX, CB_SETCURSEL, (WPARAM)idx, 0); |
239 |
|
|
240 |
|
s = card->serial; |
241 |
|
while (s && *s == '0') s++; |
242 |
|
_snprintf (cardinf, sizeof (cardinf)-1, |
243 |
|
"Card Edit - OpenPGP card no. %s version %s", |
244 |
|
s, get_printable_version (card->version)); |
245 |
|
SetWindowText (dlg, cardinf); |
246 |
|
|
247 |
return 0; |
return 0; |
248 |
} |
} |
249 |
|
|
255 |
const char * s; |
const char * s; |
256 |
int i; |
int i; |
257 |
|
|
258 |
for( i=0; (s = sex[i]); i++ ) |
for (i=0; (s = sex[i]); i++) |
259 |
SendDlgItemMessage( dlg, IDC_CEDIT_SEX, CB_ADDSTRING, 0, (LPARAM) s ); |
SendDlgItemMessage (dlg, IDC_CEDIT_SEX, CB_ADDSTRING, 0, (LPARAM) s); |
260 |
SendDlgItemMessage( dlg, IDC_CEDIT_SEX, CB_SETCURSEL, 0, 0 ); |
SendDlgItemMessage (dlg, IDC_CEDIT_SEX, CB_SETCURSEL, 0, 0); |
261 |
for( i=0; (s = lang[i]); i++ ) |
for (i=0; (s = lang[i]); i++) |
262 |
SendDlgItemMessage( dlg, IDC_CEDIT_LANG, CB_ADDSTRING, 0, (LPARAM)s ); |
SendDlgItemMessage (dlg, IDC_CEDIT_LANG, CB_ADDSTRING, 0, (LPARAM)s); |
263 |
SendDlgItemMessage( dlg, IDC_CEDIT_LANG, CB_SETCURSEL, 0, 0 ); |
SendDlgItemMessage (dlg, IDC_CEDIT_LANG, CB_SETCURSEL, 0, 0); |
264 |
} |
} |
265 |
|
|
266 |
|
|
270 |
check_string (const char *str, int flags) |
check_string (const char *str, int flags) |
271 |
{ |
{ |
272 |
size_t i; |
size_t i; |
273 |
for( i=0; i < strlen( str ); i++ ) { |
for (i=0; i < strlen (str); i++) { |
274 |
if( flags & 0x02 && !isalpha( str[i] ) ) |
if (flags & 0x02 && !isalpha (str[i])) |
275 |
return -1; |
return -1; |
276 |
} |
} |
277 |
return 0; |
return 0; |
279 |
|
|
280 |
|
|
281 |
static int |
static int |
282 |
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) |
283 |
{ |
{ |
284 |
static struct { |
static struct { |
285 |
int id; |
int id; |
290 |
{IDC_CEDIT_NAME, GPG_EDITCARD_NAME, 1, 0}, |
{IDC_CEDIT_NAME, GPG_EDITCARD_NAME, 1, 0}, |
291 |
{IDC_CEDIT_LANG2, GPG_EDITCARD_LANG, 1, 0}, |
{IDC_CEDIT_LANG2, GPG_EDITCARD_LANG, 1, 0}, |
292 |
{IDC_CEDIT_SEX2, GPG_EDITCARD_SEX, 1|1,0}, |
{IDC_CEDIT_SEX2, GPG_EDITCARD_SEX, 1|1,0}, |
293 |
{IDC_CEDIT_KEYURL,GPG_EDITCARD_KEYURL,1, 0}, |
{IDC_CEDIT_KEYURL,GPG_EDITCARD_KEYURL,1|4,0}, |
294 |
{IDC_CEDIT_LOGIN, GPG_EDITCARD_LOGIN, 1, 0}, |
{IDC_CEDIT_LOGIN, GPG_EDITCARD_LOGIN, 1, 0}, |
295 |
{0} |
{0} |
296 |
}; |
}; |
323 |
n++; |
n++; |
324 |
} |
} |
325 |
} |
} |
326 |
if( !pincb || !card ) /* just return the changed elements */ |
if (!pincb || !card) /* just return the changed elements */ |
327 |
return n; |
return n; |
328 |
if( !n ) |
if (!n) |
329 |
|
return 0; |
330 |
|
if (!pincb->apin) { |
331 |
|
msg_box (dlg, _("No PINs found."), _("Card Edit"), MB_ERR); |
332 |
return 0; |
return 0; |
333 |
|
} |
334 |
|
|
335 |
ce = new GpgCardEdit (); |
ce = new GpgCardEdit (); |
336 |
if (!ce) |
if (!ce) |
337 |
BUG( NULL ); |
BUG (NULL); |
338 |
ce->setAdminPIN (pincb->apin); |
ce->setAdminPIN (pincb->apin); |
339 |
ce->setPIN (pincb->upin); |
/*ce->setPIN (pincb->upin);*/ |
340 |
for( i=0; idctl[i].id; i++ ) { |
for( i=0; idctl[i].id; i++ ) { |
341 |
if( idctl[i].changed ) { |
if( idctl[i].changed ) { |
342 |
GetDlgItemText( dlg, idctl[i].id, buf, sizeof (buf)-1 ); |
GetDlgItemText( dlg, idctl[i].id, buf, sizeof (buf)-1 ); |
350 |
_("Card Edit"), MB_ERR ); |
_("Card Edit"), MB_ERR ); |
351 |
errc--; continue; |
errc--; continue; |
352 |
} |
} |
353 |
|
if ((idctl[i].us_ascii & 4) && |
354 |
|
(!strchr (buf, ':') || !strstr (buf, "//"))) { |
355 |
|
/* XXX: better URL check. */ |
356 |
|
msg_box (dlg, _("Invalid URL."), _("Card Edit"), MB_ERR); |
357 |
|
errc--; continue; |
358 |
|
} |
359 |
if( idctl[i].cmd == GPG_EDITCARD_NAME ) { |
if( idctl[i].cmd == GPG_EDITCARD_NAME ) { |
360 |
/* The "name" command actually needs two fields */ |
/* The "name" command actually needs two fields */ |
361 |
GetDlgItemText( dlg, IDC_CEDIT_NAME2, tmp, sizeof tmp-1 ); |
GetDlgItemText( dlg, IDC_CEDIT_NAME2, tmp, sizeof tmp-1 ); |
365 |
use_arg2 = 0; |
use_arg2 = 0; |
366 |
err = ce->doCmd (idctl[i].cmd, buf, use_arg2? tmp : NULL); |
err = ce->doCmd (idctl[i].cmd, buf, use_arg2? tmp : NULL); |
367 |
if (err) { |
if (err) { |
368 |
msg_box( dlg, _("Could not modify card attribute."), |
log_box (_("Card Edit"), MB_ERR, |
369 |
_("Card Edit"), MB_ERR ); |
_("Could not modify card attribute: %s"), |
370 |
|
gpgme_strerror (err)); |
371 |
errc--; |
errc--; |
372 |
|
/* If no card is inserted, we leave the loop. */ |
373 |
|
if (gpgme_err_code (err) == GPG_ERR_CARD_REMOVED) |
374 |
|
break; |
375 |
} |
} |
376 |
} |
} |
377 |
} |
} |
378 |
if( !errc ) { |
if (!errc) { |
379 |
/* if the operation(s) succeeded, reset the modify flag for each control */ |
/* if the operation(s) succeeded, reset the modify flag for each control */ |
380 |
for( i = 0; idctl[i].id; i++ ) |
for( i = 0; idctl[i].id; i++ ) |
381 |
SendDlgItemMessage( dlg, idctl[i].id, EM_SETMODIFY, (WPARAM)(UINT)FALSE, 0 ); |
SendDlgItemMessage( dlg, idctl[i].id, EM_SETMODIFY, (WPARAM)(UINT)FALSE, 0 ); |
414 |
char * p; |
char * p; |
415 |
size_t n; |
size_t n; |
416 |
|
|
417 |
if( (which == GPG_EDITCARD_CHAPIN && pincb->apin) || |
if( (which == CARD_ADMIN_PIN && pincb->apin) || |
418 |
(which == GPG_EDITCARD_CHUPIN && pincb->upin) ) |
(which == CARD_USER_PIN && pincb->upin) ) |
419 |
return 0; |
return 0; |
420 |
|
|
421 |
if( which == GPG_EDITCARD_CHAPIN ) |
if (which == CARD_ADMIN_PIN) |
422 |
s = _("Please enter the 'Admin PIN'"); |
s = _("Please enter the 'Admin PIN'"); |
423 |
else if( which == GPG_EDITCARD_CHUPIN ) |
else if (which == CARD_USER_PIN) |
424 |
s = _("Please enter the 'User PIN'"); |
s = _("Please enter the 'User PIN'"); |
425 |
else |
else |
426 |
s = _("Please enter the PIN"); |
s = _("Please enter the PIN"); |
448 |
BUG (0); |
BUG (0); |
449 |
} |
} |
450 |
DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_PIN, dlg, |
DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_PIN, dlg, |
451 |
pin_cb_dlg_proc, (LPARAM)pincb); |
pin_cb_dlg_proc, (LPARAM)pincb); |
452 |
if (!pincb->apin && !pincb->upin) { |
if (!pincb->apin && !pincb->upin) { |
453 |
safe_free (pincb->info_text); |
safe_free (pincb->info_text); |
454 |
return -1; |
return -1; |
478 |
return TRUE; |
return TRUE; |
479 |
|
|
480 |
case WM_DESTROY: |
case WM_DESTROY: |
481 |
free_if_alloc (pincb.info_text); |
free_pincb (&pincb); |
|
sfree_if_alloc (pincb.apin); |
|
|
sfree_if_alloc (pincb.upin); |
|
482 |
memset (&pincb, 0, sizeof pincb); |
memset (&pincb, 0, sizeof pincb); |
483 |
break; |
break; |
484 |
|
|
494 |
case IDC_CEDIT_LANG: dstid = IDC_CEDIT_LANG2; break; |
case IDC_CEDIT_LANG: dstid = IDC_CEDIT_LANG2; break; |
495 |
case IDC_CEDIT_SEX: dstid = IDC_CEDIT_SEX2; break; |
case IDC_CEDIT_SEX: dstid = IDC_CEDIT_SEX2; break; |
496 |
} |
} |
497 |
GetDlgItemText (dlg, ctlid, tmp, 127); |
GetDlgItemText (dlg, ctlid, tmp, sizeof (tmp)-1); |
498 |
SetDlgItemText (dlg, dstid, tmp); |
SetDlgItemText (dlg, dstid, tmp); |
499 |
break; |
break; |
500 |
} |
} |
517 |
break; |
break; |
518 |
|
|
519 |
case IDOK: |
case IDOK: |
520 |
n = do_proc_card_cmds( dlg, NULL, NULL ); |
n = do_proc_card_cmds (dlg, NULL, NULL); |
521 |
if( n ) { |
if (n) { |
522 |
if( do_askpin( dlg, GPG_EDITCARD_CHAPIN, card, &pincb ) ) |
if (do_askpin (dlg, CARD_ADMIN_PIN, card, &pincb)) |
523 |
EndDialog( dlg, FALSE ); |
EndDialog (dlg, FALSE); |
|
if( do_askpin( dlg, GPG_EDITCARD_CHUPIN, card, &pincb ) ) |
|
|
EndDialog( dlg, FALSE ); |
|
524 |
} |
} |
525 |
do_proc_card_cmds( dlg, &pincb, card ); |
do_proc_card_cmds (dlg, &pincb, card); |
526 |
free_pincb( &pincb ); |
free_pincb (&pincb); |
527 |
if( !n ) |
if( !n ) |
528 |
EndDialog( dlg, TRUE ); |
EndDialog( dlg, TRUE ); |
529 |
break; |
break; |
562 |
BOOL CALLBACK |
BOOL CALLBACK |
563 |
card_keygen_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
card_keygen_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
564 |
{ |
{ |
|
static int state = 0; |
|
|
static int pwd_state = 0; |
|
565 |
gpgme_error_t err; |
gpgme_error_t err; |
566 |
GpgCardEdit *ce; |
GpgCardEdit *ce; |
567 |
char name[128], email[128], comment[128]; |
char name[128], email[128], comment[128]; |
572 |
|
|
573 |
switch (msg) { |
switch (msg) { |
574 |
case WM_INITDIALOG: |
case WM_INITDIALOG: |
|
state = 0; |
|
|
pwd_state = 1; |
|
575 |
center_window (dlg, NULL); |
center_window (dlg, NULL); |
576 |
CheckDlgButton (dlg, IDC_CKEYGEN_REPLACE, BST_CHECKED); |
CheckDlgButton (dlg, IDC_CKEYGEN_REPLACE, BST_CHECKED); |
577 |
CheckDlgButton (dlg, IDC_CKEYGEN_NEVER, BST_CHECKED); |
CheckDlgButton (dlg, IDC_CKEYGEN_NEVER, BST_CHECKED); |
578 |
CheckDlgButton (dlg, IDC_CKEYGEN_BACKUP, BST_CHECKED); |
CheckDlgButton (dlg, IDC_CKEYGEN_BACKUP, BST_CHECKED); |
579 |
EnableWindow (GetDlgItem (dlg, IDC_CKEYGEN_VALID), FALSE); |
EnableWindow (GetDlgItem (dlg, IDC_CKEYGEN_VALID), FALSE); |
580 |
SendDlgItemMessage (dlg, IDC_CKEYGEN_ALG, CB_ADDSTRING, 0, (LPARAM)(const char*)"RSA"); |
SendDlgItemMessage (dlg, IDC_CKEYGEN_ALG, CB_ADDSTRING, 0, |
581 |
|
(LPARAM)(const char*)"RSA"); |
582 |
SendDlgItemMessage (dlg, IDC_CKEYGEN_ALG, CB_SETCURSEL, 0, 0); |
SendDlgItemMessage (dlg, IDC_CKEYGEN_ALG, CB_SETCURSEL, 0, 0); |
583 |
SetFocus (GetDlgItem (dlg, IDC_CKEYGEN_NAME)); |
SetFocus (GetDlgItem (dlg, IDC_CKEYGEN_NAME)); |
584 |
SetForegroundWindow (dlg); |
SetForegroundWindow (dlg); |
585 |
return FALSE; |
return FALSE; |
586 |
|
|
587 |
|
case WM_SYSCOMMAND: |
588 |
|
if (LOWORD (wparam) == SC_CLOSE) |
589 |
|
EndDialog (dlg, TRUE); |
590 |
|
return FALSE; |
591 |
|
|
592 |
case WM_COMMAND: |
case WM_COMMAND: |
593 |
if (HIWORD (wparam) == BN_CLICKED) { |
if (HIWORD (wparam) == BN_CLICKED && |
594 |
switch (LOWORD (wparam)) { |
(LOWORD (wparam) == IDC_CKEYGEN_BACKUP) || |
595 |
case IDC_CKEYGEN_NEVER: |
LOWORD (wparam) == IDC_CKEYGEN_NEVER) { |
596 |
state ^= 1; |
EnableWindow (GetDlgItem (dlg, IDC_CKEYGEN_VALID), |
597 |
EnableWindow (GetDlgItem (dlg, IDC_CKEYGEN_VALID), state); |
IsDlgButtonChecked (dlg, IDC_CKEYGEN_NEVER)? 0: 1); |
598 |
break; |
EnableWindow (GetDlgItem (dlg, IDC_CKEYGEN_PASS), |
599 |
|
IsDlgButtonChecked (dlg, IDC_CKEYGEN_BACKUP)? 1 : 0); |
600 |
case IDC_CKEYGEN_BACKUP: |
return TRUE; |
601 |
pwd_state ^= 1; |
} |
|
EnableWindow (GetDlgItem (dlg, IDC_CKEYGEN_PASS), pwd_state); |
|
|
break; |
|
|
} |
|
|
} |
|
602 |
|
|
603 |
switch (LOWORD (wparam)) { |
switch (LOWORD (wparam)) { |
604 |
case IDOK: |
case IDOK: |
626 |
return TRUE; |
return TRUE; |
627 |
} |
} |
628 |
n = GetDlgItemText (dlg, IDC_CKEYGEN_PASS, pass, sizeof (pass)-1); |
n = GetDlgItemText (dlg, IDC_CKEYGEN_PASS, pass, sizeof (pass)-1); |
629 |
if (!n && pwd_state == 1) { |
if (!n && IsDlgButtonChecked (dlg, IDC_CKEYGEN_BACKUP)) { |
630 |
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); |
631 |
return TRUE; |
return TRUE; |
632 |
} |
} |
639 |
return TRUE; |
return TRUE; |
640 |
} |
} |
641 |
memset (&pincb, 0, sizeof (pincb)); |
memset (&pincb, 0, sizeof (pincb)); |
642 |
if (do_askpin (dlg, GPG_EDITCARD_CHAPIN, NULL, &pincb)) { |
if (do_askpin (dlg, CARD_ADMIN_PIN, NULL, &pincb)) { |
643 |
free_pincb (&pincb); |
free_pincb (&pincb); |
644 |
return TRUE; |
return TRUE; |
645 |
} |
} |
646 |
if (do_askpin (dlg, GPG_EDITCARD_CHUPIN, NULL, &pincb)) { |
if (do_askpin (dlg, CARD_USER_PIN, NULL, &pincb)) { |
647 |
free_pincb (&pincb); |
free_pincb (&pincb); |
648 |
return TRUE; |
return TRUE; |
649 |
} |
} |
674 |
ce->setPIN (pincb.upin); |
ce->setPIN (pincb.upin); |
675 |
ce->setAdminPIN (pincb.apin); |
ce->setAdminPIN (pincb.apin); |
676 |
|
|
677 |
SetCursor( LoadCursor (NULL, IDC_WAIT)); |
SetCursor (LoadCursor (NULL, IDC_WAIT)); |
678 |
err = ce->genKey (card_flags, name, email, n? comment: NULL, |
err = ce->genKey (card_flags, name, email, n? comment: NULL, |
679 |
expires? valid : 0); |
expires? valid : 0, NULL); |
680 |
|
|
681 |
SetCursor (LoadCursor (NULL, IDC_ARROW)); |
SetCursor (LoadCursor (NULL, IDC_ARROW)); |
682 |
/* |
/* |
695 |
memset (pass, 0, sizeof (pass)); |
memset (pass, 0, sizeof (pass)); |
696 |
free_pincb (&pincb); |
free_pincb (&pincb); |
697 |
delete ce; |
delete ce; |
698 |
break; |
return TRUE; |
699 |
|
|
700 |
case IDCANCEL: |
case IDCANCEL: |
701 |
EndDialog (dlg, FALSE); |
EndDialog (dlg, FALSE); |
721 |
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); |
722 |
return -1; |
return -1; |
723 |
} |
} |
724 |
if (which == GPG_EDITCARD_CHAPIN |
if (which == CARD_ADMIN_PIN |
725 |
&& pinlen < 8) { |
&& pinlen < 8) { |
726 |
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); |
727 |
return -1; |
return -1; |
728 |
} |
} |
729 |
if (which == GPG_EDITCARD_CHUPIN |
if (which == CARD_USER_PIN |
730 |
&& pinlen < 6) { |
&& pinlen < 6) { |
731 |
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); |
732 |
return -1; |
return -1; |
758 |
if (HIWORD (wparam) == BN_CLICKED && LOWORD (wparam) == IDC_CHPIN_HIDE) { |
if (HIWORD (wparam) == BN_CLICKED && LOWORD (wparam) == IDC_CHPIN_HIDE) { |
759 |
HWND hwnd; |
HWND hwnd; |
760 |
hide ^= 1; |
hide ^= 1; |
761 |
|
hwnd = GetDlgItem (dlg, IDC_CHPIN_OLDPIN); |
762 |
|
SendMessage (hwnd, EM_SETPASSWORDCHAR, hide? '*' : 0, 0); |
763 |
|
SetFocus (hwnd); |
764 |
hwnd = GetDlgItem (dlg, IDC_CHPIN_NEWPIN); |
hwnd = GetDlgItem (dlg, IDC_CHPIN_NEWPIN); |
765 |
SendMessage (hwnd, EM_SETPASSWORDCHAR, hide? '*' : 0, 0); |
SendMessage (hwnd, EM_SETPASSWORDCHAR, hide? '*' : 0, 0); |
766 |
SetFocus (hwnd); |
SetFocus (hwnd); |
771 |
switch( LOWORD( wparam ) ) { |
switch( LOWORD( wparam ) ) { |
772 |
case IDOK: |
case IDOK: |
773 |
if (IsDlgButtonChecked (dlg, IDC_CHPIN_ISADMIN)) |
if (IsDlgButtonChecked (dlg, IDC_CHPIN_ISADMIN)) |
774 |
which = GPG_EDITCARD_CHAPIN; |
which = CARD_ADMIN_PIN; |
775 |
else if (IsDlgButtonChecked (dlg, IDC_CHPIN_ISWORK)) |
else if (IsDlgButtonChecked (dlg, IDC_CHPIN_ISWORK)) |
776 |
which = GPG_EDITCARD_CHUPIN; |
which = CARD_USER_PIN; |
|
else |
|
|
BUG (0); |
|
777 |
|
|
778 |
n = item_get_text_length (dlg, IDC_CHPIN_OLDPIN); |
n = item_get_text_length (dlg, IDC_CHPIN_OLDPIN); |
779 |
if (check_pin_len (which, 1, n)) |
if (check_pin_len (which, 1, n)) |
788 |
GetDlgItemText (dlg, IDC_CHPIN_NEWPIN, pnew, sizeof (pnew)-1); |
GetDlgItemText (dlg, IDC_CHPIN_NEWPIN, pnew, sizeof (pnew)-1); |
789 |
GetDlgItemText (dlg, IDC_CHPIN_NEWPIN2, pnew2, sizeof (pnew2)-1); |
GetDlgItemText (dlg, IDC_CHPIN_NEWPIN2, pnew2, sizeof (pnew2)-1); |
790 |
if (strcmp (pnew, pnew2)) { |
if (strcmp (pnew, pnew2)) { |
791 |
msg_box (dlg, _("Passphrases do not match. Please try again."), _("Card Edit"), MB_ERR); |
msg_box (dlg, _("Passphrases do not match. Please try again."), |
792 |
|
_("Card Edit"), MB_ERR); |
793 |
return TRUE; |
return TRUE; |
794 |
} |
} |
795 |
|
|
796 |
ce = new GpgCardEdit (); |
ce = new GpgCardEdit (); |
797 |
if (!ce) |
if (!ce) |
798 |
BUG (0); |
BUG (0); |
799 |
ce->setPIN (pold); |
if (which == CARD_ADMIN_PIN) |
800 |
|
ce->setAdminPIN (pold); |
801 |
|
else |
802 |
|
ce->setPIN (pold); |
803 |
ce->setNewPIN (pnew); |
ce->setNewPIN (pnew); |
804 |
ce->setType (which); |
err = ce->changePIN (which == CARD_ADMIN_PIN? GPG_EDITCARD_CHAPIN : |
805 |
|
GPG_EDITCARD_CHUPIN); |
|
err = ce->changePIN (); |
|
806 |
if (err) |
if (err) |
807 |
msg_box (dlg, gpgme_strerror (err), _("Card Edit"), MB_ERR); |
msg_box (dlg, gpgme_strerror (err), _("Card Edit"), MB_ERR); |
808 |
else { |
else { |
809 |
msg_box( dlg, _("PIN successfully changed."), _("Card Edit"), MB_OK ); |
msg_box (dlg, _("PIN successfully changed."), |
810 |
|
_("Card Edit"), MB_OK); |
811 |
SetDlgItemText (dlg, IDC_CHPIN_NEWPIN, ""); |
SetDlgItemText (dlg, IDC_CHPIN_NEWPIN, ""); |
812 |
SetDlgItemText (dlg, IDC_CHPIN_OLDPIN, ""); |
SetDlgItemText (dlg, IDC_CHPIN_OLDPIN, ""); |
813 |
SetDlgItemText (dlg, IDC_CHPIN_NEWPIN2, ""); |
SetDlgItemText (dlg, IDC_CHPIN_NEWPIN2, ""); |
814 |
} |
} |
815 |
|
memset (pold, 0, sizeof (pold)); |
816 |
|
memset (pnew, 0, sizeof (pnew)); |
817 |
|
memset (pnew2, 0, sizeof (pnew2)); |
818 |
delete ce; |
delete ce; |
819 |
break; |
break; |
820 |
|
|
822 |
SetDlgItemText (dlg, IDC_CHPIN_NEWPIN, ""); |
SetDlgItemText (dlg, IDC_CHPIN_NEWPIN, ""); |
823 |
SetDlgItemText (dlg, IDC_CHPIN_OLDPIN, ""); |
SetDlgItemText (dlg, IDC_CHPIN_OLDPIN, ""); |
824 |
SetDlgItemText (dlg, IDC_CHPIN_NEWPIN2, ""); |
SetDlgItemText (dlg, IDC_CHPIN_NEWPIN2, ""); |
825 |
EndDialog( dlg, FALSE ); |
EndDialog (dlg, FALSE); |
826 |
break; |
break; |
827 |
} |
} |
828 |
break; |
break; |