2017-04-25 96 views
1

我正在使用uiwebview。我已將ssl固定到AFNetworking API調用。但我無法通過webview上的證書固定。我需要知道如何在webview重定向上傳遞ssl證書。我在通過IOS的webview SSL證書時遇到問題

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType{ 
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager]; 
    [LivefyreAPICalls sslpinning:manager :@"certificate.com" :@"cer"]; 

NSString *content =[request.URL absoluteString]; 
    NSArray *urlComponents = [content componentsSeparatedByString:@"&"]; 

for (NSString *keyValuePair in urlComponents) 
{ 
    NSArray *pairComponents = [keyValuePair componentsSeparatedByString:@"="]; 
    NSString *key = [[pairComponents firstObject] stringByRemovingPercentEncoding]; 
    NSString *value = [[pairComponents lastObject] stringByRemovingPercentEncoding]; 
    [queryStringDictionary setObject:value forKey:key]; 
} 

if ([queryStringDictionary valueForKey:@"id_token"]) { 
    [[UserNetwork manager] setUserFromSessionFromToken:[queryStringDictionary valueForKey:@"id_token"] :nil]; 
    if ([UserNetwork manager].networkUsers.count >=1) { 

     SettingsViewController *settingsView=[self.storyboard instantiateViewControllerWithIdentifier:@"SettingsViewController"]; 
     [self.navigationController pushViewController:settingsView animated:NO]; 
    }else{ 
     LiveBlogsTableViewController *blogView=[self.storyboard instantiateViewControllerWithIdentifier:@"liveblog"]; 
     [self.navigationController pushViewController:blogView animated:YES]; 
    } 
} 
return YES; 
} 
+1

你試過?你能分享代碼 –

+0

@Shabirjan我封鎖ssl_pinning.Can你請幫助,如果你知道....? – basha

+0

嗨,你是可用於小型teamviewer會議 –

回答

1

UiWebView不公開任何直接的API到,但它仍然可以使用NSURLProtocol,從而使您能夠驗證所有傳出的網絡請求的證書的能力來實現。它需要很多工作,而更好的解決方案是使用WekWebView,它提供了通過WKNavigationDelegate'swebView:didReceiveAuthenticationChallenge:completionHandler:https://developer.apple.com/library/ios/documentation/WebKit/Reference/WKNavigationDelegate_Ref/index.html)進行固定的明確方法。

本文的「在Webviews中固定」部分有更多詳細信息:https://datatheorem.github.io/TrustKit/getting-started.html,它也是一個用於在iOS應用中實現公鑰固定的庫。

退房此鏈接,以及:

https://github.com/antekarin/ssl-pinning-swift

檢查這個博客,以及: http://ryandavis.io/allowing-uiwebview-to-accept-self-signed-certificates/

+0

我已經嘗試了trustkit。它固定直接api調用。但它不適用於webview。 – basha

+0

嘗試使用WKWebView –

+0

trustkit with wekwebview .....? – basha