Skip to content

chore(relay): prove and check the relay identity with @noble/curves instead of tweetnacl - #4814

Merged
devswha merged 4 commits into
mainfrom
chore/tweetnacl-to-noble
Nov 26, 2026
Merged

devswha merged 4 commits into
mainfrom
chore/tweetnacl-to-noble

Conversation

@devswha

@devswha devswha commented Nov 26, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • The relay server proof (shared/relay-server-proof.ts) and the saved relay identity check (server/relay/identity.ts) now use @noble/curves x25519 and equalBytes instead of tweetnacl's scalarMult, box.keyPair and verify. Tests that made X25519 key pairs with tweetnacl use x25519.keygen().
  • Before the switch, a first commit pins the bytes with tweetnacl: RFC 7748's key pairs give the same server_id and the same proof answer to a fixed challenge (also with the relay key's top bit set), low-order keys (u = 0, u = 1) are refused on both sides, and an identity.json an earlier version saved still loads. The same tests pass after the switch, so old PCs and old relays keep agreeing with new ones byte for byte.
  • Low-order keys: noble refuses them before the ladder; the proof keeps its own invalid proof public key error, and the relay still closes such a PC with invalid server key.

Why tweetnacl stays in package.json

The vendored paseo code (shared/vendor/paseo-e2ee/crypto.ts, "Do not edit; update by re-vendoring") imports tweetnacl, and upstream paseo still does. So the dependency and its THIRD_PARTY_NOTICES line stay; only Ovis's own code moves to @noble/*.

Deploy

shared/relay-server-proof.ts is bundled into the relay. After merge, relay and relay-ap need a deploy of the same commit (maintainer approval). This PR does not deploy anything. Old and new relays/PCs interoperate (pinned by the byte tests), so the deploy is not urgent.

