0

I am using Alamofire in my app and I have to use a public certificate pinning. So far I have implemented below code for the same.

My domain name is api.xx.xxx.com

private static var manager: SessionManager? {

    let url = Configuration.baseUrl
    IFLOG(url.getDomain()!)
    let serverTrustPolicy = ServerTrustPolicy.pinCertificates(
        certificates: ServerTrustPolicy.certificates(),
        validateCertificateChain: true,
        validateHost: true
    )

    let serverTrustPolicies: [String: ServerTrustPolicy] = [
        url.getDomain()!: serverTrustPolicy
    ]
    let config = URLSessionConfiguration.default

    return SessionManager(configuration: config, serverTrustPolicyManager: ServerTrustPolicyManager(policies: serverTrustPolicies))

}

Here my question is how to get public key for the host and in which format (cer or der)save in Xcode and how this public key picked by Alamofire.

Thanks

Arun
  • 2,271
  • 1
  • 14
  • 18
  • You can use .cer/.der and save it in xcode. You need to map the saved certificate **let pathToCert = Bundle.main.path(forResource: githubCert, ofType: "cer") let localCertificate:NSData = NSData(contentsOfFile: pathToCert!)!** And then localCertificate Data is passed in serverTrustPoliciy – Vinaykrishnan Feb 13 '19 at 14:40
  • Thanks but i have to use public key :) – Arun Feb 13 '19 at 16:39
  • This could help, https://stackoverflow.com/q/15728636/2323806 – Vinaykrishnan Feb 14 '19 at 06:17

0 Answers0