Skip to content

Commit c961999

Browse files
authored
Merge pull request #271 from mattsb42-aws/revert
feat: revert keyrings
2 parents 5628ede + bc00e9b commit c961999

File tree

185 files changed

+1716
-10223
lines changed

Some content is hidden

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

185 files changed

+1716
-10223
lines changed

CHANGELOG.rst

-43
Original file line numberDiff line numberDiff line change
@@ -2,48 +2,6 @@
22
Changelog
33
*********
44

5-
1.5.0 -- 2020-xx-xx
6-
===================
7-
8-
Major Features
9-
--------------
10-
11-
* Add `keyrings`_.
12-
* Change one-step APIs to return a :class:`CryptoResult` rather than a tuple.
13-
14-
* Modified APIs: ``aws_encryption_sdk.encrypt`` and ``aws_encryption_sdk.decrypt``.
15-
16-
.. note::
17-
18-
For backwards compatibility,
19-
:class:`CryptoResult` also unpacks like a 2-member tuple.
20-
This allows for backwards compatibility with the previous outputs
21-
so this change should not break any existing consumers
22-
unless you are specifically relying on the output being an instance of :class:`tuple`.
23-
24-
Deprecations
25-
------------
26-
27-
* Deprecate master key providers in favor of keyrings.
28-
29-
* We still support using master key providers and are not removing them yet.
30-
When we decide to remove them,
31-
we will communicate that as defined in our versioning policy.
32-
33-
* Deprecate support for Python 3.4.
34-
35-
* This does not mean that this library will no longer work or install with 3.4,
36-
but we are no longer testing against or advertising support for 3.4.
37-
38-
Documentation
39-
-------------
40-
41-
* Added new examples demonstrating how to use
42-
APIs, keyrings, cryptographic materials managers, and master key providers.
43-
`#221 <https://github.com/aws/aws-encryption-sdk-python/pull/221>`_
44-
`#236 <https://github.com/aws/aws-encryption-sdk-python/pull/236>`_
45-
`#239 <https://github.com/aws/aws-encryption-sdk-python/pull/239>`_
46-
475
1.4.1 -- 2019-09-20
486
===================
497

@@ -235,4 +193,3 @@ Minor
235193
.. _pylint: https://www.pylint.org/
236194
.. _flake8: http://flake8.pycqa.org/en/latest/
237195
.. _doc8: https://launchpad.net/doc8
238-
.. _keyrings: https://docs.aws.amazon.com/encryption-sdk/latest/developer-guide/choose-keyring.html

README.rst

+173-26
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ Getting Started
3838
Required Prerequisites
3939
======================
4040

41-
* Python 2.7 or 3.5+
41+
* Python 2.7+ or 3.4+
4242
* cryptography >= 1.8.1
4343
* boto3
4444
* attrs
@@ -57,42 +57,189 @@ Installation
5757
5858
Concepts
5959
========
60-
There are three main concepts that are helpful to understand when using the AWS Encryption SDK.
61-
62-
For further information, see the `AWS Encryption SDK developer guide concepts`_.
60+
There are four main concepts that you need to understand to use this library:
6361

6462
Cryptographic Materials Managers
6563
--------------------------------
66-
The cryptographic materials manager (CMM) assembles the cryptographic materials
67-
that are used to encrypt and decrypt data.
64+
Cryptographic materials managers (CMMs) are resources that collect cryptographic materials and prepare them for
65+
use by the Encryption SDK core logic.
6866

69-
`For more details,
70-
see the AWS Encryption SDK developer guide cryptographic materials manager concept.
71-
<https://docs.aws.amazon.com/encryption-sdk/latest/developer-guide/concepts.html#crypt-materials-manager>`_
67+
An example of a CMM is the default CMM, which is automatically generated anywhere a caller provides a master
68+
key provider. The default CMM collects encrypted data keys from all master keys referenced by the master key
69+
provider.
7270

73-
Keyrings
74-
--------
71+
An example of a more advanced CMM is the caching CMM, which caches cryptographic materials provided by another CMM.
7572

76-
A keyring generates, encrypts, and decrypts data keys.
73+
Master Key Providers
74+
--------------------
75+
Master key providers are resources that provide master keys.
76+
An example of a master key provider is `AWS KMS`_.
7777

78-
`For more details,
79-
see the AWS Encryption SDK developer guide keyring concept.
80-
<https://docs.aws.amazon.com/encryption-sdk/latest/developer-guide/concepts.html#keyring>`_
78+
To encrypt data in this client, a ``MasterKeyProvider`` object must contain at least one ``MasterKey`` object.
8179

82-
Data Keys
83-
---------
80+
``MasterKeyProvider`` objects can also contain other ``MasterKeyProvider`` objects.
8481

