matrix-org / matrix-org/matrix-spec
How does signature verification work in pre-v6 rooms
Nobody has claimed this yet.
- Dominant language
- HTML
- Stars
- 330
- Forks
- 150
- Avg merge
- 2h 21m
- Merged PRs (30d)
- 3
Description
**Link to problem area**:
[Signing JSON](https://spec.matrix.org/v1.12/appendices/#signing-json), from the v1.12 spec.
**Issue**
The spec says
> Events in room versions 1, 2, 3, 4, and 5 might not be fully compliant with these restrictions. Servers SHOULD be capable of handling JSON which is considered invalid by these restrictions where possible.
>
> The most notable consideration is that integers might not be in the range specified above.
Then the "signing details" subsection says
> JSON is signed by encoding the JSON object without signatures or keys grouped as unsigned, using the canonical encoding described above.
Then the "checking for a signature" subsection says
> 6. Encodes the remainder of the JSON object using the [Canonical JSON](https://spec.matrix.org/v1.12/appendices/#canonical-json) encoding.
> 7. Checks the signature bytes against the encoded object using the verification key. If this fails then the check fails. Otherwise the check succeeds.
I read this as "there is no requirement that canonical JSON encoding is used when signing events in pre-v6 rooms, and servers must be able to verify events that were originally signed using _any_ JSON encoding". This is a problem, because a compliant server would need to iterate over all allowed encodings when checking signatures and can only reject an event after testing all of them. There are an unlimited number of encoding allowed by the current spec.
My outside-of-the-spec-text understanding is that the real requirement on encoding for pre-v6 rooms is "exactly what synapse does", which is something based on python's stdlib json encoder. I do not know whether this encoding is consistent between synapse versions, python versions, or pre-v6 room versions.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the v1.12 Signing JSON and checking-for-a-signature sections, then compare their wording for room versions 1–5 with the referenced Canonical JSON rules. Clarify the intended encoding and compatibility behavior for pre-v6 signatures; done means the specification makes the signing and verification procedure unambiguous.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- json
- Domain
- cryptography, documentation
- Issue type
- Documentation
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100