2015-12-14 11:26:29 -05:00
|
|
|
package http
|
|
|
|
|
2016-01-26 05:28:09 -05:00
|
|
|
import (
|
2016-05-07 04:06:12 -04:00
|
|
|
"crypto/tls"
|
|
|
|
|
2016-01-26 05:28:09 -05:00
|
|
|
v2net "github.com/v2ray/v2ray-core/common/net"
|
|
|
|
)
|
|
|
|
|
2016-05-07 04:06:12 -04:00
|
|
|
type CertificateConfig struct {
|
|
|
|
Domain string
|
|
|
|
Certificate tls.Certificate
|
|
|
|
}
|
|
|
|
|
2016-04-25 09:30:28 -04:00
|
|
|
type TlsConfig struct {
|
2016-05-07 04:06:12 -04:00
|
|
|
Enabled bool
|
|
|
|
Certs []*CertificateConfig
|
2016-04-25 09:30:28 -04:00
|
|
|
}
|
|
|
|
|
2016-05-07 04:36:36 -04:00
|
|
|
func (this *TlsConfig) GetConfig() *tls.Config {
|
|
|
|
if !this.Enabled {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
config := &tls.Config{
|
|
|
|
InsecureSkipVerify: false,
|
|
|
|
}
|
|
|
|
|
|
|
|
config.Certificates = make([]tls.Certificate, len(this.Certs))
|
|
|
|
for index, cert := range this.Certs {
|
|
|
|
config.Certificates[index] = cert.Certificate
|
|
|
|
}
|
|
|
|
|
|
|
|
config.BuildNameToCertificate()
|
|
|
|
|
|
|
|
return config
|
|
|
|
}
|
|
|
|
|
2016-01-15 06:43:06 -05:00
|
|
|
type Config struct {
|
2016-04-25 09:30:28 -04:00
|
|
|
OwnHosts []v2net.Address
|
|
|
|
TlsConfig *TlsConfig
|
2016-01-26 05:28:09 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func (this *Config) IsOwnHost(host v2net.Address) bool {
|
|
|
|
for _, ownHost := range this.OwnHosts {
|
|
|
|
if ownHost.Equals(host) {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false
|
2015-12-14 11:26:29 -05:00
|
|
|
}
|