From d7c2c33547bf2553e2abe5400698b47819fb693e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=A3=8E=E6=89=87=E6=BB=91=E7=BF=94=E7=BF=BC?= Date: Sun, 15 Sep 2024 05:17:39 +0000 Subject: [PATCH] Skip if not go1.23 --- go.mod | 2 +- transport/internet/tls/config.go | 5 ++--- transport/internet/tls/ech.go | 21 +++++++++++++++++++++ transport/internet/tls/ech_go121.go | 14 ++++++++++++++ 4 files changed, 38 insertions(+), 4 deletions(-) create mode 100644 transport/internet/tls/ech.go create mode 100644 transport/internet/tls/ech_go121.go diff --git a/go.mod b/go.mod index bc740787..e851f44c 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/xtls/xray-core -go 1.23 +go 1.21.4 require ( github.com/OmarTariq612/goech v0.0.0-20240405204721-8e2e1dafd3a0 diff --git a/transport/internet/tls/config.go b/transport/internet/tls/config.go index 36f2eac5..8518ac95 100644 --- a/transport/internet/tls/config.go +++ b/transport/internet/tls/config.go @@ -391,11 +391,10 @@ func (c *Config) GetTLSConfig(opts ...Option) *tls.Config { } } if len(c.EchConfig) > 0 { - ECHConfig, err := base64.StdEncoding.DecodeString(c.EchConfig) + err := ApplyECH(c, config) if err != nil { - errors.LogError(context.Background(), "invalid ECH config") + errors.LogError(context.Background(), err) } - config.EncryptedClientHelloConfigList = ECHConfig } return config diff --git a/transport/internet/tls/ech.go b/transport/internet/tls/ech.go new file mode 100644 index 00000000..db7ba2bb --- /dev/null +++ b/transport/internet/tls/ech.go @@ -0,0 +1,21 @@ +//go:build go1.23 +// +build go1.23 + +package tls + +import ( + "context" + "crypto/tls" + "encoding/base64" + + "github.com/xtls/xray-core/common/errors" +) + +func ApplyECH(c *Config, config *tls.Config) error { + ECHConfig, err := base64.StdEncoding.DecodeString(c.EchConfig) + if err != nil { + errors.LogError(context.Background(), "invalid ECH config") + } + config.EncryptedClientHelloConfigList = ECHConfig + return nil +} diff --git a/transport/internet/tls/ech_go121.go b/transport/internet/tls/ech_go121.go new file mode 100644 index 00000000..4d77ac5a --- /dev/null +++ b/transport/internet/tls/ech_go121.go @@ -0,0 +1,14 @@ +//go:build !go1.23 +// +build !go1.23 + +package tls + +import ( + "crypto/tls" + + "github.com/xtls/xray-core/common/errors" +) + +func ApplyECH(c *Config, config *tls.Config) error { + return errors.New("Win7 does not support ECH") +}