emqx / CocoaMQTT

MQTT 5.0 client library for iOS and macOS written in Swift
https://www.emqx.com/en
Other
1.6k stars 419 forks source link

can not connect to HiveMQ Cloud Broker, SSL, no Certificate #489

Closed joersv4 closed 1 year ago

joersv4 commented 1 year ago

Hello,

I have a problem with the connection to the HiveMQ Cloud Broker.

This code runs on my local mqtt broker (without SSL), but not on HiveMQ Cloud Broker (with SSL).

   var mqtt: CocoaMQTT5!

    func setUpMQTT() {
        let clientID = "CocoaMQTT-" + String(ProcessInfo().processIdentifier)
        mqtt = CocoaMQTT5(clientID: clientID, host: "xxxx.s1.eu.hivemq.cloud", port: 8883)
        mqtt.logLevel = .debug
        mqtt.username = "xxxx"
        mqtt.password = "xxxx"
        mqtt.willMessage = CocoaMQTT5Message(topic: "/will", string: "dieout")
        mqtt.keepAlive = 60
        mqtt.enableSSL = true
        mqtt.allowUntrustCACertificate = true
        mqtt.sslSettings = [kCFStreamSSLPeerName as String: "" as NSObject]

        mqtt.connect()
    }

I can not connect to the HiveMQ Cloud Broker. I have tried everything, but nothing changed.

Wireshark of CocoaMQTT5 Bildschirm­foto 2022-11-08 um 23 39 43

Wireshark of MQTTAnalyzer APP -> successful connection Bildschirm­foto 2022-11-08 um 23 43 37

So i see my app not send the "Client Key Exchange"

How can I fix this issue??

Thanks

leeway1208 commented 1 year ago

Hi. Trying to set mqtt5!.sslSettings = [kCFStreamSSLPeerName as String: "xxxx.s1.eu.hivemq.cloud" as NSObject].

joersv4 commented 1 year ago

Hi.

Thank you :)

now I have found the right parameters for connection to HiveMQ Cloud.

        mqtt.enableSSL = true
        mqtt.allowUntrustCACertificate = false
        mqtt.sslSettings = [kCFStreamSSLPeerName as String: "xxxx.s1.eu.hivemq.cloud" as NSObject]

its working well with "allowUntrustCACertificate = false"