Introducing a new way to review your PRs.

Read the announcement

fwdai / rowel

🔑 Local-first Secrets Manager

View on GitHub

23 documents · Updated Oct 9, 2026

docs / authentication-and-locking

Authentication, locking, and access lifecycle

Authentication protects each encrypted workspace from setup through every unlock, password change, workspace switch, and lock. The Rust side owns keys and sessions. The frontend asks for actions, receives safe session results, and follows the vault:locked event when access ends. See also Security and access and Biometrics and secure storage.

Access model

Workspace ownership

A workspace is one encrypted vault with its own password. The device has one active workspace at a time, but the app can remember the keys for workspaces that the user has already opened during the current app session. A workspace switch closes the current vault before it points the app at the next one. If the next key is known, the switch opens it without another prompt; otherwise the app shows that workspace's lock screen. src-tauri/…/workspace.rs• L1-11 src-tauri/…/workspace.rs• L50-57

The primary workspace supplies the app key. The app key lets the device seal the keys for other workspaces locally, so one successful primary unlock can open the workspaces known to that device. The keyring survives a workspace switch but ends with every lock. This local convenience does not change the password needed to restore a workspace on another device. src-tauri/…/appkey.rs• L1-21 src-tauri/…/appkey.rs• L146-167

References: src-tauri/…/workspace.rs• L1-11 src-tauri/…/workspace.rs• L50-57 src-tauri/…/appkey.rs• L1-21 src-tauri/…/appkey.rs• L146-167

Session ownership

The Rust session owns the active vault key and the open encrypted store. The frontend never receives the key or a full decrypted vault. It receives entry metadata for lists and asks for one decrypted entry when it must display secret data. src-tauri/…/session.rs• L54-68 src/…/types.ts• L151-187

Long vault operations can temporarily take the key and store out of the session. During that time normal commands see a locked vault, while the inactivity system still sees a live session. If a manual lock or inactivity lock occurs, the session does not restore itself when the operation ends. A session epoch also rejects work prepared for an older key or vault, so a lock, switch, or password change cannot receive stale writes. src-tauri/…/session.rs• L14-33 src-tauri/…/session.rs• L133-143 src-tauri/…/session.rs• L194-238

References: src-tauri/…/session.rs• L14-33 src-tauri/…/session.rs• L54-68 src-tauri/…/session.rs• L133-143 src-tauri/…/session.rs• L194-238 src/…/types.ts• L151-187

Setup and password lifecycle

Initial setup

Setup creates a new encrypted workspace or restores one from a file or a connected account. A new workspace gets a new password-based key. A restore uses the password that protects the restored vault. The result opens the new session and returns the entry metadata needed to enter the main view. src-tauri/…/setup.rs• L204-265 src-tauri/…/setup.rs• L304-343

When setup connects an account before a vault exists, credentials remain pending until a new key exists. The app then seals them with that key or discards them when the user cancels. This prevents account credentials from becoming persistent before the app has a vault to protect them. src-tauri/…/setup.rs• L1-21 src-tauri/…/setup.rs• L347-420

The setup path allows only one create or restore step at a time. A failed setup removes the new vault and returns the app to a state where the user can try again. src-tauri/…/setup.rs• L453-486

References: src-tauri/…/setup.rs• L1-21 src-tauri/…/setup.rs• L204-265 src-tauri/…/setup.rs• L304-343 src-tauri/…/setup.rs• L347-420 src-tauri/…/setup.rs• L453-486

Unlock proof

Password unlock proves the password against the active workspace, opens that encrypted store, and returns only the metadata needed by the frontend. Before the proof starts, the native side repairs an interrupted password change and checks the workspace's failed-attempt backoff. A successful proof starts the inactivity clock and updates the device keyring for later workspace access. src-tauri/…/auth.rs• L48-57 src-tauri/…/auth.rs• L71-112 src-tauri/…/session.rs• L312-349

The password path uses the workspace's stored key-derivation settings. A wrong key is reported as invalidPassword; storage, schema, and device errors keep separate error kinds. src-tauri/…/session.rs• L312-349 src-tauri/…/session.rs• L426-435 src/…/auth.ts• L4-5

Every password proof shares the same failed-attempt backoff for the workspace it tests. The first three failures are free. Later failures wait for an increasing delay up to five minutes. A successful proof clears that workspace's backoff. A live wait is checked before expensive password work begins. src-tauri/…/auth.rs• L23-35 src-tauri/…/auth.rs• L78-129 src-tauri/…/auth.rs• L43-57

