原文:http://my.oschina.net/vimfung/blog/494687

iOS9中新增App Transport Security(简称ATS)特性, 主要使到原来请求的时候用到的HTTP,都转向TLS1.2协议进行传输。这也意味着所有的HTTP协议都强制使用了HTTPS协议进行传输。原文如下:

App Transport Security

App Transport Security (ATS) enforces best practices in the secure connections between an app and its back end. ATS prevents accidental disclosure, provides secure default behavior, and is easy to adopt; it is also on by default in iOS 9 and OS X v10.11. You should adopt ATS as soon as possible, regardless of whether you’re creating a new app or updating an existing one.

If you’re developing a new app, you should use HTTPS exclusively. If you have an existing app, you should use HTTPS as much as you can right now, and create a plan for migrating the rest of your app as soon as possible. In addition, your communication through higher-level APIs needs to be encrypted using TLS version 1.2 with forward secrecy. If you try to make a connection that doesn't follow this requirement, an error is thrown. If your app needs to make a request to an insecure domain, you have to specify this domain in your app's Info.plist file

如果我们在iOS9下直接进行HTTP请求是会收到如下错误提示:

App Transport Security has blocked a cleartext HTTP (http://) resource load since it is insecure. Temporary exceptions can be configured via your app's Info.plist file.

系统会告诉我们不能直接使用HTTP进行请求,需要在Info.plist新增一段用于控制ATS的配置:

1
2
3
4
5
<key>NSAppTransportSecurity</key>
<dict>
    <key>NSAllowsArbitraryLoads</key>
    <true/>
</dict>

也即:

这段配置中的NSAppTransportSecurity是ATS配置的根节点,配置了节点表示告诉系统要走自定义的ATS设置。而NSAllowsAritraryLoads节点则是控制是否禁用ATS特性,设置YES就是禁用ATS功能。

直到前面的配置可以完美的适配iOS9了,但是如果你想遵循苹果给出的标准,让自己的数据更加安全,那么需要继续往下看。

其实ATS并不单单针对HTTP进行了限制,而是对HTTPS也有一定的要求,以百度的地址为例,如果在App中请求https://baidu.com的话,是会收到如下的错误信息:

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

查阅了一下官方资料(https://developer.apple.com/library/prerelease/ios/technotes/App-Transport-Security-Technote/),发现HTTPS的请求需要满足下面的要求:

These are the App Transport Security requirements:

  • The protocol Transport Security Layer (TLS) must be at least version 1.2.

  • Connection ciphers are limited to those that provide forward secrecy (see the list of ciphers below.)

  • Certificates must use at least an SHA256 fingerprint with either a 2048 bit or greater RSA key, or a 256 bit or greater Elliptic-Curve (ECC) key.

根据原文描述,首先必须要基于TLS 1.2版本协议。再来就是连接的加密方式要提供Forward Secrecy(正向保密?这个不清楚是什么,好奇的筒子找资料吧~),文档中罗列出支持的加密算法(如下表)。最后就是证书至少要使用一个SHA256的指纹与任一个2048位或者更高位的RSA密钥,或者是256位或者更高位的ECC密钥。如果不符合其中一项,请求将被中断并返回nil。

支持Forward Secrecy的加密方式

  • TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384

  • TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256

  • TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384

  • TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA

  • TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256

  • TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA

  • TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384

  • TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256

  • TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384

  • TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256

  • TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA

我们再来看刚才的百度的地址,用浏览器打开百度的地址,然后点击链接前面的锁图标,如图:

可以看到它使用了TLS 1.2版本协议,符合第一个约定。然后可以看到使用AES_128_GCM进行加密,并使用ECDHE_RSA作为密钥交换机制的,我们可以在Forward Secrecy的列表中找到对应两条记录:

  • TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384

  • TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256

但是还不能确定百度是否提供Forward Secrecy,我们再点开证书信息,查看“签发者名称”和“公共密钥信息”两项,如图:

看到签名算法中写着“带RSA加密的SHA-1”。可以判定该加密算法不包含在上面两项中。因此百度是一个不符合ATS的要求,所以返回了错误。这时候,如果要解决这样的问题,同样需要对ATS进行配置。配置如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<key>NSAppTransportSecurity</key>
    <dict>
        <key>NSExceptionDomains</key>
        <dict>
            <key>baidu.com</key>
            <dict>
                <key>NSIncludesSubdomains</key>
                <true/>
                <key>NSExceptionRequiresForwardSecrecy</key>
                <false/>
                                <key>NSExceptionAllowsInsecureHTTPLoads</key>
                                <true/>
            </dict>
        </dict>
    </dict>

其中NSIncludesSubdomains设置为YES表示百度的子级域名都使用相同设置。NSExceptionRequiresForwardSecrecy为NO由于百度不支持ForwardSecrecy,因此屏蔽掉改功能。最后NSExceptionAllowInsecureHTTPLoads设置为YES,则表示允许访问没有证书或者是自签名、过期、主机名不匹配的证书引发的错误的域名(这里检查过百度的证书貌似没有什么问题,但是还是需要设置此项才允许访问)。

关于iOS9中的App Transport Security相关说明及适配(转)的更多相关文章

  1. iOS9中的App Transport Security

    问题:webView加载网页加载不出来 原因:苹果在iOS9 sdk中加入了App Transport Security限制(iOS9以前的iOS sdk默认关闭ATS),默认强制使用https,并且 ...

  2. 关于iOS9中配置App Transport Security(应用程序传输安全协议)

    在 在info.plist中,进行上面的配置就行了,注意的是,那个网址,你需要访问什么网址,就填写什么网址就行了. NSTemporaryExceptionAllowsInsecureHTTPLoad ...

  3. 【iOS】App Transport Security

    iOS9中新增App Transport Security(简称ATS)特性, 主要使到原来请求的时候用到的HTTP,都转向TLS1.2协议进行传输.这也意味着所有的HTTP协议都强制使用了HTTPS ...

  4. App Transport Security has blocked a cleartext HTTP (http://)

    使用SDWebImage加载“http://”开头的图片报错,错误如下: App Transport Security has blocked a cleartext HTTP (http://) r ...

  5. Xcode 遇到 App Transport Security has blocked a cleartext HTTP 错误

    今天用Xcode  创建新项目用到 URL 发送请求时,报下面的错: “App Transport Security has blocked a cleartext HTTP (http://) re ...

  6. xcode9.4 报错 error:The resource could not be loaded because the App Transport Security policy requires the use of a secure connection.

    原因 http | https 协议  不能正常使用 找到的解决方案 但是在字段名上有了变化,不过复制进去 还是会自动选择对应的 解决办法 1. 在Info.plist中添加 App Transpor ...

  7. iOS9中请求出现App Transport Security has blocked a cleartext HTTP (http://)

    错误描述: App Transport Security has blocked a cleartext HTTP (http://) resource load since it is insecu ...

  8. iOS9 beta 请求出现App Transport Security has blocked a cleartext HTTP (http://)

    iOS9 beta 请求出现App Transport Security has blocked a cleartext HTTP (http://) http://www.bubuko.com/in ...

  9. 关于App Transport Security的更新,中英文对照 --Xcode 7 --iOS9

    章节都为本人定义,无抄袭,其中英文部分内容为官方文档摘抄以及自己总结,翻译的不好,敬请指正 App Transport Security(暂且翻译为app传输安全) What is ATS? App ...

随机推荐

  1. [python] 如何用python操作Excel

    直接上代码: from openpyxl import Workbook from openpyxl.cell import get_column_letter wb = Workbook() des ...

  2. Android网络编程之Http通信

    Android中提供的HttpURLConnection和HttpClient接口可以用来开发HTTP程序.以下是本人在学习中的总结与归纳.1. HttpURLConnection接口    首先需要 ...

  3. android安卓开发问题集 XMPP篇

    1.消息推送查了下资料,后面还是使用了androidpn (1)java.security.KeyStoreException: KeyStore jks implementation not fou ...

  4. android xml布局文件属性说明

    android xml布局文件属性说明 [摘]android xml布局文件属性说明 LinearLayout和RelativeLayout 共有属性:java代码中通过btn1关联次控件androi ...

  5. java整合easyui进行的增删改操作

    首先发一下效果图 显示全部用户信息 加入用户信息 删除用户信息 编辑用户信息 以下就来介绍一下easyui的crud,在java中是怎么与后台进行交换的 前台html页面,我将它命名为crud1.ht ...

  6. jps无法获取到tomcat(java)进程

    一.问题描述: Ubuntu 10.10版本,同个JDK 1.6版本,启动tomcat后,使用jps无法获取本机Java进程. 二.jps工作原理: 1. java进程启动时,若没有指定 -Djava ...

  7. 什么是HTTP Keep-Alive呢?

    在通过调试工具查看网络请求的时候,通常在response header能看到类似下面这种:Keep-Alive: timeout=10, max=94 .那么Keep-Alive到底是什么呢? HTT ...

  8. IE6、7下inline-block不起作用

    网上查到资料是给元素设定display:inline-block,再触发layout,设定display:inline;因为所有的浏览器都支持inlie. 即: div{display:inline- ...

  9. MVC 5 + EF 6

    (一) ??运算符 C#中两个问号(“?”)的作用是判断“?”左边的对象是否为null,如果不为null则使用“?”左边的对象,如果为null则使用“?”右边的对象. (二)VS安装Entity Fr ...

  10. View和viewController的生命周期

    View和viewController的生命周期 一.ViewController的职责 对内管理与之关联的View,对外跟其他ViewController通信和协调.对于与之关联的View,View ...