diff --git a/ssh/host_key.go b/ssh/host_key.go index cde1be88..e603d168 100644 --- a/ssh/host_key.go +++ b/ssh/host_key.go @@ -47,24 +47,31 @@ func ScanHostKey(host string, timeout time.Duration, clientHostKeyAlgos []string config.HostKeyAlgorithms = clientHostKeyAlgos } - ctx, cancel := context.WithTimeout(context.Background(), timeout) + err := sshDial(host, config) + + if len(col.knownKeys) > 0 { + return col.knownKeys, nil + } + + return col.knownKeys, err +} + +func sshDial(host string, config *ssh.ClientConfig) error { + ctx, cancel := context.WithTimeout(context.Background(), config.Timeout) defer cancel() - // support for ALL_PROXY ENV varaible + // this reads the ALL_PROXY environment varaible conn, err := proxy.Dial(ctx, "tcp", host) if err != nil { - return nil, err + return err } c, chans, reqs, err := ssh.NewClientConn(conn, host, config) if err != nil { - return nil, err + return err } client := ssh.NewClient(c, chans, reqs) defer client.Close() - if len(col.knownKeys) > 0 { - return col.knownKeys, nil - } - return col.knownKeys, err + return nil } // HostKeyCollector offers a StoreKey method which provides an