]> Cypherpunks repositories - gostls13.git/commitdiff
crypto/tls: don't select ECC ciphersuites with no mutual curve.
authorAdam Langley <agl@golang.org>
Fri, 23 Mar 2012 14:48:51 +0000 (10:48 -0400)
committerAdam Langley <agl@golang.org>
Fri, 23 Mar 2012 14:48:51 +0000 (10:48 -0400)
The existing code that tried to prevent ECC ciphersuites from being
selected when there were no mutual curves still left |suite| set.
This lead to a panic on a nil pointer when there were no acceptable
ciphersuites at all.

Thanks to George Kadianakis for pointing it out.

R=golang-dev, r, bradfitz
CC=golang-dev
https://golang.org/cl/5857043

src/pkg/crypto/tls/handshake_server.go
src/pkg/crypto/tls/key_agreement.go

index 23ec5587235b5d2eebe2aa961fffc7924c99e5ee..77e56a754560a4ded5be2d13b9984969fd2afc1e 100644 (file)
@@ -60,21 +60,23 @@ FindCipherSuite:
        for _, id := range clientHello.cipherSuites {
                for _, supported := range config.cipherSuites() {
                        if id == supported {
-                               suite = nil
+                               var candidate *cipherSuite
+
                                for _, s := range cipherSuites {
                                        if s.id == id {
-                                               suite = s
+                                               candidate = s
                                                break
                                        }
                                }
-                               if suite == nil {
+                               if candidate == nil {
                                        continue
                                }
                                // Don't select a ciphersuite which we can't
                                // support for this client.
-                               if suite.elliptic && !ellipticOk {
+                               if candidate.elliptic && !ellipticOk {
                                        continue
                                }
+                               suite = candidate
                                break FindCipherSuite
                        }
                }
index 75f5c73464a14e5a4f783719d33eab6fd2af077f..a931d8fb555e784383eea48cb661c615ac80b3c2 100644 (file)
@@ -130,6 +130,10 @@ Curve:
                }
        }
 
+       if curveid == 0 {
+               return nil, errors.New("tls: no supported elliptic curves offered")
+       }
+
        var x, y *big.Int
        var err error
        ka.privateKey, x, y, err = elliptic.GenerateKey(ka.curve, config.rand())