How to use Client Certificate Authentication in iOS App

后端 未结 2 1465
傲寒
傲寒 2020-12-02 19:44

I don\'t have a lot experience about Client Certificate Authentication. Anybody can tell me how to use it in iOS app? Thanks :)

2条回答
  •  青春惊慌失措
    2020-12-02 20:03

    Your NSURLConnection delegate should respond to the connection:didReceiveAuthenticationChallenge: delegate method (see link below).

    http://developer.apple.com/library/ios/documentation/cocoa/reference/foundation/Classes/NSURLConnection_Class/Reference/Reference.html#//apple_ref/occ/instm/NSObject/connection:didReceiveAuthenticationChallenge:

    It should respond by asking the challenge for its 'sender' and providing it with an appropriate credential.

    Something like:

    - (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge {
      id sender = [challenge sender];
    
      // create a credential from a certificate
      // see doco for details of the parameters
      NSURLCredential *creds = [NSURLCredential credentialWithIdentity:ident certificates:certs persistence:persistence];
    
      [sender useCredential:creds forAuthenticationChallenge:challenge];
    }
    

    See the NSURLCredential class reference for details of how to create a credential based on a certificate:

提交回复
热议问题