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