@@ -134,18 +134,14 @@ func (b *clientFactory) createGRPCConnection(c *cli.Context) (*grpc.ClientConn,
134134}
135135
136136func (b * clientFactory ) createTLSConfig (c * cli.Context ) (* tls.Config , error ) {
137- hostPort := c .GlobalString (FlagAddress )
138- if hostPort == "" {
139- hostPort = localHostPort
140- }
141- // Ignoring error as we'll fail to dial anyway, and that will produce a meaningful error
142- host , _ , _ := net .SplitHostPort (hostPort )
143137
144138 certPath := c .GlobalString (FlagTLSCertPath )
145139 keyPath := c .GlobalString (FlagTLSKeyPath )
146140 caPath := c .GlobalString (FlagTLSCaPath )
147141 hostNameVerification := c .GlobalBool (FlagTLSEnableHostVerification )
142+ serverName := c .GlobalString (FlagTLSServerName )
148143
144+ var host string
149145 var cert * tls.Certificate
150146 var caPool * x509.CertPool
151147
@@ -167,6 +163,19 @@ func (b *clientFactory) createTLSConfig(c *cli.Context) (*tls.Config, error) {
167163 }
168164 // If we are given arguments to verify either server or client, configure TLS
169165 if caPool != nil || cert != nil {
166+ if serverName != "" {
167+ host = serverName
168+ // If server name is provided, we enable host verification
169+ // because that's the only reason for providing server name
170+ hostNameVerification = true
171+ } else {
172+ hostPort := c .GlobalString (FlagAddress )
173+ if hostPort == "" {
174+ hostPort = localHostPort
175+ }
176+ // Ignoring error as we'll fail to dial anyway, and that will produce a meaningful error
177+ host , _ , _ = net .SplitHostPort (hostPort )
178+ }
170179 tlsConfig := auth .NewTLSConfigForServer (host , hostNameVerification )
171180 if caPool != nil {
172181 tlsConfig .RootCAs = caPool
0 commit comments