How to use ssl certificate with Swift Alamofire?

I am updating my iOS apps using HTTPS web services.

I updated my web server with an SSL certificate. But don’t know what to do with the code side of iOS?

Do I need to submit any certificate along with the web request?

I am using Alamofire to create a web request.

thank

+4
source share
1 answer

A simple googling would give you so many results.

For example, https://infinum.co/the-capsized-eight/how-to-make-your-ios-apps-more-secure-with-ssl-pinning

func configureAlamoFireSSLPinning {
     let pathToCert = NSBundle.mainBundle().pathForResource(githubCert, ofType: "cer")
     let localCertificate:NSData = NSData(contentsOfFile: pathToCert!)!

     self.serverTrustPolicy = ServerTrustPolicy.PinCertificates(
            certificates: [SecCertificateCreateWithData(nil, localCertificate)!],
         validateCertificateChain: true,
         validateHost: true
     )

     self.serverTrustPolicies = [
         "your-api.com": self.serverTrustPolicy!
     ]

     self.afManager = Manager(
         configuration: NSURLSessionConfiguration.defaultSessionConfiguration(),
         serverTrustPolicyManager: ServerTrustPolicyManager(policies: self.serverTrustPolicies)
     )
 }

func alamoFireRequestHandler {
     self.afManager.request(.GET, self.urlTextField.text!)
         .response { request, response, data, error in
      // response management code
  }
}
+2
source

Source: https://habr.com/ru/post/1665680/


All Articles