{"record":{"id":"3dce0f16fb0b6d37","repo":"siyuan-note/siyuan","slug":"conf-language-323","errorCode":null,"errorMessage":"Conf.Language(323)","messagePattern":"Conf\\.Language\\(323\\)","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/crypto.go","lineNumber":1108,"sourceCode":"\tnotebookCryptoMu.Lock()\n\tdefer notebookCryptoMu.Unlock()\n\n\t// 检查是否还有加密笔记本（含 conf 损坏但存在备份的）\n\tids, listErr := listAllEncryptedBoxIDs()\n\tif listErr != nil {\n\t\treturn fmt.Errorf(\"list encrypted notebooks failed: %w\", listErr)\n\t}\n\tif len(ids) > 0 {\n\t\treturn errors.New(\"cannot disable encrypted notebook feature while encrypted notebooks exist, remove them first\")\n\t}\n\t// 检查历史目录中是否存在已删除加密笔记本的历史快照：其恢复仍依赖当前 MasterSalt/KEKVerifier，\n\t// 删除备份前必须先清除这些历史（详见设计 §19）\n\thasHistory, historyErr := scanEncryptedNotebookHistory()\n\tif historyErr != nil {\n\t\treturn fmt.Errorf(\"check encrypted notebook history failed: %w\", historyErr)\n\t}\n\tif hasHistory {\n\t\treturn errors.New(Conf.Language(323))\n\t}\n\n\tConf.m.Lock()\n\tConf.NotebookCrypto.Enabled = false\n\tConf.NotebookCrypto.MasterSalt = nil\n\tConf.NotebookCrypto.KEKVerifier = nil\n\tConf.NotebookCrypto.VerifierNonce = nil\n\tConf.m.Unlock()\n\n\tConf.Save()\n\tremoveNotebookCryptoBackup() // 禁用时清理备份，避免残留旧密钥材料\n\tIncSync()\n\treturn nil\n}\n\n// restoreNotebookCryptoConfigFromBackup 把备份里的 NotebookCrypto 配置装回本机 conf.json（不需主密码）。\n// 用于数据同步/导入 Data.zip 后：备份文件随 DataDir 到达新设备，但本机 conf.json 的 NotebookCrypto 还是空的。\n// 此时把 salt/verifier/KDFParams 装回并置 Enabled=true，让 UI 显示\"已启用\"，笔记本显示为锁定（解锁仍需主密码）。","sourceCodeStart":1090,"sourceCodeEnd":1126,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/crypto.go#L1090-L1126","documentation":"DisableEncryptedNotebook refuses to disable when deleted-notebook history snapshots still depend on the current MasterSalt/KEKVerifier. Removing the key backup now would make that history permanently unrecoverable, so the operation returns localized message 323 telling the user to clear that history first.","triggerScenarios":"Calling DisableEncryptedNotebook (or the corresponding UI/settings action) while scanEncryptedNotebookHistory finds history snapshots of previously deleted encrypted notebooks that are encrypted with the current key material.","commonSituations":"User deleted encrypted notebooks earlier (creating history snapshots) and now tries to turn the feature off without purging history; automated cleanup scripts that toggle the setting without history maintenance.","solutions":["Clear the encrypted-notebook history snapshots first (history UI: delete the deleted-notebook history entries), then retry disabling","If recovery is no longer wanted, manually purge the relevant snapshots from data/history after backing up","Then call DisableEncryptedNotebook again; it will zero MasterSalt/KEKVerifier and save"],"exampleFix":"// before: disable blocked by history\nawait fetchPost('/api/notebook/disableEncryptedNotebook')\n// after: purge dependent history first, then disable\nawait fetchPost('/api/history/removeHistoryItems', {ids: deletedEncryptedHistoryIds})\nawait fetchPost('/api/notebook/disableEncryptedNotebook')","handlingStrategy":"validation","validationCode":"// before disabling, confirm no deleted-encrypted-notebook history remains\nhasHistory, _ := model.HasEncryptedNotebookHistory() // or equivalent scan helper\nif hasHistory { /* purge history via history UI/API first */ }","typeGuard":null,"tryCatchPattern":"if err := model.DisableEncryptedNotebook(); err != nil && strings.Contains(err.Error(), Conf.Language(323)) { /* prompt user to clear deleted-notebook history, then retry */ }","preventionTips":["Purge history of deleted encrypted notebooks before toggling the feature off","Document that disabling zeroes MasterSalt/KEKVerifier and is blocked while dependent history exists","Avoid scripted toggles of NotebookCrypto.Enabled without a history check"],"tags":["go","encrypted-notebooks","history","guarded-operation"],"backgroundTag":"invalid-state-transition","analyzedSha":"9f775e8a12daef8255556097396f9b2739078892","analyzedAt":"2026-09-19T03:17:15.984Z","contentChangedAt":"2026-09-19T03:17:15.984Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}