Fix ECH client cache sharing, retry and protocol wiring

This commit is contained in:
世界
2026-11-24 22:45:19 +08:00
parent f0fbf236f8
commit 0cdfc45e26
10 changed files with 218 additions and 121 deletions
+8 -3
View File
@@ -14,6 +14,7 @@ import (
"github.com/sagernet/sing-box/option"
"github.com/sagernet/sing-shadowtls"
"github.com/sagernet/sing/common"
E "github.com/sagernet/sing/common/exceptions"
M "github.com/sagernet/sing/common/metadata"
N "github.com/sagernet/sing/common/network"
)
@@ -38,6 +39,9 @@ func NewOutbound(ctx context.Context, router adapter.Router, logger log.ContextL
if options.Version == 0 {
options.Version = 1
}
if options.Version != 2 && options.TLS.ECH != nil && options.TLS.ECH.Enabled {
return nil, E.New("ECH is only supported in ShadowTLS v2")
}
if options.Version == 1 {
options.TLS.MinVersion = "1.2"
@@ -61,10 +65,11 @@ func NewOutbound(ctx context.Context, router adapter.Router, logger log.ContextL
return common.Error(tls.ClientHandshake(ctx, conn, tlsConfig))
}
case 3:
if idConfig, loaded := tlsConfig.(tls.WithSessionIDGenerator); loaded {
if _, loaded := tlsConfig.(tls.WithSessionIDGenerator); loaded {
tlsHandshakeFunc = func(ctx context.Context, conn net.Conn, sessionIDGenerator shadowtls.TLSSessionIDGeneratorFunc) error {
idConfig.SetSessionIDGenerator(sessionIDGenerator)
return common.Error(tls.ClientHandshake(ctx, conn, tlsConfig))
handshakeConfig := tlsConfig.Clone()
handshakeConfig.(tls.WithSessionIDGenerator).SetSessionIDGenerator(sessionIDGenerator)
return common.Error(tls.ClientHandshake(ctx, conn, handshakeConfig))
}
} else {
stdTLSConfig, err := tlsConfig.STDConfig()