@@ -38,7 +38,7 @@ Getting Started
38
38
Required Prerequisites
39
39
======================
40
40
41
- * Python 2.7 or 3.5 +
41
+ * Python 2.7+ or 3.4 +
42
42
* cryptography >= 1.8.1
43
43
* boto3
44
44
* attrs
@@ -57,42 +57,189 @@ Installation
57
57
58
58
Concepts
59
59
========
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:
63
61
64
62
Cryptographic Materials Managers
65
63
--------------------------------
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 .
68
66
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.
72
70
73
- Keyrings
74
- --------
71
+ An example of a more advanced CMM is the caching CMM, which caches cryptographic materials provided by another CMM.
75
72
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 `_.
77
77
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.
81
79
82
- Data Keys
83
- ---------
80
+ ``MasterKeyProvider `` objects can also contain other ``MasterKeyProvider `` objects.
84
81
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) `_.
86
86
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.
90
91
91
92
*****
92
93
Usage
93
94
*****
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'
94
231
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
96
243
97
244
Performance Considerations
98
245
==========================
@@ -104,14 +251,14 @@ to your use-case in order to obtain peak performance.
104
251
105
252
106
253
.. _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
109
254
.. _cryptography : https://cryptography.io/en/latest/
110
255
.. _cryptography installation guide : https://cryptography.io/en/latest/installation/
111
256
.. _Read the Docs : http://aws-encryption-sdk-python.readthedocs.io/en/latest/
112
257
.. _GitHub : https://github.com/aws/aws-encryption-sdk-python/
113
258
.. _AWS KMS : https://docs.aws.amazon.com/kms/latest/developerguide/overview.html
114
259
.. _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
115
263
.. _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