2013-06-05 23:05:39 -07:00
|
|
|
package ssh
|
|
|
|
|
2014-04-10 17:48:55 +09:00
|
|
|
import (
|
2015-04-03 22:30:13 -07:00
|
|
|
"golang.org/x/crypto/ssh"
|
2014-04-26 11:12:43 -07:00
|
|
|
"log"
|
2014-04-10 17:48:55 +09:00
|
|
|
)
|
2013-07-02 22:00:31 -07:00
|
|
|
|
2014-04-10 17:48:55 +09:00
|
|
|
// An implementation of ssh.KeyboardInteractiveChallenge that simply sends
|
2013-07-02 22:00:31 -07:00
|
|
|
// back the password for all questions. The questions are logged.
|
2014-04-26 11:12:43 -07:00
|
|
|
func PasswordKeyboardInteractive(password string) ssh.KeyboardInteractiveChallenge {
|
|
|
|
return func(user, instruction string, questions []string, echos []bool) ([]string, error) {
|
2014-04-10 17:48:55 +09:00
|
|
|
log.Printf("Keyboard interactive challenge: ")
|
|
|
|
log.Printf("-- User: %s", user)
|
|
|
|
log.Printf("-- Instructions: %s", instruction)
|
|
|
|
for i, question := range questions {
|
|
|
|
log.Printf("-- Question %d: %s", i+1, question)
|
|
|
|
}
|
2014-04-26 11:12:43 -07:00
|
|
|
|
2014-04-10 17:48:55 +09:00
|
|
|
// Just send the password back for all questions
|
|
|
|
answers := make([]string, len(questions))
|
2016-11-01 14:08:04 -07:00
|
|
|
for i := range answers {
|
2014-04-10 17:48:55 +09:00
|
|
|
answers[i] = string(password)
|
|
|
|
}
|
2014-04-26 11:12:43 -07:00
|
|
|
|
2014-04-10 17:48:55 +09:00
|
|
|
return answers, nil
|
2013-07-02 22:00:31 -07:00
|
|
|
}
|
|
|
|
}
|