gpt4 book ai didi

ios - AuthenticationMethodServerTrust 在 iOS 9 中为 nil

转载 作者:可可西里 更新时间:2023-11-01 01:37:51 26 4
gpt4 key购买 nike

我一直在尝试使用 NSURLSession 在我的 iOS 8+ 应用程序中实现一种进行公钥固定的方法。

我所做的只是实现委托(delegate)方法 didReceiveChallenge 并获取 challenge.protectionSpace.authenticationMethod 并检查它是否等于 NSURLAuthenticationMethodServerTrust。

如果它等于 NSURLAuthenticationMethodServerTrust,我会检查证书并将其与我的本地副本进行比较。

这在 iOS 8 上运行良好,但在 iOS 9 上我没有收到等于 NSURLAuthenticationMethodServerTrust 的身份验证方法。我收到 NSURLAuthenticationMethodClientCertificate,所以我无法访问 challenge.protectionSpace.serverTrust 属性。

有什么想法吗?

public func URLSession(session: NSURLSession, didReceiveChallenge challenge: NSURLAuthenticationChallenge, completionHandler: (NSURLSessionAuthChallengeDisposition, NSURLCredential!) -> Void)
{


if(challenge.protectionSpace.authenticationMethod == NSURLAuthenticationMethodServerTrust)
{
// Verify the identity of the server
println("Trusted")
return challenge.sender.performDefaultHandlingForAuthenticationChallenge!(challenge)

}
println("Not trusted")
return challenge.sender.cancelAuthenticationChallenge(challenge)
}
}

最佳答案

您的回调可以针对不同的保护空间多次调用。这里发生的是这些调用的顺序发生了变化,服务器信任保护空间调用显然由于某种原因在 iOS 9 中没有首先发生。

问题是您正在取消第一个挑战,这实际上终止了连接。不要那样做。相反,请使用“执行默认处理”。

您也可能不想对服务器信任情况执行默认处理,因为这等同于根本不编写自定义处理程序。相反,检查 key ,只有当它是您想要的 key 时才执行默认处理,否则取消身份验证质询。

或者我可能误读了您的代码。看起来好像缺少一些代码。可能是您根本没有处理非服务器信任案例,在这种情况下,这就是问题所在。如果您不为每个挑战调用东西,连接将永远停留在那里,等待您这样做。

关于ios - AuthenticationMethodServerTrust 在 iOS 9 中为 nil,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33987145/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com