我的iOS应用程序向后端发出HTTPS请求几个月以来,出现间歇性SSL错误。
错误说明:
An SSL error has occurred and a secure connection to the server cannot be made.
Run Code Online (Sandbox Code Playgroud)
控制台在调试模式下记录:
2019-07-06 15:12:37.012198+0100 MyApp[37255:12499941] [BoringSSL] nw_protocol_boringssl_input_finished(1543) [C2.1:2][0x159e8e4a0] Peer disconnected during the middle of a handshake. Sending errSSLClosedNoNotify(-9816) alert
2019-07-06 15:12:37.026641+0100 MyApp[37255:12499941] TIC TCP Conn Failed [2:0x280486d00]: 3:-9816 Err(-9816)
2019-07-06 15:12:37.027759+0100 MyApp[37255:12499941] NSURLSession/NSURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9816)
2019-07-06 15:12:37.027839+0100 MyApp[37255:12499941] Task <D5AF17C0-C202-4229-BD52-690EFDB10379>.<1> HTTP load failed (error code: -1200 [3:-9816])
2019-07-06 15:12:37.028016+0100 MyApp[37255:12499941] Task <D5AF17C0-C202-4229-BD52-690EFDB10379>.<1> finished with error - code: -1200
2019-07-06 15:12:37.032759+0100 MyApp[37255:12500041] …Run Code Online (Sandbox Code Playgroud) ssl amazon-web-services ios amazon-elastic-beanstalk app-transport-security
此代码尝试访问并且无法访问在浏览器中工作的SSL URL:
let path = "https://localhost:8443/greeting"
let request = NSMutableURLRequest(URL: NSURL(string: path)!)
let session = NSURLSession.sharedSession()
let task = session.dataTaskWithRequest(request, completionHandler: {data, response, error -> Void in
let json:JSON = JSON(data: data!)
if let c = json["content"].string {
print(c)
}
})
task.resume()
Run Code Online (Sandbox Code Playgroud)
失败并出现错误:
可选(错误域= NSURLErrorDomain代码= -1200"发生SSL错误,无法建立与服务器的安全连接."UserInfo = {NSURLErrorFailingURLPeerTrustErrorKey =,
允许应用程序接受此证书需要什么?
有问题的证书是自签名的.在SO上阅读一些解决方案但没有成功.
运行Xcode 7.2
你运行这段代码:
let URL = "https://www.nasa.gov/sites/default/files/wave_earth_mosaic_3.jpg"
let imageData = NSData(contentsOfURL: NSURL(string: URL)!)
UIImage(data: imageData!)
Run Code Online (Sandbox Code Playgroud)
你得到这个:
2015-09-11 16:33:47.433 Cassini [21200:447896] NSURLSession/NSURLConnection HTTP加载失败(kCFStreamErrorDomainSSL,-9802)
深入挖掘显示使用SHA1签名.
maximveksler$ openssl s_client -connect www.nasa.gov:443 < /dev/null 2>/dev/null | openssl x509 -text -in /dev/stdin | grep "Signature Algorithm"
Signature Algorithm: sha1WithRSAEncryption
Signature Algorithm: sha1WithRSAEncryption
Run Code Online (Sandbox Code Playgroud)
截至2015年9月11日,美国宇航局正在使用不安全的连接,现在是什么?