Nan*_*nda 102 ssl-certificate ios app-transport-security
自从我使用iOS 9升级现有项目以来,我一直收到错误:
发生SSL错误,无法与服务器建立安全连接.
Ton*_*RAN 109
对于iOS9,Apple作为App Transport Security(ATS)的一部分,在iOS 9中做出了一个激进的决定,禁用了来自iOS应用程序的所有不安全的HTTP流量.
要简单地禁用ATS,您可以通过打开Info.plist来执行此步骤,并添加以下行:
<key>NSAppTransportSecurity</key>
  <dict>
      <key>NSAllowsArbitraryLoads</key>
      <true/>
  </dict>
Sté*_*ert 59
即使允许任意load(NSAllowsArbitraryLoads = true)是一个很好的解决方法,您也不应该完全禁用ATS,而是启用您想要允许的HTTP连接:
<key>NSAppTransportSecurity</key>
<dict>
  <key>NSExceptionDomains</key>
  <dict>
    <key>yourserver.com</key>
    <dict>
      <!--Include to allow subdomains-->
      <key>NSIncludesSubdomains</key>
      <true/>
      <!--Include to allow HTTP requests-->
      <key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
      <true/>
      <!--Include to specify minimum TLS version-->
      <key>NSTemporaryExceptionMinimumTLSVersion</key>
      <string>TLSv1.1</string>
    </dict>
  </dict>
</dict>
Tec*_*eko 15
iOS 9强制使用HTTPS的连接为TLS 1.2以避免最近的漏洞.在iOS 8中,甚至支持未加密的HTTP连接,因此旧版本的TLS也没有出现任何问题.作为解决方法,您可以将此代码段添加到Info.plist:
<key>NSAppTransportSecurity</key>
<dict>
    <key>NSAllowsArbitraryLoads</key>
    <true/>
</dict>
*参考App Transport Security(ATS)
Nat*_*ble 14
如果您只是针对特定域,可以尝试将其添加到应用程序的Info.plist中:
<key>NSAppTransportSecurity</key>
<dict>
    <key>NSExceptionDomains</key>
    <dict>
        <key>example.com</key>
        <dict>
            <key>NSExceptionRequiresForwardSecrecy</key>
            <false/>
            <key>NSIncludesSubdomains</key>
            <true/>
        </dict>
    </dict>
</dict>
似乎iOS 9.0.2中断了对有效HTTPS端点的请求.我目前的怀疑是它需要SHA-256证书,否则它会因此错误而失败.
要重现,请使用safari检查UIWebView,然后尝试导航到任意HTTPS端点:
location.href = "https://d37gvrvc0wt4s1.cloudfront.net/js/v1.4/rollbar.min.js"
// [Error] Failed to load resource: An SSL error has occurred and a secure connection to the server cannot be made. (rollbar.min.js, line 0)
现在尝试google(因为他们当然有SHA-256证书):
location.href = "https://google.com"
// no problemo
添加运输安全性的例外(如上面的@stéphane-bruckert的回答所述)可以解决这个问题.我还假设完全禁用NSAppTransportSecurity也会起作用,虽然我已经读过完全禁用它可能会危及您的应用审核.
[编辑]我发现简单地枚举我在NSExceptionDomainsdict中连接的域修复了这个问题,即使将NSExceptionAllowsInsecureHTTPLoadsset设置为true也是如此.:\
| 归档时间: | 
 | 
| 查看次数: | 122405 次 | 
| 最近记录: |