菜鸟教程小白 发表于 2022-12-12 19:02:58

ios - SSL 证书混淆


                                            <p><p>我显然错过了啊哈!因为我一直在研究使用 CA 或自签名证书等以获得对安全 URL https 的访问权限,但我仍然无法完全理解它,我主要是在与其他人代码和解决方案一起尝试并获得我的工作,我显然缺乏基本的了解,所以希望该网站的居民可以提供帮助。</p>

<p>基本上,我有一个使用自签名证书与 https 服务器通信的应用程序。</p>

<p>我认为访问服务器所需的证书和 key 都存储在存储在应用程序根包中的 p12 中。然后我通过我在互联网上找到的这段代码将这个 p12 添加到手机或应用程序钥匙串(keychain)中</p>

<pre><code>NSString *p12Path = [ pathForResource:p12Name ofType:@&#34;p12&#34;];
NSData *p12Data = [ initWithContentsOfFile:p12Path];
NSError *error = nil;
NSData *data = [name] andServiceName:serviceName error:&amp;error] dataUsingEncoding:NSUTF8StringEncoding];
;
NSString *pass = [ 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,&amp;p12Items);

if(result == noErr)
{
    CFDictionaryRef identityDict = CFArrayGetValueAtIndex(p12Items, 0);
    SecIdentityRef identityApp =(SecIdentityRef)CFDictionaryGetValue(identityDict,kSecImportItemIdentity);

    SecCertificateRef certRef;
    SecIdentityCopyCertificate(identityApp,&amp;certRef);

    SecCertificateRef certArray = { certRef };
    CFArrayRef myCerts = CFArrayCreate(NULL, (void *)certArray, 1, NULL);
    CFRelease(certRef);

    NSURLCredential *credential = ;
    CFRelease(myCerts);

    [.HTTPClient setDefaultCredential:credential];
}
</code></pre>

<p>而且,这似乎有效,但我必须启用它</p>

<pre><code>_httpClient = .HTTPClient;
;
</code></pre>

<p>否则它无法连接,现在我看到各种帖子说,你需要将此设置为是以允许自签名证书,但同时我看到其他帖子说它应该只用于开发否则这会使使用 https 完全多余。显然冗余安全性很差,所以我将其设置为 no...并且它无法连接。</p>

<p>那么,真的有人有任何链接,或者可以抽出一些时间自己来填补我对这些东西如何工作的知识空白吗?这将不胜感激,并且不会让我从老板那里得到悲伤。 </p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>这需要由 AFNetworking 处理,称为“SSL Pinning”。查看文档 <a href="http://cocoadocs.org/docsets/AFNetworking/1.3.1/Classes/AFURLConnectionOperation.html" rel="noreferrer noopener nofollow">here</a>有关如何启用该功能并提供您的证书的详细信息。还有有用的信息<a href="http://nsscreencast.com/episodes/73-ssl-pinning" rel="noreferrer noopener nofollow">here</a> .</p></p>
                                   
                                                <p style="font-size: 20px;">关于ios - SSL 证书混淆,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/21870770/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/21870770/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - SSL 证书混淆