fix server name parsing

pull/1581/head
Darien Raymond 2019-02-19 13:05:36 +01:00
parent 9476f38f8b
commit c5cce8be6f
No known key found for this signature in database
GPG Key ID: 7251FFA14BB18169
1 changed files with 15 additions and 3 deletions

View File

@ -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" { if sn := c.parseServerName(); len(sn) > 0 {
config.ServerName = c.ServerName config.ServerName = sn
} }
if len(c.NextProtocol) > 0 { if len(c.NextProtocol) > 0 {
config.NextProtos = c.NextProtocol config.NextProtos = c.NextProtocol
} }