Metadata-Version: 2.4
Name: cryptography-suite-azure-keyvault
Version: 4.0.0rc1
Summary: Azure Key Vault and Managed HSM 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-azure-keyvault
Project-URL: Changelog, https://github.com/Psychevus/cryptography-suite/blob/main/CHANGELOG.md
Project-URL: Tracker, https://github.com/Psychevus/cryptography-suite/issues
Keywords: azure,key-vault,managed-hsm,envelope-encryption,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.0rc1
Provides-Extra: azure
Requires-Dist: azure-keyvault-keys>=4.6; extra == "azure"
Requires-Dist: azure-identity>=1.10; extra == "azure"

# cryptography-suite-azure-keyvault

Azure Key Vault and Managed HSM 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-azure-keyvault[azure]"
```

## Use

```python
from azure.identity import DefaultAzureCredential
from azure.keyvault.keys import KeyClient

from cryptography_suite import EncryptionContext, KeyRef, Policy, Protector
from cryptography_suite_azure_keyvault import PROVIDER_ID, AzureKeyVaultProvider

client = KeyClient(
    vault_url="https://acme-payments.vault.azure.net",
    credential=DefaultAzureCredential(),
)
protector = Protector(
    provider=AzureKeyVaultProvider(client),
    policy=Policy.enterprise(approved_providers=[PROVIDER_ID]),
    primary_key=KeyRef(PROVIDER_ID, "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 `KeyClient`: vault URL, credential, and transport are yours.
The provider never reads credentials or the environment and does not import
the Azure SDK itself.

## Keys and permissions

| Item | Value |
| --- | --- |
| Keys | `RSA` or `RSA-HSM` keys of 2048 bits or more with the `wrapKey` and `unwrapKey` operations, in Key Vault or Managed HSM, named by key name. |
| Recorded version | The key version. After rotating, `Protector.rewrap` moves envelopes to the new version; old versions keep unwrapping what they wrapped. |
| To seal | Key permissions `get` and `wrapKey`. With `get`, the Azure SDK wraps locally with the public key. |
| To open | Key permission `unwrapKey`. The SDK also tries `get` first and continues without it when it is denied. |
| Health check | Key permission `list` |

The built-in role *Key Vault Crypto User* (or *Managed HSM Crypto User*)
grants all of these; a custom role can split sealing from opening.

## Behaviour

- **Binding.** RSA-OAEP-256 has no associated data, so each wrap encrypts
  the data key together with `SHA-256(label || protected header)`, and
  unwrap checks that digest in constant time: a wrapped key cannot be moved
  to another envelope. Key Vault's reported key identifier is checked
  against the recorded name and version.
- **Key states.** Disabled, expired, and not-yet-valid versions are reported
  as disabled, so opening falls back to another recipient, such as an
  escrow key.
- **Timeouts.** Every call turns the SDK's retry policy off (by default ten
  retries with backoff of up to two minutes) and carries connection and read
  timeouts of the time left before the operation's deadline, whatever retry
  policy the client was built with.
- **Errors.** Key Vault errors map to stable error codes; throttling and
  transient service errors are retryable within the policy's budget.

## 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 vault.
