You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
v2ray-core/transport/internet/tls/config.go

43 lines
856 B

package tls
import (
"crypto/tls"
"v2ray.com/core/common/log"
)
var (
globalSessionCache = tls.NewLRUClientSessionCache(128)
)
8 years ago
func (v *Config) BuildCertificates() []tls.Certificate {
certs := make([]tls.Certificate, 0, len(v.Certificate))
for _, entry := range v.Certificate {
keyPair, err := tls.X509KeyPair(entry.Certificate, entry.Key)
if err != nil {
log.Warning("TLS: ignoring invalid X509 key pair: ", err)
continue
}
certs = append(certs, keyPair)
}
return certs
}
8 years ago
func (v *Config) GetTLSConfig() *tls.Config {
config := &tls.Config{
ClientSessionCache: globalSessionCache,
}
8 years ago
if v == nil {
return config
}
8 years ago
config.InsecureSkipVerify = v.AllowInsecure
config.Certificates = v.BuildCertificates()
config.BuildNameToCertificate()
if len(v.ServerName) > 0 {
config.ServerName = v.ServerName
}
return config
}