From d8a19c9c82c5930a6d39d7d15e402dbd1da25b53 Mon Sep 17 00:00:00 2001 From: dingjun Date: Thu, 16 Jul 2020 14:49:22 +0800 Subject: [PATCH] change read password method --- obfscp/scp.go | 8 +++++--- obfssh/ssh.go | 8 +++++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/obfscp/scp.go b/obfscp/scp.go index 002cc24..5707a68 100644 --- a/obfscp/scp.go +++ b/obfscp/scp.go @@ -14,13 +14,13 @@ import ( "syscall" "time" - "github.com/bgentry/speakeasy" "github.com/fangdingjun/go-log/v5" "github.com/fangdingjun/obfssh" "github.com/kr/fs" "github.com/pkg/sftp" "golang.org/x/crypto/ssh" "golang.org/x/crypto/ssh/agent" + "golang.org/x/crypto/ssh/terminal" ) type options struct { @@ -577,8 +577,10 @@ func makeDirs(p string, c dirInterface) error { func passwordAuth() (string, error) { // read password from console - s, err := speakeasy.Ask("Password: ") - return strings.Trim(s, " \r\n"), err + fmt.Fprintf(os.Stdout, "Password: ") + s, err := terminal.ReadPassword(int(os.Stdin.Fd())) + fmt.Fprintf(os.Stdout, "\n") + return strings.Trim(string(s), " \r\n"), err } // diff --git a/obfssh/ssh.go b/obfssh/ssh.go index 6c2fa2c..7e36f9c 100644 --- a/obfssh/ssh.go +++ b/obfssh/ssh.go @@ -11,11 +11,11 @@ import ( "strings" "time" - "github.com/bgentry/speakeasy" "github.com/fangdingjun/go-log/v5" "github.com/fangdingjun/obfssh" "golang.org/x/crypto/ssh" "golang.org/x/crypto/ssh/agent" + "golang.org/x/crypto/ssh/terminal" ) var dialer = &net.Dialer{Timeout: 15 * time.Second} @@ -383,8 +383,10 @@ func keyboardAuth(user, instruction string, question []string, echos []bool) (an func passwordAuth() (string, error) { // read password from console - s, err := speakeasy.Ask("Password: ") - return strings.Trim(s, " \r\n"), err + fmt.Fprintf(os.Stdout, "Password: ") + s, err := terminal.ReadPassword(int(os.Stdin.Fd())) + fmt.Fprintf(os.Stdout, "\n") + return strings.Trim(string(s), " \r\n"), err } func usage() {