Próbuję uzyskać dostęp do serwera, który jest chroniony za pomocą uwierzytelniania NTLM i wymaga certyfikatu klienta. Uwierzytelnianie za pomocą delegowanych metod NSURLConnection i pobieranie wyników za pomocą interfejsu UIWebview.NSURLConnection z certyfikatem klienta i NTLM
udało mi się opracować kod autoryzacji i uwierzytelniania NTLM, gdy serwer wymaga certyfikatu klienta:
- (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];
}
wszystko działa dobrze, gdy serwer wymaga uwierzytelniania NTLM lub certyfikat klienta oddzielnie. Gdy są wymagane razem, informacje o certyfikatach i poświadczenia NTLM są odbierane po stronie serwera, ale IIS7 zwraca stronę 403 z zapytaniem o certyfikat klienta ...
Coś, co być może trzeba wiedzieć, to to, że willSendRequestForAuthenticationChallenge jest wywoływane cztery razy w tej kolejności :
willSendRequestForAuthenticationChallenge: NSURLAuthenticationMethodServerTrust
willSendRequestForAuthenticationChallenge: NSURLAuthenticationMethodClientCertificate
willSendRequestForAuthenticationChallenge: NSURLAuthenticationMethodNTLM
willSendRequestForAuthenticationChallenge: NSURLAuthenticationMethodClientCertificate
Jeśli masz jakieś pomysły?
Dzięki z góry,
Czy zdarzyło Ci się, że to zadziała? Mam podobne problemy (czasami otrzymuję komunikat "Serwer XXX wymaga certyfikatu klienta", mimo że dostarczam go). Myślę, że może to być błąd systemu iOS 8, ale nie można przetestować systemu iOS 7 w tej chwili. – Locksleyu