@@ -54,7 +54,7 @@ func (a *KeyboardInteractive) String() string {
5454}
5555
5656func (a * KeyboardInteractive ) ClientConfig () (* ssh.ClientConfig , error ) {
57- return a .SetHostKeyCallback (& ssh.ClientConfig {
57+ return a .SetHostKeyCallbackAndAlgorithms (& ssh.ClientConfig {
5858 User : a .User ,
5959 Auth : []ssh.AuthMethod {
6060 a .Challenge ,
@@ -78,7 +78,7 @@ func (a *Password) String() string {
7878}
7979
8080func (a * Password ) ClientConfig () (* ssh.ClientConfig , error ) {
81- return a .SetHostKeyCallback (& ssh.ClientConfig {
81+ return a .SetHostKeyCallbackAndAlgorithms (& ssh.ClientConfig {
8282 User : a .User ,
8383 Auth : []ssh.AuthMethod {ssh .Password (a .Password )},
8484 })
@@ -101,7 +101,7 @@ func (a *PasswordCallback) String() string {
101101}
102102
103103func (a * PasswordCallback ) ClientConfig () (* ssh.ClientConfig , error ) {
104- return a .SetHostKeyCallback (& ssh.ClientConfig {
104+ return a .SetHostKeyCallbackAndAlgorithms (& ssh.ClientConfig {
105105 User : a .User ,
106106 Auth : []ssh.AuthMethod {ssh .PasswordCallback (a .Callback )},
107107 })
@@ -150,7 +150,7 @@ func (a *PublicKeys) String() string {
150150}
151151
152152func (a * PublicKeys ) ClientConfig () (* ssh.ClientConfig , error ) {
153- return a .SetHostKeyCallback (& ssh.ClientConfig {
153+ return a .SetHostKeyCallbackAndAlgorithms (& ssh.ClientConfig {
154154 User : a .User ,
155155 Auth : []ssh.AuthMethod {ssh .PublicKeys (a .Signer )},
156156 })
@@ -211,7 +211,7 @@ func (a *PublicKeysCallback) String() string {
211211}
212212
213213func (a * PublicKeysCallback ) ClientConfig () (* ssh.ClientConfig , error ) {
214- return a .SetHostKeyCallback (& ssh.ClientConfig {
214+ return a .SetHostKeyCallbackAndAlgorithms (& ssh.ClientConfig {
215215 User : a .User ,
216216 Auth : []ssh.AuthMethod {ssh .PublicKeysCallback (a .Callback )},
217217 })
@@ -301,20 +301,23 @@ func filterKnownHostsFiles(files ...string) ([]string, error) {
301301}
302302
303303// HostKeyCallbackHelper is a helper that provides common functionality to
304- // configure HostKeyCallback into a ssh.ClientConfig.
304+ // configure HostKeyCallback and HostKeyAlgorithms into a ssh.ClientConfig.
305305type HostKeyCallbackHelper struct {
306306 // HostKeyCallback is the function type used for verifying server keys.
307307 // If nil, a default callback will be created using NewKnownHostsDb
308308 // without argument.
309309 HostKeyCallback ssh.HostKeyCallback
310310
311+ // HostKeyAlgorithms is a list of supported host key algorithms that will
312+ // be used for host key verification.
313+ HostKeyAlgorithms []string
311314}
312315
313- // SetHostKeyCallback sets the field HostKeyCallback in the given cfg.
314- // If the host key callback is empty it is left empty. It will be handled
315- // by the dial method by falling back to knownhosts.
316- func (m * HostKeyCallbackHelper ) SetHostKeyCallback (cfg * ssh.ClientConfig ) (* ssh.ClientConfig , error ) {
317-
316+ // SetHostKeyCallbackAndAlgorithms sets the field HostKeyCallback and HostKeyAlgorithms in the given cfg.
317+ // If the host key callback or algorithms is empty it is left empty. It will be handled by the dial method,
318+ // falling back to knownhosts.
319+ func (m * HostKeyCallbackHelper ) SetHostKeyCallbackAndAlgorithms (cfg * ssh.ClientConfig ) (* ssh.ClientConfig , error ) {
318320 cfg .HostKeyCallback = m .HostKeyCallback
321+ cfg .HostKeyAlgorithms = m .HostKeyAlgorithms
319322 return cfg , nil
320323}
0 commit comments