Configuring App Transport Security Exceptions in iOS 9 and OSX 10.11

What is App Transport Security (ATS)?

At WWDC 2015, Apple announced “App Transport Security” for iOS 9 and OSX 10.11 El Capitan. The “What’s New in iOS” guide for iOS 9 explains:

*App Transport Security (ATS)* ***lets an app add a declaration to its Info.plist file*** 
*that specifies the domains with which it needs secure communication. 
ATS prevents accidental disclosure, provides secure default behavior, and is easy to adopt.
 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 simple terms, this means that if your application attempts to connect to any HTTP server (in this example, http://yourserver.com) that doesn’t support the latest SSL technology (TLSv1.2), your connections will fail with an error like this:

CFNetwork SSLHandshake failed (-9801)Error Domain=NSURLErrorDomain Code=-1200 "An SSL error has occurred 
and a secure connection to the server cannot be made." 
UserInfo=0x7fb080442170 
{NSURLErrorFailingURLPeerTrustErrorKey=<SecTrustRef: 0x7fb08043b380>, 
NSLocalizedRecoverySuggestion=Would you like to connect to the server anyway?, _kCFStreamErrorCodeKey=-9802, 
NSUnderlyingError=0x7fb08055bc00 "The operation couldn’t be completed. 
(kCFErrorDomainCFNetwork error -1200.)", 
NSLocalizedDescription=An SSL error has occurred and a secure connection to the server cannot be made., 
NSErrorFailingURLKey=https://yourserver.com, 
NSErrorFailingURLStringKey=https://yourserver.com, _kCFStreamErrorDomainKey=3}

Curiously, you’ll notice that the connection attempts to change the http protocol to https to protect against mistakes in your code where you may have accidentally misconfigured the URL. In some cases, this might actually work, but it’s also confusing.

WARNING: ATS is good for you and your users and you shouldn’t disable it!

The reason why Apple is pushing so aggressively to force secure connections is because it’s the right thing to do. Protecting personal data from being compromised over insecure wireless connections, among other things, is great for users. Just because these exceptions exist doesn’t mean you should actually use them.
If your application is connecting to third party APIs that you can’t control (such as in my case, where my application Routesy connects to public transit APIs that don’t yet support SSL) or serving as a means to load syndicated content (a browser or a news reader, for instance), these techniques might be useful to you.
The bottom line is, if you run your own API server, FIX YOUR SSL. Thanks to Dave DeLong for reminding me that I should clarify that disabling ATS is a bad idea.
That being said…

How to Bypass App Transport Security

Unfortunately, the pre-release documentation doesn’t currently include any references to this key, so many developers who are testing their preexisting apps with the new betas have been receiving this error and aren’t sure what to do about it. Thanks to some digging through the strings in the CFNetwork executable bundled with Xcode 7, I was able to find the keys necessary to configure your Info.plist.

Per-Domain Exceptions

To configure a per-domain exception so that your app can connect to a non-secure (or non TLSv1.2-enabled secure host), add these keys to your Info.plist (and note that Xcode doesn’t currently auto-complete these keys as of the first Xcode 7 beta seed):

<key>NSAppTransportSecurity</key>
<dict> 
  <key>NSExceptionDomains</key>
   <dict> <key>yourserver.com</key> 
   <dict> 
   <!--Include to allow subdomains--> 
   <key>NSIncludesSubdomains</key> <true/> 
   <!--Include to allow HTTP requests--> 
   <key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key> 
   <true/> <!--Include to specify minimum TLS version--> 
   <key>NSTemporaryExceptionMinimumTLSVersion</key> 
   <string>TLSv1.1</string>
  </dict> 
 </dict>
</dict>

There are other keys that you can use to configure App Transport Security as well, such as:

NSTemporaryExceptionRequiresForwardSecrecy
NSTemporaryThirdPartyExceptionAllowsInsecureHTTPLoads
NSTemporaryThirdPartyExceptionMinimumTLSVersion
NSTemporaryThirdPartyExceptionRequiresForwardSecrecy

When the Apple documentation is updated, you should familiarize yourself with these other keys and how they’re used. Also, note that some of these keys were listen incorrectly in the “Privacy and Your App” session at WWDC 2015 (NSExceptionAllowsInsecureHTTPLoads instead ofNSTemporaryExceptionAllowsInsecureHTTPLoads, for instance). The keys listed above are the correct ones.

But What If I Don’t Know All the Insecure Domains I Need to Use?

If your app (a third-party web browser, for instance) needs to load arbitrary content, Apple provides a way to disable ATS altogether, but I suspect it’s wise for you to use this capability sparingly:

<key>NSAppTransportSecurity</key>
<dict> 
  <!--Include to allow all connections (DANGER)-->      
  <key>NSAllowsArbitraryLoads</key> 
 <true/>
</dict>
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末鞭缭,一起剝皮案震驚了整個濱河市,隨后出現(xiàn)的幾起案子减途,更是在濱河造成了極大的恐慌阿逃,老刑警劉巖桩砰,帶你破解...
    沈念sama閱讀 206,126評論 6 481
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場離奇詭異,居然都是意外死亡悉盆,警方通過查閱死者的電腦和手機(jī)鄙麦,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 88,254評論 2 382
  • 文/潘曉璐 我一進(jìn)店門典唇,熙熙樓的掌柜王于貴愁眉苦臉地迎上來镊折,“玉大人,你說我怎么就攤上這事介衔『夼撸” “怎么了?”我有些...
    開封第一講書人閱讀 152,445評論 0 341
  • 文/不壞的土叔 我叫張陵炎咖,是天一觀的道長赃泡。 經(jīng)常有香客問我,道長乘盼,這世上最難降的妖魔是什么升熊? 我笑而不...
    開封第一講書人閱讀 55,185評論 1 278
  • 正文 為了忘掉前任,我火速辦了婚禮蹦肴,結(jié)果婚禮上僚碎,老公的妹妹穿的比我還像新娘。我一直安慰自己阴幌,他們只是感情好勺阐,可當(dāng)我...
    茶點(diǎn)故事閱讀 64,178評論 5 371
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著矛双,像睡著了一般渊抽。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上议忽,一...
    開封第一講書人閱讀 48,970評論 1 284
  • 那天懒闷,我揣著相機(jī)與錄音,去河邊找鬼栈幸。 笑死愤估,一個胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的速址。 我是一名探鬼主播玩焰,決...
    沈念sama閱讀 38,276評論 3 399
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼芍锚!你這毒婦竟也來了昔园?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 36,927評論 0 259
  • 序言:老撾萬榮一對情侶失蹤并炮,失蹤者是張志新(化名)和其女友劉穎默刚,沒想到半個月后,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體逃魄,經(jīng)...
    沈念sama閱讀 43,400評論 1 300
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡荤西,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 35,883評論 2 323
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發(fā)現(xiàn)自己被綠了。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片皂冰。...
    茶點(diǎn)故事閱讀 37,997評論 1 333
  • 序言:一個原本活蹦亂跳的男人離奇死亡店展,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出秃流,到底是詐尸還是另有隱情赂蕴,我是刑警寧澤,帶...
    沈念sama閱讀 33,646評論 4 322
  • 正文 年R本政府宣布舶胀,位于F島的核電站概说,受9級特大地震影響,放射性物質(zhì)發(fā)生泄漏嚣伐。R本人自食惡果不足惜糖赔,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 39,213評論 3 307
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望轩端。 院中可真熱鬧放典,春花似錦、人聲如沸基茵。這莊子的主人今日做“春日...
    開封第一講書人閱讀 30,204評論 0 19
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽拱层。三九已至弥臼,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間根灯,已是汗流浹背径缅。 一陣腳步聲響...
    開封第一講書人閱讀 31,423評論 1 260
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留烙肺,地道東北人纳猪。 一個月前我還...
    沈念sama閱讀 45,423評論 2 352
  • 正文 我出身青樓,卻偏偏與公主長得像桃笙,于是被迫代替她去往敵國和親兆旬。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 42,722評論 2 345

推薦閱讀更多精彩內(nèi)容