Skip to content

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 64 commits into from
Aug 3, 2019
Merged
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
0d29631
Adding Keyring API
mmegs-amzn Jun 18, 2019
237a2af
Added docstring to public class
mmegs-amzn Jun 18, 2019
9bbdf83
Delete __init__.py
MeghaShetty Jun 18, 2019
1a14a3b
Delete raw_keyring.py
MeghaShetty Jun 18, 2019
c1a1c77
Edited docstring
mmegs-amzn Jun 18, 2019
66b348f
Edited docstring again
mmegs-amzn Jun 18, 2019
4a0a1c6
Changes in docstring statements
mmegs-amzn Jun 19, 2019
5f6fcb9
Docstring changes
mmegs-amzn Jun 19, 2019
9d8d964
Changes in docstring
mmegs-amzn Jun 20, 2019
83ccdd3
Raw keyring initial
mmegs-amzn Jun 20, 2019
aed1ed7
Raw keyring encrypt commit
mmegs-amzn Jun 20, 2019
dc9352c
Encrypt functions for Raw RSA and AES
mmegs-amzn Jun 20, 2019
b9c22b9
Raw RSA and AES initial
mmegs-amzn Jun 20, 2019
369a744
raw keyrings first commit
mmegs-amzn Jun 21, 2019
a8d3019
Multi keyring first commit
mmegs-amzn Jun 24, 2019
366a189
Changes in the base file
mmegs-amzn Jun 24, 2019
05fa2b2
Temporary changes in multiple files
mmegs-amzn Jun 27, 2019
b37028c
Committing initial code
mmegs-amzn Jun 27, 2019
5d6cbe4
Deleted raw aes test
mmegs-amzn Jun 28, 2019
1c07dde
Multi Keyrings
mmegs-amzn Jul 1, 2019
8932c1c
Updating base API and raw keyrings
mmegs-amzn Jul 1, 2019
5ea0333
Corrected tox errors
mmegs-amzn Jul 1, 2019
529689a
Added typehints
mmegs-amzn Jul 2, 2019
afdeb6c
Updated raw keyrings
mmegs-amzn Jul 2, 2019
9038583
Updated raw keyrings
mmegs-amzn Jul 3, 2019
f7c951b
Changes in error conditions for multi keyrings
mmegs-amzn Jul 11, 2019
00d7ebe
Merge branch 'keyring' of github.com:aws/aws-encryption-sdk-python in…
mmegs-amzn Jul 12, 2019
21a1290
Made all suggested changes in multi-keyrings
mmegs-amzn Jul 13, 2019
d7ca059
Corrected tox errors
mmegs-amzn Jul 14, 2019
33d95e5
Added docstring to __attrs_post_init__
mmegs-amzn Jul 14, 2019
8761985
Changed variable name neither_generator_nor_children_defined to neith…
mmegs-amzn Jul 15, 2019
606c8f5
Changed raw keyrings
mmegs-amzn Jul 15, 2019
89e1c82
Corrected tox errors
mmegs-amzn Jul 15, 2019
0813372
Updated raw keyrings
mmegs-amzn Jul 15, 2019
db696d6
Updated raw keyrings and functional test for multi keyrings
mmegs-amzn Jul 16, 2019
de03efa
Functional tests for multi-keyrings work
mmegs-amzn Jul 16, 2019
afa9ebc
Autoformat errors corrected and changed Exception to BaseException to…
mmegs-amzn Jul 16, 2019
a1cdb25
Added pylint disable broad except to raw keyrings and added multi par…
mmegs-amzn Jul 17, 2019
2469b3a
Removed duplicate import statements
mmegs-amzn Jul 17, 2019
80d58d4
Changes in functional test for multi keyrings according to change in …
mmegs-amzn Jul 18, 2019
b4a34d7
Changed RSA key structure to RSAPublicKey/RSAPrivateKey and functiona…
mmegs-amzn Jul 18, 2019
caf799e
Removed unwanted commented lines from test
mmegs-amzn Jul 18, 2019
b93d4ed
Pylint errors
mmegs-amzn Jul 18, 2019
aa9145f
More pylint errors
mmegs-amzn Jul 18, 2019
7645d79
Made suggested changes in multi keyring
mmegs-amzn Jul 19, 2019
83d07a6
Multi keyring unit tests
mmegs-amzn Jul 19, 2019
f0dd30a
Optimized loop for decryption keyring
mmegs-amzn Jul 22, 2019
5bc2384
Unit tests for multi keyrings and added sample encryption materials a…
mmegs-amzn Jul 23, 2019
b1c9aaa
Multi keyrings unit tests
mmegs-amzn Jul 23, 2019
42f92c1
Making changes in tests and API
mmegs-amzn Jul 26, 2019
e89c5c7
Almost all unit tests done
mmegs-amzn Jul 26, 2019
65c749d
Unit tests for multi keyrings
mmegs-amzn Jul 27, 2019
317e0e5
Unit tests for multi keyrings
mmegs-amzn Jul 27, 2019
c8d3b32
Unit tests for multi-keyrings working except the one to check if no f…
mmegs-amzn Jul 28, 2019
b9dbcad
Made changes in raw keyrings to match the latest version
mmegs-amzn Jul 29, 2019
27c8df0
Removed unused imports
mmegs-amzn Jul 29, 2019
3c00e12
Made suggested changes
mmegs-amzn Aug 1, 2019
901a8b2
Removed unused imports
mmegs-amzn Aug 1, 2019
91bddc7
Resolved formatting errors
mmegs-amzn Aug 1, 2019
dc0b508
Made suggested changes - partial
mmegs-amzn Aug 1, 2019
66a5525
Made all suggested changes
mmegs-amzn Aug 2, 2019
324b8e7
Merge branch 'keyring' into multi-keyrings
mattsb42-aws Aug 2, 2019
7df11d4
Merge branch 'keyring' into multi-keyrings
mattsb42-aws Aug 2, 2019
ca9b904
apply autoformatting x_x
mattsb42-aws Aug 2, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
six
boto3>=1.4.4
cryptography>=1.8.1
attrs>=17.4.0
Expand Down
13 changes: 13 additions & 0 deletions src/aws_encryption_sdk/keyring/__init__.py
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."""
54 changes: 54 additions & 0 deletions src/aws_encryption_sdk/keyring/base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# 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.
"""Base class interface for Keyrings."""
from aws_encryption_sdk.materials_managers import DecryptionMaterials, EncryptionMaterials
from aws_encryption_sdk.structures import EncryptedDataKey

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


class Keyring(object):
"""Parent interface for Keyring classes.

