Skip to content

Follow the spec rules for PSK matching and handshake failures - #199

Merged
maximmaxim345 merged 1 commit into
mainfrom
fix/psk-matching-handshake-failures
Oct 26, 2026
Merged

maximmaxim345 merged 1 commit into
mainfrom
fix/psk-matching-handshake-failures

Conversation

@maximmaxim345

Copy link
Copy Markdown
Member

What does this implement/fix?

A client that lost its pairing record (cleared storage, an interrupted pairing) couldn't reconnect to a server that still had it paired, since it closed the handshake on an unknown psk_id and stopped reconnecting.
It also ignored psk_category, accepted malformed handshake payloads, and kept running on the old keys when a re-handshake failed.

Now an unknown psk_id, or one the client holds under a different category, falls back to the Sentinel PSK in the initial handshake, so the server can offer re-pairing.
Malformed payloads and failed re-handshakes close the connection, and outgoing messages are held during a re-handshake until the new server/activate.

Breaking changes:

  • longTermPsks[].serverId is now required, since the spec no longer has long-term PSKs without a server_id. Stored records without one are no longer used, so those servers need to be paired again.

Related issue or spec PR (if applicable):

Types of changes

  • 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
  • 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
maximmaxim345 requested a balanced review from Copilot October 26, 2026 11:02
@github-actions github-actions Bot added the breaking-change Changes the public API or the protocol in a way that is not backwards compatible label Oct 26, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔵 Needs a closer look

Authentication fallback, live session-key transitions, and breaking changes to stored credentials warrant final human protocol and security review.

No open issues 🎉

What changed in this PR

This PR aligns the SDK’s encrypted transport with the protocol’s PSK matching and handshake-failure rules, allowing clients with lost pairing records to reach re-pairing.

Changes:

  • Validate handshake payloads and PSK categories, with Sentinel fallback for initial lookup misses.
  • Close failed re-handshakes and queue outgoing traffic until activation, except client/hello.
  • Require server-bound long-term PSKs and skip stored records without a server ID.
File Description
tests/​unit/​transport.test.ts Tests fallback, category matching, server binding, and malformed payload rejection.
tests/​unit/​transport-unpair.test.ts Removes obsolete shared-PSK unpair coverage.
tests/​unit/​transport-rehandshake.test.ts Tests failure handling, callback isolation, and outbound queuing.
tests/​unit/​transport-harness.ts Adds reusable handshake helpers with PSK categories.
tests/​unit/​transport-activate.test.ts Updates calls to the server-bound handshake helper.
tests/​unit/​noise/​psk.test.ts Tests skipping stored PSKs without a server ID.
tests/​unit/​core-encryption.test.ts Updates integration fixtures with categories and server-bound PSKs.
src/​types.ts Makes configured long-term PSK server IDs required.
src/​core/​transport.ts Implements stricter matching, failure handling, and traffic queuing.
src/​core/​noise/​psk.ts Removes support for unbound long-term PSK records.
src/​core/​core.ts Rejects configured long-term PSKs missing a server ID.
README.md Updates the server ID configuration example.

Review effort: Balanced

@maximmaxim345
maximmaxim345 merged commit 2bdc6da into main Oct 26, 2026
4 checks passed
@maximmaxim345
maximmaxim345 deleted the fix/psk-matching-handshake-failures branch October 26, 2026 11:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breaking-change Changes the public API or the protocol in a way that is not backwards compatible

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants