swarmauri_mre_crypto_pgp 0.3.0.dev45__tar.gz → 0.11.0.dev1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {swarmauri_mre_crypto_pgp-0.3.0.dev45 → swarmauri_mre_crypto_pgp-0.11.0.dev1}/PKG-INFO +21 -18
- {swarmauri_mre_crypto_pgp-0.3.0.dev45 → swarmauri_mre_crypto_pgp-0.11.0.dev1}/README.md +13 -13
- {swarmauri_mre_crypto_pgp-0.3.0.dev45 → swarmauri_mre_crypto_pgp-0.11.0.dev1}/pyproject.toml +8 -6
- {swarmauri_mre_crypto_pgp-0.3.0.dev45 → swarmauri_mre_crypto_pgp-0.11.0.dev1}/swarmauri_mre_crypto_pgp/PGPSealMreCrypto.py +37 -11
- {swarmauri_mre_crypto_pgp-0.3.0.dev45 → swarmauri_mre_crypto_pgp-0.11.0.dev1}/swarmauri_mre_crypto_pgp/pgp_mre.py +77 -22
- {swarmauri_mre_crypto_pgp-0.3.0.dev45 → swarmauri_mre_crypto_pgp-0.11.0.dev1}/swarmauri_mre_crypto_pgp/pgp_sealed_cek_mre.py +69 -20
- {swarmauri_mre_crypto_pgp-0.3.0.dev45 → swarmauri_mre_crypto_pgp-0.11.0.dev1}/LICENSE +0 -0
- {swarmauri_mre_crypto_pgp-0.3.0.dev45 → swarmauri_mre_crypto_pgp-0.11.0.dev1}/swarmauri_mre_crypto_pgp/__init__.py +0 -0
|
@@ -1,25 +1,26 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: swarmauri_mre_crypto_pgp
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.11.0.dev1
|
|
4
4
|
Summary: OpenPGP sealed-per-recipient MRE provider for Swarmauri
|
|
5
5
|
License-Expression: Apache-2.0
|
|
6
6
|
License-File: LICENSE
|
|
7
7
|
Keywords: swarmauri,sdk,standards,mre,crypto,pgp,cryptography
|
|
8
8
|
Author: Jacob Stewart
|
|
9
9
|
Author-email: jacob@swarmauri.com
|
|
10
|
-
Requires-Python: >=3.10,<3.
|
|
10
|
+
Requires-Python: >=3.10,<3.15
|
|
11
11
|
Classifier: License :: OSI Approved :: Apache Software License
|
|
12
12
|
Classifier: Natural Language :: English
|
|
13
|
-
Classifier: Programming Language :: Python :: 3.10
|
|
14
|
-
Classifier: Programming Language :: Python :: 3.11
|
|
15
|
-
Classifier: Programming Language :: Python :: 3.12
|
|
16
|
-
Classifier: Programming Language :: Python :: 3.13
|
|
17
13
|
Classifier: Development Status :: 3 - Alpha
|
|
18
14
|
Classifier: Topic :: Security :: Cryptography
|
|
19
15
|
Classifier: Intended Audience :: Developers
|
|
20
16
|
Classifier: Programming Language :: Python
|
|
21
17
|
Classifier: Programming Language :: Python :: 3
|
|
22
18
|
Classifier: Programming Language :: Python :: 3 :: Only
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
23
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
23
24
|
Provides-Extra: cbor
|
|
24
25
|
Provides-Extra: cryptography
|
|
25
26
|
Provides-Extra: pgpy
|
|
@@ -27,26 +28,26 @@ Requires-Dist: cbor2 (>=5.4.6) ; extra == "cbor"
|
|
|
27
28
|
Requires-Dist: cryptography (>=41.0.0) ; extra == "cryptography"
|
|
28
29
|
Requires-Dist: pgpy (>=0.6.0)
|
|
29
30
|
Requires-Dist: pgpy (>=0.6.0) ; extra == "pgpy"
|
|
31
|
+
Requires-Dist: standard-imghdr (>=3.13.0) ; python_version >= "3.13"
|
|
30
32
|
Requires-Dist: swarmauri_base
|
|
31
33
|
Requires-Dist: swarmauri_core
|
|
32
34
|
Description-Content-Type: text/markdown
|
|
33
35
|
|
|
34
|
-

