1 |
/* wptCardEdit.cpp - OpenPGP editing interface |
/* wptCardEdit.cpp - OpenPGP card editing interface |
2 |
* Copyright (C) 2005, 2006 Timo Schulz |
* Copyright (C) 2005, 2006, 2007 Timo Schulz |
3 |
* |
* |
4 |
* This file is part of WinPT. |
* This file is part of WinPT. |
5 |
* |
* |
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 |
* GNU General Public License for more details. |
* GNU General Public License for more details. |
|
* |
|
|
* You should have received a copy of the GNU General Public License |
|
|
* along with WinPT; if not, write to the Free Software Foundation, |
|
|
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
|
15 |
*/ |
*/ |
|
|
|
16 |
#ifdef HAVE_CONFIG_H |
#ifdef HAVE_CONFIG_H |
17 |
#include <config.h> |
#include <config.h> |
18 |
#endif |
#endif |
27 |
#include "wptTypes.h" |
#include "wptTypes.h" |
28 |
#include "wptW32API.h" |
#include "wptW32API.h" |
29 |
|
|
30 |
|
|
31 |
/* Create a new Smartcard context. */ |
/* Create a new Smartcard context. */ |
32 |
static gpgme_error_t |
static gpgme_error_t |
33 |
gpg_card_new (gpg_card_t *ret_card) |
gpg_card_new (gpg_card_t *ret_card) |
69 |
safe_free (card->url); |
safe_free (card->url); |
70 |
safe_free (card->card_type); |
safe_free (card->card_type); |
71 |
safe_free (card); |
safe_free (card); |
|
|
|
72 |
} |
} |
73 |
|
|
74 |
|
|
82 |
|
|
83 |
if (long_ts < 1) |
if (long_ts < 1) |
84 |
return strdup (""); |
return strdup (""); |
85 |
dat = get_locale_date (long_ts, timebuf, sizeof (timebuf)-1); |
dat = get_locale_date (long_ts, timebuf, DIM (timebuf)-1); |
86 |
if (!dat) |
if (!dat) |
87 |
return strdup (""); |
return strdup (""); |
|
|
|
88 |
return strdup (dat); |
return strdup (dat); |
89 |
} |
} |
90 |
|
|
129 |
CARD_Fpr, |
CARD_Fpr, |
130 |
CARD_FprTime |
CARD_FprTime |
131 |
}; |
}; |
132 |
enum rectype_t rectype = (rectype_t)0; |
enum rectype_t rectype = CARD_None; |
133 |
char *p, *pend; |
char *p, *pend; |
134 |
int field = 0; |
int field = 0; |
135 |
|
|
309 |
{ |
{ |
310 |
static int wait_card=0; |
static int wait_card=0; |
311 |
GpgCardEdit *ce = (GpgCardEdit *)opaque; |
GpgCardEdit *ce = (GpgCardEdit *)opaque; |
312 |
const char *s=""; |
const char *s = ""; |
313 |
DWORD n; |
DWORD n; |
314 |
|
|
315 |
|
if (!ce) |
316 |
|
return gpg_error (GPG_ERR_INV_VALUE); |
317 |
|
|
318 |
if (code == GPGME_STATUS_CARDCTRL) { |
if (code == GPGME_STATUS_CARDCTRL) { |
319 |
if (!strcmp (key, "5")) |
if (!strcmp (key, "5")) |
322 |
wait_card = 1; |
wait_card = 1; |
323 |
} |
} |
324 |
if (wait_card && !strcmp (key, "cardctrl.insert_card.okay")) { |
if (wait_card && !strcmp (key, "cardctrl.insert_card.okay")) { |
325 |
|
/* :TODO: show card ID */ |
326 |
n = MessageBox (NULL, _("Please insert the card and click OK or Cancel to abort."), |
n = MessageBox (NULL, _("Please insert the card and click OK or Cancel to abort."), |
327 |
_("GPG Card Status"), MB_ICONQUESTION|MB_OKCANCEL); |
_("GPG Card Status"), MB_ICONQUESTION|MB_OKCANCEL); |
328 |
if (n == IDCANCEL) { |
if (n == IDCANCEL) { |
329 |
|
s = "c\n"; |
330 |
ce->setResult (GPG_CARDRES_CANCEL); |
ce->setResult (GPG_CARDRES_CANCEL); |
331 |
WriteFile ((HANDLE)fd, "c\n", 2, &n, NULL); |
if (!WriteFile ((HANDLE)fd, s, strlen (s), &n, NULL)) |
332 |
|
log_debug ("list_handler: WriteFile() failed ec=%d\r\n", |
333 |
|
(int)GetLastError ()); |
334 |
wait_card = 0; |
wait_card = 0; |
335 |
} |
} |
336 |
} |
} |
390 |
this->pin = _pin; |
this->pin = _pin; |
391 |
} |
} |
392 |
|
|
393 |
|
|
394 |
/* Set the admin PIN for the object to @admin_pin. */ |
/* Set the admin PIN for the object to @admin_pin. */ |
395 |
void |
void |
396 |
GpgCardEdit::setAdminPIN (const char *_admin_pin) |
GpgCardEdit::setAdminPIN (const char *_admin_pin) |
433 |
{ |
{ |
434 |
gpgme_data_t out = NULL; |
gpgme_data_t out = NULL; |
435 |
gpgme_error_t err; |
gpgme_error_t err; |
436 |
gpg_card_t card=NULL; |
gpg_card_t card = NULL; |
437 |
char buf[200]; |
char buf[200]; |
438 |
|
|
439 |
if (!r_card) |
if (!r_card) |
440 |
return gpg_error (GPG_ERR_INV_ARG); |
return gpg_error (GPG_ERR_INV_ARG); |
441 |
|
*r_card = NULL; |
442 |
|
|
443 |
err = gpg_card_new (&card); |
err = gpg_card_new (&card); |
444 |
if (err) |
if (err) |
465 |
} |
} |
466 |
|
|
467 |
*r_card = card; |
*r_card = card; |
468 |
while (gpg_data_readline (out, buf, sizeof (buf)-2) > 0) { |
while (gpg_data_readline (out, buf, DIM (buf)-2) > 0) { |
469 |
err = statuscard_colon_handler (card, buf); |
err = statuscard_colon_handler (card, buf); |
470 |
if (err) |
if (err) |
471 |
break; |
break; |
484 |
@valid: how long is the key valid in days. |
@valid: how long is the key valid in days. |
485 |
Return value: 0 on success. */ |
Return value: 0 on success. */ |
486 |
gpgme_error_t |
gpgme_error_t |
487 |
GpgCardEdit::genKey (int flags, const char *name, |
GpgCardEdit::genKey (int flags, |
488 |
const char *email, const char *comment, long valid, |
const char *name, const char *email, const char *comment, |
489 |
char **r_key_fpr) |
long valid, char **r_key_fpr) |
490 |
{ |
{ |
491 |
gpgme_error_t err; |
gpgme_error_t err; |
492 |
|
|
555 |
} |
} |
556 |
|
|
557 |
|
|
558 |
|
/* Update the given and the surname on the card. */ |
559 |
gpgme_error_t |
gpgme_error_t |
560 |
GpgCardEdit::updateName (const char *given, const char *sur) |
GpgCardEdit::updateName (const char *given, const char *sur) |
561 |
{ |
{ |
571 |
err = gpg_card_edit (ctx, this); |
err = gpg_card_edit (ctx, this); |
572 |
return err; |
return err; |
573 |
} |
} |
574 |
|
|
575 |
|
/* Update the given URL on the card. */ |
576 |
gpgme_error_t |
gpgme_error_t |
577 |
GpgCardEdit::updateURL (const char *_url) |
GpgCardEdit::updateURL (const char *_url) |
578 |
{ |
{ |
604 |
return err; |
return err; |
605 |
} |
} |
606 |
|
|
607 |
|
|
608 |
gpgme_error_t |
gpgme_error_t |
609 |
GpgCardEdit::updateSex (char sex) |
GpgCardEdit::updateSex (char sex) |
610 |
{ |
{ |