Search code examples
iosobjective-csslnsurlrequest

How can I attach a TLS/SSL certificate in a NSURLRequest?


I need to communicate with a server and I need to attach a self signed TLS certificate with every NSURLRequest.

Is there a way to do that?


Solution

  • Your connection delegate should implement connection:canAuthenticateAgainstProtectionSpace: and answer YES. Once that's done, you're delegate will receive connection:didReceiveAuthenticationChallenge:

    To proceed with a cert, that method should answer an NSURLCredential. Create one of those with your certificate using

    + (NSURLCredential *)credentialWithIdentity:(SecIdentityRef)identity certificates:(NSArray *)certArray persistence:(NSURLCredentialPersistence)persistence