は、私は次のような問題があります。クライアント証明書を使用してUIWebViewを認証する方法は?私が正しくウェブサイトをロードしている<code>UIWebView</code>を持っていますが、サーバーがあまりにもクライアント(<code>UIWebView</code>)から認証を望んでいる</p> <p>:
shouldStartLoadWithRequest:
-(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType (UIWebViewNavigationType)navigationType;
{
if(![self authenticated])
{
[self setAuthenticated:NO];
[self setUrlConnection:[[NSURLConnection alloc] initWithRequest:[self requestObj] delegate:self]];
[[self urlConnection] start];
return NO;
}
return YES;
}
didReceiveAuthenticationChallenge:
-(void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge
{
if ([challenge previousFailureCount] == 0)
{
[self setAuthenticated:YES];
NSURLCredential *credential = [NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust];
[challenge.sender useCredential:credential forAuthenticationChallenge:challenge];
}
else [[challenge sender] cancelAuthenticationChallenge:challenge];
}
didReceiveResponse:
私は、私は別のサイトからもらった次のコードでssl certificate
を追加しました
-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response;
{
[self setAuthenticated:YES];
[[self webView] loadRequest:[self requestObj]];
[[self urlConnection] cancel];
}
canAuthenticateAgainstProtectionSpace:
-(BOOL)connection:(NSURLConnection *)connection canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace *)protectionSpace
{
return [protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust];
}
今、サーバが特定のDN
名前のクライアント(証明書)から認証を必要としていました。私はiOS Client Certificates and Mobile Device Managementを見つけましたが、コードは私を助けなかったし、私の問題を解決しませんでした。
PKCS12ファイルをUIWebViewに追加することは可能ですか?サーバーがクライアントからの認証を希望する場合はUIWebView
にこのファイルを表示しますか?
私は常にエラー
2016-04-20 12:20:50.880 App [469:126255] NSURLSession/NSURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9813)
2016-04-20 12:20:51.454 App [469:126252] CFNetwork SSLHandshake failed (-9824 -> -9829)
2016-04-20 12:20:51.456 App [469:126252] NSURLSession/NSURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9829)
にこのクラスを追加しますが、シミュレータでテストしたのですか? – BHASKAR
@BHASKARいいえ私はテストデバイスでテストしました。私はシミュレータでそれをテストする必要がありますか? – Premox