【问题标题】:App TranSport security, allow arbitrary load not working after upgrade to IOS 10.1应用传输安全,升级到IOS 10.1后允许任意加载不工作
【发布时间】:2017-03-23 09:12:54
【问题描述】:

我有一个在 ios 9 和 10.0 中运行良好的应用程序(我已将“允许任意加载 = YES”的应用程序传输安全阻止添加到我的 info.plist。但升级到 10.1 和 Xcode 8.1 后似乎有应用传输安全问题。我无法连接到服务器。我的服务器仅支持 TLS 1.1

显示此错误

Error Domain=NSURLErrorDomain Code=-1022 "The resource could not be loaded because the App Transport Security policy requires the use of a secure connection.

可能是 IOS 10.1 忽略了 .plist 信息。 (请注意,在 9.3 到 10.0 上它仍然可以正常工作)。

我的 .plist 文件

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>CFBundleDevelopmentRegion</key>
    <string>en</string>
    <key>CFBundleDisplayName</key>
    <string>SingPost</string>
    <key>CFBundleExecutable</key>
    <string>${EXECUTABLE_NAME}</string>
    <key>CFBundleIdentifier</key>
    <string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
    <key>CFBundleInfoDictionaryVersion</key>
    <string>6.0</string>
    <key>CFBundleName</key>
    <string>${PRODUCT_NAME}</string>
    <key>CFBundlePackageType</key>
    <string>APPL</string>
    <key>CFBundleShortVersionString</key>
    <string>1.8.7</string>
    <key>CFBundleSignature</key>
    <string>????</string>
    <key>CFBundleURLTypes</key>
    <array>
        <dict>
            <key>CFBundleURLSchemes</key>
            <array>
                <string>fb1540614276180366</string>
            </array>
            <key>Item 0</key>
            <string>fb1540614276180366</string>
        </dict>
    </array>
    <key>CFBundleVersion</key>
    <string>1.8.7</string>
    <key>FacebookAppID</key>
    <string>1540614276180366</string>
    <key>FacebookDisplayName</key>
    <string>Singpost</string>
    <key>LSRequiresIPhoneOS</key>
    <true/>
    <key>NSAppTransportSecurity</key>
    <dict>
        <key>NSAllowsArbitraryLoads</key>
        <true/>
        <key>NSAllowsArbitraryLoadsInWebContent</key>
        <true/>
        <key>NSExceptionDomains</key>
        <dict>
            <key>prdesb1.singpost.com</key>
            <dict>
                <key>NSIncludesSubdomains</key>
                <true/>
                <key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
                <true/>
                <key>NSTemporaryExceptionMinimumTLSVersion</key>
                <string>TLSv1.1</string>
                <key>NSTemporaryExceptionRequiresForwardSecrecy</key>
                <false/>
            </dict>
            <key>mobile.singpost.com</key>
            <dict>
                <key>NSIncludesSubdomains</key>
                <true/>
                <key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
                <true/>
                <key>NSTemporaryExceptionMinimumTLSVersion</key>
                <string>TLSv1.1</string>
                <key>NSTemporaryExceptionRequiresForwardSecrecy</key>
                <false/>
            </dict>
        </dict>
    </dict>
    <key>NSCameraUsageDescription</key>
    <string>$(PRODUCT_NAME) camera use</string>
    <key>NSLocationAlwaysUsageDescription</key>
    <string>    </string>
    <key>NSLocationWhenInUseUsageDescription</key>
    <string>    </string>
    <key>NSPhotoLibraryUsageDescription</key>
    <string>$(PRODUCT_NAME) uses photos</string>
    <key>UIAppFonts</key>
    <array>
        <string>OpenSans-Regular.ttf</string>
        <string>OpenSans-Bold.ttf</string>
        <string>OpenSans-Semibold.ttf</string>
        <string>OpenSans-Light.ttf</string>
        <string>OpenSans-LightItalic.ttf</string>
    </array>
    <key>UIBackgroundModes</key>
    <array>
        <string>remote-notification</string>
    </array>
    <key>UIRequiredDeviceCapabilities</key>
    <array>
        <string>armv7</string>
    </array>
    <key>UIRequiresFullScreen</key>
    <true/>
    <key>UISupportedInterfaceOrientations</key>
    <array>
        <string>UIInterfaceOrientationPortrait</string>
    </array>
    <key>UISupportedInterfaceOrientations~ipad</key>
    <array>
        <string>UIInterfaceOrientationPortrait</string>
    </array>
</dict>
</plist>

我修复了我的添加 exeptiondomain,但在控制台中出现此错误

NSURLSession/NSURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9802) –

