CocoaMQTT icon indicating copy to clipboard operation
CocoaMQTT copied to clipboard

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

Open raghavgautam123 opened this issue 4 years ago • 9 comments

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.

raghavgautam123 avatar Jan 18 '20 19:01 raghavgautam123

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 [email protected] 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 .

lets-swapcode avatar Jan 19 '20 04:01 lets-swapcode

Add this in your CocoaMQTTDelegate

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

fishead1116 avatar Mar 09 '20 07:03 fishead1116

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.

harshsurati avatar Mar 30 '20 09:03 harshsurati

Did you find a solution to this problem ?

treeleaf-nikesh avatar Jun 03 '20 06:06 treeleaf-nikesh

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}"

barankaraoguzzzz avatar Jul 18 '22 12:07 barankaraoguzzzz

did u able to fix it?

shozab14 avatar Aug 17 '22 07:08 shozab14

Any solution found for this?

SandhiyalalEIC avatar Jun 30 '23 03:06 SandhiyalalEIC

Same question 🙏

afgarcia86 avatar Mar 04 '24 17:03 afgarcia86