mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
crypto/tls: pick ECDHE curves based on server preference.
Currently an ECDHE handshake uses the client's curve preference. This generally means that we use P-521. However, P-521's strength is mismatched with the rest of the cipher suite in most cases and we have a fast, constant-time implementation of P-256. With this change, Go servers will use P-256 where the client supports it although that can be overridden in the Config. LGTM=bradfitz R=bradfitz CC=golang-codereviews https://golang.org/cl/66060043
This commit is contained in:
parent
e6e8945001
commit
db99a8faa8
30 changed files with 793 additions and 801 deletions
|
|
@ -82,12 +82,14 @@ const (
|
|||
scsvRenegotiation uint16 = 0x00ff
|
||||
)
|
||||
|
||||
// TLS Elliptic Curves
|
||||
// CurveID is the type of a TLS identifier for an elliptic curve. See
|
||||
// http://www.iana.org/assignments/tls-parameters/tls-parameters.xml#tls-parameters-8
|
||||
type CurveID uint16
|
||||
|
||||
const (
|
||||
curveP256 uint16 = 23
|
||||
curveP384 uint16 = 24
|
||||
curveP521 uint16 = 25
|
||||
CurveP256 CurveID = 23
|
||||
CurveP384 CurveID = 24
|
||||
CurveP521 CurveID = 25
|
||||
)
|
||||
|
||||
// TLS Elliptic Curve Point Formats
|
||||
|
|
@ -290,6 +292,11 @@ type Config struct {
|
|||
// which is currently TLS 1.2.
|
||||
MaxVersion uint16
|
||||
|
||||
// CurvePreferences contains the elliptic curves that will be used in
|
||||
// an ECDHE handshake, in preference order. If empty, the default will
|
||||
// be used.
|
||||
CurvePreferences []CurveID
|
||||
|
||||
serverInitOnce sync.Once // guards calling (*Config).serverInit
|
||||
}
|
||||
|
||||
|
|
@ -348,6 +355,15 @@ func (c *Config) maxVersion() uint16 {
|
|||
return c.MaxVersion
|
||||
}
|
||||
|
||||
var defaultCurvePreferences = []CurveID{CurveP256, CurveP384, CurveP521}
|
||||
|
||||
func (c *Config) curvePreferences() []CurveID {
|
||||
if c == nil || len(c.CurvePreferences) == 0 {
|
||||
return defaultCurvePreferences
|
||||
}
|
||||
return c.CurvePreferences
|
||||
}
|
||||
|
||||
// mutualVersion returns the protocol version to use given the advertised
|
||||
// version of the peer.
|
||||
func (c *Config) mutualVersion(vers uint16) (uint16, bool) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue