Ios 如何获得服务器';NSURLConnection中的公钥是什么?
我的应用程序使用TLS连接到服务器,并从服务器接收令牌。它需要通过对照服务器的公钥检查令牌的签名来验证令牌的真实性,该公钥是从我可以在Ios 如何获得服务器';NSURLConnection中的公钥是什么?,ios,ssl,nsurlconnection,Ios,Ssl,Nsurlconnection,我的应用程序使用TLS连接到服务器,并从服务器接收令牌。它需要通过对照服务器的公钥检查令牌的签名来验证令牌的真实性,该公钥是从我可以在中获取的SecTrustRef对象中检索的-连接:willSendRequestForAuthenticationChallenge:类似这样 - (void)connection:(NSURLConnection *)connection willSendRequestForAuthenticationChallenge:(NSURLAuthentication
中获取的SecTrustRef
对象中检索的-连接:willSendRequestForAuthenticationChallenge:
类似这样
- (void)connection:(NSURLConnection *)connection
willSendRequestForAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge {
if /* server trust authentication method and server is trusted */ {
SecTrustRef trust = [challenge.protectionSpace serverTrust];
self.serverPublicKey = SecTrustCopyPublicKey(trust);
}
}
但是,如果我断开与服务器的连接,然后再次连接到服务器,我的代理的-连接:willSendRequestForAuthenticationChallenge:
方法将不会被调用,并且我没有机会存储服务器的公钥。系统似乎正在缓存服务器的凭据和我发送到服务器的客户端凭据
是否有方法检索这些缓存的凭据,以便我可以在-connectiondFinishLoading:
中获取服务器的公钥,或者只给我NSURLConnection
的某个其他委托回调