Skip to content

chore(MPL): Update README and primary pydocs #658

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 404 commits into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from 250 commits
Commits
Show all changes
404 commits
Select commit Hold shift + click to select a range
40fecc0
all message format versions
lucasmcdonald3 Feb 29, 2024
52043b9
sync upstream
lucasmcdonald3 Feb 29, 2024
d256bf5
working
lucasmcdonald3 Mar 6, 2024
488bdda
cleanup
lucasmcdonald3 Mar 6, 2024
cea9dab
cleanup:
lucasmcdonald3 Mar 7, 2024
98fd0af
fix testvector run
lucasmcdonald3 Mar 7, 2024
b4ba23c
rm module_
lucasmcdonald3 Mar 7, 2024
3e6dfa1
kwargify input
lucasmcdonald3 Mar 7, 2024
bcc689c
fix testvector
lucasmcdonald3 Mar 7, 2024
ca3e165
cleanup
lucasmcdonald3 Mar 7, 2024
d6d1493
cleanup
lucasmcdonald3 Mar 7, 2024
68ce94a
flake8
lucasmcdonald3 Mar 7, 2024
9269fc4
pylint
lucasmcdonald3 Mar 7, 2024
0a972e6
pylint
lucasmcdonald3 Mar 7, 2024
e185c35
fix
lucasmcdonald3 Mar 7, 2024
4f86337
fix
lucasmcdonald3 Mar 7, 2024
dd89e32
add mpl
lucasmcdonald3 Mar 7, 2024
5c5fb4b
missing
lucasmcdonald3 Mar 7, 2024
9cf2191
fix
lucasmcdonald3 Mar 7, 2024
df10d91
fix
lucasmcdonald3 Mar 7, 2024
e332d5b
fix
lucasmcdonald3 Mar 7, 2024
8dbeeb3
add missing files
lucasmcdonald3 Mar 7, 2024
15a6976
install testvectors
lucasmcdonald3 Mar 7, 2024
46ac8a0
fix
lucasmcdonald3 Mar 7, 2024
104ff8a
fix
lucasmcdonald3 Mar 7, 2024
65227c2
fix
lucasmcdonald3 Mar 7, 2024
a2484a0
working
lucasmcdonald3 Mar 11, 2024
faa92a0
decrypt-lite workign
lucasmcdonald3 Mar 12, 2024
bbc36f9
..?
lucasmcdonald3 Mar 12, 2024
3bf820c
missing
lucasmcdonald3 Mar 12, 2024
eb40abb
cleanup
lucasmcdonald3 Mar 12, 2024
bc0d5ff
wip
lucasmcdonald3 Mar 13, 2024
fb7d10c
requiredec working
lucasmcdonald3 Mar 13, 2024
344824b
debug cb
lucasmcdonald3 Mar 13, 2024
697f2ff
fix cb
lucasmcdonald3 Mar 13, 2024
7dbc00a
fix cb
lucasmcdonald3 Mar 13, 2024
7036337
debug cb
lucasmcdonald3 Mar 13, 2024
14c287d
Merge
lucasmcdonald3 Mar 13, 2024
2d26009
Merge branch 'lucmcdon/mpl' into lucmcdon/mpl-requiredec
lucasmcdonald3 Mar 13, 2024
35dc479
Merge branch 'lucmcdon/mpl-requiredec' into lucmcdon/mpl-testvectors
lucasmcdonald3 Mar 13, 2024
7a44191
debug gha
lucasmcdonald3 Mar 13, 2024
298235a
temp rm cov
lucasmcdonald3 Mar 13, 2024
4c1d0a0
temp rm cov
lucasmcdonald3 Mar 13, 2024
12e0060
debug gha
lucasmcdonald3 Mar 13, 2024
9ca61e2
debug gha
lucasmcdonald3 Mar 13, 2024
5deac12
debug cb
lucasmcdonald3 Mar 13, 2024
ff99fe7
debug cb
lucasmcdonald3 Mar 13, 2024
6a4b704
debug cb
lucasmcdonald3 Mar 13, 2024
0dbd4f6
fix cb
lucasmcdonald3 Mar 13, 2024
357594b
debug cb
lucasmcdonald3 Mar 13, 2024
3760ebe
debug gha
lucasmcdonald3 Mar 13, 2024
7b984fe
add missing file
lucasmcdonald3 Mar 13, 2024
9b7a58d
debug gha
lucasmcdonald3 Mar 14, 2024
93fee67
debug cb
lucasmcdonald3 Mar 14, 2024
e65fec4
debug gha
lucasmcdonald3 Mar 14, 2024
f4ebbba
imperative mood
lucasmcdonald3 Mar 14, 2024
05511a8
fix gha
lucasmcdonald3 Mar 14, 2024
c9c58e6
fix gha
lucasmcdonald3 Mar 14, 2024
a62f1b4
debug cb
lucasmcdonald3 Mar 14, 2024
752c98c
no more profile
lucasmcdonald3 Mar 14, 2024
d2897e5
debug cb
lucasmcdonald3 Mar 14, 2024
dc7887d
debug cb
lucasmcdonald3 Mar 14, 2024
36a4630
debug cb
lucasmcdonald3 Mar 14, 2024
736c1f4
debug cb
lucasmcdonald3 Mar 14, 2024
1adfb12
debug cb
lucasmcdonald3 Mar 14, 2024
dd4b495
debug cb
lucasmcdonald3 Mar 14, 2024
76b1f29
debug cb
lucasmcdonald3 Mar 14, 2024
33d7bdb
debug cb
lucasmcdonald3 Mar 14, 2024
6a8a623
debug new toxes
lucasmcdonald3 Mar 14, 2024
9fd7468
debug new toxes
lucasmcdonald3 Mar 14, 2024
5affe9c
add missing files
lucasmcdonald3 Mar 14, 2024
78b817d
debug tox
lucasmcdonald3 Mar 14, 2024
c817996
add missing
lucasmcdonald3 Mar 14, 2024
c549e39
debug cb
lucasmcdonald3 Mar 14, 2024
90a18d0
debug cb
lucasmcdonald3 Mar 14, 2024
77fba50
debug cb
lucasmcdonald3 Mar 14, 2024
991c55f
debug cb
lucasmcdonald3 Mar 14, 2024
71efaa3
debug cb
lucasmcdonald3 Mar 14, 2024
b1cbf4b
debug gha and cb
lucasmcdonald3 Mar 14, 2024
39fcb9b
debug gha and cb
lucasmcdonald3 Mar 14, 2024
5962312
debug gha and cb
lucasmcdonald3 Mar 14, 2024
0ac5e96
debug gha and cb
lucasmcdonald3 Mar 14, 2024
3dcab7f
debug gha and cb
lucasmcdonald3 Mar 14, 2024
ccb01a2
debug cb
lucasmcdonald3 Mar 14, 2024
7074f8a
add missing
lucasmcdonald3 Mar 14, 2024
2b36513
token
lucasmcdonald3 Mar 14, 2024
be6a253
token
lucasmcdonald3 Mar 14, 2024
a431365
debug
lucasmcdonald3 Mar 14, 2024
4120be3
debug cb
lucasmcdonald3 Mar 14, 2024
7391c78
missing
lucasmcdonald3 Mar 14, 2024
a16be01
missing
lucasmcdonald3 Mar 14, 2024
4b2553b
perms
lucasmcdonald3 Mar 14, 2024
843ac28
debug cb
lucasmcdonald3 Mar 14, 2024
68c068e
debug cb
lucasmcdonald3 Mar 15, 2024
adf7198
files in s3
lucasmcdonald3 Mar 18, 2024
e246463
files in s3
lucasmcdonald3 Mar 18, 2024
1aa07e5
files in s3
lucasmcdonald3 Mar 18, 2024
1702822
files in s3
lucasmcdonald3 Mar 18, 2024
207401a
files in s3
lucasmcdonald3 Mar 18, 2024
b3e0125
files in s3
lucasmcdonald3 Mar 18, 2024
644c343
files in s3
lucasmcdonald3 Mar 18, 2024
e72ab99
files in s3
lucasmcdonald3 Mar 18, 2024
36fd56b
files in s3
lucasmcdonald3 Mar 18, 2024
6052b53
files in s3
lucasmcdonald3 Mar 18, 2024
457aa88
files in s3
lucasmcdonald3 Mar 18, 2024
a8b65d3
files in s3
lucasmcdonald3 Mar 18, 2024
8ed6cca
debug gen
lucasmcdonald3 Mar 18, 2024
ef4a9d7
debug gen
lucasmcdonald3 Mar 18, 2024
b564f77
debug gen
lucasmcdonald3 Mar 18, 2024
31a58cc
debug gen
lucasmcdonald3 Mar 18, 2024
ed87953
debug gen
lucasmcdonald3 Mar 18, 2024
ac01f37
debug gen
lucasmcdonald3 Mar 18, 2024
69a934c
debug gen
lucasmcdonald3 Mar 18, 2024
65d3acd
debug gen
lucasmcdonald3 Mar 18, 2024
95e8a8b
debug gen
lucasmcdonald3 Mar 18, 2024
8d484e6
debug gen
lucasmcdonald3 Mar 18, 2024
8dcfc3c
debug gen
lucasmcdonald3 Mar 18, 2024
a9306bc
debug gen
lucasmcdonald3 Mar 18, 2024
894dcee
debug
lucasmcdonald3 Mar 18, 2024
e00ec2a
debug
lucasmcdonald3 Mar 18, 2024
2f23be3
debug
lucasmcdonald3 Mar 18, 2024
6a7d732
debug
lucasmcdonald3 Mar 18, 2024
8cbd3dc
debug
lucasmcdonald3 Mar 18, 2024
5cb4b13
debug
lucasmcdonald3 Mar 18, 2024
9d89a74
debug
lucasmcdonald3 Mar 18, 2024
51bf320
debug
lucasmcdonald3 Mar 18, 2024
3be4969
debug
lucasmcdonald3 Mar 18, 2024
9e3358d
debug
lucasmcdonald3 Mar 18, 2024
1b7a54b
debug
lucasmcdonald3 Mar 18, 2024
ce59f57
debug
lucasmcdonald3 Mar 18, 2024
6ef093b
debug
lucasmcdonald3 Mar 18, 2024
ce07e87
Debug
lucasmcdonald3 Mar 18, 2024
7225e51
debug
lucasmcdonald3 Mar 18, 2024
549fe07
debug
lucasmcdonald3 Mar 18, 2024
0f9b662
debug
lucasmcdonald3 Mar 18, 2024
8dd3468
debug
lucasmcdonald3 Mar 18, 2024
5378b62
debug
lucasmcdonald3 Mar 18, 2024
f3db08a
debug
lucasmcdonald3 Mar 18, 2024
6080556
debug
lucasmcdonald3 Mar 18, 2024
3862329
consume vectors
lucasmcdonald3 Mar 19, 2024
30f7152
rerun ci
lucasmcdonald3 Mar 19, 2024
876ed38
add missing files
lucasmcdonald3 Mar 19, 2024
8a6bf33
311
lucasmcdonald3 Mar 19, 2024
07f3b8f
cooking
lucasmcdonald3 Mar 19, 2024
a06684e
cooking
lucasmcdonald3 Mar 19, 2024
37fd225
cooking
lucasmcdonald3 Mar 19, 2024
e459045
cooking
lucasmcdonald3 Mar 19, 2024
0e8c6c9
missing
lucasmcdonald3 Mar 19, 2024
32446e2
tampering mpl
lucasmcdonald3 Mar 19, 2024
f1cd456
more
lucasmcdonald3 Mar 19, 2024
a3267bc
more
lucasmcdonald3 Mar 19, 2024
d4db5ec
more
lucasmcdonald3 Mar 19, 2024
bf78061
more
lucasmcdonald3 Mar 19, 2024
008ae6f
more
lucasmcdonald3 Mar 19, 2024
19a9dad
debug
lucasmcdonald3 Mar 19, 2024
a4aa0f9
debug
lucasmcdonald3 Mar 19, 2024
d53895d
debug
lucasmcdonald3 Mar 19, 2024
9c46200
debug
lucasmcdonald3 Mar 19, 2024
3af9f32
debug
lucasmcdonald3 Mar 19, 2024
9e255e4
debug
lucasmcdonald3 Mar 19, 2024
262696b
debug
lucasmcdonald3 Mar 19, 2024
fadea8c
debug
lucasmcdonald3 Mar 19, 2024
b8dbb1f
debug
lucasmcdonald3 Mar 19, 2024
f5d6cb7
debug
lucasmcdonald3 Mar 19, 2024
774abf6
debug
lucasmcdonald3 Mar 19, 2024
e16771a
debug
lucasmcdonald3 Mar 19, 2024
8752df7
Debug
lucasmcdonald3 Mar 19, 2024
91d219c
Debug
lucasmcdonald3 Mar 19, 2024
0178f7a
debug
lucasmcdonald3 Mar 19, 2024
1060a3f
debug
lucasmcdonald3 Mar 19, 2024
9806fba
debug
lucasmcdonald3 Mar 19, 2024
3625f98
debug
lucasmcdonald3 Mar 19, 2024
77b9165
Debug
lucasmcdonald3 Mar 19, 2024
cfc2681
debug
lucasmcdonald3 Mar 19, 2024
87bc057
debug
lucasmcdonald3 Mar 19, 2024
ca6f3a1
debug
lucasmcdonald3 Mar 19, 2024
3b01d38
debug
lucasmcdonald3 Mar 19, 2024
68495e8
debug
lucasmcdonald3 Mar 19, 2024
8a8103a
debug
lucasmcdonald3 Mar 19, 2024
89c39ff
debug
lucasmcdonald3 Mar 19, 2024
fee0cce
debug
lucasmcdonald3 Mar 19, 2024
c5ba2fd
debug
lucasmcdonald3 Mar 19, 2024
4875dbc
debug
lucasmcdonald3 Mar 19, 2024
4ed99d3
debug
lucasmcdonald3 Mar 20, 2024
9f76cbf
debug
lucasmcdonald3 Mar 20, 2024
2f08f0d
debug
lucasmcdonald3 Mar 20, 2024
594f273
debug
lucasmcdonald3 Mar 20, 2024
108cd03
refactor
lucasmcdonald3 Mar 20, 2024
b116b0d
debug
lucasmcdonald3 Mar 20, 2024
063989f
debug
lucasmcdonald3 Mar 20, 2024
101af71
debug
lucasmcdonald3 Mar 20, 2024
803ae4d
debug
lucasmcdonald3 Mar 20, 2024
58bd271
debug
lucasmcdonald3 Mar 20, 2024
bccd1be
clean37
lucasmcdonald3 Mar 20, 2024
970ca3c
clean37
lucasmcdonald3 Mar 20, 2024
9ccd014
311
lucasmcdonald3 Mar 20, 2024
2c3b380
311
lucasmcdonald3 Mar 20, 2024
c8ca704
311
lucasmcdonald3 Mar 20, 2024
c8c5a40
py311
lucasmcdonald3 Mar 20, 2024
8a0ddc4
311
lucasmcdonald3 Mar 20, 2024
20262d7
311
lucasmcdonald3 Mar 20, 2024
89efb74
312
lucasmcdonald3 Mar 20, 2024
e1700b9
ALL
lucasmcdonald3 Mar 20, 2024
1d7fcae
ALL
lucasmcdonald3 Mar 20, 2024
bdacdeb
ALL
lucasmcdonald3 Mar 20, 2024
2783808
gen decrypt keyrings
lucasmcdonald3 Mar 20, 2024
f690cf7
cleanup
lucasmcdonald3 Mar 20, 2024
446eaa4
cleanup
lucasmcdonald3 Mar 20, 2024
70b68f9
cleanup
lucasmcdonald3 Mar 20, 2024
67f0179
cleanup
lucasmcdonald3 Mar 20, 2024
7d8a515
cleanup
lucasmcdonald3 Mar 20, 2024
48974b0
debug
lucasmcdonald3 Mar 20, 2024
1bb5527
cleanup
lucasmcdonald3 Mar 20, 2024
72de35b
cleanup
lucasmcdonald3 Mar 20, 2024
f2792bc
cleanup
lucasmcdonald3 Mar 20, 2024
df45d5d
cleanup
lucasmcdonald3 Mar 20, 2024
c66938f
cleanup
lucasmcdonald3 Mar 20, 2024
693b776
deprecated
lucasmcdonald3 Apr 16, 2024
0266a55
readme
lucasmcdonald3 Apr 17, 2024
7b80c7d
cmms
lucasmcdonald3 Apr 18, 2024
37dd008
missing file
lucasmcdonald3 Apr 18, 2024
c92fe2a
fix
lucasmcdonald3 Apr 18, 2024
9e267b0
test
lucasmcdonald3 Apr 18, 2024
08a80a3
fix
lucasmcdonald3 Apr 19, 2024
d8affb6
cleanup
lucasmcdonald3 Apr 19, 2024
357ebfb
m
lucasmcdonald3 Apr 19, 2024
86cff9b
fix
lucasmcdonald3 Apr 19, 2024
cf6e9ec
m
lucasmcdonald3 Apr 19, 2024
b6859e6
m
lucasmcdonald3 Apr 19, 2024
971546b
update
lucasmcdonald3 Apr 19, 2024
e3d470f
update
lucasmcdonald3 Apr 19, 2024
0816de8
update
lucasmcdonald3 Apr 19, 2024
b67a7ef
update
lucasmcdonald3 Apr 19, 2024
9f12c96
chore(__init__.py): updated keyrings usage documentation
RitvikKapila May 7, 2024
ffe0270
updated mpl examples in README
RitvikKapila May 9, 2024
7ae669a
fix
RitvikKapila May 9, 2024
44d1746
appveyor fix
RitvikKapila May 9, 2024
b262fe5
updated readme and __init__.py
RitvikKapila May 9, 2024
6903573
Merge branch 'mpl-reviewed' into lucmcdon/mpl-deprecations
RitvikKapila May 10, 2024
8f5d559
merge fix
RitvikKapila May 10, 2024
6177753
fix
RitvikKapila May 10, 2024
6c0b6f8
remove deprecations
lucasmcdonald3 May 28, 2024
a5ecc47
wip
lucasmcdonald3 May 28, 2024
434e8bc
wip
lucasmcdonald3 May 29, 2024
295a2d9
wip
lucasmcdonald3 May 29, 2024
b8b44bc
isort
lucasmcdonald3 May 29, 2024
e75f8bd
cleanup
lucasmcdonald3 Jul 26, 2024
e50df1f
linkify
lucasmcdonald3 Jul 29, 2024
df95da7
text
lucasmcdonald3 Jul 29, 2024
0310c57
fix link
lucasmcdonald3 Jul 29, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
281 changes: 106 additions & 175 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ Required Prerequisites
* boto3 >= 1.10.0
* attrs

Recommended Prerequisites
=========================

* aws-cryptographic-material-providers: >= TODO.TODO.TODO (TODO-MPL: versionme)
* Requires Python 3.11+.

Installation
============

Expand All @@ -49,42 +55,71 @@ Installation

.. code::

$ pip install aws-encryption-sdk
$ pip install "aws-encryption-sdk[MPL]"

The `[MPL]` suffix also installs the `AWS Cryptographic Material Providers Library (MPL)`_.
This is a library that contains constructs for encrypting and decrypting your data.
We highly recommend installing the MPL.
However, if you do not wish to install the MPL, omit the `[MPL]` suffix.

Concepts
========
There are four main concepts that you need to understand to use this library:
There are three main concepts that you need to understand to use this library:

Data Keys
---------
Data keys are the encryption keys that are used to encrypt your data. If your algorithm suite
uses a key derivation function, the data key is used to generate the key that directly encrypts the data.

Keyrings
--------
Keyrings are resources that generate, encrypt, and decrypt data keys.
You specify a keyring when encrypting and the same or a different keyring when decrypting.

Note: You must also install the `AWS Cryptographic Material Providers Library (MPL)`_ to create and use keyrings.

For more information, see the `AWS Documentation for Keyrings`_.

Cryptographic Materials Managers
--------------------------------
Cryptographic materials managers (CMMs) are resources that collect cryptographic materials and prepare them for
use by the Encryption SDK core logic.

An example of a CMM is the default CMM, which is automatically generated anywhere a caller provides a master
key provider. The default CMM collects encrypted data keys from all master keys referenced by the master key
provider.
An example of a CMM is the default CMM,
which is automatically generated anywhere a caller provides a keyring.

Note: You must also install the `AWS Cryptographic Material Providers Library (MPL)`_
to create and use CMMs that use keyrings.
CMMs that use master key providers have been marked as legacy since v4 of this library.

An example of a more advanced CMM is the caching CMM, which caches cryptographic materials provided by another CMM.
Legacy Concepts
===============
This section describes legacy concepts introduced in earlier versions of this library.
These components have been superseded by new components in the `AWS Cryptographic Material Providers Library (MPL)`_.
Please avoid using these components, and instead use components in the MPL.

Master Key Providers
--------------------
Master key providers are resources that provide master keys.
An example of a master key provider is `AWS KMS`_.

To encrypt data in this client, a ``MasterKeyProvider`` object must contain at least one ``MasterKey`` object.

``MasterKeyProvider`` objects can also contain other ``MasterKeyProvider`` objects.

NOTE: Master key providers are legacy components
and have been superseded by keyrings
provided by the `AWS Cryptographic Material Providers Library (MPL)`_.
Please install this library and migrate master key providers to keyring interfaces.

Master Keys
-----------
Master keys generate, encrypt, and decrypt data keys.
An example of a master key is a `KMS customer master key (CMK)`_.
An example of a master key is an `AWS KMS key`_.

Data Keys
---------
Data keys are the encryption keys that are used to encrypt your data. If your algorithm suite
uses a key derivation function, the data key is used to generate the key that directly encrypts the data.
NOTE: Master keys are legacy constructs
and have been superseded by keyrings
provided by the `AWS Cryptographic Material Providers Library (MPL)`_.
Please install this library and migrate master key providers to keyring interfaces.

*****
Usage
Expand All @@ -110,147 +145,70 @@ version of the AWS Encryption SDK, we recommend using the default value.
)


You must then create an instance of either a master key provider or a CMM. The examples in this
readme use the ``StrictAwsKmsMasterKeyProvider`` class.
You must then create an instance of either a keyring (with the MPL installed) or a CMM.
Note: You must also install the `AWS Cryptographic Material Providers Library (MPL)`_ to use keyrings.
(You may also provide an instance of a legacy master key provider, but this is not recommended.)


AwsKmsMultiKeyring
==================

StrictAwsKmsMasterKeyProvider
=============================
A ``StrictAwsKmsMasterKeyProvider`` is configured with an explicit list of AWS KMS
CMKs with which to encrypt and decrypt data. On encryption, it encrypts the plaintext with all
configured CMKs. On decryption, it only attempts to decrypt ciphertexts that have been wrapped
with a CMK that matches one of the configured CMK ARNs.
An ``AwsKmsMultiKeyring`` is configured with a generator keyring and a list of
child keyrings of type ``AwsKmsKeyring``. The effect is like using several keyrings
in a series. When you use a multi-keyring to encrypt data, any of the wrapping keys
in any of its keyrings can decrypt that data.

To create a ``StrictAwsKmsMasterKeyProvider`` you must provide one or more CMKs. For providers that will only
be used for encryption, you can use any valid `KMS key identifier`_. For providers that will be used for decryption, you
must use the key ARN; key ids, alias names, and alias ARNs are not supported.
On encryption, the generator keyring generates and encrypts the plaintext data key.
Then, all of the wrapping keys in all of the child keyrings encrypt the same plaintext data key.
On decryption, the AWS Encryption SDK uses the keyrings to try to decrypt one of the encrypted data keys.
The keyrings are called in the order that they are specified in the multi-keyring.
Processing stops as soon as any key in any keyring can decrypt an encrypted data key.

Because the ``StrictAwsKmsMasterKeyProvider`` uses the `boto3 SDK`_ to interact with `AWS KMS`_,
An individual ``AwsKmsKeyring`` in an ``AwsKmsMultiKeyring`` is configured with an
AWS KMS key ARN.
For keyrings that will only be used for encryption,
you can use any valid `KMS key identifier`_.
For providers that will be used for decryption,
you must use the key ARN.
Key ids, alias names, and alias ARNs are not supported for decryption.

Because the ``AwsKmsMultiKeyring`` uses the `boto3 SDK`_ to interact with `AWS KMS`_,
it requires AWS Credentials.
To provide these credentials, use the `standard means by which boto3 locates credentials`_ or provide a
pre-existing instance of a ``botocore session`` to the ``StrictAwsKmsMasterKeyProvider``.
pre-existing instance of a ``botocore session`` to the ``AwsKmsMultiKeyring``.
This latter option can be useful if you have an alternate way to store your AWS credentials or
you want to reuse an existing instance of a botocore session in order to decrease startup costs.
You can also add KMS keys from multiple regions to the ``AwsKmsMultiKeyring``.

If you configure the the ``StrictAwsKmsMasterKeyProvider`` with multiple CMKs, the `final message`_
will include a copy of the data key encrypted by each configured CMK.
See `examples/src/aws_kms_multi_keyring_example.py`_ for a code example configuring and using
a ``AwsKmsMultiKeyring`` with the ``EncryptionSDKClient``.

.. code:: python

import aws_encryption_sdk

kms_key_provider = aws_encryption_sdk.StrictAwsKmsMasterKeyProvider(key_ids=[
'arn:aws:kms:us-east-1:2222222222222:key/22222222-2222-2222-2222-222222222222',
'arn:aws:kms:us-east-1:3333333333333:key/33333333-3333-3333-3333-333333333333'
])

You can add CMKs from multiple regions to the ``StrictAwsKmsMasterKeyProvider``.

.. code:: python

import aws_encryption_sdk

kms_key_provider = aws_encryption_sdk.StrictAwsKmsMasterKeyProvider(key_ids=[
'arn:aws:kms:us-east-1:2222222222222:key/22222222-2222-2222-2222-222222222222',
'arn:aws:kms:us-west-2:3333333333333:key/33333333-3333-3333-3333-333333333333',
'arn:aws:kms:ap-northeast-1:4444444444444:key/44444444-4444-4444-4444-444444444444'
])


DiscoveryAwsKmsMasterKeyProvider
================================
We recommend using a ``StrictAwsKmsMasterKeyProvider`` in order to ensure that you can only
encrypt and decrypt data using the AWS KMS CMKs you expect. However, if you are unable to
explicitly identify the AWS KMS CMKs that should be used for decryption, you can instead
use a ``DiscoveryAwsKmsMasterKeyProvider`` for decryption operations. This provider
AwsKmsDiscoveryKeyring
======================
We recommend using an ``AwsKmsMultiKeyring`` in order to ensure that you can only
encrypt and decrypt data using the AWS KMS key ARN you expect. However, if you are unable to
explicitly identify the AWS KMS key ARNs that should be used for decryption, you can instead
use an ``AwsKmsDiscoveryKeyring`` for decryption operations. This provider
attempts decryption of any ciphertexts as long as they match a ``DiscoveryFilter`` that
you configure. A ``DiscoveryFilter`` consists of a list of AWS account ids and an AWS
partition.
If you do not want to filter the set of allowed accounts, you can also omit the ``discovery_filter`` argument.

.. code:: python
Note that an ``AwsKmsDiscoveryKeyring`` cannot be used for encryption operations.

import aws_encryption_sdk
from aws_encryption_sdk.key_providers.kms import DiscoveryFilter
See `examples/src/aws_kms_discovery_keyring_example.py`_ for a code example configuring and using
an ``AwsKmsDiscoveryKeyring`` with the ``EncryptionSDKClient``.

discovery_filter = DiscoveryFilter(
account_ids=['222222222222', '333333333333'],
partition='aws'
)
kms_key_provider = aws_encryption_sdk.DiscoveryAwsKmsMasterKeyProvider(
discovery_filter=discovery_filter
)

If you do not want to filter the set of allowed accounts, you can also omit the ``discovery_filter`` argument.

Note that a ``DiscoveryAwsKmsMasterKeyProvider`` cannot be used for encryption operations.

Encryption and Decryption
=========================
After you create an instance of an ``EncryptionSDKClient`` and a ``MasterKeyProvider``, you can use either of
the client's two ``encrypt``/``decrypt`` functions to encrypt and decrypt your data.

.. code:: python

import aws_encryption_sdk
from aws_encryption_sdk.identifiers import CommitmentPolicy

client = aws_encryption_sdk.EncryptionSDKClient(
commitment_policy=CommitmentPolicy.FORBID_ENCRYPT_ALLOW_DECRYPT
)

kms_key_provider = aws_encryption_sdk.StrictAwsKmsMasterKeyProvider(key_ids=[
'arn:aws:kms:us-east-1:2222222222222:key/22222222-2222-2222-2222-222222222222',
'arn:aws:kms:us-east-1:3333333333333:key/33333333-3333-3333-3333-333333333333'
])
my_plaintext = b'This is some super secret data! Yup, sure is!'

my_ciphertext, encryptor_header = client.encrypt(
source=my_plaintext,
key_provider=kms_key_provider
)

decrypted_plaintext, decryptor_header = client.decrypt(
source=my_ciphertext,
key_provider=kms_key_provider
)

assert my_plaintext == decrypted_plaintext
assert encryptor_header.encryption_context == decryptor_header.encryption_context

You can provide an `encryption context`_: a form of additional authenticating information.

.. code:: python

import aws_encryption_sdk
from aws_encryption_sdk.identifiers import CommitmentPolicy

client = aws_encryption_sdk.EncryptionSDKClient(
commitment_policy=CommitmentPolicy.FORBID_ENCRYPT_ALLOW_DECRYPT
)
After you create an instance of an ``EncryptionSDKClient`` and a ``Keyring``, you can use
the client's ``encrypt`` and ``decrypt`` functions to encrypt and decrypt your data.

kms_key_provider = aws_encryption_sdk.StrictAwsKmsMasterKeyProvider(key_ids=[
'arn:aws:kms:us-east-1:2222222222222:key/22222222-2222-2222-2222-222222222222',
'arn:aws:kms:us-east-1:3333333333333:key/33333333-3333-3333-3333-333333333333'
])
my_plaintext = b'This is some super secret data! Yup, sure is!'

my_ciphertext, encryptor_header = client.encrypt(
source=my_plaintext,
key_provider=kms_key_provider,
encryption_context={
'not really': 'a secret',
'but adds': 'some authentication'
}
)

decrypted_plaintext, decryptor_header = client.decrypt(
source=my_ciphertext,
key_provider=kms_key_provider
)

assert my_plaintext == decrypted_plaintext
assert encryptor_header.encryption_context == decryptor_header.encryption_context
You can also provide an `encryption context`_: a form of additional authenticating information.

See code in the `examples/src/`_ directory for code examples configuring and using
keyrings and encryption context with the ``EncryptionSDKClient``.

Streaming
=========
Expand All @@ -259,57 +217,19 @@ memory at once, you can use this library's streaming clients directly. The strea
file-like objects, and behave exactly as you would expect a Python file object to behave,
offering context manager and iteration support.

.. code:: python

import aws_encryption_sdk
from aws_encryption_sdk.identifiers import CommitmentPolicy
import filecmp

client = aws_encryption_sdk.EncryptionSDKClient(
commitment_policy=CommitmentPolicy.FORBID_ENCRYPT_ALLOW_DECRYPT
)

kms_key_provider = aws_encryption_sdk.StrictAwsKmsMasterKeyProvider(key_ids=[
'arn:aws:kms:us-east-1:2222222222222:key/22222222-2222-2222-2222-222222222222',
'arn:aws:kms:us-east-1:3333333333333:key/33333333-3333-3333-3333-333333333333'
])
plaintext_filename = 'my-secret-data.dat'
ciphertext_filename = 'my-encrypted-data.ct'

with open(plaintext_filename, 'rb') as pt_file, open(ciphertext_filename, 'wb') as ct_file:
with client.stream(
mode='e',
source=pt_file,
key_provider=kms_key_provider
) as encryptor:
for chunk in encryptor:
ct_file.write(chunk)

new_plaintext_filename = 'my-decrypted-data.dat'

with open(ciphertext_filename, 'rb') as ct_file, open(new_plaintext_filename, 'wb') as pt_file:
with client.stream(
mode='d',
source=ct_file,
key_provider=kms_key_provider
) as decryptor:
for chunk in decryptor:
pt_file.write(chunk)

assert filecmp.cmp(plaintext_filename, new_plaintext_filename)
assert encryptor.header.encryption_context == decryptor.header.encryption_context
See `examples/src/file_streaming_example.py`_ for a code example streaming data to and from files.

Performance Considerations
==========================
Adjusting the frame size can significantly improve the performance of encrypt/decrypt operations with this library.

Processing each frame in a framed message involves a certain amount of overhead. If you are encrypting a large file,
increasing the frame size can offer potentially significant performance gains. We recommend that you tune these values
Processing each frame in a framed message involves a certain amount of overhead. If you are encrypting a large file,
increasing the frame size can offer potentially significant performance gains. We recommend that you tune these values
to your use-case in order to obtain peak performance.

Thread safety
==========================
The ``EncryptionSDKClient`` and all provided ``CryptoMaterialsManager`` are thread safe.
The ``EncryptionSDKClient`` and all provided ``CryptoMaterialsManager`` in this library are thread safe.
But instances of ``BaseKMSMasterKeyProvider`` MUST not be shared between threads,
for the reasons outlined in `the boto3 docs <https://boto3.amazonaws.com/v1/documentation/api/latest/guide/resources.html#multithreading-or-multiprocessing-with-resources>`_.

Expand All @@ -323,17 +243,28 @@ Finally, while the ``CryptoMaterialsCache`` is thread safe,
sharing entries in that cache across threads needs to be done carefully
(see the !Note about partition name `in the API Docs <https://aws-encryption-sdk-python.readthedocs.io/en/latest/generated/aws_encryption_sdk.materials_managers.caching.html#aws_encryption_sdk.materials_managers.caching.CachingCryptoMaterialsManager>`_).

**Important:** Components from the `AWS Cryptographic Material Providers Library (MPL)`_
have separate thread safety considerations.
For more information, see the note on thread safety in that project's README (TODO-MPL: link)


.. _AWS Encryption SDK: https://docs.aws.amazon.com/encryption-sdk/latest/developer-guide/introduction.html
.. _cryptography: https://cryptography.io/en/latest/
.. _cryptography installation guide: https://cryptography.io/en/latest/installation/
.. _Read the Docs: http://aws-encryption-sdk-python.readthedocs.io/en/latest/
.. _GitHub: https://github.com/aws/aws-encryption-sdk-python/
.. _AWS KMS: https://docs.aws.amazon.com/kms/latest/developerguide/overview.html
.. _KMS customer master key (CMK): https://docs.aws.amazon.com/kms/latest/developerguide/concepts.html#master_keys
.. _AWS KMS key: https://docs.aws.amazon.com/kms/latest/developerguide/concepts.html#master_keys
.. _KMS key identifier: https://docs.aws.amazon.com/kms/latest/developerguide/concepts.html#key-id
.. _boto3 SDK: https://boto3.readthedocs.io/en/latest/
.. _standard means by which boto3 locates credentials: https://boto3.readthedocs.io/en/latest/guide/configuration.html
.. _final message: https://docs.aws.amazon.com/encryption-sdk/latest/developer-guide/message-format.html
.. _encryption context: https://docs.aws.amazon.com/kms/latest/developerguide/concepts.html#encrypt_context
.. _Security issue notifications: ./CONTRIBUTING.md#security-issue-notifications
.. _Support Policy: ./SUPPORT_POLICY.rst
.. _AWS Cryptographic Material Providers Library (MPL): https://github.com/aws/aws-cryptographic-material-providers-library
.. _AWS Documentation for Keyrings: https://docs.aws.amazon.com/encryption-sdk/latest/developer-guide/choose-keyring.html
.. _examples/src/aws_kms_multi_keyring_example.py: https://github.com/aws/aws-encryption-sdk-python/blob/master/examples/src/aws_kms_multi_keyring_example.py
.. _examples/src/aws_kms_discovery_keyring_example.py: https://github.com/aws/aws-encryption-sdk-python/blob/master/examples/src/aws_kms_discovery_keyring_example.py
.. _examples/src/: https://github.com/aws/aws-encryption-sdk-python/tree/master/examples/src/
.. _examples/src/file_streaming_example.py: https://github.com/aws/aws-encryption-sdk-python/blob/master/examples/src/file_streaming_example.py
Loading
Loading