fix: EC-5..EC-8 error-message inversion, RSA-only wrap guard, 32-byte key guard, fingerprint_data robustness
EC-5: _load_private_key branches on whether a password was given so the normalized ValueError matches the actual cryptography TypeError case (was always claiming "encrypted but no password" even when a password was given for an unencrypted key). EC-6: encrypt_aes_key_with_rsa/decrypt_aes_key_with_rsa now raise a clear ValueError via _require_rsa for a non-RSA key (e.g. Ed25519/EC), instead of crashing raw with AttributeError at wrap/unwrap — this lib is RSA-envelope only. EC-7: initialize() requires exactly 32 bytes (isinstance bytes, len==32), rejecting a 16/24-byte key (silent AES-128/192 downgrade) or a str instead of failing late and opaquely at first encrypt. EC-8: fingerprint_data gains a default= handler (datetime/date/time, bytes/bytearray, and a type-tagged repr fallback) plus a key-type-tagging pre-pass so datetime/bytes/ ObjectId-like values no longer TypeError and int-vs-str dict keys no longer collide to the same fingerprint. Never logs the data being fingerprinted. Also compresses the essay-length docstrings (module + several methods) to cut narration while keeping the load-bearing footgun notes (RSA-only, AES-256 key length, never-log-key-material) intact — zero behavior change, re-verified after. Signed-off-by: disqualifier <dev@disqualifier.me>
This commit is contained in:
@@ -11,18 +11,18 @@ and storage-agnostic.
|
||||
`requirements.txt`:
|
||||
|
||||
```
|
||||
envelope_crypto @ git+ssh://git@git.rethinkstudios.io/rethink-public/envelope_crypto.git@v0.1.5
|
||||
envelope_crypto @ git+ssh://git@git.rethinkstudios.io/rethink-public/envelope_crypto.git@v0.1.6
|
||||
```
|
||||
|
||||
Direct:
|
||||
|
||||
```bash
|
||||
pip install "envelope_crypto @ git+ssh://git@git.rethinkstudios.io/rethink-public/envelope_crypto.git@v0.1.5"
|
||||
pip install "envelope_crypto @ git+ssh://git@git.rethinkstudios.io/rethink-public/envelope_crypto.git@v0.1.6"
|
||||
```
|
||||
|
||||
Requires `cryptography` (pulled transitively).
|
||||
|
||||
Drop the `@v0.1.5` suffix from the line above to install the latest unpinned.
|
||||
Drop the `@v0.1.6` suffix from the line above to install the latest unpinned.
|
||||
|
||||
## First-time setup
|
||||
|
||||
@@ -177,6 +177,18 @@ The lib never touches a database; only the caller's storage layer differs.
|
||||
- The scheme is envelope/hybrid encryption (AES-256-GCM data key wrapped by RSA-OAEP).
|
||||
Using it does not by itself confer PCI-DSS or any other compliance — that is a
|
||||
whole-system property.
|
||||
- `initialize(master_key)` requires exactly 32 bytes (`bytes`, `len == 32`) — a
|
||||
16/24-byte key or a `str` raises `ValueError` instead of silently downgrading to
|
||||
AES-128/192 or failing late at first encrypt.
|
||||
- Wrap/unwrap (`encrypt_aes_key_with_rsa`, `decrypt_aes_key_with_rsa`,
|
||||
`authorize_system`, `bootstrap`, `rotate_master_key`) is **RSA-only**. A non-RSA
|
||||
key (e.g. Ed25519/EC) loads and fingerprints fine but raises a clear `ValueError`
|
||||
at wrap/unwrap rather than a raw `AttributeError`.
|
||||
- `fingerprint_data` serializes non-JSON-native values (datetime/date/time,
|
||||
bytes/bytearray, ObjectId-like objects) via a stable `default=` handler instead of
|
||||
raising `TypeError`, and type-tags dict keys internally so `{1: "a"}` and
|
||||
`{"1": "a"}` no longer collide to the same fingerprint. Never logs the data it
|
||||
fingerprints.
|
||||
|
||||
## Versioning
|
||||
|
||||
|
||||
Reference in New Issue
Block a user