1
0
Fork 0
mirror of git://git.gnupg.org/gnupg.git synced 2025-07-02 22:46:30 +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: 5517
This commit is contained in:
Ingo Klöcker 2021-07-12 12:20:28 +02:00 committed by Werner Koch
parent 29d58e9de7
commit bf20a80f68
No known key found for this signature in database
GPG key ID: E3FDFF218E45B72B
4 changed files with 104 additions and 0 deletions

View file

@ -983,6 +983,67 @@ setup_genpin (ctrl_t ctrl)
}
/* 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 the text of an option (usually represented
by a checkbox) as used in pinentry. */
{ "label", "pinentry.formatted_passphrase.label",
N_("Format the passphrase") },
/* TRANSLATORS: This is the tooltip shown by pinentry when
hovering over the option for formatted passphrase.
The length is limited to about 900 characters. */
{ "tt", "pinentry.formatted_passphrase.tooltip",
N_("Enable this option to make the passphrase easier readable by "
"grouping its characters.") },
/* 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=%d",
opt.pinentry_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)
@ -1556,6 +1617,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. */