swarmauri_signing_pgp 0.3.0.dev2__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.dev2/LICENSE +201 -0
- swarmauri_signing_pgp-0.3.0.dev2/PKG-INFO +67 -0
- swarmauri_signing_pgp-0.3.0.dev2/README.md +41 -0
- swarmauri_signing_pgp-0.3.0.dev2/pyproject.toml +71 -0
- swarmauri_signing_pgp-0.3.0.dev2/swarmauri_signing_pgp/__init__.py +3 -0
- swarmauri_signing_pgp-0.3.0.dev2/swarmauri_signing_pgp/pgp_signer.py +213 -0
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [2025] [Jacob Stewart @ Swarmauri]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
Metadata-Version: 2.3
|
|
2
|
+
Name: swarmauri_signing_pgp
|
|
3
|
+
Version: 0.3.0.dev2
|
|
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
|
+
|
|
@@ -0,0 +1,41 @@
|
|
|
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
|
+
```
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "swarmauri_signing_pgp"
|
|
3
|
+
version = "0.3.0.dev2"
|
|
4
|
+
description = "OpenPGP envelope signer for Swarmauri"
|
|
5
|
+
license = "Apache-2.0"
|
|
6
|
+
readme = "README.md"
|
|
7
|
+
repository = "http://github.com/swarmauri/swarmauri-sdk"
|
|
8
|
+
requires-python = ">=3.10,<3.13"
|
|
9
|
+
classifiers = [
|
|
10
|
+
"License :: OSI Approved :: Apache Software License",
|
|
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
|
+
"Development Status :: 3 - Alpha",
|
|
17
|
+
"Topic :: Security :: Cryptography",
|
|
18
|
+
"Intended Audience :: Developers",
|
|
19
|
+
]
|
|
20
|
+
authors = [{ name = "Swarmauri", email = "opensource@swarmauri.com" }]
|
|
21
|
+
dependencies = [
|
|
22
|
+
"swarmauri_core",
|
|
23
|
+
"swarmauri_base",
|
|
24
|
+
"swarmauri_standard",
|
|
25
|
+
"pgpy>=0.6.0",
|
|
26
|
+
]
|
|
27
|
+
|
|
28
|
+
[project.optional-dependencies]
|
|
29
|
+
cbor = ["cbor2>=5.4.6"]
|
|
30
|
+
|
|
31
|
+
[tool.uv.sources]
|
|
32
|
+
swarmauri_core = { workspace = true }
|
|
33
|
+
swarmauri_base = { workspace = true }
|
|
34
|
+
swarmauri_standard = { workspace = true }
|
|
35
|
+
|
|
36
|
+
[tool.pytest.ini_options]
|
|
37
|
+
norecursedirs = ["combined", "scripts"]
|
|
38
|
+
markers = [
|
|
39
|
+
"test: standard test",
|
|
40
|
+
"unit: Unit tests",
|
|
41
|
+
"i9n: Integration tests",
|
|
42
|
+
"r8n: Regression tests",
|
|
43
|
+
"acceptance: Acceptance tests",
|
|
44
|
+
"perf: Performance tests",
|
|
45
|
+
]
|
|
46
|
+
timeout = 300
|
|
47
|
+
log_cli = true
|
|
48
|
+
log_cli_level = "INFO"
|
|
49
|
+
log_cli_format = "%(asctime)s [%(levelname)s] %(message)s"
|
|
50
|
+
log_cli_date_format = "%Y-%m-%d %H:%M:%S"
|
|
51
|
+
asyncio_default_fixture_loop_scope = "function"
|
|
52
|
+
|
|
53
|
+
[project.entry-points.'swarmauri.signings']
|
|
54
|
+
PgpEnvelopeSigner = "swarmauri_signing_pgp:PgpEnvelopeSigner"
|
|
55
|
+
|
|
56
|
+
[build-system]
|
|
57
|
+
requires = ["poetry-core>=1.0.0"]
|
|
58
|
+
build-backend = "poetry.core.masonry.api"
|
|
59
|
+
|
|
60
|
+
[dependency-groups]
|
|
61
|
+
dev = [
|
|
62
|
+
"pytest>=8.0",
|
|
63
|
+
"pytest-asyncio>=0.24.0",
|
|
64
|
+
"pytest-xdist>=3.6.1",
|
|
65
|
+
"pytest-json-report>=1.5.0",
|
|
66
|
+
"python-dotenv",
|
|
67
|
+
"flake8>=7.0",
|
|
68
|
+
"pytest-timeout>=2.3.1",
|
|
69
|
+
"ruff>=0.9.9",
|
|
70
|
+
"pytest-benchmark>=4.0.0",
|
|
71
|
+
]
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from typing import Iterable, Mapping, Optional, Sequence, Dict, Any, TYPE_CHECKING
|
|
4
|
+
from dataclasses import dataclass
|
|
5
|
+
import json
|
|
6
|
+
|
|
7
|
+
try:
|
|
8
|
+
from swarmauri_base.signing.SigningBase import SigningBase
|
|
9
|
+
except Exception: # pragma: no cover
|
|
10
|
+
|
|
11
|
+
class SigningBase: # type: ignore[too-many-ancestors]
|
|
12
|
+
"""Fallback SigningBase used when swarmauri_base is unavailable."""
|
|
13
|
+
|
|
14
|
+
pass
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
if TYPE_CHECKING: # pragma: no cover
|
|
18
|
+
from swarmauri_core.signing.ISigning import Signature, Envelope, Canon
|
|
19
|
+
from swarmauri_core.crypto.types import KeyRef, Alg
|
|
20
|
+
else: # pragma: no cover
|
|
21
|
+
Signature = Dict[str, Any]
|
|
22
|
+
Envelope = Mapping[str, Any]
|
|
23
|
+
Canon = str
|
|
24
|
+
KeyRef = Mapping[str, Any]
|
|
25
|
+
Alg = str
|
|
26
|
+
|
|
27
|
+
try:
|
|
28
|
+
import pgpy # PGPy library
|
|
29
|
+
|
|
30
|
+
_PGP_OK = True
|
|
31
|
+
except Exception: # pragma: no cover - import guard
|
|
32
|
+
_PGP_OK = False
|
|
33
|
+
|
|
34
|
+
try:
|
|
35
|
+
import cbor2
|
|
36
|
+
|
|
37
|
+
_CBOR_OK = True
|
|
38
|
+
except Exception: # pragma: no cover - import guard
|
|
39
|
+
_CBOR_OK = False
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def _ensure_pgpy() -> None:
|
|
43
|
+
if not _PGP_OK:
|
|
44
|
+
raise RuntimeError(
|
|
45
|
+
"PgpEnvelopeSigner requires 'PGPy'. Install with: pip install pgpy"
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def _canon_json(obj) -> bytes:
|
|
50
|
+
return json.dumps(
|
|
51
|
+
obj, sort_keys=True, separators=(",", ":"), ensure_ascii=False
|
|
52
|
+
).encode("utf-8")
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def _canon_cbor(obj) -> bytes:
|
|
56
|
+
if not _CBOR_OK:
|
|
57
|
+
raise RuntimeError("CBOR canonicalization requires 'cbor2' to be installed.")
|
|
58
|
+
return cbor2.dumps(obj)
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
@dataclass(frozen=True)
|
|
62
|
+
class _Sig:
|
|
63
|
+
data: Dict[str, Any]
|
|
64
|
+
|
|
65
|
+
def __getitem__(self, k: str) -> object: # pragma: no cover - simple delegation
|
|
66
|
+
return self.data[k]
|
|
67
|
+
|
|
68
|
+
def get(self, k: str, default=None): # pragma: no cover - simple delegation
|
|
69
|
+
return self.data.get(k, default)
|
|
70
|
+
|
|
71
|
+
def __iter__(self): # pragma: no cover - simple delegation
|
|
72
|
+
return iter(self.data)
|
|
73
|
+
|
|
74
|
+
def __len__(self) -> int: # pragma: no cover - simple delegation
|
|
75
|
+
return len(self.data)
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
class PgpEnvelopeSigner(SigningBase):
|
|
79
|
+
"""Detached OpenPGP signatures over bytes or canonicalized envelopes."""
|
|
80
|
+
|
|
81
|
+
def supports(self) -> Mapping[str, Iterable[str]]:
|
|
82
|
+
canons = ("json", "cbor") if _CBOR_OK else ("json",)
|
|
83
|
+
return {
|
|
84
|
+
"algs": ("OpenPGP",),
|
|
85
|
+
"canons": canons,
|
|
86
|
+
"features": ("multi", "detached_only"),
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
# ---------- bytes ----------
|
|
90
|
+
async def sign_bytes(
|
|
91
|
+
self,
|
|
92
|
+
key: KeyRef,
|
|
93
|
+
payload: bytes,
|
|
94
|
+
*,
|
|
95
|
+
alg: Optional[Alg] = None,
|
|
96
|
+
opts: Optional[Mapping[str, object]] = None,
|
|
97
|
+
) -> Sequence[Signature]:
|
|
98
|
+
_ensure_pgpy()
|
|
99
|
+
if alg not in (None, "OpenPGP"):
|
|
100
|
+
raise ValueError("Unsupported alg for PgpEnvelopeSigner.")
|
|
101
|
+
|
|
102
|
+
k = self._load_private_key(key, opts)
|
|
103
|
+
must_unlock = getattr(k, "is_unlocked", True) is False
|
|
104
|
+
if must_unlock:
|
|
105
|
+
pw = (opts or {}).get("passphrase")
|
|
106
|
+
if not isinstance(pw, (str, bytes)):
|
|
107
|
+
raise RuntimeError(
|
|
108
|
+
"PGP private key is locked; supply opts['passphrase']."
|
|
109
|
+
)
|
|
110
|
+
k.unlock(pw)
|
|
111
|
+
|
|
112
|
+
sig = k.sign(payload, detached=True)
|
|
113
|
+
kid = str(k.fingerprint)
|
|
114
|
+
sig_bytes = bytes(sig.__bytes__())
|
|
115
|
+
sig_asc = str(sig)
|
|
116
|
+
return [
|
|
117
|
+
_Sig({"alg": "OpenPGP", "kid": kid, "sig": sig_bytes, "armored": sig_asc})
|
|
118
|
+
]
|
|
119
|
+
|
|
120
|
+
async def verify_bytes(
|
|
121
|
+
self,
|
|
122
|
+
payload: bytes,
|
|
123
|
+
signatures: Sequence[Signature],
|
|
124
|
+
*,
|
|
125
|
+
require: Optional[Mapping[str, object]] = None,
|
|
126
|
+
opts: Optional[Mapping[str, object]] = None,
|
|
127
|
+
) -> bool:
|
|
128
|
+
_ensure_pgpy()
|
|
129
|
+
min_signers = int(require.get("min_signers", 1)) if require else 1
|
|
130
|
+
|
|
131
|
+
pubkeys = []
|
|
132
|
+
if opts and "pubkeys" in opts:
|
|
133
|
+
for entry in opts["pubkeys"]: # type: ignore[index]
|
|
134
|
+
if isinstance(entry, pgpy.PGPKey):
|
|
135
|
+
pubkeys.append(entry)
|
|
136
|
+
elif isinstance(entry, str):
|
|
137
|
+
pubkeys.append(pgpy.PGPKey.from_blob(entry)[0])
|
|
138
|
+
else:
|
|
139
|
+
raise TypeError("Unsupported public key in opts['pubkeys'].")
|
|
140
|
+
|
|
141
|
+
accepted = 0
|
|
142
|
+
for sig in signatures:
|
|
143
|
+
if sig.get("alg") != "OpenPGP":
|
|
144
|
+
continue
|
|
145
|
+
sig_bytes = sig.get("sig")
|
|
146
|
+
sig_arm = sig.get("armored")
|
|
147
|
+
if isinstance(sig_bytes, (bytes, bytearray)):
|
|
148
|
+
s = pgpy.PGPSignature.from_blob(bytes(sig_bytes))
|
|
149
|
+
elif isinstance(sig_arm, str):
|
|
150
|
+
s = pgpy.PGPSignature.from_blob(sig_arm)
|
|
151
|
+
else:
|
|
152
|
+
continue
|
|
153
|
+
|
|
154
|
+
ok_one = False
|
|
155
|
+
for pk in pubkeys:
|
|
156
|
+
if pk.verify(payload, s):
|
|
157
|
+
ok_one = True
|
|
158
|
+
break
|
|
159
|
+
if ok_one:
|
|
160
|
+
accepted += 1
|
|
161
|
+
if accepted >= min_signers:
|
|
162
|
+
return True
|
|
163
|
+
return False
|
|
164
|
+
|
|
165
|
+
# ---------- canonicalization ----------
|
|
166
|
+
async def canonicalize_envelope(
|
|
167
|
+
self,
|
|
168
|
+
env: Envelope,
|
|
169
|
+
*,
|
|
170
|
+
canon: Optional[Canon] = None,
|
|
171
|
+
opts: Optional[Mapping[str, object]] = None,
|
|
172
|
+
) -> bytes:
|
|
173
|
+
if canon in (None, "json"):
|
|
174
|
+
return _canon_json(env) # type: ignore[arg-type]
|
|
175
|
+
if canon == "cbor":
|
|
176
|
+
return _canon_cbor(env) # type: ignore[arg-type]
|
|
177
|
+
raise ValueError(f"Unsupported canon: {canon}")
|
|
178
|
+
|
|
179
|
+
# ---------- envelope ----------
|
|
180
|
+
async def sign_envelope(
|
|
181
|
+
self,
|
|
182
|
+
key: KeyRef,
|
|
183
|
+
env: Envelope,
|
|
184
|
+
*,
|
|
185
|
+
alg: Optional[Alg] = None,
|
|
186
|
+
canon: Optional[Canon] = None,
|
|
187
|
+
opts: Optional[Mapping[str, object]] = None,
|
|
188
|
+
) -> Sequence[Signature]:
|
|
189
|
+
payload = await self.canonicalize_envelope(env, canon=canon, opts=opts)
|
|
190
|
+
return await self.sign_bytes(key, payload, alg="OpenPGP", opts=opts)
|
|
191
|
+
|
|
192
|
+
async def verify_envelope(
|
|
193
|
+
self,
|
|
194
|
+
env: Envelope,
|
|
195
|
+
signatures: Sequence[Signature],
|
|
196
|
+
*,
|
|
197
|
+
canon: Optional[Canon] = None,
|
|
198
|
+
require: Optional[Mapping[str, object]] = None,
|
|
199
|
+
opts: Optional[Mapping[str, object]] = None,
|
|
200
|
+
) -> bool:
|
|
201
|
+
payload = await self.canonicalize_envelope(env, canon=canon, opts=opts)
|
|
202
|
+
return await self.verify_bytes(payload, signatures, require=require, opts=opts)
|
|
203
|
+
|
|
204
|
+
# ---------- internal ----------
|
|
205
|
+
def _load_private_key(self, key: KeyRef, opts: Optional[Mapping[str, object]]):
|
|
206
|
+
if isinstance(key, dict):
|
|
207
|
+
kind = key.get("kind")
|
|
208
|
+
if kind == "pgpy_key" and isinstance(key.get("priv"), pgpy.PGPKey):
|
|
209
|
+
return key["priv"]
|
|
210
|
+
if kind == "pgpy_key_armored" and isinstance(key.get("priv"), str):
|
|
211
|
+
k, _ = pgpy.PGPKey.from_blob(key["priv"])
|
|
212
|
+
return k
|
|
213
|
+
raise TypeError("Unsupported KeyRef for PgpEnvelopeSigner private key.")
|