Skip to content

Commit 88ee2c0

Browse files
committed
fix
1 parent aa727ab commit 88ee2c0

File tree

3 files changed

+37
-27
lines changed

3 files changed

+37
-27
lines changed

examples/src/keyrings/aws_kms_mrk_keyring_example.py

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -44,28 +44,30 @@
4444
def encrypt_and_decrypt_with_keyring(
4545
mrk_key_id_encrypt: str,
4646
mrk_replica_key_id_decrypt: str,
47-
default_region: str,
48-
second_region: str
47+
mrk_encrypt_region: str,
48+
mrk_replica_decrypt_region: str
4949
):
5050
"""Demonstrate an encrypt/decrypt cycle using an AWS KMS MRK keyring.
5151
5252
Usage: encrypt_and_decrypt_with_keyring(mrk_key_id_encrypt,
5353
mrk_replica_key_id_decrypt,
54-
default_region,
55-
second_region)
54+
mrk_encrypt_region,
55+
mrk_replica_decrypt_region)
5656
:param mrk_key_id_encrypt: KMS Key identifier for the KMS key located in your
5757
default region, which you want to use for encryption of your data keys
5858
:type mrk_key_id_encrypt: string
59-
:param mrk_replica_key_id_decrypt: KMS Key identifier for the KMS key KMS Key
59+
:param mrk_replica_key_id_decrypt: KMS Key identifier for the KMS key
6060
that is a replica of the `mrk_key_id_encrypt` in a second region, which you
6161
want to use for decryption of your data keys
6262
:type mrk_replica_key_id_decrypt: string
63-
:param default_region: AWS Region for encryption of your data keys
64-
:type default_region: string
65-
:param second_region: AWS Region for decryption of your data keys
66-
:type second_region: string
67-
68-
For more information on KMS Key identifiers, see
63+
:param mrk_encrypt_region: AWS Region for encryption of your data keys. This should
64+
be the region of the mrk_key_id_encrypt.
65+
:type mrk_encrypt_region: string
66+
:param mrk_replica_decrypt_region: AWS Region for decryption of your data keys. This should
67+
be the region of the mrk_replica_key_id_decrypt.
68+
:type mrk_replica_decrypt_region: string
69+
70+
For more information on KMS Key identifiers for multi-region keys, see
6971
https://docs.aws.amazon.com/kms/latest/developerguide/concepts.html#key-id
7072
"""
7173
# 1. Instantiate the encryption SDK client.
@@ -91,13 +93,13 @@ def encrypt_and_decrypt_with_keyring(
9193
"the data you are handling": "is what you think it is",
9294
}
9395

94-
# 3. Create a keyring that will encrypt your data, using a KMS MRK key in the first region.
96+
# 3. Create a keyring that will encrypt your data, using a KMS MRK in the first region.
9597
mat_prov: AwsCryptographicMaterialProviders = AwsCryptographicMaterialProviders(
9698
config=MaterialProvidersConfig()
9799
)
98100

99101
# Create a boto3 client for KMS in the first region.
100-
encrypt_kms_client = boto3.client('kms', region_name=default_region)
102+
encrypt_kms_client = boto3.client('kms', region_name=mrk_encrypt_region)
101103

