BioforestChain / dweb_browser

BioforestChain Infrastructure
https://docs.dweb-browser.org
MIT License
13 stars 4 forks source link

【提案】✨ key.std.dweb 密钥管理接口 #44

Closed Gaubee closed 3 weeks ago

Gaubee commented 11 months ago
  1. KeyController/.Render,管理面板,提供导入、查看、导出等基本功能
  2. /{(create|delete)}/?for=:reason 创建密钥,提供某一个原因。会基于 root-key+ipc.mmid+reason 来创建出一个密钥,这个 reason 也是用户在这个密钥时,辅助理解这个密钥的内容
kingsword09 commented 8 months ago
  1. /(create|delete)?for=(*:reason) 创建密钥,提供某一个原因。会基于 root-key+ipc.mmid+reason 来创建出一个密钥,这个 reason 也是用户在这个密钥时,辅助理解这个密钥的内容

可以Android使用KeyStore,iOS使用Keychain先实现这部分来使用吗?还是需要一个key.sys.dweb的模块,来做这部分内容

kingsword09 commented 7 months ago

主密码设置时序图

sequenceDiagram
participant desk as desk.browser.dweb
participant biometrics as biometrics.sys.dweb
participant keySys as key.sys.dweb
participant keyStd as key.std.dweb
participant file as file.std.dweb
participant app as example.app.dweb
desk->>desk: 1.1 设置主密码
desk->>biometrics: 1.2 使用生物认证技术对主密码进行加密
alt is success
biometrics->>biometrics: 2.1 生物认证
biometrics->>keySys: 2.2 执行进行加密
Note over keySys: Android: Keystore存储PrivateKey, 加密算法: RSA, 使用PrivateKey对数据进行加密,并存储在SharedPreferences中<br/> iOS: Keychain存储PrivateKey, 加密算法: ECC,使用PrivateKey对数据进行加密,并存储在Keychain的GenericPassword中
keySys->>desk: 3.1 主密码数据:ByteArray
desk->>keyStd: 4.1 /setRoot?key=root-key
keyStd->>file: 5.1 使用主密码自加密后存储在MicroModuleStore中
Note over keyStd: 分发管理密钥
app-->>keyStd: /create?paremts
else is failed
biometrics->>desk: 2.2 生物识别失败
end
kingsword09 commented 7 months ago
  1. 当前iOS硬件级别的加密主要由 Secure Enclave 来提供,而想要使用 kSecAttrTokenIDSecureEnclave 创建密钥,当前只支持 kSecAttrKeyTypeECSECPrimeRandom 椭圆曲线密钥,因此iOS改用椭圆曲线算法进行密钥生成,支持Face ID来获取密钥。之后的加解密数据采用kSecKeyAlgorithmECIESEncryptionCofactorX963SHA256AESGCM算法进行加解密;
  2. Android改用RSA进行加解密,Keystore 更方便存储 PrivateKey
kingsword09 commented 7 months ago
  1. Android由于KeyStore无法存储ByteArray加密数据,只能存储密钥,因此存储密钥的两种方式: 1.1 使用生物识别方式:先使用KeyStore生成RSA密钥对,使用PrivateKey对主密码进行加密,之后存储在SharedPreferences中; 1.2 使用密码方式:使用MicroModuleStore对主密码进行自加密后存储;

    最终将会保存两份密码,一份在SharedPreferences,一份在MicroModuleStore中。 (1) 当用户使用生物识别解锁DwebBrowser时,从KeyStore中读取PrivateKey和从SharedPreferences中读取加密数据后,使用PrivateKey解密加密数据来获取主密码,之后从MicroModuleStore中获取自加密数据进行校验并恢复主密码到内存中; (2)如果是使用主密码来解锁DwebBrowser,则从MicroModuleStore中读取自加密主密码校验,并恢复到内存中。

  2. iOS 2.1 使用生物识别方式:先使用Keychain生成ECC密钥对,使用PrivateKey对主密码进行加密,之后存储在Keychain中的GenericPassword中; 2.2 使用密码方式:使用MicroModuleStore对主密码进行自加密后存储;

    最终将会保存两份密码,一份在Keychain中,一份在MicroModuleStore中。 (1)当用户使用生物识别解锁DwebBrowser时,从Keychain中读取PrivateKeyGenericPassword中的加密数据,使用PrivateKey对加密数据解密校验并恢复主密码到内存中; (2)如果是使用主密码来解锁DwebBrowser,则从MicroModuleStore中读取自加密主密码校验,并恢复到内存中。