From e201c20f25e7bed29088186c5f717d43047a0f4b Mon Sep 17 00:00:00 2001 From: "Neal H. Walfield" Date: Tue, 19 May 2015 14:58:04 +0200 Subject: [PATCH] agent: Modify agent_clear_passphrase to support an ext. password cache. * agent/agent.h (agent_get_passphrase): Add arguments keyinfo and cache_mode. Update callers. * agent/call-pinentry.c (agent_get_passphrase): Add arguments keyinfo and cache_mode. If KEYINFO and CACHE_MODE describe a cachable key, then send SETKEYINFO to the pinentry. -- Signed-off-by: Neal H. Walfield --- agent/agent.h | 3 ++- agent/call-pinentry.c | 23 ++++++++++++++++++++++- agent/command.c | 5 +++-- 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/agent/agent.h b/agent/agent.h index 45f71eb19..d5d6392a2 100644 --- a/agent/agent.h +++ b/agent/agent.h @@ -366,7 +366,8 @@ int agent_askpin (ctrl_t ctrl, const char *keyinfo, cache_mode_t cache_mode); int agent_get_passphrase (ctrl_t ctrl, char **retpass, const char *desc, const char *prompt, - const char *errtext, int with_qualitybar); + const char *errtext, int with_qualitybar, + const char *keyinfo, cache_mode_t cache_mode); int agent_get_confirmation (ctrl_t ctrl, const char *desc, const char *ok, const char *notokay, int with_cancel); int agent_show_message (ctrl_t ctrl, const char *desc, const char *ok_btn); diff --git a/agent/call-pinentry.c b/agent/call-pinentry.c index 5c3743aa4..abfea93e0 100644 --- a/agent/call-pinentry.c +++ b/agent/call-pinentry.c @@ -1015,7 +1015,8 @@ agent_askpin (ctrl_t ctrl, int agent_get_passphrase (ctrl_t ctrl, char **retpass, const char *desc, const char *prompt, - const char *errtext, int with_qualitybar) + const char *errtext, int with_qualitybar, + const char *keyinfo, cache_mode_t cache_mode) { int rc; @@ -1060,6 +1061,26 @@ agent_get_passphrase (ctrl_t ctrl, prompt = desc && strstr (desc, "PIN")? "PIN": _("Passphrase"); + /* If we have a KEYINFO string and are normal, user, or ssh cache + mode, we tell that the Pinentry so it may use it for own caching + purposes. Most pinentries won't have this implemented and thus + we do not error out in this case. */ + if (keyinfo && (cache_mode == CACHE_MODE_NORMAL + || cache_mode == CACHE_MODE_USER + || cache_mode == CACHE_MODE_SSH)) + snprintf (line, DIM(line)-1, "SETKEYINFO %c/%s", + cache_mode == CACHE_MODE_USER? 'u' : + cache_mode == CACHE_MODE_SSH? 's' : 'n', + keyinfo); + else + snprintf (line, DIM(line)-1, "SETKEYINFO --clear"); + + rc = assuan_transact (entry_ctx, line, + NULL, NULL, NULL, NULL, NULL, NULL); + if (rc && gpg_err_code (rc) != GPG_ERR_ASS_UNKNOWN_CMD) + return unlock_pinentry (rc); + + if (desc) snprintf (line, DIM(line)-1, "SETDESC %s", desc); else diff --git a/agent/command.c b/agent/command.c index 3188bbd0e..8ed9a0f76 100644 --- a/agent/command.c +++ b/agent/command.c @@ -1519,7 +1519,7 @@ cmd_get_passphrase (assuan_context_t ctx, char *line) next_try: rc = agent_get_passphrase (ctrl, &response, desc, prompt, repeat_errtext? repeat_errtext:errtext, - opt_qualbar); + opt_qualbar, cacheid, CACHE_MODE_USER); xfree (repeat_errtext); repeat_errtext = NULL; if (!rc) @@ -1536,7 +1536,8 @@ cmd_get_passphrase (assuan_context_t ctx, char *line) char *response2; rc = agent_get_passphrase (ctrl, &response2, desc2, prompt, - errtext, 0); + errtext, 0, + cacheid, CACHE_MODE_USER); if (rc) break; if (strcmp (response2, response))