emqx / qmqtt

MQTT client for Qt
https://www.emqx.com
Other
698 stars 337 forks source link

QMQTT::SocketSslHandshakeFailedError on iOS #214

Closed kosadev closed 4 years ago

kosadev commented 4 years ago

Hello, first of all, I need to say that I'm not familiar with MQTT and SSL concepts. I've been trying using QMQTT library on iOS Simulator using Qt 5.13.2, but every time I finished with this error: QMQTT::SocketSslHandshakeFailedError

I try to connect mosquito test server on port 8883.

To show you the code I've created this repo: https://github.com/kosadev/MQTT-attempt/tree/master/client Actually, this app (except for dummy Qml) is a slightly modified example from yours repo. The exact same code is working for Android.

I've been trying to statically add open SSL for iOS as well (few lines in client/client.pro file). Do you have any ideas what can cause the problem?

mwallnoefer commented 4 years ago

SSL/TLS problems are never easy to deal with. I don't know the iOS platform very well, but maybe try on a real device to see if it causes differences in the behaviour? Also had you a chance to try on an Android device, just to make sure that the SSL settings are correct?

@ejvr any other ideas?

ejvr commented 4 years ago

Tricky question indeed. The error QMQTT::SocketSslHandshakeFailedError is a direct translation of QAbstractSocket::SslHandshakeFailedError. If you google that, you can find some info on how to fix this. The probable issues include a version TLS mismatch (eg. client wants TLS 1.3, but server does not support that). Another pitfall is an incorrect date/time. I your code you're explicitly setting the protocol to TLS 1.3. The server needs to support it as well, you could try to remove it for testing purposes.

Sometimes QT will log some info to standard output or standard error, this could be helpful in diagnosing the issue. Usually those messages will turn up if you start the application from the command line. I don't know if this is possible within the iOS simulator.

Apart from that, I would try to run the program on another OS (MacOS perhaps?), to weed out device specific issues.

kosadev commented 4 years ago

Thanks for your proposals guys. Actually, I've tried various approaches including adding certificate key, protocols etc.. Without them also. I also tried to ask the client to not verify the peer, but also without success. The very same code worked on Android, but it didn't on macOS. I think that it may be somehow related to the topic mentioned in this note: https://doc.qt.io/qt-5/qsslconfiguration.html#addCaCertificate

Finally, I got it working by calling ignoreSslError() on my own. No, the best approach I guess, but the most important thing is that I got working connection!

Thank you guys for all ideas.