1

I need to encrypt personal data like email, phone number, etc. I am using AWS KMS for managing the encryption keys. This is the system that is already implemented is as follows:

  1. All the existing data is encrypted using a worker which first generates a data key by calling the aws-sdk. This call returns the plaintext(decrypted data key) and the encrypted data key. This plaintext is then used to encrypt the data and then is removed from the memory.
  2. Now whenever a new data key is generated, the encrypted data key is stored in a .json file and uploaded to AWS S3 bucket. This upload has Server Side Encryption enabled using a Customer Key. I store the path to this json file to the db table that keeps record of the active data keys.
  3. Whenever I need to decrypt data, I get the json file from the s3 bucket which contains the encrypted data key. Then I call the decrypt function of aws sdk and retrieve the original data key which is then used to decrypt the encrypted data.

Now my question is:


How do I manage the customer key used in step 2 for the server side encryption of the s3 file upload. Right now I generate a random key for each data key and store this in the data keys table. Is this a safe way to handle this key?
What is the general practice regarding using SSE-C keys? Should I keep a constant key for each data key instead of generating a new one?

any help is highly appreciated

2 Answers2

0

The practice is to use envelope encryption as depicted below. You should store the master key (which is your CMK) in KMS and the data-keys along with the encrypted data.

enter image description here

Lucas Kauffman
  • 54,169
  • 17
  • 112
  • 196
0

You should always have individual keys per object, to avoid the situation where a single key being compromised will affect all objects in your bucket.

If you absolutely must do it this way -- instead of relying on SSE-KMS encryption, then I'd store the json path as metadata on the object, rather than in a separate database. This way, your solution doesn't require an additional database. You can retrieve the object meta-data, to retrieve the key material.

But I'm not sure if you can retrieve metadata from the sse-c encrypted object, but perhaps you can try.

But again, using SSE-KMS seems a more reasonable choice.

keithRozario
  • 3,571
  • 2
  • 12
  • 24