提交 40e4521b 编写于 作者: A Anders F Björklund

ssh: validate the ssh-key parameter if given

上级 c2d82491
......@@ -18,6 +18,7 @@ package ssh
import (
"fmt"
"io/ioutil"
"net"
"os"
"os/exec"
......@@ -25,6 +26,8 @@ import (
"strconv"
"time"
"golang.org/x/crypto/ssh"
"github.com/docker/machine/libmachine/drivers"
"github.com/docker/machine/libmachine/engine"
"github.com/docker/machine/libmachine/log"
......@@ -102,6 +105,16 @@ func (d *Driver) PreCreateCheck() error {
if _, err := os.Stat(d.SSHKey); os.IsNotExist(err) {
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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册