mirror of
https://github.com/XTLS/Xray-core.git
synced 2025-05-01 01:44:15 +00:00
Adjust config loader of TLS & XTLS
This commit is contained in:
parent
88dfed931b
commit
38faac5ffc
9 changed files with 215 additions and 195 deletions
|
@ -185,29 +185,17 @@ func (c *Config) GetTLSConfig(opts ...Option) *tls.Config {
|
|||
}
|
||||
|
||||
config := &tls.Config{
|
||||
ClientSessionCache: globalSessionCache,
|
||||
RootCAs: root,
|
||||
InsecureSkipVerify: c.AllowInsecure,
|
||||
NextProtos: c.NextProtocol,
|
||||
SessionTicketsDisabled: c.DisableSessionResumption,
|
||||
PreferServerCipherSuites: c.PreferServerCipherSuites,
|
||||
ClientSessionCache: globalSessionCache,
|
||||
RootCAs: root,
|
||||
InsecureSkipVerify: c.AllowInsecure,
|
||||
NextProtos: c.NextProtocol,
|
||||
SessionTicketsDisabled: c.DisableSessionResumption,
|
||||
}
|
||||
|
||||
for _, opt := range opts {
|
||||
opt(config)
|
||||
}
|
||||
|
||||
switch c.MinVersion {
|
||||
case "1.0":
|
||||
config.MinVersion = tls.VersionTLS10
|
||||
case "1.1":
|
||||
config.MinVersion = tls.VersionTLS11
|
||||
case "1.2":
|
||||
config.MinVersion = tls.VersionTLS12
|
||||
case "1.3":
|
||||
config.MinVersion = tls.VersionTLS13
|
||||
}
|
||||
|
||||
config.Certificates = c.BuildCertificates()
|
||||
config.BuildNameToCertificate()
|
||||
|
||||
|
@ -224,8 +212,30 @@ func (c *Config) GetTLSConfig(opts ...Option) *tls.Config {
|
|||
config.NextProtos = []string{"h2", "http/1.1"}
|
||||
}
|
||||
|
||||
switch c.MinVersion {
|
||||
case "1.0":
|
||||
config.MinVersion = tls.VersionTLS10
|
||||
case "1.1":
|
||||
config.MinVersion = tls.VersionTLS11
|
||||
case "1.2":
|
||||
config.MinVersion = tls.VersionTLS12
|
||||
case "1.3":
|
||||
config.MinVersion = tls.VersionTLS13
|
||||
}
|
||||
|
||||
switch c.MaxVersion {
|
||||
case "1.0":
|
||||
config.MaxVersion = tls.VersionTLS10
|
||||
case "1.1":
|
||||
config.MaxVersion = tls.VersionTLS11
|
||||
case "1.2":
|
||||
config.MaxVersion = tls.VersionTLS12
|
||||
case "1.3":
|
||||
config.MaxVersion = tls.VersionTLS13
|
||||
}
|
||||
|
||||
var cipherSuites []uint16
|
||||
if c.PreferServerCipherSuites && len(c.CipherSuites) > 0 {
|
||||
if len(c.CipherSuites) > 0 {
|
||||
cipherSuitesArray := strings.Split(c.CipherSuites, ":")
|
||||
if len(cipherSuitesArray) > 0 {
|
||||
all := tls.CipherSuites()
|
||||
|
@ -233,12 +243,14 @@ func (c *Config) GetTLSConfig(opts ...Option) *tls.Config {
|
|||
for _, s := range all {
|
||||
if s.Name == suite {
|
||||
cipherSuites = append(cipherSuites, s.ID)
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
config.CipherSuites = cipherSuites
|
||||
config.PreferServerCipherSuites = c.PreferServerCipherSuites
|
||||
|
||||
return config
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue