Commit 01abbc44 authored by Mitchell Hashimoto's avatar Mitchell Hashimoto

common/ssh: error if encrypted key is used

parent 76a82216
...@@ -20,6 +20,8 @@ IMPROVEMENTS: ...@@ -20,6 +20,8 @@ IMPROVEMENTS:
BUG FIXES: BUG FIXES:
* core: nicer error message if an encrypted private key is used for
SSH. [GH-1445]
* builder/amazon-chroot: Can properly build HVM images now. [GH-1360] * builder/amazon-chroot: Can properly build HVM images now. [GH-1360]
* builder/amazon-chroot: Fix crash in root device check. [GH-1360] * builder/amazon-chroot: Fix crash in root device check. [GH-1360]
* builder/amazon-instance: Fix deprecation warning for `ec2-bundle-vol` * builder/amazon-instance: Fix deprecation warning for `ec2-bundle-vol`
......
package ssh package ssh
import ( import (
"encoding/pem"
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"os" "os"
...@@ -21,6 +22,19 @@ func FileSigner(path string) (ssh.Signer, error) { ...@@ -21,6 +22,19 @@ func FileSigner(path string) (ssh.Signer, error) {
return nil, err 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) signer, err := ssh.ParsePrivateKey(keyBytes)
if err != nil { if err != nil {
return nil, fmt.Errorf("Error setting up SSH config: %s", err) return nil, fmt.Errorf("Error setting up SSH config: %s", err)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment