Skip to content

Refactor keychain api #56

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.cryptomator.integrations.keychain;

import org.cryptomator.integrations.common.IntegrationsLoader;
import org.cryptomator.integrations.common.NamedServiceProvider;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.Blocking;
import org.jetbrains.annotations.Nls;
Expand All @@ -11,7 +12,7 @@
/**
* This is the interface used by Cryptomator to store passwords securely in external keychains, such as system keychains or password managers.
*/
public interface KeychainAccessProvider {
public interface KeychainAccessProvider extends NamedServiceProvider {

/**
* Loads all available KeychainAccessProvider.
Expand All @@ -23,30 +24,6 @@ static Stream<KeychainAccessProvider> get() {
return IntegrationsLoader.loadAll(KeychainAccessProvider.class).filter(KeychainAccessProvider::isSupported);
}

/**
* A name to display in UI elements. If required, this should be localized.
*
* @return user-friendly name (must not be null or empty)
*/
@Nls(capitalization = Nls.Capitalization.Title)
String displayName();

/**
* Associates a passphrase with a given key.
* <p>
* Note: Caller is responsible for zeroing the passphrase array after use.
*
* @param key Key used to retrieve the passphrase via {@link #loadPassphrase(String)}.
* @param passphrase The secret to store in this keychain.
* @throws KeychainAccessException If storing the password failed
* @deprecated Please use {@link #storePassphrase(String, String, CharSequence)} instead
*/
@Deprecated
@ApiStatus.ScheduledForRemoval(inVersion = "1.2.0")
default void storePassphrase(String key, CharSequence passphrase) throws KeychainAccessException {
storePassphrase(key, null, passphrase);
}

/**
* Associates a passphrase with a given key and a name for that key.
* <p>
Expand All @@ -60,26 +37,7 @@ default void storePassphrase(String key, CharSequence passphrase) throws Keychai
* @throws KeychainAccessException If storing the password failed
*/
@Blocking
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.
* <p>
* Note: Caller is responsible for zeroing the passphrase array after use.
*
* @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;
void storePassphrase(String key, @Nullable String displayName, CharSequence passphrase) throws KeychainAccessException;

/**
* @param key Unique key previously used while {@link #storePassphrase(String, String, CharSequence)} storing a passphrase}.
Expand All @@ -97,22 +55,6 @@ default void storePassphrase(String key, @Nullable String displayName, CharSeque
*/
void deletePassphrase(String key) throws KeychainAccessException;

/**
* Updates a passphrase with a given key. Noop, if there is no item for the given key.
* <p>
* Note: Caller is responsible for zeroing the passphrase array after use.
*
* @param key Unique key previously used while {@link #storePassphrase(String, String, CharSequence)} storing a passphrase}.
* @param passphrase The secret to be updated in this keychain.
* @throws KeychainAccessException If changing the password failed
* @deprecated Please use {@link #changePassphrase(String, String, CharSequence)} instead
*/
@Deprecated
@ApiStatus.ScheduledForRemoval(inVersion = "1.2.0")
default void changePassphrase(String key, CharSequence passphrase) throws KeychainAccessException {
changePassphrase(key, null, passphrase);
}

/**
* Updates a passphrase with a given key and stores a name for that key. Noop, if there is no item for the given key.
* <p>
Expand Down

This file was deleted.