-
Notifications
You must be signed in to change notification settings - Fork 85
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
4c41f05
chore(performance_tests): added hierarchy keyring and caching cmm tests
RitvikKapila 4e692a9
minor edits
RitvikKapila 8024006
removed branch key id supplier from HKeyring; minor fixes
RitvikKapila 9a6059f
minor refactoring for HKeyring
RitvikKapila 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
128 changes: 128 additions & 0 deletions
128
performance_tests/src/aws_encryption_sdk_performance_tests/keyrings/hierarchy_keyring.py
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,128 @@ | ||
# Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
"""Performance tests for the hierarchy keyring.""" | ||
|
||
import aws_encryption_sdk | ||
import boto3 | ||
from aws_cryptographic_materialproviders.keystore import KeyStore | ||
from aws_cryptographic_materialproviders.keystore.config import KeyStoreConfig | ||
from aws_cryptographic_materialproviders.keystore.models import KMSConfigurationKmsKeyArn | ||
from aws_cryptographic_materialproviders.mpl import AwsCryptographicMaterialProviders | ||
from aws_cryptographic_materialproviders.mpl.config import MaterialProvidersConfig | ||
from aws_cryptographic_materialproviders.mpl.models import ( | ||
CacheTypeDefault, | ||
CreateAwsKmsHierarchicalKeyringInput, | ||
DefaultCache, | ||
) | ||
from aws_cryptographic_materialproviders.mpl.references import IKeyring | ||
|
||
from ..utils.util import PerfTestUtils | ||
|
||
|
||
def create_keyring( | ||
key_store_table_name: str, | ||
logical_key_store_name: str, | ||
kms_key_id: str, | ||
branch_key_id: str = PerfTestUtils.DEFAULT_BRANCH_KEY_ID | ||
): | ||
"""Demonstrate how to create a hierarchy keyring. | ||
|
||
Usage: create_keyring(key_store_table_name, logical_key_store_name, kms_key_id, branch_key_id) | ||
:param key_store_table_name: Name of the KeyStore DynamoDB table. | ||
:type key_store_table_name: string | ||
:param logical_key_store_name: Logical name of the KeyStore. | ||
:type logical_key_store_name: string | ||
:param kms_key_id: KMS Key identifier for the KMS key you want to use. | ||
:type kms_key_id: string | ||
:param branch_key_id: Branch key you want to use for the hierarchy keyring. | ||
:type branch_key_id: string | ||
|
||
For more information on KMS Key identifiers, see | ||
https://docs.aws.amazon.com/kms/latest/developerguide/concepts.html#key-id | ||
""" | ||
# Create boto3 clients for DynamoDB and KMS. | ||
ddb_client = boto3.client('dynamodb', region_name="us-west-2") | ||
kms_client = boto3.client('kms', region_name="us-west-2") | ||
|
||
# Configure your KeyStore resource. | ||
# This SHOULD be the same configuration that you used | ||
# to initially create and populate your KeyStore. | ||
keystore: KeyStore = KeyStore( | ||
config=KeyStoreConfig( | ||
ddb_client=ddb_client, | ||
ddb_table_name=key_store_table_name, | ||
logical_key_store_name=logical_key_store_name, | ||
kms_client=kms_client, | ||
kms_configuration=KMSConfigurationKmsKeyArn( | ||
value=kms_key_id | ||
), | ||
) | ||
) | ||
|
||
# Create the Hierarchical Keyring. | ||
mat_prov: AwsCryptographicMaterialProviders = AwsCryptographicMaterialProviders( | ||
config=MaterialProvidersConfig() | ||
) | ||
|
||
keyring_input: CreateAwsKmsHierarchicalKeyringInput = CreateAwsKmsHierarchicalKeyringInput( | ||
key_store=keystore, | ||
branch_key_id=branch_key_id, | ||
ttl_seconds=600, | ||
cache=CacheTypeDefault( | ||
value=DefaultCache( | ||
entry_capacity=100 | ||
) | ||
), | ||
) | ||
|
||
keyring: IKeyring = mat_prov.create_aws_kms_hierarchical_keyring( | ||
input=keyring_input | ||
) | ||
|
||
return keyring | ||
|
||
|
||
def encrypt_using_keyring( | ||
plaintext_data: bytes, | ||
keyring: IKeyring | ||
): | ||
"""Demonstrate how to encrypt plaintext data using a hierarchy keyring. | ||
|
||
Usage: encrypt_using_keyring(plaintext_data, keyring) | ||
:param plaintext_data: plaintext data you want to encrypt | ||
:type: bytes | ||
:param keyring: Keyring to use for encryption. | ||
:type keyring: IKeyring | ||
""" | ||
client = aws_encryption_sdk.EncryptionSDKClient() | ||
|
||
ciphertext_data, _ = client.encrypt( | ||
source=plaintext_data, | ||
keyring=keyring, | ||
encryption_context=PerfTestUtils.DEFAULT_ENCRYPTION_CONTEXT | ||
) | ||
|
||
return ciphertext_data | ||
|
||
|
||
def decrypt_using_keyring( | ||
ciphertext_data: bytes, | ||
keyring: IKeyring | ||
): | ||
"""Demonstrate how to decrypt ciphertext data using a hierarchy keyring. | ||
|
||
Usage: decrypt_using_keyring(ciphertext_data, keyring) | ||
:param ciphertext_data: ciphertext data you want to decrypt | ||
:type: bytes | ||
:param keyring: Keyring to use for decryption. | ||
:type keyring: IKeyring | ||
""" | ||
client = aws_encryption_sdk.EncryptionSDKClient() | ||
|
||
decrypted_plaintext_data, _ = client.decrypt( | ||
source=ciphertext_data, | ||
keyring=keyring, | ||
encryption_context=PerfTestUtils.DEFAULT_ENCRYPTION_CONTEXT | ||
) | ||
|
||
return decrypted_plaintext_data |
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
85 changes: 85 additions & 0 deletions
85
...rmance_tests/src/aws_encryption_sdk_performance_tests/master_key_providers/caching_cmm.py
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,85 @@ | ||
# Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
"""Performance tests for the Caching Cryptographic Materials Manager (CMM) with KMS Master Key Provider.""" | ||
|
||
import aws_encryption_sdk | ||
|
||
|
||
def create_cmm( | ||
kms_key_id: str, | ||
max_age_in_cache: float, | ||
cache_capacity: int | ||
): | ||
"""Demonstrate how to create a Caching CMM. | ||
|
||
Usage: create_cmm(kms_key_id, max_age_in_cache, cache_capacity) | ||
:param kms_key_id: Amazon Resource Name (ARN) of the KMS customer master key | ||
:type kms_key_id: str | ||
:param max_age_in_cache: Maximum time in seconds that a cached entry can be used | ||
:type max_age_in_cache: float | ||
:param cache_capacity: Maximum number of entries to retain in cache at once | ||
:type cache_capacity: int | ||
""" | ||
# Security thresholds | ||
# Max messages (or max bytes per) data key are optional | ||
max_messages_encrypted = 100 | ||
|
||
# Create a master key provider for the KMS customer master key (CMK) | ||
key_provider = aws_encryption_sdk.StrictAwsKmsMasterKeyProvider(key_ids=[kms_key_id]) | ||
|
||
# Create a local cache | ||
cache = aws_encryption_sdk.LocalCryptoMaterialsCache(cache_capacity) | ||
|
||
# Create a caching CMM | ||
caching_cmm = aws_encryption_sdk.CachingCryptoMaterialsManager( | ||
master_key_provider=key_provider, | ||
cache=cache, | ||
max_age=max_age_in_cache, | ||
max_messages_encrypted=max_messages_encrypted, | ||
) | ||
|
||
return caching_cmm | ||
|
||
|
||
def encrypt_using_cmm( | ||
plaintext_data: bytes, | ||
caching_cmm: aws_encryption_sdk.materials_managers.base.CryptoMaterialsManager | ||
): | ||
"""Demonstrate how to encrypt plaintext data using a Caching CMM. | ||
|
||
Usage: encrypt_using_cmm(plaintext_data, caching_cmm) | ||
:param plaintext_data: plaintext data you want to encrypt | ||
:type: bytes | ||
:param caching_cmm: Crypto Materials Manager to use for encryption. | ||
:type caching_cmm: aws_encryption_sdk.materials_managers.base.CryptoMaterialsManager | ||
""" | ||
client = aws_encryption_sdk.EncryptionSDKClient() | ||
|
||
ciphertext_data, _ = client.encrypt( | ||
source=plaintext_data, | ||
materials_manager=caching_cmm | ||
) | ||
|
||
return ciphertext_data | ||
|
||
|
||
def decrypt_using_cmm( | ||
ciphertext_data: bytes, | ||
caching_cmm: aws_encryption_sdk.materials_managers.base.CryptoMaterialsManager | ||
): | ||
"""Demonstrate how to decrypt ciphertext data using a Caching CMM. | ||
|
||
Usage: decrypt_using_cmm(ciphertext_data, caching_cmm) | ||
:param ciphertext_data: ciphertext data you want to decrypt | ||
:type: bytes | ||
:param caching_cmm: Crypto Materials Manager to use for encryption. | ||
:type caching_cmm: aws_encryption_sdk.materials_managers.base.CryptoMaterialsManager | ||
""" | ||
client = aws_encryption_sdk.EncryptionSDKClient() | ||
|
||
decrypted_plaintext_data, _ = client.decrypt( | ||
source=ciphertext_data, | ||
materials_manager=caching_cmm | ||
) | ||
|
||
return decrypted_plaintext_data |
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
Oops, something went wrong.
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.
chore(performance_tests): added hierarchy keyring and caching cmm tests #686
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