TLS ECH client: Use chrome-fingerprint and add padding; Add "h2c" and echSockopt; Fix some issues (#4949)

Completes https://github.com/XTLS/Xray-core/pull/3813
This commit is contained in:
patterniha
2025-08-02 17:47:55 +02:00
committed by RPRX
parent 146b14ab55
commit a02723e63f
7 changed files with 224 additions and 150 deletions

View File

@@ -8,6 +8,7 @@ import (
"crypto/tls"
"crypto/x509"
"encoding/base64"
"github.com/xtls/xray-core/features/dns"
"os"
"slices"
"strings"
@@ -275,6 +276,9 @@ func getNewGetCertificateFunc(certs []*tls.Certificate, rejectUnknownSNI bool) f
}
func (c *Config) parseServerName() string {
if IsFromMitm(c.ServerName) {
return ""
}
return c.ServerName
}
@@ -447,7 +451,11 @@ func (c *Config) GetTLSConfig(opts ...Option) *tls.Config {
if len(c.EchConfigList) > 0 || len(c.EchServerKeys) > 0 {
err := ApplyECH(c, config)
if err != nil {
errors.LogError(context.Background(), err)
if c.EchForceQuery || errors.Cause(err) != dns.ErrEmptyResponse {
errors.LogError(context.Background(), err)
} else {
errors.LogInfo(context.Background(), err)
}
}
}
@@ -469,6 +477,12 @@ func WithDestination(dest net.Destination) Option {
}
}
func WithOverrideName(serverName string) Option {
return func(config *tls.Config) {
config.ServerName = serverName
}
}
// WithNextProto sets the ALPN values in TLS config.
func WithNextProto(protocol ...string) Option {
return func(config *tls.Config) {
@@ -509,3 +523,7 @@ func ParseCurveName(curveNames []string) []tls.CurveID {
}
return curveIDs
}
func IsFromMitm(str string) bool {
return strings.ToLower(str) == "frommitm"
}