go.crypto/ssh: Update Dial to perform remote resolution of DNS names.

R=agl
CC=golang-dev
https://golang.org/cl/13010047
This commit is contained in:
JP Sugarbroad 2013-08-28 17:51:56 -04:00 коммит произвёл Adam Langley
Родитель a93ee0c91a
Коммит a1beccb9f0
1 изменённых файлов: 21 добавлений и 5 удалений

Просмотреть файл

@ -232,15 +232,31 @@ func (l *tcpListener) Addr() net.Addr {
} }
// Dial initiates a connection to the addr from the remote host. // Dial initiates a connection to the addr from the remote host.
// addr is resolved using net.ResolveTCPAddr before connection. // The resulting connection has a zero LocalAddr() and RemoteAddr().
// This could allow an observer to observe the DNS name of the
// remote host. Consider using ssh.DialTCP to avoid this.
func (c *ClientConn) Dial(n, addr string) (net.Conn, error) { 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 { if err != nil {
return nil, err 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, // DialTCP connects to the remote address raddr on the network net,