Skip to content

Commit b1d12a1

Browse files
committed
chore: proxy's ech should fetch from proxy-nameserver
1 parent 5a21bf3 commit b1d12a1

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

adapter/outbound/ech.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
package outbound
22

33
import (
4+
"context"
45
"encoding/base64"
56
"fmt"
67

78
"github.com/metacubex/mihomo/component/ech"
9+
"github.com/metacubex/mihomo/component/resolver"
810
)
911

1012
type ECHOptions struct {
@@ -22,7 +24,13 @@ func (o ECHOptions) Parse() (*ech.Config, error) {
2224
if err != nil {
2325
return nil, fmt.Errorf("base64 decode ech config string failed: %v", err)
2426
}
25-
echConfig.EncryptedClientHelloConfigList = list
27+
echConfig.GetEncryptedClientHelloConfigList = func(ctx context.Context, serverName string) ([]byte, error) {
28+
return list, nil
29+
}
30+
} else {
31+
echConfig.GetEncryptedClientHelloConfigList = func(ctx context.Context, serverName string) ([]byte, error) {
32+
return resolver.ResolveECHWithResolver(ctx, serverName, resolver.ProxyServerHostResolver)
33+
}
2634
}
2735
return echConfig, nil
2836
}

component/ech/ech.go

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,20 @@ import (
44
"context"
55
"fmt"
66

7-
"github.com/metacubex/mihomo/component/resolver"
87
tlsC "github.com/metacubex/mihomo/component/tls"
98
)
109

1110
type Config struct {
12-
EncryptedClientHelloConfigList []byte
11+
GetEncryptedClientHelloConfigList func(ctx context.Context, serverName string) ([]byte, error)
1312
}
1413

1514
func (cfg *Config) ClientHandle(ctx context.Context, tlsConfig *tlsC.Config) (err error) {
1615
if cfg == nil {
1716
return nil
1817
}
19-
echConfigList := cfg.EncryptedClientHelloConfigList
20-
if len(echConfigList) == 0 {
21-
echConfigList, err = resolver.ResolveECH(ctx, tlsConfig.ServerName)
22-
if err != nil {
23-
return fmt.Errorf("resolve ECH config error: %w", err)
24-
}
18+
echConfigList, err := cfg.GetEncryptedClientHelloConfigList(ctx, tlsConfig.ServerName)
19+
if err != nil {
20+
return fmt.Errorf("resolve ECH config error: %w", err)
2521
}
2622

2723
tlsConfig.EncryptedClientHelloConfigList = echConfigList

0 commit comments

Comments
 (0)