1 |
/* wptCardDlg.cpp - Smart Card support |
/* wptCardDlg.cpp - Smart Card support |
2 |
* Copyright (C) 2003, 2004 Timo Schulz |
* Copyright (C) 2003, 2004, 2005 Timo Schulz |
3 |
* |
* |
4 |
* This file is part of WinPT. |
* This file is part of WinPT. |
5 |
* |
* |
580 |
return FALSE; |
return FALSE; |
581 |
} |
} |
582 |
n = GetDlgItemText (dlg, IDC_CKEYGEN_PASS, pass, sizeof (pass)-1); |
n = GetDlgItemText (dlg, IDC_CKEYGEN_PASS, pass, sizeof (pass)-1); |
583 |
if (!n) { |
if (!n && pwd_state == 1) { |
584 |
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); |
585 |
return FALSE; |
return FALSE; |
586 |
} |
} |
688 |
|
|
689 |
|
|
690 |
BOOL CALLBACK |
BOOL CALLBACK |
691 |
card_changepin_dlg_proc( HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam ) |
card_changepin_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
692 |
{ |
{ |
693 |
|
static int hide = 1; |
694 |
gpgme_ctx_t ctx; |
gpgme_ctx_t ctx; |
695 |
gpgme_editcard_t chpin; |
gpgme_editcard_t chpin; |
696 |
gpgme_error_t rc; |
gpgme_error_t rc; |
697 |
gpgme_edit_card_t which; |
gpgme_edit_card_t which; |
698 |
char pold[128], pnew[128]; |
char pold[128], pnew[128], pnew2[128]; |
699 |
size_t n; |
size_t n; |
700 |
|
|
701 |
switch( msg ) { |
switch( msg ) { |
702 |
case WM_INITDIALOG: |
case WM_INITDIALOG: |
703 |
center_window( dlg ); |
hide = 1; |
704 |
CheckDlgButton( dlg, IDC_CHPIN_ISWORK, BST_CHECKED ); |
CheckDlgButton (dlg, IDC_CHPIN_HIDE, BST_CHECKED); |
705 |
SetForegroundWindow( dlg ); |
center_window (dlg); |
706 |
|
CheckDlgButton (dlg, IDC_CHPIN_ISWORK, BST_CHECKED); |
707 |
|
SetForegroundWindow (dlg); |
708 |
break; |
break; |
709 |
|
|
710 |
case WM_COMMAND: |
case WM_COMMAND: |
711 |
|
if (HIWORD (wparam) == BN_CLICKED && LOWORD (wparam) == IDC_CHPIN_HIDE) { |
712 |
|
HWND hwnd; |
713 |
|
hide ^= 1; |
714 |
|
hwnd = GetDlgItem (dlg, IDC_CHPIN_NEWPIN); |
715 |
|
SendMessage (hwnd, EM_SETPASSWORDCHAR, hide? '*' : 0, 0); |
716 |
|
SetFocus (hwnd); |
717 |
|
hwnd = GetDlgItem (dlg, IDC_CHPIN_NEWPIN2); |
718 |
|
SendMessage (hwnd, EM_SETPASSWORDCHAR, hide? '*' : 0, 0); |
719 |
|
SetFocus (hwnd); |
720 |
|
} |
721 |
switch( LOWORD( wparam ) ) { |
switch( LOWORD( wparam ) ) { |
722 |
case IDOK: |
case IDOK: |
723 |
if( IsDlgButtonChecked( dlg, IDC_CHPIN_ISADMIN ) ) |
if (IsDlgButtonChecked (dlg, IDC_CHPIN_ISADMIN)) |
724 |
which = GPGME_EDITCARD_CHAPIN; |
which = GPGME_EDITCARD_CHAPIN; |
725 |
else if( IsDlgButtonChecked( dlg, IDC_CHPIN_ISWORK ) ) |
else if (IsDlgButtonChecked (dlg, IDC_CHPIN_ISWORK)) |
726 |
which = GPGME_EDITCARD_CHUPIN; |
which = GPGME_EDITCARD_CHUPIN; |
727 |
else |
else |
728 |
BUG (0); |
BUG (0); |
729 |
|
|
730 |
n = item_get_text_length( dlg, IDC_CHPIN_OLDPIN ); |
n = item_get_text_length (dlg, IDC_CHPIN_OLDPIN); |
731 |
if (check_pin_len (which, 1, n)) |
if (check_pin_len (which, 1, n)) |
732 |
return FALSE; |
return FALSE; |
733 |
n = item_get_text_length( dlg, IDC_CHPIN_NEWPIN ); |
n = item_get_text_length (dlg, IDC_CHPIN_NEWPIN); |
734 |
if (check_pin_len (which, 0, n)) |
if (check_pin_len (which, 0, n)) |
735 |
return FALSE; |
return FALSE; |
736 |
GetDlgItemText( dlg, IDC_CHPIN_OLDPIN, pold, sizeof (pold)-1 ); |
n = item_get_text_length (dlg, IDC_CHPIN_NEWPIN2); |
737 |
GetDlgItemText( dlg, IDC_CHPIN_NEWPIN, pnew, sizeof (pnew)-1 ); |
if (check_pin_len (which, 0, n)) |
738 |
rc = gpgme_new( &ctx ); |
return FALSE; |
739 |
if( !rc ) |
GetDlgItemText (dlg, IDC_CHPIN_OLDPIN, pold, sizeof (pold)-1); |
740 |
rc = gpgme_editcard_new( &chpin ); |
GetDlgItemText (dlg, IDC_CHPIN_NEWPIN, pnew, sizeof (pnew)-1); |
741 |
|
GetDlgItemText (dlg, IDC_CHPIN_NEWPIN2, pnew2, sizeof (pnew2)-1); |
742 |
|
if (strcmp (pnew, pnew2)) { |
743 |
|
msg_box (dlg, _("Passphrases do not match. Please try again."), _("Card Edit"), MB_ERR); |
744 |
|
return FALSE; |
745 |
|
} |
746 |
|
rc = gpgme_new (&ctx); |
747 |
|
if (!rc) |
748 |
|
rc = gpgme_editcard_new (&chpin); |
749 |
if (rc) |
if (rc) |
750 |
BUG (0); |
BUG (0); |
751 |
gpgme_changepin_set( chpin, which, pold, pnew ); |
gpgme_changepin_set( chpin, which, pold, pnew ); |
755 |
msg_box( dlg, gpgme_strerror( rc ), _("Card Edit"), MB_ERR ); |
msg_box( dlg, gpgme_strerror( rc ), _("Card Edit"), MB_ERR ); |
756 |
else { |
else { |
757 |
msg_box( dlg, _("PIN successfully changed."), _("Card Edit"), MB_OK ); |
msg_box( dlg, _("PIN successfully changed."), _("Card Edit"), MB_OK ); |
758 |
SetDlgItemText( dlg, IDC_CHPIN_NEWPIN, "" ); |
SetDlgItemText (dlg, IDC_CHPIN_NEWPIN, ""); |
759 |
SetDlgItemText( dlg, IDC_CHPIN_OLDPIN, "" ); |
SetDlgItemText (dlg, IDC_CHPIN_OLDPIN, ""); |
760 |
|
SetDlgItemText (dlg, IDC_CHPIN_NEWPIN2, ""); |
761 |
} |
} |
762 |
gpgme_release( ctx ); |
gpgme_release( ctx ); |
763 |
gpgme_editcard_release( chpin ); |
gpgme_editcard_release( chpin ); |
764 |
break; |
break; |
765 |
|
|
766 |
case IDCANCEL: |
case IDCANCEL: |
767 |
SetDlgItemText( dlg, IDC_CHPIN_NEWPIN, "" ); |
SetDlgItemText (dlg, IDC_CHPIN_NEWPIN, ""); |
768 |
SetDlgItemText( dlg, IDC_CHPIN_OLDPIN, "" ); |
SetDlgItemText (dlg, IDC_CHPIN_OLDPIN, ""); |
769 |
|
SetDlgItemText (dlg, IDC_CHPIN_NEWPIN2, ""); |
770 |
EndDialog( dlg, FALSE ); |
EndDialog( dlg, FALSE ); |
771 |
break; |
break; |
772 |
} |
} |