Skip to content

Commit d900c71

Browse files
committed
fix: shadowtls v2 not work with X25519MLKEM768
1 parent 1672750 commit d900c71

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

transport/sing-shadowtls/shadowtls.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func NewShadowTLS(ctx context.Context, conn net.Conn, option *ShadowTLSOption) (
4949
return nil, err
5050
}
5151

52-
tlsHandshake := uTLSHandshakeFunc(tlsConfig, option.ClientFingerprint)
52+
tlsHandshake := uTLSHandshakeFunc(tlsConfig, option.ClientFingerprint, option.Version)
5353
client, err := shadowtls.NewClient(shadowtls.ClientConfig{
5454
Version: option.Version,
5555
Password: option.Password,
@@ -62,15 +62,19 @@ func NewShadowTLS(ctx context.Context, conn net.Conn, option *ShadowTLSOption) (
6262
return client.DialContextConn(ctx, conn)
6363
}
6464

65-
func uTLSHandshakeFunc(config *tls.Config, clientFingerprint string) shadowtls.TLSHandshakeFunc {
65+
func uTLSHandshakeFunc(config *tls.Config, clientFingerprint string, version int) shadowtls.TLSHandshakeFunc {
6666
return func(ctx context.Context, conn net.Conn, sessionIDGenerator shadowtls.TLSSessionIDGeneratorFunc) error {
6767
tlsConfig := tlsC.UConfig(config)
6868
tlsConfig.SessionIDGenerator = sessionIDGenerator
69-
if config.MaxVersion == tls.VersionTLS12 { // for ShadowTLS v1
69+
if version == 1 {
70+
tlsConfig.MaxVersion = tlsC.VersionTLS12 // ShadowTLS v1 only support TLS 1.2
7071
tlsConn := tlsC.Client(conn, tlsConfig)
7172
return tlsConn.HandshakeContext(ctx)
7273
}
7374
if clientFingerprint, ok := tlsC.GetFingerprint(clientFingerprint); ok {
75+
if version == 2 && clientFingerprint == tlsC.HelloChrome_Auto {
76+
clientFingerprint = tlsC.HelloChrome_120 // ShadowTLS v2 not work with X25519MLKEM768
77+
}
7478
tlsConn := tlsC.UClient(conn, tlsConfig, clientFingerprint)
7579
if slices.Equal(tlsConfig.NextProtos, WsALPN) {
7680
err := tlsC.BuildWebsocketHandshakeState(tlsConn)

0 commit comments

Comments
 (0)