-
Notifications
You must be signed in to change notification settings - Fork 160
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Change findMatchingCipherSuite #350
Conversation
Codecov Report
@@ Coverage Diff @@
## master #350 +/- ##
==========================================
+ Coverage 75.87% 75.89% +0.01%
==========================================
Files 86 86
Lines 3672 3679 +7
==========================================
+ Hits 2786 2792 +6
- Misses 601 602 +1
Partials 285 285
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
pion/dtls is used by quite a few projects outside of the WebRTC ecosystem, for which this wouldn't be appropriate at all. I don't think we should be special casing certain behaviour in here to match a particular user-agent. Our library lets you specify a list of cipher suites through |
…ame them to remote and local
@daenney Thank you for inspiring me. I dived into the code, and found that TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256 is already in the first place (see defaultCipherSuites). The problem is that function findMatchingCipherSuite confused with a and b. I renamed them to remote and local, and changed the logic. It passed the inter-op test with FreeSWITCH. |
Hey @PieerePi, so excited to get you involved. Not a lot of devs get this deep :) I see what you are talking about. So the issue is CipherSuite priority/who picks? Right now it looks like the I am totally up for switching this behavior!
|
The behaviour is usually configurable on the server side. Apache/nginx etc used to have a I think it might make sense to have a option in our |
Oh that is perfect, thanks for calling that out @daenney
@PieerePi Are you interested in taking this on? I am not able to do this soon, but I might be able to find contributors that are interested :) |
Hi @Sean-Der and @daenney, thanks for your reply! First, let me describe the issue I encountered.
In pion/dtls, I can't find any connection between the CipherSuiteID in ServerHello message and the Certificate in Certificate message. There is no constraints from the local certificate to limit how to pick cipher suite. Thanks to Sean's informative information, I studied the implementation of crypto/tls and found solution there. pickCipherSuite in crypto/tls/handshake_server.go, https://github.com/golang/go/blob/master/src/crypto/tls/handshake_server.go#L295.
But this solution might change too much code of pion/dtls, I am not familiar with pion/dtls at present and also a newbie to the Go programming language, I think I am not competent to fix this issue completely. :-) |
Sending a ServerHello with the RSA suite but then following up with a ServerCertificate with an ECDSA cert sounds like a bug on our side. That should never happen, regardless of client or server cipher suite priorities. We definitely need to fix that, if we don’t have an RSA cert we need to not pick that cipher for the ServerHello |
@daenney Yes. The implementation of crypto/tls adds more attributes for cipher suite than just an ID, gets more information from local certificate, and uses all these to check if client's cipher suite and local certificate match. |
The new function findMatchingCipherSuite in this PR picks the local preferred TLSEcdheEcdsaWithAes128GcmSha256 cipher suite in defaultCipherSuites to match the ECDSA 256 certificate set by pion/webrtc. It's just a roundabout way to avoid the problem. |
Upstream deprecated
I am going to add a test right now that confirms ECDSA/RSA causes the proper cipher suites to be used. |
We already have a test also! b8f72f3 |
change findMatchingCipherSuite to pick local prefered cipher suite from client's cipher suites when pion/dtls acting as a dtls server.
The new function findMatchingCipherSuite picks the local preferred TLSEcdheEcdsaWithAes128GcmSha256 cipher suite in defaultCipherSuites to match the ECDSA 256 certificate set by pion/webrtc.
It's just a roundabout way to avoid the inconsistency between the CipherSuiteID in ServerHello message and the Certificate in Certificate message when pion/dtls is used by pion/webrtc.
#350 (comment)
previous commit log
2nd:
Fix findMatchingCipherSuite, it confused with a and b. Rename them to remote and local, and change the logic.
1st:
Prefers ECDSA 256 cipher suite in DTLS handshake "Client Hello" process to improve compatibility
Pion returns TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA "Cipher Suite" in "Server Hello" message, but provides TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA type certificate in "Certificate" message.
// Prefers TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA like Chrome does, also because
// pion/webrtc uses it by default without any configuration interface.
// https://github.com/pion/webrtc/blob/master/dtlstransport.go#L75
func findMatchingCipherSuite(a, b []CipherSuite) (CipherSuite, bool) { //nolint
There is an old similiar issue #133.