Skip to content

Commit a0eb2ae

Browse files
texastonyalex-chewrobin-awsfarleyb-amazon
authored
feat: Improvements to the message decryption process (#23)
See GHSA-x5h4-9gqw-942j Co-authored-by: Alex Chew <[email protected]> Co-authored-by: Robin Salkeld <[email protected]> Co-authored-by: Benjamin Farley <[email protected]>
1 parent 2e6997c commit a0eb2ae

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+659
-326
lines changed

buildspec.yml

+10-35
Original file line numberDiff line numberDiff line change
@@ -7,67 +7,42 @@ batch:
77
buildspec: codebuild/py27/integ.yml
88
- identifier: py27_examples
99
buildspec: codebuild/py27/examples.yml
10-
- identifier: py27_awses_1_7_1
11-
buildspec: codebuild/py27/awses_1.7.1.yml
12-
- identifier: py27_awses_2_0_0
13-
buildspec: codebuild/py27/awses_2.0.0.yml
14-
- identifier: py27_awses_latest
15-
buildspec: codebuild/py27/awses_latest.yml
10+
- identifier: py27_awses_local
11+
buildspec: codebuild/py27/awses_local.yml
1612

1713
- identifier: py35_integ
1814
buildspec: codebuild/py35/integ.yml
1915
- identifier: py35_examples
2016
buildspec: codebuild/py35/examples.yml
21-
- identifier: py35_awses_1_7_1
22-
buildspec: codebuild/py35/awses_1.7.1.yml
23-
- identifier: py35_awses_2_0_0
24-
buildspec: codebuild/py35/awses_2.0.0.yml
25-
- identifier: py35_awses_latest
26-
buildspec: codebuild/py35/awses_latest.yml
17+
- identifier: py35_awses_local
18+
buildspec: codebuild/py35/awses_local.yml
2719

2820
- identifier: py36_integ
2921
buildspec: codebuild/py36/integ.yml
3022
- identifier: py36_examples
3123
buildspec: codebuild/py36/examples.yml
32-
- identifier: py36_awses_1_7_1
33-
buildspec: codebuild/py36/awses_1.7.1.yml
34-
- identifier: py36_awses_2_0_0
35-
buildspec: codebuild/py36/awses_2.0.0.yml
36-
- identifier: py36_awses_latest
37-
buildspec: codebuild/py36/awses_latest.yml
24+
- identifier: py36_awses_local
25+
buildspec: codebuild/py36/awses_local.yml
3826

3927
- identifier: py37_integ
4028
buildspec: codebuild/py37/integ.yml
4129
- identifier: py37_examples
4230
buildspec: codebuild/py37/examples.yml
43-
- identifier: py37_awses_1_7_1
44-
buildspec: codebuild/py37/awses_1.7.1.yml
45-
- identifier: py37_awses_2_0_0
46-
buildspec: codebuild/py37/awses_2.0.0.yml
47-
- identifier: py37_awses_latest
48-
buildspec: codebuild/py37/awses_latest.yml
31+
- identifier: py37_awses_local
32+
buildspec: codebuild/py37/awses_local.yml
4933

5034
- identifier: py38_integ
5135
buildspec: codebuild/py38/integ.yml
5236
- identifier: py38_examples
5337
buildspec: codebuild/py38/examples.yml
54-
- identifier: py38_awses_1_7_1
55-
buildspec: codebuild/py38/awses_1.7.1.yml
56-
- identifier: py38_awses_2_0_0
57-
buildspec: codebuild/py38/awses_2.0.0.yml
58-
- identifier: py38_awses_latest
59-
buildspec: codebuild/py38/awses_latest.yml
38+
- identifier: py38_awses_local
39+
buildspec: codebuild/py38/awses_local.yml
6040

6141
- identifier: py39_integ
6242
buildspec: codebuild/py39/integ.yml
6343
- identifier: py39_examples
6444
buildspec: codebuild/py39/examples.yml
65-
- identifier: py39_awses_1_7_1
66-
buildspec: codebuild/py39/awses_1.7.1.yml
67-
- identifier: py39_awses_2_0_0
68-
buildspec: codebuild/py39/awses_2.0.0.yml
6945
- identifier: py39_awses_latest
70-
buildspec: codebuild/py39/awses_latest.yml
7146

7247
- identifier: code_coverage
7348
buildspec: codebuild/coverage/coverage.yml

codebuild/py27/awses_latest.yml

-21
This file was deleted.

codebuild/py27/awses_1.7.1.yml renamed to codebuild/py27/awses_local.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ version: 0.2
22

33
env:
44
variables:
5-
TOXENV: "py27-awses_1.7.1"
5+
TOXENV: "py27-awses_local"
66
AWS_ENCRYPTION_SDK_PYTHON_INTEGRATION_TEST_AWS_KMS_KEY_ID: >-
77
arn:aws:kms:us-west-2:658956600833:key/b3537ef1-d8dc-4780-9f5a-55776cbb2f7f
88
AWS_ENCRYPTION_SDK_PYTHON_INTEGRATION_TEST_AWS_KMS_KEY_ID_2: >-

codebuild/py35/awses_1.7.1.yml

-23
This file was deleted.

codebuild/py35/awses_latest.yml

-23
This file was deleted.

codebuild/py35/awses_2.0.0.yml renamed to codebuild/py35/awses_local.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ version: 0.2
22

33
env:
44
variables:
5-
TOXENV: "py35-awses_2.0.0"
5+
TOXENV: "py35-awses_local"
66
AWS_ENCRYPTION_SDK_PYTHON_INTEGRATION_TEST_AWS_KMS_KEY_ID: >-
77
arn:aws:kms:us-west-2:658956600833:key/b3537ef1-d8dc-4780-9f5a-55776cbb2f7f
88
AWS_ENCRYPTION_SDK_PYTHON_INTEGRATION_TEST_AWS_KMS_KEY_ID_2: >-

codebuild/py36/awses_1.7.1.yml

-21
This file was deleted.

codebuild/py36/awses_latest.yml

-21
This file was deleted.

codebuild/py27/awses_2.0.0.yml renamed to codebuild/py36/awses_local.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ version: 0.2
22

33
env:
44
variables:
5-
TOXENV: "py27-awses_2.0.0"
5+
TOXENV: "py36-awses_local"
66
AWS_ENCRYPTION_SDK_PYTHON_INTEGRATION_TEST_AWS_KMS_KEY_ID: >-
77
arn:aws:kms:us-west-2:658956600833:key/b3537ef1-d8dc-4780-9f5a-55776cbb2f7f
88
AWS_ENCRYPTION_SDK_PYTHON_INTEGRATION_TEST_AWS_KMS_KEY_ID_2: >-

codebuild/py37/awses_1.7.1.yml

-23
This file was deleted.

codebuild/py37/awses_latest.yml

-23
This file was deleted.

codebuild/py37/awses_2.0.0.yml renamed to codebuild/py37/awses_local.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ version: 0.2
22

33
env:
44
variables:
5-
TOXENV: "py37-awses_2.0.0"
5+
TOXENV: "py37-awses_local"
66
AWS_ENCRYPTION_SDK_PYTHON_INTEGRATION_TEST_AWS_KMS_KEY_ID: >-
77
arn:aws:kms:us-west-2:658956600833:key/b3537ef1-d8dc-4780-9f5a-55776cbb2f7f
88
AWS_ENCRYPTION_SDK_PYTHON_INTEGRATION_TEST_AWS_KMS_KEY_ID_2: >-

codebuild/py38/awses_1.7.1.yml

-21
This file was deleted.

codebuild/py38/awses_2.0.0.yml

-21
This file was deleted.

codebuild/py38/awses_latest.yml

-21
This file was deleted.

codebuild/py36/awses_2.0.0.yml renamed to codebuild/py38/awses_local.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ version: 0.2
22

33
env:
44
variables:
5-
TOXENV: "py36-awses_2.0.0"
5+
TOXENV: "py38-awses_local"
66
AWS_ENCRYPTION_SDK_PYTHON_INTEGRATION_TEST_AWS_KMS_KEY_ID: >-
77
arn:aws:kms:us-west-2:658956600833:key/b3537ef1-d8dc-4780-9f5a-55776cbb2f7f
88
AWS_ENCRYPTION_SDK_PYTHON_INTEGRATION_TEST_AWS_KMS_KEY_ID_2: >-

examples/src/basic_file_encryption_with_multiple_providers.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -103,18 +103,18 @@ def cycle_file(key_arn, source_plaintext_filename, botocore_session=None):
103103
ciphertext.write(chunk)
104104

105105
# Decrypt the ciphertext with only the AWS KMS master key
106+
# Buffer the data in memory before writing to disk to ensure the signature is verified first.
106107
with open(ciphertext_filename, "rb") as ciphertext, open(cycled_kms_plaintext_filename, "wb") as plaintext:
107108
with client.stream(
108109
source=ciphertext, mode="d", key_provider=aws_encryption_sdk.StrictAwsKmsMasterKeyProvider(**kms_kwargs)
109110
) as kms_decryptor:
110-
for chunk in kms_decryptor:
111-
plaintext.write(chunk)
111+
plaintext.write(kms_decryptor.read())
112112

113113
# Decrypt the ciphertext with only the static master key
114+
# Buffer the data in memory before writing to disk to ensure the signature is verified first.
114115
with open(ciphertext_filename, "rb") as ciphertext, open(cycled_static_plaintext_filename, "wb") as plaintext:
115116
with client.stream(source=ciphertext, mode="d", key_provider=static_master_key_provider) as static_decryptor:
116-
for chunk in static_decryptor:
117-
plaintext.write(chunk)
117+
plaintext.write(static_decryptor.read())
118118

119119
# Verify that the "cycled" (encrypted, then decrypted) plaintext is identical to the source plaintext
120120
assert filecmp.cmp(source_plaintext_filename, cycled_kms_plaintext_filename)

0 commit comments

Comments
 (0)