现在尝试使用CFNetwork来实现NSURLContection中的网络通信,当遇到https请求的时候,就需要创建一个NSURLAuthenticationChallenge对象challenge给
[protocol.client URLProtocol:protocol didReceiveAuthenticationChallenge:challengere];
以使
- (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge
回调函数能根据challenge判读是否trust服务器,判断trust需要challenge.protectionSpace.serverTrust来获得一个SecTrustRef,
问题是我自己创建challenge对象和protectionSpace对象时,有SecTrustRef对象,但不能将其赋值给protectionSpace的serverTrust,因为serverTrust在API里是只读的,没有暴露setter接口,怎么破?
已尝试:
一、继承protectionSpace类,增加一个实例变量,覆盖serverTrust的getter方法,新增一个setter方法
二、使用类别,同理覆盖getter,新增setter
都无果,因为protectionSpace从protocol.client传到URLConnection回调的时候,已经不是同一个对象,被系统进行了一次复制,复制过程没有复制我自定义的serverTrust求大侠大神指教呀

解决方案 »

  1.   

    这两个帖子你看过没有?
    http://www.sunethmendis.com/2013/01/11/certificate-based-client-authentication-in-ios/
    http://stackoverflow.com/questions/6402442/iphone-development-verify-the-certificate-information-from-a-https-url
      

  2.   

    恩,看过了,但这两个都是在URLConnection层使用challenge.protection.serverTrust验证是否信任服务器,
    我在做的是URLConnection层的https通信用CFNetwork实现,所以自己创建了challenge、protectionSpace、trust对象,但不能把trust对象赋值给protectionSpace以返回给UIRConnection的回调