The backoff is per workspace, so guessing one workspace does not lock another. The same policy also protects password proofs used for actions such as deleting a workspace. src-tauri/…/auth.rs• L51-75 src-tauri/…/workspace.rs• L911-951

References: src-tauri/…/auth.rs• L48-57 src-tauri/…/auth.rs• L71-112 src-tauri/…/session.rs• L312-349 src-tauri/…/session.rs• L426-435 src-tauri/…/auth.rs• L23-35 src-tauri/…/auth.rs• L78-129 src-tauri/…/workspace.rs• L911-951

Master password change

Changing the master password is a device-wide action for workspaces that share the current password. The frontend sends the current password and the new password. The backend returns the workspace IDs that kept their old password because they use a different password or because their individual change failed. src/…/auth.ts• L28-36 src/…/MasterPasswordRow.tsx• L51-69

The change re-seals the vault under a new key and protects the on-disk transition with recovery data. If the process stops during the change, the next unlock restores a matching old database and key description before it tries to open the vault. A failure leaves the affected workspace on its old password. src-tauri/…/auth.rs• L191-223 src-tauri/…/auth.rs• L407-443

The active session continues with the new key only if it still owns the same session. If the user or auto-lock locks the vault while the change runs, the vault stays locked and the new password applies at the next unlock. When the primary workspace changes, the device replaces its app key, reseals the other known workspace keys, and refreshes biometric enrollment material if enrollment exists. src-tauri/…/auth.rs• L408-504 src-tauri/…/appkey.rs• L256-280

References: src/…/auth.ts• L28-36 src/…/MasterPasswordRow.tsx• L51-69 src-tauri/…/auth.rs• L191-223 src-tauri/…/auth.rs• L407-443 src-tauri/…/auth.rs• L408-504 src-tauri/…/appkey.rs• L256-280

Password change flow

The password change moves from user proof to vault re-keying and then to session adoption. The important ownership boundaries are shown here.

flowchart LR
    A[Current and new passwords] --> B[Prove current password]
    B --> C[Re-key active workspace]
    C --> D[Re-key other workspaces with the same password]
    D --> E[Adopt the new session key]
    C --> F[Rollback on failure or recover on next unlock]
    E --> G[Frontend reports success or unchanged workspaces]

References: src-tauri/…/auth.rs• L369-504 src-tauri/…/auth.rs• L225-305 src-tauri/…/auth.rs• L407-443

Lock transitions

Manual and automatic locking

Manual lock, tray lock, workspace transitions that need a password, and inactivity all end through the same session lock action. That action drops the in-memory key, closes the encrypted store, clears remembered workspace keys, clears protected frontend data, and emits vault:locked. A lock that occurs during a whole-vault operation also prevents that operation from restoring the session. src-tauri/…/session.rs• L184-238 src-tauri/…/session.rs• L241-305 src-tauri/…/auth.rs• L205-215

The lock event is the frontend's single access-loss contract. The event handler clears entry and UI state, then returns to the lock screen. The frontend does not infer a lock from a command result because the lock can also come from the timer or another native event. src/…/events.ts• L19-21 src/…/events.ts• L59-66

References: src-tauri/…/session.rs• L184-238 src-tauri/…/session.rs• L241-305 src-tauri/…/auth.rs• L205-215 src/…/events.ts• L19-21 src/…/events.ts• L59-66

Inactivity timeout

The inactivity timer runs for the whole live session. The frontend sends a throttled activity signal for input such as pointer movement, key presses, scrolling, and touch. Each signal resets the timer. The settings offer one, five, fifteen, thirty, or sixty minutes. src-tauri/…/autolock.rs• L15-37 src/…/useActivityPing.ts• L5-35 src/…/SessionGroup.tsx• L9-32

Focus changes also count as activity. When the window returns after the full timeout, the native side locks instead of granting a new timeout. Wall-clock time covers sleep and mobile app suspension, so leaving the app in front of a locked laptop or backgrounding a phone cannot keep the vault open indefinitely. src-tauri/…/autolock.rs• L125-168

An unlock or newly created workspace starts a fresh timeout immediately. This avoids a stale timer locking a new session, and it avoids leaving a newly opened vault without a timeout while the frontend is still changing screens. src-tauri/…/auth.rs• L71-96 src-tauri/…/setup.rs• L395-409

References: src-tauri/…/autolock.rs• L15-37 src-tauri/…/autolock.rs• L83-123 src-tauri/…/autolock.rs• L125-177 src/…/useActivityPing.ts• L5-35 src/…/SessionGroup.tsx• L9-32 src-tauri/…/auth.rs• L71-96

Lock transition flow

