我在ios上的webview上传递ssl证书时遇到了麻烦

时间:2017-04-25 15:43:14

标签: ios ssl-certificate

我正在使用uiwebview。我已将ssl pinning应用于AFNetworking API调用。但我无法在webview上传递证书固定。我需要知道如何在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 :(得分:1)

UiWebView没有公开任何直接API,但它仍然可以使用NSURLProtocol实现,这使您能够验证所有传出网络请求的证书。它确实需要做很多工作,更好的解决方案是使用WKWebView,它提供了一种通过WKNavigationDelegate's webView:didReceiveAuthenticationChallenge:completionHandler:https://developer.apple.com/library/ios/documentation/WebKit/Reference/WKNavigationDelegate_Ref/index.html)进行固定的明确方法。

"在网页浏览中固定"本文的一部分: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/