应用程序传输安全,在升级到IOS 10.1后,允许任意载入不起作用。

16
我有一个在iOS 9和10.0中运行良好的应用程序。我已经将“Allow Arbitrary Loads = YES”添加到我的info.plist中,以阻止App Transport Security。但是在升级到10.1和Xcode 8.1之后,似乎出现了与App Transport Security有关的问题。我无法连接到服务器。我的服务器只支持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>

我修复了我的 add exception domain,但在控制台上出现了这个错误。

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>

您IP地址为143.198.54.68,由于运营成本限制,当前对于免费用户的使用频率限制为每个IP每72小时10次对话,如需解除限制,请点击左下角设置图标按钮(手机用户先点击左上角菜单按钮)。 - Lê Khánh Vinh
哪个URL具体有问题?使用nscurl命令检查URL的SSL握手失败原因:nscurl --ats-diagnostics https://www.domain.com。我猜测这不是因为未满足ATS要求,而更可能是证书信任问题。禁用ATS不能让您连接到存在证书问题的安全Web服务器。但是,禁用ATS将允许您连接到使用不是最新版本/标准/密钥强度的SSL的服务器。这并没有回答之前如何能够正常工作的问题。 - wottle
嗨,这是我的当前日志:https://docs.google.com/document/d/16APWQippnSNr0_BWqDQd36kzRA6IpbsLSHKIt0xgEFY/edit?usp=sharing - Lê Khánh Vinh
嗨,是的,我们使用了那个服务器。我经常遇到这个错误NSURLSession/NSURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9802) - - Lê Khánh Vinh
你确定在iOS 10.0设备和10.1设备上运行的是完全相同的构建版本吗?因为ATS异常在我们的10.1设备上仍然正常工作,这里可能还有其他问题。虽然我们有不同的异常情况,但我建议向苹果公司提交一个radar报告。 - wottle
显示剩余5条评论
1个回答

20
通过指定NSAllowsArbitraryLoadsInWebContent,您可以在iOS 10上覆盖NSAllowsArbitraryLoads
在iOS 10及更高版本以及macOS 10.12及更高版本中,如果以下任何键存在于您的应用程序的Info.plist文件中,则将忽略NSAllowsArbitraryLoads键的值:
- NSAllowsArbitraryLoadsForMedia - NSAllowsArbitraryLoadsInWebContent - NSAllowsLocalNetworking
来源:App Transport Security dictionary primary keys (Apple)
此外,您提供的NSExceptionDomain字典似乎与当前文档格式不匹配。具体来说,键不匹配:
  • NSTemporaryExceptionAllowsInsecureHTTPLoads 应该是 NSExceptionAllowsInsecureHTTPLoads

  • NSTemporaryExceptionMinimumTLSVersion 应该是 NSExceptionMinimumTLSVersion

  • NSTemporaryExceptionRequiresForwardSecrecy 应该是 NSExceptionRequiresForwardSecrecy


非常感谢。我更改了我的.plist文件以编辑问题。这样可以吗,还是我们需要包含其他用于服务器连接的plist文件?(我的服务器仅支持TLS 1.1) - Lê Khánh Vinh

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接