Do some rename

This commit is contained in:
风扇滑翔翼 2025-03-09 11:40:10 +00:00 committed by GitHub
parent 22463f3256
commit 2dc6a344a5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 48 additions and 61 deletions

View file

@ -4,7 +4,6 @@ import (
"bytes"
"context"
"crypto/tls"
"fmt"
"io"
"net/http"
"strings"
@ -25,22 +24,28 @@ func ApplyECH(c *Config, config *tls.Config) error {
nameToQuery := c.ServerName
var DOHServer string
if len(c.EchConfig) != 0 || len(c.Ech_DNSserver) != 0 {
parts := strings.Split(c.Ech_DNSserver, "+")
if len(parts) == 2 {
// parse ECH DOH server in format of "example.com+https://1.1.1.1/dns-query"
nameToQuery = parts[0]
DOHServer = parts[1]
} else if len(parts) == 1 {
// normal format
DOHServer = parts[0]
} else {
return errors.New("Invalid ECH DOH server format: ", c.Ech_DNSserver)
}
if len(c.EchConfig) > 0 {
ECHConfig = c.EchConfig
} else { // ECH config > DOH lookup
// for client
if len(c.EchConfigList) != 0 {
// direct base64 config
if strings.HasPrefix(c.EchConfigList, "base64") {
Base64ECHConfigList := c.EchConfigList[len("base64://"):]
ECHConfigList, err := goech.ECHConfigListFromBase64(Base64ECHConfigList)
if err != nil {
return errors.New("Failed to unmarshal ECHConfigList: ", err)
}
ECHConfig, _ = ECHConfigList.MarshalBinary()
} else { // query config from dns
parts := strings.Split(c.EchConfigList, "+")
if len(parts) == 2 {
// parse ECH DOH server in format of "example.com+https://1.1.1.1/dns-query"
nameToQuery = parts[0]
DOHServer = parts[1]
} else if len(parts) == 1 {
// normal format
DOHServer = parts[0]
} else {
return errors.New("Invalid ECH DNS server format: ", c.EchConfigList)
}
if nameToQuery == "" {
return errors.New("Using DOH for ECH needs serverName or use dohServer format example.com+https://1.1.1.1/dns-query")
}
@ -53,6 +58,7 @@ func ApplyECH(c *Config, config *tls.Config) error {
config.EncryptedClientHelloConfigList = ECHConfig
}
// for server
if len(c.EchKeySets) != 0 {
var keys []tls.EncryptedClientHelloKey
KeySets, err := goech.UnmarshalECHKeySetList(c.EchKeySets)
@ -70,8 +76,8 @@ func ApplyECH(c *Config, config *tls.Config) error {
PrivateKey: ECHPrivateKey})
}
config.EncryptedClientHelloKeys = keys
fmt.Println(config.EncryptedClientHelloKeys)
}
return nil
}