diff options
| author | Sam Anthony <sam@samanthony.xyz> | 2025-04-11 17:24:53 -0400 |
|---|---|---|
| committer | Sam Anthony <sam@samanthony.xyz> | 2025-04-11 17:24:53 -0400 |
| commit | f558b8a0552b16a84d2b4aafb4b9cd74122522e8 (patch) | |
| tree | d190f1a4f6e36c83734e67776315a6ed516613a6 | |
| parent | 2e1f47bffc460a21bf4e743971e51e9ccb0b16c2 (diff) | |
| download | hose-f558b8a0552b16a84d2b4aafb4b9cd74122522e8.zip | |
remove name resolution
| -rw-r--r-- | handshake.go | 23 |
1 files changed, 3 insertions, 20 deletions
diff --git a/handshake.go b/handshake.go index d408e1f..0bcb0cd 100644 --- a/handshake.go +++ b/handshake.go @@ -37,7 +37,8 @@ func handshakeSend(rhost string) error { raddr := net.JoinHostPort(rhost, port) util.Logf("connecting to %s...", raddr) - conn, err := net.Dial(network, raddr) + var d net.Dialer + conn, err := d.Dial(network, raddr) if err != nil { return err } @@ -95,19 +96,14 @@ func handshakeRecv(rhost string) error { // verifyPublicKey asks the user to verify the public key of a remote host. // It returns true if the user accepts the key, or false if they don't, or a non-nil error. func verifyPublicKey(addr net.Addr, pubkey [32]byte) (bool, error) { - // Lookup human-friendly name of remote host, or fall back to the address. host, _, err := net.SplitHostPort(addr.String()) if err != nil { return false, err } - hostname, err := lookupAddr(host) - if err != nil { - return false, err - } // Ask host to verify the key. util.Logf("Public key of host %q: %x\nIs this the correct key (yes/[no])?", - hostname, pubkey[:]) + host, pubkey[:]) response, err := scan([]string{"yes", "no", ""}) if err != nil { return false, err @@ -123,19 +119,6 @@ func verifyPublicKey(addr net.Addr, pubkey [32]byte) (bool, error) { panic("unreachable") } -// lookupAddr attempts to resolve the host name of an IP address. -// If no names are mapped to the address, the address itself is returned. -func lookupAddr(addr string) (string, error) { - hostNames, err := net.LookupAddr(addr) - if err != nil { - return "", err - } - if len(hostNames) > 0 { - return hostNames[0], nil - } - return addr, nil -} - // scan reads from stdin until the user enters one of the valid responses. func scan(responses []string) (string, error) { scanner := bufio.NewScanner(os.Stdin) |