From 0cafab229f6114cd7954973304794eb074bd6527 Mon Sep 17 00:00:00 2001 From: Ralph Plawetzki Date: Fri, 16 Aug 2024 10:23:05 +0200 Subject: [PATCH] Widen API to allow storing keychain entries for an authenticated user (#41) Overlead and extend method storePassphrase() with requiresAuth flag --- .../keychain/KeychainAccessProvider.java | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/cryptomator/integrations/keychain/KeychainAccessProvider.java b/src/main/java/org/cryptomator/integrations/keychain/KeychainAccessProvider.java index 3099528..979e38c 100644 --- a/src/main/java/org/cryptomator/integrations/keychain/KeychainAccessProvider.java +++ b/src/main/java/org/cryptomator/integrations/keychain/KeychainAccessProvider.java @@ -56,7 +56,24 @@ default void storePassphrase(String key, CharSequence passphrase) throws Keychai * @throws KeychainAccessException If storing the password failed */ @Blocking - void storePassphrase(String key, @Nullable String displayName, CharSequence passphrase) throws KeychainAccessException; + default void storePassphrase(String key, @Nullable String displayName, CharSequence passphrase) throws KeychainAccessException { + storePassphrase(key, displayName, passphrase, false); + } + + /** + * Associates a passphrase with a given key and a name for that key. + * + * @param key Key used to retrieve the passphrase via {@link #loadPassphrase(String)}. + * @param displayName The according name to the key. That's the name of the vault displayed in the UI. + * It's passed to the keychain as an additional information about the vault besides the key. + * The parameter does not need to be unique or be checked by the keychain. + * @param passphrase The secret to store in this keychain. + * @param requireOsAuthentication Defines, whether the user needs to authenticate to store a passphrase. + * The authentication mechanism is provided by the operating system dependent + * implementations of this API. + * @throws KeychainAccessException If storing the password failed + */ + void storePassphrase(String key, @Nullable String displayName, CharSequence passphrase, boolean requireOsAuthentication) throws KeychainAccessException; /** * @param key Unique key previously used while {@link #storePassphrase(String, String, CharSequence)} storing a passphrase}.