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