diff --git a/go.mod b/go.mod index ca25db1..b19ccbf 100644 --- a/go.mod +++ b/go.mod @@ -4,6 +4,6 @@ go 1.24 require ( github.com/pires/go-proxyproto v0.8.1 - golang.org/x/crypto v0.37.0 - golang.org/x/sys v0.32.0 + golang.org/x/crypto v0.38.0 + golang.org/x/sys v0.33.0 ) diff --git a/go.sum b/go.sum index be439aa..6f4f082 100644 --- a/go.sum +++ b/go.sum @@ -6,7 +6,11 @@ golang.org/x/crypto v0.26.0 h1:RrRspgV4mU+YwB4FYnuBoKsUapNIL5cohGAmSH3azsw= golang.org/x/crypto v0.26.0/go.mod h1:GY7jblb9wI+FOo5y8/S2oY4zWP07AkOJ4+jxCqdqn54= golang.org/x/crypto v0.37.0 h1:kJNSjF/Xp7kU0iB2Z+9viTPMW4EqqsrywMXLJOOsXSE= golang.org/x/crypto v0.37.0/go.mod h1:vg+k43peMZ0pUMhYmVAWysMK35e6ioLh3wB8ZCAfbVc= +golang.org/x/crypto v0.38.0 h1:jt+WWG8IZlBnVbomuhg2Mdq0+BBQaHbtqHEFEigjUV8= +golang.org/x/crypto v0.38.0/go.mod h1:MvrbAqul58NNYPKnOra203SB9vpuZW0e+RRZV+Ggqjw= golang.org/x/sys v0.24.0 h1:Twjiwq9dn6R1fQcyiK+wQyHWfaz/BJB+YIpzU/Cv3Xg= golang.org/x/sys v0.24.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/sys v0.32.0 h1:s77OFDvIQeibCmezSnk/q6iAfkdiQaJi4VzroCFrN20= golang.org/x/sys v0.32.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k= +golang.org/x/sys v0.33.0 h1:q3i8TbbEz+JRD9ywIRlyRAQbM0qF7hu24q3teo2hbuw= +golang.org/x/sys v0.33.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k= diff --git a/handshake_client_tls13.go b/handshake_client_tls13.go index 295e527..f2f88b5 100644 --- a/handshake_client_tls13.go +++ b/handshake_client_tls13.go @@ -8,6 +8,7 @@ import ( "bytes" "context" "crypto" + "crypto/hkdf" "crypto/hmac" "crypto/mlkem" "crypto/rsa" @@ -18,7 +19,6 @@ import ( "time" "github.com/xtls/reality/tls13" - "golang.org/x/crypto/hkdf" ) type clientHandshakeStateTLS13 struct { @@ -90,12 +90,13 @@ func (hs *clientHandshakeStateTLS13) handshake() error { confTranscript.Write(hs.serverHello.original[:30]) confTranscript.Write(make([]byte, 8)) confTranscript.Write(hs.serverHello.original[38:]) - acceptConfirmation := tls13.ExpandLabel(hs.suite.hash.New, - hkdf.Extract(hs.suite.hash.New, hs.echContext.innerHello.random, nil), - "ech accept confirmation", - confTranscript.Sum(nil), - 8, - ) + h := hs.suite.hash.New + prk, err := hkdf.Extract(h, hs.echContext.innerHello.random, nil) + if err != nil { + c.sendAlert(alertInternalError) + return err + } + acceptConfirmation := tls13.ExpandLabel(h, prk, "ech accept confirmation", confTranscript.Sum(nil), 8) if subtle.ConstantTimeCompare(acceptConfirmation, hs.serverHello.random[len(hs.serverHello.random)-8:]) == 1 { hs.hello = hs.echContext.innerHello c.serverName = c.config.ServerName @@ -264,12 +265,13 @@ func (hs *clientHandshakeStateTLS13) processHelloRetryRequest() error { copy(hrrHello, hs.serverHello.original) hrrHello = bytes.Replace(hrrHello, hs.serverHello.encryptedClientHello, make([]byte, 8), 1) confTranscript.Write(hrrHello) - acceptConfirmation := tls13.ExpandLabel(hs.suite.hash.New, - hkdf.Extract(hs.suite.hash.New, hs.echContext.innerHello.random, nil), - "hrr ech accept confirmation", - confTranscript.Sum(nil), - 8, - ) + h := hs.suite.hash.New + prk, err := hkdf.Extract(h, hs.echContext.innerHello.random, nil) + if err != nil { + c.sendAlert(alertInternalError) + return err + } + acceptConfirmation := tls13.ExpandLabel(h, prk, "hrr ech accept confirmation", confTranscript.Sum(nil), 8) if subtle.ConstantTimeCompare(acceptConfirmation, hs.serverHello.encryptedClientHello) == 1 { hello = hs.echContext.innerHello c.serverName = c.config.ServerName diff --git a/handshake_server_tls13.go b/handshake_server_tls13.go index 3d51b52..119c699 100644 --- a/handshake_server_tls13.go +++ b/handshake_server_tls13.go @@ -625,13 +625,13 @@ func (hs *serverHandshakeStateTLS13) doHelloRetryRequest(selectedGroup CurveID) if err := transcriptMsg(helloRetryRequest, confTranscript); err != nil { return nil, err } - b, _ := hkdf.Extract(hs.suite.hash.New, hs.clientHello.random, nil) - acceptConfirmation := tls13.ExpandLabel(hs.suite.hash.New, - b, - "hrr ech accept confirmation", - confTranscript.Sum(nil), - 8, - ) + h := hs.suite.hash.New + prf, err := hkdf.Extract(h, hs.clientHello.random, nil) + if err != nil { + c.sendAlert(alertInternalError) + return nil, err + } + acceptConfirmation := tls13.ExpandLabel(h, prf, "hrr ech accept confirmation", confTranscript.Sum(nil), 8) helloRetryRequest.encryptedClientHello = acceptConfirmation } @@ -789,13 +789,13 @@ func (hs *serverHandshakeStateTLS13) sendServerParameters() error { return err } // compute the acceptance message - b, _ := hkdf.Extract(hs.suite.hash.New, hs.clientHello.random, nil) - acceptConfirmation := tls13.ExpandLabel(hs.suite.hash.New, - b, - "ech accept confirmation", - echTranscript.Sum(nil), - 8, - ) + h := hs.suite.hash.New + prk, err := hkdf.Extract(h, hs.clientHello.random, nil) + if err != nil { + c.sendAlert(alertInternalError) + return err + } + acceptConfirmation := tls13.ExpandLabel(h, prk, "ech accept confirmation", echTranscript.Sum(nil), 8) copy(hs.hello.random[32-8:], acceptConfirmation) }