102104
encrypt_keyring_input: CreateAwsKmsMrkKeyringInput = CreateAwsKmsMrkKeyringInput(
103105
kms_key_id=mrk_key_id_encrypt,
@@ -120,11 +122,11 @@ def encrypt_and_decrypt_with_keyring(
120122
assert ciphertext != EXAMPLE_DATA, \
121123
"Ciphertext and plaintext data are the same. Invalid encryption"
122124

123-
# 6. Create a keyring that will decrypt your data, using the same KMS MRK key replicated
125+
# 6. Create a keyring that will decrypt your data, using the same KMS MRK replicated
124126
# to the second region. This example assumes you have already replicated your key
125127

126128
# Create a boto3 client for KMS in the second region.
127-
decrypt_kms_client = boto3.client('kms', region_name=second_region)
129+
decrypt_kms_client = boto3.client('kms', region_name=mrk_replica_decrypt_region)
128130

129131
decrypt_keyring_input: CreateAwsKmsMrkKeyringInput = CreateAwsKmsMrkKeyringInput(
130132
kms_key_id=mrk_replica_key_id_decrypt,

examples/src/keyrings/aws_kms_mrk_multi_keyring_example.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,28 @@
44
This example sets up the KMS MRK Multi Keyring
55
66
The AWS Key Management Service (AWS KMS) MRK keyring interacts with AWS KMS to
7-
create, encrypt, and decrypt data keys with multi-region AWS KMS keys (MRKs).
8-
This example creates a KMS MRK Multi Keyring using an mrk_key_id (generator) and
9-
a kms_key_id, and then encrypts a custom input EXAMPLE_DATA with an encryption context.
7+
create, encrypt, and decrypt data keys with AWS KMS MRK keys.
8+
The KMS MRK multi-keyring consists of one or more individual keyrings of the
9+
same or different type. The keys can either be regular KMS keys or MRKs.
10+
The effect is like using several keyrings in a series.
11+
12+
This example creates a AwsKmsMrkMultiKeyring using an mrk_key_id (generator) and a kms_key_id
13+
as a child key, and then encrypts a custom input EXAMPLE_DATA with an encryption context.
14+
Either KMS Key individually is capable of decrypting data encrypted under this keyring.
1015
This example also includes some sanity checks for demonstration:
1116
1. Ciphertext and plaintext data are not the same
1217
2. Encryption context is correct in the decrypted message header
1318
3. Decrypted plaintext value matches EXAMPLE_DATA
1419
4. Ciphertext can be decrypted using an AwsKmsMrkKeyring containing a replica of the
15-
MRK key (from the multi-keyring used for encryption) copied from the first region into
20+
MRK (from the multi-keyring used for encryption) copied from the first region into
1621
the second region
1722
These sanity checks are for demonstration in the example only. You do not need these in your code.
1823
1924
For more information on how to use KMS keyrings, see
2025
https://docs.aws.amazon.com/encryption-sdk/latest/developer-guide/use-kms-keyring.html
26+
27+
For more info on KMS MRK (multi-region keys), see the KMS documentation:
28+
https://docs.aws.amazon.com/kms/latest/developerguide/multi-region-keys-overview.html
2129
"""
2230
import sys
2331

@@ -56,15 +64,15 @@ def encrypt_and_decrypt_with_keyring(
5664
default region
5765
:type mrk_key_id: string
5866
:param kms_key_id: KMS Key identifier for a KMS key, possibly located in a different region
59-
than the MRK key
67+
than the MRK
6068
:type kms_key_id: string
6169
:param mrk_replica_key_id: KMS Key identifier for an MRK that is a replica of the
6270
`mrk_key_id` in a second region.
6371
:type mrk_replica_key_id: string
6472
:param second_region: The second region where the MRK replica is located
6573
:type second_region: string
6674
67-
For more information on KMS Key identifiers, see
75+
For more information on KMS Key identifiers for multi-region keys, see
6876
https://docs.aws.amazon.com/kms/latest/developerguide/concepts.html#key-id
6977
"""
7078
# 1. Instantiate the encryption SDK client.
@@ -120,8 +128,8 @@ def encrypt_and_decrypt_with_keyring(
120128
"Ciphertext and plaintext data are the same. Invalid encryption"
121129

122130
# 6. Decrypt your encrypted data using the same AwsKmsMrkMultiKeyring you used on encrypt.
123-
# It will decrypt the data using the generator KMS MRK key since that is the first available
124-
# KMS key on the keyring that is capable of decrypting the data.
131+
# It will decrypt the data using the generator key (in this case, the MRK), since that is
132+
# the first available KMS key on the keyring that is capable of decrypting the data.
125133
plaintext_bytes, dec_header = client.decrypt(
126134
source=ciphertext,
127135
keyring=kms_mrk_multi_keyring

examples/test/keyrings/test_i_aws_kms_mrk_keyring_example.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ def test_encrypt_and_decrypt_with_keyring():
1414
"arn:aws:kms:us-east-1:658956600833:key/mrk-80bd8ecdcd4342aebd84b7dc9da498a7"
1515
mrk_replica_key_id_decrypt = \
1616
"arn:aws:kms:eu-west-1:658956600833:key/mrk-80bd8ecdcd4342aebd84b7dc9da498a7"
17-
default_region = "us-east-1"
18-
second_region = "eu-west-1"
17+
mrk_encrypt_region = "us-east-1"
18+
mrk_replica_decrypt_region = "eu-west-1"
1919
encrypt_and_decrypt_with_keyring(mrk_key_id_encrypt,
2020
mrk_replica_key_id_decrypt,
21-
default_region,
22-
second_region)
21+
mrk_encrypt_region,
22+
mrk_replica_decrypt_region)

0 commit comments

Comments
 (0)