# The vault

Everything you configure in Vaultport — hosts, groups, identities, keys, passwords, known hosts, snippets, port-forwarding rules, workspaces, cloud integrations and settings — is stored in a **vault**: a single encrypted SQLite file in the app's data directory. You can have several vaults on one device (for example _work_ and _personal_) and switch between them with the vault switcher or on the lock screen.

## Encryption at a glance

- A random 256-bit **vault key** encrypts every record with **XChaCha20-Poly1305**. The vault id and the record id are bound into each ciphertext, so records cannot be swapped between entries or vaults.
- The vault key itself is only ever stored **wrapped**, once per **unlock method** (a _key slot_): your **master password** (Argon2id, 256 MiB of memory and 3 passes on desktop, 64 MiB on phones and tablets), **Windows Hello** or **Touch ID**, a **PIN**, **security keys / passkeys**, and optionally **auto-unlock**. Unlock methods are stored on each device separately; they are not synced.
- **Secrets** (passwords, private keys, API tokens) are separate records that are only decrypted when the Rust core needs them, held in memory that is wiped after use, and never sent to the UI.

The details are in [Vault cryptography](http://vaultport.niessen.dev/security/vault-crypto.md).

## Unlocking

The lock screen shows the methods set up for the selected vault on this device, the most convenient first. Add, remove and change them in **Settings → Security**.

| Method                        | How it works                                                                                                                                                                                                                                                  |
| ----------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Master password               | Derives the key with Argon2id. Works on every device.                                                                                                                                                                                                         |
| Windows Hello                 | Windows: face, fingerprint or Hello PIN. The key comes from a Windows Hello key in the TPM, so nothing in Credential Manager can open the vault.                                                                                                              |
| Touch ID                      | macOS: Touch ID or your Mac password, through a key in the Secure Enclave.                                                                                                                                                                                    |
| Unlock with this device       | Linux, iPhone/iPad and Android: a key in the system key store (Secret Service, Keychain "this device only", Android Keystore).                                                                                                                                |
| PIN                           | A short PIN for this device, combined with a secret in the system key store. After 5 wrong PINs the PIN is removed and you need another method.                                                                                                               |
| Security key / passkey        | A FIDO2 security key or passkey with `hmac-secret` (PRF). Add several, e.g. a backup key. Desktop only.                                                                                                                                                       |
| Password + security key (2FA) | With two-factor unlock on, the master password works only together with a security key — neither alone opens the vault, not even a copied file. Authenticator-app codes (TOTP) are not offered: a code cannot encrypt a file, so it would not protect a copy. |
| Auto-unlock on this device    | Off by default. Opens the vault without any prompt at startup. **Anyone who can use your OS account — on Windows any program running as you — can open the vault without a password.**                                                                        |

At least one method other than the PIN always remains. Losing every method on a device is recoverable only with the master password on another device, another paired device, or an encrypted backup — see [Backups](#backups).

What each method protects against, and how, is in [Vault cryptography](http://vaultport.niessen.dev/security/vault-crypto.md#key-slots).

> **Android**
>
> On Android, the device key is encrypted with an AES-256-GCM key that is generated inside the Android Keystore (StrongBox-backed when the phone has a StrongBox chip) and never leaves it; only the ciphertext is kept in the app's private storage. This support is new and has not yet been verified on a wide range of devices — keep a master password or another unlock method as a fallback.

## Several vaults

Click the vault card at the top of the sidebar to open the **vault switcher**: it lists the vaults on this device, switches between them, and offers **Create vault**, **Restore from backup**, **Pair with another device** and **Lock vault**. Switching locks and closes the current vault first — its sessions, port forwards and connections end, and nothing of it stays in memory or on screen — then shows the other vault's lock screen, or opens it directly if it has auto-unlock and you have not locked it since Vaultport started. Vaultport remembers the last selected vault and shows it first when it starts.

## Locking

When the vault locks, decrypted data is wiped from memory and open sessions are closed. Vaultport locks the vault:

- after a period of inactivity (15 minutes by default, configurable or _never_),
- when the computer wakes from sleep (desktop, on by default; **Settings → Security → Lock when the computer sleeps**) — Vaultport notices the suspend as soon as it runs again, before you can use it,
- when the app moves to the background (phones and tablets, on by default),
- when you press <kbd>Mod</kbd>+<kbd>Shift</kbd>+<kbd>L</kbd> or choose **Lock vault**.

A vault with auto-unlock opens by itself only when Vaultport starts or when you switch to it. Once you lock it (or it locks after inactivity or sleep), it stays locked until Vaultport restarts or you unlock it with another method.

## Why an operation log?

Internally the vault is not a set of rows that get overwritten. It is an append-only **log of operations** — "set field `/config/ssh/port` of host X to 2222 at time T" — that is materialized into documents. Each field is a _last-writer-wins register_ ordered by a hybrid logical clock, and deletions are tombstones.

This is a [CRDT](https://crdt.tech/): any two devices that have seen the same set of operations hold exactly the same data, no matter in which order the operations arrived. That property is what lets Vaultport sync through plain, untrusted storage — a folder, WebDAV or an S3 bucket — without a server to resolve conflicts. See [Sync, backup & pairing](http://vaultport.niessen.dev/guide/sync.md) and the [sync protocol](http://vaultport.niessen.dev/security/sync.md).

## Backups

Because the vault is end-to-end encrypted, losing every device _and_ the master password means losing the data. Protect yourself with at least one of:

- sync to a second device,
- an [encrypted `.vaultport` export](http://vaultport.niessen.dev/guide/sync.md#encrypted-backups) kept somewhere safe.
