TLS handshake failure on Android API < 21 with Xamarin.Android HttpClient
0 reputation · 20 May 2023, 03:25 UTC
TLS handshake failure on Android API < 21 with Xamarin.Android HttpClient
When a Xamarin.Android app uses HttpClient to connect to a TLS‑1.2‑only endpoint on devices running API 19 or 20, the request frequently fails with an SSL handshake exception. The failure occurs even though the OS kernel supports TLS 1.2, because the default AndroidClientHandler (wrapping java.net.HttpURLConnection) does not enable the protocol by default. The managed handler, which relies on ServicePointManager, also cannot guarantee TLS 1.2 usage on these API levels.
The goal is to determine a reliable configuration that guarantees a TLS 1.2 handshake without duplicating writes or relying on server‑side idempotency. Constraints include the handler selection logic, the version of Xamarin.Android, and the fact that ServicePointManager.SecurityProtocol only affects the managed handler.
Unresolved questions:
- Which HttpClient handler should I use to reliably enforce TLS 1.2 on API 19/20?
- Does setting ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 affect AndroidClientHandler behavior?
- Is there a supported way to configure AndroidClientHandler with a custom SSLContext to enable TLS 1.2?