我正在使用 OWASP 示例证书和公钥固定 https://www.owasp.org/index.php/Certificate_and_Public_Key_Pinning。示例使用随机组织 http://www.random.org, and 随机组织 http://www.random.org最近拿到了新的证书。这意味着connection:didReceiveAuthenticationChallenge:
正在失败。这是预期的并且很好:)
但是,失败显示为“NSURLErrorDomain”,代码为-1012。这不是很有帮助,用户将无法用它做任何有意义的事情:
最好提供一条消息,其中包含类似于“警告:标识网站的公钥已更改...”的文本。
另一个小问题:在connection:didFailWithError:
,我无法判断 -1012 是否是由于固定失败或其他网络错误造成的。因此,我只想提供证书失败的消息,而不提供其他 -1012 错误的消息。
如何向调用提供“丰富的错误信息”[[challenge sender] cancelAuthenticationChallenge: challenge]
(当connection:didReceiveAuthenticationChallenge:
失败)。NSURLConnection 委托协议参考 http://developer.apple.com/library/mac/#documentation/Foundation/Reference/NSURLConnectionDelegate_Protocol/Reference/Reference.html and NSURLAuthenticationChallengeSender 协议参考 http://developer.apple.com/library/mac/#documentation/cocoa/reference/foundation/Protocols/NSURLAuthenticationChallengeSender_Protocol/Reference/Reference.html不提如何做。
尝试使用
NSString * alertMessage = [challenge.error localizedFailureReason];
获取人类可读的错误信息。
请参阅文档NSError https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSError_Class/Reference/Reference.html#//apple_ref/occ/instm/NSError/localizedFailureReason and URL身份验证挑战 https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSURLAuthenticationChallenge_Class/Reference/Reference.html#//apple_ref/occ/instm/NSURLAuthenticationChallenge/error.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)