1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-11-18 02:16:10 -05:00
v2fly/transport/internet/tls/config.go
2016-11-27 21:39:09 +01:00

40 lines
790 B
Go

package tls
import (
"crypto/tls"
"v2ray.com/core/common/log"
)
var (
globalSessionCache = tls.NewLRUClientSessionCache(128)
)
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
}
func (v *Config) GetTLSConfig() *tls.Config {
config := &tls.Config{
ClientSessionCache: globalSessionCache,
}
if v == nil {
return config
}
config.InsecureSkipVerify = v.AllowInsecure
config.Certificates = v.BuildCertificates()
config.BuildNameToCertificate()
return config
}