1
0
Fork 0
mirror of git://git.gnupg.org/gnupg.git synced 2025-07-03 22:56:33 +02:00

agent: New option --pinentry-formatted-passphrase

* agent/agent.h (opt): Add field pinentry_formatted_passphrase.
* agent/call-pinentry.c (setup_formatted_passphrase): New.
(agent_get_passphrase): Pass option to pinentry.
* agent/gpg-agent.c (oPinentryFormattedPassphrase): New.
(opts): Add option.
(parse_rereadable_options): Set option.
--

GnuPG-bug-id: 5553, 5517

This is a squashed backport of two commits from master.
Backport-from-master: bf20a80f68
Backport-from-master: 99601778f4

Signed-off-by: Werner Koch <wk@gnupg.org>
This commit is contained in:
Ingo Klöcker 2021-08-12 10:47:34 +02:00 committed by Werner Koch
parent 8fff61de94
commit 32fbdddf8b
No known key found for this signature in database
GPG key ID: E3FDFF218E45B72B
4 changed files with 73 additions and 0 deletions

View file

@ -854,6 +854,56 @@ inq_quality (void *opaque, const char *line)
}
/* Helper to setup pinentry for formatted passphrase. */
static gpg_error_t
setup_formatted_passphrase (ctrl_t ctrl)
{
static const struct { const char *key, *help_id, *value; } tbl[] = {
/* TRANSLATORS: This is a text shown by pinentry if the option
for formatted passphrase is enabled. The length is
limited to about 900 characters. */
{ "hint", "pinentry.formatted_passphrase.hint",
N_("Note: The blanks are not part of the passphrase.") },
{ NULL, NULL }
};
gpg_error_t rc;
char line[ASSUAN_LINELENGTH];
int idx;
char *tmpstr;
const char *s;
(void)ctrl;
if (opt.pinentry_formatted_passphrase)
{
snprintf (line, DIM(line), "OPTION formatted-passphrase");
rc = assuan_transact (entry_ctx, line, NULL, NULL, NULL, NULL, NULL,
NULL);
if (rc && gpg_err_code (rc) != GPG_ERR_UNKNOWN_OPTION)
return rc;
for (idx=0; tbl[idx].key; idx++)
{
tmpstr = gnupg_get_help_string (tbl[idx].help_id, 0);
if (tmpstr)
s = tmpstr;
else
s = L_(tbl[idx].value);
snprintf (line, DIM(line), "OPTION formatted-passphrase-%s=%s",
tbl[idx].key, s);
xfree (tmpstr);
rc = assuan_transact (entry_ctx, line, NULL, NULL, NULL, NULL, NULL,
NULL);
if (rc && gpg_err_code (rc) != GPG_ERR_UNKNOWN_OPTION)
return rc;
}
}
return 0;
}
/* Helper for agent_askpin and agent_get_passphrase. */
static gpg_error_t
setup_qualitybar (ctrl_t ctrl)
@ -1334,6 +1384,10 @@ agent_get_passphrase (ctrl_t ctrl,
return unlock_pinentry (ctrl, rc);
}
rc = setup_formatted_passphrase (ctrl);
if (rc)
return unlock_pinentry (ctrl, rc);
if (!pininfo)
{
/* Legacy method without PININFO. */