自签名 SSL 证书和 stringWithContentsOfURL
我正在使用 NSString#stringWithContentsOfURL:
从服务器请求一些数据。服务器使用自签名证书,因此 stringWithContentsOfURL:
仅返回 nil,并且不进行更改以接受证书。
这都是预期的行为。我知道如何使用 NSURLConnection 及其委托方法正确执行此操作,但我正在寻找短期修复而不是重写此代码。 (是的截止日期)
所以我的问题是,是否可以将自签名证书导入到应用程序的钥匙串中,这会导致 stringWithContentsOfURL:
接受自签名证书吗?
I am requesting some data from a server with NSString#stringWithContentsOfURL:
. The server is using a self-signed certificate, so stringWithContentsOfURL:
simply returns nil and does not give a change to accept the certificate.
This is all expected behaviour. I know how to properly do this with NSURLConnection
and it's delegate methods instead, but I am looking for a shorter term fix instead of rewriting this code. (Yay deadlines)
So my question is, is it possible to import the self-signed certificate into the application's keychain, and will that cause stringWithContentsOfURL:
to accept the self-signed certificate?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我相信 Apple 有一个用于安装 SSL 证书的企业工具——它是交换邮件正常工作所必需的。
您也可以将 .cer 文件邮寄给自己,在 iPhone 上打开并安装。
还有来自 Apple 的 AdvancedURLConnections 示例项目
I beleive that there is an enterprise tool from Apple for installing SSL certs -- it was necessary to get exchange mail working.
You may also be able to mail the .cer file to yourself, open on your iPhone and install it.
There is also the AdvancedURLConnections sample project from Apple
没有办法绕过 SSL 验证方案,经过一段时间的尝试和到处寻找解决方案后,我必须实现一个类来做到这一点。
由于 NSString 的 stringWithContentsOfURL 的优点是同步,所以我必须确保我的也是同步的。对于每个目的来说,它可能都有点大,但你已经明白了它的要点。
它的用法是这样的:
如果我愿意的话,我想我可以只调用一次。
There is no way to go around that SSL verification scheme, and after a while of trying and looking all over the place for a solution, I had to implement a class to do just that.
Since the advantage of NSString's stringWithContentsOfURL is to be synchronous, I had to make sure mine was as well. It's probably a little big for every purpose, but you get the gist of it.
And it's used like this:
I guess I could make it just one call, if I wanted to.