Class KeychainSecretStore
- All Implemented Interfaces:
SecretStore
SecretStore backed by the macOS
Each operation shells out to
store(java.lang.String, char[])→add-generic-password -U (create or update).find(java.lang.String)→find-generic-password -g (print the password to stderr).exists(java.lang.String)→find-generic-password (presence only, without the password).delete(java.lang.String)→delete-generic-password .
Platform. Only macOS is supported; on any other OS, or when FailMode.
Backend-unavailable behavior. A key that is simply not present is a normal absent result, never a
failure. A genuine failure — the tool missing, a non-zero exit that is not "item not found", or a timeout
— is resolved by the FailMode chosen at construction: FailMode.FAIL_OPEN degrades to
absent/no-op, while FailMode.FAIL_CLOSED (the default) throws.
Secret handling. store(java.lang.String, char[]) never places the secret on the security process's argv, and never
relies on the CLI's password prompt (a bare security read from the controlling terminal,
ps), and no terminal is ever read. Each of the three values is
double-quoted, with only security -i
for spaces, tabs, single and double quotes, backslashes, shell metacharacters, and non-ASCII text). Neither
store(java.lang.String, char[]) nor find(java.lang.String) materializes the secret as a String: store encodes the
char[] directly to the stdin byte payload, and find decodes the retrieved bytes into a
char[] (zeroing the intermediate buffers). The value is never logged or toString()'d by this class. Because the command is
newline-terminated, a key, service, or secret containing '\n' or '\r' cannot be delivered this way
(it would end or inject a command) and is rejected by store(java.lang.String, char[]) before any process is started.
Reading secrets. find(java.lang.String) deliberately does not use
- Since:
- 10.0.0
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final longDefault per-call timeout, in seconds, bounding a slow/hungsecurityinvocation. -
Constructor Summary
ConstructorsConstructorDescriptionKeychainSecretStore(String service) Constructor usingFailMode.FAIL_CLOSEDand thedefaulttimeout.KeychainSecretStore(String service, FailMode failMode) Constructor using thedefaulttimeout.KeychainSecretStore(String service, FailMode failMode, long timeoutSeconds) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionbooleanDeletes the secret stored under the specified key.booleanReturns whether a secret is stored under the specified key without materializing its value.Optional<char[]>Returns the secret stored under the specified key.voidStores a secret under the specified key, replacing any existing value.
-
Field Details
-
DEFAULT_TIMEOUT_SECONDS
Default per-call timeout, in seconds, bounding a slow/hungsecurityinvocation.- See Also:
-
-
Constructor Details
-
KeychainSecretStore
Constructor usingFailMode.FAIL_CLOSEDand thedefaulttimeout.- Parameters:
service- The keychain service name that namespaces this store's items. Must not benull or blank.
-
KeychainSecretStore
Constructor using thedefaulttimeout.- Parameters:
service- The keychain service name that namespaces this store's items. Must not benull or blank.failMode- The policy applied on a backend failure. Must not benull .
-
KeychainSecretStore
Constructor.- Parameters:
service- The keychain service name that namespaces this store's items. Must not benull or blank.failMode- The policy applied on a backend failure. Must not benull .timeoutSeconds- The per-call timeout, in seconds, bounding a slow/hungsecurityinvocation. Must be> 0.
-
-
Method Details
-
store
Description copied from interface:SecretStoreStores a secret under the specified key, replacing any existing value.The caller retains ownership of
secret and may zero it after this call returns; an implementation that needs to retain the value must copy it.- Specified by:
storein interfaceSecretStore- Parameters:
key- The key under which to store the secret. Must not benull .secret- The secret value. Must not benull .
-
find
Description copied from interface:SecretStoreReturns the secret stored under the specified key.The returned array is the caller's to own and zero; it is not a live view of the store's internal state.
- Specified by:
findin interfaceSecretStore- Parameters:
key- The key to look up. Must not benull .- Returns:
- The secret value, or
Optional.empty()if no secret is stored under the key.
-
exists
Description copied from interface:SecretStoreReturns whether a secret is stored under the specified key without materializing its value.- Specified by:
existsin interfaceSecretStore- Parameters:
key- The key to check. Must not benull .- Returns:
true if a secret is stored under the key.
-
delete
Description copied from interface:SecretStoreDeletes the secret stored under the specified key.- Specified by:
deletein interfaceSecretStore- Parameters:
key- The key to delete. Must not benull .- Returns:
true if a secret was present and removed;false if the key was already absent.
-