2010-09-20 110 views
11

我對客戶端證書身份驗證沒有太多經驗。任何人都可以告訴我如何在iOS應用中使用它?謝謝:)如何在iOS應用程序中使用客戶端證書身份驗證

+0

的可能重複[iPhone:HTTPS客戶端證書認證(http://stackoverflow.com/questions/1460626/iphone-https-client-cert -authentication) – 2011-05-20 10:56:53

回答

18

您的NSURLConnection委託人應回覆connection:didReceiveAuthenticationChallenge:委託方法(請參閱下面的鏈接)。

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

應該通過詢問挑戰它的「發件人」,併爲它提供一個合適的證書響應。

喜歡的東西:

- (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]; 
} 

請參閱如何基於證書創建證書的詳細信息,NSURLCredential類參考:

+0

我剛纔說didreceiveAuthenticationChallenge現在已被棄用嗎? http://developer.apple.com/library/ios/#documentation/Foundation/Reference/NSURLConnectionDelegate_Protocol/Reference/Reference.html#//apple_ref/occ/intf/NSURLConnectionDelegate任何人都可以點我一個更完整的例子,使用客戶端證書來驗證請求? – Rory 2013-02-16 22:59:31

2

在您的應用程序使用客戶端證書(如已經回答了前傑克),你必須在你的應用程序中實現你的應用程序鑰匙鏈導入證書。 (請注意,您需要使用PKCS#12證書格式,但您需要在您的應用程序中註冊它(搜索導出的UTI和文檔類型),並使用不同的擴展名,而不是已由iOS註冊的「.p12」。已在我的應用中使用.x-p12)

或者您需要將證書包含在您的應用包中。

在這裏看到:iOS Client Certificates and Mobile Device Management

這裏:https://developer.apple.com/library/ios/qa/qa1745/_index.html

相關問題