| 1 | # Conformance vectors for the canonical form |
| 2 | |
| 3 | These files are the interop contract for the bytes an attestation signature covers. A second |
| 4 | implementation of `attest` — a rewrite of this one, or a reader written in another language — must |
| 5 | render every `input.json` here into exactly the bytes of the `canonical.json` beside it. Anything |
| 6 | else and the two sign different bytes over the same statement, so a signature made by one does not |
| 7 | verify against the other, and the way that failure arrives is a verification error that names |
| 8 | nothing. |
| 9 | |
| 10 | The serialization itself is RFC 8785 canonical JSON, narrowed by excluding numbers, and the reasons |
| 11 | for that are in [`../canonical.go`](../canonical.go) and in the decision node it cites. |
| 12 | |
| 13 | ## What is here |
| 14 | |
| 15 | Each 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 | |
| 25 | The vectors cover the places implementations actually part company: member order over keys that |
| 26 | differ only in case, keys where one is a prefix of another, and the empty key; nesting of objects |
| 27 | inside arrays inside objects; empty objects, empty arrays and the empty string; every string escape, |
| 28 | including the control characters that have short forms and the ones that do not, the characters a |
| 29 | JavaScript-oriented encoder escapes and RFC 8785 does not, and text above the basic multilingual |
| 30 | plane; and the difference between an absent `provenance` and one present but empty, which the schema |
| 31 | permits and which is two different byte sequences. |
| 32 | |
| 33 | A 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 |
| 35 | documents no verifier would accept. Numbers are absent on purpose — a statement carries none, so the |
| 36 | canonical 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 |
| 42 | the form is a fixed point. The signed vector is then put through `attest verify`, so the path from a |
| 43 | statement to a signature something else can check is pinned end to end rather than only the |
| 44 | serialization. The check also perturbs one recorded byte sequence and requires the comparison to |
| 45 | reject it, so a vector set that agrees with itself vacuously cannot pass. |
| 46 | |
| 47 | By 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 | |
| 56 | A vector's recorded bytes may only change when the canonical form itself changes, and that |
| 57 | invalidates every signature ever made under it. Regenerating a `canonical.json` to make a failing |
| 58 | check pass is the one thing this directory exists to prevent. A new vector is a new directory and |
| 59 | needs no registration; the check finds it. |