Search code examples
iosobjective-chttpsapp-transport-security

TIC TCP Conn Failed 1:54 Err(54)


I am attempting to make POST requests to a secure server in my app, without a certificate. When I make a request I'm getting these errors in the console:

2018-04-24 16:14:22.942030-0400 TIC TCP Conn Failed [8:0x60000017c440]: 1:54 Err(54) 2018-04-24 16:14:22.942779-0400 Task <1E09E1AE-CE51-48C4-9A56-F3738B8FD68F>.<1> HTTP load failed (error code: -1005 [1:54]) 2018-04-24 16:14:22.943219-0400 [93037:8075678] Task <1E09E1AE-CE51-48C4-9A56-F3738B8FD68F>.<1> finished with error - code: -1005

In URLSession:didReceiveChallenge I'm not validating the certificate; I'm simply calling continueWithoutCredentialForAuthenticationChallenge.

I have my domain set as an exception for ATS in Info.plist:

<key>NSAppTransportSecurity</key>
<dict>
    <key>NSAllowsArbitraryLoads</key>
    <true/>
    <key>NSExceptionDomains</key>
    <dict>
        <key>mydomain.net</key>
        <dict>
            <key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
            <true/>
            <key>NSIncludesSubdomains</key>
            <true/>
            <key>NSThirdPartyExceptionRequiresForwardSecrecy</key>
            <false/>
        </dict>
    </dict>
</dict>

I can't find any documentation on what Err(54) and error code: -1005 mean, so I'm running into a roadblock while troubleshooting. It may also be worth mentioning that I have to connect my Mac to my VPN to ping this server, and that I'm running this in my simulator.

I'm hoping to hear some suggestions for what might be going wrong and how to fix.


Solution

  • I found that the issue was with how I was handling URLSession:didReceiveChallenge. I was only calling continueWithoutCredentialForAuthenticationChallenge. What I did to get it to work was to call the completionHandler with a credential:

    SecTrustRef serverTrust = [[challenge protectionSpace] serverTrust]; ASSERT(nil != serverTrust); NSURLCredential *credential = [NSURLCredential credentialForTrust:serverTrust]; completionHandler(NSURLSessionAuthChallengeUseCredential, credential);