Skip to content

Commit

Permalink
Skip if not go1.23
Browse files Browse the repository at this point in the history
  • Loading branch information
Fangliding authored Sep 15, 2024
1 parent 4c7ca8b commit ea2a68a
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 3 deletions.
5 changes: 2 additions & 3 deletions transport/internet/tls/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 21 additions & 0 deletions transport/internet/tls/ech.go
Original file line number Diff line number Diff line change
@@ -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
}
14 changes: 14 additions & 0 deletions transport/internet/tls/ech_go121.go
Original file line number Diff line number Diff line change
@@ -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")
}

0 comments on commit ea2a68a

Please sign in to comment.