@@ -54,7 +54,7 @@ func (a *KeyboardInteractive) String() string {
54
54
}
55
55
56
56
func (a * KeyboardInteractive ) ClientConfig () (* ssh.ClientConfig , error ) {
57
- return a .SetHostKeyCallback (& ssh.ClientConfig {
57
+ return a .SetHostKeyCallbackAndAlgorithms (& ssh.ClientConfig {
58
58
User : a .User ,
59
59
Auth : []ssh.AuthMethod {
60
60
a .Challenge ,
@@ -78,7 +78,7 @@ func (a *Password) String() string {
78
78
}
79
79
80
80
func (a * Password ) ClientConfig () (* ssh.ClientConfig , error ) {
81
- return a .SetHostKeyCallback (& ssh.ClientConfig {
81
+ return a .SetHostKeyCallbackAndAlgorithms (& ssh.ClientConfig {
82
82
User : a .User ,
83
83
Auth : []ssh.AuthMethod {ssh .Password (a .Password )},
84
84
})
@@ -101,7 +101,7 @@ func (a *PasswordCallback) String() string {
101
101
}
102
102
103
103
func (a * PasswordCallback ) ClientConfig () (* ssh.ClientConfig , error ) {
104
- return a .SetHostKeyCallback (& ssh.ClientConfig {
104
+ return a .SetHostKeyCallbackAndAlgorithms (& ssh.ClientConfig {
105
105
User : a .User ,
106
106
Auth : []ssh.AuthMethod {ssh .PasswordCallback (a .Callback )},
107
107
})
@@ -150,7 +150,7 @@ func (a *PublicKeys) String() string {
150
150
}
151
151
152
152
func (a * PublicKeys ) ClientConfig () (* ssh.ClientConfig , error ) {
153
- return a .SetHostKeyCallback (& ssh.ClientConfig {
153
+ return a .SetHostKeyCallbackAndAlgorithms (& ssh.ClientConfig {
154
154
User : a .User ,
155
155
Auth : []ssh.AuthMethod {ssh .PublicKeys (a .Signer )},
156
156
})
@@ -211,7 +211,7 @@ func (a *PublicKeysCallback) String() string {
211
211
}
212
212
213
213
func (a * PublicKeysCallback ) ClientConfig () (* ssh.ClientConfig , error ) {
214
- return a .SetHostKeyCallback (& ssh.ClientConfig {
214
+ return a .SetHostKeyCallbackAndAlgorithms (& ssh.ClientConfig {
215
215
User : a .User ,
216
216
Auth : []ssh.AuthMethod {ssh .PublicKeysCallback (a .Callback )},
217
217
})
@@ -301,20 +301,23 @@ func filterKnownHostsFiles(files ...string) ([]string, error) {
301
301
}
302
302
303
303
// 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.
305
305
type HostKeyCallbackHelper struct {
306
306
// HostKeyCallback is the function type used for verifying server keys.
307
307
// If nil, a default callback will be created using NewKnownHostsDb
308
308
// without argument.
309
309
HostKeyCallback ssh.HostKeyCallback
310
310
311
+ // HostKeyAlgorithms is a list of supported host key algorithms that will
312
+ // be used for host key verification.
313
+ HostKeyAlgorithms []string
311
314
}
312
315
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 ) {
318
320
cfg .HostKeyCallback = m .HostKeyCallback
321
+ cfg .HostKeyAlgorithms = m .HostKeyAlgorithms
319
322
return cfg , nil
320
323
}
0 commit comments