Skip to content

Fix Preserve SNI when fetching certificate fingerprints - #6553

Merged
2dust merged 1 commit into
2dust:masterfrom
OneMiny:fix/certificate-fingerprint-sni
Nov 30, 2026
Merged

2dust merged 1 commit into
2dust:masterfrom
OneMiny:fix/certificate-fingerprint-sni

Conversation

@OneMiny

@OneMiny OneMiny commented Nov 29, 2026

Copy link
Copy Markdown
Contributor

Problem

When a user enters a DNS hostname, leaves SNI blank and selects Fetch certificate fingerprint, v2rayNG may resolve the hostname to an IP before it calls JNI. The IP reaches the native probe without the original hostname for SNI. A server that requires SNI can reject the handshake. A server that serves a fallback certificate can return its fingerprint instead, and saving that pin can break the profile's connection.

QUIC also failed to select the intended certificate in the test where Android left the hostname for native DNS. Some invalid explicit ports silently fell back to 443.

Fix

  • When explicit SNI is absent, send the profile's original hostname as SNI whether Android DNS returns an IP or leaves lookup to the native resolver.
  • Trim and honor valid explicit SNI. An IP-only profile still needs an explicit DNS name if its server requires SNI. Keep Android's existing IPv4 and IPv6 preference.
  • Reject invalid explicit ports before DNS. Use 443 for a blank or omitted port. Keep the JNI request format and run with the official AndroidLibXrayLite.
Scenario Before After
Domain with blank SNI, strict SNI endpoint 0 of 10 matching leaf fingerprints 10 of 10 matching leaf fingerprints
Domain with blank SNI, endpoint serving a fallback certificate 10 of 10 returned the fallback fingerprint 10 of 10 returned the intended leaf fingerprint
Hostname left for native DNS, five QUIC modes 0 of 5 matching leaf fingerprints 5 of 5 matching leaf fingerprints
Valid explicit SNI 10 of 10 matching leaf fingerprints 10 of 10 matching leaf fingerprints
Five invalid explicit ports None rejected by the request builder before DNS All five rejected before DNS
Blank or omitted port Used 443 Used 443

Verification

  • Ran the Kotlin caller and real JNI on a Android 12 against TLS and QUIC endpoints on a VPS, using an ADB relay. Checked the returned hashes against the VPS certificates. Coverage included VMess, VLESS, Trojan, and Shadowsocks over TLS, Hysteria2 over QUIC, and MASQUE with default, HTTP/2, HTTP/3, mixed, and other ALPN values.
  • Three external JUnit checks passed for hostname preservation across DNS outcomes, explicit SNI and an IP literal, and port validation before DNS.
  • The submitted patch applies independently to upstream and changes only CertificateFingerprintManager.kt. Its production source matches the tested revision byte for byte.

@2dust
2dust merged commit fe33251 into 2dust:master Nov 30, 2026
2 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.

2 participants