6
我試圖訪問受NTLM身份驗證保護並需要客戶端證書的服務器。我使用NSURLConnection的委託方法進行身份驗證,並使用UIWebview檢索結果。帶客戶端證書和NTLM的NSURLConnection
我已經成功,當服務器需要客戶端證書開發NTLM身份驗證和驗證碼:當服務器需要NTLM身份驗證或客戶端證書分別
- (void) connection:(NSURLConnection *)connection willSendRequestForAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge {
authMethod = challenge.protectionSpace.authenticationMethod;
if ([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust])
{
[challenge.sender useCredential:[NSURLCredential credentialForTrust: challenge.protectionSpace.serverTrust] forAuthenticationChallenge: challenge];
return;
}
if ([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodClientCertificate])
{
[... code to extract certificate ...]
NSURLCredential *credential = [NSURLCredential credentialWithIdentity:myIdentity certificates:(NSArray*)certsArray persistence:NSURLCredentialPersistencePermanent];
[challenge.sender useCredential:credential forAuthenticationChallenge:challenge];
return;
}
if ([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodNTLM])
{
NSURLCredential *credential;
credential = [NSURLCredential
credentialWithUser:@"user"
password:@"password"
persistence:NSURLCredentialPersistencePermanent];
[challenge.sender useCredential:credential forAuthenticationChallenge:challenge];
return;
}
[[challenge sender] performDefaultHandlingForAuthenticationChallenge:challenge];
}
,一切工作正常。當一起需要時,服務器端會收到證書信息和NTLM憑證,但IIS7會返回403頁,要求客戶端證書...
您可能需要知道的一件事是,將按此順序調用四次「發送請求身份驗證挑戰」 :
willSendRequestForAuthenticationChallenge: NSURLAuthenticationMethodServerTrust
willSendRequestForAuthenticationChallenge: NSURLAuthenticationMethodClientCertificate
willSendRequestForAuthenticationChallenge: NSURLAuthenticationMethodNTLM
willSendRequestForAuthenticationChallenge: NSURLAuthenticationMethodClientCertificate
如果您有什麼想法?
在此先感謝,
你有沒有得到過這個工作?我有類似的問題(有時我會得到「服務器XXX需要客戶端證書」,即使我提供了一個)我認爲它可能是iOS 8的錯誤,但目前無法測試iOS 7。 – Locksleyu 2016-03-18 20:18:40