dart-lang / http

A composable API for making HTTP requests in Dart.
https://pub.dev/packages/http
BSD 3-Clause "New" or "Revised" License
1.01k stars 351 forks source link

HandshakeException: Handshake error in client (OS Error: CERTIFICATE_VERIFY_FAILED: unable to get local issuer certificate(handshake.cc:359)) #627

Open mryogi1976 opened 2 years ago

mryogi1976 commented 2 years ago

HandshakeException: Handshake error in client (OS Error: CERTIFICATE_VERIFY_FAILED: unable to get local issuer certificate(handshake.cc:359))

I have 4 apps live on Google Play Store from last few months , yesterday all stopped working because of above error.

I did not understand the cause of above error and no solution found til now.

Could anybody suggest. I am using http: ^0.13.3 in my one of the app , It comes in http.post method.

eximius313 commented 1 year ago

So to sum it up:

  1. Cold boot your emulator and verify it has correct time (source1 and source2)
  2. Disable VPN (source)
  3. Change WiFi connection (source)
  4. Wipe your emulator (or if it doesn't work - delete and recreate it) (source)
  5. load cert https://letsencrypt.org/certs/lets-encrypt-r3.pem (source):

main.dart:

Future<void> loadCerts() async {
  final certs = [
    'assets/ca/lets-encrypt-r3.pem'
  ];
  for (var cert in certs) {
    final certBytes = await PlatformAssetBundle().load(cert);
    SecurityContext.defaultContext.setTrustedCertificatesBytes(certBytes.buffer.asUint8List());
  }
}

pubspec.yaml:

flutter:
  assets:
    - assets/ca/
  1. [not a solution but a workaround] (source)
    class MyHttpOverrides extends HttpOverrides {
    @override
    HttpClient createHttpClient(SecurityContext context) {
    return super.createHttpClient(context)
      ..badCertificateCallback = (X509Certificate cert, String host, int port) => true;
    }
    }
maniveltvl commented 11 months ago

Please try the below

final ioc = new HttpClient(); ioc.badCertificateCallback = (X509Certificate cert, String host, int port) => true; Client _client = IOClient(ioc); _client.get(url);

eximius313 commented 11 months ago

badCertificateCallback is rather nasty workaround - not a solution to the real problem IMHO

abichinger commented 9 months ago

lehttp_overrides package solved this issue for me.

A Flutter package to resolve Let's Encrypt SSL certificate problems with Android 7.1.1 and below

It adds the ISRG Root X1 certificate to the set of trusted X509 certificates.