I've read every answer I could find on this topic, but I'm still having issues with a self-signed certificate running on localhost
. My iOS test is very simple:
Alamofire.request("https://localhost:4567/hello").responseJSON { (dataRes) in
guard let jsonData = dataRes.data else { return }
NSLog("Received JSON: \(jsonData)")
}
Which results in the output:
2016-11-06 10:59:12.566 Chatty[20454:772766] NSURLSession/NSURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9802)
2016-11-06 10:59:12.583 Chatty[20454:772681] Received JSON: 0 bytes
With the following Info.plist
:
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<false/>
<key>NSExceptionDomains</key>
<dict>
<key>localhost:4567</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
</dict>
</dict>
I've also tried it without the port, and I even tried the dreaded:
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
Which fails with a different error code (-9813
)
2016-11-06 11:01:22.773 Chatty[20750:776671] NSURLSession/NSURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9813)
Other apps (like my Mocha tests) connect fine, as does Safari:
Ideally I would like to update my iOS simulator to accept only this self-signed certificate (I have the .cer
file, and have even dragged it into the simulator and 'trusted' it with no apparent effects), however I would also be okay with an exclusion for localhost
if that's the only way - but can't seem to get either to work.
What am I missing?
Edit: Updating my Info.plist
to the following also left me with -9802
as the error code:
<key>NSAppTransportSecurity</key>
<dict>
<key>NSExceptionDomains</key>
<dict>
<key>localhost:4567</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
<key>NSThirdPartyExceptionAllowsInsecureHTTPLoads</key>
<true/>
</dict>
</dict>
</dict>