[英]iPhone Custom CA certificate for an application which uses NSURLConnection?
我有一个与许多不同站点通信的应用程序,每个站点都有自己的SSL证书,由我们自己的内部CA签名。 这样做可以防止我们为每个站点购买SSL证书(数百或数千),并且在每个站点上使用带有共享密钥的通配符证书时更安全。 因此,基本上使用CA证书是唯一的方法。
现在,我有一个mobileprovision文件,它将CA证书作为配置文件安装在手机上。 如果我们的iPhone应用程序在获得SSL证书错误时启动,它将通过Safari重定向到此移动配置文件,系统将提示用户安装CA.
问题是我担心Apple AppStore可能会拒绝我的应用程序(此时只是来自其他开发人员的一些反馈),我想研究其他方法来实现这一目标。
基本上我需要完成的是允许SSL连接,该连接将验证将嵌入我的应用程序中的自定义CA证书。 这将使CA证书仅对我拨打的电话有效。 我使用标准的NSURLConnection方法来与服务进行通信。
这可能吗? 有人可以告诉我如何加载CA(PEM的形式是什么?)并将其添加到我的应用程序的可信CA证书列表中? 如果那是不可能的,我还有其他选择吗? 只是信任所有证书并不是真正的选择,我们希望防止中间人攻击并且只信任我们的CA颁发的证书。
谢谢!
使用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");
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.