Skip to content

How to fix CERTIFICATE_VERIFY_FAILED error?

Dominik Cvetan edited this page Mar 6, 2024 · 1 revision

If getting the following error on the end-user client:

Error during verifying with exception: HandshakeException: Handshake error in client (OS Error:
	CERTIFICATE_VERIFY_FAILED: self signed certificate in certificate chain(handshake.cc:393))

Create the following class:

class MyHttpOverrides extends HttpOverrides {
  @override
  HttpClient createHttpClient(SecurityContext? context) {
    return super.createHttpClient(context)
      ..badCertificateCallback = (X509Certificate cert, String host, int port) => true;
  }
}

And add the following line in the main.dart before running the application:

HttpOverrides.global = MyHttpOverrides();