Skip to content

Commit

Permalink
Merge pull request #10293 from afbjorklund/ssh-validate
Browse files Browse the repository at this point in the history
ssh: validate the ssh-key parameter if given
  • Loading branch information
medyagh authored Feb 11, 2021
2 parents bf5301c + 40e4521 commit ee6283e
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions pkg/drivers/ssh/ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,16 @@ package ssh

import (
"fmt"
"io/ioutil"
"net"
"os"
"os/exec"
"path"
"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"
Expand Down Expand Up @@ -106,6 +109,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
Expand Down

0 comments on commit ee6283e

Please sign in to comment.