GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — Add support for recipient for KMS Decrypt by mboorstin-circle · Pull Request #13343 · localstack/localstack
This repository was archived by the owner on Mar 23, 2026. It is now read-only.
Conversation
|
|
All contributors have signed the CLA ✍️ ✅ |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Welcome to LocalStack! Thanks for raising your first Pull Request and landing in your contributions. Our team will reach out with any reviews or feedbacks that we have shortly. We recommend joining our Slack Community and share your PR on the #community channel to share your contributions with us. Please make sure you are following our contributing guidelines and our Code of Conduct.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
(I know that I need to sign the CLA; I just need to consult with my employer's legal department before doing so). |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
I have read the CLA Document and I hereby sign the CLA |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
recheck |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
recheck |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@sannya-singal @alexrashed @bentsku (tagging some of the automatically selected reviewers) I believe this should be ready for review. Thank you in advance! |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Awesome! Thanks for adding this functionality 🚀 The implementation looks good and the approach of gracefully handling invalid attestations is really great. I just have a few suggestions to improve it, please let me know if you require some help or have questions.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
| from Crypto.Cipher import AES, PKCS1_OAEP | ||
| from Crypto.Hash import SHA256 | ||
| from Crypto.PublicKey import RSA as CryptoRSA |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
In my opinion we could eliminate the use of Crypto here and use dependencies from cryptography.hazmat.primitives.
So something like:
encrypted_session_key = recipient_pubkey.encrypt(
session_key,
padding.OAEP(
mgf=padding.MGF1(algorithm=hashes.SHA256()),
algorithm=hashes.SHA256(),
label=None
)
)
cipher = Cipher(algorithms.AES(session_key), modes.CBC(iv), backend=default_backend())
encryptor = cipher.encryptor()
padder = sym_padding.PKCS7(algorithms.AES.block_size).padder()
padded_plaintext = padder.update(plaintext) + padder.finalize()
encrypted_content = encryptor.update(padded_plaintext) + encryptor.finalize()
Please let me know if you would like to know more context here.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Yes, thank you! This all makes sense. I went down this path because Hazmat's one-shot PKCS7 only supports RSA-PKCS1.5 rather than the RSA-OAEP that AWS provides, but yes, I can still do the individual encryption operations with Hazmat and then just use the asn1crypto library to build them into a PKCS7 envelope. So I've updated things to follow your example and remove the PyCryptoDome usage here and in the test file. Let me know if things now look better. Thank you!
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
| return decrypted | ||
|
|
||
|
|
||
| def pkcs7_envelope_encrypt(plaintext: bytes, recipient_pubkey) -> bytes: |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Parameter recipient_pubkey lacks type hint here, can you please add it?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Yes, added.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| from Crypto.Cipher import AES, PKCS1_OAEP | ||
| from Crypto.Hash import SHA256 | ||
| from Crypto.PublicKey import RSA as CryptoRSA | ||
| from Crypto.Util.Padding import unpad as crypto_unpad |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Same as suggested in the crypto.py most of this can be done with cryptography library.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Yes, thank you! I've updated it in the same way of still using as1ncrypto to deserialize the envelope, but then using the normal Hazmat methods to do the actual decryption. Thanks!
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| assert base64.b64decode(plaintext) == message | ||
|
|
||
| @markers.aws.only_localstack | ||
| def test_decrypt_recipient_invalid_attestation(self, kms_create_key, snapshot, aws_client): |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
We can safely remove snapshot fixture as its not being used in this test.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Fixed, thanks.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| snapshot.match("decrypt_response_with_invalid_ciphertext", e.value.response) | ||
|
|
||
| @markers.aws.only_localstack | ||
| def test_decrypt_recipient(self, kms_create_key, snapshot, aws_client): |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
We can safely remove snapshot fixture as its not being used in this test.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Fixed, thanks.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Thanks @sannya-singal ! All of your comments make sense and I have updated the diff appropriately. As you requested, I changed back to using |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Thanks @mboorstin-circle for addressing all the comments so quickly 🚀 🎉 Changes LGTM, tagging @k-a-il for a quick sanity check on the dependency file changes.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Sounds great. Thanks @sannya-singal and (in advance) @k-a-il ! |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
The PR looks great, thank you for adding this new functionality to KMS @mboorstin-circle 🚀
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Great, thanks @k-a-il ! I do not have merge permissions on this repository, so can you or @sannya-singal please merge this PR for me? Thank you! |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
All merged! Thanks once more for your contribution 🎉 |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.