{"record":{"id":"d7373ee56986d80a","repo":"siyuan-note/siyuan","slug":"conf-language-324","errorCode":null,"errorMessage":"Conf.Language(324)","messagePattern":"Conf\\.Language\\(324\\)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/crypto.go","lineNumber":326,"sourceCode":"}\n\n// ImportNotebookCryptoBackup 接收用户导入的密钥备份文件内容（JSON 字节），\n// 校验为合法 NotebookCrypto 后写回 <DataDir>/.siyuan/data-crypto-backup.json 并装回本机 Conf。\n// 用于新设备/重装后不依赖同步、手动恢复加密配置（详见设计文档 §4.1）。\n// 安全：备份文件不含主密码（salt 不保密、verifier 是密文），导入只恢复配置，解锁仍需主密码。\n// 防呆：本机已有完整且已启用的加密配置时拒绝导入，避免覆盖现有 salt/verifier 孤立现有 WrappedDEK。\n// ImportNotebookCryptoBackup 接收用户导入的密钥备份文件内容（JSON 字节）+ 主密码，\n// 校验主密码能解开备份里的 verifier 后才写回配置。防止 crafted 备份设置弱 KDFParams 等攻击。\n// RecoveryRequired 状态允许导入，但候选 KEK 必须能解开所有现存笔记本和已删除笔记本历史。\nfunc ImportNotebookCryptoBackup(data []byte, password string) error {\n\tnotebookCryptoMu.Lock()\n\tdefer notebookCryptoMu.Unlock()\n\n\tConf.m.RLock()\n\tcurrent := *Conf.NotebookCrypto\n\tConf.m.RUnlock()\n\tif current.Enabled && notebookCryptoConfigurationComplete(&current) {\n\t\treturn errors.New(Conf.Language(324))\n\t}\n\n\tnc := &conf.NotebookCrypto{}\n\tif err := json.Unmarshal(data, nc); err != nil {\n\t\treturn errors.New(Conf.Language(317))\n\t}\n\tif !notebookCryptoConfigurationComplete(nc) {\n\t\treturn errors.New(Conf.Language(317))\n\t}\n\n\t// 用导入的 salt + 用户输入的主密码派生 KEK，校验能否解开备份里的 verifier\n\tparams, validErr := util.ValidateArgon2Params(nc.KDFParams)\n\tif validErr != nil {\n\t\treturn errors.New(Conf.Language(317))\n\t}\n\tkek := util.DeriveKey(password, nc.MasterSalt, params)\n\tdefer zeroAndClear(kek)\n\tif nc.Checksum != computeBackupChecksum(nc) {","sourceCodeStart":308,"sourceCodeEnd":344,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/crypto.go#L308-L344","documentation":"Conf.Language(324) is the localized refusal message shown when importing a notebook-crypto backup would overwrite an existing, complete, enabled encryption configuration. ImportNotebookCryptoBackup intentionally rejects the import to avoid replacing the current salt/verifier and orphaning existing WrappedDEKs (data that could no longer be decrypted).","triggerScenarios":"Calling model.ImportNotebookCryptoBackup(data, password) (kernel/model/crypto.go:326) when Conf.NotebookCrypto.Enabled is true and the current configuration is complete (notebookCryptoConfigurationComplete) — i.e. the machine already has working encryption configured. Also reached from TestPasswordChangePreservesDeletedHistoryRecovery.","commonSituations":"User drags a key-backup file into a machine that already has encryption enabled and configured; an automation re-imports the same backup after a successful setup; testing scripts import twice without resetting config.","solutions":["If the existing configuration is the one you want, do not import — the machine is already set up; use the master password to unlock","If you truly need to switch to the imported configuration, first disable/reset the current notebook-crypto configuration (following the documented recovery procedure and keeping recovery material), then import","Verify which workspace/machine you are on — the backup likely belongs to a different device; import it there instead"],"exampleFix":"// caller-side precheck\nconst conf = window.siyuan.config.localNotebookCrypto;\nif (conf?.enabled) { showMessage(\"Encryption already configured on this device; import refused\"); return; }\nawait fetchPost(\"/api/notebook/importNotebookCryptoBackup\", {data, password});","handlingStrategy":"validation","validationCode":"const cfg = window.siyuan?.config?.localNotebookCrypto;\nif (cfg?.enabled) {\n  showMessage(\"This device already has encryption configured; import refused\");\n  return;\n}","typeGuard":"const cryptoAlreadyConfigured = (cfg) => !!cfg && cfg.enabled === true && !!cfg.masterSalt;","tryCatchPattern":"try {\n  const res = await fetchSyncPost(\"/api/notebook/importNotebookCryptoBackup\", {data, password});\n  if (res.code !== 0) showMessage(res.msg);\n} catch (e) {\n  showMessage(\"Import refused: encryption already configured on this device\");\n}","preventionTips":["Only import key backups on fresh devices or after a deliberate, documented reset of the current configuration","Confirm which machine/workspace the backup belongs to before importing","Never script repeated imports without resetting config between runs"],"tags":["encryption","config-conflict","backup-import","i18n"],"backgroundTag":"conflicting-config-options","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"}