【发布时间】:2017-02-16 18:21:25
【问题描述】:
我是 Alamofire 的新手,但这应该很简单,我不知道为什么会遇到问题。
我正在使用 XCode8、Swift3 和 Alamofire 4.0.1,并为 iOS9 构建。
我正在访问的 URL 使用从 GoDaddy 获得的全新证书进行保护。 Chrome 和 Safari 都可以在我的 MacBookPo 上加载安全站点,一切看起来都很好。
但是下面的代码:
Alamofire.request(buildRequestString().addingPercentEncoding(withAllowedCharacters: NSCharacterSet.urlQueryAllowed)! ).validate().responseJSON { response in
switch response.result {
case .success(let data):
print(JSON(data))
case .failure(let error):
print(error)
}
}
导致以下错误:(出于安全原因,我没有替换我的地址/域)
[] nw_coretls_read_one_record tls_handshake_process: [-9801]
[] nw_endpoint_flow_protocol_error [1.1 12.345.67.890:443 in_progress socket-flow (satisfied)] TLS protocol sent error: [-9801]
[] nw_endpoint_flow_protocol_disconnected [1.1 12.345.67.890:443 in_progress socket-flow (satisfied)] Output protocol disconnected
[] nw_endpoint_resolver_receive_report [1 sub.domain.ext:443 in_progress resolver (satisfied)] received child report:[1.1 12.345.67.890:443 failed socket-flow (satisfied)]
[] nw_connection_endpoint_report [1.1 12.345.67.890:443 failed socket-flow (satisfied)] reported event flow:failed_connect, error Error Domain=kNWErrorDomainTLS Code=-9801 "Security Error: -9801" UserInfo={NSDescription=Security Error: -9801}
[] nw_connection_endpoint_report [1 sub.domain.ext:443 failed resolver (satisfied)] reported event flow:failed_connect
[] __tcp_connection_start_block_invoke 1 sending event TCP_CONNECTION_EVENT_DISCONNECTED in response to state failed and error Error Domain=kNWErrorDomainTLS Code=-9801 "Security Error: -9801" UserInfo={NSDescription=Security Error: -9801}
[] tcp_connection_event_notify 1 event: TCP_CONNECTION_EVENT_DISCONNECTED, reason: nw_connection event, should deliver: true
[] tcp_connection_cancel 1
[] nw_endpoint_handler_cancel [1 sub.domain.ext:443 failed resolver (satisfied)]
NSURLSession/NSURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9801)
[] nw_endpoint_handler_cancel [1.1 12.345.67.890:443 failed socket-flow (satisfied)]
[] nw_resolver_cancel_on_queue 0x600000101b00
[] -[NWConcrete_tcp_connection dealloc] 1
Error Domain=NSURLErrorDomain Code=-1200 "An SSL error has occurred and a secure connection to the server cannot be made." UserInfo={_kCFStreamErrorCodeKey=-9801, NSLocalizedRecoverySuggestion=Would you like to connect to the server anyway?, NSUnderlyingError=0x608000046e70 {Error Domain=kCFErrorDomainCFNetwork Code=-1200 "(null)" UserInfo={_kCFStreamPropertySSLClientCertificateState=0, _kCFNetworkCFStreamSSLErrorOriginalValue=-9801, _kCFStreamErrorDomainKey=3, _kCFStreamErrorCodeKey=-9801}}, NSLocalizedDescription=An SSL error has occurred and a secure connection to the server cannot be made., NSErrorFailingURLKey=https://sub.domain.ext/api/v1/Assignment?query=%22%22&device=%22%22, NSErrorFailingURLStringKey=https://sub.domain.ext/api/v1/Assignment?query=%22%22&device=%22%22, _kCFStreamErrorDomainKey=3}
谁能告诉我为什么会发生这个错误?即使有有效的证书,该站点似乎也不受信任。我需要调整 XCode 中的任何其他设置以允许此连接吗? Alamofire 文档似乎表明上面的代码是所有必要的。
【问题讨论】:
-
使用 ssllabs.com/ssltest/index.html 检查您的网站。检查它是否支持 TLS、前向保密密码并发送中间证书。
-
好的.. 所以我从那个网站得到了“F”的总分。看起来这个全新的证书(我昨天刚拿到)不支持 TLS 1.2?!?!?谢谢 GoDaddy……那我有什么选择?
-
TLS1.2 支持与证书本身无关。相反,这取决于您如何配置 Web 服务器。您是在站点上部署证书并启用 SSL 还是由 GoDaddy 完成的?根据您的网络服务器,启用 TLS 支持并使您的网站符合 Apple 的 ATS 标准相当容易。
-
这是在我自己的 IIS 7.5 服务器上运行的 Windows Server 2008 R2,尽管它是根据 GoDaddy 提供的说明进行设置的。我按照本教程:tecadmin.net/enable-tls-on-windows-server-and-iis/# 启用 TLS 1.2,但这似乎并没有改变任何东西。
-
备份您的注册表后,尝试使用scotthelme.co.uk/… 中所述的 IIS 加密工具来启用 TLS 和 FS 密码。 不要此时设置严格的传输安全性。
标签: ssl ios9 ios-simulator alamofire xcode8