Skip to content

Use native libsodium for iOS crypto on Node 24 - #3542

Merged
holmesworcester merged 8 commits into
developfrom
experiment/ios-native-libsodium
Sep 21, 2026
Merged

holmesworcester merged 8 commits into
developfrom
experiment/ios-native-libsodium

Conversation

@holmesworcester

@holmesworcester holmesworcester commented Sep 15, 2026 •

Copy link
Copy Markdown
Collaborator

iOS runs costly curve operations in the existing libsodium JavaScript fallback. This adds a small Node-API binding that calls upstream libsodium directly for Ed25519 key generation/sign/verify, X25519 public-key derivation, and box encryption/decryption. The production backend activates it after ready; failed startup checks retain the existing implementation.

Targets develop after merged #3423: unreleased React Native 0.81.5/New Architecture and embedded Node 24.18.0. Related to #3536 and the native-crypto portion of #3539. Message indexing and auth-cache changes from #3539 are separate.

The official libsodium 1.0.19 source is SHA-256 pinned and compiled without modifications. Our additions are the 142-line C boundary, a 106-line API adapter, and build/embedding tooling. The version matches the existing wrapper core. ARM64 device/simulator frameworks are built from source, checked for stale/corrupt cache artifacts, embedded with the license, and signed. The writable cache manifest is not authenticated build provenance. Only the two Node-API entry symbols are exported. The device executable adds about 245 KiB before app signing/compression.

Validation

All 33 app E2E tests passed again after the audit fix, before pushing, with zero skips:

  • 25/25 starter tests and 1/1 backend message acknowledgment/restart test.
  • 1/1 QSS registration, storage, invitation, and restart test; server log count/sequence advanced from 3 to 4.
  • 6/6 desktop + iOS multiplayer stages: joining/history with iOS stopped, online messages both ways, offline retrieval with sender processes stopped in each direction, and persistence of all five messages after another restart.

The latest run rebuilt the backend, desktop peer, and iOS QSS app. All four suites use ios.sim.e2e.qss; starter and native-community choose no server. The original staging run is retained in the evidence. The running app loaded the native framework and the updated backend bundle; captured logs contain zero fallback warnings.

  • Full Mac Node 20 native suite: 17/17 passed, including the new falsy-format regression, all 151 Ed25519 and 518 X25519 differential vectors, malformed buffers, activation/fallback, cache corruption, and actual webpack loading.
  • Earlier upstream host make check, Linux Node 24 host tests, both iOS framework builds, embedding/cache/signing checks, and 11 iOS workflow checks passed.
  • Actual embedded Node 24 simulator probe: 12/12 in each of two earlier runs, including all 669 vectors and asserted native calls through the production webpack rule.
  • Simulator microbenchmark: 1,000 fixed-message signature verifications took 29.5 seconds through the existing wrapper and 44.4 ms natively. This measures the primitive, not full message latency.

Daybreak Blue audit

The independent Daybreak Blue subagent found one low-severity output-format compatibility difference. The fix now matches the wrapper’s defaults for every falsy format, with a regression across all five output-producing operations. Daybreak independently re-ran the focused native/webpack suite (16/16) and accepted the fix with no remaining findings. It reported no medium/high findings and clarified the cache/signing trust boundary. Its app-evidence review did not independently repeat the Mac app tests.

Audit report, latest E2E evidence, and implementation report record source hashes, reproduction instructions, and scope. Physical iPhone message/lifecycle validation, release signing/distribution, production libsodium version selection, and integration with #3539's other optimizations remain pending.

Pull Request Checklist

  • Linked to a related GitHub issue.
  • Added a root changelog entry.
  • Mobile E2E tests passed.
  • Updated visual-regression screenshots (no UI changes).

Physical phone and Tor desktop tryout (September 16)

A development-signed Release build is installed on an iPhone 16e / iOS 18.5. It launches with bundled JavaScript, and the user confirmed it appears to work. A matching Linux desktop is available for manual Tor messaging and lifecycle checks with QSS/QPS disabled. Both packaged apps contain the same backend bundle as the passing post-audit E2E run. This update changes reports only.

Physical native-library mapping was not independently confirmed, and physical multiplayer/lifecycle results are not asserted. Phone push notifications are unavailable without Firebase configuration. Installation and desktop evidence records the checks and limitations.

Develop integration — 2026-09-21

Fresh develop integration retains auth 17e0b5b and current security/QSS changes. Rebuilt pinned libsodium from source with upstream make check; all 17 native binding/webpack/cache tests pass on both Node 20.20.1 and 24.21.0, including all 669 crypto vectors. Eleven iOS workflow tests pass. Prior native iOS evidence remains applicable to the feature implementation; Apple builds were not repeated on this Linux host.

@holmesworcester

Copy link
Copy Markdown
Collaborator Author

Manual physical-device Tor/lifecycle result

The user reports that, apart from the initial connection lag, Tor appears to work across lifecycle transitions between the physical iPhone and the matching Linux desktop. Reconnecting was substantially faster than the initial join. This was Tor-only testing; the community has QSS disabled.

The captured logs quantify the initial delay:

  • Phone join requested at 08:57:19 UTC; joined at 09:07:07 UTC: approximately 9 minutes 48 seconds.
  • Before the first connection, the phone made 23 dial attempts, with 22 failed onion-service lookups. Tor repeatedly reported: resolve failed. Fetch status: No more HSDir available to query. Quiet retried with delays increasing from 8 to 20 seconds.
  • Both Tor instances had bootstrapped before the join. Once the peer connection was established, the join completed in approximately 3.6 seconds.
  • Two subsequent foreground resumptions reconnected in approximately 17.5 seconds and 2.8 seconds. The phone reported that its existing Tor session and hidden-service state were preserved.

The initial bottleneck is narrowed to onion-service discovery/reachability. Current logs do not distinguish delayed publication of the desktop's fresh onion descriptor from a problem retrieving it on the phone; the desktop does not currently retain the relevant Tor publication events. That initial delay remains a follow-up item.

This is user-reported manual lifecycle validation supported by captured logs. Raw logs, onion addresses, peer identifiers, and invitation data are kept private.

@holmesworcester holmesworcester added the 11.2 React Native 0.81, New Architecture, Node 24, Electron 44 and native iOS crypto label Sep 17, 2026
@holmesworcester
holmesworcester changed the base branch from upgrade/react-native-new-architecture-node to develop September 21, 2026 14:42
@holmesworcester
holmesworcester marked this pull request as ready for review September 21, 2026 14:43
@holmesworcester
holmesworcester merged commit 7c5202f into develop Sep 21, 2026
44 of 49 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

11.2 React Native 0.81, New Architecture, Node 24, Electron 44 and native iOS crypto

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant