Skip to content

fix(ffi): verify default clients with the OS platform verifier - #511

Merged
kixelated merged 3 commits into
mainfrom
quest/a1/ffi-platform-verifier
Nov 11, 2026
Merged

kixelated merged 3 commits into
mainfrom
quest/a1/ffi-platform-verifier

Conversation

@kixelated

@kixelated kixelated commented Nov 11, 2026 •

Copy link
Copy Markdown
Collaborator

Python, Kotlin and Swift clients using default verification (no server_certificate_hashes, no no_cert_verification) now verify servers with rustls-platform-verifier on the crate's existing provider (rind), so the OS trust store decides on every platform, including iOS and Android. rustls-native-certs is dropped from web-transport-ffi. Follows moq-dev/moq#1968.

Closes #506

Changes

  • rs/web-transport-ffi: the default branch of Client::new installs rustls_platform_verifier::Verifier::new(provider).
  • Android (src/android.rs): exports JNI_OnLoad, which registers the JavaVM and initializes the verifier from ActivityThread.currentApplication(). If the Application is null or a JNI call throws, the error is logged with tracing, the exception is cleared by jni 0.22's attach_current_thread, and the library load still succeeds. Each new default-verification client retries initialization through JavaVM::singleton(). Until initialization succeeds, Android clients trust bundled webpki-roots, and a client built during that fallback keeps them. The fallback is Android-only.
  • Kotlin AAR:
    • A manifest-merged ContentProvider (internal, not exported) calls System.loadLibrary("web_transport_ffi") at startup, after the Application exists. JNA alone never runs JNI_OnLoad. An UnsatisfiedLinkError there is logged rather than crashing startup; JNA still reports it on first use.
    • The verifier's Kotlin component (org.rustls:rustls-platform-verifier:0.2.0) is bundled into the AAR (libs/classes.jar). Gradle downloads it from upstream's GitHub Maven repo (an exclusiveContent repository limited to org.rustls) and checks a pinned SHA-256.
    • A consumer-rules.pro ships the upstream keep rule.
  • Version lock: rustls-platform-verifier-android = "=0.2.0" in web-transport-ffi (ignored by cargo-shear) pins the crate to the Kotlin component version in kt/gradle.properties. If an upgrade needs a different component version, Cargo resolution fails instead of shipping a mismatch.
  • Docs: certificate verification sections in the FFI, Kotlin, Swift and Python READMEs. The FFI README documents the manual Android setup for anyone who packages the library themselves.
  • Quests: deletes quest/a1/ffi-platform-verifier.md and updates the sibling quest/a1/platform-verifier.md, which pointed to it.

Compatibility

  • Public API: unchanged. FFI ClientConfig, the generated bindings, and the Python/Kotlin/Swift wrappers are identical; the only new Kotlin class is internal. No version bump.
  • Behavior change (approved): default verification now goes through the OS platform verifier. On Linux that is still the system CA bundle (via webpki), but Client() now fails at construction with InvalidArgument("platform verifier: No CA certificates were loaded from the system") when no system CA certificate can be loaded. Before, construction succeeded and every connection failed. On macOS/Windows/iOS the OS verifier also applies OS policy (enterprise roots, distrust, revocation where supported). Android apps now load libweb_transport_ffi.so at app startup instead of on first use.
  • Wire: unchanged.

Choices made without asking

  1. Bundle the classes instead of declaring a Maven dependency. Upstream publishes the component only to a GitHub-hosted Maven repo, so a POM dependency would make every consumer add that repo. Trade-off: an app that also gets org.rustls:rustls-platform-verifier from another Rust library will hit duplicate classes.
  2. Leave out upstream's manifest and network security config. The upstream AAR sets android:networkSecurityConfig on <application>, which would conflict with apps that set their own, and sets cleartextTrafficPermitted="false" app-wide. It exists only so best-effort CRL fetches can use HTTP. The Kotlin verifier uses PKIXRevocationChecker.Option.SOFT_FAIL, so the cost is weaker best-effort revocation, not failed verification.
  3. Use a ContentProvider to call System.loadLibrary. It runs before Application.onCreate and after currentApplication() is set, so JNI_OnLoad succeeds on its first try in normal apps. Apps can remove it with tools:node="remove"; the per-client retry then still covers clients built after the first explicit System.loadLibrary.
  4. Fail construction when the platform verifier can't initialize (moq's behavior), instead of deferring the failure to connect.

Verification

Ran locally:

  • just check and just test: pass. That includes new default_verification_rejects_untrusted_server, which asserts that a default client rejects a self-signed loopback server with UnknownIssuer.
  • cargo clippy -p web-transport-ffi --lib -- -D warnings for aarch64-linux-android, armv7-linux-androideabi and aarch64-apple-ios, using a rustup toolchain isolated under .tmp/ (the Nix shell has no Android/iOS std): clean.
  • Linked a release libweb_transport_ffi.so for aarch64-linux-android with NDK 30 (from nixpkgs androidenv): JNI_OnLoad is exported.
  • gradlew -Pandroid.enabled=true :web-transport:assembleRelease :web-transport:lintRelease with that SDK: the AAR contains the provider in its manifest, proguard.txt with the keep rule, the org.rustls.platformverifier classes in libs/classes.jar, and the .so. Lint reports only the pre-existing AGP/JNA version warnings.
  • just test-kotlin (packaged JVM JAR smoke): passes.
  • Python wheel tests: 174 passed. The browser interop tests were deselected because Playwright doesn't support Ubuntu 26.04 (the known wheel failure).

Not exercised at runtime: nothing ran on an Android device/emulator or on iOS/macOS. In particular, these are untested: JNI_OnLoad initialization through currentApplication(), the ContentProvider ordering, the per-client retry and webpki fallback, verification through Android's TrustManager using the bundled Kotlin classes, R8 with the keep rule, and Apple SecTrust verification. CI here has no emulator or simulator. The Swift runtime macOS job will exercise the host macOS build, but not default verification.

Suggested follow-ups

  • An Android instrumented test (emulator job) covering default verification against a trusted and a self-signed server.
  • Consumer keep rules for JNA and the UniFFI-generated classes. The AAR ships none today, so R8-minified apps may already break independently of this change.

🤖 Generated with Claude Code

(Written by Claude Opus 5.5)

kixelated and others added 2 commits November 11, 2026 00:21
Python, Kotlin and Swift clients without certificate hashes or disabled
verification now verify with rustls-platform-verifier on the crate's
provider instead of rustls-native-certs, which finds no roots on iOS or
Android.

On Android, JNI_OnLoad initializes the verifier from
ActivityThread.currentApplication(), and each new client retries until it
succeeds, trusting bundled webpki-roots meanwhile. The AAR loads the
library through System.loadLibrary from a startup ContentProvider (JNA
skips JNI_OnLoad), bundles the verifier's Kotlin component, and ships its
keep rule.

Closes #506

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kixelated kixelated changed the title Verify FFI clients with the OS platform verifier fix(ffi): verify default clients with the OS platform verifier Nov 11, 2026
@kixelated
kixelated marked this pull request as ready for review November 11, 2026 08:51
@coderabbitai

coderabbitai Bot commented Nov 11, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 44 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 2 included reviews currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: b265cd13-ef7a-4dba-8ce3-0d2faaa515a3
Commits

Reviewing files that changed from the base of the PR and between 9834ac3 and 042b2f7.

Files selected for processing: 18

  • kt/README.md
  • kt/gradle.properties
  • kt/settings.gradle.kts
  • kt/web-transport/build.gradle.kts
  • kt/web-transport/consumer-rules.pro
  • kt/web-transport/src/androidMain/AndroidManifest.xml
  • kt/web-transport/src/androidMain/kotlin/dev/moq/webtransport/NativeLibraryInitializer.kt
  • py/web-transport/README.md
  • quest/a1/README.md
  • quest/a1/ffi-platform-verifier.md
  • quest/a1/platform-verifier.md
  • rs/web-transport-ffi/Cargo.toml
  • rs/web-transport-ffi/README.md
  • rs/web-transport-ffi/src/android.rs
  • rs/web-transport-ffi/src/client.rs
  • rs/web-transport-ffi/src/lib.rs
  • rs/web-transport-ffi/src/test.rs
  • swift/README.md
  • 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

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-11T19:40:29.315933Z 042b2f7 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@kixelated

Copy link
Copy Markdown
Collaborator Author

Merge summary:

  • Merged main into the branch (merge 042b2f7). The only conflict was in quest/a1/README.md: this PR removes the FFI platform verifier link, and main removed the package-selection link when Document package and backend selection #501 finished it. Both are now gone. just check and cargo test -p web-transport-ffi pass locally.
  • The optional wheel failure is fixed by fix(py): run the browser test on Ubuntu 26.04 #517, which this merge picks up.
  • The design is accepted as is: the startup ContentProvider, the bundled verifier Kotlin classes, the =0.2.0 pin, and failing at Client() construction on Linux when no CA bundle exists. chatgpt-codex-connector reviewed the new head.
  • Suggested follow-up: on-device testing of platform verification on iOS and Android, since none was done here.

(Written by Claude Opus 5.5)

@kixelated
kixelated enabled auto-merge (squash) November 11, 2026 19:44
@kixelated
kixelated merged commit 840c2f6 into main Nov 11, 2026
33 checks passed
@kixelated
kixelated deleted the quest/a1/ffi-platform-verifier branch November 11, 2026 19:58
@moq-bot moq-bot Bot mentioned this pull request Nov 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support for platform verifier?

1 participant