Gra*_*son 412 url nsurl ios ios9 app-transport-security
因此,昨晚发布的iOS新测试版SDK具有"App Transport Security",鼓励开发人员使用https而不是http.原则上,这是一个好主意,我已经在我们的临时/生产环境中使用https.但是,当iOS应用程序连接到我在笔记本电脑上运行的Web服务时,我的本地开发环境中没有设置https.
从今天早上的一些游戏中可以看出,URL加载系统即使您将其设为http URL,也会决定使用https.有谁知道如何禁用此行为 - 即使只是针对特定的URL?
adu*_*din 680
有关完整详细信息,请参阅Apple的Info.plist参考(感谢@ gnasher729).
您可以在Info.plist中为特定域添加例外:
<key>NSAppTransportSecurity</key>
<dict>
<key>NSExceptionDomains</key>
<dict>
<key>testdomain.com</key>
<dict>
<key>NSIncludesSubdomains</key>
<true/>
<key>NSExceptionAllowsInsecureHTTPLoads</key>
<true/>
<key>NSExceptionRequiresForwardSecrecy</key>
<true/>
<key>NSExceptionMinimumTLSVersion</key>
<string>TLSv1.2</string>
<key>NSThirdPartyExceptionAllowsInsecureHTTPLoads</key>
<false/>
<key>NSThirdPartyExceptionRequiresForwardSecrecy</key>
<true/>
<key>NSThirdPartyExceptionMinimumTLSVersion</key>
<string>TLSv1.2</string>
<key>NSRequiresCertificateTransparency</key>
<false/>
</dict>
</dict>
</dict>
Run Code Online (Sandbox Code Playgroud)
每个例外域的所有密钥都是可选的.演讲者没有详细说明任何一个键,但我认为它们都是相当明显的.
(来源:WWDC 2015会议703,"隐私和你的应用",30:18)
如果您的应用有充分的理由,您还可以使用单个密钥忽略所有应用传输安全限制:
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
Run Code Online (Sandbox Code Playgroud)
如果您的应用没有充分的理由,您可能会有拒绝的风险:
将NSAllowsArbitraryLoads设置为true将允许它工作,但Apple非常清楚他们打算拒绝使用此标志的应用程序而没有特定原因.使用NSAllowsArbitraryLoads的主要原因我可以想到的是用户创建的内容(链接共享,自定义Web浏览器等).在这种情况下,Apple仍然希望您包含对您控制的URL强制执行ATS的例外情况.
如果确实需要访问未通过TLS 1.2提供的特定URL,则需要为这些域编写特定的例外,而不是使用设置为yes的NSAllowsArbitraryLoads.您可以在NSURLSesssion WWDC会话中找到更多信息.
请小心共享NSAllowsArbitraryLoads解决方案.这不是Apple的推荐修复.
- kcharwood(感谢@ marco-tolman)
Aks*_*ani 106
由于已接受的答案提供了所需的信息,有关使用和禁用App Transport Security的更多信息,可以在此处找到更多信息.
对于Per-Domain Exceptions,将这些添加到Info.plist:
<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>
Run Code Online (Sandbox Code Playgroud)
但如果我不知道我需要使用的所有不安全域,该怎么办? 在Info.plist中使用以下键
<key>NSAppTransportSecurity</key>
<dict>
<!--Include to allow all connections (DANGER)-->
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
Run Code Online (Sandbox Code Playgroud)
Man*_*Mal 54
跟着这个.
我已经通过在info.plist中添加一些键来解决它.我遵循的步骤是:
打开我的Projects info.plist
文件
增加了一个名为关键NSAppTransportSecurity
的Dictionary
.
NSAllowsArbitraryLoads
as 的子键Boolean
,并将其值设置YES
为如下图所示.
清洁项目,现在一切正常,就像以前一样.
参考链接.
Ian*_*Ian 31
如果您只想为本地开发服务器禁用应用传输策略,则以下解决方案可以正常运行.当您无法或无法设置HTTPS时(例如,在使用Google App Engine开发服务器时),此功能非常有用.
正如其他人所说的那样,对于生产应用程序,绝对不能关闭ATP.
复制您的Plist文件和NSAllowsArbitraryLoads.使用此Plist进行调试.
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
Run Code Online (Sandbox Code Playgroud)
或者,您可以使用单个plist文件并排除特定服务器.但是,您似乎不能排除IP 4地址,因此您可能需要使用服务器名称(可在系统首选项 - >共享中找到,或在本地DNS中配置).
<key>NSAppTransportSecurity</key>
<dict>
<key>NSExceptionDomains</key>
<dict>
<key>server.local</key>
<dict/>
<key>NSExceptionAllowsInsecureHTTPLoads</key>
<true/>
</dict>
</dict>
Run Code Online (Sandbox Code Playgroud)
Avi*_*651 29
我已解决为plist文件.
Dam*_*ito 21
上面的配置对我不起作用.我尝试了很多键组合,这个工作正常:
<key>NSAppTransportSecurity</key>
<dict>
<key>NSExceptionDomains</key>
<dict>
<key>mydomain.com</key>
<dict>
<key>NSIncludesSubdomains</key>
<true/>
<key>NSExceptionAllowsInsecureHTTPLoads</key>
<true/>
<key>NSExceptionRequiresForwardSecrecy</key>
<false/>
</dict>
</dict>
</dict>
Run Code Online (Sandbox Code Playgroud)
Aqi*_*taz 17
编译@adurdin和@User给出的答案
将以下内容添加到您的info.plist并localhost.com
使用相应的域名进行更改,您还可以添加多个域:
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
<key>NSExceptionDomains</key>
<dict>
<key>localhost.com</key>
<dict>
<key>NSIncludesSubdomains</key>
<false/>
<key>NSExceptionAllowsInsecureHTTPLoads</key>
<false/>
<key>NSExceptionRequiresForwardSecrecy</key>
<true/>
<key>NSExceptionMinimumTLSVersion</key>
<string>TLSv1.2</string>
<key>NSThirdPartyExceptionAllowsInsecureHTTPLoads</key>
<false/>
<key>NSThirdPartyExceptionRequiresForwardSecrecy</key>
<true/>
<key>NSThirdPartyExceptionMinimumTLSVersion</key>
<string>TLSv1.2</string>
<key>NSRequiresCertificateTransparency</key>
<false/>
</dict>
</dict>
</dict>
</plist>
Run Code Online (Sandbox Code Playgroud)
你info.plist必须如下所示:
0ye*_*eoj 13
这对我有用:
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<false/>
<key>NSExceptionDomains</key>
<dict>
<key><!-- your_remote_server.com / localhost --></key>
<dict>
<key>NSIncludesSubdomains</key>
<true/>
<key>NSExceptionAllowsInsecureHTTPLoads</key>
<true/>
<key>NSExceptionRequiresForwardSecrecy</key>
<true/>
</dict>
<!-- add more domain here -->
</dict>
</dict>
Run Code Online (Sandbox Code Playgroud)
我只是想添加它来帮助别人并节省一些时间:
如果你正在使用:CFStreamCreatePairWithSocketToHost
.确保你的host
内容与你的内容相同,.plist
或者你有单独的socket域名,只需将其添加到那里.
CFStreamCreatePairWithSocketToHost(NULL, (__bridge CFStringRef)/*from .plist*/, (unsigned int)port, &readStream, &writeStream);
Run Code Online (Sandbox Code Playgroud)
希望这是有帮助的.干杯.:)
归档时间: |
|
查看次数: |
356286 次 |
最近记录: |