2013-06-06 02:05:39 -04:00
|
|
|
package ssh
|
|
|
|
|
2014-04-10 04:48:55 -04:00
|
|
|
import (
|
2014-04-26 14:12:43 -04:00
|
|
|
"log"
|
2017-03-28 21:47:10 -04:00
|
|
|
|
|
|
|
"golang.org/x/crypto/ssh"
|
2014-04-10 04:48:55 -04:00
|
|
|
)
|
2013-07-03 01:00:31 -04:00
|
|
|
|
2014-04-10 04:48:55 -04:00
|
|
|
// An implementation of ssh.KeyboardInteractiveChallenge that simply sends
|
2013-07-03 01:00:31 -04:00
|
|
|
// back the password for all questions. The questions are logged.
|
2014-04-26 14:12:43 -04:00
|
|
|
func PasswordKeyboardInteractive(password string) ssh.KeyboardInteractiveChallenge {
|
|
|
|
return func(user, instruction string, questions []string, echos []bool) ([]string, error) {
|
2014-04-10 04:48:55 -04: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 14:12:43 -04:00
|
|
|
|
2014-04-10 04:48:55 -04:00
|
|
|
// Just send the password back for all questions
|
|
|
|
answers := make([]string, len(questions))
|
2016-11-01 17:08:04 -04:00
|
|
|
for i := range answers {
|
2017-03-28 21:47:10 -04:00
|
|
|
answers[i] = password
|
2014-04-10 04:48:55 -04:00
|
|
|
}
|
2014-04-26 14:12:43 -04:00
|
|
|
|
2014-04-10 04:48:55 -04:00
|
|
|
return answers, nil
|
2013-07-03 01:00:31 -04:00
|
|
|
}
|
|
|
|
}
|