diefferson / http_certificate_pinning

Https Certificate pinning for Flutter
Apache License 2.0
84 stars 71 forks source link

Organization, incorrect error handling and iOS freezing #15

Closed nivisi closed 2 years ago

nivisi commented 2 years ago

Organization

I split the code a bit and provided a library class, so users can use all the classes by importing a single file instead of a bunch of them.

Dart Side

Because onRequest in the Dio intercepter is an unawaited future, the exception here: https://github.com/diefferson/http_certificate_pinning/blob/b5f2cbddcc19af745a9f33cf7f525b52cd6c67ab/lib/certificate_pinning_interceptor.dart#L24

Is never handled by the try-catch blocks. The solution is to "throw" it this way:

handler.reject(
  DioError(
    requestOptions: options,
    error: CertificateNotVerifiedException(),
  ),
);

The PR fixes that and also add safety in case some platform or other error occurs: the reject method is also called then.

iOS Freezing

Because the SessionManager used to be "global", e.g. shared, concurrent executions broke each other: FlutterResult were overriden every time the call is made.

Now we create a SessionManager for every request and nothing interrupts nothing.

Another thing is that flutter result was executed twice: the actual result of fingerprints check and every time the request was cancelled. A minor thing, still fixed.

diefferson commented 2 years ago

Thanks @nivisi