@@ -92,76 +92,121 @@ uses a key derivation function, the data key is used to generate the key that di
92
92
*****
93
93
Usage
94
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
95
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.
96
+ EncryptionSDKClient
97
+ ===================
98
+ 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 ``.
105
101
106
102
.. code :: python
107
103
108
104
import aws_encryption_sdk
109
- import botocore.session
105
+ from aws_encryption_sdk.identifiers import CommitmentPolicy
106
+
107
+
108
+ client = aws_encryption_sdk.EncryptionSDKClient(
109
+ commitment_policy = CommitmentPolicy.FORBID_ENCRYPT_ALLOW_DECRYPT
110
+ )
111
+
110
112
111
- kms_key_provider = aws_encryption_sdk.KMSMasterKeyProvider()
113
+ You must then create an instance of either a master key provider or a CMM. The examples in this
114
+ readme use the ``StrictAwsKmsMasterKeyProvider `` class.
112
115
113
- existing_botocore_session = botocore.session.Session()
114
- kms_key_provider = aws_encryption_sdk.KMSMasterKeyProvider(botocore_session = existing_botocore_session)
115
116
117
+ StrictAwsKmsMasterKeyProvider
118
+ =============================
119
+ A ``StrictAwsKmsMasterKeyProvider `` is configured with an explicit list of AWS KMS
120
+ CMKs with which to encrypt and decrypt data. On encryption, it encrypts the plaintext with all
121
+ configured CMKs. On decryption, it only attempts to decrypt ciphertexts that have been wrapped
122
+ with one of the configured CMKs.
116
123
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 `_
124
+ Because the ``StrictAwsKmsMasterKeyProvider `` uses the `boto3 SDK `_ to interact with `AWS KMS `_,
125
+ it requires AWS Credentials.
126
+ To provide these credentials, use the `standard means by which boto3 locates credentials `_ or provide a
127
+ pre-existing instance of a ``botocore session `` to the ``StrictAwsKmsMasterKeyProvider ``.
128
+ This latter option can be useful if you have an alternate way to store your AWS credentials or
129
+ you want to reuse an existing instance of a botocore session in order to decrease startup costs.
130
+
131
+ To create a ``StrictAwsKmsMasterKeyProvider `` you must provide one or more CMKs.
132
+ If you configure the the ``StrictAwsKmsMasterKeyProvider `` with multiple CMKs, the `final message `_
120
133
will include a copy of the data key encrypted by each configured CMK.
121
134
122
135
.. code :: python
123
136
124
137
import aws_encryption_sdk
125
138
126
- kms_key_provider = aws_encryption_sdk.KMSMasterKeyProvider (key_ids = [
139
+ kms_key_provider = aws_encryption_sdk.StrictAwsKmsMasterKeyProvider (key_ids = [
127
140
' arn:aws:kms:us-east-1:2222222222222:key/22222222-2222-2222-2222-222222222222' ,
128
141
' arn:aws:kms:us-east-1:3333333333333:key/33333333-3333-3333-3333-333333333333'
129
142
])
130
143
131
- You can add CMKs from multiple regions to the ``KMSMasterKeyProvider ``.
144
+ You can add CMKs from multiple regions to the ``StrictAwsKmsMasterKeyProvider ``.
132
145
133
146
.. code :: python
134
147
135
148
import aws_encryption_sdk
136
149
137
- kms_key_provider = aws_encryption_sdk.KMSMasterKeyProvider (key_ids = [
150
+ kms_key_provider = aws_encryption_sdk.StrictAwsKmsMasterKeyProvider (key_ids = [
138
151
' arn:aws:kms:us-east-1:2222222222222:key/22222222-2222-2222-2222-222222222222' ,
139
152
' arn:aws:kms:us-west-2:3333333333333:key/33333333-3333-3333-3333-333333333333' ,
140
153
' arn:aws:kms:ap-northeast-1:4444444444444:key/44444444-4444-4444-4444-444444444444'
141
154
])
142
155
143
156
157
+ DiscoveryAwsKmsMasterKeyProvider
158
+ ================================
159
+ We recommend using a ``StrictAwsKmsMasterKeyProvider `` in order to ensure that you can only
160
+ encrypt and decrypt data using the AWS KMS CMKs you expect. However, if you are unable to
161
+ explicitly identify the AWS KMS CMKs that should be used for decryption, you can instead
162
+ use a ``DiscoveryAwsKmsMasterKeyProvider `` for decryption operations. This provider
163
+ attempts decryption of any ciphertexts as long as they match a ``DiscoveryFilter `` that
164
+ you configure. A ``DiscoveryFilter `` consists of a list of AWS account ids and an AWS
165
+ partition.
166
+
167
+ .. code :: python
168
+
169
+ import aws_encryption_sdk
170
+ from aws_encryption_sdk.key_providers.kms import DiscoveryFilter
171
+
172
+ discovery_filter = DiscoveryFilter(
173
+ account_ids = [' 222222222222' , ' 333333333333' ],
174
+ partition = ' aws'
175
+ )
176
+ kms_key_provider = aws_encryption_sdk.DiscoveryAwsKmsMasterKeyProvider(
177
+ discovery_filter = discovery_filter
178
+ )
179
+
180
+ If you do not want to filter the set of allowed accounts, you can also omit the ``discovery_filter `` argument.
181
+
182
+ Note that a ``DiscoveryAwsKmsMasterKeyProvider `` cannot be used for encryption operations.
183
+
144
184
Encryption and Decryption
145
185
=========================
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.
186
+ After you create an instance of an `` EncryptionSDKClient `` and a ``MasterKeyProvider ``, you can use either of
187
+ the client's two ``encrypt ``/``decrypt `` functions to encrypt and decrypt your data.
148
188
149
189
.. code :: python
150
190
151
191
import aws_encryption_sdk
192
+ from aws_encryption_sdk.identifiers import CommitmentPolicy
152
193
153
- kms_key_provider = aws_encryption_sdk.KMSMasterKeyProvider(key_ids = [
194
+ client = aws_encryption_sdk.EncryptionSDKClient(
195
+ commitment_policy = CommitmentPolicy.FORBID_ENCRYPT_ALLOW_DECRYPT
196
+ )
197
+
198
+ kms_key_provider = aws_encryption_sdk.StrictAwsKmsMasterKeyProvider(key_ids = [
154
199
' arn:aws:kms:us-east-1:2222222222222:key/22222222-2222-2222-2222-222222222222' ,
155
200
' arn:aws:kms:us-east-1:3333333333333:key/33333333-3333-3333-3333-333333333333'
156
201
])
157
202
my_plaintext = b ' This is some super secret data! Yup, sure is!'
158
203
159
- my_ciphertext, encryptor_header = aws_encryption_sdk .encrypt(
204
+ my_ciphertext, encryptor_header = client .encrypt(
160
205
source = my_plaintext,
161
206
key_provider = kms_key_provider
162
207
)
163
208
164
- decrypted_plaintext, decryptor_header = aws_encryption_sdk .decrypt(
209
+ decrypted_plaintext, decryptor_header = client .decrypt(
165
210
source = my_ciphertext,
166
211
key_provider = kms_key_provider
167
212
)
@@ -174,14 +219,19 @@ You can provide an `encryption context`_: a form of additional authenticating in
174
219
.. code :: python
175
220
176
221
import aws_encryption_sdk
222
+ from aws_encryption_sdk.identifiers import CommitmentPolicy
223
+
224
+ client = aws_encryption_sdk.EncryptionSDKClient(
225
+ commitment_policy = CommitmentPolicy.FORBID_ENCRYPT_ALLOW_DECRYPT
226
+ )
177
227
178
- kms_key_provider = aws_encryption_sdk.KMSMasterKeyProvider (key_ids = [
228
+ kms_key_provider = aws_encryption_sdk.StrictAwsKmsMasterKeyProvider (key_ids = [
179
229
' arn:aws:kms:us-east-1:2222222222222:key/22222222-2222-2222-2222-222222222222' ,
180
230
' arn:aws:kms:us-east-1:3333333333333:key/33333333-3333-3333-3333-333333333333'
181
231
])
182
232
my_plaintext = b ' This is some super secret data! Yup, sure is!'
183
233
184
- my_ciphertext, encryptor_header = aws_encryption_sdk .encrypt(
234
+ my_ciphertext, encryptor_header = client .encrypt(
185
235
source = my_plaintext,
186
236
key_provider = kms_key_provider,
187
237
encryption_context = {
@@ -190,7 +240,7 @@ You can provide an `encryption context`_: a form of additional authenticating in
190
240
}
191
241
)
192
242
193
- decrypted_plaintext, decryptor_header = aws_encryption_sdk .decrypt(
243
+ decrypted_plaintext, decryptor_header = client .decrypt(
194
244
source = my_ciphertext,
195
245
key_provider = kms_key_provider
196
246
)
@@ -209,17 +259,22 @@ offering context manager and iteration support.
209
259
.. code :: python
210
260
211
261
import aws_encryption_sdk
262
+ from aws_encryption_sdk.identifiers import CommitmentPolicy
212
263
import filecmp
213
264
214
- kms_key_provider = aws_encryption_sdk.KMSMasterKeyProvider(key_ids = [
265
+ client = aws_encryption_sdk.EncryptionSDKClient(
266
+ commitment_policy = CommitmentPolicy.FORBID_ENCRYPT_ALLOW_DECRYPT
267
+ )
268
+
269
+ kms_key_provider = aws_encryption_sdk.StrictAwsKmsMasterKeyProvider(key_ids = [
215
270
' arn:aws:kms:us-east-1:2222222222222:key/22222222-2222-2222-2222-222222222222' ,
216
271
' arn:aws:kms:us-east-1:3333333333333:key/33333333-3333-3333-3333-333333333333'
217
272
])
218
273
plaintext_filename = ' my-secret-data.dat'
219
274
ciphertext_filename = ' my-encrypted-data.ct'
220
275
221
276
with open (plaintext_filename, ' rb' ) as pt_file, open (ciphertext_filename, ' wb' ) as ct_file:
222
- with aws_encryption_sdk .stream(
277
+ with client .stream(
223
278
mode = ' e' ,
224
279
source = pt_file,
225
280
key_provider = kms_key_provider
@@ -230,7 +285,7 @@ offering context manager and iteration support.
230
285
new_plaintext_filename = ' my-decrypted-data.dat'
231
286
232
287
with open (ciphertext_filename, ' rb' ) as ct_file, open (new_plaintext_filename, ' wb' ) as pt_file:
233
- with aws_encryption_sdk .stream(
288
+ with client .stream(
234
289
mode = ' d' ,
235
290
source = ct_file,
236
291
key_provider = kms_key_provider
0 commit comments