<xi:include href="version-info.xml" xpointer="v249"/></listitem>
</varlistentry>
+ <varlistentry>
+ <term><option>password-cache=yes|no|read-only</option></term>
+
+ <listitem><para>Controls whether to use cache for passwords or security token PINs.
+ Takes a boolean or the special string <literal>read-only</literal>. Defaults to
+ <literal>yes</literal>.</para>
+
+ <para>If set to <literal>read-only</literal>, the kernel keyring is checked for a
+ password/PIN before requesting one interactively. If set to <literal>yes</literal>,
+ in addition to checking the keyring, any password/PIN entered interactively is cached
+ in the keyring with a 2.5-minute timeout before being purged.</para>
+
+ <para>Note that this option is not permitted for PKCS#11 security tokens. The reasoning
+ behind this is that PKCS#11 security tokens are usually configured to lock after being
+ supplied an invalid PIN multiple times, so using the cache might inadvertently lock the
+ token.</para>
+
+ <xi:include href="version-info.xml" xpointer="v257"/></listitem>
+ </varlistentry>
+
<varlistentry>
<term><option>pkcs11-uri=</option></term>
static unsigned arg_tries = 3;
static bool arg_readonly = false;
static bool arg_verify = false;
-static AskPasswordFlags arg_ask_password_flags = 0;
+static bool arg_password_cache_set = false; /* Not the actual argument value, just an indicator that some value is set */
+static AskPasswordFlags arg_ask_password_flags = ASK_PASSWORD_ACCEPT_CACHED | ASK_PASSWORD_PUSH_CACHE;
static bool arg_discards = false;
static bool arg_same_cpu_crypt = false;
static bool arg_submit_from_crypt_cpus = false;
SET_FLAG(arg_ask_password_flags, ASK_PASSWORD_ECHO, r);
SET_FLAG(arg_ask_password_flags, ASK_PASSWORD_SILENT, !r);
}
+ } else if ((val = startswith(option, "password-cache="))) {
+ arg_password_cache_set = true;
+
+ if (streq(val, "read-only")) {
+ arg_ask_password_flags |= ASK_PASSWORD_ACCEPT_CACHED;
+ arg_ask_password_flags &= ~ASK_PASSWORD_PUSH_CACHE;
+ } else {
+ r = parse_boolean(val);
+ if (r < 0) {
+ log_warning_errno(r, "Invalid password-cache= option \"%s\", ignoring.", val);
+ return 0;
+ }
+
+ SET_FLAG(arg_ask_password_flags, ASK_PASSWORD_ACCEPT_CACHED|ASK_PASSWORD_PUSH_CACHE, r);
+ }
} else if (STR_IN_SET(option, "allow-discards", "discard"))
arg_discards = true;
else if (streq(option, "same-cpu-crypt"))
log_warning("skip= ignored with type %s", arg_type);
}
+ if (arg_pkcs11_uri || arg_pkcs11_uri_auto) {
+ /* If password-cache was not configured explicitly, default to no cache for PKCS#11 */
+ if (!arg_password_cache_set)
+ arg_ask_password_flags &= ~(ASK_PASSWORD_ACCEPT_CACHED|ASK_PASSWORD_PUSH_CACHE);
+
+ /* This prevents future backward-compatibility issues if we decide to allow caching for PKCS#11 */
+ if (FLAGS_SET(arg_ask_password_flags, ASK_PASSWORD_ACCEPT_CACHED))
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Password cache is not supported for PKCS#11 security tokens.");
+ }
+
return 0;
}
const char *vol,
const char *src,
usec_t until,
- bool accept_cached,
+ bool ignore_cached,
PassphraseType passphrase_type,
char ***ret) {
_cleanup_free_ char *friendly = NULL, *text = NULL, *disk_path = NULL, *id = NULL;
_cleanup_strv_free_erase_ char **passwords = NULL;
- AskPasswordFlags flags = arg_ask_password_flags | ASK_PASSWORD_PUSH_CACHE;
+ AskPasswordFlags flags = arg_ask_password_flags;
int r;
assert(vol);
.credential = "cryptsetup.passphrase",
};
- r = ask_password_auto(
- &req,
- until,
- flags | (accept_cached*ASK_PASSWORD_ACCEPT_CACHED),
- &passwords);
+ if (ignore_cached)
+ flags &= ~ASK_PASSWORD_ACCEPT_CACHED;
+
+ r = ask_password_auto(&req, until, flags, &passwords);
if (r < 0)
return log_error_errno(r, "Failed to query password: %m");
const char *credential) {
#if HAVE_LIBCRYPTSETUP_PLUGINS
- AskPasswordFlags flags = arg_ask_password_flags | ASK_PASSWORD_PUSH_CACHE | ASK_PASSWORD_ACCEPT_CACHED;
+ AskPasswordFlags flags = arg_ask_password_flags;
_cleanup_strv_free_erase_ char **pins = NULL;
int r;
return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "No passphrase or recovery key registered.");
}
- r = get_password(volume, source, until, use_cached_passphrase && !arg_verify, passphrase_type, &passwords);
+ r = get_password(
+ volume,
+ source,
+ until,
+ /* ignore_cached= */ !use_cached_passphrase || arg_verify,
+ passphrase_type,
+ &passwords);
use_cached_passphrase = false;
if (r == -EAGAIN)
continue;