diff options
author | Ben Kibbey <bjk@luxsci.net> | 2011-03-04 04:20:08 +0100 |
---|---|---|
committer | Werner Koch <wk@gnupg.org> | 2011-03-04 09:39:39 +0100 |
commit | 3582e2efa4cf1fd955d8ebe848e0a996ab15305e (patch) | |
tree | 238b9b60d51cc51afcc2cf152babc43aa80d9944 /agent | |
parent | New agent option pinentry-mode. (diff) | |
download | gnupg2-3582e2efa4cf1fd955d8ebe848e0a996ab15305e.tar.xz gnupg2-3582e2efa4cf1fd955d8ebe848e0a996ab15305e.zip |
Added option --inquire to PRESET_PASSPHRASE. Note that the inquired passphrase will be truncated to the first encountered null byte.
Diffstat (limited to 'agent')
-rw-r--r-- | agent/ChangeLog | 4 | ||||
-rw-r--r-- | agent/command.c | 30 |
2 files changed, 30 insertions, 4 deletions
diff --git a/agent/ChangeLog b/agent/ChangeLog index de5f3da5b..f4be533f7 100644 --- a/agent/ChangeLog +++ b/agent/ChangeLog @@ -1,3 +1,7 @@ +2011-03-03 Ben Kibbey <bjk@luxsci.net> + + * command.c (cmd_preset_passphrase): Add option --inquire. + 2011-03-03 Werner Koch <wk@g10code.com> * gpg-agent.c: Add option --allow-loopback-pinentry. diff --git a/agent/command.c b/agent/command.c index b4b9b9e4c..9df72aa88 100644 --- a/agent/command.c +++ b/agent/command.c @@ -1528,25 +1528,29 @@ cmd_passwd (assuan_context_t ctx, char *line) static const char hlp_preset_passphrase[] = - "PRESET_PASSPHRASE <string_or_keygrip> <timeout> <hexstring>\n" + "PRESET_PASSPHRASE [--inquire] <string_or_keygrip> <timeout> [<hexstring>]\n" "\n" "Set the cached passphrase/PIN for the key identified by the keygrip\n" "to passwd for the given time, where -1 means infinite and 0 means\n" "the default (currently only a timeout of -1 is allowed, which means\n" "to never expire it). If passwd is not provided, ask for it via the\n" - "pinentry module."; + "pinentry module unless --inquire is passed in which case the passphrase\n" + "is retrieved from the client via a server inquire.\n"; static gpg_error_t cmd_preset_passphrase (assuan_context_t ctx, char *line) { int rc; char *grip_clear = NULL; - char *passphrase = NULL; + unsigned char *passphrase = NULL; int ttl; size_t len; + int opt_inquire; if (!opt.allow_preset_passphrase) return set_error (GPG_ERR_NOT_SUPPORTED, "no --allow-preset-passphrase"); + opt_inquire = has_option (line, "--inquire"); + line = skip_options (line); grip_clear = line; while (*line && (*line != ' ' && *line != '\t')) line++; @@ -1577,17 +1581,35 @@ cmd_preset_passphrase (assuan_context_t ctx, char *line) required. */ if (*line) { + if (opt_inquire) + { + rc = set_error (GPG_ERR_ASS_PARAMETER, + "both --inquire and passphrase specified"); + goto leave; + } + /* Do in-place conversion. */ passphrase = line; if (!hex2str (passphrase, passphrase, strlen (passphrase)+1, NULL)) rc = set_error (GPG_ERR_ASS_PARAMETER, "invalid hexstring"); } + else if (opt_inquire) + { + /* Note that the passphrase will be truncated at any null byte and the + * limit is 480 characters. */ + rc = assuan_inquire (ctx, "PASSPHRASE", &passphrase, &len, 480); + } else rc = set_error (GPG_ERR_NOT_IMPLEMENTED, "passphrase is required"); if (!rc) - rc = agent_put_cache (grip_clear, CACHE_MODE_ANY, passphrase, ttl); + { + rc = agent_put_cache (grip_clear, CACHE_MODE_ANY, passphrase, ttl); + if (opt_inquire) + xfree (passphrase); + } +leave: return leave_cmd (ctx, rc); } |