I am trying to figure out how to use Alamofire 4.0 with Swift 3.0 to send a p12 (i also have the PEM cert and key if need be) to a website for authentication. All the examples i have seen are for Swift 2.0 and not exactly what i'm looking for. In safari on my mac i can access the site by putting the p12 in the keychain and sending it when safari asks so i know that portion works. I don't know if anyone can help me with an example of how to do so in Alamofire 4.0 and Swift 3.0 in an application. The certificates are self signed as well.
Any thoughts or help? I am not just looking to pin the certificate as the client key and cert needs to be sent to the server for access...
I was able to get it to work. A few issues got into the way. First, you have to allow IOS to accept self signed certificates. This requires to set up AlamoFire serverTrustPolicy:
From there, you have to override the sessionDidRecieveChallenge to send the client certificate. Because i wanted to use a p12 file I modified some code I found elsewhere (sorry i don't have the source anymore) to make is Swift 3.0 to import the p12 using foundation classes:
This will allow me to import the file, and send it back to the client.
Now you can use the sessionManager to create as many calls as you need to.
As a note, i've also added the following to the info.plist as recomended to get around the new security features in newer iOS features:
I hope this helps!
Here is my example that might help someone (Alamofire 4.0, Swift 3, xCode 8)
add following to your Info.plist
and here is an example of making an request