We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
KMS Decrypt response is missing KeyId
Self-explanatory.

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `moto/kms/responses.py`
Content:
```
1 from __future__ import unicode_literals
2 
3 import base64
4 import json
5 import re
6 import six
7 
8 from boto.exception import JSONResponseError
9 from boto.kms.exceptions import AlreadyExistsException, NotFoundException
10 
11 from moto.core.responses import BaseResponse
12 from .models import kms_backends
13 
14 reserved_aliases = [
15     'alias/aws/ebs',
16     'alias/aws/s3',
17     'alias/aws/redshift',
18     'alias/aws/rds',
19 ]
20 
21 
22 class KmsResponse(BaseResponse):
23 
24     @property
25     def parameters(self):
26         return json.loads(self.body)
27 
28     @property
29     def kms_backend(self):
30         return kms_backends[self.region]
31 
32     def create_key(self):
33         policy = self.parameters.get('Policy')
34         key_usage = self.parameters.get('KeyUsage')
35         description = self.parameters.get('Description')
36 
37         key = self.kms_backend.create_key(
38             policy, key_usage, description, self.region)
39         return json.dumps(key.to_dict())
40 
41     def update_key_description(self):
42         key_id = self.parameters.get('KeyId')
43         description = self.parameters.get('Description')
44 
45         self.kms_backend.update_key_description(key_id, description)
46         return json.dumps(None)
47 
48     def tag_resource(self):
49         key_id = self.parameters.get('KeyId')
50         tags = self.parameters.get('Tags')
51         self.kms_backend.tag_resource(key_id, tags)
52         return json.dumps({})
53 
54     def list_resource_tags(self):
55         key_id = self.parameters.get('KeyId')
56         tags = self.kms_backend.list_resource_tags(key_id)
57         return json.dumps({
58             "Tags": tags,
59             "NextMarker": None,
60             "Truncated": False,
61         })
62 
63     def describe_key(self):
64         key_id = self.parameters.get('KeyId')
65         try:
66             key = self.kms_backend.describe_key(
67                 self.kms_backend.get_key_id(key_id))
68         except KeyError:
69             headers = dict(self.headers)
70             headers['status'] = 404
71             return "{}", headers
72         return json.dumps(key.to_dict())
73 
74     def list_keys(self):
75         keys = self.kms_backend.list_keys()
76 
77         return json.dumps({
78             "Keys": [
79                 {
80                     "KeyArn": key.arn,
81                     "KeyId": key.id,
82                 } for key in keys
83             ],
84             "NextMarker": None,
85             "Truncated": False,
86         })
87 
88     def create_alias(self):
89         alias_name = self.parameters['AliasName']
90         target_key_id = self.parameters['TargetKeyId']
91         region = self.region
92 
93         if not alias_name.startswith('alias/'):
94             raise JSONResponseError(400, 'Bad Request',
95                                     body={'message': 'Invalid identifier', '__type': 'ValidationException'})
96 
97         if alias_name in reserved_aliases:
98             raise JSONResponseError(400, 'Bad Request', body={
99                                     '__type': 'NotAuthorizedException'})
100 
101         if ':' in alias_name:
102             raise JSONResponseError(400, 'Bad Request', body={
103                 'message': '{alias_name} contains invalid characters for an alias'.format(**locals()),
104                 '__type': 'ValidationException'})
105 
106         if not re.match(r'^[a-zA-Z0-9:/_-]+$', alias_name):
107             raise JSONResponseError(400, 'Bad Request', body={
108                 'message': "1 validation error detected: Value '{alias_name}' at 'aliasName' failed to satisfy constraint: Member must satisfy regular expression pattern: ^[a-zA-Z0-9:/_-]+$"
109                                     .format(**locals()),
110                                     '__type': 'ValidationException'})
111 
112         if self.kms_backend.alias_exists(target_key_id):
113             raise JSONResponseError(400, 'Bad Request', body={
114                 'message': 'Aliases must refer to keys. Not aliases',
115                 '__type': 'ValidationException'})
116 
117         if self.kms_backend.alias_exists(alias_name):
118             raise AlreadyExistsException(400, 'Bad Request', body={
119                 'message': 'An alias with the name arn:aws:kms:{region}:012345678912:{alias_name} already exists'
120                                          .format(**locals()), '__type': 'AlreadyExistsException'})
121 
122         self.kms_backend.add_alias(target_key_id, alias_name)
123 
124         return json.dumps(None)
125 
126     def delete_alias(self):
127         alias_name = self.parameters['AliasName']
128         region = self.region
129 
130         if not alias_name.startswith('alias/'):
131             raise JSONResponseError(400, 'Bad Request',
132                                     body={'message': 'Invalid identifier', '__type': 'ValidationException'})
133 
134         if not self.kms_backend.alias_exists(alias_name):
135             raise NotFoundException(400, 'Bad Request', body={
136                 'message': 'Alias arn:aws:kms:{region}:012345678912:{alias_name} is not found.'.format(**locals()),
137                 '__type': 'NotFoundException'})
138 
139         self.kms_backend.delete_alias(alias_name)
140 
141         return json.dumps(None)
142 
143     def list_aliases(self):
144         region = self.region
145 
146         response_aliases = [
147             {
148                 'AliasArn': u'arn:aws:kms:{region}:012345678912:{reserved_alias}'.format(region=region,
149                                                                                          reserved_alias=reserved_alias),
150                 'AliasName': reserved_alias
151             } for reserved_alias in reserved_aliases
152         ]
153 
154         backend_aliases = self.kms_backend.get_all_aliases()
155         for target_key_id, aliases in backend_aliases.items():
156             for alias_name in aliases:
157                 response_aliases.append({
158                     'AliasArn': u'arn:aws:kms:{region}:012345678912:{alias_name}'.format(region=region,
159                                                                                          alias_name=alias_name),
160                     'AliasName': alias_name,
161                     'TargetKeyId': target_key_id,
162                 })
163 
164         return json.dumps({
165             'Truncated': False,
166             'Aliases': response_aliases,
167         })
168 
169     def enable_key_rotation(self):
170         key_id = self.parameters.get('KeyId')
171         _assert_valid_key_id(self.kms_backend.get_key_id(key_id))
172         try:
173             self.kms_backend.enable_key_rotation(key_id)
174         except KeyError:
175             raise JSONResponseError(404, 'Not Found', body={
176                 'message': "Key 'arn:aws:kms:{region}:012345678912:key/{key_id}' does not exist".format(region=self.region, key_id=key_id),
177                 '__type': 'NotFoundException'})
178 
179         return json.dumps(None)
180 
181     def disable_key_rotation(self):
182         key_id = self.parameters.get('KeyId')
183         _assert_valid_key_id(self.kms_backend.get_key_id(key_id))
184         try:
185             self.kms_backend.disable_key_rotation(key_id)
186         except KeyError:
187             raise JSONResponseError(404, 'Not Found', body={
188                 'message': "Key 'arn:aws:kms:{region}:012345678912:key/{key_id}' does not exist".format(region=self.region, key_id=key_id),
189                 '__type': 'NotFoundException'})
190         return json.dumps(None)
191 
192     def get_key_rotation_status(self):
193         key_id = self.parameters.get('KeyId')
194         _assert_valid_key_id(self.kms_backend.get_key_id(key_id))
195         try:
196             rotation_enabled = self.kms_backend.get_key_rotation_status(key_id)
197         except KeyError:
198             raise JSONResponseError(404, 'Not Found', body={
199                 'message': "Key 'arn:aws:kms:{region}:012345678912:key/{key_id}' does not exist".format(region=self.region, key_id=key_id),
200                 '__type': 'NotFoundException'})
201         return json.dumps({'KeyRotationEnabled': rotation_enabled})
202 
203     def put_key_policy(self):
204         key_id = self.parameters.get('KeyId')
205         policy_name = self.parameters.get('PolicyName')
206         policy = self.parameters.get('Policy')
207         _assert_valid_key_id(self.kms_backend.get_key_id(key_id))
208         _assert_default_policy(policy_name)
209 
210         try:
211             self.kms_backend.put_key_policy(key_id, policy)
212         except KeyError:
213             raise JSONResponseError(404, 'Not Found', body={
214                 'message': "Key 'arn:aws:kms:{region}:012345678912:key/{key_id}' does not exist".format(region=self.region, key_id=key_id),
215                 '__type': 'NotFoundException'})
216 
217         return json.dumps(None)
218 
219     def get_key_policy(self):
220         key_id = self.parameters.get('KeyId')
221         policy_name = self.parameters.get('PolicyName')
222         _assert_valid_key_id(self.kms_backend.get_key_id(key_id))
223         _assert_default_policy(policy_name)
224 
225         try:
226             return json.dumps({'Policy': self.kms_backend.get_key_policy(key_id)})
227         except KeyError:
228             raise JSONResponseError(404, 'Not Found', body={
229                 'message': "Key 'arn:aws:kms:{region}:012345678912:key/{key_id}' does not exist".format(region=self.region, key_id=key_id),
230                 '__type': 'NotFoundException'})
231 
232     def list_key_policies(self):
233         key_id = self.parameters.get('KeyId')
234         _assert_valid_key_id(self.kms_backend.get_key_id(key_id))
235         try:
236             self.kms_backend.describe_key(key_id)
237         except KeyError:
238             raise JSONResponseError(404, 'Not Found', body={
239                 'message': "Key 'arn:aws:kms:{region}:012345678912:key/{key_id}' does not exist".format(region=self.region, key_id=key_id),
240                 '__type': 'NotFoundException'})
241 
242         return json.dumps({'Truncated': False, 'PolicyNames': ['default']})
243 
244     def encrypt(self):
245         """
246         We perform no encryption, we just encode the value as base64 and then
247         decode it in decrypt().
248         """
249         value = self.parameters.get("Plaintext")
250         if isinstance(value, six.text_type):
251             value = value.encode('utf-8')
252         return json.dumps({"CiphertextBlob": base64.b64encode(value).decode("utf-8")})
253 
254     def decrypt(self):
255         value = self.parameters.get("CiphertextBlob")
256         return json.dumps({"Plaintext": base64.b64decode(value).decode("utf-8")})
257 
258     def disable_key(self):
259         key_id = self.parameters.get('KeyId')
260         _assert_valid_key_id(self.kms_backend.get_key_id(key_id))
261         try:
262             self.kms_backend.disable_key(key_id)
263         except KeyError:
264             raise JSONResponseError(404, 'Not Found', body={
265                 'message': "Key 'arn:aws:kms:{region}:012345678912:key/{key_id}' does not exist".format(region=self.region, key_id=key_id),
266                 '__type': 'NotFoundException'})
267         return json.dumps(None)
268 
269     def enable_key(self):
270         key_id = self.parameters.get('KeyId')
271         _assert_valid_key_id(self.kms_backend.get_key_id(key_id))
272         try:
273             self.kms_backend.enable_key(key_id)
274         except KeyError:
275             raise JSONResponseError(404, 'Not Found', body={
276                 'message': "Key 'arn:aws:kms:{region}:012345678912:key/{key_id}' does not exist".format(region=self.region, key_id=key_id),
277                 '__type': 'NotFoundException'})
278         return json.dumps(None)
279 
280     def cancel_key_deletion(self):
281         key_id = self.parameters.get('KeyId')
282         _assert_valid_key_id(self.kms_backend.get_key_id(key_id))
283         try:
284             self.kms_backend.cancel_key_deletion(key_id)
285         except KeyError:
286             raise JSONResponseError(404, 'Not Found', body={
287                 'message': "Key 'arn:aws:kms:{region}:012345678912:key/{key_id}' does not exist".format(region=self.region, key_id=key_id),
288                 '__type': 'NotFoundException'})
289         return json.dumps({'KeyId': key_id})
290 
291     def schedule_key_deletion(self):
292         key_id = self.parameters.get('KeyId')
293         if self.parameters.get('PendingWindowInDays') is None:
294             pending_window_in_days = 30
295         else:
296             pending_window_in_days = self.parameters.get('PendingWindowInDays')
297         _assert_valid_key_id(self.kms_backend.get_key_id(key_id))
298         try:
299             return json.dumps({
300                 'KeyId': key_id,
301                 'DeletionDate': self.kms_backend.schedule_key_deletion(key_id, pending_window_in_days)
302             })
303         except KeyError:
304             raise JSONResponseError(404, 'Not Found', body={
305                 'message': "Key 'arn:aws:kms:{region}:012345678912:key/{key_id}' does not exist".format(region=self.region, key_id=key_id),
306                 '__type': 'NotFoundException'})
307 
308 
309 def _assert_valid_key_id(key_id):
310     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):
311         raise JSONResponseError(404, 'Not Found', body={
312                                 'message': ' Invalid keyId', '__type': 'NotFoundException'})
313 
314 
315 def _assert_default_policy(policy_name):
316     if policy_name != 'default':
317         raise JSONResponseError(404, 'Not Found', body={
318             'message': "No such policy exists",
319             '__type': 'NotFoundException'})
320
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/moto/kms/responses.py b/moto/kms/responses.py
--- a/moto/kms/responses.py
+++ b/moto/kms/responses.py
@@ -249,11 +249,11 @@
         value = self.parameters.get("Plaintext")
         if isinstance(value, six.text_type):
             value = value.encode('utf-8')
-        return json.dumps({"CiphertextBlob": base64.b64encode(value).decode("utf-8")})
+        return json.dumps({"CiphertextBlob": base64.b64encode(value).decode("utf-8"), 'KeyId': 'key_id'})
 
     def decrypt(self):
         value = self.parameters.get("CiphertextBlob")
-        return json.dumps({"Plaintext": base64.b64decode(value).decode("utf-8")})
+        return json.dumps({"Plaintext": base64.b64decode(value).decode("utf-8"), 'KeyId': 'key_id'})
 
     def disable_key(self):
         key_id = self.parameters.get('KeyId')

{"golden_diff": "diff --git a/moto/kms/responses.py b/moto/kms/responses.py\n--- a/moto/kms/responses.py\n+++ b/moto/kms/responses.py\n@@ -249,11 +249,11 @@\n         value = self.parameters.get(\"Plaintext\")\n         if isinstance(value, six.text_type):\n             value = value.encode('utf-8')\n-        return json.dumps({\"CiphertextBlob\": base64.b64encode(value).decode(\"utf-8\")})\n+        return json.dumps({\"CiphertextBlob\": base64.b64encode(value).decode(\"utf-8\"), 'KeyId': 'key_id'})\n \n     def decrypt(self):\n         value = self.parameters.get(\"CiphertextBlob\")\n-        return json.dumps({\"Plaintext\": base64.b64decode(value).decode(\"utf-8\")})\n+        return json.dumps({\"Plaintext\": base64.b64decode(value).decode(\"utf-8\"), 'KeyId': 'key_id'})\n \n     def disable_key(self):\n         key_id = self.parameters.get('KeyId')\n", "issue": "KMS Decrypt response is missing KeyId\nSelf-explanatory.\n", "before_files": [{"content": "from __future__ import unicode_literals\n\nimport base64\nimport json\nimport re\nimport six\n\nfrom boto.exception import JSONResponseError\nfrom boto.kms.exceptions import AlreadyExistsException, NotFoundException\n\nfrom moto.core.responses import BaseResponse\nfrom .models import kms_backends\n\nreserved_aliases = [\n    'alias/aws/ebs',\n    'alias/aws/s3',\n    'alias/aws/redshift',\n    'alias/aws/rds',\n]\n\n\nclass KmsResponse(BaseResponse):\n\n    @property\n    def parameters(self):\n        return json.loads(self.body)\n\n    @property\n    def kms_backend(self):\n        return kms_backends[self.region]\n\n    def create_key(self):\n        policy = self.parameters.get('Policy')\n        key_usage = self.parameters.get('KeyUsage')\n        description = self.parameters.get('Description')\n\n        key = self.kms_backend.create_key(\n            policy, key_usage, description, self.region)\n        return json.dumps(key.to_dict())\n\n    def update_key_description(self):\n        key_id = self.parameters.get('KeyId')\n        description = self.parameters.get('Description')\n\n        self.kms_backend.update_key_description(key_id, description)\n        return json.dumps(None)\n\n    def tag_resource(self):\n        key_id = self.parameters.get('KeyId')\n        tags = self.parameters.get('Tags')\n        self.kms_backend.tag_resource(key_id, tags)\n        return json.dumps({})\n\n    def list_resource_tags(self):\n        key_id = self.parameters.get('KeyId')\n        tags = self.kms_backend.list_resource_tags(key_id)\n        return json.dumps({\n            \"Tags\": tags,\n            \"NextMarker\": None,\n            \"Truncated\": False,\n        })\n\n    def describe_key(self):\n        key_id = self.parameters.get('KeyId')\n        try:\n            key = self.kms_backend.describe_key(\n                self.kms_backend.get_key_id(key_id))\n        except KeyError:\n            headers = dict(self.headers)\n            headers['status'] = 404\n            return \"{}\", headers\n        return json.dumps(key.to_dict())\n\n    def list_keys(self):\n        keys = self.kms_backend.list_keys()\n\n        return json.dumps({\n            \"Keys\": [\n                {\n                    \"KeyArn\": key.arn,\n                    \"KeyId\": key.id,\n                } for key in keys\n            ],\n            \"NextMarker\": None,\n            \"Truncated\": False,\n        })\n\n    def create_alias(self):\n        alias_name = self.parameters['AliasName']\n        target_key_id = self.parameters['TargetKeyId']\n        region = self.region\n\n        if not alias_name.startswith('alias/'):\n            raise JSONResponseError(400, 'Bad Request',\n                                    body={'message': 'Invalid identifier', '__type': 'ValidationException'})\n\n        if alias_name in reserved_aliases:\n            raise JSONResponseError(400, 'Bad Request', body={\n                                    '__type': 'NotAuthorizedException'})\n\n        if ':' in alias_name:\n            raise JSONResponseError(400, 'Bad Request', body={\n                'message': '{alias_name} contains invalid characters for an alias'.format(**locals()),\n                '__type': 'ValidationException'})\n\n        if not re.match(r'^[a-zA-Z0-9:/_-]+$', alias_name):\n            raise JSONResponseError(400, 'Bad Request', body={\n                'message': \"1 validation error detected: Value '{alias_name}' at 'aliasName' failed to satisfy constraint: Member must satisfy regular expression pattern: ^[a-zA-Z0-9:/_-]+$\"\n                                    .format(**locals()),\n                                    '__type': 'ValidationException'})\n\n        if self.kms_backend.alias_exists(target_key_id):\n            raise JSONResponseError(400, 'Bad Request', body={\n                'message': 'Aliases must refer to keys. Not aliases',\n                '__type': 'ValidationException'})\n\n        if self.kms_backend.alias_exists(alias_name):\n            raise AlreadyExistsException(400, 'Bad Request', body={\n                'message': 'An alias with the name arn:aws:kms:{region}:012345678912:{alias_name} already exists'\n                                         .format(**locals()), '__type': 'AlreadyExistsException'})\n\n        self.kms_backend.add_alias(target_key_id, alias_name)\n\n        return json.dumps(None)\n\n    def delete_alias(self):\n        alias_name = self.parameters['AliasName']\n        region = self.region\n\n        if not alias_name.startswith('alias/'):\n            raise JSONResponseError(400, 'Bad Request',\n                                    body={'message': 'Invalid identifier', '__type': 'ValidationException'})\n\n        if not self.kms_backend.alias_exists(alias_name):\n            raise NotFoundException(400, 'Bad Request', body={\n                'message': 'Alias arn:aws:kms:{region}:012345678912:{alias_name} is not found.'.format(**locals()),\n                '__type': 'NotFoundException'})\n\n        self.kms_backend.delete_alias(alias_name)\n\n        return json.dumps(None)\n\n    def list_aliases(self):\n        region = self.region\n\n        response_aliases = [\n            {\n                'AliasArn': u'arn:aws:kms:{region}:012345678912:{reserved_alias}'.format(region=region,\n                                                                                         reserved_alias=reserved_alias),\n                'AliasName': reserved_alias\n            } for reserved_alias in reserved_aliases\n        ]\n\n        backend_aliases = self.kms_backend.get_all_aliases()\n        for target_key_id, aliases in backend_aliases.items():\n            for alias_name in aliases:\n                response_aliases.append({\n                    'AliasArn': u'arn:aws:kms:{region}:012345678912:{alias_name}'.format(region=region,\n                                                                                         alias_name=alias_name),\n                    'AliasName': alias_name,\n                    'TargetKeyId': target_key_id,\n                })\n\n        return json.dumps({\n            'Truncated': False,\n            'Aliases': response_aliases,\n        })\n\n    def enable_key_rotation(self):\n        key_id = self.parameters.get('KeyId')\n        _assert_valid_key_id(self.kms_backend.get_key_id(key_id))\n        try:\n            self.kms_backend.enable_key_rotation(key_id)\n        except KeyError:\n            raise JSONResponseError(404, 'Not Found', body={\n                'message': \"Key 'arn:aws:kms:{region}:012345678912:key/{key_id}' does not exist\".format(region=self.region, key_id=key_id),\n                '__type': 'NotFoundException'})\n\n        return json.dumps(None)\n\n    def disable_key_rotation(self):\n        key_id = self.parameters.get('KeyId')\n        _assert_valid_key_id(self.kms_backend.get_key_id(key_id))\n        try:\n            self.kms_backend.disable_key_rotation(key_id)\n        except KeyError:\n            raise JSONResponseError(404, 'Not Found', body={\n                'message': \"Key 'arn:aws:kms:{region}:012345678912:key/{key_id}' does not exist\".format(region=self.region, key_id=key_id),\n                '__type': 'NotFoundException'})\n        return json.dumps(None)\n\n    def get_key_rotation_status(self):\n        key_id = self.parameters.get('KeyId')\n        _assert_valid_key_id(self.kms_backend.get_key_id(key_id))\n        try:\n            rotation_enabled = self.kms_backend.get_key_rotation_status(key_id)\n        except KeyError:\n            raise JSONResponseError(404, 'Not Found', body={\n                'message': \"Key 'arn:aws:kms:{region}:012345678912:key/{key_id}' does not exist\".format(region=self.region, key_id=key_id),\n                '__type': 'NotFoundException'})\n        return json.dumps({'KeyRotationEnabled': rotation_enabled})\n\n    def put_key_policy(self):\n        key_id = self.parameters.get('KeyId')\n        policy_name = self.parameters.get('PolicyName')\n        policy = self.parameters.get('Policy')\n        _assert_valid_key_id(self.kms_backend.get_key_id(key_id))\n        _assert_default_policy(policy_name)\n\n        try:\n            self.kms_backend.put_key_policy(key_id, policy)\n        except KeyError:\n            raise JSONResponseError(404, 'Not Found', body={\n                'message': \"Key 'arn:aws:kms:{region}:012345678912:key/{key_id}' does not exist\".format(region=self.region, key_id=key_id),\n                '__type': 'NotFoundException'})\n\n        return json.dumps(None)\n\n    def get_key_policy(self):\n        key_id = self.parameters.get('KeyId')\n        policy_name = self.parameters.get('PolicyName')\n        _assert_valid_key_id(self.kms_backend.get_key_id(key_id))\n        _assert_default_policy(policy_name)\n\n        try:\n            return json.dumps({'Policy': self.kms_backend.get_key_policy(key_id)})\n        except KeyError:\n            raise JSONResponseError(404, 'Not Found', body={\n                'message': \"Key 'arn:aws:kms:{region}:012345678912:key/{key_id}' does not exist\".format(region=self.region, key_id=key_id),\n                '__type': 'NotFoundException'})\n\n    def list_key_policies(self):\n        key_id = self.parameters.get('KeyId')\n        _assert_valid_key_id(self.kms_backend.get_key_id(key_id))\n        try:\n            self.kms_backend.describe_key(key_id)\n        except KeyError:\n            raise JSONResponseError(404, 'Not Found', body={\n                'message': \"Key 'arn:aws:kms:{region}:012345678912:key/{key_id}' does not exist\".format(region=self.region, key_id=key_id),\n                '__type': 'NotFoundException'})\n\n        return json.dumps({'Truncated': False, 'PolicyNames': ['default']})\n\n    def encrypt(self):\n        \"\"\"\n        We perform no encryption, we just encode the value as base64 and then\n        decode it in decrypt().\n        \"\"\"\n        value = self.parameters.get(\"Plaintext\")\n        if isinstance(value, six.text_type):\n            value = value.encode('utf-8')\n        return json.dumps({\"CiphertextBlob\": base64.b64encode(value).decode(\"utf-8\")})\n\n    def decrypt(self):\n        value = self.parameters.get(\"CiphertextBlob\")\n        return json.dumps({\"Plaintext\": base64.b64decode(value).decode(\"utf-8\")})\n\n    def disable_key(self):\n        key_id = self.parameters.get('KeyId')\n        _assert_valid_key_id(self.kms_backend.get_key_id(key_id))\n        try:\n            self.kms_backend.disable_key(key_id)\n        except KeyError:\n            raise JSONResponseError(404, 'Not Found', body={\n                'message': \"Key 'arn:aws:kms:{region}:012345678912:key/{key_id}' does not exist\".format(region=self.region, key_id=key_id),\n                '__type': 'NotFoundException'})\n        return json.dumps(None)\n\n    def enable_key(self):\n        key_id = self.parameters.get('KeyId')\n        _assert_valid_key_id(self.kms_backend.get_key_id(key_id))\n        try:\n            self.kms_backend.enable_key(key_id)\n        except KeyError:\n            raise JSONResponseError(404, 'Not Found', body={\n                'message': \"Key 'arn:aws:kms:{region}:012345678912:key/{key_id}' does not exist\".format(region=self.region, key_id=key_id),\n                '__type': 'NotFoundException'})\n        return json.dumps(None)\n\n    def cancel_key_deletion(self):\n        key_id = self.parameters.get('KeyId')\n        _assert_valid_key_id(self.kms_backend.get_key_id(key_id))\n        try:\n            self.kms_backend.cancel_key_deletion(key_id)\n        except KeyError:\n            raise JSONResponseError(404, 'Not Found', body={\n                'message': \"Key 'arn:aws:kms:{region}:012345678912:key/{key_id}' does not exist\".format(region=self.region, key_id=key_id),\n                '__type': 'NotFoundException'})\n        return json.dumps({'KeyId': key_id})\n\n    def schedule_key_deletion(self):\n        key_id = self.parameters.get('KeyId')\n        if self.parameters.get('PendingWindowInDays') is None:\n            pending_window_in_days = 30\n        else:\n            pending_window_in_days = self.parameters.get('PendingWindowInDays')\n        _assert_valid_key_id(self.kms_backend.get_key_id(key_id))\n        try:\n            return json.dumps({\n                'KeyId': key_id,\n                'DeletionDate': self.kms_backend.schedule_key_deletion(key_id, pending_window_in_days)\n            })\n        except KeyError:\n            raise JSONResponseError(404, 'Not Found', body={\n                'message': \"Key 'arn:aws:kms:{region}:012345678912:key/{key_id}' does not exist\".format(region=self.region, key_id=key_id),\n                '__type': 'NotFoundException'})\n\n\ndef _assert_valid_key_id(key_id):\n    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):\n        raise JSONResponseError(404, 'Not Found', body={\n                                'message': ' Invalid keyId', '__type': 'NotFoundException'})\n\n\ndef _assert_default_policy(policy_name):\n    if policy_name != 'default':\n        raise JSONResponseError(404, 'Not Found', body={\n            'message': \"No such policy exists\",\n            '__type': 'NotFoundException'})\n", "path": "moto/kms/responses.py"}], "after_files": [{"content": "from __future__ import unicode_literals\n\nimport base64\nimport json\nimport re\nimport six\n\nfrom boto.exception import JSONResponseError\nfrom boto.kms.exceptions import AlreadyExistsException, NotFoundException\n\nfrom moto.core.responses import BaseResponse\nfrom .models import kms_backends\n\nreserved_aliases = [\n    'alias/aws/ebs',\n    'alias/aws/s3',\n    'alias/aws/redshift',\n    'alias/aws/rds',\n]\n\n\nclass KmsResponse(BaseResponse):\n\n    @property\n    def parameters(self):\n        return json.loads(self.body)\n\n    @property\n    def kms_backend(self):\n        return kms_backends[self.region]\n\n    def create_key(self):\n        policy = self.parameters.get('Policy')\n        key_usage = self.parameters.get('KeyUsage')\n        description = self.parameters.get('Description')\n\n        key = self.kms_backend.create_key(\n            policy, key_usage, description, self.region)\n        return json.dumps(key.to_dict())\n\n    def update_key_description(self):\n        key_id = self.parameters.get('KeyId')\n        description = self.parameters.get('Description')\n\n        self.kms_backend.update_key_description(key_id, description)\n        return json.dumps(None)\n\n    def tag_resource(self):\n        key_id = self.parameters.get('KeyId')\n        tags = self.parameters.get('Tags')\n        self.kms_backend.tag_resource(key_id, tags)\n        return json.dumps({})\n\n    def list_resource_tags(self):\n        key_id = self.parameters.get('KeyId')\n        tags = self.kms_backend.list_resource_tags(key_id)\n        return json.dumps({\n            \"Tags\": tags,\n            \"NextMarker\": None,\n            \"Truncated\": False,\n        })\n\n    def describe_key(self):\n        key_id = self.parameters.get('KeyId')\n        try:\n            key = self.kms_backend.describe_key(\n                self.kms_backend.get_key_id(key_id))\n        except KeyError:\n            headers = dict(self.headers)\n            headers['status'] = 404\n            return \"{}\", headers\n        return json.dumps(key.to_dict())\n\n    def list_keys(self):\n        keys = self.kms_backend.list_keys()\n\n        return json.dumps({\n            \"Keys\": [\n                {\n                    \"KeyArn\": key.arn,\n                    \"KeyId\": key.id,\n                } for key in keys\n            ],\n            \"NextMarker\": None,\n            \"Truncated\": False,\n        })\n\n    def create_alias(self):\n        alias_name = self.parameters['AliasName']\n        target_key_id = self.parameters['TargetKeyId']\n        region = self.region\n\n        if not alias_name.startswith('alias/'):\n            raise JSONResponseError(400, 'Bad Request',\n                                    body={'message': 'Invalid identifier', '__type': 'ValidationException'})\n\n        if alias_name in reserved_aliases:\n            raise JSONResponseError(400, 'Bad Request', body={\n                                    '__type': 'NotAuthorizedException'})\n\n        if ':' in alias_name:\n            raise JSONResponseError(400, 'Bad Request', body={\n                'message': '{alias_name} contains invalid characters for an alias'.format(**locals()),\n                '__type': 'ValidationException'})\n\n        if not re.match(r'^[a-zA-Z0-9:/_-]+$', alias_name):\n            raise JSONResponseError(400, 'Bad Request', body={\n                'message': \"1 validation error detected: Value '{alias_name}' at 'aliasName' failed to satisfy constraint: Member must satisfy regular expression pattern: ^[a-zA-Z0-9:/_-]+$\"\n                                    .format(**locals()),\n                                    '__type': 'ValidationException'})\n\n        if self.kms_backend.alias_exists(target_key_id):\n            raise JSONResponseError(400, 'Bad Request', body={\n                'message': 'Aliases must refer to keys. Not aliases',\n                '__type': 'ValidationException'})\n\n        if self.kms_backend.alias_exists(alias_name):\n            raise AlreadyExistsException(400, 'Bad Request', body={\n                'message': 'An alias with the name arn:aws:kms:{region}:012345678912:{alias_name} already exists'\n                                         .format(**locals()), '__type': 'AlreadyExistsException'})\n\n        self.kms_backend.add_alias(target_key_id, alias_name)\n\n        return json.dumps(None)\n\n    def delete_alias(self):\n        alias_name = self.parameters['AliasName']\n        region = self.region\n\n        if not alias_name.startswith('alias/'):\n            raise JSONResponseError(400, 'Bad Request',\n                                    body={'message': 'Invalid identifier', '__type': 'ValidationException'})\n\n        if not self.kms_backend.alias_exists(alias_name):\n            raise NotFoundException(400, 'Bad Request', body={\n                'message': 'Alias arn:aws:kms:{region}:012345678912:{alias_name} is not found.'.format(**locals()),\n                '__type': 'NotFoundException'})\n\n        self.kms_backend.delete_alias(alias_name)\n\n        return json.dumps(None)\n\n    def list_aliases(self):\n        region = self.region\n\n        response_aliases = [\n            {\n                'AliasArn': u'arn:aws:kms:{region}:012345678912:{reserved_alias}'.format(region=region,\n                                                                                         reserved_alias=reserved_alias),\n                'AliasName': reserved_alias\n            } for reserved_alias in reserved_aliases\n        ]\n\n        backend_aliases = self.kms_backend.get_all_aliases()\n        for target_key_id, aliases in backend_aliases.items():\n            for alias_name in aliases:\n                response_aliases.append({\n                    'AliasArn': u'arn:aws:kms:{region}:012345678912:{alias_name}'.format(region=region,\n                                                                                         alias_name=alias_name),\n                    'AliasName': alias_name,\n                    'TargetKeyId': target_key_id,\n                })\n\n        return json.dumps({\n            'Truncated': False,\n            'Aliases': response_aliases,\n        })\n\n    def enable_key_rotation(self):\n        key_id = self.parameters.get('KeyId')\n        _assert_valid_key_id(self.kms_backend.get_key_id(key_id))\n        try:\n            self.kms_backend.enable_key_rotation(key_id)\n        except KeyError:\n            raise JSONResponseError(404, 'Not Found', body={\n                'message': \"Key 'arn:aws:kms:{region}:012345678912:key/{key_id}' does not exist\".format(region=self.region, key_id=key_id),\n                '__type': 'NotFoundException'})\n\n        return json.dumps(None)\n\n    def disable_key_rotation(self):\n        key_id = self.parameters.get('KeyId')\n        _assert_valid_key_id(self.kms_backend.get_key_id(key_id))\n        try:\n            self.kms_backend.disable_key_rotation(key_id)\n        except KeyError:\n            raise JSONResponseError(404, 'Not Found', body={\n                'message': \"Key 'arn:aws:kms:{region}:012345678912:key/{key_id}' does not exist\".format(region=self.region, key_id=key_id),\n                '__type': 'NotFoundException'})\n        return json.dumps(None)\n\n    def get_key_rotation_status(self):\n        key_id = self.parameters.get('KeyId')\n        _assert_valid_key_id(self.kms_backend.get_key_id(key_id))\n        try:\n            rotation_enabled = self.kms_backend.get_key_rotation_status(key_id)\n        except KeyError:\n            raise JSONResponseError(404, 'Not Found', body={\n                'message': \"Key 'arn:aws:kms:{region}:012345678912:key/{key_id}' does not exist\".format(region=self.region, key_id=key_id),\n                '__type': 'NotFoundException'})\n        return json.dumps({'KeyRotationEnabled': rotation_enabled})\n\n    def put_key_policy(self):\n        key_id = self.parameters.get('KeyId')\n        policy_name = self.parameters.get('PolicyName')\n        policy = self.parameters.get('Policy')\n        _assert_valid_key_id(self.kms_backend.get_key_id(key_id))\n        _assert_default_policy(policy_name)\n\n        try:\n            self.kms_backend.put_key_policy(key_id, policy)\n        except KeyError:\n            raise JSONResponseError(404, 'Not Found', body={\n                'message': \"Key 'arn:aws:kms:{region}:012345678912:key/{key_id}' does not exist\".format(region=self.region, key_id=key_id),\n                '__type': 'NotFoundException'})\n\n        return json.dumps(None)\n\n    def get_key_policy(self):\n        key_id = self.parameters.get('KeyId')\n        policy_name = self.parameters.get('PolicyName')\n        _assert_valid_key_id(self.kms_backend.get_key_id(key_id))\n        _assert_default_policy(policy_name)\n\n        try:\n            return json.dumps({'Policy': self.kms_backend.get_key_policy(key_id)})\n        except KeyError:\n            raise JSONResponseError(404, 'Not Found', body={\n                'message': \"Key 'arn:aws:kms:{region}:012345678912:key/{key_id}' does not exist\".format(region=self.region, key_id=key_id),\n                '__type': 'NotFoundException'})\n\n    def list_key_policies(self):\n        key_id = self.parameters.get('KeyId')\n        _assert_valid_key_id(self.kms_backend.get_key_id(key_id))\n        try:\n            self.kms_backend.describe_key(key_id)\n        except KeyError:\n            raise JSONResponseError(404, 'Not Found', body={\n                'message': \"Key 'arn:aws:kms:{region}:012345678912:key/{key_id}' does not exist\".format(region=self.region, key_id=key_id),\n                '__type': 'NotFoundException'})\n\n        return json.dumps({'Truncated': False, 'PolicyNames': ['default']})\n\n    def encrypt(self):\n        \"\"\"\n        We perform no encryption, we just encode the value as base64 and then\n        decode it in decrypt().\n        \"\"\"\n        value = self.parameters.get(\"Plaintext\")\n        if isinstance(value, six.text_type):\n            value = value.encode('utf-8')\n        return json.dumps({\"CiphertextBlob\": base64.b64encode(value).decode(\"utf-8\"), 'KeyId': 'key_id'})\n\n    def decrypt(self):\n        value = self.parameters.get(\"CiphertextBlob\")\n        return json.dumps({\"Plaintext\": base64.b64decode(value).decode(\"utf-8\"), 'KeyId': 'key_id'})\n\n    def disable_key(self):\n        key_id = self.parameters.get('KeyId')\n        _assert_valid_key_id(self.kms_backend.get_key_id(key_id))\n        try:\n            self.kms_backend.disable_key(key_id)\n        except KeyError:\n            raise JSONResponseError(404, 'Not Found', body={\n                'message': \"Key 'arn:aws:kms:{region}:012345678912:key/{key_id}' does not exist\".format(region=self.region, key_id=key_id),\n                '__type': 'NotFoundException'})\n        return json.dumps(None)\n\n    def enable_key(self):\n        key_id = self.parameters.get('KeyId')\n        _assert_valid_key_id(self.kms_backend.get_key_id(key_id))\n        try:\n            self.kms_backend.enable_key(key_id)\n        except KeyError:\n            raise JSONResponseError(404, 'Not Found', body={\n                'message': \"Key 'arn:aws:kms:{region}:012345678912:key/{key_id}' does not exist\".format(region=self.region, key_id=key_id),\n                '__type': 'NotFoundException'})\n        return json.dumps(None)\n\n    def cancel_key_deletion(self):\n        key_id = self.parameters.get('KeyId')\n        _assert_valid_key_id(self.kms_backend.get_key_id(key_id))\n        try:\n            self.kms_backend.cancel_key_deletion(key_id)\n        except KeyError:\n            raise JSONResponseError(404, 'Not Found', body={\n                'message': \"Key 'arn:aws:kms:{region}:012345678912:key/{key_id}' does not exist\".format(region=self.region, key_id=key_id),\n                '__type': 'NotFoundException'})\n        return json.dumps({'KeyId': key_id})\n\n    def schedule_key_deletion(self):\n        key_id = self.parameters.get('KeyId')\n        if self.parameters.get('PendingWindowInDays') is None:\n            pending_window_in_days = 30\n        else:\n            pending_window_in_days = self.parameters.get('PendingWindowInDays')\n        _assert_valid_key_id(self.kms_backend.get_key_id(key_id))\n        try:\n            return json.dumps({\n                'KeyId': key_id,\n                'DeletionDate': self.kms_backend.schedule_key_deletion(key_id, pending_window_in_days)\n            })\n        except KeyError:\n            raise JSONResponseError(404, 'Not Found', body={\n                'message': \"Key 'arn:aws:kms:{region}:012345678912:key/{key_id}' does not exist\".format(region=self.region, key_id=key_id),\n                '__type': 'NotFoundException'})\n\n\ndef _assert_valid_key_id(key_id):\n    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):\n        raise JSONResponseError(404, 'Not Found', body={\n                                'message': ' Invalid keyId', '__type': 'NotFoundException'})\n\n\ndef _assert_default_policy(policy_name):\n    if policy_name != 'default':\n        raise JSONResponseError(404, 'Not Found', body={\n            'message': \"No such policy exists\",\n            '__type': 'NotFoundException'})\n", "path": "moto/kms/responses.py"}]}