bitspark-archon-sdk 0.8.1__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.
- bitspark_archon_sdk-0.8.1/LICENSE +202 -0
- bitspark_archon_sdk-0.8.1/NOTICE +4 -0
- bitspark_archon_sdk-0.8.1/PKG-INFO +91 -0
- bitspark_archon_sdk-0.8.1/README.md +68 -0
- bitspark_archon_sdk-0.8.1/pyproject.toml +45 -0
- bitspark_archon_sdk-0.8.1/setup.cfg +4 -0
- bitspark_archon_sdk-0.8.1/src/archon_sdk/__init__.py +26 -0
- bitspark_archon_sdk-0.8.1/src/archon_sdk/_conformance.py +98 -0
- bitspark_archon_sdk-0.8.1/src/archon_sdk/envelope.py +106 -0
- bitspark_archon_sdk-0.8.1/src/archon_sdk/possession.py +76 -0
- bitspark_archon_sdk-0.8.1/src/archon_sdk/py.typed +0 -0
- bitspark_archon_sdk-0.8.1/src/bitspark_archon_sdk.egg-info/PKG-INFO +91 -0
- bitspark_archon_sdk-0.8.1/src/bitspark_archon_sdk.egg-info/SOURCES.txt +15 -0
- bitspark_archon_sdk-0.8.1/src/bitspark_archon_sdk.egg-info/dependency_links.txt +1 -0
- bitspark_archon_sdk-0.8.1/src/bitspark_archon_sdk.egg-info/requires.txt +1 -0
- bitspark_archon_sdk-0.8.1/src/bitspark_archon_sdk.egg-info/top_level.txt +1 -0
- bitspark_archon_sdk-0.8.1/test/test_sdk.py +167 -0
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: bitspark-archon-sdk
|
|
3
|
+
Version: 0.8.1
|
|
4
|
+
Summary: archon sdk: proof of possession and the signed envelope, one layer above the identity floor. Deterministic given its inputs; no RNG, no clock, no socket.
|
|
5
|
+
Author: Bitspark
|
|
6
|
+
License-Expression: Apache-2.0
|
|
7
|
+
Project-URL: Homepage, https://github.com/Bitspark/archon
|
|
8
|
+
Project-URL: Documentation, https://github.com/Bitspark/archon/tree/main/docs
|
|
9
|
+
Project-URL: Repository, https://github.com/Bitspark/archon
|
|
10
|
+
Project-URL: Issues, https://github.com/Bitspark/archon/issues
|
|
11
|
+
Classifier: Development Status :: 3 - Alpha
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
15
|
+
Classifier: Topic :: Security :: Cryptography
|
|
16
|
+
Classifier: Typing :: Typed
|
|
17
|
+
Requires-Python: >=3.11
|
|
18
|
+
Description-Content-Type: text/markdown
|
|
19
|
+
License-File: LICENSE
|
|
20
|
+
License-File: NOTICE
|
|
21
|
+
Requires-Dist: bitspark-archon-core~=0.8.1
|
|
22
|
+
Dynamic: license-file
|
|
23
|
+
|
|
24
|
+
# archon sdk — Python
|
|
25
|
+
|
|
26
|
+
One layer above the identity floor: proof of possession and the signed envelope.
|
|
27
|
+
|
|
28
|
+
```console
|
|
29
|
+
pip install bitspark-archon-sdk
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
The distribution is `bitspark-archon-sdk`; the import is `archon_sdk`. It depends on
|
|
33
|
+
[`bitspark-archon-core`](https://pypi.org/project/bitspark-archon-core/) and nothing else, and
|
|
34
|
+
pip installs the floor with it.
|
|
35
|
+
|
|
36
|
+
```python
|
|
37
|
+
from archon_core import public_key_from_seed
|
|
38
|
+
from archon_sdk import envelope, possession
|
|
39
|
+
|
|
40
|
+
seed = bytes(range(32))
|
|
41
|
+
pub = public_key_from_seed(seed)
|
|
42
|
+
|
|
43
|
+
# Proof of possession: the challenger picks the nonce and the channel binding.
|
|
44
|
+
nonce, binding = bytes(range(16)), b"tls-exporter-bytes"
|
|
45
|
+
proof = possession.prove(seed, "example/pop/v1", nonce, binding)
|
|
46
|
+
possession.verify(pub, "example/pop/v1", nonce, binding, proof) # True
|
|
47
|
+
possession.verify(pub, "example/pop/v1", nonce, b"another channel", proof) # False
|
|
48
|
+
|
|
49
|
+
# The signed envelope: the verifier chooses the domain, never the envelope.
|
|
50
|
+
sealed = envelope.seal(seed, "example/env/v1", b"payload")
|
|
51
|
+
opened = envelope.open(sealed, "example/env/v1") # Opened(pubkey=…, payload=b'payload')
|
|
52
|
+
envelope.open(sealed, "example/env/other") # ValueError: claims a different domain
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## What it is
|
|
56
|
+
|
|
57
|
+
| | |
|
|
58
|
+
|---|---|
|
|
59
|
+
| `possession` | `prove`, `verify`, `message_bytes` — *can they sign, right now, for this channel?* |
|
|
60
|
+
| `envelope` | `seal`, `open`, `message_bytes`, `Opened` — *these bytes, signed by this key, in this domain* |
|
|
61
|
+
|
|
62
|
+
Both sign in the **caller's** domain through `archon_core.sign_in_domain`, and each prefixes
|
|
63
|
+
its layout with a one-byte scheme tag so a possession proof and an envelope payload in the
|
|
64
|
+
same domain can never be the same bytes.
|
|
65
|
+
|
|
66
|
+
**Entropy, time and channel binding are arguments.** This package never sources them, which
|
|
67
|
+
is what makes every byte it emits a deterministic function of its inputs. Verification is
|
|
68
|
+
total: `possession.verify` returns `False` on any shape failure and never raises;
|
|
69
|
+
`envelope.open` raises `ValueError` and never returns an unverified payload.
|
|
70
|
+
|
|
71
|
+
**Not here yet: the login scheme.** The Go, Rust and TypeScript sdks also carry
|
|
72
|
+
`archon-login/1` ([docs/login.md](https://github.com/Bitspark/archon/blob/main/docs/login.md));
|
|
73
|
+
this one does not.
|
|
74
|
+
|
|
75
|
+
## Agreement is the claim
|
|
76
|
+
|
|
77
|
+
This sdk is held to the same hand-authored oracle as the Go, Rust and TypeScript sdks — 38
|
|
78
|
+
cases in [`vectors/sdk.json`](https://github.com/Bitspark/archon/blob/main/vectors/sdk.json),
|
|
79
|
+
recomputed rather than echoed. If it disagrees with them about a proof or an envelope, that
|
|
80
|
+
disagreement is the defect.
|
|
81
|
+
|
|
82
|
+
## Verification
|
|
83
|
+
|
|
84
|
+
```console
|
|
85
|
+
node conformance/check-py-sdk.mjs # the oracle, against this tree
|
|
86
|
+
node conformance/check-py-sdk-package.mjs # the built wheel, installed from nothing
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
## License
|
|
90
|
+
|
|
91
|
+
Apache-2.0.
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
# archon sdk — Python
|
|
2
|
+
|
|
3
|
+
One layer above the identity floor: proof of possession and the signed envelope.
|
|
4
|
+
|
|
5
|
+
```console
|
|
6
|
+
pip install bitspark-archon-sdk
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
The distribution is `bitspark-archon-sdk`; the import is `archon_sdk`. It depends on
|
|
10
|
+
[`bitspark-archon-core`](https://pypi.org/project/bitspark-archon-core/) and nothing else, and
|
|
11
|
+
pip installs the floor with it.
|
|
12
|
+
|
|
13
|
+
```python
|
|
14
|
+
from archon_core import public_key_from_seed
|
|
15
|
+
from archon_sdk import envelope, possession
|
|
16
|
+
|
|
17
|
+
seed = bytes(range(32))
|
|
18
|
+
pub = public_key_from_seed(seed)
|
|
19
|
+
|
|
20
|
+
# Proof of possession: the challenger picks the nonce and the channel binding.
|
|
21
|
+
nonce, binding = bytes(range(16)), b"tls-exporter-bytes"
|
|
22
|
+
proof = possession.prove(seed, "example/pop/v1", nonce, binding)
|
|
23
|
+
possession.verify(pub, "example/pop/v1", nonce, binding, proof) # True
|
|
24
|
+
possession.verify(pub, "example/pop/v1", nonce, b"another channel", proof) # False
|
|
25
|
+
|
|
26
|
+
# The signed envelope: the verifier chooses the domain, never the envelope.
|
|
27
|
+
sealed = envelope.seal(seed, "example/env/v1", b"payload")
|
|
28
|
+
opened = envelope.open(sealed, "example/env/v1") # Opened(pubkey=…, payload=b'payload')
|
|
29
|
+
envelope.open(sealed, "example/env/other") # ValueError: claims a different domain
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## What it is
|
|
33
|
+
|
|
34
|
+
| | |
|
|
35
|
+
|---|---|
|
|
36
|
+
| `possession` | `prove`, `verify`, `message_bytes` — *can they sign, right now, for this channel?* |
|
|
37
|
+
| `envelope` | `seal`, `open`, `message_bytes`, `Opened` — *these bytes, signed by this key, in this domain* |
|
|
38
|
+
|
|
39
|
+
Both sign in the **caller's** domain through `archon_core.sign_in_domain`, and each prefixes
|
|
40
|
+
its layout with a one-byte scheme tag so a possession proof and an envelope payload in the
|
|
41
|
+
same domain can never be the same bytes.
|
|
42
|
+
|
|
43
|
+
**Entropy, time and channel binding are arguments.** This package never sources them, which
|
|
44
|
+
is what makes every byte it emits a deterministic function of its inputs. Verification is
|
|
45
|
+
total: `possession.verify` returns `False` on any shape failure and never raises;
|
|
46
|
+
`envelope.open` raises `ValueError` and never returns an unverified payload.
|
|
47
|
+
|
|
48
|
+
**Not here yet: the login scheme.** The Go, Rust and TypeScript sdks also carry
|
|
49
|
+
`archon-login/1` ([docs/login.md](https://github.com/Bitspark/archon/blob/main/docs/login.md));
|
|
50
|
+
this one does not.
|
|
51
|
+
|
|
52
|
+
## Agreement is the claim
|
|
53
|
+
|
|
54
|
+
This sdk is held to the same hand-authored oracle as the Go, Rust and TypeScript sdks — 38
|
|
55
|
+
cases in [`vectors/sdk.json`](https://github.com/Bitspark/archon/blob/main/vectors/sdk.json),
|
|
56
|
+
recomputed rather than echoed. If it disagrees with them about a proof or an envelope, that
|
|
57
|
+
disagreement is the defect.
|
|
58
|
+
|
|
59
|
+
## Verification
|
|
60
|
+
|
|
61
|
+
```console
|
|
62
|
+
node conformance/check-py-sdk.mjs # the oracle, against this tree
|
|
63
|
+
node conformance/check-py-sdk-package.mjs # the built wheel, installed from nothing
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## License
|
|
67
|
+
|
|
68
|
+
Apache-2.0.
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=77.0.3"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "bitspark-archon-sdk"
|
|
7
|
+
version = "0.8.1"
|
|
8
|
+
description = "archon sdk: proof of possession and the signed envelope, one layer above the identity floor. Deterministic given its inputs; no RNG, no clock, no socket."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.11"
|
|
11
|
+
license = "Apache-2.0"
|
|
12
|
+
license-files = ["LICENSE", "NOTICE"]
|
|
13
|
+
authors = [{ name = "Bitspark" }]
|
|
14
|
+
|
|
15
|
+
# The floor, and nothing else. A REGISTRY range, never a path: this is what a consumer's pip
|
|
16
|
+
# resolves, so it has to name something PyPI serves. `~=X.Y.Z` is `>=X.Y.Z, ==X.Y.*`, the
|
|
17
|
+
# same compatible range npm's `^` and cargo's default give the other two sdks for a 0.x
|
|
18
|
+
# version. archon versions in lockstep (ADR 0005), so the release's manifest guard holds this
|
|
19
|
+
# range to the tag as well as the version above — an sdk that names an older floor than the
|
|
20
|
+
# one it was tested against is the defect it exists to catch.
|
|
21
|
+
dependencies = ["bitspark-archon-core~=0.8.1"]
|
|
22
|
+
|
|
23
|
+
classifiers = [
|
|
24
|
+
"Development Status :: 3 - Alpha",
|
|
25
|
+
"Intended Audience :: Developers",
|
|
26
|
+
"Programming Language :: Python :: 3",
|
|
27
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
28
|
+
"Topic :: Security :: Cryptography",
|
|
29
|
+
"Typing :: Typed",
|
|
30
|
+
]
|
|
31
|
+
|
|
32
|
+
[project.urls]
|
|
33
|
+
Homepage = "https://github.com/Bitspark/archon"
|
|
34
|
+
Documentation = "https://github.com/Bitspark/archon/tree/main/docs"
|
|
35
|
+
Repository = "https://github.com/Bitspark/archon"
|
|
36
|
+
Issues = "https://github.com/Bitspark/archon/issues"
|
|
37
|
+
|
|
38
|
+
[tool.setuptools.packages.find]
|
|
39
|
+
where = ["src"]
|
|
40
|
+
|
|
41
|
+
[tool.setuptools.package-data]
|
|
42
|
+
archon_sdk = ["py.typed"]
|
|
43
|
+
|
|
44
|
+
[tool.pytest.ini_options]
|
|
45
|
+
testpaths = ["test"]
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"""archon sdk — one layer above the identity floor, in Python.
|
|
2
|
+
|
|
3
|
+
`archon_core` answers *"is this really them?"* over bytes. This package answers the two
|
|
4
|
+
questions every protocol asks next, without knowing the protocol:
|
|
5
|
+
|
|
6
|
+
- `possession` — *can they sign, right now, for this channel?* The challenger supplies a
|
|
7
|
+
nonce and a channel binding, the prover signs a fixed layout of both in the protocol's
|
|
8
|
+
domain, the challenger verifies. The binding is what makes the proof unrelayable; without
|
|
9
|
+
one there is no proof, so an empty binding is refused.
|
|
10
|
+
- `envelope` — *these bytes, signed by this key, in this domain.* A fixed container:
|
|
11
|
+
version, domain, public key, signature, opaque payload. No expiry, issuer, audience or
|
|
12
|
+
key-id — each is either policy or a second spelling of the key, and both are the
|
|
13
|
+
consumer's.
|
|
14
|
+
|
|
15
|
+
**The rule that keeps this layer honest:** entropy, time and channel binding are arguments.
|
|
16
|
+
This package never sources them, so every byte it emits is a deterministic function of its
|
|
17
|
+
inputs and is pinned by `vectors/sdk.json` — the same oracle the Go, Rust and TypeScript sdks
|
|
18
|
+
are held to. The login scheme, which the other three also carry, is not here yet.
|
|
19
|
+
"""
|
|
20
|
+
|
|
21
|
+
from . import envelope, possession
|
|
22
|
+
from .envelope import Opened
|
|
23
|
+
|
|
24
|
+
__version__ = "0.8.1"
|
|
25
|
+
|
|
26
|
+
__all__ = ["envelope", "possession", "Opened", "__version__"]
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
"""Conformance CLI (python, sdk) — a dev/CI artifact, not part of the library surface.
|
|
2
|
+
|
|
3
|
+
The same `conformance v1` protocol as the floor's CLI: `conformance <family>` reads the whole
|
|
4
|
+
vectors/sdk.json on stdin, selects its family, RECOMPUTES each result from the case INPUTS
|
|
5
|
+
(ignoring the expected value the oracle carries), and writes one NDJSON line per case to
|
|
6
|
+
stdout in input order.
|
|
7
|
+
|
|
8
|
+
possession_prove : in {name, seed, domain, nonce, binding} out {"name","result":{"ok":"<128-hex>"}|{"error":true}}
|
|
9
|
+
possession_verify : in {name, pubkey, domain, nonce, binding, sig} out {"name","valid":<bool>}
|
|
10
|
+
envelope_seal : in {name, seed, domain, payload} out {"name","result":{"ok":"<hex>"}|{"error":true}}
|
|
11
|
+
envelope_open : in {name, envelope, domain} out {"name","result":{"ok":{"pubkey","payload"}}|{"error":true}}
|
|
12
|
+
|
|
13
|
+
Recomputing rather than echoing is the whole point: a CLI that read `result` from the case
|
|
14
|
+
would agree with the oracle by construction and prove nothing.
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
import json
|
|
18
|
+
import sys
|
|
19
|
+
|
|
20
|
+
from . import envelope, possession
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def _attempt(fn):
|
|
24
|
+
"""The oracle's two-shape result: {"ok": …} or {"error": true}. It distinguishes success
|
|
25
|
+
from failure, never the message."""
|
|
26
|
+
try:
|
|
27
|
+
return {"ok": fn()}
|
|
28
|
+
except Exception: # noqa: BLE001 - every failure is one refusal to the oracle
|
|
29
|
+
return {"error": True}
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def _unhex(text: str) -> bytes:
|
|
33
|
+
# Case inputs that are *already* known-good hex; a bad one is a broken vector file, not a
|
|
34
|
+
# case the family is testing.
|
|
35
|
+
return bytes.fromhex(text)
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def _opened(env_hex: str, domain: str) -> dict:
|
|
39
|
+
o = envelope.open(_unhex(env_hex), domain)
|
|
40
|
+
return {"pubkey": o.pubkey.hex(), "payload": o.payload.hex()}
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def main(argv=None) -> int:
|
|
44
|
+
argv = sys.argv[1:] if argv is None else argv
|
|
45
|
+
if len(argv) != 1:
|
|
46
|
+
print("usage: conformance <family>", file=sys.stderr)
|
|
47
|
+
return 2
|
|
48
|
+
family = argv[0]
|
|
49
|
+
|
|
50
|
+
doc = json.load(sys.stdin)
|
|
51
|
+
cases = doc.get(family)
|
|
52
|
+
if not isinstance(cases, list):
|
|
53
|
+
print(f"conformance: no such family: {family}", file=sys.stderr)
|
|
54
|
+
return 1
|
|
55
|
+
|
|
56
|
+
out_lines = []
|
|
57
|
+
for case in cases:
|
|
58
|
+
name = case["name"]
|
|
59
|
+
if family == "possession_prove":
|
|
60
|
+
out = {
|
|
61
|
+
"name": name,
|
|
62
|
+
"result": _attempt(
|
|
63
|
+
lambda: possession.prove(
|
|
64
|
+
_unhex(case["seed"]), case["domain"], _unhex(case["nonce"]), _unhex(case["binding"])
|
|
65
|
+
).hex()
|
|
66
|
+
),
|
|
67
|
+
}
|
|
68
|
+
elif family == "possession_verify":
|
|
69
|
+
out = {
|
|
70
|
+
"name": name,
|
|
71
|
+
"valid": possession.verify(
|
|
72
|
+
_unhex(case["pubkey"]),
|
|
73
|
+
case["domain"],
|
|
74
|
+
_unhex(case["nonce"]),
|
|
75
|
+
_unhex(case["binding"]),
|
|
76
|
+
_unhex(case["sig"]),
|
|
77
|
+
),
|
|
78
|
+
}
|
|
79
|
+
elif family == "envelope_seal":
|
|
80
|
+
out = {
|
|
81
|
+
"name": name,
|
|
82
|
+
"result": _attempt(
|
|
83
|
+
lambda: envelope.seal(_unhex(case["seed"]), case["domain"], _unhex(case["payload"])).hex()
|
|
84
|
+
),
|
|
85
|
+
}
|
|
86
|
+
elif family == "envelope_open":
|
|
87
|
+
out = {"name": name, "result": _attempt(lambda: _opened(case["envelope"], case["domain"]))}
|
|
88
|
+
else:
|
|
89
|
+
print(f"conformance: no such family: {family}", file=sys.stderr)
|
|
90
|
+
return 1
|
|
91
|
+
out_lines.append(json.dumps(out))
|
|
92
|
+
|
|
93
|
+
sys.stdout.write("".join(line + "\n" for line in out_lines))
|
|
94
|
+
return 0
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
if __name__ == "__main__":
|
|
98
|
+
sys.exit(main())
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
"""The signed envelope — *these bytes, signed by this key, in this domain.*
|
|
2
|
+
|
|
3
|
+
A fixed binary container, JWS-shaped and deliberately not JWT-shaped::
|
|
4
|
+
|
|
5
|
+
"arcn" ‖ 0x01 ‖ u8(len domain) ‖ domain ‖ pubkey[32] ‖ signature[64] ‖ payload
|
|
6
|
+
|
|
7
|
+
where `signature = sign_in_domain(seed, domain, SCHEME_TAG ‖ payload)`. The domain is bound
|
|
8
|
+
cryptographically (it is the RFC 8032 context), the public key is bound by verification, and
|
|
9
|
+
the payload is opaque: the envelope says nothing about what it means. **What is not here, on
|
|
10
|
+
purpose:** expiry, issuer, audience, key-id, nonce. Each is either policy — whose clock, whose
|
|
11
|
+
trust? — or a second spelling of the key, and both belong to the consumer.
|
|
12
|
+
|
|
13
|
+
`open` takes the domain the *verifier* expects and refuses an envelope that claims another.
|
|
14
|
+
The verifier chooses the domain; an envelope never gets to choose it for them. Whether to
|
|
15
|
+
trust the key it names is, again, the verifier's.
|
|
16
|
+
"""
|
|
17
|
+
|
|
18
|
+
from dataclasses import dataclass
|
|
19
|
+
|
|
20
|
+
from archon_core import (
|
|
21
|
+
MAX_DOMAIN_SIZE,
|
|
22
|
+
PUBLIC_KEY_SIZE,
|
|
23
|
+
SIGNATURE_SIZE,
|
|
24
|
+
public_key_from_seed,
|
|
25
|
+
sign_in_domain,
|
|
26
|
+
verify_in_domain,
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
#: The first four bytes of every envelope.
|
|
30
|
+
MAGIC = b"arcn"
|
|
31
|
+
|
|
32
|
+
#: The envelope format version.
|
|
33
|
+
VERSION = 0x01
|
|
34
|
+
|
|
35
|
+
#: The first byte of every signed envelope message. Distinct from `possession.SCHEME_TAG`.
|
|
36
|
+
SCHEME_TAG = 0x02
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
@dataclass(frozen=True)
|
|
40
|
+
class Opened:
|
|
41
|
+
"""What `open` returns: the sealing key and the payload, both verified."""
|
|
42
|
+
|
|
43
|
+
#: The public key that sealed the envelope. Trusting it is the caller's decision.
|
|
44
|
+
pubkey: bytes
|
|
45
|
+
#: The payload, verbatim.
|
|
46
|
+
payload: bytes
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def seal(seed: bytes, domain: str, payload: bytes) -> bytes:
|
|
50
|
+
"""Seal `payload` in `domain` with the key behind `seed`.
|
|
51
|
+
|
|
52
|
+
Raises `ValueError` on an invalid domain (see `archon_core.sign_in_domain`) or a seed
|
|
53
|
+
that is not 32 bytes. An empty payload is allowed — the signed message is never empty,
|
|
54
|
+
because of the scheme tag.
|
|
55
|
+
"""
|
|
56
|
+
payload = bytes(payload)
|
|
57
|
+
# Signing first: it is what validates the domain and the seed, so nothing below is
|
|
58
|
+
# reached with either one wrong.
|
|
59
|
+
signature = sign_in_domain(seed, domain, message_bytes(payload))
|
|
60
|
+
pubkey = public_key_from_seed(seed)
|
|
61
|
+
d = domain.encode("utf-8")
|
|
62
|
+
return MAGIC + bytes([VERSION, len(d)]) + d + pubkey + signature + payload
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def open(envelope: bytes, domain: str) -> Opened: # noqa: A001 - the module is the namespace
|
|
66
|
+
"""Open `envelope`, which the caller expects to be sealed in `domain`.
|
|
67
|
+
|
|
68
|
+
Raises `ValueError` — never returns a payload — when the bytes are not an envelope
|
|
69
|
+
(magic, version, length), the envelope claims a different domain, or the signature does
|
|
70
|
+
not verify.
|
|
71
|
+
"""
|
|
72
|
+
envelope = bytes(envelope)
|
|
73
|
+
at = 0
|
|
74
|
+
|
|
75
|
+
def take(n: int) -> bytes:
|
|
76
|
+
nonlocal at
|
|
77
|
+
if at + n > len(envelope):
|
|
78
|
+
raise ValueError(f"envelope: truncated at byte {len(envelope)}")
|
|
79
|
+
chunk = envelope[at : at + n]
|
|
80
|
+
at += n
|
|
81
|
+
return chunk
|
|
82
|
+
|
|
83
|
+
if take(4) != MAGIC:
|
|
84
|
+
raise ValueError("envelope: not an envelope, bad magic")
|
|
85
|
+
version = take(1)[0]
|
|
86
|
+
if version != VERSION:
|
|
87
|
+
raise ValueError(f"envelope: unsupported version {version}")
|
|
88
|
+
dlen = take(1)[0]
|
|
89
|
+
if dlen == 0 or dlen > MAX_DOMAIN_SIZE:
|
|
90
|
+
raise ValueError(f"envelope: domain length {dlen} out of range")
|
|
91
|
+
claimed = take(dlen)
|
|
92
|
+
# The verifier's expectation decides, before any signature is checked. An envelope that
|
|
93
|
+
# names another domain is refused here even when its signature is genuine in that one.
|
|
94
|
+
if claimed != domain.encode("utf-8"):
|
|
95
|
+
raise ValueError("envelope: claims a different domain")
|
|
96
|
+
pubkey = take(PUBLIC_KEY_SIZE)
|
|
97
|
+
signature = take(SIGNATURE_SIZE)
|
|
98
|
+
payload = envelope[at:]
|
|
99
|
+
if not verify_in_domain(pubkey, domain, message_bytes(payload), signature):
|
|
100
|
+
raise ValueError("envelope: signature does not verify")
|
|
101
|
+
return Opened(pubkey=pubkey, payload=payload)
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
def message_bytes(payload: bytes) -> bytes:
|
|
105
|
+
"""The pinned layout of what gets signed: the scheme tag, then the payload verbatim."""
|
|
106
|
+
return bytes([SCHEME_TAG]) + bytes(payload)
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"""Proof of possession — *can they sign, right now, for this channel?*
|
|
2
|
+
|
|
3
|
+
The challenger picks a `nonce` (fresh entropy, at least 16 bytes — its own, never this
|
|
4
|
+
package's) and a `binding` (something only this channel has: a session key, a TLS exporter,
|
|
5
|
+
the server's identity — the transport's, never this package's). The prover signs a fixed
|
|
6
|
+
layout of both in the protocol's domain; the challenger verifies with the prover's public key.
|
|
7
|
+
|
|
8
|
+
**The binding is what makes this a proof.** A signed nonce alone is relayable: an attacker
|
|
9
|
+
facing the server as the victim forwards the server's nonce to the victim under some pretext,
|
|
10
|
+
gets it signed, and presents the signature. Bound to the channel, the signature is worthless
|
|
11
|
+
anywhere else. So an empty binding is refused outright — the thing it would produce looks like
|
|
12
|
+
a proof and is not one.
|
|
13
|
+
|
|
14
|
+
The signed bytes are `SCHEME_TAG ‖ u16be(len nonce) ‖ nonce ‖ u16be(len binding) ‖ binding`,
|
|
15
|
+
signed with `archon_core.sign_in_domain` in the caller's domain. The tag keeps a possession
|
|
16
|
+
message and an envelope payload in the same domain from ever being the same bytes.
|
|
17
|
+
"""
|
|
18
|
+
|
|
19
|
+
from archon_core import sign_in_domain, verify_in_domain
|
|
20
|
+
|
|
21
|
+
#: The first byte of every possession message. Distinct from `envelope.SCHEME_TAG`.
|
|
22
|
+
SCHEME_TAG = 0x01
|
|
23
|
+
|
|
24
|
+
#: The shortest nonce accepted, in bytes. Below this a proof is guessable, so it is refused
|
|
25
|
+
#: rather than weakened.
|
|
26
|
+
MIN_NONCE_SIZE = 16
|
|
27
|
+
|
|
28
|
+
#: The longest nonce or binding, in bytes — the u16 length prefix's bound.
|
|
29
|
+
MAX_FIELD_SIZE = 0xFFFF
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def prove(seed: bytes, domain: str, nonce: bytes, binding: bytes) -> bytes:
|
|
33
|
+
"""Prove possession of the key behind `seed` to a challenger who supplied `nonce` and
|
|
34
|
+
`binding`, in `domain`.
|
|
35
|
+
|
|
36
|
+
Raises `ValueError` on an invalid domain (see `archon_core.sign_in_domain`), a seed that
|
|
37
|
+
is not 32 bytes, a nonce shorter than `MIN_NONCE_SIZE`, an empty binding, or either field
|
|
38
|
+
over `MAX_FIELD_SIZE`.
|
|
39
|
+
"""
|
|
40
|
+
return sign_in_domain(seed, domain, message_bytes(nonce, binding))
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def verify(pubkey: bytes, domain: str, nonce: bytes, binding: bytes, signature: bytes) -> bool:
|
|
44
|
+
"""True when `signature` was made by the key behind `pubkey` over this `nonce` and
|
|
45
|
+
`binding` in `domain`.
|
|
46
|
+
|
|
47
|
+
Total: every shape failure — bad domain, short nonce, empty binding, wrong-sized key or
|
|
48
|
+
signature — is False, never an exception, so a caller cannot mistake "malformed" for
|
|
49
|
+
"valid".
|
|
50
|
+
"""
|
|
51
|
+
try:
|
|
52
|
+
message = message_bytes(nonce, binding)
|
|
53
|
+
except (ValueError, TypeError):
|
|
54
|
+
return False
|
|
55
|
+
return verify_in_domain(pubkey, domain, message, signature)
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def message_bytes(nonce: bytes, binding: bytes) -> bytes:
|
|
59
|
+
"""The pinned layout of what gets signed. Public so a consumer can pin it too."""
|
|
60
|
+
nonce = bytes(nonce)
|
|
61
|
+
binding = bytes(binding)
|
|
62
|
+
if len(nonce) < MIN_NONCE_SIZE:
|
|
63
|
+
raise ValueError(f"possession: nonce is {len(nonce)} bytes, min {MIN_NONCE_SIZE}")
|
|
64
|
+
if len(nonce) > MAX_FIELD_SIZE:
|
|
65
|
+
raise ValueError(f"possession: nonce is {len(nonce)} bytes, max {MAX_FIELD_SIZE}")
|
|
66
|
+
if len(binding) == 0:
|
|
67
|
+
raise ValueError("possession: binding is empty — an unbound proof is not a proof")
|
|
68
|
+
if len(binding) > MAX_FIELD_SIZE:
|
|
69
|
+
raise ValueError(f"possession: binding is {len(binding)} bytes, max {MAX_FIELD_SIZE}")
|
|
70
|
+
return (
|
|
71
|
+
bytes([SCHEME_TAG])
|
|
72
|
+
+ len(nonce).to_bytes(2, "big")
|
|
73
|
+
+ nonce
|
|
74
|
+
+ len(binding).to_bytes(2, "big")
|
|
75
|
+
+ binding
|
|
76
|
+
)
|
|
File without changes
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: bitspark-archon-sdk
|
|
3
|
+
Version: 0.8.1
|
|
4
|
+
Summary: archon sdk: proof of possession and the signed envelope, one layer above the identity floor. Deterministic given its inputs; no RNG, no clock, no socket.
|
|
5
|
+
Author: Bitspark
|
|
6
|
+
License-Expression: Apache-2.0
|
|
7
|
+
Project-URL: Homepage, https://github.com/Bitspark/archon
|
|
8
|
+
Project-URL: Documentation, https://github.com/Bitspark/archon/tree/main/docs
|
|
9
|
+
Project-URL: Repository, https://github.com/Bitspark/archon
|
|
10
|
+
Project-URL: Issues, https://github.com/Bitspark/archon/issues
|
|
11
|
+
Classifier: Development Status :: 3 - Alpha
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
15
|
+
Classifier: Topic :: Security :: Cryptography
|
|
16
|
+
Classifier: Typing :: Typed
|
|
17
|
+
Requires-Python: >=3.11
|
|
18
|
+
Description-Content-Type: text/markdown
|
|
19
|
+
License-File: LICENSE
|
|
20
|
+
License-File: NOTICE
|
|
21
|
+
Requires-Dist: bitspark-archon-core~=0.8.1
|
|
22
|
+
Dynamic: license-file
|
|
23
|
+
|
|
24
|
+
# archon sdk — Python
|
|
25
|
+
|
|
26
|
+
One layer above the identity floor: proof of possession and the signed envelope.
|
|
27
|
+
|
|
28
|
+
```console
|
|
29
|
+
pip install bitspark-archon-sdk
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
The distribution is `bitspark-archon-sdk`; the import is `archon_sdk`. It depends on
|
|
33
|
+
[`bitspark-archon-core`](https://pypi.org/project/bitspark-archon-core/) and nothing else, and
|
|
34
|
+
pip installs the floor with it.
|
|
35
|
+
|
|
36
|
+
```python
|
|
37
|
+
from archon_core import public_key_from_seed
|
|
38
|
+
from archon_sdk import envelope, possession
|
|
39
|
+
|
|
40
|
+
seed = bytes(range(32))
|
|
41
|
+
pub = public_key_from_seed(seed)
|
|
42
|
+
|
|
43
|
+
# Proof of possession: the challenger picks the nonce and the channel binding.
|
|
44
|
+
nonce, binding = bytes(range(16)), b"tls-exporter-bytes"
|
|
45
|
+
proof = possession.prove(seed, "example/pop/v1", nonce, binding)
|
|
46
|
+
possession.verify(pub, "example/pop/v1", nonce, binding, proof) # True
|
|
47
|
+
possession.verify(pub, "example/pop/v1", nonce, b"another channel", proof) # False
|
|
48
|
+
|
|
49
|
+
# The signed envelope: the verifier chooses the domain, never the envelope.
|
|
50
|
+
sealed = envelope.seal(seed, "example/env/v1", b"payload")
|
|
51
|
+
opened = envelope.open(sealed, "example/env/v1") # Opened(pubkey=…, payload=b'payload')
|
|
52
|
+
envelope.open(sealed, "example/env/other") # ValueError: claims a different domain
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## What it is
|
|
56
|
+
|
|
57
|
+
| | |
|
|
58
|
+
|---|---|
|
|
59
|
+
| `possession` | `prove`, `verify`, `message_bytes` — *can they sign, right now, for this channel?* |
|
|
60
|
+
| `envelope` | `seal`, `open`, `message_bytes`, `Opened` — *these bytes, signed by this key, in this domain* |
|
|
61
|
+
|
|
62
|
+
Both sign in the **caller's** domain through `archon_core.sign_in_domain`, and each prefixes
|
|
63
|
+
its layout with a one-byte scheme tag so a possession proof and an envelope payload in the
|
|
64
|
+
same domain can never be the same bytes.
|
|
65
|
+
|
|
66
|
+
**Entropy, time and channel binding are arguments.** This package never sources them, which
|
|
67
|
+
is what makes every byte it emits a deterministic function of its inputs. Verification is
|
|
68
|
+
total: `possession.verify` returns `False` on any shape failure and never raises;
|
|
69
|
+
`envelope.open` raises `ValueError` and never returns an unverified payload.
|
|
70
|
+
|
|
71
|
+
**Not here yet: the login scheme.** The Go, Rust and TypeScript sdks also carry
|
|
72
|
+
`archon-login/1` ([docs/login.md](https://github.com/Bitspark/archon/blob/main/docs/login.md));
|
|
73
|
+
this one does not.
|
|
74
|
+
|
|
75
|
+
## Agreement is the claim
|
|
76
|
+
|
|
77
|
+
This sdk is held to the same hand-authored oracle as the Go, Rust and TypeScript sdks — 38
|
|
78
|
+
cases in [`vectors/sdk.json`](https://github.com/Bitspark/archon/blob/main/vectors/sdk.json),
|
|
79
|
+
recomputed rather than echoed. If it disagrees with them about a proof or an envelope, that
|
|
80
|
+
disagreement is the defect.
|
|
81
|
+
|
|
82
|
+
## Verification
|
|
83
|
+
|
|
84
|
+
```console
|
|
85
|
+
node conformance/check-py-sdk.mjs # the oracle, against this tree
|
|
86
|
+
node conformance/check-py-sdk-package.mjs # the built wheel, installed from nothing
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
## License
|
|
90
|
+
|
|
91
|
+
Apache-2.0.
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
NOTICE
|
|
3
|
+
README.md
|
|
4
|
+
pyproject.toml
|
|
5
|
+
src/archon_sdk/__init__.py
|
|
6
|
+
src/archon_sdk/_conformance.py
|
|
7
|
+
src/archon_sdk/envelope.py
|
|
8
|
+
src/archon_sdk/possession.py
|
|
9
|
+
src/archon_sdk/py.typed
|
|
10
|
+
src/bitspark_archon_sdk.egg-info/PKG-INFO
|
|
11
|
+
src/bitspark_archon_sdk.egg-info/SOURCES.txt
|
|
12
|
+
src/bitspark_archon_sdk.egg-info/dependency_links.txt
|
|
13
|
+
src/bitspark_archon_sdk.egg-info/requires.txt
|
|
14
|
+
src/bitspark_archon_sdk.egg-info/top_level.txt
|
|
15
|
+
test/test_sdk.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
bitspark-archon-core~=0.8.1
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
archon_sdk
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
"""Unit tests for the Python sdk.
|
|
2
|
+
|
|
3
|
+
The oracle in `vectors/sdk.json` is the cross-language authority and is driven by
|
|
4
|
+
`conformance/check-py-sdk.mjs`; these tests cover the same ground from inside Python, plus
|
|
5
|
+
what the oracle's `ok` / `error` protocol cannot express: which exception is raised, and that
|
|
6
|
+
verification never raises. The two verify-side refusals below (a short nonce and an empty
|
|
7
|
+
binding) are also pinned by the oracle since 0.8.0; before that its cases for them carried
|
|
8
|
+
no genuine signature, and these tests were the only thing that caught their removal.
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
import pytest
|
|
12
|
+
|
|
13
|
+
from archon_core import public_key_from_seed, sign, sign_in_domain
|
|
14
|
+
from archon_sdk import Opened, envelope, possession
|
|
15
|
+
|
|
16
|
+
SEED = bytes(range(32))
|
|
17
|
+
OTHER_SEED = bytes(range(1, 33))
|
|
18
|
+
DOMAIN = "example/pop/v1"
|
|
19
|
+
NONCE = bytes(range(16))
|
|
20
|
+
BINDING = b"channel"
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
# --- possession: the layout ----------------------------------------------------------
|
|
24
|
+
|
|
25
|
+
def test_possession_layout_is_pinned():
|
|
26
|
+
assert possession.message_bytes(NONCE, BINDING) == (
|
|
27
|
+
b"\x01" + b"\x00\x10" + NONCE + b"\x00\x07" + BINDING
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def test_possession_layout_bounds():
|
|
32
|
+
possession.message_bytes(bytes(possession.MIN_NONCE_SIZE), b"x")
|
|
33
|
+
possession.message_bytes(bytes(possession.MAX_FIELD_SIZE), bytes(possession.MAX_FIELD_SIZE))
|
|
34
|
+
with pytest.raises(ValueError, match="min 16"):
|
|
35
|
+
possession.message_bytes(bytes(15), b"x")
|
|
36
|
+
with pytest.raises(ValueError, match="max 65535"):
|
|
37
|
+
possession.message_bytes(bytes(possession.MAX_FIELD_SIZE + 1), b"x")
|
|
38
|
+
with pytest.raises(ValueError, match="empty"):
|
|
39
|
+
possession.message_bytes(NONCE, b"")
|
|
40
|
+
with pytest.raises(ValueError, match="max 65535"):
|
|
41
|
+
possession.message_bytes(NONCE, bytes(possession.MAX_FIELD_SIZE + 1))
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
# --- possession: prove and verify ------------------------------------------------------
|
|
45
|
+
|
|
46
|
+
def test_possession_round_trip_and_every_field_binds():
|
|
47
|
+
pub = public_key_from_seed(SEED)
|
|
48
|
+
proof = possession.prove(SEED, DOMAIN, NONCE, BINDING)
|
|
49
|
+
assert len(proof) == 64
|
|
50
|
+
assert possession.verify(pub, DOMAIN, NONCE, BINDING, proof)
|
|
51
|
+
assert not possession.verify(pub, DOMAIN, bytes(range(1, 17)), BINDING, proof)
|
|
52
|
+
assert not possession.verify(pub, DOMAIN, NONCE, b"other channel", proof)
|
|
53
|
+
assert not possession.verify(pub, "example/pop/v2", NONCE, BINDING, proof)
|
|
54
|
+
assert not possession.verify(public_key_from_seed(OTHER_SEED), DOMAIN, NONCE, BINDING, proof)
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def test_possession_is_deterministic():
|
|
58
|
+
assert possession.prove(SEED, DOMAIN, NONCE, BINDING) == possession.prove(SEED, DOMAIN, NONCE, BINDING)
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def test_a_raw_signature_over_the_layout_is_not_a_proof():
|
|
62
|
+
pub = public_key_from_seed(SEED)
|
|
63
|
+
raw = sign(SEED, possession.message_bytes(NONCE, BINDING))
|
|
64
|
+
assert not possession.verify(pub, DOMAIN, NONCE, BINDING, raw)
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def test_prove_refuses_what_is_not_a_proof():
|
|
68
|
+
with pytest.raises(ValueError):
|
|
69
|
+
possession.prove(SEED, DOMAIN, bytes(15), BINDING)
|
|
70
|
+
with pytest.raises(ValueError):
|
|
71
|
+
possession.prove(SEED, DOMAIN, NONCE, b"")
|
|
72
|
+
with pytest.raises(ValueError):
|
|
73
|
+
possession.prove(SEED, "", NONCE, BINDING)
|
|
74
|
+
with pytest.raises(ValueError):
|
|
75
|
+
possession.prove(SEED[:31], DOMAIN, NONCE, BINDING)
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def test_verify_refuses_a_genuine_signature_over_an_unbound_layout():
|
|
79
|
+
# A GENUINE signature over the exact bytes the scheme would sign if it allowed an empty
|
|
80
|
+
# binding, in the domain — so only the sdk's own check can refuse it. The oracle's
|
|
81
|
+
# `binding-empty-rejected` verify case has pinned the same thing since 0.8.0.
|
|
82
|
+
pub = public_key_from_seed(SEED)
|
|
83
|
+
unbound = b"\x01" + b"\x00\x10" + NONCE + b"\x00\x00"
|
|
84
|
+
assert not possession.verify(pub, DOMAIN, NONCE, b"", sign_in_domain(SEED, DOMAIN, unbound))
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
def test_verify_refuses_a_genuine_signature_over_a_short_nonce():
|
|
88
|
+
# The same for `nonce-15-rejected`: a genuine signature over the 15-byte layout.
|
|
89
|
+
pub = public_key_from_seed(SEED)
|
|
90
|
+
short = bytes(15)
|
|
91
|
+
layout = b"\x01" + b"\x00\x0f" + short + b"\x00\x07" + BINDING
|
|
92
|
+
assert not possession.verify(pub, DOMAIN, short, BINDING, sign_in_domain(SEED, DOMAIN, layout))
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
def test_verify_is_total():
|
|
96
|
+
pub = public_key_from_seed(SEED)
|
|
97
|
+
proof = possession.prove(SEED, DOMAIN, NONCE, BINDING)
|
|
98
|
+
assert possession.verify(pub[:31], DOMAIN, NONCE, BINDING, proof) is False
|
|
99
|
+
assert possession.verify(pub, DOMAIN, NONCE, BINDING, proof[:63]) is False
|
|
100
|
+
assert possession.verify(pub, "", NONCE, BINDING, proof) is False
|
|
101
|
+
assert possession.verify(pub, DOMAIN, None, BINDING, proof) is False
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
# --- envelope --------------------------------------------------------------------------
|
|
105
|
+
|
|
106
|
+
ENV_DOMAIN = "example/env/v1"
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
def test_envelope_layout_is_pinned():
|
|
110
|
+
sealed = envelope.seal(SEED, ENV_DOMAIN, b"payload")
|
|
111
|
+
d = ENV_DOMAIN.encode()
|
|
112
|
+
assert sealed[:4] == b"arcn"
|
|
113
|
+
assert sealed[4] == envelope.VERSION
|
|
114
|
+
assert sealed[5] == len(d)
|
|
115
|
+
assert sealed[6 : 6 + len(d)] == d
|
|
116
|
+
at = 6 + len(d)
|
|
117
|
+
assert sealed[at : at + 32] == public_key_from_seed(SEED)
|
|
118
|
+
assert sealed[at + 96 :] == b"payload"
|
|
119
|
+
assert envelope.message_bytes(b"payload") == b"\x02payload"
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
def test_envelope_round_trip():
|
|
123
|
+
opened = envelope.open(envelope.seal(SEED, ENV_DOMAIN, b"payload"), ENV_DOMAIN)
|
|
124
|
+
assert opened == Opened(pubkey=public_key_from_seed(SEED), payload=b"payload")
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
def test_empty_payload_is_allowed():
|
|
128
|
+
assert envelope.open(envelope.seal(SEED, ENV_DOMAIN, b""), ENV_DOMAIN).payload == b""
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
def test_the_verifier_chooses_the_domain():
|
|
132
|
+
# A genuine envelope in another domain: an opener that trusted the envelope's own domain
|
|
133
|
+
# field would accept it.
|
|
134
|
+
sealed = envelope.seal(SEED, "example/env/other", b"payload")
|
|
135
|
+
with pytest.raises(ValueError, match="different domain"):
|
|
136
|
+
envelope.open(sealed, ENV_DOMAIN)
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
def test_every_tamper_is_refused():
|
|
140
|
+
sealed = bytearray(envelope.seal(SEED, ENV_DOMAIN, b"payload"))
|
|
141
|
+
for index in (0, 4, 5, 6, 6 + len(ENV_DOMAIN), len(sealed) - 1):
|
|
142
|
+
bent = bytearray(sealed)
|
|
143
|
+
bent[index] ^= 0x01
|
|
144
|
+
with pytest.raises(ValueError):
|
|
145
|
+
envelope.open(bytes(bent), ENV_DOMAIN)
|
|
146
|
+
for cut in (0, 3, 5, 6 + len(ENV_DOMAIN) + 31, 6 + len(ENV_DOMAIN) + 95):
|
|
147
|
+
with pytest.raises(ValueError):
|
|
148
|
+
envelope.open(bytes(sealed[:cut]), ENV_DOMAIN)
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
def test_a_possession_proof_is_never_an_envelope_signature():
|
|
152
|
+
# The scheme tags keep the two layouts apart: sign the payload bytes as a possession
|
|
153
|
+
# message would be signed (no envelope tag) and splice that signature in.
|
|
154
|
+
sealed = bytearray(envelope.seal(SEED, ENV_DOMAIN, b"payload"))
|
|
155
|
+
at = 6 + len(ENV_DOMAIN) + 32
|
|
156
|
+
sealed[at : at + 64] = sign_in_domain(SEED, ENV_DOMAIN, b"payload")
|
|
157
|
+
with pytest.raises(ValueError, match="does not verify"):
|
|
158
|
+
envelope.open(bytes(sealed), ENV_DOMAIN)
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
def test_seal_refuses_a_bad_domain_or_seed():
|
|
162
|
+
with pytest.raises(ValueError):
|
|
163
|
+
envelope.seal(SEED, "", b"x")
|
|
164
|
+
with pytest.raises(ValueError):
|
|
165
|
+
envelope.seal(SEED, "d" * 256, b"x")
|
|
166
|
+
with pytest.raises(ValueError):
|
|
167
|
+
envelope.seal(SEED[:31], ENV_DOMAIN, b"x")
|