Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
CFNetwork SSLHandshake在iOS 9中失败_Ios_Ssl_Nsurlconnection_Ios9 - Fatal编程技术网

CFNetwork SSLHandshake在iOS 9中失败

CFNetwork SSLHandshake在iOS 9中失败,ios,ssl,nsurlconnection,ios9,Ios,Ssl,Nsurlconnection,Ios9,iOS 9 beta 1版有人有过这个问题吗 我使用标准NSURLConnection连接到Web服务,一旦调用Web服务,我就会得到以下错误。这目前在iOS 8.3中运行 可能的测试错误?任何想法都会很棒!我知道这是iOS 9开发的早期阶段 以下是全部错误: CFN网络SSLHandshake失败(-9824) NSURLSession/NSURLConnection HTTP加载失败(kCFStreamErrorDomainSSL,-9824) 除非在应用程序的Info.plist文件中指定

iOS 9 beta 1版有人有过这个问题吗

我使用标准NSURLConnection连接到Web服务,一旦调用Web服务,我就会得到以下错误。这目前在iOS 8.3中运行

可能的测试错误?任何想法都会很棒!我知道这是iOS 9开发的早期阶段

以下是全部错误:

CFN网络SSLHandshake失败(-9824) NSURLSession/NSURLConnection HTTP加载失败(kCFStreamErrorDomainSSL,-9824)


除非在应用程序的Info.plist文件中指定了例外域,否则iOS 9和OSX 10.11要求所有计划从中请求数据的主机使用TLSv1.2 SSL


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 insecure HTTP requests-->
      <key>NSExceptionAllowsInsecureHTTPLoads</key>
      <true/>
      <!--Include to specify minimum TLS version-->
      <key>NSExceptionMinimumTLSVersion</key>
      <string>TLSv1.1</string>
    </dict>
  </dict>
</dict>
<key>NSAppTransportSecurity</key>
<dict>
    <!--Connect to anything (this is probably BAD)-->
    <key>NSAllowsArbitraryLoads</key>
    <true/>
</dict>
NSAppTransportSecurity
NSExceptionDomains
yourserver.com
n包括多个域
N异常低安全Http负载
NSExceptionMinimumTLSVersion
TLSv1.1
如果您的应用程序(例如,第三方web浏览器)需要连接到任意主机,则可以如下配置:

<key>NSAppTransportSecurity</key>
<dict>
  <key>NSExceptionDomains</key>
  <dict>
    <key>yourserver.com</key>
    <dict>
      <!--Include to allow subdomains-->
      <key>NSIncludesSubdomains</key>
      <true/>
      <!--Include to allow insecure HTTP requests-->
      <key>NSExceptionAllowsInsecureHTTPLoads</key>
      <true/>
      <!--Include to specify minimum TLS version-->
      <key>NSExceptionMinimumTLSVersion</key>
      <string>TLSv1.1</string>
    </dict>
  </dict>
</dict>
<key>NSAppTransportSecurity</key>
<dict>
    <!--Connect to anything (this is probably BAD)-->
    <key>NSAllowsArbitraryLoads</key>
    <true/>
</dict>
NSAppTransportSecurity
NSAllowsArbitraryLoads
如果您必须这样做,那么最好更新您的服务器以使用TLSv1.2和SSL,如果它们还没有这样做的话。这应被视为临时解决办法


到目前为止,预发布文档没有以任何特定的方式提及这些配置选项。完成后,我将更新答案以链接到相关文档。

在iOS 10+中,TLS字符串的格式必须为“TLSv1.0”。它不能只是“1.0”。(叹气)


以下是其他答案的组合

假设您正在尝试连接到只有TLS 1.0的主机(YOUR_host.COM)

将这些添加到应用程序的Info.plist

<key>NSAppTransportSecurity</key>
<dict>
    <key>NSExceptionDomains</key>
    <dict>
        <key>YOUR_HOST.COM</key>
        <dict>
            <key>NSIncludesSubdomains</key>
            <true/>
            <key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
            <true/>
            <key>NSTemporaryExceptionMinimumTLSVersion</key>
            <string>TLSv1.0</string>
            <key>NSTemporaryExceptionRequiresForwardSecrecy</key>
            <false/>
        </dict>
    </dict>
</dict>
NSAppTransportSecurity
NSExceptionDomains
YOUR_HOST.COM
n包括多个域
NSTemporary ExceptionalLowsInSecureHttpLoads
NSTemporaryExceptionMinimumTLSVersion
TLSv1.0
N临时例外要求转发保密
了解更多信息