|
|
35
37
|
|
|
36
38
|
<p align="center">
|
|
37
|
-
<a href="https://
|
|
38
|
-
<img src="https://
|
|
39
|
+
<a href="https://pepy.tech/project/swarmauri_mre_crypto_pgp/">
|
|
40
|
+
<img src="https://static.pepy.tech/badge/swarmauri_mre_crypto_pgp/month" alt="PyPI - Downloads"/></a>
|
|
39
41
|
<a href="https://hits.sh/github.com/swarmauri/swarmauri-sdk/tree/master/pkgs/standards/swarmauri_mre_crypto_pgp/">
|
|
40
42
|
<img alt="Hits" src="https://hits.sh/github.com/swarmauri/swarmauri-sdk/tree/master/pkgs/standards/swarmauri_mre_crypto_pgp.svg"/></a>
|
|
41
43
|
<a href="https://pypi.org/project/swarmauri_mre_crypto_pgp/">
|
|
42
|
-
<img src="https://img.shields.io/
|
|
44
|
+
<img src="https://img.shields.io/badge/python-3.10%20%7C%203.11%20%7C%203.12%20%7C%203.13%20%7C%203.14-blue" alt="PyPI - Python Version"/></a>
|
|
43
45
|
<a href="https://pypi.org/project/swarmauri_mre_crypto_pgp/">
|
|
44
46
|
<img src="https://img.shields.io/pypi/l/swarmauri_mre_crypto_pgp" alt="PyPI - License"/></a>
|
|
45
47
|
<a href="https://pypi.org/project/swarmauri_mre_crypto_pgp/">
|
|
46
48
|
<img src="https://img.shields.io/pypi/v/swarmauri_mre_crypto_pgp?label=swarmauri_mre_crypto_pgp&color=green" alt="PyPI - swarmauri_mre_crypto_pgp"/></a>
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
---
|
|
49
|
+
<a href="https://discord.gg/N4UpBuQv8T">
|
|
50
|
+
<img src="https://img.shields.io/badge/Discord-Join%20Chat-5865F2?logo=discord&logoColor=white" alt="Discord"/></a></p>
|
|
50
51
|
|
|
51
52
|
## Swarmauri MRE Crypto PGP
|
|
52
53
|
|
|
@@ -58,15 +59,15 @@ Providers that wrap a shared content-encryption key (CEK) additionally require
|
|
|
58
59
|
|
|
59
60
|
### Highlights
|
|
60
61
|
|
|
61
|
-
- **PGPSealMreCrypto**
|
|
62
|
+
- **PGPSealMreCrypto** ? Implements the `sealed_per_recipient` mode. Each
|
|
62
63
|
recipient receives a sealed copy of the plaintext. Associated data (AAD) is
|
|
63
64
|
not supported and re-wrapping new recipients requires the original plaintext
|
|
64
65
|
via `opts["plaintext"]`.
|
|
65
|
-
- **PGPSealedCekMreCrypto**
|
|
66
|
+
- **PGPSealedCekMreCrypto** ? Implements the `sealed_cek+aead` mode with an
|
|
66
67
|
AES-256-GCM payload. The CEK is sealed per recipient and can be re-used to
|
|
67
68
|
add or rotate recipients without decrypting the payload when
|
|
68
69
|
`opts["cek"]` or `opts["opener_identities"]` are supplied.
|
|
69
|
-
- **PGPMreCrypto**
|
|
70
|
+
- **PGPMreCrypto** ? Composite provider supporting both
|
|
70
71
|
`enc_once+per_recipient_header` (AES-256-GCM payload with OpenPGP headers)
|
|
71
72
|
and `sealed_per_recipient`. Re-wrapping shared-payload envelopes requires the
|
|
72
73
|
CEK via `opts["cek"]` or a managing private key supplied through
|
|
@@ -161,9 +162,9 @@ not match the expected values.
|
|
|
161
162
|
|
|
162
163
|
### Re-wrapping envelopes
|
|
163
164
|
|
|
164
|
-
- **Sealed per recipient**
|
|
165
|
+
- **Sealed per recipient** ? Re-wrapping with additional recipients requires
|
|
165
166
|
`opts["plaintext"]` so the providers can seal the original payload again.
|
|
166
|
-
- **Shared CEK (enc_once / sealed_cek)**
|
|
167
|
+
- **Shared CEK (enc_once / sealed_cek)** ? Supply either the decrypted CEK via
|
|
167
168
|
`opts["cek"]` or provide identities capable of opening the envelope through
|
|
168
169
|
`opts["manage_key"]` (composite provider) or
|
|
169
170
|
`opts["opener_identities"]` (sealed CEK provider).
|
|
@@ -180,3 +181,5 @@ Providers are registered under the `swarmauri.mre_cryptos` entry point as
|
|
|
180
181
|
If you want to contribute to swarmauri-sdk, read up on our
|
|
181
182
|
[guidelines for contributing](https://github.com/swarmauri/swarmauri-sdk/blob/master/CONTRIBUTING.md)
|
|
182
183
|
that will help you get started.
|
|
184
|
+
|
|
185
|
+
|
|
@@ -1,19 +1,18 @@
|
|
|
1
|
-

|
|
2
2
|
|
|
3
3
|
<p align="center">
|
|
4
|
-
<a href="https://
|
|
5
|
-
<img src="https://
|
|
4
|
+
<a href="https://pepy.tech/project/swarmauri_mre_crypto_pgp/">
|
|
5
|
+
<img src="https://static.pepy.tech/badge/swarmauri_mre_crypto_pgp/month" alt="PyPI - Downloads"/></a>
|
|
6
6
|
<a href="https://hits.sh/github.com/swarmauri/swarmauri-sdk/tree/master/pkgs/standards/swarmauri_mre_crypto_pgp/">
|
|
7
7
|
<img alt="Hits" src="https://hits.sh/github.com/swarmauri/swarmauri-sdk/tree/master/pkgs/standards/swarmauri_mre_crypto_pgp.svg"/></a>
|
|
8
8
|
<a href="https://pypi.org/project/swarmauri_mre_crypto_pgp/">
|
|
9
|
-
<img src="https://img.shields.io/
|
|
9
|
+
<img src="https://img.shields.io/badge/python-3.10%20%7C%203.11%20%7C%203.12%20%7C%203.13%20%7C%203.14-blue" alt="PyPI - Python Version"/></a>
|
|
10
10
|
<a href="https://pypi.org/project/swarmauri_mre_crypto_pgp/">
|
|
11
11
|
<img src="https://img.shields.io/pypi/l/swarmauri_mre_crypto_pgp" alt="PyPI - License"/></a>
|
|
12
12
|
<a href="https://pypi.org/project/swarmauri_mre_crypto_pgp/">
|
|
13
13
|
<img src="https://img.shields.io/pypi/v/swarmauri_mre_crypto_pgp?label=swarmauri_mre_crypto_pgp&color=green" alt="PyPI - swarmauri_mre_crypto_pgp"/></a>
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
---
|
|
14
|
+
<a href="https://discord.gg/N4UpBuQv8T">
|
|
15
|
+
<img src="https://img.shields.io/badge/Discord-Join%20Chat-5865F2?logo=discord&logoColor=white" alt="Discord"/></a></p>
|
|
17
16
|
|
|
18
17
|
## Swarmauri MRE Crypto PGP
|
|
19
18
|
|
|
@@ -25,15 +24,15 @@ Providers that wrap a shared content-encryption key (CEK) additionally require
|
|
|
25
24
|
|
|
26
25
|
### Highlights
|
|
27
26
|
|
|
28
|
-
- **PGPSealMreCrypto**
|
|
27
|
+
- **PGPSealMreCrypto** ? Implements the `sealed_per_recipient` mode. Each
|
|
29
28
|
recipient receives a sealed copy of the plaintext. Associated data (AAD) is
|
|
30
29
|
not supported and re-wrapping new recipients requires the original plaintext
|
|
31
30
|
via `opts["plaintext"]`.
|
|
32
|
-
- **PGPSealedCekMreCrypto**
|
|
31
|
+
- **PGPSealedCekMreCrypto** ? Implements the `sealed_cek+aead` mode with an
|
|
33
32
|
AES-256-GCM payload. The CEK is sealed per recipient and can be re-used to
|
|
34
33
|
add or rotate recipients without decrypting the payload when
|
|
35
34
|
`opts["cek"]` or `opts["opener_identities"]` are supplied.
|
|
36
|
-
- **PGPMreCrypto**
|
|
35
|
+
- **PGPMreCrypto** ? Composite provider supporting both
|
|
37
36
|
`enc_once+per_recipient_header` (AES-256-GCM payload with OpenPGP headers)
|
|
38
37
|
and `sealed_per_recipient`. Re-wrapping shared-payload envelopes requires the
|
|
39
38
|
CEK via `opts["cek"]` or a managing private key supplied through
|
|
@@ -128,9 +127,9 @@ not match the expected values.
|
|
|
128
127
|
|
|
129
128
|
### Re-wrapping envelopes
|
|
130
129
|
|
|
131
|
-
- **Sealed per recipient**
|
|
130
|
+
- **Sealed per recipient** ? Re-wrapping with additional recipients requires
|
|
132
131
|
`opts["plaintext"]` so the providers can seal the original payload again.
|
|
133
|
-
- **Shared CEK (enc_once / sealed_cek)**
|
|
132
|
+
- **Shared CEK (enc_once / sealed_cek)** ? Supply either the decrypted CEK via
|
|
134
133
|
`opts["cek"]` or provide identities capable of opening the envelope through
|
|
135
134
|
`opts["manage_key"]` (composite provider) or
|
|
136
135
|
`opts["opener_identities"]` (sealed CEK provider).
|
|
@@ -146,4 +145,5 @@ Providers are registered under the `swarmauri.mre_cryptos` entry point as
|
|
|
146
145
|
|
|
147
146
|
If you want to contribute to swarmauri-sdk, read up on our
|
|
148
147
|
[guidelines for contributing](https://github.com/swarmauri/swarmauri-sdk/blob/master/CONTRIBUTING.md)
|
|
149
|
-
that will help you get started.
|
|
148
|
+
that will help you get started.
|
|
149
|
+
|
{swarmauri_mre_crypto_pgp-0.3.0.dev45 → swarmauri_mre_crypto_pgp-0.11.0.dev1}/pyproject.toml
RENAMED
|
@@ -1,29 +1,31 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "swarmauri_mre_crypto_pgp"
|
|
3
|
-
version = "0.
|
|
3
|
+
version = "0.11.0.dev1"
|
|
4
4
|
description = "OpenPGP sealed-per-recipient MRE provider for Swarmauri"
|
|
5
5
|
license = "Apache-2.0"
|
|
6
6
|
readme = "README.md"
|
|
7
|
-
requires-python = ">=3.10,<3.
|
|
7
|
+
requires-python = ">=3.10,<3.15"
|
|
8
8
|
authors = [{ name = "Jacob Stewart", email = "jacob@swarmauri.com" }]
|
|
9
9
|
classifiers = [
|
|
10
10
|
"License :: OSI Approved :: Apache Software License",
|
|
11
11
|
"Natural Language :: English",
|
|
12
|
-
"Programming Language :: Python :: 3.10",
|
|
13
|
-
"Programming Language :: Python :: 3.11",
|
|
14
|
-
"Programming Language :: Python :: 3.12",
|
|
15
|
-
"Programming Language :: Python :: 3.13",
|
|
16
12
|
"Development Status :: 3 - Alpha",
|
|
17
13
|
"Topic :: Security :: Cryptography",
|
|
18
14
|
"Intended Audience :: Developers",
|
|
19
15
|
"Programming Language :: Python",
|
|
20
16
|
"Programming Language :: Python :: 3",
|
|
21
17
|
"Programming Language :: Python :: 3 :: Only",
|
|
18
|
+
"Programming Language :: Python :: 3.10",
|
|
19
|
+
"Programming Language :: Python :: 3.11",
|
|
20
|
+
"Programming Language :: Python :: 3.12",
|
|
21
|
+
"Programming Language :: Python :: 3.13",
|
|
22
|
+
"Programming Language :: Python :: 3.14",
|
|
22
23
|
]
|
|
23
24
|
dependencies = [
|
|
24
25
|
"swarmauri_core",
|
|
25
26
|
"swarmauri_base",
|
|
26
27
|
"pgpy>=0.6.0",
|
|
28
|
+
"standard-imghdr>=3.13.0; python_version >= '3.13'",
|
|
27
29
|
]
|
|
28
30
|
keywords = [
|
|
29
31
|
'swarmauri',
|
|
@@ -5,7 +5,11 @@ from __future__ import annotations
|
|
|
5
5
|
import base64
|
|
6
6
|
from typing import Any, Dict, Iterable, List, Mapping, Optional, Sequence
|
|
7
7
|
|
|
8
|
-
from swarmauri_core.mre_crypto.types import
|
|
8
|
+
from swarmauri_core.mre_crypto.types import (
|
|
9
|
+
MultiRecipientEnvelope,
|
|
10
|
+
RecipientId,
|
|
11
|
+
MreMode,
|
|
12
|
+
)
|
|
9
13
|
from swarmauri_core.crypto.types import Alg, KeyRef
|
|
10
14
|
from swarmauri_base.mre_crypto.MreCryptoBase import MreCryptoBase
|
|
11
15
|
from swarmauri_base.ComponentBase import ComponentBase
|
|
@@ -37,7 +41,9 @@ def _load_pubkey(ref: KeyRef) -> "pgpy.PGPKey":
|
|
|
37
41
|
raise TypeError("Unsupported recipient KeyRef for PGP public key.")
|
|
38
42
|
|
|
39
43
|
|
|
40
|
-
def _load_privkey(
|
|
44
|
+
def _load_privkey(
|
|
45
|
+
ref: KeyRef, passphrase: Optional[bytes | str]
|
|
46
|
+
) -> "pgpy.PGPKey":
|
|
41
47
|
_ensure_pgpy()
|
|
42
48
|
if isinstance(ref, dict):
|
|
43
49
|
kind = ref.get("kind")
|
|
@@ -115,10 +121,15 @@ class PGPSealMreCrypto(MreCryptoBase):
|
|
|
115
121
|
)
|
|
116
122
|
if m != MreMode.SEALED_PER_RECIPIENT:
|
|
117
123
|
raise ValueError(
|
|
118
|
-
|
|
124
|
+
(
|
|
125
|
+
f"PGPSealMreCrypto supports only "
|
|
126
|
+
f"mode={MreMode.SEALED_PER_RECIPIENT.value}."
|
|
127
|
+
)
|
|
119
128
|
)
|
|
120
129
|
if aad is not None:
|
|
121
|
-
raise ValueError(
|
|
130
|
+
raise ValueError(
|
|
131
|
+
"AAD is not supported in sealed_per_recipient mode."
|
|
132
|
+
)
|
|
122
133
|
|
|
123
134
|
pubs = [_load_pubkey(r) for r in recipients]
|
|
124
135
|
rids = [_fingerprint_pub(pk) for pk in pubs]
|
|
@@ -146,9 +157,13 @@ class PGPSealMreCrypto(MreCryptoBase):
|
|
|
146
157
|
) -> bytes:
|
|
147
158
|
_ensure_pgpy()
|
|
148
159
|
if env.get("mode") != MreMode.SEALED_PER_RECIPIENT.value:
|
|
149
|
-
raise ValueError(
|
|
160
|
+
raise ValueError(
|
|
161
|
+
"Envelope mode mismatch; expected sealed_per_recipient."
|
|
162
|
+
)
|
|
150
163
|
if aad is not None:
|
|
151
|
-
raise ValueError(
|
|
164
|
+
raise ValueError(
|
|
165
|
+
"AAD is not supported in sealed_per_recipient mode."
|
|
166
|
+
)
|
|
152
167
|
|
|
153
168
|
priv = _load_privkey(my_identity, (opts or {}).get("passphrase"))
|
|
154
169
|
my_id = str(priv.fingerprint)
|
|
@@ -193,12 +208,16 @@ class PGPSealMreCrypto(MreCryptoBase):
|
|
|
193
208
|
) -> MultiRecipientEnvelope:
|
|
194
209
|
_ensure_pgpy()
|
|
195
210
|
if env.get("mode") != MreMode.SEALED_PER_RECIPIENT.value:
|
|
196
|
-
raise ValueError(
|
|
211
|
+
raise ValueError(
|
|
212
|
+
"Envelope mode mismatch; expected sealed_per_recipient."
|
|
213
|
+
)
|
|
197
214
|
|
|
198
215
|
add = add or ()
|
|
199
216
|
remove_ids = set(remove or ())
|
|
200
217
|
new_env: MultiRecipientEnvelope = {k: v for k, v in env.items()}
|
|
201
|
-
current_entries: List[Dict[str, Any]] = list(
|
|
218
|
+
current_entries: List[Dict[str, Any]] = list(
|
|
219
|
+
new_env.get("recipients", [])
|
|
220
|
+
)
|
|
202
221
|
if remove_ids:
|
|
203
222
|
current_entries = [
|
|
204
223
|
e for e in current_entries if e.get("id") not in remove_ids
|
|
@@ -207,16 +226,23 @@ class PGPSealMreCrypto(MreCryptoBase):
|
|
|
207
226
|
pt_bytes = (opts or {}).get("plaintext")
|
|
208
227
|
if not isinstance(pt_bytes, (bytes, bytearray)):
|
|
209
228
|
raise RuntimeError(
|
|
210
|
-
|
|
229
|
+
(
|
|
230
|
+
"Rewrap(add=...) in sealed_per_recipient mode requires " # noqa: E501
|
|
231
|
+
"opts['plaintext'] (bytes)."
|
|
232
|
+
)
|
|
211
233
|
)
|
|
212
234
|
pubs = [_load_pubkey(r) for r in add]
|
|
213
235
|
rids = [_fingerprint_pub(pk) for pk in pubs]
|
|
214
236
|
new_entries = [
|
|
215
|
-
_make_sealed_recipient(
|
|
237
|
+
_make_sealed_recipient(
|
|
238
|
+
rid, _pgp_encrypt_bytes_for(pk, pt_bytes)
|
|
239
|
+
)
|
|
216
240
|
for rid, pk in zip(rids, pubs)
|
|
217
241
|
]
|
|
218
242
|
remaining = [
|
|
219
|
-
e
|
|
243
|
+
e
|
|
244
|
+
for e in current_entries
|
|
245
|
+
if e["id"] not in {rid for rid in rids}
|
|
220
246
|
]
|
|
221
247
|
current_entries = remaining + new_entries
|
|
222
248
|
new_env["recipients"] = current_entries
|
|
@@ -16,7 +16,11 @@ from typing import (
|
|
|
16
16
|
Tuple,
|
|
17
17
|
)
|
|
18
18
|
|
|
19
|
-
from swarmauri_core.mre_crypto.types import
|
|
19
|
+
from swarmauri_core.mre_crypto.types import (
|
|
20
|
+
MultiRecipientEnvelope,
|
|
21
|
+
RecipientId,
|
|
22
|
+
MreMode,
|
|
23
|
+
)
|
|
20
24
|
from swarmauri_core.crypto.types import Alg, KeyRef
|
|
21
25
|
from swarmauri_base.mre_crypto.MreCryptoBase import MreCryptoBase
|
|
22
26
|
from swarmauri_base.ComponentBase import ComponentBase
|
|
@@ -39,7 +43,10 @@ except Exception: # pragma: no cover
|
|
|
39
43
|
def _ensure_crypto() -> None:
|
|
40
44
|
if not _CRYPTOGRAPHY_OK:
|
|
41
45
|
raise RuntimeError(
|
|
42
|
-
|
|
46
|
+
(
|
|
47
|
+
"PGPMreCrypto requires 'cryptography'. Install with: pip "
|
|
48
|
+
"install cryptography"
|
|
49
|
+
)
|
|
43
50
|
)
|
|
44
51
|
|
|
45
52
|
|
|
@@ -67,7 +74,9 @@ def _load_pubkey(ref: KeyRef) -> "pgpy.PGPKey":
|
|
|
67
74
|
raise TypeError("Unsupported recipient KeyRef for PGP public key.")
|
|
68
75
|
|
|
69
76
|
|
|
70
|
-
def _load_privkey(
|
|
77
|
+
def _load_privkey(
|
|
78
|
+
ref: KeyRef, passphrase: Optional[bytes | str]
|
|
79
|
+
) -> "pgpy.PGPKey":
|
|
71
80
|
_ensure_pgpy()
|
|
72
81
|
if isinstance(ref, dict):
|
|
73
82
|
kind = ref.get("kind")
|
|
@@ -203,7 +212,11 @@ class PGPMreCrypto(MreCryptoBase):
|
|
|
203
212
|
if m == MreMode.ENC_ONCE_HEADERS:
|
|
204
213
|
if payload_alg != "AES-256-GCM":
|
|
205
214
|
raise ValueError(
|
|
206
|
-
|
|
215
|
+
(
|
|
216
|
+
"PGPMreCrypto currently supports only AES-256-GCM for "
|
|
217
|
+
"shared "
|
|
218
|
+
"payload."
|
|
219
|
+
)
|
|
207
220
|
)
|
|
208
221
|
cek = os.urandom(32)
|
|
209
222
|
nonce, ct, tag = _aead_encrypt_gcm(cek, pt, aad=aad)
|
|
@@ -215,7 +228,9 @@ class PGPMreCrypto(MreCryptoBase):
|
|
|
215
228
|
"mode": MreMode.ENC_ONCE_HEADERS.value,
|
|
216
229
|
"payload_alg": payload_alg,
|
|
217
230
|
"recipient_alg": "OpenPGP",
|
|
218
|
-
"payload": _make_aead_payload(
|
|
231
|
+
"payload": _make_aead_payload(
|
|
232
|
+
payload_alg, nonce, ct, tag, aad
|
|
233
|
+
),
|
|
219
234
|
"recipients": headers,
|
|
220
235
|
}
|
|
221
236
|
if shared:
|
|
@@ -268,11 +283,15 @@ class PGPMreCrypto(MreCryptoBase):
|
|
|
268
283
|
except Exception:
|
|
269
284
|
continue
|
|
270
285
|
if cek is None:
|
|
271
|
-
raise PermissionError(
|
|
286
|
+
raise PermissionError(
|
|
287
|
+
"This identity cannot open the envelope."
|
|
288
|
+
)
|
|
272
289
|
|
|
273
290
|
payload = env["payload"]
|
|
274
291
|
if payload.get("alg") != "AES-256-GCM":
|
|
275
|
-
raise ValueError(
|
|
292
|
+
raise ValueError(
|
|
293
|
+
"Unsupported payload_alg for PGPMreCrypto open."
|
|
294
|
+
)
|
|
276
295
|
nonce, ct, tag = payload["nonce"], payload["ct"], payload["tag"]
|
|
277
296
|
bound_aad = payload.get("aad", None)
|
|
278
297
|
if aad is not None and bound_aad is not None and aad != bound_aad:
|
|
@@ -289,7 +308,9 @@ class PGPMreCrypto(MreCryptoBase):
|
|
|
289
308
|
return _pgp_decrypt_bytes_with(priv, e["sealed"])
|
|
290
309
|
except Exception:
|
|
291
310
|
continue
|
|
292
|
-
raise PermissionError(
|
|
311
|
+
raise PermissionError(
|
|
312
|
+
"This identity cannot open the sealed envelope."
|
|
313
|
+
)
|
|
293
314
|
return _pgp_decrypt_bytes_with(priv, target["sealed"])
|
|
294
315
|
|
|
295
316
|
raise ValueError(f"Unsupported mode: {mode_str}")
|
|
@@ -332,7 +353,9 @@ class PGPMreCrypto(MreCryptoBase):
|
|
|
332
353
|
new_env: MultiRecipientEnvelope = {k: v for k, v in env.items()}
|
|
333
354
|
|
|
334
355
|
if m == MreMode.ENC_ONCE_HEADERS:
|
|
335
|
-
current_headers: List[Dict[str, Any]] = list(
|
|
356
|
+
current_headers: List[Dict[str, Any]] = list(
|
|
357
|
+
new_env.get("recipients", [])
|
|
358
|
+
)
|
|
336
359
|
if remove_ids:
|
|
337
360
|
current_headers = [
|
|
338
361
|
h for h in current_headers if h.get("id") not in remove_ids
|
|
@@ -351,20 +374,27 @@ class PGPMreCrypto(MreCryptoBase):
|
|
|
351
374
|
)
|
|
352
375
|
for h in candidate_headers:
|
|
353
376
|
try:
|
|
354
|
-
cek = _pgp_decrypt_bytes_with(
|
|
377
|
+
cek = _pgp_decrypt_bytes_with(
|
|
378
|
+
manage_key, h["header"]
|
|
379
|
+
)
|
|
355
380
|
break
|
|
356
381
|
except Exception:
|
|
357
382
|
continue
|
|
358
383
|
else:
|
|
359
384
|
raise RuntimeError(
|
|
360
|
-
|
|
385
|
+
(
|
|
386
|
+
"Rewrap(add=...) requires opts['cek'] or "
|
|
387
|
+
"opts['manage_key']."
|
|
388
|
+
)
|
|
361
389
|
)
|
|
362
390
|
|
|
363
391
|
if add and cek is not None:
|
|
364
392
|
pubs = [_load_pubkey(r) for r in add]
|
|
365
393
|
rids = [_fingerprint_pub(pk) for pk in pubs]
|
|
366
394
|
new_headers = [
|
|
367
|
-
_make_recipient_header(
|
|
395
|
+
_make_recipient_header(
|
|
396
|
+
rid, _pgp_encrypt_bytes_for(pk, cek)
|
|
397
|
+
)
|
|
368
398
|
for rid, pk in zip(rids, pubs)
|
|
369
399
|
]
|
|
370
400
|
merged: List[Dict[str, Any]] = []
|
|
@@ -374,7 +404,9 @@ class PGPMreCrypto(MreCryptoBase):
|
|
|
374
404
|
merged.extend(new_headers)
|
|
375
405
|
current_headers = merged
|
|
376
406
|
|
|
377
|
-
rotate =
|
|
407
|
+
rotate = (
|
|
408
|
+
bool(opts.get("rotate_payload_on_revoke")) if opts else False
|
|
409
|
+
)
|
|
378
410
|
if remove_ids and rotate:
|
|
379
411
|
if not cek:
|
|
380
412
|
if opts and opts.get("manage_key"):
|
|
@@ -383,13 +415,18 @@ class PGPMreCrypto(MreCryptoBase):
|
|
|
383
415
|
)
|
|
384
416
|
for h in env.get("recipients", []):
|
|
385
417
|
try:
|
|
386
|
-
cek = _pgp_decrypt_bytes_with(
|
|
418
|
+
cek = _pgp_decrypt_bytes_with(
|
|
419
|
+
manage_key, h["header"]
|
|
420
|
+
)
|
|
387
421
|
break
|
|
388
422
|
except Exception:
|
|
389
423
|
continue
|
|
390
424
|
if not cek:
|
|
391
425
|
raise RuntimeError(
|
|
392
|
-
|
|
426
|
+
(
|
|
427
|
+
"rotate_payload_on_revoke requires CEK via opts['manage_key'] " # noqa: E501
|
|
428
|
+
"or opts['cek']."
|
|
429
|
+
)
|
|
393
430
|
)
|
|
394
431
|
|
|
395
432
|
new_cek = os.urandom(32)
|
|
@@ -413,14 +450,22 @@ class PGPMreCrypto(MreCryptoBase):
|
|
|
413
450
|
)
|
|
414
451
|
|
|
415
452
|
add_pubkeys = (opts or {}).get("add_pubkeys")
|
|
416
|
-
if
|
|
453
|
+
if (
|
|
454
|
+
not isinstance(add_pubkeys, (list, tuple))
|
|
455
|
+
or not add_pubkeys
|
|
456
|
+
):
|
|
417
457
|
raise RuntimeError(
|
|
418
|
-
|
|
458
|
+
(
|
|
459
|
+
"After rotation, provide opts['add_pubkeys'] = "
|
|
460
|
+
"[KeyRef(pub=...), ...] for remaining recipients."
|
|
461
|
+
)
|
|
419
462
|
)
|
|
420
463
|
pubs = [_load_pubkey(r) for r in add_pubkeys]
|
|
421
464
|
rids = [_fingerprint_pub(pk) for pk in pubs]
|
|
422
465
|
new_headers = [
|
|
423
|
-
_make_recipient_header(
|
|
466
|
+
_make_recipient_header(
|
|
467
|
+
rid, _pgp_encrypt_bytes_for(pk, new_cek)
|
|
468
|
+
)
|
|
424
469
|
for rid, pk in zip(rids, pubs)
|
|
425
470
|
]
|
|
426
471
|
current_headers = new_headers
|
|
@@ -429,7 +474,9 @@ class PGPMreCrypto(MreCryptoBase):
|
|
|
429
474
|
return new_env
|
|
430
475
|
|
|
431
476
|
if m == MreMode.SEALED_PER_RECIPIENT:
|
|
432
|
-
current_entries: List[Dict[str, Any]] = list(
|
|
477
|
+
current_entries: List[Dict[str, Any]] = list(
|
|
478
|
+
new_env.get("recipients", [])
|
|
479
|
+
)
|
|
433
480
|
if remove_ids:
|
|
434
481
|
current_entries = [
|
|
435
482
|
e for e in current_entries if e.get("id") not in remove_ids
|
|
@@ -438,16 +485,24 @@ class PGPMreCrypto(MreCryptoBase):
|
|
|
438
485
|
pt_bytes = (opts or {}).get("plaintext")
|
|
439
486
|
if not isinstance(pt_bytes, (bytes, bytearray)):
|
|
440
487
|
raise RuntimeError(
|
|
441
|
-
|
|
488
|
+
(
|
|
489
|
+
"Rewrap(add=...) in sealed_per_recipient mode "
|
|
490
|
+
"requires "
|
|
491
|
+
"opts['plaintext']."
|
|
492
|
+
)
|
|
442
493
|
)
|
|
443
494
|
pubs = [_load_pubkey(r) for r in add]
|
|
444
495
|
rids = [_fingerprint_pub(pk) for pk in pubs]
|
|
445
496
|
new_entries = [
|
|
446
|
-
_make_sealed_recipient(
|
|
497
|
+
_make_sealed_recipient(
|
|
498
|
+
rid, _pgp_encrypt_bytes_for(pk, pt_bytes)
|
|
499
|
+
)
|
|
447
500
|
for rid, pk in zip(rids, pubs)
|
|
448
501
|
]
|
|
449
502
|
remaining = [
|
|
450
|
-
e
|
|
503
|
+
e
|
|
504
|
+
for e in current_entries
|
|
505
|
+
if e["id"] not in {rid for rid in rids}
|
|
451
506
|
]
|
|
452
507
|
current_entries = remaining + new_entries
|
|
453
508
|
|
|
@@ -6,7 +6,16 @@ sealing of the content-encryption key (CEK).
|
|
|
6
6
|
|
|
7
7
|
from __future__ import annotations
|
|
8
8
|
|
|
9
|
-
from typing import
|
|
9
|
+
from typing import (
|
|
10
|
+
Any,
|
|
11
|
+
Dict,
|
|
12
|
+
Iterable,
|
|
13
|
+
List,
|
|
14
|
+
Mapping,
|
|
15
|
+
Optional,
|
|
16
|
+
Sequence,
|
|
17
|
+
Tuple,
|
|
18
|
+
)
|
|
10
19
|
|
|
11
20
|
import os
|
|
12
21
|
|
|
@@ -14,7 +23,10 @@ from swarmauri_core.mre_crypto.IMreCrypto import IMreCrypto
|
|
|
14
23
|
from swarmauri_core.crypto.types import Alg, KeyRef
|
|
15
24
|
|
|
16
25
|
try: # type-checking only
|
|
17
|
-
from swarmauri_core.mre_crypto.types import
|
|
26
|
+
from swarmauri_core.mre_crypto.types import (
|
|
27
|
+
MultiRecipientEnvelope,
|
|
28
|
+
RecipientId,
|
|
29
|
+
)
|
|
18
30
|
except Exception: # pragma: no cover - typing fallback
|
|
19
31
|
MultiRecipientEnvelope = Dict[str, Any] # type: ignore
|
|
20
32
|
RecipientId = str # type: ignore
|
|
@@ -37,14 +49,20 @@ except Exception: # pragma: no cover
|
|
|
37
49
|
def _ensure_crypto() -> None:
|
|
38
50
|
if not _CRYPTOGRAPHY_OK:
|
|
39
51
|
raise RuntimeError(
|
|
40
|
-
|
|
52
|
+
(
|
|
53
|
+
"PGPSealedCekMreCrypto requires 'cryptography'. Install with: "
|
|
54
|
+
"pip install cryptography"
|
|
55
|
+
)
|
|
41
56
|
)
|
|
42
57
|
|
|
43
58
|
|
|
44
59
|
def _ensure_pgpy() -> None:
|
|
45
60
|
if not _PGP_OK:
|
|
46
61
|
raise RuntimeError(
|
|
47
|
-
|
|
62
|
+
(
|
|
63
|
+
"PGPSealedCekMreCrypto requires 'PGPy'. Install with: pip "
|
|
64
|
+
"install pgpy"
|
|
65
|
+
)
|
|
48
66
|
)
|
|
49
67
|
|
|
50
68
|
|
|
@@ -65,9 +83,13 @@ def _load_pgpy_pubkey(rec: KeyRef) -> Tuple[str, "pgpy.PGPKey"]:
|
|
|
65
83
|
elif kind == "pgpy_pub_armored" and isinstance(rec.get("pub"), str):
|
|
66
84
|
pk, _ = pgpy.PGPKey.from_blob(rec["pub"])
|
|
67
85
|
else:
|
|
68
|
-
raise TypeError(
|
|
86
|
+
raise TypeError(
|
|
87
|
+
"Unsupported KeyRef for PGP public key encryption."
|
|
88
|
+
)
|
|
69
89
|
else:
|
|
70
|
-
raise TypeError(
|
|
90
|
+
raise TypeError(
|
|
91
|
+
"Unsupported KeyRef type for PGP public key encryption."
|
|
92
|
+
)
|
|
71
93
|
|
|
72
94
|
if getattr(pk, "is_public", True) is False and hasattr(pk, "pubkey"):
|
|
73
95
|
pk = pk.pubkey # type: ignore[arg-type]
|
|
@@ -93,7 +115,9 @@ def _load_pgpy_privkey(
|
|
|
93
115
|
|
|
94
116
|
if getattr(k, "is_unlocked", True) is False:
|
|
95
117
|
if passphrase is None:
|
|
96
|
-
raise RuntimeError(
|
|
118
|
+
raise RuntimeError(
|
|
119
|
+
"PGP private key is locked. Provide opts['passphrase']."
|
|
120
|
+
)
|
|
97
121
|
k.unlock(passphrase)
|
|
98
122
|
return k
|
|
99
123
|
|
|
@@ -128,7 +152,9 @@ def _aead_decrypt(
|
|
|
128
152
|
class PGPSealedCekMreCrypto(IMreCrypto):
|
|
129
153
|
"""IMreCrypto provider for the ``sealed_cek+aead`` mode using OpenPGP."""
|
|
130
154
|
|
|
131
|
-
def supports(
|
|
155
|
+
def supports(
|
|
156
|
+
self,
|
|
157
|
+
) -> Dict[str, Iterable[str]]: # pragma: no cover - trivial
|
|
132
158
|
return {
|
|
133
159
|
"payload": ("AES-256-GCM",),
|
|
134
160
|
"recipient": ("OpenPGP-SEAL",),
|
|
@@ -155,11 +181,16 @@ class PGPSealedCekMreCrypto(IMreCrypto):
|
|
|
155
181
|
)
|
|
156
182
|
payload_alg = payload_alg or "AES-256-GCM"
|
|
157
183
|
if payload_alg != "AES-256-GCM":
|
|
158
|
-
raise ValueError(
|
|
184
|
+
raise ValueError(
|
|
185
|
+
"Unsupported payload_alg for PGPSealedCekMreCrypto."
|
|
186
|
+
)
|
|
159
187
|
recipient_alg = recipient_alg or "OpenPGP-SEAL"
|
|
160
188
|
if recipient_alg != "OpenPGP-SEAL":
|
|
161
189
|
raise ValueError(
|
|
162
|
-
|
|
190
|
+
(
|
|
191
|
+
"Unsupported recipient_alg for PGPSealedCekMreCrypto "
|
|
192
|
+
"(expected 'OpenPGP-SEAL')."
|
|
193
|
+
)
|
|
163
194
|
)
|
|
164
195
|
if not recipients:
|
|
165
196
|
raise ValueError("At least one recipient is required.")
|
|
@@ -221,7 +252,9 @@ class PGPSealedCekMreCrypto(IMreCrypto):
|
|
|
221
252
|
if opts and "passphrase" in opts:
|
|
222
253
|
passphrase = opts["passphrase"]
|
|
223
254
|
priv = _load_pgpy_privkey(my_identity, passphrase=passphrase)
|
|
224
|
-
my_rid = str(
|
|
255
|
+
my_rid = str(
|
|
256
|
+
(priv.pubkey if hasattr(priv, "pubkey") else priv).fingerprint
|
|
257
|
+
)
|
|
225
258
|
|
|
226
259
|
header = None
|
|
227
260
|
for ent in env.get("recipients") or []:
|
|
@@ -254,7 +287,9 @@ class PGPSealedCekMreCrypto(IMreCrypto):
|
|
|
254
287
|
raise (
|
|
255
288
|
last_err
|
|
256
289
|
if last_err
|
|
257
|
-
else RuntimeError(
|
|
290
|
+
else RuntimeError(
|
|
291
|
+
"Failed to open envelope with provided identities."
|
|
292
|
+
)
|
|
258
293
|
)
|
|
259
294
|
|
|
260
295
|
async def rewrap(
|
|
@@ -270,16 +305,19 @@ class PGPSealedCekMreCrypto(IMreCrypto):
|
|
|
270
305
|
raise ValueError("Unsupported envelope mode for rewrap.")
|
|
271
306
|
if recipient_alg and recipient_alg != "OpenPGP-SEAL":
|
|
272
307
|
raise ValueError(
|
|
273
|
-
|
|
308
|
+
(
|
|
309
|
+
"PGPSealedCekMreCrypto only supports "
|
|
310
|
+
"recipient_alg='OpenPGP-SEAL' in rewrap."
|
|
311
|
+
)
|
|
274
312
|
)
|
|
275
313
|
|
|
276
314
|
add = add or []
|
|
277
315
|
remove_ids = set(remove or [])
|
|
278
316
|
recipients = list(env.get("recipients") or [])
|
|
279
317
|
payload = env.get("payload") or {}
|
|
280
|
-
rotate_flag = bool(
|
|
281
|
-
|
|
282
|
-
)
|
|
318
|
+
rotate_flag = bool(
|
|
319
|
+
(opts or {}).get("rotate_payload_on_revoke")
|
|
320
|
+
) and bool(remove_ids)
|
|
283
321
|
|
|
284
322
|
cek: Optional[bytes] = None
|
|
285
323
|
need_cek = add or rotate_flag
|
|
@@ -290,7 +328,10 @@ class PGPSealedCekMreCrypto(IMreCrypto):
|
|
|
290
328
|
opener_list = (opts or {}).get("opener_identities")
|
|
291
329
|
if not opener_list:
|
|
292
330
|
raise RuntimeError(
|
|
293
|
-
|
|
331
|
+
(
|
|
332
|
+
"Rewrap(add=... or rotate) requires opts['cek'] or " # noqa: E501
|
|
333
|
+
"opts['opener_identities']."
|
|
334
|
+
)
|
|
294
335
|
)
|
|
295
336
|
if not isinstance(opener_list, (list, tuple)):
|
|
296
337
|
opener_list = [opener_list]
|
|
@@ -300,7 +341,9 @@ class PGPSealedCekMreCrypto(IMreCrypto):
|
|
|
300
341
|
priv = _load_pgpy_privkey(ident, passphrase=passphrase)
|
|
301
342
|
for ent in recipients:
|
|
302
343
|
try:
|
|
303
|
-
sealed = pgpy.PGPMessage.from_blob(
|
|
344
|
+
sealed = pgpy.PGPMessage.from_blob(
|
|
345
|
+
bytes(ent["header"])
|
|
346
|
+
)
|
|
304
347
|
with priv:
|
|
305
348
|
lit = priv.decrypt(sealed)
|
|
306
349
|
cek = bytes(lit.message)
|
|
@@ -315,13 +358,19 @@ class PGPSealedCekMreCrypto(IMreCrypto):
|
|
|
315
358
|
raise RuntimeError("Unable to recover CEK for rewrap.")
|
|
316
359
|
|
|
317
360
|
if remove_ids:
|
|
318
|
-
recipients = [
|
|
361
|
+
recipients = [
|
|
362
|
+
r for r in recipients if r.get("id") not in remove_ids
|
|
363
|
+
]
|
|
319
364
|
|
|
320
365
|
if rotate_flag and cek is not None:
|
|
321
366
|
new_cek = os.urandom(32)
|
|
322
367
|
bound_aad = payload.get("aad")
|
|
323
368
|
pt = _aead_decrypt(
|
|
324
|
-
cek,
|
|
369
|
+
cek,
|
|
370
|
+
payload["nonce"],
|
|
371
|
+
payload["ct"],
|
|
372
|
+
payload["tag"],
|
|
373
|
+
aad=bound_aad,
|
|
325
374
|
)
|
|
326
375
|
nonce, ct, tag = _aead_encrypt(new_cek, pt, aad=bound_aad)
|
|
327
376
|
env["payload"] = {
|
|
File without changes
|
|
File without changes
|