1 |
/* wptCardDlg.cpp - Smart Card support |
/* wptCardDlg.cpp - Smart Card support |
2 |
* Copyright (C) 2003-2006 Timo Schulz |
* Copyright (C) 2003-2007 Timo Schulz |
3 |
* Copyright (C) 2005 g10 Code GmbH |
* Copyright (C) 2005 g10 Code GmbH |
4 |
* |
* |
5 |
* This file is part of WinPT. |
* This file is part of WinPT. |
14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 |
* GNU General Public License for more details. |
* GNU General Public License for more details. |
16 |
*/ |
*/ |
|
|
|
17 |
#ifdef HAVE_CONFIG_H |
#ifdef HAVE_CONFIG_H |
18 |
#include <config.h> |
#include <config.h> |
19 |
#endif |
#endif |
114 |
} |
} |
115 |
|
|
116 |
|
|
|
static GpgCardEdit* |
|
|
create_GpgCardEdit (void) |
|
|
{ |
|
|
GpgCardEdit *ce; |
|
|
|
|
|
ce = new GpgCardEdit (); |
|
|
if (!ce) |
|
|
BUG (0); |
|
|
return ce; |
|
|
} |
|
|
|
|
|
|
|
117 |
/* Check if there is a card in the reader and analyze the |
/* Check if there is a card in the reader and analyze the |
118 |
returned information. |
returned information. |
119 |
Return value: card context or NULL on error. */ |
Return value: card context or NULL on error. */ |
121 |
gpg_card_load (void) |
gpg_card_load (void) |
122 |
{ |
{ |
123 |
gpgme_error_t err; |
gpgme_error_t err; |
124 |
GpgCardEdit *ce; |
GpgCardEdit ce; |
125 |
gpg_card_t card = NULL; |
gpg_card_t card = NULL; |
126 |
struct card_cb_s cb = {0}; |
struct card_cb_s cb = {0}; |
127 |
|
|
|
ce = create_GpgCardEdit (); |
|
128 |
memset (&cb, 0, sizeof (cb)); |
memset (&cb, 0, sizeof (cb)); |
129 |
ce->setCallback (card_callback, &cb); |
ce.setCallback (card_callback, &cb); |
130 |
err = ce->getCardStatus (&card); |
err = ce.getCardStatus (&card); |
131 |
if (err) { |
if (err) { |
132 |
msg_box (NULL, gpgme_strerror (err), _("Card Manager"), MB_ERR); |
msg_box (NULL, gpgme_strerror (err), _("Card Manager"), MB_ERR); |
133 |
goto leave; |
return card; |
134 |
} |
} |
135 |
|
|
136 |
if (!card->aid || |
if (!card->aid || |
137 |
strncmp (card->aid, OPENPGP_APPID, strlen (OPENPGP_APPID))) { |
strncmp (card->aid, OPENPGP_APPID, strlen (OPENPGP_APPID))) { |
138 |
msg_box (NULL, winpt_strerror (WPTERR_NOPGPCARD), "WinPT", MB_ERR); |
msg_box (NULL, winpt_strerror (WPTERR_NOPGPCARD), "WinPT", MB_ERR); |
139 |
gpg_card_release (card); |
gpg_card_release (card); |
140 |
card = NULL; |
return NULL; |
141 |
} |
} |
142 |
else { |
else { |
143 |
struct winpt_key_s key; |
struct winpt_key_s key; |
150 |
} |
} |
151 |
} |
} |
152 |
|
|
|
leave: |
|
|
delete ce; |
|
153 |
return card; |
return card; |
154 |
} |
} |
155 |
|
|
285 |
{0} |
{0} |
286 |
}; |
}; |
287 |
gpgme_error_t err; |
gpgme_error_t err; |
288 |
GpgCardEdit *ce; |
GpgCardEdit ce; |
289 |
char buf[256], tmp[128]; |
char buf[256], tmp[128]; |
290 |
int errc=0, use_arg2 = 0; |
int errc=0, use_arg2 = 0; |
291 |
int i, id, n=0; |
int i, id, n=0; |
322 |
return 0; |
return 0; |
323 |
} |
} |
324 |
|
|
325 |
ce = create_GpgCardEdit (); |
ce.setAdminPIN (cb->apin); |
|
ce->setAdminPIN (cb->apin); |
|
326 |
for( i=0; idctl[i].id; i++ ) { |
for( i=0; idctl[i].id; i++ ) { |
327 |
if( idctl[i].changed ) { |
if( idctl[i].changed ) { |
328 |
GetDlgItemText( dlg, idctl[i].id, buf, sizeof (buf)-1 ); |
GetDlgItemText( dlg, idctl[i].id, buf, sizeof (buf)-1 ); |
349 |
} |
} |
350 |
else |
else |
351 |
use_arg2 = 0; |
use_arg2 = 0; |
352 |
err = ce->doCmd (idctl[i].cmd, buf, use_arg2? tmp : NULL); |
err = ce.doCmd (idctl[i].cmd, buf, use_arg2? tmp : NULL); |
353 |
if (err) { |
if (err) { |
354 |
log_box (_("Card Edit"), MB_ERR, |
log_box (_("Card Edit"), MB_ERR, |
355 |
_("Could not modify card attribute: %s"), |
_("Could not modify card attribute: %s"), |
369 |
SetDlgItemText( dlg, IDC_CEDIT_LANG2, "" ); |
SetDlgItemText( dlg, IDC_CEDIT_LANG2, "" ); |
370 |
SetDlgItemText( dlg, IDC_CEDIT_SEX2, "" ); |
SetDlgItemText( dlg, IDC_CEDIT_SEX2, "" ); |
371 |
} |
} |
|
delete ce; |
|
372 |
return errc; |
return errc; |
373 |
} |
} |
374 |
|
|
545 |
card_keygen_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
card_keygen_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
546 |
{ |
{ |
547 |
gpgme_error_t err; |
gpgme_error_t err; |
|
GpgCardEdit *ce; |
|
548 |
char name[128], email[128], comment[128]; |
char name[128], email[128], comment[128]; |
549 |
char pass[128]; |
char pass[128]; |
550 |
int card_flags = GPG_CARDFLAG_NONE; |
int card_flags = GPG_CARDFLAG_NONE; |
634 |
free_pincb (&pincb); |
free_pincb (&pincb); |
635 |
return TRUE; |
return TRUE; |
636 |
} |
} |
|
ce = create_GpgCardEdit (); |
|
637 |
|
|
638 |
expires = !IsDlgButtonChecked (dlg, IDC_CKEYGEN_NEVER); |
expires = !IsDlgButtonChecked (dlg, IDC_CKEYGEN_NEVER); |
639 |
if (expires) { |
if (expires) { |
644 |
msg_box (dlg, _("The date you have chosen has already passed."), |
msg_box (dlg, _("The date you have chosen has already passed."), |
645 |
_("Card Edit"), MB_ERR); |
_("Card Edit"), MB_ERR); |
646 |
free_pincb (&pincb); |
free_pincb (&pincb); |
|
delete ce; |
|
647 |
return TRUE; |
return TRUE; |
648 |
} |
} |
649 |
GetSystemTime (&ct); |
GetSystemTime (&ct); |
655 |
card_flags |= GPG_CARDFLAG_REPLACE; |
card_flags |= GPG_CARDFLAG_REPLACE; |
656 |
if (IsDlgButtonChecked (dlg, IDC_CKEYGEN_BACKUP)) |
if (IsDlgButtonChecked (dlg, IDC_CKEYGEN_BACKUP)) |
657 |
card_flags |= GPG_CARDFLAG_BAKENC; |
card_flags |= GPG_CARDFLAG_BAKENC; |
|
ce->setKeygenPassphrase (pass); |
|
|
ce->setPIN (pincb.upin); |
|
|
ce->setAdminPIN (pincb.apin); |
|
658 |
|
|
659 |
SetCursor (LoadCursor (NULL, IDC_WAIT)); |
{ |
660 |
err = ce->genKey (card_flags, name, email, n? comment: NULL, |
GpgCardEdit ce; |
661 |
expires? valid : 0, NULL); |
|
662 |
SetCursor (LoadCursor (NULL, IDC_ARROW)); |
ce.setKeygenPassphrase (pass); |
663 |
|
ce.setPIN (pincb.upin); |
664 |
|
ce.setAdminPIN (pincb.apin); |
665 |
|
|
666 |
|
SetCursor (LoadCursor (NULL, IDC_WAIT)); |
667 |
|
err = ce.genKey (card_flags, name, email, n? comment: NULL, |
668 |
|
expires? valid : 0, NULL); |
669 |
|
SetCursor (LoadCursor (NULL, IDC_ARROW)); |
670 |
|
} |
671 |
|
|
672 |
if (gpgme_err_code (err) == GPG_ERR_CANCELED) |
if (gpgme_err_code (err) == GPG_ERR_CANCELED) |
673 |
msg_box (dlg, _("Operation was canceled. It seems that there are " |
msg_box (dlg, _("Operation was canceled. It seems that there are " |
674 |
"existing\nkeys on the cards. You need to mark the " |
"existing\nkeys on the cards. You need to mark the " |
675 |
"'Overwrite' flag."), _("Card Edit"), MB_INFO); |
"'Overwrite' flag."), _("Card Edit"), MB_INFO); |
676 |
else |
else if (err) |
|
if (err) |
|
677 |
msg_box (dlg, "The operation does not succeed.\n" |
msg_box (dlg, "The operation does not succeed.\n" |
678 |
"Please make sure you entered the right PIN's." |
"Please make sure you entered the right PIN's." |
679 |
, _("Card Edit"), MB_ERR); |
, _("Card Edit"), MB_ERR); |
682 |
_("Card Edit"), MB_OK); |
_("Card Edit"), MB_OK); |
683 |
wipememory (pass, sizeof (pass)); |
wipememory (pass, sizeof (pass)); |
684 |
free_pincb (&pincb); |
free_pincb (&pincb); |
|
delete ce; |
|
685 |
EndDialog (dlg, TRUE); |
EndDialog (dlg, TRUE); |
686 |
return TRUE; |
return TRUE; |
687 |
|
|
728 |
{ |
{ |
729 |
static int hide = 1; |
static int hide = 1; |
730 |
gpgme_error_t err; |
gpgme_error_t err; |
|
GpgCardEdit *ce; |
|
731 |
char pold[128], pnew[128], pnew2[128]; |
char pold[128], pnew[128], pnew2[128]; |
732 |
int which = 0; |
int which = 0; |
733 |
DWORD n; |
DWORD n; |
783 |
return TRUE; |
return TRUE; |
784 |
} |
} |
785 |
|
|
786 |
ce = create_GpgCardEdit (); |
{ |
787 |
if (which == CARD_ADMIN_PIN) |
GpgCardEdit ce; |
788 |
ce->setAdminPIN (pold); |
|
789 |
else |
if (which == CARD_ADMIN_PIN) |
790 |
ce->setPIN (pold); |
ce.setAdminPIN (pold); |
791 |
ce->setNewPIN (pnew); |
else |
792 |
err = ce->changePIN (which == CARD_ADMIN_PIN? GPG_EDITCARD_CHAPIN : |
ce.setPIN (pold); |
793 |
GPG_EDITCARD_CHUPIN); |
ce.setNewPIN (pnew); |
794 |
|
err = ce.changePIN (which == CARD_ADMIN_PIN? |
795 |
|
GPG_EDITCARD_CHAPIN : |
796 |
|
GPG_EDITCARD_CHUPIN); |
797 |
|
} |
798 |
if (err) |
if (err) |
799 |
msg_box (dlg, gpgme_strerror (err), _("Card Edit"), MB_ERR); |
msg_box (dlg, gpgme_strerror (err), _("Card Edit"), MB_ERR); |
800 |
else { |
else { |
807 |
wipememory (pold, sizeof (pold)); |
wipememory (pold, sizeof (pold)); |
808 |
wipememory (pnew, sizeof (pnew)); |
wipememory (pnew, sizeof (pnew)); |
809 |
wipememory (pnew2, sizeof (pnew2)); |
wipememory (pnew2, sizeof (pnew2)); |
|
delete ce; |
|
810 |
break; |
break; |
811 |
|
|
812 |
case IDCANCEL: |
case IDCANCEL: |