Hello ,
I have obtained three strings from the server: ca (the root certificate), cert (the client certificate), and privateKey (the private key) for authentication between the iOS client and server. I have successfully used ca for server authentication.
However, I am having trouble generating an NSURLCredential from the cert and privateKey strings for client authentication. Can anyone guide me on how to convert these strings into an NSURLCredential? Any example code would be greatly appreciated!
Thank you for your help!
It’s tricky to offer specific advice without seeing an example of the credentials that you’re trying to import. If you post some examples, I may be able to help more.
My general advice is that you no try to add the data you have directly to the keychain. That can get really tricky. Instead, create objects from the data you have and then add those to the keychain. That way you learn about any import failures when you create the objects, not when trying to read stuff back from the keychain.
To import your private key, call SecKeyCreateWithData
. See Importing Cryptographic Keys for a lot more detail on that.
To import your certificate, call SecCertificateCreateWithData
.
Don’t both importing the public key. You won’t need it, and if you do you can get it from the certificate via SecCertificateCopyKey
.
Once you have these objects, add each one to the keychain using SecItemAdd
. I have two posts that explain the ins and outs of that API:
Share and Enjoy
—
Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"