【问题标题】:How to make iPhone application accept incorrect server certificate but only specific one?如何让 iPhone 应用程序接受不正确的服务器证书但只接受特定的一个?
【发布时间】:2011-02-10 04:08:16
【问题描述】:

我需要使用私有 HTTPS API 并且客户端在主机上的证书不正确。 证书适用于 www.clienthost.com,我正在使用 api.clienthost.com。 所以我需要通过 HTTPS 连接到 api.clienthost.com 忽略不正确的证书,但仍然确保它是 www.clienthost.com 的证书而不是其他证书。 我找到了这个答案:How to use NSURLConnection to connect with SSL for an untrusted cert?,它似乎解决了我的一半问题,但我试图弄清楚如何仍然检查主机证书是我希望看到的并且没有什么不同。

【问题讨论】:

    标签: iphone ssl https certificate


    【解决方案1】:

    尝试实现 NSURLConnection 的委托方法

    - (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge
    

    那么下面会包含宿主

    [[challenge protectionSpace] host]
    

    然后您可以通过调用以下方法之一继续

    continueWithoutCredentialForAuthenticationChallenge:
    
    cancelAuthenticationChallenge:
    
    useCredential:forAuthenticationChallenge:
    

    【讨论】:

    • 我想这不会让我免于接受一些带有正确主机的自制证书吗?
    • 应该是证书的来源主机。如果您担心这是伪造的可能性,您应该做一些测试来确定这一点。此外,NSURLAuthenticationChallenge 中的 NSURLCredential 和 NSURLProtectionSpace 对象提供了对其他可以进行安全检查的字段的访问。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多