Validation

  • Fixture tests on tweetnacl (commit 1): bun test shared/relay-server-proof.test.ts server/relay/identity.test.ts - 28 pass.
  • After the switch: bun test shared/relay-server-proof.test.ts server/relay/ relay/ shared/account-service-fake.test.ts shared/relay-e2ee (path filters also picked up src/lib/relay/) - 1555 pass; 6 fails in src/lib/relay/*contract* and review-alarm-p15 under that mixed run, which pass alone on this branch and on origin/main (41/41 each).
  • bun run typecheck - clean.
  • bun scripts/relay-e2e-regression.ts (this checkout) - PASS.
  • bun scripts/relay-e2e-regression.ts --skew v0.5.10 (two v0.5.10 PCs, still on tweetnacl, through this branch's relay and shell), rerun at load ~80/128: the whole journey passes (pairing, the control and data server proofs, terminal, roster, reload, relay lost and back, storage, network, revoke, CSP). The run then fails in the media part, waiting for private-notes.md in the file browser; origin/main (7751232) fails at the same step under the same command, so that is a v0.5.10 skew gap, not this change. Two earlier runs at load 190 and 65-85 timed out earlier, at sidebar steps, after the proofs had passed.
  • bun run check fast - ran on old-desktop (this PC was over 85% CPU): every step ok except one unit test, server/account/device-journal.test.ts G15, which timed out at 31 s in the parallel run; it passes alone on this branch and on origin/main (16/16 each) and this PR does not touch it. Unit: 28742 pass, 1 fail.
  • Codex adversarial review (gpt-6.2-sol-fast, xhigh): no HIGH or MEDIUM. Three LOWs: (1) noble's BigInt X25519 is less uniform in timing than tweetnacl on the PC's long-lived key; the vendored Noise channel already runs noble x25519 on that same key, so this adds no new exposure. (2) noble's x25519 draws randomness while deriving the public key, so a broken crypto.getRandomValues would now make a saved identity unreadable; not reachable in a working runtime. (3) No test pinned the masked top bit of the relay's key; fixed with a test that a top-bit key gives tweetnacl's answer. Codex also ran 42 mixed old/new exchanges and 777 accepted proof cases, 294 low-order refusals and 512 identity parser cases, and old and new agreed on all of them.

@coderabbitai

coderabbitai Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Explain Change →

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review

No actionable comments were generated in the recent review.

Summary

Summary by CodeRabbit

  • Bug Fixes
    • Existing relay identities remain compatible when loaded, with their keys preserved.
    • Relay server proofs continue to work consistently, and invalid public keys are rejected during proof creation and verification.
    • Proof validation continues to check that proofs match the connection and client identity.

Relay identity and server-proof code now use Noble X25519 instead of TweetNaCl. The changes retain a test for loading a saved version-1 identity and add server-proof compatibility and invalid-key tests.

Changes: Relay X25519 migration

Layer / File(s) Summary
Server-proof derivation and verification
shared/relay-server-proof.ts, shared/relay-server-proof.test.ts, relay/server-proof.test.ts
Proof code uses Noble X25519 for shared-secret derivation and ephemeral key generation. It maps derivation errors to invalid proof public key and compares proof bytes with equalBytes. Tests cover fixed proof vectors, binding to connection ID and PC secret, top-bit compatibility, and low-order keys.
Identity key-pair validation
server/relay/identity.ts, server/relay/identity.test.ts
Identity loading derives the public key from the saved secret key and compares it with the stored public key. A compatibility test checks that a version-1 RFC 7748 key pair loads unchanged.
Relay test key generation
relay/relay-test-client.ts, shared/account-service-fake*.test.ts
Relay test clients and account-service test helpers use x25519.keygen() to generate key pairs.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Refactor

Merge Risk: Minimal · previous review fa0a5

This change moves relay proof and identity key handling to a different X25519 library, with tests meant to keep derived IDs, proofs and saved identities unchanged. No concrete defect was found. The risk is low, though the author asks for relay and relay-ap to be deployed together.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: relay proof and identity checks move from tweetnacl to @noble/curves. It matches the summary and objectives. The chore(relay) prefix is accurate and the title is one s…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Description check Passed The description covers the change, why tweetnacl remains in package.json, the deploy requirement, and validation results. It uses the required Change and Validation headings. The change is a refactor,…
Full details: Title check

Explanation

The title names the main change: relay proof and identity checks move from tweetnacl to @noble/curves. It matches the summary and objectives. The chore(relay) prefix is accurate and the title is one sentence.

Full details: Description check

Explanation

The description covers the change, why tweetnacl remains in package.json, the deploy requirement, and validation results. It uses the required Change and Validation headings. The change is a refactor, so the missing issue link is not a blocker. The change does not affect HTTP or WebSocket behavior, so the missing contract-test note is not a blocker. The description omits the changelog.d entry required by CONTRIBUTING.md.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 7751232 and fa0a546.

Files selected for processing: 8

  • relay/relay-test-client.ts
  • relay/server-proof.test.ts
  • server/relay/identity.test.ts
  • server/relay/identity.ts
  • shared/account-service-fake.list.test.ts
  • shared/account-service-fake.test.ts
  • shared/relay-server-proof.test.ts
  • shared/relay-server-proof.ts

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 2 remain after this review.

@devswha
devswha merged commit c2ccf2b into main Nov 26, 2026
21 checks passed
@devswha
devswha deleted the chore/tweetnacl-to-noble branch November 26, 2026 15:03
@devswha

devswha commented Nov 26, 2026

Copy link
Copy Markdown
Owner Author

Merged through pr-merge at head a2202db91. Seen before the merge was asked for: required checks green, no unresolved thread, no conflict, no hold, main not red, no release in progress. CodeRabbit said it did not review (a limit or a skip) since this head.

main moved but untouched: merged without update. Its new commits up to 7d1d71a6c change no file of this pull request, none imported by one, nothing that decides which checks run, and no core path.

Reviews: omo gate (dori review) CLEAR at fa0a546; Codex adversarial review (gpt-6.2-sol-fast, xhigh) found no HIGH or MEDIUM, its one LOW test gap fixed in fa0a546; CodeRabbit reviewed the head. Merged on Dori's (lead) word after the 0.5.11 release freeze lifted.

devswha added a commit that referenced this pull request Nov 26, 2026
…ect socket refused as full (#4850)

## What

Refs #3243: fixes its reproduced lockout (part 1's counting) and part 2.
Its remaining item, a deadline for carriers an app never kept, is moved
to #3310: a server-only timer closed live race winners in #3306, so it
needs an app-to-PC "kept" signal first.

1. **One device's racing carriers no longer lock another device out**
(`server/relay/admissions.ts`). With every place taken, a device already
at its share of sessions always gets a racing carrier in, with up to
three of its own (its oldest gives way past that). Before, at most three
carriers in all could get past every place. So device A holding three
unused carriers made device B's replacements close, even though B would
have replaced its own oldest session (the #3243 reproduction). This is
the part of closed #3306 that never had a reproduced problem. None of
#3306's give-way rules come back: no carrier of one device is ever
closed for another.
- Bound: 8 places plus 3 racing carriers for each device at its share.
Only devices that already hold four sessions can grow, so at most 14
entries, and 7 per device key.
2. **A direct socket refused because a closing one still holds the
plugin's place now waits for it** (`src/lib/relay/directSocket.ts`).
Both OvisDirect plugins refuse an open with `too_many` until they report
a close; iOS counts a closing socket for up to 5 s. A socket from an
earlier race or probe that was still closing therefore made the next
race's or probe's socket fail. Now a socket refused `too_many` stays
connecting on the page and is asked for again once the plugin reports a
close. If a close arrived while the refused ask was on its way, it is
asked again at once. A socket the page gives up while it waits ends with
1006 and never reaches the plugin.
- The background PC sweep (`shell.tsx`, `createPcSweep`) opts out of
waiting (`waitForPlace` false), so it never takes a freed place ahead of
a connection the user is waiting for.
- The page does not count sockets itself: the plugins' own limits stay
the authority (Android: two open, four with closing ones), so nothing is
held back that the plugin would accept.

No HTTP/WS contract changes. Nothing under `relay/` changes, so **this
PR needs no relay or relay-ap deploy** (the pending #4814 deploy is
unaffected).

## Validation

- Failing first: the two new `server/relay/direct.contract.test.ts`
cases fail on origin/main's `admissions.ts`, and the new
`directSocket.test.ts` case fails on origin/main's `directSocket.ts`.
All three pass with this change.
- Focused: `server/relay/direct.contract.test.ts` 59,
`server/relay/link.test.ts` 21, `src/lib/relay/directSocket.test.ts` 13,
`transport.direct.test.ts` 23, `transport.test.ts` 60, `pcSweep.test.ts`
14, and the `shell*.test.tsx` files (1,000+). All pass. `bun run
typecheck` is clean.
- `bun run check fast`: workflow syntax, generated types and themes,
typecheck and build ok; unit tests 28,797 pass, 25 fail in four files
(`tui/testing/entry-pty.test.ts`, `server/usage-login-outcome.test.ts`,
`server/usage-account-list.test.ts`,
`server/usage-login-private.test.ts`). Each fails the same way on
origin/main (4fae1e7) on this PC, which has no PTY host ("the Rust PTY
host cannot run here"); `usage-login-private` also hangs there past 90
s. None touches this change. After rebasing onto 1b0066f: the focused
files above and `bun run typecheck` pass again.
- `bun scripts/relay-e2e-regression.ts`: PASS. `--skew v0.5.11` (two
v0.5.11 PCs through this branch's shell and relay): PASS, media browser
QA included.

## Reviews

One adversarial Codex review (gpt-6.2-sol-fast, xhigh) of the first
version, then one fix round:

- MEDIUM, Android: page-side counting of closing sockets held back opens
that Android's plugin (2 open / 4 total) would accept. **Fixed:** the
page no longer counts and retries only after the plugin's own
`too_many`.
- MEDIUM, sweep priority: a queued background sweep could take the freed
place ahead of a foreground connection. **Fixed:** the sweep does not
wait.
- MEDIUM, iOS listener loss: if Capacitor dropped listeners while the
page survived, page-side counting could stall forever. **Fixed** by the
same change; without close events it behaves as before (refused).
- LOW: a throwing `onclose` stranded a place. **Fixed** (the close is
handled in a `finally`). A send-overflowed (1009) socket waiting for a
place no longer reaches the plugin.
- MEDIUM, server, **not changed here:** unused carriers of a device at
its share can stay after that device's sessions in use close, so a third
device may wait while places hold unused carriers. That is #3310's class
(the server cannot tell a kept but idle carrier from a loser), and every
server-only rule tried in #3306 closed live winners. It is bounded at 14
entries and 7 per key, and left to #3310.
@devswha devswha mentioned this pull request Nov 27, 2026
devswha added a commit that referenced this pull request Nov 27, 2026
Release 0.5.12 from `main` on the maintainer's go in the Dori session
2026-11-27 ("ㄱㄱ", to "release 0.5.12 and build Android 1.0.9 and iOS
1.0.4 from the same tag, up to internal testing"). It ships what `main`
holds at 12e9a21 (0d2c3c3, then #4883 on the maintainer's screen OK,
its fragment folded by hand): 79 commits since v0.5.11.

- `package.json` and `herdr-plugin.toml`: 0.5.11 -> 0.5.12.
- `REMOTE_BUNDLE_VERSION` 55 -> 56 (`shared/machines.ts`). After this
merges, `remote-v56` is tagged on the merge commit and **Remote PC
bundles** publishes it before the Release run.
- `CHANGELOG.md`: `bun scripts/changelog-fold.ts 0.5.12` folded 62
fragments (69 entries). `by @login` credits were added to the 22 links
of PRs from outside contributors: @todor-a, @chung-song, @jimbb,
@mdobro, @YuuuXie, @tung-dnt, @knightnemo, @Danipulok, @odfalik,
@iyuzhang, @ricardofelixb, @jiaoningbo, @imurfutur3.
- `release-summaries.json`: 0.5.12 in en, ko, ja and zh: 4 new, 4
improved, 5 fixed. Each English line is at most 70 characters.
- Android 1.0.9 (17) (`app/android/app/build.gradle`,
`app/store/android.md`) and iOS 1.0.4 (13) (`project.pbxproj`,
`app/store/ios.md`): both store builds are made from the v0.5.12 tag for
internal testing only.

## Checklist
1. Account service: production runs 26eabfd. The app's account routes
since v0.5.11 (`/v1/identities`, `/v1/identities/link`,
`/v1/safety-records`, ...) are all served there. Nothing on main reads
the `history` that ovis-sh/account#79 (migration 0040) adds. No deploy;
#79 waits for the maintainer.
2. Relay: since v0.5.11 only #4814 changed
`shared/relay-server-proof.ts`, swapping tweetnacl for @noble/curves.
The math is the same (X25519 shared secret, HMAC-SHA256 over the same
message), and low-order keys are still refused, so a 0.5.12 PC answers
the deployed relay's challenge as before. #4850 changes the PC and shell
side only. No relay deploy; #4814's deploy waits for the maintainer.
3. `MIN_SUPPORTED_CLIENT_VERSION` stays 0.4.20.

## Contract diff v0.5.11..main
Additive only. No HTTP route, WebSocket message `type` or relay frame
was removed or renamed, and `WIRE_VERSION`, `RELAY_PROTOCOL` and
`BRIDGE_PROTOCOL` are unchanged.
- `attach` and `pane-geometry` gain an optional `windows_fit`.
- `PaneSummary` gains an optional `copilot_processing`.
- `PUT /api/preferences` takes an optional `expected_revision` and
answers 409 `revision_conflict` only when it is given. A 0.5.11 server
ignores that key, and ignores the new `markdownStyle` setting, so a
0.5.12 shell on a 0.5.11 PC saves settings as before.
- Read with `git diff v0.5.11 origin/main -- shared/ server/`. No skew
test was run.

## Validation
- `bun run check fast` at 05480b3: every step ok (unit: 29194 pass, 0
fail, 259 skip).
- `bun scripts/release-guards.ts --base origin/main`: "Release 0.5.12:
remote bundle, telemetry Worker and release metadata are in order."
- `bun scripts/release-notes.ts 0.5.12` renders the notes.
- The release-notes, guard and app version tests: 180 pass, 0 fail.
- After merging main 12e9a21 (#4883) and folding its fragment: `bun
run check fast` at 3417dd7, every step ok (unit: 29198 pass, 0 fail,
259 skip).
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.

1 participant