mirror of
https://github.com/XTLS/Xray-core.git
synced 2025-08-23 10:06:48 +08:00
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:
@@ -2,6 +2,7 @@ package tcp
|
||||
|
||||
import (
|
||||
"context"
|
||||
gotls "crypto/tls"
|
||||
"slices"
|
||||
"strings"
|
||||
|
||||
@@ -15,10 +16,6 @@ import (
|
||||
"github.com/xtls/xray-core/transport/internet/tls"
|
||||
)
|
||||
|
||||
func IsFromMitm(str string) bool {
|
||||
return strings.ToLower(str) == "frommitm"
|
||||
}
|
||||
|
||||
// Dial dials a new TCP connection to the given destination.
|
||||
func Dial(ctx context.Context, dest net.Destination, streamSettings *internet.MemoryStreamConfig) (stat.Connection, error) {
|
||||
errors.LogInfo(ctx, "dialing TCP to ", dest)
|
||||
@@ -30,14 +27,17 @@ func Dial(ctx context.Context, dest net.Destination, streamSettings *internet.Me
|
||||
if config := tls.ConfigFromStreamSettings(streamSettings); config != nil {
|
||||
mitmServerName := session.MitmServerNameFromContext(ctx)
|
||||
mitmAlpn11 := session.MitmAlpn11FromContext(ctx)
|
||||
tlsConfig := config.GetTLSConfig(tls.WithDestination(dest))
|
||||
if IsFromMitm(tlsConfig.ServerName) {
|
||||
tlsConfig.ServerName = mitmServerName
|
||||
var tlsConfig *gotls.Config
|
||||
if tls.IsFromMitm(config.ServerName) {
|
||||
tlsConfig = config.GetTLSConfig(tls.WithOverrideName(mitmServerName))
|
||||
} else {
|
||||
tlsConfig = config.GetTLSConfig(tls.WithDestination(dest))
|
||||
}
|
||||
|
||||
isFromMitmVerify := false
|
||||
if r, ok := tlsConfig.Rand.(*tls.RandCarrier); ok && len(r.VerifyPeerCertInNames) > 0 {
|
||||
for i, name := range r.VerifyPeerCertInNames {
|
||||
if IsFromMitm(name) {
|
||||
if tls.IsFromMitm(name) {
|
||||
isFromMitmVerify = true
|
||||
r.VerifyPeerCertInNames[0], r.VerifyPeerCertInNames[i] = r.VerifyPeerCertInNames[i], r.VerifyPeerCertInNames[0]
|
||||
r.VerifyPeerCertInNames = r.VerifyPeerCertInNames[1:]
|
||||
@@ -56,7 +56,7 @@ func Dial(ctx context.Context, dest net.Destination, streamSettings *internet.Me
|
||||
}
|
||||
}
|
||||
}
|
||||
isFromMitmAlpn := len(tlsConfig.NextProtos) == 1 && IsFromMitm(tlsConfig.NextProtos[0])
|
||||
isFromMitmAlpn := len(tlsConfig.NextProtos) == 1 && tls.IsFromMitm(tlsConfig.NextProtos[0])
|
||||
if isFromMitmAlpn {
|
||||
if mitmAlpn11 {
|
||||
tlsConfig.NextProtos[0] = "http/1.1"
|
||||
|
Reference in New Issue
Block a user