UndoHaven 如何加密快照,令主機無法看見檔案名稱
How UndoHaven encrypts snapshots so a host never sees file names
UndoHaven 以數據金鑰加密快照,託管服務無法看見檔案內容或檔案名稱。數據金鑰分別由 Argon2id 衍生的密鑰和 BIP39 格式的 24 詞復原碼包裝;檔案路徑及大小則存於加密清單。預設無需帳戶或網絡,密文保存在 dsh home 下。
I build UndoHaven; this post is about how it handles encryption.
UndoHaven is an unofficial third-party CLI for dsh, a local agent runtime. It takes an encrypted snapshot of a dsh home (plus AGENTS.md and skills/ under ~/.agents) and writes the files back after you quit dsh. Restore is a command, not a screen inside the app, so it does not run against a session that is still writing.
The default needs no account and no network. npx undohaven init (or undohaven snapshot later) writes ciphertext under $DSH_HOME/undohaven, or ~/.dsh/undohaven if DSH_HOME is unset. Storing the ciphertext next to the dsh home is intentional: the snapshot travels with that home. It is also the limit the homepage is explicit about. A full-permission agent can wipe a home directory, local backups included. The copy that survives that wipe is an export you take off the machine, a bucket you configure, or an upload after you log in.
The rest of this post is how those bytes are sealed, and what restore refuses to do.
A data key, wrapped twice
The client generates a 32-byte data key. It does not encrypt files with the passphrase itself. The passphrase is stretched with Argon2id (64 MiB of memory, 3 iterations, parallelism 1; the memorySize value is 65536 because hash-wasm counts kibibytes), and that wrapping key seals the data key with AES-256-GCM. A 24-word recovery code, in the BIP39 layout, is 32 bytes of entropy plus a checksum. It wraps the same data key a second time, but with HKDF-SHA256 over the entropy, not Argon2. The recovery code already has 256 bits of randomness. A human-chosen passphrase does not.
From the data key the client derives three more keys with HKDF-SHA256, each under a fixed info string: one to encrypt chunks, one to encrypt the manifest, and one to name chunks.
If you lose both the passphrase and the recovery code, there is no reset. init, a passphrase unlock, and a recovery-code passphrase change all write the unwrapped data key to local keys.json (file mode 0600, directory 0700) so later snapshots on this machine do not prompt every time. undohaven logout clears that field. chmod has no effect on Windows. keys.json sits in the same $DSH_HOME/undohaven directory as the ciphertext, so syncing or copying the whole home takes the key along. The encryption protects copies that leave this machine; it does not defend a machine that is already compromised. An export file and, if you log in, the server carry only the wrapped keys.
Content-defined chunks, keyed names, then padding
Each file is split with a normalized FastCDC cutter (Xia et al.). The gear table is a fixed SplitMix64 stream, so the same bytes cut at the same places on another machine. The defaults aim at a 1 MiB average chunk, with a 256 KiB floor and a 2 MiB cap, so a sealed chunk stays under a 4 MiB object limit.
A chunk id is not a plain hash of the plaintext. It is HMAC-SHA256 of the plaintext under the chunk-id key. Duplicate chunks still collapse for the same data key, which is what you want across one person's snapshots. A host that only sees the ids cannot confirm a guessed file the way it could with unkeyed SHA-256.
Each piece is optionally compressed with zstd if it is at least 32 bytes and the compressed form is actually smaller, then sealed: a version byte, a flag bit, a 12-byte nonce, AES-256-GCM ciphertext, and a 16-byte tag. On disk or in a bucket the sealed chunk is padded to a 64 KiB multiple (an UHVP header, the true length, then zeros). The stored chunk size is not the plaintext length, and it is not the exact ciphertext length either. Export files and the encrypted manifest are not padded that way.
Paths and per-file sizes live in the manifest, which is encrypted with the third derived key. The claim I will make about the hosted service is narrow: the server cannot see file contents or file names. That is spelled out on the encryption page.
What a snapshot refuses to pick up
The walker does not follow symbolic links or Windows junctions. It skips the undohaven data directory itself, node_modules, cache, common model-weight extensions, and any file larger than 64 MB. Credentials (.env, .credentials.yaml) stay out unless you pass --include-credentials. That flag is off by default. The free plan will still take a local snapshot that includes them if you opt in; it will not upload a snapshot that contains them.
Those cuts are practical. They also mean a snapshot is not a whole-disk image. Files that were never snapshotted cannot be invented later.
Restore runs after dsh has quit
undohaven restore --to SNAPSHOT_ID will not start if it thinks dsh is still up. UndoHaven itself listens on nothing; before restore it connects to 127.0.0.1 and ::1 on port 3999, plus UNDOHAVEN_DSH_PORT if set, to see whether the dsh desktop app is open. On Unix it checks session and desktop lock files through python3 flock or /proc/locks, and refuses the restore if neither method is available. On Windows it looks at tasklist for dsh.exe and at a named semaphore. The error is blunt: quit first, so a live writer cannot race the rollback. There is an escape hatch, UNDOHAVEN_ASSUME_DSH_STOPPED=1, which the code tells you not to set until dsh has actually exited.
If the home still has files, restore takes a safety snapshot first, tagged safety / before-restore, then writes the selected scope back. Files in that scope that are not in the snapshot are deleted; they are still in the safety snapshot. Scopes include all, sessions, storages, config, profile, scheduled tasks (--scope tasks), or a single session. For a full or config restore it also drops a removed tool-working-directory profile entry so a snapshot taken before dsh 0.2.2-rc.3 will still load on 0.2.2-rc.5. Session bytes, including workspace-root paths, are written as stored. dsh itself, not UndoHaven, moves the workspace root.
When dsh will not start at all, undohaven rescue --to SNAPSHOT_ID is narrower still. It does the same lock check and safety snapshot, then writes that profile's package.json, pnpm-lock.yaml, and cordis.patch.yml back (--scope profile). It does not try to replay the whole home while you are still figuring out why the process will not boot.
The optional dsh-undohaven plugin can take snapshots on start, on a 6-hour timer by default, and when the plugin is disposed. The startup snapshot only runs when the local data key is already unlocked. If the installed dsh base package version has changed, startup pins the previous snapshot as pre-upgrade and also stores a storage-only snapshot. Restore still happens from the CLI after you quit, so it does not conflict with a session that is writing.
Try it
The CLI needs Node.js 24.9 or newer (undohaven-core itself accepts 22.19). As of 24 November 2026 (Asia/Shanghai), the published packages are undohaven 0.1.14, undohaven-core 0.1.15, and dsh-undohaven 0.1.12.
npx undohaven init
undohaven snapshot
undohaven list
# quit dsh first, including the tray icon
undohaven restore --to SNAPSHOT_ID --scope all
Write the 24-word recovery code down off the machine when init prints it. The crypto lives in the published undohaven-core package, in src/crypto.js, src/cdc.js, and src/byo.js.
Site: https://undohaven.com/
UndoHaven is an unofficial third-party tool compatible with dsh. It is not affiliated with DeepSeek.
來源:DEV Community · dev.to