swarmauri_signing_pgp 0.3.0.dev4__tar.gz → 0.3.0.dev30__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_signing_pgp-0.3.0.dev30/PKG-INFO +176 -0
- swarmauri_signing_pgp-0.3.0.dev30/README.md +143 -0
- {swarmauri_signing_pgp-0.3.0.dev4 → swarmauri_signing_pgp-0.3.0.dev30}/pyproject.toml +27 -5
- {swarmauri_signing_pgp-0.3.0.dev4 → swarmauri_signing_pgp-0.3.0.dev30}/swarmauri_signing_pgp/pgp_signer.py +167 -4
- swarmauri_signing_pgp-0.3.0.dev4/PKG-INFO +0 -67
- swarmauri_signing_pgp-0.3.0.dev4/README.md +0 -41
- {swarmauri_signing_pgp-0.3.0.dev4 → swarmauri_signing_pgp-0.3.0.dev30}/LICENSE +0 -0
- {swarmauri_signing_pgp-0.3.0.dev4 → swarmauri_signing_pgp-0.3.0.dev30}/swarmauri_signing_pgp/__init__.py +0 -0
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: swarmauri_signing_pgp
|
|
3
|
+
Version: 0.3.0.dev30
|
|
4
|
+
Summary: OpenPGP envelope signer for Swarmauri
|
|
5
|
+
License-Expression: Apache-2.0
|
|
6
|
+
License-File: LICENSE
|
|
7
|
+
Keywords: swarmauri,signing,pgp,openpgp,envelope,sdk,standards,cryptography,digital-signature,pgp-keys,ascii-armor,message-codec,openpgp-format
|
|
8
|
+
Author: Jacob Stewart
|
|
9
|
+
Author-email: jacob@swarmauri.com
|
|
10
|
+
Requires-Python: >=3.10,<3.13
|
|
11
|
+
Classifier: Development Status :: 1 - Planning
|
|
12
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
13
|
+
Classifier: Natural Language :: English
|
|
14
|
+
Classifier: Programming Language :: Python
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Classifier: Topic :: Security :: Cryptography
|
|
20
|
+
Classifier: Intended Audience :: Developers
|
|
21
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
22
|
+
Provides-Extra: cbor
|
|
23
|
+
Requires-Dist: cbor2 (>=5.4.6) ; extra == "cbor"
|
|
24
|
+
Requires-Dist: pgpy (>=0.6.0)
|
|
25
|
+
Requires-Dist: swarmauri_base
|
|
26
|
+
Requires-Dist: swarmauri_core
|
|
27
|
+
Requires-Dist: swarmauri_standard
|
|
28
|
+
Project-URL: Documentation, https://github.com/swarmauri/swarmauri-sdk/tree/main/pkgs/standards/swarmauri_signing_pgp#readme
|
|
29
|
+
Project-URL: Homepage, https://github.com/swarmauri/swarmauri-sdk
|
|
30
|
+
Project-URL: Source, https://github.com/swarmauri/swarmauri-sdk/tree/main/pkgs/standards/swarmauri_signing_pgp
|
|
31
|
+
Description-Content-Type: text/markdown
|
|
32
|
+
|
|
33
|
+

|
|
34
|
+
|
|
35
|
+
<p align="center">
|
|
36
|
+
<a href="https://pypi.org/project/swarmauri_signing_pgp/">
|
|
37
|
+
<img src="https://img.shields.io/pypi/dm/swarmauri_signing_pgp" alt="PyPI - Downloads"/></a>
|
|
38
|
+
<a href="https://hits.sh/github.com/swarmauri/swarmauri-sdk/tree/master/pkgs/standards/swarmauri_signing_pgp/">
|
|
39
|
+
<img alt="Hits" src="https://hits.sh/github.com/swarmauri/swarmauri-sdk/tree/master/pkgs/standards/swarmauri_signing_pgp.svg"/></a>
|
|
40
|
+
<a href="https://pypi.org/project/swarmauri_signing_pgp/">
|
|
41
|
+
<img src="https://img.shields.io/pypi/pyversions/swarmauri_signing_pgp" alt="PyPI - Python Version"/></a>
|
|
42
|
+
<a href="https://pypi.org/project/swarmauri_signing_pgp/">
|
|
43
|
+
<img src="https://img.shields.io/pypi/l/swarmauri_signing_pgp" alt="PyPI - License"/></a>
|
|
44
|
+
<a href="https://pypi.org/project/swarmauri_signing_pgp/">
|
|
45
|
+
<img src="https://img.shields.io/pypi/v/swarmauri_signing_pgp?label=swarmauri_signing_pgp&color=green" alt="PyPI - swarmauri_signing_pgp"/></a>
|
|
46
|
+
</p>
|
|
47
|
+
|
|
48
|
+
---
|
|
49
|
+
|
|
50
|
+
# Swarmauri Signing PGP
|
|
51
|
+
|
|
52
|
+
The `swarmauri_signing_pgp` package provides an OpenPGP signer for the Swarmauri
|
|
53
|
+
SDK. It creates and verifies detached signatures over raw byte payloads or
|
|
54
|
+
structured envelopes that are canonicalized to JSON or, optionally, CBOR.
|
|
55
|
+
|
|
56
|
+
## Features
|
|
57
|
+
|
|
58
|
+
- Detached OpenPGP signatures for bytes and envelopes
|
|
59
|
+
- JSON canonicalization with optional CBOR support via `cbor2`
|
|
60
|
+
- Multi-signer verification with configurable minimum signer requirements
|
|
61
|
+
- Private key loading from in-memory `pgpy` objects or ASCII-armored blobs
|
|
62
|
+
- Passphrase handling for locked private keys
|
|
63
|
+
|
|
64
|
+
## Installation
|
|
65
|
+
|
|
66
|
+
Install the package with your preferred Python packaging tool:
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
pip install swarmauri_signing_pgp
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
```bash
|
|
73
|
+
poetry add swarmauri_signing_pgp
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
uv pip install swarmauri_signing_pgp
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
### Optional CBOR support
|
|
81
|
+
|
|
82
|
+
Enable canonicalization to CBOR by installing the optional dependency group:
|
|
83
|
+
|
|
84
|
+
```bash
|
|
85
|
+
pip install "swarmauri_signing_pgp[cbor]"
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
```bash
|
|
89
|
+
poetry add swarmauri_signing_pgp -E cbor
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
```bash
|
|
93
|
+
uv pip install "swarmauri_signing_pgp[cbor]"
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
## Usage
|
|
97
|
+
|
|
98
|
+
The signer exposes asynchronous methods from the Swarmauri signing base class.
|
|
99
|
+
Key references are dictionaries describing how to load private keys. For `pgpy`
|
|
100
|
+
objects, the signer expects a mapping such as `{"kind": "pgpy_key", "priv":
|
|
101
|
+
pgpy_key}`. Verification requires the corresponding public keys supplied in the
|
|
102
|
+
`opts={"pubkeys": [...]}` argument.
|
|
103
|
+
|
|
104
|
+
### Sign and verify raw bytes
|
|
105
|
+
|
|
106
|
+
```python
|
|
107
|
+
import asyncio
|
|
108
|
+
|
|
109
|
+
from pgpy import PGPKey, PGPUID
|
|
110
|
+
from pgpy.constants import (
|
|
111
|
+
CompressionAlgorithm,
|
|
112
|
+
HashAlgorithm,
|
|
113
|
+
KeyFlags,
|
|
114
|
+
PubKeyAlgorithm,
|
|
115
|
+
SymmetricKeyAlgorithm,
|
|
116
|
+
)
|
|
117
|
+
|
|
118
|
+
from swarmauri_signing_pgp import PgpEnvelopeSigner
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
def make_demo_key() -> PGPKey:
|
|
122
|
+
key = PGPKey.new(PubKeyAlgorithm.RSAEncryptOrSign, 2048)
|
|
123
|
+
uid = PGPUID.new("Example User", email="user@example.com")
|
|
124
|
+
key.add_uid(
|
|
125
|
+
uid,
|
|
126
|
+
usage={KeyFlags.Sign},
|
|
127
|
+
hashes=[HashAlgorithm.SHA256],
|
|
128
|
+
ciphers=[SymmetricKeyAlgorithm.AES256],
|
|
129
|
+
compression=[CompressionAlgorithm.ZLIB],
|
|
130
|
+
)
|
|
131
|
+
return key
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
async def main() -> None:
|
|
135
|
+
signer = PgpEnvelopeSigner()
|
|
136
|
+
key = make_demo_key()
|
|
137
|
+
key_ref = {"kind": "pgpy_key", "priv": key}
|
|
138
|
+
payload = b"openpgp demo"
|
|
139
|
+
|
|
140
|
+
signatures = await signer.sign_bytes(key_ref, payload)
|
|
141
|
+
verified = await signer.verify_bytes(
|
|
142
|
+
payload,
|
|
143
|
+
signatures,
|
|
144
|
+
opts={"pubkeys": [key.pubkey]},
|
|
145
|
+
)
|
|
146
|
+
print("Verified:", verified)
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
asyncio.run(main())
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
The signer returns detached signatures that include both binary and ASCII-armored
|
|
153
|
+
representations. Passphrases for locked private keys can be supplied through
|
|
154
|
+
`opts={"passphrase": "secret"}`.
|
|
155
|
+
|
|
156
|
+
### Sign envelopes
|
|
157
|
+
|
|
158
|
+
Envelopes are canonicalized before signing. JSON canonicalization is always
|
|
159
|
+
available and CBOR becomes available when the optional dependency group is
|
|
160
|
+
installed:
|
|
161
|
+
|
|
162
|
+
```python
|
|
163
|
+
envelope = {"subject": "demo", "body": "hello"}
|
|
164
|
+
signatures = await signer.sign_envelope(key_ref, envelope, canon="json")
|
|
165
|
+
await signer.verify_envelope(
|
|
166
|
+
envelope,
|
|
167
|
+
signatures,
|
|
168
|
+
canon="json",
|
|
169
|
+
opts={"pubkeys": [key.pubkey]},
|
|
170
|
+
)
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
Use `canon="cbor"` to opt into CBOR canonicalization. The `supports()` helper
|
|
174
|
+
exposes the available algorithms, canonicalization formats, and feature flags at
|
|
175
|
+
runtime.
|
|
176
|
+
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+

|
|
2
|
+
|
|
3
|
+
<p align="center">
|
|
4
|
+
<a href="https://pypi.org/project/swarmauri_signing_pgp/">
|
|
5
|
+
<img src="https://img.shields.io/pypi/dm/swarmauri_signing_pgp" alt="PyPI - Downloads"/></a>
|
|
6
|
+
<a href="https://hits.sh/github.com/swarmauri/swarmauri-sdk/tree/master/pkgs/standards/swarmauri_signing_pgp/">
|
|
7
|
+
<img alt="Hits" src="https://hits.sh/github.com/swarmauri/swarmauri-sdk/tree/master/pkgs/standards/swarmauri_signing_pgp.svg"/></a>
|
|
8
|
+
<a href="https://pypi.org/project/swarmauri_signing_pgp/">
|
|
9
|
+
<img src="https://img.shields.io/pypi/pyversions/swarmauri_signing_pgp" alt="PyPI - Python Version"/></a>
|
|
10
|
+
<a href="https://pypi.org/project/swarmauri_signing_pgp/">
|
|
11
|
+
<img src="https://img.shields.io/pypi/l/swarmauri_signing_pgp" alt="PyPI - License"/></a>
|
|
12
|
+
<a href="https://pypi.org/project/swarmauri_signing_pgp/">
|
|
13
|
+
<img src="https://img.shields.io/pypi/v/swarmauri_signing_pgp?label=swarmauri_signing_pgp&color=green" alt="PyPI - swarmauri_signing_pgp"/></a>
|
|
14
|
+
</p>
|
|
15
|
+
|
|
16
|
+
---
|
|
17
|
+
|
|
18
|
+
# Swarmauri Signing PGP
|
|
19
|
+
|
|
20
|
+
The `swarmauri_signing_pgp` package provides an OpenPGP signer for the Swarmauri
|
|
21
|
+
SDK. It creates and verifies detached signatures over raw byte payloads or
|
|
22
|
+
structured envelopes that are canonicalized to JSON or, optionally, CBOR.
|
|
23
|
+
|
|
24
|
+
## Features
|
|
25
|
+
|
|
26
|
+
- Detached OpenPGP signatures for bytes and envelopes
|
|
27
|
+
- JSON canonicalization with optional CBOR support via `cbor2`
|
|
28
|
+
- Multi-signer verification with configurable minimum signer requirements
|
|
29
|
+
- Private key loading from in-memory `pgpy` objects or ASCII-armored blobs
|
|
30
|
+
- Passphrase handling for locked private keys
|
|
31
|
+
|
|
32
|
+
## Installation
|
|
33
|
+
|
|
34
|
+
Install the package with your preferred Python packaging tool:
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
pip install swarmauri_signing_pgp
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
poetry add swarmauri_signing_pgp
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
uv pip install swarmauri_signing_pgp
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### Optional CBOR support
|
|
49
|
+
|
|
50
|
+
Enable canonicalization to CBOR by installing the optional dependency group:
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
pip install "swarmauri_signing_pgp[cbor]"
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
poetry add swarmauri_signing_pgp -E cbor
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
uv pip install "swarmauri_signing_pgp[cbor]"
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## Usage
|
|
65
|
+
|
|
66
|
+
The signer exposes asynchronous methods from the Swarmauri signing base class.
|
|
67
|
+
Key references are dictionaries describing how to load private keys. For `pgpy`
|
|
68
|
+
objects, the signer expects a mapping such as `{"kind": "pgpy_key", "priv":
|
|
69
|
+
pgpy_key}`. Verification requires the corresponding public keys supplied in the
|
|
70
|
+
`opts={"pubkeys": [...]}` argument.
|
|
71
|
+
|
|
72
|
+
### Sign and verify raw bytes
|
|
73
|
+
|
|
74
|
+
```python
|
|
75
|
+
import asyncio
|
|
76
|
+
|
|
77
|
+
from pgpy import PGPKey, PGPUID
|
|
78
|
+
from pgpy.constants import (
|
|
79
|
+
CompressionAlgorithm,
|
|
80
|
+
HashAlgorithm,
|
|
81
|
+
KeyFlags,
|
|
82
|
+
PubKeyAlgorithm,
|
|
83
|
+
SymmetricKeyAlgorithm,
|
|
84
|
+
)
|
|
85
|
+
|
|
86
|
+
from swarmauri_signing_pgp import PgpEnvelopeSigner
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
def make_demo_key() -> PGPKey:
|
|
90
|
+
key = PGPKey.new(PubKeyAlgorithm.RSAEncryptOrSign, 2048)
|
|
91
|
+
uid = PGPUID.new("Example User", email="user@example.com")
|
|
92
|
+
key.add_uid(
|
|
93
|
+
uid,
|
|
94
|
+
usage={KeyFlags.Sign},
|
|
95
|
+
hashes=[HashAlgorithm.SHA256],
|
|
96
|
+
ciphers=[SymmetricKeyAlgorithm.AES256],
|
|
97
|
+
compression=[CompressionAlgorithm.ZLIB],
|
|
98
|
+
)
|
|
99
|
+
return key
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
async def main() -> None:
|
|
103
|
+
signer = PgpEnvelopeSigner()
|
|
104
|
+
key = make_demo_key()
|
|
105
|
+
key_ref = {"kind": "pgpy_key", "priv": key}
|
|
106
|
+
payload = b"openpgp demo"
|
|
107
|
+
|
|
108
|
+
signatures = await signer.sign_bytes(key_ref, payload)
|
|
109
|
+
verified = await signer.verify_bytes(
|
|
110
|
+
payload,
|
|
111
|
+
signatures,
|
|
112
|
+
opts={"pubkeys": [key.pubkey]},
|
|
113
|
+
)
|
|
114
|
+
print("Verified:", verified)
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
asyncio.run(main())
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
The signer returns detached signatures that include both binary and ASCII-armored
|
|
121
|
+
representations. Passphrases for locked private keys can be supplied through
|
|
122
|
+
`opts={"passphrase": "secret"}`.
|
|
123
|
+
|
|
124
|
+
### Sign envelopes
|
|
125
|
+
|
|
126
|
+
Envelopes are canonicalized before signing. JSON canonicalization is always
|
|
127
|
+
available and CBOR becomes available when the optional dependency group is
|
|
128
|
+
installed:
|
|
129
|
+
|
|
130
|
+
```python
|
|
131
|
+
envelope = {"subject": "demo", "body": "hello"}
|
|
132
|
+
signatures = await signer.sign_envelope(key_ref, envelope, canon="json")
|
|
133
|
+
await signer.verify_envelope(
|
|
134
|
+
envelope,
|
|
135
|
+
signatures,
|
|
136
|
+
canon="json",
|
|
137
|
+
opts={"pubkeys": [key.pubkey]},
|
|
138
|
+
)
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
Use `canon="cbor"` to opt into CBOR canonicalization. The `supports()` helper
|
|
142
|
+
exposes the available algorithms, canonicalization formats, and feature flags at
|
|
143
|
+
runtime.
|
|
@@ -1,23 +1,39 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "swarmauri_signing_pgp"
|
|
3
|
-
version = "0.3.0.
|
|
3
|
+
version = "0.3.0.dev30"
|
|
4
4
|
description = "OpenPGP envelope signer for Swarmauri"
|
|
5
5
|
license = "Apache-2.0"
|
|
6
6
|
readme = "README.md"
|
|
7
|
-
repository = "http://github.com/swarmauri/swarmauri-sdk"
|
|
8
7
|
requires-python = ">=3.10,<3.13"
|
|
8
|
+
authors = [{ name = "Jacob Stewart", email = "jacob@swarmauri.com" }]
|
|
9
|
+
keywords = [
|
|
10
|
+
"swarmauri",
|
|
11
|
+
"signing",
|
|
12
|
+
"pgp",
|
|
13
|
+
"openpgp",
|
|
14
|
+
"envelope",
|
|
15
|
+
"sdk",
|
|
16
|
+
"standards",
|
|
17
|
+
"cryptography",
|
|
18
|
+
"digital-signature",
|
|
19
|
+
"pgp-keys",
|
|
20
|
+
"ascii-armor",
|
|
21
|
+
"message-codec",
|
|
22
|
+
"openpgp-format",
|
|
23
|
+
]
|
|
9
24
|
classifiers = [
|
|
25
|
+
"Development Status :: 1 - Planning",
|
|
10
26
|
"License :: OSI Approved :: Apache Software License",
|
|
11
27
|
"Natural Language :: English",
|
|
28
|
+
"Programming Language :: Python",
|
|
29
|
+
"Programming Language :: Python :: 3",
|
|
12
30
|
"Programming Language :: Python :: 3.10",
|
|
13
31
|
"Programming Language :: Python :: 3.11",
|
|
14
32
|
"Programming Language :: Python :: 3.12",
|
|
15
|
-
"Programming Language :: Python :: 3.13",
|
|
16
|
-
"Development Status :: 3 - Alpha",
|
|
17
33
|
"Topic :: Security :: Cryptography",
|
|
18
34
|
"Intended Audience :: Developers",
|
|
35
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
19
36
|
]
|
|
20
|
-
authors = [{ name = "Swarmauri", email = "opensource@swarmauri.com" }]
|
|
21
37
|
dependencies = [
|
|
22
38
|
"swarmauri_core",
|
|
23
39
|
"swarmauri_base",
|
|
@@ -25,6 +41,11 @@ dependencies = [
|
|
|
25
41
|
"pgpy>=0.6.0",
|
|
26
42
|
]
|
|
27
43
|
|
|
44
|
+
[project.urls]
|
|
45
|
+
Homepage = "https://github.com/swarmauri/swarmauri-sdk"
|
|
46
|
+
Source = "https://github.com/swarmauri/swarmauri-sdk/tree/main/pkgs/standards/swarmauri_signing_pgp"
|
|
47
|
+
Documentation = "https://github.com/swarmauri/swarmauri-sdk/tree/main/pkgs/standards/swarmauri_signing_pgp#readme"
|
|
48
|
+
|
|
28
49
|
[project.optional-dependencies]
|
|
29
50
|
cbor = ["cbor2>=5.4.6"]
|
|
30
51
|
|
|
@@ -42,6 +63,7 @@ markers = [
|
|
|
42
63
|
"r8n: Regression tests",
|
|
43
64
|
"acceptance: Acceptance tests",
|
|
44
65
|
"perf: Performance tests",
|
|
66
|
+
"example: Documentation example tests",
|
|
45
67
|
]
|
|
46
68
|
timeout = 300
|
|
47
69
|
log_cli = true
|
|
@@ -1,15 +1,25 @@
|
|
|
1
|
+
"""
|
|
2
|
+
pgp_signer.py
|
|
3
|
+
|
|
4
|
+
OpenPGP signing utilities for the Swarmauri SDK.
|
|
5
|
+
|
|
6
|
+
This module exposes :class:`PgpEnvelopeSigner`, an implementation capable of
|
|
7
|
+
creating and verifying detached OpenPGP signatures over raw byte payloads or
|
|
8
|
+
structured envelopes that are canonicalized to JSON or, optionally, CBOR.
|
|
9
|
+
"""
|
|
10
|
+
|
|
1
11
|
from __future__ import annotations
|
|
2
12
|
|
|
3
|
-
from typing import Iterable, Mapping, Optional, Sequence, Dict, Any, TYPE_CHECKING
|
|
4
13
|
from dataclasses import dataclass
|
|
5
14
|
import json
|
|
15
|
+
from typing import Any, Dict, Iterable, Mapping, Optional, Sequence, TYPE_CHECKING
|
|
6
16
|
|
|
7
17
|
try:
|
|
8
18
|
from swarmauri_base.signing.SigningBase import SigningBase
|
|
9
19
|
except Exception: # pragma: no cover
|
|
10
20
|
|
|
11
21
|
class SigningBase: # type: ignore[too-many-ancestors]
|
|
12
|
-
"""Fallback SigningBase used when swarmauri_base is
|
|
22
|
+
"""Fallback ``SigningBase`` used when :mod:`swarmauri_base` is missing."""
|
|
13
23
|
|
|
14
24
|
pass
|
|
15
25
|
|
|
@@ -40,6 +50,12 @@ except Exception: # pragma: no cover - import guard
|
|
|
40
50
|
|
|
41
51
|
|
|
42
52
|
def _ensure_pgpy() -> None:
|
|
53
|
+
"""Ensure the :mod:`pgpy` dependency is available.
|
|
54
|
+
|
|
55
|
+
Raises:
|
|
56
|
+
RuntimeError: If :mod:`pgpy` is not installed.
|
|
57
|
+
"""
|
|
58
|
+
|
|
43
59
|
if not _PGP_OK:
|
|
44
60
|
raise RuntimeError(
|
|
45
61
|
"PgpEnvelopeSigner requires 'PGPy'. Install with: pip install pgpy"
|
|
@@ -47,12 +63,33 @@ def _ensure_pgpy() -> None:
|
|
|
47
63
|
|
|
48
64
|
|
|
49
65
|
def _canon_json(obj) -> bytes:
|
|
66
|
+
"""Serialize ``obj`` to canonical JSON bytes.
|
|
67
|
+
|
|
68
|
+
Args:
|
|
69
|
+
obj: Object to serialize.
|
|
70
|
+
|
|
71
|
+
Returns:
|
|
72
|
+
bytes: Canonical JSON representation of ``obj``.
|
|
73
|
+
"""
|
|
74
|
+
|
|
50
75
|
return json.dumps(
|
|
51
76
|
obj, sort_keys=True, separators=(",", ":"), ensure_ascii=False
|
|
52
77
|
).encode("utf-8")
|
|
53
78
|
|
|
54
79
|
|
|
55
80
|
def _canon_cbor(obj) -> bytes:
|
|
81
|
+
"""Serialize ``obj`` to canonical CBOR bytes.
|
|
82
|
+
|
|
83
|
+
Args:
|
|
84
|
+
obj: Object to serialize.
|
|
85
|
+
|
|
86
|
+
Returns:
|
|
87
|
+
bytes: Canonical CBOR representation of ``obj``.
|
|
88
|
+
|
|
89
|
+
Raises:
|
|
90
|
+
RuntimeError: If the :mod:`cbor2` dependency is missing.
|
|
91
|
+
"""
|
|
92
|
+
|
|
56
93
|
if not _CBOR_OK:
|
|
57
94
|
raise RuntimeError("CBOR canonicalization requires 'cbor2' to be installed.")
|
|
58
95
|
return cbor2.dumps(obj)
|
|
@@ -60,6 +97,8 @@ def _canon_cbor(obj) -> bytes:
|
|
|
60
97
|
|
|
61
98
|
@dataclass(frozen=True)
|
|
62
99
|
class _Sig:
|
|
100
|
+
"""Lightweight mapping wrapper for signature data."""
|
|
101
|
+
|
|
63
102
|
data: Dict[str, Any]
|
|
64
103
|
|
|
65
104
|
def __getitem__(self, k: str) -> object: # pragma: no cover - simple delegation
|
|
@@ -76,11 +115,25 @@ class _Sig:
|
|
|
76
115
|
|
|
77
116
|
|
|
78
117
|
class PgpEnvelopeSigner(SigningBase):
|
|
79
|
-
"""
|
|
118
|
+
"""Generate and verify detached OpenPGP signatures.
|
|
119
|
+
|
|
120
|
+
The signer operates on raw byte payloads or structured envelopes that are
|
|
121
|
+
canonicalized to JSON or CBOR prior to signing.
|
|
122
|
+
"""
|
|
80
123
|
|
|
81
124
|
def supports(self) -> Mapping[str, Iterable[str]]:
|
|
125
|
+
"""Describe the algorithms and canonicalizations supported by the signer.
|
|
126
|
+
|
|
127
|
+
Returns:
|
|
128
|
+
Mapping[str, Iterable[str]]: Mapping of capability names to supported values.
|
|
129
|
+
"""
|
|
130
|
+
|
|
82
131
|
canons = ("json", "cbor") if _CBOR_OK else ("json",)
|
|
132
|
+
structured = tuple(f"structured-{canon}" for canon in canons)
|
|
83
133
|
return {
|
|
134
|
+
"signs": ("bytes", "digest", "envelope", "stream"),
|
|
135
|
+
"verifies": ("bytes", "digest", "envelope", "stream"),
|
|
136
|
+
"envelopes": ("mapping", "detached-bytes", *structured),
|
|
84
137
|
"algs": ("OpenPGP",),
|
|
85
138
|
"canons": canons,
|
|
86
139
|
"features": ("multi", "detached_only"),
|
|
@@ -95,6 +148,23 @@ class PgpEnvelopeSigner(SigningBase):
|
|
|
95
148
|
alg: Optional[Alg] = None,
|
|
96
149
|
opts: Optional[Mapping[str, object]] = None,
|
|
97
150
|
) -> Sequence[Signature]:
|
|
151
|
+
"""Create a detached OpenPGP signature for raw bytes.
|
|
152
|
+
|
|
153
|
+
Args:
|
|
154
|
+
key (KeyRef): Reference to the private key used for signing.
|
|
155
|
+
payload (bytes): Data to sign.
|
|
156
|
+
alg (Optional[Alg]): Requested algorithm, defaults to ``"OpenPGP"``.
|
|
157
|
+
opts (Optional[Mapping[str, object]]): Additional options such as
|
|
158
|
+
``passphrase`` for locked keys.
|
|
159
|
+
|
|
160
|
+
Returns:
|
|
161
|
+
Sequence[Signature]: A list containing the generated signature.
|
|
162
|
+
|
|
163
|
+
Raises:
|
|
164
|
+
RuntimeError: If the private key is locked and no passphrase is provided.
|
|
165
|
+
ValueError: If an unsupported algorithm is requested.
|
|
166
|
+
"""
|
|
167
|
+
|
|
98
168
|
_ensure_pgpy()
|
|
99
169
|
if alg not in (None, "OpenPGP"):
|
|
100
170
|
raise ValueError("Unsupported alg for PgpEnvelopeSigner.")
|
|
@@ -125,6 +195,23 @@ class PgpEnvelopeSigner(SigningBase):
|
|
|
125
195
|
require: Optional[Mapping[str, object]] = None,
|
|
126
196
|
opts: Optional[Mapping[str, object]] = None,
|
|
127
197
|
) -> bool:
|
|
198
|
+
"""Verify detached OpenPGP signatures against raw bytes.
|
|
199
|
+
|
|
200
|
+
Args:
|
|
201
|
+
payload (bytes): Signed data.
|
|
202
|
+
signatures (Sequence[Signature]): Signatures to validate.
|
|
203
|
+
require (Optional[Mapping[str, object]]): Verification requirements such
|
|
204
|
+
as ``min_signers``.
|
|
205
|
+
opts (Optional[Mapping[str, object]]): Options containing public keys in
|
|
206
|
+
``pubkeys``.
|
|
207
|
+
|
|
208
|
+
Returns:
|
|
209
|
+
bool: ``True`` if the signatures satisfy the requirements, ``False`` otherwise.
|
|
210
|
+
|
|
211
|
+
Raises:
|
|
212
|
+
TypeError: If an unsupported public key is supplied in ``opts``.
|
|
213
|
+
"""
|
|
214
|
+
|
|
128
215
|
_ensure_pgpy()
|
|
129
216
|
min_signers = int(require.get("min_signers", 1)) if require else 1
|
|
130
217
|
|
|
@@ -162,6 +249,26 @@ class PgpEnvelopeSigner(SigningBase):
|
|
|
162
249
|
return True
|
|
163
250
|
return False
|
|
164
251
|
|
|
252
|
+
async def sign_digest(
|
|
253
|
+
self,
|
|
254
|
+
key: KeyRef,
|
|
255
|
+
digest: bytes,
|
|
256
|
+
*,
|
|
257
|
+
alg: Optional[Alg] = None,
|
|
258
|
+
opts: Optional[Mapping[str, object]] = None,
|
|
259
|
+
) -> Sequence[Signature]:
|
|
260
|
+
return await self.sign_bytes(key, digest, alg=alg, opts=opts)
|
|
261
|
+
|
|
262
|
+
async def verify_digest(
|
|
263
|
+
self,
|
|
264
|
+
digest: bytes,
|
|
265
|
+
signatures: Sequence[Signature],
|
|
266
|
+
*,
|
|
267
|
+
require: Optional[Mapping[str, object]] = None,
|
|
268
|
+
opts: Optional[Mapping[str, object]] = None,
|
|
269
|
+
) -> bool:
|
|
270
|
+
return await self.verify_bytes(digest, signatures, require=require, opts=opts)
|
|
271
|
+
|
|
165
272
|
# ---------- canonicalization ----------
|
|
166
273
|
async def canonicalize_envelope(
|
|
167
274
|
self,
|
|
@@ -170,6 +277,21 @@ class PgpEnvelopeSigner(SigningBase):
|
|
|
170
277
|
canon: Optional[Canon] = None,
|
|
171
278
|
opts: Optional[Mapping[str, object]] = None,
|
|
172
279
|
) -> bytes:
|
|
280
|
+
"""Canonicalize an envelope to bytes.
|
|
281
|
+
|
|
282
|
+
Args:
|
|
283
|
+
env (Envelope): Envelope to canonicalize.
|
|
284
|
+
canon (Optional[Canon]): Canonicalization format, ``"json"`` or ``"cbor"``.
|
|
285
|
+
opts (Optional[Mapping[str, object]]): Additional options (unused).
|
|
286
|
+
|
|
287
|
+
Returns:
|
|
288
|
+
bytes: Canonical representation of the envelope.
|
|
289
|
+
|
|
290
|
+
Raises:
|
|
291
|
+
ValueError: If an unsupported canonicalization format is provided.
|
|
292
|
+
RuntimeError: If CBOR canonicalization is requested without ``cbor2``.
|
|
293
|
+
"""
|
|
294
|
+
|
|
173
295
|
if canon in (None, "json"):
|
|
174
296
|
return _canon_json(env) # type: ignore[arg-type]
|
|
175
297
|
if canon == "cbor":
|
|
@@ -186,6 +308,19 @@ class PgpEnvelopeSigner(SigningBase):
|
|
|
186
308
|
canon: Optional[Canon] = None,
|
|
187
309
|
opts: Optional[Mapping[str, object]] = None,
|
|
188
310
|
) -> Sequence[Signature]:
|
|
311
|
+
"""Sign a structured envelope after canonicalization.
|
|
312
|
+
|
|
313
|
+
Args:
|
|
314
|
+
key (KeyRef): Private key reference.
|
|
315
|
+
env (Envelope): Envelope to sign.
|
|
316
|
+
alg (Optional[Alg]): Requested algorithm, defaults to ``"OpenPGP"``.
|
|
317
|
+
canon (Optional[Canon]): Canonicalization format.
|
|
318
|
+
opts (Optional[Mapping[str, object]]): Additional options.
|
|
319
|
+
|
|
320
|
+
Returns:
|
|
321
|
+
Sequence[Signature]: Detached signature over the canonicalized envelope.
|
|
322
|
+
"""
|
|
323
|
+
|
|
189
324
|
payload = await self.canonicalize_envelope(env, canon=canon, opts=opts)
|
|
190
325
|
return await self.sign_bytes(key, payload, alg="OpenPGP", opts=opts)
|
|
191
326
|
|
|
@@ -198,11 +333,39 @@ class PgpEnvelopeSigner(SigningBase):
|
|
|
198
333
|
require: Optional[Mapping[str, object]] = None,
|
|
199
334
|
opts: Optional[Mapping[str, object]] = None,
|
|
200
335
|
) -> bool:
|
|
336
|
+
"""Verify signatures over a structured envelope.
|
|
337
|
+
|
|
338
|
+
Args:
|
|
339
|
+
env (Envelope): Envelope whose signatures are being verified.
|
|
340
|
+
signatures (Sequence[Signature]): Signatures to check.
|
|
341
|
+
canon (Optional[Canon]): Canonicalization format used.
|
|
342
|
+
require (Optional[Mapping[str, object]]): Verification requirements.
|
|
343
|
+
opts (Optional[Mapping[str, object]]): Additional options.
|
|
344
|
+
|
|
345
|
+
Returns:
|
|
346
|
+
bool: ``True`` if verification succeeds, ``False`` otherwise.
|
|
347
|
+
"""
|
|
348
|
+
|
|
201
349
|
payload = await self.canonicalize_envelope(env, canon=canon, opts=opts)
|
|
202
350
|
return await self.verify_bytes(payload, signatures, require=require, opts=opts)
|
|
203
351
|
|
|
204
352
|
# ---------- internal ----------
|
|
205
|
-
def _load_private_key(
|
|
353
|
+
def _load_private_key(
|
|
354
|
+
self, key: KeyRef, opts: Optional[Mapping[str, object]]
|
|
355
|
+
) -> pgpy.PGPKey:
|
|
356
|
+
"""Load a PGP private key from a key reference.
|
|
357
|
+
|
|
358
|
+
Args:
|
|
359
|
+
key (KeyRef): Key reference containing private key data.
|
|
360
|
+
opts (Optional[Mapping[str, object]]): Additional options (unused).
|
|
361
|
+
|
|
362
|
+
Returns:
|
|
363
|
+
pgpy.PGPKey: Loaded private key object.
|
|
364
|
+
|
|
365
|
+
Raises:
|
|
366
|
+
TypeError: If the key reference is unsupported.
|
|
367
|
+
"""
|
|
368
|
+
|
|
206
369
|
if isinstance(key, dict):
|
|
207
370
|
kind = key.get("kind")
|
|
208
371
|
if kind == "pgpy_key" and isinstance(key.get("priv"), pgpy.PGPKey):
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.3
|
|
2
|
-
Name: swarmauri_signing_pgp
|
|
3
|
-
Version: 0.3.0.dev4
|
|
4
|
-
Summary: OpenPGP envelope signer for Swarmauri
|
|
5
|
-
License: Apache-2.0
|
|
6
|
-
Author: Swarmauri
|
|
7
|
-
Author-email: opensource@swarmauri.com
|
|
8
|
-
Requires-Python: >=3.10,<3.13
|
|
9
|
-
Classifier: License :: OSI Approved :: Apache Software License
|
|
10
|
-
Classifier: Natural Language :: English
|
|
11
|
-
Classifier: Programming Language :: Python :: 3.10
|
|
12
|
-
Classifier: Programming Language :: Python :: 3.11
|
|
13
|
-
Classifier: Programming Language :: Python :: 3.12
|
|
14
|
-
Classifier: Programming Language :: Python :: 3.13
|
|
15
|
-
Classifier: Development Status :: 3 - Alpha
|
|
16
|
-
Classifier: Topic :: Security :: Cryptography
|
|
17
|
-
Classifier: Intended Audience :: Developers
|
|
18
|
-
Provides-Extra: cbor
|
|
19
|
-
Requires-Dist: cbor2 (>=5.4.6) ; extra == "cbor"
|
|
20
|
-
Requires-Dist: pgpy (>=0.6.0)
|
|
21
|
-
Requires-Dist: swarmauri_base
|
|
22
|
-
Requires-Dist: swarmauri_core
|
|
23
|
-
Requires-Dist: swarmauri_standard
|
|
24
|
-
Description-Content-Type: text/markdown
|
|
25
|
-
|
|
26
|
-

|
|
27
|
-
|
|
28
|
-
<p align="center">
|
|
29
|
-
<a href="https://pypi.org/project/swarmauri_signing_pgp/">
|
|
30
|
-
<img src="https://img.shields.io/pypi/dm/swarmauri_signing_pgp" alt="PyPI - Downloads"/></a>
|
|
31
|
-
<a href="https://hits.sh/github.com/swarmauri/swarmauri-sdk/tree/master/pkgs/standards/swarmauri_signing_pgp/">
|
|
32
|
-
<img alt="Hits" src="https://hits.sh/github.com/swarmauri/swarmauri-sdk/tree/master/pkgs/standards/swarmauri_signing_pgp.svg"/></a>
|
|
33
|
-
<a href="https://pypi.org/project/swarmauri_signing_pgp/">
|
|
34
|
-
<img src="https://img.shields.io/pypi/pyversions/swarmauri_signing_pgp" alt="PyPI - Python Version"/></a>
|
|
35
|
-
<a href="https://pypi.org/project/swarmauri_signing_pgp/">
|
|
36
|
-
<img src="https://img.shields.io/pypi/l/swarmauri_signing_pgp" alt="PyPI - License"/></a>
|
|
37
|
-
<a href="https://pypi.org/project/swarmauri_signing_pgp/">
|
|
38
|
-
<img src="https://img.shields.io/pypi/v/swarmauri_signing_pgp?label=swarmauri_signing_pgp&color=green" alt="PyPI - swarmauri_signing_pgp"/></a>
|
|
39
|
-
</p>
|
|
40
|
-
|
|
41
|
-
---
|
|
42
|
-
|
|
43
|
-
# Swarmauri Signing PGP
|
|
44
|
-
|
|
45
|
-
OpenPGP envelope signer for Swarmauri. Supports JSON and optional CBOR canonicalization.
|
|
46
|
-
|
|
47
|
-
## Installation
|
|
48
|
-
|
|
49
|
-
```bash
|
|
50
|
-
pip install swarmauri_signing_pgp
|
|
51
|
-
```
|
|
52
|
-
|
|
53
|
-
To enable CBOR canonicalization:
|
|
54
|
-
|
|
55
|
-
```bash
|
|
56
|
-
pip install swarmauri_signing_pgp[cbor]
|
|
57
|
-
```
|
|
58
|
-
|
|
59
|
-
## Usage
|
|
60
|
-
|
|
61
|
-
```python
|
|
62
|
-
from swarmauri_signing_pgp import PgpEnvelopeSigner
|
|
63
|
-
|
|
64
|
-
signer = PgpEnvelopeSigner()
|
|
65
|
-
# ... use signer.sign_bytes or signer.sign_envelope
|
|
66
|
-
```
|
|
67
|
-
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-

|
|
2
|
-
|
|
3
|
-
<p align="center">
|
|
4
|
-
<a href="https://pypi.org/project/swarmauri_signing_pgp/">
|
|
5
|
-
<img src="https://img.shields.io/pypi/dm/swarmauri_signing_pgp" alt="PyPI - Downloads"/></a>
|
|
6
|
-
<a href="https://hits.sh/github.com/swarmauri/swarmauri-sdk/tree/master/pkgs/standards/swarmauri_signing_pgp/">
|
|
7
|
-
<img alt="Hits" src="https://hits.sh/github.com/swarmauri/swarmauri-sdk/tree/master/pkgs/standards/swarmauri_signing_pgp.svg"/></a>
|
|
8
|
-
<a href="https://pypi.org/project/swarmauri_signing_pgp/">
|
|
9
|
-
<img src="https://img.shields.io/pypi/pyversions/swarmauri_signing_pgp" alt="PyPI - Python Version"/></a>
|
|
10
|
-
<a href="https://pypi.org/project/swarmauri_signing_pgp/">
|
|
11
|
-
<img src="https://img.shields.io/pypi/l/swarmauri_signing_pgp" alt="PyPI - License"/></a>
|
|
12
|
-
<a href="https://pypi.org/project/swarmauri_signing_pgp/">
|
|
13
|
-
<img src="https://img.shields.io/pypi/v/swarmauri_signing_pgp?label=swarmauri_signing_pgp&color=green" alt="PyPI - swarmauri_signing_pgp"/></a>
|
|
14
|
-
</p>
|
|
15
|
-
|
|
16
|
-
---
|
|
17
|
-
|
|
18
|
-
# Swarmauri Signing PGP
|
|
19
|
-
|
|
20
|
-
OpenPGP envelope signer for Swarmauri. Supports JSON and optional CBOR canonicalization.
|
|
21
|
-
|
|
22
|
-
## Installation
|
|
23
|
-
|
|
24
|
-
```bash
|
|
25
|
-
pip install swarmauri_signing_pgp
|
|
26
|
-
```
|
|
27
|
-
|
|
28
|
-
To enable CBOR canonicalization:
|
|
29
|
-
|
|
30
|
-
```bash
|
|
31
|
-
pip install swarmauri_signing_pgp[cbor]
|
|
32
|
-
```
|
|
33
|
-
|
|
34
|
-
## Usage
|
|
35
|
-
|
|
36
|
-
```python
|
|
37
|
-
from swarmauri_signing_pgp import PgpEnvelopeSigner
|
|
38
|
-
|
|
39
|
-
signer = PgpEnvelopeSigner()
|
|
40
|
-
# ... use signer.sign_bytes or signer.sign_envelope
|
|
41
|
-
```
|
|
File without changes
|
|
File without changes
|