Skip to content

Commit 6d44ed1

Browse files
committed
fix comments
1 parent 7c721ed commit 6d44ed1

File tree

3 files changed

+56
-31
lines changed

3 files changed

+56
-31
lines changed

examples/src/migration/README.rst

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,21 @@
22
Migration Examples
33
##################
44

5-
The `Encryption SDK for Python`_ now uses the `AWS Cryptographic Material Providers Library`_,
6-
which introduces keyrings in place of Master Key Providers. The MPL abstracts lower
5+
The `Encryption SDK for Python`_ now uses the `AWS Cryptographic Material Providers Library`_. The MPL abstracts lower
76
level cryptographic materials management of encryption and decryption materials.
87

9-
This directory contains some examples to migrate from the old version of the ESDK.
10-
If you have messages encrypted in the older versions using Master Key Providers,
11-
these examples can guide you on how to decrypt those messages using the new version
12-
of the ESDK. Here is the list of examples:
13-
1. Migration example for AWS KMS keys
14-
2. Migration example for Raw AES keys
15-
3. Migration example for Raw RSA keys
16-
4. Setting a 'CommitmentPolicy' during migration
8+
This directory contains migration examples for:
9+
10+
* Moving to Keyrings from Master Key Providers:
11+
#. Migration example to AWS KMS keyring from AWS KMS Master Key Provider.
12+
#. Migration example to Raw AES keyring from Raw AES Master Key Provider.
13+
#. Migration example to Raw RSA keyring from Raw RSA Master Key Provider.
14+
15+
* Migration to newer versions of the ESDK from the old version (1.x):
16+
#. Setting a 'CommitmentPolicy' during migration.
17+
If you have messages encrypted in the older versions of the ESDK (1.x),
18+
this example can guide you on how to decrypt those messages using the
19+
new version of the ESDK.
1720

1821
.. _AWS Cryptographic Material Providers Library: https://github.com/aws/aws-cryptographic-material-providers-library
1922
.. _Encryption SDK for Python: https://github.com/aws/aws-encryption-sdk-python/tree/9c34aad60fc918c1a9186ec5215a451e8bfd0f65

examples/src/migration/migration_raw_aes_key_example.py

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,12 @@
4949

5050
DEFAULT_AES_256_STATIC_KEY = secrets.token_bytes(32)
5151

52+
# The key namespace in the Raw keyrings is equivalent to Provider ID (or Provider) field
53+
# in the Raw Master Key Providers
5254
DEFAULT_KEY_NAME_SPACE = "Some managed raw keys"
5355

56+
# The key name in the Raw keyrings is equivalent to the Key ID field
57+
# in the Raw Master Key Providers
5458
DEFAULT_KEY_NAME = "My 256-bit AES wrapping key"
5559

5660

@@ -66,6 +70,10 @@ def create_keyring():
6670
config=MaterialProvidersConfig()
6771
)
6872

