android – Subject with SSL Pining utilizing Dio Flutter my certificates is wildcard certificates


In flutter i’m making an attempt to implement SSL Pinning utilizing dio: ^4.0.4 however each time I get this error

HandshakeException: Handshake error in consumer (OS Error: CERTIFICATE_VERIFY_FAILED: unable to get native issuer certificates(handshake.cc:393))

   String pem = "";

late ByteData _byteData;

Future loadAsset() async {
String _part = BUILD_ENV == 0 ? “dev” : BUILD_ENV == 1 ? “stage” : BUILD_ENV == 3 ? “check” : “reside”;
return await rootBundle.load(‘property/certificates/$_part/sslCertificate.pem’);}

Future loadPem() async {
String _part = BUILD_ENV == 0 ? “dev” : BUILD_ENV == 1 ? “stage” : BUILD_ENV == 3 ? “check” : “reside”;
return rootBundle.loadString(‘property/certificates/$_part/sslCertificate.pem’);
}

methodology 1:

(dio.httpClientAdapter as DefaultHttpClientAdapter).onHttpClientCreate = (consumer) {
  SecurityContext securityContext = SecurityContext();
  securityContext.setTrustedCertificatesBytes(_byteData.buffer.asUint8List());
  HttpClient httpClient = HttpClient(context: securityContext);
  return httpClient;
};

methodology 2:

(dio.httpClientAdapter as DefaultHttpClientAdapter).onHttpClientCreate  = (consumer) {
  debugPrint("badCertificateCallback :: xx");
  consumer.badCertificateCallback=(X509Certificate cert, String host, int port){
    debugPrint("badCertificateCallback :: yy ::${cert.pem}");
    if(cert.pem==pem){ // Confirm the certificates
      return true;
    }
    return false;
  };
  return consumer;
};

methodology 1 retains giving handshake error (described above)

methodology 2 (badCertificateCallback :: yy ::) line by no means get executed (this methodology by no means labored)

another factor my certificates is wildcard certificates *.instance.com
and my API base URL is api.instance.com

can anybody assist me to repair this

thanks upfront

Similar Posts

Leave a Reply

Your email address will not be published.