blackhorse-one / stomp_dart_client

Dart STOMP client for easy messaging interoperability.
BSD 3-Clause "New" or "Revised" License
59 stars 44 forks source link

CERTIFICATE_VERIFY_FAILED #101

Closed Katletos closed 3 months ago

Katletos commented 4 months ago

Is it possible to use library with self signed? Or how I can pass a certificate in StompClient like http client

flutter: HandshakeException: Handshake error in client (OS Error: CERTIFICATE_VERIFY_FAILED: self signed certificate(handshake.cc:393))

final client = await _getSSLPinningClient();
locator.registerSingleton<InterceptedClient>(InterceptedClient.build(
    client: client,
    interceptors: [
        LoggingInterceptor(storage: locator.get<SecureStorage>())
    ]));
KammererTob commented 4 months ago

As far i am aware there is no mechanism provided for this by the libraries i am using (mainly WebSocketChannel). But if this is for local development only you could try to provide a override for bad certificates like this:

class MyHttpOverrides extends HttpOverrides {
  @override
  HttpClient createHttpClient(SecurityContext? context) {
    return super.createHttpClient(context)
      ..badCertificateCallback =
          (X509Certificate cert, String host, int port) => true; // add your localhost detection logic here if you want
  }
}

void main() {
  HttpOverrides.global = MyHttpOverrides();
  runApp(MaterialApp(home: MyApp()));
}

Also see here: https://github.com/dart-lang/sdk/issues/34284

KammererTob commented 3 months ago

I will close this issue due to inactivity. If you still need assistance feel free to reopen.