IOS ATS適配SSL證書方案

蘋果公司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+版本。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章