Skip to content

Commit 73cce71

Browse files
feat!: Updates to the AWS Encryption SDK.
This change includes fixes for issues that were reported by Thai Duong from Google's Security team, and for issues that were identified by AWS Cryptography. BREAKING CHANGE: AWS KMS KeyIDs must be specified explicitly or Discovery mode explicitly chosen. Key committing suites are now default. CommitmentPolicy requires commitment by default. See: https://docs.aws.amazon.com/encryption-sdk/latest/developer-guide/migration.html
1 parent 02b442f commit 73cce71

37 files changed

+1289
-794
lines changed

README.rst

+6-3
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,11 @@ Usage
9696
EncryptionSDKClient
9797
===================
9898
To use this module, you (the caller) must first create an instance of the ``EncryptionSDKClient`` class.
99-
The constructor to this class requires a single keyword argument, ``commitment_policy``. There is
100-
currently only one valid value for this argument: ``FORBID_ENCRYPT_ALLOW_DECRYPT``.
99+
The constructor to this class accepts an optional keyword argument, ``commitment_policy``, that controls
100+
which algorithm suites can be used for encryption and decryption. If no value
101+
is provided for this argument, a default value of ``REQUIRE_ENCRYPT_REQUIRE_DECRYPT`` is used. Unless
102+
you have specialized performance requirements or are in the process of migrating from an older
103+
version of the AWS Encryption SDK, we recommend using the default value.
101104

102105
.. code:: python
103106
@@ -106,7 +109,7 @@ currently only one valid value for this argument: ``FORBID_ENCRYPT_ALLOW_DECRYPT
106109
107110
108111
client = aws_encryption_sdk.EncryptionSDKClient(
109-
commitment_policy=CommitmentPolicy.FORBID_ENCRYPT_ALLOW_DECRYPT
112+
commitment_policy=CommitmentPolicy.REQUIRE_ENCRYPT_REQUIRE_DECRYPT
110113
)
111114
112115

examples/src/basic_encryption.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@ def cycle_string(key_arn, source_plaintext, botocore_session=None):
2323
:param botocore_session: existing botocore session instance
2424
:type botocore_session: botocore.session.Session
2525
"""
26-
# Set up an encryption client with an explicit commitment policy
27-
client = aws_encryption_sdk.EncryptionSDKClient(commitment_policy=CommitmentPolicy.FORBID_ENCRYPT_ALLOW_DECRYPT)
26+
# Set up an encryption client with an explicit commitment policy. Note that if you do not explicitly choose a
27+
# commitment policy, REQUIRE_ENCRYPT_REQUIRE_DECRYPT is used by default.
28+
client = aws_encryption_sdk.EncryptionSDKClient(commitment_policy=CommitmentPolicy.REQUIRE_ENCRYPT_REQUIRE_DECRYPT)
2829

2930
# Create a KMS master key provider
3031
kms_kwargs = dict(key_ids=[key_arn])

examples/src/basic_file_encryption_with_multiple_providers.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,9 @@ def cycle_file(key_arn, source_plaintext_filename, botocore_session=None):
7676
cycled_kms_plaintext_filename = source_plaintext_filename + ".kms.decrypted"
7777
cycled_static_plaintext_filename = source_plaintext_filename + ".static.decrypted"
7878

79-
# Set up an encryption client with an explicit commitment policy
80-
client = aws_encryption_sdk.EncryptionSDKClient(commitment_policy=CommitmentPolicy.FORBID_ENCRYPT_ALLOW_DECRYPT)
79+
# Set up an encryption client with an explicit commitment policy. Note that if you do not explicitly choose a
80+
# commitment policy, REQUIRE_ENCRYPT_REQUIRE_DECRYPT is used by default.
81+
client = aws_encryption_sdk.EncryptionSDKClient(commitment_policy=CommitmentPolicy.REQUIRE_ENCRYPT_REQUIRE_DECRYPT)
8182

8283
# Create a KMS master key provider
8384
kms_kwargs = dict(key_ids=[key_arn])

examples/src/basic_file_encryption_with_raw_key_provider.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,9 @@ def cycle_file(source_plaintext_filename):
5353
5454
:param str source_plaintext_filename: Filename of file to encrypt
5555
"""
56-
# Set up an encryption client with an explicit commitment policy
57-
client = aws_encryption_sdk.EncryptionSDKClient(commitment_policy=CommitmentPolicy.FORBID_ENCRYPT_ALLOW_DECRYPT)
56+
# Set up an encryption client with an explicit commitment policy. Note that if you do not explicitly choose a
57+
# commitment policy, REQUIRE_ENCRYPT_REQUIRE_DECRYPT is used by default.
58+
client = aws_encryption_sdk.EncryptionSDKClient(commitment_policy=CommitmentPolicy.REQUIRE_ENCRYPT_REQUIRE_DECRYPT)
5859

