diff options
Diffstat (limited to 'cmd/puppeth/ssh.go')
-rw-r--r-- | cmd/puppeth/ssh.go | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/cmd/puppeth/ssh.go b/cmd/puppeth/ssh.go index 26f846685..158261ce0 100644 --- a/cmd/puppeth/ssh.go +++ b/cmd/puppeth/ssh.go @@ -27,7 +27,6 @@ import ( "os/user" "path/filepath" "strings" - "syscall" "github.com/ethereum/go-ethereum/log" "golang.org/x/crypto/ssh" @@ -78,14 +77,25 @@ func dial(server string, pubkey []byte) (*sshClient, error) { } else { key, err := ssh.ParsePrivateKey(buf) if err != nil { - log.Warn("Bad SSH key, falling back to passwords", "path", path, "err", err) + fmt.Printf("What's the decryption password for %s? (won't be echoed)\n>", path) + blob, err := terminal.ReadPassword(int(os.Stdin.Fd())) + fmt.Println() + if err != nil { + log.Warn("Couldn't read password", "err", err) + } + key, err := ssh.ParsePrivateKeyWithPassphrase(buf, blob) + if err != nil { + log.Warn("Failed to decrypt SSH key, falling back to passwords", "path", path, "err", err) + } else { + auths = append(auths, ssh.PublicKeys(key)) + } } else { auths = append(auths, ssh.PublicKeys(key)) } } auths = append(auths, ssh.PasswordCallback(func() (string, error) { fmt.Printf("What's the login password for %s at %s? (won't be echoed)\n> ", login, server) - blob, err := terminal.ReadPassword(int(syscall.Stdin)) + blob, err := terminal.ReadPassword(int(os.Stdin.Fd())) fmt.Println() return string(blob), err @@ -106,6 +116,7 @@ func dial(server string, pubkey []byte) (*sshClient, error) { keycheck := func(hostname string, remote net.Addr, key ssh.PublicKey) error { // If no public key is known for SSH, ask the user to confirm if pubkey == nil { + fmt.Println() fmt.Printf("The authenticity of host '%s (%s)' can't be established.\n", hostname, remote) fmt.Printf("SSH key fingerprint is %s [MD5]\n", ssh.FingerprintLegacyMD5(key)) fmt.Printf("Are you sure you want to continue connecting (yes/no)? ") @@ -205,8 +216,8 @@ func (client *sshClient) Stream(cmd string) error { return session.Run(cmd) } -// Upload copied the set of files to a remote server via SCP, creating any non- -// existing folder in te mean time. +// Upload copies the set of files to a remote server via SCP, creating any non- +// existing folders in the mean time. func (client *sshClient) Upload(files map[string][]byte) ([]byte, error) { // Establish a single command session session, err := client.client.NewSession() |