cache_key
The SQLCipher cache key, derived from the desktop app's encryption key.
The desktop app keeps one AES-GCM-256 key in the OS keychain (service
Bitfount, account ENCRYPTION::KEY), stored as a JSON Web Key. The caches
never use that key directly; they use keys derived from it:
| Key | Derived from | HKDF info | Length |
|---|---|---|---|
| cache key | the JWK's k | CACHE_KEY_INFO | 32 |
| key id (public) | cache key | KEY_ID_INFO | 8, as hex |
Both derivations are HKDF-SHA256 with an empty salt. The desktop app derives the same two values, so the labels and lengths are a contract with it: changing either strands every encrypted cache.
Module
Functions
cache_key_from_hex
def cache_key_from_hex(value: str) ‑> CacheKey:Parses an explicit cache key, as BITFOUNT_CACHE_ENCRYPTION_KEY holds it.
Arguments
value: The key as 64 hex characters, optionally prefixed0xor0Xand surrounded by whitespace.
Returns The cache key.
Raises
InvalidCacheKeyError: Ifvalueisn't 64 hex characters. The message never includes any part ofvalue.
cache_key_from_jwk
def cache_key_from_jwk(jwk_json: str | bytes) ‑> bytes:Derives the SQLCipher cache key from the desktop app's encryption key.
Arguments
jwk_json: The keychain item's value: a JSON Web Key holding a 32-byte symmetric key, as text or as the UTF-8 bytes the keychain readers return. Pass the bytes as they are: decoding them first raises aUnicodeDecodeErrorthat holds the key.
Returns The 32-byte cache key.
Raises
InvalidCacheKeyError: Ifjwk_jsonisn't a JWK of typeoctwith a 32-bytek. The message never includes any part of the key.
cache_key_id
def cache_key_id(cache_key: bytes) ‑> str:Derives the public id of a cache key.
The id names which key encrypted a cache without revealing the key, so it can appear in logs, telemetry and error messages.
Arguments
cache_key: The 32-byte cache key.
Returns 16 lowercase hex characters.
Raises
InvalidCacheKeyError: Ifcache_keyis not 32 bytes.
Classes
CacheKey
class CacheKey(key: bytes):A 32-byte SQLCipher cache key that keeps itself out of logs and pickles.
It prints as its public key id, and refuses to be pickled or copied, so it
can't reach a log line, a multiprocessing argument or a Prefect parameter
by accident. secret is the only way to the bytes.
Wraps a cache key.
Arguments
key: The 32-byte cache key.
Raises
InvalidCacheKeyError: Ifkeyis not 32 bytes.
Variables
key_id : str- The key's public id: 16 lowercase hex characters.
Methods
secret
def secret(self) ‑> bytes:The key's 32 bytes.