This is not for a production application, but just my exploration to help me understand cryptography.
At the simplest level, I want to design a key-value store for user secrets.
This is exposed over an HTTPS API with usual create-read-update-delete operations supported: send a post request with a body of a sercret, the server encrypts and stores that secret, then returns back an id for that secret; send a get to the id and get back the decrypted secret; etc.
This service receives requests from other microserivces in the network on behalf of the user.
How should the service protect a user's secrets, and protect against unauthorized access to this API?
I know that in some way the service needs to authenticate and authorize the request from both the upstream service and the user.
What's a good way to pair these? One idea I have is something like...
- Generate a key
- Encrypt the secret using the key
- Store the encrypted secret
- Encrypt the key using...? something from the server + user - a shared secret maybe?
- Store the encrypted key
- Return to the user an id (token)
And to retrieve the secret:
- user/other service requests id from server
- server + user shared secret decrypts key
- key decrypts secret
- send secret to user