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

kCFStreamErrorDomainSSL Code=-9806 "(null)"... When trying to connect via one way SSL. #318

Open raghavgautam123 opened 4 years ago

raghavgautam123 commented 4 years ago

I'm not able to connect to my server using one way TLS.

The code I use to connect is : self.mqttClient = CocoaMQTT(clientID: clientId, host: host, port: UInt16(port)) self.mqttClient.keepAlive = 15 self.mqttClient.autoReconnect = setAutomaticReconnect self.mqttClient.delegate = self self.mqttClient.enableSSL = true self.mqttClient.allowUntrustCACertificate = true self.mqttClient.connect()

This returns error: Optional(Error Domain=kCFStreamErrorDomainSSL Code=-9806 "(null)" UserInfo={NSLocalizedRecoverySuggestion=Error code definition can be found in Apple's SecureTransport.h})

If I comment out enableSSL and allowUntrustCACertificate, it works perfectly. Server is EMQX based and works fine with all the other libraries for TLS operations except this one.

Any help by the maintainers would be appreciated. I'm kinda stuck.

lets-swapcode commented 4 years ago

I tried commenting as well as setting enable SSL to false and allowUntrustCACertificate to true. Still the same.

On Sun, Jan 19, 2020 at 1:27 AM raghavgautam123 notifications@github.com wrote:

I'm facing the same issue. The code I use to connect is : self.mqttClient = CocoaMQTT(clientID: clientId, host: host, port: UInt16(port)) self.mqttClient.keepAlive = 15 self.mqttClient.autoReconnect = setAutomaticReconnect self.mqttClient.delegate = self self.mqttClient.enableSSL = true self.mqttClient.allowUntrustCACertificate = true self.mqttClient.connect()

This returns error: Optional(Error Domain=kCFStreamErrorDomainSSL Code=-9806 "(null)" UserInfo={NSLocalizedRecoverySuggestion=Error code definition can be found in Apple's SecureTransport.h})

If I comment out enableSSL and allowUntrustCACertificate, it works perfectly. Server is EMQX based and works fine with all the other libraries for TLS operations except this one.

Any help by the maintainers would be appreciated. I'm kinda stuck.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/emqx/CocoaMQTT/issues/318?email_source=notifications&email_token=AE5Q2NZGRY2FY5I4JAQEAMTQ6NNMDA5CNFSM4KIU3WRKYY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4IHEBR4Q, or unsubscribe https://github.com/notifications/unsubscribe-auth/AE5Q2N4HY2A4ABUPXGZPURDQ6NNMDANCNFSM4KIU3WRA .

fishead1116 commented 4 years ago

Add this in your CocoaMQTTDelegate

    func mqtt(_ mqtt: CocoaMQTT, didReceive trust: SecTrust, completionHandler: @escaping (Bool) -> Void) {
        completionHandler(true)
    }
harshsurati commented 4 years ago

This delegate is already there and has completion true also.

What is happening now is.

[TRACE] [didDisconect]: Error Domain=GCDAsyncSocketErrorDomain Code=7 "Socket closed by remote peer" UserInfo={NSLocalizedDescription=Socket closed by remote peer}
[TRACE] [didStateChangeTo]: new state: connecting
[TRACE] [didDisconect]: Error Domain=kCFStreamErrorDomainSSL Code=-9806 "(null)" UserInfo={NSLocalizedRecoverySuggestion=Error code definition can be found in Apple's SecureTransport.h}

This happen 1 in 20 times. Rest is working fine.

treeleaf-nikesh commented 4 years ago

Did you find a solution to this problem ?

barankaraoguzzzz commented 2 years ago

I have same problem. I have connected socket and i am trying many subscribes or unsubscribes. Sometimes i got this error. "Error Domain=GCDAsyncSocketErrorDomain Code=7 "Socket closed by remote peer" UserInfo={NSLocalizedDescription=Socket closed by remote peer}"

shozab14 commented 2 years ago

did u able to fix it?

SandhiyalalEIC commented 1 year ago

Any solution found for this?

afgarcia86 commented 8 months ago

Same question 🙏

leonardo-miguel-silva-alb commented 5 months ago

Any solutions found?