{"record":{"id":"94b8e9a4c879e896","repo":"siyuan-note/siyuan","slug":"conf-language-310","errorCode":null,"errorMessage":"Conf.Language(310)","messagePattern":"Conf\\.Language\\(310\\)","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"kernel/model/crypto.go","lineNumber":1194,"sourceCode":"\t*Conf.NotebookCrypto = *backup\n\tConf.m.Unlock()\n\tConf.Save()\n\t// 恢复成功后同步重写备份，确保配置和备份内容一致。\n\t// 调用方已持有 notebookCryptoMu，且 writeNotebookCryptoBackupData 不再申请该锁，故无死锁；\n\t// 同步写避免与 ChangeMasterPassword 的并发备份写竞争同一文件（lost update 导致 verifier 被回退）。\n\tnc := *backup\n\tif err := writeNotebookCryptoBackupData(&nc, kek); err != nil {\n\t\tlogging.LogWarnf(\"rewrite notebook crypto backup after restore failed: %s\", err)\n\t}\n\tlogging.LogInfof(\"notebook crypto restored from backup (e.g. after sync to a new device)\")\n\treturn kek, nil\n}\n\n// deriveNotebookCryptoBackupCandidate 对同步备份做无副作用验证，并确认它覆盖全部现有加密笔记本。\nfunc deriveNotebookCryptoBackupCandidate(password string) (backup *conf.NotebookCrypto, kek []byte, err error) {\n\tbackup, err = loadNotebookCryptoBackup()\n\tif err != nil || backup == nil || len(backup.MasterSalt) == 0 || len(backup.KEKVerifier) == 0 {\n\t\treturn nil, nil, errors.New(Conf.Language(310))\n\t}\n\tparams, validErr := util.ValidateArgon2Params(backup.KDFParams)\n\tif validErr != nil {\n\t\treturn nil, nil, errors.New(Conf.Language(317))\n\t}\n\tkek = util.DeriveKey(password, backup.MasterSalt, params)\n\tdecrypted, decryptErr := util.DecryptWithAAD(kek, backup.KEKVerifier, []byte(\"siyuan:kek-verifier\"))\n\tif decryptErr != nil || string(decrypted) != string(kekVerifierMagic) {\n\t\tzeroAndClear(kek)\n\t\treturn nil, nil, errors.New(Conf.Language(311))\n\t}\n\tif backup.Spec != conf.CurrentNotebookCryptoSpec || backup.Checksum == \"\" ||\n\t\tlen(backup.KEKMAC) == 0 || !verifyKEKMAC(backup, kek) {\n\t\tzeroAndClear(kek)\n\t\treturn nil, nil, errors.New(Conf.Language(316))\n\t}\n\tif !verifyKEKAgainstExistingBoxes(kek, backup) || !verifyKEKAgainstEncryptedHistory(kek, backup) {\n\t\tzeroAndClear(kek)","sourceCodeStart":1176,"sourceCodeEnd":1212,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/crypto.go#L1176-L1212","documentation":"deriveNotebookCryptoBackupCandidate loads the synchronized key backup file and returns message 310 ('Encrypted notebook feature is not enabled') when the backup is absent, unreadable, or missing MasterSalt/KEKVerifier. Here the idiom reuses 310 to mean 'no usable key backup exists', so KEK derivation cannot proceed from the sync backup.","triggerScenarios":"deriveKEK / tryRestoreNotebookCryptoFromBackupLocked call deriveNotebookCryptoBackupCandidate and loadNotebookCryptoBackup returns an error, nil, or a backup struct with empty MasterSalt or empty KEKVerifier (e.g. no backup file on this device, or a freshly synced conf without the crypto backup).","commonSituations":"Syncing conf.json to a new device without the key backup file; user deleted or moved the backup; backup written by an old/failed run that never stored MasterSalt/KEKVerifier.","solutions":["Restore the key backup file to its expected location (or restore the original conf.json that contains it)","Re-enable encrypted notebooks with a fresh master password if the backup is genuinely lost, accepting that old encrypted data/history cannot be recovered","Import a previously exported key backup file before retrying unlock"],"exampleFix":"// before: backup file missing -> error 310\nrm ~/.config/siyuan/.../notebook-crypto-backup\n// after: keep/restore the backup so deriveNotebookCryptoBackupCandidate finds it\nrestore('notebook-crypto-backup.json') // then retry unlock","handlingStrategy":"fallback","validationCode":"// caller: ensure a key backup exists before attempting unlock\nif _, statErr := os.Stat(backupPath); statErr != nil { restoreBackupFromSyncOrExport() }","typeGuard":null,"tryCatchPattern":"_, _, err := model.DeriveKEK(password); if err != nil && strings.Contains(err.Error(), Conf.Language(310)) { /* restore key backup file, then retry */ }","preventionTips":["Keep the key backup file synced alongside conf.json","Export a key backup whenever enabling or re-keying encrypted notebooks","Never delete the backup while encrypted notebooks exist"],"tags":["go","encrypted-notebooks","key-derivation","missing-backup"],"backgroundTag":"missing-config-file","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"}