An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:memo: Refine encrypted notebook docs: terminology and usage scenarios https://github.com/siyuan-note/siyuan/issues/18034
Danielf069d7fb2dce
diff --git a/docs/ENCRYPTED-NOTEBOOK.md b/docs/ENCRYPTED-NOTEBOOK.mdindex 72c509b84a..5699a4b3ed 100644--- a/docs/ENCRYPTED-NOTEBOOK.md+++ b/docs/ENCRYPTED-NOTEBOOK.md@@ -8,7 +8,7 @@ Implement an "encrypted notebook" in SiYuan — a special notebook whose `.sy` d| Aspect | Design Decision ||---|---|-| Encryption scope | `.sy` + assets (incl. filenames) + database definitions + db (content + blocktree) all encrypted |+| Encryption scope | `.sy` + assets (incl. filenames) + database files + SQLite database (content + blocktree) all encrypted || Notebook identity | Dynamic boxID + `BoxConf.Encrypted: true` flag || Quantity | Multiple encrypted notebooks supported || Password | Shared master password (KEK envelope, per-notebook independent DEK) |@@ -19,7 +19,7 @@ Implement an "encrypted notebook" in SiYuan — a special notebook whose `.sy` d| Block refs | Normal refs within the box; cross-boundary refs forbidden (bidirectional: normal↔encrypted, encrypted A↔encrypted B) || AI / LLM | No functional-layer isolation — when unlocked, AI/LLM can read/search just like a normal notebook; when locked, physically unreachable without DEK (see §13) || Cross-boundary move | Forbidden — would break data consistency and leak |-| Database | Notebook-level storage — encrypted box database definitions follow the box directory, DEK-encrypted; cross-boundary mirroring forbidden |+| Database | Notebook-level storage — encrypted box database files follow the box directory, DEK-encrypted; cross-boundary mirroring forbidden || Flashcards / spaced repetition | Not supported (feature limitation) || Bookmarks | Not supported (feature limitation) || Tags | Not supported (feature limitation) |@@ -38,7 +38,7 @@ Implement an "encrypted notebook" in SiYuan — a special notebook whose `.sy` d| **After restart** | Keeps last open state | Force-closed; must re-enter master password to unlock || **.sy files** | Plaintext JSON on disk | AES-256-GCM ciphertext on disk, transparently decrypted on read || **assets files** | Plaintext binary, original filename | AES-256-GCM ciphertext, filename desensitized, original name encrypted |-| **database definitions** | Global `storage/av/<avID>.json` (plaintext) | Notebook-level `<boxID>/storage/av/<avID>.json` (DEK-encrypted) |+| **database files** | Global `storage/av/<avID>.json` (plaintext) | Notebook-level `<boxID>/storage/av/<avID>.json` (DEK-encrypted) || **content SQLite database** | Written to global siyuan.db (plaintext) | Written to independent siyuan-encrypted-`<boxID>`.db (SQLCipher) || **blocktree SQLite database** | Written to global blocktree.db (plaintext) | Written to independent siyuan-encrypted-`<boxID>`-blocktree.db (SQLCipher) || **Global search** | Participates (FTS hits) | Does not participate (data not in global SQLite database) |@@ -67,7 +67,7 @@ Implement an "encrypted notebook" in SiYuan — a special notebook whose `.sy` d| **Rebuild index** | Full | Skipped on startup (closed); on open box.Index() fully rebuilds into the encrypted SQLite database || **/api/file/getFile + putFile** | Can read/write any file | Refuses .sy reads/writes on encrypted boxes (prevent ciphertext leak or plaintext corruption) |-**Core difference summary**: An encrypted notebook is an "island" — data is physically isolated, operations have dedicated entry points, it never participates in global features (global search/graph), and documents/database definitions do not cross the boundary. In-box features (editing, block refs, backlinks, search, database, outline, history, etc.) work normally; AI/LLM is also usable when unlocked (same as a normal notebook). Encrypted notebooks are also isolated from each other. Normal notebooks are completely unaffected.+**Core difference summary**: An encrypted notebook is an "island" — data is physically isolated, operations have dedicated entry points, it never participates in global features (global search/graph), and documents/database files do not cross the boundary. In-box features (editing, block refs, backlinks, search, database, outline, history, etc.) work normally; AI/LLM is also usable when unlocked (same as a normal notebook). Encrypted notebooks are also isolated from each other. Normal notebooks are completely unaffected.## 4. Key Architecture@@ -77,7 +77,7 @@ User master password▼KEK (key-encryption key, memory-only, used and discarded)│ AES-256-GCM envelope- ├─→ unwrap BoxConf.WrappedDEK → DEK₁ → encrypts notebook 1's .sy/assets/database definition/SQLite database+ ├─→ unwrap BoxConf.WrappedDEK → DEK₁ → encrypts notebook 1's .sy/assets/database file/SQLite database├─→ unwrap BoxConf.WrappedDEK → DEK₂ → encrypts notebook 2└─→ unwrap BoxConf.WrappedDEK → DEK₃ → encrypts notebook 3```@@ -113,7 +113,7 @@ MasterSalt is the global root of KEK derivation — the master password + Master```<workspace>/├── conf/conf.json ← global encryption config (MasterSalt/KEKVerifier)-├── storage/av/ ← normal-box database definitions (plaintext)+├── storage/av/ ← normal-box database files (plaintext)├── data/│ ├── .siyuan/│ │ └── notebook-crypto-backup.json ← NotebookCrypto backup (MasterSalt/KEKVerifier, synced; see §4.1)@@ -124,11 +124,11 @@ MasterSalt is the global root of KEK derivation — the master password + Master│ │ │ ├── <uuid>-<blockID>.ext ← AES-256-GCM ciphertext, filename desensitized│ │ │ └── .names.json ← original filename mapping (DEK-encrypted)│ │ └── storage/av/-│ │ └── <avID>.json ← database definition (DEK-encrypted)+│ │ └── <avID>.json ← database file (DEK-encrypted)│ └── <normal-boxID>/ ← normal notebook (plaintext, untouched)├── history/ ← history directory (ciphertext stored verbatim)│ └── <timestamp>-update/-│ └── <boxID>/ ← encrypted-box history (ciphertext .sy + ciphertext database definitions)+│ └── <boxID>/ ← encrypted-box history (ciphertext .sy + ciphertext database files)└── temp/├── siyuan.db ← global SQLite (plaintext, no encrypted-box data)├── blocktree.db ← global blocktree (plaintext, no encrypted-box data)@@ -136,7 +136,7 @@ MasterSalt is the global root of KEK derivation — the master password + Master└── siyuan-encrypted-<boxID>-blocktree.db ← encrypted-notebook blocktree SQLite database (SQLCipher)```-## 6. Database Isolation Design+## 6. SQLite Database Isolation Design```Normal-notebook operations:@@ -155,7 +155,7 @@ Encrypted-notebook operations (dedicated read path, with boxID):**Generic-entry fallback**: Core functions like `GetBlockTree` / `ExistBlockTree` / `GetBlockTrees` / `LoadTreeByBlockID` automatically iterate opened encrypted boxes when a global lookup misses.-## 7. .sy / assets / Database Definition Encryption+## 7. .sy / assets / Database File Encryption**`.sy` transparent encryption** (filesys layer):- `DEKProvider` callback injected (avoids circular dependency)@@ -169,8 +169,8 @@ Encrypted-notebook operations (dedicated read path, with boxID):- Encrypted boxes disable the global assets fallback; notebook-level is mandatory- Asset file rename is forbidden (desensitized-filename rename breaks the mapping)-**database definition encryption**:-- Path fallback: encrypted-box database definitions are stored at `<boxID>/storage/av/<avID>.json`; normal boxes still use global `storage/av/`+**database file encryption**:+- Path fallback: encrypted-box database files are stored at `<boxID>/storage/av/<avID>.json`; normal boxes still use global `storage/av/`- Read: first check the global path; on miss, iterate opened encrypted boxes; after finding, DEK-decrypt then JSON-parse- Save: after JSON serialization, route by path (global plaintext / encrypted-box DEK-encrypted)- First creation: `RenderAttributeView` looks up the boxID from the blockID and presets ownership@@ -190,9 +190,9 @@ Deleted-notebook history:restore → ciphertext directory copied back verbatimdatabase history:- generate → encrypted-box database definitions copied from notebook-level dir to history dir+ generate → encrypted-box database files copied from notebook-level dir to history dirview → decrypt by path boxID- roll back → encrypted-box database definition/resources rolled back to notebook-level dir+ roll back → encrypted-box database file/resources rolled back to notebook-level dir```## 9. Block-Ref Cross-Boundary Protection@@ -243,10 +243,10 @@ Encrypted notebooks forbid moving documents across the encrypted boundary (norma- `.sy` document body (encrypted)- assets binary files (encrypted)- assets filenames (desensitized, original name encrypted)-- database definitions (columns/rows/cell values/view config/content snapshots, encrypted)+- database files (columns/rows/cell values/view config/content snapshots, encrypted)- content SQLite database (blocks/FTS/attributes/refs, SQLCipher-encrypted)- blocktree SQLite database (block-tree metadata: ID/path/title, SQLCipher-encrypted)-- .sy and database definitions in the history directory (ciphertext stored verbatim)+- .sy and database files in the history directory (ciphertext stored verbatim)**Not protected**:- MasterSalt/KEKVerifier in `conf.json` (designed to be plaintext: salt is not secret, verifier is ciphertext)@@ -317,7 +317,7 @@ An encrypted notebook is an island; some features are unimplemented because of tGo to **Settings → Access authorization → Change master password**. Changing the password only re-wraps each box's WrappedDEK — **document data is not re-encrypted**, so it completes instantly. The key backup is auto-refreshed and synced after a password change.### Multi-device sync-Encrypted-notebook ciphertext `.sy`/assets/database definitions sync along with the data (ciphertext in, ciphertext out, self-consistent); the global key material (MasterSalt etc.) is also automatically backed up to the sync directory. **No manual "enable" is needed on a new device after sync**:+Encrypted-notebook ciphertext `.sy`/assets/database files sync along with the data (ciphertext in, ciphertext out, self-consistent); the global key material (MasterSalt etc.) is also automatically backed up to the sync directory. **No manual "enable" is needed on a new device after sync**:1. Configure the same sync account on the new device and complete a sync2. Sync pulls the key backup to the local machine; the kernel auto-restores the "enabled" state@@ -338,7 +338,7 @@ If both `conf/conf.json` and the key backup in the sync directory are lost (an e### Suitable scenarios for encrypted notebooks- Private diary, financial records, medical information- Work secrets, business plans, contracts-- Multi-user shared computer where each person has their own encrypted notebook+- Concern about device loss or theft — once encrypted, even if the disk data is recovered, it remains ciphertext without the master password### Unsuitable scenarios for encrypted notebooks- Daily notes, study notes (the extra encryption overhead is not worth it)diff --git a/docs/ENCRYPTED-NOTEBOOK.zh-CN.md b/docs/ENCRYPTED-NOTEBOOK.zh-CN.mdindex 10d127ba83..75919d8c99 100644--- a/docs/ENCRYPTED-NOTEBOOK.zh-CN.md+++ b/docs/ENCRYPTED-NOTEBOOK.zh-CN.md@@ -2,13 +2,13 @@## 1. 设计目标-在 SiYuan 中实现"加密笔记本"——一种特殊笔记本,其 `.sy` 文档、assets 资源文件(含文件名)、数据库定义、SQLite 索引数据库(content + blocktree)都在磁盘上加密存储,需要主密码解锁才能查看内容。已有的普通笔记本完全不受影响。+在 SiYuan 中实现"加密笔记本"——一种特殊笔记本,其 `.sy` 文档、assets 资源文件(含文件名)、数据库文件、SQLite 索引数据库(content + blocktree)都在磁盘上加密存储,需要主密码解锁才能查看内容。已有的普通笔记本完全不受影响。## 2. 核心约束| 维度 | 设计决策 ||---|---|-| 加密范围 | `.sy` + assets(含文件名)+ 数据库定义 + SQLite 数据库(content + blocktree)全部加密 |+| 加密范围 | `.sy` + assets(含文件名)+ 数据库文件 + SQLite 数据库(content + blocktree)全部加密 || 笔记本身份 | 动态 boxID + `BoxConf.Encrypted: true` 标志位 || 数量 | 支持多个加密笔记本 || 密码 | 共用主密码(KEK 包络,每个笔记本独立 DEK) |@@ -19,7 +19,7 @@| 块引 | box 内部正常引用;禁止跨加密边界引用(双向:普通↔加密、加密 A↔加密 B) || AI / LLM | 不做功能层隔离——解锁后与普通笔记本一样可读可搜;锁定后因无 DEK 物理上不可达(详见 §13) || 跨边界移动 | 禁止——会破坏数据一致性且泄漏 |-| 数据库 | 笔记本级存储——加密 box 的 数据库定义跟随 box 目录,DEK 加密;禁止跨边界镜像 |+| 数据库 | 笔记本级存储——加密 box 的 数据库文件跟随 box 目录,DEK 加密;禁止跨边界镜像 || 闪卡 / 间隔重复 | 不支持(功能限制) || 书签 | 不支持(功能限制) || 标签 | 不支持(功能限制) |@@ -38,7 +38,7 @@| **重启后** | 保持上次打开状态 | 强制关闭,需重新输主密码解锁 || **.sy 文件** | 明文 JSON 落盘 | AES-256-GCM 密文落盘,读时透明解密 || **assets 文件** | 明文二进制,原始文件名 | AES-256-GCM 密文,文件名脱敏,原始名加密存储 |-| **数据库定义** | 全局 `storage/av/<avID>.json`(明文) | 笔记本级 `<boxID>/storage/av/<avID>.json`(DEK 加密) |+| **数据库文件** | 全局 `storage/av/<avID>.json`(明文) | 笔记本级 `<boxID>/storage/av/<avID>.json`(DEK 加密) || **content SQLite 数据库** | 写入全局 siyuan.db(明文) | 写入独立 siyuan-encrypted-`<boxID>`.db(SQLCipher 加密) || **blocktree SQLite 数据库** | 写入全局 blocktree.db(明文) | 写入独立 siyuan-encrypted-`<boxID>`-blocktree.db(SQLCipher 加密) || **全局搜索** | 参与(FTS 命中) | 不参与(数据不在全局 SQLite 数据库) |@@ -67,7 +67,7 @@| **重建索引** | 全量 | 启动时跳过(已关闭);打开时 box.Index() 全量重建到加密 SQLite 数据库 || **/api/file/getFile + putFile** | 可读写任意文件 | 拒绝加密 box 的 .sy 读写(防止密文泄漏或明文破坏) |-**核心区别总结**:加密笔记本是"孤岛"——数据物理隔离、操作专用入口、完全不参与全局功能(全局搜索/关系图)、文档和 数据库定义不进出边界。box 内部功能(编辑、块引、反链、搜索、数据库、大纲、历史等)正常使用;解锁后 AI/LLM 也可用(与普通笔记本一致)。加密笔记本之间也互相隔离。普通笔记本完全不受影响。+**核心区别总结**:加密笔记本是"孤岛"——数据物理隔离、操作专用入口、完全不参与全局功能(全局搜索/关系图)、文档和 数据库文件不进出边界。box 内部功能(编辑、块引、反链、搜索、数据库、大纲、历史等)正常使用;解锁后 AI/LLM 也可用(与普通笔记本一致)。加密笔记本之间也互相隔离。普通笔记本完全不受影响。## 4. 密钥架构@@ -77,7 +77,7 @@▼KEK(密钥加密密钥,仅内存,用完即弃)│ AES-256-GCM 包络- ├─→ 解 BoxConf.WrappedDEK → DEK₁ → 加密笔记本 1 的 .sy/assets/数据库定义/SQLite 数据库+ ├─→ 解 BoxConf.WrappedDEK → DEK₁ → 加密笔记本 1 的 .sy/assets/数据库文件/SQLite 数据库├─→ 解 BoxConf.WrappedDEK → DEK₂ → 加密笔记本 2└─→ 解 BoxConf.WrappedDEK → DEK₃ → 加密笔记本 3```@@ -113,7 +113,7 @@ MasterSalt 是 KEK 派生的全局根基——主密码 + MasterSalt 经 Argon2i```<workspace>/├── conf/conf.json ← 全局加密配置(MasterSalt/KEKVerifier)-├── storage/av/ ← 普通 box 的 数据库定义(明文)+├── storage/av/ ← 普通 box 的 数据库文件(明文)├── data/│ ├── .siyuan/│ │ └── notebook-crypto-backup.json ← NotebookCrypto 备份(MasterSalt/KEKVerifier,进同步范围,详见 §4.1)@@ -124,11 +124,11 @@ MasterSalt 是 KEK 派生的全局根基——主密码 + MasterSalt 经 Argon2i│ │ │ ├── <uuid>-<blockID>.ext ← AES-256-GCM 密文,文件名已脱敏│ │ │ └── .names.json ← 原始文件名映射(DEK 加密)│ │ └── storage/av/-│ │ └── <avID>.json ← 数据库定义(DEK 加密)+│ │ └── <avID>.json ← 数据库文件(DEK 加密)│ └── <normal-boxID>/ ← 普通笔记本(明文,不动)├── history/ ← 历史目录(密文原样存储)│ └── <timestamp>-update/-│ └── <boxID>/ ← 加密 box 的历史(密文 .sy + 密文数据库定义)+│ └── <boxID>/ ← 加密 box 的历史(密文 .sy + 密文数据库文件)└── temp/├── siyuan.db ← 全局 SQLite(明文,不含加密 box 数据)├── blocktree.db ← 全局 blocktree(明文,不含加密 box 数据)@@ -136,7 +136,7 @@ MasterSalt 是 KEK 派生的全局根基——主密码 + MasterSalt 经 Argon2i└── siyuan-encrypted-<boxID>-blocktree.db ← 加密笔记本 blocktree SQLite 数据库(SQLCipher)```-## 6. 数据库隔离设计+## 6. SQLite 数据库隔离设计```普通笔记本操作:@@ -155,7 +155,7 @@ MasterSalt 是 KEK 派生的全局根基——主密码 + MasterSalt 经 Argon2i**通用入口 fallback**:`GetBlockTree` / `ExistBlockTree` / `GetBlockTrees` / `LoadTreeByBlockID` 等核心函数全局查不到时自动遍历已打开的加密 box。-## 7. .sy / assets / 数据库定义加解密+## 7. .sy / assets / 数据库文件加解密**`.sy` 透明加解密**(filesys 层):- `DEKProvider` 回调注入(避免循环依赖)@@ -169,8 +169,8 @@ MasterSalt 是 KEK 派生的全局根基——主密码 + MasterSalt 经 Argon2i- 加密 box 禁用全局 assets 回退,强制笔记本级- 资源文件重命名禁止(脱敏文件名重命名会破坏映射)-**数据库定义加密**:-- 路径 fallback:加密 box 的 数据库定义存 `<boxID>/storage/av/<avID>.json`,普通 box 仍存全局 `storage/av/`+**数据库文件加密**:+- 路径 fallback:加密 box 的 数据库文件存 `<boxID>/storage/av/<avID>.json`,普通 box 仍存全局 `storage/av/`- 读取:先查全局路径,找不到时遍历已打开的加密 box;找到后 DEK 解密再 JSON 解析- 保存:JSON 序列化后按路径路由(全局明文 / 加密 box DEK 加密)- 首次创建:`RenderAttributeView` 从 blockID 反查 boxID 并预设归属@@ -190,9 +190,9 @@ MasterSalt 是 KEK 派生的全局根基——主密码 + MasterSalt 经 Argon2i恢复 → 密文目录原样拷回数据库历史:- 生成 → 加密 box 的 数据库定义从笔记本级目录拷到历史目录+ 生成 → 加密 box 的 数据库文件从笔记本级目录拷到历史目录查看 → 按路径 boxID 解密- 回滚 → 加密 box 的数据库定义/资源回滚到笔记本级目录+ 回滚 → 加密 box 的数据库文件/资源回滚到笔记本级目录```## 9. 块引跨加密边界防护@@ -243,10 +243,10 @@ MasterSalt 是 KEK 派生的全局根基——主密码 + MasterSalt 经 Argon2i- `.sy` 文档正文(已加密)- assets 二进制文件(已加密)- assets 文件名(脱敏,原始名加密存储)-- 数据库定义(列/行/cell 值/视图配置/内容快照,已加密)+- 数据库文件(列/行/cell 值/视图配置/内容快照,已加密)- content SQLite 数据库(blocks/FTS/attributes/refs,SQLCipher 加密)- blocktree SQLite 数据库(块树元数据:ID/路径/标题,SQLCipher 加密)-- 历史目录中的 .sy 和 数据库定义(密文原样存储)+- 历史目录中的 .sy 和 数据库文件(密文原样存储)**不保护**:- `conf.json` 里的 MasterSalt/KEKVerifier(设计可明文:salt 不保密,verifier 是密文)@@ -317,7 +317,7 @@ MasterSalt 是 KEK 派生的全局根基——主密码 + MasterSalt 经 Argon2i进入 **设置 → 访问授权 → 修改主密码**。改密只需重新包络各 box 的 WrappedDEK,**不重新加密文档数据**,因此即时完成。改密后密钥备份会自动刷新并同步。### 多设备同步-加密笔记本的密文 `.sy`/assets/数据库定义会随数据同步(密文进密文出,闭环自洽);全局密钥材料(MasterSalt 等)也会自动备份到同步目录。**新设备同步后无需手动"启用"**:+加密笔记本的密文 `.sy`/assets/数据库文件会随数据同步(密文进密文出,闭环自洽);全局密钥材料(MasterSalt 等)也会自动备份到同步目录。**新设备同步后无需手动"启用"**:1. 在新设备配置好相同的同步账号并完成同步2. 同步会把密钥备份拉到本地,内核自动恢复"已启用"状态@@ -338,7 +338,7 @@ MasterSalt 是 KEK 派生的全局根基——主密码 + MasterSalt 经 Argon2i### 适合用加密笔记本的场景- 隐私日记、财务记录、医疗信息- 工作机密、商业方案、合同-- 多用户共享电脑,每人有自己的加密笔记本+- 担心设备遗失或被盗——加密后即使磁盘数据被恢复,没有主密码也只是密文### 不适合用加密笔记本的场景- 日常笔记、学习笔记(加密的额外开销不值得)