aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIngo Klöcker <[email protected]>2021-08-12 08:47:34 +0000
committerWerner Koch <[email protected]>2021-08-16 10:45:37 +0000
commit32fbdddf8b4729d9a54a7751c0b5e406a470657f (patch)
treeb774d38c4924bfbfcc81f6a04acfad8e73f37840
parentcommon: Pass XDG_SESSION_TYPE and QT_QPA_PLATFORM envvars to pinentry (diff)
downloadgnupg-32fbdddf8b4729d9a54a7751c0b5e406a470657f.tar.gz
gnupg-32fbdddf8b4729d9a54a7751c0b5e406a470657f.zip
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: bf20a80f68449cc83b67c53ba9a0a84c45827ac4 Backport-from-master: 99601778f4a9dc1c9fee792361c959f5e0732cfd Signed-off-by: Werner Koch <[email protected]>
-rw-r--r--agent/agent.h3
-rw-r--r--agent/call-pinentry.c54
-rw-r--r--agent/gpg-agent.c7
-rw-r--r--doc/gpg-agent.texi9
4 files changed, 73 insertions, 0 deletions
diff --git a/agent/agent.h b/agent/agent.h
index fb4641259..ad687e69d 100644
--- a/agent/agent.h
+++ b/agent/agent.h
@@ -99,6 +99,9 @@ struct
upon this timeout value. */
unsigned long pinentry_timeout;
+ /* If set, then passphrase formatting is enabled in pinentry. */
+ int pinentry_formatted_passphrase;
+
/* The default and maximum TTL of cache entries. */
unsigned long def_cache_ttl; /* Default. */
unsigned long def_cache_ttl_ssh; /* for SSH. */
diff --git a/agent/call-pinentry.c b/agent/call-pinentry.c
index c306d1b72..6648a18ba 100644
--- a/agent/call-pinentry.c
+++ b/agent/call-pinentry.c
@@ -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. */
diff --git a/agent/gpg-agent.c b/agent/gpg-agent.c
index b167c34ea..43e8d96c7 100644
--- a/agent/gpg-agent.c
+++ b/agent/gpg-agent.c
@@ -98,6 +98,7 @@ enum cmd_and_opt_values
oPinentryTouchFile,
oPinentryInvisibleChar,
oPinentryTimeout,
+ oPinentryFormattedPassphrase,
oDisplay,
oTTYname,
oTTYtype,
@@ -191,6 +192,8 @@ static ARGPARSE_OPTS opts[] = {
ARGPARSE_s_s (oPinentryTouchFile, "pinentry-touch-file", "@"),
ARGPARSE_s_s (oPinentryInvisibleChar, "pinentry-invisible-char", "@"),
ARGPARSE_s_u (oPinentryTimeout, "pinentry-timeout", "@"),
+ ARGPARSE_s_n (oPinentryFormattedPassphrase, "pinentry-formatted-passphrase",
+ "@"),
ARGPARSE_s_s (oScdaemonProgram, "scdaemon-program",
/* */ N_("|PGM|use PGM as the SCdaemon program") ),
ARGPARSE_s_n (oDisableScdaemon, "disable-scdaemon",
@@ -829,6 +832,7 @@ parse_rereadable_options (ARGPARSE_ARGS *pargs, int reread)
xfree (opt.pinentry_invisible_char);
opt.pinentry_invisible_char = NULL;
opt.pinentry_timeout = 0;
+ opt.pinentry_formatted_passphrase = 0;
opt.scdaemon_program = NULL;
opt.def_cache_ttl = DEFAULT_CACHE_TTL;
opt.def_cache_ttl_ssh = DEFAULT_CACHE_TTL_SSH;
@@ -889,6 +893,9 @@ parse_rereadable_options (ARGPARSE_ARGS *pargs, int reread)
opt.pinentry_invisible_char = xtrystrdup (pargs->r.ret_str); break;
break;
case oPinentryTimeout: opt.pinentry_timeout = pargs->r.ret_ulong; break;
+ case oPinentryFormattedPassphrase:
+ opt.pinentry_formatted_passphrase = 1;
+ break;
case oScdaemonProgram: opt.scdaemon_program = pargs->r.ret_str; break;
case oDisableScdaemon: opt.disable_scdaemon = 1; break;
case oDisableCheckOwnSocket: disable_check_own_socket = 1; break;
diff --git a/doc/gpg-agent.texi b/doc/gpg-agent.texi
index 3955ed0e2..7dbe0bd06 100644
--- a/doc/gpg-agent.texi
+++ b/doc/gpg-agent.texi
@@ -484,6 +484,15 @@ user input. The default value of 0 does not ask the pinentry to
timeout, however a Pinentry may use its own default timeout value in
this case. A Pinentry may or may not honor this request.
+@item --pinentry-formatted-passphrase
+@opindex pinentry-formatted-passphrase
+This option asks the Pinentry to enable passphrase formatting when asking the
+user for a new passphrase and masking of the passphrase is turned off.
+
+If passphrase formatting is enabled, then all non-breaking space characters
+are stripped from the entered passphrase. Passphrase formatting is mostly
+useful in combination with passphrases generated with the GENPIN command.
+
@item --pinentry-program @var{filename}
@opindex pinentry-program
Use program @var{filename} as the PIN entry. The default is