奇怪的是,您会注意到连接试图更改 http协议到https,以防止代码中的错误 您可能意外地错误配置了URL。在某些情况下 可能真的有用,但也令人困惑

本文介绍了一些很好的调试技巧

ATS故障

大多数ATS故障将显示为CFErrors,代码为-9800 系列这些在Security/SecureTransport.h标头中定义

CFU网络诊断

将环境变量CFNETWORK_DIAGNOSTICS设置为1,以便 在控制台上获取有关故障的更多信息

nscurl

该工具将运行几个不同的ATS组合 异常,尝试在每个 ATS配置并报告结果


如果您的后端使用安全连接ant,则可以使用NSURLSession获得

CFNetwork SSLHandshake failed (-9801)
NSURLSession/NSURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9801)
您需要检查服务器配置,尤其是获取ATS版本和SSL证书信息:

通过设置
NSExceptionAllowsInsecureHTTPLoads=YES
,而不是只允许不安全的连接,相反,您需要允许降低安全性,以防您的服务器不满足ATS的最低要求(v1.2)(或更好地修复服务器端)

允许降低单个服务器的安全性

<key>NSExceptionDomains</key>
<dict>
    <key>api.yourDomaine.com</key>
    <dict>
        <key>NSExceptionMinimumTLSVersion</key>
        <string>TLSv1.0</string>
        <key>NSExceptionRequiresForwardSecrecy</key>
        <false/>
    </dict>
</dict>
…在最后找到

SSL-Session:
    Protocol  : TLSv1
    Cipher    : AES256-SHA
    Session-ID: //
    Session-ID-ctx: 
    Master-Key: //
    Key-Arg   : None
    Start Time: 1449693038
    Timeout   : 300 (sec)
    Verify return code: 0 (ok)
应用程序传输安全(ATS)需要传输层安全(TLS)协议版本1.2

使用应用程序传输安全性(ATS)的web服务连接要求涉及服务器、连接密码和证书,如下所示:

证书必须使用以下类型的密钥之一进行签名:

  • 摘要长度至少为256(即SHA-256或更大)的安全哈希算法2(SHA-2)密钥

  • 大小至少为256位的椭圆曲线密码(ECC)密钥

  • Rivest Shamir Adleman(RSA)密钥,长度至少为2048位 无效证书会导致硬故障和无连接

以下连接密码支持前向保密(FS)和工作 使用自动测试系统:

TLS_ECDHE_ECDSA_与_AES_256_GCM_SHA384 TLS_ECDHE_ECDSA_与_AES_128_GCM_SHA256 TLS_ECDHE_ECDSA_与_AES_256_CBC_SHA384 TLS_ECDHE_ECDSA_与_AES_256_CBC_SHA TLS_ECDHE_ECDSA_与_AES_128_CBC_SHA256 TLS_ECDHE_ECDSA_与_AES_128_CBC_SHA TLS_ECDHE_RSA_与_AES_256_GCM_SHA384 TLS_ECDHE_RSA_与_AES_128_GCM_SHA256 TLS_ECDHE_RSA_与_AES_256_CBC_SHA384 TLS_ECDHE_RSA_与_AES_128_CBC_SHA256 TLS_ECDHE_RSA_与_AES_128_CBC_SHA


更新:事实证明,openssl只提供了最低协议版本协议:TLSv1

当我使用有缺陷的/crashy Cordova iOS版本时,这个错误有时会出现在日志中。当我升级或降级cordova iOS时,它消失了


我连接的服务器使用的是TLSv1.2 SSL,因此我知道这不是问题所在。

在您的项目中
.plist
文件中添加此权限:

<key>NSAppTransportSecurity</key>
<dict>
    <!--Connect to anything (this is probably BAD)-->
    <key>NSAllowsArbitraryLoads</key>
    <true/>
</dict>
NSAppTransportSecurity
NSAllowsArbitraryLoads

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 insecure HTTP requests-->
  <key>NSExceptionAllowsInsecureHTTPLoads</key>
  <true/>
  <!--Include to specify minimum TLS version-->
  <key>NSExceptionMinimumTLSVersion</key>
  <string>TLSv1.1</string>
   </dict>
 </dict>
NSAppTransportSecurity
NSExceptionDomains
yourserver.com
n包括多个域
N异常低安全Http负载
NSExceptionMinimumTLSVersion
TLSv1.1

最新答案(2016年世界大战后):

