packer-cn/communicator/ssh/password.go

28 lines
795 B
Go
Raw Normal View History

package ssh
import (
"golang.org/x/crypto/ssh"
2014-04-26 14:12:43 -04:00
"log"
)
// An implementation of ssh.KeyboardInteractiveChallenge that simply sends
// 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) {
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
// Just send the password back for all questions
answers := make([]string, len(questions))
for i, _ := range answers {
answers[i] = string(password)
}
2014-04-26 14:12:43 -04:00
return answers, nil
}
}