Skip to content

Commit 577f64a

Browse files
committed
fix: X25519MLKEM768 does not work properly with reality
1 parent 025ff19 commit 577f64a

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

component/tls/reality.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
utls "github.com/metacubex/utls"
2727
"golang.org/x/crypto/chacha20poly1305"
2828
"golang.org/x/crypto/hkdf"
29+
"golang.org/x/exp/slices"
2930
"golang.org/x/net/http2"
3031
)
3132

@@ -60,6 +61,27 @@ func GetRealityConn(ctx context.Context, conn net.Conn, ClientFingerprint string
6061
return nil, err
6162
}
6263

64+
// ------for X25519MLKEM768 does not work properly with reality-------
65+
// Iterate over extensions and check
66+
for _, extension := range uConn.Extensions {
67+
if ce, ok := extension.(*utls.SupportedCurvesExtension); ok {
68+
ce.Curves = slices.DeleteFunc(ce.Curves, func(curveID utls.CurveID) bool {
69+
return curveID == utls.X25519MLKEM768
70+
})
71+
}
72+
if ks, ok := extension.(*utls.KeyShareExtension); ok {
73+
ks.KeyShares = slices.DeleteFunc(ks.KeyShares, func(share utls.KeyShare) bool {
74+
return share.Group == utls.X25519MLKEM768
75+
})
76+
}
77+
}
78+
// Rebuild the client hello
79+
err = uConn.BuildHandshakeState()
80+
if err != nil {
81+
return nil, err
82+
}
83+
// --------------------------------------------------------------------
84+
6385
hello := uConn.HandshakeState.Hello
6486
rawSessionID := hello.Raw[39 : 39+32] // the location of session ID
6587
for i := range rawSessionID { // https://github.com/golang/go/issues/5373

0 commit comments

Comments
 (0)