helper/ssh: error if private key on SSH [GH-73]

This commit is contained in:
Mitchell Hashimoto 2014-08-05 09:53:02 -07:00
parent 642fed0356
commit a74775d077
2 changed files with 22 additions and 4 deletions

View File

@ -25,6 +25,8 @@ BUG FIXES:
* providers/aws: Description is now required for security groups
* providers/digitalocean: Private IP addresses are now a separate
attribute
* provisioner/all: If an SSH key is given with a password, a better
error message is shown. [GH-73]
## 0.1.0 (July 28, 2014)

View File

@ -1,6 +1,7 @@
package ssh
import (
"encoding/pem"
"fmt"
"io/ioutil"
"log"
@ -105,10 +106,25 @@ func PrepareConfig(conf *SSHConfig) (*Config, error) {
if err != nil {
return nil, fmt.Errorf("Failed to read key file '%s': %v", conf.KeyFile, 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(key)
if block == nil {
return nil, fmt.Errorf(
"Failed to read key '%s': no key found", conf.KeyFile)
}
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.", conf.KeyFile)
}
signer, err := ssh.ParsePrivateKey(key)
if err != nil {
return nil, fmt.Errorf("Failed to parse key file '%s': %v", conf.KeyFile, err)
}
sshConf.Auth = append(sshConf.Auth, ssh.PublicKeys(signer))
}
if conf.Password != "" {