Skip to content

Commit 115825f

Browse files
committed
TLS: Force connection failed if ApplyECH failed
1 parent b6b51c5 commit 115825f

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

transport/internet/tls/ech.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,13 @@ func ApplyECH(c *Config, config *tls.Config) error {
3434

3535
// for client
3636
if len(c.EchConfigList) != 0 {
37+
defer func() {
38+
// if failed to get ECHConfig, use an invalid one to make connection fail
39+
if err != nil {
40+
ECHConfig = []byte{1, 1, 4, 5, 1, 4}
41+
}
42+
config.EncryptedClientHelloConfigList = ECHConfig
43+
}()
3744
// direct base64 config
3845
if strings.Contains(c.EchConfigList, "://") {
3946
// query config from dns
@@ -61,8 +68,6 @@ func ApplyECH(c *Config, config *tls.Config) error {
6168
return errors.New("Failed to unmarshal ECHConfigList: ", err)
6269
}
6370
}
64-
65-
config.EncryptedClientHelloConfigList = ECHConfig
6671
}
6772

6873
// for server
@@ -239,6 +244,7 @@ func dnsQuery(server string, domain string) ([]byte, uint32, error) {
239244
}
240245
conn.Write(msg)
241246
udpResponse := make([]byte, 512)
247+
conn.SetReadDeadline(time.Now().Add(5 * time.Second))
242248
_, err = conn.Read(udpResponse)
243249
if err != nil {
244250
return []byte{}, 0, err

0 commit comments

Comments
 (0)