@@ -256,33 +256,32 @@ func (hs *serverHandshakeStateTLS13) processClientHello() error {
256
256
}
257
257
}
258
258
259
- // Pick the ECDHE group in server preference order, but give priority to
260
- // groups with a key share, to avoid a HelloRetryRequest round-trip.
259
+ // Pick group by server preference. In contrast to upstream Go, we will
260
+ // send an HelloRetryRequest and accept an extra roundtrip if there is
261
+ // a more preferred group, than those for which the client has sent
262
+ // a keyshare in the initial ClientHello.
263
+ // Cf. https://datatracker.ietf.org/doc/draft-davidben-tls-key-share-prediction/
261
264
var selectedGroup CurveID
262
265
var clientKeyShare * keyShare
263
266
GroupSelection:
264
267
for _ , preferredGroup := range supportedCurves {
265
- for _ , ks := range hs .clientHello .keyShares {
266
- if ks .group == preferredGroup {
267
- selectedGroup = ks .group
268
- clientKeyShare = & ks
269
- break GroupSelection
270
- }
271
- }
272
- if selectedGroup != 0 {
273
- continue
274
- }
275
268
for _ , group := range hs .clientHello .supportedCurves {
276
269
if group == preferredGroup {
277
270
selectedGroup = group
278
- break
271
+ break GroupSelection
279
272
}
280
273
}
281
274
}
282
275
if selectedGroup == 0 {
283
276
c .sendAlert (alertHandshakeFailure )
284
277
return errors .New ("tls: no ECDHE curve supported by both client and server" )
285
278
}
279
+ for _ , ks := range hs .clientHello .keyShares {
280
+ if ks .group == selectedGroup {
281
+ clientKeyShare = & ks
282
+ break
283
+ }
284
+ }
286
285
if clientKeyShare == nil {
287
286
if err := hs .doHelloRetryRequest (selectedGroup ); err != nil {
288
287
return err
0 commit comments