1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-06-10 01:40:44 +00:00
v2fly/transport/internet/tls/config.go

40 lines
790 B
Go
Raw Normal View History

2016-10-02 21:43:58 +00:00
package tls
import (
"crypto/tls"
"v2ray.com/core/common/log"
)
var (
globalSessionCache = tls.NewLRUClientSessionCache(128)
)
2016-11-27 20:39:09 +00:00
func (v *Config) BuildCertificates() []tls.Certificate {
certs := make([]tls.Certificate, 0, len(v.Certificate))
for _, entry := range v.Certificate {
2016-10-02 21:43:58 +00:00
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
}
2016-11-27 20:39:09 +00:00
func (v *Config) GetTLSConfig() *tls.Config {
2016-10-02 21:43:58 +00:00
config := &tls.Config{
ClientSessionCache: globalSessionCache,
}
2016-11-27 20:39:09 +00:00
if v == nil {
2016-10-02 21:43:58 +00:00
return config
}
2016-11-27 20:39:09 +00:00
config.InsecureSkipVerify = v.AllowInsecure
config.Certificates = v.BuildCertificates()
2016-10-02 21:43:58 +00:00
config.BuildNameToCertificate()
return config
}