ades-sign 0.4.0__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.
- ades_sign-0.4.0/.gitignore +7 -0
- ades_sign-0.4.0/LICENSE +28 -0
- ades_sign-0.4.0/PKG-INFO +131 -0
- ades_sign-0.4.0/README.md +103 -0
- ades_sign-0.4.0/SPEC.md +199 -0
- ades_sign-0.4.0/pyproject.toml +59 -0
- ades_sign-0.4.0/src/ades_sign/__init__.py +49 -0
- ades_sign-0.4.0/src/ades_sign/cli.py +130 -0
- ades_sign-0.4.0/src/ades_sign/core.py +538 -0
- ades_sign-0.4.0/src/ades_sign/version.py +24 -0
- ades_sign-0.4.0/tests/data/example.psv +21 -0
- ades_sign-0.4.0/tests/data/rfc10073-mldsa65-ed25519.json +6 -0
- ades_sign-0.4.0/tests/test_ades_sign.py +247 -0
ades_sign-0.4.0/LICENSE
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
BSD 3-Clause License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026, Mario Juric
|
|
4
|
+
|
|
5
|
+
Redistribution and use in source and binary forms, with or without
|
|
6
|
+
modification, are permitted provided that the following conditions are met:
|
|
7
|
+
|
|
8
|
+
1. Redistributions of source code must retain the above copyright notice, this
|
|
9
|
+
list of conditions and the following disclaimer.
|
|
10
|
+
|
|
11
|
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
12
|
+
this list of conditions and the following disclaimer in the documentation
|
|
13
|
+
and/or other materials provided with the distribution.
|
|
14
|
+
|
|
15
|
+
3. Neither the name of the copyright holder nor the names of its
|
|
16
|
+
contributors may be used to endorse or promote products derived from
|
|
17
|
+
this software without specific prior written permission.
|
|
18
|
+
|
|
19
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
20
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
21
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
22
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
23
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
24
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
25
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
26
|
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
27
|
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
28
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
ades_sign-0.4.0/PKG-INFO
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: ades-sign
|
|
3
|
+
Version: 0.4.0
|
|
4
|
+
Summary: Signatures embedded in ADES PSV files (X-ADES-SIG): Ed25519, ML-DSA-65 and RFC 10073's composite
|
|
5
|
+
Project-URL: Source, https://github.com/juriclab/ades-sign
|
|
6
|
+
Project-URL: Specification, https://github.com/juriclab/ades-sign/blob/main/SPEC.md
|
|
7
|
+
Project-URL: Issues, https://github.com/juriclab/ades-sign/issues
|
|
8
|
+
Author: Mario Juric
|
|
9
|
+
License-Expression: BSD-3-Clause
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Keywords: ADES,Ed25519,ML-DSA,astrometry,minor planets,post-quantum,signatures
|
|
12
|
+
Classifier: Development Status :: 4 - Beta
|
|
13
|
+
Classifier: Environment :: Console
|
|
14
|
+
Classifier: Intended Audience :: Science/Research
|
|
15
|
+
Classifier: Operating System :: OS Independent
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
21
|
+
Classifier: Topic :: Scientific/Engineering :: Astronomy
|
|
22
|
+
Classifier: Topic :: Security :: Cryptography
|
|
23
|
+
Requires-Python: >=3.11
|
|
24
|
+
Requires-Dist: cryptography>=47
|
|
25
|
+
Provides-Extra: test
|
|
26
|
+
Requires-Dist: pytest; extra == 'test'
|
|
27
|
+
Description-Content-Type: text/markdown
|
|
28
|
+
|
|
29
|
+
# ades-sign
|
|
30
|
+
|
|
31
|
+
Signatures embedded in [ADES](https://minorplanetcenter.net/iau/info/ADES.html) PSV files. A signed file carries its
|
|
32
|
+
signatures in its own header, as ordinary ADES comment lines, so it stays valid ADES. Anyone with the signer's public
|
|
33
|
+
key can check, offline, that the file is byte for byte the one that was signed.
|
|
34
|
+
|
|
35
|
+
[SPEC.md](SPEC.md) states the format, X-ADES-SIG version 1. It supports three algorithms:
|
|
36
|
+
- Ed25519;
|
|
37
|
+
- ML-DSA-65 (post-quantum);
|
|
38
|
+
- the hybrid of the two standardised in RFC 10073, which stays secure as long as either part is.
|
|
39
|
+
|
|
40
|
+
You can check a signature by hand with `grep` and `openssl`; SPEC.md shows how.
|
|
41
|
+
|
|
42
|
+
## Install
|
|
43
|
+
|
|
44
|
+
```sh
|
|
45
|
+
uv tool install ades-sign # or: pipx install ades-sign, or pip install ades-sign
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
It needs Python 3.11 or later and pyca `cryptography` 47 or later. Install the command in an environment of its own
|
|
49
|
+
(as `uv tool` and `pipx` do), not in one shared with many other packages: any package installed there could run code
|
|
50
|
+
in a process that holds your private key.
|
|
51
|
+
|
|
52
|
+
## Use
|
|
53
|
+
|
|
54
|
+
Make a key. This writes the private key, encrypted, and prints its entry for a key list:
|
|
55
|
+
|
|
56
|
+
```sh
|
|
57
|
+
ades-sign keygen example-2026a.pem --name example-2026a --role example-survey
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
The key is RFC 10073's composite (`mldsa65-ed25519-sha512`) unless `--alg` names another (`ed25519` or
|
|
61
|
+
`ml-dsa-65`), and expires in two years unless `--expires` says when. The passphrase comes from
|
|
62
|
+
`ADES_SIGN_PASSPHRASE` or is asked for; `--no-passphrase` writes the key unencrypted.
|
|
63
|
+
|
|
64
|
+
Put the printed entry in a key list, `keys.json`:
|
|
65
|
+
|
|
66
|
+
```json
|
|
67
|
+
{"keys": [ ...the entry... ]}
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
Sign a file. The passphrase comes from `ADES_SIGN_PASSPHRASE` or is asked for:
|
|
71
|
+
|
|
72
|
+
```sh
|
|
73
|
+
ades-sign sign obs.psv obs.signed.psv -k example-2026a.pem --keylist keys.json
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
The file must have a `# comment` block; the signatures go at its end. Repeat `-k` for more signatures.
|
|
77
|
+
|
|
78
|
+
Verify a file:
|
|
79
|
+
|
|
80
|
+
```sh
|
|
81
|
+
ades-sign verify obs.signed.psv --keylist keys.json [--policy policy.json]
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
It prints `VALID` or `INVALID` with the comment lines just before the signature block (where a signer puts what
|
|
85
|
+
it wants signed: who signed, when, with what settings), the digest the signatures sign, which identifies the signed
|
|
86
|
+
file, and every signature found. It exits with status 1 if a file is not valid, and 2 on an error (a missing file, a bad key list or
|
|
87
|
+
policy). By default a file is valid if a current key of the list
|
|
88
|
+
signed it. A policy can name the signers required instead (SPEC.md, Verification).
|
|
89
|
+
|
|
90
|
+
A signed file must travel as unchanged bytes. Converting its line endings breaks the signature.
|
|
91
|
+
|
|
92
|
+
## Library
|
|
93
|
+
|
|
94
|
+
```python
|
|
95
|
+
import ades_sign
|
|
96
|
+
|
|
97
|
+
key = ades_sign.load_private("example-2026a.pem", passphrase)
|
|
98
|
+
signed = ades_sign.sign(open("obs.psv", "rb").read(), [key])
|
|
99
|
+
result = ades_sign.verify(signed, ades_sign.load_keylist("keys.json")) # the default policy
|
|
100
|
+
print(result.valid, *result.report(), sep="\n")
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
`verify` returns a `Verification`: `valid`; `error` (why a file is malformed); the `digest`; each signature, with
|
|
104
|
+
its key list entry and status; each requirement of the policy and the signature that met it; and the `comments`,
|
|
105
|
+
the lines of the first `# comment` block before the signature block. `report()` gives them as lines of text.
|
|
106
|
+
|
|
107
|
+
## Development
|
|
108
|
+
|
|
109
|
+
```sh
|
|
110
|
+
uv venv && uv pip install -e ".[test]"
|
|
111
|
+
.venv/bin/python -m pytest
|
|
112
|
+
uvx ruff check && uvx ruff format --check
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
CI (`.github/workflows/ci.yml`) runs the tests on Python 3.11 to 3.14 (and on macOS and Windows), ruff, and a build
|
|
116
|
+
check, on every push to `main` and every pull request.
|
|
117
|
+
|
|
118
|
+
The version comes from git: the latest tag `vX.Y.Z` (between tags, a development version after it). To release,
|
|
119
|
+
tag the commit and push the tag: `git tag -a vX.Y.Z -m "ades-sign X.Y.Z" && git push origin vX.Y.Z`. Any tag of
|
|
120
|
+
`v` and a digit starts the release workflow: it runs the tests, builds (the version is the tag's), checks that, and
|
|
121
|
+
publishes to PyPI through trusted publishing: no token is stored anywhere.
|
|
122
|
+
|
|
123
|
+
Change SPEC.md first, then the code: `src/ades_sign/core.py` implements it. The tests include RFC 10073's own test
|
|
124
|
+
vector for the composite (`tests/data/rfc10073-mldsa65-ed25519.json`).
|
|
125
|
+
|
|
126
|
+
ades-sign started as the signing code of [rubin-sarc-check](https://github.com/lsst-ssp/sarc-guidance), which
|
|
127
|
+
signs the files Rubin Observatory returns for submission to the Minor Planet Center.
|
|
128
|
+
|
|
129
|
+
## License
|
|
130
|
+
|
|
131
|
+
BSD 3-Clause; see [LICENSE](LICENSE).
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
# ades-sign
|
|
2
|
+
|
|
3
|
+
Signatures embedded in [ADES](https://minorplanetcenter.net/iau/info/ADES.html) PSV files. A signed file carries its
|
|
4
|
+
signatures in its own header, as ordinary ADES comment lines, so it stays valid ADES. Anyone with the signer's public
|
|
5
|
+
key can check, offline, that the file is byte for byte the one that was signed.
|
|
6
|
+
|
|
7
|
+
[SPEC.md](SPEC.md) states the format, X-ADES-SIG version 1. It supports three algorithms:
|
|
8
|
+
- Ed25519;
|
|
9
|
+
- ML-DSA-65 (post-quantum);
|
|
10
|
+
- the hybrid of the two standardised in RFC 10073, which stays secure as long as either part is.
|
|
11
|
+
|
|
12
|
+
You can check a signature by hand with `grep` and `openssl`; SPEC.md shows how.
|
|
13
|
+
|
|
14
|
+
## Install
|
|
15
|
+
|
|
16
|
+
```sh
|
|
17
|
+
uv tool install ades-sign # or: pipx install ades-sign, or pip install ades-sign
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
It needs Python 3.11 or later and pyca `cryptography` 47 or later. Install the command in an environment of its own
|
|
21
|
+
(as `uv tool` and `pipx` do), not in one shared with many other packages: any package installed there could run code
|
|
22
|
+
in a process that holds your private key.
|
|
23
|
+
|
|
24
|
+
## Use
|
|
25
|
+
|
|
26
|
+
Make a key. This writes the private key, encrypted, and prints its entry for a key list:
|
|
27
|
+
|
|
28
|
+
```sh
|
|
29
|
+
ades-sign keygen example-2026a.pem --name example-2026a --role example-survey
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
The key is RFC 10073's composite (`mldsa65-ed25519-sha512`) unless `--alg` names another (`ed25519` or
|
|
33
|
+
`ml-dsa-65`), and expires in two years unless `--expires` says when. The passphrase comes from
|
|
34
|
+
`ADES_SIGN_PASSPHRASE` or is asked for; `--no-passphrase` writes the key unencrypted.
|
|
35
|
+
|
|
36
|
+
Put the printed entry in a key list, `keys.json`:
|
|
37
|
+
|
|
38
|
+
```json
|
|
39
|
+
{"keys": [ ...the entry... ]}
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
Sign a file. The passphrase comes from `ADES_SIGN_PASSPHRASE` or is asked for:
|
|
43
|
+
|
|
44
|
+
```sh
|
|
45
|
+
ades-sign sign obs.psv obs.signed.psv -k example-2026a.pem --keylist keys.json
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
The file must have a `# comment` block; the signatures go at its end. Repeat `-k` for more signatures.
|
|
49
|
+
|
|
50
|
+
Verify a file:
|
|
51
|
+
|
|
52
|
+
```sh
|
|
53
|
+
ades-sign verify obs.signed.psv --keylist keys.json [--policy policy.json]
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
It prints `VALID` or `INVALID` with the comment lines just before the signature block (where a signer puts what
|
|
57
|
+
it wants signed: who signed, when, with what settings), the digest the signatures sign, which identifies the signed
|
|
58
|
+
file, and every signature found. It exits with status 1 if a file is not valid, and 2 on an error (a missing file, a bad key list or
|
|
59
|
+
policy). By default a file is valid if a current key of the list
|
|
60
|
+
signed it. A policy can name the signers required instead (SPEC.md, Verification).
|
|
61
|
+
|
|
62
|
+
A signed file must travel as unchanged bytes. Converting its line endings breaks the signature.
|
|
63
|
+
|
|
64
|
+
## Library
|
|
65
|
+
|
|
66
|
+
```python
|
|
67
|
+
import ades_sign
|
|
68
|
+
|
|
69
|
+
key = ades_sign.load_private("example-2026a.pem", passphrase)
|
|
70
|
+
signed = ades_sign.sign(open("obs.psv", "rb").read(), [key])
|
|
71
|
+
result = ades_sign.verify(signed, ades_sign.load_keylist("keys.json")) # the default policy
|
|
72
|
+
print(result.valid, *result.report(), sep="\n")
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
`verify` returns a `Verification`: `valid`; `error` (why a file is malformed); the `digest`; each signature, with
|
|
76
|
+
its key list entry and status; each requirement of the policy and the signature that met it; and the `comments`,
|
|
77
|
+
the lines of the first `# comment` block before the signature block. `report()` gives them as lines of text.
|
|
78
|
+
|
|
79
|
+
## Development
|
|
80
|
+
|
|
81
|
+
```sh
|
|
82
|
+
uv venv && uv pip install -e ".[test]"
|
|
83
|
+
.venv/bin/python -m pytest
|
|
84
|
+
uvx ruff check && uvx ruff format --check
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
CI (`.github/workflows/ci.yml`) runs the tests on Python 3.11 to 3.14 (and on macOS and Windows), ruff, and a build
|
|
88
|
+
check, on every push to `main` and every pull request.
|
|
89
|
+
|
|
90
|
+
The version comes from git: the latest tag `vX.Y.Z` (between tags, a development version after it). To release,
|
|
91
|
+
tag the commit and push the tag: `git tag -a vX.Y.Z -m "ades-sign X.Y.Z" && git push origin vX.Y.Z`. Any tag of
|
|
92
|
+
`v` and a digit starts the release workflow: it runs the tests, builds (the version is the tag's), checks that, and
|
|
93
|
+
publishes to PyPI through trusted publishing: no token is stored anywhere.
|
|
94
|
+
|
|
95
|
+
Change SPEC.md first, then the code: `src/ades_sign/core.py` implements it. The tests include RFC 10073's own test
|
|
96
|
+
vector for the composite (`tests/data/rfc10073-mldsa65-ed25519.json`).
|
|
97
|
+
|
|
98
|
+
ades-sign started as the signing code of [rubin-sarc-check](https://github.com/lsst-ssp/sarc-guidance), which
|
|
99
|
+
signs the files Rubin Observatory returns for submission to the Minor Planet Center.
|
|
100
|
+
|
|
101
|
+
## License
|
|
102
|
+
|
|
103
|
+
BSD 3-Clause; see [LICENSE](LICENSE).
|
ades_sign-0.4.0/SPEC.md
ADDED
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
# X-ADES-SIG: signatures embedded in ADES PSV files
|
|
2
|
+
|
|
3
|
+
A signed ADES PSV file carries its signatures in its own header, as ordinary ADES comment lines: readers that do
|
|
4
|
+
not know them see comments, and the file stays valid ADES. Anyone with the signers' public keys can check, offline,
|
|
5
|
+
that the file is byte for byte the one that was signed. This is version 1 of the format; `src/ades_sign/core.py`
|
|
6
|
+
implements this statement.
|
|
7
|
+
|
|
8
|
+
## Signed message
|
|
9
|
+
|
|
10
|
+
A line is everything up to and including a line feed (`\n`); a carriage return (`\r`) is an ordinary byte of its
|
|
11
|
+
line. The signed message is the file's exact bytes, with every line that starts `! line X-ADES-SIG:` removed. Nothing
|
|
12
|
+
else is changed: there is no normalisation of line endings or white space. The file must end with a line feed and
|
|
13
|
+
contain no NUL byte.
|
|
14
|
+
|
|
15
|
+
Every signature in a file signs the **digest**: the 64 bytes of the SHA-512 of the signed message, bound to
|
|
16
|
+
X-ADES-SIG by the context `X-ADES-SIG:v1` (see Algorithms). Signing a digest of fixed size lets a signer that takes
|
|
17
|
+
only short messages, such as a hardware key store, sign files of any size.
|
|
18
|
+
|
|
19
|
+
Anything a signer wants signed (who signed, when, with what settings) goes in ordinary comment lines before
|
|
20
|
+
signing, at the end of the first `# comment` block, so they are just before the signature block. They are part of the
|
|
21
|
+
signed message like any other line, and a verifier shows the lines of the first `# comment` block before the
|
|
22
|
+
signature block.
|
|
23
|
+
|
|
24
|
+
## Algorithms
|
|
25
|
+
|
|
26
|
+
The context `X-ADES-SIG:v1` (13 ASCII bytes) ties every signature to X-ADES-SIG, so that a signature made by the
|
|
27
|
+
same key for any other purpose is not an X-ADES-SIG signature.
|
|
28
|
+
|
|
29
|
+
- `ed25519`: Ed25519 (RFC 8032; plain Ed25519, not Ed25519ph) over `"X-ADES-SIG:v1" || 0x00 || digest` (78 bytes).
|
|
30
|
+
64 bytes.
|
|
31
|
+
- `ml-dsa-65`: ML-DSA-65 (FIPS 204; pure ML-DSA, not HashML-DSA) over the digest, with the context `X-ADES-SIG:v1`.
|
|
32
|
+
3,309 bytes.
|
|
33
|
+
- `mldsa65-ed25519-sha512`: the composite (hybrid) MLDSA65-Ed25519-SHA512 of RFC 10073, with the application context
|
|
34
|
+
`X-ADES-SIG:v1`, valid only if both of its parts verify. As that RFC states, both parts sign
|
|
35
|
+
|
|
36
|
+
```
|
|
37
|
+
M' = "CompositeAlgorithmSignatures2025" || "COMPSIG-MLDSA65-Ed25519-SHA512" || 0x0d || "X-ADES-SIG:v1" || digest
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
(0x0d is the length of the context), ML-DSA-65 with the context `COMPSIG-MLDSA65-Ed25519-SHA512` and Ed25519
|
|
41
|
+
plainly. The signature is the ML-DSA-65 signature followed by the Ed25519 one, 3,373 bytes. Its parts sign `M'`,
|
|
42
|
+
never the digest itself, so neither is a signature of the file by a key of its own. In the RFC's terms the
|
|
43
|
+
composite signs the signed message, with the context `X-ADES-SIG:v1`: an implementation of RFC 10073 checks it
|
|
44
|
+
given the signed message (it computes the digest itself), or given the digest through a prehash interface.
|
|
45
|
+
|
|
46
|
+
The prehashed variants Ed25519ph and HashML-DSA are not used: RFC 8032 advises against Ed25519ph, and RFC 10073
|
|
47
|
+
does its own hashing with pure ML-DSA, as X-ADES-SIG does.
|
|
48
|
+
|
|
49
|
+
## Layout
|
|
50
|
+
|
|
51
|
+
The signature lines form one block at the end of the first `# comment` block in the file. (A file of several
|
|
52
|
+
ADES blocks is signed whole, all its headers and data included; its signature block is in the first `# comment`
|
|
53
|
+
block.)
|
|
54
|
+
|
|
55
|
+
```
|
|
56
|
+
# version=2022
|
|
57
|
+
...
|
|
58
|
+
# comment
|
|
59
|
+
! line Signed by the Example Survey's pipeline, release 3.2
|
|
60
|
+
! line X-ADES-SIG:v1
|
|
61
|
+
! line X-ADES-SIG:1:key:<fingerprint>
|
|
62
|
+
! line X-ADES-SIG:1:alg:ed25519
|
|
63
|
+
! line X-ADES-SIG:1:001:<base64>
|
|
64
|
+
! line X-ADES-SIG:1:002:<base64>
|
|
65
|
+
! line X-ADES-SIG:2:key:<fingerprint>
|
|
66
|
+
! line X-ADES-SIG:2:alg:mldsa65-ed25519-sha512
|
|
67
|
+
! line X-ADES-SIG:2:001:<base64>
|
|
68
|
+
...
|
|
69
|
+
! line X-ADES-SIG:2:060:<base64>
|
|
70
|
+
# observers
|
|
71
|
+
...
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
- `X-ADES-SIG:v1` opens the block, once. The first `# comment` block is the first line that is `#` and `comment`
|
|
75
|
+
separated by spaces or tabs, and the `!` lines after it. A file to be signed must have one.
|
|
76
|
+
- `<n>` numbers a signature: a positive integer of at most four digits, unique in the file. It is not signed, so
|
|
77
|
+
signatures can be renumbered, removed, added or merged from other copies of the file freely.
|
|
78
|
+
- Each signature is a `key` line, an `alg` line, then its signature lines. A signature's lines are contiguous.
|
|
79
|
+
- `<fingerprint>`: 64 hex digits, the SHA-256 of the key's DER SubjectPublicKeyInfo. For a composite key, that of
|
|
80
|
+
RFC 10073 (algorithm `1.3.6.1.5.5.7.6.48`, no parameters; the ML-DSA-65 public key followed by the Ed25519 one).
|
|
81
|
+
- `alg` names the signature's algorithm, so that people reading the file can see it. It is not signed, and it must
|
|
82
|
+
name the algorithm of the signature's key in the key list: a signature whose `alg` line names another is
|
|
83
|
+
invalid.
|
|
84
|
+
- The signature, in canonical standard base64 (RFC 4648, with padding, and unused bits zero), in chunks of 76
|
|
85
|
+
characters (as in MIME, RFC 2045) but the last, numbered `001`, `002`, ... in order with no gaps.
|
|
86
|
+
- Each line of the block is exactly as shown, ending in a bare line feed: no carriage return, no other white space.
|
|
87
|
+
- Every `X-ADES-SIG` line must be in this block. A line elsewhere, a broken block, a file not ending with a line
|
|
88
|
+
feed, or a NUL byte anywhere makes the file malformed, and invalid.
|
|
89
|
+
|
|
90
|
+
Every value is within the ADES limit of 100 characters (`X-ADES-SIG:9999:001:` and 76 characters is 96). An Ed25519
|
|
91
|
+
signature takes 2 lines, an ML-DSA-65 signature 59, a composite 60 (plus the `key` and `alg` lines).
|
|
92
|
+
|
|
93
|
+
## Keys
|
|
94
|
+
|
|
95
|
+
Keys are dedicated to X-ADES-SIG and sign nothing else. A verifier trusts the keys of a **key list**, a JSON file:
|
|
96
|
+
|
|
97
|
+
```json
|
|
98
|
+
{"keys": [{"name": "example-2026a", "role": "example-survey", "alg": "mldsa65-ed25519-sha512",
|
|
99
|
+
"public": "-----BEGIN PUBLIC KEY-----\n...\n-----END PUBLIC KEY-----\n",
|
|
100
|
+
"expires": "2028-12-05"}]}
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
Each entry records exactly: its `name`, `role` (who signs with it, as the policy names them), `alg`, `public` key
|
|
104
|
+
(its SubjectPublicKeyInfo, in PEM) and the date it `expires` (fixed when the key is made); and, once it is retired,
|
|
105
|
+
the date it was `retired` (absent or null until then). Dates are ISO 8601 (`2028-12-05`), in UTC.
|
|
106
|
+
|
|
107
|
+
A verifier refuses a key list with an entry that is not so, whose algorithm is not that of its public key, a name
|
|
108
|
+
that appears twice, or a public key that appears twice (as a key, or as a part of a composite key). So the parts of
|
|
109
|
+
a composite key are never keys of their own, each fingerprint names one entry, and each name one key.
|
|
110
|
+
|
|
111
|
+
A key is **current** until the day it expires or is retired, whichever comes first: a key list, however old, stops
|
|
112
|
+
trusting a key when it expires.
|
|
113
|
+
|
|
114
|
+
A private key is kept in a PEM file: a PKCS#8 key, or two (ML-DSA-65 first) for a composite. It is encrypted with
|
|
115
|
+
a passphrase (PBES2: scrypt with N = 2^17, r = 8, p = 1, and AES-256-CBC), unless made without one.
|
|
116
|
+
|
|
117
|
+
## Verification
|
|
118
|
+
|
|
119
|
+
1. If the file is malformed, it is **invalid**.
|
|
120
|
+
2. Each signature is checked on its own. It is valid if its fingerprint is in the key list, its `alg` line names
|
|
121
|
+
that key's algorithm, and it verifies with the list's public key and algorithm. The algorithm used is always the
|
|
122
|
+
list's: the `alg` line is only checked against it.
|
|
123
|
+
3. A **policy** names the signatures required: at least one, each by a current key of a given role (or of any) with
|
|
124
|
+
one of the algorithms accepted (or any). The default requires one: a valid signature by any current key of the
|
|
125
|
+
list.
|
|
126
|
+
4. The file is **valid** if and only if every requirement is met, each by a signature of its own, and no two by
|
|
127
|
+
the same key.
|
|
128
|
+
5. Every other signature (invalid, by an unknown, expired or retired key, or not required) is reported, and changes
|
|
129
|
+
nothing.
|
|
130
|
+
|
|
131
|
+
So stripping a required signature, changing any byte of the signed message, changing a required signature's `alg`
|
|
132
|
+
line or its base64, or removing half of a composite makes the file invalid; adding, removing or renumbering any
|
|
133
|
+
other signature does not change the result.
|
|
134
|
+
|
|
135
|
+
A policy is a JSON object whose only field is `require`, a list of requirements; each has an optional `role` and
|
|
136
|
+
an optional `algs` (a list of algorithms), and nothing else:
|
|
137
|
+
|
|
138
|
+
```json
|
|
139
|
+
{"require": [{"role": "example-survey", "algs": ["ed25519", "mldsa65-ed25519-sha512", "ml-dsa-65"]}]}
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
A verifier refuses a policy that is not so, or that requires nothing (which would make any file valid).
|
|
143
|
+
|
|
144
|
+
A verifier shows any text it takes from a file with its control characters escaped (`\x1b`), so a file cannot
|
|
145
|
+
rewrite what it prints.
|
|
146
|
+
|
|
147
|
+
## Checking by hand
|
|
148
|
+
|
|
149
|
+
For signature 1, an Ed25519 key whose public key is in `ed.pem` (from the key list):
|
|
150
|
+
|
|
151
|
+
```sh
|
|
152
|
+
LC_ALL=C grep -av '^! line X-ADES-SIG:' file.psv | openssl dgst -sha512 -binary > digest
|
|
153
|
+
{ printf 'X-ADES-SIG:v1\000'; cat digest; } > m
|
|
154
|
+
LC_ALL=C grep -a '^! line X-ADES-SIG:1:[0-9]' file.psv | cut -d: -f4 | base64 -d > sig
|
|
155
|
+
openssl pkeyutl -verify -pubin -inkey ed.pem -rawin -in m -sigfile sig
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
The colon after `1` keeps signature 1 from matching signature 10, and `[0-9]` picks its signature lines.
|
|
159
|
+
`LC_ALL=C` and `-a` keep grep from treating the file as binary, which would make it stop reading (at a NUL byte,
|
|
160
|
+
say) and drop the rest of the file. This checks the signature only, not the format (a NUL byte, the block's place,
|
|
161
|
+
the final line feed) nor whether the key is current: `ades-sign verify` does all of it. An ML-DSA-65 signature is
|
|
162
|
+
checked over `digest`, with the context `X-ADES-SIG:v1`, with OpenSSL 3.5 or later.
|
|
163
|
+
|
|
164
|
+
For the Ed25519 part of a composite signature 1, whose public key is in `composite.pem`, after the first line
|
|
165
|
+
above (the 12 bytes of `printf` before the key make it an Ed25519 public key):
|
|
166
|
+
|
|
167
|
+
```sh
|
|
168
|
+
{ printf 'CompositeAlgorithmSignatures2025COMPSIG-MLDSA65-Ed25519-SHA512\015X-ADES-SIG:v1'; cat digest; } > m
|
|
169
|
+
LC_ALL=C grep -a '^! line X-ADES-SIG:1:[0-9]' file.psv | cut -d: -f4 | base64 -d | tail -c 64 > sig
|
|
170
|
+
{ printf '\060\052\060\005\006\003\053\145\160\003\041\000'; sed '1d;$d' composite.pem | base64 -d | tail -c 32; } > ed.der
|
|
171
|
+
openssl pkeyutl -verify -pubin -keyform DER -inkey ed.der -rawin -in m -sigfile sig
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
Its ML-DSA-65 part (the first 3,309 bytes) is checked over `m` with the context `COMPSIG-MLDSA65-Ed25519-SHA512`,
|
|
175
|
+
with OpenSSL 3.5 or later.
|
|
176
|
+
|
|
177
|
+
## What a valid signature means
|
|
178
|
+
|
|
179
|
+
That the signed message is the one a current key of the list signed (through its digest), and no more:
|
|
180
|
+
|
|
181
|
+
- **No freshness.** A signed file stays valid for as long as its key is current: it can be sent again, any time.
|
|
182
|
+
A signer that wants a time signed writes it in a comment line before signing.
|
|
183
|
+
- **Retiring a key retires its signatures.** Every file a retired or expired key signed becomes invalid, whenever
|
|
184
|
+
it was signed. That is the point for a compromised key; for a routine change of key, re-sign any file still in
|
|
185
|
+
transit.
|
|
186
|
+
- **The key list is trusted as given.** An old copy of a key list brings back the keys it lists, retired since or
|
|
187
|
+
not, until they expire. Verify with a current list.
|
|
188
|
+
- **Post-quantum protection** needs a post-quantum key (`mldsa65-ed25519-sha512` or `ml-dsa-65`), and starts only
|
|
189
|
+
once no current key of the required role is Ed25519 alone and the policy no longer accepts `ed25519`.
|
|
190
|
+
- **The bytes are not unique.** The signature lines of a required signature are fixed by its signature, but its
|
|
191
|
+
number is not; other signatures can be added, removed or renumbered, and any signature by an unknown key carries
|
|
192
|
+
whatever base64 it likes, unsigned. Re-signing changes the bytes too (ML-DSA signatures are randomised). To name a
|
|
193
|
+
signed file, use its digest, which `ades-sign verify` prints, not a hash of the file.
|
|
194
|
+
|
|
195
|
+
## Consequences
|
|
196
|
+
|
|
197
|
+
- A signed file must travel as unchanged bytes: a conversion of line endings (CRLF), re-padding or re-wrapping
|
|
198
|
+
breaks every signature. Send it as an attachment, not pasted.
|
|
199
|
+
- A program that rewrites a signed file should remove its signature block: the file it writes is a new one.
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling", "hatch-vcs"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "ades-sign"
|
|
7
|
+
dynamic = ["version"]
|
|
8
|
+
description = "Signatures embedded in ADES PSV files (X-ADES-SIG): Ed25519, ML-DSA-65 and RFC 10073's composite"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.11"
|
|
11
|
+
license = "BSD-3-Clause"
|
|
12
|
+
license-files = ["LICENSE"]
|
|
13
|
+
authors = [{name = "Mario Juric"}]
|
|
14
|
+
keywords = ["ADES", "astrometry", "minor planets", "signatures", "Ed25519", "ML-DSA", "post-quantum"]
|
|
15
|
+
classifiers = [
|
|
16
|
+
"Development Status :: 4 - Beta",
|
|
17
|
+
"Environment :: Console",
|
|
18
|
+
"Intended Audience :: Science/Research",
|
|
19
|
+
"Operating System :: OS Independent",
|
|
20
|
+
"Programming Language :: Python :: 3",
|
|
21
|
+
"Programming Language :: Python :: 3.11",
|
|
22
|
+
"Programming Language :: Python :: 3.12",
|
|
23
|
+
"Programming Language :: Python :: 3.13",
|
|
24
|
+
"Programming Language :: Python :: 3.14",
|
|
25
|
+
"Topic :: Scientific/Engineering :: Astronomy",
|
|
26
|
+
"Topic :: Security :: Cryptography",
|
|
27
|
+
]
|
|
28
|
+
dependencies = ["cryptography>=47"]
|
|
29
|
+
|
|
30
|
+
[project.optional-dependencies]
|
|
31
|
+
test = ["pytest"]
|
|
32
|
+
|
|
33
|
+
[project.scripts]
|
|
34
|
+
ades-sign = "ades_sign.cli:main"
|
|
35
|
+
|
|
36
|
+
[project.urls]
|
|
37
|
+
Source = "https://github.com/juriclab/ades-sign"
|
|
38
|
+
Specification = "https://github.com/juriclab/ades-sign/blob/main/SPEC.md"
|
|
39
|
+
Issues = "https://github.com/juriclab/ades-sign/issues"
|
|
40
|
+
|
|
41
|
+
# The version is the latest tag vX.Y.Z; between tags, the next version as a development release
|
|
42
|
+
# (X.Y.(Z+1).devN+g<commit>). The build writes it to src/ades_sign/version.py, which is not in git.
|
|
43
|
+
[tool.hatch.version]
|
|
44
|
+
source = "vcs"
|
|
45
|
+
|
|
46
|
+
[tool.hatch.build.hooks.vcs]
|
|
47
|
+
version-file = "src/ades_sign/version.py"
|
|
48
|
+
|
|
49
|
+
[tool.hatch.build.targets.sdist]
|
|
50
|
+
include = ["src", "tests", "SPEC.md", "README.md", "LICENSE"]
|
|
51
|
+
|
|
52
|
+
[tool.hatch.build.targets.wheel]
|
|
53
|
+
packages = ["src/ades_sign"]
|
|
54
|
+
|
|
55
|
+
[tool.pytest.ini_options]
|
|
56
|
+
testpaths = ["tests"]
|
|
57
|
+
|
|
58
|
+
[tool.ruff]
|
|
59
|
+
line-length = 120
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"""ades-sign: X-ADES-SIG signatures embedded in ADES PSV files (SPEC.md).
|
|
2
|
+
|
|
3
|
+
The library: sign(data, [load_private(path, passphrase)]) adds signatures to a file's bytes;
|
|
4
|
+
verify(data, load_keylist(path), policy) checks them and returns a Verification.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from .core import (
|
|
8
|
+
ALGORITHMS,
|
|
9
|
+
COMPOSITE,
|
|
10
|
+
DEFAULT_POLICY,
|
|
11
|
+
PASSPHRASE,
|
|
12
|
+
Malformed,
|
|
13
|
+
PrivateKey,
|
|
14
|
+
Verification,
|
|
15
|
+
current,
|
|
16
|
+
digest,
|
|
17
|
+
key_entry,
|
|
18
|
+
load_keylist,
|
|
19
|
+
load_policy,
|
|
20
|
+
load_private,
|
|
21
|
+
new_key,
|
|
22
|
+
opens_comment,
|
|
23
|
+
printable,
|
|
24
|
+
sign,
|
|
25
|
+
verify,
|
|
26
|
+
)
|
|
27
|
+
from .version import __version__
|
|
28
|
+
|
|
29
|
+
__all__ = [
|
|
30
|
+
"ALGORITHMS",
|
|
31
|
+
"COMPOSITE",
|
|
32
|
+
"DEFAULT_POLICY",
|
|
33
|
+
"PASSPHRASE",
|
|
34
|
+
"Malformed",
|
|
35
|
+
"PrivateKey",
|
|
36
|
+
"Verification",
|
|
37
|
+
"__version__",
|
|
38
|
+
"current",
|
|
39
|
+
"digest",
|
|
40
|
+
"key_entry",
|
|
41
|
+
"load_keylist",
|
|
42
|
+
"load_policy",
|
|
43
|
+
"load_private",
|
|
44
|
+
"new_key",
|
|
45
|
+
"opens_comment",
|
|
46
|
+
"printable",
|
|
47
|
+
"sign",
|
|
48
|
+
"verify",
|
|
49
|
+
]
|