Add cipherSuites setting for TLS & XTLS (#78)

This commit is contained in:
eMeab 2020-12-16 20:53:55 +08:00 committed by GitHub
parent 19ce0e99a5
commit 88dfed931b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 212 additions and 110 deletions

View file

@ -2,6 +2,7 @@ package xtls
import (
"crypto/x509"
"strings"
"sync"
"time"
@ -175,11 +176,12 @@ func (c *Config) GetXTLSConfig(opts ...Option) *xtls.Config {
}
config := &xtls.Config{
ClientSessionCache: globalSessionCache,
RootCAs: root,
InsecureSkipVerify: c.AllowInsecure,
NextProtos: c.NextProtocol,
SessionTicketsDisabled: c.DisableSessionResumption,
ClientSessionCache: globalSessionCache,
RootCAs: root,
InsecureSkipVerify: c.AllowInsecure,
NextProtos: c.NextProtocol,
SessionTicketsDisabled: c.DisableSessionResumption,
PreferServerCipherSuites: c.PreferServerCipherSuites,
}
for _, opt := range opts {
@ -212,6 +214,23 @@ func (c *Config) GetXTLSConfig(opts ...Option) *xtls.Config {
case "1.3":
config.MinVersion = xtls.VersionTLS13
}
var cipherSuites []uint16
if c.PreferServerCipherSuites && 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)
}
}
}
}
}
config.CipherSuites = cipherSuites
return config
}