diff options
author | Werner Koch <wk@gnupg.org> | 2014-04-15 16:40:48 +0200 |
---|---|---|
committer | Werner Koch <wk@gnupg.org> | 2014-04-15 19:44:50 +0200 |
commit | db3b528239c9d56bc71fd2283e07a3f1d91e4fd0 (patch) | |
tree | 905f77e255d5f32f01590c37a6802dc773de96e6 /g10/delkey.c | |
parent | gpg: Re-indent a file. (diff) | |
download | gnupg2-db3b528239c9d56bc71fd2283e07a3f1d91e4fd0.tar.xz gnupg2-db3b528239c9d56bc71fd2283e07a3f1d91e4fd0.zip |
gpg: Re-enable secret key deletion.
* g10/call-agent.c (agent_delete_key): New.
* g10/keydb.h (FORMAT_KEYDESC_DELKEY): New.
* g10/passphrase.c (gpg_format_keydesc): Support new format.
* g10/delkey.c (do_delete_key): Add secret key deletion.
Diffstat (limited to 'g10/delkey.c')
-rw-r--r-- | g10/delkey.c | 47 |
1 files changed, 43 insertions, 4 deletions
diff --git a/g10/delkey.c b/g10/delkey.c index 2e4477be9..3de705dfa 100644 --- a/g10/delkey.c +++ b/g10/delkey.c @@ -40,6 +40,7 @@ #include "ttyio.h" #include "status.h" #include "i18n.h" +#include "call-agent.h" /**************** @@ -52,7 +53,7 @@ do_delete_key( const char *username, int secret, int force, int *r_sec_avail ) { gpg_error_t err; kbnode_t keyblock = NULL; - kbnode_t node; + kbnode_t node, kbctx; KEYDB_HANDLE hd; PKT_public_key *pk = NULL; u32 keyid[2]; @@ -156,9 +157,47 @@ do_delete_key( const char *username, int secret, int force, int *r_sec_avail ) { if (secret) { - log_error (_("deleting secret key not implemented\n")); - err = gpg_error (GPG_ERR_NOT_IMPLEMENTED); /* FIXME */ - goto leave; + char *prompt; + gpg_error_t firsterr = 0; + char *hexgrip; + + setup_main_keyids (keyblock); + for (kbctx=NULL; (node = walk_kbnode (keyblock, &kbctx, 0)); ) + { + if (!(node->pkt->pkttype == PKT_PUBLIC_KEY + || node->pkt->pkttype == PKT_PUBLIC_SUBKEY)) + continue; + + if (agent_probe_secret_key (NULL, node->pkt->pkt.public_key)) + continue; /* No secret key for that public (sub)key. */ + + prompt = gpg_format_keydesc (node->pkt->pkt.public_key, + FORMAT_KEYDESC_DELKEY, 1); + err = hexkeygrip_from_pk (node->pkt->pkt.public_key, &hexgrip); + if (!err) + err = agent_delete_key (NULL, hexgrip, prompt); + xfree (prompt); + xfree (hexgrip); + if (err) + { + if (gpg_err_code (err) == GPG_ERR_KEY_ON_CARD) + write_status_text (STATUS_DELETE_PROBLEM, "1"); + log_error (_("deleting secret %s failed: %s\n"), + (node->pkt->pkttype == PKT_PUBLIC_KEY + ? _("key"):_("subkey")), + gpg_strerror (err)); + if (!firsterr) + firsterr = err; + if (gpg_err_code (err) == GPG_ERR_CANCELED + || gpg_err_code (err) == GPG_ERR_FULLY_CANCELED) + break; + } + + } + + err = firsterr; + if (firsterr) + goto leave; } else { |