deepchat icon indicating copy to clipboard operation
deepchat copied to clipboard

[Feature] sqlite with cipher

Open zerob13 opened this issue 1 year ago • 3 comments

中文描述

目前已经通过集成better-sqlite3-multiple-ciphers来支持了sqlite3 密码。但是现在有如下几个问题还需要解决,所以目前还没有开起加密

  • [ ] 加密密码如何生成
  • [ ] sqlite3的密码如何安全的保存
  • [ ] 如何解决开源代码不要暴露release的密码

目前有几个思路

通过 dot 文件配置密码

相当于我们有个本地的dot文件,只有打包的时候导入加密密码,然后release出来,其他的fork的话就可以自行打包设置自定义的密码。

优点

密码/密码规则是嵌入到代码中,开启字节码加密之后相对泄漏难度会变大,

缺点

一旦泄漏所有人的密码其实是都比较容易被破解,相当于回退到当前版本的无密码sqlite

第一次安装启动时随机生成一个并存储

优点

安全性比较高,千人千面。

缺点

是需要持久化这个密码,然后持久化的方式一定是可以解密的,由于代码是开源的,所以从安全性角度来说其实意义不大。除非能找到比较好的密码存储方式 另一个问题是用户的数据文件无法被其他电脑打开,如果有同步需求或者是彻底删除安装后可能会无法恢复数据

让用户自行选择开启密码,并且输入一个自定义密码

优点

可以不用明文存密码了,只要有个规则能把用户密码算成最终sqlite 密码就行(比如 md5 一下用户密码作为 key)

坏处

增加了使用成本,忘记密码后就完全无解

English Translation:

SQLite password support has been implemented by integrating better-sqlite3-multiple-ciphers. However, the following issues still need to be resolved before encryption can be enabled:

  • [ ] How should the encryption password be generated?
  • [ ] How can the SQLite password be securely stored?
  • [ ] How can we prevent exposing the release password in open-source code? Currently, we have a few ideas:

Configure Password via dot File

This approach involves having a local dot file. The encryption password would only be imported during the packaging process and included in the release. Forks of the repository could then package the application with their own custom passwords.

Advantages:

The password or password generation logic is embedded within the code. Enabling bytecode encryption would make leakage more difficult.

Disadvantages:

Once the password is leaked, it could potentially be used to decrypt databases for all users, essentially reverting to the security level of the current unencrypted SQLite version.

Randomly Generate and Store Password on First Installation

Advantages:

Higher security as each installation would have a unique, randomly generated password (per-installation uniqueness).

Disadvantages:

This password needs to be persistently stored, and the storage mechanism must be decryptable. Given that the code is open source, the security benefit is likely limited unless a robust password storage method can be found. User data files created with this password will not be accessible on other computers. This could be problematic for users who need to sync data or recover data after a complete uninstall and reinstall.

Allow Users to Choose to Enable Password and Enter a Custom Password

Advantages:

Avoids the need to store the password in plaintext. A rule could be implemented to derive the final SQLite password from the user's input (e.g., using MD5 hashing the user's password as a key).

Disadvantages:

Increases the user's setup complexity. If the user forgets their password, data recovery would be impossible.

zerob13 avatar Feb 24 '25 03:02 zerob13

让用户自行选择开启密码,并且输入一个自定义密码。同时参考现在一些加密货币钱包的做法,增加密钥云备份和恢复功能

terryso avatar Feb 24 '25 06:02 terryso

我先来认领这个feature,稍后补上方案

anzihenry avatar Feb 26 '25 03:02 anzihenry

暂时不考虑在开源版本增加密码,目前已经在SQLitePresenter构造函数中增加了对数据库密码的支持,如果有需求可以修改后通过环境变量或者写死代码注入

zerob13 avatar May 29 '25 14:05 zerob13