cache_key_lookup
Finds the SQLCipher cache key, read-only, in one fixed order.
Every process that needs the cache key asks resolve_cache_key, which looks in
this order and never creates or changes a keychain item:
- An explicit key:
BITFOUNT_CACHE_ENCRYPTION_KEY, or the file named byBITFOUNT_CACHE_ENCRYPTION_KEY_FILE(never both). It is the cache key itself. A malformed or unreadable explicit key is a failure: the lookup doesn't fall back to the keychain, which would quietly use a different key from the one configured. - The desktop app's
ENCRYPTION::KEY, read from the OS keychain without UI and derived into the cache key. Only macOS and Windows have a keychain to read.
A key whose id doesn't match the one recorded beside the caches is dropped.
Opting out (BITFOUNT_CACHE_ENCRYPTION_ENABLED=false) doesn't stop the lookup,
because caches already encrypted must still open; it only changes the outcome.
The first key a lookup finds is held for the life of the process; a failed read isn't, so a keychain that was locked can still be read later. The key id check and the opt-out are applied afresh on every lookup.
Module
Functions
resolve_cache_key
def resolve_cache_key( cache_dir: Path | None = None,) ‑> CacheKeyResolution:Looks up the cache key, read-only, in the order the module describes.
Arguments
cache_dir: The directory whose recorded key id the key must match. Defaults to the configured cache directory.
Returns
The lookup's result. Once a key has been found, later lookups in the
process reuse it without reading again, but still check it against
cache_dir and the current settings.
Classes
CacheKeyOutcome
class CacheKeyOutcome(*args, **kwds):Whether the caches can be encrypted with the key that was found.
Ancestors
CacheKeyResolution
class CacheKeyResolution( source: CacheKeySource, outcome: CacheKeyOutcome, reason: CacheKeyUnavailableReason | None, key: CacheKey | None, duration_seconds: float, refused_key_id: str | None = None, recorded_key_id: str | None = None,):The result of one cache key lookup.
Attributes
source: Where the key came from, or where the lookup looked last.outcome: Whether the key can be used, or the site has opted out.reason: Why no usable key was found;Nonewhen one was.key: The key, orNone. It prints as its key id only.duration_seconds: How long the lookup took.refused_key_id: The public id of a key that was found but refused, because it doesn't match the key id recorded beside the caches.recorded_key_id: The key id recorded beside the caches, when a found key didn't match it.
Variables
-
duration_seconds : float
-
key : CacheKey | None
key_id : str | None- The public id of the key that was found, whether or not it was refused.
-
outcome : CacheKeyOutcome
-
reason : CacheKeyUnavailableReason | None
-
recorded_key_id : str | None
-
refused_key_id : str | None
-
source : CacheKeySource
CacheKeySource
class CacheKeySource(*args, **kwds):Where the lookup found the key, or looked last when it found none.
Ancestors
CacheKeyUnavailableReason
class CacheKeyUnavailableReason(*args, **kwds):Why no usable key was found, as reported in logs and telemetry.
The keychain's own reasons keep their codes.
Ancestors
Variables
- static
ACCESS_DENIED
- static
INVALID_EXPLICIT_KEY
- static
ITEM_UNREADABLE
- static
KEYCHAIN_ERROR
- static
KEYCHAIN_LOCKED
- static
KEY_FILE_UNREADABLE
- static
KEY_ID_MISMATCH
- static
KEY_ID_RECORD_UNREADABLE
- static
NO_ITEM
- static
NO_KEYCHAIN
- static
UI_REQUIRED