github.com/terramate-io/tf@v0.0.0-20230830114523-fce866b4dfcd/communicator/ssh/password.go (about) 1 // Copyright (c) HashiCorp, Inc. 2 // SPDX-License-Identifier: MPL-2.0 3 4 package ssh 5 6 import ( 7 "log" 8 9 "golang.org/x/crypto/ssh" 10 ) 11 12 // An implementation of ssh.KeyboardInteractiveChallenge that simply sends 13 // back the password for all questions. The questions are logged. 14 func PasswordKeyboardInteractive(password string) ssh.KeyboardInteractiveChallenge { 15 return func(user, instruction string, questions []string, echos []bool) ([]string, error) { 16 log.Printf("Keyboard interactive challenge: ") 17 log.Printf("-- User: %s", user) 18 log.Printf("-- Instructions: %s", instruction) 19 for i, question := range questions { 20 log.Printf("-- Question %d: %s", i+1, question) 21 } 22 23 // Just send the password back for all questions 24 answers := make([]string, len(questions)) 25 for i := range answers { 26 answers[i] = string(password) 27 } 28 29 return answers, nil 30 } 31 }