2025-05-17 13:53:21 +08:00
|
|
|
package ech
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
tlsC "github.com/metacubex/mihomo/component/tls"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Config struct {
|
2025-05-22 17:42:40 +08:00
|
|
|
GetEncryptedClientHelloConfigList func(ctx context.Context, serverName string) ([]byte, error)
|
2025-05-17 13:53:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (cfg *Config) ClientHandle(ctx context.Context, tlsConfig *tlsC.Config) (err error) {
|
|
|
|
if cfg == nil {
|
|
|
|
return nil
|
|
|
|
}
|
2025-05-22 17:42:40 +08:00
|
|
|
echConfigList, err := cfg.GetEncryptedClientHelloConfigList(ctx, tlsConfig.ServerName)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("resolve ECH config error: %w", err)
|
2025-05-17 13:53:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
tlsConfig.EncryptedClientHelloConfigList = echConfigList
|
|
|
|
if tlsConfig.MinVersion != 0 && tlsConfig.MinVersion < tlsC.VersionTLS13 {
|
|
|
|
tlsConfig.MinVersion = tlsC.VersionTLS13
|
|
|
|
}
|
|
|
|
if tlsConfig.MaxVersion != 0 && tlsConfig.MaxVersion < tlsC.VersionTLS13 {
|
|
|
|
tlsConfig.MaxVersion = tlsC.VersionTLS13
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|