Skip to content

Commit cbec7e1

Browse files
authored
Merge branch 'master' into jocorell/changelog-version-405
2 parents 8ea84e4 + 241c007 commit cbec7e1

2 files changed

Lines changed: 58 additions & 0 deletions

File tree

src/aws_encryption_sdk/streaming_client.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -553,6 +553,8 @@ def _prep_message(self):
553553
request=encryption_materials_request
554554
)
555555

556+
validate_commitment_policy_on_encrypt(self.config.commitment_policy, self._encryption_materials.algorithm)
557+
556558
if self.config.algorithm is not None and self._encryption_materials.algorithm != self.config.algorithm:
557559
raise ActionNotAllowedError(
558560
(

test/functional/test_f_commitment.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,3 +225,59 @@ def test_encrypt_with_uncommitting_algorithm_require_decrypt():
225225
with pytest.raises(ActionNotAllowedError) as excinfo:
226226
decrypting_client.decrypt(source=ciphertext, key_provider=key_provider)
227227
excinfo.match("Configuration conflict. Cannot decrypt due to .* requiring only committed messages")
228+
229+
230+
def test_encrypt_with_require_policy_fail_when_retrieving_invalid_cmm_materials():
231+
"""Tests that when a client with a require policy shares a cache with a client with a forbid policy
232+
an error gets thrown due to invalid materials retrieved from cmm"""
233+
forbid_encrypting_client = aws_encryption_sdk.EncryptionSDKClient(
234+
commitment_policy=CommitmentPolicy.FORBID_ENCRYPT_ALLOW_DECRYPT
235+
)
236+
required_encrypting_client = aws_encryption_sdk.EncryptionSDKClient(
237+
commitment_policy=CommitmentPolicy.REQUIRE_ENCRYPT_REQUIRE_DECRYPT
238+
)
239+
240+
provider = StaticRawMasterKeyProvider(
241+
wrapping_algorithm=WrappingAlgorithm.AES_256_GCM_IV12_TAG16_NO_PADDING,
242+
encryption_key_type=EncryptionKeyType.SYMMETRIC,
243+
key_bytes=b"\00" * 32,
244+
)
245+
provider.add_master_key("KeyId")
246+
cache = aws_encryption_sdk.LocalCryptoMaterialsCache(capacity=10)
247+
ccmm = aws_encryption_sdk.CachingCryptoMaterialsManager(
248+
master_key_provider=provider, cache=cache, max_age=3600.0, max_messages_encrypted=5
249+
)
250+
plaintext = b"Yellow Submarine"
251+
252+
_, _ = forbid_encrypting_client.encrypt(source=plaintext, materials_manager=ccmm)
253+
with pytest.raises(ActionNotAllowedError) as excinfo:
254+
required_encrypting_client.encrypt(source=plaintext, materials_manager=ccmm)
255+
excinfo.match("Configuration conflict. Cannot encrypt due to .* requiring only committed messages")
256+
257+
258+
def test_encrypt_with_forbid_policy_fail_when_retrieving_invalid_cmm_materials():
259+
"""Tests that when a client with a forbid policy shares a cache with a client with a require policy
260+
an error gets thrown due to invalid materials retrieved from cmm"""
261+
forbid_encrypting_client = aws_encryption_sdk.EncryptionSDKClient(
262+
commitment_policy=CommitmentPolicy.FORBID_ENCRYPT_ALLOW_DECRYPT
263+
)
264+
required_encrypting_client = aws_encryption_sdk.EncryptionSDKClient(
265+
commitment_policy=CommitmentPolicy.REQUIRE_ENCRYPT_REQUIRE_DECRYPT
266+
)
267+
268+
provider = StaticRawMasterKeyProvider(
269+
wrapping_algorithm=WrappingAlgorithm.AES_256_GCM_IV12_TAG16_NO_PADDING,
270+
encryption_key_type=EncryptionKeyType.SYMMETRIC,
271+
key_bytes=b"\00" * 32,
272+
)
273+
provider.add_master_key("KeyId")
274+
cache = aws_encryption_sdk.LocalCryptoMaterialsCache(capacity=10)
275+
ccmm = aws_encryption_sdk.CachingCryptoMaterialsManager(
276+
master_key_provider=provider, cache=cache, max_age=3600.0, max_messages_encrypted=5
277+
)
278+
plaintext = b"Yellow Submarine"
279+
280+
_, _ = required_encrypting_client.encrypt(source=plaintext, materials_manager=ccmm)
281+
with pytest.raises(ActionNotAllowedError) as excinfo:
282+
forbid_encrypting_client.encrypt(source=plaintext, materials_manager=ccmm)
283+
excinfo.match("Configuration conflict. Cannot encrypt due to .* requiring only non-committed messages.")

0 commit comments

Comments
 (0)