-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
49 lines (41 loc) · 1.02 KB
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package tls
import (
"crypto/tls"
"v2ray.com/core/app/log"
)
var (
globalSessionCache = tls.NewLRUClientSessionCache(128)
)
func (c *Config) BuildCertificates() []tls.Certificate {
certs := make([]tls.Certificate, 0, len(c.Certificate))
for _, entry := range c.Certificate {
keyPair, err := tls.X509KeyPair(entry.Certificate, entry.Key)
if err != nil {
log.Trace(newError("ignoring invalid X509 key pair").Base(err).AtWarning())
continue
}
certs = append(certs, keyPair)
}
return certs
}
func (c *Config) GetTLSConfig() *tls.Config {
config := &tls.Config{
ClientSessionCache: globalSessionCache,
NextProtos: []string{"http/1.1"},
}
if c == nil {
return config
}
config.InsecureSkipVerify = c.AllowInsecure
config.Certificates = c.BuildCertificates()
config.BuildNameToCertificate()
if len(c.ServerName) > 0 {
config.ServerName = c.ServerName
}
return config
}
func (c *Config) OverrideServerNameIfEmpty(serverName string) {
if len(c.ServerName) == 0 {
c.ServerName = serverName
}
}