-
Notifications
You must be signed in to change notification settings - Fork 86
Base keyrings #176
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
Base keyrings #176
Changes from 103 commits
Commits
Show all changes
113 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 745c9ed
Changes in raw keyrings according to new keyring materials
mmegs-amzn bb163bc
Updated with autoformat
mmegs-amzn 27fe8d9
Modified base
mmegs-amzn e8286ac
Corrected tox and flake errors
mmegs-amzn eef26e7
Docstring error correction
mmegs-amzn 900a064
Added docstrings and corrected errors
mmegs-amzn c500970
Some more changes in docstrings
mmegs-amzn 8a00e15
Updating base API
mmegs-amzn 250f554
Made all suggested changes
mmegs-amzn d8a8389
Corrected tox and flake8 errors
mmegs-amzn 8f9f737
Minor change in raw-keyrings
mmegs-amzn 9cd81ea
Adding Keyring API
mmegs-amzn e3d0757
Added docstring to public class
mmegs-amzn fcb03c2
Delete __init__.py
MeghaShetty ae78331
Delete raw_keyring.py
MeghaShetty f668ca4
Edited docstring
mmegs-amzn c06b1fa
Edited docstring again
mmegs-amzn 1e2a672
Changes in docstring statements
mmegs-amzn 82feb00
Docstring changes
mmegs-amzn 11f9ce6
Changes in docstring
mmegs-amzn 7a345a5
Raw keyring initial
mmegs-amzn 6ef9ea7
Raw keyring encrypt commit
mmegs-amzn 6576731
Encrypt functions for Raw RSA and AES
mmegs-amzn 5a87c0e
Raw RSA and AES initial
mmegs-amzn dd01e6b
bump attrs to 19.1.0
mattsb42-aws 82429fe
add keyring trace and integrate into updated encrytion/decryption mat…
mattsb42-aws 0dc48a2
s/KeyRing/Keyring/g
mattsb42-aws ea0b09d
align cryptographic materials and add write-only interface
mattsb42-aws 9b3d4e2
encrypted_data_keys must only contain EncryptedDataKey
mattsb42-aws ac67a6f
fix test to be Python 2 compatible
mattsb42-aws 0921eff
Changes in raw keyrings according to new keyring materials
mmegs-amzn 8399fea
Updated with autoformat
mmegs-amzn 38c756b
Modified base
mmegs-amzn 5005cfb
data encryption key must be set before encrypted data keys can be add…
mattsb42-aws 242a3a3
Corrected tox and flake errors
mmegs-amzn 2672567
Docstring error correction
mmegs-amzn 2696183
Added docstrings and corrected errors
mmegs-amzn f1d1977
Some more changes in docstrings
mmegs-amzn f08239c
Updating base API
mmegs-amzn 881cf5e
add signing/verification key checks to Encryption/DecryptionMaterials
mattsb42-aws 5769efa
DecryptionMaterials.algorithm must be set before DecryptionMaterials.…
mattsb42-aws 00a7678
update materials docs and typehints
mattsb42-aws 36edf5b
Made all suggested changes
mmegs-amzn 98cf791
EncryptionMaterials must not be initialized with encrypted_data_keys …
mattsb42-aws e03f38b
add is_complete properties to EncryptionMaterials and DecryptionMater…
mattsb42-aws f99ac6c
Corrected tox and flake8 errors
mmegs-amzn b928fd2
Minor change in raw-keyrings
mmegs-amzn e92db76
change KeyringTraceFlag values to bitshifted ints to match other impl…
mattsb42-aws bcd4cfe
normalize EncryptionMaterials._encrypted_data_keys to list and encryp…
mattsb42-aws be3a391
temporarily pin pydocstyle at <4.0.0 to avoid issue breaking flake8-d…
mattsb42-aws 402af2c
temporarily cap pydocstyle at <4.0.0 for decrypt oracle
mattsb42-aws be4f74c
Changes to keyring trace in raw keyrings
mmegs-amzn f165e22
Merge branch 'keyring' of github.com:aws/aws-encryption-sdk-python in…
mmegs-amzn b921715
Changes to raw keyrings after rebase
mmegs-amzn c01fb90
Adding test files
mmegs-amzn 85a0149
Adding tests
mmegs-amzn af239f6
Changed data encryption key type to RawDataKey
mmegs-amzn 1a49427
Added keyring trace to pytest encryption materials
mmegs-amzn ec1d8b5
Changed value of keyring_trace.wrapping_key
mmegs-amzn 5ff39d6
Few changes to match new API
mmegs-amzn 64298a7
Tox errors
mmegs-amzn cc5aa44
Functional tests pass
mmegs-amzn 7d896d1
Formatting errors corrected and functional tests pass
mmegs-amzn 3eb4536
Corrected too broad exception error and deleted empty return statemen…
mmegs-amzn b1ad3ed
Changed Exeception to BaseException to solve broad exception error
mmegs-amzn 03aeae3
Added suppress broad exception
mmegs-amzn 2a248f5
Added pylint disable broad exception
mmegs-amzn 92f419c
Changed wrapping keys for RSA keyrings from WrappingKey to cryptograp…
mmegs-amzn 66b56b7
Fixed tox errors
mmegs-amzn 0295db5
More tox errors
mmegs-amzn 4adec20
Moved code for generation of plaintext to be before the check for key…
mmegs-amzn 22243dc
Tox errors
mmegs-amzn 07d05f7
Added metaclass to base API and unit tests for base API
mmegs-amzn 6df10d5
Changed metaclass to six.add_metaclass in base API
mmegs-amzn 8e47bad
Fixed pylint errors
mmegs-amzn 4aae643
Fixed more pylint errors
mmegs-amzn ede165a
Removed RawAESKeyring instance
mmegs-amzn 39dbfd3
Changed on_encrypt_helper to generate_data_key and removed on_decrypt…
mmegs-amzn 61e8fe5
Changed docstring for generate_data_key
mmegs-amzn e61f4a2
Changed decryption_materials.data_key to decryption_materials.data_en…
mmegs-amzn 89f8a2c
Fixed pylint errors
mmegs-amzn fbf351f
Changed raw keyrings to have class methods for PEM and DER encoded keys
mmegs-amzn fb8b7b8
Unit tests for raw keyrings
mmegs-amzn 41dd140
Changes for PEM encoding
mmegs-amzn b350207
Changed base API to remove metaclass and modified tests
mmegs-amzn 9de5b16
Delete raw_keyring.py
MeghaShetty 16d433d
Delete test_f_keyring_raw_aes.py
MeghaShetty 7c021da
Delete test_f_keyring_raw_rsa.py
MeghaShetty 115f804
Delete test_keyring_raw_aes.py
MeghaShetty 3f9a3c0
Delete test_keyring_raw_rsa.py
MeghaShetty d2bb774
Suggested changes
mmegs-amzn 3620b58
Made suggested changes to base API and tests
mmegs-amzn 115254b
Made suggested changes to base API tests
mmegs-amzn 8943bf2
Merge branch 'base-keyrings' of github.com:MeghaShetty/aws-encryption…
mmegs-amzn b37933c
Ignore commit
mmegs-amzn a7eb7e2
Corrected tox and pylint errors in base API unit tests
mmegs-amzn 5a9d2bb
Removed try except for Iterable
mmegs-amzn 0767416
Removed try except for Iterable from test_utils
mmegs-amzn 66d96c2
Added try except for Iterable in base API
mmegs-amzn 28fdbd8
Resolved isort errors
mmegs-amzn 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 |
---|---|---|
@@ -0,0 +1,78 @@ | ||
# Copyright 2019 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. | ||
"""Functional tests for Raw AES keyring encryption decryption path.""" | ||
|
||
import pytest | ||
|
||
from aws_encryption_sdk.identifiers import Algorithm, WrappingAlgorithm | ||
from aws_encryption_sdk.keyring.raw_keyring import RawAESKeyring | ||
from aws_encryption_sdk.materials_managers import DecryptionMaterials, EncryptionMaterials | ||
|
||
pytestmark = [pytest.mark.functional, pytest.mark.local] | ||
|
||
_ENCRYPTION_CONTEXT = {"key_a": "value_a", "key_b": "value_b", "key_c": "value_c"} | ||
_PROVIDER_ID = "Random Raw Keys" | ||
_KEY_ID = b"5325b043-5843-4629-869c-64794af77ada" | ||
_WRAPPING_KEY = b"12345678901234567890123456789012" | ||
_SIGNING_KEY = b"aws-crypto-public-key" | ||
|
||
_ENCRYPTION_MATERIALS = EncryptionMaterials( | ||
algorithm=Algorithm.AES_256_GCM_IV12_TAG16_HKDF_SHA384_ECDSA_P384, | ||
encryption_context=_ENCRYPTION_CONTEXT, | ||
signing_key=_SIGNING_KEY, | ||
) | ||
|
||
|
||
def sample_aes_encryption_decryption(): | ||
|
||
# Initializing attributes | ||
key_namespace = _PROVIDER_ID | ||
key_name = _KEY_ID | ||
_wrapping_algorithm = WrappingAlgorithm.AES_256_GCM_IV12_TAG16_NO_PADDING | ||
|
||
# Creating an instance of a raw AES keyring | ||
fake_raw_aes_keyring = RawAESKeyring( | ||
key_namespace=key_namespace, | ||
key_name=key_name, | ||
wrapping_key=_WRAPPING_KEY, | ||
wrapping_algorithm=_wrapping_algorithm, | ||
) | ||
|
||
# Call on_encrypt function for the keyring | ||
encryption_materials = fake_raw_aes_keyring.on_encrypt(encryption_materials=_ENCRYPTION_MATERIALS) | ||
|
||
print("PLAINTEXT DATA KEY") | ||
print(encryption_materials.data_encryption_key.data_key) | ||
|
||
print("ENCRYPTED DATA KEY") | ||
print(encryption_materials.encrypted_data_keys) | ||
|
||
# Generate decryption materials | ||
decryption_materials = DecryptionMaterials( | ||
algorithm=Algorithm.AES_256_GCM_IV12_TAG16_HKDF_SHA384_ECDSA_P384, verification_key=b"ex_verification_key" | ||
) | ||
|
||
# Call on_decrypt function for the keyring | ||
decryption_materials = fake_raw_aes_keyring.on_decrypt( | ||
decryption_materials=decryption_materials, encrypted_data_keys=encryption_materials.encrypted_data_keys | ||
) | ||
|
||
print("DECRYPTED DATA KEY") | ||
print(decryption_materials.data_encryption_key.data_key) | ||
|
||
if decryption_materials.data_encryption_key: | ||
# Check if the data keys match | ||
assert encryption_materials.data_encryption_key == decryption_materials.data_encryption_key | ||
|
||
|
||
sample_aes_encryption_decryption() |
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
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,73 @@ | ||
# Copyright 2019 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. | ||
"""Unit tests for base keyring.""" | ||
|
||
import pytest | ||
import six | ||
|
||
from aws_encryption_sdk.identifiers import Algorithm | ||
from aws_encryption_sdk.keyring.base import EncryptedDataKey, Keyring | ||
from aws_encryption_sdk.materials_managers import DecryptionMaterials, EncryptionMaterials | ||
from aws_encryption_sdk.structures import MasterKeyInfo | ||
|
||
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 | ||
|
||
pytestmark = [pytest.mark.unit, pytest.mark.local] | ||
|
||
_encryption_materials = EncryptionMaterials( | ||
algorithm=Algorithm.AES_256_GCM_IV12_TAG16_HKDF_SHA384_ECDSA_P384, | ||
encryption_context={"encryption": "context", "values": "here"}, | ||
signing_key=b"aws-crypto-public-key", | ||
) | ||
|
||
_decryption_materials = DecryptionMaterials( | ||
algorithm=Algorithm.AES_256_GCM_IV12_TAG16_HKDF_SHA384_ECDSA_P384, verification_key=b"ex_verification_key" | ||
) | ||
|
||
_encrypted_data_keys = [ | ||
EncryptedDataKey( | ||
key_provider=MasterKeyInfo(provider_id="Random Raw Keys", key_info=b"5325b043-5843-4629-869c-64794af77ada"), | ||
encrypted_data_key=six.b( | ||
"\n \x8b\xc6\xfd\x91\xc7\xd5\xdc+S\x15n\xd9P\x99n\x1d\xb2\xdd\x15\xeaW" | ||
"\xc3\x13k2\xf6\x02\xd0\x0f\x85\xec\x9e\x12\xa7\x01\x01\x01\x01\x00x" | ||
"\x8b\xc6\xfd\x91\xc7\xd5\xdc+S\x15n\xd9P\x99n\x1d\xb2\xdd\x15\xeaW" | ||
"\xc3\x13k2\xf6\x02\xd0\x0f\x85\xec\x9e\x00\x00\x00~0|\x06\t*\x86H" | ||
"\x86\xf7\r\x01\x07\x06\xa0o0m\x02\x01\x000h\x06\t*\x86H\x86\xf7\r" | ||
"\x01\x07\x010\x1e\x06\t`\x86H\x01e\x03\x04\x01.0\x11\x04\x0c\xc9rP" | ||
"\xa1\x08t6{\xf2\xfd\xf1\xb3\x02\x01\x10\x80;D\xa4\xed`qP~c\x0f\xa0d" | ||
"\xd5\xa2Kj\xc7\xb2\xc6\x1e\xec\xfb\x0fK\xb2*\xd5\t2\x81pR\xee\xd1" | ||
'\x1a\xde<"\x1b\x98\x88\x8b\xf4&\xdaB\x95I\xd2\xff\x10\x13\xfc\x1aX' | ||
"\x08,/\x8b\x8b" | ||
), | ||
) | ||
] | ||
|
||
|
||
def test_keyring_no_encrypt(): | ||
class KeyringNoEncrypt(Keyring): | ||
mattsb42-aws marked this conversation as resolved.
Show resolved
Hide resolved
|
||
def on_decrypt(self, _decryption_materials, _encrypted_data_keys): | ||
mattsb42-aws marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return | ||
mattsb42-aws marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
assert pytest.raises(NotImplementedError) | ||
mattsb42-aws marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
|
||
def test_keyring_no_decrypt(): | ||
mattsb42-aws marked this conversation as resolved.
Show resolved
Hide resolved
|
||
class KeyringNoDecrypt(Keyring): | ||
def on_encrypt(self, _encryption_materials): | ||
return | ||
|
||
assert pytest.raises(NotImplementedError) |
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
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.