diff options
| author | Paul Bütow <pbuetow@mimecast.com> | 2020-01-09 20:30:15 +0000 |
|---|---|---|
| committer | Paul Bütow <pbuetow@mimecast.com> | 2020-01-09 20:30:15 +0000 |
| commit | 3755a9911ecb05886577095f2b8cc8b9e4066a3a (patch) | |
| tree | 86e24bc466986cb5c9c6d167a918e6064defeafc /ssh/client/authmethods.go | |
Release of DTail v1.0.0v1.0.0
Diffstat (limited to 'ssh/client/authmethods.go')
| -rw-r--r-- | ssh/client/authmethods.go | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/ssh/client/authmethods.go b/ssh/client/authmethods.go new file mode 100644 index 0000000..84b7ce3 --- /dev/null +++ b/ssh/client/authmethods.go @@ -0,0 +1,45 @@ +package client + +import ( + "dtail/config" + "dtail/logger" + "dtail/ssh" + "os" + + gossh "golang.org/x/crypto/ssh" +) + +// InitSSHAuthMethods initialises all known SSH auth methods on othe client side. +func InitSSHAuthMethods(trustAllHosts bool, throttleCh chan struct{}) ([]gossh.AuthMethod, *HostKeyCallback) { + var sshAuthMethods []gossh.AuthMethod + + if config.Common.ExperimentalFeaturesEnable { + sshAuthMethods = append(sshAuthMethods, gossh.Password("experimental feature test")) + logger.Info("Added experimental method to list of auth methods") + } + + keyPath := os.Getenv("HOME") + "/.ssh/id_rsa" + if authMethod, err := ssh.PrivateKey(keyPath); err == nil { + sshAuthMethods = append(sshAuthMethods, authMethod) + logger.Info("Added path to list of auth methods", keyPath) + } + + keyPath = os.Getenv("HOME") + "/.ssh/id_dsa" + if authMethod, err := ssh.PrivateKey(keyPath); err == nil { + sshAuthMethods = append(sshAuthMethods, authMethod) + logger.Info("Added path to list of auth methods", keyPath) + } + + if authMethod, err := ssh.Agent(); err == nil { + sshAuthMethods = append(sshAuthMethods, authMethod) + logger.Info("Added SSH Agent to list of auth methods") + } + + knownHostsPath := os.Getenv("HOME") + "/.ssh/known_hosts" + hostKeyCallback, err := NewHostKeyCallback(knownHostsPath, trustAllHosts, throttleCh) + if err != nil { + logger.FatalExit(knownHostsPath, err) + } + + return sshAuthMethods, hostKeyCallback +} |
