Skip to content

fix(desktop): 凭据保险箱无法解密时保留原文件并继续启动 - #109

Merged
freedomkk-qfeng merged 9 commits into
ECNU:mainfrom
wf0229:pr/credential-vault-recovery
Nov 15, 2026
Merged

freedomkk-qfeng merged 9 commits into
ECNU:mainfrom
wf0229:pr/credential-vault-recovery

Conversation

@wf0229

@wf0229 wf0229 commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

问题

Windows 上,本机凭据保险箱(browser/credentials.encrypted)无法被当前账户解密时,应用卡在启动页:

dsh: startup failed: 1 required plugin did not activate
  connection (required)
    Error: native credential resolve failed with status 400

重装应用无效。首次启动时,签名配置的试运行也会因此失败,配置被标记为「未通过启动检查」。

常见场景:从其他电脑或账户拷贝了安装目录、管理员重置过 Windows 密码、Local State 损坏而保险箱文件仍在。

原因

保险箱由 Electron safeStorage 加密,密钥受当前账户的 DPAPI 保护。EncryptedVault.read() 解密或解析失败时直接抛错,本机桥对任何异常都返回 400,于是必需的 connection 插件无法激活。

修改

  • 解密失败、JSON 无效或结构无效时,把原文件改名为 credentials.encrypted.unreadable-<时间戳>,原样保留不删除,然后按「没有凭据」继续,用户重新登录即可。
  • 通过 onUnreadable 回调写一行诊断日志 {"component":"credential-vault","event":"unreadable","reason":"decrypt|format|schema","kept":"…"},不含任何密钥。
  • 文件不存在以外的读取错误(权限、占用等)仍然抛错,不会被误当成解密失败而挪走文件。

测试

dsh-electron/tests/native-vault.test.mjs:

  • 原先「换密钥后读取应失败」的断言,改为新行为:换一把密钥模拟拷贝来的安装,应用能继续使用,原文件字节完整保留,新写入的凭据可正常读回。
  • 新增用例:路径是目录、无法读取时,仍然报错。

node --test dsh-electron/tests/*.test.mjs:127/127。

来源

原作者:@wf0229(词元工坊 USTC TokenWorks),已随 TokenWorks 0.2.7 发布。用户实测:手动改名保险箱文件后即可恢复,与本修复的行为一致。

@JunieXD

JunieXD commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

已审查提交 0bea2b0,并在 macOS arm64 上完成凭据文件损坏后的真实客户端恢复测试。

损坏凭据文件后,客户端能够启动,原坏文件完整保留;设置中能明确看到密钥缺失。重新填写测试密钥后,模型请求正常,再次启动仍可使用,会话和模型配置保留。文件读取错误也没有被误当作损坏文件处理。

本轮主要覆盖凭据文件损坏后的恢复,模型服务为合成测试源;没有完整覆盖 macOS 钥匙串临时故障和跨机器迁移。在上述已测范围内未发现阻断合并的问题,建议合并。

wf0229 and others added 2 commits October 26, 2026 05:12
… failing startup

A vault the current OS account can no longer decrypt (copied install,
reset password, lost key) made every credential read return 400, so the
required connection plugin failed and the content trial was rejected.
Rename the file beside itself, log the reason, and continue signed out.
Read errors other than a missing file still fail.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
@wf0229
wf0229 force-pushed the pr/credential-vault-recovery branch from 0bea2b0 to d5f6580 Compare October 26, 2026 12:14
@wf0229

wf0229 commented Oct 26, 2026

Copy link
Copy Markdown
Contributor Author

已基于最新 main(0.4.9)重新整理,解决了与通知窗口改动的冲突,桌面测试全部通过,源码收据已刷新。此前的 macOS 实测结论仍适用,麻烦维护者有空时看一下。

@freedomkk-qfeng
freedomkk-qfeng merged commit c85e2a0 into ECNU:main Nov 15, 2026
13 of 15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants