TomDesktopSecretStore class final

TomSecretStore over the OS keychain for plain Dart programs (a CLI, a background service compiled ahead of time), where flutter_secure_storage is not available:

  • macOS: the login keychain through /usr/bin/security. The one call that carries the secret (add-generic-password) is sent on the tool's standard input (security -i), never as an argument: an argument is visible to every user in ps.
  • Linux: libsecret through secret-tool, the secret on standard input. Without a D-Bus session (an SSH login) or without secret-tool the store is not available.
  • Windows: the Credential Manager through CredWriteW, CredReadW and CredDeleteW (CRED_TYPE_GENERIC, target <service>/<handle>).

Secrets are stored as base64 of their UTF-8 bytes, so every backend reads them back unambiguously (security prints a non-ASCII password as hex). Every call has a timeout: a keychain that would wait for a prompt answers as not available instead of hanging. A failing call throws TomSecretStoreException; isAvailable says beforehand whether the store can be used at all.

Implemented types

Constructors

TomDesktopSecretStore({required String service, Duration timeout = const Duration(seconds: 10), String? operatingSystem, Map<String, String>? environment, String securityExecutable = '/usr/bin/security', String secretToolExecutable = 'secret-tool'})
The store of service (the keychain's service name, e.g. tom-secrets-manager). operatingSystem and environment default to this process's.

Properties

hashCode → int
The hash code for this object.
no setterinherited
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
service → String
The keychain's service name.
final
timeout → Duration
How long one call may take.
final

Methods

delete(String handle) → Future<void>
Forgets the secret at handle, if any.
override
isAvailable() → Future<bool>
Whether the keychain can be used now: a probe item is written and deleted. A locked keychain, a missing D-Bus session or tool, or a Windows logon without credentials answer false; never a prompt.
override
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
read(String handle) → Future<String?>
The secret stored under handle, or null when nothing is.
override
toString() → String
A string representation of this object.
inherited
write(String handle, String secret) → Future<void>
Stores secret under handle, replacing any current value.
override

Operators

operator ==(Object other) → bool
The equality operator.
inherited