ChainSafe / forest

🌲 Rust Filecoin Node Implementation
https://forest.chainsafe.io
Apache License 2.0
618 stars 147 forks source link

Encrypted Key Store #1033

Closed amerameen closed 3 years ago

amerameen commented 3 years ago

ACs

Notes

cryptoquick commented 3 years ago

@ec2 Is this related to the keystore.json file? I don't think that's kept in the db. If it is, that should probably change, since it's already on-disk as a separate file.

ec2 commented 3 years ago

Oh nice. I thought it was stored in the DB for some reason...

cryptoquick commented 3 years ago

Just had a conversation with @f8-ptrk and he'd really like this feature prioritized. For his use-case, any degree of encryption is helpful, even if it's just AES-GCM-256 with a simple symmetric secret that decrypts the key in-memory while keeping the data encrypted at-rest. That way the keys cannot be exfiltrated from the data center from their miner workers.

Also, I might add one additional point I think the security auditors might bring up: The HTTP JSON-RPC API should have all requests over encrypted (HTTPS) connections, especially when sending a symmetric secret. This should technically be managed by the HTTP gateway on the machine, such as Nginx, or perhaps other network infrastructure, but regardless, I think we should check the X-Forwarded-Proto header to check for HTTPS when an RPC keystore decrypt method is called. This behavior could also be disabled for local testing with a command-line option when running the daemon.

I think this would be a good first issue to throw @connormullett at once he joins, what does everyone think?

cryptoquick commented 3 years ago

After speaking with @f8-ptrk, I added a requirement that the keystore be portable. That'd make it easier to backup and recover, especially if the user loses track of their hostname.

cryptoquick commented 3 years ago

I've moved the following ACs to issue #1083:

cryptoquick commented 3 years ago

Over the weekend I refactored the Encrypted Key Store quite a bit. We're only using sodiumoxide now, instead of mixing cryptosystems. I removed ring from the key_management crate, and we're now using the sodiumoxide Argon2id hash KDF. The salt is then prepended to the keystore when encrypted.

I just tested this out, writing and reading works great. I verified with hexyl that the first 16 bytes were the same (as a salt should be), but the remainder of the file is completely different, which means that secretbox is using a different nonce while flushing bytes to disk, which is more secure. The file also grows when running lotus wallet new and lotus wallet new bls, and I can check the balance of an existing wallet with lotus wallet balance [wallet address]. I'm not able to list, unfortunately.

Remaining items I'll leave to @connormullett to implement, which are the final remaining ACs: