Metadata-Version: 2.4
Name: cryptography-suite-aws-kms
Version: 4.0.0b2
Summary: AWS KMS key provider for cryptography-suite v4 envelope encryption (pre-release; not independently audited).
Author: Mojtaba Zaferanloo
License-Expression: MIT
Project-URL: Homepage, https://github.com/Psychevus/cryptography-suite
Project-URL: Documentation, https://psychevus.github.io/cryptography-suite
Project-URL: Source, https://github.com/Psychevus/cryptography-suite/tree/main/packages/cryptography-suite-aws-kms
Project-URL: Changelog, https://github.com/Psychevus/cryptography-suite/blob/main/CHANGELOG.md
Project-URL: Tracker, https://github.com/Psychevus/cryptography-suite/issues
Keywords: aws,kms,envelope-encryption,key-management,cryptography
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Programming Language :: Python :: 3.15
Classifier: Topic :: Security :: Cryptography
Classifier: Typing :: Typed
Requires-Python: >=3.11
Description-Content-Type: text/markdown
Requires-Dist: cryptography-suite==4.0.0b2
Provides-Extra: boto3
Requires-Dist: boto3>=1.35; extra == "boto3"

# cryptography-suite-aws-kms

AWS Key Management Service provider for
[cryptography-suite](https://github.com/Psychevus/cryptography-suite), the
policy-driven envelope encryption SDK.
Pre-release; not independently audited.

## Install

```console
python -m pip install "cryptography-suite-aws-kms[boto3]"
```

## Use

```python
import boto3
from botocore.config import Config

from cryptography_suite import EncryptionContext, KeyRef, Policy, Protector
from cryptography_suite_aws_kms import PROVIDER_ID, AwsKmsProvider

kms = boto3.client(
    "kms",
    region_name="eu-west-1",
    config=Config(connect_timeout=3, read_timeout=5, retries={"total_max_attempts": 1}),
)
protector = Protector(
    provider=AwsKmsProvider(kms),
    policy=Policy.enterprise(approved_providers=[PROVIDER_ID]),
    primary_key=KeyRef(PROVIDER_ID, "alias/payments"),
    audit_sink=audit_sink,
)
context = EncryptionContext({"tenant": "acme"}, purpose="payments")
envelope = protector.seal(b"...", context=context)
plaintext = protector.open(envelope, context=context)
```

You build the boto3 client: region, credentials, endpoints, and retries are
yours. The provider never reads credentials or the environment and does not
import boto3 itself.

## Keys and permissions

| Item | Value |
| --- | --- |
| Keys | Symmetric encryption keys (`SYMMETRIC_DEFAULT`), named by key ID, key ARN, or alias. |
| Recorded version | The key ARN. AWS rotates key material behind the same ARN, so automatic rotation needs no rewrap. |
| To seal | `kms:DescribeKey`, `kms:Encrypt` |
| To open | `kms:Decrypt`, and `kms:DescribeKey` when the trusted key is given by alias |
| Health check | `kms:ListKeys` |

## Behaviour

- **Binding.** Each wrap calls `Encrypt` with the encryption context
  `{"cryptography-suite:binding": base64url(SHA-256(protected header))}`.
  KMS authenticates it, so a wrapped key cannot be moved to another envelope,
  and CloudTrail links every key use to an envelope without revealing it.
- **Exact keys.** `Decrypt` is pinned to the key ARN the envelope records,
  and a recipient whose key and version disagree is refused before KMS is
  called, so the key used is always the one the reader trusts.
- **One attempt per call.** boto3 sets retries per client, not per call, so
  the client must make exactly one attempt: `retries={"total_max_attempts":
  1}`. Any other client is refused with a `ValueError`, because botocore's
  retries would multiply the policy's bounded attempts. Note that botocore's
  `max_attempts` counts retries: `{"max_attempts": 1}` means two attempts.
- **Timeouts.** The policy's `provider_timeout_ms` (30 seconds by default) is
  checked between attempts but cannot cut a call short. Keep
  `connect_timeout` plus `read_timeout` within it (botocore defaults to 60
  seconds each).
- **Errors.** KMS errors map to stable error codes; throttling and transient
  service errors are retryable within the policy's budget, and missing or
  expired credentials are `PROVIDER_AUTH_FAILED`. `grant_tokens=` passes KMS
  grant tokens.

## Documentation

- [Key services guide](https://github.com/Psychevus/cryptography-suite/blob/main/docs/guide/key-services.md)
- [Rotation and recovery](https://github.com/Psychevus/cryptography-suite/blob/main/docs/guide/rotation-and-recovery.md)
- [Security policy](https://github.com/Psychevus/cryptography-suite/blob/main/SECURITY.md)

`cryptography_suite.providers.conformance.verify_provider` checks the
provider against a test key in your account.
