你运行这段代码:
let URL = "https://www.nasa.gov/sites/default/files/wave_earth_mosaic_3.jpg"
let imageData = NSData(contentsOfURL: NSURL(string: URL)!)
UIImage(data: imageData!)
你会得到这个:
2015-09-11 16:33:47.433 Cassini[21200:447896] NSURLSession/NSURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9802)
深入挖掘会发现使用了 SHA1 签名。
maximveksler$ openssl s_client -connect www.nasa.gov:443 < /dev/null 2>/dev/null | openssl x509 -text -in /dev/stdin | grep "Signature Algorithm"
Signature Algorithm: sha1WithRSAEncryption
Signature Algorithm: sha1WithRSAEncryption
自 2015 年 9 月 11 日起,NASA 正在使用不安全的连接,现在怎么办?
最佳答案
为什么会这样?
因为使用不安全的网络不利于您的用户隐私。
从 iOS9 开始,Apple 将强制您的应用程序与通过 HTTP 访问的任何资源建立安全连接。这意味着您要连接的服务器需要跟进最新的安全连接最佳实践。
截至 2015 年 9 月,这些包括:
- 使用HTTPS (而不是普通的 http)
- 使用 SHA-2 签署证书
- 使用Forward Secrecy
更多信息可以在 App Transport Security Technote 找到
你能做什么?
管理自己的服务器?修理它!确保它们坚固且安全。您可以通过使用 shaaaaaaaaaaaaa.com 在线测试来验证您的服务器是否正常。或在本地使用概述的任何方法 here
如果您连接到 other servers ,有“白名单”问题资源的选项,这是不鼓励的。
降低特定 URL 的安全性
转到您的 Info.plist
并添加以下条目:
<key>NSAppTransportSecurity</key>
<dict>
<key>NSExceptionDomains</key>
<dict>
<key>www.nasa.gov</key>
<dict>
<key>NSExceptionAllowsInsecureHTTPLoads</key>
<true/>
</dict>
</dict>
</dict>
全局关闭App Transport Security
请注意,这是一个非常糟糕的主意。
转到您的 Info.plist
并添加以下条目:
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
关于security - 处理应用程序传输安全(kCFStreamErrorDomainSSL,-9802),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32525736/