Browse Source

lib/relay: Send SNI when the address is a host name (fixes #8014) (#8015)

Jakob Borg 4 years ago
parent
commit
e2288fe441
1 changed files with 11 additions and 1 deletions
  1. 11 1
      lib/relay/client/static.go

+ 11 - 1
lib/relay/client/static.go

@@ -141,7 +141,17 @@ func (c *staticClient) connect(ctx context.Context) error {
 		return err
 	}
 
-	conn := tls.Client(tcpConn, c.config)
+	// Copy the TLS config and set the server name we're connecting to. In
+	// many cases this will be an IP address, in which case it's a no-op. In
+	// other cases it will be a hostname, which will cause the TLS stack to
+	// send SNI.
+	cfg := c.config
+	if host, _, err := net.SplitHostPort(c.uri.Host); err == nil {
+		cfg = cfg.Clone()
+		cfg.ServerName = host
+	}
+
+	conn := tls.Client(tcpConn, cfg)
 
 	if err := conn.SetDeadline(time.Now().Add(c.connectTimeout)); err != nil {
 		conn.Close()