Skip to content

Commit 37cedd2

Browse files
FiloSottileheschi
authored andcommitted
[release-branch.go1.18] crypto/tls: support ECDHE when ec_point_formats is missing
Updates #49126 Fixes #54642 Change-Id: I9d6f6392b1a6748bdac1d2c6371b22d75829a2b6 Reviewed-on: https://go-review.googlesource.com/c/go/+/425295 Run-TryBot: Filippo Valsorda <filippo@golang.org> Auto-Submit: Filippo Valsorda <filippo@golang.org> Reviewed-by: Alex Scheel <alex.scheel@hashicorp.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Roland Shoemaker <roland@golang.org> Reviewed-by: David Chase <drchase@google.com> (cherry picked from commit 1df2a03) Reviewed-on: https://go-review.googlesource.com/c/go/+/425636
1 parent 175c2da commit 37cedd2

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

src/crypto/tls/handshake_server.go

+8-1
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ func (hs *serverHandshakeState) processClientHello() error {
240240

241241
hs.ecdheOk = supportsECDHE(c.config, hs.clientHello.supportedCurves, hs.clientHello.supportedPoints)
242242

243-
if hs.ecdheOk {
243+
if hs.ecdheOk && len(hs.clientHello.supportedPoints) > 0 {
244244
// Although omitting the ec_point_formats extension is permitted, some
245245
// old OpenSSL version will refuse to handshake if not present.
246246
//
@@ -321,6 +321,13 @@ func supportsECDHE(c *Config, supportedCurves []CurveID, supportedPoints []uint8
321321
break
322322
}
323323
}
324+
// Per RFC 8422, Section 5.1.2, if the Supported Point Formats extension is
325+
// missing, uncompressed points are supported. If supportedPoints is empty,
326+
// the extension must be missing, as an empty extension body is rejected by
327+
// the parser. See https://go.dev/issue/49126.
328+
if len(supportedPoints) == 0 {
329+
supportsPointFormat = true
330+
}
324331

325332
return supportsCurve && supportsPointFormat
326333
}

src/crypto/tls/handshake_server_test.go

+7-14
Original file line numberDiff line numberDiff line change
@@ -281,16 +281,19 @@ func TestTLS12OnlyCipherSuites(t *testing.T) {
281281

282282
func TestTLSPointFormats(t *testing.T) {
283283
// Test that a Server returns the ec_point_format extension when ECC is
284-
// negotiated, and not returned on RSA handshake.
284+
// negotiated, and not on a RSA handshake or if ec_point_format is missing.
285285
tests := []struct {
286286
name string
287287
cipherSuites []uint16
288288
supportedCurves []CurveID
289289
supportedPoints []uint8
290290
wantSupportedPoints bool
291291
}{
292-
{"ECC", []uint16{TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA}, []CurveID{CurveP256}, []uint8{compressionNone}, true},
292+
{"ECC", []uint16{TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA}, []CurveID{CurveP256}, []uint8{pointFormatUncompressed}, true},
293+
{"ECC without ec_point_format", []uint16{TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA}, []CurveID{CurveP256}, nil, false},
294+
{"ECC with extra values", []uint16{TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA}, []CurveID{CurveP256}, []uint8{13, 37, pointFormatUncompressed, 42}, true},
293295
{"RSA", []uint16{TLS_RSA_WITH_AES_256_GCM_SHA384}, nil, nil, false},
296+
{"RSA with ec_point_format", []uint16{TLS_RSA_WITH_AES_256_GCM_SHA384}, nil, []uint8{pointFormatUncompressed}, false},
294297
}
295298
for _, tt := range tests {
296299
t.Run(tt.name, func(t *testing.T) {
@@ -330,18 +333,8 @@ func TestTLSPointFormats(t *testing.T) {
330333
t.Fatalf("didn't get ServerHello message in reply. Got %v\n", reply)
331334
}
332335
if tt.wantSupportedPoints {
333-
if len(serverHello.supportedPoints) < 1 {
334-
t.Fatal("missing ec_point_format extension from server")
335-
}
336-
found := false
337-
for _, p := range serverHello.supportedPoints {
338-
if p == pointFormatUncompressed {
339-
found = true
340-
break
341-
}
342-
}
343-
if !found {
344-
t.Fatal("missing uncompressed format in ec_point_format extension from server")
336+
if !bytes.Equal(serverHello.supportedPoints, []uint8{pointFormatUncompressed}) {
337+
t.Fatal("incorrect ec_point_format extension from server")
345338
}
346339
} else {
347340
if len(serverHello.supportedPoints) != 0 {

0 commit comments

Comments
 (0)