85-
A data key is an encryption key that the AWS Encryption SDK uses to encrypt your data.
82+
Master Keys
83+
-----------
84+
Master keys generate, encrypt, and decrypt data keys.
85+
An example of a master key is a `KMS customer master key (CMK)`_.
8686

87-
`For more details,
88-
see the AWS Encryption SDK developer guide data key concept.
89-
<https://docs.aws.amazon.com/encryption-sdk/latest/developer-guide/concepts.html#DEK>`_
87+
Data Keys
88+
---------
89+
Data keys are the encryption keys that are used to encrypt your data. If your algorithm suite
90+
uses a key derivation function, the data key is used to generate the key that directly encrypts the data.
9091

9192
*****
9293
Usage
9394
*****
95+
To use this client, you (the caller) must provide an instance of either a master key provider
96+
or a CMM. The examples in this readme use the ``KMSMasterKeyProvider`` class.
97+
98+
KMSMasterKeyProvider
99+
====================
100+
Because the ``KMSMasterKeyProvider`` uses the `boto3 SDK`_ to interact with `AWS KMS`_, it requires AWS Credentials.
101+
To provide these credentials, use the `standard means by which boto3 locates credentials`_ or provide a
102+
pre-existing instance of a ``botocore session`` to the ``KMSMasterKeyProvider``.
103+
This latter option can be useful if you have an alternate way to store your AWS credentials or
104+
you want to reuse an existing instance of a botocore session in order to decrease startup costs.
105+
106+
.. code:: python
107+
108+
import aws_encryption_sdk
109+
import botocore.session
110+
111+
kms_key_provider = aws_encryption_sdk.KMSMasterKeyProvider()
112+
113+
existing_botocore_session = botocore.session.Session()
114+
kms_key_provider = aws_encryption_sdk.KMSMasterKeyProvider(botocore_session=existing_botocore_session)
115+
116+
117+
You can pre-load the ``KMSMasterKeyProvider`` with one or more CMKs.
118+
To encrypt data, you must configure the ``KMSMasterKeyProvider`` with as least one CMK.
119+
If you configure the the ``KMSMasterKeyProvider`` with multiple CMKs, the `final message`_
120+
will include a copy of the data key encrypted by each configured CMK.
121+
122+
.. code:: python
123+
124+
import aws_encryption_sdk
125+
126+
kms_key_provider = aws_encryption_sdk.KMSMasterKeyProvider(key_ids=[
127+
'arn:aws:kms:us-east-1:2222222222222:key/22222222-2222-2222-2222-222222222222',
128+
'arn:aws:kms:us-east-1:3333333333333:key/33333333-3333-3333-3333-333333333333'
129+
])
130+
131+
You can add CMKs from multiple regions to the ``KMSMasterKeyProvider``.
132+
133+
.. code:: python
134+
135+
import aws_encryption_sdk
136+
137+
kms_key_provider = aws_encryption_sdk.KMSMasterKeyProvider(key_ids=[
138+
'arn:aws:kms:us-east-1:2222222222222:key/22222222-2222-2222-2222-222222222222',
139+
'arn:aws:kms:us-west-2:3333333333333:key/33333333-3333-3333-3333-333333333333',
140+
'arn:aws:kms:ap-northeast-1:4444444444444:key/44444444-4444-4444-4444-444444444444'
141+
])
142+
143+
144+
Encryption and Decryption
145+
=========================
146+
After you create an instance of a ``MasterKeyProvider``, you can use either of the two
147+
high-level ``encrypt``/``decrypt`` functions to encrypt and decrypt your data.
148+
149+
.. code:: python
150+
151+
import aws_encryption_sdk
152+
153+
kms_key_provider = aws_encryption_sdk.KMSMasterKeyProvider(key_ids=[
154+
'arn:aws:kms:us-east-1:2222222222222:key/22222222-2222-2222-2222-222222222222',
155+
'arn:aws:kms:us-east-1:3333333333333:key/33333333-3333-3333-3333-333333333333'
156+
])
157+
my_plaintext = b'This is some super secret data! Yup, sure is!'
158+
159+
my_ciphertext, encryptor_header = aws_encryption_sdk.encrypt(
160+
source=my_plaintext,
161+
key_provider=kms_key_provider
162+
)
163+
164+
decrypted_plaintext, decryptor_header = aws_encryption_sdk.decrypt(
165+
source=my_ciphertext,
166+
key_provider=kms_key_provider
167+
)
168+
169+
assert my_plaintext == decrypted_plaintext
170+
assert encryptor_header.encryption_context == decryptor_header.encryption_context
171+
172+
You can provide an `encryption context`_: a form of additional authenticating information.
173+
174+
.. code:: python
175+
176+
import aws_encryption_sdk
177+
178+
kms_key_provider = aws_encryption_sdk.KMSMasterKeyProvider(key_ids=[
179+
'arn:aws:kms:us-east-1:2222222222222:key/22222222-2222-2222-2222-222222222222',
180+
'arn:aws:kms:us-east-1:3333333333333:key/33333333-3333-3333-3333-333333333333'
181+
])
182+
my_plaintext = b'This is some super secret data! Yup, sure is!'
183+
184+
my_ciphertext, encryptor_header = aws_encryption_sdk.encrypt(
185+
source=my_plaintext,
186+
key_provider=kms_key_provider,
187+
encryption_context={
188+
'not really': 'a secret',
189+
'but adds': 'some authentication'
190+
}
191+
)
192+
193+
decrypted_plaintext, decryptor_header = aws_encryption_sdk.decrypt(
194+
source=my_ciphertext,
195+
key_provider=kms_key_provider
196+
)
197+
198+
assert my_plaintext == decrypted_plaintext
199+
assert encryptor_header.encryption_context == decryptor_header.encryption_context
200+
201+
202+
Streaming
203+
=========
204+
If you are handling large files or simply do not want to put the entire plaintext or ciphertext in
205+
memory at once, you can use this library's streaming clients directly. The streaming clients are
206+
file-like objects, and behave exactly as you would expect a Python file object to behave,
207+
offering context manager and iteration support.
208+
209+
.. code:: python
210+
211+
import aws_encryption_sdk
212+
import filecmp
213+
214+
kms_key_provider = aws_encryption_sdk.KMSMasterKeyProvider(key_ids=[
215+
'arn:aws:kms:us-east-1:2222222222222:key/22222222-2222-2222-2222-222222222222',
216+
'arn:aws:kms:us-east-1:3333333333333:key/33333333-3333-3333-3333-333333333333'
217+
])
218+
plaintext_filename = 'my-secret-data.dat'
219+
ciphertext_filename = 'my-encrypted-data.ct'
220+
221+
with open(plaintext_filename, 'rb') as pt_file, open(ciphertext_filename, 'wb') as ct_file:
222+
with aws_encryption_sdk.stream(
223+
mode='e',
224+
source=pt_file,
225+
key_provider=kms_key_provider
226+
) as encryptor:
227+
for chunk in encryptor:
228+
ct_file.write(chunk)
229+
230+
new_plaintext_filename = 'my-decrypted-data.dat'
94231
95-
For examples of how to use these concepts to accomplish different tasks, see our `examples`_.
232+
with open(ciphertext_filename, 'rb') as ct_file, open(new_plaintext_filename, 'wb') as pt_file:
233+
with aws_encryption_sdk.stream(
234+
mode='d',
235+
source=ct_file,
236+
key_provider=kms_key_provider
237+
) as decryptor:
238+
for chunk in decryptor:
239+
pt_file.write(chunk)
240+
241+
assert filecmp.cmp(plaintext_filename, new_plaintext_filename)
242+
assert encryptor.header.encryption_context == decryptor.header.encryption_context
96243
97244
Performance Considerations
98245
==========================
@@ -104,14 +251,14 @@ to your use-case in order to obtain peak performance.
104251

105252

106253
.. _AWS Encryption SDK: https://docs.aws.amazon.com/encryption-sdk/latest/developer-guide/introduction.html
107-
.. _AWS Encryption SDK developer guide concepts:
108-
https://docs.aws.amazon.com/encryption-sdk/latest/developer-guide/concepts.html
109254
.. _cryptography: https://cryptography.io/en/latest/
110255
.. _cryptography installation guide: https://cryptography.io/en/latest/installation/
111256
.. _Read the Docs: http://aws-encryption-sdk-python.readthedocs.io/en/latest/
112257
.. _GitHub: https://github.com/aws/aws-encryption-sdk-python/
113258
.. _AWS KMS: https://docs.aws.amazon.com/kms/latest/developerguide/overview.html
114259
.. _KMS customer master key (CMK): https://docs.aws.amazon.com/kms/latest/developerguide/concepts.html#master_keys
260+
.. _boto3 SDK: https://boto3.readthedocs.io/en/latest/
261+
.. _standard means by which boto3 locates credentials: https://boto3.readthedocs.io/en/latest/guide/configuration.html
262+
.. _final message: https://docs.aws.amazon.com/encryption-sdk/latest/developer-guide/message-format.html
115263
.. _encryption context: https://docs.aws.amazon.com/kms/latest/developerguide/concepts.html#encrypt_context
116-
.. _examples: https://github.com/aws/aws-encryption-sdk-python/tree/master/examples
117-
.. _Security issue notifications: https://github.com/aws/aws-encryption-sdk-python/tree/master/CONTRIBUTING.md#security-issue-notifications
264+
.. _Security issue notifications: ./CONTRIBUTING.md#security-issue-notifications

0 commit comments

Comments
 (0)