Implementing KMS encrypt/decrypt
This adds support for testing the /encrypt and /decrypt endpoints of Amazon KMS
This commit is contained in:
parent
4157abe8de
commit
ea24376131
2 changed files with 36 additions and 0 deletions
|
|
@ -1,5 +1,6 @@
|
|||
from __future__ import unicode_literals
|
||||
|
||||
import base64
|
||||
import json
|
||||
import re
|
||||
|
||||
|
|
@ -213,6 +214,19 @@ class KmsResponse(BaseResponse):
|
|||
|
||||
return json.dumps({'Truncated': False, 'PolicyNames': ['default']})
|
||||
|
||||
def encrypt(self):
|
||||
"""
|
||||
We perform no encryption, we just encode the value as base64 and then
|
||||
decode it in decrypt().
|
||||
"""
|
||||
value = self.parameters.get("Plaintext")
|
||||
return json.dumps({"CiphertextBlob": base64.b64encode(value).encode("utf-8")})
|
||||
|
||||
def decrypt(self):
|
||||
value = self.parameters.get("CiphertextBlob")
|
||||
return json.dumps({"Plaintext": base64.b64decode(value).encode("utf-8")})
|
||||
|
||||
|
||||
def _assert_valid_key_id(key_id):
|
||||
if not re.match(r'^[A-F0-9]{8}-[A-F0-9]{4}-[A-F0-9]{4}-[A-F0-9]{4}-[A-F0-9]{12}$', key_id, re.IGNORECASE):
|
||||
raise JSONResponseError(404, 'Not Found', body={'message': ' Invalid keyId', '__type': 'NotFoundException'})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue