Skip to content

Commit 2c70690

Browse files
tsaarnigopherbot
authored andcommitted
crypto/tls: fix PSK binder calculation
When server and client have mismatch in curve preference, the server will send HelloRetryRequest during TLSv1.3 PSK resumption. There was a bug introduced by Go1.19.6 or later and Go1.20.1 or later, that makes the client calculate the PSK binder hash incorrectly. Server will reject the TLS handshake by sending alert: invalid PSK binder. Fixes #59424 Change-Id: I2ca8948474275740a36d991c057b62a13392dbb9 GitHub-Last-Rev: 1aad9bc GitHub-Pull-Request: #59425 Reviewed-on: https://go-review.googlesource.com/c/go/+/481955 Reviewed-by: Roland Shoemaker <[email protected]> Reviewed-by: Dmitri Shuralyov <[email protected]> Run-TryBot: Roland Shoemaker <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Auto-Submit: Roland Shoemaker <[email protected]>
1 parent 6bbbc5d commit 2c70690

2 files changed

Lines changed: 22 additions & 1 deletion

File tree

src/crypto/tls/handshake_client_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1028,6 +1028,27 @@ func testResumption(t *testing.T, version uint16) {
10281028
deleteTicket()
10291029
testResumeState("WithoutSessionTicket", false)
10301030

1031+
// In TLS 1.3, HelloRetryRequest is sent after incorrect key share.
1032+
// See https://www.rfc-editor.org/rfc/rfc8446#page-14.
1033+
if version == VersionTLS13 {
1034+
deleteTicket()
1035+
serverConfig = &Config{
1036+
// Use a different curve than the client to force a HelloRetryRequest.
1037+
CurvePreferences: []CurveID{CurveP521, CurveP384, CurveP256},
1038+
MaxVersion: version,
1039+
Certificates: testConfig.Certificates,
1040+
}
1041+
testResumeState("InitialHandshake", false)
1042+
testResumeState("WithHelloRetryRequest", true)
1043+
1044+
// Reset serverConfig back.
1045+
serverConfig = &Config{
1046+
MaxVersion: version,
1047+
CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA, TLS_ECDHE_RSA_WITH_RC4_128_SHA},
1048+
Certificates: testConfig.Certificates,
1049+
}
1050+
}
1051+
10311052
// Session resumption should work when using client certificates
10321053
deleteTicket()
10331054
serverConfig.ClientCAs = rootCAs

src/crypto/tls/handshake_client_tls13.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ func (hs *clientHandshakeStateTLS13) processHelloRetryRequest() error {
259259
transcript := hs.suite.hash.New()
260260
transcript.Write([]byte{typeMessageHash, 0, 0, uint8(len(chHash))})
261261
transcript.Write(chHash)
262-
if err := transcriptMsg(hs.serverHello, hs.transcript); err != nil {
262+
if err := transcriptMsg(hs.serverHello, transcript); err != nil {
263263
return err
264264
}
265265
helloBytes, err := hs.hello.marshalWithoutBinders()

0 commit comments

Comments
 (0)