windows_credentials
Reads the desktop app's key from Windows Credential Manager.
The desktop app stores its key through keyring-core with
windows-native-keyring-store's default settings, which write service
Bitfount, account ENCRYPTION::KEY as a generic credential with:
| Field | Value |
|---|---|
| target | {account}.{service}, so ENCRYPTION::KEY.Bitfount |
| UserName | {account} |
| blob | the password as UTF-16LE, with no terminator |
| persistence | CRED_PERSIST_ENTERPRISE |
The desktop app's Windows contract test pins this format against the Rust store itself, so a change on that side fails its CI rather than this reader.
This module reads through pywin32's win32cred rather than the keyring
package: keyring's Windows backend looks under target service (or
account@service), never account.service, so it would never find the app's
credential; and, as on macOS, keyring.get_password hides the Win32 error that
the key lookup and telemetry need.
Credential Manager has no per-app access list: every process running as the same Windows user reads the credential without a prompt, and a process running as a different user (a service account, say) can't read it at all.
Only Windows needs pywin32. Elsewhere every read fails with keychain_error.
Module
Functions
decode_keyring_core_blob
def decode_keyring_core_blob(blob: bytes) ‑> bytes:Turns the app's credential blob into the password's UTF-8 bytes.
Arguments
blob: The credential's blob, aswindows-native-keyring-storewrote it.
Returns The password, UTF-8 encoded, so callers treat it as they treat the macOS reader's result.
Raises
KeychainReadError: Ifblobisn't valid UTF-16LE (an odd length or a lone surrogate), with reasonkeychain_error. The message never includes any part of the blob.
keyring_core_target
def keyring_core_target(service: str, account: str) ‑> str:The credential target windows-native-keyring-store uses by default.
Arguments
service: The entry's service.account: The entry's account (keyring-core's "user").
Returns
{account}.{service}.
read_generic_password
def read_generic_password(service: str, account: str) ‑> bytes:Reads a password the desktop app stored in Credential Manager.
Arguments
service: The entry's service.account: The entry's account.
Returns The password, UTF-8 encoded.
Raises
KeychainReadError: If the credential can't be read or isn't UTF-16LE, with the reason and the Win32 error (0 for a bad blob). Off Windows, always, with reasonkeychain_errorand status 0.
reason_for_winerror
def reason_for_winerror( winerror: int,) ‑> KeychainUnavailableReason:Maps a failed read's Win32 error to the reason the key lookup reports.
ERROR_NOT_FOUND(1168) isno_item.ERROR_ACCESS_DENIED(5) isaccess_denied.- Anything else is
keychain_error, includingERROR_NO_SUCH_LOGON_SESSION(1312), which means the process has no loaded user profile and so no Credential Manager.
Arguments
winerror: The Win32 error code the read failed with.
Returns The reason for the failure.