我正在尝试NSRequiresCertificateTransparency
为我的 ios 应用启用 App Transport Security 标志以实现更好的安全性。我进行了测试,它在我的装有 iOS 10 的设备和装有 iOS 10 的模拟器上运行良好。但它使 https 连接在装有 iOS 9.3 的模拟器中失败。如果我只是关闭这个特定的标志,它就会再次工作。
问题不在我连接的服务器上,因为即使使用 www.apple.com 也能重现它。这是我使用的 Info.plist 中的设置:
<key>NSAppTransportSecurity</key>
<dict>
<key>NSExceptionDomains</key>
<dict>
<key>www.apple.com</key>
<dict>
<key>NSRequiresCertificateTransparency</key>
<true/>
</dict>
</dict>
</dict>
这是代码:
NSURLSessionDataTask *task = [[NSURLSession sharedSession] dataTaskWithURL:[NSURL URLWithString:@"https://www.apple.com/"] completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
if (error) {
NSLog(@"fail");
}
}];
[task resume];
我在日志中看到的错误是: NSURLSession/NSURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9802)
也许它只发生在 iOS 9 的模拟器中?不幸的是,我手头没有装有 iOS 9 的设备来测试它。
更新:
设置 CFNETWORK_DIAGNOSTICS=3 环境变量后,我在日志中看不到任何有用的信息。这是关于错误的部分:
Response Error
Request: <CFURLRequest 0x7f8d0f668d00 [0x108314a40]> {url = https://www.apple.com/, cs = 0x0}
Error: Error Domain=kCFErrorDomainCFNetwork Code=-1200 "(null)" UserInfo={_kCFStreamPropertySSLClientCertificateState=0, kCFStreamPropertySSLPeerTrust=<SecTrustRef: 0x7f8d0f590a80>, _kCFNetworkCFStreamSSLErrorOriginalValue=-9802, _kCFStreamErrorDomainKey=3, _kCFStreamErrorCodeKey=-9802, kCFStreamPropertySSLPeerCertificates=<CFArray 0x7f8d0f50dfb0 [0x108314a40]>{type = immutable, count = 2, values = (
0 : <cert(0x7f8d0f66ef10) s: www.apple.com i: Symantec Class 3 EV SSL CA - G3>
1 : <cert(0x7f8d0f637e60) s: Symantec Class 3 EV SSL CA - G3 i: VeriSign Class 3 Public Primary Certification Authority - G5>
)}}
} [3:22]
Jan 31 17:09:13 test2[34612] <Notice>: CFNetwork Diagnostics [3:23] 17:09:13.125 {
Did Fail
Loader: <CFURLRequest 0x7f8d0f737670 [0x108314a40]> {url = https://www.apple.com/, cs = 0x0}
Error: Error Domain=kCFErrorDomainCFNetwork Code=-1200 "(null)" UserInfo={_kCFStreamPropertySSLClientCertificateState=0, kCFStreamPropertySSLPeerTrust=<SecTrustRef: 0x7f8d0f590a80>, _kCFNetworkCFStreamSSLErrorOriginalValue=-9802, _kCFStreamErrorDomainKey=3, _kCFStreamErrorCodeKey=-9802, kCFStreamPropertySSLPeerCertificates=<CFArray 0x7f8d0f50dfb0 [0x108314a40]>{type = immutable, count = 2, values = (
0 : <cert(0x7f8d0f66ef10) s: www.apple.com i: Symantec Class 3 EV SSL CA - G3>
1 : <cert(0x7f8d0f637e60) s: Symantec Class 3 EV SSL CA - G3 i: VeriSign Class 3 Public Primary Certification Authority - G5>
)}}
init to origin load: 0.00299901s
total time: 0.156503s
total bytes: 0
} [3:23]
更新 2:
这是调试器中错误对象的视图。