.. versionadded:: 1.5.0
"""

def on_encrypt(self, encryption_materials):
# type: (EncryptionMaterials) -> EncryptionMaterials
"""Generate a data key if not present and encrypt it using any available wrapping key.

:param encryption_materials: Encryption materials for the 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 NotImplementedError: if method is not implemented
"""
raise NotImplementedError("Keyring does not implement on_encrypt function")

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 the keyring to modify.
:type decryption_materials: aws_encryption_sdk.materials_managers.DecryptionMaterials
:param encrypted_data_keys: List of encrypted data keys.
:type: Iterable of :class:`aws_encryption_sdk.structures.EncryptedDataKey`
:returns: Optionally modified decryption materials.
:rtype: aws_encryption_sdk.materials_managers.DecryptionMaterials
:raises NotImplementedError: if method is not implemented
"""
raise NotImplementedError("Keyring does not implement on_decrypt function")
92 changes: 92 additions & 0 deletions src/aws_encryption_sdk/keyring/multi_keyring.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
# 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 attr

from aws_encryption_sdk.exceptions import EncryptKeyError
from aws_encryption_sdk.keyring.base import 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
:type generator: Keyring
:param list children: List of keyrings used to encrypt the data encryption key
:raises EncryptKeyError: if encryption of data key fails for any reason
"""

generator = attr.ib(validator=attr.validators.instance_of(Keyring))
children = attr.ib(validator=attr.validators.instance_of(list))

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 not self.generator and not encryption_materials.data_encryption_key:
raise EncryptKeyError("Generator keyring not provided.")

# Check if generator keyring is provided and data key is generated
if self.generator and encryption_materials.data_encryption_key:
raise EncryptKeyError("Data encryption key already exists.")

# Call on_encrypt on the generator keyring
encryption_materials = self.generator.on_encrypt(encryption_materials)

# Check if data key is generated
if not encryption_materials.data_encryption_key:
raise EncryptKeyError("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
"""
# Check if plaintext data key exists
if decryption_materials.data_key:
return decryption_materials

# Call on_decrypt on all keyrings till decryption is successful
for keyring in self.children:
decryption_materials = keyring.on_decrypt(decryption_materials, encrypted_data_keys)
if decryption_materials.data_key:
return decryption_materials

return decryption_materials
Loading