0011 · klav-client library, client TLS and local keys
- Status: accepted
- Date: 2026-11-02
Context
Phase 3 brings the first real clients: the klav CLI and the klavd daemon. Both do the same things with the server (registration, login, session, sync, CRUD) and with the disk (encrypted cache, high-water marks). In addition:
- The CLI must speak HTTPS to real servers, and
deny.tomlbansringandopenssl. - The
metaformat for vaults and projects was left "for phase 3" (api.md§4.1), andklav://bóveda/proyecto/…references need those names. - Unlocking with Touch ID (design §4.3) needs a local unlock key that opens the account without the password, and the local cache needs a key to be encrypted with.
Decision
- New crate
crates/klav-client(Apache-2.0) with everything that isn't interface: account, session and its renewal, encrypted local cache, sync with rollback detection and item CRUD. It is used by the CLI (direct mode) and the daemon, and will be used by the SDK andklav mcp(phase 4). Putting it insideklav-cliwould force the daemon to depend on a binary. It contains no cryptography: everything goes throughklav-core. - TLS with
rustlsand theaws-lc-rsprovider, throughreqwest(featurerustls), with the system certificate store (rustls-platform-verifier).- Rejected alternatives:
rustls-rustcrypto(alpha, and it pulls inrustls-webpki0.102 with open security advisories andrsawith the Marvin attack),native-tls(on Linux it is OpenSSL, which is banned) andring(banned). aws-lc-rsis the defaultrustlsprovider, maintained by AWS and FIPS-validated. Its licenses (ISC, Apache-2.0, MIT, BSD-3-Clause) are already allowed.- TLS is only transport: it protects the session tokens and the plaintext metadata. Klav's data is still end-to-end encrypted with
klav-core, and the rule "Klav's cryptography lives inklav-core" doesn't change.ringandopensslare still banned. webpki-root-certs(Mozilla roots as data, CDLA-Permissive-2.0) comes in as a license exception indeny.toml.http://is only accepted forlocalhost/127.0.0.1/::1(development and tests). The client doesn't follow redirects.- Open question for Omar: if a 100 % RustCrypto provider is preferred once
rustls-rustcryptomatures, the change is local toklav-client.
- Rejected alternatives:
- Vault and project metadata (spec §7.2): JSON
{ "v": 1, "name", "description"? }sealed with the vault key (type0x12) or the project key (type0x13), with the version in the AAD like items. The project's metadata uses the project key so that an agent with a project grant can read its name. - Local hierarchy (spec §12.2):
llave local = HKDF(KEK, tuple("klav/v1/kdf/local-key", cuenta, dispositivo)). It seals a local copy of the identity (type0x40) and the local data (type0x41: cache and tokens). A password unlock recomputes it from the KEK; a biometric one gets it from the Secure Enclave (phase 3, ADR 0013). It is derived rather than random so that no other wrapping is stored on disk and no key cycle is created (KEK ↔ local key). - Local state in a directory (
KLAV_HOME, by default~/Library/Application Support/klavon macOS and~/.config/klavon Linux), mode 0700, files 0600 written atomically. The Secret Key is stored in that directory (as 1Password stores it on the device): on its own it is useless without the password. - Rollback detection (T7): inside the encrypted cache, the client stores the highest revision seen per vault and the highest version per vault, project and item, plus purged items and deleted projects. Any regression (in
/v1/sync, inchangesor in a version) aborts the whole sync with a security error and doesn't touch the cache. The marks survive a vault disappearing. - Session renewal across processes: refresh tokens are single-use and reusing one revokes the session, so the CLI and the daemon renew under a file lock (
session.lock) and, before renewing, adopt the tokens another process may have saved.
Consequences
- A single place for client logic; the CLI and the daemon only change the interface.
- The clients' dependency tree includes
aws-lc-sys(C code compiled withcc): client builds need a C compiler. The server doesn't change. - The cache, the tokens and the local identity never travel to the server; losing the directory only means signing in again.
- If the local cache is deleted, the rollback marks are lost with it (a local attacker with access to the directory is outside the model, §6 of the threat model).