IOS ATS适配SSL证书方案

来源:互联网 发布:java多线程调用单例 编辑:程序博客网 时间:2024/05/18 15:05

苹果公司2015年推出iOS9系统,为了提升应用程序与Web服务之间的连接安全,苹果要求所有应用程序的HTTP协议全部升级为HTTPS协议。由于iOS平台的封闭性,遭遇到的安全问题相比于Android来说要少得多,这就导致了许多iOS开发人员对于安全性方面没有太多的深入,但苹果公司强调每个开发者都应该致力于保证客户的数据的安全。在今年的WWDC大会上,苹果公司明确表示将以身作则,在iOS9中内置App Transport Security(简称ATS)功能,通过该新特性来提高操作系统的安全性。

什么是ATS功能?


ATS是iOS9和OS X El Capitan的一个新特性。开启该功能后,ATS对使用NSURLConnection, CFURL或NSURLSession 等APIs 进行的网络请求默认强制使用HTTPS加密传输,目标是提高Apple 操作系统以及应用程序的安全性。
WWDC 16 中,Apple 表示将继续在 iOS 10 和OS X 10.12 中持续收紧对普通 HTTP站点的访问限制。从 2017 年 1 月 1 日起,所有新提交到appstore中的 app 默认都将不再允许使用 NSAllowsArbitraryLoads 来绕过 ATS 限制的。也就是说,我们最好保证 与app 通讯的所有网络服务器都部署了 HTTPS 加密的,否则可能会在应用审核时遇到大麻烦。
苹果公司官方文章指出,https必须符合ATS要求,服务器必须支持传输层安全(TLS)协议1.2以上版本;证书必须使用SHA256或更高的哈希算法签名,并使用2048位以上RSA密钥或256位以上ECC算法;使用安全度更高的ECDHE加密套件。下面是苹果官方要求的3点关于SSL的技术要点:
Requirements for Connecting Using ATS
With ATS fully enabled, your app’s HTTP connections must use HTTPS and must satisfy the following security requirements:


The server certificate must meet at least one of the following trust requirements:
Issued by a certificate authority (CA) whose root certificate is incorporated into the operating system
Issued by a trusted root CA and installed by the user or a system administrator
The negotiated Transport Layer Security version must be TLS 1.2
The negotiated TLS connection cipher suite must support forward secrecy (FS) and be one of the following:
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
The leaf server certificate must be signed with one of the following types of keys:
Rivest-Shamir-Adleman (RSA) key with a length of at least 2048 bits
Elliptic-Curve Cryptography (ECC) key with a size of at least 256 bits
In addition, the leaf server certificate hashing algorithm must be Secure Hash Algorithm 2 (SHA-2) with a digest length of at least 256 (that is, SHA-256 or greater).
If ATS is not enabled, the system still performs HTTPS server trust evaluation but you can override it on a case-by-case basis, as described in HTTPS Server Trust Evaluation. With ATS fully enabled, you cannot override the default HTTPS server trust evaluation.
其中需要书必须使用SHA256或更高的哈希算法签名,并使用2048位以上RSA密钥或256位以上ECC算法证书需要从 天威诚信商务人员处购买符合要求的证书。支持TLS1.2协议和ECDHE算法需要在 Services端做相应的调整。
Nginx中,需要修改nginx.conf,在其中SSL部分修改配置:
server { 
        listen       443; 
        server_name  localhost; 
        ssl                  on; 
        ssl_certificate      server.pem; 
        ssl_certificate_key  server.key; 
        ssl_session_timeout  5m; 
        ssl_session_cache    shared:SSL:1m;
        ssl_protocols  TLSv1 TLSv1.1 TLSv1.2;
        ssl_ciphers    EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH:HIGH:!RC4:!MD5:!aNULL:!eNULL:!NULL:!DH:!EDH:!EXP:+MEDIUM;
#顺便加上一些其他的优化配置
ssl_stapling on;
ssl_stapling_verify on;
resolver 8.8.4.4 8.8.8.8 valid=300s;
resolver_timeout 10s;
ssl_prefer_server_ciphers on;
location / { 
            root   html; 
            index  index.html index.htm; 
        } 



Apache中,需要在httpd-ssl.conf或者vhost.conf中修改ssl部分:
SSLProtocol all -SSLv2 -SSLv3
SSLCipherSuite EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH:HIGH:!RC4:!MD5:!aNULL:!eNULL:!NULL:!DH:!EDH:!EXP:+MEDIUM
SSLProtocol All -SSLv2 -SSLv3
SSLHonorCipherOrder On
SSLSessionTickets Off
SSLCompression off
SSLUseStapling on
SSLStaplingCache "shmcb:logs/stapling-cache(150000)"


由于容器的一些限制,在解决IOS ATS适配SSL的问题上面推荐使用apache和nginx来安装证书,同时openssl的版本建议使用 1.0.1+,因为openssl在1.0.1以后才开始支持TLSv1.2协议,介于一些其他漏洞的因素,openssl版本 官方推荐使用1.0.1g+版本。

0 0
原创粉丝点击