Skip to content

Commit ddb3fd8

Browse files
committed
imitate ssh.Dial func for simplicity
previously ScanHostKey ignored any SSH/network errors in case it managed to get host keys to make it more obvious we imitate `ssh.Dial` with `sshDial` func Signed-off-by: Artem Nistratov <[email protected]>
1 parent 63c6588 commit ddb3fd8

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

ssh/host_key.go

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,24 +47,31 @@ func ScanHostKey(host string, timeout time.Duration, clientHostKeyAlgos []string
4747
config.HostKeyAlgorithms = clientHostKeyAlgos
4848
}
4949

50-
ctx, cancel := context.WithTimeout(context.Background(), timeout)
50+
err := sshDial(host, config)
51+
52+
if len(col.knownKeys) > 0 {
53+
return col.knownKeys, nil
54+
}
55+
56+
return col.knownKeys, err
57+
}
58+
59+
func sshDial(host string, config *ssh.ClientConfig) error {
60+
ctx, cancel := context.WithTimeout(context.Background(), config.Timeout)
5161
defer cancel()
52-
// support for ALL_PROXY ENV varaible
62+
// this reads the ALL_PROXY environment varaible
5363
conn, err := proxy.Dial(ctx, "tcp", host)
5464
if err != nil {
55-
return nil, err
65+
return err
5666
}
5767
c, chans, reqs, err := ssh.NewClientConn(conn, host, config)
5868
if err != nil {
59-
return nil, err
69+
return err
6070
}
6171
client := ssh.NewClient(c, chans, reqs)
6272
defer client.Close()
6373

64-
if len(col.knownKeys) > 0 {
65-
return col.knownKeys, nil
66-
}
67-
return col.knownKeys, err
74+
return nil
6875
}
6976

7077
// HostKeyCollector offers a StoreKey method which provides an

0 commit comments

Comments
 (0)