2013-12-22 12:08:09 -05:00
|
|
|
package common
|
|
|
|
|
|
|
|
import (
|
2017-04-04 16:39:01 -04:00
|
|
|
commonssh "github.com/hashicorp/packer/common/ssh"
|
|
|
|
"github.com/hashicorp/packer/communicator/ssh"
|
2018-01-19 19:18:44 -05:00
|
|
|
"github.com/hashicorp/packer/helper/multistep"
|
2015-06-09 00:34:20 -04:00
|
|
|
gossh "golang.org/x/crypto/ssh"
|
2013-12-22 12:08:09 -05:00
|
|
|
)
|
|
|
|
|
2016-08-24 12:30:26 -04:00
|
|
|
func CommHost(host string) func(multistep.StateBag) (string, error) {
|
|
|
|
return func(state multistep.StateBag) (string, error) {
|
|
|
|
return host, nil
|
|
|
|
}
|
2015-06-13 19:23:33 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func SSHPort(state multistep.StateBag) (int, error) {
|
2015-06-21 22:56:55 -04:00
|
|
|
sshHostPort := state.Get("sshHostPort").(int)
|
2017-03-28 21:47:10 -04:00
|
|
|
return sshHostPort, nil
|
2013-12-22 12:08:09 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func SSHConfigFunc(config SSHConfig) func(multistep.StateBag) (*gossh.ClientConfig, error) {
|
|
|
|
return func(state multistep.StateBag) (*gossh.ClientConfig, error) {
|
2014-04-10 04:48:55 -04:00
|
|
|
auth := []gossh.AuthMethod{
|
2015-06-13 18:08:12 -04:00
|
|
|
gossh.Password(config.Comm.SSHPassword),
|
2014-04-10 04:48:55 -04:00
|
|
|
gossh.KeyboardInteractive(
|
2015-06-13 18:08:12 -04:00
|
|
|
ssh.PasswordKeyboardInteractive(config.Comm.SSHPassword)),
|
2013-12-22 12:08:09 -05:00
|
|
|
}
|
|
|
|
|
2015-07-13 11:35:30 -04:00
|
|
|
if config.Comm.SSHPrivateKey != "" {
|
2015-06-13 18:08:12 -04:00
|
|
|
signer, err := commonssh.FileSigner(config.Comm.SSHPrivateKey)
|
2013-12-22 12:08:09 -05:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2014-04-26 14:12:43 -04:00
|
|
|
|
2014-04-10 04:48:55 -04:00
|
|
|
auth = append(auth, gossh.PublicKeys(signer))
|
2013-12-22 12:08:09 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return &gossh.ClientConfig{
|
2017-05-20 16:17:04 -04:00
|
|
|
User: config.Comm.SSHUsername,
|
|
|
|
Auth: auth,
|
|
|
|
HostKeyCallback: gossh.InsecureIgnoreHostKey(),
|
2013-12-22 12:08:09 -05:00
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
}
|