shamblett / mqtt_client

A server and browser based MQTT client for dart
Other
548 stars 176 forks source link

Can't connect to mosquitto, on IOS, with certificate #425

Closed pognibene closed 1 year ago

pognibene commented 1 year ago

Hello, Using mqtt_client with Flutter. On Android I use this code:

final context = SecurityContext.defaultContext;
String s = await rootBundle.loadString('assets/conf/ca.crt');
context.setTrustedCertificatesBytes(
utf8.encode(s));
await globals.mqttClient!.connect();

this works fine and I'm connected with a secure connection on port 8883.

On IOS, the very same code fails with the following error:

[VERBOSE-2:dart_vm_initializer.cc(41)] Unhandled Exception: HandshakeException: Handshake error in client (OS Error: 
    CERTIFICATE_VERIFY_FAILED: application verification failure(handshake.cc:393))
[log] ERROR bad certificate when connecting to MQTT

The mosquitto broker rejects the connection with an 'invalid protocol' error.

Any idea what's wrong here? Should I initialize the connection in a different way on IOS? Thank you!

shamblett commented 1 year ago

The client is just Dart code, it doesn't know where it is running so there is no different set up for any specific platform. All I can suggest is you take this up with flutter IOS users and see if they know what the problem is, looks as though IOS may need more platform specific stuff setting than android.

cuixiaocun commented 1 year ago

Has this problem been solved? I also have this problem