Certificate pinning seems to have stopped working in Alamofire 4 and Swift 3
This is my code
let pathToCert = Bundle.main.path(forResource: "certificate", ofType: "der")
let localCertificate = NSData(contentsOfFile: pathToCert!)!
let serverTrustPolicy = ServerTrustPolicy.pinCertificates(
certificates: [SecCertificateCreateWithData(nil, localCertificate)!],
validateCertificateChain: true,
validateHost: true
)
let myServer = "...". //string in format without https://
let serverTrustPolicies = [
myServer: serverTrustPolicy
]
afManager = SessionManager(
serverTrustPolicyManager: ServerTrustPolicyManager(policies: serverTrustPolicies)
)
afManager.request("https://www.google.co.uk", method: .get).response { response in
//I get status code 200 here, which should NOT happen
log.info(response)
}
The certificate loads correctly, this is the certificate
certificate printed inside console
My problem is that I seem to receive status code 200 from my domain and any other domain.
I should not be receiving 200 from other domains
I was told that SSL certificate pinning should not be implemented this way in swift 3 / alamofire 4, could this be true?
Also, could something be wrong with the certificate?
P.S. I tried this code too, but no luck either :(((
let serverTrustPolicies = [
"*.mydomain.com": serverTrustPolicy
]