sdcreceipt 4.0.0__py3-none-any.whl
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.
Potentially problematic release.
This version of sdcreceipt might be problematic. Click here for more details.
- sdcreceipt/__init__.py +22 -0
- sdcreceipt/canonical.py +26 -0
- sdcreceipt/cli.py +206 -0
- sdcreceipt/party.py +223 -0
- sdcreceipt/verify.py +311 -0
- sdcreceipt-4.0.0.dist-info/METADATA +211 -0
- sdcreceipt-4.0.0.dist-info/RECORD +11 -0
- sdcreceipt-4.0.0.dist-info/WHEEL +5 -0
- sdcreceipt-4.0.0.dist-info/entry_points.txt +2 -0
- sdcreceipt-4.0.0.dist-info/licenses/LICENSE +201 -0
- sdcreceipt-4.0.0.dist-info/top_level.txt +1 -0
sdcreceipt/__init__.py
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Copyright (c) 2025, Axius SDC, Inc.
|
|
3
|
+
# Licensed under the Apache License, Version 2.0.
|
|
4
|
+
#
|
|
5
|
+
"""
|
|
6
|
+
sdcreceipt - verify and settle VSL Settlement Receipts.
|
|
7
|
+
|
|
8
|
+
Three verbs and no more: `verify`, `init`, `trigger`. It is a client, not a
|
|
9
|
+
product; the value is in it being small enough to read.
|
|
10
|
+
|
|
11
|
+
`verify` requires no network, no account, and nothing from the issuer.
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
#: SDC ecosystem versioning: MAJOR tracks the reference model, so a 4.x.x
|
|
15
|
+
#: release targets SDC4. It starts at 4 rather than 0 for that reason, not
|
|
16
|
+
#: because there were three earlier versions. MINOR is features, PATCH is
|
|
17
|
+
#: fixes. An SDC5 reference model would make this 5.x.x.
|
|
18
|
+
__version__ = "4.0.0"
|
|
19
|
+
|
|
20
|
+
from sdcreceipt.verify import Result, verify # noqa: F401
|
|
21
|
+
|
|
22
|
+
__all__ = ["verify", "Result", "__version__"]
|
sdcreceipt/canonical.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Copyright (c) 2025, Axius SDC, Inc.
|
|
3
|
+
# Licensed under the Apache License, Version 2.0.
|
|
4
|
+
#
|
|
5
|
+
"""
|
|
6
|
+
RFC 8785 canonicalization.
|
|
7
|
+
|
|
8
|
+
★ Deliberately a thin re-export rather than an implementation.
|
|
9
|
+
|
|
10
|
+
A second implementation of a canonicalization scheme can disagree with the
|
|
11
|
+
first, and the disagreement is silent: the bytes differ, so the hash differs,
|
|
12
|
+
and the artifact reads as tampered with rather than misencoded. That converts
|
|
13
|
+
a structural guarantee into a testing problem defended forever.
|
|
14
|
+
|
|
15
|
+
`sdcgovernance` is Apache-2.0, on PyPI, and differential-tested against a real
|
|
16
|
+
ECMAScript engine, which matters because RFC 8785 defines number formatting in
|
|
17
|
+
terms of ECMAScript `Number::toString`. Reusing it means this tool and the
|
|
18
|
+
issuer cannot disagree about bytes.
|
|
19
|
+
|
|
20
|
+
This is a library dependency, not a service dependency. Nothing here calls
|
|
21
|
+
out to anything at runtime.
|
|
22
|
+
"""
|
|
23
|
+
|
|
24
|
+
from sdcgovernance.jcs import canonicalize, canonicalize_bytes # noqa: F401
|
|
25
|
+
|
|
26
|
+
__all__ = ["canonicalize", "canonicalize_bytes"]
|
sdcreceipt/cli.py
ADDED
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Copyright (c) 2025, Axius SDC, Inc.
|
|
3
|
+
# Licensed under the Apache License, Version 2.0.
|
|
4
|
+
#
|
|
5
|
+
"""
|
|
6
|
+
Command line interface.
|
|
7
|
+
|
|
8
|
+
sdcreceipt verify receipt.json --keys keys.json
|
|
9
|
+
sdcreceipt init --key-id https://vendor.example/.well-known/vsl-key.json
|
|
10
|
+
sdcreceipt trigger receipt.json --key party.pem --key-id <id>
|
|
11
|
+
|
|
12
|
+
`verify` exits 0 only if every check passed, so it composes in a shell without
|
|
13
|
+
anyone having to parse the output.
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
from __future__ import annotations
|
|
17
|
+
|
|
18
|
+
import argparse
|
|
19
|
+
import json
|
|
20
|
+
import sys
|
|
21
|
+
from pathlib import Path
|
|
22
|
+
|
|
23
|
+
from sdcreceipt import __version__
|
|
24
|
+
from sdcreceipt.party import (
|
|
25
|
+
PartyError,
|
|
26
|
+
generate_key,
|
|
27
|
+
key_document,
|
|
28
|
+
load_key_set_file,
|
|
29
|
+
load_private_key,
|
|
30
|
+
publication_path,
|
|
31
|
+
sign_trigger,
|
|
32
|
+
write_private_key,
|
|
33
|
+
)
|
|
34
|
+
from sdcreceipt.verify import verify
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def _load_json(path: Path, what: str) -> dict:
|
|
38
|
+
try:
|
|
39
|
+
return json.loads(path.read_text())
|
|
40
|
+
except FileNotFoundError:
|
|
41
|
+
raise SystemExit(f"error: no {what} at {path}")
|
|
42
|
+
except json.JSONDecodeError as exc:
|
|
43
|
+
raise SystemExit(f"error: {path} is not valid JSON: {exc}")
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def cmd_verify(args) -> int:
|
|
47
|
+
receipt = _load_json(Path(args.receipt), "receipt")
|
|
48
|
+
|
|
49
|
+
issuer_keys = {}
|
|
50
|
+
party_keys = None
|
|
51
|
+
if args.keys:
|
|
52
|
+
try:
|
|
53
|
+
keyset = load_key_set_file(Path(args.keys))
|
|
54
|
+
except PartyError as exc:
|
|
55
|
+
raise SystemExit(f"error: {exc}")
|
|
56
|
+
# One file may carry both; the Receipt says which id is which.
|
|
57
|
+
issuer_ids = {s.get("key_id") for s in receipt.get("signatures", [])}
|
|
58
|
+
issuer_keys = {k: v for k, v in keyset.items() if k in issuer_ids}
|
|
59
|
+
party_keys = {k: v for k, v in keyset.items() if k not in issuer_ids} or None
|
|
60
|
+
|
|
61
|
+
schema = _load_json(Path(args.schema), "schema") if args.schema else None
|
|
62
|
+
governance = (
|
|
63
|
+
_load_json(Path(args.governance), "governance receipt")
|
|
64
|
+
if args.governance
|
|
65
|
+
else None
|
|
66
|
+
)
|
|
67
|
+
payload = Path(args.payload).read_bytes() if args.payload else None
|
|
68
|
+
|
|
69
|
+
result = verify(
|
|
70
|
+
receipt,
|
|
71
|
+
issuer_keys=issuer_keys,
|
|
72
|
+
party_keys=party_keys,
|
|
73
|
+
schema=schema,
|
|
74
|
+
governance_receipt=governance,
|
|
75
|
+
payload=payload,
|
|
76
|
+
)
|
|
77
|
+
|
|
78
|
+
print(result)
|
|
79
|
+
if result.ok:
|
|
80
|
+
print("\nVERIFIED")
|
|
81
|
+
return 0
|
|
82
|
+
|
|
83
|
+
print(f"\nNOT VERIFIED - {len(result.failures)} check(s) failed")
|
|
84
|
+
if not args.keys:
|
|
85
|
+
print(
|
|
86
|
+
"\nNo --keys given, so no signature could be checked. Fetch the "
|
|
87
|
+
"issuer's published key set and pass it; never take a key from a "
|
|
88
|
+
"location inside the Receipt."
|
|
89
|
+
)
|
|
90
|
+
return 1
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
def cmd_init(args) -> int:
|
|
94
|
+
key_id = args.key_id
|
|
95
|
+
try:
|
|
96
|
+
publish_at = publication_path(key_id)
|
|
97
|
+
except PartyError as exc:
|
|
98
|
+
raise SystemExit(f"error: {exc}")
|
|
99
|
+
|
|
100
|
+
key = generate_key()
|
|
101
|
+
private_path = Path(args.out)
|
|
102
|
+
document_path = private_path.with_name(private_path.stem + "-key-document.json")
|
|
103
|
+
|
|
104
|
+
try:
|
|
105
|
+
write_private_key(key, private_path)
|
|
106
|
+
except PartyError as exc:
|
|
107
|
+
raise SystemExit(f"error: {exc}")
|
|
108
|
+
|
|
109
|
+
document_path.write_text(json.dumps(key_document(key, key_id), indent=2) + "\n")
|
|
110
|
+
|
|
111
|
+
print(f"private key {private_path} (mode 0600, keep it)")
|
|
112
|
+
print(f"key document {document_path}")
|
|
113
|
+
print()
|
|
114
|
+
print("Publish the key document so it is reachable, unauthenticated, at:")
|
|
115
|
+
print(f" {publish_at}")
|
|
116
|
+
print()
|
|
117
|
+
print(
|
|
118
|
+
"Until it is reachable there, a verifier cannot resolve your triggers.\n"
|
|
119
|
+
"Give the issuer this key_id when the settlement is created:\n"
|
|
120
|
+
f" {key_id}"
|
|
121
|
+
)
|
|
122
|
+
return 0
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
def cmd_trigger(args) -> int:
|
|
126
|
+
receipt = _load_json(Path(args.receipt), "receipt")
|
|
127
|
+
|
|
128
|
+
try:
|
|
129
|
+
key = load_private_key(Path(args.key))
|
|
130
|
+
trigger = sign_trigger(key, receipt, args.key_id)
|
|
131
|
+
except PartyError as exc:
|
|
132
|
+
raise SystemExit(f"error: {exc}")
|
|
133
|
+
|
|
134
|
+
body = json.dumps(trigger, indent=2)
|
|
135
|
+
|
|
136
|
+
if not args.submit:
|
|
137
|
+
# Default: print and stop. Signing is inert and pipeable; submitting
|
|
138
|
+
# is a side effect and should be asked for.
|
|
139
|
+
print(body)
|
|
140
|
+
print(
|
|
141
|
+
"\n# Not submitted. Send it with --submit <url>, or pipe this to "
|
|
142
|
+
"whatever you use.",
|
|
143
|
+
file=sys.stderr,
|
|
144
|
+
)
|
|
145
|
+
return 0
|
|
146
|
+
|
|
147
|
+
import urllib.error
|
|
148
|
+
import urllib.request
|
|
149
|
+
|
|
150
|
+
request = urllib.request.Request(
|
|
151
|
+
args.submit,
|
|
152
|
+
data=body.encode("utf-8"),
|
|
153
|
+
headers={"Content-Type": "application/json"},
|
|
154
|
+
method="POST",
|
|
155
|
+
)
|
|
156
|
+
try:
|
|
157
|
+
with urllib.request.urlopen(request, timeout=30) as response:
|
|
158
|
+
print(response.read().decode("utf-8"))
|
|
159
|
+
return 0
|
|
160
|
+
except urllib.error.HTTPError as exc:
|
|
161
|
+
print(f"error: {exc.code} from {args.submit}", file=sys.stderr)
|
|
162
|
+
print(exc.read().decode("utf-8", errors="replace"), file=sys.stderr)
|
|
163
|
+
return 1
|
|
164
|
+
except urllib.error.URLError as exc:
|
|
165
|
+
print(f"error: could not reach {args.submit}: {exc.reason}", file=sys.stderr)
|
|
166
|
+
return 1
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
def build_parser() -> argparse.ArgumentParser:
|
|
170
|
+
parser = argparse.ArgumentParser(
|
|
171
|
+
prog="sdcreceipt",
|
|
172
|
+
description="Verify and settle VSL Settlement Receipts.",
|
|
173
|
+
)
|
|
174
|
+
parser.add_argument("--version", action="version", version=f"sdcreceipt {__version__}")
|
|
175
|
+
sub = parser.add_subparsers(dest="command", required=True)
|
|
176
|
+
|
|
177
|
+
p = sub.add_parser("verify", help="verify a Receipt (no network, no account)")
|
|
178
|
+
p.add_argument("receipt")
|
|
179
|
+
p.add_argument("--keys", help="published key set, JSON")
|
|
180
|
+
p.add_argument("--schema", help="the published JSON Schema")
|
|
181
|
+
p.add_argument("--governance", help="the governance Receipt, if held")
|
|
182
|
+
p.add_argument("--payload", help="the payload, if held")
|
|
183
|
+
p.set_defaults(func=cmd_verify)
|
|
184
|
+
|
|
185
|
+
p = sub.add_parser("init", help="generate a keypair and the document to publish")
|
|
186
|
+
p.add_argument("--key-id", required=True, help="https:// URL or did:web: identifier")
|
|
187
|
+
p.add_argument("--out", default="vsl-party.pem", help="private key path")
|
|
188
|
+
p.set_defaults(func=cmd_init)
|
|
189
|
+
|
|
190
|
+
p = sub.add_parser("trigger", help="sign a trigger for a settlement")
|
|
191
|
+
p.add_argument("receipt")
|
|
192
|
+
p.add_argument("--key", required=True, help="your private key")
|
|
193
|
+
p.add_argument("--key-id", required=True, help="your key_id, as listed on the settlement")
|
|
194
|
+
p.add_argument("--submit", metavar="URL", help="POST it rather than printing it")
|
|
195
|
+
p.set_defaults(func=cmd_trigger)
|
|
196
|
+
|
|
197
|
+
return parser
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
def main(argv=None) -> int:
|
|
201
|
+
args = build_parser().parse_args(argv)
|
|
202
|
+
return args.func(args)
|
|
203
|
+
|
|
204
|
+
|
|
205
|
+
if __name__ == "__main__":
|
|
206
|
+
sys.exit(main())
|
sdcreceipt/party.py
ADDED
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Copyright (c) 2025, Axius SDC, Inc.
|
|
3
|
+
# Licensed under the Apache License, Version 2.0.
|
|
4
|
+
#
|
|
5
|
+
"""
|
|
6
|
+
The party side: hold a key, publish it, sign a trigger.
|
|
7
|
+
|
|
8
|
+
A settlement identifies each party by a ``key_id`` that **the party controls**,
|
|
9
|
+
either an ``https://`` URL or a ``did:web:`` identifier. That keeps
|
|
10
|
+
verification independent of the issuer, and it means the party has to publish
|
|
11
|
+
one JSON file. This module reduces that to a single command.
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
from __future__ import annotations
|
|
15
|
+
|
|
16
|
+
import json
|
|
17
|
+
import os
|
|
18
|
+
import stat
|
|
19
|
+
from pathlib import Path
|
|
20
|
+
from typing import Any
|
|
21
|
+
|
|
22
|
+
from cryptography.hazmat.primitives import hashes, serialization
|
|
23
|
+
from cryptography.hazmat.primitives.asymmetric import ec, utils
|
|
24
|
+
|
|
25
|
+
from sdcreceipt.verify import trigger_message
|
|
26
|
+
|
|
27
|
+
#: Owner read/write only. A private key readable by other accounts on a shared
|
|
28
|
+
#: machine is a private key you no longer control.
|
|
29
|
+
PRIVATE_KEY_MODE = stat.S_IRUSR | stat.S_IWUSR
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
class PartyError(Exception):
|
|
33
|
+
"""Raised when key material or a settlement is not usable."""
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def generate_key() -> ec.EllipticCurvePrivateKey:
|
|
37
|
+
"""A P-256 key, which is what ES256 means."""
|
|
38
|
+
return ec.generate_private_key(ec.SECP256R1())
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def private_key_pem(key: ec.EllipticCurvePrivateKey) -> bytes:
|
|
42
|
+
"""
|
|
43
|
+
Serialize a private key, unencrypted.
|
|
44
|
+
|
|
45
|
+
Unencrypted is a deliberate, narrow choice: a passphrase this tool prompts
|
|
46
|
+
for would be typed into scripts and CI, which is worse than a file with
|
|
47
|
+
correct permissions and an honest warning. Use a KMS or an HSM if the key
|
|
48
|
+
matters more than that, and this tool will sign with whatever key you
|
|
49
|
+
hand it.
|
|
50
|
+
"""
|
|
51
|
+
return key.private_bytes(
|
|
52
|
+
encoding=serialization.Encoding.PEM,
|
|
53
|
+
format=serialization.PrivateFormat.PKCS8,
|
|
54
|
+
encryption_algorithm=serialization.NoEncryption(),
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def public_key_pem(key) -> str:
|
|
59
|
+
public = key.public_key() if hasattr(key, "public_key") else key
|
|
60
|
+
return public.public_bytes(
|
|
61
|
+
encoding=serialization.Encoding.PEM,
|
|
62
|
+
format=serialization.PublicFormat.SubjectPublicKeyInfo,
|
|
63
|
+
).decode("ascii")
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def write_private_key(key: ec.EllipticCurvePrivateKey, path: Path) -> Path:
|
|
67
|
+
"""Write a private key with owner-only permissions, refusing to clobber."""
|
|
68
|
+
if path.exists():
|
|
69
|
+
raise PartyError(
|
|
70
|
+
f"{path} already exists. Refusing to overwrite a private key: if "
|
|
71
|
+
"it is in use, replacing it invalidates every signature made with "
|
|
72
|
+
"it. Move it aside deliberately if you mean to rotate."
|
|
73
|
+
)
|
|
74
|
+
path.write_bytes(private_key_pem(key))
|
|
75
|
+
os.chmod(path, PRIVATE_KEY_MODE)
|
|
76
|
+
return path
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
def load_private_key(path: Path) -> ec.EllipticCurvePrivateKey:
|
|
80
|
+
"""Load a P-256 private key, warning if the file is world-readable."""
|
|
81
|
+
try:
|
|
82
|
+
key = serialization.load_pem_private_key(path.read_bytes(), password=None)
|
|
83
|
+
except Exception as exc:
|
|
84
|
+
raise PartyError(f"Could not read a private key from {path}: {exc}") from exc
|
|
85
|
+
|
|
86
|
+
if not isinstance(key, ec.EllipticCurvePrivateKey) or not isinstance(
|
|
87
|
+
key.curve, ec.SECP256R1
|
|
88
|
+
):
|
|
89
|
+
raise PartyError(
|
|
90
|
+
f"{path} is not an ECDSA P-256 key, which is the only curve VSL "
|
|
91
|
+
"signatures use (alg ES256)."
|
|
92
|
+
)
|
|
93
|
+
return key
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
def key_document(key, key_id: str) -> dict[str, Any]:
|
|
97
|
+
"""
|
|
98
|
+
The document a party publishes at their ``key_id``.
|
|
99
|
+
|
|
100
|
+
Shaped like the issuer's published key set so one verifier reads both.
|
|
101
|
+
"""
|
|
102
|
+
return {
|
|
103
|
+
"issuer": key_id,
|
|
104
|
+
"keys": [
|
|
105
|
+
{
|
|
106
|
+
"key_id": key_id,
|
|
107
|
+
"algorithm": "EC_SIGN_P256_SHA256",
|
|
108
|
+
"alg": "ES256",
|
|
109
|
+
"public_key_pem": public_key_pem(key),
|
|
110
|
+
"status": "active",
|
|
111
|
+
}
|
|
112
|
+
],
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
def publication_path(key_id: str) -> str:
|
|
117
|
+
"""
|
|
118
|
+
Where the key document has to be reachable for `key_id` to resolve.
|
|
119
|
+
|
|
120
|
+
Returned so `init` can tell the operator exactly what to publish, rather
|
|
121
|
+
than leaving them to infer it from a specification.
|
|
122
|
+
"""
|
|
123
|
+
if key_id.startswith("https://"):
|
|
124
|
+
return key_id
|
|
125
|
+
if key_id.startswith("did:web:"):
|
|
126
|
+
remainder = key_id[len("did:web:"):]
|
|
127
|
+
segments = remainder.split(":")
|
|
128
|
+
domain = segments[0].replace("%3A", ":")
|
|
129
|
+
if len(segments) == 1:
|
|
130
|
+
return f"https://{domain}/.well-known/did.json"
|
|
131
|
+
return f"https://{domain}/{'/'.join(segments[1:])}/did.json"
|
|
132
|
+
raise PartyError(
|
|
133
|
+
f"Unsupported key_id {key_id!r}. It must be an https URL or a did:web "
|
|
134
|
+
"identifier, so that you control it and verification does not route "
|
|
135
|
+
"through the issuer."
|
|
136
|
+
)
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
def sign_trigger(
|
|
140
|
+
key: ec.EllipticCurvePrivateKey, receipt: dict[str, Any], key_id: str
|
|
141
|
+
) -> dict[str, Any]:
|
|
142
|
+
"""
|
|
143
|
+
Produce a trigger for a Receipt.
|
|
144
|
+
|
|
145
|
+
Signs ``{condition_hash, receipt_id}``. Both are fixed before either party
|
|
146
|
+
signs, so the two can sign alone and in any order, while the signature
|
|
147
|
+
still cannot be replayed into another settlement.
|
|
148
|
+
|
|
149
|
+
Raises:
|
|
150
|
+
PartyError: If `key_id` is not a party to this settlement, which is
|
|
151
|
+
worth catching here rather than after a round trip.
|
|
152
|
+
"""
|
|
153
|
+
settlement = receipt.get("settlement")
|
|
154
|
+
if not settlement:
|
|
155
|
+
raise PartyError("This Receipt has no settlement block to trigger.")
|
|
156
|
+
|
|
157
|
+
parties = settlement.get("parties", [])
|
|
158
|
+
if key_id not in parties:
|
|
159
|
+
raise PartyError(
|
|
160
|
+
f"{key_id} is not a party to this settlement. Listed parties:\n "
|
|
161
|
+
+ "\n ".join(parties)
|
|
162
|
+
)
|
|
163
|
+
|
|
164
|
+
already = {t.get("key_id") for t in settlement.get("triggers", [])}
|
|
165
|
+
if key_id in already:
|
|
166
|
+
raise PartyError(
|
|
167
|
+
f"{key_id} has already triggered this settlement. A second "
|
|
168
|
+
"trigger adds no authorization."
|
|
169
|
+
)
|
|
170
|
+
|
|
171
|
+
message = trigger_message(receipt["receipt_id"], settlement["condition_hash"])
|
|
172
|
+
der = key.sign(message, ec.ECDSA(hashes.SHA256()))
|
|
173
|
+
r, s = utils.decode_dss_signature(der)
|
|
174
|
+
|
|
175
|
+
import base64
|
|
176
|
+
|
|
177
|
+
raw = r.to_bytes(32, "big") + s.to_bytes(32, "big")
|
|
178
|
+
signature = base64.urlsafe_b64encode(raw).decode("ascii").rstrip("=")
|
|
179
|
+
|
|
180
|
+
from datetime import datetime, timezone
|
|
181
|
+
|
|
182
|
+
return {
|
|
183
|
+
"receipt_id": receipt["receipt_id"],
|
|
184
|
+
"key_id": key_id,
|
|
185
|
+
"signature": signature,
|
|
186
|
+
"timestamp": datetime.now(timezone.utc).strftime("%Y-%m-%dT%H:%M:%SZ"),
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
def load_key_set(document: dict[str, Any]) -> dict[str, Any]:
|
|
191
|
+
"""
|
|
192
|
+
Turn a published key document into ``{key_id: public_key}``.
|
|
193
|
+
|
|
194
|
+
Accepts the issuer key-set shape and a did:web DID document, so a party
|
|
195
|
+
does not have to publish a second document just for this tool.
|
|
196
|
+
"""
|
|
197
|
+
keys: dict[str, Any] = {}
|
|
198
|
+
|
|
199
|
+
for entry in document.get("keys", []):
|
|
200
|
+
pem = entry.get("public_key_pem")
|
|
201
|
+
if pem and entry.get("key_id"):
|
|
202
|
+
keys[entry["key_id"]] = serialization.load_pem_public_key(
|
|
203
|
+
pem.encode("ascii")
|
|
204
|
+
)
|
|
205
|
+
|
|
206
|
+
for method in document.get("verificationMethod", []):
|
|
207
|
+
pem = method.get("publicKeyPem")
|
|
208
|
+
if pem and method.get("id"):
|
|
209
|
+
keys[method["id"]] = serialization.load_pem_public_key(pem.encode("ascii"))
|
|
210
|
+
|
|
211
|
+
if not keys:
|
|
212
|
+
raise PartyError(
|
|
213
|
+
"No usable keys in that document. Expected a `keys` array with "
|
|
214
|
+
"key_id and public_key_pem, or a DID document verificationMethod."
|
|
215
|
+
)
|
|
216
|
+
return keys
|
|
217
|
+
|
|
218
|
+
|
|
219
|
+
def load_key_set_file(path: Path) -> dict[str, Any]:
|
|
220
|
+
try:
|
|
221
|
+
return load_key_set(json.loads(path.read_text()))
|
|
222
|
+
except json.JSONDecodeError as exc:
|
|
223
|
+
raise PartyError(f"{path} is not valid JSON: {exc}") from exc
|
sdcreceipt/verify.py
ADDED
|
@@ -0,0 +1,311 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Copyright (c) 2025, Axius SDC, Inc.
|
|
3
|
+
# Licensed under the Apache License, Version 2.0.
|
|
4
|
+
#
|
|
5
|
+
"""
|
|
6
|
+
Verify a VSL Settlement Receipt.
|
|
7
|
+
|
|
8
|
+
Implements the published verification procedure. Nothing here contacts a
|
|
9
|
+
network or requires an account: keys are supplied by the caller, because the
|
|
10
|
+
procedure permits verifying from a key retained earlier. **If this module ever
|
|
11
|
+
needs to fetch something to do its job, the property it exists to demonstrate
|
|
12
|
+
has quietly stopped being true.**
|
|
13
|
+
|
|
14
|
+
★ Keys are parameters, and that is a security property rather than a
|
|
15
|
+
convenience. The caller decides which keys are acceptable *before* this reads
|
|
16
|
+
the Receipt, so a Receipt cannot nominate the key used to judge it. Resolving
|
|
17
|
+
a key from a location carried inside the artifact lets a forged document name
|
|
18
|
+
the forger's key and verify against it. Do not add an overload that fetches.
|
|
19
|
+
"""
|
|
20
|
+
|
|
21
|
+
from __future__ import annotations
|
|
22
|
+
|
|
23
|
+
import hashlib
|
|
24
|
+
from dataclasses import dataclass, field
|
|
25
|
+
from typing import Any
|
|
26
|
+
|
|
27
|
+
from sdcreceipt.canonical import canonicalize_bytes
|
|
28
|
+
|
|
29
|
+
#: Excluded from `receipt_hash`. Signatures sign the hash, so they cannot be
|
|
30
|
+
#: inside it, and triggers are appended after hashing so the parties can sign
|
|
31
|
+
#: independently and out of order.
|
|
32
|
+
HASH_EXCLUDED = ("receipt_hash", "signatures")
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
@dataclass
|
|
36
|
+
class Check:
|
|
37
|
+
name: str
|
|
38
|
+
passed: bool
|
|
39
|
+
detail: str = ""
|
|
40
|
+
|
|
41
|
+
def __str__(self) -> str:
|
|
42
|
+
return f"{'PASS' if self.passed else 'FAIL'} {self.name}: {self.detail}"
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
@dataclass
|
|
46
|
+
class Result:
|
|
47
|
+
"""
|
|
48
|
+
Every check that ran, not just the first failure.
|
|
49
|
+
|
|
50
|
+
Stopping early tells an implementer one thing per run, and hides the case
|
|
51
|
+
that matters most: a Receipt whose signature verifies but whose governance
|
|
52
|
+
binding does not.
|
|
53
|
+
"""
|
|
54
|
+
|
|
55
|
+
checks: list[Check] = field(default_factory=list)
|
|
56
|
+
|
|
57
|
+
def record(self, name: str, passed: bool, detail: str = "") -> None:
|
|
58
|
+
self.checks.append(Check(name, passed, detail))
|
|
59
|
+
|
|
60
|
+
@property
|
|
61
|
+
def ok(self) -> bool:
|
|
62
|
+
return bool(self.checks) and all(c.passed for c in self.checks)
|
|
63
|
+
|
|
64
|
+
@property
|
|
65
|
+
def failures(self) -> list[Check]:
|
|
66
|
+
return [c for c in self.checks if not c.passed]
|
|
67
|
+
|
|
68
|
+
def __str__(self) -> str:
|
|
69
|
+
return "\n".join(str(c) for c in self.checks)
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def canonical_content(receipt: dict[str, Any]) -> bytes:
|
|
73
|
+
"""The exact bytes `receipt_hash` commits to."""
|
|
74
|
+
content = {k: v for k, v in receipt.items() if k not in HASH_EXCLUDED}
|
|
75
|
+
if "settlement" in content:
|
|
76
|
+
content["settlement"] = {
|
|
77
|
+
k: v for k, v in receipt["settlement"].items() if k != "triggers"
|
|
78
|
+
}
|
|
79
|
+
return canonicalize_bytes(content)
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
def receipt_digest(receipt: dict[str, Any]) -> bytes:
|
|
83
|
+
"""
|
|
84
|
+
The 32 raw bytes a signature covers.
|
|
85
|
+
|
|
86
|
+
Identical to the value `receipt_hash` records in hex, so a verifier
|
|
87
|
+
computes it once and uses it for both checks.
|
|
88
|
+
"""
|
|
89
|
+
return hashlib.sha256(canonical_content(receipt)).digest()
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
def trigger_message(receipt_id: str, condition_hash: str) -> bytes:
|
|
93
|
+
"""
|
|
94
|
+
What a party signs to trigger a settlement.
|
|
95
|
+
|
|
96
|
+
`receipt_id` is included deliberately: a signature over `condition_hash`
|
|
97
|
+
alone is replayable into any other Receipt sharing that release condition,
|
|
98
|
+
and repeat trading relationships reuse conditions as a matter of course.
|
|
99
|
+
"""
|
|
100
|
+
return canonicalize_bytes(
|
|
101
|
+
{"condition_hash": condition_hash, "receipt_id": receipt_id}
|
|
102
|
+
)
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
def _b64url_to_raw(value: str) -> bytes:
|
|
106
|
+
import base64
|
|
107
|
+
|
|
108
|
+
raw = base64.urlsafe_b64decode(value + "=" * (-len(value) % 4))
|
|
109
|
+
if len(raw) != 64:
|
|
110
|
+
raise ValueError(
|
|
111
|
+
f"expected a 64-byte P1363 signature, got {len(raw)} bytes "
|
|
112
|
+
"(a DER signature is variable length and will not be 64)"
|
|
113
|
+
)
|
|
114
|
+
return raw
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
def _verify_ecdsa(public_key, message: bytes, signature: str, *, prehashed: bool) -> str:
|
|
118
|
+
"""Return "" on success, or the reason it failed."""
|
|
119
|
+
from cryptography.exceptions import InvalidSignature
|
|
120
|
+
from cryptography.hazmat.primitives import hashes
|
|
121
|
+
from cryptography.hazmat.primitives.asymmetric import ec, utils
|
|
122
|
+
|
|
123
|
+
try:
|
|
124
|
+
raw = _b64url_to_raw(signature)
|
|
125
|
+
except Exception as exc:
|
|
126
|
+
return f"malformed signature: {exc}"
|
|
127
|
+
|
|
128
|
+
algorithm = (
|
|
129
|
+
ec.ECDSA(utils.Prehashed(hashes.SHA256()))
|
|
130
|
+
if prehashed
|
|
131
|
+
else ec.ECDSA(hashes.SHA256())
|
|
132
|
+
)
|
|
133
|
+
try:
|
|
134
|
+
public_key.verify(
|
|
135
|
+
utils.encode_dss_signature(
|
|
136
|
+
int.from_bytes(raw[:32], "big"), int.from_bytes(raw[32:], "big")
|
|
137
|
+
),
|
|
138
|
+
message,
|
|
139
|
+
algorithm,
|
|
140
|
+
)
|
|
141
|
+
except InvalidSignature:
|
|
142
|
+
return "does not verify against the stated key"
|
|
143
|
+
return ""
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
def verify(
|
|
147
|
+
receipt: dict[str, Any],
|
|
148
|
+
*,
|
|
149
|
+
issuer_keys: dict[str, Any],
|
|
150
|
+
party_keys: dict[str, Any] | None = None,
|
|
151
|
+
schema: dict[str, Any] | None = None,
|
|
152
|
+
governance_receipt: dict[str, Any] | None = None,
|
|
153
|
+
payload: bytes | None = None,
|
|
154
|
+
) -> Result:
|
|
155
|
+
"""
|
|
156
|
+
Run the verification procedure over one Receipt.
|
|
157
|
+
|
|
158
|
+
Args:
|
|
159
|
+
receipt: The Receipt.
|
|
160
|
+
issuer_keys: ``{key_id: public_key}``. Held or fetched beforehand.
|
|
161
|
+
party_keys: ``{key_id: public_key}`` for triggers. Omit to skip that
|
|
162
|
+
step, which is legitimate when the keys are not held.
|
|
163
|
+
schema: The published JSON Schema, to check shape first.
|
|
164
|
+
governance_receipt: The governance Receipt, if held.
|
|
165
|
+
payload: The payload, if held.
|
|
166
|
+
"""
|
|
167
|
+
result = Result()
|
|
168
|
+
|
|
169
|
+
if schema is not None:
|
|
170
|
+
import jsonschema
|
|
171
|
+
|
|
172
|
+
errors = sorted(
|
|
173
|
+
jsonschema.Draft202012Validator(schema).iter_errors(receipt),
|
|
174
|
+
key=lambda e: list(e.absolute_path),
|
|
175
|
+
)
|
|
176
|
+
result.record(
|
|
177
|
+
"schema",
|
|
178
|
+
not errors,
|
|
179
|
+
"conforms" if not errors else f"{len(errors)} violation(s): {errors[0].message}",
|
|
180
|
+
)
|
|
181
|
+
if errors:
|
|
182
|
+
return result
|
|
183
|
+
|
|
184
|
+
recomputed = hashlib.sha256(canonical_content(receipt)).hexdigest()
|
|
185
|
+
matches = recomputed == receipt.get("receipt_hash")
|
|
186
|
+
result.record(
|
|
187
|
+
"receipt_hash",
|
|
188
|
+
matches,
|
|
189
|
+
"matches the canonical content"
|
|
190
|
+
if matches
|
|
191
|
+
else (
|
|
192
|
+
f"recorded {receipt.get('receipt_hash')} but content hashes to "
|
|
193
|
+
f"{recomputed}. If this is your only failure, suspect "
|
|
194
|
+
"canonicalization: RFC 8785 renders an integral float as 1, not 1.0"
|
|
195
|
+
),
|
|
196
|
+
)
|
|
197
|
+
|
|
198
|
+
digest = receipt_digest(receipt)
|
|
199
|
+
for signature in receipt.get("signatures", []):
|
|
200
|
+
key_id = signature.get("key_id", "")
|
|
201
|
+
label = f"signature[{key_id}]"
|
|
202
|
+
|
|
203
|
+
if signature.get("alg") != "ES256":
|
|
204
|
+
result.record(label, False, f"alg is {signature.get('alg')!r}, expected ES256")
|
|
205
|
+
continue
|
|
206
|
+
|
|
207
|
+
key = issuer_keys.get(key_id)
|
|
208
|
+
if key is None:
|
|
209
|
+
result.record(
|
|
210
|
+
label,
|
|
211
|
+
False,
|
|
212
|
+
f"no key held for {key_id!r}. Resolve it from the published "
|
|
213
|
+
"key set, never from a location inside the Receipt",
|
|
214
|
+
)
|
|
215
|
+
continue
|
|
216
|
+
|
|
217
|
+
reason = _verify_ecdsa(key, digest, signature.get("sig", ""), prehashed=True)
|
|
218
|
+
result.record(label, not reason, reason or "verifies over receipt_hash")
|
|
219
|
+
|
|
220
|
+
if not receipt.get("signatures"):
|
|
221
|
+
result.record("signatures", False, "the Receipt carries no signature")
|
|
222
|
+
|
|
223
|
+
settlement = receipt.get("settlement", {})
|
|
224
|
+
parties = settlement.get("parties", [])
|
|
225
|
+
triggers = settlement.get("triggers", [])
|
|
226
|
+
|
|
227
|
+
if party_keys is not None:
|
|
228
|
+
message = trigger_message(
|
|
229
|
+
receipt.get("receipt_id", ""), settlement.get("condition_hash", "")
|
|
230
|
+
)
|
|
231
|
+
for trig in triggers:
|
|
232
|
+
key_id = trig.get("key_id", "")
|
|
233
|
+
label = f"trigger[{key_id}]"
|
|
234
|
+
|
|
235
|
+
if key_id not in parties:
|
|
236
|
+
result.record(label, False, f"{key_id!r} is not a listed party")
|
|
237
|
+
continue
|
|
238
|
+
|
|
239
|
+
key = party_keys.get(key_id)
|
|
240
|
+
if key is None:
|
|
241
|
+
result.record(label, False, f"no key held for party {key_id!r}")
|
|
242
|
+
continue
|
|
243
|
+
|
|
244
|
+
reason = _verify_ecdsa(
|
|
245
|
+
key, message, trig.get("signature", ""), prehashed=False
|
|
246
|
+
)
|
|
247
|
+
result.record(
|
|
248
|
+
label,
|
|
249
|
+
not reason,
|
|
250
|
+
reason or "verifies over {condition_hash, receipt_id}",
|
|
251
|
+
)
|
|
252
|
+
if reason:
|
|
253
|
+
result.checks[-1].detail += (
|
|
254
|
+
". If it is well formed, check whether it belongs to a "
|
|
255
|
+
"different Receipt sharing this release condition"
|
|
256
|
+
)
|
|
257
|
+
|
|
258
|
+
duplicated = len(triggers) != len({t.get("key_id") for t in triggers})
|
|
259
|
+
result.record(
|
|
260
|
+
"triggers.unique",
|
|
261
|
+
not duplicated,
|
|
262
|
+
"one trigger per party"
|
|
263
|
+
if not duplicated
|
|
264
|
+
else "a party appears more than once, overstating agreement",
|
|
265
|
+
)
|
|
266
|
+
|
|
267
|
+
complete = bool(parties) and {t.get("key_id") for t in triggers} >= set(parties)
|
|
268
|
+
result.record(
|
|
269
|
+
"settlement.complete",
|
|
270
|
+
complete,
|
|
271
|
+
"every listed party has triggered"
|
|
272
|
+
if complete
|
|
273
|
+
else f"awaiting {sorted(set(parties) - {t.get('key_id') for t in triggers})}",
|
|
274
|
+
)
|
|
275
|
+
|
|
276
|
+
if governance_receipt is not None:
|
|
277
|
+
expected = receipt.get("governance", {}).get("receipt_hash")
|
|
278
|
+
actual = governance_receipt.get("receipt_hash")
|
|
279
|
+
result.record(
|
|
280
|
+
"governance.receipt_hash",
|
|
281
|
+
actual == expected,
|
|
282
|
+
"binds the governance Receipt that produced the verdict"
|
|
283
|
+
if actual == expected
|
|
284
|
+
else (
|
|
285
|
+
f"commits to {expected} but the held Receipt is {actual}. "
|
|
286
|
+
"The verdict is signed and unsupported"
|
|
287
|
+
),
|
|
288
|
+
)
|
|
289
|
+
|
|
290
|
+
verdict = receipt.get("governance", {}).get("decision")
|
|
291
|
+
held = governance_receipt.get("decision")
|
|
292
|
+
result.record(
|
|
293
|
+
"governance.decision",
|
|
294
|
+
verdict == held,
|
|
295
|
+
f"matches ({verdict})"
|
|
296
|
+
if verdict == held
|
|
297
|
+
else f"Receipt says {verdict!r}, governance Receipt says {held!r}",
|
|
298
|
+
)
|
|
299
|
+
|
|
300
|
+
if payload is not None:
|
|
301
|
+
expected = receipt.get("payload_hash")
|
|
302
|
+
actual = hashlib.sha256(payload).hexdigest()
|
|
303
|
+
result.record(
|
|
304
|
+
"payload_hash",
|
|
305
|
+
actual == expected,
|
|
306
|
+
"commits to the payload held"
|
|
307
|
+
if actual == expected
|
|
308
|
+
else f"recorded {expected} but the payload hashes to {actual}",
|
|
309
|
+
)
|
|
310
|
+
|
|
311
|
+
return result
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: sdcreceipt
|
|
3
|
+
Version: 4.0.0
|
|
4
|
+
Summary: Verify and settle VSL Settlement Receipts. No account, no network for verification.
|
|
5
|
+
Author: Axius SDC, Inc.
|
|
6
|
+
License: Apache-2.0
|
|
7
|
+
Project-URL: Homepage, https://github.com/SemanticDataCharter/sdcreceipt
|
|
8
|
+
Keywords: vsl,settlement,receipt,xmldsig,rfc8785,sdc
|
|
9
|
+
Requires-Python: >=3.10
|
|
10
|
+
Description-Content-Type: text/markdown
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Requires-Dist: sdcgovernance>=4.2.0
|
|
13
|
+
Requires-Dist: cryptography>=42.0
|
|
14
|
+
Provides-Extra: schema
|
|
15
|
+
Requires-Dist: jsonschema>=4.20; extra == "schema"
|
|
16
|
+
Provides-Extra: dev
|
|
17
|
+
Requires-Dist: pytest>=8.0; extra == "dev"
|
|
18
|
+
Requires-Dist: jsonschema>=4.20; extra == "dev"
|
|
19
|
+
Dynamic: license-file
|
|
20
|
+
|
|
21
|
+
# sdcreceipt
|
|
22
|
+
|
|
23
|
+
Verify and settle VSL Settlement Receipts.
|
|
24
|
+
|
|
25
|
+
**Verification needs no account, no network, and nothing from the issuer.**
|
|
26
|
+
That is the point of the tool: a claim that anyone can check a Receipt
|
|
27
|
+
independently is worth exactly as much as the ability to do it.
|
|
28
|
+
|
|
29
|
+
Apache-2.0.
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
pip install sdcreceipt
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## Three verbs
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
# Check a Receipt you were sent. Offline.
|
|
39
|
+
sdcreceipt verify receipt.json --keys issuer-keys.json
|
|
40
|
+
|
|
41
|
+
# Set yourself up as a party: keypair + the document to publish.
|
|
42
|
+
sdcreceipt init --key-id https://vendor.example/.well-known/vsl-key.json
|
|
43
|
+
|
|
44
|
+
# Authorize a settlement you are a party to.
|
|
45
|
+
sdcreceipt trigger receipt.json --key vsl-party.pem \
|
|
46
|
+
--key-id https://vendor.example/.well-known/vsl-key.json
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
`verify` exits 0 only if every check passed, so it composes in a shell without
|
|
50
|
+
anyone parsing output.
|
|
51
|
+
|
|
52
|
+
There will not be a fourth verb. This is a client, not a product, and its
|
|
53
|
+
value is in being small enough to read.
|
|
54
|
+
|
|
55
|
+
---
|
|
56
|
+
|
|
57
|
+
## If you were sent a Receipt
|
|
58
|
+
|
|
59
|
+
You do not need an account with anyone.
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
pip install sdcreceipt
|
|
63
|
+
curl -O https://sdcstudio.axius-sdc.com/.well-known/sdcstudio-signing-keys.json
|
|
64
|
+
sdcreceipt verify receipt.json --keys sdcstudio-signing-keys.json
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
Every check is reported, not just the first failure:
|
|
68
|
+
|
|
69
|
+
```
|
|
70
|
+
PASS schema: conforms
|
|
71
|
+
PASS receipt_hash: matches the canonical content
|
|
72
|
+
PASS signature[sdcstudio-signing-key-v1]: verifies over receipt_hash
|
|
73
|
+
PASS trigger[https://vendor.example/.well-known/vsl-key.json]: verifies
|
|
74
|
+
PASS settlement.complete: every listed party has triggered
|
|
75
|
+
|
|
76
|
+
VERIFIED
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
A Receipt carries **hash commitments, never the payload**. So verification
|
|
80
|
+
tells you a conformant, authorized, dual-triggered exchange occurred, without
|
|
81
|
+
anyone having to disclose what was exchanged. If you also hold the payload or
|
|
82
|
+
the governance Receipt, pass them and those get checked too:
|
|
83
|
+
|
|
84
|
+
```bash
|
|
85
|
+
sdcreceipt verify receipt.json --keys keys.json \
|
|
86
|
+
--payload manifest.xml --governance governance-receipt.json
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
## If you need to become a party
|
|
90
|
+
|
|
91
|
+
A settlement identifies each party by a `key_id` that **you** control. That is
|
|
92
|
+
deliberate: it means verifying your signature does not route through the
|
|
93
|
+
issuer, so nobody has to stay alive for your old signatures to keep meaning
|
|
94
|
+
something.
|
|
95
|
+
|
|
96
|
+
```bash
|
|
97
|
+
sdcreceipt init --key-id https://vendor.example/.well-known/vsl-key.json
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
That writes a private key (mode `0600`) and a key document, and tells you the
|
|
101
|
+
exact URL the document must be reachable at. Publishing one JSON file is the
|
|
102
|
+
whole onboarding requirement.
|
|
103
|
+
|
|
104
|
+
Then, when you are sent a Receipt to authorize:
|
|
105
|
+
|
|
106
|
+
```bash
|
|
107
|
+
sdcreceipt trigger receipt.json --key vsl-party.pem --key-id <your key_id>
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
It prints a signed trigger and stops. **Signing is inert; submitting is a side
|
|
111
|
+
effect**, so you send it yourself, or add `--submit <url>`.
|
|
112
|
+
|
|
113
|
+
---
|
|
114
|
+
|
|
115
|
+
## ★ Never take the verification key from the document
|
|
116
|
+
|
|
117
|
+
> The set of keys you will accept is decided **before** you read the document,
|
|
118
|
+
> and the document cannot change it.
|
|
119
|
+
|
|
120
|
+
`ds:RetrievalMethod` in XML-Signature, `jku` and `x5u` in JOSE, and their
|
|
121
|
+
equivalents elsewhere all say *"here is where my key lives."* That pointer was
|
|
122
|
+
written by whoever produced the document, so following it asks the document to
|
|
123
|
+
nominate the key that will judge it. A forged document nominates the forger's
|
|
124
|
+
key and verification "succeeds."
|
|
125
|
+
|
|
126
|
+
The failure is quiet. A pointer can name a domain that was correct when the
|
|
127
|
+
document was signed and has since lapsed; anyone who registers it can serve a
|
|
128
|
+
key at that path, and nothing about the document looks wrong — because nothing
|
|
129
|
+
about it *is* wrong. The verifier was asked where to look and did as it was
|
|
130
|
+
told.
|
|
131
|
+
|
|
132
|
+
This tool cannot make that mistake: `verify` takes keys as arguments and has
|
|
133
|
+
no code path that fetches one. That is a security property, not an
|
|
134
|
+
inconvenience.
|
|
135
|
+
|
|
136
|
+
The same applies to party keys, with a corollary rather than an exemption.
|
|
137
|
+
Those `key_id`s *are* URIs the counterparty controls, deliberately. Resolve
|
|
138
|
+
them over HTTPS only, only for identifiers already recorded in a Receipt you
|
|
139
|
+
trust, and keep a copy — a party who later loses a domain must not be able to
|
|
140
|
+
change what their old signatures mean.
|
|
141
|
+
|
|
142
|
+
---
|
|
143
|
+
|
|
144
|
+
## Conformance
|
|
145
|
+
|
|
146
|
+
`tests/conformance/` ships the issuer's published vectors, and the suite runs
|
|
147
|
+
this implementation against them.
|
|
148
|
+
|
|
149
|
+
Ten vectors. **Every invalid one encodes a defect that was actually made**,
|
|
150
|
+
not a hypothetical: a DER signature where ES256 requires P1363, a signature
|
|
151
|
+
over the hex text of `receipt_hash` rather than its raw bytes, a governance
|
|
152
|
+
binding that does not match the evidence held, a trigger replayed from another
|
|
153
|
+
Receipt sharing the same release condition, and so on. Failing one for the
|
|
154
|
+
wrong reason does not count — the manifest names the check that must break.
|
|
155
|
+
|
|
156
|
+
```bash
|
|
157
|
+
pytest
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
**On independence, honestly.** Passing these vectors shows this tool agrees
|
|
161
|
+
with the issuer's published expectations, and that it never drifted from them.
|
|
162
|
+
It is *not* an independent re-derivation: this implementation and the issuer's
|
|
163
|
+
share design and history. The vectors are most valuable to someone writing a
|
|
164
|
+
verifier from the specification alone, which is what they are published for.
|
|
165
|
+
|
|
166
|
+
## Building your own
|
|
167
|
+
|
|
168
|
+
You do not have to use this tool, and the specification does not depend on it.
|
|
169
|
+
If you are writing a verifier:
|
|
170
|
+
|
|
171
|
+
**Do not write a second canonicalizer.** Use `sdcgovernance` or another
|
|
172
|
+
conformant RFC 8785 implementation. A second implementation can disagree with
|
|
173
|
+
the first, and the disagreement is silent: the bytes differ, so the hash
|
|
174
|
+
differs, and the artifact reads as tampered with rather than misencoded. This
|
|
175
|
+
tool re-exports `sdcgovernance.jcs` for exactly that reason and adds nothing.
|
|
176
|
+
|
|
177
|
+
**Refuse rather than guess.** Integers beyond ±(2⁵³−1) cannot round-trip
|
|
178
|
+
through an IEEE 754 double, and `NaN`/`Infinity` have no JSON representation.
|
|
179
|
+
Emitting something for those produces a hash that looks fine and fails only in
|
|
180
|
+
someone else's verifier.
|
|
181
|
+
|
|
182
|
+
**Report every check.** Stopping at the first failure hides the case that
|
|
183
|
+
matters most: a Receipt whose signature verifies but whose governance binding
|
|
184
|
+
does not.
|
|
185
|
+
|
|
186
|
+
**Check the curve.** A signature verified against a key on an unexpected curve
|
|
187
|
+
proves nothing about the party you believe signed.
|
|
188
|
+
|
|
189
|
+
## Versioning
|
|
190
|
+
|
|
191
|
+
MAJOR tracks the **SDC reference model**, so a `4.x.x` release targets SDC4.
|
|
192
|
+
It starts at 4 rather than 0 because of that convention, not because there
|
|
193
|
+
were three earlier versions. MINOR is features, PATCH is fixes. An SDC5
|
|
194
|
+
reference model would make this `5.x.x`.
|
|
195
|
+
|
|
196
|
+
The same scheme is used by `sdcvalidator`, `sdcgovernance` and the rest of the
|
|
197
|
+
family, so a version number tells you which reference model an artifact
|
|
198
|
+
targets without looking anything up.
|
|
199
|
+
|
|
200
|
+
Note that the **Receipt format version is separate** and independent: a
|
|
201
|
+
Receipt says `"version": "1.0"`, which is the frozen wire format, not this
|
|
202
|
+
package.
|
|
203
|
+
|
|
204
|
+
## Dependencies
|
|
205
|
+
|
|
206
|
+
`sdcgovernance` for canonicalization and `cryptography` for ECDSA, both
|
|
207
|
+
Apache-2.0-compatible libraries. `jsonschema` is optional and only needed for
|
|
208
|
+
`--schema`.
|
|
209
|
+
|
|
210
|
+
These are **library** dependencies. Nothing here calls a service, and
|
|
211
|
+
`verify` makes no network request at all.
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
sdcreceipt/__init__.py,sha256=HwPI883tuViDEDCcFFXc9oMYcR9uBC97Sjgb4wmn7OE,771
|
|
2
|
+
sdcreceipt/canonical.py,sha256=bj_uih8ue4mt2Yta6ocjFoxYP-lyKNEiRUuDjdfUQTA,991
|
|
3
|
+
sdcreceipt/cli.py,sha256=90DWZzg-24HG6HumARpw7IaG1tJ1S_MrwXHJ7cDyp68,6601
|
|
4
|
+
sdcreceipt/party.py,sha256=aEcS0dmxT_hGJdcV5td_oFhMzksZZQtN-kcpTKvalpo,7609
|
|
5
|
+
sdcreceipt/verify.py,sha256=Rstys3ebZk5usuEGBrnZ0hCDfptI1uI2ExQuoDEHhsM,10464
|
|
6
|
+
sdcreceipt-4.0.0.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
|
7
|
+
sdcreceipt-4.0.0.dist-info/METADATA,sha256=OBcTuIbTFkZ_5bKBptfa9dw81OU3dPHaAB599yusygI,7837
|
|
8
|
+
sdcreceipt-4.0.0.dist-info/WHEEL,sha256=YVMoNqKzERt-wjUZwJ33xBGAwnFl-4cqbYkTtWa4itE,91
|
|
9
|
+
sdcreceipt-4.0.0.dist-info/entry_points.txt,sha256=cvW-ifbjP8fI1RjYb92cUG-b5c_hOJmIm7YCTkws28k,51
|
|
10
|
+
sdcreceipt-4.0.0.dist-info/top_level.txt,sha256=9VQe_SVo6LhxHG_Ibub8z7ktonhRc9FlRvMSaMMM1lE,11
|
|
11
|
+
sdcreceipt-4.0.0.dist-info/RECORD,,
|
|
@@ -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 [yyyy] [name of copyright owner]
|
|
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 @@
|
|
|
1
|
+
sdcreceipt
|