2015-01-02 15:51:37 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
|
|
|
)
|
|
|
|
|
2015-01-02 17:01:52 +00:00
|
|
|
// Another auth. method.
|
2015-01-02 15:51:37 +00:00
|
|
|
func keyboardInteractiveChallenge(user, instruction string, questions []string, echos []bool) (answers []string, err error) {
|
|
|
|
|
2015-01-02 17:01:52 +00:00
|
|
|
// Log all the provided data:
|
2015-01-02 15:51:37 +00:00
|
|
|
log.Println(`User: ` + user)
|
|
|
|
log.Println(`Instruction: ` + instruction)
|
|
|
|
log.Println(`Questions:`)
|
|
|
|
for q := range questions {
|
|
|
|
log.Println(q)
|
|
|
|
}
|
|
|
|
|
2015-01-02 17:01:52 +00:00
|
|
|
// How many questions are asked?
|
2015-01-02 15:51:37 +00:00
|
|
|
countQuestions := len(questions)
|
|
|
|
|
2015-01-02 17:01:52 +00:00
|
|
|
if countQuestions == 1 {
|
|
|
|
|
|
|
|
// We expect that in this case (only one question is asked), that the server want to know the password ;-)
|
|
|
|
answers = make([]string, countQuestions, countQuestions)
|
2015-01-02 15:51:37 +00:00
|
|
|
answers[0] = password
|
2015-01-02 17:01:52 +00:00
|
|
|
|
|
|
|
} else if countQuestions > 1 {
|
|
|
|
|
|
|
|
// After logging, this call will exit the whole program:
|
|
|
|
log.Fatalln(`The SSH server is asking multiple questions! This program cannot handle this case.`)
|
2015-01-02 15:51:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
err = nil
|
|
|
|
return
|
|
|
|
}
|