Authentication and vault access

Registration, sign-in with a second factor, session restore, sign-out, and unlocking the vault.

Cerberus keeps two questions apart:

  1. Who are you? Answered by Heimdall. The result is a bearer token.
  2. Can you open this vault? Answered on the device, by knowing the password, and proven to the API with a signed challenge. The result is a vault-access handle.

A token alone opens nothing: GET /api/accounts/me with only a token answers 401 vault_access_required.

Registration

sequenceDiagram
    autonumber
    actor U as Prospective owner
    participant C as Cerberus UI
    participant A as Cerberus API
    participant H as Heimdall

    U->>C: name, email, password
    Note over C: generate accountId (GUID) and idempotencyKey,<br/>encrypt account details locally
    C->>A: POST /api/accounts<br/>{accountId, idempotencyKey, identity, details envelope}
    A->>A: persist RegistrationOperation<br/>(HMAC fingerprint of the request)
    A->>H: POST /api/scopes/{scope}/persons<br/>(scope-owner service token)
    H-->>A: person created (role 3)
    A->>A: bind account to identity atomically
    A-->>C: 201 {id, revision, onboardingState, replayed}
  • The account id is generated by the client, so details can be encrypted before registration.
  • A retry with the same idempotency key is reconciled with the stored operation and returns the same outcome (replayed: true); the fingerprint key CERBERUS_REGISTRATION_FINGERPRINT_KEY makes that comparison without storing the request.
  • The scope owner must own exactly the configured scope; there is no global-admin fallback.

Sign-in with a second factor

sequenceDiagram
    autonumber
    actor U as Owner
    participant C as Cerberus UI
    participant A as Cerberus API
    participant H as Heimdall

    U->>C: email, password
    C->>A: POST /api/auth/login
    A->>H: POST /api/auth/login (configured scope)
    alt second factor required
        H-->>A: challenge
        A-->>C: requiresTwoFactor, challengeToken, availableMethods
        Note over C: ChallengePending — in memory only,<br/>no token stored, every other route signed out
        U->>C: code (or recovery code)
        C->>A: POST /api/auth/2fa/verify
        A->>H: POST /api/auth/2fa/verify
        H-->>A: token
    else no second factor
        H-->>A: token
    end
    A-->>C: identity {token, expiresAt, …} + account {id, revision}
    Note over C: store token (secure storage on native,<br/>memory on web), clear credential fields
    C->>C: route to /unlock (or /vault/setup if no protection)
  • Credentials exist only for the submission: never stored, logged or kept on a screen the user has left.
  • A refused code shows the API’s message, clears the field and keeps the challenge outstanding. Leaving the screen discards the challenge.
  • If platform secure storage is unavailable, the app says the session cannot be kept and may continue for this run with the token in memory — it never falls back to preferences or a file.

Session restore

flowchart TD
    S([App starts]) --> T{Token in<br/>secure storage?}
    T -- no --> SI[/sign-in/]
    T -- yes --> St["/starting — neutral screen<br/>guard holds the start"]
    St --> Q["GET /api/vault/protection<br/>(outcome only; material discarded unread)"]
    Q -- "200" --> UL["/unlock<br/>(or the remembered deep link)"]
    Q -- "404 not_found" --> VS[/vault/setup/]
    Q -- "401 authentication_required" --> Del["delete token<br/>sign-in: session ended"]
    Q -- "unreachable" --> Off{"Default mode<br/>with a valid lease?"}
    Off -- yes --> OU[Offer offline unlock]
    Off -- no --> R[Offer retry, keep token]

On the web there is never a stored token: a reload always lands on sign-in.

Unlocking the vault

sequenceDiagram
    autonumber
    actor U as Owner
    participant C as Cerberus UI
    participant A as Cerberus API

    C->>A: GET /api/vault/protection
    A-->>C: wrappers + public verifiers
    U->>C: master (or profile) password
    Note over C: Argon2id off the UI isolate → unwrap the bundle.<br/>A wrong password is detected here — nothing is sent.
    C->>A: POST /api/vault/challenges (unlock-account)
    A-->>C: challenge (60 s)
    Note over C: sign the proof with the unlock key
    C->>A: POST /api/vault/unlock + proof headers
    A-->>C: vaultAccess handle (account-wide)
    opt open one profile
        C->>A: POST /api/profiles/{id}/access/challenges
        A-->>C: challenge
        C->>A: POST /api/profiles/{id}/access + proof
        A-->>C: vaultAccess handle (scoped to the profile)
    end
    C->>A: content requests with X-Cerberus-Vault-Access
  • In master mode the user picks a profile after unlocking; in per-profile mode the password picks the profile. A device restricted to one profile offers only that one.
  • A handle expires after 24 hours by default, or never when offline renewal is disabled, and goes stale as soon as protection, the offline policy or a share changes.

Locking and signing out

TriggerEffect
The user locksClose open records, overwrite key buffers, clear decrypted lists, clear the app’s clipboard value, route to /unlock.
Inactivity (default 5 minutes, counted while backgrounded)The same.
The offline lease expiresThe same, until it is renewed online.
Sign-outLock, delete the token, discard in-memory state. In the default mode, ask whether to keep the ciphertext store or remove it — stating how many pending edits would be lost.
A token rejected mid-sessionEnd the session and lock; keep the store. No silent refresh, no replay.

An edit in progress when the vault locks is discarded, with a notice after the next unlock.

Errors that matter here

ResponseMeaningClient behaviour
401 authentication_required on a request with a tokenThe identity token is no longer valid.End the session and lock.
401 vault_access_requiredSigned in but the vault is not unlocked (or the handle is stale).Go to /unlock; the session stays.
401 on a credential submissionWrong credentials.Show the message; the session is unaffected.
503 identity_unavailableHeimdall is unreachable; the API fails closed.Report and offer a retry.