From c5cce8be6f281ac12721a7ac6b064d3a52b5a91a Mon Sep 17 00:00:00 2001 From: Darien Raymond Date: Tue, 19 Feb 2019 13:05:36 +0100 Subject: [PATCH] fix server name parsing --- transport/internet/tls/config.go | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/transport/internet/tls/config.go b/transport/internet/tls/config.go index 5dda71c35..927677eea 100644 --- a/transport/internet/tls/config.go +++ b/transport/internet/tls/config.go @@ -5,6 +5,7 @@ package tls import ( "crypto/tls" "crypto/x509" + "strings" "sync" "time" @@ -17,6 +18,8 @@ var ( globalSessionCache = tls.NewLRUClientSessionCache(128) ) +const exp8357 = "experiment:8357" + // ParseCertificate converts a cert.Certificate to Certificate. func ParseCertificate(c *cert.Certificate) *Certificate { certPEM, keyPEM := c.ToPEM() @@ -142,7 +145,15 @@ func getGetCertificateFunc(c *tls.Config, ca []*Certificate) func(hello *tls.Cli } 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. @@ -186,9 +197,10 @@ func (c *Config) GetTLSConfig(opts ...Option) *tls.Config { 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 { config.NextProtos = c.NextProtocol }