Skip to content

Commit

Permalink
Merge melbahja#55 from gjung56/keyboard-interactive
Browse files Browse the repository at this point in the history
Add KeyboardInteractive auth as fallback of password
  • Loading branch information
melbahja committed Sep 2, 2023
2 parents 6258fe9 + 6a95efe commit b1f2e47
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"io/ioutil"
"net"
"os"
"strings"

"golang.org/x/crypto/ssh"
"golang.org/x/crypto/ssh/agent"
Expand All @@ -23,6 +24,23 @@ func Password(pass string) Auth {
}
}

// KeyboardInteractive returns password keyboard interactive auth method as fallback of password auth method.
func KeyboardInteractive(pass string) Auth {
return Auth{
ssh.Password(pass),
ssh.KeyboardInteractive(func(user, instruction string, questions []string, echos []bool) (answers []string, err error) {
for _, q := range questions {
if strings.Contains(strings.ToLower(q), "password") {
answers = append(answers, pass)
} else {
answers = append(answers, "")
}
}
return answers, nil
}),
}
}

// Key returns auth method from private key with or without passphrase.
func Key(prvFile string, passphrase string) (Auth, error) {

Expand Down

0 comments on commit b1f2e47

Please sign in to comment.