Browse Source

fix server name parsing

Darien Raymond 6 years ago
parent
commit
c5cce8be6f
1 changed files with 15 additions and 3 deletions
  1. 15 3
      transport/internet/tls/config.go

+ 15 - 3
transport/internet/tls/config.go

@@ -5,6 +5,7 @@ package tls
 import (
 import (
 	"crypto/tls"
 	"crypto/tls"
 	"crypto/x509"
 	"crypto/x509"
+	"strings"
 	"sync"
 	"sync"
 	"time"
 	"time"
 
 
@@ -17,6 +18,8 @@ var (
 	globalSessionCache = tls.NewLRUClientSessionCache(128)
 	globalSessionCache = tls.NewLRUClientSessionCache(128)
 )
 )
 
 
+const exp8357 = "experiment:8357"
+
 // ParseCertificate converts a cert.Certificate to Certificate.
 // ParseCertificate converts a cert.Certificate to Certificate.
 func ParseCertificate(c *cert.Certificate) *Certificate {
 func ParseCertificate(c *cert.Certificate) *Certificate {
 	certPEM, keyPEM := c.ToPEM()
 	certPEM, keyPEM := c.ToPEM()
@@ -142,7 +145,15 @@ func getGetCertificateFunc(c *tls.Config, ca []*Certificate) func(hello *tls.Cli
 }
 }
 
 
 func (c *Config) IsExperiment8357() bool {
 func (c *Config) IsExperiment8357() bool {
-	return c.ServerName == "experiment:8357"
+	return strings.HasPrefix(c.ServerName, exp8357)
+}
+
+func (c *Config) parseServerName() string {
+	if c.IsExperiment8357() {
+		return c.ServerName[len(exp8357):]
+	}
+
+	return c.ServerName
 }
 }
 
 
 // GetTLSConfig converts this Config into tls.Config.
 // GetTLSConfig converts this Config into tls.Config.
@@ -186,9 +197,10 @@ func (c *Config) GetTLSConfig(opts ...Option) *tls.Config {
 		config.GetCertificate = getGetCertificateFunc(config, caCerts)
 		config.GetCertificate = getGetCertificateFunc(config, caCerts)
 	}
 	}
 
 
-	if len(c.ServerName) > 0 && c.ServerName != "experiment:8357" {
-		config.ServerName = c.ServerName
+	if sn := c.parseServerName(); len(sn) > 0 {
+		config.ServerName = sn
 	}
 	}
+
 	if len(c.NextProtocol) > 0 {
 	if len(c.NextProtocol) > 0 {
 		config.NextProtos = c.NextProtocol
 		config.NextProtos = c.NextProtocol
 	}
 	}