Skip to content

fix(react-native): accept ECDSA push broker certificates on Android - #2186

Merged
ArnabChatterjee20k merged 3 commits into
mainfrom
fix/rn-push-tls-ecdsa
Nov 2, 2026
Merged

ArnabChatterjee20k merged 3 commits into
mainfrom
fix/rn-push-tls-ecdsa

Conversation

@ArnabChatterjee20k

Copy link
Copy Markdown
Member

What

Android Push over TLS refused every broker with an ECDSA certificate, a regression from #2166. Reported on appwrite/sdk-for-react-native#130.

#2166 compared the socket's getPeerCertificate().fingerprint256 with the certificate the native module verified. On Android, react-native-tcp-socket builds that map by casting the public key to RSAPublicKey (getModulus(), getExponent(), in every release up to the latest, 6.4.3). So an ECDSA certificate rejects, and Push never sends CONNECT.

Fix

The fix no longer reads the peer certificate. It pins the certificate instead:

  • verifiedCertificate(host, port) still verifies the chain and the hostname (subjectAltName) as HTTPS does. It now returns the verified leaf as PEM instead of a fingerprint.
  • tcp-stream runs that check before opening the socket, then calls connectTLS({ ca: pem }). The library loads a string ca into a key store holding only that certificate and uses the platform TrustManagerFactory. A server presenting any other certificate fails the handshake, so nothing is written or read before verification.
  • With no pre-verification window left, the inbound buffer, the read pause and the 64 KiB cap are removed. iOS and tlsInsecure are unchanged.

Tests

  • The Node shim now mirrors the library on Android: getPeerCertificate() rejects non-RSA keys, and a string ca is the only certificate trusted.
  • New Push TLS ECDSA certificate check, using a test ECDSA CA and leaf. It replaces flood while verifying, because that window no longer exists. other certificate now pins a different certificate.
  • Robolectric PushTlsTest expects the PEM back, and checks that a trust store holding only that PEM accepts its server and refuses another certificate from the same root.

Run locally: RN format:check, lint, analyse and composer lint-twig pass. All 7 Push TLS checks pass under Node against the generated SDK. The Robolectric test and the full e2e run on CI.

🤖 Generated with Claude Code

ArnabChatterjee20k and others added 3 commits November 2, 2026 17:25
…rtificate

The shim now mirrors react-native-tcp-socket on Android: its peer certificate
is read through an RSA key, so an ECDSA certificate rejects, and a string ca
is the only certificate trusted.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ng the peer's

react-native-tcp-socket builds getPeerCertificate() by casting the key to RSA,
so on Android an ECDSA broker certificate failed verification and Push never
connected. The native module now returns the PEM it verified, and the socket
trusts that certificate alone, so a server presenting any other fails the
handshake before anything is written.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…erver

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ghost

ghost commented Nov 2, 2026 •

Copy link
Copy Markdown

🟢 Tier S · Ready to merge

Android push TLS verification now returns the verified leaf certificate as PEM and pins the subsequent socket handshake to it, avoiding the peer-certificate API that fails for ECDSA keys. The React Native TLS checks and Robolectric tests were updated to cover PEM pinning and ECDSA certificates.

Verdict New comments Fixed Still open
✅ Approved 0 0 0
📂 Walkthrough · 8
File Change
templates/react-native/android/src/main/java/io/package/reactnative/PushModule.kt.twig Return the verified server leaf as PEM after chain and hostname validation.
templates/react-native/src/lib/tcp-stream.ts.twig Verify Android TLS before opening the MQTT socket, pin its TLS handshake, and simplify buffering.
templates/react-native/src/react-native-shim.d.ts.twig Update socket typings and add the PEM CA option.
tests/e2e/Output.php Replace the flood check's expected output with the ECDSA certificate check.
tests/e2e/languages/react-native/android-test/src/test/java/Tests.kt Test the returned PEM and that it alone trusts the matching certificate.
tests/e2e/languages/react-native/push/shims/react-native-tcp-socket/index.js Model single-certificate trust and RSA-only peer-certificate behavior in the Node shim.
tests/e2e/languages/react-native/push/tls-fixtures.js Add ECDSA CA and localhost leaf fixtures.
tests/e2e/languages/react-native/push/tls.node.js Exercise PEM pinning, certificate mismatch, and ECDSA TLS behavior.

Reviewed 61af1ac · Details · Comment @hansi-codes review to re-run, or mention @hansi-codes with a question.

@ghost ghost 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.

🟢 Tier S · Looks good to merge. Summary

@ArnabChatterjee20k
ArnabChatterjee20k merged commit 4f68eac into main Nov 2, 2026
62 checks passed
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