Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
packer
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kristopher Ruzic
packer
Commits
5d630bf5
Commit
5d630bf5
authored
Jun 13, 2015
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
helper/communicator: validate ssh keys
parent
90581899
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
56 additions
and
0 deletions
+56
-0
helper/communicator/config.go
helper/communicator/config.go
+12
-0
helper/communicator/ssh.go
helper/communicator/ssh.go
+44
-0
No files found.
helper/communicator/config.go
View file @
5d630bf5
...
...
@@ -2,6 +2,8 @@ package communicator
import
(
"errors"
"fmt"
"os"
"time"
"github.com/mitchellh/packer/template/interpolate"
...
...
@@ -39,6 +41,16 @@ func (c *Config) Prepare(ctx *interpolate.Context) []error {
if
c
.
SSHUsername
==
""
{
errs
=
append
(
errs
,
errors
.
New
(
"An ssh_username must be specified"
))
}
if
c
.
SSHPrivateKey
!=
""
{
if
_
,
err
:=
os
.
Stat
(
c
.
SSHPrivateKey
);
err
!=
nil
{
errs
=
append
(
errs
,
fmt
.
Errorf
(
"ssh_private_key_file is invalid: %s"
,
err
))
}
else
if
_
,
err
:=
SSHFileSigner
(
c
.
SSHPrivateKey
);
err
!=
nil
{
errs
=
append
(
errs
,
fmt
.
Errorf
(
"ssh_private_key_file is invalid: %s"
,
err
))
}
}
}
return
errs
...
...
helper/communicator/ssh.go
0 → 100644
View file @
5d630bf5
package
communicator
import
(
"encoding/pem"
"fmt"
"io/ioutil"
"os"
"golang.org/x/crypto/ssh"
)
// SSHFileSigner returns an ssh.Signer for a key file.
func
SSHFileSigner
(
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
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment