Skip to content

Delete trust_level from client/hello - #158

Merged
arturpragacz merged 4 commits into
mainfrom
refactor/delete-trust-level
Aug 28, 2026
Merged

arturpragacz merged 4 commits into
mainfrom
refactor/delete-trust-level

Conversation

@maximmaxim345

@maximmaxim345 maximmaxim345 commented Aug 20, 2026 •

Copy link
Copy Markdown
Member

The server already knows which PSK matched during the Noise handshake, so it can derive whether the session is paired instead of taking the client's word for it. Nothing consumed the field: every enforcement rule already keys on the matched PSK.

One gap made the field load-bearing until now: a management server could remove a record and then set its PSK as the client's pairing PSK, and the original server's next handshake would complete with the two sides disagreeing about the matched category - trust_level was the only signal exposing that. This PR therefore adds psk_category: 'lt' | 'pr' | 'sn' to the Noise message 1 payload: the server declares which category it is using the referenced PSK as, and the client matches psk_id only among candidates of that category. A recategorized credential is now an ordinary lookup miss that lands in the Sentinel fallback, which already tells the server to re-pair, so paired state is fully derivable on both sides and the field can go. A miss during a re-handshake instead fails the handshake as before; the server's reconnect then takes the initial-handshake fallback path.

Design notes: a category mismatch is deliberately a miss rather than a hard failure - the fallback turns it into an authenticated credential-mismatch signal with the re-pair path attached, where a hard failure would just produce a mute reconnect loop. The three codes share one length, keeping the encrypted payload's length independent of the category. The psk_id derivation, the published Sentinel constant, and the already_exists guards are all unchanged; the cross-category uniqueness rule stays, its rationale restated as what it actually protects (the pairing token distributes the pairing PSK in cleartext, so the same bytes must not also back a record).

This PR also rewords the "trust level" term in the spec. This was a left over from when we had 3 (the additional owner level, whose management rights were merged into the user level - now called just paired).

unpaired_access.enabled remains because it is genuine client policy the server cannot derive.

Breaking change

Existing pairing records and psk_ids are untouched, so deployed pairings keep working. Breaking only when a client is updated before its server: an updated client requires psk_category in Noise message 1 and no longer sends trust_level, both of which an old server trips on. The reverse order is safe: receivers ignore unrecognized payload fields, so an updated server interoperates with old clients, which then simply don't enforce the category check.


Closes #140

Alternative to #138, which keeps the field as a boolean paired instead.

@arturpragacz arturpragacz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After thinking about it some more I'm not sure it's a good idea to do this actually.

The problem is that there are some very weird edge cases, which are not going to happen in normal use, but someone could do it theoretically and so we have to handle them somehow. Consider for example:

  • two servers, both already paired to the client
  • the second one removes the pairing record for the first one
  • it then sets the pairing PSK to the same PSK as the first server had
  • now when the first server connects it thinks it is paired, but it actually isn't

So I think we should either go with the other solution (using paired field) or alternatively just leave it as is to make it easier to extend in the future if there is a need.

@maximmaxim345
maximmaxim345 force-pushed the refactor/delete-trust-level branch from b3cd38d to 75ad081 Compare August 27, 2026 13:01
@maximmaxim345

Copy link
Copy Markdown
Member Author

Hmm, yea that's tricky to solve without any signal from the client

Maybe there's another approach if we change the psk_id derivation though: All three categories share one label right now, which is why a record and the pairing PSK can collide at all. Give each category its own label and the stale server just gets a lookup miss, which lands in the Sentinel fallback and already tells it to re-pair. I pushed a commit on this branch that tries this approach - it also means the already_exists guards compare PSK bytes instead of psk_ids, and the published Sentinel psk_id constant changes. The tradeoff: today a server could in principle detect the mismatch and silently re-pair itself in-session, while with the labels the mismatch is explicit and re-pairing goes through the normal flows - which after a deliberate remove-record seems like the right default.

The rename to paired is simpler though, so I reopened #138 as the alternative. In theory we can still expand later if we do want more "trust levels", just with an added allowed_activities field or similar instead of a third enum value. This is better backwards compatible as well: unknown fields have to be ignored, unknown enum values are undefined behavior or invalid I think.

@arturpragacz Let me know which you prefer - the psk_id labels here, or the boolean paired in #138.

@arturpragacz

Copy link
Copy Markdown
Contributor

That's overkill and makes things more complicated. We don't need domain separation here.

But I think I agree failing early is not a bad idea.

So instead revert the psk_id changes and just add:

psk_category: 'lt' | 'pr' | 'sn'

to Noise 1 message (keep it exactly as above for same length).

@maximmaxim345
maximmaxim345 force-pushed the refactor/delete-trust-level branch from 75ad081 to 8db2e97 Compare August 28, 2026 07:37
@maximmaxim345

Copy link
Copy Markdown
Member Author

Done, added the psk_category field instead in this PR.

Also, I made a category mismatch a lookup miss rather than a hard handshake failure, so it lands in the Sentinel fallback and the server gets the credential-mismatch signal and re-pair prompt instead of a silent reconnect loop.

Comment thread messaging.md Resolved
Comment thread README.md Resolved
@arturpragacz
arturpragacz merged commit 7f52403 into main Aug 28, 2026
1 check passed
@arturpragacz
arturpragacz deleted the refactor/delete-trust-level branch August 28, 2026 12:00
arturpragacz pushed a commit to Sendspin/aiosendspin that referenced this pull request Sep 11, 2026
# What does this implement/fix?

Implements spec [#158](Sendspin/spec#158).

Noise message 1 now carries `psk_category` alongside `psk_id`, naming
which category the server is using the referenced PSK as. The client
matches the `psk_id` only against candidates of that category, so a PSK
it holds under a different one is a lookup miss. In exchange,
`trust_level` leaves `client/hello`: the server reads trust off the PSK
category it matched rather than being told by the client.


NOTE:

- **`ConnectionSecurity.trust_level` changes provenance.** It is now a
property derived from `psk_category` rather than a value the client
asserted. Consumers see the same attribute, but a client claiming `user`
over a Sentinel connection reported `USER` and now reports `NONE`. No
authorization gate moves — none of them read the field; they already
read the PSK category. This is an API-honesty fix, not a hardening.

- **`ClientHelloPayload`'s positional signature shifts**, since a field
was removed. Keyword construction is unaffected.

Backwards compatibility is a server concern here, and the server keeps
it: a hello still carrying `trust_level` parses and the value is
ignored. The client speaks the current spec and carries no second
reading of it — `psk_category` is required, so a message 1 without it is
a malformed payload and the handshake fails, and resolution is always
scoped to the category the server declared.

**Related issue (if applicable):**

- n/a

## Types of changes

- [x] Enhancement to an existing feature — `enhancement`

## Checklist

- [x] The code change is tested and works locally.
- [x] `pre-commit run --all-files` passes.
- [x] `pytest` passes, and tests have been added/updated under `tests/`
where applicable.
maximmaxim345 added a commit to Sendspin/aiosendspin that referenced this pull request Oct 5, 2026
# What does this implement/fix?

<!-- Quick description and explanation of changes. -->

The spec removed trust level and made `psk_category` the only name for
it, so `TrustLevel` and `ConnectionSecurity.trust_level` are removed.
Use `ConnectionSecurity.psk_category` instead: `PskCategory.LONG_TERM`
was trust level `user`, and anything else was `none`.

Nothing changes on the wire. The server still accepts a `trust_level`
key in `client/hello` from older clients.

**Related issue or spec PR (if applicable):**

- Sendspin/spec#158
- Sendspin/spec#159

## Types of changes

<!--
Tick exactly one box. CI (.github/workflows/pr-labels.yaml) applies the
matching label, and the release notes use it to sort this change.
-->

- [ ] Bugfix (non-breaking change which fixes an issue): `bugfix`
- [ ] New feature (non-breaking change which adds functionality):
`new-feature`
- [ ] Enhancement to an existing feature: `enhancement`
- [x] Breaking change (changes the public API or the protocol in a way
that is not backwards compatible): `breaking-change`
- [ ] Refactor (no behavior change): `refactor`
- [ ] Documentation only: `documentation`
- [ ] Maintenance / chore: `maintenance`
- [ ] CI / workflow change: `ci`
- [ ] Dependencies bump: `dependencies`
maximmaxim345 added a commit to Sendspin/sendspin-js that referenced this pull request Oct 28, 2026
# What does this implement/fix?

<!-- Quick description and explanation of changes. -->

Audio from a server that sends the spec's 13-byte audio chunk header was
corrupted, since the client read the 4-byte `send_ahead` field as audio.
The client also sent `trust_level` and player `supported_commands` in
`client/hello`, which strict servers reject.

The client now sends the rc1 `client/hello` and skips the full 13-byte
header, and `send_ahead` doesn't affect playback. The operator's
`languages` for a spoken pairing code are now read from `server/hello`,
where the spec defines them.

Breaking changes:
- A server that still sends 9-byte audio chunk headers now plays
corrupted audio.
- `ClientHello` no longer has `trust_level` or player
`supported_commands`, and `ActivatePairing` no longer has `languages`.

Closing the connection on an audio message shorter than 13 bytes is left
for a later PR.

**Related issue or spec PR (if applicable):**

- Sendspin/spec#158
- Sendspin/spec#167
- Sendspin/spec#177
- Sendspin/spec#241

## Types of changes

<!--
Tick exactly one box. CI (.github/workflows/pr-labels.yaml) applies the
matching label, and the release notes use it to sort this change.
-->

- [ ] Bugfix (non-breaking change which fixes an issue): `bugfix`
- [ ] New feature (non-breaking change which adds functionality):
`new-feature`
- [ ] Enhancement to an existing feature: `enhancement`
- [x] Breaking change (changes the public API or the protocol in a way
that is not backwards compatible): `breaking-change`
- [ ] Refactor (no behavior change): `refactor`
- [ ] Documentation only: `documentation`
- [ ] Maintenance / chore: `maintenance`
- [ ] CI / workflow change: `ci`
- [ ] Dependencies bump: `dependencies`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Delete trust_level from client/hello instead of renaming it — the server already derives it from the matched PSK

2 participants