I am designing my first web3 app and I would like to use MetaMask as an identity and crypto provider. My web3 app will encrypt user data with AES-GCM, but I do not want to generate and store an encryption key (as well as iv/salt) anywhere on user device. Instead, I would like to use MetaMask connection and the private key hold by MetaMask. Because MetaMask does not provide a direct access to private keys, I can use it indirectly by signing a known message (using "personal_sign" request). The generated signature will never leave the device, being effectively a key material. Then I use PKDF2 to derive AES key and iv from this signature. This scheme would allow me to encrypt/decrypt user data by just running MetaMask to sign some pre-defined string, e.g. "Hello world".
For now I do not see any obvious security breaches here, except if the signature can be intercepted. The reason to not persist anything on the device (e.g. localStorage) is because I want to enable seamless user access from any browser where the same MetaMask account is present. Also, for now I do not want to add a second factor like additional user password.
Questions:
- is it safe to derive an encryption key with PKDF2 from a ECDSA signature?
- is it possible to intercept/steal a MetaMask generated signature with "personal_sign"?
Thank you very much!