2023-05-02 10:33:06 -05:00
|
|
|
// Copyright (c) HashiCorp, Inc.
|
|
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
|
2014-07-10 16:52:43 -05:00
|
|
|
package ssh
|
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
2016-04-18 19:28:46 -05:00
|
|
|
|
|
|
|
"golang.org/x/crypto/ssh"
|
2014-07-10 16:52:43 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
// An implementation of ssh.KeyboardInteractiveChallenge that simply sends
|
|
|
|
// back the password for all questions. The questions are logged.
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Just send the password back for all questions
|
|
|
|
answers := make([]string, len(questions))
|
2014-08-07 12:41:41 -05:00
|
|
|
for i := range answers {
|
2014-07-10 16:52:43 -05:00
|
|
|
answers[i] = string(password)
|
|
|
|
}
|
|
|
|
|
|
|
|
return answers, nil
|
|
|
|
}
|
|
|
|
}
|