Skip to content

Fix Validate and bound TLS and QUIC certificate probes - #213

Merged
2dust merged 1 commit into
2dust:mainfrom
OneMiny:fix/tls-quic-certificate-probes
Nov 30, 2026
Merged

2dust merged 1 commit into
2dust:mainfrom
OneMiny:fix/tls-quic-certificate-probes

Conversation

@OneMiny

@OneMiny OneMiny commented Nov 29, 2026

Copy link
Copy Markdown
Contributor

Problem

Certificate fingerprint discovery in FetchTlsCertSha256 and FetchQuicCertSha256 had inconsistent timeout and input handling. In QUIC, DNS could outlive the request deadline, a zero or omitted timeout expired the request immediately, and a DNS name could reach the server without SNI. Bracketed IPv6 addresses also failed to dial. Malformed fields could reach DNS or the transport before they were rejected.

Fix

  • Trim and validate the address, SNI, port and timeout before networking. Normalize bracketed IPv6 literals. Port 0 selects 443, timeout 0 selects five seconds, and the maximum timeout is 60 seconds.
  • Use one context deadline for native DNS resolution, dialing and handshaking. Release the probe sockets after the attempt.
  • Use the original DNS hostname for QUIC SNI when the caller leaves SNI empty. Preserve a valid explicit SNI and keep support for TLS 1.2, TLS 1.3 and QUIC over TLS 1.3.
  • Keep both exported method signatures, the JSON response, and the SHA-256 hash of the peer's leaf certificate. The fingerprint is for manual pinning and should be verified against a trusted source before it is saved.
Scenario Before After
Direct native QUIC probe with a hostname and empty SNI The VPS rejected the handshake Returned the SHA-256 of the intended leaf
Bracketed IPv6 with valid explicit SNI 0 of 10 profile modes returned the expected hash 10 of 10 returned the expected hash
Native QUIC timeout omitted or zero Timed out immediately on the VPS test Returned the expected hash with the five-second default
Stalled DNS with a 100 ms QUIC deadline Still running after the two-second test guard Reported a timeout at about 100 ms
SNI containing a port, an embedded endpoint port, or an out-of-range port or timeout Reached DNS or the handshake, or returned a lower-level error Returned an input error before dialing
Valid TLS 1.2, TLS 1.3 and QUIC with explicit SNI Returned the expected leaf hash Returned the same hash
Stalled TLS and QUIC handshakes with a 220 ms timeout Timed out at about 223 ms Timed out at about 223 ms

Related v2rayNG PR

The app PR preserves the profile's hostname as SNI when Android DNS resolves it to an IP or leaves lookup to the native resolver. It also rejects invalid explicit ports before DNS. 2dust/v2rayNG#6553

Passing the hostname from the app matters because JNI may already receive only an IP address. This library PR can infer SNI when the native request still contains a hostname. Its DNS deadline, IPv6 handling, and input validation also apply to other native callers. Each patch was tested with the other project's official version and can be merged independently.

Verification

  • The four Go certificate probe test groups passed ten shuffled runs with the race detector. go vet passed. The test fixture was supplied by an external overlay.
  • The Android ARM64 build passed three Go test runs on a Android 12. The VPS comparison used the Kotlin/JNI call path on the same phone and an ADB relay to reach TLS and QUIC endpoints. The library-only variant used the official app. With the companion app patch applied, the isolated and integrated library builds matched in all 193 cases.
  • The submitted patch applies independently to upstream and changes only libv2ray_certSha256.go. Its production source matches the tested revision byte for byte.

@2dust
2dust merged commit b80e254 into 2dust:main Nov 30, 2026
1 check 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