Http: CERTIFICATE_VERIFY_FAILED - self signed certificate

Created on 10 Aug 2020  路  3Comments  路  Source: dart-lang/http

Hi,

how we can disable the certificate verify ? Because in local / dev we have a self signed certificate and it make an error (indicate in the title of the issue).

I can't make a real certificate in a local server (symfony server) so i'm blocked if i can't disabled this control.

Most helpful comment

First, Having self-signed certificate is not recommended beacuse it's not secured.
For Production, A certificate chain must be added to server configuration which allows your app can access server through api requests.

For Development, you can proceed in 2ways.

  1. With Self Signed certificate which fails in your case. There must be something wrong with certificate
  2. Without Self Signed certificate
    a. Create a file with dart extensionand then dump the below code into it

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

b. Call the above class in main() method as first statement
main(){
HttpOverrides.global = new MyHttpOverrides();
runApp(widget)
}

All 3 comments

First, Having self-signed certificate is not recommended beacuse it's not secured.
For Production, A certificate chain must be added to server configuration which allows your app can access server through api requests.

For Development, you can proceed in 2ways.

  1. With Self Signed certificate which fails in your case. There must be something wrong with certificate
  2. Without Self Signed certificate
    a. Create a file with dart extensionand then dump the below code into it

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

b. Call the above class in main() method as first statement
main(){
HttpOverrides.global = new MyHttpOverrides();
runApp(widget)
}

Solution no. 2 provided by @venkatesh-u works for me but what I couldn't understand that this issue occurs at only old Android Devices like Samsung Galaxy Grand 2 and Samsung A5 etc. ? Not for other devices with the latest Operating System.

This given solution did the trick for me also. Considering that Flutter is soon forcing https-connections, it would still be nice if this would work in a more obvious way (e.g, the Client() call could consume an optional onHandshakeError callback)

Was this page helpful?
0 / 5 - 0 ratings