【问题标题】:Restrict web service call if https server is hosted with non-secured SSL certificate如果 https 服务器使用非安全 SSL 证书托管,则限制 Web 服务调用
【发布时间】:2018-04-03 18:55:16
【问题描述】:

一个 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,我会收到隐私错误消息,

如果证书不安全,有没有办法限制 API 调用?

【问题讨论】:

    标签: ios web-services ssl ssl-certificate


    【解决方案1】:

    您必须在 .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>
    

    【讨论】:

    • 它没有多大帮助。因为我也需要支持http API 调用
    • 然后在 NSAppTransportSecurity 中添加不带任何 http 或 https 的 url
    猜你喜欢
    • 2019-01-05
    • 1970-01-01
    • 1970-01-01
    • 2011-01-18
    • 2014-07-23
    • 1970-01-01
    • 2013-05-24
    • 2013-11-01
    • 1970-01-01
    相关资源
    最近更新 更多