Skip to content

Commit ee6283e

Browse files
authored
Merge pull request #10293 from afbjorklund/ssh-validate
ssh: validate the ssh-key parameter if given
2 parents bf5301c + 40e4521 commit ee6283e

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

pkg/drivers/ssh/ssh.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,16 @@ package ssh
1818

1919
import (
2020
"fmt"
21+
"io/ioutil"
2122
"net"
2223
"os"
2324
"os/exec"
2425
"path"
2526
"strconv"
2627
"time"
2728

29+
"golang.org/x/crypto/ssh"
30+
2831
"github.com/docker/machine/libmachine/drivers"
2932
"github.com/docker/machine/libmachine/engine"
3033
"github.com/docker/machine/libmachine/log"
@@ -106,6 +109,16 @@ func (d *Driver) PreCreateCheck() error {
106109
if _, err := os.Stat(d.SSHKey); os.IsNotExist(err) {
107110
return fmt.Errorf("SSH key does not exist: %q", d.SSHKey)
108111
}
112+
113+
key, err := ioutil.ReadFile(d.SSHKey)
114+
if err != nil {
115+
return err
116+
}
117+
118+
_, err = ssh.ParsePrivateKey(key)
119+
if err != nil {
120+
return errors.Wrapf(err, "SSH key does not parse: %q", d.SSHKey)
121+
}
109122
}
110123

111124
return nil

0 commit comments

Comments
 (0)