kms decrypt ignores key-id
enhancement
## Summary
Once a piece of ciphertext has been created by a copy of Moto, it will then subsequently honor that ciphertext going forward, so long as the embedded key-id is available at all on the server
## Current Behavior
```sh
k_id=$(awslocal kms create-key --output text --query KeyMetadata.KeyId)
enc=$(awslocal kms encrypt --key-id $k_id --plaintext "$(echo "hello world" | base64 -w 0)" --output text --query CiphertextBlob)
awslocal kms decrypt --key-id "$(python3 -m uuid -u uuid4)" --ciphertext "$enc" --output text --query Plaintext | base64 --decode
```
emits "hello world"
## Expected Behavior
Unknown --key-id parameters should produce `botocore.exceptions.ClientError: An error occurred (AccessDeniedException) when calling the Decrypt operation`
```sh
k_id=$(awslocal kms create-key --output text --query KeyMetadata.KeyId)
enc=$(awslocal kms encrypt --key-id $k_id --plaintext "$(echo "hello world" | base64 -w 0)" --output text --query CiphertextBlob)
if awslocal kms decrypt --key-id "$(python3 -m uuid -u uuid4)" --ciphertext "$enc"; then
echo "a random key-id should have terminated the exchange" >&2
exit 1
fi
```
---
If my mental model is correct, there are two general approaches to fixing this experience:
- have the enforcement be opt-in
- use the original key-id as part of the ciphertext
For the opt-in, the `decrypt`and `re_encrypt` functions could compare the input key-id to the key-id that is currently embedded in the ciphertext. The hazard is that such comparison behavior would need to be retrofitted everywhere the kms backend touches the ciphertext, but would allow those who don't care about enforcement to continue to not concern themselves
In a more strict mode, one could essentially need the "password" of the original key-id to unlock the cipher text, and then the code could go back to behaving as it does now, including continuing to embed the key-id, IV, and tag to avoid having to make the change wide-ranging. It need not be industrial strength cryptography, merely not unconditionally trusting the input key-id
0 条评论