根据建议进行编辑。我将我的 plist 更改为

<key>mobile.singpost.com</key>
            <dict>
                <key>NSIncludesSubdomains</key>
                <true/>
                <key>NSExceptionAllowsInsecureHTTPLoads</key>
                <true/>
                <key>NSExceptionMinimumTLSVersion</key>
                <string>TLSv1.1</string>
                <key>NSExceptionRequiresForwardSecrecy</key>
                <false/>
            </dict>
            <key>mysam.sg</key>
            <dict>
                <key>NSIncludesSubdomains</key>
                <true/>
                <key>NSExceptionAllowsInsecureHTTPLoads</key>
                <true/>
                <key>NSExceptionMinimumTLSVersion</key>
                <string>TLSv1.1</string>
                <key>NSExceptionRequiresForwardSecrecy</key>
                <false/>
            </dict>

【问题讨论】:

  • 您在 8.1 之前构建的 Xcode 版本是什么?你能显示你的 Info.plist 设置吗?
  • 我正在使用 Xcode 8。我正在通过添加 Exeption Domains 来修复它。但在控制台中我收到此错误:NSURLSession/NSURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9802)
  • 我使用的是 Xcode 8.1。 IOS 10.1。我正在通过添加 Exeption Domains 来修复它。但在控制台中我收到此错误:NSURLSession/NSURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9802)
  • 具体是针对哪个 URL 的?使用 nscurl 命令检查 url 导致 SSL 握手失败的原因:nscurl --ats-diagnostics https://www.domain.com。我的猜测是,这与其说是不满足 ATS 要求,不如说是关于证书信任问题。禁用 ATS 不允许您连接到证书有问题的安全 Web 服务器。但是,禁用 ATS 将允许您使用不使用最新版本/标准/密钥强度的 SSL 连接到服务器。但它并没有回答它以前是如何工作的。
  • 另外,您是否在 UIWebView 中访问这些资源?通过 NSUrlConnection?

标签: ios ios10 app-transport-security


【解决方案1】:

通过指定 NSAllowsArbitraryLoadsInWebContent,您将在 iOS 10 上覆盖 NSAllowsArbitraryLoads。

在 iOS 10 及更高版本以及 macOS 10.12 及更高版本中,如果您的应用的 Info.plist 文件中存在以下任何键,则 [NSAllowsArbitraryLoads] 键的值将被忽略:

  • NSAllowsArbitraryLoadsForMedia
  • NSAllowsArbitraryLoadsInWebContent
  • NSAllowsLocalNetworking

来源:App Transport Security dictionary primary keys(苹果)

此外,您提供的NSExceptionDomain 字典似乎与current documented format 不匹配。具体来说,键不匹配:

  • NSTemporaryExceptionAllowsInsecureHTTPLoads 应该是 NSExceptionAllowsInsecureHTTPLoads

  • NSTemporaryExceptionMinimumTLSVersion 应该是 NSExceptionMinimumTLSVersion

  • NSTemporaryExceptionRequiresForwardSecrecy 应该是 NSExceptionRequiresForwardSecrecy

【讨论】:

  • 非常感谢。我将 .plist 更改为编辑问题。那应该没问题还是我们必须包含其他plist来进行服务器连接? (我的服务器只支持 TLS 1.1)
猜你喜欢
  • 1970-01-01
  • 2017-02-13
  • 1970-01-01
  • 2016-03-06
  • 1970-01-01
  • 1970-01-01
  • 2019-10-20
  • 2019-12-03
  • 1970-01-01
相关资源
最近更新 更多