This flow shows how both a user action and an idle timeout reach the same frontend state.

flowchart TD
    A[Manual lock, tray, switch, or idle timeout] --> B[Native session lock]
    B --> C[Drop key and close store]
    C --> D[Clear keyring and protected local state]
    D --> E[Emit vault:locked]
    E --> F[Clear frontend session state]
    F --> G[Refresh status and show lock screen]

References: src-tauri/…/session.rs• L252-305 src/…/events.ts• L59-66 src/…/app.ts• L239-262

Biometric access

Enrollment and retrieval

Biometric unlock is an opt-in shortcut for an already unlocked session. Enrollment stores the primary workspace's app key in the platform secure store and records the gate mode that was used. The user can enroll during setup or later in Settings, but not while the app is locked. src-tauri/…/auth.rs• L316-357 src/…/index.tsx• L19-39

Retrieval uses the recorded mode exactly. The app does not silently switch between a stronger OS-enforced gate and a weaker app-enforced prompt. A missing secure-store item clears the enrollment marker; cancellation or a temporary store error leaves the enrollment available for another try. src-tauri/…/auth.rs• L241-314 src-tauri/…/secure_store.rs• L31-37

The enrolled app key opens the primary workspace directly and opens another workspace only when that workspace has a local key sealed under the app key. If a workspace has no such local key, biometric unlock is not offered for it. src-tauri/…/auth.rs• L228-297 src-tauri/…/appkey.rs• L106-143

References: src-tauri/…/auth.rs• L228-297 src-tauri/…/auth.rs• L316-357 src-tauri/…/secure_store.rs• L31-37 src-tauri/…/appkey.rs• L106-143 src/…/index.tsx• L19-39

Biometric password relationship

Biometric unlock does not replace the master password. It gives the device a gated way to recover the app key. A master-password change replaces the stored material when the primary changes, so the enrollment stays aligned with the key that now opens the primary workspace. If that replacement cannot be stored, the enrollment is removed rather than left pointing to retired key material. src-tauri/…/auth.rs• L495-525

The platform reports whether a biometric gate is available, whether enrollment can work, which gate the device names, and which enrollment mode is active. The frontend uses those values to decide whether to show a biometric control and how to describe its protection. src-tauri/…/biometrics.rs• L148-175 src/…/app.ts• L78-89 src/…/BiometricRow.tsx• L12-48

References: src-tauri/…/auth.rs• L495-525 src-tauri/…/biometrics.rs• L148-175 src/…/app.ts• L78-89 src/…/BiometricRow.tsx• L12-48

Frontend-native authentication contract

Command boundary

The frontend-native contract is a small set of Tauri commands. Password and biometric unlock return an UnlockResult with safe entry metadata and the workspace's sync status. Lock and activity commands return no vault data. Enrollment commands return the chosen biometric mode or an error. src/…/auth.ts• L4-26 src/…/types.ts• L184-187

The native side keeps password derivation and store opening away from the UI thread. The frontend therefore presents a verifying state while it waits and must treat native errors as typed outcomes, not as proof that the password was wrong. src-tauri/…/auth.rs• L25-35 src/…/useUnlock.ts• L23-39

References: src/…/auth.ts• L4-26 src/…/types.ts• L184-187 src-tauri/…/auth.rs• L25-35 src/…/useUnlock.ts• L23-39

Lock-screen behavior

The wide lock screen leads with the password field. The compact lock screen leads with a biometric tile when enrollment is usable and keeps the password one tap away. Both layouts use the same unlock state and the same native commands. src/…/index.tsx• L16-49 src/…/LockScreen.tsx• L19-85

The frontend maps native outcomes to user meaning. An invalid password shows a password error. A lockout disables password entry until the returned wait ends. A cancelled biometric prompt returns to the waiting state without blaming the password. Other native failures keep their own message. src/…/useUnlock.ts• L23-44 src/…/useUnlock.ts• L150-185

After native unlock succeeds, the frontend holds the success view briefly and enters the main view. If the auth component is remounted during that handoff, it still completes the already-open native session once. src/…/useUnlock.ts• L115-147 src/…/auth.test.tsx• L113-145

References: src/…/index.tsx• L16-49 src/…/LockScreen.tsx• L19-85 src/…/useUnlock.ts• L23-44 src/…/useUnlock.ts• L115-185 src/…/auth.test.tsx• L113-145

Workspace switch contract

The workspace picker is part of the lock screen because a switch can end on a different workspace's password prompt. While a switch is in flight, the frontend blocks unlock attempts because the native active workspace may already differ from the one still shown on screen. After the switch, one status probe updates the workspace identity and biometric availability together. src/…/workspace.ts• L38-70 src/…/app.ts• L204-237