73+
# The key namespace in the Raw keyrings is equivalent to Provider ID (or Provider) field
74+
# in the Raw Master Key Providers
75+
# The key name in the Raw keyrings is equivalent to the Key ID field
76+
# in the Raw Master Key Providers
6977
keyring_input: CreateRawAesKeyringInput = CreateRawAesKeyringInput(
7078
key_namespace=DEFAULT_KEY_NAME_SPACE,
7179
key_name=DEFAULT_KEY_NAME,
@@ -81,19 +89,24 @@ def create_keyring():
8189

8290

8391
# This is a helper class necessary for the Raw AES master key provider
84-
class StaticRandomMasterKeyProvider(RawMasterKeyProvider):
92+
# In the StaticMasterKeyProvider, we fix the static key to
93+
# DEFAULT_AES_256_STATIC_KEY in order to make the test deterministic.
94+
# Thus, both the Raw AES keyring and Raw AES MKP have the same key
95+
# and we are able to encrypt data using keyrings and decrypt using MKP and vice versa
96+
# In practice, users should generate a new random key for each key id.
97+
class StaticMasterKeyProvider(RawMasterKeyProvider):
8598
"""Generates 256-bit keys for each unique key ID."""
8699

87-
# The Provider ID (or Provider) field in the JceMasterKey and RawMasterKey is
88-
# equivalent to key namespace in the Raw keyrings
100+
# The key namespace in the Raw keyrings is equivalent to Provider ID (or Provider) field
101+
# in the Raw Master Key Providers
89102
provider_id = DEFAULT_KEY_NAME_SPACE
90103

91104
def __init__(self, **kwargs): # pylint: disable=unused-argument
92105
"""Initialize empty map of keys."""
93106
self._static_keys = {}
94107

95108
def _get_raw_key(self, key_id):
96-
"""Returns a static, randomly-generated symmetric key for the specified key ID.
109+
"""Returns a static, symmetric key for the specified key ID.
97110
98111
:param str key_id: Key ID
99112
:returns: Wrapping key that contains the specified static key
@@ -120,9 +133,10 @@ def create_key_provider():
120133
"""
121134
# Create a Raw AES master key provider.
122135

123-
# The Key ID field in the JceMasterKey and RawMasterKey is equivalent to key name in the Raw keyrings
136+
# The key name in the Raw keyrings is equivalent to the Key ID field
137+
# in the Raw Master Key Providers
124138
key_id = DEFAULT_KEY_NAME
125-
key_provider = StaticRandomMasterKeyProvider()
139+
key_provider = StaticMasterKeyProvider()
126140
key_provider.add_master_key(key_id)
127141

128142
return key_provider

examples/src/migration/migration_raw_rsa_key_example.py

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,12 @@
5252
"the data you are handling": "is what you think it is",
5353
}
5454

55+
# The key namespace in the Raw keyrings is equivalent to Provider ID (or Provider) field
56+
# in the Raw Master Key Providers
5557
DEFAULT_KEY_NAME_SPACE = "Some managed raw keys"
5658

59+
# The key name in the Raw keyrings is equivalent to the Key ID field
60+
# in the Raw Master Key Providers
5761
DEFAULT_KEY_NAME = "My 4096-bit RSA wrapping key"
5862

5963

@@ -98,6 +102,10 @@ def create_keyring(public_key, private_key):
98102
config=MaterialProvidersConfig()
99103
)
100104

105+
# The key namespace in the Raw keyrings is equivalent to Provider ID (or Provider) field
106+
# in the Raw Master Key Providers
107+
# The key name in the Raw keyrings is equivalent to the Key ID field
108+
# in the Raw Master Key Providers
101109
keyring_input: CreateRawRsaKeyringInput = CreateRawRsaKeyringInput(
102110
key_namespace=DEFAULT_KEY_NAME_SPACE,
103111
key_name=DEFAULT_KEY_NAME,
@@ -114,24 +122,24 @@ def create_keyring(public_key, private_key):
114122

115123

116124
# This is a helper class necessary for the Raw RSA master key provider.
117-
# In the StaticRandomMasterKeyProvider, we fix the static key to
125+
# In the StaticMasterKeyProvider, we fix the static key to
118126
# DEFAULT_RSA_PRIVATE_KEY in order to make the test deterministic.
119127
# Thus, both the Raw RSA keyring and Raw RSA MKP have the same private_key
120128
# and we are able to encrypt data using keyrings and decrypt using MKP and vice versa
121-
# In practice, users should generate a new key pair for each key id.
122-
class StaticRandomMasterKeyProvider(RawMasterKeyProvider):
123-
"""Randomly generates and provides 4096-bit RSA keys consistently per unique key id."""
129+
# In practice, users should generate a new random key pair for each key id.
130+
class StaticMasterKeyProvider(RawMasterKeyProvider):
131+
"""Provides 4096-bit RSA keys consistently per unique key id."""
124132

125-
# The Provider ID (or Provider) field in the JceMasterKey and RawMasterKey is
126-
# equivalent to key namespace in the Raw keyrings
133+
# The key namespace in the Raw keyrings is equivalent to Provider ID (or Provider) field
134+
# in the Raw Master Key Providers
127135
provider_id = DEFAULT_KEY_NAME_SPACE
128136

129137
def __init__(self, **kwargs): # pylint: disable=unused-argument
130138
"""Initialize empty map of keys."""
131139
self._static_keys = {}
132140

133141
def _get_raw_key(self, key_id):
134-
"""Retrieves a static, randomly generated, RSA key for the specified key id.
142+
"""Retrieves a static, RSA key for the specified key id.
135143
136144
:param str key_id: User-defined ID for the static key
137145
:returns: Wrapping key that contains the specified static key
@@ -143,7 +151,7 @@ def _get_raw_key(self, key_id):
143151
# We fix the static key in order to make the test deterministic
144152
# In practice, you should get this key from a secure key management system such as an HSM.
145153
# Also, in practice, users should generate a new key pair for each key id in
146-
# the StaticRandomMasterKeyProvider.
154+
# the StaticMasterKeyProvider.
147155
static_key = DEFAULT_RSA_PRIVATE_KEY
148156
self._static_keys[key_id] = static_key
149157
return WrappingKey(
@@ -160,17 +168,17 @@ def create_key_provider():
160168
"""
161169
# Create a Raw RSA master key provider.
162170

163-
# The Key ID field in the JceMasterKey and RawMasterKey is equivalent to key name
164-
# in the Raw keyrings
171+
# The key name in the Raw keyrings is equivalent to the Key ID field
172+
# in the Raw Master Key Providers
165173
key_id = DEFAULT_KEY_NAME
166174

167175
# In this example, we fix the static key to DEFAULT_RSA_PRIVATE_KEY in both the keyring
168-
# and MKP (for MKP, we fix the static key in StaticRandomMasterKeyProvider) in order to make
176+
# and MKP (for MKP, we fix the static key in StaticMasterKeyProvider) in order to make
169177
# the test deterministic. Thus, both the Raw RSA keyring and Raw RSA MKP have the same
170178
# private_key and we are able to encrypt data using keyrings and decrypt using MKP
171179
# and vice versa. In practice, users should generate a new key pair for each key id in
172-
# the StaticRandomMasterKeyProvider.
173-
key_provider = StaticRandomMasterKeyProvider()
180+
# the StaticMasterKeyProvider.
181+
key_provider = StaticMasterKeyProvider()
174182
key_provider.add_master_key(key_id)
175183

176184
return key_provider
@@ -192,11 +200,11 @@ def migration_raw_rsa_key(
192200
# 1b. Create a Raw RSA Master Key Provider
193201

194202
# In this example, we fix the static key to DEFAULT_RSA_PRIVATE_KEY in both the keyring
195-
# and MKP (for MKP, we fix the static key in StaticRandomMasterKeyProvider) in order to make
203+
# and MKP (for MKP, we fix the static key in StaticMasterKeyProvider) in order to make
196204
# the test deterministic. Thus, both the Raw RSA keyring and Raw RSA MKP have the same
197205
# private_key and we are able to encrypt data using keyrings and decrypt using MKP
198206
# and vice versa. In practice, users should generate a new key pair for each key id in
199-
# the StaticRandomMasterKeyProvider.
207+
# the StaticMasterKeyProvider.
200208
raw_rsa_master_key_provider = create_key_provider()
201209

202210
# 2a. Encrypt EXAMPLE_DATA using Raw RSA Keyring

0 commit comments

Comments
 (0)