如果https服务器托管了非安全SSL证书,则限制Web服务调用

时间:2018-04-03 18:55:17

标签: ios web-services ssl ssl-certificate

一个https服务器托管有非安全SSL证书,但是如果我尝试使用NSURLSession从iOS进行Web服务调用,则返回SUCCESS消息(http status code 200)一个警告,

challenge : <NSURLProtectionSpace: 0x60000000e050>: Host:ucsmv2012.xx.xxxxx.com, Server:https, Auth-Scheme:NSURLAuthenticationMethodServerTrust, Realm:(null), Port:7002, Proxy:NO, Proxy-Type:(null)

如果我尝试访问浏览器中的URL,则会收到隐私错误消息

Privacy Error

如果证书不受保护,是否有办法限制API调用?

1 个答案:

答案 0 :(得分:0)

您必须在.plist文件中的NSAppTransportSecurity字典下设置以下密钥。

<key>NSAppTransportSecurity</key>
    <dict>
        <key>NSAllowsArbitraryLoads</key>
        <true/>
        <key>NSExceptionDomains</key>
        <dict>
            <key>testdomain.com</key>
            <dict>
                <key>NSIncludesSubdomains</key>
                <true/>
                <key>NSExceptionAllowsInsecureHTTPLoads</key>
                <false/>
                <key>NSExceptionRequiresForwardSecrecy</key>
                <false/>
                <key>NSExceptionMinimumTLSVersion</key>
                <string>TLSv1.2</string>
                <key>NSThirdPartyExceptionAllowsInsecureHTTPLoads</key>
                <false/>
                <key>NSThirdPartyExceptionRequiresForwardSecrecy</key>
                <false/>
                <key>NSThirdPartyExceptionMinimumTLSVersion</key>
                <string>TLSv1.2</string>
                <key>NSRequiresCertificateTransparency</key>
                <false/>
            </dict>
        </dict>
    </dict>