From 02f1db4d0b7889092e171412d92198b0cd509936 Mon Sep 17 00:00:00 2001 From: Vojtech Vitek Date: Tue, 16 Jan 2018 21:35:18 -0500 Subject: [PATCH] WIP: SSH interactive passwords --- ssh.go | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/ssh.go b/ssh.go index eb3cefb..32a22b2 100644 --- a/ssh.go +++ b/ssh.go @@ -77,7 +77,7 @@ func (c *SSHClient) parseHost(host string) error { } var initAuthMethodOnce sync.Once -var authMethod ssh.AuthMethod +var signers []ssh.Signer // initAuthMethod initiates SSH authentication method. func initAuthMethod() { @@ -105,9 +105,7 @@ func initAuthMethod() { continue } signers = append(signers, signer) - } - authMethod = ssh.PublicKeys(signers...) } // SSHDialFunc can dial an ssh server and return a client @@ -137,7 +135,19 @@ func (c *SSHClient) ConnectWith(host string, dialer SSHDialFunc) error { config := &ssh.ClientConfig{ User: c.user, Auth: []ssh.AuthMethod{ - authMethod, + ssh.PublicKeysCallback(func() ([]ssh.Signer, error) { + return signers, nil + }), + ssh.KeyboardInteractive(func(user string, instruction string, questions []string, echos []bool) (answers []string, err error) { + answers = make([]string, len(questions)) + panic(fmt.Sprintf("%+v", questions)) + for n, q := range questions { + _ = q + answers[n] = "" + } + + return answers, nil + }), }, }