From a1beccb9f04fe55cadfe429117eb2edb74460ce6 Mon Sep 17 00:00:00 2001 From: JP Sugarbroad Date: Wed, 28 Aug 2013 17:51:56 -0400 Subject: [PATCH] go.crypto/ssh: Update Dial to perform remote resolution of DNS names. R=agl CC=golang-dev https://golang.org/cl/13010047 --- ssh/tcpip.go | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/ssh/tcpip.go b/ssh/tcpip.go index f198554..05de3e1 100644 --- a/ssh/tcpip.go +++ b/ssh/tcpip.go @@ -232,15 +232,31 @@ func (l *tcpListener) Addr() net.Addr { } // Dial initiates a connection to the addr from the remote host. -// addr is resolved using net.ResolveTCPAddr before connection. -// This could allow an observer to observe the DNS name of the -// remote host. Consider using ssh.DialTCP to avoid this. +// The resulting connection has a zero LocalAddr() and RemoteAddr(). func (c *ClientConn) Dial(n, addr string) (net.Conn, error) { - raddr, err := net.ResolveTCPAddr(n, addr) + // Parse the address into host and numeric port. + host, portString, err := net.SplitHostPort(addr) if err != nil { return nil, err } - return c.DialTCP(n, nil, raddr) + port, err := strconv.ParseUint(portString, 10, 16) + if err != nil { + return nil, err + } + // Use a zero address for local and remote address. + zeroAddr := &net.TCPAddr{ + IP: net.IPv4zero, + Port: 0, + } + ch, err := c.dial(net.IPv4zero.String(), 0, host, int(port)) + if err != nil { + return nil, err + } + return &tcpChanConn{ + tcpChan: ch, + laddr: zeroAddr, + raddr: zeroAddr, + }, nil } // DialTCP connects to the remote address raddr on the network net,