Optimize cipherSuites setting loader

This commit is contained in:
RPRX 2020-12-17 09:25:30 +00:00 committed by GitHub
parent 38faac5ffc
commit ff9bb2d8df
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 24 deletions

View file

@ -234,22 +234,18 @@ func (c *Config) GetTLSConfig(opts ...Option) *tls.Config {
config.MaxVersion = tls.VersionTLS13
}
var cipherSuites []uint16
if len(c.CipherSuites) > 0 {
cipherSuitesArray := strings.Split(c.CipherSuites, ":")
if len(cipherSuitesArray) > 0 {
all := tls.CipherSuites()
for _, suite := range cipherSuitesArray {
for _, s := range all {
if s.Name == suite {
cipherSuites = append(cipherSuites, s.ID)
break
id := make(map[string]uint16)
for _, s := range tls.CipherSuites() {
id[s.Name] = s.ID
}
for _, n := range strings.Split(c.CipherSuites, ":") {
if id[n] != 0 {
config.CipherSuites = append(config.CipherSuites, id[n])
}
}
}
}
}
config.CipherSuites = cipherSuites
config.PreferServerCipherSuites = c.PreferServerCipherSuites
return config

View file

@ -225,22 +225,18 @@ func (c *Config) GetXTLSConfig(opts ...Option) *xtls.Config {
config.MaxVersion = xtls.VersionTLS13
}
var cipherSuites []uint16
if len(c.CipherSuites) > 0 {
cipherSuitesArray := strings.Split(c.CipherSuites, ":")
if len(cipherSuitesArray) > 0 {
all := xtls.CipherSuites()
for _, suite := range cipherSuitesArray {
for _, s := range all {
if s.Name == suite {
cipherSuites = append(cipherSuites, s.ID)
break
id := make(map[string]uint16)
for _, s := range xtls.CipherSuites() {
id[s.Name] = s.ID
}
for _, n := range strings.Split(c.CipherSuites, ":") {
if id[n] != 0 {
config.CipherSuites = append(config.CipherSuites, id[n])
}
}
}
}
}
config.CipherSuites = cipherSuites
config.PreferServerCipherSuites = c.PreferServerCipherSuites
return config