-
Notifications
You must be signed in to change notification settings - Fork 86
Multi keyrings #166
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
Multi keyrings #166
Changes from 45 commits
Commits
Show all changes
64 commits
Select commit
Hold shift + click to select a range
0d29631
Adding Keyring API
mmegs-amzn 237a2af
Added docstring to public class
mmegs-amzn 9bbdf83
Delete __init__.py
MeghaShetty 1a14a3b
Delete raw_keyring.py
MeghaShetty c1a1c77
Edited docstring
mmegs-amzn 66b348f
Edited docstring again
mmegs-amzn 4a0a1c6
Changes in docstring statements
mmegs-amzn 5f6fcb9
Docstring changes
mmegs-amzn 9d8d964
Changes in docstring
mmegs-amzn 83ccdd3
Raw keyring initial
mmegs-amzn aed1ed7
Raw keyring encrypt commit
mmegs-amzn dc9352c
Encrypt functions for Raw RSA and AES
mmegs-amzn b9c22b9
Raw RSA and AES initial
mmegs-amzn 369a744
raw keyrings first commit
mmegs-amzn a8d3019
Multi keyring first commit
mmegs-amzn 366a189
Changes in the base file
mmegs-amzn 05fa2b2
Temporary changes in multiple files
mmegs-amzn b37028c
Committing initial code
mmegs-amzn 5d6cbe4
Deleted raw aes test
mmegs-amzn 1c07dde
Multi Keyrings
mmegs-amzn 8932c1c
Updating base API and raw keyrings
mmegs-amzn 5ea0333
Corrected tox errors
mmegs-amzn 529689a
Added typehints
mmegs-amzn afdeb6c
Updated raw keyrings
mmegs-amzn 9038583
Updated raw keyrings
mmegs-amzn f7c951b
Changes in error conditions for multi keyrings
mmegs-amzn 00d7ebe
Merge branch 'keyring' of github.com:aws/aws-encryption-sdk-python in…
mmegs-amzn 21a1290
Made all suggested changes in multi-keyrings
mmegs-amzn d7ca059
Corrected tox errors
mmegs-amzn 33d95e5
Added docstring to __attrs_post_init__
mmegs-amzn 8761985
Changed variable name neither_generator_nor_children_defined to neith…
mmegs-amzn 606c8f5
Changed raw keyrings
mmegs-amzn 89e1c82
Corrected tox errors
mmegs-amzn 0813372
Updated raw keyrings
mmegs-amzn db696d6
Updated raw keyrings and functional test for multi keyrings
mmegs-amzn de03efa
Functional tests for multi-keyrings work
mmegs-amzn afa9ebc
Autoformat errors corrected and changed Exception to BaseException to…
mmegs-amzn a1cdb25
Added pylint disable broad except to raw keyrings and added multi par…
mmegs-amzn 2469b3a
Removed duplicate import statements
mmegs-amzn 80d58d4
Changes in functional test for multi keyrings according to change in …
mmegs-amzn b4a34d7
Changed RSA key structure to RSAPublicKey/RSAPrivateKey and functiona…
mmegs-amzn caf799e
Removed unwanted commented lines from test
mmegs-amzn b93d4ed
Pylint errors
mmegs-amzn aa9145f
More pylint errors
mmegs-amzn 7645d79
Made suggested changes in multi keyring
mmegs-amzn 83d07a6
Multi keyring unit tests
mmegs-amzn f0dd30a
Optimized loop for decryption keyring
mmegs-amzn 5bc2384
Unit tests for multi keyrings and added sample encryption materials a…
mmegs-amzn b1c9aaa
Multi keyrings unit tests
mmegs-amzn 42f92c1
Making changes in tests and API
mmegs-amzn e89c5c7
Almost all unit tests done
mmegs-amzn 65c749d
Unit tests for multi keyrings
mmegs-amzn 317e0e5
Unit tests for multi keyrings
mmegs-amzn c8d3b32
Unit tests for multi-keyrings working except the one to check if no f…
mmegs-amzn b9dbcad
Made changes in raw keyrings to match the latest version
mmegs-amzn 27c8df0
Removed unused imports
mmegs-amzn 3c00e12
Made suggested changes
mmegs-amzn 901a8b2
Removed unused imports
mmegs-amzn 91bddc7
Resolved formatting errors
mmegs-amzn dc0b508
Made suggested changes - partial
mmegs-amzn 66a5525
Made all suggested changes
mmegs-amzn 324b8e7
Merge branch 'keyring' into multi-keyrings
mattsb42-aws 7df11d4
Merge branch 'keyring' into multi-keyrings
mattsb42-aws ca9b904
apply autoformatting x_x
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
six | ||
boto3>=1.4.4 | ||
cryptography>=1.8.1 | ||
attrs>=19.1.0 | ||
|
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"). You | ||
# may not use this file except in compliance with the License. A copy of | ||
# the License is located at | ||
# | ||
# http://aws.amazon.com/apache2.0/ | ||
# | ||
# or in the "license" file accompanying this file. This file is | ||
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF | ||
# ANY KIND, either express or implied. See the License for the specific | ||
# language governing permissions and limitations under the License. | ||
"""All provided Keyrings.""" |
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 |
---|---|---|
@@ -0,0 +1,107 @@ | ||
# Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"). You | ||
# may not use this file except in compliance with the License. A copy of | ||
# the License is located at | ||
# | ||
# http://aws.amazon.com/apache2.0/ | ||
# | ||
# or in the "license" file accompanying this file. This file is | ||
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF | ||
# ANY KIND, either express or implied. See the License for the specific | ||
# language governing permissions and limitations under the License. | ||
"""Resources required for Multi Keyrings.""" | ||
import itertools | ||
|
||
import attr | ||
from attr.validators import deep_iterable, instance_of, optional | ||
|
||
from aws_encryption_sdk.exceptions import EncryptKeyError, GenerateKeyError | ||
from aws_encryption_sdk.keyring.base import DecryptionMaterials, EncryptedDataKey, EncryptionMaterials, Keyring | ||
|
||
try: # Python 3.5.0 and 3.5.1 have incompatible typing modules | ||
from typing import Iterable # noqa pylint: disable=unused-import | ||
except ImportError: # pragma: no cover | ||
# We only actually need these imports when running the mypy checks | ||
pass | ||
|
||
|
||
@attr.s | ||
class MultiKeyring(Keyring): | ||
"""Public class for Multi Keyring. | ||
|
||
:param generator: Generator keyring used to generate data encryption key (optional) | ||
:type generator: Keyring | ||
:param list children: List of keyrings used to encrypt the data encryption key (optional) | ||
:raises EncryptKeyError: if encryption of data key fails for any reason | ||
""" | ||
|
||
children = attr.ib( | ||
default=attr.Factory(tuple), validator=optional(deep_iterable(member_validator=instance_of(Keyring))) | ||
) | ||
generator = attr.ib(default=None, validator=optional(instance_of(Keyring))) | ||
|
||
def __attrs_post_init__(self): | ||
# type: () -> None | ||
"""Prepares initial values not handled by attrs.""" | ||
neither_generator_nor_children = self.generator is None and not self.children | ||
if neither_generator_nor_children: | ||
raise TypeError("At least one of generator or children must be provided") | ||
|
||
_generator = (self.generator,) if self.generator is not None else () | ||
self._decryption_keyrings = itertools.chain(_generator, self.children) | ||
|
||
def on_encrypt(self, encryption_materials): | ||
# type: (EncryptionMaterials) -> EncryptionMaterials | ||
"""Generate a data key using generator keyring | ||
and encrypt it using any available wrapping key in any child keyring. | ||
|
||
:param encryption_materials: Encryption materials for keyring to modify. | ||
:type encryption_materials: aws_encryption_sdk.materials_managers.EncryptionMaterials | ||
:returns: Optionally modified encryption materials. | ||
:rtype: aws_encryption_sdk.materials_managers.EncryptionMaterials | ||
:raises EncryptKeyError: if unable to encrypt data key. | ||
""" | ||
# Check if generator keyring is not provided and data key is not generated | ||
if self.generator is None and not encryption_materials.data_encryption_key: | ||
raise EncryptKeyError( | ||
"Generator keyring not provided " | ||
"and encryption materials do not already contain a plaintext data key." | ||
) | ||
|
||
# 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) | ||
|
||
# Check if data key is generated | ||
if not encryption_materials.data_encryption_key: | ||
mattsb42-aws marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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) | ||
|
||
return encryption_materials | ||
|
||
def on_decrypt(self, decryption_materials, encrypted_data_keys): | ||
# type: (DecryptionMaterials, Iterable[EncryptedDataKey]) -> DecryptionMaterials | ||
"""Attempt to decrypt the encrypted data keys. | ||
|
||
:param decryption_materials: Decryption materials for keyring to modify. | ||
:type decryption_materials: aws_encryption_sdk.materials_managers.DecryptionMaterials | ||
:param encrypted_data_keys: List of encrypted data keys. | ||
:type: List of `aws_encryption_sdk.structures.EncryptedDataKey` | ||
:returns: Optionally modified decryption materials. | ||
:rtype: aws_encryption_sdk.materials_managers.DecryptionMaterials | ||
""" | ||
mattsb42-aws marked this conversation as resolved.
Show resolved
Hide resolved
|
||
# Check if plaintext data key exists | ||
if decryption_materials.data_encryption_key: | ||
return decryption_materials | ||
|
||
# Call on_decrypt on all keyrings till decryption is successful | ||
for keyring in self._decryption_keyrings: | ||
decryption_materials = keyring.on_decrypt(decryption_materials, encrypted_data_keys) | ||
if decryption_materials.data_encryption_key: | ||
mattsb42-aws marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return decryption_materials | ||
|
||
return decryption_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.
Uh oh!
There was an error while loading. Please reload this page.