When the target workspace is already in the app keyring, the native side returns an unlock result and the frontend enters the main view. When it is not, the native side emits vault:locked; the common lock handler shows the target workspace's lock screen. The keyring can span the switch, but a lock clears it before another workspace can use it. src-tauri/…/workspace.rs• L50-57 src-tauri/…/workspace.rs• L126-195 src-tauri/…/appkey.rs• L146-167

References: src/…/workspace.ts• L38-70 src/…/app.ts• L204-237 src-tauri/…/workspace.rs• L50-57 src-tauri/…/workspace.rs• L126-195 src-tauri/…/appkey.rs• L146-167

Change checklist

When these files or sections are changed, remember to consider these:

  • Keep the native unlock result, UnlockResult, and enterMain aligned. The result must still provide the metadata and sync flag needed to enter the main view.
  • Keep the vault:locked event, its typed event catalog, and the one frontend lock handler aligned. Every new native lock path must use the same event contract.
  • Keep password-proof callers on the workspace-specific backoff. A new path that checks a password must not create a faster guessing route.
  • Keep app-key enrollment and workspace switching aligned. A workspace may offer biometric unlock only when its key is available under the enrolled app key.
  • Keep password-change results aligned with the settings message. The returned unchanged-workspace IDs describe both workspaces with independent passwords and workspaces whose re-key did not finish.
  • Keep auto-lock settings, activity pings, focus handling, and native timer bounds aligned. Changing one part can make the visible timeout differ from the enforced timeout.
  • Keep app-key replacement and biometric enrollment together when the primary password changes. Retired primary material must not remain in the device keyring or secure store.
  • Keep session epoch checks with every operation that takes the vault out of the session. A completed operation must not restore keys after a lock or apply data prepared under an older key.

Important failure modes

TriggerConsequenceGuard
A password proof uses the wrong key for the active workspaceThe vault does not open and the attempt may enter that workspace's backoffDerive and open the active workspace, then reset the backoff only after a successful proof
Four or more failed password attemptsThe backend refuses further password work for an increasing wait, up to five minutesCheck the lockout before key derivation and return the remaining wait to the frontend
The process stops during a master-password changeThe database and key description can disagreeKeep a recovery point and restore the old pair before the next unlock
The user locks while a whole-vault operation runsThe operation must not reopen the vault behind the lock screenSession ownership claims must fail to adopt after a lock
A stale operation writes after a password change or fresh unlockData prepared under an old key can be applied to a new sessionCheck the session epoch before using the store
The app is backgrounded or the device sleeps past the timeoutA timer based only on active thread time could leave the vault openCompare focus loss and resume with wall-clock time
A biometric enrollment is missing or invalidatedThe biometric control could remain visible but never workClear the marker only for a confirmed missing secure-store item
A workspace has no key sealed under the app keyBiometric unlock cannot open that workspaceKeep the password route available and do not offer biometric unlock for that workspace
A primary password change leaves old app-key material enrolledBiometric unlock can fail or point to retired access materialReplace the app key and refresh or remove enrollment as part of the change
The frontend receives a non-password native open errorShowing an incorrect-password message sends the user down the wrong recovery pathPreserve native error kinds and map only invalidPassword to a password message

Key files

FileWhy to read it
src-tauri/…/session.rsDefines session ownership, lock behavior, key lifetime, and the safe boundary between native secrets and frontend data.
src-tauri/…/auth.rsConnects frontend commands to unlock, lock, biometric access, inactivity activity, and password changes.
src-tauri/…/auth.rsDefines failed-password backoff and recovery for interrupted password changes.
src-tauri/…/autolock.rsDefines inactivity timing, focus handling, and the native lock trigger.
src-tauri/…/appkey.rsExplains how the device keyring and app-level key give access to known workspaces and how those keys end at lock.
src-tauri/…/secure_store.rsDefines platform secure-store modes and the rule that retrieval uses the recorded enrollment mode.
src-tauri/…/setup.rsShows how a new or restored vault becomes the first live session.
src-tauri/…/workspace.rsShows how switching, creating, deleting, and proving passwords for other workspaces affect access.
src/…/auth.tsLists the frontend's request/response boundary for authentication and locking.
src/…/useUnlock.tsDefines the frontend attempt states and error mapping for password and biometric unlock.
src/…/events.tsDefines the frontend reaction to the native vault:locked event.
src/…/useActivityPing.tsDefines which frontend activity refreshes the native inactivity timer.