mirror of
https://github.com/v2fly/v2ray-core.git
synced 2025-02-20 23:47:21 -05:00
fix #643
This commit is contained in:
parent
09b955bead
commit
af88016320
@ -135,10 +135,10 @@ func DialKCP(ctx context.Context, dest net.Destination) (internet.Connection, er
|
|||||||
if securitySettings := internet.SecuritySettingsFromContext(ctx); securitySettings != nil {
|
if securitySettings := internet.SecuritySettingsFromContext(ctx); securitySettings != nil {
|
||||||
switch securitySettings := securitySettings.(type) {
|
switch securitySettings := securitySettings.(type) {
|
||||||
case *v2tls.Config:
|
case *v2tls.Config:
|
||||||
config := securitySettings.GetTLSConfig()
|
|
||||||
if dest.Address.Family().IsDomain() {
|
if dest.Address.Family().IsDomain() {
|
||||||
config.ServerName = dest.Address.Domain()
|
securitySettings.OverrideServerNameIfEmpty(dest.Address.Domain())
|
||||||
}
|
}
|
||||||
|
config := securitySettings.GetTLSConfig()
|
||||||
tlsConn := tls.Client(iConn, config)
|
tlsConn := tls.Client(iConn, config)
|
||||||
iConn = tlsConn
|
iConn = tlsConn
|
||||||
}
|
}
|
||||||
|
@ -29,10 +29,10 @@ func Dial(ctx context.Context, dest net.Destination) (internet.Connection, error
|
|||||||
if securitySettings := internet.SecuritySettingsFromContext(ctx); securitySettings != nil {
|
if securitySettings := internet.SecuritySettingsFromContext(ctx); securitySettings != nil {
|
||||||
tlsConfig, ok := securitySettings.(*tls.Config)
|
tlsConfig, ok := securitySettings.(*tls.Config)
|
||||||
if ok {
|
if ok {
|
||||||
config := tlsConfig.GetTLSConfig()
|
|
||||||
if dest.Address.Family().IsDomain() {
|
if dest.Address.Family().IsDomain() {
|
||||||
config.ServerName = dest.Address.Domain()
|
tlsConfig.OverrideServerNameIfEmpty(dest.Address.Domain())
|
||||||
}
|
}
|
||||||
|
config := tlsConfig.GetTLSConfig()
|
||||||
conn = tls.Client(conn, config)
|
conn = tls.Client(conn, config)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,9 +10,9 @@ var (
|
|||||||
globalSessionCache = tls.NewLRUClientSessionCache(128)
|
globalSessionCache = tls.NewLRUClientSessionCache(128)
|
||||||
)
|
)
|
||||||
|
|
||||||
func (v *Config) BuildCertificates() []tls.Certificate {
|
func (c *Config) BuildCertificates() []tls.Certificate {
|
||||||
certs := make([]tls.Certificate, 0, len(v.Certificate))
|
certs := make([]tls.Certificate, 0, len(c.Certificate))
|
||||||
for _, entry := range v.Certificate {
|
for _, entry := range c.Certificate {
|
||||||
keyPair, err := tls.X509KeyPair(entry.Certificate, entry.Key)
|
keyPair, err := tls.X509KeyPair(entry.Certificate, entry.Key)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Trace(newError("ignoring invalid X509 key pair").Base(err).AtWarning())
|
log.Trace(newError("ignoring invalid X509 key pair").Base(err).AtWarning())
|
||||||
@ -23,21 +23,27 @@ func (v *Config) BuildCertificates() []tls.Certificate {
|
|||||||
return certs
|
return certs
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v *Config) GetTLSConfig() *tls.Config {
|
func (c *Config) GetTLSConfig() *tls.Config {
|
||||||
config := &tls.Config{
|
config := &tls.Config{
|
||||||
ClientSessionCache: globalSessionCache,
|
ClientSessionCache: globalSessionCache,
|
||||||
NextProtos: []string{"http/1.1"},
|
NextProtos: []string{"http/1.1"},
|
||||||
}
|
}
|
||||||
if v == nil {
|
if c == nil {
|
||||||
return config
|
return config
|
||||||
}
|
}
|
||||||
|
|
||||||
config.InsecureSkipVerify = v.AllowInsecure
|
config.InsecureSkipVerify = c.AllowInsecure
|
||||||
config.Certificates = v.BuildCertificates()
|
config.Certificates = c.BuildCertificates()
|
||||||
config.BuildNameToCertificate()
|
config.BuildNameToCertificate()
|
||||||
if len(v.ServerName) > 0 {
|
if len(c.ServerName) > 0 {
|
||||||
config.ServerName = v.ServerName
|
config.ServerName = c.ServerName
|
||||||
}
|
}
|
||||||
|
|
||||||
return config
|
return config
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *Config) OverrideServerNameIfEmpty(serverName string) {
|
||||||
|
if len(c.ServerName) == 0 {
|
||||||
|
c.ServerName = serverName
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -46,10 +46,10 @@ func dialWebsocket(ctx context.Context, dest net.Destination) (net.Conn, error)
|
|||||||
tlsConfig, ok := securitySettings.(*tls.Config)
|
tlsConfig, ok := securitySettings.(*tls.Config)
|
||||||
if ok {
|
if ok {
|
||||||
protocol = "wss"
|
protocol = "wss"
|
||||||
dialer.TLSClientConfig = tlsConfig.GetTLSConfig()
|
|
||||||
if dest.Address.Family().IsDomain() {
|
if dest.Address.Family().IsDomain() {
|
||||||
dialer.TLSClientConfig.ServerName = dest.Address.Domain()
|
tlsConfig.OverrideServerNameIfEmpty(dest.Address.Domain())
|
||||||
}
|
}
|
||||||
|
dialer.TLSClientConfig = tlsConfig.GetTLSConfig()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user