-
Notifications
You must be signed in to change notification settings - Fork 86
Raw keyrings #165
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
Raw keyrings #165
Changes from 119 commits
Commits
Show all changes
123 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 9fa50cf
Made suggested changes to raw keyrings
mmegs-amzn 3b28bea
partial commit for raw keyrings
mmegs-amzn 8f65947
Made suggested changes
mmegs-amzn 40eb8cc
Changed wrapping_key_id in deserialize_wrapped_key() back to self.key…
mmegs-amzn 96979b1
Decryption and PEM input now works
mmegs-amzn f592956
Adding sample
mmegs-amzn dbbb840
Removed test comments
mmegs-amzn b71e09c
Unit tests for raw aes and rsa
mmegs-amzn 866755d
All unit tests working
mmegs-amzn dae98c3
All unit tests done. Functional tests - key_info_prefix_vectors for A…
mmegs-amzn 00a7dad
Delete sample_aes.py
MeghaShetty 29f69e0
Corrected tox and pylint errors
mmegs-amzn 2e43c1e
Removed print statements used while debugging
mmegs-amzn 8ce5cc6
Partial commit for changes to tests
mmegs-amzn 9fcf529
Partial commit for tests for raw keyrings
mmegs-amzn d5d186e
All tests except compatibility of raw rsa with mkp and key info prefi…
mmegs-amzn 69acc1a
Pulled from keyring branch
mmegs-amzn d89bc61
Merge branch 'keyring' into raw-keyrings
MeghaShetty 7ea1bd6
Updated base API
mmegs-amzn f4ee7f0
Merge branch 'raw-keyrings' of github.com:MeghaShetty/aws-encryption-…
mmegs-amzn acbd5b4
Added test for key info prefix
mmegs-amzn 8374130
Changed unittest.mock to mock
mmegs-amzn 1dc5a77
Raw keyrings test partial commit
mmegs-amzn 5a7e4b2
All tests for raw keyrings work
mmegs-amzn ced07c4
Removed unused imports
mmegs-amzn 88cd097
Removed unused imports
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
Large diffs are not rendered by default.
Oops, something went wrong.
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,224 @@ | ||
# 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, | ||
EncryptionKeyType, | ||
EncryptionType, | ||
KeyringTraceFlag, | ||
WrappingAlgorithm, | ||
) | ||
from aws_encryption_sdk.internal.crypto import WrappingKey | ||
from aws_encryption_sdk.internal.formatting.serialize import serialize_raw_master_key_prefix | ||
from aws_encryption_sdk.key_providers.raw import RawMasterKey | ||
from aws_encryption_sdk.keyring.raw_keyring import RawAESKeyring | ||
from aws_encryption_sdk.materials_managers import DecryptionMaterials, EncryptionMaterials | ||
from aws_encryption_sdk.structures import EncryptedDataKey, KeyringTrace, MasterKeyInfo, RawDataKey | ||
|
||
pytestmark = [pytest.mark.functional, pytest.mark.local] | ||
|
||
_ENCRYPTION_CONTEXT = {"encryption": "context", "values": "here"} | ||
_PROVIDER_ID = "Random Raw Keys" | ||
_KEY_ID = b"5325b043-5843-4629-869c-64794af77ada" | ||
_WRAPPING_KEY = b"12345678901234567890123456789012" | ||
_SIGNING_KEY = b"aws-crypto-public-key" | ||
|
||
_WRAPPING_ALGORITHM = [alg for alg in WrappingAlgorithm if alg.encryption_type is EncryptionType.SYMMETRIC] | ||
|
||
|
||
def sample_encryption_materials(): | ||
return [ | ||
EncryptionMaterials( | ||
algorithm=Algorithm.AES_256_GCM_IV12_TAG16_HKDF_SHA384_ECDSA_P384, | ||
encryption_context=_ENCRYPTION_CONTEXT, | ||
signing_key=_SIGNING_KEY, | ||
), | ||
EncryptionMaterials( | ||
algorithm=Algorithm.AES_256_GCM_IV12_TAG16_HKDF_SHA384_ECDSA_P384, | ||
data_encryption_key=RawDataKey( | ||
key_provider=MasterKeyInfo(provider_id=_PROVIDER_ID, key_info=_KEY_ID), | ||
data_key=b'*!\xa1"^-(\xf3\x105\x05i@B\xc2\xa2\xb7\xdd\xd5\xd5\xa9\xddm\xfae\xa8\\$\xf9d\x1e(', | ||
), | ||
encryption_context=_ENCRYPTION_CONTEXT, | ||
signing_key=_SIGNING_KEY, | ||
keyring_trace=[ | ||
KeyringTrace( | ||
wrapping_key=MasterKeyInfo(provider_id=_PROVIDER_ID, key_info=_KEY_ID), | ||
flags={KeyringTraceFlag.WRAPPING_KEY_GENERATED_DATA_KEY}, | ||
) | ||
], | ||
), | ||
EncryptionMaterials( | ||
algorithm=Algorithm.AES_256_GCM_IV12_TAG16_HKDF_SHA384_ECDSA_P384, | ||
data_encryption_key=RawDataKey( | ||
key_provider=MasterKeyInfo(provider_id=_PROVIDER_ID, key_info=_KEY_ID), | ||
data_key=b'*!\xa1"^-(\xf3\x105\x05i@B\xc2\xa2\xb7\xdd\xd5\xd5\xa9\xddm\xfae\xa8\\$\xf9d\x1e(', | ||
), | ||
encrypted_data_keys=[ | ||
EncryptedDataKey( | ||
key_provider=MasterKeyInfo(provider_id=_PROVIDER_ID, key_info=_KEY_ID), | ||
encrypted_data_key=b"\xde^\x97\x7f\x84\xe9\x9e\x98\xd0\xe2\xf8\xd5\xcb\xe9\x7f.}\x87\x16,\x11n#\xc8p" | ||
b"\xdb\xbf\x94\x86*Q\x06\xd2\xf5\xdah\x08\xa4p\x81\xf7\xf4G\x07FzE\xde", | ||
) | ||
], | ||
encryption_context=_ENCRYPTION_CONTEXT, | ||
signing_key=_SIGNING_KEY, | ||
keyring_trace=[ | ||
KeyringTrace( | ||
wrapping_key=MasterKeyInfo(provider_id=_PROVIDER_ID, key_info=_KEY_ID), | ||
flags={ | ||
KeyringTraceFlag.WRAPPING_KEY_GENERATED_DATA_KEY, | ||
KeyringTraceFlag.WRAPPING_KEY_ENCRYPTED_DATA_KEY, | ||
}, | ||
) | ||
], | ||
), | ||
] | ||
|
||
|
||
@pytest.mark.parametrize("encryption_materials_samples", sample_encryption_materials()) | ||
@pytest.mark.parametrize("wrapping_algorithm_samples", _WRAPPING_ALGORITHM) | ||
def test_raw_aes_encryption_decryption(encryption_materials_samples, wrapping_algorithm_samples): | ||
|
||
# Initializing attributes | ||
key_namespace = _PROVIDER_ID | ||
key_name = _KEY_ID | ||
_wrapping_algorithm = wrapping_algorithm_samples | ||
|
||
# Creating an instance of a raw AES keyring | ||
test_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 = test_raw_aes_keyring.on_encrypt(encryption_materials=encryption_materials_samples) | ||
|
||
# Generate decryption materials | ||
decryption_materials = DecryptionMaterials( | ||
algorithm=Algorithm.AES_256_GCM_IV12_TAG16_HKDF_SHA384_ECDSA_P384, | ||
verification_key=b"ex_verification_key", | ||
encryption_context=_ENCRYPTION_CONTEXT, | ||
) | ||
|
||
# Call on_decrypt function for the keyring | ||
decryption_materials = test_raw_aes_keyring.on_decrypt( | ||
decryption_materials=decryption_materials, encrypted_data_keys=encryption_materials.encrypted_data_keys | ||
) | ||
|
||
# Check if the data keys match | ||
assert encryption_materials.data_encryption_key.data_key == decryption_materials.data_encryption_key.data_key | ||
|
||
|
||
@pytest.mark.parametrize("encryption_materials_samples", sample_encryption_materials()) | ||
@pytest.mark.parametrize("wrapping_algorithm_samples", _WRAPPING_ALGORITHM) | ||
def test_raw_master_key_decrypts_what_raw_keyring_encrypts(encryption_materials_samples, wrapping_algorithm_samples): | ||
|
||
# Initializing attributes | ||
key_namespace = _PROVIDER_ID | ||
key_name = _KEY_ID | ||
_wrapping_algorithm = wrapping_algorithm_samples | ||
|
||
# Creating an instance of a raw AES keyring | ||
test_raw_aes_keyring = RawAESKeyring( | ||
key_namespace=key_namespace, | ||
key_name=key_name, | ||
wrapping_key=_WRAPPING_KEY, | ||
wrapping_algorithm=_wrapping_algorithm, | ||
) | ||
|
||
# Creating an instance of a raw master key | ||
test_raw_master_key = RawMasterKey( | ||
key_id=test_raw_aes_keyring.key_name, | ||
provider_id=test_raw_aes_keyring.key_namespace, | ||
wrapping_key=test_raw_aes_keyring._wrapping_key_structure, | ||
) | ||
|
||
# Encrypt using raw AES keyring | ||
encryption_materials = test_raw_aes_keyring.on_encrypt(encryption_materials=encryption_materials_samples) | ||
|
||
# Check if plaintext data key encrypted by raw keyring is decrypted by raw master key | ||
assert ( | ||
encryption_materials.data_encryption_key.data_key | ||
== test_raw_master_key.decrypt_data_key_from_list( | ||
mattsb42-aws marked this conversation as resolved.
Show resolved
Hide resolved
|
||
encrypted_data_keys=encryption_materials._encrypted_data_keys, | ||
algorithm=encryption_materials.algorithm, | ||
encryption_context=encryption_materials.encryption_context, | ||
).data_key | ||
) | ||
|
||
|
||
@pytest.mark.parametrize("encryption_materials_samples", sample_encryption_materials()) | ||
@pytest.mark.parametrize("wrapping_algorithm_samples", _WRAPPING_ALGORITHM) | ||
def test_raw_keyring_decrypts_what_raw_master_key_encrypts(encryption_materials_samples, wrapping_algorithm_samples): | ||
|
||
# Initializing attributes | ||
key_namespace = _PROVIDER_ID | ||
key_name = _KEY_ID | ||
_wrapping_algorithm = wrapping_algorithm_samples | ||
|
||
# Creating an instance of a raw AES keyring | ||
test_raw_aes_keyring = RawAESKeyring( | ||
key_namespace=key_namespace, | ||
key_name=key_name, | ||
wrapping_key=_WRAPPING_KEY, | ||
wrapping_algorithm=_wrapping_algorithm, | ||
) | ||
|
||
# Creating an instance of a raw master key | ||
test_raw_master_key = RawMasterKey( | ||
key_id=test_raw_aes_keyring.key_name, | ||
provider_id=test_raw_aes_keyring.key_namespace, | ||
wrapping_key=test_raw_aes_keyring._wrapping_key_structure, | ||
) | ||
|
||
if encryption_materials_samples.data_encryption_key is not None: | ||
mattsb42-aws marked this conversation as resolved.
Show resolved
Hide resolved
|
||
raw_master_key_encrypted_data_key = test_raw_master_key.encrypt_data_key( | ||
data_key=encryption_materials_samples.data_encryption_key, | ||
algorithm=encryption_materials_samples.algorithm, | ||
encryption_context=encryption_materials_samples.encryption_context, | ||
) | ||
assert ( | ||
encryption_materials_samples.data_encryption_key.data_key | ||
== test_raw_aes_keyring.on_decrypt( | ||
mattsb42-aws marked this conversation as resolved.
Show resolved
Hide resolved
|
||
decryption_materials=DecryptionMaterials( | ||
algorithm=encryption_materials_samples.algorithm, | ||
encryption_context=encryption_materials_samples.encryption_context, | ||
verification_key=b"ex_verification_key", | ||
), | ||
encrypted_data_keys=[raw_master_key_encrypted_data_key], | ||
).data_encryption_key.data_key | ||
) | ||
|
||
|
||
@pytest.mark.parametrize("wrapping_algorithm", _WRAPPING_ALGORITHM) | ||
def test_key_info_prefix_vectors(wrapping_algorithm): | ||
assert ( | ||
serialize_raw_master_key_prefix( | ||
raw_master_key=RawMasterKey( | ||
provider_id=_PROVIDER_ID, | ||
key_id=_KEY_ID, | ||
wrapping_key=WrappingKey( | ||
wrapping_algorithm=wrapping_algorithm, | ||
wrapping_key=_WRAPPING_KEY, | ||
wrapping_key_type=EncryptionKeyType.SYMMETRIC, | ||
), | ||
) | ||
) | ||
== _KEY_ID + b"\x00\x00\x00\x80\x00\x00\x00\x0c" | ||
) |
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.