2010-06-11 24 views
10

我有一个应用程序与许多不同的站点进行通信,每个站点都有自己的SSL证书,由我们自己的内部CA签署。这样做可以防止我们购买每个站点(数百或数千个)的SSL证书,并且更安全,然后在每个站点上使用带有共享密钥的通配符证书。所以,基本上使用CA证书是唯一的方法。使用NSURLConnection的iPhone应用程序的iPhone自定义CA证书?

现在,我有一个mobileprovision文件,它将CA证书作为配置文件安装在手机上。当我们的iPhone应用程序启动时,如果它出现SSL证书错误,它会通过Safari重定向到此移动配置文件,并提示用户安装CA.

问题是,我担心苹果AppStore可能会拒绝我的应用程序这样做(只需从其他开发人员那里获得一些反馈),并且我想研究其他方法来实现此目的。

基本上我需要完成的是允许一个SSL连接,它将验证将被嵌入到我的应用程序中的自定义CA证书。这将使CA证书仅对我所做的呼叫有效。我正在使用标准的NSURLConnection方法来与服务进行通信。

这可能吗?有人可以告诉我如何加载CA(哪种形式的PEM?)并将其添加到我的应用程序的可信CA证书列表中?如果这是不可能的,我还有其他的选择吗?只是相信所有的证书并不是真正的选择,我们希望阻止中间人攻击并且只信任我们的CA颁发的证书。

谢谢!

+1

-1没有注释的访问任何网站。太好了! – 2010-06-11 21:41:04

回答

1

使用下面NSURLConnection的两个委托方法无效的证书

- (BOOL)connection:(NSURLConnection *)connection canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace *)protectionSpace 
    { 

      NSLog(@"canAuthenticateAgainstProtectionSpace"); 
     if([[protectionSpace authenticationMethod] isEqualToString:NSURLAuthenticationMethodServerTrust]) { 
      // Note: this is presently only called once per server (or URL?) until 
      //  you restart the app 
       NSLog(@"Authentication checking is doing"); 
      return YES; // Self-signed cert will be accepted 
      // Note: it doesn't seem to matter what you return for a proper SSL cert 
      //  only self-signed certs 
     } 
     return NO; 
    } 

    - (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge 
    { 
      NSLog(@"didReceiveAuthenticationChallenge"); 
     if ([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust]) 
     { 
      [challenge.sender useCredential:[NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust] forAuthenticationChallenge:challenge]; 
       NSLog(@"chalenging protection space authentication checking"); 
     } 
    } 
+0

目前我已经实现了这些,但没有被调用:([NSURLRequest setAllowsAnyHTTPSCertificate:YES forHost:[[NSURL URLWithString:url] host]]; – jsetting32 2013-07-24 17:14:55

相关问题