[core] TOTP, Wi-Fi QR payloads, device key wrap (v0.2.0) #3

Manually merged
mnovak merged 2 commits from feature/totp-qr into main 2026-10-31 10:45:08 +01:00
Owner

Phase B core: 2FA codes, QR payloads, and the key wrap Windows Hello unlock needs. v0.2.0.

What

  • custos-totp (new): RFC 4226 HOTP and RFC 6238 TOTP on RustCrypto hmac + sha1/sha2
    (SHA-1/256/512, 6–8 digits, any period); Totp::parse reads otpauth://totp/… URIs (label, issuer,
    algorithm, digits, period) or a bare base32 secret (case, spaces, = tolerated); to_uri,
    seconds_left. HOTP URIs are refused (not supported). Secret zeroized, [redacted] in Debug.
  • custos-qr (new): wifi_payload(ssid, password, security, hidden) →
    WIFI:T:<WPA|WEP|nopass>;S:…;P:…;H:<true|false>;; with \ ; , : " escaped (no P: for open networks);
    secret_payload. Payload strings only; the app renders.
  • custos-vault: Vault::wrap_for_device(material) / Vault::open_with_device(bytes, blob, material):
    the vault key wrapped with HKDF-SHA256(material, random salt) → XChaCha20-Poly1305, as a 108-byte blob the
    app keeps on the device (never in the vault file). New error DeviceKeyRejected. Documented in
    docs/FORMAT.md ("Device key wrap") and docs/THREAT_MODEL.md.

Tests (cargo test --workspace --release, written first)

  • custos-totp: 5 passed — RFC 6238 Appendix B: all 18 vectors exact (6 times × SHA1/256/512, 8 digits,
    seeds as in the RFC's reference code), RFC 4226 Appendix D: all 10 HOTP values exact, otpauth parsing
    incl. defaults and 7 malformed URIs refused, URI round trip + countdown, secret redacted. Vectors copied
    from rfc-editor.org, not from memory.
  • custos-qr: 5 passed — every special character escaped; an SSID and a password containing all of
    \ ; , : " survive a reader's unescaping exactly; WEP/open/hidden variants; Unicode SSID.
  • custos-vault: 11 passed (one new: device wrap round trip, wrong material → DeviceKeyRejected, every
    blob byte flipped refused, a blob from another vault refused).
  • custos-gen: 15 passed. Doctests: 2. Total 38 passed, 0 failed.

Self-review

  • The device KEK is HKDF over material the caller supplies. Its strength is the device's: for Windows Hello
    that is a TPM-held RSA key behind PIN/biometrics. The core does not and cannot check that.
  • HMAC-SHA1 is used only because TOTP requires it (it stays secure as a MAC).
  • Totp::parse decodes percent-escapes with decode_utf8_lossy; a malformed label becomes U+FFFD rather than
    an error. Only the secret matters for the code.
  • Not verified: interop with real authenticator QR codes (the app does that with real sites).
Phase B core: 2FA codes, QR payloads, and the key wrap Windows Hello unlock needs. v0.2.0. ## What - **`custos-totp`** (new): RFC 4226 HOTP and RFC 6238 TOTP on RustCrypto `hmac` + `sha1`/`sha2` (SHA-1/256/512, 6–8 digits, any period); `Totp::parse` reads `otpauth://totp/…` URIs (label, issuer, algorithm, digits, period) or a bare base32 secret (case, spaces, `=` tolerated); `to_uri`, `seconds_left`. HOTP URIs are refused (not supported). Secret zeroized, `[redacted]` in `Debug`. - **`custos-qr`** (new): `wifi_payload(ssid, password, security, hidden)` → `WIFI:T:<WPA|WEP|nopass>;S:…;P:…;H:<true|false>;;` with `\ ; , : "` escaped (no `P:` for open networks); `secret_payload`. Payload strings only; the app renders. - **`custos-vault`**: `Vault::wrap_for_device(material)` / `Vault::open_with_device(bytes, blob, material)`: the vault key wrapped with HKDF-SHA256(material, random salt) → XChaCha20-Poly1305, as a 108-byte blob the app keeps on the device (never in the vault file). New error `DeviceKeyRejected`. Documented in `docs/FORMAT.md` ("Device key wrap") and `docs/THREAT_MODEL.md`. ## Tests (`cargo test --workspace --release`, written first) - `custos-totp`: **5 passed** — **RFC 6238 Appendix B: all 18 vectors exact** (6 times × SHA1/256/512, 8 digits, seeds as in the RFC's reference code), **RFC 4226 Appendix D: all 10 HOTP values exact**, otpauth parsing incl. defaults and 7 malformed URIs refused, URI round trip + countdown, secret redacted. Vectors copied from rfc-editor.org, not from memory. - `custos-qr`: **5 passed** — every special character escaped; an SSID and a password containing all of `\ ; , : "` survive a reader's unescaping exactly; WEP/open/hidden variants; Unicode SSID. - `custos-vault`: **11 passed** (one new: device wrap round trip, wrong material → `DeviceKeyRejected`, every blob byte flipped refused, a blob from another vault refused). - `custos-gen`: 15 passed. Doctests: 2. **Total 38 passed, 0 failed.** ## Self-review - The device KEK is HKDF over material the caller supplies. Its strength is the device's: for Windows Hello that is a TPM-held RSA key behind PIN/biometrics. The core does not and cannot check that. - HMAC-SHA1 is used only because TOTP requires it (it stays secure as a MAC). - `Totp::parse` decodes percent-escapes with `decode_utf8_lossy`; a malformed label becomes U+FFFD rather than an error. Only the secret matters for the code. - Not verified: interop with real authenticator QR codes (the app does that with real sites).
mnovak added 2 commits 2026-10-31 10:44:55 +01:00
mnovak manually merged commit a68b3b46bf into main 2026-10-31 10:45:08 +01:00
Sign in to join this conversation.
No Reviewers
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: mnovak/CustosPublic#3