应用程序钥匙串中带有自签名证书的 HTTPS

发布于 2024-08-17 08:14:43 字数 395 浏览 4 评论 0原文

我必须通过 HTTPS 将我的 iPhone 应用程序连接到具有自签名证书的服务器。我无法更改证书或服务器。

由于我不想接受所有自签名证书,仅此一个,我的想法是将证书导入到应用程序钥匙串中(从文件中读取证书并使用 SecItemAdd 将其添加到钥匙串中) )。

如果我在模拟器中运行应用程序,安装证书,然后在钥匙串中搜索它(使用 SecItemCopyMatching ),则会找到证书,但连接仍然失败,并显示“不受信任的服务器证书”错误。

这是模拟器的问题还是我的应用程序的问题?我还需要做其他事情才能使其发挥作用吗?或者我可以假设,如果我将证书添加到真实设备上的钥匙串中,到服务器的连接将会成功(我正在使用 NSURLConnection.sendSynchronousRequest )?

感谢您的帮助!

I have to connect my iPhone app to a server with a self-signed certificate via HTTPS. I cannot change the certificate or the server.

Since I don't want to accept all self-signed certs, just this one, my idea was to import the cert to the apps keychain (reading the cert from file and adding it to the keychain with SecItemAdd).

If I run the App in the Simulator, install the cert and then search the keychain for it (using SecItemCopyMatching), the cert is found, but the connection still fails with "untrusted server certificate" error.

Is this a problem with the simulator or my app? Do I have to do anything else, for this to work? Or can I assume, that if I add a certificate to the keychain on a real device, the connect to the server will be successfull(I'm using NSURLConnection.sendSynchronousRequest)?

Thanks for any help!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

走野 2024-08-24 08:14:43

您可以使用 ASIHTTPRequest 库。它允许通过将 ASIHTTPRequest 对象的 validatesSecureCertificate 属性设置为 NO 来忽略证书验证。

You can use ASIHTTPRequest library. It allows to ignore certificate validation by setting validatesSecureCertificate property of ASIHTTPRequest object to NO.

红玫瑰 2024-08-24 08:14:43

这应该可以在模拟器中运行,但有一些注意事项,请参阅 Apple 示例代码示例“AdvancedURLConnections”。

This should work in the Simulator with some caveats, see the Apple sample code example "AdvancedURLConnections".

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文