'Flutter HTTPS Handshake error in client (OS Error: CERTIFICATE_VERIFY_FAILED: ok(handshake.cc:363))

A colleague has given me a Flutter project to try to build the app in iOS (I use a Mac, we both use Android Studio). Everything is ok except for this error:

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

If I use HTTP instead of HTTPS it works obviously. My colleague said he solved by adding this line of code:

client.badCertificateCallback = (X509Certificate cert, String host, int port) => true;

This line of code is also in my project because the source is the same. So why does it work on Android, but not on iOS?



Solution 1:[1]

best way for ssl certification problem on all http requests

it is work on both platform (android & ios)

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

void main(){
    HttpOverrides.global = new MyHttpOverrides();
    runApp(new MyApp());
}

Solution 2:[2]

Old question but my solution was to ensure the time/date set correctly on client

Solution 3:[3]

I've found a secure way to do this.
use this code below:

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

inside main():

HttpOverrides.global = new MyHttpOverrides();

Solution 4:[4]

this should work on ios if you have added this line

client.badCertificateCallback = (X509Certificate cert, String host, int port) 
=> true;

so double check that you are using the same instance of the client for your request, and that you are making the request after you set the badCertificateCallback parameter

Solution 5:[5]

Check your https certificate that you are using, i think iOS has more strict measures than android when it comes to https connection. To be on the safe side, try to update your server certificate.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Kiax
Solution 2 Vince Lowe
Solution 3 rahul dhruw
Solution 4 Hussein Abdallah
Solution 5 Sami Kanafani