flutter network_error ai_generated partial

HandshakeException: Handshake error in client (OS Error: CERTIFICATE_VERIFY_FAILED: ok(handshake.cc:393))

ID: flutter/dart-io-ssl-handshake-error

Also available as: JSON · Markdown · 中文
75%Fix Rate
85%Confidence
1Evidence
2023-06-01First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
Flutter 3.10 active
Dart 3.0 active
iOS 16 active
Android 13 active

Root Cause

SSL certificate verification failed, typically due to a self-signed certificate, expired certificate, or missing intermediate CA in the device's trust store.

generic

中文

SSL 证书验证失败,通常由自签名证书、证书过期或设备信任存储中缺少中间 CA 导致。

Official Documentation

https://api.flutter.dev/flutter/dart-io/HttpClient-class.html

Workarounds

  1. 80% success Add the self-signed certificate to the device's trust store, or use a proper CA-signed certificate on the server.
    Add the self-signed certificate to the device's trust store, or use a proper CA-signed certificate on the server.
  2. 70% success If testing only, use a custom HttpClient with badCertificateCallback that validates the specific certificate fingerprint.
    If testing only, use a custom HttpClient with badCertificateCallback that validates the specific certificate fingerprint.

中文步骤

  1. Add the self-signed certificate to the device's trust store, or use a proper CA-signed certificate on the server.
  2. If testing only, use a custom HttpClient with badCertificateCallback that validates the specific certificate fingerprint.

Dead Ends

Common approaches that don't work:

  1. 80% fail

    Disables all certificate validation, creating a security vulnerability and may still fail on some platforms due to other TLS checks.

  2. 90% fail

    The underlying SSL issue persists; retrying without fixing the certificate chain will produce the same error.

  3. 70% fail

    The http package also relies on dart:io's underlying TLS implementation; the error will be identical.