5960
# Create a static random master key provider
6061
key_id = os.urandom(8)

examples/src/data_key_caching_basic.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,9 @@ def encrypt_with_caching(kms_cmk_arn, max_age_in_cache, cache_capacity):
3232
# Create an encryption context
3333
encryption_context = {"purpose": "test"}
3434

35-
# Set up an encryption client with an explicit commitment policy
36-
client = aws_encryption_sdk.EncryptionSDKClient(commitment_policy=CommitmentPolicy.FORBID_ENCRYPT_ALLOW_DECRYPT)
35+
# Set up an encryption client with an explicit commitment policy. Note that if you do not explicitly choose a
36+
# commitment policy, REQUIRE_ENCRYPT_REQUIRE_DECRYPT is used by default.
37+
client = aws_encryption_sdk.EncryptionSDKClient(commitment_policy=CommitmentPolicy.REQUIRE_ENCRYPT_REQUIRE_DECRYPT)
3738

3839
# Create a master key provider for the KMS customer master key (CMK)
3940
key_provider = aws_encryption_sdk.StrictAwsKmsMasterKeyProvider(key_ids=[kms_cmk_arn])

examples/src/discovery_kms_provider.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
# ANY KIND, either express or implied. See the License for the specific
1212
# language governing permissions and limitations under the License.
1313
"""Example showing encryption of a value already in memory using one KMS CMK, then decryption of the ciphertext using
14-
a DiscoveryKMSMasterKeyProvider.
14+
a DiscoveryAwsKmsMasterKeyProvider.
1515
"""
1616
import aws_encryption_sdk
1717
from aws_encryption_sdk import CommitmentPolicy
@@ -32,8 +32,9 @@ def encrypt_decrypt(key_arn, source_plaintext, botocore_session=None):
3232
if botocore_session is not None:
3333
encrypt_kwargs["botocore_session"] = botocore_session
3434

35-
# Set up an encryption client with an explicit commitment policy
36-
client = aws_encryption_sdk.EncryptionSDKClient(commitment_policy=CommitmentPolicy.FORBID_ENCRYPT_ALLOW_DECRYPT)
35+
# Set up an encryption client with an explicit commitment policy. Note that if you do not explicitly choose a
36+
# commitment policy, REQUIRE_ENCRYPT_REQUIRE_DECRYPT is used by default.
37+
client = aws_encryption_sdk.EncryptionSDKClient(commitment_policy=CommitmentPolicy.REQUIRE_ENCRYPT_REQUIRE_DECRYPT)
3738

3839
# Create strict master key provider that is only allowed to encrypt and decrypt using the ARN of the provided key.
3940
strict_key_provider = aws_encryption_sdk.StrictAwsKmsMasterKeyProvider(**encrypt_kwargs)

examples/src/multiple_kms_cmk.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,9 @@ def encrypt_decrypt(key_arns, source_plaintext, botocore_session=None):
2828
if botocore_session is not None:
2929
encrypt_kwargs["botocore_session"] = botocore_session
3030

31-
# Set up an encryption client with an explicit commitment policy
32-
client = aws_encryption_sdk.EncryptionSDKClient(commitment_policy=CommitmentPolicy.FORBID_ENCRYPT_ALLOW_DECRYPT)
31+
# Set up an encryption client with an explicit commitment policy. Note that if you do not explicitly choose a
32+
# commitment policy, REQUIRE_ENCRYPT_REQUIRE_DECRYPT is used by default.
33+
client = aws_encryption_sdk.EncryptionSDKClient(commitment_policy=CommitmentPolicy.REQUIRE_ENCRYPT_REQUIRE_DECRYPT)
3334

3435
# Create strict master key provider that is only allowed to encrypt and decrypt using the ARN of the provided key.
3536
strict_encrypt_key_provider = aws_encryption_sdk.StrictAwsKmsMasterKeyProvider(**encrypt_kwargs)

examples/src/one_kms_cmk.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,9 @@ def encrypt_decrypt(key_arn, source_plaintext, botocore_session=None):
2828
if botocore_session is not None:
2929
kwargs["botocore_session"] = botocore_session
3030

31-
# Set up an encryption client with an explicit commitment policy
32-
client = aws_encryption_sdk.EncryptionSDKClient(commitment_policy=CommitmentPolicy.FORBID_ENCRYPT_ALLOW_DECRYPT)
31+
# Set up an encryption client with an explicit commitment policy. Note that if you do not explicitly choose a
32+
# commitment policy, REQUIRE_ENCRYPT_REQUIRE_DECRYPT is used by default.
33+
client = aws_encryption_sdk.EncryptionSDKClient(commitment_policy=CommitmentPolicy.REQUIRE_ENCRYPT_REQUIRE_DECRYPT)
3334

3435
# Create master key provider using the ARN of the key and the session (botocore_session)
3536
kms_key_provider = aws_encryption_sdk.StrictAwsKmsMasterKeyProvider(**kwargs)

examples/src/one_kms_cmk_streaming_data.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,9 @@ def encrypt_decrypt_stream(key_arn, source_plaintext_filename, botocore_session=
3232
if botocore_session is not None:
3333
kwargs["botocore_session"] = botocore_session
3434

35-
# Set up an encryption client with an explicit commitment policy
36-
client = aws_encryption_sdk.EncryptionSDKClient(commitment_policy=CommitmentPolicy.FORBID_ENCRYPT_ALLOW_DECRYPT)
35+
# Set up an encryption client with an explicit commitment policy. Note that if you do not explicitly choose a
36+
# commitment policy, REQUIRE_ENCRYPT_REQUIRE_DECRYPT is used by default.
37+
client = aws_encryption_sdk.EncryptionSDKClient(commitment_policy=CommitmentPolicy.REQUIRE_ENCRYPT_REQUIRE_DECRYPT)
3738

3839
# Create master key provider using the ARN of the key and the session (botocore_session)
3940
kms_key_provider = aws_encryption_sdk.StrictAwsKmsMasterKeyProvider(**kwargs)

examples/src/one_kms_cmk_unsigned.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
# language governing permissions and limitations under the License.
1313
"""Example showing basic encryption and decryption of a value already in memory
1414
using one AWS KMS CMK with an unsigned algorithm.
15+
16+
Note: We recommend using an algorithm with signing as an AWS Encryption SDK best practice.
1517
"""
1618
import aws_encryption_sdk
1719
from aws_encryption_sdk import StrictAwsKmsMasterKeyProvider
@@ -31,15 +33,16 @@ def encrypt_decrypt(key_arn, source_plaintext, botocore_session=None):
3133
if botocore_session is not None:
3234
kwargs["botocore_session"] = botocore_session
3335

34-
# Set up an encryption client with an explicit commitment policy
35-
client = aws_encryption_sdk.EncryptionSDKClient(commitment_policy=CommitmentPolicy.FORBID_ENCRYPT_ALLOW_DECRYPT)
36+
# Set up an encryption client with an explicit commitment policy. Note that if you do not explicitly choose a
37+
# commitment policy, REQUIRE_ENCRYPT_REQUIRE_DECRYPT is used by default.
38+
client = aws_encryption_sdk.EncryptionSDKClient(commitment_policy=CommitmentPolicy.REQUIRE_ENCRYPT_REQUIRE_DECRYPT)
3639

3740
# Create master key provider using the ARN of the key and the session (botocore_session)
3841
kms_key_provider = StrictAwsKmsMasterKeyProvider(**kwargs)
3942

4043
# Encrypt the plaintext using the AWS Encryption SDK. It returns the encrypted message and the header
4144
ciphertext, encrypted_message_header = client.encrypt(
42-
algorithm=Algorithm.AES_256_GCM_IV12_TAG16_HKDF_SHA256, source=source_plaintext, key_provider=kms_key_provider
45+
algorithm=Algorithm.AES_256_GCM_HKDF_SHA512_COMMIT_KEY, source=source_plaintext, key_provider=kms_key_provider
4346
)
4447

4548
# Decrypt the encrypted message using the AWS Encryption SDK. It returns the decrypted message and the header

0 commit comments

Comments
 (0)