Skip to content

Commit 7f6a825

Browse files
authored
Do some rename
1 parent 6d5be86 commit 7f6a825

File tree

5 files changed

+48
-61
lines changed

5 files changed

+48
-61
lines changed

infra/conf/transport_internet.go

+3-10
Original file line numberDiff line numberDiff line change
@@ -412,8 +412,7 @@ type TLSConfig struct {
412412
MasterKeyLog string `json:"masterKeyLog"`
413413
ServerNameToVerify string `json:"serverNameToVerify"`
414414
VerifyPeerCertInNames []string `json:"verifyPeerCertInNames"`
415-
ECHConfig string `json:"echConfig"`
416-
ECHDNSServer string `json:"echDnsServer"`
415+
ECHConfigList string `json:"echConfigList"`
417416
EchKeySets string `json:"echKeySets"`
418417
}
419418

@@ -486,21 +485,15 @@ func (c *TLSConfig) Build() (proto.Message, error) {
486485
}
487486
config.VerifyPeerCertInNames = c.VerifyPeerCertInNames
488487

489-
if c.ECHConfig != "" {
490-
ECHConfig, err := base64.StdEncoding.DecodeString(c.ECHConfig)
491-
if err != nil {
492-
return nil, errors.New("invalid ECH Config", c.ECHConfig)
493-
}
494-
config.EchConfig = ECHConfig
495-
}
488+
config.EchConfigList = c.ECHConfigList
489+
496490
if c.EchKeySets != "" {
497491
EchPrivateKey, err := base64.StdEncoding.DecodeString(c.EchKeySets)
498492
if err != nil {
499493
return nil, errors.New("invalid ECH Config", c.EchKeySets)
500494
}
501495
config.EchKeySets = EchPrivateKey
502496
}
503-
config.Ech_DNSserver = c.ECHDNSServer
504497

505498
return config, nil
506499
}

transport/internet/tls/config.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ func (c *Config) GetTLSConfig(opts ...Option) *tls.Config {
444444
config.KeyLogWriter = writer
445445
}
446446
}
447-
if len(c.EchConfig) > 0 || len(c.Ech_DNSserver) > 0 || len(c.EchKeySets) > 0 {
447+
if len(c.EchConfigList) > 0 || len(c.EchKeySets) > 0 {
448448
err := ApplyECH(c, config)
449449
if err != nil {
450450
errors.LogError(context.Background(), err)

transport/internet/tls/config.pb.go

+18-28
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

transport/internet/tls/config.proto

+2-4
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,7 @@ message Config {
9292
*/
9393
repeated string verify_peer_cert_in_names = 17;
9494

95-
bytes ech_config = 18;
95+
string ech_config_list = 18;
9696

97-
string ech_DNSserver = 19;
98-
99-
bytes ech_key_sets = 20;
97+
bytes ech_key_sets = 19;
10098
}

transport/internet/tls/ech.go

+24-18
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"bytes"
55
"context"
66
"crypto/tls"
7-
"fmt"
87
"io"
98
"net/http"
109
"strings"
@@ -25,22 +24,28 @@ func ApplyECH(c *Config, config *tls.Config) error {
2524
nameToQuery := c.ServerName
2625
var DOHServer string
2726

28-
if len(c.EchConfig) != 0 || len(c.Ech_DNSserver) != 0 {
29-
parts := strings.Split(c.Ech_DNSserver, "+")
30-
if len(parts) == 2 {
31-
// parse ECH DOH server in format of "example.com+https://1.1.1.1/dns-query"
32-
nameToQuery = parts[0]
33-
DOHServer = parts[1]
34-
} else if len(parts) == 1 {
35-
// normal format
36-
DOHServer = parts[0]
37-
} else {
38-
return errors.New("Invalid ECH DOH server format: ", c.Ech_DNSserver)
39-
}
40-
41-
if len(c.EchConfig) > 0 {
42-
ECHConfig = c.EchConfig
43-
} else { // ECH config > DOH lookup
27+
// for client
28+
if len(c.EchConfigList) != 0 {
29+
// direct base64 config
30+
if strings.HasPrefix(c.EchConfigList, "base64") {
31+
Base64ECHConfigList := c.EchConfigList[len("base64://"):]
32+
ECHConfigList, err := goech.ECHConfigListFromBase64(Base64ECHConfigList)
33+
if err != nil {
34+
return errors.New("Failed to unmarshal ECHConfigList: ", err)
35+
}
36+
ECHConfig, _ = ECHConfigList.MarshalBinary()
37+
} else { // query config from dns
38+
parts := strings.Split(c.EchConfigList, "+")
39+
if len(parts) == 2 {
40+
// parse ECH DOH server in format of "example.com+https://1.1.1.1/dns-query"
41+
nameToQuery = parts[0]
42+
DOHServer = parts[1]
43+
} else if len(parts) == 1 {
44+
// normal format
45+
DOHServer = parts[0]
46+
} else {
47+
return errors.New("Invalid ECH DNS server format: ", c.EchConfigList)
48+
}
4449
if nameToQuery == "" {
4550
return errors.New("Using DOH for ECH needs serverName or use dohServer format example.com+https://1.1.1.1/dns-query")
4651
}
@@ -53,6 +58,7 @@ func ApplyECH(c *Config, config *tls.Config) error {
5358
config.EncryptedClientHelloConfigList = ECHConfig
5459
}
5560

61+
// for server
5662
if len(c.EchKeySets) != 0 {
5763
var keys []tls.EncryptedClientHelloKey
5864
KeySets, err := goech.UnmarshalECHKeySetList(c.EchKeySets)
@@ -70,8 +76,8 @@ func ApplyECH(c *Config, config *tls.Config) error {
7076
PrivateKey: ECHPrivateKey})
7177
}
7278
config.EncryptedClientHelloKeys = keys
73-
fmt.Println(config.EncryptedClientHelloKeys)
7479
}
80+
7581
return nil
7682
}
7783

0 commit comments

Comments
 (0)