setupCertificate method
void
setupCertificate(
{ - String? certFilePath,
- String? password,
})
Implementation
void setupCertificate({String? certFilePath, String? password}) {
if (kIsWeb) {
_dio?.httpClientAdapter = HttpClientAdapter();
} else {
_dio?.httpClientAdapter = IOHttpClientAdapter(createHttpClient: () {
///set https SSl certificate
if (certFilePath != null && password != null) {
if (certFilePath.isEmpty || password.isEmpty) {
assert(certFilePath.isNotEmpty && password.isNotEmpty, "filePath and password cannot be empty!");
}
final pfxFile = File(certFilePath);
final data = pfxFile.readAsBytesSync();
final context = SecurityContext.defaultContext;
context.useCertificateChainBytes(data.buffer.asUint8List(), password: password);
context.usePrivateKeyBytes(data.buffer.asUint8List(), password: password);
HttpClient httpClient = HttpClient(context: context);
httpClient.badCertificateCallback = (X509Certificate cert, String host, int port) {
return false;
};
return httpClient;
}
///Ignore https SSl certificate
HttpClient client = HttpClient();
client.badCertificateCallback = (X509Certificate cert, String host, int port) {
return true;
};
return client;
});
}
}