I’m trying to learn how to do SSL Pinning in Flutter with my movie catalog app I’ve made using https://api.themoviedb.org/3/. I think the certificate that I used is correct and I don’t what is causing this error :
Exception has occurred.
HandshakeException (HandshakeException: Handshake error in client (OS Error:
CERTIFICATE_VERIFY_FAILED: unable to get local issuer certificate(handshake.cc:393)))
I’ve tried using google and cloudflare dns but the result is still the same.
My Code :
static const BASE_URL = 'https://api.themoviedb.org/3';
Future<SecurityContext> get globalContext async {
try {
final sslCert = await rootBundle.load('certificates/certificates.pem');
print('Certificate loaded successfully.');
SecurityContext securityContext =
SecurityContext(withTrustedRoots: false);
securityContext.setTrustedCertificatesBytes(sslCert.buffer.asInt8List());
return securityContext;
} catch (e) {
print('Error loading certificate: $e');
rethrow;
}
}
@override
Future<List<MovieModel>> getNowPlayingMovies() async {
HttpClient client = HttpClient(context: await globalContext);
client.badCertificateCallback =
(X509Certificate cert, String host, int port) => false;
IOClient ioClient = IOClient(client);
final response =
await ioClient.get(Uri.parse('$BASE_URL/movie/now_playing?$API_KEY'));
if (response.statusCode == 200) {
return MovieResponse.fromJson(json.decode(response.body)).movieList;
} else {
throw ServerException();
}
}
2