iOS应用程序将在年底前需要安全的HTTPS连接 2016尝试关闭ATS可能会导致您的应用在将来被拒绝

应用程序传输
<key>NSAppTransportSecurity</key>
<dict>
    <!--Connect to anything (this is probably BAD)-->
    <key>NSAllowsArbitraryLoads</key>
    <true/>
</dict>
   <key>NSAppTransportSecurity</key>
   <dict>
   <key>NSExceptionDomains</key>
    <dict>
    <key>yourserver.com</key>
   <dict>
  <!--Include to allow subdomains-->
  <key>NSIncludesSubdomains</key>
  <true/>
  <!--Include to allow insecure HTTP requests-->
  <key>NSExceptionAllowsInsecureHTTPLoads</key>
  <true/>
  <!--Include to specify minimum TLS version-->
  <key>NSExceptionMinimumTLSVersion</key>
  <string>TLSv1.1</string>
   </dict>
 </dict>
nmap --script ssl-enum-ciphers -p 443 google.com
Starting Nmap 7.12 ( https://nmap.org ) at 2016-08-11 17:25 IDT
Nmap scan report for google.com (172.217.23.46)
Host is up (0.061s latency).
Other addresses for google.com (not scanned): 2a00:1450:4009:80a::200e
PORT    STATE SERVICE
443/tcp open  https
| ssl-enum-ciphers: 
|   TLSv1.0: 
|     ciphers: 
|       TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA (secp256r1) - A
|       TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA (secp256r1) - A
|       TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA (secp256r1) - A
|       TLS_RSA_WITH_AES_128_CBC_SHA (rsa 2048) - A
|       TLS_RSA_WITH_3DES_EDE_CBC_SHA (rsa 2048) - C
|       TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA (secp256r1) - A
|       TLS_RSA_WITH_AES_256_CBC_SHA (rsa 2048) - A
|     compressors: 
|       NULL
|     cipher preference: server
|   TLSv1.1: 
|     ciphers: 
|       TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA (secp256r1) - A
|       TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA (secp256r1) - A
|       TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA (secp256r1) - A
|       TLS_RSA_WITH_AES_128_CBC_SHA (rsa 2048) - A
|       TLS_RSA_WITH_3DES_EDE_CBC_SHA (rsa 2048) - C
|       TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA (secp256r1) - A
|       TLS_RSA_WITH_AES_256_CBC_SHA (rsa 2048) - A
|     compressors: 
|       NULL
|     cipher preference: server
|   TLSv1.2: 
|     ciphers: 
|       TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA (secp256r1) - A
|       TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256 (secp256r1) - A
|       TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256 (secp256r1) - A
|       TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA (secp256r1) - A
|       TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384 (secp256r1) - A
|       TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384 (secp256r1) - A
|       TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256 (secp256r1) - A
|       TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA (secp256r1) - A
|       TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256 (secp256r1) - A
|       TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (secp256r1) - A
|       TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA (secp256r1) - A
|       TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384 (secp256r1) - A
|       TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (secp256r1) - A
|       TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256 (secp256r1) - A
|       TLS_RSA_WITH_3DES_EDE_CBC_SHA (rsa 2048) - C
|       TLS_RSA_WITH_AES_128_CBC_SHA (rsa 2048) - A
|       TLS_RSA_WITH_AES_128_CBC_SHA256 (rsa 2048) - A
|       TLS_RSA_WITH_AES_128_GCM_SHA256 (rsa 2048) - A
|       TLS_RSA_WITH_AES_256_CBC_SHA (rsa 2048) - A
|       TLS_RSA_WITH_AES_256_CBC_SHA256 (rsa 2048) - A
|       TLS_RSA_WITH_AES_256_GCM_SHA384 (rsa 2048) - A
|     compressors: 
|       NULL
|     cipher preference: client
|_  least strength: C

Nmap done: 1 IP address (1 host up) scanned in 5.48 seconds
  NSTemporaryExceptionMinimumTLSVersion
  NSExceptionMinimumTLSVersion
<key>NSAppTransportSecurity</key>
    <dict>
        <key>NSExceptionDomains</key>
        <dict>
            <key>YOUR_HOST.COM</key>
            <dict>
                <key>NSExceptionAllowsInsecureHTTPLoads</key>
                <true/>
                <key>NSExceptionMinimumTLSVersion</key>
                <string>TLSv1.0</string>
                <key>NSExceptionRequiresForwardSecrecy</key>
                <false/>
                <key>NSIncludesSubdomains</key>
                <true/>
            </dict>
        </dict>
    </dict>