ssh: validate the ssh-key parameter if given
parent
c2d824911b
commit
40e4521bb2
|
@ -18,6 +18,7 @@ package ssh
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
"net"
|
"net"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
@ -25,6 +26,8 @@ import (
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"golang.org/x/crypto/ssh"
|
||||||
|
|
||||||
"github.com/docker/machine/libmachine/drivers"
|
"github.com/docker/machine/libmachine/drivers"
|
||||||
"github.com/docker/machine/libmachine/engine"
|
"github.com/docker/machine/libmachine/engine"
|
||||||
"github.com/docker/machine/libmachine/log"
|
"github.com/docker/machine/libmachine/log"
|
||||||
|
@ -102,6 +105,16 @@ func (d *Driver) PreCreateCheck() error {
|
||||||
if _, err := os.Stat(d.SSHKey); os.IsNotExist(err) {
|
if _, err := os.Stat(d.SSHKey); os.IsNotExist(err) {
|
||||||
return fmt.Errorf("SSH key does not exist: %q", d.SSHKey)
|
return fmt.Errorf("SSH key does not exist: %q", d.SSHKey)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
key, err := ioutil.ReadFile(d.SSHKey)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = ssh.ParsePrivateKey(key)
|
||||||
|
if err != nil {
|
||||||
|
return errors.Wrapf(err, "SSH key does not parse: %q", d.SSHKey)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|
Loading…
Reference in New Issue