Ios SSL证书混淆
我显然是错过了啊哈!因为我一直在研究如何使用CA或自签名证书等来访问安全URL https,而且我仍然无法完全理解它,所以我主要只是在与其他人进行代码和解决方案的交流,以尝试让我的工作正常进行,我显然缺乏一个基本的了解,所以希望该网站的居民可以帮助 本质上,我有一个应用程序,使用自签名证书与https服务器进行通信 我认为访问服务器所需的证书和密钥都存储在应用程序根捆绑包中的p12中。然后,我通过在互联网上找到的代码将p12添加到手机或应用程序的钥匙链中Ios SSL证书混淆,ios,ssl-certificate,afnetworking,restkit-0.20,Ios,Ssl Certificate,Afnetworking,Restkit 0.20,我显然是错过了啊哈!因为我一直在研究如何使用CA或自签名证书等来访问安全URL https,而且我仍然无法完全理解它,所以我主要只是在与其他人进行代码和解决方案的交流,以尝试让我的工作正常进行,我显然缺乏一个基本的了解,所以希望该网站的居民可以帮助 本质上,我有一个应用程序,使用自签名证书与https服务器进行通信 我认为访问服务器所需的证书和密钥都存储在应用程序根捆绑包中的p12中。然后,我通过在互联网上找到的代码将p12添加到手机或应用程序的钥匙链中 NSString *p12Path =
NSString *p12Path = [[NSBundle mainBundle] pathForResource:p12Name ofType:@"p12"];
NSData *p12Data = [[NSData alloc] initWithContentsOfFile:p12Path];
NSError *error = nil;
NSData *data = [[SFHFKeychainUtils getPasswordForUsername:[[UIDevice currentDevice]name] andServiceName:serviceName error:&error] dataUsingEncoding:NSUTF8StringEncoding];
[self transform:data];
NSString *pass = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
CFStringRef password = (__bridge CFStringRef)pass;
const void *keys[] = { kSecImportExportPassphrase };
const void *values[] = { password };
CFDictionaryRef optionsDictionary = CFDictionaryCreate(NULL, keys, values, 1, NULL, NULL);
CFArrayRef p12Items;
OSStatus result = SecPKCS12Import((__bridge CFDataRef)p12Data, optionsDictionary,&p12Items);
if(result == noErr)
{
CFDictionaryRef identityDict = CFArrayGetValueAtIndex(p12Items, 0);
SecIdentityRef identityApp =(SecIdentityRef)CFDictionaryGetValue(identityDict,kSecImportItemIdentity);
SecCertificateRef certRef;
SecIdentityCopyCertificate(identityApp,&certRef);
SecCertificateRef certArray[1] = { certRef };
CFArrayRef myCerts = CFArrayCreate(NULL, (void *)certArray, 1, NULL);
CFRelease(certRef);
NSURLCredential *credential = [NSURLCredential credentialWithIdentity:identityApp certificates:(__bridge NSArray *)myCerts persistence:NSURLCredentialPersistencePermanent];
CFRelease(myCerts);
[[RKObjectManager sharedManager].HTTPClient setDefaultCredential:credential];
}
而且,这似乎有效,但我必须启用它
_httpClient = [RKObjectManager sharedManager].HTTPClient;
[_httpClient setAllowsInvalidSSLCertificate:YES];
否则它不会连接,现在我看到很多帖子说,你需要将此设置为“是”才能允许自签名证书,但同时我看到其他帖子说它应该只用于开发,否则这会使使用https变得完全多余。很明显,冗余安全性不好,所以我把它设为“否”,它不连接
那么,真的有人有任何联系,或者可以自己抽出一些时间来填补我对这些东西如何工作的知识空白吗?这将是非常感谢,并将节省我从老板那里得到的悲伤 这需要由AFNetworking处理,称为“SSL固定”。有关如何启用该功能和提供证书的详细信息,请查看文档。还有一些有用的信息。谢谢你的回答和链接,我还在慢慢地想办法,希望有更多的人发表评论,帮助我和其他人更好地掌握手头的概念以及如何为它们编码。