mirror of
https://github.com/hashicorp/packer.git
synced 2026-09-30 19:54:00 -04:00
common/ssh: error if encrypted key is used
This commit is contained in:
@@ -20,6 +20,8 @@ IMPROVEMENTS:
|
||||
|
||||
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: Fix crash in root device check. [GH-1360]
|
||||
* builder/amazon-instance: Fix deprecation warning for `ec2-bundle-vol`
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package ssh
|
||||
|
||||
import (
|
||||
"encoding/pem"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
@@ -21,6 +22,19 @@ func FileSigner(path string) (ssh.Signer, error) {
|
||||
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)
|
||||
|
||||
Reference in New Issue
Block a user