gunk-dev/the-valley

README.md

source07d67d385df1main's published tip history
3.4 KiB · Rendered
1# Conformance vectors for the canonical form
2
3These files are the interop contract for the bytes an attestation signature covers. A second
4implementation of `attest` — a rewrite of this one, or a reader written in another language — must
5render every `input.json` here into exactly the bytes of the `canonical.json` beside it. Anything
6else and the two sign different bytes over the same statement, so a signature made by one does not
7verify against the other, and the way that failure arrives is a verification error that names
8nothing.
9
10The serialization itself is RFC 8785 canonical JSON, narrowed by excluding numbers, and the reasons
11for that are in [`../canonical.go`](../canonical.go) and in the decision node it cites.
12
13## What is here
14
15Each directory under `vectors/` is one vector.
16
17- `input.json` is a statement or fragment written in some arbitrary rendering — members out of
18 order, whitespace anywhere, escapes chosen freely. It is input, not output.
19- `canonical.json` is the exact byte sequence the canonical form produces from it. There is no
20 trailing newline: the file is the bytes, and nothing else is signed.
21- `statement.sig`, where present, is a detached SSHSIG signature over those exact bytes, under the
22 namespace `the-valley.attestation.v1`, made by the key in `../signer.pub` and listed in
23 `../allowed_signers`. That key exists for these vectors and holds no authority anywhere.
24
25The vectors cover the places implementations actually part company: member order over keys that
26differ only in case, keys where one is a prefix of another, and the empty key; nesting of objects
27inside arrays inside objects; empty objects, empty arrays and the empty string; every string escape,
28including the control characters that have short forms and the ones that do not, the characters a
29JavaScript-oriented encoder escapes and RFC 8785 does not, and text above the basic multilingual
30plane; and the difference between an absent `provenance` and one present but empty, which the schema
31permits and which is two different byte sequences.
32
33A vector whose `canonical.json` is a whole statement also vets against
34[`../../schema/attestation.cue`](../../schema/attestation.cue), so the set does not drift into
35documents no verifier would accept. Numbers are absent on purpose — a statement carries none, so the
36canonical form of one has never been decided and `attest` refuses rather than guessing.
37
38## Running them
39
40`nix flake check` runs them as `attest-conformance`. Each vector is rendered with
41`attest canonical`, compared byte for byte, and re-rendered from its own canonical bytes to confirm
42the form is a fixed point. The signed vector is then put through `attest verify`, so the path from a
43statement to a signature something else can check is pinned end to end rather than only the
44serialization. The check also perturbs one recorded byte sequence and requires the comparison to
45reject it, so a vector set that agrees with itself vacuously cannot pass.
46
47By hand, against any one vector:
48
49```
50$ nix run .#attest -- canonical attest/conformance/vectors/01-key-order/input.json \
51 | cmp - attest/conformance/vectors/01-key-order/canonical.json
52```
53
54## Changing them
55
56A vector's recorded bytes may only change when the canonical form itself changes, and that
57invalidates every signature ever made under it. Regenerating a `canonical.json` to make a failing
58check pass is the one thing this directory exists to prevent. A new vector is a new directory and
59needs no registration; the check finds it.