-
Notifications
You must be signed in to change notification settings - Fork 86
feat: immutable cryptographic materials (for keyrings) #231
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
Merged
Merged
Changes from 11 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
8e7a636
feat: change keyring materials modifiers to immutable constructors
mattsb42-aws b88b8aa
feat: add key_name parameter and key_namespace accessor to MasterKeyInfo
mattsb42-aws 4a18fbd
feat: adopt immutable materials for KMS keyring
mattsb42-aws c6fb4e7
feat: adopt immutable materials for multi-keyring
mattsb42-aws 7f9d74a
fix: revise test helpers to use key IDs that are not used in tests
mattsb42-aws 030c736
feat: add key_name parameter and key_namespace accessor to MasterKeyI…
mattsb42-aws 54bcdb3
feat: fix raw keyrings and move to immutable materials
mattsb42-aws 8de2b7a
fix: fix incorrectly placed test assertions
mattsb42-aws c3844dd
chore: clean up linting
mattsb42-aws d9e3a0d
docs: update src/aws_encryption_sdk/keyrings/raw.py
mattsb42-aws 2d3f9a3
chore: remove unnecessary copies on encrypt and avoid overwriting poi…
mattsb42-aws 8a31fa0
chore: finish copy cleanup
mattsb42-aws File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
# Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
"""Resources required for Multi Keyrings.""" | ||
import copy | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Needed? |
||
import itertools | ||
|
||
import attr | ||
|
@@ -67,20 +68,21 @@ def on_encrypt(self, encryption_materials): | |
"and encryption materials do not already contain a plaintext data key." | ||
) | ||
|
||
new_materials = encryption_materials | ||
|
||
# Call on_encrypt on the generator keyring if it is provided | ||
if self.generator is not None: | ||
|
||
encryption_materials = self.generator.on_encrypt(encryption_materials=encryption_materials) | ||
new_materials = self.generator.on_encrypt(encryption_materials=new_materials) | ||
|
||
# Check if data key is generated | ||
if encryption_materials.data_encryption_key is None: | ||
if new_materials.data_encryption_key is None: | ||
raise GenerateKeyError("Unable to generate data encryption key.") | ||
|
||
# Call on_encrypt on all other keyrings | ||
for keyring in self.children: | ||
encryption_materials = keyring.on_encrypt(encryption_materials=encryption_materials) | ||
new_materials = keyring.on_encrypt(encryption_materials=new_materials) | ||
|
||
return encryption_materials | ||
return new_materials | ||
|
||
def on_decrypt(self, decryption_materials, encrypted_data_keys): | ||
# type: (DecryptionMaterials, Iterable[EncryptedDataKey]) -> DecryptionMaterials | ||
|
@@ -92,10 +94,13 @@ def on_decrypt(self, decryption_materials, encrypted_data_keys): | |
:rtype: DecryptionMaterials | ||
""" | ||
# Call on_decrypt on all keyrings till decryption is successful | ||
new_materials = decryption_materials | ||
for keyring in self._decryption_keyrings: | ||
if decryption_materials.data_encryption_key is not None: | ||
return decryption_materials | ||
decryption_materials = keyring.on_decrypt( | ||
decryption_materials=decryption_materials, encrypted_data_keys=encrypted_data_keys | ||
if new_materials.data_encryption_key is not None: | ||
return new_materials | ||
|
||
new_materials = keyring.on_decrypt( | ||
decryption_materials=new_materials, encrypted_data_keys=encrypted_data_keys | ||
) | ||
return decryption_materials | ||
|
||
return new_materials |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Do you still need this?
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.
Nope! That'll be why CI is failing. :)