Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing the decode_encryption_key in the sample code (see below) #9

Open
imlocn opened this issue Jun 30, 2016 · 4 comments
Open

Missing the decode_encryption_key in the sample code (see below) #9

imlocn opened this issue Jun 30, 2016 · 4 comments

Comments

@imlocn
Copy link

imlocn commented Jun 30, 2016

REGION = 'us-west-2'
BUCKET = 'testing.stuff.bucket'
s3_key = 'testing.txt'

s3 = boto3.client('s3', region_name=REGION)
encoded_key = s3.get_object(Bucket=BUCKET, Key=s3_key + '.key')

plaintext_key = decode_encryption_key(encoded_key)

s3e = S3EncryptionClient(encryption_key=plaintext_key, region_name=REGION)
print s3e.get_object(Bucket=BUCKET, Key=s3_key)

'this is a test'

@boldfield
Copy link
Owner

There's several ways to approach getting the plaintext key. My assumption here was that it would be generated somewhere else making calls to the KMS service and exist in scope for this example. Upon reflection, that makes things very ambiguous. I'll update this to make things a little more clear, thanks for pointing this out.

@imlocn
Copy link
Author

imlocn commented Jun 30, 2016

Can you provide an complete example of front-end encrypt/decrypt for upload/download files to S3?

@imlocn
Copy link
Author

imlocn commented Jun 30, 2016

Do you have the code for the decode_encryption_key(encoded_key)?

@tolidano
Copy link

tolidano commented Oct 1, 2017

imlocn - just to add some clarity here - the point is that it is NOT the responsibility of boldfield (or this library) to encrypt or decrypt the content that goes into the s3_key + '.key' file.

If you want a fast and easy way of doing this with boto3 and KMS:

When you encrypt:

def get_info():
    kms = boto3.client('kms')
    data_key_req = kms.generate_data_key(KeyId=self.key_id, KeySpec='AES_128')
    # now, data_key_req has TWO keys:
    encrypt_your_data_with_this_key = data_key_req['Plaintext']
    upload_this_to_the_dot_key_file = data_key_req['CiphertextBlob']
    return {'p': encrypt_your_data_with_this_key, 'c': upload_this_to_the_dot_key_file}

Now when you decrypt, this is the bit you need:

def decode_encryption_key(encoded_key):
    kms = boto3.client('kms')
    decrypt_req = kms.decrypt(CiphertextBlob=encoded_key)
    return decrypt_req['Plaintext']

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants