1 |
/* wptKeyEditCB.cpp - Key edit callback handling |
/* wptKeyEditCB.cpp - Key edit callback handling |
2 |
* Copyright (C) 2005, 2006 Timo Schulz |
* Copyright (C) 2005, 2006, 2009 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. |
345 |
if (!strcmp (key, "passphrase.enter")) |
if (!strcmp (key, "passphrase.enter")) |
346 |
return ctx->pass; |
return ctx->pass; |
347 |
if (!strcmp (key, "keygen.algo")) { |
if (!strcmp (key, "keygen.algo")) { |
348 |
_snprintf (buf, sizeof (buf)-1, "%d", ctx->pubkey_algo); |
_snprintf (buf, DIM (buf)-1, "%d", ctx->pubkey_algo); |
349 |
return buf; |
return buf; |
350 |
} |
} |
351 |
if (!strcmp (key, "keygen.size")) { |
if (!strcmp (key, "keygen.size")) { |
352 |
_snprintf (buf, sizeof (buf)-1, "%d", ctx->pubkey_size); |
_snprintf (buf, DIM (buf)-1, "%d", ctx->pubkey_size); |
353 |
return buf; |
return buf; |
354 |
} |
} |
355 |
if (!strcmp (key, "keygen.valid")) { |
if (!strcmp (key, "keygen.valid")) { |
356 |
_snprintf (buf, sizeof (buf)-1, "%d", ctx->getValidDays ()); |
_snprintf (buf, DIM (buf)-1, "%d", ctx->getValidDays ()); |
357 |
return buf; |
return buf; |
358 |
} |
} |
359 |
if (!strcmp (key, "keyedit.prompt")) { |
if (!strcmp (key, "keyedit.prompt")) { |
399 |
static char buf[128] = {0}; |
static char buf[128] = {0}; |
400 |
|
|
401 |
if (!strcmp (key, "keyedit.prompt") && !ctx->cmd_sent) { |
if (!strcmp (key, "keyedit.prompt") && !ctx->cmd_sent) { |
402 |
_snprintf (buf, sizeof (buf)-1, "uid %d", ctx->getUseridIndex ()); |
_snprintf (buf, DIM (buf)-1, "uid %d", ctx->getUseridIndex ()); |
403 |
ctx->cmd_sent = 1; |
ctx->cmd_sent = 1; |
404 |
ctx->cnt = 1; |
ctx->cnt = 1; |
405 |
return buf; |
return buf; |
406 |
} |
} |
407 |
if (!strcmp (key, "keyedit.prompt") && ctx->cnt == 1) { |
if (!strcmp (key, "keyedit.prompt") && ctx->cnt == 1) { |
408 |
_snprintf (buf, sizeof buf-1, "setpref %s", ctx->new_prefs); |
_snprintf (buf, DIM (buf)-1, "setpref %s", ctx->new_prefs); |
409 |
ctx->cnt = 2; |
ctx->cnt = 2; |
410 |
return buf; |
return buf; |
411 |
} |
} |
641 |
ctx->cnt = 1; |
ctx->cnt = 1; |
642 |
return "addrevoker"; |
return "addrevoker"; |
643 |
} |
} |
644 |
if (ctx->cnt == 1 && !strcmp (key, "keyedit.add_revoker")) { |
if (!strcmp (key, "keyedit.add_revoker")) |
|
ctx->cnt = 2; |
|
645 |
return ctx->name; |
return ctx->name; |
646 |
} |
|
647 |
if (ctx->cnt == 2 && !strcmp (key, "keyedit.add_revoker.okay")) { |
if (!strcmp (key, "keyedit.add_revoker.okay")) |
|
ctx->cnt = 3; |
|
648 |
return "Y"; |
return "Y"; |
649 |
} |
|
650 |
if (ctx->cnt == 3 && !strcmp (key, "passphrase.enter")) { |
if (!strcmp (key, "passphrase.enter")) |
|
ctx->cnt = 4; |
|
651 |
return ctx->pass; |
return ctx->pass; |
652 |
} |
|
653 |
if (ctx->cnt == 4 && !strcmp (key, "keyedit.prompt")) { |
if (ctx->cnt > 0 && !strcmp (key, "keyedit.prompt")) { |
654 |
ctx->reset (); |
ctx->reset (); |
655 |
return "save"; |
return "save"; |
656 |
} |
} |
748 |
ke->setResult (EDITKEY_ERR_ALREADY_SIGNED); |
ke->setResult (EDITKEY_ERR_ALREADY_SIGNED); |
749 |
break; |
break; |
750 |
|
|
751 |
|
//case GPGME_STATUS_GOOD_PASSPHRASE: |
752 |
|
// ke->setResult (0); |
753 |
|
// break; |
754 |
|
|
755 |
case GPGME_STATUS_BAD_PASSPHRASE: |
case GPGME_STATUS_BAD_PASSPHRASE: |
756 |
log_debug ("editkey_command_handler: bad passphrase\n"); |
if (!ke->usePassphraseCallback ()) { |
757 |
ke->setResult (EDITKEY_ERR_BAD_PASSPHRASE); |
log_debug ("editkey_command_handler: bad passphrase\n"); |
758 |
|
ke->setResult (EDITKEY_ERR_BAD_PASSPHRASE); |
759 |
|
} |
760 |
break; |
break; |
761 |
|
|
762 |
default: |
default: |
763 |
break; |
break; |
764 |
} |
} |
765 |
|
|
766 |
if (ke->getResult () & EDITKEY_ERR_BAD_PASSPHRASE) { |
/* If the entered passphrase is bad, we supply empty |
767 |
/* If the entered passphrase is bad, we supply empty |
passphrase to abort and send 'quit' as soon as possible. |
768 |
passphrase to abort and send 'quit' as soon as possible. */ |
But this semantic is not used when we use the callback mode. */ |
769 |
|
if (!ke->usePassphraseCallback() && |
770 |
|
(ke->getResult () & EDITKEY_ERR_BAD_PASSPHRASE)) { |
771 |
|
|
772 |
if (!strcmp (key, "passphrase.enter")) |
if (!strcmp (key, "passphrase.enter")) |
773 |
WriteFile (hd, "\n", 1, &n, NULL); |
WriteFile (hd, "\n", 1, &n, NULL); |
774 |
if (!strcmp (key, "keyedit.prompt")) |
if (!strcmp (key, "keyedit.prompt")) |
886 |
Return value: gpg error constant. */ |
Return value: gpg error constant. */ |
887 |
static gpgme_error_t |
static gpgme_error_t |
888 |
map_result (GpgKeyEdit *ke) |
map_result (GpgKeyEdit *ke) |
889 |
{ |
{ |
|
/* XXX Sometimes ALREADY_SIGNED indicates an failure. */ |
|
890 |
if (!ke->getResult ()) |
if (!ke->getResult ()) |
891 |
return gpg_error (GPG_ERR_NO_ERROR); |
return gpg_error (GPG_ERR_NO_ERROR); |
892 |
if (ke->getResult () & EDITKEY_ERR_BAD_PASSPHRASE) |
if (ke->getResult () & EDITKEY_ERR_BAD_PASSPHRASE) |