问题
My code for ssl handshake fails since I updated xcode to 6.4 (and simulator to ios 8.4).
The error is: CFNetwork SSLHandshake failed (-9850)
The same code is performing ssl handshake successfully on ios 8.3 simulator (i've also tried ios 8.3 simulator from xcode 6.4 and it handshakes well).
Here's the piece of code that cofigures and starts handshake. I'm using swift.
self.socket.startTLS([kCFStreamSSLLevel:kCFStreamSocketSecurityLevelTLSv1,
kCFStreamSSLValidatesCertificateChain:kCFBooleanFalse])
I was trying to figure this out whole day and I couldn't even find out what the error code -9850 means. It isn't listed with all the other codes in SecureTransport.h file.
Update1:
I found out that apple introduced app transport security which means that you can declare domains you want to establish secure connection to. Anyway I tried with ATS but without any success. -9850 error is still making problems.
Update 2 - Solution
As Michal and Steven suggested in their answers I started to suspect that the main issue is on the server side which ended up to be true.
I talked with guy who implemented the server and all problems were gone after he generated new ssl certificates of length 2048. Before that they were 512.
With new certificates, code on my side works perfectly fine.
回答1:
-9850 appears in the SecureTransport.h
header buried inside the iOS 9 SDK:
errSSLWeakPeerEphemeralDHKey = -9850, /* weak ephemeral dh key */
It sounds like Michal is on the right track. A more general search for this problem led me to http://www.chromium.org/administrators/err_ssl_weak_server_ephemeral_dh_key:
As of Chrome 45, this error message is triggered if the SSL/TLS handshake attempts to use a public key, smaller than 1024 bits, for ephemeral Diffie-Hellman key agreement.
I'm not saying that iOS 9 imposes exactly the same requirements as Chrome, but I'd start looking at the server configuration and if you can increase the key size it uses for the SSL handshake.
回答2:
I believe it has something to do with coreTLS:
Description: coreTLS accepted short ephemeral Diffie-Hellman (DH) keys, as used in export-strength ephemeral DH cipher suites. This issue, also known as Logjam, allowed an attacker with a privileged network position to downgrade security to 512-bit DH if the server supported an export-strength ephemeral DH cipher suite. The issue was addressed by increasing the default minimum size allowed for DH ephemeral keys to 768 bits.
From what I can tell from your code, I guess you're using GCDAsyncSocket. It has been updated 10 months ago, so it definitely does not reflect this issue.
回答3:
When I get CFNetwork SSLHandshake failed -(*)
its because my device is connected to the network but not the internet.
来源:https://stackoverflow.com/questions/31208371/ios-8-4-cfnetwork-sslhandshake-failed-9850