The service I'm connecting to is using a self signed certificate. For dev purposes I do not want to validate that chain.
Using swift 3 with Alamofire 4. Fixed the ATS accordingly:
<key>NSAppTransportSecurity</key>
<dict>
<key>NSExceptionDomains</key>
<dict>
<key>url.com</key>
<dict>
<key>NSExceptionAllowsInsecureHTTPLoads</key>
<true/>
<key>NSExceptionRequiresForwardSecrecy</key>
<false/>
<key>NSIncludesSubdomains</key>
<true/>
</dict>
</dict>
</dict>
Code to connect and disable evaluation.
let serverTrustPolicies: [String: ServerTrustPolicy] = [
"example.domain.com": .pinCertificates(
certificates: ServerTrustPolicy.certificates(),
validateCertificateChain: false,
validateHost: true
),
"sub.url.com": .disableEvaluation
]
let sessionManager = Alamofire.SessionManager(
serverTrustPolicyManager: ServerTrustPolicyManager(policies: serverTrustPolicies)
)
let headers = ["Authorization": "Basic /*...*/"]
sessionManager.request("https://sub.url.com/path", headers: headers).responseJSON { response in
print(response.request) // original URL request
print(response.response) // HTTP URL response
print(response.data) // server data
print(response.result) // result of response serialization
debugPrint(response)
if let JSON = response.result.value {
print("JSON: \(JSON)")
}
}
Error log from dumpPrint
[Result]: FAILURE: Error Domain=NSURLErrorDomain Code=-999 "cancelled" UserInfo={NSErrorFailingURLKey=https://sub.url.com/path, NSLocalizedDescription=cancelled, NSErrorFailingURLStringKey=https://sub.url.com/path}
URL has been masked.