harness: use a conforming RFC 8785 canonicalizer - #2
Open
laxsharma wants to merge 1 commit into
Open
Conversation
`manifest.json` declares `"canonicalizer": "rfc8785@0.1.4"`, and the
verification recipe says the payload is RFC 8785 canonical JSON. The
harness implements that as
`json.dumps(sort_keys=True, separators=(",", ":"))`, which is not RFC 8785
and which its own docstring described as a "JCS subset".
The two agree byte-for-byte on all five current v0 vectors, so nothing is
broken today. That is a property of the vectors, not of the code: they are
pure ASCII and carry `amount` as a string rather than a JSON number. The
first vector that is neither will be signed correctly by a conforming
signer and then rejected here, and it will surface as
`payload bytes != canonical unsigned vector`, which reads like a forged
signature rather than a canonicalizer mismatch.
Divergences, all verified against `rfc8785` 0.1.4:
| input | `json.dumps` | RFC 8785 |
|---|---|---|
| `{"note":"café"}` | `{"note":"café"}` | `{"note":"café"}` |
| `{"merchant":"München GmbH"}` | escaped | UTF-8 |
| `{"amount":1e16}` | `1e+16` | `10000000000000000` |
| `{"amount":-0.0}` | `-0.0` | `0` |
| `{"😀":1,"�":2}` | U+FFFD first | 😀 first (UTF-16 order) |
Changes:
- `harness/jws.py` uses `rfc8785.dumps`.
- `rfc8785>=0.1.4` added to `harness/requirements.txt`.
- `tests/test_canonicalization.py` covers the string, number and
sort-order cases. Every case fails before this change and passes after.
- One regression test asserts the five vendored vectors canonicalize
identically under both implementations, so the change is
signature-preserving for everything currently in the corpus.
- `docs/vector-format.md` step 2 no longer describes the approximation as
the recipe.
Verified locally: `python -m harness.validate_vectors --vectors vectors/v0`
reports all 5 valid, and `pytest tests/` is 20 passed.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Use a conforming RFC 8785 canonicalizer in the harness
manifest.jsondeclares"canonicalizer": "rfc8785@0.1.4", and theverification recipe says the payload is RFC 8785 canonical JSON. The
harness implements that as
json.dumps(sort_keys=True, separators=(",", ":")), which is not RFC 8785and which its own docstring described as a "JCS subset".
The two agree byte-for-byte on all five current v0 vectors, so nothing is
broken today. That is a property of the vectors, not of the code: they are
pure ASCII and carry
amountas a string rather than a JSON number. Thefirst vector that is neither will be signed correctly by a conforming
signer and then rejected here, and it will surface as
payload bytes != canonical unsigned vector, which reads like a forgedsignature rather than a canonicalizer mismatch.
Divergences, all verified against
rfc87850.1.4:json.dumps{"note":"café"}{"note":"café"}{"note":"café"}{"merchant":"München GmbH"}{"amount":1e16}1e+1610000000000000000{"amount":-0.0}-0.00{"😀":1,"�":2}Changes:
harness/jws.pyusesrfc8785.dumps.rfc8785>=0.1.4added toharness/requirements.txt.tests/test_canonicalization.pycovers the string, number andsort-order cases. Every case fails before this change and passes after.
identically under both implementations, so the change is
signature-preserving for everything currently in the corpus.
docs/vector-format.mdstep 2 no longer describes the approximation asthe recipe.
Verified locally:
python -m harness.validate_vectors --vectors vectors/v0reports all 5 valid, and
pytest tests/is 20 passed.Co-Authored-By: Claude Fable 5 noreply@anthropic.com