diff --git a/builder/alicloud/ecs/builder.go b/builder/alicloud/ecs/builder.go index 99d759dc2..9c76fc31a 100644 --- a/builder/alicloud/ecs/builder.go +++ b/builder/alicloud/ecs/builder.go @@ -156,10 +156,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe Host: SSHHost( client, b.config.SSHPrivateIp), - SSHConfig: SSHConfig( - b.config.RunConfig.Comm.SSHAgentAuth, - b.config.RunConfig.Comm.SSHUsername, - b.config.RunConfig.Comm.SSHPassword), + SSHConfig: b.config.RunConfig.Comm.SSHConfigFunc(), }, &common.StepProvision{}, &stepStopAlicloudInstance{ diff --git a/builder/alicloud/ecs/ssh_helper.go b/builder/alicloud/ecs/ssh_helper.go index aac733ece..21354d017 100644 --- a/builder/alicloud/ecs/ssh_helper.go +++ b/builder/alicloud/ecs/ssh_helper.go @@ -1,15 +1,9 @@ package ecs import ( - "fmt" - "net" - "os" "time" - packerssh "github.com/hashicorp/packer/communicator/ssh" "github.com/hashicorp/packer/helper/multistep" - "golang.org/x/crypto/ssh" - "golang.org/x/crypto/ssh/agent" ) var ( @@ -27,57 +21,3 @@ func SSHHost(e alicloudSSHHelper, private bool) func(multistep.StateBag) (string return ipAddress, nil } } - -// SSHConfig returns a function that can be used for the SSH communicator -// config for connecting to the instance created over SSH using the private key -// or password. -func SSHConfig(useAgent bool, username, password string) func(multistep.StateBag) (*ssh.ClientConfig, error) { - return func(state multistep.StateBag) (*ssh.ClientConfig, error) { - if useAgent { - authSock := os.Getenv("SSH_AUTH_SOCK") - if authSock == "" { - return nil, fmt.Errorf("SSH_AUTH_SOCK is not set") - } - - sshAgent, err := net.Dial("unix", authSock) - if err != nil { - return nil, fmt.Errorf("Cannot connect to SSH Agent socket %q: %s", authSock, err) - } - - return &ssh.ClientConfig{ - User: username, - Auth: []ssh.AuthMethod{ - ssh.PublicKeysCallback(agent.NewClient(sshAgent).Signers), - }, - HostKeyCallback: ssh.InsecureIgnoreHostKey(), - }, nil - } - - privateKey, hasKey := state.GetOk("privateKey") - if hasKey { - - signer, err := ssh.ParsePrivateKey([]byte(privateKey.(string))) - if err != nil { - return nil, fmt.Errorf("Error setting up SSH config: %s", err) - } - return &ssh.ClientConfig{ - User: username, - Auth: []ssh.AuthMethod{ - ssh.PublicKeys(signer), - }, - HostKeyCallback: ssh.InsecureIgnoreHostKey(), - }, nil - - } else { - return &ssh.ClientConfig{ - User: username, - Auth: []ssh.AuthMethod{ - ssh.Password(password), - ssh.KeyboardInteractive( - packerssh.PasswordKeyboardInteractive(password)), - }, - HostKeyCallback: ssh.InsecureIgnoreHostKey(), - }, nil - } - } -} diff --git a/builder/amazon/ebs/builder.go b/builder/amazon/ebs/builder.go index f2c0bcbec..c7eae1c44 100644 --- a/builder/amazon/ebs/builder.go +++ b/builder/amazon/ebs/builder.go @@ -206,10 +206,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe Host: awscommon.SSHHost( ec2conn, b.config.SSHInterface), - SSHConfig: awscommon.SSHConfig( - b.config.RunConfig.Comm.SSHAgentAuth, - b.config.RunConfig.Comm.SSHUsername, - b.config.RunConfig.Comm.SSHPassword), + SSHConfig: b.config.RunConfig.Comm.SSHConfigFunc(), }, &common.StepProvision{}, &awscommon.StepStopEBSBackedInstance{ diff --git a/builder/amazon/ebssurrogate/builder.go b/builder/amazon/ebssurrogate/builder.go index e9cc8ad7d..4414bb6ab 100644 --- a/builder/amazon/ebssurrogate/builder.go +++ b/builder/amazon/ebssurrogate/builder.go @@ -223,10 +223,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe Host: awscommon.SSHHost( ec2conn, b.config.SSHInterface), - SSHConfig: awscommon.SSHConfig( - b.config.RunConfig.Comm.SSHAgentAuth, - b.config.RunConfig.Comm.SSHUsername, - b.config.RunConfig.Comm.SSHPassword), + SSHConfig: b.config.RunConfig.Comm.SSHConfigFunc(), }, &common.StepProvision{}, &awscommon.StepStopEBSBackedInstance{ diff --git a/builder/amazon/ebsvolume/builder.go b/builder/amazon/ebsvolume/builder.go index 222febc56..10ba3046b 100644 --- a/builder/amazon/ebsvolume/builder.go +++ b/builder/amazon/ebsvolume/builder.go @@ -199,10 +199,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe Host: awscommon.SSHHost( ec2conn, b.config.SSHInterface), - SSHConfig: awscommon.SSHConfig( - b.config.RunConfig.Comm.SSHAgentAuth, - b.config.RunConfig.Comm.SSHUsername, - b.config.RunConfig.Comm.SSHPassword), + SSHConfig: b.config.RunConfig.Comm.SSHConfigFunc(), }, &common.StepProvision{}, &awscommon.StepStopEBSBackedInstance{ diff --git a/builder/amazon/instance/builder.go b/builder/amazon/instance/builder.go index fb59fff95..a6b836edf 100644 --- a/builder/amazon/instance/builder.go +++ b/builder/amazon/instance/builder.go @@ -282,10 +282,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe Host: awscommon.SSHHost( ec2conn, b.config.SSHInterface), - SSHConfig: awscommon.SSHConfig( - b.config.RunConfig.Comm.SSHAgentAuth, - b.config.RunConfig.Comm.SSHUsername, - b.config.RunConfig.Comm.SSHPassword), + SSHConfig: b.config.RunConfig.Comm.SSHConfigFunc(), }, &common.StepProvision{}, &StepUploadX509Cert{}, diff --git a/builder/cloudstack/builder.go b/builder/cloudstack/builder.go index 6726b29f9..a655c810d 100644 --- a/builder/cloudstack/builder.go +++ b/builder/cloudstack/builder.go @@ -78,12 +78,9 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe }, &stepSetupNetworking{}, &communicator.StepConnect{ - Config: &b.config.Comm, - Host: commHost, - SSHConfig: sshConfig( - b.config.Comm.SSHAgentAuth, - b.config.Comm.SSHUsername, - b.config.Comm.SSHPassword), + Config: &b.config.Comm, + Host: commHost, + SSHConfig: b.config.Comm.SSHConfigFunc(), SSHPort: commPort, WinRMPort: commPort, }, diff --git a/builder/cloudstack/ssh.go b/builder/cloudstack/ssh.go index e1c2ef846..ec9fbe123 100644 --- a/builder/cloudstack/ssh.go +++ b/builder/cloudstack/ssh.go @@ -2,13 +2,8 @@ package cloudstack import ( "fmt" - "net" - "os" - packerssh "github.com/hashicorp/packer/communicator/ssh" "github.com/hashicorp/packer/helper/multistep" - "golang.org/x/crypto/ssh" - "golang.org/x/crypto/ssh/agent" ) func commHost(state multistep.StateBag) (string, error) { @@ -28,55 +23,3 @@ func commPort(state multistep.StateBag) (int, error) { return commPort, nil } - -func sshConfig(useAgent bool, username, password string) func(state multistep.StateBag) (*ssh.ClientConfig, error) { - return func(state multistep.StateBag) (*ssh.ClientConfig, error) { - if useAgent { - authSock := os.Getenv("SSH_AUTH_SOCK") - if authSock == "" { - return nil, fmt.Errorf("SSH_AUTH_SOCK is not set") - } - - sshAgent, err := net.Dial("unix", authSock) - if err != nil { - return nil, fmt.Errorf("Cannot connect to SSH Agent socket %q: %s", authSock, err) - } - - return &ssh.ClientConfig{ - User: username, - Auth: []ssh.AuthMethod{ - ssh.PublicKeysCallback(agent.NewClient(sshAgent).Signers), - }, - HostKeyCallback: ssh.InsecureIgnoreHostKey(), - }, nil - } - - privateKey, hasKey := state.GetOk("privateKey") - - if hasKey { - signer, err := ssh.ParsePrivateKey([]byte(privateKey.(string))) - if err != nil { - return nil, fmt.Errorf("Error setting up SSH config: %s", err) - } - - return &ssh.ClientConfig{ - User: username, - Auth: []ssh.AuthMethod{ - ssh.PublicKeys(signer), - }, - HostKeyCallback: ssh.InsecureIgnoreHostKey(), - }, nil - - } else { - - return &ssh.ClientConfig{ - User: username, - HostKeyCallback: ssh.InsecureIgnoreHostKey(), - Auth: []ssh.AuthMethod{ - ssh.Password(password), - ssh.KeyboardInteractive( - packerssh.PasswordKeyboardInteractive(password)), - }}, nil - } - } -} diff --git a/builder/digitalocean/builder.go b/builder/digitalocean/builder.go index d5e674d63..1c34f6591 100644 --- a/builder/digitalocean/builder.go +++ b/builder/digitalocean/builder.go @@ -87,7 +87,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe &communicator.StepConnect{ Config: &b.config.Comm, Host: commHost, - SSHConfig: sshConfig, + SSHConfig: b.config.Comm.SSHConfigFunc(), }, new(common.StepProvision), new(stepShutdown), diff --git a/builder/digitalocean/ssh.go b/builder/digitalocean/ssh.go index 2b5c4ef8d..b47628ba8 100644 --- a/builder/digitalocean/ssh.go +++ b/builder/digitalocean/ssh.go @@ -1,10 +1,6 @@ package digitalocean import ( - "fmt" - - "golang.org/x/crypto/ssh" - "github.com/hashicorp/packer/helper/multistep" ) @@ -12,21 +8,3 @@ func commHost(state multistep.StateBag) (string, error) { ipAddress := state.Get("droplet_ip").(string) return ipAddress, nil } - -func sshConfig(state multistep.StateBag) (*ssh.ClientConfig, error) { - config := state.Get("config").(Config) - privateKey := state.Get("privateKey").(string) - - signer, err := ssh.ParsePrivateKey([]byte(privateKey)) - if err != nil { - return nil, fmt.Errorf("Error setting up SSH config: %s", err) - } - - return &ssh.ClientConfig{ - User: config.Comm.SSHUsername, - Auth: []ssh.AuthMethod{ - ssh.PublicKeys(signer), - }, - HostKeyCallback: ssh.InsecureIgnoreHostKey(), - }, nil -} diff --git a/builder/docker/builder.go b/builder/docker/builder.go index ba58f61bb..951231c8d 100644 --- a/builder/docker/builder.go +++ b/builder/docker/builder.go @@ -48,7 +48,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe &communicator.StepConnect{ Config: &b.config.Comm, Host: commHost, - SSHConfig: sshConfig(&b.config.Comm), + SSHConfig: b.config.Comm.SSHConfigFunc(), CustomConnect: map[string]multistep.Step{ "docker": &StepConnectDocker{}, }, diff --git a/builder/docker/comm.go b/builder/docker/comm.go index bda53e0a1..e11a0eaf2 100644 --- a/builder/docker/comm.go +++ b/builder/docker/comm.go @@ -1,13 +1,7 @@ package docker import ( - "fmt" - "io/ioutil" - - "github.com/hashicorp/packer/communicator/ssh" - "github.com/hashicorp/packer/helper/communicator" "github.com/hashicorp/packer/helper/multistep" - gossh "golang.org/x/crypto/ssh" ) func commHost(state multistep.StateBag) (string, error) { @@ -15,40 +9,3 @@ func commHost(state multistep.StateBag) (string, error) { driver := state.Get("driver").(Driver) return driver.IPAddress(containerId) } - -func sshConfig(comm *communicator.Config) func(state multistep.StateBag) (*gossh.ClientConfig, error) { - return func(state multistep.StateBag) (*gossh.ClientConfig, error) { - if comm.SSHPrivateKey != "" { - // key based auth - bytes, err := ioutil.ReadFile(comm.SSHPrivateKey) - if err != nil { - return nil, fmt.Errorf("Error setting up SSH config: %s", err) - } - privateKey := string(bytes) - - signer, err := gossh.ParsePrivateKey([]byte(privateKey)) - if err != nil { - return nil, fmt.Errorf("Error setting up SSH config: %s", err) - } - - return &gossh.ClientConfig{ - User: comm.SSHUsername, - Auth: []gossh.AuthMethod{ - gossh.PublicKeys(signer), - }, - HostKeyCallback: gossh.InsecureIgnoreHostKey(), - }, nil - } else { - // password based auth - return &gossh.ClientConfig{ - User: comm.SSHUsername, - Auth: []gossh.AuthMethod{ - gossh.Password(comm.SSHPassword), - gossh.KeyboardInteractive( - ssh.PasswordKeyboardInteractive(comm.SSHPassword)), - }, - HostKeyCallback: gossh.InsecureIgnoreHostKey(), - }, nil - } - } -} diff --git a/builder/googlecompute/builder.go b/builder/googlecompute/builder.go index c60117075..c532fee11 100644 --- a/builder/googlecompute/builder.go +++ b/builder/googlecompute/builder.go @@ -68,7 +68,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe &communicator.StepConnect{ Config: &b.config.Comm, Host: commHost, - SSHConfig: sshConfig, + SSHConfig: b.config.Comm.SSHConfigFunc(), WinRMConfig: winrmConfig, }, new(common.StepProvision), diff --git a/builder/googlecompute/ssh.go b/builder/googlecompute/ssh.go index bf704b13e..e498ed43b 100644 --- a/builder/googlecompute/ssh.go +++ b/builder/googlecompute/ssh.go @@ -1,32 +1,10 @@ package googlecompute import ( - "fmt" - "github.com/hashicorp/packer/helper/multistep" - "golang.org/x/crypto/ssh" ) func commHost(state multistep.StateBag) (string, error) { ipAddress := state.Get("instance_ip").(string) return ipAddress, nil } - -// sshConfig returns the ssh configuration. -func sshConfig(state multistep.StateBag) (*ssh.ClientConfig, error) { - config := state.Get("config").(*Config) - privateKey := state.Get("ssh_private_key").(string) - - signer, err := ssh.ParsePrivateKey([]byte(privateKey)) - if err != nil { - return nil, fmt.Errorf("Error setting up SSH config: %s", err) - } - - return &ssh.ClientConfig{ - User: config.Comm.SSHUsername, - Auth: []ssh.AuthMethod{ - ssh.PublicKeys(signer), - }, - HostKeyCallback: ssh.InsecureIgnoreHostKey(), - }, nil -} diff --git a/builder/hyperv/common/ssh.go b/builder/hyperv/common/ssh.go index f8a059bb0..ab136f373 100644 --- a/builder/hyperv/common/ssh.go +++ b/builder/hyperv/common/ssh.go @@ -1,10 +1,7 @@ package common import ( - commonssh "github.com/hashicorp/packer/common/ssh" - "github.com/hashicorp/packer/communicator/ssh" "github.com/hashicorp/packer/helper/multistep" - gossh "golang.org/x/crypto/ssh" ) func CommHost(state multistep.StateBag) (string, error) { @@ -23,28 +20,3 @@ func CommHost(state multistep.StateBag) (string, error) { return ip, nil } - -func SSHConfigFunc(config *SSHConfig) func(multistep.StateBag) (*gossh.ClientConfig, error) { - return func(state multistep.StateBag) (*gossh.ClientConfig, error) { - auth := []gossh.AuthMethod{ - gossh.Password(config.Comm.SSHPassword), - gossh.KeyboardInteractive( - ssh.PasswordKeyboardInteractive(config.Comm.SSHPassword)), - } - - if config.Comm.SSHPrivateKey != "" { - signer, err := commonssh.FileSigner(config.Comm.SSHPrivateKey) - if err != nil { - return nil, err - } - - auth = append(auth, gossh.PublicKeys(signer)) - } - - return &gossh.ClientConfig{ - User: config.Comm.SSHUsername, - Auth: auth, - HostKeyCallback: gossh.InsecureIgnoreHostKey(), - }, nil - } -} diff --git a/builder/hyperv/iso/builder.go b/builder/hyperv/iso/builder.go index d50e5e26a..b90894f2f 100644 --- a/builder/hyperv/iso/builder.go +++ b/builder/hyperv/iso/builder.go @@ -444,7 +444,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe &communicator.StepConnect{ Config: &b.config.SSHConfig.Comm, Host: hypervcommon.CommHost, - SSHConfig: hypervcommon.SSHConfigFunc(&b.config.SSHConfig), + SSHConfig: b.config.SSHConfig.Comm.SSHConfigFunc(), }, // provision requires communicator to be setup diff --git a/builder/hyperv/vmcx/builder.go b/builder/hyperv/vmcx/builder.go index 987c41a12..a9aae2931 100644 --- a/builder/hyperv/vmcx/builder.go +++ b/builder/hyperv/vmcx/builder.go @@ -453,7 +453,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe &communicator.StepConnect{ Config: &b.config.SSHConfig.Comm, Host: hypervcommon.CommHost, - SSHConfig: hypervcommon.SSHConfigFunc(&b.config.SSHConfig), + SSHConfig: b.config.SSHConfig.Comm.SSHConfigFunc(), }, // provision requires communicator to be setup diff --git a/builder/null/builder.go b/builder/null/builder.go index f4d4764d6..31090c311 100644 --- a/builder/null/builder.go +++ b/builder/null/builder.go @@ -32,13 +32,9 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe if b.config.CommConfig.Type != "none" { steps = append(steps, &communicator.StepConnect{ - Config: &b.config.CommConfig, - Host: CommHost(b.config.CommConfig.Host()), - SSHConfig: SSHConfig( - b.config.CommConfig.SSHAgentAuth, - b.config.CommConfig.SSHUsername, - b.config.CommConfig.SSHPassword, - b.config.CommConfig.SSHPrivateKey), + Config: &b.config.CommConfig, + Host: CommHost(b.config.CommConfig.Host()), + SSHConfig: b.config.CommConfig.SSHConfigFunc(), }, ) } diff --git a/builder/oneandone/builder.go b/builder/oneandone/builder.go index 4b84b3938..2faf953c6 100644 --- a/builder/oneandone/builder.go +++ b/builder/oneandone/builder.go @@ -45,7 +45,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe &communicator.StepConnect{ Config: &b.config.Comm, Host: commHost, - SSHConfig: sshConfig, + SSHConfig: b.config.Comm.SSHConfigFunc(), }, &common.StepProvision{}, new(stepTakeSnapshot), diff --git a/builder/oneandone/ssh.go b/builder/oneandone/ssh.go index 9fdb128a9..4068b87af 100644 --- a/builder/oneandone/ssh.go +++ b/builder/oneandone/ssh.go @@ -1,49 +1,10 @@ package oneandone import ( - "fmt" - - "github.com/hashicorp/packer/communicator/ssh" "github.com/hashicorp/packer/helper/multistep" - gossh "golang.org/x/crypto/ssh" ) func commHost(state multistep.StateBag) (string, error) { ipAddress := state.Get("server_ip").(string) return ipAddress, nil } - -func sshConfig(state multistep.StateBag) (*gossh.ClientConfig, error) { - config := state.Get("config").(*Config) - var privateKey string - - var auth []gossh.AuthMethod - - if config.Comm.SSHPassword != "" { - auth = []gossh.AuthMethod{ - gossh.Password(config.Comm.SSHPassword), - gossh.KeyboardInteractive( - ssh.PasswordKeyboardInteractive(config.Comm.SSHPassword)), - } - } - - if config.Comm.SSHPrivateKey != "" { - if priv, ok := state.GetOk("privateKey"); ok { - privateKey = priv.(string) - } - signer, err := gossh.ParsePrivateKey([]byte(privateKey)) - if err != nil { - return nil, fmt.Errorf("Error setting up SSH config: %s", err) - } - if err != nil { - return nil, err - } - - auth = append(auth, gossh.PublicKeys(signer)) - } - return &gossh.ClientConfig{ - User: config.Comm.SSHUsername, - Auth: auth, - HostKeyCallback: gossh.InsecureIgnoreHostKey(), - }, nil -} diff --git a/builder/openstack/builder.go b/builder/openstack/builder.go index 2938d67c0..548d55de3 100644 --- a/builder/openstack/builder.go +++ b/builder/openstack/builder.go @@ -125,10 +125,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe computeClient, b.config.SSHInterface, b.config.SSHIPVersion), - SSHConfig: SSHConfig( - b.config.RunConfig.Comm.SSHAgentAuth, - b.config.RunConfig.Comm.SSHUsername, - b.config.RunConfig.Comm.SSHPassword), + SSHConfig: b.config.RunConfig.Comm.SSHConfigFunc(), }, &common.StepProvision{}, &StepStopServer{}, diff --git a/builder/openstack/ssh.go b/builder/openstack/ssh.go index 15c9bc36f..0fd9f794b 100644 --- a/builder/openstack/ssh.go +++ b/builder/openstack/ssh.go @@ -4,17 +4,12 @@ import ( "errors" "fmt" "log" - "net" - "os" "time" "github.com/gophercloud/gophercloud" "github.com/gophercloud/gophercloud/openstack/compute/v2/servers" "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/layer3/floatingips" - packerssh "github.com/hashicorp/packer/communicator/ssh" "github.com/hashicorp/packer/helper/multistep" - "golang.org/x/crypto/ssh" - "golang.org/x/crypto/ssh/agent" ) // CommHost looks up the host for the communicator. @@ -63,62 +58,6 @@ func CommHost( } } -// SSHConfig returns a function that can be used for the SSH communicator -// config for connecting to the instance created over SSH using a private key -// or a password. -func SSHConfig(useAgent bool, username, password string) func(multistep.StateBag) (*ssh.ClientConfig, error) { - return func(state multistep.StateBag) (*ssh.ClientConfig, error) { - if useAgent { - authSock := os.Getenv("SSH_AUTH_SOCK") - if authSock == "" { - return nil, fmt.Errorf("SSH_AUTH_SOCK is not set") - } - - sshAgent, err := net.Dial("unix", authSock) - if err != nil { - return nil, fmt.Errorf("Cannot connect to SSH Agent socket %q: %s", authSock, err) - } - - return &ssh.ClientConfig{ - User: username, - Auth: []ssh.AuthMethod{ - ssh.PublicKeysCallback(agent.NewClient(sshAgent).Signers), - }, - HostKeyCallback: ssh.InsecureIgnoreHostKey(), - }, nil - } - - privateKey, hasKey := state.GetOk("privateKey") - - if hasKey { - - signer, err := ssh.ParsePrivateKey([]byte(privateKey.(string))) - if err != nil { - return nil, fmt.Errorf("Error setting up SSH config: %s", err) - } - - return &ssh.ClientConfig{ - User: username, - Auth: []ssh.AuthMethod{ - ssh.PublicKeys(signer), - }, - HostKeyCallback: ssh.InsecureIgnoreHostKey(), - }, nil - - } else { - - return &ssh.ClientConfig{ - User: username, - HostKeyCallback: ssh.InsecureIgnoreHostKey(), - Auth: []ssh.AuthMethod{ - ssh.Password(password), - ssh.KeyboardInteractive( - packerssh.PasswordKeyboardInteractive(password)), - }}, nil - } - } -} - func sshAddrFromPool(s *servers.Server, desired string, sshIPVersion string) string { // Get all the addresses associated with this server. This // was taken directly from Terraform. diff --git a/builder/oracle/classic/builder.go b/builder/oracle/classic/builder.go index 1e90439be..d5c950d91 100644 --- a/builder/oracle/classic/builder.go +++ b/builder/oracle/classic/builder.go @@ -72,11 +72,9 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe &stepSecurity{}, &stepCreateInstance{}, &communicator.StepConnect{ - Config: &b.config.Comm, - Host: ocommon.CommHost, - SSHConfig: ocommon.SSHConfig( - b.config.Comm.SSHUsername, - b.config.Comm.SSHPassword), + Config: &b.config.Comm, + Host: ocommon.CommHost, + SSHConfig: b.config.Comm.SSHConfigFunc(), }, &common.StepProvision{}, &stepSnapshot{}, diff --git a/builder/oracle/common/ssh.go b/builder/oracle/common/ssh.go index 8e448e592..53b5d349a 100644 --- a/builder/oracle/common/ssh.go +++ b/builder/oracle/common/ssh.go @@ -1,45 +1,10 @@ package common import ( - "fmt" - - packerssh "github.com/hashicorp/packer/communicator/ssh" "github.com/hashicorp/packer/helper/multistep" - "golang.org/x/crypto/ssh" ) func CommHost(state multistep.StateBag) (string, error) { ipAddress := state.Get("instance_ip").(string) return ipAddress, nil } - -// SSHConfig returns a function that can be used for the SSH communicator -// config for connecting to the instance created over SSH using the private key -// or password. -func SSHConfig(username, password string) func(state multistep.StateBag) (*ssh.ClientConfig, error) { - return func(state multistep.StateBag) (*ssh.ClientConfig, error) { - privateKey, hasKey := state.GetOk("privateKey") - if hasKey { - - signer, err := ssh.ParsePrivateKey([]byte(privateKey.(string))) - if err != nil { - return nil, fmt.Errorf("Error setting up SSH config: %s", err) - } - return &ssh.ClientConfig{ - User: username, - Auth: []ssh.AuthMethod{ssh.PublicKeys(signer)}, - HostKeyCallback: ssh.InsecureIgnoreHostKey(), - }, nil - - } - - return &ssh.ClientConfig{ - User: username, - HostKeyCallback: ssh.InsecureIgnoreHostKey(), - Auth: []ssh.AuthMethod{ - ssh.Password(password), - ssh.KeyboardInteractive(packerssh.PasswordKeyboardInteractive(password)), - }, - }, nil - } -} diff --git a/builder/oracle/oci/builder.go b/builder/oracle/oci/builder.go index 1554f6013..672746829 100644 --- a/builder/oracle/oci/builder.go +++ b/builder/oracle/oci/builder.go @@ -64,11 +64,9 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe BuildName: b.config.PackerBuildName, }, &communicator.StepConnect{ - Config: &b.config.Comm, - Host: ocommon.CommHost, - SSHConfig: ocommon.SSHConfig( - b.config.Comm.SSHUsername, - b.config.Comm.SSHPassword), + Config: &b.config.Comm, + Host: ocommon.CommHost, + SSHConfig: b.config.Comm.SSHConfigFunc(), }, &common.StepProvision{}, &stepImage{}, diff --git a/builder/parallels/common/ssh.go b/builder/parallels/common/ssh.go index 6673698b5..7c94006eb 100644 --- a/builder/parallels/common/ssh.go +++ b/builder/parallels/common/ssh.go @@ -1,10 +1,7 @@ package common import ( - commonssh "github.com/hashicorp/packer/common/ssh" - packerssh "github.com/hashicorp/packer/communicator/ssh" "github.com/hashicorp/packer/helper/multistep" - "golang.org/x/crypto/ssh" ) // CommHost returns the VM's IP address which should be used to access it by SSH. @@ -24,29 +21,3 @@ func CommHost(state multistep.StateBag) (string, error) { return ip, nil } - -// SSHConfigFunc returns SSH credentials to access the VM by SSH. -func SSHConfigFunc(config SSHConfig) func(multistep.StateBag) (*ssh.ClientConfig, error) { - return func(state multistep.StateBag) (*ssh.ClientConfig, error) { - auth := []ssh.AuthMethod{ - ssh.Password(config.Comm.SSHPassword), - ssh.KeyboardInteractive( - packerssh.PasswordKeyboardInteractive(config.Comm.SSHPassword)), - } - - if config.Comm.SSHPrivateKey != "" { - signer, err := commonssh.FileSigner(config.Comm.SSHPrivateKey) - if err != nil { - return nil, err - } - - auth = append(auth, ssh.PublicKeys(signer)) - } - - return &ssh.ClientConfig{ - User: config.Comm.SSHUsername, - Auth: auth, - HostKeyCallback: ssh.InsecureIgnoreHostKey(), - }, nil - } -} diff --git a/builder/parallels/iso/builder.go b/builder/parallels/iso/builder.go index 9ba2002f7..860787bf7 100644 --- a/builder/parallels/iso/builder.go +++ b/builder/parallels/iso/builder.go @@ -196,7 +196,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe &communicator.StepConnect{ Config: &b.config.SSHConfig.Comm, Host: parallelscommon.CommHost, - SSHConfig: parallelscommon.SSHConfigFunc(b.config.SSHConfig), + SSHConfig: b.config.SSHConfig.Comm.SSHConfigFunc(), }, ¶llelscommon.StepUploadVersion{ Path: b.config.PrlctlVersionFile, diff --git a/builder/parallels/pvm/builder.go b/builder/parallels/pvm/builder.go index e36916092..8868a19ff 100644 --- a/builder/parallels/pvm/builder.go +++ b/builder/parallels/pvm/builder.go @@ -85,7 +85,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe &communicator.StepConnect{ Config: &b.config.SSHConfig.Comm, Host: parallelscommon.CommHost, - SSHConfig: parallelscommon.SSHConfigFunc(b.config.SSHConfig), + SSHConfig: b.config.SSHConfig.SSHConfigFunc(), }, ¶llelscommon.StepUploadVersion{ Path: b.config.PrlctlVersionFile, diff --git a/builder/profitbricks/builder.go b/builder/profitbricks/builder.go index 6a1428075..dfc754ad4 100644 --- a/builder/profitbricks/builder.go +++ b/builder/profitbricks/builder.go @@ -42,7 +42,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe &communicator.StepConnect{ Config: &b.config.Comm, Host: commHost, - SSHConfig: sshConfig, + SSHConfig: b.config.Comm.SSHConfigFunc(), }, &common.StepProvision{}, new(stepTakeSnapshot), diff --git a/builder/profitbricks/ssh.go b/builder/profitbricks/ssh.go index d56696330..c860bc841 100644 --- a/builder/profitbricks/ssh.go +++ b/builder/profitbricks/ssh.go @@ -1,49 +1,10 @@ package profitbricks import ( - "fmt" - - "github.com/hashicorp/packer/communicator/ssh" "github.com/hashicorp/packer/helper/multistep" - gossh "golang.org/x/crypto/ssh" ) func commHost(state multistep.StateBag) (string, error) { ipAddress := state.Get("server_ip").(string) return ipAddress, nil } - -func sshConfig(state multistep.StateBag) (*gossh.ClientConfig, error) { - config := state.Get("config").(*Config) - var privateKey string - - var auth []gossh.AuthMethod - - if config.Comm.SSHPassword != "" { - auth = []gossh.AuthMethod{ - gossh.Password(config.Comm.SSHPassword), - gossh.KeyboardInteractive( - ssh.PasswordKeyboardInteractive(config.Comm.SSHPassword)), - } - } - - if config.Comm.SSHPrivateKey != "" { - if priv, ok := state.GetOk("privateKey"); ok { - privateKey = priv.(string) - } - signer, err := gossh.ParsePrivateKey([]byte(privateKey)) - if err != nil { - return nil, fmt.Errorf("Error setting up SSH config: %s", err) - } - if err != nil { - return nil, err - } - - auth = append(auth, gossh.PublicKeys(signer)) - } - return &gossh.ClientConfig{ - User: config.Comm.SSHUsername, - Auth: auth, - HostKeyCallback: gossh.InsecureIgnoreHostKey(), - }, nil -} diff --git a/builder/qemu/builder.go b/builder/qemu/builder.go index fa2f1f9d9..47ebb2396 100644 --- a/builder/qemu/builder.go +++ b/builder/qemu/builder.go @@ -393,7 +393,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe &communicator.StepConnect{ Config: &b.config.Comm, Host: commHost, - SSHConfig: sshConfig, + SSHConfig: b.config.Comm.SSHConfigFunc(), SSHPort: commPort, WinRMPort: commPort, }, diff --git a/builder/qemu/ssh.go b/builder/qemu/ssh.go index 1ee44ddb0..ec030df2e 100644 --- a/builder/qemu/ssh.go +++ b/builder/qemu/ssh.go @@ -1,15 +1,7 @@ package qemu import ( - "fmt" - "net" - "os" - - commonssh "github.com/hashicorp/packer/common/ssh" - packerssh "github.com/hashicorp/packer/communicator/ssh" "github.com/hashicorp/packer/helper/multistep" - gossh "golang.org/x/crypto/ssh" - "golang.org/x/crypto/ssh/agent" ) func commHost(state multistep.StateBag) (string, error) { @@ -20,47 +12,3 @@ func commPort(state multistep.StateBag) (int, error) { sshHostPort := state.Get("sshHostPort").(uint) return int(sshHostPort), nil } - -func sshConfig(state multistep.StateBag) (*gossh.ClientConfig, error) { - config := state.Get("config").(*Config) - - var auth []gossh.AuthMethod - - if config.Comm.SSHAgentAuth { - authSock := os.Getenv("SSH_AUTH_SOCK") - if authSock == "" { - return nil, fmt.Errorf("SSH_AUTH_SOCK is not set") - } - - sshAgent, err := net.Dial("unix", authSock) - if err != nil { - return nil, fmt.Errorf("Cannot connect to SSH Agent socket %q: %s", authSock, err) - } - auth = []gossh.AuthMethod{ - gossh.PublicKeysCallback(agent.NewClient(sshAgent).Signers), - } - } - - if config.Comm.SSHPassword != "" { - auth = append(auth, - gossh.Password(config.Comm.SSHPassword), - gossh.KeyboardInteractive( - packerssh.PasswordKeyboardInteractive(config.Comm.SSHPassword)), - ) - } - - if config.Comm.SSHPrivateKey != "" { - signer, err := commonssh.FileSigner(config.Comm.SSHPrivateKey) - if err != nil { - return nil, err - } - - auth = append(auth, gossh.PublicKeys(signer)) - } - - return &gossh.ClientConfig{ - User: config.Comm.SSHUsername, - Auth: auth, - HostKeyCallback: gossh.InsecureIgnoreHostKey(), - }, nil -} diff --git a/builder/scaleway/builder.go b/builder/scaleway/builder.go index 457002c74..f7a19927d 100644 --- a/builder/scaleway/builder.go +++ b/builder/scaleway/builder.go @@ -58,7 +58,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe &communicator.StepConnect{ Config: &b.config.Comm, Host: commHost, - SSHConfig: sshConfig, + SSHConfig: b.config.Comm.SSHConfigFunc(), }, new(common.StepProvision), new(stepShutdown), diff --git a/builder/scaleway/ssh.go b/builder/scaleway/ssh.go index e4677849f..e291151ab 100644 --- a/builder/scaleway/ssh.go +++ b/builder/scaleway/ssh.go @@ -1,61 +1,10 @@ package scaleway import ( - "fmt" - "net" - "os" - - packerssh "github.com/hashicorp/packer/communicator/ssh" "github.com/hashicorp/packer/helper/multistep" - "golang.org/x/crypto/ssh" - "golang.org/x/crypto/ssh/agent" ) func commHost(state multistep.StateBag) (string, error) { ipAddress := state.Get("server_ip").(string) return ipAddress, nil } - -func sshConfig(state multistep.StateBag) (*ssh.ClientConfig, error) { - config := state.Get("config").(Config) - - var auth []ssh.AuthMethod - - if config.Comm.SSHAgentAuth { - authSock := os.Getenv("SSH_AUTH_SOCK") - if authSock == "" { - return nil, fmt.Errorf("SSH_AUTH_SOCK is not set") - } - - sshAgent, err := net.Dial("unix", authSock) - if err != nil { - return nil, fmt.Errorf("Cannot connect to SSH Agent socket %q: %s", authSock, err) - } - auth = []ssh.AuthMethod{ - ssh.PublicKeysCallback(agent.NewClient(sshAgent).Signers), - } - } - - if config.Comm.SSHPassword != "" { - auth = append(auth, - ssh.Password(config.Comm.SSHPassword), - ssh.KeyboardInteractive( - packerssh.PasswordKeyboardInteractive(config.Comm.SSHPassword)), - ) - } - - // Use key based auth if there is a private key in the state bag - if privateKey, ok := state.GetOk("private_key"); ok { - signer, err := ssh.ParsePrivateKey([]byte(privateKey.(string))) - if err != nil { - return nil, fmt.Errorf("Error setting up SSH config: %s", err) - } - auth = append(auth, ssh.PublicKeys(signer)) - } - - return &ssh.ClientConfig{ - User: config.Comm.SSHUsername, - Auth: auth, - HostKeyCallback: ssh.InsecureIgnoreHostKey(), - }, nil -} diff --git a/builder/triton/builder.go b/builder/triton/builder.go index f2937a702..e260cd536 100644 --- a/builder/triton/builder.go +++ b/builder/triton/builder.go @@ -63,13 +63,9 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe steps := []multistep.Step{ &StepCreateSourceMachine{}, &communicator.StepConnect{ - Config: &config.Comm, - Host: commHost, - SSHConfig: sshConfig( - b.config.Comm.SSHAgentAuth, - b.config.Comm.SSHUsername, - b.config.Comm.SSHPrivateKey, - b.config.Comm.SSHPassword), + Config: &config.Comm, + Host: commHost, + SSHConfig: b.config.Comm.SSHConfigFunc(), }, &common.StepProvision{}, &StepStopMachine{}, diff --git a/builder/triton/ssh.go b/builder/triton/ssh.go index 179b94215..0508bfed9 100644 --- a/builder/triton/ssh.go +++ b/builder/triton/ssh.go @@ -1,17 +1,7 @@ package triton import ( - "fmt" - - "io/ioutil" - "log" - "net" - "os" - - packerssh "github.com/hashicorp/packer/communicator/ssh" "github.com/hashicorp/packer/helper/multistep" - "golang.org/x/crypto/ssh" - "golang.org/x/crypto/ssh/agent" ) func commHost(state multistep.StateBag) (string, error) { @@ -25,68 +15,3 @@ func commHost(state multistep.StateBag) (string, error) { return machine, nil } - -// SSHConfig returns a function that can be used for the SSH communicator -// config for connecting to the instance created over SSH using the private key -// or password. -func sshConfig(useAgent bool, username, privateKeyPath, password string) func(multistep.StateBag) (*ssh.ClientConfig, error) { - return func(state multistep.StateBag) (*ssh.ClientConfig, error) { - - if useAgent { - log.Println("Configuring SSH agent.") - - authSock := os.Getenv("SSH_AUTH_SOCK") - if authSock == "" { - return nil, fmt.Errorf("SSH_AUTH_SOCK is not set") - } - - sshAgent, err := net.Dial("unix", authSock) - if err != nil { - return nil, fmt.Errorf("Cannot connect to SSH Agent socket %q: %s", authSock, err) - } - - return &ssh.ClientConfig{ - User: username, - Auth: []ssh.AuthMethod{ - ssh.PublicKeysCallback(agent.NewClient(sshAgent).Signers), - }, - HostKeyCallback: ssh.InsecureIgnoreHostKey(), - }, nil - } - - hasKey := privateKeyPath != "" - - if hasKey { - log.Printf("Configuring SSH private key '%s'.", privateKeyPath) - - privateKeyBytes, err := ioutil.ReadFile(privateKeyPath) - if err != nil { - return nil, fmt.Errorf("Unable to read SSH private key: %s", err) - } - - signer, err := ssh.ParsePrivateKey(privateKeyBytes) - if err != nil { - return nil, fmt.Errorf("Error setting up SSH config: %s", err) - } - - return &ssh.ClientConfig{ - User: username, - Auth: []ssh.AuthMethod{ - ssh.PublicKeys(signer), - }, - HostKeyCallback: ssh.InsecureIgnoreHostKey(), - }, nil - } else { - log.Println("Configuring SSH keyboard interactive.") - - return &ssh.ClientConfig{ - User: username, - HostKeyCallback: ssh.InsecureIgnoreHostKey(), - Auth: []ssh.AuthMethod{ - ssh.Password(password), - ssh.KeyboardInteractive( - packerssh.PasswordKeyboardInteractive(password)), - }}, nil - } - } -} diff --git a/builder/virtualbox/common/ssh.go b/builder/virtualbox/common/ssh.go index 45a99fb29..7734dc6b2 100644 --- a/builder/virtualbox/common/ssh.go +++ b/builder/virtualbox/common/ssh.go @@ -1,10 +1,7 @@ package common import ( - commonssh "github.com/hashicorp/packer/common/ssh" - "github.com/hashicorp/packer/communicator/ssh" "github.com/hashicorp/packer/helper/multistep" - gossh "golang.org/x/crypto/ssh" ) func CommHost(host string) func(multistep.StateBag) (string, error) { @@ -17,28 +14,3 @@ func SSHPort(state multistep.StateBag) (int, error) { sshHostPort := state.Get("sshHostPort").(int) return sshHostPort, nil } - -func SSHConfigFunc(config SSHConfig) func(multistep.StateBag) (*gossh.ClientConfig, error) { - return func(state multistep.StateBag) (*gossh.ClientConfig, error) { - auth := []gossh.AuthMethod{ - gossh.Password(config.Comm.SSHPassword), - gossh.KeyboardInteractive( - ssh.PasswordKeyboardInteractive(config.Comm.SSHPassword)), - } - - if config.Comm.SSHPrivateKey != "" { - signer, err := commonssh.FileSigner(config.Comm.SSHPrivateKey) - if err != nil { - return nil, err - } - - auth = append(auth, gossh.PublicKeys(signer)) - } - - return &gossh.ClientConfig{ - User: config.Comm.SSHUsername, - Auth: auth, - HostKeyCallback: gossh.InsecureIgnoreHostKey(), - }, nil - } -} diff --git a/builder/virtualbox/iso/builder.go b/builder/virtualbox/iso/builder.go index 2ea19e70f..433e6cdc6 100644 --- a/builder/virtualbox/iso/builder.go +++ b/builder/virtualbox/iso/builder.go @@ -253,7 +253,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe &communicator.StepConnect{ Config: &b.config.SSHConfig.Comm, Host: vboxcommon.CommHost(b.config.SSHConfig.Comm.SSHHost), - SSHConfig: vboxcommon.SSHConfigFunc(b.config.SSHConfig), + SSHConfig: b.config.SSHConfig.Comm.SSHConfigFunc(), SSHPort: vboxcommon.SSHPort, WinRMPort: vboxcommon.SSHPort, }, diff --git a/builder/virtualbox/ovf/builder.go b/builder/virtualbox/ovf/builder.go index 09fd416a3..6194f1d8c 100644 --- a/builder/virtualbox/ovf/builder.go +++ b/builder/virtualbox/ovf/builder.go @@ -114,7 +114,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe &communicator.StepConnect{ Config: &b.config.SSHConfig.Comm, Host: vboxcommon.CommHost(b.config.SSHConfig.Comm.SSHHost), - SSHConfig: vboxcommon.SSHConfigFunc(b.config.SSHConfig), + SSHConfig: b.config.SSHConfig.Comm.SSHConfigFunc(), SSHPort: vboxcommon.SSHPort, WinRMPort: vboxcommon.SSHPort, }, diff --git a/builder/vmware/common/ssh.go b/builder/vmware/common/ssh.go index e03f9b6bf..75d89c6b6 100644 --- a/builder/vmware/common/ssh.go +++ b/builder/vmware/common/ssh.go @@ -5,10 +5,7 @@ import ( "fmt" "log" - commonssh "github.com/hashicorp/packer/common/ssh" - "github.com/hashicorp/packer/communicator/ssh" "github.com/hashicorp/packer/helper/multistep" - gossh "golang.org/x/crypto/ssh" ) func CommHost(config *SSHConfig) func(multistep.StateBag) (string, error) { @@ -34,28 +31,3 @@ func CommHost(config *SSHConfig) func(multistep.StateBag) (string, error) { return ipAddress, nil } } - -func SSHConfigFunc(config *SSHConfig) func(multistep.StateBag) (*gossh.ClientConfig, error) { - return func(state multistep.StateBag) (*gossh.ClientConfig, error) { - auth := []gossh.AuthMethod{ - gossh.Password(config.Comm.SSHPassword), - gossh.KeyboardInteractive( - ssh.PasswordKeyboardInteractive(config.Comm.SSHPassword)), - } - - if config.Comm.SSHPrivateKey != "" { - signer, err := commonssh.FileSigner(config.Comm.SSHPrivateKey) - if err != nil { - return nil, err - } - - auth = append(auth, gossh.PublicKeys(signer)) - } - - return &gossh.ClientConfig{ - User: config.Comm.SSHUsername, - Auth: auth, - HostKeyCallback: gossh.InsecureIgnoreHostKey(), - }, nil - } -} diff --git a/builder/vmware/iso/builder.go b/builder/vmware/iso/builder.go index 0944db927..811cf234f 100644 --- a/builder/vmware/iso/builder.go +++ b/builder/vmware/iso/builder.go @@ -343,7 +343,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe &communicator.StepConnect{ Config: &b.config.SSHConfig.Comm, Host: driver.CommHost, - SSHConfig: vmwcommon.SSHConfigFunc(&b.config.SSHConfig), + SSHConfig: b.config.SSHConfig.Comm.SSHConfigFunc(), }, &vmwcommon.StepUploadTools{ RemoteType: b.config.RemoteType, diff --git a/builder/vmware/vmx/builder.go b/builder/vmware/vmx/builder.go index dbb74b7a1..a59536d66 100644 --- a/builder/vmware/vmx/builder.go +++ b/builder/vmware/vmx/builder.go @@ -101,7 +101,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe &communicator.StepConnect{ Config: &b.config.SSHConfig.Comm, Host: driver.CommHost, - SSHConfig: vmwcommon.SSHConfigFunc(&b.config.SSHConfig), + SSHConfig: b.config.SSHConfig.Comm.SSHConfigFunc(), }, &vmwcommon.StepUploadTools{ RemoteType: b.config.RemoteType, diff --git a/common/ssh/key.go b/common/ssh/key.go deleted file mode 100644 index 0de73b78c..000000000 --- a/common/ssh/key.go +++ /dev/null @@ -1,44 +0,0 @@ -package ssh - -import ( - "encoding/pem" - "fmt" - "io/ioutil" - "os" - - "golang.org/x/crypto/ssh" -) - -// FileSigner returns an ssh.Signer for a key file. -func FileSigner(path string) (ssh.Signer, error) { - f, err := os.Open(path) - if err != nil { - return nil, err - } - defer f.Close() - - keyBytes, err := ioutil.ReadAll(f) - if err != nil { - return nil, err - } - - // We parse the private key on our own first so that we can - // show a nicer error if the private key has a password. - block, _ := pem.Decode(keyBytes) - if block == nil { - return nil, fmt.Errorf( - "Failed to read key '%s': no key found", path) - } - if block.Headers["Proc-Type"] == "4,ENCRYPTED" { - return nil, fmt.Errorf( - "Failed to read key '%s': password protected keys are\n"+ - "not supported. Please decrypt the key prior to use.", path) - } - - signer, err := ssh.ParsePrivateKey(keyBytes) - if err != nil { - return nil, fmt.Errorf("Error setting up SSH config: %s", err) - } - - return signer, nil -} diff --git a/helper/communicator/step_connect_ssh.go b/helper/communicator/step_connect_ssh.go index 18fd699c7..45198d5fd 100644 --- a/helper/communicator/step_connect_ssh.go +++ b/helper/communicator/step_connect_ssh.go @@ -10,7 +10,6 @@ import ( "strings" "time" - commonssh "github.com/hashicorp/packer/common/ssh" "github.com/hashicorp/packer/communicator/ssh" "github.com/hashicorp/packer/helper/multistep" "github.com/hashicorp/packer/packer"