-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
KMS: Remove the reserved key value pair from aad #8350
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Deferring to @whummer who has better context 🙂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Kudos for digging into this issue @sannya-singal , great analysis! 🚀 Added a comment regarding the key name (removing the backticks), and a small suggestion for restructuring the code a bit. 👍
localstack/services/kms/models.py
Outdated
aad.write(key.encode("utf-8")) | ||
aad.write(value.encode("utf-8")) | ||
# remove the reserved key-value pair from additional authentication data | ||
if key != "`aws-crypto-public-key`": |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should compare against the verbatim string "aws-crypto-public-key"
here, without the backticks.
After changing this line to the following, I was able to successfully run the upstream test in (test_encrypt_via_aws_encryption_sdk
) that is currently disabled:
if key != "aws-crypto-public-key":
nit: As a general note, we usually configure string constants like this one at the global scope of the module - this can help improve readability and reduce duplication, and can also facilitate monkey patching more easily (e.g., for testing, or if the logic needs to be extended from -ext, etc). 👍
I'd suggest that we define a global variable like IGNORED_CONTEXT_KEYS
(somewhere at the top of this file), and then use it as follows:
# list of key names that should be skipped when serializing the encryption context
IGNORED_CONTEXT_KEYS = ["aws-crypto-public-key"]
...
def _serialize_encryption_context(...) ...:
if encryption_context:
aad = io.BytesIO()
for key, value in sorted(encryption_context.items(), key=lambda x: x[0]):
# remove ignored context keys from additional authentication data
if key in IGNORED_CONTEXT_KEYS:
continue
...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the detailed review @whummer 🙏🙂 Doing the restructure and pushing it back again.
Regarding backticks: My bad, I mistakenly added it in the defaults.py
of aws_encryption_sdk
and therefore in models.py
as well, I am correcting this also.
8797e4f
to
0c0e4a6
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for addressing the comments. LGTM! 👍
Issue:
test_encrypt_via_aws_encryption_sdk
in localstack-ext repo invokesaws_encryption_sdk
which internally updates encryption context param value by the method_generate_signing_key_and_update_encryption_context
which is done after the actual encryption. Now, when we decrypt this cipher text, we have an additional reserved key-value pair ofencryption_context
by the nameaws-crypto-public-key
which was missing during encryption.The PR removes the check of any such reserved key-value pair during decryption as no such value is passed for authentication in encryption.