Hide ALPN in ECH

This commit is contained in:
风扇滑翔翼
2026-02-24 12:27:39 +00:00
committed by GitHub
parent e6207e3a97
commit a28e215bf0
3 changed files with 16 additions and 3 deletions
+12 -1
View File
@@ -10,6 +10,7 @@ import (
utls "github.com/refraction-networking/utls"
"github.com/xtls/xray-core/common/buf"
"github.com/xtls/xray-core/common/net"
"github.com/xtls/xray-core/common/utils"
)
type Interface interface {
@@ -97,6 +98,12 @@ func (c *UConn) WebsocketHandshakeContext(ctx context.Context) error {
if err := c.BuildHandshakeState(); err != nil {
return err
}
config := *utils.AccessField[*utls.Config](c, "config")
// Do not modify outer ALPN to http/1.1 if ECH is used
// Outer ALPN will be h2,http/1.1, and real ALPN in config will be hidden in ECH
if config.EncryptedClientHelloConfigList != nil {
return c.HandshakeContext(ctx)
}
// Iterate over extensions and check for utls.ALPNExtension
hasALPNExtension := false
for _, extension := range c.Extensions {
@@ -131,7 +138,7 @@ func GeneraticUClient(c net.Conn, config *tls.Config) *utls.UConn {
}
func copyConfig(c *tls.Config) *utls.Config {
return &utls.Config{
config := &utls.Config{
Rand: c.Rand,
RootCAs: c.RootCAs,
ServerName: c.ServerName,
@@ -140,6 +147,10 @@ func copyConfig(c *tls.Config) *utls.Config {
KeyLogWriter: c.KeyLogWriter,
EncryptedClientHelloConfigList: c.EncryptedClientHelloConfigList,
}
if config.EncryptedClientHelloConfigList != nil {
config.NextProtos = c.NextProtos
}
return config
}
func init() {