NSURLAuthenticationMethodServerTrust是ssl

时间:2012-06-20 13:16:25

标签: ios ipad nsurlconnection

我无法理解NSURLAuthenticationMethodServerTrust。在我的应用程序中,我必须使用基于服务器的http和https连接。我的问题是如果我得到一个NSURLAuthenticationMethodServerTrust挑战,它是一个安全的假设,采取是作为https连接。我究竟应该对这一挑战做出什么回应。

任何帮助将不胜感激。 感谢

1 个答案:

答案 0 :(得分:1)

我不确定接收NSURLAuthenticationMethodServerTrust是否始终表示https连接。我不明白为什么或如何普通的http连接可能导致NSURLAuthenticationMethodServerTrust身份验证质询,所以我假设它是https但我不确定。 但NSURLAuthenticationChallenge有一个NSURLProtectionSpace,而NSURLAuthenticationMethodServerTrust又有一个属性receivesCredentialSecurely。文档有点不明确,但我认为这个属性表明与服务器的安全连接,在http / https情况下,这意味着它是https。

关于回复什么,macnetworkprog-mailinglist上有一个关于这个主题的有用帖子:Question + Answer

摘要:protectionSpace不是关于您,客户端,而是响应服务器的身份验证质询,而是让您(客户端)有机会检查您是否应该完全信任服务器。在这种情况下,挑战的serverTrust包含SecTrustEvaluate对象/结构,其中包含验证是否应该信任此服务器所需的所有信息。通常,您可以使用serverTrust函数检查NSURLConnectionDelegate并根据该检查的结果执行操作。您可以在此处找到更多信息:Overriding TLS Chain Validation Correctly

如果检查确定服务器应该信任您create an NSURLCredential with the serverTrust object并将其传递给身份验证质询发件人/完成块。

Apple可以在这里找到一个非常广泛的示例项目:http://developer.apple.com/library/ios/#samplecode/AdvancedURLConnections/Introduction/Intro.html 它已经很老了(iOS 3/4,pre-Arc),只处理旧的NSURLSessionDelegate,它必须委托方法而不是一个(比如新的和NSURLSession)。但是,此处显示的验证以及您可以实施的不同方案仍然适用,应该可以轻松转移到import jupyter_client cf=jupyter_client.find_connection_file('6759') km=jupyter_client.BlockingKernelClient(connection_file=cf) km.load_connection_file() km.execute('a=5')

相关问题