emqx / CocoaMQTT

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

Can't Connect CocoaMQTT connection with HiveMQ, says noAuthrized #589

Open gurpalrajput opened 6 months ago

gurpalrajput commented 6 months ago

Hie, I am trying to connect CocoaMQTT With HiveMQ, with correct credentials, I had verified them too, but in acknoledgement it says NotAuthrized, below is code I am trying.

Note:- Two way ssl is also working had verified.

    ///Connection Building
func buildMQTTConnection() {
    ///MQTT 5.0
    let clientID = "CocoaMQTT-" + String(ProcessInfo().processIdentifier)

// let mqtt5 = CocoaMQTT5(clientID: clientID, host: "broker.hivemq.com", port: 1883) ///8dbc6815c7824b0482d7ae0439514faa.s1.eu.hivemq.cloud mqtt5 = CocoaMQTT5(clientID: clientID, host: "8dbc6815c7824b0482d7ae0439514faa.s1.eu.hivemq.cloud", port: 8883) /// let connectProperties = MqttConnectProperties() connectProperties.topicAliasMaximum = 0 connectProperties.sessionExpiryInterval = 0 connectProperties.receiveMaximum = 100 connectProperties.maximumPacketSize = 500 mqtt5?.connectProperties = connectProperties mqtt5?.logLevel = .error

    /// SSL Configuration
    let clientCertArray = getClientCertFromP12File(certName: "certificate", certPassword: "gurpal")
    var sslSettings: [String: NSObject] = [:]
    sslSettings[kCFStreamSSLCertificates as String] = clientCertArray
    mqtt5?.allowUntrustCACertificate = true
    mqtt5?.enableSSL = true
    mqtt5?.sslSettings = sslSettings

    mqtt5?.username = "gurpalrajput2505"
    mqtt5?.password = "Gurpalrajput25"

    mqtt5?.willMessage = CocoaMQTT5Message(topic: "/will", string: "dieout")
    mqtt5?.delegate = self
    mqtt5?.keepAlive = 60

}

CocoaMQTT Failed to authenticate with HiveMQ, I Am using 5.0 version for CocoaMQTT. Any solution.

JaylinYu commented 5 months ago

debug tls layer from your hivemq.