siyuan-note/siyuan · error

Conf.Language(317)

Error message

Conf.Language(317)

What it means

Conf.Language(317) is the localized 'invalid key backup file' message. ImportNotebookCryptoBackup returns it when the uploaded backup content is not valid JSON that unmarshals into a conf.NotebookCrypto structure — the file is malformed, truncated, or not a SiYuan crypto backup at all.

Solutions

  1. Re-export the key backup from the original device (ExportNotebookCryptoBackup) and import that exact file
  2. Open the file in a text editor and confirm it is valid JSON containing fields like MasterSalt, KDFParams, KEKVerifier, Checksum
  3. If the only copy is corrupted, restore it from the workspace/sync backup; otherwise the encryption configuration must be recreated with the original master password and recovery procedure

Example fix

// caller-side precheck
let parsed;
try { parsed = JSON.parse(fileText); } catch { showMessage("Not a valid backup file (invalid JSON)"); return; }
if (!parsed.MasterSalt || !parsed.KDFParams) { showMessage("Not a SiYuan key backup file"); return; }
await fetchPost("/api/notebook/importNotebookCryptoBackup", {data: fileText, password});
Defensive patterns

Strategy: validation

Validate before calling

let parsed;
try { parsed = JSON.parse(fileText); } catch { showMessage("File is not valid JSON"); return; }
if (!parsed || typeof parsed !== "object" || !parsed.MasterSalt || !parsed.KEKVerifier || !parsed.Checksum) {
  showMessage("Not a SiYuan notebook-crypto backup file"); return;
}

Type guard

const isCryptoBackup = (o) => !!o && typeof o === "object" &&
  typeof o.MasterSalt === "string" && !!o.KDFParams && typeof o.Checksum === "string";

Try / catch

try {
  const res = await fetchSyncPost("/api/notebook/importNotebookCryptoBackup", {data: fileText, password});
  if (res.code !== 0) showMessage(res.msg);
} catch (e) { showMessage("Invalid backup file"); }

Prevention

When it happens

Trigger: Calling model.ImportNotebookCryptoBackup(data, password) where json.Unmarshal(data, nc) fails (kernel/model/crypto.go:331) — the payload is empty, HTML from a failed download, a renamed unrelated file, or JSON with the wrong schema.

Common situations: A browser saved an error page instead of the backup JSON; the file was truncated by an incomplete transfer; user picked the wrong file (e.g. a sync snapshot or conf.json); the backup was hand-edited and syntax broke.

Understand the failure class

Background: "failed to unmarshal" / json.Unmarshal errors: why parsing a response into a Go struct fails and how to fix it — this error's family across 23 libraries.

Related errors


AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19). Data as JSON: /api/errors/8f0c26816b4c0c6a. Report an issue: GitHub.

Appendix: source

Thrown at kernel/model/crypto.go:331

// 安全:备份文件不含主密码(salt 不保密、verifier 是密文),导入只恢复配置,解锁仍需主密码。
// 防呆:本机已有完整且已启用的加密配置时拒绝导入,避免覆盖现有 salt/verifier 孤立现有 WrappedDEK。
// ImportNotebookCryptoBackup 接收用户导入的密钥备份文件内容(JSON 字节)+ 主密码,
// 校验主密码能解开备份里的 verifier 后才写回配置。防止 crafted 备份设置弱 KDFParams 等攻击。
// RecoveryRequired 状态允许导入,但候选 KEK 必须能解开所有现存笔记本和已删除笔记本历史。
func ImportNotebookCryptoBackup(data []byte, password string) error {
	notebookCryptoMu.Lock()
	defer notebookCryptoMu.Unlock()

	Conf.m.RLock()
	current := *Conf.NotebookCrypto
	Conf.m.RUnlock()
	if current.Enabled && notebookCryptoConfigurationComplete(&current) {
		return errors.New(Conf.Language(324))
	}

	nc := &conf.NotebookCrypto{}
	if err := json.Unmarshal(data, nc); err != nil {
		return errors.New(Conf.Language(317))
	}
	if !notebookCryptoConfigurationComplete(nc) {
		return errors.New(Conf.Language(317))
	}

	// 用导入的 salt + 用户输入的主密码派生 KEK,校验能否解开备份里的 verifier
	params, validErr := util.ValidateArgon2Params(nc.KDFParams)
	if validErr != nil {
		return errors.New(Conf.Language(317))
	}
	kek := util.DeriveKey(password, nc.MasterSalt, params)
	defer zeroAndClear(kek)
	if nc.Checksum != computeBackupChecksum(nc) {
		return errors.New(Conf.Language(317))
	}
	if !verifyKEKMAC(nc, kek) {
		return errors.New(Conf.Language(317))
	}

View on GitHub (pinned to 9f775e8a12)